From nobody Mon Jun 8 13:31:36 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 700E33A1A2D for ; Fri, 29 May 2026 06:28:44 +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=1780036127; cv=none; b=GlxZp+gpGdJFIP1RzLZNqUuI8uU+FEOQdpaRETW9LxXCHKkeA+8IO2dcQ63dSQGScF3rQfrAYBeSrKt3eSm6mX4i8AHfvz1vv2eZ5hqNNHptAZAzSbGm5AmAnJWJiKcqzCDUZKO43rVPeUHfZSvcz4xfH6l1705PoIozZCtevDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780036127; c=relaxed/simple; bh=gufrfTZMS1eYNpCVXosGyGtRLMto/FMoEgCvhEzoK+g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mSk8x6NbbmL02sN5pgHYhJjknxQ3QXtuL9/NFCUZyR1OQv8Mfr5Tu6txOl0UKsJeHMJr43vFHDTvLryliUQHhMbwefgsxwVT5Q+R7BX3qmi/X9DTOCm/wPT3pUi1CUGjal/MBTaLqqnREkmm2klwWDXTL2F3MSaV11a8Nn0awUI= 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=eIuW1e1E; 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="eIuW1e1E" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-304d555293aso124798eec.0 for ; Thu, 28 May 2026 23:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1780036124; x=1780640924; 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=NB+TMW9/jFeVQq09mC6JlH7aNglQQ/HmhdkvMfkdL10=; b=eIuW1e1EwFv3xQxnEYpEwVcmQP95EU/pP2Bq30khrAvnXiycNtUXZMGC/H7+tmPW5f kICyxEiXJAWCHxSW/Yf2sGaXASHK+mmwE4ZPPu4QjgSKSLYXT1F61QcbIDFRMEG7C6cy z8YMEjeG1F7usNeuoshMjHlpIEboEGo4UJtWJHEROl0ibr4bDnxysT5XgLk0Dx5mCTtZ KTGM3r2NpDk8gLgug/aqtYhsR/02LQNs48M6E+DEqC553teQ3XUIEcnam/Hzt7ANua33 6ZahTehafIwTBRsH6QJ6Gp8yrt3grHdAwpcMT+4sGQE8YQjkshPVcoam8mA8azbNuMkZ M6FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780036124; x=1780640924; 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=NB+TMW9/jFeVQq09mC6JlH7aNglQQ/HmhdkvMfkdL10=; b=f8M54OPkEcmQjDY4xX1gVOlFG8GV4tsvI0Ki2+f8/S2gzpEvhsq1O6m6g1mBYOEF7q IQ/OE3OD/QYSJwduykWSvSY1+CTydcpXiv4P9ZYIFlz2whWPAY/MeVqxulbGTTHUUD3Q dIw8AST5EJ76IIdikfM3IxyP1gJNd2VisRD9IKHO/iS18TsjpvDw8dieAE4klvp7TRYs QIDngg8AcqWMl6PkcsrcwNKluS+6K8/fLGUz/WZve7tLxDbt+oSrh9+pEPykHy4qcCMk z2hKRTgX/Z11VIThrtemGTb4/i198/cuIcWUAYDK7TCuj/cvGtmMcGJnC55s+ele/W7r nkHg== X-Forwarded-Encrypted: i=1; AFNElJ9toT2iCeXZmV2tpOwlViQqloPi1ystJiZAIQiwHjoHI+Q4UH47hLK9ygS4tMHIu2SLyDzNgqDQXnh09cM=@vger.kernel.org X-Gm-Message-State: AOJu0YzglrXX8/IdEXkNPaTKJxD72QRntxu2C5rJ5kehj/Cxd+DDq/iM E65d9k1cL4p6aj8ml5XSzGQ7p7YgrxM7MkYPsKp1hiKD75c+msQROn5U1G68T6HL29Y= X-Gm-Gg: Acq92OHyzXk0OVBhj9ioWDdy0epn2LjN9QPkvivEbfzGlv8M0rXTUaG2rRou+AFM3BV RJYuYqddQbNkhWjaZJ1j0dTZmdU+hYwN1QeMUbQfXX0Vk39N9AITgExFo2DXTKDP2tgLsBB9nVF 9ukcn1ZBi+XNxz/1XsQdNliJjCVMQi4IylL+BmJy8SllihYykMl+0vYVOck2kztD3jCM3KzqRpQ PDs2aIMHrw6k9c3py8sgDOqMuIlDFYVa6hMmaQ1d3PHyoZ/jlFNOTIARoKGyIXCCOzNkQwBySPJ YHmWMIlT7BeRv7K/x0w7XfWGERwYgg+yypI4ahSiwOHcgENFpvannfKkFr1bq5hDVgbAAopOUZf bWaYaAYC+nvWiPLANYjy2/l6YPdxDk+Lkf3Z968mu5hL4q/kOdVzGTx+0BDaQZVl0PnhlL5MTjC nY3klUvvtaAXJ8tXrqYYZlca4FKu6jmybt1pqLSVCUm/IrtBTpF2oNxg== X-Received: by 2002:a05:7301:3e18:b0:2e7:c701:aa85 with SMTP id 5a478bee46e88-304eb1fbfeemr788995eec.17.1780036124198; Thu, 28 May 2026 23:28:44 -0700 (PDT) Received: from sw07.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-304ed3358b1sm694607eec.13.2026.05.28.23.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 23:28:43 -0700 (PDT) From: Yong-Xuan Wang Date: Thu, 28 May 2026 23:28:27 -0700 Subject: [PATCH v3 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: <20260528-kvm-get_reg_list-v2-v3-1-170969a8599f@sifive.com> References: <20260528-kvm-get_reg_list-v2-v3-0-170969a8599f@sifive.com> In-Reply-To: <20260528-kvm-get_reg_list-v2-v3-0-170969a8599f@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=1780036122; l=5665; i=yongxuan.wang@sifive.com; s=20260424; h=from:subject:message-id; bh=gufrfTZMS1eYNpCVXosGyGtRLMto/FMoEgCvhEzoK+g=; b=WWBCwq4jwkp6SRoxOcz1Jqdq+qxsnLAk5+EHEMyZpoZoggSowU9LIrRhG1Qp2dAA/kMgX6pIr cPdeKvX0qchBNiYTAP5ttS8UXUQdcjMuvfybLhSsR98eOz9wk6ya0ST 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 | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c index 2eab15339694..dde6e39aab5e 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,10 +147,12 @@ 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 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); @@ -231,6 +243,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 +294,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 +380,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 +426,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 +450,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 +487,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 +526,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 13:31:36 2026 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (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 8BF7D3A7F40 for ; Fri, 29 May 2026 06:28:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780036131; cv=none; b=i2LiXPAINxVSi1Nk3YqcNtzWU/oDszk823zTMRHI5vfKpoOM3+NB+O8fD+WyynUkHpEOuLlAGjbROUFIGy/7OIrPdojeuhTns+1xHyG+keeFuiOWbSXsssjJyRcQrHqWJRwIzxKyRwrIDNZO8Go2dcHgcudKXEImyhuBHZtPJTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780036131; c=relaxed/simple; bh=FNI4e0Y9g5FK2/4DBzvxjuh05HswRPQCPmugp/FnJwg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YKBJcVqVnhRGa/jJulD6ic216Hchlxmr4j3IPJh2ujHIbbEGyNtwPfBQm8VCYqrDVzQd0aHwdz7tpGRLe2nfP5ymfvyZRELjKie53v9Ay15+QWbRjueMNL7+ykjc3tbBb8/VVORYFc3Yzdm7ksDGM1njWlTq1d7T72lSA2kxo6M= 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=bbyHOMGm; arc=none smtp.client-ip=74.125.82.174 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="bbyHOMGm" Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-304d8362a58so1000353eec.1 for ; Thu, 28 May 2026 23:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1780036125; x=1780640925; 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=bbyHOMGmafaOJ54uzljC0W/8L9aiQPYLSkosZ5dYrdthnzRSOKjzefqz7n99cr0FdJ gdxP6EJV6ejCYo7WgEUMGUokLyRR1976Wg+cA4UGwpqL2mTdl1PoS6K+Mj8Nx1mBDN5T 47aKlf0BosO5SZVlNy8xbQnUHnfLcgm1NoWMwel6chH3rJ95VsuGEi53h1bFkBryeEu/ 1fHv6K3HSHczDUcMxP9L9Qev0OBi0pAJkMcKz3TJZX5vSvMSMzHtT/wZQN7S0OvJ9ryY WdGtAxC0Y9kza/+W1Z7ZGkjrp1WdR6GPVBFRY+9VYIGB9wX3aRLmbuUOzIIdmXYlOyDl gfwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780036125; x=1780640925; 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=Fl+vDA15in6jlT3me6eMtRn8fe/hUdULQqLs1NP4PXfTxNvqBKeTfHOCTrm98yjNGF r1C72lKukJ1S5B9+wgEfcSrxMHZgGpzgJnstBLfUwzFVY5ymfNSQwnae2uWoFwThQ/JH 7uQ+CWSBw+5x1lS2PJ2Oe5SFn5ujrIsOg3nt8Z8jYWCoeUQBy449EEDla2bo5GilMP3w n4ZP0DnmysgEB53NdRB96IPp/P+g0/sa2jfp9mZ9lYzNnBer4rnUwo6IKm+RhXjTUUO8 ZF1BcW1kBdLOhPu41bdwQkqdEm5N7mESbYhIwj49aLYSY5Ax9afNVFojKqZ9oK5LBBau k0rw== X-Forwarded-Encrypted: i=1; AFNElJ/XxWOsd8oC1VkLMs5oPz7lLfNS8t79xm8hKXxObjPoz2xrxIDqoYPU1jKREa4VxSyGZiRwQKT+sCcd7YQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywhq8dMyf3wi2ZLCoIM+vbMXUy8G9YIdmPUDrXrL7ZBF8o//XWP XUjyV2LGeQu3qTwFMtBl0lYZ82qgf7gwrX44duA5Hq4MsZH2NQzjKnaoz4RJ542cUHU= X-Gm-Gg: Acq92OFG3kuigvSHrsvwCwIERcUt8pg5Qe5ooeSWRlDa2HHOqqHMUPTjdBzqswdU6ho YzKsEH3Stx7fQmA/ovC+yZrq32Z4oGIA93mN76lOkekFygvdGXOUOeYSGqh6aWtJbnWv0ig+sX2 sVHOrPRQDBr4PW+n8hNPxXvVUFhW/WpDpxgX7chjiy3WyCgqckxw6sMYB4Q3cy3AF7GiIdmdAMU ORpivM/cpU3nbMBvIAMqh91/dysps4BBqY++dgV4i9RdP3aEmmL0b7oeWxblPGXMwuow9OBNj3f vkxJybsmh+u8ODG/Mt36yYcFHBTaXp1kFqbf7O/9UqcO7yLTOfo7Nw0SQzkK3OcfWoWTg0V73rB EQRtUV39GVrVUKT1mKrci73LVV9Q376havz+mySVdBEHlyDgxcXTS6b3ZNfHEQgX+AAu7B2g+qb wwc26caj54W6nMHXb+zXQaHEW/YZRhrr9pA5U4tCE/VYaicP6VZPvkSyqQDEto8uIN X-Received: by 2002:a05:7300:5b9e:b0:2c6:67b6:3acc with SMTP id 5a478bee46e88-304eb1e9955mr723799eec.15.1780036125527; Thu, 28 May 2026 23:28:45 -0700 (PDT) Received: from sw07.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-304ed3358b1sm694607eec.13.2026.05.28.23.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 23:28:44 -0700 (PDT) From: Yong-Xuan Wang Date: Thu, 28 May 2026 23:28:28 -0700 Subject: [PATCH v3 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: <20260528-kvm-get_reg_list-v2-v3-2-170969a8599f@sifive.com> References: <20260528-kvm-get_reg_list-v2-v3-0-170969a8599f@sifive.com> In-Reply-To: <20260528-kvm-get_reg_list-v2-v3-0-170969a8599f@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=1780036122; l=6365; i=yongxuan.wang@sifive.com; s=20260424; h=from:subject:message-id; bh=FNI4e0Y9g5FK2/4DBzvxjuh05HswRPQCPmugp/FnJwg=; b=NKxY/K/jSMMPh4VOKPxki0ZAqPzHMvzBwMys9X+hufCVuPO2SlBYQdwbdx51iAE7NCNc4BsvI erwQW5palAMAEvy5VzcG592+Krbg/C9IfU8jixjzXN+8FcTyaehY+ut 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 13:31:36 2026 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (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 8BAE83A7843 for ; Fri, 29 May 2026 06:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780036130; cv=none; b=bLteeYad9SGiXkXdHwa1rRiqfxc1UDyWQGzC+BFMnN4AWGYoAZt/HfzwKk1xMHhYAlajhxLM8EhPbg0mRZCw/AICnSL6quJbacyyjV4XyTh1HFHRLuMcty7jXwIc3Lu3srhTZdLdlxYELBBSF7u1IPoUShty8mInjbPp7+6X0kA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780036130; c=relaxed/simple; bh=3uThBhNaY+zRvOn064pZTF8raJgmTDzDgSiNvxgnqt0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CObThWT2PuNAlv4K2wW/ec1TSCLK43Fw3ahCpgBQZMCfcHfdHc/UYIrbttVO9e+6v8ZwLLzElhgb8gSxrOaKw/phpjXAt1tzxz0e20eXZ4MSQJbG0gGITPkgM6UX6EQ0WXpWFQ0jnRWbw6jKZAzbt1DMmDj8UGOiqbO7LYMP0jc= 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=khpmOwDL; arc=none smtp.client-ip=74.125.82.174 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="khpmOwDL" Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-304545f5206so10268649eec.0 for ; Thu, 28 May 2026 23:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1780036127; x=1780640927; 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=gxMETX/1hxmLpjZh8E8SUrLwKpabU2lfgKz/6O/A+s8=; b=khpmOwDLwZtr949TB3tK4ktuSXLgtGcA2o0bRifRIsmWjSt45ncgs3L76RduBod8/i p6qmfcZyzFoMrmGuAnxyxp5p5hf1E2E6IFaBDiAHI2g3uG+camZLC3nTC3+aacE9fUdy 1aFxCNHG9o5fD5yHSpMXDkKC2Mn8NeU3WDW07JQES4CdA9BpzoCMVm4r9n5FEfPNIHaL TUAyC5rD8uI6DnV9lSFj2VutKx9D/J2nv7LJEeI89dhlNr3iJ3p7xpgemCNOTovvbuNg BUry9W2IctKW7FnuqGWuawv3yf1Fowrj2LuE/BTx1wLHf3LTGtQWNHhBEH8KvL16SQwm 3oZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780036127; x=1780640927; 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=gxMETX/1hxmLpjZh8E8SUrLwKpabU2lfgKz/6O/A+s8=; b=hvoFjI0blLHpoqJniQvzPx00m3/mcSY404UdmsLFKbP7G9YfbBVY6POnz5A+p5TXM5 9qSnkroaZPJmhPFxDta4kX7zLC2NyIXzIloVHdxCCiPvZnb3DOh3Get37k6xUWRmGTcl ll2gDdKri9J1w8ZKwlSMxW6MmYgMirkcjVb9Z/DsXzsPEn1Zf52HFjCueAUQJ3TJ3q/8 6XWy+5edHXOhJY0L/P1MVHdb2mLzmwk9/rAXktn5b1qdWRWXiQ6z3GrPS7AwGvutrQvy GA0oGZ0cZMrKYluxnZQ7BXdcDSJex6K8/jpnnq8Y6XojpmahoWn+ifnr6kHzjK5SCt83 W66A== X-Forwarded-Encrypted: i=1; AFNElJ+myJYTQEqI6Oo+Ohywe2jbeqlSLdyoptTY1kERCzyfSa3UBBf8rIziMwYcAo1K8BFKz9L9QiVv3t77m74=@vger.kernel.org X-Gm-Message-State: AOJu0YwiaXLzJn6v9iNrA/x8PIakzhMTBguZ8ffj+FxcV4E3e0jAOCJ6 lX5mjdzV6TZJGe/ZOtRJzHO4XfzILbUKFpB4KSmKw0ablKYT1FWd2EI39uYXHZnT+tI= X-Gm-Gg: Acq92OGClwQzVwMRDMvTDzOw7VK2RmfMO4fRqVuF32hmOCtL8dauUrpbiR0c7ja8TDS +s7IUEiI3OYb8BBgoToWKtuJIdH9/mJ58wbFhGvH95UvCwxQ1+vt7pK4mUoI0MIiLOLA6QTr1Xs 4OS80FdFzLP+2CwZ0KdwQjQ46l2QtTcom8/YOvN3wLGL71XITjL++PZfblsmfrukmxbGhve+1NZ sG0fl+LBRa5kDH8jOJp6HbRJ7ESj4RT3QmOqfaOpK2hIlm/zEqHnl7sKcTvaYCakyjZinLt1E1A kihpF8AQ4mACS7nd+L+OK5rW9Z12KZa0NIyD2GeK8MNq9QGTXFO0TTy31Kp3GOeTNROcbKS7FSk 4YGojJmZoHedbpZKX7oQF1SKaocIg+MRNe5fJnH6V1Ykdz2lbTe9Qhpkr1U0dGKxTL1qZ2aC4Db c6Ebpt6ktDwHnedkjctga/5RVDQOfPKXQk7j5jFNztz9rN717Vdb0Rlg== X-Received: by 2002:a05:7300:2154:b0:304:b93a:511a with SMTP id 5a478bee46e88-304eb204f20mr625767eec.28.1780036126724; Thu, 28 May 2026 23:28:46 -0700 (PDT) Received: from sw07.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-304ed3358b1sm694607eec.13.2026.05.28.23.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 23:28:46 -0700 (PDT) From: Yong-Xuan Wang Date: Thu, 28 May 2026 23:28:29 -0700 Subject: [PATCH v3 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: <20260528-kvm-get_reg_list-v2-v3-3-170969a8599f@sifive.com> References: <20260528-kvm-get_reg_list-v2-v3-0-170969a8599f@sifive.com> In-Reply-To: <20260528-kvm-get_reg_list-v2-v3-0-170969a8599f@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=1780036122; l=7950; i=yongxuan.wang@sifive.com; s=20260424; h=from:subject:message-id; bh=3uThBhNaY+zRvOn064pZTF8raJgmTDzDgSiNvxgnqt0=; b=UJt9lgaaEV/6X0Wm2ZL+TKZkFJtdMJtIVecgcG006PE6wBq8pql2yEe41adYrKAvTbyBu6A4f Cqk7TgKtm+kAvoqekaex5imWd74p16LOhGAiiZ36mjnuiU3bTwdENQ9 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_supported_reg() function to validate register availability based on required ISA extensions and SBI extensions - 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 | 90 ++++++++++++++++++++= ++-- 1 file changed, 83 insertions(+), 7 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..7ae55fbad29a 100644 --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c @@ -27,6 +27,23 @@ enum { }; =20 static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX]; +static bool isa_ext_enabled[KVM_RISCV_ISA_EXT_MAX]; +static bool sbi_ext_enabled[KVM_RISCV_SBI_EXT_MAX]; + +bool check_supported_reg(struct kvm_vcpu *vcpu, __u64 reg) +{ + switch (reg & ~REG_MASK) { + case KVM_REG_RISCV_SBI_STATE | KVM_REG_RISCV_SBI_FWFT | KVM_REG_RISCV_SBI= _FWFT_REG(pointer_masking.enable): + case KVM_REG_RISCV_SBI_STATE | KVM_REG_RISCV_SBI_FWFT | KVM_REG_RISCV_SBI= _FWFT_REG(pointer_masking.flags): + case KVM_REG_RISCV_SBI_STATE | KVM_REG_RISCV_SBI_FWFT | KVM_REG_RISCV_SBI= _FWFT_REG(pointer_masking.value): + return sbi_ext_enabled[KVM_RISCV_SBI_EXT_FWFT] && + isa_ext_enabled[KVM_RISCV_ISA_EXT_SMNPM]; + default: + break; + } + + return true; +} =20 bool filter_reg(__u64 reg) { @@ -149,6 +166,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,15 +218,39 @@ static int override_vector_reg_size(struct kvm_vcpu *= vcpu, 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 }; + unsigned long isa_ext_state; struct vcpu_reg_sublist *s; u64 feature; int rc; =20 - for (int i =3D 0; i < KVM_RISCV_ISA_EXT_MAX; i++) - __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(i), &isa_ext_state[i]); + for (int i =3D 0; i < KVM_RISCV_ISA_EXT_MAX; i++) { + rc =3D __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(i), &isa_ext_state); + if (!rc) + isa_ext_enabled[i] =3D !!isa_ext_state; + } =20 /* * Disable all extensions which were enabled by default @@ -209,8 +258,10 @@ void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_= reg_list *c) */ for (int i =3D 0; i < KVM_RISCV_ISA_EXT_MAX; i++) { rc =3D __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0); - if (rc && isa_ext_state[i]) + if (rc && isa_ext_enabled[i]) isa_ext_cant_disable[i] =3D true; + else + isa_ext_enabled[i] =3D false; } =20 for (int i =3D 0; i < KVM_RISCV_SBI_EXT_MAX; i++) { @@ -232,9 +283,13 @@ void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_= reg_list *c) switch (s->feature_type) { case VCPU_FEATURE_ISA_EXT: feature =3D RISCV_ISA_EXT_REG(s->feature); + isa_ext_enabled[s->feature] =3D true; 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 +952,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 +1188,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 +1264,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 +1288,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