virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Christian Borntraeger <borntraeger@de.ibm.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	KVM list <kvm@vger.kernel.org>,
	dbueso@suse.de, Peter Zijlstra <peterz@infradead.org>,
	netdev <netdev@vger.kernel.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	virtualization@lists.linux-foundation.org,
	Paul McKenney <paulmck@linux.vnet.ibm.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Dmitry Vyukov <dvyukov@google.com>
Subject: Re: [PATCH 0/3] virtio/vringh: kill off ACCESS_ONCE()
Date: Fri, 25 Nov 2016 22:45:23 +0100	[thread overview]
Message-ID: <ed82912d-2ca7-d9f3-2e2f-40a4696241f1@de.ibm.com> (raw)
In-Reply-To: <20161125230735-mutt-send-email-mst@kernel.org>

On 11/25/2016 10:08 PM, Michael S. Tsirkin wrote:
> On Fri, Nov 25, 2016 at 05:49:45PM +0100, Christian Borntraeger wrote:
>> On 11/25/2016 05:17 PM, Peter Zijlstra wrote:
>>> On Fri, Nov 25, 2016 at 04:10:04PM +0000, Mark Rutland wrote:
>>>> On Fri, Nov 25, 2016 at 04:21:39PM +0100, Dmitry Vyukov wrote:
>>>
>>>>> What are use cases for such primitive that won't be OK with "read once
>>>>> _and_ atomically"?
>>>>
>>>> I have none to hand.
>>>
>>> Whatever triggers the __builtin_memcpy() paths, and even the size==8
>>> paths on 32bit.
>>>
>>> You could put a WARN in there to easily find them.
>>
>> There were several cases that I found during writing the *ONCE stuff.
>> For example there are some 32bit ppc variants with 64bit PTEs. Some for
>> others (I think sparc). And the mm/ code is perfectly fine with these
>> PTE accesses being done NOT atomic.
> 
> In that case do we even need _ONCE at all?

Yes. For example look at gup_pmd_range. Here several checks are made on the pmd.
It is important the the check for pmd_none is made on the same value than
the check for pmd_trans_huge, but it is not important that the value is still up
to date. 
And there are really cases where we cannot read the  thing atomically, e.g. on 
m68k and sparc(32bit) pmd_t is defined as array of longs.

Another problem is that a compiler can implement the following code as 2 memory
reads (e.g. if you have compare instructions that work on memory) instead of a 
memory read and 2 compares

int check(unsigned long *value_p) {
	unsigned long value = *value_p;
	if (condition_a(value))
		return 1;
	if (condition_b(value))
		return 2;
	return 3;
}

With READ_ONCE you forbid that. In past times you would have used barrier() after 
the assignment to achieve the same goal.


> Are there assumptions these are two 32 bit reads?

It depends on the code. Some places (e.g. in gup) assumes that the access via
READ_ONCE is atomic (which it is for sane compilers as long as the pointer
is <= word size). In some others places just one bit is tested.
> 
> 
>>
>>>
>>> The advantage of introducing the SINGLE_{LOAD,STORE}() helpers is that
>>> they compiletime validate this the size is 'right' and can runtime check
>>> alignment constraints.
>>>
>>> IE, they are strictly stronger than {READ,WRITE}_ONCE().
>>>
> 

  reply	other threads:[~2016-11-25 21:45 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1479983114-17190-1-git-send-email-mark.rutland@arm.com>
2016-11-24 10:25 ` [PATCH 1/3] tools/virtio: fix READ_ONCE() Mark Rutland
2016-11-24 10:25 ` [PATCH 2/3] vringh: kill off ACCESS_ONCE() Mark Rutland
2016-11-24 10:25 ` [PATCH 3/3] tools/virtio: use {READ,WRITE}_ONCE() in uaccess.h Mark Rutland
     [not found] ` <1479983114-17190-2-git-send-email-mark.rutland@arm.com>
2016-11-24 11:34   ` [PATCH 1/3] tools/virtio: fix READ_ONCE() Cornelia Huck
2016-11-25  2:38   ` Jason Wang
2016-11-24 20:36 ` [PATCH 0/3] virtio/vringh: kill off ACCESS_ONCE() Michael S. Tsirkin
2016-11-25 11:22   ` Mark Rutland
     [not found]   ` <20161125112203.GA26611@leverpostej>
2016-11-25 11:33     ` Christian Borntraeger
2016-11-25 12:23       ` Mark Rutland
     [not found]       ` <20161125122356.GB26611@leverpostej>
2016-11-25 12:40         ` Peter Zijlstra
2016-11-25 12:44           ` Peter Zijlstra
2016-11-25 14:56             ` Boqun Feng
2016-11-25 15:21               ` Dmitry Vyukov via Virtualization
     [not found]               ` <CACT4Y+ZpzFhmSqOG+dG7QHSNObWatLOjPjNK2BznnRLeRQpF8A@mail.gmail.com>
2016-11-25 16:10                 ` Mark Rutland
     [not found]                 ` <20161125161004.GA30181@leverpostej>
2016-11-25 16:17                   ` Peter Zijlstra
2016-11-25 16:32                     ` Mark Rutland
2016-11-25 16:49                     ` Christian Borntraeger
2016-11-25 17:28                       ` Mark Rutland
     [not found]                       ` <20161125172624.GA30811@leverpostej>
2016-11-25 17:42                         ` Peter Zijlstra
2016-11-25 18:46                         ` Christian Borntraeger
2016-11-25 21:08                       ` Michael S. Tsirkin
2016-11-25 21:45                         ` Christian Borntraeger [this message]
2016-11-25 17:28                     ` Dmitry Vyukov via Virtualization
     [not found]                     ` <CACT4Y+YJUUjU_FCR1FOcF2DmkkcjiRFpnU7Q4=yzbgvKv0VhyQ@mail.gmail.com>
2016-11-25 17:43                       ` Mark Rutland
2016-11-25 17:52                       ` Linus Torvalds
2016-11-25 18:07                         ` Mark Rutland
     [not found]                         ` <20161125180649.GC30811@leverpostej>
2016-11-25 18:47                           ` Linus Torvalds
2016-11-25 14:35           ` Mark Rutland
     [not found] ` <1479983114-17190-3-git-send-email-mark.rutland@arm.com>
2016-11-24 11:10   ` [PATCH 2/3] vringh: " Christian Borntraeger
2016-11-24 11:35   ` Cornelia Huck
2016-11-25  2:40   ` Jason Wang
     [not found] ` <1479983114-17190-4-git-send-email-mark.rutland@arm.com>
2016-11-24 11:37   ` [PATCH 3/3] tools/virtio: use {READ,WRITE}_ONCE() in uaccess.h Cornelia Huck
2016-11-25  2:40   ` Jason Wang
2016-11-24 10:25 [PATCH 0/3] virtio/vringh: kill off ACCESS_ONCE() Mark Rutland

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=ed82912d-2ca7-d9f3-2e2f-40a4696241f1@de.ibm.com \
    --to=borntraeger@de.ibm.com \
    --cc=boqun.feng@gmail.com \
    --cc=dave@stgolabs.net \
    --cc=dbueso@suse.de \
    --cc=dvyukov@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=virtualization@lists.linux-foundation.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).