From patchwork Tue Jan 14 02:19: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: 13938326 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 D515EC02180 for ; Tue, 14 Jan 2025 02:20:27 +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=P9Ker27qX+Ur2jDnHiMQ2WMhBf6PUfx6F/g3+6m2xm0=; b=KGtWMElFxlALRq CkAAUgCtrxE4+LaJYWwqqA2alnECAbCq1ppOU/5TbXijYJjvlTkOPv0DJEh3KbXd+D1p0/avsfKrU H5H8+hG92CsqTo4nH8bDlYL005lqrO+rdhmcAvd0C0uTlHb+rXJS00j6puIDiVf1Wtr80CycQYVl7 VBGNmee7NfCDuLhc10CmB9e4YsR+6otKQw4XCk2gxQA75luDFh3jxYP0JS8wj5I4laZMUy5d2YFSY vBkgoffXbEW2pE7tkYX0+fqdMtQfSCubxLt1+gIbXLjx9b8xG4xic9Ov+viwFx15M5nnSCXUAulx4 zH+mSZVnhAuSCQZKrTcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tXWXX-00000007EHS-1HH7; Tue, 14 Jan 2025 02:20:23 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXWXU-00000007EFy-2Qoz for linux-riscv@lists.infradead.org; Tue, 14 Jan 2025 02:20:21 +0000 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2ef714374c0so7455718a91.0 for ; Mon, 13 Jan 2025 18:20:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736821219; x=1737426019; 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=n+lHU8O3OzxopxeMRFW7AZqN84liiT6mDTuuIRoGMNs=; b=IRFbqo50UsYaIXmFjKzLwbsBaZfL1zdB7IInetUFXImzNHit5QIL+UFznp7Z1inGGE zjBc0oo/cyDblxVdAN7fcy5opg/5TcZ9ViAVcAp58ywo6Rt/yGTYRdUrYdrAhBw3LJlU YLTtAMVsDiJOeXjA7J8UwhJBXQjZyQPM8c18ZIzxyW/YBvVat84ETYSJi1eHyxx8M6WP 73LOCTUkqNHmHV8ZsWagtY7srz8wJu40N8XI2C/g3rmMqi0+SzAzlATxT2XDzJ04jlI5 wcglv+sQblbzBLeftabZ4Kd2DNVlC2lWzDt/30ZZQPbF//0CPWZF1NB2Jw4WMq8nMDlW 7izA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736821219; x=1737426019; 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=Pkr1EBJunLlVu7QclPYNQAWxD6hyv+PPR/+cQ79mmMDcev416JKcBbY32nXTdfqiyj cBCv8OXmx/rmd/vJeod4SryqRjWvyZreWzl/xWH9uN3vFtZ6FHLJUOCoPm0/7eSI409u 5Ku/TiJmdcZ7j0sbJruqpvV5qj6wAvELo9PBGWxjavQTyKSHsyJ6fzLXnCHoxnOfMayo Vm+EGLd4LSThN4Jw7NeezDI4fkMfmTF6FIrFk4c5P9BdAi/gq7dqK/LEcBKIqG7s4284 uvNLaXpPBMH+UAiUl0mgogpFeF2ezl13ut6g4FxICce5rrPRPW5WTpH7ao1d84I5bGdE bLow== X-Forwarded-Encrypted: i=1; AJvYcCU8+Vtzxhtmyp4J44sxB8hh8Wx8eW7KLkY2omIIlMqY44qlrLn6EHAul6Pa8BwJ9wCUmDisnicW4Qs9dw==@lists.infradead.org X-Gm-Message-State: AOJu0Yy/O0IafKFG3b2ejws8rtra5YDYMzVvS8iioM0K2F4VZr80qG4O ZWhDlTEqoB0F2+2GyS9dAkfGaulgVpSXuWEWrNi3E1sEAJy6iZout4/bMfiM0EA= X-Gm-Gg: ASbGncsbFNbPHTcFWuJ1EyD9QxsRXFpX2NbdJjSZYypReeBJEm4Zo9CH0ypKxaCVvYk /fTjKA3Sy2Ax+eFNWCBJ9qFmz1l3YtS7ls82dgGkUs1g2EZUARCwA2MiF/gHGa11J0cIaNUcWvm U9GUp6yNPRRR9+hcCXOE1kmeFsCxCL59GOQtG6QhjVIoa2wPbJwyTi0T/opOQkK+KwPAcEYdymj Cly/vwdjS+hhq5rq9vEqc5u6jBUr935lPqEVRDIFqmANdufQOUgLtauZnATv4yTdV4u4SZlDMiD YPCmLkVhjDAwrgc= X-Google-Smtp-Source: AGHT+IEpY8vThDWOwMPEtXiB5G1hpEHBvYVE1WuJdpEosAMMRWGkN1c3leoGAuLEHJ1SaSfa2zx7OQ== X-Received: by 2002:a17:90a:d448:b0:2ee:c30f:33c9 with SMTP id 98e67ed59e1d1-2f55838d0eamr27670389a91.14.1736821219527; Mon, 13 Jan 2025 18:20:19 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f217b38sm58948065ad.145.2025.01.13.18.20.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 18:20:19 -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 v4 1/3] RISC-V: Enable cbo.clean/flush in usermode Date: Tue, 14 Jan 2025 10:19:34 +0800 Message-Id: <20250114021936.17234-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250114021936.17234-1-cuiyunhui@bytedance.com> References: <20250114021936.17234-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250113_182020_613798_FE09FC6C X-CRM114-Status: UNSURE ( 9.79 ) X-CRM114-Notice: Please train this message. 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 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 Tue Jan 14 02:19: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: 13938327 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 D7447C02180 for ; Tue, 14 Jan 2025 02:20:34 +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=1dg/oMDOgyi11/MyUeef+l48F2wt4V1/n9ShlxwyAHo=; b=RrUm9EceNYaGrA jWLSFpsrxc09OrbsYWlwQS6aOEldWyBTpi7d0E+sI3ztskqGAoG1rvE/Sc65GLGRksEe7/YH6AJjF AWM9SHeaBBtQ3HJmaq4dFQFSGy/rbt8+idgvxruojLiPDaxlbatogX5yie2k8quJtr+jtwj4n4dVX SfWvNRGX94Zq55lk1bXWJFPMb++0nKL0k4f6CB0c0OCdT/zI3j/IRJC9RRBz+8VKZQw5gMmf4U/us ARgNiARv0XpWSY8xTpWV8ayGVSPHael6JB8IjUG7ubNIzyCqxdabX5lWs8nBTe/hLK0sMOy0q8gc0 c/ZbrkqEOFGcFXGvid7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tXWXe-00000007EL0-3cJq; Tue, 14 Jan 2025 02:20:30 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXWXb-00000007EJf-3JmQ for linux-riscv@lists.infradead.org; Tue, 14 Jan 2025 02:20:29 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-216401de828so81770875ad.3 for ; Mon, 13 Jan 2025 18:20:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736821227; x=1737426027; 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=cBNMHaJ4/jliKhn3dX1fpdixipAbOn0nv46ZAdfBeMA=; b=OfMbfTv3VkOyruRV+kaprsMRrQUvoAkeFi1DDhUqHczvtyhW3mk8xLtad3fsMw6U1P iwcwMFbkE4Mdy7DMr0oTV871xuaw/JMzk9YEEsHx+4m9HQ8Tf600nMnAVPSp25GKQK0+ s2mW8ZCnTY4Xq9GUwjZvGQ5kJT3BDLYavjbfVjBSbHT3w2Yt6jjeRqK+9w9uHPNfg3E1 dd1GPsUzOfQ9kpxpijsGsEnz363X4upUPIkB+M+enHxsm2eiAVwgK7J5nnTnDyS0cb9C i742rMXX1hRi6YvtIhsAm/7vk77S5zM42F36jAJBbrkpbgCxBcITXKx2DRVGrtYPDLv7 M7vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736821227; x=1737426027; 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=cBNMHaJ4/jliKhn3dX1fpdixipAbOn0nv46ZAdfBeMA=; b=DbkChm1lbImYkvdvy+Pl3CQfo/xNVqEbALGdMu/DfYcrWISPOaKEWLe2n8C0SFa+oZ 0L4jzFRaqE38OwI44nqW1aRfvdb5QQcBkfuioA8U63YpCmrs1ibKRuG7JUg9sCvSplz5 UsLmxKNspC5OrUWxFqKVCM5/YjmVDdm8Nj2xTnTVHfrjO9r35WmuRRMDBNBDetLCi488 Or2Axdfc0kKAbwm4KVkuCbsC9js4T5C/BOvZWarFJauWo0foVA0/48nmq8BCzoeXiyxn trOtmI10vABbbZqnb1uBcP4LuCrtRlFWoPJm6MtkamsWlt8u+AmQnm5wFq5gQLg94Agt hjoA== X-Forwarded-Encrypted: i=1; AJvYcCXcSFmd1Z/Rs683DeHkK5/6qzR58mZaYgVjttKvT9mhjELVtqA6iCgfq9t134Z7FqnBj19vibcu9JHEzw==@lists.infradead.org X-Gm-Message-State: AOJu0YzgtnoDqo9g8PwLVj/4Rfq5IbniRWufg6+HbpCrZU9BqaQwDtFP cqzlO0Cn1oyCMMkfFWzxBD4xevFmv6Rzds4vr7jag3K2PJyeNmb6Lrg+cnEorpE= X-Gm-Gg: ASbGncudqo3Z5GpBnytnaxFGVnGjWFe3XnZBqWCUsKd/OUpST7gvLo9M5CaO+PSL2ni ngNhGeSKOKI3O5byba59QEo7HSTc8DKXzKwVtWzS63L2Miyh5zwfgLIRVTOClG4pWMx29ye6uMQ X1TFB+KP6bL57mSGj12FPGNHDPdm8s6DjqZGea2h1UFQIvcihqbpNAc/GzsebpdgXoKFwrXMfEC TGvytx1+zSbJ3bgzCmmxgsCnht9dlZAf+FgArG7SNYhM7dAtwp8NS71wCnzMRMYG2ADIKGFbjUM hEZofCBoT6j8epk= X-Google-Smtp-Source: AGHT+IE8gXNlz9uvRlAxGGGoxzeSxnCrgIxrMIHzdxRxrwL5DTCwEfXr5I7vV5OOSc2ZZIkB+wm2Yw== X-Received: by 2002:a17:903:124d:b0:20b:7210:5859 with SMTP id d9443c01a7336-21a83fe4982mr290497735ad.38.1736821227154; Mon, 13 Jan 2025 18:20:27 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f217b38sm58948065ad.145.2025.01.13.18.20.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 18:20: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 v4 2/3] RISC-V: hwprobe: Expose Zicbom extension and its block size Date: Tue, 14 Jan 2025 10:19:35 +0800 Message-Id: <20250114021936.17234-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250114021936.17234-1-cuiyunhui@bytedance.com> References: <20250114021936.17234-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250113_182027_826636_A2F4962B X-CRM114-Status: GOOD ( 12.26 ) 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. 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..0ea7754b2049 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. @@ -281,6 +284,9 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_KEY_MISALIGNED_VECTOR_PERF`: An enum value describing the performance of misaligned vector accesses on the selected set of processors. +* :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_MISALIGNED_VECTOR_UNKNOWN`: The performance of misaligned vector accesses is unknown. 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..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. */ /* Flags */ diff --git a/arch/riscv/kernel/sys_hwprobe.c b/arch/riscv/kernel/sys_hwprobe.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 *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 Tue Jan 14 02:19:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunhui Cui X-Patchwork-Id: 13938328 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 DF421C02183 for ; Tue, 14 Jan 2025 02:20: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=5W+JmlaP6VI35l2WWrpvWXeHUuEbhrdDfuhPGgJTb3A=; b=QOmF0IAPT5aUuB I0v7vwQbkaUX60fdbNqpV/JxJkORF6CmAeRXvGr++F4qyXUvxOk1VMBZzg6l1Sl+WYEi69x7KiX2L zSE4iJDtgbDqPXLxS7KcYIC45+34KEsyfyI/O7ldHPmbbQ/MUOXuBb3DEJXCovplnuvwsg8GlFkuW 3//KFFbw64RFlFlv3M5jGgsfcB0HPaB8CTk7QCSOeQvnhlRAX3V9Iy/1hkpynM6ErXroVPylZ46B3 PqcNIqwwwTPd57JPgh7hl1x5ZAj33J42hTJj9NMq+7+w+OhKyupdPB4IgwchrnnGfr3H7euNAqlmy XrSAFRiklN8GswEUlWLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tXWXm-00000007EPx-2Acr; Tue, 14 Jan 2025 02:20:38 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tXWXk-00000007EOj-1c1F for linux-riscv@lists.infradead.org; Tue, 14 Jan 2025 02:20:37 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-216395e151bso60450125ad.0 for ; Mon, 13 Jan 2025 18:20:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1736821235; x=1737426035; 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=AU+kJdFGquiw6jMN24/Ei4xUPExeegdDiALtzowhFsI=; b=eDX8ePb69eKwp8TwmDADk8Or/fObEKBAs5+CpVfrSa7IVMD7ysnTeC+s5R2bOhEVFe 8Thbri9acrF+qhcThzK2TOUKzOhR07o2WqolxjScJGKokuJbLdgLPB+kUgJPvbx4c/94 G3y5nQkSS+nlT572ThNPDZop/ZeRv9K+G3zNIu6bnXJKtiXWZLISUVGg7Iz4hWP1EYyx F6iZBSaSXP0mN+hudNjAyoZlJ15BBqFut8w0+pozBi/LB7gyH5hCquvxzhKYSrhTTcya YrQLJaBBPWfHjVF9hES2HYpjRSSeGPHMjG/8OfacnBMEbAW8ihYsD5zhQsGsW/mLs9ML yU6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736821235; x=1737426035; 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=AU+kJdFGquiw6jMN24/Ei4xUPExeegdDiALtzowhFsI=; b=MiRZgdj0zytXB3tCrY0i6AJpI+Eh5MOkrhZIPrAmd43eetgbdn3a8FZPRw0IXmS5Tx T0FfFZRh1dEVG5r/J1QXZ+3V2E4Edg0fV+7qYeVmzAxhNXfCMuxcdcgaanJbloJ6N4u5 97AoYV8E8I1AGMY7FTFbQoBbsdtKwVtbkRkIyyjyNsH5BwoLU4NH/6QKNEBUpOu8+PBo ym14gXg2i+c0RTGgInRTfWq+NoJ3pwM55MgApQEHcbIB0i2wCQ4x1OE8X9D5i72jmAm7 3Ts8c9jAOfCII+wm2ABPV5uYq69hNs8jis3JTuZdjHBxGuy950h9vPl5r1Mpy50WUA4W A4pg== X-Forwarded-Encrypted: i=1; AJvYcCUpG5HIHAyHhOEAwit/apueFDkYaLaxIoTSJQgAE3IrRyCwTZ1HDJoh5mN/tqkZO5VoOwzJGAmH2SfijA==@lists.infradead.org X-Gm-Message-State: AOJu0YwEfqJUUNCnZuYSr7YgsQY6hL4RRnC+yG4wmYfPMIeJCePxNbBu D60Ir9dE2ifwpyIPRrKDRPG7fzaRWSciw9dHTcgQq02PbiG7R+quvFnKPtjP1CQ= X-Gm-Gg: ASbGnctpt3lD96lgOlnFViPx0E81teBHYpssB9KtLf/MGwEmBMJSrSmm25PQpYgeBk8 JJk6FC9GVGyqHfUH9NCmUZaQstEhp7E8IuqZ++IA2Jhnx5+5KEKadIiMpPNA7+S5wDCEs97XEt/ J5TLCWD8Xhu+v8cum56qWA6o8NzqhGe+UK8vxgaurjhq959DWUHCZaLcey8DIUlFKggy3jPMD6D GvZrj1R9EQr7EMCwR/B29wDg4IwlGGM2w9fgq3kuwAzzcod6N7fObNxrVlPQ2iBKLmBuzxZFhN0 KDSpZQtWbAxikvk= X-Google-Smtp-Source: AGHT+IETuOAy38hbNYEg3JS95akJoO/X69j3f9vqhvGvre0TcMAbZshy9c/3Vf/4QESbup51MnYasA== X-Received: by 2002:a17:902:f691:b0:216:4fad:35d0 with SMTP id d9443c01a7336-21a8d6484c9mr258669205ad.9.1736821235444; Mon, 13 Jan 2025 18:20:35 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f217b38sm58948065ad.145.2025.01.13.18.20.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Jan 2025 18:20: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 v4 3/3] RISC-V: selftests: Add TEST_ZICBOM into CBO tests Date: Tue, 14 Jan 2025 10:19:36 +0800 Message-Id: <20250114021936.17234-4-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250114021936.17234-1-cuiyunhui@bytedance.com> References: <20250114021936.17234-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250113_182036_422310_87C74A8A X-CRM114-Status: GOOD ( 14.60 ) 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. Signed-off-by: Yunhui Cui Reviewed-by: Samuel Holland Reviewed-by: Andrew Jones --- 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..dec510291ab8 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_ZICBOINVAL, }; 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_ZICBOINVAL] = { .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_ZICBOINVAL].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)