From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384796; b=D08ABSDjZuLI+Mdc0ywZ32ifiaqMlo6qum3Snts28GUIAXaZYT1PaNBjLNu2NAf7KIcZ l64aTNSyGDVg/YcdBU/1/GpM/rqxYoG3Z1WWrxRNr3md6Cb0IiSkgEPKXv79feiK/Oe3o ThYJWqfA/tM+/kiV1DIZeXGF1mzgyCRMdgn0nkdZcRN76ITpPZkHs8C6g8T9VUyo/Lt2p p2uX72fXsNKNrNuUsGgPtbugmvw1V9EHfpqTNgZEmsT8X4BAYKlUTofT4OMoyD92mXzhH elqvjxXakk2l0leqTIexT2VL0/jKes+TmbwXBNMWOaZUFl/ka9752GfO5JGf3OHfBlw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384796; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=dtnE7HIxwTjXt0UmS5+/keVj7MuHJjO8h6/nkqkJnu8=; b=agRNzkzMtGU3bMN1PJ28ZicBEsQIBWsZ+lzi2t8Ct+qohzVV4KRszyLDg5McAA89w3iR 768YVop57JnfSF7yV+734q/h9bFu6who11lCnc7+DrGsNkNJGcDKL9bRCvMRX32z51h1A bKUpGYzYGvlZSmUpJKg60HAbs3Pg911xPmEDGKMg2Gn/YVmJ6d9yvl0XMSabGoooyfM+F A3nd/IygBdFdXKoMimYu5DZuMfF6D4zHvqINvPvN1upyB+iMtekW7dypQN31EclcJgmwO dhs2ck+Hb8qq3ProyylbL/avhpVdCK/HnmRBU7ww3t8NfQgV6I+BkG8FlQST+imEGFw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="GjQ/iLi2"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEB93606A322; Fri, 4 Dec 2026 11:46:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=GjQ/iLi2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 661361F000CE; Fri, 4 Dec 2026 11:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384795; bh=dtnE7HIxwTjXt0UmS5+/keVj7MuHJjO8h6/nkqkJnu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GjQ/iLi2Z2Xa32SpOCngMger6GH7qo8e2cQCYLKU8IhAvs7NiUtuNyGdeBo9NUvyD B+g6nj/ZcYcoT7OrGHNw8TcNFE5m8xm+yKunFYoaGrXmRisplEVotujBp3iq+ufF0z 8Oo2z71NlAECW6xM7pv5MKdiz1SboKWTbZRMBYH4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ian Rogers , Hui Su , Namhyung Kim , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.6 0298/1167] perf evsel: Restrict incremental open error unwind Date: Fri, 4 Dec 2026 18:55:25 +0900 Message-ID: <20261204100709.794037101@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hui Su [ Upstream commit d023b2110d0d7232ba952a486c497ba8817f6f66 ] evsel__open_cpu(), evsel__tool_pmu_open() and evsel__hwmon_pmu_open() support opening a subrange of a CPU map, bounded by [start_cpu_map_idx, end_cpu_map_idx). Their error paths, however, unwind using "while (--idx >= 0)" all the way back to CPU index 0 regardless of start_cpu_map_idx. If lower CPU indices were opened by an earlier invocation, a later incremental open failure therefore closes those existing file descriptors and overwrites their slots with -1. Before this fix, running the new incremental open test demonstrates this corruption: $ perf test -v "Tool PMU" 12: Tool PMU: 12.1: Tool PMU : Ok 12.2: Tool PMU leader : Ok 12.3: Incremental open error unwind boundary: FAILED: CPU 0 FD overwritten: FD(evsel, 0, 0)=-1, expected 4 FAILED! Stop the unwind at start_cpu_map_idx so that only file descriptors opened by the current invocation are rolled back. After this fix: $ perf test -v "Tool PMU" 12: Tool PMU: 12.1: Tool PMU : Ok 12.2: Tool PMU leader : Ok 12.3: Incremental open error unwind boundary : Ok Fixes: 4804e0111662d7d8 ("perf stat: Use affinity for opening events") Fixes: 240505b2d0adcdc8 ("perf tool_pmu: Factor tool events into their own PMU") Fixes: 53cc0b351ec99278 ("perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs") Reviewed-by: Ian Rogers Signed-off-by: Hui Su Acked-by: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo [ sashal: Only the evsel.c hunk of the upstream change was applied, as the same one-line loop-bound fix; the tool_pmu.c, hwmon_pmu.c and new test hunks were dropped because those files don't exist in this tree. ] Signed-off-by: Sasha Levin --- tools/perf/util/evsel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ff9ad7637562a..139956317a33a 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2174,7 +2174,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, FD(evsel, idx, thread) = -1; } thread = nthreads; - } while (--idx >= 0); + } while (--idx >= start_cpu_map_idx); errno = old_errno; return err; } -- 2.53.0