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

login
register
mail settings
Submitter Grant Likely
Date June 29, 2009, 11:40 p.m.
Message ID <20090629234035.12475.58493.stgit@localhost.localdomain>
Download mbox | patch
Permalink /patch/29299/
State Accepted
Commit ad9064d5e22a6a24f828dad63c4775c4d7280bd4
Delegated to: Benjamin Herrenschmidt
Headers show

Comments

Grant Likely - June 29, 2009, 11:40 p.m.
From: Grant Likely <grant.likely@secretlab.ca>

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.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

 arch/powerpc/include/asm/delay.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Timur Tabi - June 30, 2009, 3:02 p.m.
On Mon, Jun 29, 2009 at 6:40 PM, Grant Likely<grant.likely@secretlab.ca> wrote:
> From: Grant Likely <grant.likely@secretlab.ca>
>
> 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.
>
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

Acked-by: Timur Tabi <timur@freescale.com>

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

Patch

diff --git a/arch/powerpc/include/asm/delay.h b/arch/powerpc/include/asm/delay.h
index 1e2eb41..52e4d54 100644
--- a/arch/powerpc/include/asm/delay.h
+++ b/arch/powerpc/include/asm/delay.h
@@ -63,6 +63,8 @@  extern void udelay(unsigned long usecs);
 			udelay(delay);                                         \
 		else                                                           \
 			cpu_relax();                                           \
+	if (!__ret)                                                            \
+		__ret = (condition);                                           \
 	__ret;		                                                       \
 })