From: James Bottomley <James.Bottomley@suse.de>
To: dgilbert@interlog.com
Cc: iceberg <strakh@ispras.ru>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Subject: Re: [BUG] sg.c: sleeping function called from invalid context
Date: Thu, 01 Oct 2009 20:25:27 +0000 [thread overview]
Message-ID: <1254428727.3885.64.camel@mulgrave.site> (raw)
In-Reply-To: <4AC50A3A.4010200@interlog.com>
On Thu, 2009-10-01 at 15:59 -0400, Douglas Gilbert wrote:
> iceberg wrote:
> > KERNEL_VERSION: 2.6.31
> > DESCRIBE:
> > Driver sg.c might sleep in atomic context, because it calls
> > scsi_device_put under lock_kernel.
> >
> > /drivers/scsi/sg.c:306:
> > static int
> > sg_open(struct inode *inode, struct file *filp)
> > {
> > ...
> > lock_kernel();
> > ...
> > error_out:
> > if (retval)
> > scsi_device_put(sdp->device);
> > ...
> >
> > Path to might_sleep macro from scsi_device_put:
> > 1. scsi_device_put calls put_device at ./drivers/scsi/scsi.c:1111
> > 2. put_device calls kobject_put at ./drivers/base/core.c:1038
> > 3. kobject_put calls kref_put at ./lib/kobject.c
> > 4. kref_put may call callback function kobject_release at ./lib/kref.c if
> > refcount becomes zero, which might_sleep because it calls user event. Details:
> > 5.1 kobject_cleanup calls kobject_uevent at ./lib/kobject.c:555
> > 5.2 kobject_uevent calls kobject_uevent_env at ./lib/kobject_uevent.c:282
> > 5.3 kobject_uevent_env calls call_usermodehelper_exec at
> > include/linux/kmod.h:83
> > 5.4 call_usermodehelper_exec calls wait_for_completion at ./kernel/kmod.c:481
> > 5.5 wait_for_completion calls wait_for_common at ./kernel/sched.c:5710
> > 5.6 wait_for_common calls might_sleep at ./kernels/sched.c:5692
> >
> > Found by: Linux Driver Verification
>
> This patch to sg_open() does one (and only one) unlock_kernel()
> prior to scsi_device_put(). I presume sg_put_dev() may also
> sleep so the unlock_kernel() is moved before it as well.
>
> Hopefully Tomo will comment.
Really, this isn't a bug, so no fix is required.
The analysis is wrong on two levels. Firstly scsi_device_put() is
designed to be called from interrupt/locked context and secondly
lock_kernel isn't actually a lock taking interrupt context anyway. The
BLK is a strange beast; it's recursive and it's actually transparently
dropped and reacquired over schedule, so you can sleep by design with
the BKL held.
James
prev parent reply other threads:[~2009-10-01 20:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-01 16:28 [BUG] sg.c: sleeping function called from invalid context iceberg
2009-10-01 19:59 ` Douglas Gilbert
2009-10-01 20:25 ` James Bottomley [this message]
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=1254428727.3885.64.camel@mulgrave.site \
--to=james.bottomley@suse.de \
--cc=dgilbert@interlog.com \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=strakh@ispras.ru \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox