All of lore.kernel.org
 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 1/8] KVM: x86/pmu: Add mediated PMU capability flags
Date: Mon, 10 Aug 2026 10:29:06 +0000	[thread overview]
Message-ID: <20260810102906.EA9B71F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <6ee8548572f74a2ded7e2904e222045c257a9812.1786345201.git.sandipan.das@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Transient failure in `perf_create_mediated_pmu` permanently clears `mediated_pmu_caps`, corrupting VM capability state on retry.
- [Medium] `kvm_vcpu_has_mediated_pmu_caps` evaluates to true if *any* capability matches, rather than *all*.
--

--- Patch [1]: [PATCH 1/8] KVM: x86/pmu: Add mediated PMU capability flags ---
commit b775f5357bd23699130ac68abbdd7cd26849e026
Author: Sandipan Das <sandipan.das@amd.com>

KVM: x86/pmu: Add mediated PMU capability flags

This commit introduces VM-scoped mediated PMU capability flags to help KVM
determine available hardware assists for saving and restoring guest PMU
state. It defines flags for hardware-switched and hardware-filtered PMU
states, and manages these capabilities during VM initialization.

> diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
> index a5821d7c87f93..f60856c48462b 100644
> --- a/arch/x86/kvm/pmu.h
> +++ b/arch/x86/kvm/pmu.h
[ ... ]
> @@ -88,6 +88,26 @@ static inline bool kvm_vcpu_has_mediated_pmu(struct kvm_vcpu *vcpu)
>  	return enable_mediated_pmu && vcpu_to_pmu(vcpu)->version;
>  }
>  
> +static inline bool kvm_vcpu_has_mediated_pmu_caps(struct kvm_vcpu *vcpu, u32 caps)
> +{
> +	return kvm_vcpu_has_mediated_pmu(vcpu) &&
> +	       !!(vcpu->kvm->arch.mediated_pmu_caps & caps);

[Severity: Medium]
When a caller checks for multiple capabilities simultaneously, will this
return true if only one of the bits matches, rather than all requested bits?

If a future caller checks kvm_vcpu_has_mediated_pmu_caps() with multiple
flags, it appears it would return true even if only a subset of those flags
are present in mediated_pmu_caps.

[ ... ]
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index afcac1042947a..9f0e072ff466d 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
[ ... ]
> @@ -12759,6 +12759,7 @@ int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
>  		if (irqchip_in_kernel(kvm)) {
>  			r = perf_create_mediated_pmu();
>  			if (r) {
> +				kvm->arch.mediated_pmu_caps = 0;

[Severity: High]
If perf_create_mediated_pmu() returns a transient error like -EBUSY, is it
safe to permanently clear the VM-wide mediated_pmu_caps here?

If userspace receives the error, resolves the host perf conflict, and
retries the KVM_CREATE_VCPU ioctl, the retry might succeed but the VM's
capabilities will have been irreversibly wiped. Does this lead to a silent
downgrade to software switching for the VM on a successful retry?

>  				pr_warn_ratelimited(PERF_MEDIATED_PMU_MSG);
>  				return r;
>  			}

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

  reply	other threads:[~2026-08-10 10:29 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 [this message]
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

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=20260810102906.EA9B71F00A3A@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 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.