From patchwork Wed Feb 26 06:32:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13991579 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 3BA6F267B8E for ; Wed, 26 Feb 2025 06:32:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740551548; cv=none; b=MfUUG/HZ/dPQM45rvr4QBWlNnuiMoumxoXfPFYXh5WVqgrV/M7oMB3lU1b8T6mFBneI97SPTxIwbmrJK4w8zuQVZibkP53GjHN5rXevMPm7dATD3aw3yvBVYyp3jyon2lhwKIW5zd+e+MpTkr4kP8b76aRH+8OgriN+VkxEmol0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740551548; c=relaxed/simple; bh=6A+KzqvEXADqQRFxfflnjdJnKHnamJmScDSK6m9touM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tVNVgfSVDUxe8OA0oZdy+n8uA98IvY/uQAx5EPWhOtQZn9en/mwRPkxEz7bF+R2PGVfrhESfuLY74cjBo665Gt/mHei+Ddegt1hnCtmxzkaqM6HirLpOhDUSbA0qP8RIHXAzqS1rNuFeDeIp1MD0JXwSA3wDco4bRIDV9zmAZTc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=I9sdic8D; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="I9sdic8D" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-220d39a5627so98487775ad.1 for ; Tue, 25 Feb 2025 22:32:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1740551546; x=1741156346; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=bLyDt49U/qvQrnUcu83brJz3XFH8EzOsk0B+VADLLKM=; b=I9sdic8DvQaA+ur5tIZjSHBAtWVFMY0lJrbu2EEGMxGkgrG7J6EtEK+N6GU4SV52+r Q4Ce7jP/Utk5l1Bpfagyc1W9/GAfL0k4nmnY9kRiVrm8NIuj4khH9ygZO3BnzSNKSzp/ EESJ7bwGDgz8yFihIUfjn6Ok0mJjtHf463yH30n4cdP0C5nbwZMtNULyB4ZXzgbEMs4S /QZsqfCEvGKp8J4+k3ulw01qenQ9sdbSbU0YqqieXZ07ozMOzD/AqFNJKnqI03Cvy45O Sfr9FWPomBecz51A7KIxJNtoxDOFiS9ZQP0gjhglW+Wx2q0rV6o363f0DSf/F3UCWfqe k13A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740551546; x=1741156346; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bLyDt49U/qvQrnUcu83brJz3XFH8EzOsk0B+VADLLKM=; b=mMGW2I0cLN15vlaK41Ggg0LEnNzHDJ5VPgGAdt+gfn359mslCH8t9TzT2gbcGOUlOI lYtsNcj8GHCzpjXoGOxjduTJw4y0NFroNevhk07r8FczqsBpj6b/PdX9G9EEQZ2c4Rrd ZeQ8WsC89I5Y/ekeR1ePsAsDKSl9lYNuGHdANzZQBo79iQ+6E+uPldHq29Tu0+2knet9 78BQnXYB7uQCCzGl4V8Ukaaq5OPLJU21ObyHXdyeFPWq5UwfsR3zE+T5fDh6UfyczMUa LSHOHQb01ks5Z1U1CGKUXu+LVWe5aWGPZD/nxKMYrOraJgu6lP7ehQcfnk8y9XThVqBm s+tQ== X-Forwarded-Encrypted: i=1; AJvYcCX5rtbMOgeTofDjIG+0eOqs0getzUunb4CmvvKTkoLmykh7KBCkhoP8f7m5U1yKvKdfH/Yuel/VYejIYqxfRQ8=@vger.kernel.org X-Gm-Message-State: AOJu0YygaBWl5wgUrw2IgPBZl+U31KILkqIXdYI3AvXLF05DVdGD2fpn aI0SQ4+Z+w7rC15wsWme1y5WCjR6XNaMZEJLDadsbBjZPMfa001v/yIVotC2XnQ= X-Gm-Gg: ASbGncsYFSmsCtc6zGz8k7XaMnZQ3pKzcC9DwTnIoQ7uICgMneLgoOuTQHSJx4/lZ93 9IgNTPoDwQQczs7FS8OQEegkZB2nJ+i95C2bK1fHtnCXvKLYOeTREg+S1cWfB90X2JCu+IVswug Pgk3K0c0RMoZbr5O4JYHyCr89XavWaK44B25PTEGRooYZDEhytt5J+w+goTH2cKOVzKw+jCzcpy YlatA2t0khHktN3HL+x3EBPe/8JFY6Ztfs+ac3sPw1ht4I8/Pt2cl00wOcb0eL1G2r7rRM2vbuC eS/0WKLcYcqJbWc6NcYltGbxhQNSX522lCDyPKhINEWbQ27YTc8U+cpGDofk X-Google-Smtp-Source: AGHT+IFFs8SZ5lPd2kWTT1U7ETWzPeSTog8WGxZry4kav5NnRHKIbt7T9I/ZeIxsd70AumwEzTSVFg== X-Received: by 2002:a17:902:d48d:b0:21f:136a:a374 with SMTP id d9443c01a7336-221a0025a63mr347304555ad.43.1740551546420; Tue, 25 Feb 2025 22:32:26 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2fe8284f152sm682599a91.46.2025.02.25.22.32.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Feb 2025 22:32:26 -0800 (PST) From: Yunhui Cui To: ajones@ventanamicro.com, alexghiti@rivosinc.com, andybnac@gmail.com, aou@eecs.berkeley.edu, charlie@rivosinc.com, cleger@rivosinc.com, conor.dooley@microchip.com, conor@kernel.org, corbet@lwn.net, cuiyunhui@bytedance.com, evan@rivosinc.com, jesse@rivosinc.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, palmer@dabbelt.com, paul.walmsley@sifive.com, samuel.holland@sifive.com, shuah@kernel.org Subject: [PATCH v7 1/3] RISC-V: Enable cbo.clean/flush in usermode Date: Wed, 26 Feb 2025 14:32:04 +0800 Message-Id: <20250226063206.71216-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250226063206.71216-1-cuiyunhui@bytedance.com> References: <20250226063206.71216-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Enabling cbo.clean and cbo.flush in user mode makes it more convenient to manage the cache state and achieve better performance. Reviewed-by: Andrew Jones Signed-off-by: Yunhui Cui --- arch/riscv/kernel/cpufeature.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 40ac72e407b6..a8b726d0dab8 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -32,6 +32,7 @@ #define NUM_ALPHA_EXTS ('z' - 'a' + 1) static bool any_cpu_has_zicboz; +static bool any_cpu_has_zicbom; unsigned long elf_hwcap __read_mostly; @@ -91,6 +92,8 @@ static int riscv_ext_zicbom_validate(const struct riscv_isa_ext_data *data, pr_err("Zicbom disabled as cbom-block-size present, but is not a power-of-2\n"); return -EINVAL; } + + any_cpu_has_zicbom = true; return 0; } @@ -1001,6 +1004,11 @@ void __init riscv_user_isa_enable(void) current->thread.envcfg |= ENVCFG_CBZE; else if (any_cpu_has_zicboz) pr_warn("Zicboz disabled as it is unavailable on some harts\n"); + + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_ZICBOM)) + current->thread.envcfg |= ENVCFG_CBCFE; + else if (any_cpu_has_zicbom) + pr_warn("Zicbom disabled as it is unavailable on some harts\n"); } #ifdef CONFIG_RISCV_ALTERNATIVE From patchwork Wed Feb 26 06:32:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13991580 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 071D6268C4F for ; Wed, 26 Feb 2025 06:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740551556; cv=none; b=QSBN75t37M6LZ4kYV7JvLzoxe4+pew9WsB+KcVjYT0EpEx+96e8cYdZ5r99P+DFCSlGyA6zzfg40ajdblWKiOKj/6pEiZ97TlZwiA5UXaW61WcryRwBZJruxZpMcrazcQzJjgjfcvu0BCE+zUwpnv5FdTeckMyqslQdnE2n0g3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740551556; c=relaxed/simple; bh=lgZ8JylI1sS39qvmCo0egec9M/xBN/1P8DIeRTMPV1s=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PiC48xffy9iIOWsF1vw05Z7xCnKCkCW9RP3B/zNbQNw3z+qpgeucLVyfVHU0vOVe/Eqo+U+kCCnXczbGY82HTgCO771hKNuEqBqThR/nmIWDNeqbrOUhDFGRw2ogt6ah1Fy8TYpOGJ1CGx/PxjuuxQh3EbrmWXInL7kcdJmH06Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=iU0yd9Wj; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="iU0yd9Wj" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2fc0bd358ccso12694268a91.2 for ; Tue, 25 Feb 2025 22:32:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1740551554; x=1741156354; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=T2XeNxbHPPMmfxCJjw+vu4vYKA8Lsa9L2O6TiyKPYYk=; b=iU0yd9WjPYOFGUiwfc8FcZRkiqP1GN6SkcoNFCCrnfHLTXIOOKTmeTknWwLdW9PemE rg8JYaQb7TJvw3IsNtG7dcKQ6twTewv1igqdNce67lS/Znw0Zx2Fm73byN4j/SaNV+M6 hSLKy2ekMBUac/THi+XZYYQwjgSE+WsXvktk37eHe6WF4evJu570dEmODC/yBZCujJh1 P6ofFi1nH+jq5C7ataZHociV9DW7jYF9gFxfDvzZAaTMIeDNTu0BT+Il/Fj5LT/Vz2I0 d828Laf/atsiwTUoYnWtoolDtjmfnGLACetCVThA6Ian8XHSpc3cR5Fjz3FmZDv/ltp+ 510Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740551554; x=1741156354; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T2XeNxbHPPMmfxCJjw+vu4vYKA8Lsa9L2O6TiyKPYYk=; b=rN1H9wJ1bjIEv/mg771YJSvHfw6aoSlMGwe9F8NxAjPBAPjaoWlqpWWBWMGiuVtU+B MQMjUw/I4op7NSCxz7mh5Cl6i+r4WkXiaKvNeN4J2ShnglskvF7G0HIKj6oNjUn6dESO mE9Q8i1izxbjdQMgp3OCh6ZWU+fM8AIU0kM80ek7INE80ZvFt32YSrOzMaEzNSQ8Y/7d dhy83LAvxn439Kv6fBDlcvcIBkA42gOToGjrYzAghCxkn9RMiS1GWe5qVEgmolDFddWJ miO2+pDl9jo3puVnN1JseUUj2lgYPaveVZguaqRgltSSoElK8O1DcsTSPGhU6xkXlHW2 qsWQ== X-Forwarded-Encrypted: i=1; AJvYcCWG5Tnr5YLVaW2BOWioPr5OF0CsaodM85k55g96S/tyit5aEFDy7KI4WAQRYlSqpv2+L2QiAkPdDzQYdlI5Woc=@vger.kernel.org X-Gm-Message-State: AOJu0YxO8Ja4QzBch9/MTqLA5d/tNn/aLLUQlmDHcy9+VRpJd0RRNs8C NE/YuJQ/4Rpvt8lpJH6lE/Mv6+CseqA7mLSuzxMNAkVVyMfnCAGXO/AMPJ4KqXc= X-Gm-Gg: ASbGncumpgbYsVXCviWIO2Lfck2Gkmf24U2KzV5IxE3iroFTw8oSXMlwYFvQ9dDCUDD 74LzKFiudGl3pb/LwTqWNTZZu5u1XdWJvyFsmycF9ONEBG3o9iZFGGZpf+KeAGIzmkzikBpygtF 6rSLPQKJ+lu9qcRxWj+J7OblrTUtylOPGxO1RT7oSIg1j84O8sYOUNws2Kd2k7RMrPWqR0dsXBR 4DiogixFJukTxfni08eFMQT0C4BlzoIiCFVrtOWsnY1YEdEjHYHb9MBUbyUUNWwGCM/UPIRiwiY YU/9srNbE5UyIf6SdwuI/Dan/a3zqD52AhrAyjK9HYPe5PByzJuyPGzNTd8y X-Google-Smtp-Source: AGHT+IHwvV7I7NlJ9jqPsn3374kntVoW/0IqCvSXn/+vGzdzMVefrgZflgML33Q88VI8BAdqqvkLhA== X-Received: by 2002:a17:90b:2e08:b0:2f5:88bb:12f with SMTP id 98e67ed59e1d1-2fe68ae74ebmr8882080a91.21.1740551554107; Tue, 25 Feb 2025 22:32:34 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2fe8284f152sm682599a91.46.2025.02.25.22.32.26 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Feb 2025 22:32:33 -0800 (PST) From: Yunhui Cui To: ajones@ventanamicro.com, alexghiti@rivosinc.com, andybnac@gmail.com, aou@eecs.berkeley.edu, charlie@rivosinc.com, cleger@rivosinc.com, conor.dooley@microchip.com, conor@kernel.org, corbet@lwn.net, cuiyunhui@bytedance.com, evan@rivosinc.com, jesse@rivosinc.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, palmer@dabbelt.com, paul.walmsley@sifive.com, samuel.holland@sifive.com, shuah@kernel.org Subject: [PATCH v7 2/3] RISC-V: hwprobe: Expose Zicbom extension and its block size Date: Wed, 26 Feb 2025 14:32:05 +0800 Message-Id: <20250226063206.71216-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250226063206.71216-1-cuiyunhui@bytedance.com> References: <20250226063206.71216-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Expose Zicbom through hwprobe and also provide a key to extract its respective block size. Reviewed-by: Andrew Jones Reviewed-by: Samuel Holland Signed-off-by: Yunhui Cui --- Documentation/arch/riscv/hwprobe.rst | 6 ++++++ arch/riscv/include/asm/hwprobe.h | 2 +- arch/riscv/include/uapi/asm/hwprobe.h | 2 ++ arch/riscv/kernel/sys_hwprobe.c | 8 +++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/riscv/hwprobe.rst index f273ea15a8e8..d91e39e19ea0 100644 --- a/Documentation/arch/riscv/hwprobe.rst +++ b/Documentation/arch/riscv/hwprobe.rst @@ -242,6 +242,9 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_EXT_SUPM`: The Supm extension is supported as defined in version 1.0 of the RISC-V Pointer Masking extensions. + * :c:macro:`RISCV_HWPROBE_EXT_ZICBOM`: The Zicbom extension is supported, as + ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMOs. + * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar values to :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_SCALAR_PERF`, but the key was mistakenly classified as a bitmask rather than a value. @@ -303,3 +306,6 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR`: The xtheadvector vendor extension is supported in the T-Head ISA extensions spec starting from commit a18c801634 ("Add T-Head VECTOR vendor extension. "). + +* :c:macro:`RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE`: An unsigned int which + represents the size of the Zicbom block in bytes. diff --git a/arch/riscv/include/asm/hwprobe.h b/arch/riscv/include/asm/hwprobe.h index dd624523981c..1f690fea0e03 100644 --- a/arch/riscv/include/asm/hwprobe.h +++ b/arch/riscv/include/asm/hwprobe.h @@ -8,7 +8,7 @@ #include -#define RISCV_HWPROBE_MAX_KEY 11 +#define RISCV_HWPROBE_MAX_KEY 12 static inline bool riscv_hwprobe_key_is_valid(__s64 key) { diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uapi/asm/hwprobe.h index c3c1cc951cb9..8c706cde3777 100644 --- a/arch/riscv/include/uapi/asm/hwprobe.h +++ b/arch/riscv/include/uapi/asm/hwprobe.h @@ -73,6 +73,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_EXT_ZCMOP (1ULL << 47) #define RISCV_HWPROBE_EXT_ZAWRS (1ULL << 48) #define RISCV_HWPROBE_EXT_SUPM (1ULL << 49) +#define RISCV_HWPROBE_EXT_ZICBOM (1ULL << 50) #define RISCV_HWPROBE_KEY_CPUPERF_0 5 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) @@ -95,6 +96,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_MISALIGNED_VECTOR_FAST 3 #define RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED 4 #define RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0 11 +#define RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE 12 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */ /* Flags */ diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.c index 04a4e5495512..69fe9da320dc 100644 --- a/arch/riscv/kernel/sys_hwprobe.c +++ b/arch/riscv/kernel/sys_hwprobe.c @@ -107,6 +107,7 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair, EXT_KEY(ZCA); EXT_KEY(ZCB); EXT_KEY(ZCMOP); + EXT_KEY(ZICBOM); EXT_KEY(ZICBOZ); EXT_KEY(ZICOND); EXT_KEY(ZIHINTNTL); @@ -161,7 +162,7 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair, pair->value &= ~missing; } -static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext) +static bool hwprobe_ext0_has(const struct cpumask *cpus, u64 ext) { struct riscv_hwprobe pair; @@ -279,6 +280,11 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair, if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOZ)) pair->value = riscv_cboz_block_size; break; + case RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE: + pair->value = 0; + if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOM)) + pair->value = riscv_cbom_block_size; + break; case RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS: pair->value = user_max_virt_addr(); break; From patchwork Wed Feb 26 06:32:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13991581 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 CD6771E868 for ; Wed, 26 Feb 2025 06:32:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740551564; cv=none; b=vBasoMEVYOBN5iYQppFsMIP6cijBlLnsBqOB82HYXpsfxGiQVBooNNnSWOdeboE9wU79MJO9xi17iw/gFGGGTqTS9arvdW4Hj/zC2rcxjrt0fUgaLo3uHcTaBF7O0X7Jl1SeIWlSECcHDgIL2o24C4Xaip1hJ0SLfExQp+JeQ3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740551564; c=relaxed/simple; bh=NqOUrka99DSUi18FOpq9XilJAxI+Dx6U6EraUGvZnFk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LqU8974bZ3srWVVMo1EO8vLceCF1+xAWiy1Aoay3LjHqm5l7HEfNAYVHb/Yz3hSDOqhqFDDySXcNvjIf7vEB+CERjTOe1P+BTW5CzhsbCyQrRgK5o4rO/RWBV1JJgIsUtvOrM+gmPOE4BobJk+F9jAfoJlGOcl7u+D0oJ3gss90= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=cClNN/kK; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="cClNN/kK" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2fc1c80cdc8so9859380a91.2 for ; Tue, 25 Feb 2025 22:32:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1740551562; x=1741156362; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Y6H6/Xpe5szI3425MURKDC2kUnYsqHlXT/4n1BN4R7E=; b=cClNN/kKf3Ag/Jf81Njzu/dr376IYzR9AYZNF6pUbWSn/TTxadExPYirR9HUAKLman 0oHXyz9mW7wz05rEZT9wQXM1YA/Td8EKmJqXwqlPVMgSAI3FbgBHYr/8bVkkhx4soBI0 uadfr3ZnIgWuI2jTLHchGbBjiTYC9H/RN1F2y+Vk4RdibBtPJDnZj045iWw4AVPWKegW 739XSl51rHWryG8/Tr9e/VtXjM+ZCmA1Jk3Ij8q9worThYF2PEymX1uxCI61013ykAam WtQwwTReGh4g24D0WHBHZmZzYJ4Epumu6T3bJC72rbX2WCG6fzREe8gKla4Ly8dxbh7t O5dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740551562; x=1741156362; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y6H6/Xpe5szI3425MURKDC2kUnYsqHlXT/4n1BN4R7E=; b=GLpMZ4DkUEw4BVWujW/nxtzj9EJqxUfyoNRXXrbS5iJu0qUa71FTUBNR/HUbP07L/h /hUL8+DfCoDDu6fXht+100oJtAQxNAkQqFF6Kmo6FbgyTAjVJ2/+LwB684d5qqJKbzDU Zq8YllxlmDa+bJz3jCnNHKWGnd8CnKVg6/jCnA+xjfuR70x/O4xMbmusnRBGIsnmh6YP 2N0LcEjtRQr+uvAaM0jokfN80HcqOo1jHw73Thh+quJ6jR6JMmvJlWtgodBRzApyzwXr aZTgvXIv+mF/5xnjEQ6e9UxB7QSGL/sgXdesGBmfcUGurcY7WxgOB20P6rMw8XqlOeY1 eWQA== X-Forwarded-Encrypted: i=1; AJvYcCWqZUDWDwvykRdEl5wOmavqlWnKM5xJCCTk9lHGmaa7ha9F5Jw38OT4nRzqCI/fa8dzViSPfQEm2bUdmR8wlVQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyJD7m3UXD9nZ7X+bVVDbifKNpUspYuimN8EdzvxEnN8ialUj5b s/FdWJ8+rxxn+bYjlQrtfPa7qP6sg5UQ8lemwQkAtfW8y+tHRexeT5zQWadupt4= X-Gm-Gg: ASbGncsyQNzv0rhNwGlRnGLS1KLLHdvG3sLfpCrKKIiCBb2+Gd/UETO3qV/aaQSazrX dkqqNWC6RyluLlLIzZcBv7B1MSuchZopYPNZ+cziGshHFxM78jcTJ2gwmTRo97G+wj+gRE0mlTw wAnRILPcU2NcCw6ugOe9r9ReiMnha9UqmzZ7zu8s20+wEzqSL/qrMyV9X5ylxA8ePpxb3ToM03S 7IxgT2HBCIrHQtLPiG6gRRSA1w6L7OXVkobYh0OOaMyeXf+phOIzjDzC0yIZBX6bW01+ge4os4a j4+13zy2M4NX3iksJCWgyOgvP/00a77Pr9F01+wIgFDbQykTjlzBoinlriYb X-Google-Smtp-Source: AGHT+IEdlez3a8zCoVcQhSExdtKJWaxRweBj5/bzxHVZ9RIDHfLdLR/jDGw16LdyFBY45f4pDOd51w== X-Received: by 2002:a17:90a:cf8e:b0:2fe:7fea:ca34 with SMTP id 98e67ed59e1d1-2fe7feaca86mr2608925a91.32.1740551562148; Tue, 25 Feb 2025 22:32:42 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.253]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2fe8284f152sm682599a91.46.2025.02.25.22.32.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 25 Feb 2025 22:32:41 -0800 (PST) From: Yunhui Cui To: ajones@ventanamicro.com, alexghiti@rivosinc.com, andybnac@gmail.com, aou@eecs.berkeley.edu, charlie@rivosinc.com, cleger@rivosinc.com, conor.dooley@microchip.com, conor@kernel.org, corbet@lwn.net, cuiyunhui@bytedance.com, evan@rivosinc.com, jesse@rivosinc.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, palmer@dabbelt.com, paul.walmsley@sifive.com, samuel.holland@sifive.com, shuah@kernel.org Subject: [PATCH v7 3/3] RISC-V: selftests: Add TEST_ZICBOM into CBO tests Date: Wed, 26 Feb 2025 14:32:06 +0800 Message-Id: <20250226063206.71216-4-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250226063206.71216-1-cuiyunhui@bytedance.com> References: <20250226063206.71216-1-cuiyunhui@bytedance.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add test for Zicbom and its block size into CBO tests, when Zicbom is present, test that cbo.clean/flush may be issued and works. As the software can't verify the clean/flush functions, we just judged that cbo.clean/flush isn't executed illegally. Reviewed-by: Andrew Jones Reviewed-by: Samuel Holland Signed-off-by: Yunhui Cui --- tools/testing/selftests/riscv/hwprobe/cbo.c | 66 +++++++++++++++++---- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/selftests/riscv/hwprobe/cbo.c index a40541bb7c7d..5e96ef785d0d 100644 --- a/tools/testing/selftests/riscv/hwprobe/cbo.c +++ b/tools/testing/selftests/riscv/hwprobe/cbo.c @@ -50,6 +50,14 @@ static void cbo_clean(char *base) { cbo_insn(base, 1); } static void cbo_flush(char *base) { cbo_insn(base, 2); } static void cbo_zero(char *base) { cbo_insn(base, 4); } +static void test_no_cbo_inval(void *arg) +{ + ksft_print_msg("Testing cbo.inval instruction remain privileged\n"); + illegal_insn = false; + cbo_inval(&mem[0]); + ksft_test_result(illegal_insn, "No cbo.inval\n"); +} + static void test_no_zicbom(void *arg) { ksft_print_msg("Testing Zicbom instructions remain privileged\n"); @@ -61,10 +69,6 @@ static void test_no_zicbom(void *arg) illegal_insn = false; cbo_flush(&mem[0]); ksft_test_result(illegal_insn, "No cbo.flush\n"); - - illegal_insn = false; - cbo_inval(&mem[0]); - ksft_test_result(illegal_insn, "No cbo.inval\n"); } static void test_no_zicboz(void *arg) @@ -81,6 +85,30 @@ static bool is_power_of_2(__u64 n) return n != 0 && (n & (n - 1)) == 0; } +static void test_zicbom(void *arg) +{ + struct riscv_hwprobe pair = { + .key = RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE, + }; + cpu_set_t *cpus = (cpu_set_t *)arg; + __u64 block_size; + long rc; + + rc = riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)cpus, 0); + block_size = pair.value; + ksft_test_result(rc == 0 && pair.key == RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE && + is_power_of_2(block_size), "Zicbom block size\n"); + ksft_print_msg("Zicbom block size: %llu\n", block_size); + + illegal_insn = false; + cbo_clean(&mem[block_size]); + ksft_test_result(!illegal_insn, "cbo.clean\n"); + + illegal_insn = false; + cbo_flush(&mem[block_size]); + ksft_test_result(!illegal_insn, "cbo.flush\n"); +} + static void test_zicboz(void *arg) { struct riscv_hwprobe pair = { @@ -129,7 +157,7 @@ static void test_zicboz(void *arg) ksft_test_result_pass("cbo.zero check\n"); } -static void check_no_zicboz_cpus(cpu_set_t *cpus) +static void check_no_zicbo_cpus(cpu_set_t *cpus, __u64 cbo) { struct riscv_hwprobe pair = { .key = RISCV_HWPROBE_KEY_IMA_EXT_0, @@ -137,6 +165,7 @@ static void check_no_zicboz_cpus(cpu_set_t *cpus) cpu_set_t one_cpu; int i = 0, c = 0; long rc; + char *cbostr; while (i++ < CPU_COUNT(cpus)) { while (!CPU_ISSET(c, cpus)) @@ -148,10 +177,13 @@ static void check_no_zicboz_cpus(cpu_set_t *cpus) rc = riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)&one_cpu, 0); assert(rc == 0 && pair.key == RISCV_HWPROBE_KEY_IMA_EXT_0); - if (pair.value & RISCV_HWPROBE_EXT_ZICBOZ) - ksft_exit_fail_msg("Zicboz is only present on a subset of harts.\n" - "Use taskset to select a set of harts where Zicboz\n" - "presence (present or not) is consistent for each hart\n"); + cbostr = cbo == RISCV_HWPROBE_EXT_ZICBOZ ? "Zicboz" : "Zicbom"; + + if (pair.value & cbo) + ksft_exit_fail_msg("%s is only present on a subset of harts.\n" + "Use taskset to select a set of harts where %s\n" + "presence (present or not) is consistent for each hart\n", + cbostr, cbostr); ++c; } } @@ -159,7 +191,9 @@ static void check_no_zicboz_cpus(cpu_set_t *cpus) enum { TEST_ZICBOZ, TEST_NO_ZICBOZ, + TEST_ZICBOM, TEST_NO_ZICBOM, + TEST_NO_CBO_INVAL, }; static struct test_info { @@ -169,7 +203,9 @@ static struct test_info { } tests[] = { [TEST_ZICBOZ] = { .nr_tests = 3, test_zicboz }, [TEST_NO_ZICBOZ] = { .nr_tests = 1, test_no_zicboz }, - [TEST_NO_ZICBOM] = { .nr_tests = 3, test_no_zicbom }, + [TEST_ZICBOM] = { .nr_tests = 3, test_zicbom }, + [TEST_NO_ZICBOM] = { .nr_tests = 2, test_no_zicbom }, + [TEST_NO_CBO_INVAL] = { .nr_tests = 1, test_no_cbo_inval }, }; int main(int argc, char **argv) @@ -189,6 +225,7 @@ int main(int argc, char **argv) assert(rc == 0); tests[TEST_NO_ZICBOZ].enabled = true; tests[TEST_NO_ZICBOM].enabled = true; + tests[TEST_NO_CBO_INVAL].enabled = true; } rc = sched_getaffinity(0, sizeof(cpu_set_t), &cpus); @@ -206,7 +243,14 @@ int main(int argc, char **argv) tests[TEST_ZICBOZ].enabled = true; tests[TEST_NO_ZICBOZ].enabled = false; } else { - check_no_zicboz_cpus(&cpus); + check_no_zicbo_cpus(&cpus, RISCV_HWPROBE_EXT_ZICBOZ); + } + + if (pair.value & RISCV_HWPROBE_EXT_ZICBOM) { + tests[TEST_ZICBOM].enabled = true; + tests[TEST_NO_ZICBOM].enabled = false; + } else { + check_no_zicbo_cpus(&cpus, RISCV_HWPROBE_EXT_ZICBOM); } for (i = 0; i < ARRAY_SIZE(tests); ++i)