From: Parag Warudkar <parag.lkml@gmail.com>
To: Jens Axboe <jaxboe@fusionio.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Parag Warudkar <parag.lkml@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"James.Bottomley@hansenpartnership.com"
<James.Bottomley@hansenpartnership.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
Linux SCSI List <linux-scsi@vger.kernel.org>
Subject: Re: [PATCH] SCSI IOCTL: Check for device deletion [was Re: __elv_add_request OOPS]
Date: Wed, 25 May 2011 15:52:16 -0400 (EDT) [thread overview]
Message-ID: <alpine.DEB.2.02.1105251548420.2742@ubuntu-natty> (raw)
In-Reply-To: <4DDD55D6.1080909@fusionio.com>
On Wed, 25 May 2011, Jens Axboe wrote:
> I don't think we can move it earlier, we essentially have to do the
> check at both ends. The "normal" IO path would see that the queue is
> dead and error the IO, but this is an internal setup that sets up the
> request and then adds it to the stored queue pointer. So it needs to
> check this state one way or the other. I think the above fix with the
> sdev_alive() will be good enough.
>
If I understood it right we need checks in both places (kind of makes
sense as the device could be gone *after* we checked in ioctl function and
before the request queue was dereferenced). So here is the ioctl check
with a helper function for state check that Linus asked for.
Signed-off-by: Parag Warudkar <parag.lkml@gmail.com>
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index d9564fb..8615e63 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -30,6 +30,13 @@
#define MAX_BUF PAGE_SIZE
+static inline int sdev_early_check(struct scsi_device *sdev)
+{
+ if (!sdev || sdev->sdev_state == SDEV_DEL
+ || sdev->sdev_state > SDEV_QUIESCE)
+ return -ENXIO;
+ return 0;
+}
/**
* ioctl_probe -- return host identification
* @host: host to identify
@@ -91,6 +98,10 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
int result;
struct scsi_sense_hdr sshdr;
+ result = sdev_early_check(sdev);
+ if (result)
+ return result;
+
SCSI_LOG_IOCTL(1, printk("Trying ioctl with scsi command %d\n", *cmd));
result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0,
@@ -194,10 +205,11 @@ static int scsi_ioctl_get_pci(struct scsi_device *sdev, void __user *arg)
int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
{
char scsi_cmd[MAX_COMMAND_SIZE];
+ int result;
- /* No idea how this happens.... */
- if (!sdev)
- return -ENXIO;
+ result = sdev_early_check(sdev);
+ if (result)
+ return result;
/*
* If we are in the middle of error recovery, don't let anyone
@@ -288,6 +300,10 @@ int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd,
{
int val, result;
+ result = sdev_early_check(sdev);
+ if (result)
+ return result;
+
/* The first set of iocts may be executed even if we're doing
* error processing, as long as the device was opened
* non-blocking */
next prev parent reply other threads:[~2011-05-25 19:52 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-24 4:29 __elv_add_request OOPS Parag Warudkar
2011-05-24 10:44 ` Jens Axboe
2011-05-25 1:41 ` [PATCH] SCSI IOCTL: Check for device deletion [was Re: __elv_add_request OOPS] Parag Warudkar
2011-05-25 7:37 ` Jens Axboe
2011-05-25 18:44 ` Parag Warudkar
2011-05-25 18:55 ` Linus Torvalds
2011-05-25 19:02 ` Jens Axboe
2011-05-25 19:13 ` Linus Torvalds
2011-05-25 19:17 ` Jens Axboe
2011-05-25 19:52 ` Parag Warudkar [this message]
2011-05-25 20:03 ` Linus Torvalds
2011-05-25 20:18 ` Parag Warudkar
2011-05-25 20:26 ` Linus Torvalds
2011-05-25 20:42 ` Parag Warudkar
2011-05-25 20:52 ` James Bottomley
2011-05-25 23:00 ` Parag Warudkar
2011-05-25 23:14 ` Linus Torvalds
2011-05-25 23:45 ` Parag Warudkar
2011-05-25 23:52 ` Linus Torvalds
[not found] ` <1306370123.1641.76.camel@mulgrave.site>
2011-05-26 1:01 ` Linus Torvalds
2011-05-26 1:06 ` James Bottomley
2011-05-26 1:43 ` Parag Warudkar
2011-05-27 3:53 ` James Bottomley
2011-05-27 5:43 ` Jens Axboe
2011-05-27 20:21 ` James Bottomley
2011-05-28 12:42 ` Jens Axboe
2011-06-08 6:50 ` Torsten Hilbrich
2011-05-25 20:20 ` James Bottomley
2011-05-25 20:22 ` Parag Warudkar
2011-05-25 20:29 ` James Bottomley
2011-05-25 20:26 ` __elv_add_request OOPS James Bottomley
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=alpine.DEB.2.02.1105251548420.2742@ubuntu-natty \
--to=parag.lkml@gmail.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=akpm@linux-foundation.org \
--cc=jaxboe@fusionio.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®