From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: "Ian Rogers" <irogers@google.com>,
"James Clark" <james.clark@arm.com>,
"Adrian Hunter" <adrian.hunter@intel.com>,
"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
"Alexandre Ghiti" <alexghiti@rivosinc.com>,
"Andrew Jones" <ajones@ventanamicro.com>,
"André Almeida" <andrealmeid@igalia.com>,
"Athira Jajeev" <atrajeev@linux.vnet.ibm.com>,
"Atish Patra" <atishp@rivosinc.com>,
"Changbin Du" <changbin.du@huawei.com>,
"Darren Hart" <dvhart@infradead.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Huacai Chen" <chenhuacai@kernel.org>,
"Ingo Molnar" <mingo@redhat.com>, "Jiri Olsa" <jolsa@kernel.org>,
"John Garry" <john.g.garry@oracle.com>,
"K Prateek Nayak" <kprateek.nayak@amd.com>,
"Kajol Jain" <kjain@linux.ibm.com>,
"Kan Liang" <kan.liang@linux.intel.com>,
"Leo Yan" <leo.yan@linaro.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Mike Leach" <mike.leach@linaro.org>,
"Namhyung Kim" <namhyung@kernel.org>,
"Nick Desaulniers" <ndesaulniers@google.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Paran Lee" <p4ranlee@gmail.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ravi Bangoria" <ravi.bangoria@amd.com>,
"Sandipan Das" <sandipan.das@amd.com>,
"Sean Christopherson" <seanjc@google.com>,
"Steinar H. Gunderson" <sesse@google.com>,
"Suzuki Poulouse" <suzuki.poulose@arm.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Will Deacon" <will@kernel.org>,
"Yang Jihong" <yangjihong1@huawei.com>,
"Yang Li" <yang.lee@linux.alibaba.com>,
"Yanteng Si" <siyanteng@loongson.cn>,
bpf@vger.kernel.org, coresight@lists.linaro.org,
linux-arm-kernel@lists.infradead.org,
"Arnaldo Carvalho de Melo" <acme@redhat.com>,
"Sasha Levin" <sashal@kernel.org>
Subject: [PATCH 6.6.y 1/2] libperf cpumap: Add for_each_cpu() that skips the "any CPU" case
Date: Thu, 3 Dec 2026 23:15:50 -0500 [thread overview]
Message-ID: <20261204041543.2574571-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120242-finite-impure-8f05@gregkh>
From: Ian Rogers <irogers@google.com>
[ Upstream commit 5805c82513c444333efb086017be8d666336858a ]
When iterating CPUs in a CPU map it is often desirable to skip the "any
CPU" (aka dummy) case. Add a helper for this and use in builtin-record.
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Andrew Jones <ajones@ventanamicro.com>
Cc: André Almeida <andrealmeid@igalia.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Atish Patra <atishp@rivosinc.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paran Lee <p4ranlee@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Yang Li <yang.lee@linux.alibaba.com>
Cc: Yanteng Si <siyanteng@loongson.cn>
Cc: bpf@vger.kernel.org
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20231129060211.1890454-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Stable-dep-of: 82b4a28e7588 ("perf record: Reject CPU indices equal to the mask size")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
tools/lib/perf/include/perf/cpumap.h | 6 ++++++
tools/perf/builtin-record.c | 4 +---
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h
index e38d859a384d2..4e0e4c3533973 100644
--- a/tools/lib/perf/include/perf/cpumap.h
+++ b/tools/lib/perf/include/perf/cpumap.h
@@ -51,6 +51,12 @@ LIBPERF_API bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map);
(idx) < perf_cpu_map__nr(cpus); \
(idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx))
+#define perf_cpu_map__for_each_cpu_skip_any(_cpu, idx, cpus) \
+ for ((idx) = 0, (_cpu) = perf_cpu_map__cpu(cpus, idx); \
+ (idx) < perf_cpu_map__nr(cpus); \
+ (idx)++, (_cpu) = perf_cpu_map__cpu(cpus, idx)) \
+ if ((_cpu).cpu != -1)
+
#define perf_cpu_map__for_each_idx(idx, cpus) \
for ((idx) = 0; (idx) < perf_cpu_map__nr(cpus); (idx)++)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index ddaf38f92898f..30e57aae7f252 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -3531,9 +3531,7 @@ static int record__mmap_cpu_mask_init(struct mmap_cpu_mask *mask, struct perf_cp
if (cpu_map__is_dummy(cpus))
return 0;
- perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
- if (cpu.cpu == -1)
- continue;
+ perf_cpu_map__for_each_cpu_skip_any(cpu, idx, cpus) {
/* Return ENODEV is input cpu is greater than max cpu */
if ((unsigned long)cpu.cpu > mask->nbits)
return -ENODEV;
--
2.53.0
next prev parent reply other threads:[~2026-12-04 4:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:39 FAILED: patch "[PATCH] perf record: Reject CPU indices equal to the mask size" failed to apply to 6.6-stable tree gregkh
2026-12-04 4:15 ` Sasha Levin [this message]
2026-12-04 4:15 ` [PATCH 6.6.y 2/2] perf record: Reject CPU indices equal to the mask size Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204041543.2574571-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=ajones@ventanamicro.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexghiti@rivosinc.com \
--cc=andrealmeid@igalia.com \
--cc=atishp@rivosinc.com \
--cc=atrajeev@linux.vnet.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=changbin.du@huawei.com \
--cc=chenhuacai@kernel.org \
--cc=coresight@lists.linaro.org \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=irogers@google.com \
--cc=james.clark@arm.com \
--cc=john.g.garry@oracle.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=kjain@linux.ibm.com \
--cc=kprateek.nayak@amd.com \
--cc=leo.yan@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mike.leach@linaro.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=ndesaulniers@google.com \
--cc=p4ranlee@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@amd.com \
--cc=sandipan.das@amd.com \
--cc=seanjc@google.com \
--cc=sesse@google.com \
--cc=siyanteng@loongson.cn \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
--cc=yang.lee@linux.alibaba.com \
--cc=yangjihong1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.