From: Pavel Emelyanov <xemul@openvz.org>
To: Duncan Sands <baldrick.bulk@free.fr>
Cc: linux-usb@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH][USBATM]: convert heavy init dances to kthread API
Date: Thu, 07 Feb 2008 12:23:55 +0300 [thread overview]
Message-ID: <47AACE2B.2040404@openvz.org> (raw)
In-Reply-To: <200802061820.54870.baldrick.bulk@free.fr>
Duncan Sands wrote:
> Hi,
>
>> The problem is that I couldn't find the maintainer for the code
>> in drivers/usb/atm/.
>
> that would be me (though since I haven't used this modem in years I would
> be more than happy to hand it off to someone else).
>
>> Besides, I don't have a proper hardware to test this.
>
> I will try to find where I put my old modem and test your patch this weekend.
Oh, that would be great :)
>> @@ -1014,11 +1015,7 @@ static int usbatm_do_heavy_init(void *arg)
>> struct usbatm_data *instance = arg;
>> int ret;
>>
>> - daemonize(instance->driver->driver_name);
>> allow_signal(SIGTERM);
>> - instance->thread_pid = current->pid;
>> -
>> - complete(&instance->thread_started);
>
> One reason the completion existed to make sure that the thread was not
> sent SIGTERM before the above call to allow_signal(SIGTERM). So I think
> you have opened up a (tiny) race by deleting it.
Nope. See my answer below :)
>> static int usbatm_heavy_init(struct usbatm_data *instance)
>> {
>> - int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_FS | CLONE_FILES);
>> -
>> - if (ret < 0) {
>> - usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
>
> Please don't delete this message.
>
>> - return ret;
>> - }
>> + struct task_struct *t;
>>
>> - wait_for_completion(&instance->thread_started);
>> + t = kthread_create(usbatm_do_heavy_init, instance,
>> + instance->driver->driver_name);
>> + if (IS_ERR(t))
>> + return PTR_ERR(t);
>>
>> + instance->thread = t;
>> + wake_up_process(t);
>
> Does the kthread API guarantee that the kthread is not running until you call
It does. That's why the race, you mentioned above is impossible.
> wake_up_process? Because if not then what is to stop the kthread finishing before
> this thread does "instance->thread = t", resulting in an attempt to send a signal
> to a dead process later on in disconnect?
>
> Otherwise it looks fine - thanks!
>
> By the way, the right thing to do is (I think) to replace the thread with a workqueue
> and have users of usbatm register a "shut_down" callback rather than using signals: the
> disconnect method would call shut_down rathering than trying to kill the thread. That
> way all this mucking around with pids etc wouldn't be needed. All users of usbatm would
> need to be modified. I managed to convince myself once that they could all be fixed up
> in a fairly simple manner thanks to a few tricks and a completion or two, but I don't
> recall the details...
Well, that would be also great, since kill_proc will be gone - that's what
I'm trying to achieve.
> Best wishes,
>
> Duncan.
>
Thanks,
Pavel
next prev parent reply other threads:[~2008-02-07 9:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-06 16:15 [PATCH][USBATM]: convert heavy init dances to kthread API Pavel Emelyanov
2008-02-06 17:20 ` Duncan Sands
2008-02-07 9:23 ` Pavel Emelyanov [this message]
2008-02-07 9:57 ` Duncan Sands
2008-02-07 10:08 ` Pavel Emelyanov
2008-02-10 20:30 ` Duncan Sands
2008-02-11 11:22 ` Pavel Emelyanov
2008-02-11 11:51 ` Duncan Sands
2008-02-07 16:18 ` Alan Stern
2008-02-07 16:37 ` Pavel Emelyanov
-- strict thread matches above, loose matches on Subject: below --
2008-02-11 12:26 [PATCH] Usbatm: " Pavel Emelyanov
2008-02-11 12:39 ` Duncan Sands
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47AACE2B.2040404@openvz.org \
--to=xemul@openvz.org \
--cc=baldrick.bulk@free.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.