Skip to contentSkip to conversation

powerpc: Fix spin_event_timeout() to be robust over context switches

PATCH In review Grant Likely 2 participants 2 messages Jun 29, 2009 – Jun 30, 2009 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: Fix spin_event_timeout() to be robust over context switches

From: Grant Likely <[email protected]>

Current implementation of spin_event_timeout can be interrupted by an IRQ or context switch after testing the condition, but before checking the timeout. This can cause the loop to report a timeout when the condition actually became true in the middle.

This patch adds one final check of the condition upon exit of the loop if the last test of the condition was still false.

---

 arch/powerpc/include/asm/delay.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/delay.h +2 -0
index 1e2eb41..52e4d54 100644
@@ -63,6 +63,8 @@ extern void udelay(unsigned long usecs);
 			udelay(delay);                                         \
 		else                                                           \
 			cpu_relax();                                           \
+	if (!__ret)                                                            \
+		__ret = (condition);                                           \
 	__ret;		                                                       \
 })
 
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Grant Likely

From: Grant Likely <[email protected]>

Current implementation of spin_event_timeout can be interrupted by an IRQ or context switch after testing the condition, but before checking the timeout.  This can cause the loop to report a timeout when the condition actually became true in the middle.

This patch adds one final check of the condition upon exit of the loop if the last test of the condition was still false.

Ben, please pick this up for the next rc of 2.6.31.

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale