From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 2/4] perf/x86/intel: Don't context switch DS_AREA (and PEBS config) if PEBS is unused
Date: Tue, 14 Apr 2026 20:49:57 +0000 [thread overview]
Message-ID: <20260414204958.866B1C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260414191425.2697918-3-seanjc@google.com>
Sashiko AI review found 1 potential issue(s):
- [Critical] Omitting MSRs from the returned array fails to clear them from KVM's VMCS autoload list, defeating the optimization and causing host PMU state corruption and cross-CPU memory corruption.
--
commit 96e2a3492ccedcf6d37eda9e864908154fe181d9
Author: Sean Christopherson <seanjc@google.com>
perf/x86/intel: Don't context switch DS_AREA (and PEBS config) if PEBS is unused
This commit conditionally omits DS_AREA and MSR_PEBS_DATA_CFG from the list
of MSRs to be loaded by KVM on VMX transitions when PEBS is not active in
the guest. The goal is to save MSR writes and eliminate pointless writes
on roundtrips when the guest isn't using PEBS.
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
[ ... ]
> + /*
> + * Context switch DS_AREA and PEBS_DATA_CFG if and only if PEBS will be
> + * active in the guest; if no records will be generated while the guest
> + * is running, then running with host values is safe (see above).
> + */
> + if (!guest_pebs_mask)
> + return arr;
Will KVM actually stop context switching these MSRs if they are simply omitted
from the array?
To instruct KVM to stop context switching an MSR, the perf subsystem
needs to explicitly return the MSR in the array with .host == .guest,
which triggers KVM to call clear_atomic_switch_msr().
By dynamically omitting MSR_IA32_DS_AREA and MSR_PEBS_DATA_CFG when
guest_pebs_mask is 0, KVM never processes these MSRs and permanently leaves
them in its msr_autoload lists with stale .host and .guest values.
Does this regression cause cross-CPU memory corruption?
If a vCPU migrates to a different physical CPU while guest PEBS is disabled,
the VMCS retains the old physical CPU's MSR_IA32_DS_AREA host pointer.
On VM-Exit, the new physical CPU will load the old CPU's DS_AREA pointer.
Any subsequent host PEBS records generated on the new CPU would then be
erroneously written to the old CPU's memory.
> +
> arr[(*nr)++] = (struct perf_guest_switch_msr){
> .msr = MSR_IA32_DS_AREA,
> .host = (unsigned long)cpuc->ds,
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260414191425.2697918-1-seanjc@google.com?part=2
next prev parent reply other threads:[~2026-04-14 20:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 19:14 [PATCH 0/4] perf/x86: Don't write PEBS_ENABLED on KVM transitions Sean Christopherson
2026-04-14 19:14 ` [PATCH 1/4] perf/x86/intel: Don't write PEBS_ENABLED on host<=>guest xfers if CPU has isolation Sean Christopherson
2026-04-16 18:24 ` Namhyung Kim
2026-04-16 19:38 ` Sean Christopherson
2026-04-16 23:51 ` Namhyung Kim
2026-04-17 0:23 ` Sean Christopherson
2026-04-14 19:14 ` [PATCH 2/4] perf/x86/intel: Don't context switch DS_AREA (and PEBS config) if PEBS is unused Sean Christopherson
2026-04-14 20:49 ` sashiko-bot [this message]
2026-04-14 21:31 ` Jim Mattson
2026-04-14 22:49 ` Sean Christopherson
2026-04-15 13:00 ` Jim Mattson
2026-04-14 19:14 ` [PATCH 3/4] perf/x86/intel: Make @data a mandatory param for intel_guest_get_msrs() Sean Christopherson
2026-04-14 22:29 ` Jim Mattson
2026-04-14 19:14 ` [PATCH 4/4] perf/x86: KVM: Have perf define a dedicated struct for getting guest PEBS data Sean Christopherson
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=20260414204958.866B1C19425@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko@lists.linux.dev \
--cc=seanjc@google.com \
/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