From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 192A53ED126; Tue, 30 Jun 2026 09:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782810591; cv=none; b=sQ17RjuaMwnTBKJf+M8RmOS8V/FlDcvfTid254Rty7N0emBr3QhhXtvTYi0sW7IgU6AXz5kBhEU/qd5JSuZyk+cjapXez67pgqFxFaYYEKnMqVZsfg5qM0k8H32wn2fP0sbHzFpu9kB7CMDCYh30aF6+yfYiexFbNPrJVyPys8w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782810591; c=relaxed/simple; bh=Ml0mSxSlSVZA2Tzbc4sngRlOlbgit+s45dryNlxGC+o=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=btdh5OEF2zdfTwOecM+iTjc+CSyeiXDTZzTcUFDdqLaNj8tl5fsfprv7rrLGH9Ebh/1/VTAI1PGjFlmCNTm31G0XAH1k51LUnMfXdAokKs5wjs8LjGS4zQak3VILigGrgW1EFShctzAl9S8rPWvd97PoYb4fYrmMn5PlLvVaYwg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kGtm2b2v; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iev/q6rd; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kGtm2b2v"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iev/q6rd" Date: Tue, 30 Jun 2026 09:09:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1782810588; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yRswPIUbriOETbMQAyPt1wCC7/jLP4uDFoUNEGn9Mkw=; b=kGtm2b2vhtc10GpD6Rw28pqFC/VtMFAJb9BRuG8kFBYqVDYZ7i7s/eur57voibrTbExTHk jJsfxqRZdITAqGGphiMNCsnfFSgJlZ2rFdMHuOKuW0OIw/bG/pcMxKBZeHf1YOgShVoewN eReFfD5OqlHXI9o1Hzf4cV9PbmFsvs6ytjdQJeWxjEOeSw/iKDDNaDgmPEkmh2hkosYNAd LpKjKYwJKklEwA5yC5FrcTA17j8BSAdGmOlcXpL7SUp7uLxnry+QnWm/TJdX9+rIBp8pQT i70nXbCRcYWGTf9gSMfe1fDjx/NpNaicBZFEGKqW4FUWBmM7a/Wssm/+i+6wXA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1782810588; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yRswPIUbriOETbMQAyPt1wCC7/jLP4uDFoUNEGn9Mkw=; b=iev/q6rdKlkLWf82tB/jrH/oPWiaV3EyZ8gk2HpmVP5xJQ19Op4kPtiX+4otC5idwJ4gg7 FW8A0caKg3jwLfCw== From: "tip-bot2 for Zide Chen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/intel/uncore: Fix refcnt and other cleanups Cc: Zide Chen , "Peter Zijlstra (Intel)" , Dapeng Mi , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260611160033.66760-3-zide.chen@intel.com> References: <20260611160033.66760-3-zide.chen@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178281058734.3843924.11848781753885080709.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the perf/core branch of tip: Commit-ID: 7d3a9ff98898b3521eb5d7a3daf703b383f7935a Gitweb: https://git.kernel.org/tip/7d3a9ff98898b3521eb5d7a3daf703b383f= 7935a Author: Zide Chen AuthorDate: Thu, 11 Jun 2026 09:00:27 -07:00 Committer: Peter Zijlstra CommitterDate: Tue, 30 Jun 2026 10:57:03 +02:00 perf/x86/intel/uncore: Fix refcnt and other cleanups Fix typo UNCORE_BOX_FLAG_INITIATED to UNCORE_BOX_FLAG_INITIALIZED. Rename the 'id' parameter in uncore_box_{ref,unref}() to 'die' to reflect its actual meaning and be consistent with other functions. box->refcnt is incremented in the PCI PMU register path but has never been checked or decremented. Although for PCI PMUs box->refcnt effectively tracks only a single user, add atomic_dec_return() in the PCI PMU unregister path to make the reference counting complete and consistent. Signed-off-by: Zide Chen Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Dapeng Mi Link: https://patch.msgid.link/20260611160033.66760-3-zide.chen@intel.com --- arch/x86/events/intel/uncore.c | 16 +++++++++------- arch/x86/events/intel/uncore.h | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index b69b6a2..21c8ed1 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -1255,8 +1255,10 @@ static void uncore_pci_pmu_unregister(struct intel_unc= ore_pmu *pmu, int die) pmu->boxes[die] =3D NULL; if (atomic_dec_return(&pmu->activeboxes) =3D=3D 0) uncore_pmu_unregister(pmu); - uncore_box_exit(box); - kfree(box); + if (atomic_dec_return(&box->refcnt) =3D=3D 0) { + uncore_box_exit(box); + kfree(box); + } } =20 static void uncore_pci_remove(struct pci_dev *pdev) @@ -1518,7 +1520,7 @@ static void uncore_change_context(struct intel_uncore_t= ype **uncores, uncore_change_type_ctx(*uncores, old_cpu, new_cpu); } =20 -static void uncore_box_unref(struct intel_uncore_type **types, int id) +static void uncore_box_unref(struct intel_uncore_type **types, int die) { struct intel_uncore_type *type; struct intel_uncore_pmu *pmu; @@ -1529,7 +1531,7 @@ static void uncore_box_unref(struct intel_uncore_type *= *types, int id) type =3D *types; pmu =3D type->pmus; for (i =3D 0; i < type->num_boxes; i++, pmu++) { - box =3D pmu->boxes[id]; + box =3D pmu->boxes[die]; if (box && box->cpu >=3D 0 && atomic_dec_return(&box->refcnt) =3D=3D 0) uncore_box_exit(box); } @@ -1604,14 +1606,14 @@ cleanup: } =20 static int uncore_box_ref(struct intel_uncore_type **types, - int id, unsigned int cpu) + int die, unsigned int cpu) { struct intel_uncore_type *type; struct intel_uncore_pmu *pmu; struct intel_uncore_box *box; int i, ret; =20 - ret =3D allocate_boxes(types, id, cpu); + ret =3D allocate_boxes(types, die, cpu); if (ret) return ret; =20 @@ -1619,7 +1621,7 @@ static int uncore_box_ref(struct intel_uncore_type **ty= pes, type =3D *types; pmu =3D type->pmus; for (i =3D 0; i < type->num_boxes; i++, pmu++) { - box =3D pmu->boxes[id]; + box =3D pmu->boxes[die]; if (box && box->cpu >=3D 0 && atomic_inc_return(&box->refcnt) =3D=3D 1) uncore_box_init(box); } diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index c2e5ccb..bad5d8d 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -185,7 +185,7 @@ struct intel_uncore_box { #define CFL_UNC_CBO_7_PERFEVTSEL0 0xf70 #define CFL_UNC_CBO_7_PER_CTR0 0xf76 =20 -#define UNCORE_BOX_FLAG_INITIATED 0 +#define UNCORE_BOX_FLAG_INITIALIZED 0 /* event config registers are 8-byte apart */ #define UNCORE_BOX_FLAG_CTL_OFFS8 1 /* CFL 8th CBOX has different MSR space */ @@ -559,7 +559,7 @@ static inline u64 uncore_read_counter(struct intel_uncore= _box *box, =20 static inline void uncore_box_init(struct intel_uncore_box *box) { - if (!test_and_set_bit(UNCORE_BOX_FLAG_INITIATED, &box->flags)) { + if (!test_and_set_bit(UNCORE_BOX_FLAG_INITIALIZED, &box->flags)) { if (box->pmu->type->ops->init_box) box->pmu->type->ops->init_box(box); } @@ -567,7 +567,7 @@ static inline void uncore_box_init(struct intel_uncore_bo= x *box) =20 static inline void uncore_box_exit(struct intel_uncore_box *box) { - if (test_and_clear_bit(UNCORE_BOX_FLAG_INITIATED, &box->flags)) { + if (test_and_clear_bit(UNCORE_BOX_FLAG_INITIALIZED, &box->flags)) { if (box->pmu->type->ops->exit_box) box->pmu->type->ops->exit_box(box); }