Commit Graph

12 Commits

Author SHA1 Message Date
Radu Rendec 566b5dbe26 arch_topology: Build cacheinfo from primary CPU
Bugzilla: https://bugzilla.redhat.com/2180619

commit 5944ce092b97caed5d86d961e963b883b5c44ee2
Author: Pierre Gondois <pierre.gondois@arm.com>
Date:   Wed Jan 4 19:30:29 2023 +0100

    arch_topology: Build cacheinfo from primary CPU

    commit 3fcbf1c77d08 ("arch_topology: Fix cache attributes detection
    in the CPU hotplug path")
    adds a call to detect_cache_attributes() to populate the cacheinfo
    before updating the siblings mask. detect_cache_attributes() allocates
    memory and can take the PPTT mutex (on ACPI platforms). On PREEMPT_RT
    kernels, on secondary CPUs, this triggers a:
      'BUG: sleeping function called from invalid context' [1]
    as the code is executed with preemption and interrupts disabled.

    The primary CPU was previously storing the cache information using
    the now removed (struct cpu_topology).llc_id:
    commit 5b8dc787ce4a ("arch_topology: Drop LLC identifier stash from
    the CPU topology")

    allocate_cache_info() tries to build the cacheinfo from the primary
    CPU prior secondary CPUs boot, if the DT/ACPI description
    contains cache information.
    If allocate_cache_info() fails, then fallback to the current state
    for the cacheinfo allocation. [1] will be triggered in such case.

    When unplugging a CPU, the cacheinfo memory cannot be freed. If it
    was, then the memory would be allocated early by the re-plugged
    CPU and would trigger [1].

    Note that populate_cache_leaves() might be called multiple times
    due to populate_leaves being moved up. This is required since
    detect_cache_attributes() might be called with per_cpu_cacheinfo(cpu)
    being allocated but not populated.

    [1]:
     | BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:46
     | in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 0, name: swapper/111
     | preempt_count: 1, expected: 0
     | RCU nest depth: 1, expected: 1
     | 3 locks held by swapper/111/0:
     |  #0:  (&pcp->lock){+.+.}-{3:3}, at: get_page_from_freelist+0x218/0x12c8
     |  #1:  (rcu_read_lock){....}-{1:3}, at: rt_spin_trylock+0x48/0xf0
     |  #2:  (&zone->lock){+.+.}-{3:3}, at: rmqueue_bulk+0x64/0xa80
     | irq event stamp: 0
     | hardirqs last  enabled at (0):  0x0
     | hardirqs last disabled at (0):  copy_process+0x5dc/0x1ab8
     | softirqs last  enabled at (0):  copy_process+0x5dc/0x1ab8
     | softirqs last disabled at (0):  0x0
     | Preemption disabled at:
     |  migrate_enable+0x30/0x130
     | CPU: 111 PID: 0 Comm: swapper/111 Tainted: G        W          6.0.0-rc4-rt6-[...]
     | Call trace:
     |  __kmalloc+0xbc/0x1e8
     |  detect_cache_attributes+0x2d4/0x5f0
     |  update_siblings_masks+0x30/0x368
     |  store_cpu_topology+0x78/0xb8
     |  secondary_start_kernel+0xd0/0x198
     |  __secondary_switched+0xb0/0xb4

    Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
    Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
    Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
    Link: https://lore.kernel.org/r/20230104183033.755668-7-pierre.gondois@arm.com
    Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

Signed-off-by: Radu Rendec <rrendec@redhat.com>
2023-05-02 16:57:28 -04:00
Radu Rendec d86dc62d68 cacheinfo: Use RISC-V's init_cache_level() as generic OF implementation
Bugzilla: https://bugzilla.redhat.com/2180619

commit c3719bd9eeb2edf84bd263d662e36ca0ba262a23
Author: Pierre Gondois <pierre.gondois@arm.com>
Date:   Wed Jan 4 19:30:24 2023 +0100

    cacheinfo: Use RISC-V's init_cache_level() as generic OF implementation

    RISC-V's implementation of init_of_cache_level() is following
    the Devicetree Specification v0.3 regarding caches, cf.:
    - s3.7.3 'Internal (L1) Cache Properties'
    - s3.8 'Multi-level and Shared Cache Nodes'

    Allow reusing the implementation by moving it.

    Also make 'levels', 'leaves' and 'level' unsigned int.

    Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
    Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
    Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
    Link: https://lore.kernel.org/r/20230104183033.755668-2-pierre.gondois@arm.com
    Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

Signed-off-by: Radu Rendec <rrendec@redhat.com>
2023-05-02 16:57:27 -04:00
Vitaly Kuznetsov 06a1bfd3c2 drivers: base: cacheinfo: Get rid of DEFINE_SMP_CALL_CACHE_FUNCTION()
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2031644

commit 4b92d4add5f6dcf21275185c997d6ecb800054cd
Author: Thomas Gleixner <tglx@linutronix.de>
Date:   Tue Aug 31 13:48:34 2021 +0200

    drivers: base: cacheinfo: Get rid of DEFINE_SMP_CALL_CACHE_FUNCTION()

    DEFINE_SMP_CALL_CACHE_FUNCTION() was usefel before the CPU hotplug rework
    to ensure that the cache related functions are called on the upcoming CPU
    because the notifier itself could run on any online CPU.

    The hotplug state machine guarantees that the callbacks are invoked on the
    upcoming CPU. So there is no need to have this SMP function call
    obfuscation. That indirection was missed when the hotplug notifiers were
    converted.

    This also solves the problem of ARM64 init_cache_level() invoking ACPI
    functions which take a semaphore in that context. That's invalid as SMP
    function calls run with interrupts disabled. Running it just from the
    callback in context of the CPU hotplug thread solves this.

    Fixes: 8571890e15 ("arm64: Add support for ACPI based firmware tables")
    Reported-by: Guenter Roeck <linux@roeck-us.net>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Tested-by: Guenter Roeck <linux@roeck-us.net>
    Acked-by: Will Deacon <will@kernel.org>
    Acked-by: Peter Zijlstra <peterz@infradead.org>
    Link: https://lore.kernel.org/r/871r69ersb.ffs@tglx

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
2021-12-13 17:34:51 +01:00
Kefeng Wang 80709af732
riscv: cacheinfo: Fix using smp_processor_id() in preemptible
Use raw_smp_processor_id instead of smp_processor_id() to fix warning,

BUG: using smp_processor_id() in preemptible [00000000] code: init/1
caller is debug_smp_processor_id+0x1c/0x26
CPU: 0 PID: 1 Comm: init Not tainted 5.10.0-rc4 #211
Call Trace:
  walk_stackframe+0x0/0xaa
  show_stack+0x32/0x3e
  dump_stack+0x76/0x90
  check_preemption_disabled+0xaa/0xac
  debug_smp_processor_id+0x1c/0x26
  get_cache_size+0x18/0x68
  load_elf_binary+0x868/0xece
  bprm_execve+0x224/0x498
  kernel_execve+0xdc/0x142
  run_init_process+0x90/0x9e
  try_to_run_init_process+0x12/0x3c
  kernel_init+0xb4/0xf8
  ret_from_exception+0x0/0xc

The issue is found when CONFIG_DEBUG_PREEMPT enabled.

Reviewed-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
[Palmer: Added a comment.]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-01-12 20:25:32 -08:00
Zong Li 38f5bd23de
riscv: Add cache information in AUX vector
There are no standard CSR registers to provide cache information, the
way for RISC-V is to get this information from DT. Currently, AT_L1I_X,
AT_L1D_X and AT_L2_X are present in glibc header, and sysconf syscall
could use them to get information of cache through AUX vector.

The result of 'getconf -a' as follows:
LEVEL1_ICACHE_SIZE                 32768
LEVEL1_ICACHE_ASSOC                8
LEVEL1_ICACHE_LINESIZE             64
LEVEL1_DCACHE_SIZE                 32768
LEVEL1_DCACHE_ASSOC                8
LEVEL1_DCACHE_LINESIZE             64
LEVEL2_CACHE_SIZE                  2097152
LEVEL2_CACHE_ASSOC                 32
LEVEL2_CACHE_LINESIZE              64

Signed-off-by: Zong Li <zong.li@sifive.com>
Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-09-15 18:46:08 -07:00
Zong Li baf7cbd94b
riscv: Set more data to cacheinfo
Set cacheinfo.{size,sets,line_size} for each cache node, then we can
get these information from userland through auxiliary vector.

Signed-off-by: Zong Li <zong.li@sifive.com>
Reviewed-by: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-09-15 18:46:06 -07:00
Yash Shah 087958a176
riscv: cacheinfo: Implement cache_get_priv_group with a generic ops structure
Implement cache_get_priv_group() that will make use of a generic ops
structure to return a private attribute group for custom cache info.

Using riscv_set_cacheinfo_ops() users can hook their own custom function
to return the private attribute group for cacheinfo. In future we can
add more ops to this generic ops structure for SOC specific cacheinfo.

Signed-off-by: Yash Shah <yash.shah@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2020-05-20 15:05:05 -07:00
Thomas Gleixner 50acfb2b76 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 286
Based on 1 normalized pattern(s):

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license as published by
  the free software foundation version 2 this program is distributed
  in the hope that it will be useful but without any warranty without
  even the implied warranty of merchantability or fitness for a
  particular purpose see the gnu general public license for more
  details

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-only

has been chosen to replace the boilerplate/reference in 97 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Allison Randal <allison@lohutok.net>
Reviewed-by: Alexios Zavras <alexios.zavras@intel.com>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190529141901.025053186@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-06-05 17:36:37 +02:00
Atish Patra 94f9bf118f
RISC-V: Fix of_node_* refcount
Fix of_node* refcount at various places by using of_node_put.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
2018-12-21 08:10:49 -08:00
Palmer Dabbelt 1760debb51
RISC-V: Don't set cacheinfo.{physical_line_partition,attributes}
These are just hard coded in the RISC-V port, which doesn't make any
sense.  We should probably be setting these from device tree entries
when they exist, but for now I think it's saner to just leave them all
as their default values.

Reviewed-by: Jeremy Linton <jeremy.linton@arm.com>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
2018-10-22 17:37:41 -07:00
Jeremy Linton 2ff075c7df drivers: base: cacheinfo: setup DT cache properties early
The original intent in cacheinfo was that an architecture
specific populate_cache_leaves() would probe the hardware
and then cache_shared_cpu_map_setup() and
cache_override_properties() would provide firmware help to
extend/expand upon what was probed. Arm64 was really
the only architecture that was working this way, and
with the removal of most of the hardware probing logic it
became clear that it was possible to simplify the logic a bit.

This patch combines the walk of the DT nodes with the
code updating the cache size/line_size and nr_sets.
cache_override_properties() (which was DT specific) is
then removed. The result is that cacheinfo.of_node is
no longer used as a temporary place to hold DT references
for future calls that update cache properties. That change
helps to clarify its one remaining use (matching
cacheinfo nodes that represent shared caches) which
will be used by the ACPI/PPTT code in the following patches.

Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Vijaya Kumar K <vkilari@codeaurora.org>
Tested-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Tested-by: Tomasz Nowicki <Tomasz.Nowicki@cavium.com>
Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2018-05-17 17:27:49 +01:00
Palmer Dabbelt 76d2a0493a RISC-V: Init and Halt Code
This contains the various __init C functions, the initial assembly
kernel entry point, and the code to reset the system.  When a file was
init-related this patch contains the entire file.

Signed-off-by: Palmer Dabbelt <palmer@dabbelt.com>
2017-09-26 15:26:44 -07:00