From nobody Mon Jun 8 06:38:44 2026 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D6A8389110 for ; Mon, 1 Jun 2026 08:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780303246; cv=none; b=mXQuaq8evFDjB8Al0s4QoLItDl5BmPZnSTk9uOkQYgbXW/c+8UVfjFXLAXonEHnbHjTioXTlbI/HZyUfb2IISZwKf8x0X8XcB2ytDC4KGMlE8dR1r6tE2rUD+l4Q7ZJ6tvCxUwzxKmsJofZCvCvpkExZSxhzUkTy+TgBFgf71Aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780303246; c=relaxed/simple; bh=v8xk3QHpXNBkj9I0DJjJ1PRYb/tbiijkclCWUxXXvfY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XryL8xOGUs30nHVAmE9aIYI+gRtERXpvkJ2r3FlzGwbVR8HlAUYNtUkSmxenXsUMGOuJbs8CWoMh3Nis2Xmu3xYWCXrnbaCu0GwNCL26wrgRmPUXmHcOQjY91t24zjeALxGvvNRGeX0ZfKfPmxugQ7e2ZUL8t8KiO2XNcx5o5lU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=eb8uItkr; arc=none smtp.client-ip=74.125.82.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="eb8uItkr" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-304ec41197bso2558804eec.1 for ; Mon, 01 Jun 2026 01:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1780303239; x=1780908039; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=4lscgRQDRbt2yakLS5hYeNYWDRzaYuJMCuwhj5mWoTY=; b=eb8uItkrLeJdlbWuXCWyCVXkABrGN1w5LqfoGRKUBqQC/i57iXMTj9CGpreNi8XEt8 bcjciWBoNyIcpRVvzNosFx37oXNaYgJ4HZbbnKQ/J0j6wNz4JmPp15w38KGP8WYdlBFy LhSMi73mshDVWuVixLtKazNLTGyfQkmRNyfcXiJar6xAJUC66vxoc/7uVL8sx5xtJIPJ ViwDC+vShMYtO8MaKnOya2Imc15ApnOrjE+MXp/mO1pz/aw6ODkkG4OAuWn7NcLxsVAr RMZEadFAqOKZ8we851nLOEL5DYCNdf94bQ+13GjqkgMsCt3OAKZATw8LvqQwvVmPprGL k+zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780303239; x=1780908039; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=4lscgRQDRbt2yakLS5hYeNYWDRzaYuJMCuwhj5mWoTY=; b=bgRsTeMBq8wiwINRt7vCzT3rYuT4E1BmdnRkdqdkL+91OHESAQct6yM+xK8WzBP4yG cOoYs1T7Nim9p8IRui4DDPM+AImhhIDZ5jE3wSzfOSpbloLppacYcGIurP1gFLxzk4/b ZXO6cekXUvQq6ryC4UMvoKxvmPwGQHua5W7IHkRg14YQwSJqIpIUp9PXE64V5E67cNMC JylNq10CPvV1bQRTKpG3Im6v76lwAr5VQ3vvIK1+VWposIGsP6rcePNAf3D7LNYkxXVk rpF14JXwgaat7iud6nnTXuz3sz2XJ1klp7ckWUvo+7rJ2AeH1kLTomKTqNjoI18+wMXl ca/g== X-Forwarded-Encrypted: i=1; AFNElJ9Wi/gJK/dj/3YCpe/y2I2Q8fyJMfQ+kfKmCcDJbJAR5eLGr1l5ZO0h4iwG9EzrPxhoG/N5021S38S3C8A=@vger.kernel.org X-Gm-Message-State: AOJu0YyRmDPRLkHCefJpXSKdRgxGDiZfr7JVwP19y+fMy4Vyx0Nrb8nj 7tnHCrgSyvh+A91UXNWkoMNDKoc5bCjofhrR/kM7oKn62tOAP/gdy/0OZBLrRKDE4U8= X-Gm-Gg: Acq92OEDQmdgYq0mxWglZhhk244nEUwb1l4WPTyofSimAS/3on6aBk4pN1vopUstXx6 eNLUz+psbXigYhVBx7u7c/vSRmaw1FbXSFkf1x4CGz8htQ1VYpU+yvKHlbIWBKCDpObAOv8CBML FgkIEkAweGeMA3b34PnFppQT+c3mpmpYgH0P5SASGC2J+ALqMyP3dyCnOwoG6G949qCsBtAFvac L0RU4W5amg52c8CM+rlPKImiCHbGNZU5vMJFKTbkhCeFZ0EJ8J8c+VYr/JQ/EWn+TrrMTBTaz7u B1/KPxyge98VNuBevs/te0NvbvlPj++RIdAvjiuMK5j9HGrY4zX+F2ZG4Nrg9pqrRn6Xlh25dQG KHjKkyRjaoH9R3W5Vz6/YwKeEebfbIUwyN0t1mmfUIxeIiqZKjQ8fk4J5qGTMFF5QYb0R3c1KeI LJidQEC+aER3iqzzvWEmFD3wyvEbkRp45jVODgdKRsI5czNBQqFP2oaA== X-Received: by 2002:a05:7300:6c84:b0:2d9:6373:ad24 with SMTP id 5a478bee46e88-304fa67bcafmr4151923eec.26.1780303239441; Mon, 01 Jun 2026 01:40:39 -0700 (PDT) Received: from sw07.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-304ed5b9be7sm8011818eec.27.2026.06.01.01.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 01:40:38 -0700 (PDT) From: Yong-Xuan Wang Date: Mon, 01 Jun 2026 01:40:34 -0700 Subject: [PATCH v4 1/3] KVM: RISC-V: SBI FWFT: Fix stale feature exposure after runtime extension changes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260601-kvm-get_reg_list-v2-v4-1-c88abc81ebda@sifive.com> References: <20260601-kvm-get_reg_list-v2-v4-0-c88abc81ebda@sifive.com> In-Reply-To: <20260601-kvm-get_reg_list-v2-v4-0-c88abc81ebda@sifive.com> To: Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Andrew Jones , Paolo Bonzini , Shuah Khan Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, zong.li@sifive.com, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Yong-Xuan Wang X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1780303237; l=5776; i=yongxuan.wang@sifive.com; s=20260424; h=from:subject:message-id; bh=v8xk3QHpXNBkj9I0DJjJ1PRYb/tbiijkclCWUxXXvfY=; b=1EORkE6aAPHvwki+++Fi5anJeWWxlG6JgO9U5hx75Vmk/RBJMBCu3oiM1KmnU2PCa3r+OevoK x5Y9n8XWskBCXYDCfn/p/NOQSYH6gvcbzqdVTD59VfTevV2mR0+gJAZ X-Developer-Key: i=yongxuan.wang@sifive.com; a=ed25519; pk=+8NCHB1ZJvZthQAmZspOAaqjo+/snaW8mFSiDx45HxY= Fix a bug where FWFT features could be incorrectly exposed to guests after userspace disables their dependent ISA extensions at runtime. The 'supported' field in kvm_sbi_fwft_config was set once during vCPU initialization based on the initial hardware/extension availability. However, when userspace subsequently disables ISA extensions via the KVM ONE_REG interface, the 'supported' field was not updated. This caused the following issues: 1. FWFT features would remain visible and accessible to guests even after their prerequisite ISA extensions were disabled 2. Guests could configure FWFT features that depend on disabled extensions, leading to undefined behavior 3. The static 'supported' flag and the dynamic supported() callback could disagree about feature availability The fix introduces a two-layer checking mechanism: 1. Add an optional init() callback to the kvm_sbi_fwft_feature structure for features that require hardware probing during initialization. This separates the one-time hardware detection logic from the runtime availability check. 2. Add runtime checks in all FWFT-related functions that call feature->supported(vcpu) if the callback exists. This ensures feature availability is re-evaluated based on the current ISA extension state. This approach maintains the cached 'supported' field for initialization- time decisions while ensuring runtime availability is always determined by the current vCPU configuration, not initialization-time snapshots. Fixes: 6b72fd170592 ("RISC-V: KVM: add support for FWFT SBI extension") Signed-off-by: Yong-Xuan Wang --- arch/riscv/kvm/vcpu_sbi_fwft.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c index 2eab15339694..2ad269a21021 100644 --- a/arch/riscv/kvm/vcpu_sbi_fwft.c +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c @@ -35,6 +35,16 @@ struct kvm_sbi_fwft_feature { */ bool (*supported)(struct kvm_vcpu *vcpu); =20 + /** + * @init: Probe and initialize the feature on the vcpu + * + * This callback is optional. If provided, it will be called during + * vcpu initialization to probe the feature availability and perform + * any necessary initialization. Returns true if the feature is supported + * and initialized successfully, false otherwise. + */ + bool (*init)(struct kvm_vcpu *vcpu); + /** * @reset: Reset the feature value irrespective whether feature is suppor= ted or not * @@ -137,13 +147,17 @@ static bool try_to_set_pmm(unsigned long value) =20 static bool kvm_sbi_fwft_pointer_masking_pmlen_supported(struct kvm_vcpu *= vcpu) { - struct kvm_sbi_fwft *fwft =3D vcpu_to_fwft(vcpu); + return riscv_isa_extension_available(vcpu->arch.isa, SMNPM); +} =20 - if (!riscv_isa_extension_available(vcpu->arch.isa, SMNPM)) - return false; +static bool kvm_sbi_fwft_pointer_masking_pmlen_init(struct kvm_vcpu *vcpu) +{ + struct kvm_sbi_fwft *fwft =3D vcpu_to_fwft(vcpu); =20 + preempt_disable(); fwft->have_vs_pmlen_7 =3D try_to_set_pmm(ENVCFG_PMM_PMLEN_7); fwft->have_vs_pmlen_16 =3D try_to_set_pmm(ENVCFG_PMM_PMLEN_16); + preempt_enable(); =20 return fwft->have_vs_pmlen_7 || fwft->have_vs_pmlen_16; } @@ -231,6 +245,7 @@ static const struct kvm_sbi_fwft_feature features[] =3D= { .first_reg_num =3D offsetof(struct kvm_riscv_sbi_fwft, pointer_masking.e= nable) / sizeof(unsigned long), .supported =3D kvm_sbi_fwft_pointer_masking_pmlen_supported, + .init =3D kvm_sbi_fwft_pointer_masking_pmlen_init, .reset =3D kvm_sbi_fwft_reset_pointer_masking_pmlen, .set =3D kvm_sbi_fwft_set_pointer_masking_pmlen, .get =3D kvm_sbi_fwft_get_pointer_masking_pmlen, @@ -281,6 +296,8 @@ static int kvm_fwft_get_feature(struct kvm_vcpu *vcpu, = u32 feature, =20 if (!tconf->supported || !tconf->enabled) return SBI_ERR_NOT_SUPPORTED; + else if (tconf->feature->supported && !tconf->feature->supported(vcpu)) + return SBI_ERR_NOT_SUPPORTED; =20 *conf =3D tconf; =20 @@ -365,6 +382,9 @@ static int kvm_sbi_ext_fwft_init(struct kvm_vcpu *vcpu) else conf->supported =3D true; =20 + if (conf->supported && feature->init) + conf->supported =3D feature->init(vcpu); + conf->enabled =3D conf->supported; conf->feature =3D feature; } @@ -408,6 +428,8 @@ static unsigned long kvm_sbi_ext_fwft_get_reg_count(str= uct kvm_vcpu *vcpu) conf =3D kvm_sbi_fwft_get_config(vcpu, feature->id); if (!conf || !conf->supported) continue; + else if (conf->feature->supported && !conf->feature->supported(vcpu)) + continue; =20 ret++; } @@ -430,6 +452,8 @@ static int kvm_sbi_ext_fwft_get_reg_id(struct kvm_vcpu = *vcpu, int index, u64 *re conf =3D kvm_sbi_fwft_get_config(vcpu, feature->id); if (!conf || !conf->supported) continue; + else if (conf->feature->supported && !conf->feature->supported(vcpu)) + continue; =20 if (index =3D=3D idx) { *reg_id =3D KVM_REG_RISCV | @@ -465,6 +489,8 @@ static int kvm_sbi_ext_fwft_get_reg(struct kvm_vcpu *vc= pu, unsigned long reg_num conf =3D kvm_sbi_fwft_get_config(vcpu, feature->id); if (!conf || !conf->supported) return -ENOENT; + else if (conf->feature->supported && !conf->feature->supported(vcpu)) + return -ENOENT; =20 switch (reg_num - feature->first_reg_num) { case 0: @@ -502,6 +528,8 @@ static int kvm_sbi_ext_fwft_set_reg(struct kvm_vcpu *vc= pu, unsigned long reg_num conf =3D kvm_sbi_fwft_get_config(vcpu, feature->id); if (!conf || !conf->supported) return -ENOENT; + else if (conf->feature->supported && !conf->feature->supported(vcpu)) + return -ENOENT; =20 switch (reg_num - feature->first_reg_num) { case 0: --=20 2.43.7 From nobody Mon Jun 8 06:38:44 2026 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 417601E885A for ; Mon, 1 Jun 2026 08:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780303246; cv=none; b=Kfe7eJbye9V/FREruB6WYQ/twlol84jUR4tGJ25WRDkNgNtEBkZrpAf7Q3HNB7P2x2D66tYRcz/LX4SPqKDvBifycLCYhH+M6z+IeLzjtzn9Y9k+lDh/ZgIKjS1C4NdcwikmcH7GKI7FTQrvtTZZPCvkDc6KZ8vlQv29oDJC/vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780303246; c=relaxed/simple; bh=FNI4e0Y9g5FK2/4DBzvxjuh05HswRPQCPmugp/FnJwg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XKk2niq7rtHBap/DzH0NGXnwMZ7cGUec66TQU6UNsXq0eO25zthvgx1ZTxrjbmmp/BJmQuokNfEQbQglE8nfcjwIHmU65vbnTrRmXYsahplRhBLAyDJfYFBc6scsKYSJdoHMu85L+mFAVxFmlwpQZ2R4ZX2rrOdNZk0oKCuBVa0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=lntYhilL; arc=none smtp.client-ip=74.125.82.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="lntYhilL" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-304d0ac5e3cso4849011eec.0 for ; Mon, 01 Jun 2026 01:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1780303241; x=1780908041; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=v45EvKOKpiUmWI/368ayn/Qc0smHoYJt4UbJf2J9agE=; b=lntYhilLFc2bJaDc2BZnsz3EpjmwB1VhT0njjq6zL5zylODZL2zjiKSaZd9Qw6mx8K bmHwhfpM7dAL4Z/aCJYgp9sIs4xRHOojsFE+LCsPlO2pem7oVg18VzbhebvjxasHRcp7 0f0pqpDvyRuYXV25s+9zkphLpp3aFHaafrak1aWxw7WCvvOYk3wMYZU845Zlk5qco+pd mWk2JJ+99RApXdyKH1v8FeTAdfGMI1C/S18zRJQ2ilGU0mwoDEJ1jjWrHE+JzHhZkzB7 KkItLGvP1YUNvQcAC36kFnhUcR96M9OZnRWShhQD4/Y92dFWvbI3VkfDEnNudeVlolHY PqlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780303241; x=1780908041; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=v45EvKOKpiUmWI/368ayn/Qc0smHoYJt4UbJf2J9agE=; b=irGE6Z3+5plbUsM5oZULQDwFQXic0U/o00uBAOkWhyCUw05K8LN78709epMq9KNada BWNXWsE9AtmTtM8vftmmmbhlrHeD1Dx5U1vAM63dP76guzPVCKrpszaNeV2X3zJDHabo OAz3IAv40Ih2fqdAi5QwXiGuTKxSGd3fMk+OzTx/aXvbWC1UpST6WPP7+32Fghhv9IpJ auAfnYX8MBBweZm4CIc/PIU12qjeOzB8UNz2zD5hxouFuJNPuGvMz8Ymmld5L1B3Dim7 cne+pRX6MO/wvHVAeLBHi8HZOqUFJ0ObQ+Kjv+U9pz30f/jFyLGVzSMZUObhj0LjtVDc YrGQ== X-Forwarded-Encrypted: i=1; AFNElJ9vSJnlZSGAZOmvMT+SyG1XpL/H+QDsuU3XUnCy0KrmZxKv5Mk3RnQIVlBCIvyTFEvbjlnPBoWqtkLKg/8=@vger.kernel.org X-Gm-Message-State: AOJu0Yyp374OS6vikvjxSVvZdV6U8BWFxPKrluSrGbgfNf4GniFPNBjA Gh+CG3RPltvoIhJR5G2gZMKOnqFAIwgXywNzCs5jB8S5wdfwLR3ntZN2ANODo6TsvkU= X-Gm-Gg: Acq92OHYdlR4Xo3bLfs7ZLgZ2sygdH/a/N3HxPw0wpvwiEyNeyGIfgZu0sGPdOD7Ssf XqhiE6I+b57YeQkFA29ZO8jfglDFJ1alfQMwbyCyKq8iJfqjGVz0ua5Nh5j5vqM+qJf5ky/d/Lj 7kKNwFd+WnuN8s9mkQdNXbb94DZAHsfU+5qBogvHiEQ2B7mArcsOuuWpZo+a+VfB8AIkraNhk23 91+v/sLySGJGHfGTbiCbsk6Vh5F4V0QD12NpU+ZXFXbgYozXloaxey2Y4NZRREfxBZchur8nAzj 93LDdfihJDCClWexTIbj0TXN5DtRqCs+pdSBICIuvm9qXo7RmisN4GA8+tp1SGGaTYrz60x8uIF C/vtM2emTJhGhB1pb9nxoUkzjX7YdGerScpZhhp14AhRo7sqTFmqXKFXjJA0RVeYq2LPyZwtJa4 wGrx6kssERat9CN4uXlOl2rdp12Jby6bYNeQp4hcHCWC2z2+z1wCdkxod6Vjcn6OR6 X-Received: by 2002:a05:7300:4312:b0:2c8:6361:ab2e with SMTP id 5a478bee46e88-304fa55b483mr5275232eec.8.1780303240985; Mon, 01 Jun 2026 01:40:40 -0700 (PDT) Received: from sw07.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-304ed5b9be7sm8011818eec.27.2026.06.01.01.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 01:40:39 -0700 (PDT) From: Yong-Xuan Wang Date: Mon, 01 Jun 2026 01:40:35 -0700 Subject: [PATCH v4 2/3] KVM: riscv: selftests: Refactor ISA and SBI extension sublist macros Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260601-kvm-get_reg_list-v2-v4-2-c88abc81ebda@sifive.com> References: <20260601-kvm-get_reg_list-v2-v4-0-c88abc81ebda@sifive.com> In-Reply-To: <20260601-kvm-get_reg_list-v2-v4-0-c88abc81ebda@sifive.com> To: Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Andrew Jones , Paolo Bonzini , Shuah Khan Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, zong.li@sifive.com, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Yong-Xuan Wang X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1780303237; l=6365; i=yongxuan.wang@sifive.com; s=20260424; h=from:subject:message-id; bh=FNI4e0Y9g5FK2/4DBzvxjuh05HswRPQCPmugp/FnJwg=; b=MQ06NJgix/Zxl//w8IbQdbNn3SaNFFRcNUH/9n8W6PwJ3yigUdSvO65zzH5h0c70kLUSFb42g WWXCEEyYLvPBhgoZmCwFNxwuGPzDUGE1fWhfU0HH7POi72XUxNt0sJ+ X-Developer-Key: i=yongxuan.wang@sifive.com; a=ed25519; pk=+8NCHB1ZJvZthQAmZspOAaqjo+/snaW8mFSiDx45HxY= Refactor the get-reg-list test to use unified sublist macros for ISA and SBI extensions, eliminating code duplication and improving maintainability. Previously, each extension had its own hand-coded sublist definition (e.g., SUBLIST_ZICBOM, SUBLIST_AIA, etc.) and the config structures repeated the same pattern. This made the code verbose and error-prone. Signed-off-by: Yong-Xuan Wang --- tools/testing/selftests/kvm/riscv/get-reg-list.c | 78 +++++++++-----------= ---- 1 file changed, 28 insertions(+), 50 deletions(-) diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testi= ng/selftests/kvm/riscv/get-reg-list.c index 8d6fdb5d38b8..5033c09201ef 100644 --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c @@ -1013,7 +1013,7 @@ static __u64 fp_d_regs[] =3D { }; =20 /* Define a default vector registers with length. This will be overwritten= at runtime */ -static __u64 vector_regs[] =3D { +static __u64 v_regs[] =3D { KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_VECTOR | KVM_REG_RISCV= _VECTOR_CSR_REG(vstart), KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_VECTOR | KVM_REG_RISCV= _VECTOR_CSR_REG(vl), KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_VECTOR | KVM_REG_RISCV= _VECTOR_CSR_REG(vtype), @@ -1057,37 +1057,17 @@ static __u64 vector_regs[] =3D { #define SUBLIST_BASE \ {"base", .regs =3D base_regs, .regs_n =3D ARRAY_SIZE(base_regs), \ .skips_set =3D base_skips_set, .skips_set_n =3D ARRAY_SIZE(base_skips_se= t),} -#define SUBLIST_SBI_BASE \ - {"sbi-base", .feature_type =3D VCPU_FEATURE_SBI_EXT, .feature =3D KVM_RIS= CV_SBI_EXT_V01, \ - .regs =3D sbi_base_regs, .regs_n =3D ARRAY_SIZE(sbi_base_regs),} -#define SUBLIST_SBI_STA \ - {"sbi-sta", .feature_type =3D VCPU_FEATURE_SBI_EXT, .feature =3D KVM_RISC= V_SBI_EXT_STA, \ - .regs =3D sbi_sta_regs, .regs_n =3D ARRAY_SIZE(sbi_sta_regs),} -#define SUBLIST_SBI_FWFT \ - {"sbi-fwft", .feature_type =3D VCPU_FEATURE_SBI_EXT, .feature =3D KVM_RIS= CV_SBI_EXT_FWFT, \ - .regs =3D sbi_fwft_regs, .regs_n =3D ARRAY_SIZE(sbi_fwft_regs),} -#define SUBLIST_ZICBOM \ - {"zicbom", .feature =3D KVM_RISCV_ISA_EXT_ZICBOM, .regs =3D zicbom_regs, = .regs_n =3D ARRAY_SIZE(zicbom_regs),} -#define SUBLIST_ZICBOP \ - {"zicbop", .feature =3D KVM_RISCV_ISA_EXT_ZICBOP, .regs =3D zicbop_regs, = .regs_n =3D ARRAY_SIZE(zicbop_regs),} -#define SUBLIST_ZICBOZ \ - {"zicboz", .feature =3D KVM_RISCV_ISA_EXT_ZICBOZ, .regs =3D zicboz_regs, = .regs_n =3D ARRAY_SIZE(zicboz_regs),} -#define SUBLIST_AIA \ - {"aia", .feature =3D KVM_RISCV_ISA_EXT_SSAIA, .regs =3D aia_regs, .regs_n= =3D ARRAY_SIZE(aia_regs),} -#define SUBLIST_SMSTATEEN \ - {"smstateen", .feature =3D KVM_RISCV_ISA_EXT_SMSTATEEN, .regs =3D smstate= en_regs, .regs_n =3D ARRAY_SIZE(smstateen_regs),} -#define SUBLIST_FP_F \ - {"fp_f", .feature =3D KVM_RISCV_ISA_EXT_F, .regs =3D fp_f_regs, \ - .regs_n =3D ARRAY_SIZE(fp_f_regs),} -#define SUBLIST_FP_D \ - {"fp_d", .feature =3D KVM_RISCV_ISA_EXT_D, .regs =3D fp_d_regs, \ - .regs_n =3D ARRAY_SIZE(fp_d_regs),} - -#define SUBLIST_V \ - {"v", .feature =3D KVM_RISCV_ISA_EXT_V, .regs =3D vector_regs, .regs_n = =3D ARRAY_SIZE(vector_regs),} + +#define SUBLIST_ISA(ext, extu) \ + { \ + .name =3D #ext, \ + .feature =3D KVM_RISCV_ISA_EXT_##extu, \ + .regs =3D ext##_regs, \ + .regs_n =3D ARRAY_SIZE(ext##_regs), \ + } =20 #define KVM_ISA_EXT_SIMPLE_CONFIG(ext, extu) \ -static __u64 regs_##ext[] =3D { \ +static __u64 ext##_regs[] =3D { \ KVM_REG_RISCV | KVM_REG_SIZE_ULONG | \ KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | \ KVM_RISCV_ISA_EXT_##extu, \ @@ -1095,18 +1075,22 @@ static __u64 regs_##ext[] =3D { \ static struct vcpu_reg_list config_##ext =3D { \ .sublists =3D { \ SUBLIST_BASE, \ - { \ - .name =3D #ext, \ - .feature =3D KVM_RISCV_ISA_EXT_##extu, \ - .regs =3D regs_##ext, \ - .regs_n =3D ARRAY_SIZE(regs_##ext), \ - }, \ + SUBLIST_ISA(ext, extu), \ {0}, \ }, \ } \ =20 +#define SUBLIST_SBI(ext, extu) \ + { \ + .name =3D "sbi-"#ext, \ + .feature_type =3D VCPU_FEATURE_SBI_EXT, \ + .feature =3D KVM_RISCV_SBI_EXT_##extu, \ + .regs =3D sbi_##ext##_regs, \ + .regs_n =3D ARRAY_SIZE(sbi_##ext##_regs), \ + } + #define KVM_SBI_EXT_SIMPLE_CONFIG(ext, extu) \ -static __u64 regs_sbi_##ext[] =3D { \ +static __u64 sbi_##ext##_regs[] =3D { \ KVM_REG_RISCV | KVM_REG_SIZE_ULONG | \ KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | \ KVM_RISCV_SBI_EXT_##extu, \ @@ -1114,13 +1098,7 @@ static __u64 regs_sbi_##ext[] =3D { \ static struct vcpu_reg_list config_sbi_##ext =3D { \ .sublists =3D { \ SUBLIST_BASE, \ - { \ - .name =3D "sbi-"#ext, \ - .feature_type =3D VCPU_FEATURE_SBI_EXT, \ - .feature =3D KVM_RISCV_SBI_EXT_##extu, \ - .regs =3D regs_sbi_##ext, \ - .regs_n =3D ARRAY_SIZE(regs_sbi_##ext), \ - }, \ + SUBLIST_SBI(ext, extu), \ {0}, \ }, \ } \ @@ -1129,7 +1107,7 @@ static struct vcpu_reg_list config_sbi_##ext =3D { \ static struct vcpu_reg_list config_##ext =3D { \ .sublists =3D { \ SUBLIST_BASE, \ - SUBLIST_##extu, \ + SUBLIST_ISA(ext, extu), \ {0}, \ }, \ } \ @@ -1138,14 +1116,14 @@ static struct vcpu_reg_list config_##ext =3D { \ static struct vcpu_reg_list config_sbi_##ext =3D { \ .sublists =3D { \ SUBLIST_BASE, \ - SUBLIST_SBI_##extu, \ + SUBLIST_SBI(ext, extu), \ {0}, \ }, \ } \ =20 /* Note: The below list is alphabetically sorted. */ =20 -KVM_SBI_EXT_SUBLIST_CONFIG(base, BASE); +KVM_SBI_EXT_SUBLIST_CONFIG(base, V01); KVM_SBI_EXT_SUBLIST_CONFIG(sta, STA); KVM_SBI_EXT_SIMPLE_CONFIG(pmu, PMU); KVM_SBI_EXT_SIMPLE_CONFIG(dbcn, DBCN); @@ -1153,9 +1131,9 @@ KVM_SBI_EXT_SIMPLE_CONFIG(susp, SUSP); KVM_SBI_EXT_SIMPLE_CONFIG(mpxy, MPXY); KVM_SBI_EXT_SUBLIST_CONFIG(fwft, FWFT); =20 -KVM_ISA_EXT_SUBLIST_CONFIG(aia, AIA); -KVM_ISA_EXT_SUBLIST_CONFIG(fp_f, FP_F); -KVM_ISA_EXT_SUBLIST_CONFIG(fp_d, FP_D); +KVM_ISA_EXT_SUBLIST_CONFIG(aia, SSAIA); +KVM_ISA_EXT_SUBLIST_CONFIG(fp_f, F); +KVM_ISA_EXT_SUBLIST_CONFIG(fp_d, D); KVM_ISA_EXT_SUBLIST_CONFIG(v, V); KVM_ISA_EXT_SIMPLE_CONFIG(h, H); KVM_ISA_EXT_SIMPLE_CONFIG(smnpm, SMNPM); --=20 2.43.7 From nobody Mon Jun 8 06:38:44 2026 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A16538D3EA for ; Mon, 1 Jun 2026 08:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780303249; cv=none; b=moM3UdWodKkG4phV8PHPt8XwN+R8MCe9sJKK/E7qb0iirXx23eSA6ZV4h+T1G/R8LE4JzYYv9Uk4OEauOa5UHyHV+OmHHJqjcyGPZHVyMp5NYVWkTbiF3hksEWTk0APYhdhViJ7zQOc4XS6QWMmz+5qi8+T/yLYuYNDtw3HVvbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780303249; c=relaxed/simple; bh=dvopGRgDaRky18g/xnQDE1UFxOqmLWbk1vHTjPzPMBI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QXp7AfUcad+tZ9ryMCTCwaw06qlCJvXH7/axlPkH7vo3OHtZXZQrzJdjbT9aZuIkGdISPw5+10KLhGjVnzdDCDhKmq4My+0bM91MLzs2kIPergC6QghnHi937Ij3vIfvSf2B70OdQoMqj1o8pYMMh4U1u2LZaGQStjQdW/VzSdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=ABBvk80x; arc=none smtp.client-ip=74.125.82.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="ABBvk80x" Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-304d0ac5e3cso4849041eec.0 for ; Mon, 01 Jun 2026 01:40:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1780303242; x=1780908042; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZpUjEIn4ZuMPGVsNdGCP5Htku1Dpr8xmIsStUVmQFFI=; b=ABBvk80xwBxEyqbYca1SqP6g/NLlKno7sXvkGt2i/lMEfOtGEceC3sAZN/A0wYUH2E 4cGfjS9iexdNeqp3dcHvMyth/8NPdLxymT9X4Nl9aaRhGAz3bz0M5NtKlubkNNqOMSAz p31Xdubn6Mmcr+jiE7U2U0DWhdajKS+Q8bOLaym2V2/nmyu3D3moGKXt9chxFbhel8JI Ok/eSeprXePexZ7QLei+KnGG3yvlczY0jqyOSQxETravyrJvT0u7ZOOiCtPn2tkMCoZC QkaUSSpWR0ZEIZ0EV7RCPogzMW7TNL3InelqQoRp26RkVwn2ELCNuzxezWlW8Ea/UxhQ XJxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780303242; x=1780908042; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ZpUjEIn4ZuMPGVsNdGCP5Htku1Dpr8xmIsStUVmQFFI=; b=TLbeh2iIV1yaTAMU+8IpY/rZVCcpXCirnaNEn4Z0sJxIDpYWep2J452zx9AM13MKAw zRAZ89HP302DerCG2Qsa10katVaz8U5mqWBq9zoQ/gHNx7b47Ndj3NFK9bcmvFYb2VH9 YajNWZAe3/vX3vsY1TOTtO0nTm9EYW7s4Hmbv/H0WAoDFWXJd89O9nTfaZiFDe+cNfmE ddlHfkOYIBgzEOOtnnXGrT3hjKvKeLvFHz3HnIdeLfHNmcPLqE1aWGMdB5eOzDLu2he2 s67m3GxIv8zMrw/HZRrFPyCBviNGYuNSVouTJx/vcAVQofyojst4XOJMuTHwDj6CqEDM iwmA== X-Forwarded-Encrypted: i=1; AFNElJ+pVoOhD97kBFjty29DD35YIuRw8TEQuwoNGgO/SJCPPCpUWXa6xCllMH2Hbjv5ybTA57vjld75kpmesuY=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9irTa/QF4FuObYlSjojoLWDhMHTc+Cno2e7bU/OWe71lYIzge 4XOiajH1KyK/zgwazfKyQ0ZONHl0TtEw0J2gnAIPh4MqbzBjum1gSYyTIcblu6tWraxe4DsbYT9 RkhF3Bjk= X-Gm-Gg: Acq92OGxcQbVocwWne8QbACcaUEUxmUko+cCpvhO4hn+r3zjFteEFIZYC4a6zYypgRJ qVMeFMofnQcNzULJfdWisdBm4KfC0Cug4hiwoFSJq6zcHjb1Rc6S16mo9s4T/iZwQ+Dg1+eLnFK ElBPp4f28vQqrPeTSXhrRp+LG/GCTwZf7MZCIdDWp1p2TaHZHP8Iyj9ngIvnzRphN4jX6YTq+X1 jjdteb0sOX7pP2UcQi/RVjdp3W6rKmYTesw+rj53ZulWxJLqvm26sldPswp2px9FnTl2M2qqK1U kNdrUaVsZfRGSkQd9VIxB9kDskrUxKEQzDnBopGx8LRz8mQxJPi8KreSkxfPe5yMnnlpA2mj7hQ k4KVCbSNqFAU0UGsodrkDb/E+K3Xww4sE7nmj/O0xoF28IUxmr/ZA7j+ShOgwlE4arfFBItwl4s 2jvEzfVIUiwgGY9NE4ydMuHr+G8y2ptPAy0OMv350IOON2fvikUlIjsYnc2WuBtsap X-Received: by 2002:a05:7300:cd94:b0:2e0:4edd:64e4 with SMTP id 5a478bee46e88-304fa75091emr4500790eec.26.1780303242427; Mon, 01 Jun 2026 01:40:42 -0700 (PDT) Received: from sw07.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-304ed5b9be7sm8011818eec.27.2026.06.01.01.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jun 2026 01:40:41 -0700 (PDT) From: Yong-Xuan Wang Date: Mon, 01 Jun 2026 01:40:36 -0700 Subject: [PATCH v4 3/3] KVM: riscv: selftests: Split SBI FWFT into separate feature-specific sublists Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260601-kvm-get_reg_list-v2-v4-3-c88abc81ebda@sifive.com> References: <20260601-kvm-get_reg_list-v2-v4-0-c88abc81ebda@sifive.com> In-Reply-To: <20260601-kvm-get_reg_list-v2-v4-0-c88abc81ebda@sifive.com> To: Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Andrew Jones , Paolo Bonzini , Shuah Khan Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, zong.li@sifive.com, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Yong-Xuan Wang X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1780303237; l=6157; i=yongxuan.wang@sifive.com; s=20260424; h=from:subject:message-id; bh=dvopGRgDaRky18g/xnQDE1UFxOqmLWbk1vHTjPzPMBI=; b=2HV2PtEehribkyjlVJiSDoKw01n9W76kDsd12gE0hfFft+547TXue2yYjgqmdzHfFWA9qYpdt qYXVGjh7cLfCjbRbfzHbu38BJLB5UyEVKjvAT3Mu+cfea8alvWtTAM9 X-Developer-Key: i=yongxuan.wang@sifive.com; a=ed25519; pk=+8NCHB1ZJvZthQAmZspOAaqjo+/snaW8mFSiDx45HxY= Divide the monolithic SBI FWFT (Firmware Features) register list into separate sublists, each testing a specific FWFT feature independently with proper dependency checking. Previously, all FWFT features were tested together in a single sublist. This caused issues because: 1. Not all FWFT features are available on all platforms 2. Some features depend on specific ISA extensions (e.g., pointer_masking requires Smnpm) 3. Tests would fail if any single feature was unavailable Add the feature-specific SBI FWFT sublists with the following improvements: - Add check_fwft_feature() helper to verify FWFT feature availability at runtime - Update filter_reg() to handle per-feature FWFT register filtering Signed-off-by: Yong-Xuan Wang --- tools/testing/selftests/kvm/riscv/get-reg-list.c | 60 ++++++++++++++++++++= ++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testi= ng/selftests/kvm/riscv/get-reg-list.c index 5033c09201ef..cb86cb6b3635 100644 --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c @@ -27,6 +27,7 @@ enum { }; =20 static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; +static bool sbi_ext_enabled[KVM_RISCV_SBI_EXT_MAX]; =20 bool filter_reg(__u64 reg) { @@ -149,6 +150,14 @@ bool filter_reg(__u64 reg) case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_RE= G(iprio1h): case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_RE= G(iprio2h): return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA]; + /* + * FWFT misaligned delegation registers are always visible when the SBI F= WFT + * extension is enable and the host supports the misaligned delegation. + */ + case KVM_REG_RISCV_SBI_STATE | KVM_REG_RISCV_SBI_FWFT | KVM_REG_RISCV_SBI= _FWFT_REG(misaligned_deleg.enable): + case KVM_REG_RISCV_SBI_STATE | KVM_REG_RISCV_SBI_FWFT | KVM_REG_RISCV_SBI= _FWFT_REG(misaligned_deleg.flags): + case KVM_REG_RISCV_SBI_STATE | KVM_REG_RISCV_SBI_FWFT | KVM_REG_RISCV_SBI= _FWFT_REG(misaligned_deleg.value): + return sbi_ext_enabled[KVM_RISCV_SBI_EXT_FWFT]; default: break; } @@ -193,6 +202,27 @@ static int override_vector_reg_size(struct kvm_vcpu *v= cpu, struct vcpu_reg_subli return 0; } =20 +void check_fwft_feature(struct kvm_vcpu *vcpu, struct vcpu_reg_sublist *s,= u64 feature) +{ + unsigned long value; + int rc; + + /* Enable SBI FWFT extension so that we can check the supported register = */ + rc =3D __vcpu_set_reg(vcpu, feature, 1); + if (rc) + return; + + for (int i =3D 0; i < s->regs_n; i++) { + if ((s->regs[i] & KVM_REG_RISCV_TYPE_MASK) =3D=3D KVM_REG_RISCV_SBI_STAT= E) { + rc =3D __vcpu_get_reg(vcpu, s->regs[i], &value); + __TEST_REQUIRE(!rc, "%s not available, skipping tests", s->name); + } + } + + /* We should assert if disabling failed here while enabling succeeded bef= ore */ + vcpu_set_reg(vcpu, feature, 0); +} + void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c) { unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] =3D { 0 }; @@ -235,6 +265,9 @@ void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_r= eg_list *c) break; case VCPU_FEATURE_SBI_EXT: feature =3D RISCV_SBI_EXT_REG(s->feature); + if (s->feature =3D=3D KVM_RISCV_SBI_EXT_FWFT) + check_fwft_feature(vcpu, s, feature); + sbi_ext_enabled[s->feature] =3D true; break; default: TEST_FAIL("Unknown feature type"); @@ -897,11 +930,15 @@ static __u64 sbi_sta_regs[] =3D { KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_STATE | KVM_REG_RI= SCV_SBI_STA | KVM_REG_RISCV_SBI_STA_REG(shmem_hi), }; =20 -static __u64 sbi_fwft_regs[] =3D { +static __u64 sbi_fwft_misaligned_deleg_regs[] =3D { KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_EXT | KVM_REG_RISC= V_SBI_SINGLE | KVM_RISCV_SBI_EXT_FWFT, KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_STATE | KVM_REG_RI= SCV_SBI_FWFT | KVM_REG_RISCV_SBI_FWFT_REG(misaligned_deleg.enable), KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_STATE | KVM_REG_RI= SCV_SBI_FWFT | KVM_REG_RISCV_SBI_FWFT_REG(misaligned_deleg.flags), KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_STATE | KVM_REG_RI= SCV_SBI_FWFT | KVM_REG_RISCV_SBI_FWFT_REG(misaligned_deleg.value), +}; + +static __u64 sbi_fwft_pointer_masking_regs[] =3D { + KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_EXT | KVM_REG_RISC= V_SBI_SINGLE | KVM_RISCV_SBI_EXT_FWFT, KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_STATE | KVM_REG_RI= SCV_SBI_FWFT | KVM_REG_RISCV_SBI_FWFT_REG(pointer_masking.enable), KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_STATE | KVM_REG_RI= SCV_SBI_FWFT | KVM_REG_RISCV_SBI_FWFT_REG(pointer_masking.flags), KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_STATE | KVM_REG_RI= SCV_SBI_FWFT | KVM_REG_RISCV_SBI_FWFT_REG(pointer_masking.value), @@ -1129,7 +1166,6 @@ KVM_SBI_EXT_SIMPLE_CONFIG(pmu, PMU); KVM_SBI_EXT_SIMPLE_CONFIG(dbcn, DBCN); KVM_SBI_EXT_SIMPLE_CONFIG(susp, SUSP); KVM_SBI_EXT_SIMPLE_CONFIG(mpxy, MPXY); -KVM_SBI_EXT_SUBLIST_CONFIG(fwft, FWFT); =20 KVM_ISA_EXT_SUBLIST_CONFIG(aia, SSAIA); KVM_ISA_EXT_SUBLIST_CONFIG(fp_f, F); @@ -1206,6 +1242,23 @@ KVM_ISA_EXT_SIMPLE_CONFIG(zvksed, ZVKSED); KVM_ISA_EXT_SIMPLE_CONFIG(zvksh, ZVKSH); KVM_ISA_EXT_SIMPLE_CONFIG(zvkt, ZVKT); =20 +static struct vcpu_reg_list config_sbi_fwft_misaligned_deleg =3D { + .sublists =3D { + SUBLIST_BASE, + SUBLIST_SBI(fwft_misaligned_deleg, FWFT), + {0}, + }, +}; + +static struct vcpu_reg_list config_sbi_fwft_pointer_masking =3D { + .sublists =3D { + SUBLIST_BASE, + SUBLIST_ISA(smnpm, SMNPM), + SUBLIST_SBI(fwft_pointer_masking, FWFT), + {0}, + }, +}; + struct vcpu_reg_list *vcpu_configs[] =3D { &config_sbi_base, &config_sbi_sta, @@ -1213,7 +1266,8 @@ struct vcpu_reg_list *vcpu_configs[] =3D { &config_sbi_dbcn, &config_sbi_susp, &config_sbi_mpxy, - &config_sbi_fwft, + &config_sbi_fwft_misaligned_deleg, + &config_sbi_fwft_pointer_masking, &config_aia, &config_fp_f, &config_fp_d, --=20 2.43.7