Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1112057lqo; Sat, 11 May 2024 07:54:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXTtz6uyYP7nlkxtc4iTm6nmIBKw7NHz/THnCPFhepmCJ7eVXWM5NsaleW6W3i/uuYmu8y6djrWFw/lGom6kaugczzkbhaRWvDVcvrVsg== X-Google-Smtp-Source: AGHT+IFNcKtIixhXN1yj4DjUmKTHKyEKq5ur3eM6QbIlKm2RazyBtGMkmWAqnYC9a8/AbL+ZIbiI X-Received: by 2002:a17:906:2bc6:b0:a59:c090:7781 with SMTP id a640c23a62f3a-a5a2d55a8d2mr376667466b.3.1715439288794; Sat, 11 May 2024 07:54:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715439288; cv=pass; d=google.com; s=arc-20160816; b=yWlhYKIlBkQb8iu0SbiJCBbNb44IESY9PH21/vvNBz+Rq+Ok0vgbEACI3Wjow+tEYe MyR/F9VgcKq3SnBIyGP3PsQ1tZ/hkNbigeBrQoYUM8GjWVGrm4y0p0TsfmMdUUMZEBYc TH1EkMiUXgRMPfNYFX5EjKSI/6Tbbe6w0IPT+U4HijnUcjf4A6xGTz3fGLDc6YpwMkzl P1gO9jUIQJ1mk+NG3Lqkb2HCKE8fkQmzCIPi4YfRYQQ5lPwXiHie0RL7pFxG9NPAdr04 phdr+g+w6YfmPaA7cM3KmHvttRqTXKbSy0l1csJk1FTIdGq8svUJKibPghq2CzfIHzOX A73g== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=i8DWagfyUSJZ0q2ALfAXPn6vR1kwhLVMTi9odB0f53E=; fh=Ov4mVVt36ysR2YXTyUT5HifAlQkRfO4RK+uedzbAnrk=; b=XpeAO+8jjBnqI5BczjHFtiP2W5vzkTdONzweGSJnVUwPxPr5OzKCANT2ZaeUALpEvu LKQUMm4AOM6pt9ZdSGfvRyNcUUfHEgmLP+feM82H6Im89LRaIEfS+pU/W66tSDVGmrmr MboopzDsGJIs34zld41Nxz63nwf1RHi1ktma4m00DRmY7jfzYZgED/xKDzmxTDGJyRNv 6mR1XX+TKPKf+LxgU2uHh3vSgCD7JFeueAipmpaGVWOMmgQfOfc63WSNfrgBpwcSdL/4 bffy4TMIFa/SSi6r7xAZNDueeHHJrFyFdndqrrp+8ZpPr31jaMcxV6s7pFnBHaUZO5Oa j77Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZurLr3OX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176589-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176589-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17b4c589si340788466b.387.2024.05.11.07.54.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 May 2024 07:54:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176589-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZurLr3OX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176589-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176589-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5DACE1F2175A for ; Sat, 11 May 2024 14:54:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D1F75674C; Sat, 11 May 2024 14:54:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZurLr3OX" 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 3FB2856446 for ; Sat, 11 May 2024 14:54:34 +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=1715439275; cv=none; b=qI49qvj1P/J55Sh8zkRUXr4fd3FQGUhUmQTbUra3PakZjrfiLxbRlhYDsirG0NfjpnVf19/4aNuhtEyuwvdPnBgX+tH38qJI5cYAMpDWjPNq7BMJTC21NQjOI/AyMjY0Y4tr7MosGXHtzXT8Ya28OawRqm6hJ+N1qt7D9jo70bo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715439275; c=relaxed/simple; bh=rubNTKa3Iwun2UymZEiP0WYCh3XNAOyMB5tCLTlUEFI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lwfp8FyGuqOleCNJNJRyq9r0cgP9xzSkZoQu2cXiIXs+bM+fvU06G8ZE/2czHIGRKGMTUKAkWPoi7y5GFLfr0U9xadIfRmZdoI4Siy3JvJi4aSEMu2j6df5kUXIv8SOSEk7EG9/JaQTTXbeq5nEkblcOsXt48+AWHFP7skBmu4w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZurLr3OX; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B401FC2BBFC; Sat, 11 May 2024 14:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715439274; bh=rubNTKa3Iwun2UymZEiP0WYCh3XNAOyMB5tCLTlUEFI=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=ZurLr3OXzHvnrGXTC0m0EjbLQcWxLY8Sd8TfY83aiW61ZZyjC3/e9a5GbfnLII4JF FCKllJgagsqPk15iOK2VWkzCZmj3LgADqytPr/xUK+PLOmy9LWyWiyayqjsBShNIDb Bzr9KMT/T7u/hKYD03UhBobomiFLb/cS2nIyumnYQR0lT6LPBSNdhirExo+dph3oWh M6O9zEvCuCx9S6AheT3VDcXuNBBgIH6TcV8sB8q/tgagCXjwE1OEuGEzS9XzekDbK0 t+AlY31dWNadimMISPDEx95SGQMPUqcx+KhON7uRXBSvxH9WuCqy3pg8rK5Rc91JB0 WbQxFumacovNg== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 595AECE0F8E; Sat, 11 May 2024 07:54:34 -0700 (PDT) Date: Sat, 11 May 2024 07:54:34 -0700 From: "Paul E. McKenney" To: Guo Ren Cc: Leonardo Bras , 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: <9a84b94c-34ff-4c3a-ab2b-2741a5755db9@paulmck-laptop> Reply-To: paulmck@kernel.org 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 Sat, May 11, 2024 at 02:50:13AM -0400, Guo Ren wrote: > 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 I am carrying this in -rcu, but only for testing purposes, not for inclusion into mainline. Not that I know of anyone testing -rcu on RISC-V, but still, I wouldn't want to do anything do discourage such testing. The reason that this patch is no longer intended for inclusion is that it has been obsoleted by a patch that provides native support for one-byte and two-byte cmpxchg() operations. Which is even better! ;-) Thanx, Paul > > 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" \ > >