From patchwork Fri Jan 24 03:59:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13948890 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 F3CD2C0218C for ; Fri, 24 Jan 2025 04:01:11 +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=phrLiK//d0eCEn ZolzXK+cXxe1ShTHqvNh5uVCIaAJuyFO6I+KbkWdYQUrgzcQ6upKMcXTrXG3AS7e3MuIfasAkZudt hz48Eq9fJVaXJ1VYj1tUFSzccZPUi5Iz+dBE70QkdzaxXp/IvaOpnXkFl7C1It7VFE4muroddBRlb E18KuEl+eYqFnYAqR0/qEaWVyzmQSFqpLEhFDMnPhN4/JfYlyRAE7ca8GX/I0BSFGqiWEROc75nZH A5SBRvsJQ1VcyJXAAZgFgO7tWR7Sdh1DcUUPMC+4bPTUaM3SBq7ZhpBsP8Cugd2DvOuIlXDmnV9Mr 2KJzl4CQKq/CimfHUr6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tbAsU-0000000Dqmw-1hWU; Fri, 24 Jan 2025 04:01:06 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tbAsR-0000000Dqlp-3ark for linux-riscv@lists.infradead.org; Fri, 24 Jan 2025 04:01:04 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-216426b0865so26952115ad.0 for ; Thu, 23 Jan 2025 20:01:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737691263; x=1738296063; 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=ONfg/KkhnEJ5qJ19yPgmamI22hylkxgzUmgMs5NL8UhkeMauJz66z3p4wPPDMhosTd DnCtOV6yRaWIkXvJkzd0EBuA66Rx7v+Ihm4KQOzkNg47PRV3GoPoP0Mf2RYVVbMF8Op4 zpPm0ZCClxOkwJ17PEdCkEYAXFuVYuS5StyBKjA4mzLp30aApbrOxILw7z+E/jksI/Ju RzTsqk0guH4vndZdZw9G2lw0YhnB7SFZplGuqaCqiSAWNpi6ls/w699aMjjM6Opd+tgp HoASnzz+4pTMJQ7o6L789WMTjWSta1suxB4IDL+nXg7EsosBvI5dYdpnZaT9jeOk3xY6 0Fyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737691263; x=1738296063; 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=NWLZQEL1ADOLFso9AGt30t1YLp1ZLKMdus86+rqVlF4SBjsN7/a5I3eDJ62MwqU6MF jIeGwsx45xJ0cnx1/JssBIImHRc9gdbNkh70hC6kHQhqpWI0WGLZhBAgYuUT241GrUs4 N0vT8hllXHywZ+eG8mTNpGkfcaOtoePmQEeGg1xfNGj2OsjKwlYK3yFUbkkFyiKYkkLG vohwvDYQsYhMXs6IwmL/zwo2KEke3o1gHLIM9OmtjMAAeBZF9fnvj9YNKPU/okMjQ/Nq A4rit9pprkFypE+EKRLOXvc81sLs6lCAb1iZ4D6i3tGMhAUWbaBkVKmfEN+F72KefkLq 93YA== X-Forwarded-Encrypted: i=1; AJvYcCUrfYHd15peGuAw9DQG4Lfwc0ft7ckh8mRRYj2wNLs3P22khlIrCmrvMx0ZRluRvBh3waP+lM/oVz1HLw==@lists.infradead.org X-Gm-Message-State: AOJu0Yyib8GVwuNzoeCKfa4xTbuUv1ATi/YqNI1TcJJXOcT6tmStse0Q vgBs6dR4IXz9CSilKW7CI9IydI3Zs5JbQGBq+0HS+ZBiS34HLrTV1h7szsrMMag= X-Gm-Gg: ASbGncsylJiCdzdjVelxrd9zhowk7xadzIJt6uM6146Rh6htOuLM1FOit6KE1Rmb3jM FGVG1B/2YJjzVPeElSnnlqaYHKLTsoZYhUdSRw0gDPgnh350mLRzi1iERMdZANvWQwIQM/OQwEZ SbHUn1Aje/WbaWxkJELOI1L+72udBMU8RmEyUHhn0cNPKSBVo6ltffsm4bjhP6eNi49BNfQ/xj8 TLwOXqGm5tV4IfJuoLaj4jkjc0WloPxF08xaulab5AZgpFE3aSgGpRMKPysdZWgM6i4eP1GJkVG a16sH03uOsQxonK7eABfnFGgOal/C7TmpuifWbMDnj+Z6RsjWA== X-Google-Smtp-Source: AGHT+IHEVuIwXoOL2BRMckKQdUn6rThK8+gCeYIzAbtbkLa2fGtpENXBcF3NVF3avHHuHE184wgyUA== X-Received: by 2002:a17:903:8cb:b0:21a:874e:8adf with SMTP id d9443c01a7336-21c355dc4eemr425518995ad.45.1737691263230; Thu, 23 Jan 2025 20:01:03 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([2408:8406:78d1:bf49:24c4:f518:9b3b:36de]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21da4141d67sm6758915ad.153.2025.01.23.20.00.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Jan 2025 20:01:02 -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 v6 1/3] RISC-V: Enable cbo.clean/flush in usermode Date: Fri, 24 Jan 2025 11:59:57 +0800 Message-Id: <20250124035959.45499-2-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250124035959.45499-1-cuiyunhui@bytedance.com> References: <20250124035959.45499-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250123_200103_896383_D3287A79 X-CRM114-Status: UNSURE ( 9.70 ) 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 Fri Jan 24 03:59:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13948891 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 4F457C0218B for ; Fri, 24 Jan 2025 04:01:18 +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=/j1ISeSKt2nkNhS121qPjw3TsaBMdygWRIa0+jtpDe4=; b=aDscqX9HXMYBT7 OtcwmYP3/KZmDQdC46zNJZe1hHEKmDAG0pUg8nUXqjdzCio2SUlmuax+lYn8Pr/uKW4U1rqxrYHts aVbnZNUOooX24XkB7qG3ilX8hBktAIEyN0uQCdl/hAef4gh+wfGExLSDdb2c7yAs+Yrj+G/9wQ1WA G/uMceusfrXK65OXCp1kRNAHGpBW7FQPOObY2lqgU9Wn6y8jzLWwwhTEncielu+bI0mPniEYg8kDm NxHwPharSqcmns44pylEbTRp+4WQp9QnsvRrGsmC/DZeKNgj7oUHN2dPLnigP6lglTynT6tCUljT0 etN7zpqzVb5KppGaH9Uw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tbAsa-0000000Dqpo-47f7; Fri, 24 Jan 2025 04:01:12 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tbAsY-0000000Dqot-3voI for linux-riscv@lists.infradead.org; Fri, 24 Jan 2025 04:01:12 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2166f1e589cso40446345ad.3 for ; Thu, 23 Jan 2025 20:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737691270; x=1738296070; 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=uhogcwNy3A24ar7Arj4nwWwwc1NEi0tTGPamBbIerrs=; b=l1XgPmYnWO4n7rJp/qj4jgojG0yf3osYICFo7zVYkvvjomdiUPXYbwhr9g7DXglunH Mp56amHcS4WQ9ZzYPCHdcURLYr6mNLumjIkcBFjtsZazkMPyx9tSqMDWHpEnfM5GG5Z2 RajFgw/79O01M3k1yKIHYjeGb6sJcIk4AChHqFIAfO9QHfOaC3Ww6ifb+63MLBeSwY1C 9XZbIlbQVz0ff5NsDAMnOk7Wy3XGFfvuQ1xbRwzswt/92xnS6kX1M+AMmHouX2vz4WKb IJFnTAxWrw5jajf5DsYPp63/zZSHmiEZ4dfakW+nbVKlaKlX0ZhLjQbg52AB4akdVEKh Bbsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737691270; x=1738296070; 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=uhogcwNy3A24ar7Arj4nwWwwc1NEi0tTGPamBbIerrs=; b=Dn/NNQqN+rm9aRR+t6qshEYlyhmEzwPD3Ot+GY0rmHMJ0qMfkz9i/mrSpV9HwI3itb n6bCct2LoEoQUwH4kAjEuzkTpr8tMvSuD4aZ9pOuKjE5bbK7x3lPXoCl30hmW9OA873f d8ClKSY6yHuyw3wRUDlRJyOl7DX69fhpED04UzPTOB9nYBghu5dQ+aXu5IMSqRoggi68 h9ZUaPYsB96KeM7xrQGN4AnaB4SW+Ct6r7k0Cj4BsNsetMDh/ISZnPoQcRadowvuVZ/x Cw15pAl0FyzLxN5esFdgvfLw+4XHM2QHTR+04Ux3L5OCz2TSbXBe2DBhOI1KJBmKRfN7 wL/w== X-Forwarded-Encrypted: i=1; AJvYcCXLo9GUaRJa94EV+jzsHSEIu59dFfo9iKUZejySdMMlFlSipWeSFJ34KffYXGbcGMHhFYGdjoM/vdmyTQ==@lists.infradead.org X-Gm-Message-State: AOJu0Ywyl4a8jxZY1wcLDMpGRiDgsMjGVgH18jcQqom+MEXE4kv8CPYv hfB9yozD5p/kIKP1xkUb6hKp6svYKu6gaec7n/TOndqNQQLW1TlvO738sMdFuSM= X-Gm-Gg: ASbGncuIIMsm43G+UwCD2Rcz5DrH+5YTSjoPtuxFrb4E/j6s2SzQ98+mDOf4zB93zPy TwVDxHf1NqMAmzdS0jI3Yw0rIz1JoyGV+azedlSrunEVulYuUS9T71YvWl9O4KgHn2JpGAw7tKM wauwpZ3hRdDrV2UuYo5nPbtm4F4dE6B/yvkOD3oYctzTZj0I+ttHeXvHdEQy9O3IxPU8s6fNFbe d4rv0IiamypZSn3XVpA7/ZBPRMYdGAy+sWT/gRQymdjR4IVJvfssNmQCQJoP3NRj3oYbxd6mP7a ZX9IPr9FmLGYmWQjQsmPzK3rfJU07dmTThHe20j1NualxFX21g== X-Google-Smtp-Source: AGHT+IHypLNaXsQx1FvJy6sHsbSOt7rVRjml9Nk+TXnCiyBsirRqofRzqo0H1bHoO0B4nLDc9UgDlQ== X-Received: by 2002:a17:903:1381:b0:216:361a:783d with SMTP id d9443c01a7336-21c3562097amr473816585ad.28.1737691270197; Thu, 23 Jan 2025 20:01:10 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([2408:8406:78d1:bf49:24c4:f518:9b3b:36de]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21da4141d67sm6758915ad.153.2025.01.23.20.01.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Jan 2025 20:01:09 -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 v6 2/3] RISC-V: hwprobe: Expose Zicbom extension and its block size Date: Fri, 24 Jan 2025 11:59:58 +0800 Message-Id: <20250124035959.45499-3-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250124035959.45499-1-cuiyunhui@bytedance.com> References: <20250124035959.45499-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250123_200110_982230_E570FCF8 X-CRM114-Status: GOOD ( 12.93 ) 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 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. + * :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. @@ -293,3 +296,6 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_MISALIGNED_VECTOR_UNSUPPORTED`: Misaligned vector 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/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..b47939f5ffee 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); @@ -160,7 +161,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; @@ -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 Fri Jan 24 03:59:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yunhui cui X-Patchwork-Id: 13948892 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 1CEF2C02181 for ; Fri, 24 Jan 2025 04:01: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=JOTMjmVOwz8zunZj7dszqJpZm9AA5TsOGK5Xz0wgyZU=; b=p4hT5Ju3YoxGXb iPDWrpk0NX6AxbfR085CcAfJFBuQoU4h/beWFMDveIMz2VhGN1ipvWCSvEkz33rpBJfyOcO0LOnNx z7ayHXaxObK4ElmJ2Ljbe+nSntSCa96VYa+HhnILWjXl6nNmvA3ZJP8n8p0Lq4onat4VDJrXsVu6x DOJBIzs4iVxehmKyW5mhf7zrXAmDcpHFxa7MiVy0d5ZNVwTZSW7/9BSVQaU6WqjlJtcA4LBnehEm5 Nki0xFkkZWW9HJftAjYoooJN6Xt2wOzo2HfvK/g4uqeHUVDXzhDyT1mjkHvMHk1FySmmHbYqF4VsI HlzaYlRzhxdKVVN4/zUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tbAsi-0000000DquK-2OoL; Fri, 24 Jan 2025 04:01:20 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tbAsf-0000000Dqsa-4BTS for linux-riscv@lists.infradead.org; Fri, 24 Jan 2025 04:01:19 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-216395e151bso22526645ad.0 for ; Thu, 23 Jan 2025 20:01:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1737691277; x=1738296077; 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=TQ4WAQzzMUKvYH9C6IokBNOHp6dAyzVD4IM2OwSuZUli3DacoC+o/fP4Wh6zHBOOVg FukzgUAMXO8bG0ez4ClksHAYcKVXXsy0SLFfzXvDGifFYrlEAMPdvHr/LcNnGnaJmSkU zg9VVFo3hWYfrZtxBtDbj1+lole3O33olsnalng6jpuqDrxaU5i4T+k9ZaAvi67DYgiR YFVGDX0oOK5q7ZeRw3hTV88oeIHAuN3ACN7Hf1inHuIeP141mBjptlXk0943nBrdSMdV E+VoyzE4jRECGAiHZQWnmYyDAzUE027HIPO9WfgQJuk27XMZoCz3b6EjFo3o3I4KYxSK BrEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737691277; x=1738296077; 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=Plt45obdAYshZ+xViC3GVTtlfyf3IiECU4dBvJcKMPM88y9YdSn7VZiSIfAiECMQp2 PcxCStEc5A0Hf8otRZQP9wwue16tAoU28VS86dh2Fc/kiiJ+1P9bR6mBotkCWdotWT9z +LpBvtG9U2Z1QONySNpsJi6GfUpgwZW7YbptXwSVRB+J942ykiPAR1hGVibZlvpW8fBs hFWmcGOIFv4rFOh4WEwXsXtfBIkgFSwVWwi4nJdaX3BPQ4ES9UmpwD5Onbj0bQg4MqaI pksk6EBPbEBbdjYLn2dTQKDuubcl+4O4e3v7heay68eHX1Bpl++zGRivKG1nE90ck0Mh cKRA== X-Forwarded-Encrypted: i=1; AJvYcCV/Ye5ccU/ZjMyE2+Fcuxf9xFYWAPf/ixPURoe88Wa0FdUZhkTYesHndCbUcGt8M0zj8HsteFHulyozEA==@lists.infradead.org X-Gm-Message-State: AOJu0YxyMUZ2TNZxU5LrCmv+jvEO26/4EC1mzOqkKDe8l1o8qg9/DpVj k4P4Spem5zvt3SSlmwfsRdAmu+EhuHzshp2dcNBdj2CPkOe9WbQuWhpJiF1Ke1w= X-Gm-Gg: ASbGnctEApcxHw46xPqmgT9MC/uz+Z7KsjKVKMNjYRN0JZnPf0Nl8pmOBBxfuE4i6BQ wLq7URy27Hp2TPVPvjrcMTl/nuBYkzUJZaklQefKJPG9YBYkhmVURT1QYL+T61XGPeHlz5Qke1+ AcW6mscUyt/gr3DbB5rRpqXBYa15oWbvskua0t+KLBHMyZtSKj8PYSkV+WQgC6D7dNrExskBPQt yQQyzCXfQoAFVsCzpbD3X71TIuzwDgp6pROr184db+hfAOcbV9SYLjUERzBPCLVC5iQi2M26z36 D/WiC06iYBdKoUij9duz8OqfN6v2zYgnpE1QUq3/OZdXrYkmXg== X-Google-Smtp-Source: AGHT+IEmNJ9PTxDO/9xUv7qTG6D6YOowwQFpMMoo6I4xfnFmtGI8+HqdGOFtB4iDinl8gA0atu0SWA== X-Received: by 2002:a17:903:124b:b0:215:98e7:9b1 with SMTP id d9443c01a7336-21d993177a2mr87590995ad.5.1737691277079; Thu, 23 Jan 2025 20:01:17 -0800 (PST) Received: from L6YN4KR4K9.bytedance.net ([2408:8406:78d1:bf49:24c4:f518:9b3b:36de]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21da4141d67sm6758915ad.153.2025.01.23.20.01.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 23 Jan 2025 20:01:16 -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 v6 3/3] RISC-V: selftests: Add TEST_ZICBOM into CBO tests Date: Fri, 24 Jan 2025 11:59:59 +0800 Message-Id: <20250124035959.45499-4-cuiyunhui@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20250124035959.45499-1-cuiyunhui@bytedance.com> References: <20250124035959.45499-1-cuiyunhui@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250123_200118_034797_7B685EE1 X-CRM114-Status: GOOD ( 14.51 ) 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)