All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bibo Mao" <maobibo@loongson.cn>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] LoongArch: KVM: Allow to set pv_feature until vCPU run
Date: Thu, 16 Jul 2026 02:03:38 +0000	[thread overview]
Message-ID: <20260716020338.888241F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260716013823.3259816-1-maobibo@loongson.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Per-vCPU execution state is used to protect VM-wide configuration, allowing malicious userspace to modify PV features while the guest is running.
- [High] The enforcement mechanism ensuring all vCPUs use identical PV features has been removed, silently allowing cross-vCPU mismatch.
--

--- Patch [1]: [PATCH] LoongArch: KVM: Allow to set pv_feature until vCPU run ---
commit bf9fe2ebf34418b4704a3fcafd58fb42df1697c5
Author: Bibo Mao <maobibo@loongson.cn>

LoongArch: KVM: Allow to set pv_feature until vCPU run

This patch modifies KVM on LoongArch to allow setting the pv_feature
multiple times during VM creation. The restriction is relaxed so that
features can be modified until the vCPU starts running, which aims to help
with VM migration.

> diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
> index 20c207d80e31a..ce6a1b06d50db 100644
> --- a/arch/loongarch/kvm/vcpu.c
> +++ b/arch/loongarch/kvm/vcpu.c

[ ... ]

> @@ -1164,11 +1164,14 @@ static int kvm_loongarch_cpucfg_set_attr(struct kvm_vcpu *vcpu,
>  		if (val & ~valid)
>  			return -EINVAL;
>  
> -		/* All vCPUs need set the same PV features */
> -		if ((kvm->arch.pv_features & LOONGARCH_PV_FEAT_UPDATED)
> -				&& ((kvm->arch.pv_features & valid) != val))
> +		if ((kvm->arch.pv_features & valid) == val)
> +			return 0;
> +
> +		if (vcpu->arch.ran_atleast_once)
>  			return -EINVAL;

[Severity: High]
Can this allow a user space process to modify PV features while the guest is
running?

Because the check in kvm_loongarch_cpucfg_set_attr() uses per-vCPU state
(vcpu->arch.ran_atleast_once) to gate the VM-wide configuration, what
happens if userspace runs vCPU 0 (setting its ran_atleast_once flag to
true), and then invokes KVM_SET_DEVICE_ATTR on vCPU 1 (whose
ran_atleast_once is still false)?

Wouldn't this bypass the check and mutate the VM-wide kvm->arch.pv_features
while vCPU 0 is actively executing?

> -		kvm->arch.pv_features = val | LOONGARCH_PV_FEAT_UPDATED;
> +
> +		/* All vCPUs need set the same PV features */
> +		kvm->arch.pv_features = val;

[Severity: High]
Does this silently mask misconfigurations if userspace sets different
features on different vCPUs?

Without the LOONGARCH_PV_FEAT_UPDATED latch, if userspace configures
different PV features on different unrun vCPUs, it appears KVM will accept
both operations and simply overwrite kvm->arch.pv_features with the latest
value rather than returning an error.

Could this fail to enforce the architectural invariant mentioned in the
comment that all vCPUs must have the same features?

>  		return 0;
>  	default:
>  		return -ENXIO;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260716013823.3259816-1-maobibo@loongson.cn?part=1

  reply	other threads:[~2026-07-16  2:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  1:38 [PATCH] LoongArch: KVM: Allow to set pv_feature until vCPU run Bibo Mao
2026-07-16  2:03 ` sashiko-bot [this message]
2026-07-16  4:27 ` Huacai Chen
2026-07-16  6:08   ` Bibo Mao
2026-07-16  4:46 ` Tao Cui
2026-07-16  6:12   ` Bibo Mao

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=20260716020338.888241F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=maobibo@loongson.cn \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.