On 5/15/2025 7:30 AM, Sean Christopherson wrote: > On Mon, Mar 24, 2025, Mingwei Zhang wrote: >> From: Kan Liang <kan.li...@linux.intel.com> >> >> When entering/exiting a guest, some contexts for a guest have to be >> switched. For examples, there is a dedicated interrupt vector for >> guests on Intel platforms. >> >> When PMI switch into a new guest vector, guest_lvtpc value need to be >> reflected onto HW, e,g., guest clear PMI mask bit, the HW PMI mask >> bit should be cleared also, then PMI can be generated continuously >> for guest. So guest_lvtpc parameter is added into perf_guest_enter() >> and switch_guest_ctx(). >> >> Add a dedicated list to track all the pmus with the PASSTHROUGH cap, which >> may require switching the guest context. It can avoid going through the >> huge pmus list. >> >> Suggested-by: Peter Zijlstra (Intel) <pet...@infradead.org> >> Signed-off-by: Kan Liang <kan.li...@linux.intel.com> >> Signed-off-by: Mingwei Zhang <mizh...@google.com> >> --- >> include/linux/perf_event.h | 17 +++++++++++-- >> kernel/events/core.c | 51 +++++++++++++++++++++++++++++++++++++- >> 2 files changed, 65 insertions(+), 3 deletions(-) >> >> diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h >> index 37187ee8e226..58c1cf6939bf 100644 >> --- a/include/linux/perf_event.h >> +++ b/include/linux/perf_event.h >> @@ -584,6 +584,11 @@ struct pmu { >> * Check period value for PERF_EVENT_IOC_PERIOD ioctl. >> */ >> int (*check_period) (struct perf_event *event, u64 value); >> /* optional */ >> + >> + /* >> + * Switch guest context when a guest enter/exit, e.g., interrupt >> vectors. >> + */ >> + void (*switch_guest_ctx) (bool enter, void *data); /* optional */ > IMO, putting this in "struct pmu" is unnecessarily convoluted and complex, > and a > poor fit for what needs to be done. The only usage of the hook is for the > CPU to > swap the LVTPC, and the @data payload communicates exactly that. I.e. this > has > one user, and can't reasonably be extended to other users without some > ugliness. > > And if by some miracle there's no CPU pmu in perf, KVM's mediated PMU still > needs > to swap to its PMI IRQ. So rather than per-PMU hook along with a list and a > spinlock, just make this an arch hook. And if all of the mediated PMU code is > guarded by a Kconfig, then perf doesn't even needs __weak stubs.
Sounds good for me. >