Re: [PATCH v2 2/4] perf/x86/intel: Don't context switch DS_AREA (and PEBS config) if PEBS is unused

Sean Christopherson
2026-04-27T17:34:40Z

On Mon, Apr 27, 2026, Dapeng Mi wrote:
> > @@ -5065,6 +5056,26 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data)
> > if (pebs_mask & ~cpuc->intel_ctrl_guest_mask)
> > guest_pebs_mask = 0;
> >
> > + /*
> > + * 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 simply keep the host values resident in hardware.
> > + */
> > + arr[(*nr)++] = (struct perf_guest_switch_msr){
> > + .msr = MSR_IA32_DS_AREA,
> > + .host = (unsigned long)cpuc->ds,
> > + .guest = guest_pebs_mask ? kvm_pmu->ds_area : (unsigned long)cpuc->ds,
> > + };
>
> The code looks good to me.
>
> one nit: people may be curious on why set same host value for guest if they
> don't notice that the same value on host and guest would lead to the MSRs
> would be removed from MSR load-list. Maybe add comments to further explain it.

+1. In the same comment (maybe on the function?), I'll also call out that the
inclusion/exclusion of MSRs must only ever be based on constant host state,
specifically because of the need to _remove_ MSRs from the list when KVM doesn't
need to load a guest value on entry.