Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp212340rdh; Tue, 13 Feb 2024 14:40:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVBWHhYoYFs+qsCI3JDy/Gk0AsR5OD7JysTaqf91aDaPfFcTRFXh1AlIGheCB7//UU0HpHzeXtEYUG8cRo1X14A8mldqgZ+7lQp8d1awA== X-Google-Smtp-Source: AGHT+IHsgaisyoKI45NANrAEkkvBg6tEOH93Vb9AclaXVlnPk6JKhOSXx56k5y1ILkHLc0OSSysx X-Received: by 2002:a05:6512:3d25:b0:511:7746:5687 with SMTP id d37-20020a0565123d2500b0051177465687mr845944lfv.24.1707864007722; Tue, 13 Feb 2024 14:40:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707864007; cv=pass; d=google.com; s=arc-20160816; b=zj2r/O8unZR3zbrPZ3iqfrok7qbsPlp0FDFyPf1dwaXIQyU161KDhFI7WQV1o2rdqc Ltg2f8azHQHoFAVOy9zu36J6vxYHkpNzcvv4cExe/242E5ftU1vJTsAY1D4jVSB7lJE4 XQrqPWv+ASEUBEzzBfTiV2jVyworWu5duW4R2UBaKd/b9DZudJ+VyUjcImO/oQ+kZ6XL wfHzvgylOnDva7H0oaTrZGQg53wO/917eMUD9w1SpO7vugTQaF1sEfJPriX/xEzww7uO 8SgvntC8J/LqJnYTCxhYL/lvWScjzQOrMv8gg5/QXHwcR9cNSG0HOEog6dkMv9svpuyT QQgw== 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=q9YxVKlwPPisplj9fNAOIgP/MaC1rMSGuVvZDTvY6E4=; b=IqIfW6LG9eSbgfilKQC2Ky1iD7vcYtbz6UJ0VQiCqLX3OboHOybCCZabMWZPgCXaI6 u8oksWDg9A7HKu3uGh6ctRhMzOXitUsj1vA2ySL026fEFdQa1ANJPpSpa1v5uJSA+Ce8 MVryP83/ZuNJj+joWqrjiicQSPyNYhRGmY6I0otuYeefiFRdW+9iR5fsqaoc86G6eMuw FQgVW8Pp8zrCFUaztoHgxI04Xz7rM5+YBCup5fJIiFCRGtGjFnqJz268Lx0p9O8QVgXP U0O7KlkrLE+8BXCgriZDiHLhs2L8DOZJqwYI0xfmuVGPBYrDQO6jUAQUO3SJGAXHvX4Q PnwQ==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64472-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCWCywOcDvaLAh46hFVtGegnpfUlGuHHZKFRodu/11mIkbV4u2mZEBObh643G2MOpfDjgCEBWyHMUQsq0smjWMHkrAD+yFXseK29ThUBsg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dc18-20020a170906c7d200b00a3d303d7c53si270338ejb.726.2024.02.13.14.40.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 14:40:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64472-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=@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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64472-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4D4211F29BBF for ; Tue, 13 Feb 2024 22:40:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64942626DB; Tue, 13 Feb 2024 22:39:56 +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 Content-Type: text/plain; charset="UTF-8" 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(-) 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 -- 2.43.0.687.g38aa6559b0-goog