From patchwork Mon Sep 18 13:15:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13389596 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 87F0BC46CA1 for ; Mon, 18 Sep 2023 13:15:30 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AvDj9xENAtW6KOMnt5UggB/i8EnPUfdU7hcSFNpbJYo=; b=cMWCzGRxXHrgQT 7WODg4reO+x8ZwiR4w0PhD6+p8xZjxee7ozykMik+YVP7USuJLSvyKpOS+P3/i9ephH5Jfnb91ivU S8XcCck64oftccFt4xjjVDYt1U59R1GdzenJpeZDVSS4tmpr26/c2rdha6VPN4WeY3yjPyGYOgEw4 1ehjyvmdjGkELAlnhYyfjd6MnMK58xWErPAc3o3d7mbadm7ZXvyVkJk/tmXIO9hadJ4em43+a/kc9 3fT1UnHqsaevBMY/NjFqf0rOOLnCKLoB2Vq6D4f5wB8gDCY2vlswAzAXttoTra+FJTTei5UKqSb5p Vdkh/bAigsOVSSohXtpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiE62-00FVk3-2n; Mon, 18 Sep 2023 13:15:26 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qiE60-00FVii-0Z for linux-riscv@lists.infradead.org; Mon, 18 Sep 2023 13:15:25 +0000 Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-503065c4b25so2726944e87.1 for ; Mon, 18 Sep 2023 06:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1695042921; x=1695647721; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FO9jFtHKdL/VA2yvoAt0QPSgBvoVTbEt9F3nOYbDAaU=; b=UwfedFiKKsKqMDafOHpt3W42xOEJm8PdDi2nk9VNWTaNgSCjzCkEhhywTnL6ir8XcT R4ouPChF7SCPzLgfaa42LK3tXuQApyxnFODgucrGIwIz3Vb0vJqFL2fKyN1BaxE/MG/A 1jCCttvIL529U9Ie9d2TYwnT0mwfM+0c6GrN5y8+YwpOaT2friY/wvlm/SfKUpDA62wP W8qaCyZAotGWBnfQA55Y363MHsrIc2HSXn0aFnXx1+bHcd8dfMGbm3wxAv6Kz2J4HxrG v0R9U3SjEF9tRRZmvrpzKjZh3bnjioOeD7ey6QA+a3yTkcAG5ebVE6rJUtUfMy8ZkZHZ PZGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695042921; x=1695647721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FO9jFtHKdL/VA2yvoAt0QPSgBvoVTbEt9F3nOYbDAaU=; b=nAO57rr6GQzQ4DwqxiSCsirFFSeYFbT/N0Lq2VAonKhmV4naQHg36O9kz9mjUreUHg WnZaw7RIEVsIEwP3FTA3tFcsb5MtVO0Ezk5J3GpToxBkUdgt5snIpR5sSs54Mc4kr0JF j+AdMQ05rjLdtCuUx/n7QttcpbG3QEqm75M1ib/30f2+S39cLRJY3OpdWBvXcee057mI 1OALeIV/J6EetEyQJotmFM6hAVA6easH0WuGnJ8UsMdugC1VRveq2g0rh9D2942vFgPl 8L9TouOwy+fV+xBies67itt5UJzKudSF7xmJTnqHri16op/QWbt0CCtnZi/RcxhAsNtw hNoA== X-Gm-Message-State: AOJu0YxAxvVCwEv9nTNws85MxCzKBU1XV1F+Aaz6vrePSGZEb9VpWIHl HY43rAg2o0e74IP7BUthRVw8K0ONuoPU2uKsfXg= X-Google-Smtp-Source: AGHT+IF1xMj+a6HUdDfGm7K2pUhrfNWIHtT8B90y3c/kxs+izdBT6mSVTwYqC+GBD5mlUYIGYxUqww== X-Received: by 2002:a05:6512:31c7:b0:500:9d4a:89ff with SMTP id j7-20020a05651231c700b005009d4a89ffmr8834854lfe.62.1695042921045; Mon, 18 Sep 2023 06:15:21 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id h1-20020a0564020e8100b00531050807a9sm1835055eda.13.2023.09.18.06.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 06:15:20 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, evan@rivosinc.com, conor.dooley@microchip.com, apatel@ventanamicro.com, xiao.w.wang@intel.com Subject: [PATCH v4 1/6] RISC-V: Make zicbom/zicboz errors consistent Date: Mon, 18 Sep 2023 15:15:20 +0200 Message-ID: <20230918131518.56803-9-ajones@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918131518.56803-8-ajones@ventanamicro.com> References: <20230918131518.56803-8-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230918_061524_212207_71E92732 X-CRM114-Status: GOOD ( 10.59 ) 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 commit c818fea83de4 ("riscv: say disabling zicbom if no or bad riscv,cbom-block-size found") improved the error messages for zicbom but zicboz was missed since its patches were in flight at the same time. Get 'em now. Signed-off-by: Andrew Jones Reviewed-by: Conor Dooley --- arch/riscv/kernel/cpufeature.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 1cfbba65d11a..f9ac2717bc7d 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -93,10 +93,10 @@ static bool riscv_isa_extension_check(int id) return true; case RISCV_ISA_EXT_ZICBOZ: if (!riscv_cboz_block_size) { - pr_err("Zicboz detected in ISA string, but no cboz-block-size found\n"); + pr_err("Zicboz detected in ISA string, disabling as no cboz-block-size found\n"); return false; } else if (!is_power_of_2(riscv_cboz_block_size)) { - pr_err("cboz-block-size present, but is not a power-of-2\n"); + pr_err("Zicboz disabled as cboz-block-size present, but is not a power-of-2\n"); return false; } return true; From patchwork Mon Sep 18 13:15:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13389597 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 E365DCD13D2 for ; Mon, 18 Sep 2023 13:15:30 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ts0mGMLfB1EX4WQwlfTwXeucDUHFthWUeQ/RM04lAPc=; b=jJlKQu+reThWIT iHwke5kZIcknxqfxL9Kx0IERH00M5ixHrgLbbNb3obB4HEkp0eqJmnwSkniIWE37rmMEe+as+M2S8 Zc8hrHr1Xd9qEPLEmcYJAA+HEAAtp2fSwXv8eBFrfByljzDmP47ClVx4cVLyKNF6wOvf2JkFKT5lR Jm8uW9ObmVTl5d02v3Qeff+85nn22m83HwiN1ezKLJNhf0HIRLsKWLRbcW09wqkUFwORt7TgjR1gk n3vqUllc4yufE46gJ5fKas4s48p2kGgzUU/Dj3+RZeZXaa9W8IdaNpmnrwjAsZO4U/IsfG79bZ3F0 aV6riVuoJWCEIjZJCZTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiE63-00FVkY-1N; Mon, 18 Sep 2023 13:15:27 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qiE60-00FVin-13 for linux-riscv@lists.infradead.org; Mon, 18 Sep 2023 13:15:25 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-52a39a1c4d5so5527302a12.3 for ; Mon, 18 Sep 2023 06:15:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1695042922; x=1695647722; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CsZRtUh4qk088++R7VgYrPCijHAh8P5AlGmexFz8Gz0=; b=pCFzSewnH6+uwv+TdDGgUHI8jBiXUHp12vPFiKPk2GIQBQ8VCCRID8fqms2XZmWKN7 LHA7k3dtbE/bffXoFsPPGlysIx/g5rYiJ/2pfSxafQzWRgF9XDMrLxaOxaUHpX2i1Ppn 2cdscqQS0i0MpmxsnmJwtA/CiTGUUeOEBTMXGuFI3ucMhBmBpJUMci3c6eUShBLnoEEM nOsL3ETL9JJrDcw30RCkb54IITqNd8qTLyaCsk7gao6w+7sqOVDjMMlXLB/OotyXUYcC qA+rLPY3tQ0N7y81G3fyWbgtPjFcNBEiZMCxxqy7MJ5P1ybcEsu6X/a1jHUxg5H/kY6R qj/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695042922; x=1695647722; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CsZRtUh4qk088++R7VgYrPCijHAh8P5AlGmexFz8Gz0=; b=YO07zNCT19AAWWusR38KjW1nn8YOlRbKMi/Zq5cM8n1W6HydZ1aaIx6mN0d3x/HcQK gJnoWiWHv8u+carVND/zJjE9smmuzpxs1q7NCyDWjre+lGNCG6OoA1OUH6LaHIXBvm5A zlTzEew15PwhIBp2awC4jUQyNhdnlQp6nA7w46K2WciOw0TwcqVVLoViCPcOPQ/PBjgW uRYOtjZaJBwCrOS+YTWg3MqgqzsTkQeC1rQ3t+Re6HdXZokEBqV9Ga8RG6dPetQOVNA9 ecYjQC9tms+un5GzuCvnnoNOdIKu+GDLf4vwPlx0/zdnHsPvVNObUypHYqADmi8bwNZN Ikmg== X-Gm-Message-State: AOJu0YxceF3DPLizSwkxS0YKQg6BL7aeXpLSxPZjRgfzQ5w7O1BPh1AV TZvR5HKxZJpudUlmiwXhcKolTCZUVBod8FNmMQc= X-Google-Smtp-Source: AGHT+IGTOyYt8EnsnV3VrcUK6joTXivzwJiosKKxznTsBnIxAkPoolWauImqqEBZ1A55QpwTFXOCJQ== X-Received: by 2002:a05:6402:2c2:b0:530:8801:47aa with SMTP id b2-20020a05640202c200b00530880147aamr7832625edx.19.1695042922474; Mon, 18 Sep 2023 06:15:22 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id v15-20020a056402348f00b005308a170845sm4604794edc.29.2023.09.18.06.15.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 06:15:22 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, evan@rivosinc.com, conor.dooley@microchip.com, apatel@ventanamicro.com, xiao.w.wang@intel.com Subject: [PATCH v4 2/6] RISC-V: Enable cbo.zero in usermode Date: Mon, 18 Sep 2023 15:15:21 +0200 Message-ID: <20230918131518.56803-10-ajones@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918131518.56803-8-ajones@ventanamicro.com> References: <20230918131518.56803-8-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230918_061524_367781_7447A20F X-CRM114-Status: GOOD ( 17.61 ) 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 When Zicboz is present, enable its instruction (cbo.zero) in usermode by setting its respective senvcfg bit. We don't bother trying to set this bit per-task, which would also require an interface for tasks to request enabling and/or disabling. Instead, permanently set the bit for each hart which has the extension when bringing it online. This patch also introduces riscv_cpu_has_extension_[un]likely() functions to check a specific hart's ISA bitmap for extensions. Prior to checking the specific hart's bitmap in these functions we try the bitmap which represents the LCD of extensions, but only when we know it will use its optimized, alternatives path by gating its call on CONFIG_RISCV_ALTERNATIVE. When alternatives are used, the compiler ensures that the invocation of the LCD search becomes a constant true or false. When it's true, even the new functions will completely vanish from their callsites. OTOH, when the LCD check is false, we need to do a search of the hart's ISA bitmap. Had we also checked the LCD bitmap without the use of alternatives, then we would have ended up with two bitmap searches instead of one. Signed-off-by: Andrew Jones Reviewed-by: Conor Dooley --- arch/riscv/include/asm/cpufeature.h | 1 + arch/riscv/include/asm/csr.h | 1 + arch/riscv/include/asm/hwcap.h | 16 ++++++++++++++++ arch/riscv/kernel/cpufeature.c | 6 ++++++ arch/riscv/kernel/setup.c | 4 ++++ arch/riscv/kernel/smpboot.c | 4 ++++ 6 files changed, 32 insertions(+) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index d0345bd659c9..13b7d35648a9 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -31,5 +31,6 @@ DECLARE_PER_CPU(long, misaligned_access_speed); extern struct riscv_isainfo hart_isa[NR_CPUS]; void check_unaligned_access(int cpu); +void riscv_user_isa_enable(void); #endif diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 777cb8299551..5fba25db82d2 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -275,6 +275,7 @@ #define CSR_SIE 0x104 #define CSR_STVEC 0x105 #define CSR_SCOUNTEREN 0x106 +#define CSR_SENVCFG 0x10a #define CSR_SSCRATCH 0x140 #define CSR_SEPC 0x141 #define CSR_SCAUSE 0x142 diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index b7b58258f6c7..31774bcdf1c6 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -70,6 +70,7 @@ #ifndef __ASSEMBLY__ #include +#include unsigned long riscv_get_elf_hwcap(void); @@ -137,6 +138,21 @@ riscv_has_extension_unlikely(const unsigned long ext) return true; } +static __always_inline bool riscv_cpu_has_extension_likely(int cpu, const unsigned long ext) +{ + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && riscv_has_extension_likely(ext)) + return true; + + return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); +} + +static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsigned long ext) +{ + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && riscv_has_extension_unlikely(ext)) + return true; + + return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); +} #endif #endif /* _ASM_RISCV_HWCAP_H */ diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index f9ac2717bc7d..8ad6da03ee34 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -653,6 +653,12 @@ static int check_unaligned_access_boot_cpu(void) arch_initcall(check_unaligned_access_boot_cpu); +void riscv_user_isa_enable(void) +{ + if (riscv_cpu_has_extension_unlikely(smp_processor_id(), RISCV_ISA_EXT_ZICBOZ)) + csr_set(CSR_SENVCFG, ENVCFG_CBZE); +} + #ifdef CONFIG_RISCV_ALTERNATIVE /* * Alternative patch sites consider 48 bits when determining when to patch diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index e600aab116a4..8fd6c02353d4 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -314,10 +315,13 @@ void __init setup_arch(char **cmdline_p) riscv_fill_hwcap(); init_rt_signal_env(); apply_boot_alternatives(); + if (IS_ENABLED(CONFIG_RISCV_ISA_ZICBOM) && riscv_isa_extension_available(NULL, ZICBOM)) riscv_noncoherent_supported(); riscv_set_dma_cache_alignment(); + + riscv_user_isa_enable(); } static int __init topology_init(void) diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 1b8da4e40a4d..d1b0a6fc3adf 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -25,6 +25,8 @@ #include #include #include + +#include #include #include #include @@ -253,6 +255,8 @@ asmlinkage __visible void smp_callin(void) elf_hwcap &= ~COMPAT_HWCAP_ISA_V; } + riscv_user_isa_enable(); + /* * Remote TLB flushes are ignored while the CPU is offline, so emit * a local TLB flush right now just in case. From patchwork Mon Sep 18 13:15:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13389598 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 8BC6FC46CA1 for ; Mon, 18 Sep 2023 13:15:33 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dRtz8YK9rcWmGqQN8w4UMCDjiKmBTApskO/2/7AfgJE=; b=Cu+B3CSGmc7W6Q /5wd3aScCGJP/zSXLcNbz9qiCEDpH2JIV4jXPsAxx1i4o461+aE5oD7Nolu8UfsGl+R1wS0Vy5HcA EBSbsaDFz5W9wPhBiiP7ZJqbmkIOtargxnldI1zrxyfkLx/qmWvCI0iS3pZdf7R5aR0VafN5NoXO6 e1OFtdfa1gcbJVY2ab8ZnDMgJWCEAbGF8hvn3ZLjQTcmGSdJPeSrOyRgahrmylDzdh9nJqZxZFyW5 zeChl6pxynVzKhYOfjtxyeKZ9hW080XJijqR80+seWMV8KhNR1NzH/tdWaA/JrZsTWWqCJO2nUcAF LyfEQP5uL5pPfEURAh+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiE66-00FVlY-0J; Mon, 18 Sep 2023 13:15:30 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qiE61-00FVj5-2L for linux-riscv@lists.infradead.org; Mon, 18 Sep 2023 13:15:27 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2bf5bf33bcdso75811171fa.0 for ; Mon, 18 Sep 2023 06:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1695042923; x=1695647723; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DTiZ9hMTKh0ItREWlKdtTv/LCx2NEpn9SM1Hm5dmra8=; b=VV1/ZUOCJcIhTancoWhCNKzvaVEB3NLqOG95JbnCrwxcebFf+nDeZs84kXR3LPCkyl E6PhQ9c9xOe1tJfjSBObZMIjiuLXUeCFFced+wEn7dcx+i9P75Oln2UFqw2YufKgtUFr H+x/qvvL4hAixYY90Qru8H2jm99m+RPZJOPr/qpYa/J7cJ410i7Lzj+134j/ONI5AQg4 YtNOt4NkcO1XMtEu5fbHuMxF98wHK6U9rJ2msLFfeT8aMbMWNPXpS3q8v2+naekTIgaE ZPGwXmVGzeiqF7kZ9pX4fM8KY0mR2MKBojHnBOz3M0YEXBkWDgX/d62xzL/UPx2XKP/V 7D5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695042923; x=1695647723; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DTiZ9hMTKh0ItREWlKdtTv/LCx2NEpn9SM1Hm5dmra8=; b=X3wOK5QteWppH9eE6Pu49aiqQYRC/0kvq8t9DAHz0QvPkjw5fu6DBMyfKequHv8qx1 TD52zTzG+zmgBeB6/CFnUx4VsS9kEchRtJ/Mrx7ACaoRHt1gZV2ZaHaRP7HDGpZS6T3x wjFylPK+BWfIuxI7qWcUOFM+62UyB6bLmb3X8Belch28hbWGEhhbAocinfknq32yqqyt nGkOrE+zZ7f2u6tGECDDSauawM9uC7sQJj9vjAYOklt5/se9YGz0EOOjlJhLrzzDWfX6 t6DoBzpDX1Ya0Hzs9ZI425RGimVe/fQoiLTSDaT72xeMHRWBnQWx200YN9nh2cPI4Pu8 PBOg== X-Gm-Message-State: AOJu0Yx7XiFO4wXVfphGWa4m8aRWnPinzegBtVuRmfU8YAIklqSW7vfh JfdywXd5ZPiQoXGcpLBjy1UgGP4S7Dd3gjdmyEw= X-Google-Smtp-Source: AGHT+IHGBp/5kZVH3trmy9p0QvhmLnPEiPOvSqQsGcaO5LLtm5af9j9jvLoaZkXQzaoAmnDgzpQ3zw== X-Received: by 2002:a2e:8215:0:b0:2bc:e2bc:81ff with SMTP id w21-20020a2e8215000000b002bce2bc81ffmr7448960ljg.51.1695042923763; Mon, 18 Sep 2023 06:15:23 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id lg13-20020a170906f88d00b009828e26e519sm6389702ejb.122.2023.09.18.06.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 06:15:23 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, evan@rivosinc.com, conor.dooley@microchip.com, apatel@ventanamicro.com, xiao.w.wang@intel.com Subject: [PATCH v4 3/6] RISC-V: hwprobe: Expose Zicboz extension and its block size Date: Mon, 18 Sep 2023 15:15:22 +0200 Message-ID: <20230918131518.56803-11-ajones@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918131518.56803-8-ajones@ventanamicro.com> References: <20230918131518.56803-8-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230918_061525_762888_3F570B07 X-CRM114-Status: GOOD ( 17.61 ) 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 Zicboz through hwprobe and also provide a key to extract its respective block size. Opportunistically add a macro and apply it to current extensions in order to avoid duplicating code. Signed-off-by: Andrew Jones Reviewed-by: Evan Green Reviewed-by: Conor Dooley --- Documentation/riscv/hwprobe.rst | 6 ++++ arch/riscv/include/asm/hwprobe.h | 2 +- arch/riscv/include/uapi/asm/hwprobe.h | 2 ++ arch/riscv/kernel/sys_riscv.c | 46 +++++++++++++++++++-------- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/Documentation/riscv/hwprobe.rst b/Documentation/riscv/hwprobe.rst index a52996b22f75..7b2384de471f 100644 --- a/Documentation/riscv/hwprobe.rst +++ b/Documentation/riscv/hwprobe.rst @@ -77,6 +77,9 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_EXT_ZBS`: The Zbs extension is supported, as defined in version 1.0 of the Bit-Manipulation ISA extensions. + * :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_KEY_CPUPERF_0`: A bitmask that contains performance information about the selected set of processors. @@ -96,3 +99,6 @@ The following keys are defined: * :c:macro:`RISCV_HWPROBE_MISALIGNED_UNSUPPORTED`: Misaligned accesses are not supported at all and will generate a misaligned address fault. + +* :c:macro:`RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE`: An unsigned int which + represents the size of the Zicboz block in bytes. diff --git a/arch/riscv/include/asm/hwprobe.h b/arch/riscv/include/asm/hwprobe.h index 78936f4ff513..39df8604fea1 100644 --- a/arch/riscv/include/asm/hwprobe.h +++ b/arch/riscv/include/asm/hwprobe.h @@ -8,6 +8,6 @@ #include -#define RISCV_HWPROBE_MAX_KEY 5 +#define RISCV_HWPROBE_MAX_KEY 6 #endif diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uapi/asm/hwprobe.h index 006bfb48343d..86d08a0e617b 100644 --- a/arch/riscv/include/uapi/asm/hwprobe.h +++ b/arch/riscv/include/uapi/asm/hwprobe.h @@ -29,6 +29,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_EXT_ZBA (1 << 3) #define RISCV_HWPROBE_EXT_ZBB (1 << 4) #define RISCV_HWPROBE_EXT_ZBS (1 << 5) +#define RISCV_HWPROBE_EXT_ZICBOZ (1 << 6) #define RISCV_HWPROBE_KEY_CPUPERF_0 5 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) @@ -36,6 +37,7 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_MISALIGNED_FAST (3 << 0) #define RISCV_HWPROBE_MISALIGNED_UNSUPPORTED (4 << 0) #define RISCV_HWPROBE_MISALIGNED_MASK (7 << 0) +#define RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE 6 /* Increase RISCV_HWPROBE_MAX_KEY when adding items. */ #endif diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index 473159b5f303..d7266a9abc66 100644 --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -145,26 +145,38 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair, for_each_cpu(cpu, cpus) { struct riscv_isainfo *isainfo = &hart_isa[cpu]; - if (riscv_isa_extension_available(isainfo->isa, ZBA)) - pair->value |= RISCV_HWPROBE_EXT_ZBA; - else - missing |= RISCV_HWPROBE_EXT_ZBA; - - if (riscv_isa_extension_available(isainfo->isa, ZBB)) - pair->value |= RISCV_HWPROBE_EXT_ZBB; - else - missing |= RISCV_HWPROBE_EXT_ZBB; - - if (riscv_isa_extension_available(isainfo->isa, ZBS)) - pair->value |= RISCV_HWPROBE_EXT_ZBS; - else - missing |= RISCV_HWPROBE_EXT_ZBS; +#define EXT_KEY(ext) \ + do { \ + if (__riscv_isa_extension_available(isainfo->isa, RISCV_ISA_EXT_##ext)) \ + pair->value |= RISCV_HWPROBE_EXT_##ext; \ + else \ + missing |= RISCV_HWPROBE_EXT_##ext; \ + } while (false) + + /* + * Only use EXT_KEY() for extensions which can be exposed to userspace, + * regardless of the kernel's configuration, as no other checks, besides + * presence in the hart_isa bitmap, are made. + */ + EXT_KEY(ZBA); + EXT_KEY(ZBB); + EXT_KEY(ZBS); + EXT_KEY(ZICBOZ); +#undef EXT_KEY } /* Now turn off reporting features if any CPU is missing it. */ pair->value &= ~missing; } +static bool hwprobe_ext0_has(const struct cpumask *cpus, unsigned long ext) +{ + struct riscv_hwprobe pair; + + hwprobe_isa_ext0(&pair, cpus); + return (pair.value & ext); +} + static u64 hwprobe_misaligned(const struct cpumask *cpus) { int cpu; @@ -215,6 +227,12 @@ static void hwprobe_one_pair(struct riscv_hwprobe *pair, pair->value = hwprobe_misaligned(cpus); break; + case RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE: + pair->value = 0; + if (hwprobe_ext0_has(cpus, RISCV_HWPROBE_EXT_ZICBOZ)) + pair->value = riscv_cboz_block_size; + break; + /* * For forward compatibility, unknown keys don't fail the whole * call, but get their element key set to -1 and value set to 0 From patchwork Mon Sep 18 13:15:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13389599 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 5AD9DCD37B0 for ; Mon, 18 Sep 2023 13:15: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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Kt7TDor2V8+i+0uLrI5Q0DY2HOyGX82IWXecX1Plj+s=; b=DSEviyXdpQskNV HTMMqGUOKUeQDuB7ZfBpDyHl2fU/w1aOQXC7U94o2H0aqGsqW10riU47OegviWYvMBFgfWNe+lDN+ YJT98WA02FxQoY2klf5T/59+B4I6IgXoVCXMDf3m5kTNe5w8WbmZk++656Xoy9Ft337U9IZ3bXrjc mxARuy9Z+HXEbWWhWDma0NJ8fy4MkE4rzbKE54npW4lTexYNAh87dVPg5OgDo6p9i7bm2yWikv7tO G9matMHfgR4ee4NXtOfAFigegS55/GaozD45xS/+2543DikwMG94fbJCvalNTk8uwRN/MZ3TttwIF tLHsqcaJr+5WfSvnegAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiE66-00FVlx-2Q; Mon, 18 Sep 2023 13:15:30 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qiE63-00FVjQ-0e for linux-riscv@lists.infradead.org; Mon, 18 Sep 2023 13:15:28 +0000 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9936b3d0286so602353566b.0 for ; Mon, 18 Sep 2023 06:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1695042925; x=1695647725; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6W2Ir1Sk4srM7JCVvNjwrt7XvrtWi/G5OfkZCNgeg30=; b=eqFS8Qyfo/QT4mfab06PcI32FOgQMjFqFmtES61mMqcJyzD7uDIGNrttDMPMmEpsUC VdHpOEmijKtulRctzhMYxW7e1vbg0wLZSZtGjBUdhPAmpOkp5Mo8vokysqrF5Ky7CHAA l0jePJ3uWSsWszZ4N1QvgRDi5f/lpGBxUOWYGDunPtS3U4AOpoyuwrZeQs/HEl6x3+Zy NxMSK2pgzIBjhGV8xTTU2KspBeEaXwR4Z0r33FtTUK3poe39fBzJjbgP1QkUbpYPq+8p KjTgooi9iJSdWIykK0N1vqSFUDSBVxNUaUVBKDAmNG/YZW5yQ847KaGnQNCRnReRgWCN GPPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695042925; x=1695647725; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6W2Ir1Sk4srM7JCVvNjwrt7XvrtWi/G5OfkZCNgeg30=; b=oi6t5BGVSu+LZaGitSyF4zUEbUcbUGqj+l/GL/PJBqnmwwKlVyE8dsmO1R6Xxv/EmW J84DqEwdG1qD52tefO+4KMm/3gILH34zuksfmUvLbiOUpd84s0/JGMsIlGyBmKpqCXjl Ij/VpISy8wxUYEcU6tcpv09loESHklYrMIx/q5K8lFOP9XXX2TnZpWbtBTZcaGFucVM/ ef/FyBIW5Ah1qTDRxrcrmL5+SA/tlqi++TyeE1qSDPMznPlkzNeQ21qER8W9WBy9z7PZ w+CA25SK2mjt77t8KIEFfLglkred7+blDU4pH+gKWHngerpySrI2Na8dCNLsEAz5ANBY uBhA== X-Gm-Message-State: AOJu0YwhtZZs18ger5TWuwe6iOm7KFUvj+Ni8swHQPclFnhuHXbJee+2 MONG47ml+hd3rFqjXQQtwH8rz5Lu7sFwMDeTsik= X-Google-Smtp-Source: AGHT+IHpIpnGU8/JCW3LZvEJRchUFZgIb9pAALn49p4SxCE7tzd6QDd18aZmtar+ANSyPAVRvkIL4A== X-Received: by 2002:a17:906:7682:b0:9a9:f239:d87b with SMTP id o2-20020a170906768200b009a9f239d87bmr7068197ejm.1.1695042925027; Mon, 18 Sep 2023 06:15:25 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id b10-20020a170906490a00b0099b5a71b0bfsm6487309ejq.94.2023.09.18.06.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 06:15:24 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, evan@rivosinc.com, conor.dooley@microchip.com, apatel@ventanamicro.com, xiao.w.wang@intel.com Subject: [PATCH v4 4/6] RISC-V: selftests: Statically link hwprobe test Date: Mon, 18 Sep 2023 15:15:23 +0200 Message-ID: <20230918131518.56803-12-ajones@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918131518.56803-8-ajones@ventanamicro.com> References: <20230918131518.56803-8-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230918_061527_239396_FD1655CA X-CRM114-Status: UNSURE ( 8.59 ) 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 Statically linking makes it more convenient to copy the test to a minimal busybox environment. Signed-off-by: Andrew Jones Reviewed-by: Conor Dooley --- tools/testing/selftests/riscv/hwprobe/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/riscv/hwprobe/Makefile b/tools/testing/selftests/riscv/hwprobe/Makefile index ebdbb3c22e54..5f614c3ba598 100644 --- a/tools/testing/selftests/riscv/hwprobe/Makefile +++ b/tools/testing/selftests/riscv/hwprobe/Makefile @@ -7,4 +7,4 @@ TEST_GEN_PROGS := hwprobe include ../../lib.mk $(OUTPUT)/hwprobe: hwprobe.c sys_hwprobe.S - $(CC) -o$@ $(CFLAGS) $(LDFLAGS) $^ + $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^ From patchwork Mon Sep 18 13:15:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13389600 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 C1CDDCD37B0 for ; Mon, 18 Sep 2023 13:15:37 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=d1VHy/YDV1mvD8a931oEOqXD5PBWt6ybwjhyng7AAxw=; b=j//4gO1zknAIz7 d3ahKBe1J36xKEnzD4GoeyeQ7V+GeMsUO2FTPBZJ68FCt4bwYlR4mzwicB4A+62wIkfitvCoZ54O9 rs65ipRI4/dHkmlU6LfNTmsNrQVBAFmWGrimw6BnalO78zIwK3tJXmzpzAmj66WeYaKpVH67NoG8R t5/gdRC3DV2SNoQPjsJx+4VuWGRvHNiBj0eq5vt5pw0bDP0e4t8Mv7OFSRj8Ou1CK1eTwItKhgzau wO84j/Q35IMmsnE8pP8AJSxF0AR/ZUkjbKMB5q/I4ZZ4s9fuUGXBJ97TvDqm0D+6U5egTqGSQlVih 8Wb2VDc4vC+1uQyHpN8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiE6A-00FVnD-1b; Mon, 18 Sep 2023 13:15:34 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qiE64-00FVkC-2T for linux-riscv@lists.infradead.org; Mon, 18 Sep 2023 13:15:30 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9a9d82d73f9so558274166b.3 for ; Mon, 18 Sep 2023 06:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1695042926; x=1695647726; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GCGTSuqvvD5txfHJJaQYik4t5PK/mtwBdizG3ZZUj7w=; b=pd+h5etkQ94sfY4xLb0NttfBmmqHug056IFC+Z62CWBFXbcocTPGjT0jGhC0xq991b Gb+7u2U3uOt/olNp+sUZWbXtGZ1PuWyxd2I6tIX4+DL0i3+XWcPVdhkmMvmx7BB6V5gl m/wBUHLiOMbh9WYdISQ8ctyVMUq4lm/76Nu6oqOMfDO+Pmj6yZCrViM/60AebkluZ+w1 4W5a2Lre59Vf243J09cEEDr3MHNkNbg2SZswd7nHJeoUbo4JOUXuX6uzWocod5czeoxc w5ZCDmt2cL5cJpAZuuoKMO8tOQecpGK0GWhjeQIfR8QJo5i1k+xy7c2dEKgvDFhnMSO7 x0hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695042926; x=1695647726; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GCGTSuqvvD5txfHJJaQYik4t5PK/mtwBdizG3ZZUj7w=; b=DidOeA8JutAyMp3wMKq7qFcEtmqUbeHl9RvScA8Hc09X621sFubzJ3VAVXKkhiM9qJ 2Xq0Mt5sr1JAtK4vHL2Y344nR4PV9brlkon8ASb1cuw+vm5SccTbBMirgZJDZhg6k0Du 0VkOb9Ri1xXIrgDzcmtnyVfP6eXiCK5m5nACRSx3jUFNXJfWvlG7AK4pHGXAY9ybvwyU SqRi+TtK8xA8o5IFgwkfK7QQKafGat8PbcWeXaKyhzDjVxo7huIlh/DDC8UZnoo76mdF nD0pSL1f69rnium3dHnvdYktpu7ciI6YQrn293B6jRtUdmSnuc4DS9PkK5MlMVlv4wqD rZzQ== X-Gm-Message-State: AOJu0YyPHIzrLamC4m1gAoUjWvU7MNHkE+p53k2n9L3klf89HFwehEZl NvtupgbmMxqtqAUZDGKtkIcApc9PQNll/3KK5aQ= X-Google-Smtp-Source: AGHT+IEmnIJavJKEJFKSD/N1apctV1oNLSIjSRPXkpAWjNRFZ603SPwvq6SCGcE8zwkd9xlEo2qUJg== X-Received: by 2002:a17:907:78d5:b0:99d:fab5:e888 with SMTP id kv21-20020a17090778d500b0099dfab5e888mr8015056ejc.34.1695042926378; Mon, 18 Sep 2023 06:15:26 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id lc25-20020a170906dff900b0099bd86f9248sm6455373ejc.63.2023.09.18.06.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 06:15:26 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, evan@rivosinc.com, conor.dooley@microchip.com, apatel@ventanamicro.com, xiao.w.wang@intel.com Subject: [PATCH v4 5/6] RISC-V: selftests: Convert hwprobe test to kselftest API Date: Mon, 18 Sep 2023 15:15:24 +0200 Message-ID: <20230918131518.56803-13-ajones@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918131518.56803-8-ajones@ventanamicro.com> References: <20230918131518.56803-8-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230918_061528_805086_47B38DC4 X-CRM114-Status: GOOD ( 17.79 ) 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 Returning (exiting with) negative exit codes isn't user friendly, because the user must output the exit code with the shell, convert it from its unsigned 8-bit value back to the negative value, and then look up where that comes from in the code (which may be multiple places). Use the kselftests TAP interface, instead. Signed-off-by: Andrew Jones --- .../testing/selftests/riscv/hwprobe/hwprobe.c | 54 +++++++------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/tools/testing/selftests/riscv/hwprobe/hwprobe.c b/tools/testing/selftests/riscv/hwprobe/hwprobe.c index 09f290a67420..4f15f1f3b4c3 100644 --- a/tools/testing/selftests/riscv/hwprobe/hwprobe.c +++ b/tools/testing/selftests/riscv/hwprobe/hwprobe.c @@ -2,6 +2,8 @@ #include #include +#include "../../kselftest.h" + /* * Rather than relying on having a new enough libc to define this, just do it * ourselves. This way we don't need to be coupled to a new-enough libc to @@ -16,6 +18,9 @@ int main(int argc, char **argv) unsigned long cpus; long out; + ksft_print_header(); + ksft_set_plan(5); + /* Fake the CPU_SET ops. */ cpus = -1; @@ -25,13 +30,16 @@ int main(int argc, char **argv) */ for (long i = 0; i < 8; i++) pairs[i].key = i; + out = riscv_hwprobe(pairs, 8, 1, &cpus, 0); if (out != 0) - return -1; + ksft_exit_fail_msg("hwprobe() failed with %ld\n", out); + for (long i = 0; i < 4; ++i) { /* Fail if the kernel claims not to recognize a base key. */ if ((i < 4) && (pairs[i].key != i)) - return -2; + ksft_exit_fail_msg("Failed to recognize base key: key != i, " + "key=%ld, i=%ld\n", pairs[i].key, i); if (pairs[i].key != RISCV_HWPROBE_KEY_BASE_BEHAVIOR) continue; @@ -39,52 +47,30 @@ int main(int argc, char **argv) if (pairs[i].value & RISCV_HWPROBE_BASE_BEHAVIOR_IMA) continue; - return -3; + ksft_exit_fail_msg("Unexpected pair: (%ld, %ld)\n", pairs[i].key, pairs[i].value); } - /* - * This should also work with a NULL CPU set, but should not work - * with an improperly supplied CPU set. - */ out = riscv_hwprobe(pairs, 8, 0, 0, 0); - if (out != 0) - return -4; + ksft_test_result(out == 0, "NULL CPU set\n"); out = riscv_hwprobe(pairs, 8, 0, &cpus, 0); - if (out == 0) - return -5; + ksft_test_result(out != 0, "Bad CPU set\n"); out = riscv_hwprobe(pairs, 8, 1, 0, 0); - if (out == 0) - return -6; + ksft_test_result(out != 0, "NULL CPU set with non-zero count\n"); - /* - * Check that keys work by providing one that we know exists, and - * checking to make sure the resultig pair is what we asked for. - */ pairs[0].key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR; out = riscv_hwprobe(pairs, 1, 1, &cpus, 0); - if (out != 0) - return -7; - if (pairs[0].key != RISCV_HWPROBE_KEY_BASE_BEHAVIOR) - return -8; + ksft_test_result(out == 0 && pairs[0].key == RISCV_HWPROBE_KEY_BASE_BEHAVIOR, + "Existing key is maintained\n"); - /* - * Check that an unknown key gets overwritten with -1, - * but doesn't block elements after it. - */ pairs[0].key = 0x5555; pairs[1].key = 1; pairs[1].value = 0xAAAA; out = riscv_hwprobe(pairs, 2, 0, 0, 0); - if (out != 0) - return -9; - - if (pairs[0].key != -1) - return -10; - - if ((pairs[1].key != 1) || (pairs[1].value == 0xAAAA)) - return -11; + ksft_test_result(out == 0 && pairs[0].key == -1 && + pairs[1].key == 1 && pairs[1].value != 0xAAAA, + "Unknown key overwritten with -1 and doesn't block other elements\n"); - return 0; + ksft_finished(); } From patchwork Mon Sep 18 13:15:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 13389601 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 18425C46CA1 for ; Mon, 18 Sep 2023 13:15:39 +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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UtgnsQld673VK8FhdPJCQdbB+nkhwd+YB4U+leRoZfk=; b=AxWNXOi5bAZfan +VLegOY9nE4c7DdegJh4IbpazHov95yi0UOD4SszNqM5tuWLCX2MPhzfzfzlVpLgMcVR+DwKfi449 LhbMWbCbYFfLKPAkZJbLpqJxajTkFsBay1MI0Jf2lTS2lJHoyDX1gB/KZJzEvu+SoBDbk6/w3y7NS uZw0ALmnB6/6e5dTGbZqLdBnMSv7iXhbK7dsn+xUmDSSwogPtwwS7mYO7S2fTZTKlNc0VqwI4EpYG GEj/JvtVwSjY4FvuUGgeXtZBFG3savFHPSkZu6LKMT7JYt2fpL2EpBwVXvdYpHBQcID9KgEpLxm+Y 9ga/BlZHgNESl1P3vo1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qiE6B-00FVnf-0R; Mon, 18 Sep 2023 13:15:35 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qiE65-00FVko-32 for linux-riscv@lists.infradead.org; Mon, 18 Sep 2023 13:15:31 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-9936b3d0286so602360666b.0 for ; Mon, 18 Sep 2023 06:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1695042927; x=1695647727; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MaxBL4GVnBdz2YK7yA8HCSEthbSs3QSGku6gLlvI2Hc=; b=M4OEwiu5pfEIM2T8D8pMVHySLcKQzC7jZ0viSkO4pwZRMQStfAxeLpJoYsIk76BhpF ORZcQRwNjsePeRFtxZvrXckQjDW5dEUTjdzYv+h6EGvlGsTbklDQKu8Plp4JhNHo7ukT al4sWp+OAzzzkV0QH8aNQGyg+xwSUCh+xKRjGaepRCVcRepeLSbycvSaFJsuf8o8x6pO enyWFMakTvhIntIsXgEx65/DzO486DjgmRtQ8sx7iUxR9j1Cq7SJUh3shG1ngfnxVK5W x+pbVrXikvVkJWq+ExfkwxT+Dtd3/nJZPk50IKmJsuXPxurw5Px0g5BMPQSgbaC3EsQS 0Opg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695042927; x=1695647727; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MaxBL4GVnBdz2YK7yA8HCSEthbSs3QSGku6gLlvI2Hc=; b=xKtziwDoQcm8+IJ28Q94tK/jDUVcAyXUtJQLNxwdPGJtpJWmCP0fXM1x8oRFLJvF3P 6Mzltn+shM9LZZdZQMq/6r2wkVs/GXDBBr3vqr77ACQ5LLzFmAih97ahxcVmJZGIKP6u jaB+E0cXdk8w2d3DeSb5f2UYyHWxd9Djiz1ejRB5aX4hpx8fx0CLJCdN9ee02KNOWi3X lAMliUivF6wirL7GskRBwbnCu6l3hAm6fHJJO6395aUWzSHaYSnnuBJ14lnztk6b3OHc cl7umwxKOTGi5UIbfosW23iwEpj561TseO/rNOMLaBGhR/1igazzP+AbZgcY1cf6VdQr 7MTw== X-Gm-Message-State: AOJu0Yyd+hrYECquvoRk+v324CvMlfIEaRT3TdvWYT/4Iyc6nBrESSwZ 9K+yWk9YPGew5u2MjbQDvtcuO3OtVP5vvKo9doU= X-Google-Smtp-Source: AGHT+IFTKd5g6iODtSVuoqtLamfHZBvarOjCJbfeK0jn/Im200pq7+VzrJt5e3uU2mSbXDrqMVuYkw== X-Received: by 2002:a17:906:20a:b0:9a5:ac56:3b63 with SMTP id 10-20020a170906020a00b009a5ac563b63mr7405232ejd.63.1695042927591; Mon, 18 Sep 2023 06:15:27 -0700 (PDT) Received: from localhost (2001-1ae9-1c2-4c00-20f-c6b4-1e57-7965.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:20f:c6b4:1e57:7965]) by smtp.gmail.com with ESMTPSA id xj7-20020a170906db0700b009adc77330ebsm5392748ejb.199.2023.09.18.06.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 06:15:27 -0700 (PDT) From: Andrew Jones To: linux-riscv@lists.infradead.org Cc: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, evan@rivosinc.com, conor.dooley@microchip.com, apatel@ventanamicro.com, xiao.w.wang@intel.com Subject: [PATCH v4 6/6] RISC-V: selftests: Add CBO tests Date: Mon, 18 Sep 2023 15:15:25 +0200 Message-ID: <20230918131518.56803-14-ajones@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230918131518.56803-8-ajones@ventanamicro.com> References: <20230918131518.56803-8-ajones@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230918_061529_978536_3F0F5B80 X-CRM114-Status: GOOD ( 26.81 ) 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 hwprobe test for Zicboz and its block size. Also, when Zicboz is present, test that cbo.zero may be issued and works. Additionally provide a command line option that enables testing that the Zicbom instructions cause SIGILL and also that cbo.zero causes SIGILL when Zicboz it's not present. The SIGILL tests require "opt-in" with a command line option because the RISC-V ISA does not require unimplemented standard opcodes to issue illegal-instruction exceptions (but hopefully most platforms do). Pinning the test to a subset of cpus with taskset will also restrict the hwprobe calls to that set. Signed-off-by: Andrew Jones Reviewed-by: Xiao Wang --- .../testing/selftests/riscv/hwprobe/Makefile | 7 +- tools/testing/selftests/riscv/hwprobe/cbo.c | 228 ++++++++++++++++++ .../testing/selftests/riscv/hwprobe/hwprobe.c | 12 +- .../testing/selftests/riscv/hwprobe/hwprobe.h | 15 ++ 4 files changed, 250 insertions(+), 12 deletions(-) create mode 100644 tools/testing/selftests/riscv/hwprobe/cbo.c create mode 100644 tools/testing/selftests/riscv/hwprobe/hwprobe.h diff --git a/tools/testing/selftests/riscv/hwprobe/Makefile b/tools/testing/selftests/riscv/hwprobe/Makefile index 5f614c3ba598..f224b84591fb 100644 --- a/tools/testing/selftests/riscv/hwprobe/Makefile +++ b/tools/testing/selftests/riscv/hwprobe/Makefile @@ -2,9 +2,14 @@ # Copyright (C) 2021 ARM Limited # Originally tools/testing/arm64/abi/Makefile -TEST_GEN_PROGS := hwprobe +CFLAGS += -I$(top_srcdir)/tools/include + +TEST_GEN_PROGS := hwprobe cbo include ../../lib.mk $(OUTPUT)/hwprobe: hwprobe.c sys_hwprobe.S $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^ + +$(OUTPUT)/cbo: cbo.c sys_hwprobe.S + $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^ diff --git a/tools/testing/selftests/riscv/hwprobe/cbo.c b/tools/testing/selftests/riscv/hwprobe/cbo.c new file mode 100644 index 000000000000..50a2cc8aef38 --- /dev/null +++ b/tools/testing/selftests/riscv/hwprobe/cbo.c @@ -0,0 +1,228 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2023 Ventana Micro Systems Inc. + * + * Run with 'taskset -c cbo' to only execute hwprobe on a + * subset of cpus, as well as only executing the tests on those cpus. + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "hwprobe.h" +#include "../../kselftest.h" + +#define MK_CBO(fn) cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15) + +static char mem[4096] __aligned(4096) = { [0 ... 4095] = 0xa5 }; + +static bool illegal_insn; + +static void sigill_handler(int sig, siginfo_t *info, void *context) +{ + unsigned long *regs = (unsigned long *)&((ucontext_t *)context)->uc_mcontext; + uint32_t insn = *(uint32_t *)regs[0]; + + assert(insn == MK_CBO(regs[11])); + + illegal_insn = true; + regs[0] += 4; +} + +static void cbo_insn(char *base, int fn) +{ + uint32_t insn = MK_CBO(fn); + + asm volatile( + "mv a0, %0\n" + "li a1, %1\n" + ".4byte %2\n" + : : "r" (base), "i" (fn), "i" (insn) : "a0", "a1", "memory"); +} + +static void cbo_inval(char *base) { cbo_insn(base, 0); } +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_zicbom(void *arg) +{ + ksft_print_msg("Testing Zicbom instructions remain privileged\n"); + + illegal_insn = false; + cbo_clean(&mem[0]); + ksft_test_result(illegal_insn, "No cbo.clean\n"); + + 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) +{ + ksft_print_msg("No Zicboz, testing cbo.zero remains privileged\n"); + + illegal_insn = false; + cbo_zero(&mem[0]); + ksft_test_result(illegal_insn, "No cbo.zero\n"); +} + +static bool is_power_of_2(__u64 n) +{ + return n != 0 && (n & (n - 1)) == 0; +} + +static void test_zicboz(void *arg) +{ + struct riscv_hwprobe pair = { + .key = RISCV_HWPROBE_KEY_ZICBOZ_BLOCK_SIZE, + }; + cpu_set_t *cpus = (cpu_set_t *)arg; + __u64 block_size; + int i, j; + 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_ZICBOZ_BLOCK_SIZE && + is_power_of_2(block_size), "Zicboz block size\n"); + ksft_print_msg("Zicboz block size: %ld\n", block_size); + + illegal_insn = false; + cbo_zero(&mem[block_size]); + ksft_test_result(!illegal_insn, "cbo.zero\n"); + + if (illegal_insn || !is_power_of_2(block_size)) { + ksft_test_result_skip("cbo.zero check\n"); + return; + } + + assert(block_size <= 1024); + + for (i = 0; i < 4096 / block_size; ++i) { + if (i % 2) + cbo_zero(&mem[i * block_size]); + } + + for (i = 0; i < 4096 / block_size; ++i) { + char expected = i % 2 ? 0x0 : 0xa5; + + for (j = 0; j < block_size; ++j) { + if (mem[i * block_size + j] != expected) { + ksft_test_result_fail("cbo.zero check\n"); + ksft_print_msg("cbo.zero check: mem[%d] != 0x%x\n", + i * block_size + j, expected); + return; + } + } + } + + ksft_test_result_pass("cbo.zero check\n"); +} + +static void check_no_zicboz_cpus(cpu_set_t *cpus) +{ + struct riscv_hwprobe pair = { + .key = RISCV_HWPROBE_KEY_IMA_EXT_0, + }; + cpu_set_t one_cpu; + int i = 0, c = 0; + long rc; + + while (i++ < CPU_COUNT(cpus)) { + while (!CPU_ISSET(c, cpus)) + ++c; + + CPU_ZERO(&one_cpu); + CPU_SET(c, &one_cpu); + + 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"); + ++c; + } +} + +enum { + TEST_ZICBOZ, + TEST_NO_ZICBOZ, + TEST_NO_ZICBOM, +}; + +static struct test_info { + bool enabled; + unsigned int nr_tests; + void (*test_fn)(void *arg); +} 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 }, +}; + +int main(int argc, char **argv) +{ + struct sigaction act = { + .sa_sigaction = &sigill_handler, + .sa_flags = SA_SIGINFO, + }; + struct riscv_hwprobe pair; + unsigned int plan = 0; + cpu_set_t cpus; + long rc; + int i; + + if (argc > 1 && !strcmp(argv[1], "--sigill")) { + rc = sigaction(SIGILL, &act, NULL); + assert(rc == 0); + tests[TEST_NO_ZICBOZ].enabled = true; + tests[TEST_NO_ZICBOM].enabled = true; + } + + rc = sched_getaffinity(0, sizeof(cpu_set_t), &cpus); + assert(rc == 0); + + ksft_print_header(); + + pair.key = RISCV_HWPROBE_KEY_IMA_EXT_0; + rc = riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)&cpus, 0); + if (rc < 0) + ksft_exit_fail_msg("hwprobe() failed with %d\n", rc); + assert(rc == 0 && pair.key == RISCV_HWPROBE_KEY_IMA_EXT_0); + + if (pair.value & RISCV_HWPROBE_EXT_ZICBOZ) { + tests[TEST_ZICBOZ].enabled = true; + tests[TEST_NO_ZICBOZ].enabled = false; + } else { + check_no_zicboz_cpus(&cpus); + } + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + plan += tests[i].enabled ? tests[i].nr_tests : 0; + + if (plan == 0) + ksft_print_msg("No tests enabled.\n"); + else + ksft_set_plan(plan); + + for (i = 0; i < ARRAY_SIZE(tests); ++i) { + if (tests[i].enabled) + tests[i].test_fn(&cpus); + } + + ksft_finished(); +} diff --git a/tools/testing/selftests/riscv/hwprobe/hwprobe.c b/tools/testing/selftests/riscv/hwprobe/hwprobe.c index 4f15f1f3b4c3..c474891df307 100644 --- a/tools/testing/selftests/riscv/hwprobe/hwprobe.c +++ b/tools/testing/selftests/riscv/hwprobe/hwprobe.c @@ -1,17 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only -#include -#include - +#include "hwprobe.h" #include "../../kselftest.h" -/* - * Rather than relying on having a new enough libc to define this, just do it - * ourselves. This way we don't need to be coupled to a new-enough libc to - * contain the call. - */ -long riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count, - size_t cpu_count, unsigned long *cpus, unsigned int flags); - int main(int argc, char **argv) { struct riscv_hwprobe pairs[8]; diff --git a/tools/testing/selftests/riscv/hwprobe/hwprobe.h b/tools/testing/selftests/riscv/hwprobe/hwprobe.h new file mode 100644 index 000000000000..721b0ce73a56 --- /dev/null +++ b/tools/testing/selftests/riscv/hwprobe/hwprobe.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef SELFTEST_RISCV_HWPROBE_H +#define SELFTEST_RISCV_HWPROBE_H +#include +#include + +/* + * Rather than relying on having a new enough libc to define this, just do it + * ourselves. This way we don't need to be coupled to a new-enough libc to + * contain the call. + */ +long riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count, + size_t cpu_count, unsigned long *cpus, unsigned int flags); + +#endif