From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: Matthew Wilcox <matthew@wil.cx>
Cc: Mike Christie <michaelc@cs.wisc.edu>,
SCSI Mailing List <linux-scsi@vger.kernel.org>
Subject: Re: possible scsi driver bugs with atomic_set/atomic_read and missing barrier
Date: Wed, 11 Mar 2009 10:36:55 +0100 [thread overview]
Message-ID: <49B78637.1080102@s5r6.in-berlin.de> (raw)
In-Reply-To: <20090311033927.GB25995@parisc-linux.org>
Matthew Wilcox wrote:
> On Tue, Mar 10, 2009 at 10:25:44PM -0500, Mike Christie wrote:
>> atomic_set(&hba->state, SOME_STATE_VALUE);
>>
>> in a interrupt or thread or tasklet then in another thread they will do
>>
>> if (atomic_read(&hba->state) == SOME_STATE_VALUE))
>>
>> Does this mean that the drivers should be doing a
>>
>> atomic_set(&hba->state, SOME_STATE_VALUE);
>> smp_mb();
>
> Possibly "smp_mb__after_atomic_inc()" might be correct.
Is this guaranteed to work with anything else than atomic_inc?
Mike,
it's also important to remember that barriers will be needed at the
reader place too (/if/ there actually are ordering requirements, that is).
E.g. in the writer:
atomic_set(&hba->x, new_x);
smp_wmb();
hba->y = new_y;
And in the reader:
y = hba->y;
smp_rmb();
x = atomic_read(&hba->x);
do_something(x, y);
You would do this if you have a requirement that a reader needs 'x' to
always be at least as new as 'y', IOW would work incorrectly if an
outdated x would be used together with a current y.
This only works though if the reader can safely operate on an outdated
'y' + a current 'x'. If neither current x + old y nor old x + current y
can be safely combined, then you need to wrap their write and read
accesses into lock- or mutex- protected sections.
--
Stefan Richter
-=====-==--= --== -=-==
http://arcgraph.de/sr/
next prev parent reply other threads:[~2009-03-11 9:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-11 3:25 possible scsi driver bugs with atomic_set/atomic_read and missing barrier Mike Christie
2009-03-11 3:39 ` Matthew Wilcox
2009-03-11 9:36 ` Stefan Richter [this message]
2009-03-11 8:45 ` Stefan Richter
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=49B78637.1080102@s5r6.in-berlin.de \
--to=stefanr@s5r6.in-berlin.de \
--cc=linux-scsi@vger.kernel.org \
--cc=matthew@wil.cx \
--cc=michaelc@cs.wisc.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.