Re: [PATCH] riscv: Move call to init_cpu_topology() to later initialization stage
From: Conor Dooley
Date: Wed Jan 04 2023 - 08:00:45 EST
Hey Ley Foon Tan,
Apologies for my various bits of confusion.
On Tue, Jan 03, 2023 at 11:53:16AM +0800, Ley Foon Tan wrote:
> topology_parse_cpu_capacity() is failed to allocate memory with kcalloc()
> after read "capacity-dmips-mhz" DT parameter in CPU DT nodes. This
> topology_parse_cpu_capacity() is called from init_cpu_topology(), move
> call to init_cpu_topology() to later initialization stage (after memory
> allocation is available).
>
> Note, this refers to ARM64 implementation, call init_cpu_topology() in
> smp_prepare_cpus().
>
> Tested on Qemu platform.
I'd like to suggest a change to the commit message:
```
If "capacity-dmips-mhz" is present in a CPU DT node,
topology_parse_cpu_capacity() will fail to allocate memory.
arm64, with which this code path is shared, does not call
topology_parse_cpu_capacity() until later in boot where memory
allocation is available.
While "capacity-dmips-mhz" is not yet a valid property on RISC-V,
invalid properties should be ignored rather than cause issues.
Move init_cpu_topology(), which calls topology_parse_cpu_capacity(),
to a later initialization stage, to match arm64.
As a side effect of this change, RISC-V is "protected" from changes to
core topology code that would work on arm64 where memory allocation is
safe but on RISC-V isn't.
```
You don't need to use exactly that, but with something along those
lines:
Reviewed-by: Conor Dooley <conor.dooley@xxxxxxxxxxxxx>
Thanks,
Conor.
>
> Signed-off-by: Ley Foon Tan <leyfoon.tan@xxxxxxxxxxxxxxxx>
>
> ---
>
> In drivers/base/arch_topology.c: topology_parse_cpu_capacity():
>
> ret = of_property_read_u32(cpu_node, "capacity-dmips-mhz",
> &cpu_capacity);
> if (!ret) {
> if (!raw_capacity) {
> raw_capacity = kcalloc(num_possible_cpus(),
> sizeof(*raw_capacity),
> GFP_KERNEL);
> if (!raw_capacity) {
> cap_parsing_failed = true;
> return false;
> }
> ---
> arch/riscv/kernel/smpboot.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> index 3373df413c88..ddb2afba6d25 100644
> --- a/arch/riscv/kernel/smpboot.c
> +++ b/arch/riscv/kernel/smpboot.c
> @@ -39,7 +39,6 @@ static DECLARE_COMPLETION(cpu_running);
>
> void __init smp_prepare_boot_cpu(void)
> {
> - init_cpu_topology();
> }
>
> void __init smp_prepare_cpus(unsigned int max_cpus)
> @@ -48,6 +47,8 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
> int ret;
> unsigned int curr_cpuid;
>
> + init_cpu_topology();
> +
> curr_cpuid = smp_processor_id();
> store_cpu_topology(curr_cpuid);
> numa_store_cpu_info(curr_cpuid);
> --
> 2.25.1
>
Attachment:
signature.asc
Description: PGP signature