From nobody Mon Feb 9 06:24:52 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.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 DAB9D328B47 for ; Thu, 8 Jan 2026 22:56:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767913012; cv=none; b=CVE0x+iv9Tjtakx7NJhcwzKNbiZBqUn9x89dg1DazmNbqL1BfUokLfKd8LUf6LiDFIHU7TFXT16T2mxolW5vOjBYBMud+ecUVgSBT6OPFr2otPxSV+G0lZGkQ1oRno5ustq4iVsaW9M0DDXQT9su6lSxk1BbK9AaJAwIWJYkylE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767913012; c=relaxed/simple; bh=kuVmwolLprvgFQC5gK2CvP6uE4+/Xs3CDYIOcSnFIuI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZKu8ezKKBPMsutYzLwWdPJyTeWn9QO8VqTgmJVrs7fzCXLKF2AWiQUW2Er5dTtAgj8kwKvYbXJbATvp9O4ebSp/GAr6pf3nQRXJ6s4XvKX9/r1Sy7TBbCcsZ4o1vx1D1MJGFPxgvDx1i1/Ws7QxqL4PCH+DcGI1TgPybH5E6M+I= 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=jCbnL6gW; arc=none smtp.client-ip=74.125.82.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="jCbnL6gW" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-121b1cb8377so4904341c88.0 for ; Thu, 08 Jan 2026 14:56:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767913010; x=1768517810; 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=CuaylGKmhlV4n+kOnxwaacUMm3XMBF1qN/OxctemuKo=; b=jCbnL6gWyHuDCKcaPrAAtyioE9hZB9mzzsjjpJfXVpFFlBrH3VPv98CY0IeeWCkgbh EvJYr39s8LfREbVC9B+1hCJ1Nk3x0QzJE8MTaDC2CgWRlEt7bl7ZR79s43q9b4rh6wng rGzEnwApZXrWlU1X1LCVdSYB6mgBsnZ/MXkdIksl1iaF6MpWQ3hS9HAOuaZWwxJtdsGd JKbJwLGYY4iSDIS303QQGNUmQGuCGSyMVTTfGi99QxPWIR4gSzu3GxnflfeRGhb+ktS4 5/7fxTD7ScJcD3U8zNoktpZGrp7Ypz5kcSpNc3UM5gMPRplLaFQC4nTS6Qw50/wYW7tP hHsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767913010; x=1768517810; 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=CuaylGKmhlV4n+kOnxwaacUMm3XMBF1qN/OxctemuKo=; b=KutLl8BMZ3EYrFb7582CaRxEdlCvDdAhn0ljh7x/noNvSSNpo9Yu2WegpiG7NxfI/v KbTXiUhWTx1mTEj9LIYq8zaqkw/x8IsiVFUMlbRpN/VFKqVYIQ1/6SjJKFYmV0QbSa4B eL8AYm4VR/SPOa9uAXi3jfzgWA9SXKEQuFiVKo2x+2U8Ly9YWmZsR3PhHtgEuTJn8ac7 e68uPsKEbu7bfjqxQoqeKVRHV7lHF+ZgWmA/0JXvKYdbb/BJSW2oC1PwvP+WNMA1FKGB 4X8Ob5YWSWUVM4PoKb+SK5Rrxm9Xj/m210vPM9/G2yNtRGpHobvnFodcQmkuI2N2kZrU +KyQ== X-Forwarded-Encrypted: i=1; AJvYcCUCFhhiYT+3X82yYzX8zl0mxadF3SHcpHUg2zmNtyMAq93P0crtCw8IgAlJV3WKHrV+FipwK4On2B4ZgEY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2IDbmRCPMsNpxx9lKIyJGCVNHWYdZRQxG0RrhHkM/w2Q31ldv fymfp06vW2vaX7MblcQ9LOLh+7t607mSrqVaCQXKtl5Wubncyv+FCtA8A3dCWT4RyOvfPJZBm34 P/N9XDjDdd5Qzpw== X-Google-Smtp-Source: AGHT+IENQBlDEvxTyqSWqxJtIK7u6/aN3XKMd1H9vZCTl6QBchXevnwExPMON9th5RerMP1jT6OOwF5oFTEgqQ== X-Received: from dlbcf27.prod.google.com ([2002:a05:7022:459b:b0:11d:cf87:f4ee]) (user=wusamuel job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ff46:b0:11e:3e9:3e8c with SMTP id a92af1059eb24-121f8b9e460mr7435141c88.49.1767913010038; Thu, 08 Jan 2026 14:56:50 -0800 (PST) Date: Thu, 8 Jan 2026 14:55:19 -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-3-wusamuel@google.com> Subject: [PATCH bpf-next v2 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: 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 9eaa4185e0a7..ca34d7614c3a 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 ab83d212a1f9..149baecfe436 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.457.g6b5491de43-goog