* kernel panic on device removal when using a workqueue and delayed_work
@ 2011-10-30 19:19 Frank Schäfer
2011-10-31 3:11 ` Yong Zhang
0 siblings, 1 reply; 7+ messages in thread
From: Frank Schäfer @ 2011-10-30 19:19 UTC (permalink / raw)
To: linux-kernel
Hi,
with the following simple kernel module, I have a good chance to get a
kernel panic when I unplug the device:
#include <linux/workqueue.h>
#include <linux/usb.h>
#include <linux/module.h>
MODULE_AUTHOR("Nobody");
MODULE_DESCRIPTION("example driver for causing kernel panic");
MODULE_LICENSE("GPL");
static struct delayed_work poll_work;
static void poll(struct work_struct *work)
{
schedule_delayed_work(&poll_work,
msecs_to_jiffies(100));
}
static int test_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
INIT_DELAYED_WORK(&poll_work, poll);
schedule_delayed_work(&poll_work,
msecs_to_jiffies(100));
return 0;
}
static void test_disconnect(struct usb_interface *intf)
{
cancel_delayed_work_sync(&poll_work);
}
static const struct usb_device_id device_table[] = {
{USB_DEVICE(0x1234, 0x5678)},
{}
};
MODULE_DEVICE_TABLE(usb, device_table);
static struct usb_driver test_driver = {
.name = "test",
.id_table = device_table,
.probe = test_probe,
.disconnect = test_disconnect,
};
static int __init test_mod_init(void)
{
return usb_register(&test_driver);
}
static void __exit test_mod_exit(void)
{
usb_deregister(&test_driver);
}
module_init(test_mod_init);
module_exit(test_mod_exit);
A picture of the backtrace (the machine immediately turns off without
saving a backtrace) can be found at
http://imageshack.us/photo/my-images/823/img075gv.jpg
Kernel version is 3.1.0.
This is the first time I'm using a workqueue, so there is a good chance
that I missed something...
Or is this a kernel bug ?
Regards,
Frank Schaefer
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: kernel panic on device removal when using a workqueue and delayed_work
2011-10-30 19:19 kernel panic on device removal when using a workqueue and delayed_work Frank Schäfer
@ 2011-10-31 3:11 ` Yong Zhang
2011-10-31 10:26 ` Frank Schäfer
0 siblings, 1 reply; 7+ messages in thread
From: Yong Zhang @ 2011-10-31 3:11 UTC (permalink / raw)
To: Frank Sch�fer; +Cc: linux-kernel
On Sun, Oct 30, 2011 at 08:19:10PM +0100, Frank Sch�fer wrote:
> Hi,
>
> with the following simple kernel module, I have a good chance to get
> a kernel panic when I unplug the device:
>
>
> #include <linux/workqueue.h>
> #include <linux/usb.h>
> #include <linux/module.h>
>
> MODULE_AUTHOR("Nobody");
> MODULE_DESCRIPTION("example driver for causing kernel panic");
> MODULE_LICENSE("GPL");
>
> static struct delayed_work poll_work;
>
> static void poll(struct work_struct *work)
> {
> schedule_delayed_work(&poll_work,
> msecs_to_jiffies(100));
> }
>
> static int test_probe(struct usb_interface *intf,
> const struct usb_device_id *id)
> {
> INIT_DELAYED_WORK(&poll_work, poll);
> schedule_delayed_work(&poll_work,
> msecs_to_jiffies(100));
> return 0;
> }
>
> static void test_disconnect(struct usb_interface *intf)
> {
> cancel_delayed_work_sync(&poll_work);
> }
>
> static const struct usb_device_id device_table[] = {
> {USB_DEVICE(0x1234, 0x5678)},
> {}
> };
>
> MODULE_DEVICE_TABLE(usb, device_table);
>
> static struct usb_driver test_driver = {
> .name = "test",
> .id_table = device_table,
> .probe = test_probe,
> .disconnect = test_disconnect,
> };
>
> static int __init test_mod_init(void)
> {
> return usb_register(&test_driver);
> }
>
> static void __exit test_mod_exit(void)
> {
> usb_deregister(&test_driver);
> }
>
> module_init(test_mod_init);
> module_exit(test_mod_exit);
>
>
>
>
> A picture of the backtrace (the machine immediately turns off
> without saving a backtrace) can be found at
>
> http://imageshack.us/photo/my-images/823/img075gv.jpg
>
> Kernel version is 3.1.0.
>
>
> This is the first time I'm using a workqueue, so there is a good
> chance that I missed something...
You should cancel the work you have armed before exit.
See cancel_delayed_work().
> Or is this a kernel bug ?
I don't think so.
Thanks,
Yong
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: kernel panic on device removal when using a workqueue and delayed_work
2011-10-31 3:11 ` Yong Zhang
@ 2011-10-31 10:26 ` Frank Schäfer
2011-10-31 10:29 ` Oliver Neukum
2011-11-02 6:31 ` Yong Zhang
0 siblings, 2 replies; 7+ messages in thread
From: Frank Schäfer @ 2011-10-31 10:26 UTC (permalink / raw)
To: linux-kernel
Am 31.10.2011 04:11, schrieb Yong Zhang:
> On Sun, Oct 30, 2011 at 08:19:10PM +0100, Frank Sch�fer wrote:
>> Hi,
>>
>> with the following simple kernel module, I have a good chance to get
>> a kernel panic when I unplug the device:
>>
>>
>> #include<linux/workqueue.h>
>> #include<linux/usb.h>
>> #include<linux/module.h>
>>
>> MODULE_AUTHOR("Nobody");
>> MODULE_DESCRIPTION("example driver for causing kernel panic");
>> MODULE_LICENSE("GPL");
>>
>> static struct delayed_work poll_work;
>>
>> static void poll(struct work_struct *work)
>> {
>> schedule_delayed_work(&poll_work,
>> msecs_to_jiffies(100));
>> }
>>
>> static int test_probe(struct usb_interface *intf,
>> const struct usb_device_id *id)
>> {
>> INIT_DELAYED_WORK(&poll_work, poll);
>> schedule_delayed_work(&poll_work,
>> msecs_to_jiffies(100));
>> return 0;
>> }
>>
>> static void test_disconnect(struct usb_interface *intf)
>> {
>> cancel_delayed_work_sync(&poll_work);
>> }
...
>> static const struct usb_device_id device_table[] = {
>> {USB_DEVICE(0x1234, 0x5678)},
>> {}
>> };
>>
>> MODULE_DEVICE_TABLE(usb, device_table);
>>
>> static struct usb_driver test_driver = {
>> .name = "test",
>> .id_table = device_table,
>> .probe = test_probe,
>> .disconnect = test_disconnect,
>> };
>>
>> static int __init test_mod_init(void)
>> {
>> return usb_register(&test_driver);
>> }
>>
>> static void __exit test_mod_exit(void)
>> {
>> usb_deregister(&test_driver);
>> }
>>
>> module_init(test_mod_init);
>> module_exit(test_mod_exit);
>>
>>
>>
>>
>> A picture of the backtrace (the machine immediately turns off
>> without saving a backtrace) can be found at
>>
>> http://imageshack.us/photo/my-images/823/img075gv.jpg
>>
>> Kernel version is 3.1.0.
>>
>>
>> This is the first time I'm using a workqueue, so there is a good
>> chance that I missed something...
> You should cancel the work you have armed before exit.
> See cancel_delayed_work().
That's what I'm doing (see above).
Did you read the code ? ;-)
Regards,
Frank Schaefer
>> Or is this a kernel bug ?
> I don't think so.
>
> Thanks,
> Yong
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: kernel panic on device removal when using a workqueue and delayed_work
2011-10-31 10:26 ` Frank Schäfer
@ 2011-10-31 10:29 ` Oliver Neukum
2011-11-02 20:02 ` Frank Schäfer
2011-11-02 6:31 ` Yong Zhang
1 sibling, 1 reply; 7+ messages in thread
From: Oliver Neukum @ 2011-10-31 10:29 UTC (permalink / raw)
To: Frank Schäfer; +Cc: linux-kernel
Am Montag, 31. Oktober 2011, 11:26:58 schrieb Frank Schäfer:
> Am 31.10.2011 04:11, schrieb Yong Zhang:
> >> This is the first time I'm using a workqueue, so there is a good
> >> chance that I missed something...
> > You should cancel the work you have armed before exit.
> > See cancel_delayed_work().
> That's what I'm doing (see above).
> Did you read the code ? ;-)
Does it work if you set a flag and resubmit the work only conditionally
on it?
Regards
Oliver
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kernel panic on device removal when using a workqueue and delayed_work
2011-10-31 10:29 ` Oliver Neukum
@ 2011-11-02 20:02 ` Frank Schäfer
0 siblings, 0 replies; 7+ messages in thread
From: Frank Schäfer @ 2011-11-02 20:02 UTC (permalink / raw)
To: Oliver Neukum; +Cc: linux-kernel
Am 31.10.2011 11:29, schrieb Oliver Neukum:
> Am Montag, 31. Oktober 2011, 11:26:58 schrieb Frank Schäfer:
>> Am 31.10.2011 04:11, schrieb Yong Zhang:
>>>> This is the first time I'm using a workqueue, so there is a good
>>>> chance that I missed something...
>>> You should cancel the work you have armed before exit.
>>> See cancel_delayed_work().
>> That's what I'm doing (see above).
>> Did you read the code ? ;-)
> Does it work if you set a flag and resubmit the work only conditionally
> on it?
What do you mean ? Which flag should I set and what's the condition to
check for ?
Regards,
Frank
> Regards
> Oliver
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kernel panic on device removal when using a workqueue and delayed_work
2011-10-31 10:26 ` Frank Schäfer
2011-10-31 10:29 ` Oliver Neukum
@ 2011-11-02 6:31 ` Yong Zhang
2011-11-05 13:32 ` Frank Schäfer
1 sibling, 1 reply; 7+ messages in thread
From: Yong Zhang @ 2011-11-02 6:31 UTC (permalink / raw)
To: Frank Schäfer; +Cc: linux-kernel
On Mon, Oct 31, 2011 at 11:26:58AM +0100, Frank Schäfer wrote:
> Am 31.10.2011 04:11, schrieb Yong Zhang:
> That's what I'm doing (see above).
> Did you read the code ? ;-)
Oh, blind me.
Maybe you can enable DEBUG_OBJECTS_TIMERS && DEBUG_OBJECTS_WORK
to check if anything is broken.
Thanks,
Yong
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: kernel panic on device removal when using a workqueue and delayed_work
2011-11-02 6:31 ` Yong Zhang
@ 2011-11-05 13:32 ` Frank Schäfer
0 siblings, 0 replies; 7+ messages in thread
From: Frank Schäfer @ 2011-11-05 13:32 UTC (permalink / raw)
To: Yong Zhang; +Cc: linux-kernel
Am 02.11.2011 07:31, schrieb Yong Zhang:
> On Mon, Oct 31, 2011 at 11:26:58AM +0100, Frank Schäfer wrote:
>> Am 31.10.2011 04:11, schrieb Yong Zhang:
>> That's what I'm doing (see above).
>> Did you read the code ? ;-)
> Oh, blind me.
>
> Maybe you can enable DEBUG_OBJECTS_TIMERS&& DEBUG_OBJECTS_WORK
> to check if anything is broken.
I enabled both debug options but nothing changed (nothing new in the logs).
Any other ideas to debug this further ?
Thanks,
Frank
> Thanks,
> Yong
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-11-05 13:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-30 19:19 kernel panic on device removal when using a workqueue and delayed_work Frank Schäfer
2011-10-31 3:11 ` Yong Zhang
2011-10-31 10:26 ` Frank Schäfer
2011-10-31 10:29 ` Oliver Neukum
2011-11-02 20:02 ` Frank Schäfer
2011-11-02 6:31 ` Yong Zhang
2011-11-05 13:32 ` Frank Schäfer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox