From: sashiko-bot@kernel.org
To: "Yong-Xuan Wang" <yongxuan.wang@sifive.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 3/5] KVM: RISC-V: SBI FWFT: Fix stale feature exposure after runtime extension changes
Date: Mon, 01 Jun 2026 11:37:38 +0000 [thread overview]
Message-ID: <20260601113739.501F11F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260601-kvm-get_reg_list-v2-v5-3-415d08a2813b@sifive.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] State mutation on error path in SBI FWFT set operation permanently locks features on invalid requests.
- [High] Hiding FWFT features at runtime without reverting architectural state causes hardware to run with unadvertised features.
--
commit 7286cc45c5a1525ff749cb1b680b09d20f49fbe4
Author: Yong-Xuan Wang <yongxuan.wang@sifive.com>
KVM: RISC-V: SBI FWFT: Fix stale feature exposure after runtime extension changes
Fix a bug where FWFT features could be incorrectly exposed to guests
after userspace disables their dependent ISA extensions at runtime. The
fix adds a two-layer checking mechanism to ensure feature availability
is re-evaluated based on the current ISA extension state.
> diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c
> index aee951f2b8e63..ab39ac464ffd8 100644
> --- a/arch/riscv/kvm/vcpu_sbi_fwft.c
> +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c
[ ... ]
> @@ -527,6 +535,8 @@ static int kvm_sbi_ext_fwft_set_reg(struct kvm_vcpu *vcpu, unsigned long reg_num
> conf = 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;
[Severity: High]
This isn't a bug introduced by this patch, but this dynamic check might lock
userspace out of clearing the feature state.
If userspace disables the prerequisite ISA extension (e.g. SMNPM) via ONE_REG,
the extension is cleared from vcpu->arch.isa, but the dependent FWFT
architectural state in vcpu->arch.cfg.henvcfg remains intact.
If userspace then attempts to clear the FWFT feature state via ONE_REG, this
check returns -ENOENT because the underlying ISA extension is now disabled.
When the vCPU runs, kvm_riscv_vcpu_config_load() unconditionally writes the
stale henvcfg to the physical CSR_HENVCFG register:
arch/riscv/kvm/vcpu_config.c:kvm_riscv_vcpu_config_load() {
...
csr_write(CSR_HENVCFG, cfg->henvcfg);
...
}
Will this cause the guest to run with unadvertised hardware features enabled?
Should the architectural state be reverted before hiding the feature, or should
userspace be permitted to clear the state even if the feature is unsupported?
>
> switch (reg_num - feature->first_reg_num) {
> case 0:
[Severity: High]
This is a pre-existing issue, but I noticed a potential problem in how
feature flags are handled during guest set operations:
arch/riscv/kvm/vcpu_sbi_fwft.c:kvm_sbi_fwft_set() {
...
if (conf->flags & SBI_FWFT_SET_FLAG_LOCK)
return SBI_ERR_DENIED_LOCKED;
conf->flags = flags;
return conf->feature->set(vcpu, conf, false, value);
}
If a guest issues an SBI_EXT_FWFT_SET call with an invalid value but sets
the SBI_FWFT_SET_FLAG_LOCK flag, conf->flags is updated unconditionally.
If the feature-specific set() callback rejects the invalid value and returns
SBI_ERR_INVALID_PARAM, the hypervisor will return this error to the guest
but the lock flag remains permanently set.
Does this permanently lock the feature on invalid requests, preventing
subsequent attempts to set a valid value? Should conf->flags only be
updated if the set() callback succeeds?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260601-kvm-get_reg_list-v2-v5-0-415d08a2813b@sifive.com?part=3
next prev parent reply other threads:[~2026-06-01 11:37 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-01 10:26 [PATCH v5 0/5] KVM: riscv: Fix stale FWFT feature exposure and enhance selftests Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 10:26 ` [PATCH v5 1/5] KVM: RISC-V: SBI FWFT: Mark vCPU CSRs dirty after setting feature value Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 11:04 ` sashiko-bot
2026-06-05 15:30 ` Anup Patel
2026-06-05 15:30 ` Anup Patel
2026-06-05 15:30 ` Anup Patel
2026-06-01 10:26 ` [PATCH v5 2/5] KVM: RISC-V: SBI FWFT: Add optional init() callback for hardware probing Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-05 16:11 ` Anup Patel
2026-06-05 16:11 ` Anup Patel
2026-06-05 16:11 ` Anup Patel
2026-06-01 10:26 ` [PATCH v5 3/5] KVM: RISC-V: SBI FWFT: Fix stale feature exposure after runtime extension changes Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 11:37 ` sashiko-bot [this message]
2026-06-05 16:12 ` Anup Patel
2026-06-05 16:12 ` Anup Patel
2026-06-05 16:12 ` Anup Patel
2026-06-01 10:26 ` [PATCH v5 4/5] KVM: riscv: selftests: Refactor ISA and SBI extension sublist macros Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-05 16:13 ` Anup Patel
2026-06-05 16:13 ` Anup Patel
2026-06-05 16:13 ` Anup Patel
2026-06-01 10:26 ` [PATCH v5 5/5] KVM: riscv: selftests: Split SBI FWFT into separate feature-specific sublists Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 10:26 ` Yong-Xuan Wang
2026-06-01 11:54 ` sashiko-bot
2026-06-04 9:28 ` Yong-Xuan Wang
2026-06-05 16:14 ` Anup Patel
2026-06-05 16:14 ` Anup Patel
2026-06-05 16:14 ` Anup Patel
2026-06-05 16:16 ` [PATCH v5 0/5] KVM: riscv: Fix stale FWFT feature exposure and enhance selftests Anup Patel
2026-06-05 16:16 ` Anup Patel
2026-06-05 16:16 ` Anup Patel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260601113739.501F11F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yongxuan.wang@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.