mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: linux1394-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ieee1394: sbp2: fix race condition in state change
Date: Mon, 01 Dec 2008 20:52:50 +0100	[thread overview]
Message-ID: <49344092.9050908@s5r6.in-berlin.de> (raw)
In-Reply-To: <tkrat.b365b7fbc771f9d0@s5r6.in-berlin.de>

I wrote:
> An intermediate transition from _RUNNING to _IN_SHUTDOWN could have been
> missed by the former code.
> 
> Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
> ---
>  drivers/ieee1394/sbp2.c |    9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> Index: linux/drivers/ieee1394/sbp2.c
> ===================================================================
> --- linux.orig/drivers/ieee1394/sbp2.c
> +++ linux/drivers/ieee1394/sbp2.c
> @@ -895,12 +895,13 @@ static void sbp2_host_reset(struct hpsb_
>  		return;
>  
>  	read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
> +
>  	list_for_each_entry(lu, &hi->logical_units, lu_list)
> -		if (likely(atomic_read(&lu->state) !=
> -			   SBP2LU_STATE_IN_SHUTDOWN)) {
> -			atomic_set(&lu->state, SBP2LU_STATE_IN_RESET);
> +		if (atomic_cmpxchg(&lu->state,
> +				   SBP2LU_STATE_RUNNING, SBP2LU_STATE_IN_RESET)
> +		    == SBP2LU_STATE_RUNNING)
>  			scsi_block_requests(lu->shost);
> -		}
> +
>  	read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
>  }
>  

Still not entirely correct.  Maybe

		scsi_block_requests(lu->shost);
		if (atomic_cmpxchg(&lu->state,
				   SBP2LU_STATE_RUNNING,
				   SBP2LU_STATE_IN_RESET)
		    == SBP2LU_IN_SHUTDOWN)
			scsi_unblock_requests(lu->shost);

Does What I Mean.  Or I should just put a lock around all lu->state and
shost->host_self_blocked manipulations.
-- 
Stefan Richter
-=====-==--- ==-- ----=
http://arcgraph.de/sr/

      reply	other threads:[~2008-12-01 19:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-29 13:55 Stefan Richter
2008-12-01 19:52 ` Stefan Richter [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=49344092.9050908@s5r6.in-berlin.de \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux1394-devel@lists.sourceforge.net \
    /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®