From nobody Fri Dec 19 21:17:24 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 29D453148B5 for ; Thu, 4 Dec 2025 02:50:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764816632; cv=none; b=Wx0kGJX6pzp2EDoVS9zE6dXW/DbhUOZyeJbGcLN5T90XHbr3wUGR3Zu2+YIKvkIx9CkB7A+s50JerZyPFyTS2zwY11MCQPcyuN8MiwNTCS2K6BmVxHpQuDVSz53APSzb3lQDUQy1eu7wLb7CIJ0Bta/lVIToIeipywzbeso8OIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764816632; c=relaxed/simple; bh=i9rWPJ1BRPlZegR1PINTMP8i5dYmXfU+6qSQof50Jxc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lYYsIy09mK5L8hh6Ni4mAEY+G9tscrLhmfUUb+r30kXcdfdilmOEiOSONLnIb2Bhah+DmDqcq1DHKJkZ7C1E56EnoiE93euOffH4W7lGf6GmQP5jt9ASUYxV4mstAk5eT9+s4Djdi35bcTnfZUFOFbjD1WE1jmKVO5Y3M+GlAmA= 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=fuQ6s5Hn; arc=none smtp.client-ip=209.85.216.74 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="fuQ6s5Hn" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-343daf0f488so437063a91.1 for ; Wed, 03 Dec 2025 18:50:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764816622; x=1765421422; 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=qSyTnP2FbGdIREPxSFsXIq8s93x8aTcDdJSLn+2cqSQ=; b=fuQ6s5HnszUxh/kS8dnXcT8QoiqQ5LWe05lQ7bln9fw7ujHtTjFUcBlK2OTVFIzF3f 32gNiQScCBnk2K76LNxGta/Jsqurg8YXc5CcTBWTYDnraTWb8ISEmfACNgQFXvB3Pww8 H7nkMD39BcavVrTyVxlGLies42dZM1nCvukAtpEPq6nAdsvrSo9tNzKTkocZ5zvS3UW2 ti5194GwkzglfBGNSjP0mFeo5RpsrVS6ls/ba+iHxcpM9B+ExyHMgi/fqseUi2Z87S/N HVBaMVbK2HRWZQM28tiqYpdIKgR9W/jSZ7W1baiD2lUmbOHPISW5EbKTtqJF7QJ65vDt s6vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764816622; x=1765421422; 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=qSyTnP2FbGdIREPxSFsXIq8s93x8aTcDdJSLn+2cqSQ=; b=cvwduidyDsEwd+nxnCanUYISRh3L3+69C4Tlc/sPPeucS62ewehUBaGtwyaQIPWR08 wgLRPelCjlcRzJOC2HOuUeW3noMlBmOJD8hbB22rViIjvD4QSYRugJWrGu8c4B8Um+ET WhDlIb4tmVMjqvcaZNc4FoZDz+De9AF9VH7stNb8kJlWRrIAuT3bhEHu7lsRvxQue4j1 ekGpFN5HTDinr2FU1B4gMFEuaqM6ArHh4YWrDfNE7oP5VbTdVHGQEtMqUBr0uML+Ku0F /j0kz8QmG/Ji5MLbxoUQWUeceEI4j7Lr2yZWKr9jiHXrsAmJesBMehZJRnklPEC7VVDQ v4Gw== X-Forwarded-Encrypted: i=1; AJvYcCU7BQbc73VpsctYgnU6JV+TeCBYChTmvc9GFb9viOuCng6IvVPVafdDCtqI4AlSUDxHoNAUjw6OArMg568=@vger.kernel.org X-Gm-Message-State: AOJu0YzvCJgFS45JLM5CymPlp+/NATtE+Nw/ybFJyCJm9zdE2o/J6YGO tpLUH/PI+VPgGj9ocUXQ+27zejGA23OLM3JDhcoJazhXQsLW0LQSSZTqqhG+OCo72Ogps/6AXxD 0r/1TFg5wvHeNmQ== X-Google-Smtp-Source: AGHT+IF+RwUg4NL/WO7wzUqMdZLA75lB4Kko0R/cM/dJoFvWb5ppd/z3qezKD0KnEXcQmgmOSSRWiV2vCaVfcQ== X-Received: from pgdi15.prod.google.com ([2002:a05:6a02:51ef:b0:bc8:68ae:e506]) (user=wusamuel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2588:b0:35c:f727:8a89 with SMTP id adf61e73a8af0-36403876ee8mr1666667637.41.1764816621600; Wed, 03 Dec 2025 18:50:21 -0800 (PST) Date: Wed, 3 Dec 2025 18:49:59 -0800 In-Reply-To: <20251204025003.3162056-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: <20251204025003.3162056-1-wusamuel@google.com> X-Mailer: git-send-email 2.52.0.177.g9f829587af-goog Message-ID: <20251204025003.3162056-3-wusamuel@google.com> Subject: [PATCH v1 2/4] bpf: Open coded BPF for wakeup_sources 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: rafael.j.wysocki@intel.com, 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 open coded BPF iterators for wakeup_sources, which opens up more options for BPF programs that need to traverse through wakeup_sources. Signed-off-by: Samuel Wu --- kernel/bpf/helpers.c | 3 +++ kernel/bpf/wakeup_source_iter.c | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index db72b96f9c8c..a5f867de6bd6 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -4518,6 +4518,9 @@ BTF_ID_FLAGS(func, bpf_iter_dmabuf_new, KF_ITER_NEW |= KF_SLEEPABLE) BTF_ID_FLAGS(func, bpf_iter_dmabuf_next, KF_ITER_NEXT | KF_RET_NULL | KF_S= LEEPABLE) BTF_ID_FLAGS(func, bpf_iter_dmabuf_destroy, KF_ITER_DESTROY | KF_SLEEPABLE) #endif +BTF_ID_FLAGS(func, bpf_iter_wakeup_source_new, KF_ITER_NEW | KF_SLEEPABLE) +BTF_ID_FLAGS(func, bpf_iter_wakeup_source_next, KF_ITER_NEXT | KF_RET_NULL= | KF_SLEEPABLE) +BTF_ID_FLAGS(func, bpf_iter_wakeup_source_destroy, KF_ITER_DESTROY | KF_SL= EEPABLE) BTF_ID_FLAGS(func, __bpf_trap) BTF_ID_FLAGS(func, bpf_strcmp); BTF_ID_FLAGS(func, bpf_strcasecmp); diff --git a/kernel/bpf/wakeup_source_iter.c b/kernel/bpf/wakeup_source_ite= r.c index b8719f47428e..e2c0dcbfd02d 100644 --- a/kernel/bpf/wakeup_source_iter.c +++ b/kernel/bpf/wakeup_source_iter.c @@ -90,6 +90,40 @@ static struct bpf_iter_reg bpf_wakeup_source_reg_info = =3D { .seq_info =3D &wakeup_source_iter_seq_info, }; =20 +struct bpf_iter_wakeup_source { + struct wakeup_source *ws; + int srcuidx; +}; + +__bpf_kfunc_start_defs(); + +__bpf_kfunc int bpf_iter_wakeup_source_new(struct bpf_iter_wakeup_source *= it) +{ + it->srcuidx =3D wakeup_sources_read_lock(); + it->ws =3D wakeup_sources_walk_start(); + + return 0; +} + +__bpf_kfunc struct wakeup_source *bpf_iter_wakeup_source_next(struct bpf_i= ter_wakeup_source *it) +{ + struct wakeup_source *prev =3D it->ws; + + if (!prev) + return NULL; + + it->ws =3D wakeup_sources_walk_next(it->ws); + + return prev; +} + +__bpf_kfunc void bpf_iter_wakeup_source_destroy(struct bpf_iter_wakeup_sou= rce *it) +{ + wakeup_sources_read_unlock(it->srcuidx); +} + +__bpf_kfunc_end_defs(); + 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) --=20 2.52.0.177.g9f829587af-goog