Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sandipan Das" <sandipan.das@amd.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 8/8] KVM: SEV: Disallow the use of hardware-switched PMU
Date: Mon, 10 Aug 2026 10:40:51 +0000	[thread overview]
Message-ID: <20260810104051.C82981F000E9@smtp.kernel.org> (raw)
In-Reply-To: <c88cd7d448c7ff998efae53979624b5b08a045c1.1786345201.git.sandipan.das@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch correctly disables hardware-switched PMU for newly initialized SEV-ES guests to fix a bug where KVM attempts to interact with PMU state in the unencrypted VMCB save area instead of the guest's encrypted VMSA. However, this fix fails to apply to SEV-ES VMs created via migration or mirroring.
--

--- Patch [8]: [PATCH 8/8] KVM: SEV: Disallow the use of hardware-switched PMU ---
commit 0e4fd883c1122d7a244f0bb8754669e617c9a34a
Author: Sandipan Das <sandipan.das@amd.com>

KVM: SEV: Disallow the use of hardware-switched PMU

For hardware-switched mediated PMU, the guest PMU state resides in the
VMCB save area. When SEV-ES or SEV-SNP is used, KVM cannot access the
encrypted VMSA, so this patch clears KVM_MEDIATED_PMU_CAP_HW_SWITCHED for
such guests to force software-switched mode.

> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 944aaea6501f2..c5df6da8d030f 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -534,6 +534,9 @@ static int __sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp,
>  	if (snp_active)
>  		sev->vmsa_features |= SVM_SEV_FEAT_SNP_ACTIVE;
>  
> +	if (es_active)
> +		kvm_clr_mediated_pmu_caps(kvm, KVM_MEDIATED_PMU_CAP_HW_SWITCHED);
> +

[Severity: High]
Does this clearing also need to happen when an SEV-ES VM is created via
migration or mirroring?

Looking at sev_migrate_from(), it copies the es_active state to the
destination VM but does not appear to clear the hardware-switched PMU
capability:

arch/x86/kvm/svm/sev.c:sev_migrate_from() {
	...
	dst->es_active = src->es_active;
	dst->vmsa_features = src->vmsa_features;
	...
}

Similarly, in sev_vm_copy_enc_context_from(), the mirror_sev->es_active flag
is set to true without clearing the PMU capability:

arch/x86/kvm/svm/sev.c:sev_vm_copy_enc_context_from() {
	...
	mirror_sev->es_active = source_sev->es_active;
	...
}

Since KVM unconditionally sets KVM_MEDIATED_PMU_CAP_HW_SWITCHED during VM
creation, could failing to clear it on the destination VMs leave the hardware
PMU feature incorrectly enabled?

If a user migrates or mirrors an SEV-ES VM, might KVM attempt to read/write
PMU state from the unencrypted VMCB save area instead of the guest's
encrypted VMSA, reintroducing the issue this patch aims to fix?

>  	ret = sev_asid_new(sev, vm_type);
>  	if (ret)
>  		goto e_no_asid;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1786345201.git.sandipan.das@amd.com?part=8

      reply	other threads:[~2026-08-10 10:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 10:14 [PATCH 0/8] KVM: Add support for hardware-switched mediated PMU Sandipan Das
2026-08-10 10:14 ` [PATCH 1/8] KVM: x86/pmu: Add mediated PMU capability flags Sandipan Das
2026-08-10 10:29   ` sashiko-bot
2026-08-10 10:14 ` [PATCH 2/8] KVM: x86/pmu: Add PMU ops for vendor state sync Sandipan Das
2026-08-10 10:29   ` sashiko-bot
2026-08-10 10:14 ` [PATCH 3/8] KVM: x86/pmu: Add support for hardware-switched PMU Sandipan Das
2026-08-10 10:36   ` sashiko-bot
2026-08-10 10:14 ` [PATCH 4/8] x86/cpufeatures: Add PerfCtrVirt feature bit Sandipan Das
2026-08-10 10:24   ` sashiko-bot
2026-08-10 10:14 ` [PATCH 5/8] KVM: SVM: Add VMCB fields for PMC virtualization Sandipan Das
2026-08-10 10:14 ` [PATCH 6/8] KVM: SVM: Add support for hardware-switched PMU Sandipan Das
2026-08-10 10:57   ` sashiko-bot
2026-08-10 10:14 ` [PATCH 7/8] KVM: nSVM: " Sandipan Das
2026-08-10 10:54   ` sashiko-bot
2026-08-10 10:14 ` [PATCH 8/8] KVM: SEV: Disallow the use of " Sandipan Das
2026-08-10 10:40   ` sashiko-bot [this message]

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=20260810104051.C82981F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sandipan.das@amd.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox