From nobody Mon Dec 15 21:44:52 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 270DD16C854 for ; Wed, 26 Feb 2025 06:32:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740551548; cv=none; b=kqfca+CvgOlSXPoJS33Hey2iWrCwhMolxPTZLK8LuPBv0z9TvNe+z4W4fzXBdXXi8mdxYsSeojrGcX0QUg/H9ELo6m8Gq9a52Qa3B0YKsKfUX3+/FJ9loEqytV6tzq3jZP++2jPNFxVLekvjEgUVvzJrzKuQDF7Im7YwjTSz0Qc= 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.170 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-f170.google.com with SMTP id d9443c01a7336-220e6028214so140354435ad.0 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=H10w5//bVE/VuuPpT3jxWOvydQ5U09mrxytnE4uTc19INg+FmBgllHs2ayQHOTNjdU lRmL7lcUn3/lRLog6DqO3r27f8jhdppB/6SHApjY3/26D/gLaRTG2VT1IKwgDK2v4S38 6XxaP/Oq3BkdcDS9dP6qqQeZcGrIgRc+aCq/zDx0YCOt0rX4sNXD2Q4OZkktW6E3c6tT fdWcT2WBwMpcewhTSmlj/eSBbJsbe1Lu4LX9+UKWxn1ZyddlsnkYjny3SpvG27o1eUd1 uTZSpu7alNZ0iXiDNAb7jooEaf1cDoHo5P4u4wC/8Y5Oja1Q7AbMzIKDNBacyBpq8JyC naEA== X-Forwarded-Encrypted: i=1; AJvYcCXFqGZycxQg9HxXSy6+pGTmy6Vdc12k0IujbdBtwW7meyk+ot08k5IOZbpQ7edhNFBKU3cguSg39iWZXxY=@vger.kernel.org X-Gm-Message-State: AOJu0YydfPoL+TuqzcZrC4FP8CdAX1Ot5cmkzpN8HbGxVeidMGSaIxI4 Jhp5X9CYHWpADFSyXPRmY8aqE6gMGuoI9d+nF4HrME9ZYANx+xQlF3xjUnrYu2M= X-Gm-Gg: ASbGncv3XLJDKTykyG+8ZrQNrJmjpseY7zULIzdB/0jaB6FbpA041zfMYyf8jAobggM 4x1nSOVeBVerGXcR2L86ZkuP1ssbd1Tn+ouL9959NOPPwnaUKckyEKJwjYVQfYkuQhS12hdIyiP JMrwSPzhOQVqcCzgGlnCPrguR5o7Fh/mWgqx2PtLW0PAL2pgqhY2uRZrslEC46QctUDRElYw9a2 ausugFME0wGhaw1MGaRSfmkl0t9QHk56cVjoficv2c7rCpyf/I6UCC4SACH+02jGsNLZZdAxlZu iwhkDwka16aOtzAmQE4MG+G+HUW8sbRPZLBTbhtxp0ElYJd5C6JUlPQONU14 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) =20 static bool any_cpu_has_zicboz; +static bool any_cpu_has_zicbom; =20 unsigned long elf_hwcap __read_mostly; =20 @@ -91,6 +92,8 @@ static int riscv_ext_zicbom_validate(const struct riscv_i= sa_ext_data *data, pr_err("Zicbom disabled as cbom-block-size present, but is not a power-o= f-2\n"); return -EINVAL; } + + any_cpu_has_zicbom =3D true; return 0; } =20 @@ -1001,6 +1004,11 @@ void __init riscv_user_isa_enable(void) current->thread.envcfg |=3D 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 |=3D ENVCFG_CBCFE; + else if (any_cpu_has_zicbom) + pr_warn("Zicbom disabled as it is unavailable on some harts\n"); } =20 #ifdef CONFIG_RISCV_ALTERNATIVE --=20 2.39.2 From nobody Mon Dec 15 21:44:52 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 D7AFA1E502 for ; Wed, 26 Feb 2025 06:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740551556; cv=none; b=lE+/0pa+W1UwtU7wqU1u7fcMmOdV3nnvQpTS/oflAOJRdX83G58fDLCiawIhMnG7pXCHgq+YeyZOBFkLlWhtjcSQeHzT3EY6ftWIqx7m39gzCYZd2GhYfMsGtxJuKK1iG01OreAU/l4jG/ph1WG2g22IH8HzccmO5C1ESJSq38k= 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.43 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-f43.google.com with SMTP id 98e67ed59e1d1-2fe82414cf7so675081a91.0 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=SSKyP/qOrA2LokTO7DGkXNhSkHz4VxLxVj8Tt/Pvj7eB6q4ua21jqu1vfAq194mG/A euL9Vn1/WzTm7n8lYYo1j8EVa834Pgh11sSpSgTi7+yM5wZgBkGdPquBeHHe9BfKXpgI RnevdkUH9aU1PlK3Xzh2AsY0TED53TbtfCiCHl3/oCXN33FEm/2sq/PODCkkEDVX92YL TV/GaYX9P4fhCcKDidsGpFuq3uqNV037fi+i1dj+VZl6lQNdvCGElrcpXBfJ95HoCuEU ikl11oFxWW5/BJ5d/nHLUUzL6dVqqvZ5jsbbXU0S8TcTHhkrWmxMr+6etaezLHZUKb2x niRg== X-Forwarded-Encrypted: i=1; AJvYcCW6teLbjcEHGfCgDO1mti44NhFhBuJHXitAQYO2q48kIBjBTtR0cJDQ2D88j6lJwh5WZE4hRTHXnJi6eik=@vger.kernel.org X-Gm-Message-State: AOJu0YweBtJIDjPjxed4IeNEuLH9TW5uJ7TP9MsoAA5cLgGSmQpe6For xVcUEdgmbj6rGuONSyVec1HAC2cj3ziQIIGdYqBZwt0Z9nBQAzdIuesSy/2pb/w= X-Gm-Gg: ASbGnctCw1rPIgtUSgc+M+Xh6I9aBdbuca8OTS1Iq52eVyEDE0wd7NrUWtICr8WvQnT cayWgEr6G8VuhSEObU0QU9Oywrhgbz3tv4HKCwhIxK6B++g/P3OPA5irJaZrohkIzlwx0uMoQRE CqMgvUkh7LFcYi1RGl3R1vhvn0OLab1TyhvFONop2p7OW4oXWFsLepbHo9wgGpXKmyMe9wOSmu5 1R0HUTcSAwI3PtCBYbOM/V3/MOgwmmjU7RBe497kENvuhvsBN1iic62tWmVh+C02P95oqdGqFpV nvI2FLHBOI93PQPnzZVBoUD6o8LEu29fRzIE6T2HoQdKMf/76A+EmN6wk534 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/risc= v/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. =20 + * :c:macro:`RISCV_HWPROBE_EXT_ZICBOM`: The Zicbom extension is supported= , as + ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMO= s. + * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: Deprecated. Returns similar val= ues 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 v= endor 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/hwpr= obe.h index dd624523981c..1f690fea0e03 100644 --- a/arch/riscv/include/asm/hwprobe.h +++ b/arch/riscv/include/asm/hwprobe.h @@ -8,7 +8,7 @@ =20 #include =20 -#define RISCV_HWPROBE_MAX_KEY 11 +#define RISCV_HWPROBE_MAX_KEY 12 =20 static inline bool riscv_hwprobe_key_is_valid(__s64 key) { diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uap= i/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. */ =20 /* Flags */ diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprob= e.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 &=3D ~missing; } =20 -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; =20 @@ -279,6 +280,11 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pai= r, if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOZ)) pair->value =3D riscv_cboz_block_size; break; + case RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE: + pair->value =3D 0; + if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOM)) + pair->value =3D riscv_cbom_block_size; + break; case RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS: pair->value =3D user_max_virt_addr(); break; --=20 2.39.2 From nobody Mon Dec 15 21:44:52 2025 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 EED1526773B for ; Wed, 26 Feb 2025 06:32:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740551564; cv=none; b=L3eePu4fMsMC+ed/OvZ8SNU0mzX5BlXRG7hduNyJ/zbSs4ToCY6hocRxBbSItlxVvnmKlk3+pMPuQUpTLduuIJAbYStbPCDSFcsgPn0P5MKSGU5D5CNDLlbnF9kazRk1irjebJo2umaAEyF+sODZA6efWLUCyDt8WphtDDZ76wk= 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.50 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-f50.google.com with SMTP id 98e67ed59e1d1-2fc1c80cdc8so9859379a91.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=tC4MSlWgtVzIsf20Eop+ux56w9syHPlr+DNihG3qcyeDNLZL9+DLQUn8RNYTaAA3G3 ybzhiR924DhQYT5Abn7RQ8c6SALQ4nUguHhpNYwLyI5V++o9rZZKtwLJDYI9yBWNOAwC ZHldvfvc74XyV62N3/YVIUPN3GbimhAi+dGKfFwn0OxFtlcNYU0mYAIBKB6LvG0chlt9 vRWJDm1YrKDtt1vpR7R0BdVayf7E8yvmsFSu7qPeDiAQYIRPTNgN9ATEB7t1R9B/0bAc kl+1sBsUyjfNACxaCDi9SEDTTniFbSYwB3t+MVbR8QS8R91Q+mzcVdWcSKABqGKRZ/dX SzRQ== X-Forwarded-Encrypted: i=1; AJvYcCUo0udFU0pCe6wTskKlJZBNNZ8BKgrKv0/GIfNqya4lYPvo9uOmAUFnRGNS+i+Pkyfz7ArBNep4AKKbJ+s=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5XKdGehlt/hQd/z5gbiUVp8qRX54rzHMjSmuTEGzJbtR97EM5 +sjE1Ec/nfiFGoWD2uQV3wIuHelK7LwtKissdJM72qHfCeV67xptkMLT8tIpDIo= X-Gm-Gg: ASbGncsf1VgCLNMjAFzmgWJw5Dnnrq+oQsuuAhv2MCJ+ujwZg28jqhZwcSZYsHfaVR+ rqic5+qwHT2L/zg6hemS3xNUGVtQp07V6fEoYE2tI6J5cGOWxSkSaxdjopYfcSftiv+93O/9ixV VFjK+ql/lM2ijsQKfppXvTFII59xgLyOYHLxBEele7rDRSSdFC974KpiYj+tSk6nxIRD4poXYrI MPK3uuwsyKhVB//3G3920hmcDK19ZpowhHqJ91FpFaxFBx/s+CM3yT3wYJcQYooY3akV4rstemU UVqVd21x3ktZ1Ih3Od2pkHKcwlHZMgXFUpcqsbCDzhxLxYUXgS0X3+DGybfx 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/se= lftests/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); } =20 +static void test_no_cbo_inval(void *arg) +{ + ksft_print_msg("Testing cbo.inval instruction remain privileged\n"); + illegal_insn =3D 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 =3D false; cbo_flush(&mem[0]); ksft_test_result(illegal_insn, "No cbo.flush\n"); - - illegal_insn =3D false; - cbo_inval(&mem[0]); - ksft_test_result(illegal_insn, "No cbo.inval\n"); } =20 static void test_no_zicboz(void *arg) @@ -81,6 +85,30 @@ static bool is_power_of_2(__u64 n) return n !=3D 0 && (n & (n - 1)) =3D=3D 0; } =20 +static void test_zicbom(void *arg) +{ + struct riscv_hwprobe pair =3D { + .key =3D RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE, + }; + cpu_set_t *cpus =3D (cpu_set_t *)arg; + __u64 block_size; + long rc; + + rc =3D riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)cpus, = 0); + block_size =3D pair.value; + ksft_test_result(rc =3D=3D 0 && pair.key =3D=3D 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 =3D false; + cbo_clean(&mem[block_size]); + ksft_test_result(!illegal_insn, "cbo.clean\n"); + + illegal_insn =3D false; + cbo_flush(&mem[block_size]); + ksft_test_result(!illegal_insn, "cbo.flush\n"); +} + static void test_zicboz(void *arg) { struct riscv_hwprobe pair =3D { @@ -129,7 +157,7 @@ static void test_zicboz(void *arg) ksft_test_result_pass("cbo.zero check\n"); } =20 -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 =3D { .key =3D 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 =3D 0, c =3D 0; long rc; + char *cbostr; =20 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 =3D riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)&one_= cpu, 0); assert(rc =3D=3D 0 && pair.key =3D=3D RISCV_HWPROBE_KEY_IMA_EXT_0); =20 - 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 =3D cbo =3D=3D 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, }; =20 static struct test_info { @@ -169,7 +203,9 @@ static struct test_info { } tests[] =3D { [TEST_ZICBOZ] =3D { .nr_tests =3D 3, test_zicboz }, [TEST_NO_ZICBOZ] =3D { .nr_tests =3D 1, test_no_zicboz }, - [TEST_NO_ZICBOM] =3D { .nr_tests =3D 3, test_no_zicbom }, + [TEST_ZICBOM] =3D { .nr_tests =3D 3, test_zicbom }, + [TEST_NO_ZICBOM] =3D { .nr_tests =3D 2, test_no_zicbom }, + [TEST_NO_CBO_INVAL] =3D { .nr_tests =3D 1, test_no_cbo_inval }, }; =20 int main(int argc, char **argv) @@ -189,6 +225,7 @@ int main(int argc, char **argv) assert(rc =3D=3D 0); tests[TEST_NO_ZICBOZ].enabled =3D true; tests[TEST_NO_ZICBOM].enabled =3D true; + tests[TEST_NO_CBO_INVAL].enabled =3D true; } =20 rc =3D sched_getaffinity(0, sizeof(cpu_set_t), &cpus); @@ -206,7 +243,14 @@ int main(int argc, char **argv) tests[TEST_ZICBOZ].enabled =3D true; tests[TEST_NO_ZICBOZ].enabled =3D 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 =3D true; + tests[TEST_NO_ZICBOM].enabled =3D false; + } else { + check_no_zicbo_cpus(&cpus, RISCV_HWPROBE_EXT_ZICBOM); } =20 for (i =3D 0; i < ARRAY_SIZE(tests); ++i) --=20 2.39.2