From: Oliver Neukum <oliver@neukum.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-kernel@vger.kernel.org
Subject: Re: question on read_barrier_depends
Date: Mon, 21 Apr 2014 11:40:59 +0200 [thread overview]
Message-ID: <1398073259.9256.3.camel@linux-fkkt.site> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1404161119490.1334-100000@iolanthe.rowland.org>
On Wed, 2014-04-16 at 11:26 -0400, Alan Stern wrote:
> On Wed, 16 Apr 2014, Oliver Neukum wrote:
>
> > Hi,
> >
> > I am looking at memory ordering and a question hit me.
> > I was looking at the kfifo code. kfifo_put() has a barrier:
> >
> > )[__kfifo->in & __tmp->kfifo.mask] = \
> > (typeof(*__tmp->type))__val; \
> > smp_wmb(); \
> > __kfifo->in++; \
> >
> > Looking at kfifo_get()
> >
> > __ret = !kfifo_is_empty(__tmp); \
> > if (__ret) { \
> > *(typeof(__tmp->type))__val = \
> > (__is_kfifo_ptr(__tmp) ? \
> >
> > A thought struck me. There is no corresponding barrier. I cannot
> > help myself, but I think there needs to be a smp_read_barrier_depends()
> > between reading kfifo->in (in kfifo_is empty) and reading val.
> > What do you think?
>
> I think you are right.
>
> In addition, the following code in kfifo_get() does this:
>
> *(typeof(__tmp->type))__val = \
> (__is_kfifo_ptr(__tmp) ? \
> ((typeof(__tmp->type))__kfifo->data) : \
> (__tmp->buf) \
> )[__kfifo->out & __tmp->kfifo.mask]; \
> smp_wmb(); \
> __kfifo->out++; \
>
> It looks like the smp_wmb() should really be smp_mb(), because it
> separates the _read_ for val from the _write_ of kfifo->out.
On the third hand, I now think wmb() is sufficient, because
there's also a write to __val. It does depend on the read
of buf[out & mask], but if no CPU does speculative writes
it must be correct.
Regards
Oliver
next prev parent reply other threads:[~2014-04-21 9:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-16 7:47 Oliver Neukum
2014-04-16 15:26 ` Alan Stern
2014-04-17 15:16 ` Oliver Neukum
2014-04-17 15:50 ` Alan Stern
2014-04-18 14:02 ` Oliver Neukum
2014-04-18 18:16 ` Alan Stern
2014-04-18 17:17 ` Oliver Neukum
2014-04-21 9:40 ` Oliver Neukum [this message]
2014-04-21 14:03 ` Alan Stern
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=1398073259.9256.3.camel@linux-fkkt.site \
--to=oliver@neukum.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stern@rowland.harvard.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 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®