Skip to contentSkip to conversation

powerpc: Make doorbell check preemption safe

PATCH In review Shreyas B. Prabhu 2 participants 3 messages May 19, 2015 – Jun 4, 2015 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: Make doorbell check preemption safe

Doorbell can be used to cause ipi on cpus which are sibling threads on the same core. So icp_native_cause_ipi checks if the destination cpu is a sibling thread of the current cpu and uses doorbell in such cases.

But while running with CONFIG_PREEMPT=y, since this section is preemtible, we can run into issues if after we check if the destination cpu is a sibling cpu, the task gets migrated from a sibling cpu to a cpu on another core.

Fix this by using get_cpu()/ put_cpu()

---
 arch/powerpc/sysdev/xics/icp-native.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
arch/powerpc/sysdev/xics/icp-native.c +9 -5
index 2fc4cf1..62fd478 100644
@@ -147,12 +147,16 @@ static void icp_native_cause_ipi(int cpu, unsigned long data)
 {
 	kvmppc_set_host_ipi(cpu, 1);
 #ifdef CONFIG_PPC_DOORBELL
-	if (cpu_has_feature(CPU_FTR_DBELL) &&
-	    (cpumask_test_cpu(cpu, cpu_sibling_mask(smp_processor_id()))))
-		doorbell_cause_ipi(cpu, data);
-	else
+	if (cpu_has_feature(CPU_FTR_DBELL)) {
+		if (cpumask_test_cpu(cpu, cpu_sibling_mask(get_cpu()))) {
+			doorbell_cause_ipi(cpu, data);
+			put_cpu();
+			return;
+		}
+		put_cpu();
+	}
 #endif
-		icp_native_set_qirr(cpu, IPI_PRIORITY);
+	icp_native_set_qirr(cpu, IPI_PRIORITY);
 }
 
 /*
Signature · 1 line
1.9.3
#1 lore raw
Quoted 10 lines · Shreyas B. Prabhu

Doorbell can be used to cause ipi on cpus which are sibling threads on the same core. So icp_native_cause_ipi checks if the destination cpu is a sibling thread of the current cpu and uses doorbell in such cases. =20
But while running with CONFIG_PREEMPT=3Dy, since this section is preemtible, we can run into issues if after we check if the destination cpu is a sibling cpu, the task gets migrated from a sibling cpu to a cpu on another core.
=20
Fix this by using get_cpu()/ put_cpu()

Thanks. Looks good and it's boots for me.

arch/powerpc/sysdev/=

Quoted 6 lines
---
 arch/powerpc/sysdev/xics/icp-native.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

=20

arch/powerpc/sysdev/= renamed from arch/powerpc/sysdev/xics/icp-native.c +0 -0

xics/icp-native.c

arch/powerpc/sysdev/xics/icp-native.c static void icp_native_cause_ipi(int cpu, unsigned =

Quoted 4 lines

index 2fc4cf1..62fd478 100644

arch/powerpc/sysdev/xics/icp-native.c +0 -0
@@ -147,12 +147,16 @@ static void icp_native_cause_ipi(int cpu, unsigned =

long data)

Quoted 21 lines
arch/powerpc/sysdev/xics/icp-native.c +9 -5
 {
 	kvmppc_set_host_ipi(cpu, 1);
 #ifdef CONFIG_PPC_DOORBELL
-	if (cpu_has_feature(CPU_FTR_DBELL) &&
-	    (cpumask_test_cpu(cpu, cpu_sibling_mask(smp_processor_id()))))
-		doorbell_cause_ipi(cpu, data);
-	else
+	if (cpu_has_feature(CPU_FTR_DBELL)) {
+		if (cpumask_test_cpu(cpu, cpu_sibling_mask(get_cpu()))) {
+			doorbell_cause_ipi(cpu, data);
+			put_cpu();
+			return;
+		}
+		put_cpu();
+	}
 #endif
-		icp_native_set_qirr(cpu, IPI_PRIORITY);
+	icp_native_set_qirr(cpu, IPI_PRIORITY);
 }

=20
/*

#2 lore raw
Quoted 10 lines · Michael Neuling
Quoted 9 lines · Shreyas B. Prabhu

Doorbell can be used to cause ipi on cpus which are sibling threads on the same core. So icp_native_cause_ipi checks if the destination cpu is a sibling thread of the current cpu and uses doorbell in such cases.

But while running with CONFIG_PREEMPT=y, since this section is preemtible, we can run into issues if after we check if the destination cpu is a sibling cpu, the task gets migrated from a sibling cpu to a cpu on another core.

Quoted 6 lines
Quoted 1 line

Fix this by using get_cpu()/ put_cpu()

Thanks. Looks good and it's boots for me.

mikey, Thanks!

mpe, if this looks ok, can you please pick it up?