Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2427338pxj; Mon, 10 May 2021 02:42:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEdCXRR4tttgBiVcGoWM/mgINnl1crGwN4VQlVoA5PMBrFAMTBtGBINCvazLXJSHElwBtm X-Received: by 2002:a92:dc92:: with SMTP id c18mr20788606iln.252.1620639731185; Mon, 10 May 2021 02:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620639731; cv=none; d=google.com; s=arc-20160816; b=y4KxceRxXKmlCIvMXp8PAaQGkFmrhl/IG81Zxas4GRAX3iyOCv6hRc1gHKGlPdTLht TvjShBAHssPqQXFW7c/CoDbiplDQFY48dWfRvIAhjA8sqOs9tYSpld6E40poHuBcGT6q HV51hjJ5RC6ughPMgAK9WP0vLCDEr9PajvLWd3eCFnUKTx/XOZE8xxbOMpKIXCig/EwY h2UrF3oyj5BGFFDMI+tY4QHWRPcamZL6dOkaBP7ss+LKKsffOYSGe5JP0thLQ8BM+I3K dmy1mTp2O3NtxES9QjTPDHRwa8vDiF2SlPa7IGh36M1u9CYqQZ4+j4kiTBUu9XlGDp3C m9tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=0J/7WqOruRfhwVPvrABB4skd7+ce2pZqv9x2vxJhOWk=; b=ToN+1MQ5eOgIr0w4Kqjfw5umE5HeiNBYfg9jxh6oNbeq9ohTQcYHfbvt+SHc0rxO0Z TkZxEaIUZNCScJk8QfiJqb/daORv0TastL6zTDmP8gjG5O/dlAvngD+SQk2MyQ/KE7dQ fdJR6CZqxPDsahqBvhdd0GAGSl86sa1DVNFKRN96i+1UyYniS7i15FgGOHZULHb47C15 PqWu8Z+O0GhsksKJtWhtMCw/rKZtzx+lXQv+ohvoUPIMsbvcgJOHN2JLe6nDlBEME+lh CYY4rydX6nRF6V0wM0OHLSTBUEE1H6nQDYa2wb6uqGqKNXYQbobtFLE2sYc1adGhui49 IPVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si15674778ilm.57.2021.05.10.02.41.59; Mon, 10 May 2021 02:42:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230426AbhEJJl5 (ORCPT + 99 others); Mon, 10 May 2021 05:41:57 -0400 Received: from foss.arm.com ([217.140.110.172]:51108 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbhEJJl4 (ORCPT ); Mon, 10 May 2021 05:41:56 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 61E151509; Mon, 10 May 2021 02:40:52 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 381F03F73B; Mon, 10 May 2021 02:40:48 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org, will@kernel.org, boqun.feng@gmail.com, peterz@infradead.org Cc: aou@eecs.berkeley.edu, arnd@arndb.de, bcain@codeaurora.org, benh@kernel.crashing.org, chris@zankel.net, dalias@libc.org, davem@davemloft.net, deanbo422@gmail.com, deller@gmx.de, geert@linux-m68k.org, green.hu@gmail.com, guoren@kernel.org, ink@jurassic.park.msu.ru, James.Bottomley@HansenPartnership.com, jcmvbkbc@gmail.com, jonas@southpole.se, ley.foon.tan@intel.com, linux@armlinux.org.uk, mark.rutland@arm.com, mattst88@gmail.com, monstr@monstr.eu, mpe@ellerman.id.au, nickhu@andestech.com, palmer@dabbelt.com, paulus@samba.org, paul.walmsley@sifive.com, rth@twiddle.net, shorne@gmail.com, stefan.kristiansson@saunalahti.fi, tsbogend@alpha.franken.de, vgupta@synopsys.com, ysato@users.sourceforge.jp Subject: [PATCH 12/33] locking/atomic: cmpxchg: support ARCH_ATOMIC Date: Mon, 10 May 2021 10:37:32 +0100 Message-Id: <20210510093753.40683-13-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210510093753.40683-1-mark.rutland@arm.com> References: <20210510093753.40683-1-mark.rutland@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We'd like all architectures to convert to ARCH_ATOMIC, as this will enable functionality, and once all architectures are converted it will be possible to make significant cleanups to the atomic headers. A number of architectures use asm-generic/cmpxchg.h or asm-generic/cmpxhg-local.h, and it's impractical to convert the headers and all these architectures in one go. To make it possible to convert them one-by-one, let's make the asm-generic implementation function as either cmpxchg*() or arch_cmpxchg*() depending on whether ARCH_ATOMIC is selected. To do this, the generic implementations are prefixed as generic_cmpxchg_*(), and preprocessor definitions map cmpxchg_*()/arch_cmpxchg_*() onto these as appropriate. Once all users are moved over to ARCH_ATOMIC the ifdeffery in the header can be simplified and/or removed entirely. For existing users (none of which select ARCH_ATOMIC), there should be no functional change as a result of this patch. Signed-off-by: Mark Rutland Cc: Arnd Bergmann Cc: Boqun Feng Cc: Peter Zijlstra Cc: Will Deacon --- include/asm-generic/cmpxchg.h | 61 +++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/include/asm-generic/cmpxchg.h b/include/asm-generic/cmpxchg.h index b9d54c7afc52..98c931199089 100644 --- a/include/asm-generic/cmpxchg.h +++ b/include/asm-generic/cmpxchg.h @@ -14,16 +14,14 @@ #include #include -#ifndef xchg - /* * This function doesn't exist, so you'll get a linker error if * something tries to do an invalidly-sized xchg(). */ -extern void __xchg_called_with_bad_pointer(void); +extern void __generic_xchg_called_with_bad_pointer(void); static inline -unsigned long __xchg(unsigned long x, volatile void *ptr, int size) +unsigned long __generic_xchg(unsigned long x, volatile void *ptr, int size) { unsigned long ret, flags; @@ -75,35 +73,64 @@ unsigned long __xchg(unsigned long x, volatile void *ptr, int size) #endif /* CONFIG_64BIT */ default: - __xchg_called_with_bad_pointer(); + __generic_xchg_called_with_bad_pointer(); return x; } } -#define xchg(ptr, x) ({ \ - ((__typeof__(*(ptr))) \ - __xchg((unsigned long)(x), (ptr), sizeof(*(ptr)))); \ +#define generic_xchg(ptr, x) ({ \ + ((__typeof__(*(ptr))) \ + __generic_xchg((unsigned long)(x), (ptr), sizeof(*(ptr)))); \ }) -#endif /* xchg */ - /* * Atomic compare and exchange. */ #include -#ifndef cmpxchg_local -#define cmpxchg_local(ptr, o, n) ({ \ - ((__typeof__(*(ptr)))__generic_cmpxchg_local((ptr), (unsigned long)(o),\ - (unsigned long)(n), sizeof(*(ptr)))); \ +#define generic_cmpxchg_local(ptr, o, n) ({ \ + ((__typeof__(*(ptr)))__generic_cmpxchg_local((ptr), (unsigned long)(o), \ + (unsigned long)(n), sizeof(*(ptr)))); \ }) + +#define generic_cmpxchg64_local(ptr, o, n) \ + __generic_cmpxchg64_local((ptr), (o), (n)) + + +#ifdef CONFIG_ARCH_ATOMIC + +#ifndef arch_xchg +#define arch_xchg generic_xchg +#endif + +#ifndef arch_cmpxchg_local +#define arch_cmpxchg_local generic_cmpxchg_local +#endif + +#ifndef arch_cmpxchg64_local +#define arch_cmpxchg64_local generic_cmpxchg64_local +#endif + +#define arch_cmpxchg arch_cmpxchg_local +#define arch_cmpxchg64 arch_cmpxchg64_local + +#else /* CONFIG_ARCH_ATOMIC */ + +#ifndef xchg +#define xchg generic_xchg +#endif + +#ifndef cmpxchg_local +#define cmpxchg_local generic_cmpxchg_local #endif #ifndef cmpxchg64_local -#define cmpxchg64_local(ptr, o, n) __generic_cmpxchg64_local((ptr), (o), (n)) +#define cmpxchg64_local generic_cmpxchg64_local #endif -#define cmpxchg(ptr, o, n) cmpxchg_local((ptr), (o), (n)) -#define cmpxchg64(ptr, o, n) cmpxchg64_local((ptr), (o), (n)) +#define cmpxchg cmpxchg_local +#define cmpxchg64 cmpxchg64_local + +#endif /* CONFIG_ARCH_ATOMIC */ #endif /* __ASM_GENERIC_CMPXCHG_H */ -- 2.11.0