From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754626AbaKYMi4 (ORCPT ); Tue, 25 Nov 2014 07:38:56 -0500 Received: from e06smtp13.uk.ibm.com ([195.75.94.109]:41432 "EHLO e06smtp13.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754122AbaKYMiq (ORCPT ); Tue, 25 Nov 2014 07:38:46 -0500 From: Christian Borntraeger To: linux-kernel@vger.kernel.org Cc: "linux-arch@vger.kernel.org, linux-mips@linux-mips.org, linux-x86_64@vger.kernel.org, linux-s390"@vger.kernel.org, Paolo Bonzini , paulmck@linux.vnet.ibm.com, mingo@kernel.org, torvalds@linux-foundation.org, Catalin Marinas , Will Deacon , Alexei Starovoitov , David Howells , Russell King , Christian Borntraeger Subject: [PATCHv2 09/10] tighten rules for ACCESS ONCE Date: Tue, 25 Nov 2014 13:38:36 +0100 Message-Id: <1416919117-50652-10-git-send-email-borntraeger@de.ibm.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1416919117-50652-1-git-send-email-borntraeger@de.ibm.com> References: <1416919117-50652-1-git-send-email-borntraeger@de.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14112512-0013-0000-0000-000001FADD3D Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that all non-scalar users of ACCESS_ONCE have been converted to READ_ONCE or ASSIGN once, lets tighten ACCESS_ONCE to only work on scalar types. This variant was proposed by Alexei Starovoitov. Signed-off-by: Christian Borntraeger --- include/linux/compiler.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 0ff01f2..7265a6c 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -411,8 +411,16 @@ static __always_inline void __read_once_size(volatile void *p, void *res, int si * merging, or refetching absolutely anything at any time. Its main intended * use is to mediate communication between process-level code and irq/NMI * handlers, all running on the same CPU. + * + * ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE + * on a union member will work as long as the size of the member matches the + * size of the union and the size is smaller than word size. + * If possible READ_ONCE/ASSIGN_ONCE should be used instead. */ -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) +#define __ACCESS_ONCE(x) ({ \ + __maybe_unused typeof(x) __var = 0; \ + (volatile typeof(x) *)&(x); }) +#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x)) /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */ #ifdef CONFIG_KPROBES -- 1.9.3