Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp246591lqb; Tue, 4 Jun 2024 10:05:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUUuMk4fBytjZdqfFvIT+QPs5u396l15ZSW0NbFoCbeMYZh+5VBFxGE+36u4HKxsNHwCRkvrk8+t0Lf3lexJL9JFuZOeukyniLz/pRSfg== X-Google-Smtp-Source: AGHT+IGxoGU6/lLaMZpkGoTCztPnpO+aZjMJSr4h4IgJRXw3f6xr8rRf8HU8v5EI/g/M4dhGqwUK X-Received: by 2002:a05:6102:441a:b0:48a:32d9:85af with SMTP id ada2fe7eead31-48c04aa6388mr134606137.30.1717520724120; Tue, 04 Jun 2024 10:05:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717520724; cv=pass; d=google.com; s=arc-20160816; b=wh2FdhIA4k+S3JUyhEMsWTo2xYoMz+lE37VigAoZuKJPJ7yglHIVdxqPmNYPdRoX7n QQ7OUlJFyXhU3KIKZT5lfHPRrRo3KxGtPvdRr21JCyIy6OubquFu6e37Iv4wzjWc2FnI XHrgV6nPKa2q2GJrkXeg+nnQh/tXfTx0qz8cPQOYGjoohPO/qqjgfKNYT0kwIcWesjH4 uXoOGvdyfj7U/WRxBaFSaBpU2Racr4AXpyjv5/W4QhX/MolAUK7eez5PjD7wGT4dQnPf A9JTlxS9GoUpPU49uYtvvpTOk8r0f4Hakme/CHrpX2XNsOVJyTim3UdFWL5pOWic4e5a SVqg== 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=1z8rSLe003nK5rBUfYsLZUtRc7G8ewBNSGIu/Gm+DF0=; fh=9PUQ791GGfWEcVJv373riapdpjpPC8WuH5fwlWFSNPU=; b=BKTgSM9K8Y4w8ng+tdrCPQRlRH653omz98L+IWelwWvQX9tr6kVxniG9DmtU6DwteN ffif8o/i1k1TlNYJ21IrILwjU6/mTDwZs91pBPSYAGBJpk+tmWiGCWNWt++rqtzy0Hpy orveP5cQhYhTcmrgrSx1GlRkWmIdnt9W78M4BYTbyNQDGvdE19RGr2jxD4VXCfSHsI4l rj3usoINmxMQIBZEb2Sk5/NDH9nA55mgAF9s/pho/JZphjlRaFmHHbYo/NtjTt6UGcws jeP2lE4xq+z651J+1iz6J4QyXfRFzexfoiQNnEqXftKLH0vG+nMMGJl4Xz9Y7RRcr08l 1UxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="HNF05O/z"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201119-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201119-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-48bbd00f0c7si1897180137.722.2024.06.04.10.05.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 10:05:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201119-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="HNF05O/z"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-201119-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201119-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6B59F1C2503F for ; Tue, 4 Jun 2024 17:05:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF05314A092; Tue, 4 Jun 2024 17:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HNF05O/z" 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 BF4AF149C62; Tue, 4 Jun 2024 17:04:41 +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=1717520681; cv=none; b=uN2CT/nkV617qa+b4UMQFgvs/74EEKXbmgqdjpTWwLElgkEK13QcMz54+04bc1VcAHar+7TEGeQkuyghg8rcPkwbQvkbXYO+SMqC3QYBCshDJTk0E7uvMxaxk5WlIzGyVo9+Bxrkrlj5k2mmeXl8XO5dO5wiDig3Ls3jlilPsZk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717520681; c=relaxed/simple; bh=m6rqAOBQ64nAVbwfoMwra9NFlfK4T5G41qjNyF62BxA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hKGwDRcUmhCNocGgcxI1pUEtT9ltzuVIJH8yP7s5BHh17zYl+9A2Ks3+92/J+DxUYxjPoapSkE4ERhC9VUzRB9n6mEaNhXp6FxoWd/BE1vg3m4Fj7czqKiu72IV4+fYZwbKYF9IZrd09OYwj8+JJeVKqDiJfv7CKuYmz+f0PsrA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HNF05O/z; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C318C2BBFC; Tue, 4 Jun 2024 17:04:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717520681; bh=m6rqAOBQ64nAVbwfoMwra9NFlfK4T5G41qjNyF62BxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HNF05O/z83KdgySpuamBtdJNQPd+6KMd8DXn+woZXtYeUdCI1eSQfGWa6KtuuXFmR MteA50UrqjFRjOjHRs/udBUOaJWKJe0HyRtAwUJgDy8V6V7k/GVcnEjUbX2MMmS/mK P+lpopMYf4HzqNyqG1TKE6SyW1bm1zrwdUPGYZSPh9/ueugXY2d3O8MQphL6kohvDp Qodja9iSGJwXRX+ySo0tt7Q1/2EOIm8z+DEO7fEMgFbUSH52SBB47s0hmw7B/Gk84Q zzGFnjfhHlwGcq1Pny93N1jAVngBGUrVq4eXMBrbCCMihe9FGaegY6MEzlXhVHxyis prjhj0VWrTClA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id F3F2DCE3F09; Tue, 4 Jun 2024 10:04:40 -0700 (PDT) From: "Paul E. McKenney" To: linux-arch@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, elver@google.com, akpm@linux-foundation.org, tglx@linutronix.de, peterz@infradead.org, dianders@chromium.org, pmladek@suse.com, torvalds@linux-foundation.org, arnd@arndb.de, "Paul E. McKenney" , Vineet Gupta , Andi Shyti , Andrzej Hajda , Palmer Dabbelt , linux-snps-arc@lists.infradead.org Subject: [PATCH v3 cmpxchg 1/4] ARC: Emulate one-byte cmpxchg Date: Tue, 4 Jun 2024 10:04:34 -0700 Message-Id: <20240604170437.2362545-1-paulmck@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <1dee481f-d584-41d6-a5f1-d84375be5fe8@paulmck-laptop> References: <1dee481f-d584-41d6-a5f1-d84375be5fe8@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() 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: --- 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_; \ }) -- 2.40.1