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: 13991586 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31F84C19777 for ; Wed, 26 Feb 2025 06:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ifGk4VVnit+9C8G1uJIPlSJOJDNMupkeum/+vzaa3ns=; b=VARXZX9WxdL/Yg fEVFOOOR5NDghR4fS2iIZTJzpUBDuPrwtWvK2OaCFV4Mp2CUoK3hZAC+LhXBUsVivPrLgNuh1dmuQ 1YvX0fjSHr16nh9yR54Rko1HYblW6ykvo97cB0pXoIF/nu+KANdMrcNIpaiH/GAFZxPu7CFff6rp1 H2BEaui0gWWpCX5SFcGbGNvLqHyXz8PuUeaI6tnVpy3do86OUdjb++LwfrbN6rmqwEO84rn0B08zG QiU2kjl36X8YR2tOiBz+tpCw7V24f1MYLn2HoS0KinmdiuHi8KDmFx5R2X+j1mMk7r7l6dAC+gSYT da5IsnyPKMqoHRiSBovQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tnAzA-00000002XnM-1iXK; Wed, 26 Feb 2025 06:33:36 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tnAy3-00000002XR2-19G6 for linux-riscv@lists.infradead.org; Wed, 26 Feb 2025 06:32:28 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-220c665ef4cso112951965ad.3 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=lists.infradead.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=UFXOwefNcMmTGXwx3//qvpUoZFZRlyAWjA9RPOvgDgs77J8UrHbvrAsQeGRwUuKjVX /YTd80RkWAo0gZiWXBjG3v0owpibWdDdWJPZFcbZc7b7SMxuSkzx13w7lWH4cIZ2q90T 75c8gv2guV6SkX1RmHIk+WYzwVMDkGXbNh2E9E05asX4+GmgXhztGMVMomuJ3arqmMDL ldoaL9QUu7X8qk1NQ5lsjFeStArVuKl6UzNqI8JyahFQXooLm8+bfAhZMtP1mLCOha+W YWnsCZ0rotaJ6qcdd/e3Zt8ythKw0JpkqMQwWrkzDY4OaqitMLzATyPUgW7UpyinzJz6 aO6w== 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=VQX9M0PKZRGJZ0EZ6JYhvAVTXFxx9ph8YSeXCiFDrR96pgoUqYVzfuRcO4FK2tp141 722QPxQE1Ln7H8wYzIiXAI1YUM2Rte+9t5rdkwCLWXZnCh+HGtPZFq3OaJgmVp/84tOD us3XBoXYN4pmmDwt5nTjb0JCwQ0AmEoxtWLgjJrZC2CUVISA8/Mxps8jfnKBrrXUbu/M JnaM4jPVXJVci1IkYl4wMg/vlGTZvJzNEhcFGklekxT3KDt7d4tGl3eFZDyQi5WnkzTx a3G13oiIqqI1y/bqmszNfv43lt5H/Whf+sj5hcA4hECsTGfmVt5qbpkhA6SS1YipV7pP 9xzA== X-Forwarded-Encrypted: i=1; AJvYcCWDb4e2FBW8ZuRO+imJQXO0E2+sa2h6JmDTrMhuFRPklmiGknzCNRcBHK5fp1a5UTmiZoiL34zeyc1E2A==@lists.infradead.org X-Gm-Message-State: AOJu0YzF5fq3Aj7yszXHzJ+6qRq8CBoxLP1uHSNb+Lrex6Xh0q4RpVav bRvHrTw/gHvJqUY+6nqAWSbRoP3tCr07cq4bGb2oFpUwrvnEGTQXXOyWPTqiYPs= X-Gm-Gg: ASbGncur3qY12t738QPUzYx9X3cp4JKDa0NIlqAyvVtSIuos1E2Pw3/erAIZR086Ac+ uQO7SFmYulerqyw28PAyLY2Wm3qzrVUD4vfJ1GYWDNVlrZ+dUnBHNvE99W9Z1/kJo0Z68b0SfvX p4yscxdKjDq0QrJ22ph9ngIYT1tnSRt+VaEmssNMBDMxzwi6XT2E2e0Qf0ZjDyA8DRJLGG8jL0d F+ajJjGcp18W9OunrXwhQHYNf4OGkdIM8XLPm7zslnlisu0OfjhgDqmGty0x0bEKL+FxBljeM+3 +APRaTfNZLR+14uJo5ybfX8+ontnQLQHi43ygYdyD2NUmtHYEvjak46zV7bB 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250225_223227_312246_BFB4CBDF X-CRM114-Status: GOOD ( 10.16 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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: 13991588 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D7CFC19F2E for ; Wed, 26 Feb 2025 06:33:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=I072SpVigKjhXZbdjD/Zy/p4v/uircy9lWmhmA5Rh/4=; b=owantw/mt7DE3i mVHmuVsKruRoz0a8UtLtpg93YF3s3XU4tW+9019WMVlxOe/cLLK6SFYsfL/Fd4CtsU5OxnrbkyqUx JFalYze0Gyfu46O22XWR+NC1R0aTidwokUZDcs1c72Vq373nRHHuSKwP4TVNYWLf6wqTLsOKcnr5v 4X4ZrulzoN085kic/9mXD6h4fiXmiuK2V709AhEX5D1Mr0399mZcWKgvBTYoFSZQwnJohZcyxRZLP DIsqul87GpjQOgEnEOApHomf/cy4aLcIJrh8akyEorbUA161D5m8p00q7Lcd/YTM2bqVD5Egfiwk/ +iME5VXdVLKQxlIf7UqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tnAzB-00000002Xo0-14Mi; Wed, 26 Feb 2025 06:33:37 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tnAyB-00000002XTw-0GMd for linux-riscv@lists.infradead.org; Wed, 26 Feb 2025 06:32:36 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2fe77285e12so2008837a91.1 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=lists.infradead.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=KY/nI3cq4mDbHow691jUW0pb7FHhgCS87uE84nC5tQph7dmSD1VBbcfOvvmLgd0Upw w70LVEDjEwMiWlSnJCzhDO14QW9iFr1fqea9ZUoRAxTYdpGBbIopiOipGLcGcVFGiyd9 Hy1ARQwiUqe1piIg02J+BVrfVV8uxqPnxNehgHwO0jVN78JHQvbswHmHKGutvUOfLbxP ovBr8FGSCvR5xvoLFlH6SQUcmrnx6Bv6bJJSwSsi5++QdpOLSCryVEh4vr1R7sRezfOj RTGH6/ZzJfnjGyt09HT5T4k60n0huOJNi8XpC2sqJ7O/EkhaORmdtOORn1E08qgWyzuY xlYw== 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=ckXHbi1SrLMFIwtmrLLmoeXkiVRxwleiT6VFPsIsnJjecULgERuY6uAMYxKcLSnLme wUVW9+JM3gChgHT6w5Ca2/eedvxamVbxA6Re9hH5735sbqcVqi+JxaHsAaTBzDhRwHmq vaaMmiCd4aJR7HQrjbEmFzjY64xmxpG4nR8Duk4xbrFbvH+31ojD17k788wgVIMYXLyt AzeCNllvosioTTlFO2TodYBU+DaejnRpIH70s1nJ+w76NZrMadDFDIkJRisXjtolD4U4 dRyVMz7NFxdiP69jw1OvsJq89cz7ZSmFRsWl2y75tmODHSXEzRcyKhgdgz92Ab2NYsa6 6/7Q== X-Forwarded-Encrypted: i=1; AJvYcCVgO5ml3JpktF+O7BSBSe/8bTe5umxw/kQpxLN4BXDH8NfR9t1szVHQibK+sozYYg2A8MKOFpHlae2isQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yxth7/aWO6n2LyAPFTagW9prRsWyp9DJvYa6d/3RRPjDiMi/fmt uD/imZhvTanWaem6em0XNUBhLJPBQRIggq41XAClrt65Mxo17EUmqfgsxq3fXUY= X-Gm-Gg: ASbGncuA1RVL/ZdGYKT2Ij3jYrvS1ZbqhLAGcBdZ8RpMht8ItNzaRbZFdv8i8EN/jRb nhKpaHgVeBiGmdIiXKdYUHP52ftrBBVpzD2TsDoJEFGGsmxBEAixWFjsVdD7T+MvLl+bU87oFan IH9AFjF6H++FQIZhGdbPv6n41oB007wzmc6SkJO6UVt+pJ59mq9XjEg6s2rQmh//WZt8JbanERI aMJrbxwvxUYTh9c33Oj4EvRLHcRkrtO6p144N1cWQvAIbq9r5o11B9S6kOncJCKSsjJ+HFntGG1 nKACvvxFlVCxIejoECmrrgXFm0zuSROgzZJk2BWVOxr07lMbP6w4vWh7Zl+8 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250225_223235_153044_FB5C8A80 X-CRM114-Status: GOOD ( 12.75 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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: 13991589 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3CA02C19776 for ; Wed, 26 Feb 2025 06:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JOTMjmVOwz8zunZj7dszqJpZm9AA5TsOGK5Xz0wgyZU=; b=r+n8DOk6uU7sfV Ca3l3b0Dmnm63io8DBvT4+kD59A85RrMOFxBW0cJR8okT/Xl7ib1fgB3WMK863AdvdShOztfXGFA3 hDErNxc+Arx0mF6NaARpuyqUhUN2OkgpN3BvAmLxnLIUac98BSrMSNOfp12CGuwPQ2ZlQZHBtf911 hg245nHssF2B3RGXenZFf1RfhtRlWsQDgDLtgkneFKTMeAEBkp9ccp8rH3J+u1U8XonMC0PMp+omm lB4+EOIypGmylQyGQ7u/akBllH5XLVwp2Kcc2EGMTB4otfkjSTjbKhmGbhiayDUZeojrSA4F8wLHH J+c1SqoxIztf8Ju+PHpw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tnAzB-00000002Xov-4531; Wed, 26 Feb 2025 06:33:37 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tnAyJ-00000002XXC-0Njo for linux-riscv@lists.infradead.org; Wed, 26 Feb 2025 06:32:44 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2fce3b01efcso8478197a91.3 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=lists.infradead.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=ixb6y50LoNKfkduqs0hX6HTxSM0SSpIVlc2KEBAB/dnAS0RrKYbDT45jC+/JnvmWob nnV9tjRSBVfQ4SS4VpgAhuibAY23ZKhXjmoUesU2ut6Km88v3cmk5Z7wDmdGitifnqos iEisy8WAYBdezsbKfOvKn+zcyA3oy5inIaV/83saRv5DJCm1B9iZZE0ievULCaykbMyi W7BYCS1P0A99EDajbCHQf44pBKiufyQbiAKQGOEkk0TmXIYaC8CvSNYEfktkWKAapO4F jkv1SE1kqaK/H7emwqi9Vw+zEVdk0hMkx9y/Rtbi+gualzIMfDSlFCKL8oJhjpmM8Nev f83w== 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=S1Z0aKl7s7C1ck/UBm7tq2ZxCAenvz5nGbUw6RC6/vU4+c6FBR/smrGqtlKEYAK3+H vYagNG4dgp0H6NnJYrB7ZrcL0hDC66ESu4WvpRoX4oIgb45cfJnxnDavu1Vbvd6QuwQy +mUqFrm3uxJyQda10k3ut7mppg9ItyvFpPbhkuPrnD4MN6OtpUe/SBjEzaZeo7tMAzLW 8QY7il06rv9oEoPgwlc0GtmHL7Is666ub7b4ay1GQK4+dA+VWxUlRY0lWluvF4JjASvm wBIbyjySnatBC3jueL61ALJtsLqSsaPuJOBC1lUMgL5wKnzZaejm1OWLmM6QLPkowIrr TM+w== X-Forwarded-Encrypted: i=1; AJvYcCWMbZYgs9FqAFbdnWXVr8OFbnL42a+OZ4HqGvsW0fm9lGW9to9DKvRA9zLnbw5B7UXO6EPuC1okYA1U5Q==@lists.infradead.org X-Gm-Message-State: AOJu0YxPcruSzU0p0OsxQljahkuDWnSzpNpl0UUUskQI82XH9LPefFS4 CsBbGjh4C6NsZtCrTtn3Xib1/SKCi/md5TItrFQzQBCFipA7vSNekBVtW52c6sU= X-Gm-Gg: ASbGncu3p1cJ4qcgWaevaPT0q25mbevRN1ImV4BjuR3WCVgd2nko9o4tpgx253NtZ1L ACv6WrfJIAEqN5p4cxhZ49PA9BIpfnY2oSEP7mFyxUL0euFFsWZmmMqXufK+I5k2eQG0URUVrGB FHM7cBFB95UyGTM2lDcO2wQA61oAut7/MAIj5dHY0baylxuY+0kWUF8Y8pzBkQGQSvHzWHHYH9s jhpJd2dSUGXVm4aZFTNX3y5xj8wS3zionFDgp/prDDexfVrxcmqF0r3oGscc/oS6U4flguoOGkz SdBYHlhfJ1iJc0eUL1+P/Q5riAXQb1nHc8z7su6VOAgdF71UJDBcIzZPPz9s 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250225_223243_155796_8789ED73 X-CRM114-Status: GOOD ( 14.87 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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)