From: "Chen, Zide" <zide.chen@intel.com>
To: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Peter Zijlstra <peterz@infradead.org>
Cc: kvm@vger.kernel.org, Andi Kleen <ak@linux.intel.com>,
Jim Mattson <jmattson@google.com>,
Stephane Eranian <eranian@google.com>,
linux-kernel@vger.kernel.org, Mingwei Zhang <mizhang@google.com>,
Das Sandipan <Sandipan.Das@amd.com>,
Shukla Manali <Manali.Shukla@amd.com>,
Xudong Hao <xudong.hao@intel.com>
Subject: Re: [PATCH 16/23] KVM: x86/pmu: Handle FIXED_CTR_CTRL under PerfMon masking
Date: Thu, 27 Aug 2026 17:38:44 -0500 [thread overview]
Message-ID: <0b1afe89-8ea5-4961-8582-4e59c5e369f7@intel.com> (raw)
In-Reply-To: <86696454-bf73-4d06-83f6-1f85e6540259@linux.intel.com>
On 8/26/2026 3:43 AM, Mi, Dapeng wrote:
>
> On 8/22/2026 6:19 AM, Zide Chen wrote:
>> PerfMon masking affects reads from and writes to this MSR. The effective
>> mask is defined as bits 4n+3:4n and bits 4n+35:4n+32 being set if and
>> only if bit 32+n of the PerfMon mask is set (for 0 <= n <= 7).
>>
>> KVM doesn't support some fixed-counter features, and
>> pmu->fixed_ctr_ctrl_rsvd is a subset of the effective mask above, so the
>> existing gating in intel_pmu_set_msr() is sufficient even under PerfMon
>> masking.
>>
>> Upon guest PMU context load, OR the guest-owned bits with whatever the
>> hardware currently holds for every fixed-counter index the guest does
>> not own, before writing the result to the MSR.
>>
>> During PMU context put, host-owned fixed counters may still be scheduled
>> for system-wide host events, so the host-owned bits should remain
>> unchanged.
>>
>> Signed-off-by: Zide Chen <zide.chen@intel.com>
>> ---
>> arch/x86/kvm/vmx/pmu_intel.c | 40 +++++++++++++++++++++++++++++++++---
>> 1 file changed, 37 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
>> index 19ccc7cd319c..9236bfa15c41 100644
>> --- a/arch/x86/kvm/vmx/pmu_intel.c
>> +++ b/arch/x86/kvm/vmx/pmu_intel.c
>> @@ -920,6 +920,33 @@ static void intel_pmu_write_global_ctrl(u64 global_ctrl)
>> vmcs_write64(GUEST_IA32_PERF_GLOBAL_CTRL, global_ctrl);
>> }
>>
>> +static u64 intel_fixed_ctrl_host_bits(struct kvm_pmu *pmu)
>> +{
>> + unsigned long fixed_mask;
>> + u64 fixed_ctl;
>> + int i;
>> +
>> + if (!kvm_vcpu_has_perfmon_mask(pmu_to_vcpu(pmu)))
>> + return 0;
>> +
>> + fixed_mask = kvm_fixed_pmc_mask(pmu);
>> +
>> + rdmsrq(MSR_CORE_PERF_FIXED_CTR_CTRL, fixed_ctl);
>> +
>> + /*
>> + * Use the full per-counter nibbles (bits 4n+3:4n and 4n+35:4n+32) to
>> + * strip all bits belonging to guest-owned counters.
>> + *
>> + * pmu->fixed_ctr_ctrl_rsvd can't be used here since it can't gate bits
>> + * that are not supported by KVM.
>> + */
>> + kvm_for_each_fixed_counter(i, fixed_mask)
>> + fixed_ctl &= ~intel_fixed_bits_by_idx(i, GENMASK_ULL(3, 0) |
>> + GENMASK_ULL(35, 32));
>> +
>> + return fixed_ctl;
>> +}
>
> Strictly speaking, this should be a perf/x86/intel function and then
> exposed to KVM. Perf host side may also need this function.
The code is slightly different. For example, fc0 is bit 0 in
kvm_fixed_pmc_mask(), while it is bit 32 in the host case
(x86_pmu_current_partition_mask()).
It does not seem worthwhile to refactor the code for reuse for such a
small API.
next prev parent reply other threads:[~2026-08-27 22:38 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 22:19 [PATCH 00/23] perf/KVM: Support PMU partitioning for x86 platforms Zide Chen
2026-08-21 22:19 ` [PATCH 01/23] perf/x86/intel: Guard counter masks against zero counters Zide Chen
2026-08-26 7:53 ` Mi, Dapeng
2026-08-21 22:19 ` [PATCH 02/23] perf, perf/x86: Pass partition mask from KVM to perf/x86 Zide Chen
2026-08-21 22:19 ` [PATCH 03/23] perf/x86: Add GUEST_PMU states for PMU partitioning Zide Chen
2026-08-21 22:19 ` [PATCH 04/23] perf/x86: Split host/guest PMI handling under " Zide Chen
2026-08-21 22:19 ` [PATCH 05/23] perf/x86: Allow exclude_host events to run in non-root mode Zide Chen
2026-08-21 22:19 ` [PATCH 06/23] perf/x86: Restrict !exclude_guest events to host-owned counters Zide Chen
2026-08-21 22:19 ` [PATCH 07/23] perf/x86: Apply PMU partition mask on static constraints Zide Chen
2026-08-26 8:12 ` Mi, Dapeng
2026-08-27 23:01 ` Chen, Zide
2026-08-21 22:19 ` [PATCH 08/23] perf/x86: Export available PMU counters to sysfs Zide Chen
2026-08-21 22:19 ` [PATCH 09/23] perf: Skip exclude_guest events on PMU partitioned counters Zide Chen
2026-08-21 22:19 ` [PATCH 10/23] perf: Reschedule events across PMU partition transitions Zide Chen
2026-08-21 22:19 ` [PATCH 11/23] perf, perf/x86: Allow host !exclude_guest events in PMU partitioning Zide Chen
2026-08-21 22:19 ` [PATCH 12/23] KVM: x86/pmu: Add the perfmon_mask module parameter Zide Chen
2026-08-26 8:18 ` Mi, Dapeng
2026-08-27 22:45 ` Chen, Zide
2026-08-21 22:19 ` [PATCH 13/23] KVM: x86/pmu: Set up the PERFMON_MASK VMCS field Zide Chen
2026-08-21 22:19 ` [PATCH 14/23] KVM: x86/pmu, perf/x86: Update effective PMU partition mask Zide Chen
2026-08-21 22:19 ` [PATCH 15/23] KVM: x86/pmu: Relax MSR intercept policy under PerfMon masking Zide Chen
2026-08-21 22:19 ` [PATCH 16/23] KVM: x86/pmu: Handle FIXED_CTR_CTRL " Zide Chen
2026-08-26 8:43 ` Mi, Dapeng
2026-08-27 22:38 ` Chen, Zide [this message]
2026-08-21 22:19 ` [PATCH 17/23] KVM: x86/pmu: Handle GLOBAL_CTRL " Zide Chen
2026-08-21 22:19 ` [PATCH 18/23] KVM: x86/pmu: Handle GLOBAL_STATUS MSRs " Zide Chen
2026-08-21 22:19 ` [PATCH 19/23] KVM: x86/pmu: Always intercept GLOBAL_INUSE " Zide Chen
2026-08-21 22:19 ` [PATCH 20/23] KVM: x86/pmu: Request guest PMI for guest-induced PMIs Zide Chen
2026-08-21 22:20 ` [PATCH 21/23] KVM: x86/pmu: Enable PerfMon masking Zide Chen
2026-08-21 22:20 ` [PATCH 22/23] KVM: selftests: Fix PERF_METRICS test by checking FC3 availability Zide Chen
2026-08-21 22:20 ` [PATCH 23/23] KVM: selftests: Allow no general purpose counters on the host Zide Chen
2026-08-26 7:52 ` [PATCH 00/23] perf/KVM: Support PMU partitioning for x86 platforms Mi, Dapeng
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=0b1afe89-8ea5-4961-8582-4e59c5e369f7@intel.com \
--to=zide.chen@intel.com \
--cc=Manali.Shukla@amd.com \
--cc=Sandipan.Das@amd.com \
--cc=ak@linux.intel.com \
--cc=dapeng1.mi@linux.intel.com \
--cc=eranian@google.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mizhang@google.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=xudong.hao@intel.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
all inboxes | Powered by JetHome®