From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A43D5C3600B for ; Mon, 31 Mar 2025 14:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=k7HAqjeWwLVnuthJm9T0TyotQsYdYi4nXf0ltHZaJaY=; b=jnwK47h6X5UzImefvYIXdqvh9l wzEWqw6mRbGepfPgcX6yM0hq0HRoJU9BRAHWCjKLqsdc7IDZhneElqF86xW7bfbvDkwav3ejXT1a2 Zqvbg4uDwNWSIe2J4O6LyvtQyPn9x2gLcwLDmFbQgS/C0yeVczfIhyEa+Y9uJyUiXfSJXFb8Ssb2D BVkLrKfmePqYhubvgesYA/MfB7O3UUhY3JtNKnFF7DXPbJwJYBHdol+XGxeFnhinNatz5u40cwB6l WciGt+XiieGmNpwNqLVSYFa8kI2y7/m2jUeB4YRI3m5UcEhhY+oKplxAk9o8xyxIYe5/D1kb8xT2k l9CUprPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzGWQ-00000000e6v-0C15; Mon, 31 Mar 2025 14:53:54 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzGEr-00000000ZsY-3Qtr for linux-arm-kernel@lists.infradead.org; Mon, 31 Mar 2025 14:35:45 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id AB677614CA; Mon, 31 Mar 2025 14:35:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5FBEC4CEE4; Mon, 31 Mar 2025 14:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743431745; bh=RxXN5ImDkHlxqQmfInHiKTyFOrz987IzeR6333NbSJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mCjFciJ5/RPu2UxMUzlt6qzZzymmvnyaW8g8d+HaTDzirlooR6z7mMKGymRwtc7mr gibwz5DkEXTTlIIxyT+OYPqvDFxnskFr6KogsX/Dini7l1P6dH4/E6PbZZIbcldFt4 escs/isngKuGS1Qd+rvbzisuXrHGyHpSLV/yxyUTy+3uTLh9Ol8+v/1AMU9U3Fsm7o 4uWPUBAq6unHxUo0coNPIgZYQbZL9x2FO+PXXkQphb6vTdQEJTc0PMQKNs0hFrcr9p fGf0kWLqavenDp7QhBAw/YbD6MA0Q2x4byOQHIXAjWzzqIECH6vodYyqTkz8bGUvJk PRgAc2wl1Jtnw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mark Rutland , Rob Herring , Anshuman Khandual , James Clark , Will Deacon , Sasha Levin , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Subject: [PATCH AUTOSEL 6.12 06/13] perf: arm_pmu: Don't disable counter in armpmu_add() Date: Mon, 31 Mar 2025 10:35:20 -0400 Message-Id: <20250331143528.1685794-6-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250331143528.1685794-1-sashal@kernel.org> References: <20250331143528.1685794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.12.21 Content-Transfer-Encoding: 8bit X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Mark Rutland [ Upstream commit dcca27bc1eccb9abc2552aab950b18a9742fb8e7 ] Currently armpmu_add() tries to handle a newly-allocated counter having a stale associated event, but this should not be possible, and if this were to happen the current mitigation is insufficient and potentially expensive. It would be better to warn if we encounter the impossible case. Calls to pmu::add() and pmu::del() are serialized by the core perf code, and armpmu_del() clears the relevant slot in pmu_hw_events::events[] before clearing the bit in pmu_hw_events::used_mask such that the counter can be reallocated. Thus when armpmu_add() allocates a counter index from pmu_hw_events::used_mask, it should not be possible to observe a stale even in pmu_hw_events::events[] unless either pmu_hw_events::used_mask or pmu_hw_events::events[] have been corrupted. If this were to happen, we'd end up with two events with the same event->hw.idx, which would clash with each other during reprogramming, deletion, etc, and produce bogus results. Add a WARN_ON_ONCE() for this case so that we can detect if this ever occurs in practice. That possiblity aside, there's no need to call arm_pmu::disable(event) for the new event. The PMU reset code initialises the counter in a disabled state, and armpmu_del() will disable the counter before it can be reused. Remove the redundant disable. Signed-off-by: Mark Rutland Signed-off-by: Rob Herring (Arm) Reviewed-by: Anshuman Khandual Tested-by: James Clark Link: https://lore.kernel.org/r/20250218-arm-brbe-v19-v20-2-4e9922fc2e8e@kernel.org Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/perf/arm_pmu.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c index 398cce3d76fc4..2f33e69a8caf2 100644 --- a/drivers/perf/arm_pmu.c +++ b/drivers/perf/arm_pmu.c @@ -342,12 +342,10 @@ armpmu_add(struct perf_event *event, int flags) if (idx < 0) return idx; - /* - * If there is an event in the counter we are going to use then make - * sure it is disabled. - */ + /* The newly-allocated counter should be empty */ + WARN_ON_ONCE(hw_events->events[idx]); + event->hw.idx = idx; - armpmu->disable(event); hw_events->events[idx] = event; hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE; -- 2.39.5