From patchwork Mon Aug 5 19:21:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13753978 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDF3F143C6E; Mon, 5 Aug 2024 19:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722885682; cv=none; b=etHJ7ny2M1oLXSQK15mRc0sk/PymhAMdtSg5wzauAh90hkL55N9J2oXKO7P2Gy9N+3soKSfghKMhoYz979XsA3i1PGD7mLSQz9JaslVLZRjAgwr1JtuzoNe2MyQlx0WAHItR8+TDhCu/kmk8/CZbyJ7xYOwU2MJWHhuNbdQ4xas= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722885682; c=relaxed/simple; bh=SsfSYlvMJfbrFJhxWSLRoEWcjcncMnxVxwE9E1US2+0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=etEP9cbzgFTwfVsRtpxHvfFymJIH3htKu7PusLhoOpjOIt/lLOXSCk2i1KBJXjlqlPqw9EbApNOYi3lakbKKxdDet7sAglMUVVUV4i7P0XDnQYRWGxZ9Hu9bk1E0HMkc5Vj+aHuUqU35ggCvux/mz0hKrVMF2jp5OlGu9m1G6S4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZairQtTn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZairQtTn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C592C32782; Mon, 5 Aug 2024 19:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722885681; bh=SsfSYlvMJfbrFJhxWSLRoEWcjcncMnxVxwE9E1US2+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZairQtTnGfrM8IsiBq71qJecW1kAYKoiw1mpOCVFzhcp0z+L0X8x1VjPgRNexVi6f 8dNooCLXYg89HV1K9eqYdLHzBidYZwlAOEMNXFkTC7Op4DmGfpDSo5sQPUiEdQif2B oU0qTkenvvqwDkugiHSAdwpzafTmDvT1HKSZxk6Lc9+HOKS2LHmemDLh5aDTX6CbHL z2xTQm1U4txlS4aUH4Y8lBM3vLIpPNptvjafVM+s2ZBPqHl40cnEeKxs9r8ECBnY9F io31MjG/bZkCIt5+AXzgPRQvDlRAO8FsgyPApEDpo/2ET85G4DdXtKSkw08a4OlzIx s0Mj/Zrfo14tQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 49204CE0A6F; Mon, 5 Aug 2024 12:21:21 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, torvalds@linux-foundation.org, arnd@arndb.de, geert@linux-m68k.org, palmer@rivosinc.com, mhiramat@kernel.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, "Paul E. McKenney" , Yujie Liu , Andi Shyti Subject: [PATCH cmpxchg 1/3] xtensa: Emulate one-byte cmpxchg Date: Mon, 5 Aug 2024 12:21:17 -0700 Message-Id: <20240805192119.56816-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the new cmpxchg_emu_u8() to emulate one-byte cmpxchg() on xtensa. [ paulmck: Apply kernel test robot feedback. ] [ paulmck: Drop two-byte support per Arnd Bergmann feedback. ] [ Apply Geert Uytterhoeven feedback. ] Signed-off-by: Paul E. McKenney Tested-by: Yujie Liu Cc: Andi Shyti Cc: Geert Uytterhoeven Cc: Arnd Bergmann Cc: "Peter Zijlstra (Intel)" --- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/cmpxchg.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index f200a4ec044e6..d3db28f2f8110 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -14,6 +14,7 @@ config XTENSA select ARCH_HAS_DMA_SET_UNCACHED if MMU select ARCH_HAS_STRNCPY_FROM_USER if !KASAN select ARCH_HAS_STRNLEN_USER + select ARCH_NEED_CMPXCHG_1_EMU select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS diff --git a/arch/xtensa/include/asm/cmpxchg.h b/arch/xtensa/include/asm/cmpxchg.h index 675a11ea8de76..95e33a913962d 100644 --- a/arch/xtensa/include/asm/cmpxchg.h +++ b/arch/xtensa/include/asm/cmpxchg.h @@ -15,6 +15,7 @@ #include #include +#include /* * cmpxchg @@ -74,6 +75,7 @@ static __inline__ unsigned long __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) { switch (size) { + case 1: return cmpxchg_emu_u8(ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); default: __cmpxchg_called_with_bad_pointer(); return old; From patchwork Mon Aug 5 19:21:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13753977 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDEF7143879; Mon, 5 Aug 2024 19:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722885682; cv=none; b=U7rVVvcpOuPzj8yroSp7Ceg0WCVjs5XwzzK72OZDtsPm97Ye6VvhuSKiEjtsGF3LiftilDyK0nxL2visI8Q28Sllm79fvMkxEafShS2bMuQEU51zKO6WGiZllvY+YU6SsBxrPs+X3HmSaBDOi2lU68bsZMRtbEG01PL6K/rSDVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722885682; c=relaxed/simple; bh=m6rqAOBQ64nAVbwfoMwra9NFlfK4T5G41qjNyF62BxA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DYnL/T3gf44kAy6fdR1j0PyTvBQFXshby7u3Htvp/P2ae/NytqnGS8eAHdpoI6MkNI5ByfqqaXkB30DuR91HrXEj7CqavHLw0WNm+MFnPIzZiu0ZSvzdIM77Z79L6x7fuQaemQ00GNEI30RoGCY1TaFh1cFS76PzEMXT64fBjDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P9xw3M+j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P9xw3M+j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99CC4C4AF0C; Mon, 5 Aug 2024 19:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722885681; bh=m6rqAOBQ64nAVbwfoMwra9NFlfK4T5G41qjNyF62BxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P9xw3M+jZZKLkByOvsvujKOYcqIjvh1t7l+C55KVmDAuk0br3vgOiqQInvj1SWeKU kYgf0uWDIceGbQyl4L7Y/lp3v2FcfyW+dEm9H7MewGbPyS8CNJY/bKFOgdHM4P6RtU hckAHUe623ao0rG5MO5mKqLp/s/Fu/1WGqB7DN7UDHR8L6c3WehpQ6LwtIq4N/Zlr1 xJB0tNk5xFeAK9GInSAv/43+AV2UkZ0SD3CVSreMn1gzF8ybDc34ggxXpsEJ+YYsM4 a3Cu+RU7yrNU9AQRj64/3z3yuAzSETJtrVktLxVzDR2kSnAk5E5Lc6ap01ZUsLZYYi 9caRQD1IVhidQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 4E00FCE10D8; Mon, 5 Aug 2024 12:21:21 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, torvalds@linux-foundation.org, arnd@arndb.de, geert@linux-m68k.org, palmer@rivosinc.com, mhiramat@kernel.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, "Paul E. McKenney" , Vineet Gupta , Andi Shyti , Andrzej Hajda Subject: [PATCH cmpxchg 2/3] ARC: Emulate one-byte cmpxchg Date: Mon, 5 Aug 2024 12:21:18 -0700 Message-Id: <20240805192119.56816-2-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the new cmpxchg_emu_u8() to emulate one-byte cmpxchg() on arc. [ paulmck: Drop two-byte support per Arnd Bergmann feedback. ] [ paulmck: Apply feedback from Naresh Kamboju. ] [ paulmck: Apply kernel test robot feedback. ] Signed-off-by: Paul E. McKenney Cc: Vineet Gupta Cc: Andi Shyti Cc: Andrzej Hajda Cc: Arnd Bergmann Cc: Palmer Dabbelt Cc: Acked-by: Vineet Gupta --- arch/arc/Kconfig | 1 + arch/arc/include/asm/cmpxchg.h | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index fd0b0a0d4686a..163608fd49d18 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -13,6 +13,7 @@ config ARC select ARCH_HAS_SETUP_DMA_OPS select ARCH_HAS_SYNC_DMA_FOR_CPU select ARCH_HAS_SYNC_DMA_FOR_DEVICE + select ARCH_NEED_CMPXCHG_1_EMU select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC select ARCH_32BIT_OFF_T select BUILDTIME_TABLE_SORT diff --git a/arch/arc/include/asm/cmpxchg.h b/arch/arc/include/asm/cmpxchg.h index e138fde067dea..2102ce076f28b 100644 --- a/arch/arc/include/asm/cmpxchg.h +++ b/arch/arc/include/asm/cmpxchg.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -46,6 +47,9 @@ __typeof__(*(ptr)) _prev_; \ \ switch(sizeof((_p_))) { \ + case 1: \ + _prev_ = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)_p_, (uintptr_t)_o_, (uintptr_t)_n_); \ + break; \ case 4: \ _prev_ = __cmpxchg(_p_, _o_, _n_); \ break; \ @@ -65,16 +69,27 @@ __typeof__(*(ptr)) _prev_; \ unsigned long __flags; \ \ - BUILD_BUG_ON(sizeof(_p_) != 4); \ + switch(sizeof((_p_))) { \ + case 1: \ + __flags = cmpxchg_emu_u8((volatile u8 *)_p_, (uintptr_t)_o_, (uintptr_t)_n_); \ + _prev_ = (__typeof__(*(ptr)))__flags; \ + break; \ + break; \ + case 4: \ + /* \ + * spin lock/unlock provide the needed smp_mb() \ + * before/after \ + */ \ + atomic_ops_lock(__flags); \ + _prev_ = *_p_; \ + if (_prev_ == _o_) \ + *_p_ = _n_; \ + atomic_ops_unlock(__flags); \ + break; \ + default: \ + BUILD_BUG(); \ + } \ \ - /* \ - * spin lock/unlock provide the needed smp_mb() before/after \ - */ \ - atomic_ops_lock(__flags); \ - _prev_ = *_p_; \ - if (_prev_ == _o_) \ - *_p_ = _n_; \ - atomic_ops_unlock(__flags); \ _prev_; \ }) From patchwork Mon Aug 5 19:21:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 13753979 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FBDB15B147; Mon, 5 Aug 2024 19:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722885682; cv=none; b=IUmvpxaVF/2MhejuHTRivY22qgJZ3fSTktZQAB+hocxXB5KBhwoL0NH2dnC0u0JskmSx4FOwGVomInfF4QxGez3xC/r5dcgjIpkHCkYmYE8+hRxdI1B4/kzNkM5TIH/NAkDfRCMLtiTLIzRdVny0nolPg831FPvJXlJXlhBVcBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722885682; c=relaxed/simple; bh=rHLBTLGCozsc8ZYyoVtgXgyWtG7mLnt/2HwV6ku00sk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=t8mh2dJz5TEx+PVv4XNB0rF72kgt8E4YH8oDRngghesuIKz/P6yaOX9GhWtdAUailQ36btjhKqOUVzMfAFGJKhZdbuTeOaV2/eUd+czVZ4JEu9SjrsamKalR4trLsxIhpOVuLnPOhO4/z0EgQOc7cqj7jrVlwu8g+qbJEvgATaM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JeZmvV35; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JeZmvV35" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACF64C4AF0E; Mon, 5 Aug 2024 19:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722885681; bh=rHLBTLGCozsc8ZYyoVtgXgyWtG7mLnt/2HwV6ku00sk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JeZmvV35UmDfaPr6trM/HZwiyXgBBYiM79k8hwahfN7zysawZ9ZqeljXBeibBxhTW XmZ9krPGcFEJSs02cDDOTWMyZaSRF7znUDHVev751sJP0Gv5Td6hPaXpo+hdRa6EyB 5yuvlDFujJRFq97YX050Lb3StOqrAPuPbgKchfcTNY5az670n41g+A3MhzgD3p3TgV LSkTsnSq9XxjrehqV/uoL5inxzoPMRQsSfLRdZErvkfBpWnqKK/HFzqcgXxjreH/hs gShiXwGHYVqWM8a5NnGHyjoTrn6zX/ubBKFaYnIOFb9aYMfniRuOSfOnGj4/V90E4B JLUUqZiU5AaXg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 50378CE10F9; Mon, 5 Aug 2024 12:21:21 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Cc: elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, torvalds@linux-foundation.org, arnd@arndb.de, geert@linux-m68k.org, palmer@rivosinc.com, mhiramat@kernel.org, linux-sh@vger.kernel.org, linux-snps-arc@lists.infradead.org, "Paul E. McKenney" , Andi Shyti Subject: [PATCH cmpxchg 3/3] sh: Emulate one-byte cmpxchg Date: Mon, 5 Aug 2024 12:21:19 -0700 Message-Id: <20240805192119.56816-3-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the new cmpxchg_emu_u8() to emulate one-byte cmpxchg() on sh. [ paulmck: Drop two-byte support per Arnd Bergmann feedback. ] [ paulmck: Apply feedback from Naresh Kamboju. ] [ Apply Geert Uytterhoeven feedback. ] Signed-off-by: Paul E. McKenney Cc: Andi Shyti Cc: Palmer Dabbelt Cc: Masami Hiramatsu Cc: Arnd Bergmann Cc: Acked-by: John Paul Adrian Glaubitz --- arch/sh/Kconfig | 1 + arch/sh/include/asm/cmpxchg.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 1aa3c4a0c5b27..e9103998cca91 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -14,6 +14,7 @@ config SUPERH select ARCH_HIBERNATION_POSSIBLE if MMU select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_WANT_IPC_PARSE_VERSION + select ARCH_NEED_CMPXCHG_1_EMU select CPU_NO_EFFICIENT_FFS select DMA_DECLARE_COHERENT select GENERIC_ATOMIC64 diff --git a/arch/sh/include/asm/cmpxchg.h b/arch/sh/include/asm/cmpxchg.h index 5d617b3ef78f7..1e5dc5ccf7bf5 100644 --- a/arch/sh/include/asm/cmpxchg.h +++ b/arch/sh/include/asm/cmpxchg.h @@ -9,6 +9,7 @@ #include #include +#include #if defined(CONFIG_GUSA_RB) #include @@ -56,6 +57,8 @@ static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old, unsigned long new, int size) { switch (size) { + case 1: + return cmpxchg_emu_u8(ptr, old, new); case 4: return __cmpxchg_u32(ptr, old, new); }