From nobody Mon Dec 15 21:45:39 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 0DDD1229B21 for ; Wed, 15 Jan 2025 02:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736908864; cv=none; b=GsEjBy/vjyP3O0giQGuh9pI5JxfsjZPb6/z3vThiB7RbdrXQYGbTWAEd2b2Mi4UifPcTeAgni6cy2RNhkP7H4FUDIq24F7jhWnsLyeFRUZaeq+MgUIYPWl8zCEXjtazpzsffh5iRCzbJ70mGFStqugRYioAGvx7T/PHArz1VSqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736908864; c=relaxed/simple; bh=G+K9MvSpAIpwDwMmunI0YSdJnqQJGTJZcC3ONEVxX60=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AjMgDzCilf3jEURCofFYKPKFWhSTaOAB4DmIQgcYAmNWoU2JVL4E+JzbBojY61uPZGoBhKhDns3zSVl6AzEmbEgQHWoDHiXrEz8LnXlv8hU+19c5xX8p9dvdoHgkDSCSfJa2CJuQw2g35u2LEaB6kzd96lIA8sdfpBsaQ99ouS8= 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=N9vqMPRe; arc=none smtp.client-ip=209.85.214.178 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="N9vqMPRe" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-21649a7bcdcso106252415ad.1 for ; Tue, 14 Jan 2025 18:41:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736908862; x=1737513662; 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=n+lHU8O3OzxopxeMRFW7AZqN84liiT6mDTuuIRoGMNs=; b=N9vqMPRelNsEAHkyRKo7lK/eY6HPffqDkwqLLl9XD08GJblRfKsJKzA+709019O5Zg fCTzTkG5qCJKrdSP1NZTC5783REeByOZADHoMnRAfy1MgewDNe6AUPmyvmb3O5+i0PAL FSIdFfIGCxXploC4DPx7LPCtiX/lom8JiOdfJOIRYrsnWGlwUYssHiZmof8hCgf9PUcs ga7PSF/fnvpO2Z6Ubz/UmZcZWbyN7mUc+t53sd4HWPhJaE5M3tI7uB97SXouLLrTY5l2 6rIE2Pt/NY+jDZpAW8U422tpJRhCo8sIQzbqeRhDrkBEJOu2i8G/Q+WFwVjci6oC1cfe IQRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736908862; x=1737513662; 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=n+lHU8O3OzxopxeMRFW7AZqN84liiT6mDTuuIRoGMNs=; b=wmXN3pVMzrJvWhtio9l8fcI80eqh8hfLLfcOmTlqbv5VQB1yODzOpVxd3InGVwq78Y KMRGIYSfBfIP3ewe7e7lKQho7f0ueoip6OkUqByPbqyQWfUIueC3jhgXFdYA8nh1hnbl 0egwjux5pJc4RzN7f5C2W3Gz/l31OVmq2hOX+OR4oWWxwef2YpoUnBtvNA+Gx8mUVWxX 7wpV3DY+6FfXoYzJ5V9Q7txcNGWCpLLErf+fKjGvfX79mbz6Mnka/Ess6Ij72m0+iTi9 sVHZ/YMpC9USxsM4kHgon+tbW2sc03VW/vqWczTecE4d+Sl1/wTuLT90PoxE9VaMjRi8 iFZA== X-Forwarded-Encrypted: i=1; AJvYcCU8jhRt0N1HWNMazB5GuOHP1PN83JfGWE1Ejtdjp7X5H1Jecd68HDJgVizfST3ah2xK60GjOLwY3gUTUe4=@vger.kernel.org X-Gm-Message-State: AOJu0Yxa0i3gQ8wfsUpOazJR2XJzkMTfTHljvyctkbgV9dwWBt9Nk47P +VS9YixLUkOh/dbsLejGV5+p/bhBGwanKNRGNxHyRm5EIKkDAiZXM7q9VmBaLo4= X-Gm-Gg: ASbGncsm990QKAYvLtjqEYqEjPBzm5DmDl1PkQTSxA6Gofw4khGw97pPWZ3j2vewXkX kEbbY6C8hSTG+3kVy/6HuLi/6o/noClGFLaT7vcUqJqSs7FKPC0ElsHhAQlKGMWX90h2pQviV12 Ag7RN7oCkMx3fvAH643Ss3tJN1j1TZEjUWU9R196KIvmN4pq3DO9TWDihvv5/HuHpVysbe7XGKk tAAhcply5ZZ5gYYQZU3MCzeGmDbujpI0vVUidgVTPNUNIvwcACQjGsXLSg27qPFnt2Q4rvp4mhd AqKGJTtIqNT61z4= X-Google-Smtp-Source: AGHT+IHRs+ZLjJaMOCMFOSev5yey8o2EV/Ai+cdpqR0LkTXM3ZpNmIhiXmJyiWzASfW23X6Ls0/4fg== X-Received: by 2002:a05:6a00:4502:b0:724:f86e:e3d9 with SMTP id d2e1a72fcca58-72d21f64f72mr39087001b3a.14.1736908862297; Tue, 14 Jan 2025 18:41:02 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72d40680e67sm8321841b3a.139.2025.01.14.18.40.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Jan 2025 18:41:01 -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 v5 1/3] RISC-V: Enable cbo.clean/flush in usermode Date: Wed, 15 Jan 2025 10:40:22 +0800 Message-Id: <20250115024024.84365-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250115024024.84365-1-cuiyunhui@bytedance.com> References: <20250115024024.84365-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 c0916ed318c2..60d180b98f52 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -30,6 +30,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 @@ -87,6 +88,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 @@ -944,6 +947,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:45:39 2025 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 27E3722E404 for ; Wed, 15 Jan 2025 02:41:13 +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=1736908875; cv=none; b=Pk1CzSevpR9AB9ePaS0of/VXx/lqmjRI2SKdAmyO1Ef7c8rzseDyZ/V+iA/bgoRAjKhMhnto2s1yTAd8qb4qxQAjPZblAEXDo/w1Y+/I7mZygbssgHS8IKLppKYd9S8Up1X7oSAMvPhy0jA7yBw+B6xRKuzkP59DLPpGoaxLY3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736908875; c=relaxed/simple; bh=UbnhKwBKY9x09fUUnRX3kFsgKloXYVJNYiZhUVyRZko=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iBt7Y0Hvd7ZNifKUCZ8i5KIRLz7cfGMNgVw0t3o/QXRN2ybh6nX+cbACiaICPpyunpwCkZVlu6mIARdrua1FPDijKqRvorrOCZRgQHrF8wyWnGRKcMQvSxowe5HnpsYel3dt1JkU6emc2iBbOUMJ7aPSCw2QAVYggmRKIePPLWs= 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=VRPenhMG; 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="VRPenhMG" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2156e078563so92086765ad.2 for ; Tue, 14 Jan 2025 18:41:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736908873; x=1737513673; 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=rT2pVksutJIId1LNuVU67y8Yu8hoO+3APrCNZYHddJA=; b=VRPenhMGl2VdnAoOWKNNvMXg151afzX0ScKfkXG/HXUL5EKJAD9NeosN5jagfqnd2r iYMQhhFKo5i9MWiO0UC2IdZvYIdLe3xEyQ7S45Lts78SoMu0kdYo0xRoYr0Or7lrHtbq VhGMACaZg5BeTFBxRXqIe9K+bjCzyQMHvZVaeg9nWUfD4BMqiUXPHoFNQjHQNGy/+vcd 0G7G9O2+FyC3a8TnJIeF+usAe43LYCqABMTxHEqBOcR3jaH3t7hnRSVpjUBXuBGHEVIU H1g98n7oCo+GiYCA7zvTBzn6EHXZtjp9sh93RxAL6u5n+vQDo+1OcNRsYIqZQq/14ryv TQvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736908873; x=1737513673; 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=rT2pVksutJIId1LNuVU67y8Yu8hoO+3APrCNZYHddJA=; b=HM7Xc0GkLBUIOgzYM632Ejfozu9AEwr0HU3k99XwAOVQql+AgjuV3l/q5Q1J7Nj2WG Yvrx7qJEIyVWCLNjkzXYp/jqvwsHtfwSe27XiRBQUxDsRD+/JyXo29quHKdMo/b5PK8V idBdzwtKxVLOaSkexnfhConBopgQPzxK45YtahperOzrcglyHhiIauZQac4z7Cdee5HM sh2tSb9DvR3LtKGIzGSKvTYaL2mz8AtWl0Z2DDAG6exCBu4Yp7mlZlKZy8LMu/LL16F+ KM5jy6FFT3tSLbFMv8XNG0WUAlY6AGevcmfQr+DDS+kjAGOdPNgI/Cdiyq0vAZIkpQOB AU8g== X-Forwarded-Encrypted: i=1; AJvYcCWh+iwvzMAI6YriuIzeBzfb3agb6DBsDs070ZJswbaeIAuTWrkoDXGhy0g8DkxURq9Ez6oT1nNMxjRfWJY=@vger.kernel.org X-Gm-Message-State: AOJu0YyrmPDr84NQSVQK5lxI+RQBArHmcv2y/PZHmsMYs3cc9nukBgh1 oFkbWCZfocvRrASYTAAq0fCTiat+bE+eQ/X6tbbQNlccoNKHt+Xrxjg/lcs+OiQ= X-Gm-Gg: ASbGncszWtDds8MBUUK0UegjLmmFX3B6Tyxq4Do+wpxh/J+NBDGK1u7/aZz7fpqI1Cs uFwA8kkM6i7yRXkOnOwOMDzg/9pwhXTdjWT9hSTtaeWsPkgkvLsCjUfQiN1KxPeadgfXwHXTuPB 2ryM5IUss+H+YuuvEGBDU5UyBGdhiJIlaUJesic7k+3dWZszmR6zgkqIa47eN1DIAASTGqu9f4x 1bZn2m3317AuO4iYOyw5nF5wCOnYqm7BHlL97hcAivFFu/IiEQjQnGQ8gjyIynLKxVs7C460GKH cU5dYrW2VfnD/IA= X-Google-Smtp-Source: AGHT+IFZrkOo1kKHka7uEN46rgjAYm+/LF8Olw/yHOPwTxzyq6Nj2yHjAD5mXgPxO3CwPQSd5i6+xA== X-Received: by 2002:a05:6a21:151b:b0:1e1:ae4a:1d48 with SMTP id adf61e73a8af0-1e88d2fd01emr46853864637.40.1736908873272; Tue, 14 Jan 2025 18:41:13 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72d40680e67sm8321841b3a.139.2025.01.14.18.41.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Jan 2025 18:41:12 -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 v5 2/3] RISC-V: hwprobe: Expose Zicbom extension and its block size Date: Wed, 15 Jan 2025 10:40:23 +0800 Message-Id: <20250115024024.84365-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250115024024.84365-1-cuiyunhui@bytedance.com> References: <20250115024024.84365-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. Signed-off-by: Yunhui Cui Reviewed-by: Andrew Jones Reviewed-by: Samuel Holland --- 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 | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/risc= v/hwprobe.rst index 955fbcd19ce9..21323811a206 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. @@ -293,3 +296,6 @@ The following keys are defined: =20 * :c:macro:`RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED`: Misaligned vec= tor accesses are not supported at all and will generate a misaligned address fault. + +* :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 1ce1df6d0ff3..89379f9a2e6e 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 10 +#define RISCV_HWPROBE_MAX_KEY 11 =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 3af142b99f77..b15c0bd83ef2 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) @@ -94,6 +95,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW 2 #define RISCV_HWPROBE_MISALIGNED_VECTOR_FAST 3 #define RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED 4 +#define RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE 11 /* 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 cb93adfffc48..04150e62f998 100644 --- a/arch/riscv/kernel/sys_hwprobe.c +++ b/arch/riscv/kernel/sys_hwprobe.c @@ -106,6 +106,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); @@ -278,6 +279,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:45:39 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 7704F22DF94 for ; Wed, 15 Jan 2025 02:41:24 +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=1736908886; cv=none; b=kurVn11B9T+QIMs6hzltjcZhln/hq2Aybnrg0eMu2td31PliKXK+Q1qNR+0UEzt6ctacnH7ODTm3YOtB4eaUzhsbp4K3od/w40UoMX6JGrIcqaBwf1EXXVNwjJou/n5axXyKrhYNAKJJi+cH+u+A0AXKRk/3XkR3RGZrwtGkWa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736908886; c=relaxed/simple; bh=NqOUrka99DSUi18FOpq9XilJAxI+Dx6U6EraUGvZnFk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HbQgoNp73Ybk6RdE/aH9wYsDQcupYSdf2WLDIjaJ20BJmUh4oovQM3N52hh9Lb+lo0sbndJ1DGng6or/+MOi4k5T2PJ8Y7Gj8s6dMAKPvyJ2WIWWlpZAMq7uzcajOimKCLsY1nqagykncphNHjUQJ+mpGRjjQvJirUwy9JQY55Y= 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=h0Li9A87; 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="h0Li9A87" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-216634dd574so72771705ad.2 for ; Tue, 14 Jan 2025 18:41:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736908884; x=1737513684; 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=h0Li9A87gm27wtzSrZ0Ee3L3MmApoSpc+MCThRd7Kpif5KBOO9Xbbf0sMhV890Jlys P3IE5Pf4mAyvk4Wjrqqdwv0d4aJZFdv6F0S91rwc92LcpJe8rYJ95W8U28T1YrvVTfzI su6nwxTlgm/se7fZSUaPEy1SGNzaL49cLKrp5Olnj9NQkO/fDOEw4PicE78qAnhoIm3s p7GOX2qwkY9F9Pi5X2g8Xpp3MtHixkFa4UVJnTfBp/9Sbp/ovi9OPdiM+kToN6RUnTjJ g3Xyr03yMz8x4eZzmc+zLD1/LMKULpDRVlvQL9k1d3a6nFcU0yw7S0KU124SUNrw5E5c 74zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736908884; x=1737513684; 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=jl/Q6P4k1VZP/gXN9Ui5ymXhi65EpU9fHntQupk+tidRvyqzO94UA9lOlndpDKFtsn cu4JYcoXouQsBDBMpNMO/v0k3sp5Jvn4NOGwZ65l3iIzSzEoxrpVjFTBFacQPiWQlmUt bdX1eXRSiJcb5lrHdHiRuIjrooLOWwmK5sakqcvRbvvhlwzHsO0tXd6wYH5FORPUMj0u QKC8l+lTvVHye5pJ1u6y9Aq/AIlWGvskixKH8BOpqDscvaT1jmQU26SqoZYF+6+45+y/ QBTIMTYSjdlNgr7Pla6tvRne3MPPhcJPVVzJbxKlbZ+E75QTRxYQGspMQmgvNzvO1Dy9 O5rg== X-Forwarded-Encrypted: i=1; AJvYcCW5XrBvDMcUi/F71CuSNkHXdjnqc4eYfbIPnbwoB+EzTa/4yGzA2DFctXrBoEk6MqmT1wQlr09jiS0q0pY=@vger.kernel.org X-Gm-Message-State: AOJu0YxCoPPCaUM6B0tJr0X59ZI6UhkHJgwO9P/XOyQCIA/b+gtaIzF7 SmKL3+hgydir4y2Y66iZ9gXyuUoRrAWSlCmI2iljZ2V8AgdK4vWmQeHCTImg2JI= X-Gm-Gg: ASbGncuCNkR4Wipvwe4oLbwPvydR7zrvjDzVrnGbAfagZnp8MQDrKtBbMVlwI8wAIz+ 5SmMG2GhYjR18/4ix9SteBWJcJLb+0W/zeFXiQACxKSKzKjCZSETu96hzhDbXHQxyLXEuijGTJD LlvVohHBTflaKHdwzhqP/RNsVfEGL+R1V7eAwhavnR3lhgxh+h5ZFxnyb0cm9sNzdZlIP7fYGwq 2l8oRwsnVUZC6y4Kkzu+6gLBQHPBhuYTDFdcr4lyIFIUME13HSna79+lVIaUfYNdu5GLr61X8yJ pqIVNWhkvSGywko= X-Google-Smtp-Source: AGHT+IEvCBxOGHR3ybaItyvONDS8hALHgTqmx4phzF1QLDXR5oLeIKvQn/ktwaSu8a6RAzuXtynCUQ== X-Received: by 2002:a05:6a00:35c6:b0:725:4109:5b5f with SMTP id d2e1a72fcca58-72d21f3233cmr46085088b3a.8.1736908883633; Tue, 14 Jan 2025 18:41:23 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72d40680e67sm8321841b3a.139.2025.01.14.18.41.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Jan 2025 18:41:23 -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 v5 3/3] RISC-V: selftests: Add TEST_ZICBOM into CBO tests Date: Wed, 15 Jan 2025 10:40:24 +0800 Message-Id: <20250115024024.84365-4-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250115024024.84365-1-cuiyunhui@bytedance.com> References: <20250115024024.84365-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