From nobody Sun Feb 8 20:32:55 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24D523346B9 for ; Thu, 8 Jan 2026 22:56:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767913007; cv=none; b=qFI3ZHKM+yPtrChsgA4gGuh6oaFkB7o8QeIYUE7SdUvP82vXfIatVX7gfDQAS5eK03IPTU+/etcigbKoB4YSXWOPtk/L7f0saHoi0td+ScvaI7AER6ElYqsxcxI7pf6cgcdag0W/w19ts+jAL+0ZaGv654a/hH41KBf7Xz/IRZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767913007; c=relaxed/simple; bh=O6ot7CPctdPFw6WHudhxbDM8ZE4E8EaTJG3EnZslIx8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=s9PJnWQ/mj4LXFjzfIAwNjp7qFel+N0TF55gzySncLRbdEiLL5tO1wxWJ1c9gCIFKA7oYhHkpeuSW30N0MZUWc1tpQc7riXktRSafqHBML+TMbGBfQrCCtze9qcd+2X6vuQvy1JAXwuzDiKUvl+IwCDed1o0cW15xdrRWQ4cjXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--wusamuel.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rEWcm3Fz; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--wusamuel.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rEWcm3Fz" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-1219f27037fso14336819c88.1 for ; Thu, 08 Jan 2026 14:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767913005; x=1768517805; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dJJFhVKyiKKoV+I6tkl9SP4apjw+O1s0pu7zT4uXhoI=; b=rEWcm3FzBG6Quo3FVczNQFeX1M/PpmRajo9yqRGjOQOAtrr6/2wig65ycv293oDUE0 N4jrSbe9T7kAzh+kl1aSApqqrZO8bprMvnPYxHocYFtWPbgbBuMEIaKwX19iuvVT77XS Rc4iyrl4g+XjNgzQlFrD1sCb22649XBilp/En8r3Iin02qAeqBm8gZUtsj8q8S47fPf2 G2CuDsDxQIJgSr+YDYmiEwyH3DsLoqf5w4hevb707LQ8fPEaXvsp9KE/3h5C1Ao9Q5td ceJI1ykbvcj8Nu0utoEyBKp7RAiJP2bL1XxUBLuU/M7u0pww6iUeiphZAjaulAiHGD6u Qaug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767913005; x=1768517805; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dJJFhVKyiKKoV+I6tkl9SP4apjw+O1s0pu7zT4uXhoI=; b=d63t/yfBrgjo33tttpvC5qHqYxqUDYQ/diNIYx9sitGZDxNMpMpDZ7zG43f5MQdARY r0wrlN2F95hQnwX6Tqj8lTqSRK6nWBUtpIge/vAxuqpqaiURH+k/Jt8ejOwbjW5nirCn auB0wXafPphcWgV6THnQA7G2BygUSANcXbOeoYcgc0tvutBFHcStT6ZxVSY2JrhFXZ/b Jznb3I7QsiGqYa4zGpuVJo3TYUkpKa6CFe1C7d1+aWGCWsXSY7uXfyGZ+U4FkTbCo4z7 yZox+36YpJOIDLmPwdFkOmRyuh/Lt08m96toChtumCRymCHcRiLp2iRQTVYFcPhYFi6y P6Tg== X-Forwarded-Encrypted: i=1; AJvYcCW9LtR0Cc5qBauJ+BEUSi1JLDVPw+HOSmhGQOBHmeP8Oy7VPOWiS3yN6xte3idv4cOgt8uZ1UMdRqB0oZU=@vger.kernel.org X-Gm-Message-State: AOJu0YwTPbb/Xv1VJlyAeh1VchB6Y+rvQ+3He1F/+4S96cd1oSMYNNP2 huA8jxGrZybi9UN6qYCuwxVz1y4Qfz26uCcMNIivH57POp2Ra7/KCHkLb4T5VhunNl1hdeHr8EA 8O4v+fZ1ikqlPVQ== X-Google-Smtp-Source: AGHT+IH3CAgfHxDvv2J1GeCokRZ2S0eL3vzB4naD0DGXvhIrgl0bXBb/VDYWZsHKr5BZFHhvYXCyyWn/7qi9tQ== X-Received: from dlbbs14.prod.google.com ([2002:a05:7022:90e:b0:11b:b756:3e9b]) (user=wusamuel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:aa9:b0:11b:9386:7ecc with SMTP id a92af1059eb24-121f8b5f7a4mr7253173c88.41.1767913005229; Thu, 08 Jan 2026 14:56:45 -0800 (PST) Date: Thu, 8 Jan 2026 14:55:18 -0800 In-Reply-To: <20260108225523.3268383-1-wusamuel@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260108225523.3268383-1-wusamuel@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260108225523.3268383-2-wusamuel@google.com> Subject: [PATCH bpf-next v2 1/4] bpf: Add wakeup_source iterator From: Samuel Wu To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Samuel Wu , kernel-team@android.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a BPF iterator for traversing through wakeup_sources. Setup iterators to traverse through a SRCUs of wakeup_sources. This is a more elegant and efficient traversal than going through the options today, such as at /sys/class/wakeup, or through debugfs. Signed-off-by: Samuel Wu --- kernel/bpf/Makefile | 3 + kernel/bpf/wakeup_source_iter.c | 103 ++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 kernel/bpf/wakeup_source_iter.c diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile index 79cf22860a99..1259373298e1 100644 --- a/kernel/bpf/Makefile +++ b/kernel/bpf/Makefile @@ -66,6 +66,9 @@ obj-$(CONFIG_BPF_SYSCALL) +=3D kmem_cache_iter.o ifeq ($(CONFIG_DMA_SHARED_BUFFER),y) obj-$(CONFIG_BPF_SYSCALL) +=3D dmabuf_iter.o endif +ifeq ($(CONFIG_PM_SLEEP),y) +obj-$(CONFIG_BPF_SYSCALL) +=3D wakeup_source_iter.o +endif =20 CFLAGS_REMOVE_percpu_freelist.o =3D $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_bpf_lru_list.o =3D $(CC_FLAGS_FTRACE) diff --git a/kernel/bpf/wakeup_source_iter.c b/kernel/bpf/wakeup_source_ite= r.c new file mode 100644 index 000000000000..ab83d212a1f9 --- /dev/null +++ b/kernel/bpf/wakeup_source_iter.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2026 Google LLC */ +#include +#include +#include +#include +#include + +struct bpf_iter__wakeup_source { + __bpf_md_ptr(struct bpf_iter_meta *, meta); + __bpf_md_ptr(struct wakeup_source *, wakeup_source); +}; + +static void *wakeup_source_iter_seq_start(struct seq_file *seq, loff_t *po= s) +{ + int *srcuidx =3D seq->private; + struct wakeup_source *ws; + loff_t i; + + *srcuidx =3D wakeup_sources_read_lock(); + + ws =3D wakeup_sources_walk_start(); + for (i =3D 0; ws && i < *pos; i++) + ws =3D wakeup_sources_walk_next(ws); + + return ws; +} + +static void *wakeup_source_iter_seq_next(struct seq_file *seq, void *v, lo= ff_t *pos) +{ + struct wakeup_source *ws =3D v; + + ++*pos; + + return wakeup_sources_walk_next(ws); +} + +static void wakeup_source_iter_seq_stop(struct seq_file *seq, void *v) +{ + int *srcuidx =3D seq->private; + + if (*srcuidx >=3D 0) + wakeup_sources_read_unlock(*srcuidx); + *srcuidx =3D -1; +} + +static int __wakeup_source_seq_show(struct seq_file *seq, void *v, bool in= _stop) +{ + struct bpf_iter_meta meta =3D { + .seq =3D seq, + }; + struct bpf_iter__wakeup_source ctx =3D { + .meta =3D &meta, + .wakeup_source =3D v, + }; + struct bpf_prog *prog =3D bpf_iter_get_info(&meta, in_stop); + + if (prog) + return bpf_iter_run_prog(prog, &ctx); + + return 0; +} + +static int wakeup_source_iter_seq_show(struct seq_file *seq, void *v) +{ + return __wakeup_source_seq_show(seq, v, false); +} + +static const struct seq_operations wakeup_source_iter_seq_ops =3D { + .start =3D wakeup_source_iter_seq_start, + .next =3D wakeup_source_iter_seq_next, + .stop =3D wakeup_source_iter_seq_stop, + .show =3D wakeup_source_iter_seq_show, +}; + +static const struct bpf_iter_seq_info wakeup_source_iter_seq_info =3D { + .seq_ops =3D &wakeup_source_iter_seq_ops, + .seq_priv_size =3D sizeof(int), +}; + +static struct bpf_iter_reg bpf_wakeup_source_reg_info =3D { + .target =3D "wakeup_source", + .ctx_arg_info_size =3D 1, + .ctx_arg_info =3D { + { + offsetof(struct bpf_iter__wakeup_source, wakeup_source), + PTR_TO_BTF_ID_OR_NULL + }, + }, + .seq_info =3D &wakeup_source_iter_seq_info, +}; + +DEFINE_BPF_ITER_FUNC(wakeup_source, struct bpf_iter_meta *meta, + struct wakeup_source *wakeup_source) +BTF_ID_LIST_SINGLE(bpf_wakeup_source_btf_id, struct, wakeup_source) + +static int __init wakeup_source_iter_init(void) +{ + bpf_wakeup_source_reg_info.ctx_arg_info[0].btf_id =3D bpf_wakeup_source_b= tf_id[0]; + return bpf_iter_reg_target(&bpf_wakeup_source_reg_info); +} + +late_initcall(wakeup_source_iter_init); --=20 2.52.0.457.g6b5491de43-goog