linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: "Jörn Engel" <joern@logfs.org>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH 06/10] sg: prevent unwoken sleep
Date: Wed, 16 May 2012 17:57:40 -0400	[thread overview]
Message-ID: <4FB422D4.2030406@interlog.com> (raw)
In-Reply-To: <20120412213358.GF17388@logfs.org>

On 12-04-12 05:33 PM, Jörn Engel wrote:
> srp->done is protected by sfp->rq_list_lock everywhere, except for this
> one case.  Result can be that the wake-up happens before the cacheline
> with the changed srp->done has arrived, so the waiter can go back to
> sleep and never be woken up again.
>
> The wait_event_interruptible() means that anyone trying to debug this
> unlikely race will likely notice everything working fine again, as the
> next signal will unwedge things.  Evil.
>
> Signed-off-by: Joern Engel<joern@logfs.org>

Acked-by: Douglas Gilbert <dgilbert@interlog.com>

> ---
>   drivers/scsi/sg.c |   16 ++++++++++++++--
>   1 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index ba657a9..758e7b4 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -137,7 +137,8 @@ typedef struct sg_request {	/* SG_MAX_QUEUE requests outstanding per file */
>   	char res_used;		/* 1 ->  using reserve buffer, 0 ->  not ... */
>   	char orphan;		/* 1 ->  drop on sight, 0 ->  normal */
>   	char sg_io_owned;	/* 1 ->  packet belongs to SG_IO */
> -	volatile char done;	/* 0->before bh, 1->before read, 2->read */
> +	/* done protected by rq_list_lock */
> +	char done;		/* 0->before bh, 1->before read, 2->read */
>   	struct request *rq;
>   	struct bio *bio;
>   	struct execute_work ew;
> @@ -760,6 +761,17 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp,
>   	return 0;
>   }
>
> +static int srp_done(Sg_fd *sfp, Sg_request *srp)
> +{
> +	unsigned long flags;
> +	int ret;
> +
> +	read_lock_irqsave(&sfp->rq_list_lock, flags);
> +	ret = srp->done;
> +	read_unlock_irqrestore(&sfp->rq_list_lock, flags);
> +	return ret;
> +}
> +
>   static int
>   sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
>   {
> @@ -791,7 +803,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
>   		if (result<  0)
>   			return result;
>   		result = wait_event_interruptible(sfp->read_wait,
> -			(srp->done || sdp->detached));
> +			(srp_done(sfp, srp) || sdp->detached));
>   		if (sdp->detached)
>   			return -ENODEV;
>   		write_lock_irq(&sfp->rq_list_lock);

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2012-05-16 21:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-12 21:32 [PATCH 01/10] sg: remove unnecessary indentation Jörn Engel
2012-04-12 21:32 ` [PATCH 02/10] sg: remove while (1) non-loop Jörn Engel
2012-05-16 21:57   ` Douglas Gilbert
2012-04-12 21:33 ` [PATCH 03/10] " Jörn Engel
2012-05-16 21:57   ` Douglas Gilbert
2012-04-12 21:33 ` [PATCH 04/10] sg: use wait_event_interruptible() Jörn Engel
2012-05-16 21:57   ` Douglas Gilbert
2012-04-12 21:33 ` [PATCH 05/10] sg: remove closed flag Jörn Engel
2012-05-16 21:57   ` Douglas Gilbert
2012-04-12 21:33 ` [PATCH 06/10] sg: prevent unwoken sleep Jörn Engel
2012-05-16 21:57   ` Douglas Gilbert [this message]
2012-04-12 21:34 ` [PATCH 07/10] sg: protect sdp->exclude Jörn Engel
2012-04-23 22:13   ` Douglas Gilbert
2012-04-24 20:13     ` [PATCH v2 " Jörn Engel
2012-05-16 21:57       ` Douglas Gilbert
2012-04-24 20:16     ` [PATCH " Jörn Engel
2012-04-12 21:34 ` [PATCH 08/10] sg: completely protect sfds Jörn Engel
2012-04-25 15:17   ` [PATCH v2 " Jörn Engel
2012-05-16 21:57     ` Douglas Gilbert
2012-04-12 21:35 ` [PATCH 09/10] sg: remove sg_mutex Jörn Engel
2012-05-16 21:57   ` Douglas Gilbert
2012-04-12 21:35 ` [PATCH 10/10] sg: constify sg_proc_leaf_arr Jörn Engel
2012-05-16 21:58   ` Douglas Gilbert
2012-05-07 19:44 ` [PATCH 01/10] sg: remove unnecessary indentation Jörn Engel
2012-05-11 14:43   ` Jörn Engel
2012-05-16 21:57 ` Douglas Gilbert

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=4FB422D4.2030406@interlog.com \
    --to=dgilbert@interlog.com \
    --cc=JBottomley@parallels.com \
    --cc=joern@logfs.org \
    --cc=linux-scsi@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).