From: sashiko-bot@kernel.org
To: "Luka Absandze" <absandze@amazon.de>
Cc: linux-perf-users@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: x86/pmu: Don't retry a counter whose config was rejected
Date: Fri, 18 Sep 2026 16:11:56 +0000 [thread overview]
Message-ID: <20260918161156.D9BE21F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260918160006.61816-1-absandze@amazon.de>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: pmu: incomplete error check leaves retry loop for non-EINVAL errors
--
commit c902c2e2a69841996cdfa4c9e356844d36d6b770
Author: Luka Absandze <absandze@amazon.de>
KVM: x86/pmu: Don't retry a counter whose config was rejected
This commit prevents KVM from infinitely retrying PMU reprogramming when the
host PMU driver rejects a configuration outright by skipping the re-arm for
-EINVAL.
Link: https://lore.kernel.org/all/20260916123315.89042-1-absandze@amazon.de/
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index d2fd47ee5ec80..ef229faafd1e1 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -680,8 +680,14 @@ void kvm_pmu_handle_event(struct kvm_vcpu *vcpu)
> * reprogram bit, i.e. opportunistically try again on the next
> * PMU refresh. Don't make a new request as doing so can stall
> * the guest if reprogramming repeatedly fails.
> + *
> + * -EINVAL means the event's config was rejected outright and
> + * can never succeed on retry, so don't re-arm; the guest can
> + * still do so itself by rewriting the event selector.
> */
> - if (reprogram_counter(pmc))
> + int r = reprogram_counter(pmc);
> +
> + if (r && r != -EINVAL)
> set_bit(pmc->idx, pmu->reprogram_pmi);
[Severity: High]
Does this condition fail to exclude other permanent error codes like
-EOPNOTSUPP or -ENOENT?
If a guest programs an invalid configuration (such as a PEBS precise_ip level
that the host hardware does not support), x86_pmu_hw_config() can return
-EOPNOTSUPP.
In that scenario, reprogram_counter() will propagate this error, the condition
here evaluates to true, and KVM will incorrectly re-arm the reprogram_pmi bit.
On subsequent PMU refreshes, KVM will repeatedly retry the heavy
perf_event_create_kernel_counter() path.
Could this leave the retry loop open for other error codes, allowing an
unprivileged guest to cause high CPU overhead on the host?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260918160006.61816-1-absandze@amazon.de?part=1
next prev parent reply other threads:[~2026-09-18 16:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 16:00 [PATCH] KVM: x86/pmu: Don't retry a counter whose config was rejected Luka Absandze
2026-09-18 16:11 ` sashiko-bot [this message]
2026-09-18 16:16 ` Sean Christopherson
2026-09-18 20:21 ` Absandze, Luka
2026-09-18 21:39 ` Sean Christopherson
2026-09-19 14:29 ` Sandipan Das
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=20260918161156.D9BE21F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=absandze@amazon.de \
--cc=kvm@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--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