From patchwork Mon Jan 13 08:36:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13936867 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 E02D3233157 for ; Mon, 13 Jan 2025 08:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736757458; cv=none; b=NnqKqXMd5uWOh1+j+Wlpy23DMSbEy6zVvQWvpkvWNMQrOLMQTgnTeDJkfdaBNuJuG8R0TODsr+QPnrqWxh+Z1uyRISt/iXU/HX5IJzPDOb8+3o4AK6VzFG+7VG54up1I4+wbnQBEw+d2x+3RvUbGqaKMu/qKRFZ/iQ8Rt70aXzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736757458; c=relaxed/simple; bh=G+K9MvSpAIpwDwMmunI0YSdJnqQJGTJZcC3ONEVxX60=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Ei4iKFGfXhgYyK55n8gjmSV/5B2ZJ61e3f63DU3OpxBCEfqybEuXFOJMjn3S7Zjdfvt4OdaXPs7X99DT4Mm/0sukJjWGGVjaOpY+msyzvhLWAJU9effeFfGa+RkZHNXV4xQzKqSVFA8tBFiFVwjxTTc8ob/z9uVeXZLLOlsappc= 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=cHOO9q23; arc=none smtp.client-ip=209.85.214.177 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="cHOO9q23" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-21675fd60feso91510025ad.2 for ; Mon, 13 Jan 2025 00:37:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736757456; x=1737362256; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=n+lHU8O3OzxopxeMRFW7AZqN84liiT6mDTuuIRoGMNs=; b=cHOO9q23GP2O7KP6uZaMhyM/GU2r/yvcPeB3+CvTGbQFRR9H0zYS+AGKm///ggF7pV trFSg7/URSm/Sb3gDsJQGprxO3BkFEbTeExnuuW4XDgnp6SEtM75xFo7rrTf0plvVLD0 HT0mSJ+BCtdPELci9mNId69V7jAhlvyZWitAHivBy4jo5E9D8sXVK1jpbUQxKcyitIFG BELszUcV1Dl0lzPS9MLgZvYBkBIBpMqACkikICkbWAq05YI1SJUZm2PSEdRo9OWZWKPv y95h9JmgAacTW2St0q/jh9rgKKsTsfwYalNyWQ5126lkf77LJ338t8Q8dcmjZruc61tl MurQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736757456; x=1737362256; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n+lHU8O3OzxopxeMRFW7AZqN84liiT6mDTuuIRoGMNs=; b=ifqo43V3xONKHgNtforoUWBJZnqWWmhbj+MfTDwopVCY2I+xFm2MdDaScjVSO7+JvD l8vfsBAaPKklCJ+bGQ8yRSI0e3pyrE7kN6jX6ONf6LtadGAqfJliFEBg16onJjrS4LAz RWtVBDKUXAyHB14OcpYzAVDx/C1hTkfr7muogcvXm0HhiDEdZMGsmLR/K3pC3aOTJ1vY vEo0dPOt0VJju2gfnaunvUXKRNMe5MsoZNEQPRsITAZ7fjPsSMkKu6ZaTb2TKEkyzaKb +xzTjcvkOmlR1Q7J+iwGbOxTzOyptO9u0BFOvBYUY0BFiC/Ks0hHhrjLmbGK9/+D85/K 4zGw== X-Forwarded-Encrypted: i=1; AJvYcCX7IfHmbkqmp762QysYwspoH73YSNyJJzLTZMEbjc2/G15K7/b6cfW1Lh3dyLnST7l/bfgPQfUXJozcBG7fZ/k=@vger.kernel.org X-Gm-Message-State: AOJu0YxHsOWu6qmOjJmrLmkY1Esy5bQIdwAPsFzzZU0xi/1fd7wgVR1g yYPRpV/qpKt9HWMSXuuM54oxJBkCj/HNCUrmCVcqfTqOFsxg/K3IJz2cUmgmEd8= X-Gm-Gg: ASbGncsJGBEiy2G3tROQSJrATuJfTCzQL1L93CaET9wRX2JcI50W9sydI2TW0i6Yv4y ebOb3StzNe8nYHLqsSUEd35XjhUXMISu0aPH/tXyMlWlZs3J6fILaQePQZ1jIuf4Eu9wqxDAxQL iCe3VtioRiGEGHxFtEo9yJES06VwHK4VteBPmMBWpldflHZRNiciBlw86ZzZ6UfV588sV5oe+M+ rjK5NByPG3vJQxr5TgSah7Fq2594tIu8ocJPFqiWOHjRNm2rQJ/hqudN9LkxxtyeyBOPGvUppA2 09+zEQP8vXrLft0= X-Google-Smtp-Source: AGHT+IE2vpLLAbTwFgumER+hiNZPVCtR/vb8/ZvSUV9VI3AIzL53lbAShlejX+qABV5VNq93sKjw+w== X-Received: by 2002:a05:6a21:33aa:b0:1e1:afa9:d397 with SMTP id adf61e73a8af0-1e88d18ea9dmr30431962637.15.1736757456055; Mon, 13 Jan 2025 00:37:36 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-a317a07ceedsm6427433a12.6.2025.01.13.00.37.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 00:37:35 -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 v3 1/3] RISC-V: Enable cbo.clean/flush in usermode Date: Mon, 13 Jan 2025 16:36:33 +0800 Message-Id: <20250113083635.73826-1-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) 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 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) static bool any_cpu_has_zicboz; +static bool any_cpu_has_zicbom; unsigned long elf_hwcap __read_mostly; @@ -87,6 +88,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; } @@ -944,6 +947,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 Mon Jan 13 08:36:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13936868 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 28178233134 for ; Mon, 13 Jan 2025 08:37:44 +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=1736757465; cv=none; b=bcrOIhEFuKPR+SCILGKLKu3EPLbn6m1dhyXqRfJcSKJuZ/a0xOXkI7QK/dl9yKQz8FkAbh7qJCFtre3JZ6FHXHEPprDjG02FGN7ot0EMzF2mIWuvSX1+/owtntrufsP+vBcT8cVCVyFCLdX4EXDM9cfaEobjiAW4Mn4XB8Ckprc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736757465; c=relaxed/simple; bh=kN2FNI5tjS/SkVUOSzbQxNdDXKPB0v0FXY6myAvsiS8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WTm5lP13Xve0bvE6HKaE4OPr/+g/p3bkOetkZqZQTC9aVSL+r5Ohx42bnr4cLECrk1xjmH+OlGCNXAMDoLblnYK/sHwwUUtBaH+iE1twhLTCDGgguiSHE0gu1cY9+6ErQSvlbVaPHVzQ0nSAEoDWHBaarM7gsTwLo5vkyK1xXB0= 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=B4DrA2Mp; 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="B4DrA2Mp" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2165448243fso82250125ad.1 for ; Mon, 13 Jan 2025 00:37:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736757463; x=1737362263; 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=SJXI8b6ff8wiNA8cdLu9hBvsj5PggOwQ7lAxRYtj+CM=; b=B4DrA2MpqSxzPFtER4lXArFAC+THT3LdKOFp8a980KfDnwmZsP0i22WDe000CilKRG CFyqEKgBX26Kx97fBhAjG0EtvVYZ30UsDRxFf+pPN37mipG0TnPy1i0952JtcXYIhZQQ BR+l4LRIdE2RmfYJWsr+eeIxKQQHHHp43fi1unAfmQqXBe3X9nD6yakBHb2Oa9eWU3wH nA9hVjsb1D0iiIHHr4/EOBkEJkzyrENcW3NJ0ivNMRW+yRUwWpCJqfWFt/pmhtKnYj18 z2NXv/FRxmLsJKnVplS398i00hH08pPEt3SomqbfIsP3LVIHF7e7my+ni9VBdd0yaUEs 28QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736757463; x=1737362263; 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=SJXI8b6ff8wiNA8cdLu9hBvsj5PggOwQ7lAxRYtj+CM=; b=Ep3e96AfTlm3ziFyxLt2MKKj+Qdr47COOIy3mLuWNbBZ2Pz6m46Sp6Rk+QYxaA8FS/ dmNj7BqYhb9kmKHM4Wt60CqjMlq677fRSC524daUwby9aRVa9nbxYCK8N1FI7K4wJSaQ Edx7845ReSkYKEjTxMY3Mu1w6phxsNWPR3Qg9tMt7ervF7wv/SaYPANEjeAA8W9bq4oJ hLA2sbm/Dp1JMrWtdi6d7CHBNSj/oVq9yLDG9P7MkC1lJjnD/2UXpgsz+TBXEfF9TxuK Lt/o7LdXozAEETWwxkppWthpGcFoIRS5+kubjA+toa7nwrwV6XqV9LSAWNkU/povlasN 50tg== X-Forwarded-Encrypted: i=1; AJvYcCX9m+51qNZRww9jgLzv0AsCXsEfWY4Lb31VJX75WYqoCj90g8B1CD0gfSy4yHa+bSPmCw6rr9rTBOOXeoeBCaY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2lqFP8ngn2akA2cHYDOn3ZfRocha9+2TU/P1qDlCRszaaTp7u rR0VQr1ooLnR5k57ytg4Yun3smJ37zLAji+TlBIXyhRoPkq2Q9zMmor8jZA0R3o= X-Gm-Gg: ASbGncsZVr7oGNpgUR2yjpn2j9CxcwAgnVxonim1Xwg1Z+FqbGNncrg4TV9gLz9jjMq HCxGWQYcrljJ0leJwsATFVgvcXzo30qvivY6QD5z8SkuONDQC1xIUxbPlNEhHyGSsT1SGDthP4+ Tm6juY8IXJXX0f20ACEvVnrYD/VhuOdl73NDTtG756A7AQybhD5uPpFhM297Cxxn4oGme2dG3Xd n+Ur8t43Og+DKnLAfRu7hl2HI7EEgXHQfOmYb7csB8Y03EZ/cwPDIOUgMmWAUdikgbPxX8lEnis WbHYmqCz0wjHIIY= X-Google-Smtp-Source: AGHT+IFtz8wCzJ8bWXX/3s5qBZWyQyvLgQzl4lgPk6ejyOwy8z7pnyLJogLi0etOSTCHQkUeGmH/OA== X-Received: by 2002:a05:6a00:2e97:b0:729:49a:2da6 with SMTP id d2e1a72fcca58-72d21f1ac4emr31951733b3a.3.1736757463405; Mon, 13 Jan 2025 00:37:43 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-a317a07ceedsm6427433a12.6.2025.01.13.00.37.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 00:37:43 -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 v3 2/3] RISC-V: hwprobe: Expose Zicbom extension and its block size Date: Mon, 13 Jan 2025 16:36:34 +0800 Message-Id: <20250113083635.73826-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250113083635.73826-1-cuiyunhui@bytedance.com> References: <20250113083635.73826-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. 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 | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Documentation/arch/riscv/hwprobe.rst b/Documentation/arch/riscv/hwprobe.rst index 955fbcd19ce9..7a47cbdbcf8e 100644 --- a/Documentation/arch/riscv/hwprobe.rst +++ b/Documentation/arch/riscv/hwprobe.rst @@ -94,6 +94,9 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_EXT_ZICBOZ`: The Zicboz extension is supported, as ratified in commit 3dd606f ("Create cmobase-v1.0.pdf") of riscv-CMOs. + * :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_EXT_ZBC` The Zbc extension is supported, as defined in version 1.0 of the Bit-Manipulation ISA extensions. @@ -273,6 +276,9 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE`: An unsigned int which represents the size of the Zicboz block in bytes. +* :c:macro:`RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE`: An unsigned int which + represents the size of the Zicbom block in bytes. + * :c:macro:`RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS`: An unsigned long which represent the highest userspace virtual address usable. diff --git a/arch/riscv/include/asm/hwprobe.h b/arch/riscv/include/asm/hwprobe.h index 1ce1df6d0ff3..89379f9a2e6e 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 10 +#define RISCV_HWPROBE_MAX_KEY 11 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 3af142b99f77..892dd71a3793 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) @@ -90,6 +91,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_MISALIGNED_SCALAR_FAST 3 #define RISCV_HWPROBE_MISALIGNED_SCALAR_UNSUPPORTED 4 #define RISCV_HWPROBE_KEY_MISALIGNED_VECTOR_PERF 10 +#define RISCV_HWPROBE_KEY_ZICBOM_BLOCK_SIZE 11 #define RISCV_HWPROBE_MISALIGNED_VECTOR_UNKNOWN 0 #define RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW 2 #define RISCV_HWPROBE_MISALIGNED_VECTOR_FAST 3 diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.c index cb93adfffc48..affcc3e58df9 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(ZCB); EXT_KEY(ZCMOP); EXT_KEY(ZICBOZ); + EXT_KEY(ZICBOM); EXT_KEY(ZICOND); EXT_KEY(ZIHINTNTL); EXT_KEY(ZIHINTPAUSE); @@ -278,6 +279,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 Mon Jan 13 08:36:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13936869 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 5C3C42343AE for ; Mon, 13 Jan 2025 08:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736757472; cv=none; b=BySoDhuGM4eutbYvk7CuK1JOoNgUnhCfiwkr9PqL4Xx2zAuEmTgMRp2qi6flEf5Z5t7VC5UYZ6EUllCMdLQwXhMb1TE3h1T4hKtkwxyfXxR1aa0s+1hA2N+zgQSNugCOLi4HkJw7PTnUNtZPDCo4rd52PbY0wqy/wPr7nQDwVuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736757472; c=relaxed/simple; bh=kpZZDmzk+pA7qUikHydnQ184ytU7CciUWTlCG7kR63U=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e09ybS9W/nBc3hIJZE16BgbVjtKKlRRpiClA/ODu9P2G+jUKidArOfBgJrmnfoJQX4XUqPjh2m9IV6z+7qGUkhrImqSVySMi7Yn9ejXUByVJsaFRDXTwFqo2+RdOiq0gz/1vuBCB9wP1rmo0SylaQ4MsL2yhwcsRXj9AEC0n7iM= 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=K/ceXTjK; arc=none smtp.client-ip=209.85.214.173 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="K/ceXTjK" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-216634dd574so44241625ad.2 for ; Mon, 13 Jan 2025 00:37:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736757471; x=1737362271; 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=qMJOsZFUuGMCCNl6Ap7/zKUJmvdFBz7dQyyFwX4yhfU=; b=K/ceXTjKYjf0qJWYIfPnAiPfXSoWgYOfJKCRhVPUTO52v5Xu12ipEfGfbrwByqoSdh VKTG4IaHw1xKfIKU5yuJKYUnQ1vAx7ZFOARRsxPu8Q8DTA61YxUa50VVH5XzE5tUAtjX ekzMdJ2UVCNGiEtZjn9JJ+3pHJsmSJewdArni+GX762ExGT56AWjOr9WY9yf+6mT4mz2 n8glp6EzruBvCUHK7g+hhi25enN0ccuVkLtI5uE7fYI2STZGz+U5dZIKZHUjYchx0FJ2 avqGJDizFlY95vb/0Rlxav3qxEfZr6CumxRYWkCaQ9Nk2J9UcZZR2elh3fYu6dOYind4 11kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736757471; x=1737362271; 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=qMJOsZFUuGMCCNl6Ap7/zKUJmvdFBz7dQyyFwX4yhfU=; b=QL9MzL6EJ4VZ4tu8tjjxky4yE+xzllG0XZIf4EW8gwyrwxo5WLEJJul4t/QBY72mK0 v2w5WM70QH8GzcSMFYgHA0USyEHYQ3tRzRvjqVVFjpRFc5u/peGAUGiFy2QOLiVey3IO g1tNytIQ/rS2qLwqGO87mtnLP4Mffw+v6yHROMVP5cKFxAfB0grRkLdeVK9HACqnXET1 1lgIQmxYtC9tMg3HpFFbTOqbNPs+B+IVXLGS/O4kxBml51hH1M8egBGHAS/sDWdAjIMe NkElpdwa4A1EdT59+w2PnWyVJdzpx+GmcWeTBwQsDiTmyKG09bq1XyaLlzbfsw14BmYE UPFA== X-Forwarded-Encrypted: i=1; AJvYcCUnJMKQ04XgHDizf03NShoUigHAYdCjC1acP83WcL4JUyaKbp91NRe8mZzqujREnNvrqujnnZ5T+7F5UcY1RpA=@vger.kernel.org X-Gm-Message-State: AOJu0YxzDMOH+cUjpGbt7/TJkEH+tIq3TphXNhoyInPANjHez7Fmr/Ki s5yl+3OB1X4LkAGxe9IlCecX/yYG8DwNWWSbAzl5Ry7kAiWeHHNacF0cdg/LU+A= X-Gm-Gg: ASbGncsNzgVenGwM0GuErtjv8Cl6TvNcR+dDH0l1xLLGfbrPtymH51h9h3izJVG/wKu HYinsJ2WdpONcc98CxdRyip2eRB+FbU5UxjNAZzBnomisHklepqT3ZV/B2HVGP2UaC6wU2Vs5wr jf+88n50GYJgnONMXdZL81wiSVDIRmWy9f3Y5vSH5Jy3bNDWY47f3w4dNTwrqL1yP4Oa5fqY9H2 8pEcy1s0U7mWeIsbJjk1jK4egcdrPxbLhrqQDNChFXA1Cy3qxgbePdG9THGqlQHsE1AzlRTyILU LGUSCLfwzPfhc+s= X-Google-Smtp-Source: AGHT+IFLYk6bgrJ0SOLLV8CBQcEe8+QaPJ84+VNsdagEBMamy215GoqGCmwUbo8FjSJ9Sz2cJj2tMw== X-Received: by 2002:a05:6a20:7344:b0:1e6:8f10:8ba2 with SMTP id adf61e73a8af0-1e88cf7f796mr31344708637.9.1736757470676; Mon, 13 Jan 2025 00:37:50 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-a317a07ceedsm6427433a12.6.2025.01.13.00.37.44 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 00:37:50 -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 v3 3/3] RISC-V: selftests: Add TEST_ZICBOM into CBO tests Date: Mon, 13 Jan 2025 16:36:35 +0800 Message-Id: <20250113083635.73826-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250113083635.73826-1-cuiyunhui@bytedance.com> References: <20250113083635.73826-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. Signed-off-by: Yunhui Cui --- tools/testing/selftests/riscv/hwprobe/cbo.c | 49 ++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/selftests/riscv/hwprobe/cbo.c index a40541bb7c7d..b63e23f95e08 100644 --- a/tools/testing/selftests/riscv/hwprobe/cbo.c +++ b/tools/testing/selftests/riscv/hwprobe/cbo.c @@ -81,6 +81,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 +153,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 +161,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 +173,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,6 +187,7 @@ static void check_no_zicboz_cpus(cpu_set_t *cpus) enum { TEST_ZICBOZ, TEST_NO_ZICBOZ, + TEST_ZICBOM, TEST_NO_ZICBOM, }; @@ -169,6 +198,7 @@ static struct test_info { } tests[] = { [TEST_ZICBOZ] = { .nr_tests = 3, test_zicboz }, [TEST_NO_ZICBOZ] = { .nr_tests = 1, test_no_zicboz }, + [TEST_ZICBOM] = { .nr_tests = 3, test_zicbom }, [TEST_NO_ZICBOM] = { .nr_tests = 3, test_no_zicbom }, }; @@ -206,7 +236,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)