Linux module for causing a system hard lock-up
Hi all, I am trying to hard lockup my Linux system (Debian) for evaluating some crash report mechanism. Basically, what I want to do is to load a module that will cause a non-interruptible hang. I found the following code on this website (http://oslearn.blogspot.com/2011/04/use-nmi-watchdog.html), but the module fails to hard lockup my system: #include <linux/module.h> #include <linux/kernel.h> /* printk() */ int init_module(void) { unsigned long flags; static spinlock_t lock; spin_lock_init(&lock); spin_lock_irqsave(&lock, flags); printk(KERN_INFO "Hello, world\n"); spin_lock_irqsave(&lock, flags); //spin_lock(&lock); printk(KERN_INFO "Hello, world\n"); return 0; } void cleanup_module(void) { printk(KERN_INFO "Goodbye cruel world\n"); } Could anyone please let me know how can I achieve this? Thanks in advance. John K.
Hello,
Could anyone please let me know how can I achieve this?
Is hard lockup detector enabled in your system? Could you post your .config.
Hi there, At the moment I haven't enabled a hard lockup detector (I guess you're talking about NMI watchdog, right?) but I am just trying to hard lockup Linux using a kernel module. I was expecting the posted module to do that but apparently it doesn't (Linux still works great after loading it). Thanks, John K.
-----Original Message----- From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies- bounces@kernelnewbies.org] On Behalf Of limp Sent: Wednesday, June 08, 2011 3:24 PM To: kernelnewbies@kernelnewbies.org Cc: 'Daniel Baluta' Subject: RE: Linux module for causing a system hard lock-up
Hello,
Could anyone please let me know how can I achieve this?
Is hard lockup detector enabled in your system? Could you post your .config.
Hi there,
At the moment I haven't enabled a hard lockup detector (I guess you're talking about NMI watchdog, right?) but I am just trying to hard lockup Linux using a kernel module. I was expecting the posted module to do that but apparently it doesn't (Linux still works great after loading it).
Thanks,
John K.
Looking at your original code, I would expect it to lock up a single processor system but not an SMP system. On SMP spinlock_irq_save() will disable interrupts on the local CPU, but they are still enabled on the others. You might want to try replacing the calls to spinlock_irq_save() with calls to cli(), which if I am not mistaken will disable interrupts on all CPUs. Something like this perhaps: int init_module(void) { cli(); return 0; } Or perhaps this: int init_module(void) { cli(); while(1); return 0; }
On Wed, Jun 08, 2011 at 11:24:06PM +0100, limp wrote:
Hello,
Could anyone please let me know how can I achieve this?
Is hard lockup detector enabled in your system? Could you post your .config.
Hi there,
At the moment I haven't enabled a hard lockup detector (I guess you're talking about NMI watchdog, right?) but I am just trying to hard lockup Linux using a kernel module. I was expecting the posted module to do that but apparently it doesn't (Linux still works great after loading it).
That's because only the thread that loaded the module is stuck, not the whole system. It continues on just fine, you are going to have to do more work to bring the whole system down. greg k-h
Hi! On 20:27 Wed 08 Jun , limp wrote:
Hi all,
I am trying to hard lockup my Linux system (Debian) for evaluating some crash report mechanism. ... int init_module(void) { unsigned long flags; static spinlock_t lock; spin_lock_init(&lock); spin_lock_irqsave(&lock, flags); printk(KERN_INFO "Hello, world\n"); spin_lock_irqsave(&lock, flags); //spin_lock(&lock); printk(KERN_INFO "Hello, world\n"); return 0; }
Do you have SMP? On non-smp spin_lock_irqsave is mapped to local_irq_save(). Maybe try this: int init_module(void) { unsigned long iflags; local_irq_save(iflags); while (1) { } local_irq_restore(iflags); return 0; } -Michi -- programing a layer 3+4 network protocol for mesh networks see http://michaelblizek.twilightparadox.com
Hi! I am not sure whether my version works on smp. If it does not, maybe try something like this: #include <linux/stop_machine.h> int func(void *) { while (1) { } return 0; } int init_module(void) { stop_machine(func, 0, 0); return 0; } -Michi -- programing a layer 3+4 network protocol for mesh networks see http://michaelblizek.twilightparadox.com
On Thu, Jun 9, 2011 at 11:46, Michael Blizek <michi1@michaelblizek.twilightparadox.com> wrote:
Hi!
I am not sure whether my version works on smp. If it does not, maybe try something like this:
#include <linux/stop_machine.h>
int func(void *) { while (1) { } return 0; }
int init_module(void) { stop_machine(func, 0, 0); return 0; }
-Michi
I vote this....I was into the same situation years ago, when I inaccidentally do busy looping during kernel module load. -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
Hi!
I am not sure whether my version works on smp. If it does not, maybe try something like this:
#include <linux/stop_machine.h>
int func(void *) { while (1) { } return 0; }
int init_module(void) { stop_machine(func, 0, 0); return 0; }
Thanks very much for that, it worked great! Would it be possible to give me a brief explanation on how this achieves the hard lockup (i.e. what does it actually do that leads to a lockup)? The first version that you've sent didn't work for me.
int init_module(void) unsigned long iflags;
local_irq_save(iflags); while (1) { } local_irq_restore(iflags);
return 0; }
The fact that my processor has a LAPIC considers it as an SMP (it has 2 logical cores but not 2 physical ones)? It's not a multicore processor (Intel Celeron M 440) and I haven't configured my kernel with SMP. Regards, John K.
On Jun 14, 2011, at 9:23 PM, limp wrote:
Thanks very much for that, it worked great! Would it be possible to give me a brief explanation on how this achieves the hard lockup (i.e. what does it actually do that leads to a lockup)?
If you look at 'stop_machine' method in kernel/stop_machine.c, as provided in [1], and check it further down the call chain, you'll see it basically calls 'stop_cpus', which will then run your 'func' method on each online cpu. From the description of 'stop_cpus',
* Execute @fn(@arg) on online cpus in @cpumask. On each target cpu, * @fn is run in a process context with the highest priority * preempting any task on the cpu and monopolizing it. This function * returns after all executions are complete.
If I understood it correctly, each cpu will be running your method 'func', which is an infinite loop that never sleeps, with the highest priority possible and, quoting, "monopolizing it". Hanging the machine with it seems only logical. I hope this helps. Cheers. [1] - http://lxr.linux.no/#linux+v2.6.37.3/kernel/stop_machine.c#L476 [2] - http://lxr.linux.no/#linux+v2.6.37.3/kernel/stop_machine.c#L170 --- João Eduardo Luís gpg key: 477C26E5 from pool.keyserver.eu
Hi everybody, can someone please explain what is the role of hlist_add_head (used in in hash lists). Or maybe provide some links with good examples of its use. I had a look at fs/dcache.c but frankly I can't understand it very well. Thanks in advance Luca
participants (8)
-
Daniel Baluta -
Greg KH -
Jeff Haran -
João Eduardo Luís -
limp -
luca ellero -
Michael Blizek -
Mulyadi Santosa