Sometime I noticed that system does not crash when the call to BUG() is made in the kernel driver. I just observed the stack trace from the kernel log and then find that target is running rather than entering crash mode.
To make the target crash when BUG() is called, the following config should be present;
CONFIG_PANIC_ON_OOPS=y
CONFIG_PANIC_ON_OOPS_VALUE=1
Let's look at kernel die() function which is called from BUG() function.
void die(const char *str, struct pt_regs *regs, int err)
{
...
if (in_interrupt())
panic("%s: Fatal exception in interrupt", str);
if (panic_on_oops)
panic("%s: Fatal exception", str);
If panic_on_oops is true, the panic() is called with "Fatal exception message". How panic_on_oops is specified? Is it configured during run-time?
Let's take a look at below statement;
int panic_on_oops = CONFIG_PANIC_ON_OOPS_VALUE;
panic_on_oops depends on CONFIG_PANIC_ON_OOPS_VALUE.
Now is time to check the definition of CONFIG_PANIC_ON_OOPS_VALUE.
config PANIC_ON_OOPS_VALUE
int
range 0 1
default 0 if !PANIC_ON_OOPS
default 1 if PANIC_ON_OOPS
CONFIG_PANIC_ON_OOPS_VALUE can be configured by PANIC_ON_OOPS.
Conclusion
PANIC_ON_OOPS should be enabled to make the target crash when BUG() is called.