On 2024-10-14 7:56 a.m., Peter Zijlstra wrote: > On Thu, Aug 01, 2024 at 04:58:23AM +0000, Mingwei Zhang wrote: > >> @@ -5941,8 +5942,21 @@ void perf_put_mediated_pmu(void) >> } >> EXPORT_SYMBOL_GPL(perf_put_mediated_pmu); >> >> +static void perf_switch_interrupt(bool enter, u32 guest_lvtpc) >> +{ >> + /* Mediated passthrough PMU should have PASSTHROUGH_VPMU cap. */ >> + if (!passthru_pmu) >> + return; >> + >> + if (passthru_pmu->switch_interrupt && >> + try_module_get(passthru_pmu->module)) { >> + passthru_pmu->switch_interrupt(enter, guest_lvtpc); >> + module_put(passthru_pmu->module); >> + } >> +} > > Should we move the whole module reference to perf_pmu_(,un}register() ? A PMU module can be load/unload anytime. How should we know if the PMU module is available when the reference check is moved to perf_pmu_(,un}register()? > >> @@ -11842,7 +11860,21 @@ int perf_pmu_register(struct pmu *pmu, const char *name, int type) >> if (!pmu->event_idx) >> pmu->event_idx = perf_event_idx_default; >> >> - list_add_rcu(&pmu->entry, &pmus); >> + /* >> + * Initialize passthru_pmu with the core pmu that has >> + * PERF_PMU_CAP_PASSTHROUGH_VPMU capability. >> + */ >> + if (pmu->capabilities & PERF_PMU_CAP_PASSTHROUGH_VPMU) { >> + if (!passthru_pmu) >> + passthru_pmu = pmu; >> + >> + if (WARN_ONCE(passthru_pmu != pmu, "Only one passthrough PMU is supported\n")) { >> + ret = -EINVAL; >> + goto free_dev; > > Why impose this limit? Changelog also fails to explain this. Because the passthru_pmu is global variable. If there are two or more PMUs with the PERF_PMU_CAP_PASSTHROUGH_VPMU, the former one will be implicitly overwritten if without the check. Thanks Kan > >> + } >> + } >> + >> + list_add_tail_rcu(&pmu->entry, &pmus); >> atomic_set(&pmu->exclusive_cnt, 0); >> ret = 0; >> unlock: >> -- >> 2.46.0.rc1.232.g9752f9e123-goog >> >