Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1704353lqz; Mon, 1 Apr 2024 14:42:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJpd728LfhiTYcqwMQMO8Hw3t6TQ+rWNhBvqMf5/ECDr248fMJqDfTnomj1JUibFA+hLnjrMGctNZDcI+AZD46rVzLFuhbAMNIuNRcsQ== X-Google-Smtp-Source: AGHT+IHtkXlik+Z/QXLTrPDeiJDhBKjsq0EJigr0V1Fml5dVcKiT5kGg0VzrZ74BoEUWFjC6h/ay X-Received: by 2002:a05:6a21:2d8e:b0:1a3:d618:cfdf with SMTP id ty14-20020a056a212d8e00b001a3d618cfdfmr10378099pzb.26.1712007733807; Mon, 01 Apr 2024 14:42:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712007733; cv=pass; d=google.com; s=arc-20160816; b=YqXlOmq9drB/JDnldh5Fajp7IW451SngW4dsTofBAZkyJe5Hr3g+ZzJvpGkfKlMWHT B8B37or7SXyPfVbNtopbuqoO9yPYretixBrponYcjUaby5gjANgqVzGdYL1vKmvnLgoQ g4jlCkvzcylXGMggCw5nTjRLeKpBJ0xsN8tdBuAqOMLrR97Svyja1dDGVXEQ/2jN385G 5rr7RURozv1zZKjhRTU7wq/Eubfa1SuKJhBduSgOCzIG4IrXMVefeUE+6cg3c4gUQDdz BT5cccHjgWFHqWEON+rAapcRYmjInPzFcm0jHgO+2Ovhk9MGZuITfxZ8EgXt0FfmZN3/ khKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=TWOuAwpsQxFOrm0ZPw6jd/g1jOjmg5ysSARPSmWXyGU=; fh=pfDPxqlJzacrNLez9ROFX5gHuf1684vUulmHaBtALMY=; b=O4050kD/aL7pTXBztvOtWTLv3tFd0YGGYp+sLR3J+mMJFNppgJJSEX+fK1eFPpsotU aQohomZzXXjdh6fvFAay6dyAPDqVk1JJLwwKRJTHfLO+PdznS57Qh610B9QYis2Jl+c5 EYkdFqqL+Opw90VEFYq4VrrhG3f03tHrfwPIRenz6O4WOtr04l5wH9d5s05zsorDTAyd 8LcT+k2W5WhyPx6v3Iz3fBCtryp9H8G8HRKHCc1QHKCixcMXLPX0ulKmbkfMNurOlq7e K9q06f+zOcnHTUXJ/zVGAg95aKQmEdAY52kHGgwx6A6KZ8tD2WGI69ozAyw7lCUidTzA DRuw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="FRjGv/+g"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-127099-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127099-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. [147.75.48.161]) by mx.google.com with ESMTPS id u16-20020a170903125000b001e23a4e7540si7003289plh.181.2024.04.01.14.42.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 14:42:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127099-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="FRjGv/+g"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-127099-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127099-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 95AEAB22EAE for ; Mon, 1 Apr 2024 21:41:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E18B58AC4; Mon, 1 Apr 2024 21:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FRjGv/+g" 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 DC95C56759 for ; Mon, 1 Apr 2024 21:39:55 +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=1712007595; cv=none; b=if5QF8zSOzXRHgCLYYOsmmHhtBM4Ruzar0AnEML9S6x1WJcFyJ0fvHU7IS6bvOOOzal6x0//0hvM25pFoJosK5iWzX+VtomlxJvwtK4CsMcnkEnJhTaovr4vjoBkOxQYvUP4EmqKiItSq1BtDeG7Swyclu488IVVWWyLx+lKqHg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712007595; c=relaxed/simple; bh=cHdjMWF2pKpjp1cSSio1TIEvF/d3v3dy9dZ8dApGZaI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q74puIz1yoDLZIm+/4kZreKTOXI65uTCj1lAzsh4XKQzcuZPuquLc8I9FV1ITiswytoC/uPv3uyavbkMfZQwkcvZyQ7RCVD6be+H+PSnlqbKp94Ba7W4i2Qn/NN1Wp3uTwizWMUdbtVU9pqwGi5L7CSQpoEOfTsAwGLfW4ySHIo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FRjGv/+g; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BC9DC41674; Mon, 1 Apr 2024 21:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712007595; bh=cHdjMWF2pKpjp1cSSio1TIEvF/d3v3dy9dZ8dApGZaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FRjGv/+gDSEbG4K6K0NV7MmU0QufJtVBYBfxeKyOQa0h0evV+yct5bBRhoMQSPCMP XDRZmN2Q2pb7o9OYst/ZZnhP3K5xDW7pk44v4JOxwr4VbVkbO5sBbK541XzK7IWXMk pXBVXdoF4cxiWsNPVZwjs4XFjDhVLYvN1G/Gc5NVJrK/HRrlrxizsJ33IyuBJBraTt jOv64zBDQ/UT9nD2WhwhbL4C5Nz0/bvECe1F1YsTvCotZG8uG6rZQo0/ghkTS7kgdr 6fHuxnq+I1XegKXRmh+QS/do3AO8kEqEYwmIvblcphWI1Hu4Tcnvt3vJyEL+HwUjQs ZF6d+P70ZxP2Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id CD0D4CE16EF; Mon, 1 Apr 2024 14:39:54 -0700 (PDT) From: "Paul E. McKenney" To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, "Paul E. McKenney" , Andi Shyti , Andrzej Hajda , linux-riscv@lists.infradead.org Subject: [PATCH RFC cmpxchg 8/8] riscv: Emulate one-byte and two-byte cmpxchg Date: Mon, 1 Apr 2024 14:39:50 -0700 Message-Id: <20240401213950.3910531-8-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> References: <31c82dcc-e203-48a9-aadd-f2fcd57d94c1@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. ] 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" \ -- 2.40.1