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=1796387438; b=UnN8XOhaAVnoWwIGlJQtlSjCttZ8IKHoylJ70WT4AOMRZ4ahGwxIur7FVwY+9BDhYUKc ggj/69ua5KZOzRDdlLfxHX21/wh39ZffO2Qy4mRoIhDDT/pbJIGXyLupH8G/3tKsHsabt 4cNGvFS0hsURrQAV03/qI4Fr/sENQsuzoHUUmkuuTzHxL4jLrR7rWeqhFl6hNgfZkUMmy kHoWxS1cXP6IzRIqkRadxRxAdQRaWen/13xb4/gISqG0xRE7m32CTxu91swTb6r7ZFa/9 rQDrj5mYrfwMS23h39vtEB62we43qpPh5RpIjzzlCblm1a/+aSYOOJLa4VbCk8AvXSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387438; 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=sRpBpXHNf5gUw+tTOmmkOeQ5MQz+N0nCylGF++o2z5I=; b=lQyK7Xt3/9bE66vZWqp6fe11eCa02tXqduw/Ii/sgeOtocujPlvxDgXwF8QcIQgEFgcJ EQWj8euxYOZQPQ8SXhqztYUJBiiStNoXG+R6MxTBOKr8/zwZyK7krLAgNi5sjB8kD1E+q 9iJQFBkauT0PFycInwzBoXLR9pfKF1g/Q6f0PJviQjnANGJSzuM6vHohGF2q/NrdiovZu ebF+4mccoZCIaUXzubPUP0lAU1q7EA4iTBUcKlAUlA0AUOw8RfOBFXyW4o8yMmg8K0qEC bVZsBR+Wpc2s/+Ovfvj4osTZCSOw4LlFlvV1XQo3HpAsBEUj2EBvH95BcihwFwIxfnQ== 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="U5yv/6U4"; 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 6A5A4606A32C; Fri, 4 Dec 2026 12:30:38 +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=U5yv/6U4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D78781F000CE; Fri, 4 Dec 2026 12:30:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387438; bh=sRpBpXHNf5gUw+tTOmmkOeQ5MQz+N0nCylGF++o2z5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U5yv/6U4k6ltpGCTfuVOwdWx31vX23s5kpQo55YKi7Euh3YgZ4YFGPCO5yjCGSJ77 vU9X38isvvS5DD59bnuihEvj5pq8GNRAwmNtfysclOixi88J1sfqvFUasRu6PaqGBf QUUzJawhQG4wqr7q7tVoGoyZgWq3hadeRiZjcHmA= 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.1 0244/1059] perf evsel: Restrict incremental open error unwind Date: Fri, 4 Dec 2026 18:56:15 +0900 Message-ID: <20261204100650.594326454@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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: Dropped the tool PMU, hwmon PMU and test hunks because those files don't exist here; only the evsel.c unwind bound change (--idx >= start_cpu_map_idx) is kept. ] 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 755da242f2670..02675d951e4ba 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2189,7 +2189,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