linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: Elias Oltmanns <eo@nebensachen.de>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
	linux-scsi@vger.kernel.org
Subject: Re: [PATCH] SCSI: Fix some locking issues
Date: Thu, 3 Jul 2008 09:47:13 -0600	[thread overview]
Message-ID: <20080703154713.GF14894@parisc-linux.org> (raw)
In-Reply-To: <87abgz30h1.fsf@denkblock.local>

On Thu, Jul 03, 2008 at 09:12:26AM +0200, Elias Oltmanns wrote:
> Matthew Wilcox <matthew@wil.cx> wrote:
> > The assumption we make (and it is believed to be true on all SMP systems)
> > is that a write to a naturally aligned memory location that is sized <=
> > sizeof(long) is atomic.  That is, a reader will get either the previous
> > value or the subsequent value, not a mixture.  The RCU code relies
> > heavily on this assumption.
> 
> Does that mean that where ever I have
> 
> spin_lock_irqsave(some_lock, flags);
> var = some_val;
> spin_unlock_irqrestore(some_lock, flags);
> 
> I could just as well discard the locking provided that
> sizeof(var) <= sizeof(long)
> because the assignment of some_val to var will be atomic anyway?

You might need a barrier.

Also, I realised I mis-spoke above.  Early Alphas do not have instructions
that store byte or 16-bit sized quantities.  So the compiler implements
a byte store by loading a 32-bit quantity, replacing the appropriate 8
bits with the new value and storing the word back again.  The same is
true for most processors with, say, bit-sized quantities.  So while it's
atomic with respect to other _readers_, it's unsafe with respect to other
_writers_ in that if you have two modification attempts simultaneously,
you can end up with only one modification having taken place, not both.

eg:

CPU 0		CPU 1
load value
		load value
modify
		modify
store value
		store value

CPU 1 got the old value, and stored it over CPU 0's value.

CPUs which have instructions like cmpxchg can avoid these kinds of
problems, but not all do.  It's certainly not something that you can
make a blanket statement on; you really need to analyse it carefully.

-- 
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

  parent reply	other threads:[~2008-07-03 15:47 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-29 11:38 [PATCH] SCSI: Fix some locking issues Elias Oltmanns
2008-07-01 21:37 ` Elias Oltmanns
2008-07-02  1:55   ` James Bottomley
2008-07-02  7:08     ` Elias Oltmanns
2008-07-02 11:50       ` Jens Axboe
2008-07-02 14:49         ` James Bottomley
2008-07-02 18:45           ` Jens Axboe
2008-07-02 20:18             ` James Bottomley
2008-07-03  7:53               ` Elias Oltmanns
2008-07-03 10:38                 ` Elias Oltmanns
2008-07-03 11:24                   ` Jens Axboe
2008-07-03 16:31                     ` James Bottomley
2008-07-03 17:54                       ` Jens Axboe
2008-07-03 19:47                       ` Elias Oltmanns
2008-07-03 21:33                         ` James Bottomley
2008-07-02 14:46       ` James Bottomley
2008-07-02 15:59         ` Elias Oltmanns
2008-07-02 16:23           ` Matthew Wilcox
2008-07-03  7:12             ` Elias Oltmanns
2008-07-03 15:22               ` James Bottomley
2008-07-03 19:39                 ` Elias Oltmanns
2008-07-03 15:47               ` Matthew Wilcox [this message]
2008-07-02 16:32           ` James Bottomley
2008-07-03  7:25             ` Elias Oltmanns

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=20080703154713.GF14894@parisc-linux.org \
    --to=matthew@wil.cx \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=eo@nebensachen.de \
    --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).