Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp936523lqo; Fri, 10 May 2024 23:50:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVfRvOB0CPoWSfmrWW0z5CEff5BQg3kfwyvc8Cxdx2Eu2gZcK+6Nec83RuhcL2JlGd2Rq/LX0Kjz5J/vMycX2BR5mnZ0MWF/wtz2fH3LQ== X-Google-Smtp-Source: AGHT+IH5+FRy8Dqhn3LgQnyKjJ8qSuS7dR31DeH9ahmNFoviEwhkqBSEnq0q25v7eGdLFNkb58Og X-Received: by 2002:a17:903:1251:b0:1eb:d7bd:c0d0 with SMTP id d9443c01a7336-1ef44050658mr54811635ad.60.1715410233398; Fri, 10 May 2024 23:50:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715410233; cv=pass; d=google.com; s=arc-20160816; b=atEUNeY8uckMXdk/ASiT74hKMqD0wQwjYFgF6IKmj4kuhRxfKHybEUYt6kILpCLnbP KeNP/89k/l7p3lDWaoHhosWHFbTqvWZe2PyGC2vKn7MCKztm0LILWXIugimT5tj2vsvm IIKKtett+InkjRJSlvtm4znCnj3Fm3g1dg9jSAFLpP0t70Zv/qAMC5jrIrykS2oWW/lD OVIqq/pn+dqVM9ssF0odBKi6crOMHUZfvL0xB8xWncylwWqL9LMnvmD3DKq2eiAb/ycA IdzCESfl6J9QSQvaTWrcnZRyhK/O2rttuS/GhayL9ftmgGnMyRaqF4L09/5NUP6tFiOf zvSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QX06jhcqClac0lstgEiOruGm6Gc0b6k9oxhov34rI8k=; fh=eU7tjpcxyz2AGD6LNrrlygi8zXt0rwkMcvEXus6PASI=; b=A57hktO8HtXz5BX8KGlPHnHNVBWTIqFjstunQ7CdnQEMVuGo4PMfswGNSsUcq0b18Z v4d6rXWaUsuwE+wYLLRz+zjJB5heiY5Z6qa3wSfzuAVV+xVt4d8tYsud55u1HvGs2BEt uw/szjh7WVckFsiCYCh+u0fnOVbXS7gw77O8j3s7nYlOT0cEvhL5K2O5ATNZJWD+zOTC LxgLNpXEhavLpy4FSwGFkgLVkImwNOprpxee2JMib2bhc+07JpYpQ3wjcfnyjE8n3KtU V3AlndiFjoAt9USwSq4i8kaxGiGZivx/JoPjYT20Y4Hp7jkRS5YN8bAidyhMlcIL2b0B IxRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IGkVoDnU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176439-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176439-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0b9cf1f8si54724725ad.36.2024.05.10.23.50.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 23:50:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176439-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IGkVoDnU; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176439-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176439-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 3570BB224DE for ; Sat, 11 May 2024 06:50:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6CC6E4C66; Sat, 11 May 2024 06:50:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IGkVoDnU" 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 8B388A55 for ; Sat, 11 May 2024 06:50:19 +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=1715410219; cv=none; b=H6xccpi6riu4CD6CG7aR3t9aSQ2OSu1BbjoSN91aNWcTN9XjsLDub/uaMpR9kwEEYp96FqlpdkeNVHEYGszA1mpq9br29gYXSQvKhD9PwWtZ84Y6OvVSRgkR8MPLD8vhAzLdTpLVLXBEttwhDW1rtbIY4OrW5nPZ68CbX1g7PZo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715410219; c=relaxed/simple; bh=lblVBvZuddzuH51cR8bOvxbCQSkyGJaGFeuYszSiyVI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kZaPrPTTpwj3qlpHh6SMyuXplx5Hz67eFRd3AssXVPkBga4iusei5nzbgMSue70u9y0XWUeIkoOYm6rfYVH9eoyNq/LSTtO8otPGPiMc9I6Q+fAcI2SnQR/PNvMwGrNLogWW8Wb7Bm98DS0qPgZtBhIJV0Gtb3jf65eEycmIaCg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IGkVoDnU; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 270FEC2BD10; Sat, 11 May 2024 06:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715410219; bh=lblVBvZuddzuH51cR8bOvxbCQSkyGJaGFeuYszSiyVI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IGkVoDnUyxFEG56w7+HuB2jpgmBVaJMMe6Fv4rXtMdyTjoVePK7lwdsQN6/yRI4zC fF4GtCGRoWEI/y6eom0/Wx6eUsQj02VA/s2biezFods6BpGUs3nhJn8hghTDmbwNyx LI5kuaTCMtvLNluAbzC/eXJQ+BZlLiN2xA6BN0NeHkJWQZuJEwlDqqVELHU0Yo84nR mH0ezWfY9CbT7B88ziN7GTsrLuyIc3kZSBaAfKUvy9oJKWFJvxcae0sh+qXNshrPJB 3sZ7Q/YFs+qD2RCS0xMjl2sTQMbMj+7st0WeeiDdKyGVu+CElQu48tpS9lXWUY4ioY gMMhUwb5yMsSQ== Date: Sat, 11 May 2024 02:50:13 -0400 From: Guo Ren To: Leonardo Bras Cc: paulmck@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, andi.shyti@linux.intel.com, andrzej.hajda@intel.com, linux-riscv@lists.infradead.org, palmer@dabbelt.com Subject: Re: [PATCH RFC cmpxchg 8/8] riscv: Emulate one-byte and two-byte cmpxchg Message-ID: References: <20240401213950.3910531-8-paulmck@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Apr 04, 2024 at 07:15:40AM -0700, Palmer Dabbelt wrote: > On Mon, 01 Apr 2024 14:39:50 PDT (-0700), paulmck@kernel.org wrote: > > Use the new cmpxchg_emu_u8() and cmpxchg_emu_u16() to emulate one-byte > > and two-byte cmpxchg() on riscv. > > > > [ paulmck: Apply kernel test robot feedback. ] > > I'm not entirely following the thread, but sounds like there's going to be > generic kernel users of this now? Before we'd said "no" to the byte/half > atomic emulation routines beacuse they weren't used, but if it's a generic > thing then I'm find adding them. > > There's a patch set over here > > that implements these more directly using LR/SC. I was sort of on the fence > about just taking it even with no direct users right now, as the byte/half > atomic extension is working its way through the spec process so we'll have > them for real soon. I stopped right there for the last merge window, > though, as I figured it was too late to be messing with the atomics... > > So > > Acked-by: Palmer Dabbelt F.Y.I Leonardo Bras > > if you guys want to take some sort of tree-wide change to make the byte/half > stuff be required everywhere. We'll eventually end up with arch routines > for the extension, so at that point we might as well also have the more > direct LR/SC flavors. > > If you want I can go review/merge that RISC-V patch set and then it'll have > time to bake for a shared tag you can pick up for all this stuff? No rush > on my end, just LMK. > > > Signed-off-by: Paul E. McKenney > > Cc: Andi Shyti > > Cc: Andrzej Hajda > > Cc: > > --- > > arch/riscv/Kconfig | 1 + > > arch/riscv/include/asm/cmpxchg.h | 25 +++++++++++++++++++++++++ > > 2 files changed, 26 insertions(+) > > > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > > index be09c8836d56b..4eaf40d0a52ec 100644 > > --- a/arch/riscv/Kconfig > > +++ b/arch/riscv/Kconfig > > @@ -44,6 +44,7 @@ config RISCV > > select ARCH_HAS_UBSAN > > select ARCH_HAS_VDSO_DATA > > select ARCH_KEEP_MEMBLOCK if ACPI > > + select ARCH_NEED_CMPXCHG_1_2_EMU > > select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX > > select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT > > select ARCH_STACKWALK > > diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h > > index 2fee65cc84432..a5b377481785c 100644 > > --- a/arch/riscv/include/asm/cmpxchg.h > > +++ b/arch/riscv/include/asm/cmpxchg.h > > @@ -9,6 +9,7 @@ > > #include > > > > #include > > +#include > > > > #define __xchg_relaxed(ptr, new, size) \ > > ({ \ > > @@ -170,6 +171,12 @@ > > __typeof__(*(ptr)) __ret; \ > > register unsigned int __rc; \ > > switch (size) { \ > > + case 1: \ > > + __ret = cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ > > + break; \ > > + case 2: \ > > + break; \ > > + __ret = cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ > > case 4: \ > > __asm__ __volatile__ ( \ > > "0: lr.w %0, %2\n" \ > > @@ -214,6 +221,12 @@ > > __typeof__(*(ptr)) __ret; \ > > register unsigned int __rc; \ > > switch (size) { \ > > + case 1: \ > > + __ret = cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ > > + break; \ > > + case 2: \ > > + break; \ > > + __ret = cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ > > case 4: \ > > __asm__ __volatile__ ( \ > > "0: lr.w %0, %2\n" \ > > @@ -260,6 +273,12 @@ > > __typeof__(*(ptr)) __ret; \ > > register unsigned int __rc; \ > > switch (size) { \ > > + case 1: \ > > + __ret = cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ > > + break; \ > > + case 2: \ > > + break; \ > > + __ret = cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ > > case 4: \ > > __asm__ __volatile__ ( \ > > RISCV_RELEASE_BARRIER \ > > @@ -306,6 +325,12 @@ > > __typeof__(*(ptr)) __ret; \ > > register unsigned int __rc; \ > > switch (size) { \ > > + case 1: \ > > + __ret = cmpxchg_emu_u8((volatile u8 *)__ptr, __old, __new); \ > > + break; \ > > + case 2: \ > > + break; \ > > + __ret = cmpxchg_emu_u16((volatile u16 *)__ptr, __old, __new); \ > > case 4: \ > > __asm__ __volatile__ ( \ > > "0: lr.w %0, %2\n" \ >