Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Manali Shukla <manali.shukla@amd.com>
To: Jim Mattson <jmattson@google.com>
Cc: <seanjc@google.com>, <pbonzini@redhat.com>, <mingo@redhat.com>,
	<bp@alien8.de>, <kvm@vger.kernel.org>, <x86@kernel.org>,
	<santosh.shukla@amd.com>, <nikunj.dadhania@amd.com>,
	<Naveen.Rao@amd.com>, <dapeng1.mi@linux.intel.com>,
	<ravi.bangoria@amd.com>, <peterz@infradead.org>,
	Yosry Ahmed <yosry@kernel.org>, <manali.shukla@amd.com>
Subject: Re: [PATCH v3 7/9] perf/x86/amd: Enable VPMU passthrough capability for IBS PMU
Date: Wed, 18 Nov 2026 19:09:07 +0530	[thread overview]
Message-ID: <ac0cf3d7-7547-40e1-b3cd-10dfd8ee2b78@amd.com> (raw)
In-Reply-To: <20261008193208.832031-1-jmattson@google.com>

On 10/9/2026 1:02 AM, Jim Mattson wrote:
> On Tue, Mar 10, 2026 at 06:00:19AM +0000, Manali Shukla wrote:
>> IBS MSRs are classified as Swap Type C, which requires the hypervisor
>> to save and restore its own IBS state before VMENTRY and after VMEXIT.
>>
>> To support this, set the ibs_op and ibs_fetch PMUs with the
>> PERF_PMU_CAP_MEDIATED_VPMU capability. This ensures that these PMUs are
>> exclusively owned by the guest while it is running, allowing the
>> hypervisor to manage IBS state transitions correctly.
>>
>> Signed-off-by: Manali Shukla <manali.shukla@amd.com>
>> ---
>>  arch/x86/events/amd/ibs.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
>> index 6d230e417b61..e075c5ed136c 100644
>> --- a/arch/x86/events/amd/ibs.c
>> +++ b/arch/x86/events/amd/ibs.c
>> @@ -978,6 +978,7 @@ static struct perf_ibs perf_ibs_fetch = {
>>  		.stop		= perf_ibs_stop,
>>  		.read		= perf_ibs_read,
>>  		.check_period	= perf_ibs_check_period,
>> +		.capabilities	= PERF_PMU_CAP_MEDIATED_VPMU,
> 
> At this point in the series, perf_ibs_init() still rejects events with
> exclude_guest set, so every IBS event is an "include guest" event, as
> defined by is_include_guest_event(). With this capability:
> 
> - If any IBS event exists, perf_create_mediated_pmu() returns -EBUSY, so
>   KVM cannot create a vCPU in a VM with a mediated PMU.
> 
> - If any VM with a mediated PMU exists, mediated_pmu_account_event()
>   returns -EOPNOTSUPP, so no IBS event can be created.
> 
> Patch 8/9 removes the exclude_guest check. Please squash patches 7/9 and
> 8/9 together, so that the series does not have this regression at any
> commit.
> 

Agreed. I will squash them.

> Do we really want to set this capability when the CPU does not support IBS
> virtualization (or when kvm_amd.vibs=0)? In that case, the guest cannot use
> IBS, but host IBS events that do not set exclude_guest still block mediated
> PMU VMs, and vice versa.
> 

I agree that we should enable PERF_PMU_CAP_MEDIATED_VPMU capability only
when boot CPU has VIBS support. Something like this in perf_ibs_pmu_init():

        if (boot_cpu_has(X86_FEATURE_VIBS))
               perf_ibs->pmu.capabilities |= PERF_PMU_CAP_MEDIATED_VPMU;


Without the capability, exclude_guest IBS events will be handled by the
software switch I have proposed in my reply to patch 8/9.

Doing the same for kvm_amd.vibs=0 is difficult. The capability is fixed
when the IBS PMU registers, which happens before kvm_amd loads. It is
checked when the event is created and again when the event is freed. If
it changes in between, nr_include_guest_events can go wrong, and a
mediated PMU VM can start while an include-guest event is running, or
it might never start at all.


> When the guest context is loaded, perf_load_guest_context() schedules
> out the exclude_guest IBS events through perf_ibs_stop(). On hardware
> with IBS_CAPS_DIS, perf_ibs_stop() does not clear IbsFetchEn or IbsOpEn.
> See my comment on patch 6/9.
> 

I have already answered this in patch 6/9.

>>  	},
>>  	.msr			= MSR_AMD64_IBSFETCHCTL,
>>  	.msr2			= MSR_AMD64_IBSFETCHCTL2,


  reply	other threads:[~2026-11-18 13:39 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10  6:00 [PATCH v3 0/9] Implement support for IBS virtualization Manali Shukla
2026-03-10  6:00 ` [PATCH v3 1/9] perf/amd/ibs: Fix race condition in IBS Manali Shukla
2026-10-08 17:19   ` Jim Mattson
2026-03-10  6:00 ` [PATCH v3 2/9] x86/cpufeatures: Add CPUID feature bit for VIBS in SVM/SEV guests Manali Shukla
2026-10-08 17:28   ` Jim Mattson
2026-03-10  6:00 ` [PATCH v3 3/9] KVM: x86/cpuid: Add a KVM-only leaf for IBS capabilities Manali Shukla
2026-10-08 17:44   ` Jim Mattson
2026-10-22 10:16     ` Manali Shukla
2026-03-10  6:00 ` [PATCH v3 4/9] KVM: x86: Extend CPUID range to include new leaf Manali Shukla
2026-10-08 17:59   ` Jim Mattson
2026-10-22 12:00     ` Manali Shukla
2026-10-22 17:15       ` Jim Mattson
2026-03-10  6:00 ` [PATCH v3 5/9] KVM: SVM: Extend VMCB area for virtualized IBS registers Manali Shukla
2026-10-08 18:01   ` Jim Mattson
2026-03-10  6:00 ` [PATCH v3 6/9] KVM: SVM: Add support for IBS Virtualization Manali Shukla
2026-10-08 19:19   ` Jim Mattson
2026-10-08 21:28     ` Jim Mattson
2026-10-16 16:01       ` Sean Christopherson
2026-11-10 12:03         ` Manali Shukla
2026-11-10 11:30     ` Manali Shukla
2026-03-10  6:00 ` [PATCH v3 7/9] perf/x86/amd: Enable VPMU passthrough capability for IBS PMU Manali Shukla
2026-10-08 19:32   ` Jim Mattson
2026-11-18 13:39     ` Manali Shukla [this message]
2026-03-10  6:00 ` [PATCH v3 8/9] perf/x86/amd: Remove exclude_guest check from perf_ibs_init() Manali Shukla
2026-10-08 19:38   ` Jim Mattson
2026-11-18 13:38     ` Manali Shukla
2026-03-10  6:00 ` [PATCH v3 9/9] KVM: SVM: Add newly added IBS capabilities and MSRs Manali Shukla
2026-10-08 21:03   ` Jim Mattson
2026-11-11 12:11     ` Manali Shukla

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=ac0cf3d7-7547-40e1-b3cd-10dfd8ee2b78@amd.com \
    --to=manali.shukla@amd.com \
    --cc=Naveen.Rao@amd.com \
    --cc=bp@alien8.de \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nikunj.dadhania@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ravi.bangoria@amd.com \
    --cc=santosh.shukla@amd.com \
    --cc=seanjc@google.com \
    --cc=x86@kernel.org \
    --cc=yosry@kernel.org \
    /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