Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luka Absandze" <absandze@amazon.de>
Cc: kvm@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH] perf/x86/amd: Reject AMD Merge event as a countable event
Date: Wed, 16 Sep 2026 12:51:45 +0000	[thread overview]
Message-ID: <20260916125146.0E96F1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260916123315.89042-1-absandze@amazon.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf/x86/amd: -EINVAL on AMD_MERGE_EVENT causes KVM retry storm
--

commit 74f1b4944fbb968a39b8b39a32bd5ffa921c5814
Author: Luka Absandze <absandze@amazon.de>

perf/x86/amd: Reject AMD Merge event as a countable event

This commit modifies amd_core_hw_config() to reject the AMD Merge event
(AMD_MERGE_EVENT) as a user-visible event by returning -EINVAL. It prevents a
counter's PerfCtl from holding the Merge encoding inappropriately, which could
otherwise artificially inflate deltas.

> diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
> index 49b6b8fce5664..cb655c751e5b1 100644
> --- a/arch/x86/events/amd/core.c
> +++ b/arch/x86/events/amd/core.c
> @@ -380,8 +380,12 @@ static int amd_core_hw_config(struct perf_event *event)
[ ... ]
> -	if ((x86_pmu.flags & PMU_FL_PAIR) && amd_is_pair_event_code(&event->hw))
> -		event->hw.flags |= PERF_X86_EVENT_PAIR;
> +	if (x86_pmu.flags & PMU_FL_PAIR) {
> +		if ((event->hw.config & AMD64_EVENTSEL_EVENT) == AMD_MERGE_EVENT)
> +			return -EINVAL;

[Severity: High]
Does returning a permanent -EINVAL error here cause an opportunistic retry storm
in KVM?

If a KVM guest programs a Large Increment per Cycle (LIPC) event by writing
AMD_MERGE_EVENT to an odd vPMC, KVM intercepts this and attempts to create a
raw host perf event.  When this fails with -EINVAL, KVM's reprogram_counter()
propagates the error to kvm_pmu_handle_event():

arch/x86/kvm/pmu.c:kvm_pmu_handle_event() {
    ...
		if (reprogram_counter(pmc))
			set_bit(pmc->idx, pmu->reprogram_pmi);
    ...
}

Because KVM treats all failures as transient and unconditionally re-adds the
failing counter to pmu->reprogram_pmi, on every subsequent PMU refresh KVM
will repeatedly retry the failed counter.

Could this create a permanent retry storm that degrades VM performance and
wastes host CPU cycles?

> +		if (amd_is_pair_event_code(&event->hw))
> +			event->hw.flags |= PERF_X86_EVENT_PAIR;
> +	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260916123315.89042-1-absandze@amazon.de?part=1

  reply	other threads:[~2026-09-16 12:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 12:33 [PATCH] perf/x86/amd: Reject AMD Merge event as a countable event Luka Absandze
2026-09-16 12:51 ` sashiko-bot [this message]
2026-09-16 14:02   ` Absandze, Luka
2026-09-17  6:44     ` Sandipan Das
2026-09-16 15:04 ` Borislav Petkov
2026-09-21  5:09 ` 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=20260916125146.0E96F1F00893@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