ARM: BUG() dies silently
PATCH 1/1 ARM: BUG() dies silently
There are some cases where the code generated for BUG() results into an infinite while loop without causing a null dereference, this ends on a kernel being stuck on a loop and the user without a clue of what happened.
E.g.: lib/scatterlist.c : __sg_alloc_table
BUG_ON(nents > max_ents); 438: 9a000000 bls 440 <__sg_alloc_table+0x20> 43c: eafffffe b 43c <__sg_alloc_table+0x1c>
Adding volatile makes the compiler to avoid optimizations on this code, which makes the panic to occur:
BUG_ON(nents > max_ents); 438: 9a000002 bls 448 <__sg_alloc_table+0x28> 43c: e3a03000 mov r3, #0 440: e5833000 str r3, [r3] 444: eafffffc b 43c <__sg_alloc_table+0x1c>
Seen with gnu/linux cs arm-2010q1-202 and arm2010.09-50.
---
If needed I can change:./arch/arm/mach-clps711x/include/mach/io.h:
#define __raw_readsb(p,d,l) do { *(int *)0 = 0; } while (0)
./arch/arm/mach-clps711x/include/mach/io.h:
#define __raw_readsl(p,d,l) do { *(int *)0 = 0; } while (0)
./arch/arm/mach-clps711x/include/mach/io.h:
#define __raw_writesb(p,d,l) do { *(int *)0 = 0; } while (0)
./arch/arm/mach-clps711x/include/mach/io.h:
#define __raw_writesl(p,d,l) do { *(int *)0 = 0; } while (0)./arch/arm/kernel/traps.c: *(int *)0 = 0;
arch/arm/include/asm/bug.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/include/asm/bug.h +1 -1
@@ -12,7 +12,7 @@ extern void __bug(const char *file, int line) __attribute__((noreturn));#else /* this just causes an oops */ -#define BUG () do { *(int *)0 = 0; } while (1) +#define BUG () do { *(volatile int *)0 = 0; } while(1)#endif
Signature · 1 line
1.7.1
You might try the generic bug patch and see if it also fixes this problem - Simon
Quoted 62 lines · Omar Ramirez Luna
There are some cases where the code generated for
BUG()results into an infinite while loop without causing a null dereference, this ends on a kernel being stuck on a loop and the user without a clue of what happened.E.g.:
lib/scatterlist.c:__sg_alloc_table? ? ? ?BUG_ON(nents >
max_ents);
?438: ?9a000000? ? ? ?bls ? ? 440 <__sg_alloc_table+0x20> ?43c: ? eafffffe ? ? ? ?b ? ? ? 43c <__sg_alloc_table+0x1c>Adding volatile makes the compiler to avoid optimizations on this code, which makes the panic to occur:
? ? ? ?BUG_ON(nents >
max_ents);
?438: ?9a000002? ? ? ?bls ? ? 448 <__sg_alloc_table+0x28> ?43c: ?e3a03000? ? ? ?mov ? ? r3, #0
?440: ?e5833000? ? ? ?str ? ? r3, [r3]
?444: ? eafffffc ? ? ? ?b ? ? ? 43c <__sg_alloc_table+0x1c>Seen with gnu/linux cs arm-2010q1-202 and arm2010.09-50.
Signed-off-by Omar Ramirez Luna <[email protected]>---
If needed I can change:
./arch/arm/mach-clps711x/include/mach/io.h:
? ? ? ?#define__raw_readsb(p,d,l)?do { *(int *)0 = 0; } while (0)./arch/arm/mach-clps711x/include/mach/io.h:
? ? ? ?#define__raw_readsl(p,d,l)?do { *(int *)0 = 0; } while (0)./arch/arm/mach-clps711x/include/mach/io.h:
? ? ? ?#define__raw_writesb(p,d,l)do { *(int *)0 = 0; } while (0)./arch/arm/mach-clps711x/include/mach/io.h:
? ? ? ?#define__raw_writesl(p,d,l)do { *(int *)0 = 0; } while (0)./arch/arm/kernel/traps.c: ? ? ?*(int *)0 = 0;?arch/arm/include/asm/bug.h | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)arch/arm/include/asm/bug.h +0
-0@@ -12,7 +12,7 @@ extern void __bug(const char *file, int line) __attribute__((noreturn));?#else
?/* this just causes an oops */
arch/arm/include/asm/bug.h +1
-1-#define BUG () ? ? ? ? ?do { *(int *)0 = 0; } while (1) +#define BUG () ? ? ? ? ?do { *(volatile int *)0 = 0; } while(1)?#endif
--
1.7.1--
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/
Quoted 2 lines · Simon Glass
You might try the generic bug patch and see if it also fixes this problem - Simon
It probably won't because presumably Omar has CONFIG_BUG=n otherwise Omar would have sent a patch against __bug() in arch/arm/kernel/traps.c
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Hi Stephen,
Sorry for the confusion, but in fact I was talking about the patch to make ARM use the generic bug handling via an undef instruction instead of calling ______bug() or writing to memory address 0. Please see here:
http://www.arm.linux.org.uk/developer/patches/viewpatch.php?id=6808/1
Regards,
Simon
Quoted 12 lines · Stephen Boyd
Quoted 2 lines · Simon Glass
You might try the generic bug patch and see if it also fixes this problem - Simon
It probably won't because presumably Omar has
CONFIG_BUG=notherwise Omar would have sent a patch against__bug()inarch/arm/kernel/traps.c--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
(Please stop top posting)
Quoted 8 lines · Simon Glass
Hi Stephen,
Sorry for the confusion, but in fact I was talking about the patch to make ARM use the generic bug handling via an undef instruction instead of calling
______bug()or writing to memory address 0. Please see here:http://www.arm.linux.org.uk/developer/patches/viewpatch.php?id=6808/1
Yes I've seen your patch (and even posted comments on it which have not been responded to).
Correct me if I'm wrong, but that patch with CONFIG_BUG=n would lead to the same error that Omar is seeing because the code only modifies the bug infrastructure when CONFIG_BUG=y.
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Quoted 10 lines · Stephen Boyd
(Please stop top posting)
Quoted 7 lines · Simon Glass
Hi Stephen,
Sorry for the confusion, but in fact I was talking about the patch to make ARM use the generic bug handling via an undef instruction instead of calling
______bug()or writing to memory address 0. Please see here:
Quoted 4 lines
Yes I've seen your patch (and even posted comments on it which have not been responded to).
Hi Stephen,
Not yet! Don't worry I will get to it. I like the suggestion and am pleased that you pointed me to it, thank you.
Quoted 3 lines
Correct me if I'm wrong, but that patch with
CONFIG_BUG=nwould lead to the same error that Omar is seeing because the code only modifies the bug infrastructure whenCONFIG_BUG=y.
Well if CONFIG_BUG=n then there is no bug infrastructure, The whole file is skipped and it falls back to the asm-generic/bug.h which has even more #ifdefs in it. But I think we end up here:
#define BUG() do {} while(0)
After all the patch removes the *(int*)0 = 0 code by virtue of CONFIG_GENERIC_BUG=y, right? If I have this wrong then I will have to break out the C preprocessor...
Regards,
Simon
Quoted 6 lines
--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Quoted 8 lines · Simon Glass
Quoted 2 lines · Stephen Boyd
Yes I've seen your patch (and even posted comments on it which have not been responded to).
Hi Stephen,
Not yet! Don't worry I will get to it. I like the suggestion and am pleased that you pointed me to it, thank you.
Great!
Quoted 7 lines
Quoted 3 lines
Correct me if I'm wrong, but that patch with
CONFIG_BUG=nwould lead to the same error that Omar is seeing because the code only modifies the bug infrastructure whenCONFIG_BUG=y.Well if
CONFIG_BUG=nthen there is no bug infrastructure, The whole file is skipped and it falls back to theasm-generic/bug.hwhich has even more #ifdefs in it. But I think we end up here:
Quoted 6 lines
#define
BUG()do {} while(0)After all the patch removes the *(int*)0 = 0 code by virtue of
CONFIG_GENERIC_BUG=y, right? If I have this wrong then I will have to break out the C preprocessor...
Ah you're right. Too many ifdefs going on there.
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Hi Simon, Stephen,
Quoted 10 lines · Stephen Boyd
(Please stop top posting)
Quoted 7 lines · Simon Glass
Hi Stephen,
Sorry for the confusion, but in fact I was talking about the patch to make ARM use the generic bug handling via an undef instruction instead of calling
______bug()or writing to memory address 0. Please see here:
Quoted 8 lines
Yes I've seen your patch (and even posted comments on it which have not been responded to).
Correct me if I'm wrong, but that patch with
CONFIG_BUG=nwould lead to the same error that Omar is seeing because the code only modifies the bug infrastructure whenCONFIG_BUG=y.
I am using CONFIG_BUG=y, however I don't have CONFIG_DEBUG_BUGVERBOSE and hence I fall into the part which doesn't print the file and the line where the BUG was found.
With Simon's patch if my .config had:
CONFIG_BUG=yCONFIG_GENERIC_BUG is not setCONFIG_DEBUG_BUGVERBOSE is not set
I would fall into the same BUG definition that is causing issues:
#define BUG() do { *(int *)0 = 0; } while (1)
OTOH, is not like "Use generic BUG() handler" gives the choice of removing GENERIC_BUG given that it is not prompted in menuconfig and auto selected, if this is the intention is there any reason to keep the #else part of /* not CONFIG_GENERIC_BUG */? there is no way we can use it with this patch, right?
Regards,
Omar
On Mon, Apr 4, 2011 at 7:29 PM, Ramirez Luna, Omar <[email protected]> wrote:
...
Quoted 8 lines
I am using
CONFIG_BUG=y, however I don't haveCONFIG_DEBUG_BUGVERBOSEand hence I fall into the part which doesn't print the file and the line where the BUG was found.With Simon's patch if my .config had:
CONFIG_BUG=yCONFIG_GENERIC_BUGis not set
In this case the patch is like a nop.
Quoted 11 lines
CONFIG_DEBUG_BUGVERBOSEis not setI would fall into the same BUG definition that is causing issues:
#define
BUG()? ? ? ? ? do { *(int *)0 = 0; } while (1)OTOH, is not like "Use generic
BUG()handler" gives the choice of removingGENERIC_BUGgiven that it is not prompted in menuconfig and auto selected, if this is the intention is there any reason to keep the #else part of /* notCONFIG_GENERIC_BUG*/? there is no way we can use it with this patch, right?
Well, er, the intention is that you use the patch. I kept the old code around since people can then simply change the Kconfig option and be back where they were, as indeed you have. I would be happy to remove the old behavior, but I was concerned about a possible roasting in this forum. Changing long-established behavior is sometimes tricky.
Regards,
Simon
Quoted 5 lines
Regards,
Omar
Hi,
Quoted 25 lines · Simon Glass
On Mon, Apr 4, 2011 at 7:29 PM, Ramirez Luna, Omar <[email protected]> wrote:
...Quoted 8 lines
I am using
CONFIG_BUG=y, however I don't haveCONFIG_DEBUG_BUGVERBOSEand hence I fall into the part which doesn't print the file and the line where the BUG was found.With Simon's patch if my .config had:
CONFIG_BUG=yCONFIG_GENERIC_BUGis not setIn this case the patch is like a nop.
Quoted 11 lines
CONFIG_DEBUG_BUGVERBOSEis not setI would fall into the same BUG definition that is causing issues:
#define
BUG()? ? ? ? ? do { *(int *)0 = 0; } while (1)OTOH, is not like "Use generic
BUG()handler" gives the choice of removingGENERIC_BUGgiven that it is not prompted in menuconfig and auto selected, if this is the intention is there any reason to keep the #else part of /* notCONFIG_GENERIC_BUG*/? there is no way we can use it with this patch, right?
Quoted 5 lines
Well, er, the intention is that you use the patch. I kept the old code around since people can then simply change the
Kconfigoption and be back where they were, as indeed you have. I would be happy to remove the old behavior, but I was concerned about a possible roasting in this forum. Changing long-established behavior is sometimes tricky.
Yes, but you can't change the Kconfig because it is not prompted with your patch, if that was the intention then an option to de/select GENERIC_BUG or not is needed:
arch/arm/Kconfig
@@ -204,6 +204,10 @@ config MMU
Select if you want MMU-based virtualised addressing space support by paged memory management. If unsure, say 'Y'.
+config GENERIC_BUG
+ bool "Generic BUG" + default y + depends on BUG
Regards,
Omar
Quoted 27 lines · Omar
Hi,
Quoted 9 lines · Simon Glass
On Mon, Apr 4, 2011 at 7:29 PM, Ramirez Luna, Omar <[email protected]> wrote:
...Quoted 5 lines
OTOH, is not like "Use generic
BUG()handler" gives the choice of removingGENERIC_BUGgiven that it is not prompted in menuconfig and auto selected, if this is the intention is there any reason to keep the #else part of /* notCONFIG_GENERIC_BUG*/? there is no way we can use it with this patch, right?Quoted 5 lines
Well, er, the intention is that you use the patch. I kept the old code around since people can then simply change the
Kconfigoption and be back where they were, as indeed you have. I would be happy to remove the old behavior, but I was concerned about a possible roasting in this forum. Changing long-established behavior is sometimes tricky.Yes, but you can't change the
Kconfigbecause it is not prompted with your patch, if that was the intention then an option to de/selectGENERIC_BUGor not is needed:
arch/arm/Kconfig(quoted diff) +0
-0@@ -204,6 +204,10 @@ config MMU? ? ? ? ?Select if you want MMU-based virtualised addressing space ? ? ? ? ?support by paged memory management. If unsure, say 'Y'.
Quoted 4 lines
+config
GENERIC_BUG
+ ? ? ? bool "Generic BUG"
+ ? ? ? default y
+ ? ? ? depends on BUG
Yes that's right, it is a manual edit. But if there are no objections I will create a patch to remove this and replace the old bug infrastructure entirely. - Simon
Quoted 5 lines
Regards,
Omar
Quoted 20 lines · Omar Ramirez Luna
There are some cases where the code generated for
BUG()results into an infinite while loop without causing a null dereference, this ends on a kernel being stuck on a loop and the user without a clue of what happened.E.g.:
lib/scatterlist.c:__sg_alloc_table? ? ? ?BUG_ON(nents >
max_ents);
?438: ?9a000000? ? ? ?bls ? ? 440 <__sg_alloc_table+0x20> ?43c: ? eafffffe ? ? ? ?b ? ? ? 43c <__sg_alloc_table+0x1c>Adding volatile makes the compiler to avoid optimizations on this code, which makes the panic to occur:
? ? ? ?BUG_ON(nents >
max_ents);
?438: ?9a000002? ? ? ?bls ? ? 448 <__sg_alloc_table+0x28> ?43c: ?e3a03000? ? ? ?mov ? ? r3, #0
?440: ?e5833000? ? ? ?str ? ? r3, [r3]
?444: ? eafffffc ? ? ? ?b ? ? ? 43c <__sg_alloc_table+0x1c>
Quoted 3 lines
Seen with gnu/linux cs arm-2010q1-202 and arm2010.09-50.
Signed-off-by Omar Ramirez Luna <[email protected]>
If the "Use generic BUG() handler" patch is only scheduled for the next merge window and not for 3.1, can this patch be merged instead for 3.1 and -stable? This problem is easily seen with GCC 4.6.
Hi
Quoted 3 lines · Rabin Vincent
If the "Use generic
BUG()handler" patch is only scheduled for the next merge window and not for 3.1, can this patch be merged instead for 3.1 and -stable? ?This problem is easily seen with GCC 4.6.
I can send it for both and let the maintainers decide.
Russell, do you give your ack?
Regards,
Omar
Quoted 10 lines · Omar
Hi
Quoted 3 lines · Rabin Vincent
If the "Use generic
BUG()handler" patch is only scheduled for the next merge window and not for 3.1, can this patch be merged instead for 3.1 and -stable? ?This problem is easily seen with GCC 4.6.I can send it for both and let the maintainers decide.
Russell, do you give your ack?
I think it's too large a change for -stable and 3.1 - let's get it into 3.2 first, and make sure no one sees any regressions there. Then we can think about submitting it to stable once its proven itself.
Quoted 8 lines · Russell King - ARM Linux
Quoted 7 lines · Omar
Hi
Quoted 3 lines · Rabin Vincent
If the "Use generic
BUG()handler" patch is only scheduled for the next merge window and not for 3.1, can this patch be merged instead for 3.1 and -stable? ?This problem is easily seen with GCC 4.6.
Quoted 7 lines
Quoted 3 lines
I can send it for both and let the maintainers decide.
Russell, do you give your ack?
I think it's too large a change for -stable and 3.1 - let's get it into 3.2 first, and make sure no one sees any regressions there. Then we can think about submitting it to stable once its proven itself.
And we're seeing link failures with the patch in the kernel, so it's *definitely* not stable material as it stands, even if the current code is a problem for GCC 4.6.
Regressions trump bug fixes.
Hi Russell,
Quoted 17 lines · Russell King - ARM Linux
Quoted 8 lines · Russell King - ARM Linux
Quoted 7 lines · Omar
Hi
Quoted 3 lines · Rabin Vincent
If the "Use generic
BUG()handler" patch is only scheduled for the next merge window and not for 3.1, can this patch be merged instead for 3.1 and -stable? ?This problem is easily seen with GCC 4.6.Quoted 7 lines
Quoted 3 lines
I can send it for both and let the maintainers decide.
Russell, do you give your ack?
I think it's too large a change for -stable and 3.1 - let's get it into 3.2 first, and make sure no one sees any regressions there. ?Then we can think about submitting it to stable once its proven itself.
Quoted 5 lines
And we're seeing link failures with the patch in the kernel, so it's *definitely* not stable material as it stands, even if the current code is a problem for GCC 4.6.
Regressions trump bug fixes.
Can you point me to the link failures please?
Regards,
Simon
Quoted 6 lines
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 21 lines · Simon Glass
Hi Russell,
Quoted 17 lines · Russell King - ARM Linux
Quoted 15 lines · Russell King - ARM Linux
Quoted 10 lines · Omar
Hi
Quoted 3 lines · Rabin Vincent
If the "Use generic
BUG()handler" patch is only scheduled for the next merge window and not for 3.1, can this patch be merged instead for 3.1 and -stable? ?This problem is easily seen with GCC 4.6.I can send it for both and let the maintainers decide.
Russell, do you give your ack?
I think it's too large a change for -stable and 3.1 - let's get it into 3.2 first, and make sure no one sees any regressions there. ?Then we can think about submitting it to stable once its proven itself.
Quoted 7 lines
Quoted 5 lines
And we're seeing link failures with the patch in the kernel, so it's *definitely* not stable material as it stands, even if the current code is a problem for GCC 4.6.
Regressions trump bug fixes.
Can you point me to the link failures please?
There's two emails during the last couple of months on lakml:
3.1-rc1 link failure
Link failures due to __bug_table in current -next
The former I looked into and came to the conclusion that the only way to solve it is to stop using asm-generic/vmlinux.lds.S in its entirety and go back to hand-coding ARMs vmlinux.lds file. No one's come forward with any better suggestion to fix this, so I'm getting very close to having to make a decision over this. I think I'm going to have to drop the generic bug support for the time being.
Hi,
Quoted 1 line · Russell King - ARM Linux
I think I'm going to have to drop the generic bug support for the time being.
In this case then my patch can targeted for 3.1 and -stable, right? I abandoned my change because the generic bug patch was the better solution in the long term, but if it is being delayed I can submit mine with your blessing.
https://lkml.org/lkml/2011/3/31/490
It just forces the compiler to generate the right code through volatile, and while at it I could fix the other similar situations (also noted in the patch).
Omar