All of lore.kernel.org
 help / color / mirror / Atom feed
* Linux module for causing a system hard lock-up
@ 2011-06-08 19:27 limp
  2011-06-08 20:12 ` Daniel Baluta
  2011-06-09  4:28 ` Michael Blizek
  0 siblings, 2 replies; 12+ messages in thread
From: limp @ 2011-06-08 19:27 UTC (permalink / raw)
  To: kernelnewbies

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Linux module for causing a system hard lock-up
  2011-06-08 19:27 Linux module for causing a system hard lock-up limp
@ 2011-06-08 20:12 ` Daniel Baluta
  2011-06-08 22:24   ` limp
  2011-06-09  4:28 ` Michael Blizek
  1 sibling, 1 reply; 12+ messages in thread
From: Daniel Baluta @ 2011-06-08 20:12 UTC (permalink / raw)
  To: kernelnewbies

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.

thanks,
Daniel.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Linux module for causing a system hard lock-up
  2011-06-08 20:12 ` Daniel Baluta
@ 2011-06-08 22:24   ` limp
  2011-06-08 22:53     ` Jeff Haran
  2011-06-08 22:53     ` Greg KH
  0 siblings, 2 replies; 12+ messages in thread
From: limp @ 2011-06-08 22:24 UTC (permalink / raw)
  To: kernelnewbies

>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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Linux module for causing a system hard lock-up
  2011-06-08 22:24   ` limp
@ 2011-06-08 22:53     ` Jeff Haran
  2011-06-08 22:53     ` Greg KH
  1 sibling, 0 replies; 12+ messages in thread
From: Jeff Haran @ 2011-06-08 22:53 UTC (permalink / raw)
  To: kernelnewbies

> -----Original Message-----
> From: kernelnewbies-bounces at kernelnewbies.org [mailto:kernelnewbies-
> bounces at kernelnewbies.org] On Behalf Of limp
> Sent: Wednesday, June 08, 2011 3:24 PM
> To: kernelnewbies at 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;
}

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Linux module for causing a system hard lock-up
  2011-06-08 22:24   ` limp
  2011-06-08 22:53     ` Jeff Haran
@ 2011-06-08 22:53     ` Greg KH
  1 sibling, 0 replies; 12+ messages in thread
From: Greg KH @ 2011-06-08 22:53 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Linux module for causing a system hard lock-up
  2011-06-08 19:27 Linux module for causing a system hard lock-up limp
  2011-06-08 20:12 ` Daniel Baluta
@ 2011-06-09  4:28 ` Michael Blizek
  2011-06-09  4:46   ` Michael Blizek
  1 sibling, 1 reply; 12+ messages in thread
From: Michael Blizek @ 2011-06-09  4:28 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Linux module for causing a system hard lock-up
  2011-06-09  4:28 ` Michael Blizek
@ 2011-06-09  4:46   ` Michael Blizek
  2011-06-09  7:06     ` Mulyadi Santosa
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Blizek @ 2011-06-09  4:46 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Linux module for causing a system hard lock-up
  2011-06-09  4:46   ` Michael Blizek
@ 2011-06-09  7:06     ` Mulyadi Santosa
  2011-06-14 20:23       ` limp
  0 siblings, 1 reply; 12+ messages in thread
From: Mulyadi Santosa @ 2011-06-09  7:06 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Linux module for causing a system hard lock-up
  2011-06-09  7:06     ` Mulyadi Santosa
@ 2011-06-14 20:23       ` limp
  2011-06-14 21:36         ` João Eduardo Luís
  0 siblings, 1 reply; 12+ messages in thread
From: limp @ 2011-06-14 20:23 UTC (permalink / raw)
  To: kernelnewbies

> 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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Linux module for causing a system hard lock-up
  2011-06-14 20:23       ` limp
@ 2011-06-14 21:36         ` João Eduardo Luís
  2011-06-28 14:35           ` hlist_add_head luca ellero
  0 siblings, 1 reply; 12+ messages in thread
From: João Eduardo Luís @ 2011-06-14 21:36 UTC (permalink / raw)
  To: kernelnewbies

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 





-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 495 bytes
Desc: This is a digitally signed message part
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110614/3a5b6e7a/attachment-0001.bin 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* hlist_add_head
  2011-06-14 21:36         ` João Eduardo Luís
@ 2011-06-28 14:35           ` luca ellero
       [not found]             ` <BANLkTikb1ungKEJ_WoHOpMG+=-sHcFb5ag@mail.gmail.com>
  0 siblings, 1 reply; 12+ messages in thread
From: luca ellero @ 2011-06-28 14:35 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* hlist_add_head
       [not found]             ` <BANLkTikb1ungKEJ_WoHOpMG+=-sHcFb5ag@mail.gmail.com>
@ 2011-06-30  9:18               ` piyush moghe
  0 siblings, 0 replies; 12+ messages in thread
From: piyush moghe @ 2011-06-30  9:18 UTC (permalink / raw)
  To: kernelnewbies

On Thu, Jun 30, 2011 at 2:47 PM, piyush moghe <pmkernel@gmail.com> wrote:

> AFAIK hlist_add_head is a function to add a node at first position in
> collision chain at particular head ( hash bucket )
>
> For ex. whenever a new inode is allocated the hash value of that inode is
> calculated which acts as an index in inode_hashtable
> which subsequently provides and hash bucket ( head ) for that inode. Now
> this inode attached at the first position in collision chain for the
> calculated hash bucket pushing the current first inode to second position.
>
> For further clarification have a look at inode_add_to_lists() and
> __inode_add_to_lists() functions.
>
> Regards,
> Piyush
>
>
> On Tue, Jun 28, 2011 at 8:05 PM, luca ellero <lroluk@gmail.com> wrote:
>
>> 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
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110630/14a130f7/attachment.html 

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-06-30  9:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-08 19:27 Linux module for causing a system hard lock-up limp
2011-06-08 20:12 ` Daniel Baluta
2011-06-08 22:24   ` limp
2011-06-08 22:53     ` Jeff Haran
2011-06-08 22:53     ` Greg KH
2011-06-09  4:28 ` Michael Blizek
2011-06-09  4:46   ` Michael Blizek
2011-06-09  7:06     ` Mulyadi Santosa
2011-06-14 20:23       ` limp
2011-06-14 21:36         ` João Eduardo Luís
2011-06-28 14:35           ` hlist_add_head luca ellero
     [not found]             ` <BANLkTikb1ungKEJ_WoHOpMG+=-sHcFb5ag@mail.gmail.com>
2011-06-30  9:18               ` hlist_add_head piyush moghe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.