From patchwork Sat Feb 17 13:12:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 13561363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4BC51C48BC3 for ; Sat, 17 Feb 2024 13:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=oyz50s2S0QiJmtO73Ikdfka/Culggel74pxUsWbGpFc=; b=YtP8yve/+j1uj0+Q1OIpfVNobi uDoKqLo6menPCYlvWKqUJetS3UF4K+OYhhTqaQkmppBjotCSwdMEMQ5UrTKSSlEOXY8o7qHr795rh hx4pzEO5RTyRjxKyt8la5Jhu3us/sLrq+Fb2pwxTB4P62k/cqogGkv0lHItugvZtil+zTsTKAjMC/ jJyW4TlCtyMuDIbEQHZuOVSya5L5+9unEhUEWsNQdC5q+8H4c+R1TT9nmNFxdEtlyls/XkfVVjK6L FShO09GkajlTfttXlypQbJCZVyfmph4BWb/q2NZj4hDJn0SXvBvcEzsBmjmRCaql9MEG3mRcDOnqZ Ki4C7jBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbKV2-00000005iC1-0GVK; Sat, 17 Feb 2024 13:13:00 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbKUy-00000005iBP-1POW for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 13:12:58 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc6ceade361so5595715276.0 for ; Sat, 17 Feb 2024 05:12:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708175575; x=1708780375; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9Nhq6jELtlORL5ogz3lCatqW4aS8TpTjuA/JogYOAbE=; b=BNy/gqTTpfmCXCQ2cIMbBzWEglYF8i2jaiSAmTL6OwQfuRnDEwESyReL6LXt9juvTE WvqTNqWfMbJEF4X1tt94RvG0DFOIMyZk+k4rTOBtza5C3OJYtx7t85khlWU0An95WH+Q wFz+tLpZTxq0MlY8ka+b4RoWl46zXTxJ6l3rElN0OQF71GFOkQoik/cXWMCoAUoNTHg3 b24C3v2ytI6JItWv8LH8uawHaT2m7i1Vuf1vqkO3aaZtCxMW/phZc6GkoH1eOyVZxXz4 2pVCt+tZLLgP4Y2eH0ru83xBuUaZWw7wKtZ0TiGsRfV2d2QRi95QG9oKEVjBHD6uMtG0 CNQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708175575; x=1708780375; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9Nhq6jELtlORL5ogz3lCatqW4aS8TpTjuA/JogYOAbE=; b=TF4Wtp7YJAvTr45/Mwa1dlBs6LYQ5l4KszWbsYt4oE4pDvJpSLhZ8hZBxOS/dxRoXp RqS0BIL4WPLXt9qmlF/HW4kDuJBUhZqTzIrr/hRh+bvM6h3BELAUxugbVXXi+vnDIYLC ITN2XP8lWGi1oxsosTN5yXGI209BbmlJ5xiIF1HkekTJBm3SXn036S+rpjsQNcz0JfHF MZqyFSmikwG4+UM506euzXgPAZLcUWpQoEIh+3ur6Y2Rxi0dl5v20k1XbglqUWbwTASS mWfv2zb8CTDRUebK7PVkE5/J/tGZVpy+kLbGi7JpAsWlFkFPrs5MvEAwgmT2UBEeD5yn ko5Q== X-Gm-Message-State: AOJu0YzQaFxUI8Nu1CzWyfwtXDJN8CaEvM87i3HkhxUpxR2Upn5t2fR5 jr9SObcAnpoWJSZ5Pv+R0/zAAMKO33SkeSQHfxqy4vI9Fhf5EnLE1cACKBMbC2e0rzZTrRYIZeV g0n57+a9KSjkY/CcEEA== X-Google-Smtp-Source: AGHT+IELhbiToXabxhoUii8w461MsVDnMXHO661y+j2h5Y0RY6bmJ1OQ3jt3aXw7K1MJbxPyaQkNPeYOrWzAEoyD X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a05:6902:2284:b0:dc8:5e26:f4d7 with SMTP id dn4-20020a056902228400b00dc85e26f4d7mr1779458ybb.13.1708175574920; Sat, 17 Feb 2024 05:12:54 -0800 (PST) Date: Sat, 17 Feb 2024 13:12:49 +0000 In-Reply-To: <20240217131206.3667544-1-ericchancf@google.com> Mime-Version: 1.0 References: <20240217131206.3667544-1-ericchancf@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240217131249.3668103-1-ericchancf@google.com> Subject: [PATCH v6 1/4] riscv/barrier: Define __{mb,rmb,wmb} From: Eric Chan To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, ericchancf@google.com, conor.dooley@microchip.com, parri.andrea@gmail.com, emil.renner.berthing@canonical.com, samuel.holland@sifive.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240217_051256_395005_B56777D3 X-CRM114-Status: UNSURE ( 9.04 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Introduce __{mb,rmb,wmb}, and rely on the generic definitions for {mb,rmb,wmb}. Although KCSAN is not supported yet, the definitions can be made more consistent with generic instrumentation. Also add a space to make the changes pass check by checkpatch.pl. Without the space, the error message is as below: ERROR: space required after that ',' (ctx:VxV) 26: FILE: arch/riscv/include/asm/barrier.h:23: +#define __mb() RISCV_FENCE(iorw,iorw) ^ Signed-off-by: Eric Chan --- v5 -> v6: let this change to pass review by checkpatch.pl instead of overwriting again in [PATCH 4/4] v3 -> v4: fix commit message weird line breaks arch/riscv/include/asm/barrier.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.44.0.rc0.258.g7320e95886-goog diff --git a/arch/riscv/include/asm/barrier.h b/arch/riscv/include/asm/barrier.h index 110752594228..173b44a989f8 100644 --- a/arch/riscv/include/asm/barrier.h +++ b/arch/riscv/include/asm/barrier.h @@ -20,9 +20,9 @@ __asm__ __volatile__ ("fence " #p "," #s : : : "memory") /* These barriers need to enforce ordering on both devices or memory. */ -#define mb() RISCV_FENCE(iorw,iorw) -#define rmb() RISCV_FENCE(ir,ir) -#define wmb() RISCV_FENCE(ow,ow) +#define __mb() RISCV_FENCE(iorw, iorw) +#define __rmb() RISCV_FENCE(ir, ir) +#define __wmb() RISCV_FENCE(ow, ow) /* These barriers do not need to enforce ordering on devices, just memory. */ #define __smp_mb() RISCV_FENCE(rw,rw) From patchwork Sat Feb 17 13:13:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 13561364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7E7A7C48BC3 for ; Sat, 17 Feb 2024 13:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=t/kUDYivXX0OxJvCd4Jwg/ogo1Y8bGYXSEm2Lv3xlX4=; b=rBeyJ4GriyrU24lvFJnmWlT3Nf CKqn8sKqr/UASjYIuJ5eKWD1BUrJUtbxFYVjn4roN6XKs3CPq5+PANWlcRcf2VsVMbc/BiIcDBlAu wMXFJnIWsbfM+OqnZ3DlJ6jHdEAuiFcnyJ8GBj87eTBWGTrAFlZkEUNid3Vc7Xxy32MTPlpnwZ7Rc 0Au146oSBzubKo7nfbNsMPK76Dcuw/mbhdpU+fGp5nOqlD8qVFxW2jHh7kFsoVOjvXpju//EV8+me QRl8xnwCuESQISaIXos3Kxrh7GWreyz2+KVqSSxKG130ytT+3pyxJaPhSVWK/Ok+8ftN68HMHrJNi vmzlBW0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbKVF-00000005iGb-01xi; Sat, 17 Feb 2024 13:13:13 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbKVB-00000005iE3-2jwF for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 13:13:11 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dc6b26845cdso4789977276.3 for ; Sat, 17 Feb 2024 05:13:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708175588; x=1708780388; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=R2+WpDCt8HOz+kxBkD8ukIa/A2HuTgCzwuZw4fcBj8Q=; b=c0GlGeTyVcKxESkAzJRDcEbZaQNKmQUuAU56AUbt9nhsp1JxodrerVF5LZw73jeqzA 9ZIvA+6tE1CqlXBWSd32UxabUr5P4IjUzkOPkcf8FafabBK3unLfY2Bvfvkc/lOKG7oc 3pNRbSNKM+IfjsFbLxd4vA5MFm1vuCizbSzWX1jVApzWKY4UmjLlW7WVq1sVHHy1zn7I moH5/IgEy5WVSm63UKcVIv13u/TXC5evfCPcpVCqOmkkMJ+eN/HxYm2vrZhHo+1asjDR 9Ou+NYLOWIVMKyI709XSEHqOt+XURji/3n65sp8bzUNF5MAPCnaySAHBs/ut6ZhkUkdo kT7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708175588; x=1708780388; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R2+WpDCt8HOz+kxBkD8ukIa/A2HuTgCzwuZw4fcBj8Q=; b=T8O2ArPiINCjUI7ZWnl9f5a0zgpzrmdM1gxejKU0lPX6Sgqd8RwgvRYHRZNUR6WHdK CjHRwv5E3b0PRXQv4GN/a+sLlsHwjpYUE7+T3pfcONtVMH8DkapbEjPKrasFxChhaai9 eFuhUteq26HSnr/S8BKEYw1V36+ZB2k+BfItrtCyt9hSX51MLBKiFlQh0mrQlSYP9eJd oDHzZbz/ME58gbZjRyNjkKk4FN47BUT7B6lSxbQWjAS0pEWfbTRg3dOOSpbgc+BV5XPw h1DAYzld1TI0BmDGMzgWELeL75TTUoZBKe0VFKVI1vFpvOSF9/p9O4gODHh+M71OyTyP Niww== X-Gm-Message-State: AOJu0YyDPhenqStXi8dho0AlUBhAPY9HVV/BDsnCGEpY9S70sgfwKEWa TJY0KV+cGtMx48VL/BcfCE78WyJ4EMnatf0I9jilsy2RvECT41WIpL5kKkPPX7j8TFxnbfZwWXm QGexK96Lo1RwONCAvvQ== X-Google-Smtp-Source: AGHT+IEAJ/4G6wD0KVnJGN5oQcDtNoKQ10qhlVZxpPvg7p+h7qHeL1Q6wHY/niRI5dbBnn7ePSTvHDt/7ZPsroqL X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a05:6902:1029:b0:dc9:5ef8:2b2d with SMTP id x9-20020a056902102900b00dc95ef82b2dmr1930551ybt.4.1708175588280; Sat, 17 Feb 2024 05:13:08 -0800 (PST) Date: Sat, 17 Feb 2024 13:13:02 +0000 In-Reply-To: <20240217131206.3667544-1-ericchancf@google.com> Mime-Version: 1.0 References: <20240217131206.3667544-1-ericchancf@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240217131302.3668481-1-ericchancf@google.com> Subject: [PATCH v6 2/4] riscv/barrier: Define RISCV_FULL_BARRIER From: Eric Chan To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, ericchancf@google.com, conor.dooley@microchip.com, parri.andrea@gmail.com, emil.renner.berthing@canonical.com, samuel.holland@sifive.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240217_051309_715383_76E03B2D X-CRM114-Status: UNSURE ( 8.89 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Introduce RISCV_FULL_BARRIER and use in arch_atomic* function. like RISCV_ACQUIRE_BARRIER and RISCV_RELEASE_BARRIER, the fence instruction can be eliminated When SMP is not enabled. Signed-off-by: Eric Chan --- arch/riscv/include/asm/atomic.h | 16 ++++++++-------- arch/riscv/include/asm/cmpxchg.h | 4 ++-- arch/riscv/include/asm/fence.h | 2 ++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/riscv/include/asm/atomic.h b/arch/riscv/include/asm/atomic.h index f5dfef6c2153..31e6e2e7cc18 100644 --- a/arch/riscv/include/asm/atomic.h +++ b/arch/riscv/include/asm/atomic.h @@ -207,7 +207,7 @@ static __always_inline int arch_atomic_fetch_add_unless(atomic_t *v, int a, int " add %[rc], %[p], %[a]\n" " sc.w.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : [a]"r" (a), [u]"r" (u) @@ -228,7 +228,7 @@ static __always_inline s64 arch_atomic64_fetch_add_unless(atomic64_t *v, s64 a, " add %[rc], %[p], %[a]\n" " sc.d.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : [a]"r" (a), [u]"r" (u) @@ -248,7 +248,7 @@ static __always_inline bool arch_atomic_inc_unless_negative(atomic_t *v) " addi %[rc], %[p], 1\n" " sc.w.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -268,7 +268,7 @@ static __always_inline bool arch_atomic_dec_unless_positive(atomic_t *v) " addi %[rc], %[p], -1\n" " sc.w.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -288,7 +288,7 @@ static __always_inline int arch_atomic_dec_if_positive(atomic_t *v) " bltz %[rc], 1f\n" " sc.w.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -310,7 +310,7 @@ static __always_inline bool arch_atomic64_inc_unless_negative(atomic64_t *v) " addi %[rc], %[p], 1\n" " sc.d.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -331,7 +331,7 @@ static __always_inline bool arch_atomic64_dec_unless_positive(atomic64_t *v) " addi %[rc], %[p], -1\n" " sc.d.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : @@ -352,7 +352,7 @@ static __always_inline s64 arch_atomic64_dec_if_positive(atomic64_t *v) " bltz %[rc], 1f\n" " sc.d.rl %[rc], %[rc], %[c]\n" " bnez %[rc], 0b\n" - " fence rw, rw\n" + RISCV_FULL_BARRIER "1:\n" : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) : diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index 2f4726d3cfcc..a608e4d1a0a4 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -313,7 +313,7 @@ " bne %0, %z3, 1f\n" \ " sc.w.rl %1, %z4, %2\n" \ " bnez %1, 0b\n" \ - " fence rw, rw\n" \ + RISCV_FULL_BARRIER \ "1:\n" \ : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "rJ" ((long)__old), "rJ" (__new) \ @@ -325,7 +325,7 @@ " bne %0, %z3, 1f\n" \ " sc.d.rl %1, %z4, %2\n" \ " bnez %1, 0b\n" \ - " fence rw, rw\n" \ + RISCV_FULL_BARRIER \ "1:\n" \ : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ : "rJ" (__old), "rJ" (__new) \ diff --git a/arch/riscv/include/asm/fence.h b/arch/riscv/include/asm/fence.h index 2b443a3a487f..6c26c44dfcd6 100644 --- a/arch/riscv/include/asm/fence.h +++ b/arch/riscv/include/asm/fence.h @@ -4,9 +4,11 @@ #ifdef CONFIG_SMP #define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" #define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#define RISCV_FULL_BARRIER "\tfence rw, rw\n" #else #define RISCV_ACQUIRE_BARRIER #define RISCV_RELEASE_BARRIER +#define RISCV_FULL_BARRIER #endif #endif /* _ASM_RISCV_FENCE_H */ From patchwork Sat Feb 17 13:13:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 13561365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1C3D8C48BC3 for ; Sat, 17 Feb 2024 13:13:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=WjxKOf9oJpohiV6L26OwbFi5BR3mEFP0XrDWFQ+fsKo=; b=HoZm4XsB7oq/ivWtKCRtMFeiN1 eM1yZWskn0uMFPlzQDkGBwbQt9T6pMAx8godZd++KWhSBL+eCrVtdMdjc3GsZLg2Fa3EtIozYKvWz 0hdFJzLkYAy9hKztWWhDCack9kRUaPDqRntZGvGQpqcBuJBIgM+vjdgVyy6SMZ+UufGGt4loUOxws omr1+GYGkaLYd/CfPKU1iqvHQHiC8S/zgVZeXIaovQdrmnc0QMsWJyAb3UDMYI0B6IckIAXgVCHWx Bcdr9z6Hg1JCAFlbGf84S6OfxCKv5gfikFkSggnlwcnvlRO2ZBB4VOfKZR0XbXYNagxQvz3/CfrgU vVPhSePw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbKVU-00000005iNN-2ecC; Sat, 17 Feb 2024 13:13:28 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbKVP-00000005iJz-1iu0 for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 13:13:25 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-60761bdbd4cso52729817b3.3 for ; Sat, 17 Feb 2024 05:13:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708175602; x=1708780402; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ANQ9Q8CsOYoivVzOOmmpID2/0jm0rKpHZABT07NfwNQ=; b=YHI2jV6nJMCyk+GczFe9HyCZRH8aOznA8Ma0UtU42ExNwzwrezMlBDERlCJWp7uBTt T1axn4eGMk38BlwLFPxQhhLwfp2Qhp+s2jpOQSQ7hx4cMcbvtmfcEVsJ/xj9PELt2BQ3 kcBUG+5IzqLEToEbeQNBlinjCT7yq+KY2Kbzc4S9oOpIfbR/8M+UuK77nd3z4+uJTG/+ sn1Q0nZR+aFHgagMSivsGpguCJ4JpmbXBXk87sz8UMxHOw1pOY5dRJYcx9/ZPqwJkOAq suCIAN0rMCA4ammmlRDm6fo3EQeEUyb4ev2mDSpys8+Ygft2Zr8sO4uuSxlIqmeT/Eu/ kCcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708175602; x=1708780402; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ANQ9Q8CsOYoivVzOOmmpID2/0jm0rKpHZABT07NfwNQ=; b=Rqcdm0bybqclem7cXH1uz9ak5DiP0UA1JHRUK3xJnUh5m1Cnyb16XwJ1R4j3kdxG2I fjT92hFpvLb7dX8bf6tSPYAoCwVxoy9D9Z51SNXs996ZO7PGUkkbHCpLn9BGa6A9Cmlf FpAXZvOmViq7hiRq2sWXrVQyfqbpy60awbnV7b//gdxjFXsP4RKshcgFF78ukBMsp6sy 9SV5hvMgt7/CIJ0+6uzzZegY28TwefdbrfkBJzCR8c4jbvQeQKtsazYNF0uZ58IyGJ87 2DKTABVoUNsDon5ySegCnZfrHwMicuSzz4Vdqpuw2VE6nDWpIeGYISW2ejzJoHLyc7YB FBZA== X-Gm-Message-State: AOJu0YyX3q+3Akee/Px874uDkTSgooufBfnNJe7EOhYj+dPnxbr3dgde CUA4Jo43iMUv2k4ksGPRlUjxK5poKk3VtX6ap8uGVgvgck4CrwQpnEM55J4yW5pLgoN6huT/vIQ ZtJ9oybfQSJVugx6Ayg== X-Google-Smtp-Source: AGHT+IFut6wtlgAhbVyHcpO0+LKbaT4xj0hzEj2c8AJpczaQ/l9VLPQeacdsPF1ojOT7WlUdtytMx2a+IO/sBEbx X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a0d:d951:0:b0:608:1b39:245c with SMTP id b78-20020a0dd951000000b006081b39245cmr149033ywe.9.1708175602463; Sat, 17 Feb 2024 05:13:22 -0800 (PST) Date: Sat, 17 Feb 2024 13:13:16 +0000 In-Reply-To: <20240217131206.3667544-1-ericchancf@google.com> Mime-Version: 1.0 References: <20240217131206.3667544-1-ericchancf@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240217131316.3668927-1-ericchancf@google.com> Subject: [PATCH v6 3/4] riscv/barrier: Consolidate fence definitions From: Eric Chan To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, ericchancf@google.com, conor.dooley@microchip.com, parri.andrea@gmail.com, emil.renner.berthing@canonical.com, samuel.holland@sifive.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240217_051323_481571_92EB0B79 X-CRM114-Status: GOOD ( 14.71 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Disparate fence implementations are consolidated into fence.h. Also introduce RISCV_FENCE_ASM to make fence macro more reusable. Signed-off-by: Eric Chan --- v4 -> v5: __atomic_acquire_fence and __atomic_release_fence omit-the-fence-on-uniprocessor optimization, and fix the typo of RISCV_RELEASE_BARRIER when spliting the patch in v3. v3 -> v4 fix the form that can pass the checking of checkpatch.pl. v1 -> v2: makes compilation pass with allyesconfig instead of defconfig only, also satisfy scripts/checkpatch.pl. - (__asm__ __volatile__ (RISCV_FENCE_ASM(p, s) : : : "memory")) + ({ __asm__ __volatile__ (RISCV_FENCE_ASM(p, s) : : : "memory"); }) arch/riscv/include/asm/atomic.h | 1 - arch/riscv/include/asm/barrier.h | 3 +-- arch/riscv/include/asm/cmpxchg.h | 1 - arch/riscv/include/asm/fence.h | 10 +++++++--- arch/riscv/include/asm/io.h | 8 ++++---- arch/riscv/include/asm/mmio.h | 5 +++-- arch/riscv/include/asm/mmiowb.h | 2 +- 7 files changed, 16 insertions(+), 14 deletions(-) -- 2.44.0.rc0.258.g7320e95886-goog diff --git a/arch/riscv/include/asm/atomic.h b/arch/riscv/include/asm/atomic.h index 31e6e2e7cc18..0e0522e588ca 100644 --- a/arch/riscv/include/asm/atomic.h +++ b/arch/riscv/include/asm/atomic.h @@ -17,7 +17,6 @@ #endif #include -#include #define __atomic_acquire_fence() \ __asm__ __volatile__(RISCV_ACQUIRE_BARRIER "" ::: "memory") diff --git a/arch/riscv/include/asm/barrier.h b/arch/riscv/include/asm/barrier.h index 173b44a989f8..15857dbc2279 100644 --- a/arch/riscv/include/asm/barrier.h +++ b/arch/riscv/include/asm/barrier.h @@ -11,13 +11,12 @@ #define _ASM_RISCV_BARRIER_H #ifndef __ASSEMBLY__ +#include #define nop() __asm__ __volatile__ ("nop") #define __nops(n) ".rept " #n "\nnop\n.endr\n" #define nops(n) __asm__ __volatile__ (__nops(n)) -#define RISCV_FENCE(p, s) \ - __asm__ __volatile__ ("fence " #p "," #s : : : "memory") /* These barriers need to enforce ordering on both devices or memory. */ #define __mb() RISCV_FENCE(iorw, iorw) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index a608e4d1a0a4..2fee65cc8443 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -8,7 +8,6 @@ #include -#include #include #define __xchg_relaxed(ptr, new, size) \ diff --git a/arch/riscv/include/asm/fence.h b/arch/riscv/include/asm/fence.h index 6c26c44dfcd6..6bcd80325dfc 100644 --- a/arch/riscv/include/asm/fence.h +++ b/arch/riscv/include/asm/fence.h @@ -1,10 +1,14 @@ #ifndef _ASM_RISCV_FENCE_H #define _ASM_RISCV_FENCE_H +#define RISCV_FENCE_ASM(p, s) "\tfence " #p "," #s "\n" +#define RISCV_FENCE(p, s) \ + ({ __asm__ __volatile__ (RISCV_FENCE_ASM(p, s) : : : "memory"); }) + #ifdef CONFIG_SMP -#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" -#define RISCV_RELEASE_BARRIER "\tfence rw, w\n" -#define RISCV_FULL_BARRIER "\tfence rw, rw\n" +#define RISCV_ACQUIRE_BARRIER RISCV_FENCE_ASM(r, rw) +#define RISCV_RELEASE_BARRIER RISCV_FENCE_ASM(rw, w) +#define RISCV_FULL_BARRIER RISCV_FENCE_ASM(rw, rw) #else #define RISCV_ACQUIRE_BARRIER #define RISCV_RELEASE_BARRIER diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h index 42497d487a17..1c5c641075d2 100644 --- a/arch/riscv/include/asm/io.h +++ b/arch/riscv/include/asm/io.h @@ -47,10 +47,10 @@ * sufficient to ensure this works sanely on controllers that support I/O * writes. */ -#define __io_pbr() __asm__ __volatile__ ("fence io,i" : : : "memory"); -#define __io_par(v) __asm__ __volatile__ ("fence i,ior" : : : "memory"); -#define __io_pbw() __asm__ __volatile__ ("fence iow,o" : : : "memory"); -#define __io_paw() __asm__ __volatile__ ("fence o,io" : : : "memory"); +#define __io_pbr() RISCV_FENCE(io, i) +#define __io_par(v) RISCV_FENCE(i, ior) +#define __io_pbw() RISCV_FENCE(iow, o) +#define __io_paw() RISCV_FENCE(o, io) /* * Accesses from a single hart to a single I/O address must be ordered. This diff --git a/arch/riscv/include/asm/mmio.h b/arch/riscv/include/asm/mmio.h index 4c58ee7f95ec..06cadfd7a237 100644 --- a/arch/riscv/include/asm/mmio.h +++ b/arch/riscv/include/asm/mmio.h @@ -12,6 +12,7 @@ #define _ASM_RISCV_MMIO_H #include +#include #include /* Generic IO read/write. These perform native-endian accesses. */ @@ -131,8 +132,8 @@ static inline u64 __raw_readq(const volatile void __iomem *addr) * doesn't define any ordering between the memory space and the I/O space. */ #define __io_br() do {} while (0) -#define __io_ar(v) ({ __asm__ __volatile__ ("fence i,ir" : : : "memory"); }) -#define __io_bw() ({ __asm__ __volatile__ ("fence w,o" : : : "memory"); }) +#define __io_ar(v) RISCV_FENCE(i, ir) +#define __io_bw() RISCV_FENCE(w, o) #define __io_aw() mmiowb_set_pending() #define readb(c) ({ u8 __v; __io_br(); __v = readb_cpu(c); __io_ar(__v); __v; }) diff --git a/arch/riscv/include/asm/mmiowb.h b/arch/riscv/include/asm/mmiowb.h index 0b2333e71fdc..52ce4a399d9b 100644 --- a/arch/riscv/include/asm/mmiowb.h +++ b/arch/riscv/include/asm/mmiowb.h @@ -7,7 +7,7 @@ * "o,w" is sufficient to ensure that all writes to the device have completed * before the write to the spinlock is allowed to commit. */ -#define mmiowb() __asm__ __volatile__ ("fence o,w" : : : "memory"); +#define mmiowb() RISCV_FENCE(o, w) #include #include From patchwork Sat Feb 17 13:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 13561366 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 593EDC48BC4 for ; Sat, 17 Feb 2024 13:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=dGxGRjn33XraXRl5w6qBP7qBD52MAPQTm8xa9R0lJmU=; b=ntGSBYBjTjxHKUn+1LYZrYCCuI XlQRqMQThecSuMKLN7kv4oL+rMQ1Mojr+R5qj716J3prBquKXQSwEjhGdofSI/i7fLOFWSo8Qz9nS JcpteALg0/zob6Yc0/DjIzUVmYUeolZ+8K+JhFlK6/+VPMSuIi7Pbnog473pnHt9H3UhH6FEuY4Z1 PaplUfjx+xMeu8s5kn72CzGmWpYfLeuqhSYt9yCfM4zWnnm7oMKL48fiRnBwjM8GhUZXV98LysUC2 MjvnjySN4jSbthTvCBEpJcd09fOBxKuKvqvhiZiX0r3zkZhxPk49d68OBS2XvI0pE5jYfi8LAOvFB FmqOQWQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbKVg-00000005iTa-3pYu; Sat, 17 Feb 2024 13:13:40 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbKVc-00000005iQP-1S9r for linux-riscv@lists.infradead.org; Sat, 17 Feb 2024 13:13:39 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-2993035cd15so1581390a91.0 for ; Sat, 17 Feb 2024 05:13:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708175614; x=1708780414; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lyeLrRd9CLe7Hw11wYIs8TpWMeWxDTUtralQA0dQ0yM=; b=Mpu+niJBRBRd6qeemZwO+Eq3ma8OUgh4FMGwMx+X+ZaFMbHv6IVnDebIMPQT1jh/00 mk0vthFDsJ01ojHdw0EoG7qyyvmyHl2fyvidhVYQgoKme2Leamsk8Vd4x/kBVruGz3/8 PE1b11PGKe6MyVILjtiQaVP8o3T5OVspC6ghKkd12fhs0yxSsVQVwonF0gnTHb65CC5J 1KhG7GEidBpDAuBVJcMSXJtMMyhG/EtNnZ2FO9crULFzoxK88Gs40/imWsf4kpw6Btqk qKoR4L6cMYE8OGHl9yfOzeDzMlT1CLMU4ripEoC1CJmbrCp/iWTpCuYlvO4vmF8r2kk5 qfkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708175614; x=1708780414; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lyeLrRd9CLe7Hw11wYIs8TpWMeWxDTUtralQA0dQ0yM=; b=DlqO/gczxs8i5ky6HoATzhQtu4aGxjpPuGHYDE5QByRL6BL5vFZyMhzJGrX0VNSvOy wXu/OnqFm70H4WEhx51TjA1wz4udy56PCApL67pglBwhj7o9nPCe5EaodK5i6/fuZ6VO lUHCpRtVTePeAhxLqw7UnVejEnoVuzm4vYWEODGUoeXVB5EMRb7vi9GZqdVkN1C6r2sm qpgFpz2KlJPuuLHP6HYLOFfyPo5Sp594N2vLv0KA/ETYc/1FDomF52OvzkwpSpsjgIDP 8kMAGfUXS8jpdTwb2f2rr6ZBV7jQQ5fwUpGnNyzc+b13fIihd3QQg1JkG/hDBhrj6Gg7 ctjQ== X-Gm-Message-State: AOJu0YxaXQgjEqsola5j4bSTvB2GOjET0c0QweN8DvymWbA+gFQVCZsP oMMCkwQDzce8393Z7Eq7NqOfVOZ+++8lEEtZqJBg2+LnI+YrXKZhzGAFZr0qXYfiqrLnZC+aS84 RBR/+jnSHL2NpdzdbzQ== X-Google-Smtp-Source: AGHT+IGcUSK2w2TzNdsgkFOUkK1bgKsf9p0KE7Ve3nXJ/cAI8GO3AnK/s3oB+wJsI9lmgIka5VRKg+dZ3U/FZtlY X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a17:90b:3a4e:b0:298:eacc:658d with SMTP id oh14-20020a17090b3a4e00b00298eacc658dmr99799pjb.3.1708175614576; Sat, 17 Feb 2024 05:13:34 -0800 (PST) Date: Sat, 17 Feb 2024 13:13:28 +0000 In-Reply-To: <20240217131206.3667544-1-ericchancf@google.com> Mime-Version: 1.0 References: <20240217131206.3667544-1-ericchancf@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240217131328.3669364-1-ericchancf@google.com> Subject: [PATCH v6 4/4] riscv/barrier: Add missing space after ',' From: Eric Chan To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, ericchancf@google.com, conor.dooley@microchip.com, parri.andrea@gmail.com, emil.renner.berthing@canonical.com, samuel.holland@sifive.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240217_051336_504730_8DABF0C2 X-CRM114-Status: GOOD ( 11.10 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The past form of RISCV_FENCE would cause checkpatch.pl to issue error messages, the example is as follows: ERROR: space required after that ',' (ctx:VxV) 26: FILE: arch/riscv/include/asm/barrier.h:27: +#define __smp_mb() RISCV_FENCE(rw,rw) ^ fix the remaining of RISCV_FENCE. Signed-off-by: Eric Chan --- v5 -> v6: change the error message example in commit message to make it more relevant arch/riscv/include/asm/barrier.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.44.0.rc0.258.g7320e95886-goog diff --git a/arch/riscv/include/asm/barrier.h b/arch/riscv/include/asm/barrier.h index 15857dbc2279..880b56d8480d 100644 --- a/arch/riscv/include/asm/barrier.h +++ b/arch/riscv/include/asm/barrier.h @@ -24,14 +24,14 @@ #define __wmb() RISCV_FENCE(ow, ow) /* These barriers do not need to enforce ordering on devices, just memory. */ -#define __smp_mb() RISCV_FENCE(rw,rw) -#define __smp_rmb() RISCV_FENCE(r,r) -#define __smp_wmb() RISCV_FENCE(w,w) +#define __smp_mb() RISCV_FENCE(rw, rw) +#define __smp_rmb() RISCV_FENCE(r, r) +#define __smp_wmb() RISCV_FENCE(w, w) #define __smp_store_release(p, v) \ do { \ compiletime_assert_atomic_type(*p); \ - RISCV_FENCE(rw,w); \ + RISCV_FENCE(rw, w); \ WRITE_ONCE(*p, v); \ } while (0) @@ -39,7 +39,7 @@ do { \ ({ \ typeof(*p) ___p1 = READ_ONCE(*p); \ compiletime_assert_atomic_type(*p); \ - RISCV_FENCE(r,rw); \ + RISCV_FENCE(r, rw); \ ___p1; \ }) @@ -68,7 +68,7 @@ do { \ * instances the scheduler pairs this with an mb(), so nothing is necessary on * the new hart. */ -#define smp_mb__after_spinlock() RISCV_FENCE(iorw,iorw) +#define smp_mb__after_spinlock() RISCV_FENCE(iorw, iorw) #include