All of lore.kernel.org
 help / color / mirror / Atom feed
* vfree in timerfunciton causes  kernel crash
@ 2004-04-16 16:10 Mikkel Christiansen
  2004-04-16 16:22 ` William Lee Irwin III
  0 siblings, 1 reply; 2+ messages in thread
From: Mikkel Christiansen @ 2004-04-16 16:10 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 402 bytes --]

Hi

Idea: a module allocates memory (vmalloc) for userspace program which 
then craches.
Due to lack of activity timer is  expires and free's the unused memory 
(vfree).
(see tc_core.c later in this mail for details)

Problem: when timer expires and vfree is called then kernel crashes -
or rather freezes silently.

Can anyone explain why this happens? a kernel bug?

Cheers
    Mikkel

kernel 2.6.5


[-- Attachment #2: tf_core.c --]
[-- Type: text/x-c, Size: 816 bytes --]

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/vmalloc.h>
#include <linux/timer.h>
#include <linux/sched.h>

#define MODULE_NAME "tf"

#ifdef __KERNEL__

int *buf;
struct timer_list timer;

static void timeoutfun(unsigned long b) {
  printk("tf: timeoutfun\n");
  vfree(buf);
}

struct timer_list timer;

int __init init_tf(void)
{
  printk("init_tf\n");
  buf = vmalloc(10*sizeof(int));
  
  init_timer(&timer); /* Initialization of the timer */
  
  timer.function = &timeoutfun;
  timer.data     = 10;
  timer.expires  = jiffies + (10 * HZ); /* 1 sec */
  
  add_timer(&timer);

  return 0;
}


void __exit exit_tf(void)
{
  printk("exit_tf\n");
  vfree(buf);
}


module_init(init_tf);
module_exit(exit_tf);
MODULE_LICENSE("GPL");


#endif

[-- Attachment #3: Makefile --]
[-- Type: text/plain, Size: 182 bytes --]

KERNEL_SOURCE = /home/mixxel/pack/linux-2.6.4
PWD = `pwd`
obj-m := tf.o

tf-objs := tf_core.o 

default: 
	make -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

clean:
	rm *.{o,ko} .*.cmd

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

* Re: vfree in timerfunciton causes  kernel crash
  2004-04-16 16:10 vfree in timerfunciton causes kernel crash Mikkel Christiansen
@ 2004-04-16 16:22 ` William Lee Irwin III
  0 siblings, 0 replies; 2+ messages in thread
From: William Lee Irwin III @ 2004-04-16 16:22 UTC (permalink / raw)
  To: Mikkel Christiansen; +Cc: linux-kernel

On Fri, Apr 16, 2004 at 06:10:50PM +0200, Mikkel Christiansen wrote:
> Idea: a module allocates memory (vmalloc) for userspace program which 
> then craches.
> Due to lack of activity timer is  expires and free's the unused memory 
> (vfree).
> (see tc_core.c later in this mail for details)
> Problem: when timer expires and vfree is called then kernel crashes -
> or rather freezes silently.
> Can anyone explain why this happens? a kernel bug?
> Cheers
>    Mikkel
> kernel 2.6.5

Use schedule_work() to do this from process context. It's a programming
error (specifically a deadlock) to vfree() from interrupt context or with
interrupts disabled.


-- wli

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

end of thread, other threads:[~2004-04-16 16:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-16 16:10 vfree in timerfunciton causes kernel crash Mikkel Christiansen
2004-04-16 16:22 ` William Lee Irwin III

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.