From patchwork Tue Feb 13 22:39:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 200712 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp848237dyb; Tue, 13 Feb 2024 14:41:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVRL+6cYuZTuZ/PQfk6Ff72cqitHimexkkl5WeBjrx73Ey3RMvRL1TrhT4k4+7YU6Eka1fA46HCFVMrnLNK+SKCZqm/0Q== X-Google-Smtp-Source: AGHT+IF3Az2f59+tyjDXiYutveJ+mjIHoW2O4r45SCLxnW76NXCeFTUsiZshmDUeMjEfj+aE72j2 X-Received: by 2002:a05:6808:3014:b0:3c0:3def:ce61 with SMTP id ay20-20020a056808301400b003c03defce61mr886515oib.8.1707864080608; Tue, 13 Feb 2024 14:41:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707864080; cv=pass; d=google.com; s=arc-20160816; b=a+WZ0PoTpMLLsfgqvLqbJfC/5pGMcJPPNQybN3FM06sq0pgj+vsV/QPnO+Yl1F3d6Z 7eTLPrHX31HEtEIuQURgtBRiMM7lzqkw2w+8pDoaBuZk+f3RPHjL07P+BUFhEb8yhQE5 zVKmzq8rLMSk+Hnd8PS2+VlyPCIjY8UzlI54NWpG52Tx/9IYjaWzwCDT8dwEr8TgbWTy 8EzZxBZFlCPgB6yMncoW/syjXjb0lKu/BbkuVh3lva+TzXZUsMv03AaRWjRR5TVBdZ6G nzYQOZyZY3rqYpWPQUkSvl1084ZCw9RAPc97+pqLVAb7+HNl/BVN0SN8B5q2FC3OEwP2 eEEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=BS7J64xtqNYr0VkPhgpx0WAA/5MaMJzR/9ev/cheMlM=; fh=BzwU+Hl/5a8cX5VcEsYhmzugaAlGznVwmzMUckfI3Wg=; b=j94eYWrZseNEBXDObkqzUleMm3CrKLPbWRSW8UWPeLhqV6saNc8WX2ylqgoNKtYLdC KwJWD+YCHE5ZmkMVBmE8YgF9wuC4KilRsG9tiRMTHy8BRHKqINhBlT+X7tmIQ9yzejky 97+3u0FCHOutgsEyd3ggFG65f6nW5Ad/HgtiaQvsFNESlvMbNJu+eI1FDYz+fxEfhdkR uRkGiZCSNT8gEZFJmP6p8EQUYCYa0oay4jgSb9tz7w4gY8bJBk/nV2CX8Yidytl0RaDJ EpVj/VUY1DWcXffmQMJLptygXk8Gy9NVSSgFwZSjlz6tMGyB4sTpQrdo3NzRbQdKabYf +Lnw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QtLYEfm8; arc=pass (i=1 spf=pass spfdomain=flex--ericchancf.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64472-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64472-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCW2OrExjOpeYAci2Tkn+JnhD3osa8sFKIpERP+oX3XsPP5KHTBBOsxeGT1THG8VfErzACQ7312FQNY0j0QhJ4O+RafO3w== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jl13-20020ad45e8d000000b0068ce9808aa8si3969514qvb.18.2024.02.13.14.41.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:41:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64472-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QtLYEfm8; arc=pass (i=1 spf=pass spfdomain=flex--ericchancf.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64472-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64472-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 59AF11C27EEF for ; Tue, 13 Feb 2024 22:40:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5A6D629E2; Tue, 13 Feb 2024 22:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QtLYEfm8" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8D7E627EA for ; Tue, 13 Feb 2024 22:39:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707863995; cv=none; b=dX5JDB2yAyucDWuU1QG86ToC+pBzouJmUxOS96uVpdDOFUmNPhf3uxCUY0YQptjQtheYbOJXYtsYCSI642trsF8nxzXLX7YjTQZznAeeIcoYxVAYybq7mVBmKCVs8i4Z9USFKT5Tql5fQu/7O+kzXVV7VUHQbE7iWwl8run9Y14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707863995; c=relaxed/simple; bh=Arzgl6pL8qoStNM3EKk4ljjB6ogUsbOSdyqkDHv4CGM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=f691VcMBwpeWazIXzy8qNUEQ9c0hErpy40Wx//htLUW+utVlTw89ta9DVEhb8xBLdpyl5FcIxVSjRRmi1wCC1RfOaEv6PI80X4E4zsA6rNQtvomGsxB58PaYwDxWxf+7Nv049hbb3c618NSVytp6oDcULhRyibvX6jgC+IBAQiA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QtLYEfm8; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ericchancf.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60492d6bfc0so65800537b3.2 for ; Tue, 13 Feb 2024 14:39:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707863993; x=1708468793; darn=vger.kernel.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=BS7J64xtqNYr0VkPhgpx0WAA/5MaMJzR/9ev/cheMlM=; b=QtLYEfm8JgOY5vtyiTJPvl8evIcqlNGm2HUnMjuFKptRU3OSQQ/TUu/zRnm4C4adbr rZF01Cf1JvaWGwfTxamdUt1FU7Jg5C7hM/Y8nLk2qGsQr93N1Dvxv7lL6arvmekhmTpC YQDxhf/57T+Pue20PUNzyguPXOX1jNg/WBz7p2biAHA++Xcbor4Z2zIWlX5nqYuRrCNJ LBrQgXPeIGaPelKc3mvPWKbP9pTct3TlwAC1SD64aNJApF7e16sbN0Pe2Od0a8qaXs0v 300UvekTUba9FTN9YDCRNakNXxq0gzgnSyltcO729pv8MPocz+Y2JfBeeJxz5YvqFJuG d4Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707863993; x=1708468793; 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=BS7J64xtqNYr0VkPhgpx0WAA/5MaMJzR/9ev/cheMlM=; b=HPVNPtdC6T48zq3vEDHElSDfJz3RxQvxzJ+3F7gidCQvGlE7UIEL1sXplHTypdkMh/ wT09xMnRPCP32B+ntMVG1W2Owkf08cf8gxqGQ3rpa2iGnCSbS/oB6ttUnJjEUYEUoYjf ynd2qMhz0lfsBHd3mF4xAwZZ/6ucrQjoXXicf8RZK8/ugixtDnWsQkTI49BvEOnGwO+q aKWsFJ/cKp0959C4Sx4/SJqXKnqVD8Tf6z3Jztf/XPQ3X/wBwV+YNqrOy+8AaTMUxO99 zoI2is3OJ+U+2BFubpfVlc9pTHnn/7TdxHbI5UMA9IggPEWwuvsziO8VuNRSwaYvB/xa o0Sg== X-Forwarded-Encrypted: i=1; AJvYcCWrPLtwdEHB7KJAwodCeUpbwlClGCMoTtwPF3RdnQRqzksrSQS2VUtbBmulCIYCTW/WBp6tq+13REfJkzMN2ZAQwXtYxywMsJNJC/I1 X-Gm-Message-State: AOJu0YwYjnZq91KZpkrlPxEl73MsCNNrCzNzL36mz/wr+NjQBxGfKPvK pCIHIN/eLilRDfYmcnOn/hp+i294cYZHMU1/gSi4fw66T8lAd8C6+vAwLQ5iLS7jnwBN2exvWNx /tMpUk8QLFQi8BQNlGA== X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a0d:e884:0:b0:5ff:a885:65b with SMTP id r126-20020a0de884000000b005ffa885065bmr136409ywe.10.1707863992743; Tue, 13 Feb 2024 14:39:52 -0800 (PST) Date: Tue, 13 Feb 2024 22:39:41 +0000 In-Reply-To: <20240213223810.2595804-1-ericchancf@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240213223810.2595804-1-ericchancf@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240213223941.2597526-1-ericchancf@google.com> Subject: [PATCH v5 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790825286174586721 X-GMAIL-MSGID: 1790825286174586721 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: keep __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. 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.43.0.687.g38aa6559b0-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 4c49a8ff2c68..4f4743d7440d 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