hal: Ensure atomicity of rthal_local_irq_disabled
PATCH 1/1 hal: Ensure atomicity of rthal_local_irq_disabled
[Patch is now also available in 'for-upstream']
ipipe_test_pipeline_from is not atomic /wrt reading the current cpu number (or an offset for the per-cpu area) and actually reading the virtualized interrupt state. Work around this by disabling hard IRQs while accessing this service.
This fixes false-positives of RTDM driver debug checks.
--- include/asm-generic/hal.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
include/asm-generic/hal.h +8 -1
@@ -117,7 +117,14 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) = ipipe_test_pipeline_from(&rthal_domain) & 1)#define rthal_local_irq_test () ipipe_test_pipeline_from(&rthal_domain) -#define rthal_local_irq_disabled () ipipe_test_pipeline_from(&rthal_domain) +#define rthal_local_irq_disabled () \ +({ \ + unsigned long __flags, __ret; \ + local_irq_save_hw(__flags); \ + __ret = ipipe_test_pipeline_from(&rthal_domain); \ + local_irq_restore_hw(__flags); \ + __ret; \ +})#define rthal_stage_irq_enable (dom) ipipe_unstall_pipeline_from(dom)#define rthal_local_irq_save_hw (x) local_irq_save_hw(x)#define rthal_local_irq_restore_hw (x) local_irq_restore_hw(x)
Signature · 1 line
1.6.0.2
Quoted 21 lines · Jan Kiszka
[Patch is now also available in 'for-upstream']
ipipe_test_pipeline_fromis not atomic /wrt reading the current cpu number (or an offset for the per-cpu area) and actually reading the virtualized interrupt state. Work around this by disabling hard IRQs while accessing this service.This fixes false-positives of RTDM driver debug checks.
Signed-off-by Jan Kiszka <[email protected]>--- include/asm-generic/hal.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)include/asm-generic/hal.h +0
-0@@ -117,7 +117,14 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) = ipipe_test_pipeline_from(&rthal_domain) & 1)
include/asm-generic/hal.h typedef spinlock_t rthal_spinlock_t; · line 127
Quoted 10 lines
include/asm-generic/hal.h +8
-1#define rthal_local_irq_test () ipipe_test_pipeline_from(&rthal_domain) -#define rthal_local_irq_disabled () ipipe_test_pipeline_from(&rthal_domain) +#define rthal_local_irq_disabled () \ +({ \ + unsigned long __flags, __ret; \ + local_irq_save_hw(__flags); \ + __ret = ipipe_test_pipeline_from(&rthal_domain); \ + local_irq_restore_hw(__flags); \ + __ret; \ +})
Maybe we can avoid that on UP systems?
Signature · 1 line
Gilles.
Quoted 26 lines · Gilles Chanteperdrix
Quoted 25 lines · Jan Kiszka
[Patch is now also available in 'for-upstream']
ipipe_test_pipeline_fromis not atomic /wrt reading the current cpu number (or an offset for the per-cpu area) and actually reading the virtualized interrupt state. Work around this by disabling hard IRQs while accessing this service.This fixes false-positives of RTDM driver debug checks.
Signed-off-by Jan Kiszka <[email protected]>--- include/asm-generic/hal.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)include/asm-generic/hal.h +2
-1@@ -117,7 +117,14 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) = ipipe_test_pipeline_from(&rthal_domain) & 1)#define rthal_local_irq_test () ipipe_test_pipeline_from(&rthal_domain) -#define rthal_local_irq_disabled () ipipe_test_pipeline_from(&rthal_domain) +#define rthal_local_irq_disabled () \ +({ \
Quoted 9 lines
include/asm-generic/hal.h typedef spinlock_t rthal_spinlock_t; · line 127
Quoted 6 lines
include/asm-generic/hal.h +6
-0+unsigned long __flags, __ret; \ +local_irq_save_hw (__flags); \ + __ret =ipipe_test_pipeline_from (&rthal_domain); \ +local_irq_restore_hw (__flags); \ + __ret; \ +})Maybe we can avoid that on UP systems?
Yep, update pushed.
Jan
---
[PATCH] hal: Ensure atomicity of rthal_local_irq_disabled
ipipe_test_pipeline_from is not atomic /wrt reading the current cpu number (or an offset for the per-cpu area) and actually reading the virtualized interrupt state. Work around this by disabling hard IRQs while accessing this service.
This fixes false-positives of RTDM driver debug checks.
--- include/asm-generic/hal.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
include/asm-generic/hal.h +0 -0
@@ -117,7 +117,18 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) =
ipipe_test_pipeline_from(&rthal_domain) & 1)
#define rthal_local_irq_test() ipipe_test_pipeline_from(&rthal_domain)
+#ifdef CONFIG_SMP
+#define rthal_local_irq_disabled() \
+({ \
+ unsigned long __flags, __ret; \
+ local_irq_save_hw(__flags); \
+ __ret = ipipe_test_pipeline_from(&rthal_domain); \
+ local_irq_restore_hw(__flags); \
+ __ret; \
+})
+#else /* !CONFIG_SMP */
#define rthal_local_irq_disabled() ipipe_test_pipeline_from(&rthal_domain)
+#endif /* !CONFIG_SMP */
#define rthal_stage_irq_enable(dom) ipipe_unstall_pipeline_from(dom)
#define rthal_local_irq_save_hw(x) local_irq_save_hw(x)
#define rthal_local_irq_restore_hw(x) local_irq_restore_hw(x)
Signature · 1 line
1.6.0.2
Quoted 26 lines · Gilles Chanteperdrix
Quoted 25 lines · Jan Kiszka
[Patch is now also available in 'for-upstream']
ipipe_test_pipeline_fromis not atomic /wrt reading the current cpu number (or an offset for the per-cpu area) and actually reading the virtualized interrupt state. Work around this by disabling hard IRQs while accessing this service.This fixes false-positives of RTDM driver debug checks.
Signed-off-by Jan Kiszka <[email protected]>--- include/asm-generic/hal.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)include/asm-generic/hal.h +2
-1@@ -117,7 +117,14 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) = ipipe_test_pipeline_from(&rthal_domain) & 1)#define rthal_local_irq_test () ipipe_test_pipeline_from(&rthal_domain) -#define rthal_local_irq_disabled () ipipe_test_pipeline_from(&rthal_domain) +#define rthal_local_irq_disabled () \ +({ \
Quoted 9 lines
include/asm-generic/hal.h typedef spinlock_t rthal_spinlock_t; · line 127
Quoted 6 lines
include/asm-generic/hal.h +6
-0+unsigned long __flags, __ret; \ +local_irq_save_hw (__flags); \ + __ret =ipipe_test_pipeline_from (&rthal_domain); \ +local_irq_restore_hw (__flags); \ + __ret; \ +})Maybe we can avoid that on UP systems?
Yes, we should rather use local_irq_save/restore_hw_smp().
Signature · 1 line
Philippe.
Quoted 37 lines · Philippe Gerum
Quoted 26 lines · Gilles Chanteperdrix
Quoted 25 lines · Jan Kiszka
[Patch is now also available in 'for-upstream']
ipipe_test_pipeline_fromis not atomic /wrt reading the current cpu number (or an offset for the per-cpu area) and actually reading the virtualized interrupt state. Work around this by disabling hard IRQs while accessing this service.This fixes false-positives of RTDM driver debug checks.
Signed-off-by Jan Kiszka <[email protected]>--- include/asm-generic/hal.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)include/asm-generic/hal.h +2
-1@@ -117,7 +117,14 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) = ipipe_test_pipeline_from(&rthal_domain) & 1)#define rthal_local_irq_test () ipipe_test_pipeline_from(&rthal_domain) -#define rthal_local_irq_disabled () ipipe_test_pipeline_from(&rthal_domain) +#define rthal_local_irq_disabled () \ +({ \Quoted 9 lines
include/asm-generic/hal.h typedef spinlock_t rthal_spinlock_t; · line 127
Quoted 6 lines
include/asm-generic/hal.h +6
-0+unsigned long __flags, __ret; \ +local_irq_save_hw (__flags); \ + __ret =ipipe_test_pipeline_from (&rthal_domain); \ +local_irq_restore_hw (__flags); \ + __ret; \ +})Maybe we can avoid that on UP systems?
Quoted 3 lines
Yes, we should rather use local_irq_save/restore_hw_smp().
NOTE: we would need to define defaults for those though, since they are not available with legacy releases of the pipeline patch.
Signature · 1 line
Philippe.
Quoted 36 lines · Philippe Gerum
Quoted 25 lines · Gilles Chanteperdrix
Quoted 24 lines · Jan Kiszka
[Patch is now also available in 'for-upstream']
ipipe_test_pipeline_fromis not atomic /wrt reading the current cpu number (or an offset for the per-cpu area) and actually reading the virtualized interrupt state. Work around this by disabling hard IRQs while accessing this service.This fixes false-positives of RTDM driver debug checks.
Signed-off-by Jan Kiszka <[email protected]>--- include/asm-generic/hal.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)include/asm-generic/hal.h +1
-1@@ -117,7 +117,14 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) = ipipe_test_pipeline_from(&rthal_domain) & 1)#define rthal_local_irq_test () ipipe_test_pipeline_from(&rthal_domain) -#define rthal_local_irq_disabled () ipipe_test_pipeline_from(&rthal_domain) +#define rthal_local_irq_disabled () \Quoted 9 lines
include/asm-generic/hal.h typedef spinlock_t rthal_spinlock_t; · line 127
Quoted 7 lines
include/asm-generic/hal.h +7
-0+({ \ +unsigned long __flags, __ret; \ +local_irq_save_hw (__flags); \ + __ret =ipipe_test_pipeline_from (&rthal_domain); \ +local_irq_restore_hw (__flags); \ + __ret; \ +})Maybe we can avoid that on UP systems?
Quoted 2 lines
Yes, we should rather use local_irq_save/restore_hw_smp().
Oh, *_hw_smp is new, isn't it? Do we need to wrap it for older I-pipes?
Jan
Quoted 37 lines · Jan Kiszka
Quoted 36 lines · Philippe Gerum
Quoted 34 lines · Gilles Chanteperdrix
Quoted 21 lines · Jan Kiszka
[Patch is now also available in 'for-upstream']
ipipe_test_pipeline_fromis not atomic /wrt reading the current cpu number (or an offset for the per-cpu area) and actually reading the virtualized interrupt state. Work around this by disabling hard IRQs while accessing this service.This fixes false-positives of RTDM driver debug checks.
Signed-off-by Jan Kiszka <[email protected]>--- include/asm-generic/hal.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)include/asm-generic/hal.h +0
-0@@ -117,7 +117,14 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) = ipipe_test_pipeline_from(&rthal_domain) & 1)include/asm-generic/hal.h typedef spinlock_t rthal_spinlock_t; · line 127
Quoted 10 lines
include/asm-generic/hal.h +8
-1#define rthal_local_irq_test () ipipe_test_pipeline_from(&rthal_domain) -#define rthal_local_irq_disabled () ipipe_test_pipeline_from(&rthal_domain) +#define rthal_local_irq_disabled () \ +({ \ + unsigned long __flags, __ret; \ + local_irq_save_hw(__flags); \ + __ret = ipipe_test_pipeline_from(&rthal_domain); \ + local_irq_restore_hw(__flags); \ + __ret; \ +})Maybe we can avoid that on UP systems?
Quoted 4 lines
Quoted 2 lines
Yes, we should rather use local_irq_save/restore_hw_smp().
Oh,
*_hw_smpis new, isn't it? Do we need to wrap it for older I-pipes?
Yes, it was introduced to solve the SMP migration issue actually, so we need a wrapper. The advantage of having that wrapper instead of going for inlined #ifdef CONFIG_SMP is that I could simply get rid of that wrapper in 3.x, since all legacy pipeline patches would be deprecated there anyway.
Quoted 2 lines
Jan
Signature · 1 line
Philippe.
Quoted 1 line · Philippe Gerum
On Tue, 2009-11-10 at 11:43 +0100, Jan Kiszka wrote:
[...]
Quoted 7 lines
Quoted 1 line
Oh,
*_hw_smpis new, isn't it? Do we need to wrap it for older I-pipes?Yes, it was introduced to solve the SMP migration issue actually, so we need a wrapper. The advantage of having that wrapper instead of going for inlined #ifdef
CONFIG_SMPis that I could simply get rid of that wrapper in 3.x, since all legacy pipeline patches would be deprecated there anyway.
Something like this, or where to put the wrapper?
Jan
---
include/asm-generic/hal.h +8 -1
@@ -117,7 +117,14 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) = ipipe_test_pipeline_from(&rthal_domain) & 1)#define rthal_local_irq_test () ipipe_test_pipeline_from(&rthal_domain) -#define rthal_local_irq_disabled () ipipe_test_pipeline_from(&rthal_domain) +#define rthal_local_irq_disabled () \ +({ \ + unsigned long __flags, __ret; \ + local_irq_save_hw_smp(__flags); \ + __ret = ipipe_test_pipeline_from(&rthal_domain); \ + local_irq_restore_hw_smp(__flags); \ + __ret; \ +})#define rthal_stage_irq_enable (dom) ipipe_unstall_pipeline_from(dom)#define rthal_local_irq_save_hw (x) local_irq_save_hw(x)#define rthal_local_irq_restore_hw (x) local_irq_restore_hw(x)
include/asm-generic/wrappers.h +12 -0
@@ -555,4 +555,16 @@ static inline void wrap_proc_dir_entry_owner(struct proc_dir_entry *entry)#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */ #endif /* CONFIG_PROC_FS */ +#include <linux/ipipe.h> + +#ifndef local_irq_save_hw_smp +#ifdef CONFIG_SMP +#define local_irq_save_hw_smp (flags) local_irq_save_hw(flags) +#define local_irq_restore_hw_smp (flags) local_irq_restore_hw(flags) +#else /* !CONFIG_SMP */ +#define local_irq_save_hw_smp (flags) do { (void)(flags); } while (0) +#define local_irq_restore_hw_smp (flags) do { } while (0) +#endif /* !CONFIG_SMP */ +#endif /* !local_irq_save_hw_smp */ +#endif /* _XENO_ASM_GENERIC_WRAPPERS_H */
Quoted 5 lines · Jan Kiszka
Quoted 1 line · Philippe Gerum
On Tue, 2009-11-10 at 11:43 +0100, Jan Kiszka wrote:
[...]
Quoted 2 lines
Quoted 1 line
Oh,
*_hw_smpis new, isn't it? Do we need to wrap it for older I-pipes?
Quoted 8 lines
Quoted 5 lines
Yes, it was introduced to solve the SMP migration issue actually, so we need a wrapper. The advantage of having that wrapper instead of going for inlined #ifdef
CONFIG_SMPis that I could simply get rid of that wrapper in 3.x, since all legacy pipeline patches would be deprecated there anyway.Something like this, or where to put the wrapper?
Better move it to asm-generic/hal.h like other i-pipe related conditionals.
Quoted 46 lines
Jan
---
include/asm-generic/hal.h +8
-1@@ -117,7 +117,14 @@ typedef spinlock_t rthal_spinlock_t;#endif /* !CONFIG_XENO_OPT_PIPELINE_HEAD */ #define rthal_local_irq_flags (x) ((x) = ipipe_test_pipeline_from(&rthal_domain) & 1)#define rthal_local_irq_test () ipipe_test_pipeline_from(&rthal_domain) -#define rthal_local_irq_disabled () ipipe_test_pipeline_from(&rthal_domain) +#define rthal_local_irq_disabled () \ +({ \ + unsigned long __flags, __ret; \ + local_irq_save_hw_smp(__flags); \ + __ret = ipipe_test_pipeline_from(&rthal_domain); \ + local_irq_restore_hw_smp(__flags); \ + __ret; \ +})#define rthal_stage_irq_enable (dom) ipipe_unstall_pipeline_from(dom)#define rthal_local_irq_save_hw (x) local_irq_save_hw(x)#define rthal_local_irq_restore_hw (x) local_irq_restore_hw(x)include/asm-generic/wrappers.h +12
-0@@ -555,4 +555,16 @@ static inline void wrap_proc_dir_entry_owner(struct proc_dir_entry *entry)#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */ #endif /* CONFIG_PROC_FS */ +#include <linux/ipipe.h> + +#ifndef local_irq_save_hw_smp +#ifdef CONFIG_SMP +#define local_irq_save_hw_smp (flags) local_irq_save_hw(flags) +#define local_irq_restore_hw_smp (flags) local_irq_restore_hw(flags) +#else /* !CONFIG_SMP */ +#define local_irq_save_hw_smp (flags) do { (void)(flags); } while (0) +#define local_irq_restore_hw_smp (flags) do { } while (0) +#endif /* !CONFIG_SMP */ +#endif /* !local_irq_save_hw_smp */ +#endif /* _XENO_ASM_GENERIC_WRAPPERS_H */
Signature · 1 line
Philippe.
Quoted 10 lines · Philippe Gerum
Quoted 9 lines · Jan Kiszka
Quoted 1 line · Philippe Gerum
On Tue, 2009-11-10 at 11:43 +0100, Jan Kiszka wrote:
[...]
Quoted 6 lines
Quoted 1 line
Oh,
*_hw_smpis new, isn't it? Do we need to wrap it for older I-pipes?Yes, it was introduced to solve the SMP migration issue actually, so we need a wrapper. The advantage of having that wrapper instead of going for inlined #ifdef
CONFIG_SMPis that I could simply get rid of that wrapper in 3.x, since all legacy pipeline patches would be deprecated there anyway.
Quoted 5 lines
Quoted 2 lines
Something like this, or where to put the wrapper?
Better move it to
asm-generic/hal.hlike other i-pipe related conditionals.
OK, pushed a corresponding version.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux