Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5327197; Tue, 7 May 2024 08:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715070959; cv=none; b=WUbuPftRMxnmZRliHd7s8YthKYsmZdrobiPu1TrXAo3/XQ0+GDto4z6bmeb9f8g/OQ0w7q+9XC/LFyWKdkfTX4SfrwSIX/wFOoZXWW7h4l7LIfTKsu/9tGqBt3TufnfzTy9qeroPo1PSDNk7iwYDBX5Q3KE+hO30e4Q8aef7Vds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715070959; c=relaxed/simple; bh=187h6QhehzgPuQwq5YOrfgctS4r9XhcRxlDEN4DzZuU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LJzblP6ELIBFBgYyi0fBYQHfFxxXYyGLRDvgxktSjdZMizamP/AtsH4fkLvBFNwgWOWzMj51OAcHkflvRlR3DulyJCZ+NIAXN+hHrTdjLUZf/XauzIigv2PRXtSgXl9e4RzIvT7+N6PjVtWyWJp1cvhPfQ3Tgqhm+q5feGOWhPo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=kt76PVGU; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="kt76PVGU" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=eMOSmiPr7+fXT7b1/qb26SLQ7/HDimZf83JbehT1XAk=; b=kt76PVGU66UoeUZqjholmDoQrQ j0GvBB2pYHIi155XPvx5HpNvbmHitlurVgQzyYpDSKnef3nlZTAI2f1ebbqhonvyO3neyvjzxILqV 9YCvXZR0X+i5UBnAqRx8wUJN3JLfoBuCdv2abDlTxek/4ehzYCms+84MyYSjg+hBZgrRvv9xlMw+C OegDbKS1/NYkjF83U/ZNm0mV8RVlz8W7NR+AkVGQvyPuW4Gu4T0kkCbAeAd3BF06o61l2g6gwiLwz Ao3I4icnb8qF/Mv0Aqdl81kenZ2PZZBoJtrkpNkk1bRk0qBT8YF8WMT9+TPJbgmrIwkeq/nGCbfLd 32/aMjJw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4GEb-000000021LQ-3d1b; Tue, 07 May 2024 08:33:46 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 6495D300362; Tue, 7 May 2024 10:31:33 +0200 (CEST) Date: Tue, 7 May 2024 10:31:33 +0200 From: Peter Zijlstra To: Mingwei Zhang Cc: Sean Christopherson , Paolo Bonzini , Xiong Zhang , Dapeng Mi , Kan Liang , Zhenyu Wang , Manali Shukla , Sandipan Das , Jim Mattson , Stephane Eranian , Ian Rogers , Namhyung Kim , gce-passthrou-pmu-dev@google.com, Samantha Alt , Zhiyuan Lv , Yanfei Xu , maobibo , Like Xu , kvm@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH v2 06/54] perf: Support get/put passthrough PMU interfaces Message-ID: <20240507083133.GQ40213@noisy.programming.kicks-ass.net> References: <20240506053020.3911940-1-mizhang@google.com> <20240506053020.3911940-7-mizhang@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240506053020.3911940-7-mizhang@google.com> 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?