On 5/7/2024 4:31 PM, Peter Zijlstra wrote: > On Mon, May 06, 2024 at 05:29:31AM +0000, Mingwei Zhang wrote: > > >> +int perf_get_mediated_pmu(void) >> +{ >> + int ret = 0; >> + >> + mutex_lock(&perf_mediated_pmu_mutex); >> + if (refcount_inc_not_zero(&nr_mediated_pmu_vms)) >> + goto end; >> + >> + if (atomic_read(&nr_include_guest_events)) { >> + ret = -EBUSY; >> + goto end; >> + } >> + refcount_set(&nr_mediated_pmu_vms, 1); >> +end: >> + mutex_unlock(&perf_mediated_pmu_mutex); >> + return ret; >> +} >> +EXPORT_SYMBOL_GPL(perf_get_mediated_pmu); > > Blergh... it seems I never got my perf guard patches merged :/, but > could we please write this like: > > int perf_get_mediated_pmu(void) > { > guard(mutex)(&perf_mediated_pmu_mutex); > if (refcount_inc_not_zero(&nr_mediated_pmu_vms)) > return 0; > > if (atomic_read(&nr_include_guest_events)) > return -EBUSY; > > refcount_set(&nr_mediated_pmu_vms, 1); > return 0; > } > > And avoid adding more unlock goto thingies? >yes, this works. And code is cleaner. thanks