Skip to contentSkip to conversation

arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

PATCH New Patrik, Kluba 3 participants 7 messages Dec 15, 2012 – Jan 8, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

Hi All,

Maybe this list is a better place for the following request. I've checked, and this bug is also present in the linux-next tree.

Regards,
Patrik

Begin forwarded message:

Date: Fri, 14 Dec 2012 15:13:57 +0100
From: "Patrik, Kluba" <[email protected]>
To: linux-kernel at vger.kernel.org
Subject: [PATCH 01/01] arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

Hi All,

After a hard days' work, I've managed to track down a ghost causing sporadic kernel warnings and system crashes. The patch applies for the HEAD of linux-stable. I don't know how to create and submit patches correctly, and hope that somebody will pick it up...

Regards,
Patrik
---

Quoted 1 line

From 4dd31e88a2715389e5ac198dcf00b48b4f148ea6 Mon Sep 17 00:00:00 2001

From: Patrik Kluba <[email protected]>
Date: Fri, 14 Dec 2012 14:36:27 +0100
Subject: [PATCH] arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

All the preempt-disabling assembly code is under CONFIG_PREEMPT, while VFP_bounce calls preempt_enable() uncoditionally, leading to a preempt_count() corruption (gets set to 0xffffffff). Fix the imbalance by adding #ifdef CONFIG_PREEMPT before preempt_enable().

---
 arch/arm/vfp/vfpmodule.c |    3 +++
 1 file changed, 3 insertions(+)
arch/arm/vfp/vfpmodule.c +0 -0
index 3b44e0d..2184f7e 100644
@@ -428,7 +428,10 @@ void VFP_bounce(u32 trigger, u32 fpexc, struct

pt_regs *regs) if (exceptions)
vfp_raise_exceptions(exceptions, trigger, orig_fpscr,
regs); exit:
+#ifdef CONFIG_PREEMPT
preempt_enable();
+#endif
+ return;
}

static void vfp_enable(void *unused)

Signature · 6 lines
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel"
in the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#1 lore raw

PATCH 1/1 arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

Quoted 44 lines · Kluba

Date: Fri, 14 Dec 2012 15:13:57 +0100
From: "Patrik, Kluba" <[email protected]>
To: linux-kernel at vger.kernel.org
Subject: [PATCH 01/01] arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

Hi All,

After a hard days' work, I've managed to track down a ghost causing sporadic kernel warnings and system crashes. The patch applies for the HEAD of linux-stable. I don't know how to create and submit patches correctly, and hope that somebody will pick it up...

Regards,
Patrik
---
From 4dd31e88a2715389e5ac198dcf00b48b4f148ea6 Mon Sep 17 00:00:00 2001
From: Patrik Kluba <[email protected]>
Date: Fri, 14 Dec 2012 14:36:27 +0100
Subject: [PATCH] arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

All the preempt-disabling assembly code is under CONFIG_PREEMPT, while VFP_bounce calls preempt_enable() uncoditionally, leading to a preempt_count() corruption (gets set to 0xffffffff). Fix the imbalance by adding #ifdef CONFIG_PREEMPT before preempt_enable().

---
 arch/arm/vfp/vfpmodule.c |    3 +++
 1 file changed, 3 insertions(+)
arch/arm/vfp/vfpmodule.c +0 -0
index 3b44e0d..2184f7e 100644
@@ -428,7 +428,10 @@ void VFP_bounce(u32 trigger, u32 fpexc, struct
 pt_regs *regs) if (exceptions)
 		vfp_raise_exceptions(exceptions, trigger, orig_fpscr,

regs); exit:

arch/arm/vfp/vfpmodule.c +3 -0
+#ifdef CONFIG_PREEMPT
 	preempt_enable();
+#endif
+	return;
Quoted 1 line

From include/linux/preempt.h

#ifdef CONFIG_PREEMPT_COUNT

...

#define preempt_enable() \

do { \
        preempt_enable_no_resched(); \
        barrier(); \
        preempt_check_resched(); \
} while (0)

...

#else /* !CONFIG_PREEMPT_COUNT */

...

#define preempt_enable() do { } while (0)

...

#endif

And CONFIG_PREEMPT_COUNT=y only if CONFIG_PREEMPT=y but your subject says PREEMPT_COUNT=n. Do you by chance have DEBUG_ATOMIC_SLEEP=y selected in your config? That seems to select PREEMPT_COUNT as well and so I believe we need to move ARM assembly to use PREEMPT_COUNT instead of plain PREEMPT in its preempt_count changing assembly code.

Can you try this patch? I'll probably send a follow up patch that consolidates the duplicated preempt_decrement code into some assembly macro. We may also want to fix it up so that assembly stubs call into the preempt tracer. I'm not sure how that works right now with VFP.

---->8------

arch/arm/vfp/entry.S +3 -3
index cc926c9..323ce1a 100644
@@ -22,7 +22,7 @@
 @  IRQs disabled.
 @
 ENTRY(do_vfp)
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
        ldr     r4, [r10, #TI_PREEMPT]  @ get preempt count
        add     r11, r4, #1             @ increment it
        str     r11, [r10, #TI_PREEMPT]
@@ -35,7 +35,7 @@ ENTRY(do_vfp)
 ENDPROC(do_vfp)
 
 ENTRY(vfp_null_entry)
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
        get_thread_info r10
        ldr     r4, [r10, #TI_PREEMPT]  @ get preempt count
        sub     r11, r4, #1             @ decrement it
@@ -53,7 +53,7 @@ ENDPROC(vfp_null_entry)
 
        __INIT
 ENTRY(vfp_testing_entry)
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
        get_thread_info r10
        ldr     r4, [r10, #TI_PREEMPT]  @ get preempt count
        sub     r11, r4, #1             @ decrement it
arch/arm/vfp/vfphw.S +2 -2
index ea0349f..dd5e56f 100644
@@ -168,7 +168,7 @@ vfp_hw_state_valid:
                                        @ else it's one 32-bit instruction, so
                                        @ always subtract 4 from the following
                                        @ instruction address.
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
        get_thread_info r10
        ldr     r4, [r10, #TI_PREEMPT]  @ get preempt count
        sub     r11, r4, #1             @ decrement it
@@ -192,7 +192,7 @@ look_for_VFP_exceptions:
        @ not recognised by VFP
 
        DBGSTR  "not VFP"
-#ifdef CONFIG_PREEMPT
+#ifdef CONFIG_PREEMPT_COUNT
        get_thread_info r10
        ldr     r4, [r10, #TI_PREEMPT]  @ get preempt count
        sub     r11, r4, #1             @ decrement it
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#2 lore raw

PATCH 1/1 arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

Quoted 4 lines · Stephen Boyd

Can you try this patch? I'll probably send a follow up patch that consolidates the duplicated preempt_decrement code into some assembly macro. We may also want to fix it up so that assembly stubs call into the preempt tracer. I'm not sure how that works right now with VFP.

This looks like a sensible fix to me - once tested of course.

#3 lore raw

PATCH 1/1 arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

Quoted 6 lines · Russell King - ARM Linux
Quoted 4 lines · Stephen Boyd

Can you try this patch? I'll probably send a follow up patch that consolidates the duplicated preempt_decrement code into some assembly macro. We may also want to fix it up so that assembly stubs call into the preempt tracer. I'm not sure how that works right now with VFP.

This looks like a sensible fix to me - once tested of course.

Kluba, did the patch work for you?

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#4 lore raw

PATCH 1/1 arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

Quoted 11 lines · On Wed, 02 Jan 2013 16:41:00 -0800 Stephen Boyd <[email protected]> wrote:
Quoted 7 lines · Russell King - ARM Linux
Quoted 5 lines · Stephen Boyd

Can you try this patch? I'll probably send a follow up patch that consolidates the duplicated preempt_decrement code into some assembly macro. We may also want to fix it up so that assembly stubs call into the preempt tracer. I'm not sure how that works right now with VFP.

This looks like a sensible fix to me - once tested of course.

Kluba, did the patch work for you?

Sorry for being late, was on holiday. Yes, you were right, CONFIG_DEBUG_PREEMPT (after breaking dependency on CONFIG_PREEMPT - this is how I caught the exact place) and CONFIG_DEBUG_ATOMIC_SLEEP was enabled due to bug hunting in own code (and found yet another at an unexpected place).
I have chosen #ifdef CONFIG_PREEMPT to match with assembly code, but your solution seems more reasonable.

Regards,
Patrik

Signature · 8 lines
Patrik KLUBA
Software Developer at

DENSION Audio Systems Ltd.
H-1116 Budapest, Sztregova u. 1
Phone: +36 1 463 0470
Fax:   +36 1 463 0479
Web:   www.dension.com
#5 lore raw

PATCH 1/1 arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

Quoted 7 lines · Kluba

Sorry for being late, was on holiday. Yes, you were right, CONFIG_DEBUG_PREEMPT (after breaking dependency on CONFIG_PREEMPT - this is how I caught the exact place) and CONFIG_DEBUG_ATOMIC_SLEEP was enabled due to bug hunting in own code (and found yet another at an unexpected place).
I have chosen #ifdef CONFIG_PREEMPT to match with assembly code, but your solution seems more reasonable.

Did you test my patch? If so, can I get your tested by please so I can stick it in the patch tracker?

Thanks,
Stephen

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#6 lore raw

PATCH 1/1 arm: fix a preempt_count() corruption for CONFIG_PREEMPT=n

Quoted 11 lines · On Fri, 04 Jan 2013 14:21:46 -0800 Stephen Boyd <[email protected]> wrote:
Quoted 7 lines · Kluba

Sorry for being late, was on holiday. Yes, you were right, CONFIG_DEBUG_PREEMPT (after breaking dependency on CONFIG_PREEMPT - this is how I caught the exact place) and CONFIG_DEBUG_ATOMIC_SLEEP was enabled due to bug hunting in own code (and found yet another at an unexpected place).
I have chosen #ifdef CONFIG_PREEMPT to match with assembly code, but your solution seems more reasonable.

Did you test my patch? If so, can I get your tested by please so I can stick it in the patch tracker?

Yes, I have tested it. Here you are:

Bye,
Patrik