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 8/9] perf/x86/amd: Remove exclude_guest check from perf_ibs_init()
Date: Wed, 18 Nov 2026 19:08:06 +0530 [thread overview]
Message-ID: <0cec5ebd-fb95-408c-8e21-dab3389ca083@amd.com> (raw)
In-Reply-To: <20261008193818.839995-1-jmattson@google.com>
On 10/9/2026 1:08 AM, Jim Mattson wrote:
> On Tue, Mar 10, 2026 at 06:00:20AM +0000, Manali Shukla wrote:
>> Currently IBS driver doesn't allow the creation of IBS event with
>> exclude_guest set. As a result, amd_ibs_init() returns -EINVAL if
>> IBS event is created with exclude_guest set.
>
> s/amd_ibs_init()/perf_ibs_init()/
Ack.
>
>> With the introduction of mediated PMU support, software-based handling
>> of exclude_guest is permitted for PMUs that have the
>> PERF_PMU_CAP_MEDIATED_VPMU capability.
>
> This software-based handling applies only while a vCPU with a mediated
> PMU is loaded (perf_load_guest_context() through perf_put_guest_context()).
> The core PMU also sets AMD64_EVENTSEL_HOSTONLY for exclude_guest events,
> so the hardware excludes guest execution in all other cases. IBS has no
> equivalent, and nothing in the IBS driver or in KVM stops an IBS event
> while a guest without a mediated PMU runs (for example, when
> kvm_amd.enable_mediated_pmu=0, or when the VM is created with
> KVM_PMU_CAP_DISABLE). After this patch, perf_ibs_init() accepts
> exclude_guest=1 in those cases, but the event does not exclude the guest.
> This seems like a problem.
I agree this is a problem. Previously exclude_guest was never supported,
so events with exclude_guest set were simply rejected.
But with mediated PMU, we can not keep rejecting them. Once IBS PMU has
PERF_PMU_CAP_MEDIATED_VPMU, a mediated PMU enabled VM can only be
created when all host events are exclude_guest, so rejecting
exclude_guest event would mean host IBS and mediated PMU enabled VMs
could never run together.
How about implementing exclude_guest in software for the guest that
doesn't support mediated PMU? KVM would disable host IBS before entering
the guest and re-enable it after exit using perf_guest_get_msrs().
Something like below:
In the perf_guest_get_msrs(), for each active exclude_guest event:
if (ibs_caps & IBS_CAPS_DIS) {
rdmsrq(perf_ibs->msr2, ctl2);
arr[nr].msr = perf_ibs->msr2;
arr[nr].host = ctl2;
arr[nr].guest = ctl2 | perf_ibs->disable_mask;
} else {
rdmsrq(perf_ibs->msr, ctl);
arr[nr].msr = perf_ibs->msr;
arr[nr].host = ctl;
arr[nr].guest = ctl & ~perf_ibs->enable_mask;
}
and in svm_vcpu_run():
msrs = perf_guest_get_msrs(&nr, NULL);
for (i = 0; i < nr; i++)
wrmsrq(msrs[i].msr, msrs[i].guest);
svm_vcpu_enter_exit(vcpu, enter_flags);
for (i = 0; i < nr; i++)
wrmsrq(msrs[i].msr, msrs[i].host);
Please let me know your thoughts.
>
>> Since ibs_op and ibs_fetch pmus has PERF_PMU_CAP_MEDIATED_VPMU
>> capability set, update perf_ibs_init() to remove exclude_guest check.
>
> s/pmus has/PMUs have/
Ack.
>
> As I said on patch 7/9, please squash this patch with patch 7/9.
>
Ack.
>> Signed-off-by: Manali Shukla <manali.shukla@amd.com>
>> ---
>> arch/x86/events/amd/ibs.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c
>> index e075c5ed136c..47f4dc0b6341 100644
>> --- a/arch/x86/events/amd/ibs.c
>> +++ b/arch/x86/events/amd/ibs.c
>> @@ -327,8 +327,7 @@ static int perf_ibs_init(struct perf_event *event)
>> return -EOPNOTSUPP;
>>
>> /* handle exclude_{user,kernel} in the IRQ handler */
>> - if (event->attr.exclude_host || event->attr.exclude_guest ||
>> - event->attr.exclude_idle)
>> + if (event->attr.exclude_host || event->attr.exclude_idle)
>> return -EINVAL;
>>
>> ret = validate_group(event);
next prev parent reply other threads:[~2026-11-18 13:38 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
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 [this message]
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=0cec5ebd-fb95-408c-8e21-dab3389ca083@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