Skip to contentSkip to conversation

ppc/smp: Replace unnecessary 'while' by 'if'

RFC PATCH NAK Leonardo Bras 2 participants 3 messages Mar 26, 2020 PowerPC

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ppc/smp: Replace unnecessary 'while' by 'if'

spin_until_cond() will wait until nmi_ipi_busy == false, and nmi_ipi_lock_start() does not seem to change nmi_ipi_busy, so there is no way this while will ever repeat.

Replace this 'while' by an 'if', so it does not look like it can repeat.

---
 arch/powerpc/kernel/smp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/smp.c +1 -1
index ea6adbf6a221..7c904d6fb4d2 100644
@@ -473,7 +473,7 @@ static int __smp_send_nmi_ipi(int cpu, void (*fn)(struct pt_regs *),
 		return 0;
 
 	nmi_ipi_lock_start(&flags);
-	while (nmi_ipi_busy) {
+	if (nmi_ipi_busy) {
 		nmi_ipi_unlock_end(&flags);
 		spin_until_cond(!nmi_ipi_busy);
 		nmi_ipi_lock_start(&flags);
Signature · 1 line
2.24.1
#1 lore raw
Quoted 5 lines · Leonardo Bras

spin_until_cond() will wait until nmi_ipi_busy == false, and nmi_ipi_lock_start() does not seem to change nmi_ipi_busy, so there is no way this while will ever repeat.

Replace this 'while' by an 'if', so it does not look like it can repeat.

Nack, it can repeat. The scenario is that cpu A is in this code, inside spin_until_cond(); cpu B has previously set nmi_ipi_busy, and cpu C is also waiting for nmi_ipi_busy to be cleared, like cpu A. When cpu B clears nmi_ipi_busy, both cpu A and cpu C will see that and will race inside nmi_ipi_lock_start(). One of them, say cpu C, will take the lock and proceed to set nmi_ipi_busy and then call nmi_ipi_unlock(). Then the other cpu (cpu A) will then take the lock and return from nmi_ipi_lock_start() and find nmi_ipi_busy == true. At that point it needs to go through the while loop body once more.

Paul.

#2 lore raw
Quoted 17 lines · Paul Mackerras
Quoted 5 lines · Leonardo Bras

spin_until_cond() will wait until nmi_ipi_busy == false, and nmi_ipi_lock_start() does not seem to change nmi_ipi_busy, so there is no way this while will ever repeat.

Replace this 'while' by an 'if', so it does not look like it can repeat.

Nack, it can repeat. The scenario is that cpu A is in this code, inside spin_until_cond(); cpu B has previously set nmi_ipi_busy, and cpu C is also waiting for nmi_ipi_busy to be cleared, like cpu A. When cpu B clears nmi_ipi_busy, both cpu A and cpu C will see that and will race inside nmi_ipi_lock_start(). One of them, say cpu C, will take the lock and proceed to set nmi_ipi_busy and then call nmi_ipi_unlock(). Then the other cpu (cpu A) will then take the lock and return from nmi_ipi_lock_start() and find nmi_ipi_busy == true. At that point it needs to go through the while loop body once more.

Quoted 1 line

Paul.

Ok, got it.

Thanks for explaining Paul!