linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next v2 1/2] cacheinfo: Use atomic allocation for percpu cache attributes
@ 2022-07-15 10:26 Sudeep Holla
  2022-07-15 10:26 ` [PATCH -next v2 2/2] arch_topology: Fix cache attributes detection in the CPU hotplug path Sudeep Holla
  2022-07-15 10:33 ` [PATCH -next v2 1/2] cacheinfo: Use atomic allocation for percpu cache attributes Conor.Dooley
  0 siblings, 2 replies; 4+ messages in thread
From: Sudeep Holla @ 2022-07-15 10:26 UTC (permalink / raw)
  To: linux-kernel, Greg Kroah-Hartman, Conor Dooley
  Cc: Sudeep Holla, Vincent Guittot, Dietmar Eggemann, Ionela Voinescu,
	Pierre Gondois, linux-arm-kernel, linux-riscv

On couple of architectures like RISC-V and ARM64, we need to detect
cache attribues quite early during the boot when the secondary CPUs
start. So we will call detect_cache_attributes in the atomic context
and since use of normal allocation can sleep, we will end up getting
"sleeping in the atomic context" bug splat.

In order avoid that, move the allocation to use atomic version in
preparation to move the actual detection of cache attributes in the
CPU hotplug path which is atomic.

Cc: Ionela Voinescu <ionela.voinescu@arm.com>
Tested-by: Conor Dooley <conor.dooley@microchip.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/base/cacheinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Hi Greg,

Can you apply these couple of patches directly if and when you are happy
with them ?

Regards,
Sudeep

v1->v2: This was added in v2

diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index 65d566ff24c4..4b5cd08c5a65 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -356,7 +356,7 @@ int detect_cache_attributes(unsigned int cpu)
 		return -ENOENT;

 	per_cpu_cacheinfo(cpu) = kcalloc(cache_leaves(cpu),
-					 sizeof(struct cacheinfo), GFP_KERNEL);
+					 sizeof(struct cacheinfo), GFP_ATOMIC);
 	if (per_cpu_cacheinfo(cpu) == NULL) {
 		cache_leaves(cpu) = 0;
 		return -ENOMEM;
--
2.37.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH -next v2 2/2] arch_topology: Fix cache attributes detection in the CPU hotplug path
  2022-07-15 10:26 [PATCH -next v2 1/2] cacheinfo: Use atomic allocation for percpu cache attributes Sudeep Holla
@ 2022-07-15 10:26 ` Sudeep Holla
  2022-07-19 15:24   ` Geert Uytterhoeven
  2022-07-15 10:33 ` [PATCH -next v2 1/2] cacheinfo: Use atomic allocation for percpu cache attributes Conor.Dooley
  1 sibling, 1 reply; 4+ messages in thread
From: Sudeep Holla @ 2022-07-15 10:26 UTC (permalink / raw)
  To: linux-kernel, Greg Kroah-Hartman, Conor Dooley
  Cc: Sudeep Holla, Vincent Guittot, Dietmar Eggemann, Ionela Voinescu,
	Pierre Gondois, linux-arm-kernel, linux-riscv

init_cpu_topology() is called only once at the boot and all the cache
attributes are detected early for all the possible CPUs. However when
the CPUs are hotplugged out, the cacheinfo gets removed. While the
attributes are added back when the CPUs are hotplugged back in as part
of CPU hotplug state machine, it ends up called quite late after the
update_siblings_masks() are called in the secondary_start_kernel()
resulting in wrong llc_sibling_masks.

Move the call to detect_cache_attributes() inside update_siblings_masks()
to ensure the cacheinfo is updated before the LLC sibling masks are
updated. This will fix the incorrect LLC sibling masks generated when
the CPUs are hotplugged out and hotplugged back in again.

Reported-by: Ionela Voinescu <ionela.voinescu@arm.com>
Tested-by: Ionela Voinescu <ionela.voinescu@arm.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: Ionela Voinescu <ionela.voinescu@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/base/arch_topology.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

v1->v2:
	- No change in this patch, but 1/2 was added to fix possible
	  bug "sleeping in the atomic context" with this patch.
	- Added all the received tags

diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 441e14ac33a4..0424b59b695e 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -732,7 +732,11 @@ const struct cpumask *cpu_clustergroup_mask(int cpu)
 void update_siblings_masks(unsigned int cpuid)
 {
 	struct cpu_topology *cpu_topo, *cpuid_topo = &cpu_topology[cpuid];
-	int cpu;
+	int cpu, ret;
+
+	ret = detect_cache_attributes(cpuid);
+	if (ret)
+		pr_info("Early cacheinfo failed, ret = %d\n", ret);

 	/* update core and thread sibling masks */
 	for_each_online_cpu(cpu) {
@@ -821,7 +825,7 @@ __weak int __init parse_acpi_topology(void)
 #if defined(CONFIG_ARM64) || defined(CONFIG_RISCV)
 void __init init_cpu_topology(void)
 {
-	int ret, cpu;
+	int ret;

 	reset_cpu_topology();
 	ret = parse_acpi_topology();
@@ -836,13 +840,5 @@ void __init init_cpu_topology(void)
 		reset_cpu_topology();
 		return;
 	}
-
-	for_each_possible_cpu(cpu) {
-		ret = detect_cache_attributes(cpu);
-		if (ret) {
-			pr_info("Early cacheinfo failed, ret = %d\n", ret);
-			break;
-		}
-	}
 }
 #endif
--
2.37.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2 1/2] cacheinfo: Use atomic allocation for percpu cache attributes
  2022-07-15 10:26 [PATCH -next v2 1/2] cacheinfo: Use atomic allocation for percpu cache attributes Sudeep Holla
  2022-07-15 10:26 ` [PATCH -next v2 2/2] arch_topology: Fix cache attributes detection in the CPU hotplug path Sudeep Holla
@ 2022-07-15 10:33 ` Conor.Dooley
  1 sibling, 0 replies; 4+ messages in thread
From: Conor.Dooley @ 2022-07-15 10:33 UTC (permalink / raw)
  To: sudeep.holla, linux-kernel, gregkh, Conor.Dooley
  Cc: vincent.guittot, dietmar.eggemann, ionela.voinescu,
	pierre.gondois, linux-arm-kernel, linux-riscv

On 15/07/2022 11:26, Sudeep Holla wrote:
> On couple of architectures like RISC-V and ARM64, we need to detect
> cache attribues quite early during the boot when the secondary CPUs
> start. So we will call detect_cache_attributes in the atomic context
> and since use of normal allocation can sleep, we will end up getting
> "sleeping in the atomic context" bug splat.
> 
> In order avoid that, move the allocation to use atomic version in
> preparation to move the actual detection of cache attributes in the
> CPU hotplug path which is atomic.
> 
> Cc: Ionela Voinescu <ionela.voinescu@arm.com>
> Tested-by: Conor Dooley <conor.dooley@microchip.com>

Since this was a conversion from comments on the other series:
Acked-by: Conor Dooley <conor.dooley@microchip.com>

> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>   drivers/base/cacheinfo.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Hi Greg,
> 
> Can you apply these couple of patches directly if and when you are happy
> with them ?
> 
> Regards,
> Sudeep
> 
> v1->v2: This was added in v2
> 
> diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
> index 65d566ff24c4..4b5cd08c5a65 100644
> --- a/drivers/base/cacheinfo.c
> +++ b/drivers/base/cacheinfo.c
> @@ -356,7 +356,7 @@ int detect_cache_attributes(unsigned int cpu)
>   		return -ENOENT;
> 
>   	per_cpu_cacheinfo(cpu) = kcalloc(cache_leaves(cpu),
> -					 sizeof(struct cacheinfo), GFP_KERNEL);
> +					 sizeof(struct cacheinfo), GFP_ATOMIC);
>   	if (per_cpu_cacheinfo(cpu) == NULL) {
>   		cache_leaves(cpu) = 0;
>   		return -ENOMEM;
> --
> 2.37.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2 2/2] arch_topology: Fix cache attributes detection in the CPU hotplug path
  2022-07-15 10:26 ` [PATCH -next v2 2/2] arch_topology: Fix cache attributes detection in the CPU hotplug path Sudeep Holla
@ 2022-07-19 15:24   ` Geert Uytterhoeven
  0 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2022-07-19 15:24 UTC (permalink / raw)
  To: Sudeep Holla
  Cc: Linux Kernel Mailing List, Greg Kroah-Hartman, Conor Dooley,
	Vincent Guittot, Dietmar Eggemann, Ionela Voinescu,
	Pierre Gondois, Linux ARM, linux-riscv

Hi Sudeep,

On Fri, Jul 15, 2022 at 12:28 PM Sudeep Holla <sudeep.holla@arm.com> wrote:
> init_cpu_topology() is called only once at the boot and all the cache
> attributes are detected early for all the possible CPUs. However when
> the CPUs are hotplugged out, the cacheinfo gets removed. While the
> attributes are added back when the CPUs are hotplugged back in as part
> of CPU hotplug state machine, it ends up called quite late after the
> update_siblings_masks() are called in the secondary_start_kernel()
> resulting in wrong llc_sibling_masks.
>
> Move the call to detect_cache_attributes() inside update_siblings_masks()
> to ensure the cacheinfo is updated before the LLC sibling masks are
> updated. This will fix the incorrect LLC sibling masks generated when
> the CPUs are hotplugged out and hotplugged back in again.
>
> Reported-by: Ionela Voinescu <ionela.voinescu@arm.com>
> Tested-by: Ionela Voinescu <ionela.voinescu@arm.com>
> Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
> Reviewed-by: Ionela Voinescu <ionela.voinescu@arm.com>
> Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
> ---
>  drivers/base/arch_topology.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
>
> v1->v2:
>         - No change in this patch, but 1/2 was added to fix possible
>           bug "sleeping in the atomic context" with this patch.
>         - Added all the received tags

Thank you, the "Early cacheinfo failed, ret = -12" is gone.

Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-19 15:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 10:26 [PATCH -next v2 1/2] cacheinfo: Use atomic allocation for percpu cache attributes Sudeep Holla
2022-07-15 10:26 ` [PATCH -next v2 2/2] arch_topology: Fix cache attributes detection in the CPU hotplug path Sudeep Holla
2022-07-19 15:24   ` Geert Uytterhoeven
2022-07-15 10:33 ` [PATCH -next v2 1/2] cacheinfo: Use atomic allocation for percpu cache attributes Conor.Dooley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).