Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755375AbcKYPXL (ORCPT ); Fri, 25 Nov 2016 10:23:11 -0500 Received: from mail-lf0-f48.google.com ([209.85.215.48]:35575 "EHLO mail-lf0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754930AbcKYPWQ (ORCPT ); Fri, 25 Nov 2016 10:22:16 -0500 MIME-Version: 1.0 In-Reply-To: <20161125145512.GA4014@Boquns-MacBook-Pro.local> References: <1479983114-17190-1-git-send-email-mark.rutland@arm.com> <20161124222357-mutt-send-email-mst@kernel.org> <20161125112203.GA26611@leverpostej> <32dfca07-59f3-b75a-3154-cf6b6c8538f0@de.ibm.com> <20161125122356.GB26611@leverpostej> <20161125124044.GN3092@twins.programming.kicks-ass.net> <20161125124404.GI3174@twins.programming.kicks-ass.net> <20161125145512.GA4014@Boquns-MacBook-Pro.local> From: Dmitry Vyukov Date: Fri, 25 Nov 2016 16:21:39 +0100 Message-ID: Subject: Re: [PATCH 0/3] virtio/vringh: kill off ACCESS_ONCE() To: Boqun Feng Cc: Peter Zijlstra , Mark Rutland , Christian Borntraeger , "Michael S. Tsirkin" , LKML , Davidlohr Bueso , dbueso@suse.de, jasowang@redhat.com, KVM list , netdev , Paul McKenney , virtualization@lists.linux-foundation.org, Linus Torvalds Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2243 Lines: 54 On Fri, Nov 25, 2016 at 3:56 PM, Boqun Feng wrote: > On Fri, Nov 25, 2016 at 01:44:04PM +0100, Peter Zijlstra wrote: >> On Fri, Nov 25, 2016 at 01:40:44PM +0100, Peter Zijlstra wrote: >> > #define SINGLE_LOAD(x) \ >> > {( \ >> > compiletime_assert_atomic_type(typeof(x)); \ >> >> Should be: >> >> compiletime_assert_atomic_type(x); >> >> > WARN_SINGLE_COPY_ALIGNMENT(&(x)); \ > > Do we need to worry about the side effect on x? Maybe > > #define SINGLE_LOAD(x) \ > ({ \ > typeof(x) *_____ptr; \ > \ > compiletime_assert_atomic_type(typeof(x)); \ > \ > _____ptr = &(x); \ > \ > WARN_SINGLE_COPY_ALIGNMENT(_____ptr); \ > \ > READ_ONCE(*_____ptr); \ > }) > > Ditto for SINGLE_STORE() > > Regards, > Boqun > >> > READ_ONCE(x); \ >> > }) >> > >> > #define SINGLE_STORE(x, v) \ >> > ({ \ >> > compiletime_assert_atomic_type(typeof(x)); \ >> >> idem >> >> > WARN_SINGLE_COPY_ALIGNMENT(&(x)); \ >> > WRITE_ONCE(x, v); \ >> > }) READ/WRITE_ONCE imply atomicity. Even if their names don't spell it (a function name doesn't have to spell all of its guarantees). Most of the uses of READ/WRITE_ONCE will be broken if they are not atomic. "Read once but not necessary atomically" is a very subtle primitive which is very easy to misuse. What are use cases for such primitive that won't be OK with "read once _and_ atomically"? Copy to/from user is obviously one such case, but it is already handled specially.