lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180126044231-mutt-send-email-mst@kernel.org>
Date:   Fri, 26 Jan 2018 04:44:12 +0200
From:   "Michael S. Tsirkin" <mst@...hat.com>
To:     Jason Wang <jasowang@...hat.com>
Cc:     linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
        John Fastabend <john.fastabend@...il.com>,
        David Miller <davem@...emloft.net>
Subject: Re: [PATCH net-next 03/12] ptr_ring: READ/WRITE_ONCE for
 __ptr_ring_empty

On Fri, Jan 26, 2018 at 10:37:58AM +0800, Jason Wang wrote:
> 
> 
> On 2018年01月26日 07:36, Michael S. Tsirkin wrote:
> > Lockless __ptr_ring_empty requires that consumer head is read and
> > written at once, atomically. Annotate accordingly to make sure compiler
> > does it correctly.  Switch locked callers to __ptr_ring_peek which does
> > not support the lockless operation.
> > 
> > Signed-off-by: Michael S. Tsirkin <mst@...hat.com>
> > ---
> >   include/linux/ptr_ring.h | 11 ++++++++---
> >   1 file changed, 8 insertions(+), 3 deletions(-)
> > 
> > diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
> > index 8594c7b..9a72d8f 100644
> > --- a/include/linux/ptr_ring.h
> > +++ b/include/linux/ptr_ring.h
> > @@ -196,7 +196,9 @@ static inline void *__ptr_ring_peek(struct ptr_ring *r)
> >    */
> >   static inline bool __ptr_ring_empty(struct ptr_ring *r)
> >   {
> > -	return !__ptr_ring_peek(r);
> > +	if (likely(r->size))
> > +		return !r->queue[READ_ONCE(r->consumer_head)];
> > +	return true;
> >   }
> 
> So after patch 8, __ptr_ring_peek() did:
> 
> static inline void *__ptr_ring_peek(struct ptr_ring *r)
> {
>     if (likely(r->size))
>         return READ_ONCE(r->queue[r->consumer_head]);
>     return NULL;
> }
> 
> Looks like a duplication.
> 
> Thanks

Nope - they are different.

The reason is that __ptr_ring_peek does not need to read the consumer_head once
since callers have a lock, and __ptr_ring_empty does not need to read
the queue once since it merely compares it to 0.

-- 
MST

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ