public inbox for driver-core@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH v1 0/2] *** Support BPF traversal of wakeup sources ***
@ 2026-03-20 16:00 Samuel Wu
  2026-03-20 16:00 ` [PATCH v1 1/2] PM: wakeup: Add kfuncs to lock/unlock wakeup_sources Samuel Wu
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Samuel Wu @ 2026-03-20 16:00 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich
  Cc: andrii, memxor, bpf, Samuel Wu, kernel-team, linux-pm,
	driver-core, linux-kernel

This patchset adds requisite kfuncs for BPF programs to safely traverse
wakeup_sources, and puts a config flag around the sysfs interface.

Currently, a traversal of wakeup sources require going through
/sys/class/wakeup/* or /d/wakeup_sources/*. The repeated syscalls to query
sysfs is inefficient, as there can be hundreds of wakeup_sources, with each
wakeup source also having multiple attributes. debugfs is unstable and
insecure.

Adding kfuncs to lock/unlock wakeup sources allows BPF program to safely
traverse the wakeup sources list. The head address of wakeup_sources can
safely be resolved through BPF helper functions or variable attributes.

On a quiescent Pixel 6 traversing 150 wakeup_sources, I am seeing ~34x
speedup (sampled 75 times in table below). For a device under load, the
speedup is greater.
+-------+----+----------+----------+
|       | n  | AVG (ms) | STD (ms) |
+-------+----+----------+----------+
| sysfs | 75 | 44.9     | 12.6     |
+-------+----+----------+----------+
| BPF   | 75 | 1.3      | 0.7      |
+-------+----+----------+----------+

On the memory side, between kernfs, dentry, and kmalloc, each wakeup source
removed from sysfs saves at least 10kB.

The initial attempts for BPF traversal of wakeup_sources was with BPF
iterators [1]. However, BPF already allows for traversing of a simple list
with bpf_for(), and this current patchset has the added benefit of being
~2-3x more performant than BPF iterators.

[1]: https://lore.kernel.org/all/20260225210820.177674-1-wusamuel@google.com/

Samuel Wu (2):
  PM: wakeup: Add kfuncs to lock/unlock wakeup_sources
  PM: Add config flag to gate sysfs wakeup_sources

 drivers/base/power/Makefile |  3 +-
 drivers/base/power/power.h  | 14 +++++++++
 drivers/base/power/wakeup.c | 63 +++++++++++++++++++++++++++++++++++--
 kernel/power/Kconfig        | 13 ++++++++
 4 files changed, 90 insertions(+), 3 deletions(-)

-- 
2.53.0.959.g497ff81fa9-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v1 1/2] PM: wakeup: Add kfuncs to lock/unlock wakeup_sources
  2026-03-20 16:00 [PATCH v1 0/2] *** Support BPF traversal of wakeup sources *** Samuel Wu
@ 2026-03-20 16:00 ` Samuel Wu
  2026-03-23 12:33   ` kernel test robot
  2026-03-20 16:00 ` [PATCH v1 2/2] PM: Add config flag to gate sysfs wakeup_sources Samuel Wu
  2026-03-21 17:51 ` [PATCH v1 0/2] *** Support BPF traversal of wakeup sources *** Kumar Kartikeya Dwivedi
  2 siblings, 1 reply; 8+ messages in thread
From: Samuel Wu @ 2026-03-20 16:00 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	Danilo Krummrich
  Cc: andrii, memxor, bpf, Samuel Wu, kernel-team, linux-pm,
	driver-core, linux-kernel

Add kfuncs to lock/unlock for safe traversal of wakeup sources.

Currently, a traversal of wakeup sources require going through
/sys/class/wakeup/* or /d/wakeup_sources/*. The repeated syscalls to
query sysfs is inefficient, as there can be hundreds of wakeup_sources,
with each wakeup source also having multiple attributes. debugfs is
unstable and insecure.

Adding kfuncs to lock/unlock wakeup sources allows BPF program to safely
traverse the wakeup sources list. A new structure, bpf_ws_lock, acts as
an opaque wrapper for the SRCU index. The head address of wakeup_sources
can be safely resolved through BPF helper functions or variable
attributes.

Doing the traversal in BPF is significantly more performant, and has an
output in a format that the user specifies; this solves all the
drawbacks of current interfaces.

Signed-off-by: Samuel Wu <wusamuel@google.com>
---
 drivers/base/power/wakeup.c | 63 +++++++++++++++++++++++++++++++++++--
 1 file changed, 61 insertions(+), 2 deletions(-)

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index b8e48a023bf0..7fc12ce125bc 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -1168,11 +1168,70 @@ static const struct file_operations wakeup_sources_stats_fops = {
 	.release = seq_release_private,
 };
 
-static int __init wakeup_sources_debugfs_init(void)
+#ifdef CONFIG_BPF_SYSCALL
+#include <linux/btf.h>
+
+struct bpf_ws_lock { };
+
+__bpf_kfunc_start_defs();
+
+/**
+ * bpf_wakeup_sources_read_lock - Acquire the SRCU lock for wakeup sources
+ *
+ * The underlying SRCU lock returns an integer index. However, the BPF verifier
+ * requires a pointer (PTR_TO_BTF_ID) to strictly track the state of acquired
+ * resources using KF_ACQUIRE and KF_RELEASE semantics. We use an opaque
+ * structure pointer (struct bpf_ws_lock *) to satisfy the verifier while
+ * safely encoding the integer index within the pointer address itself.
+ *
+ * Return: An opaque pointer encoding the SRCU lock index + 1 (to avoid NULL).
+ */
+__bpf_kfunc struct bpf_ws_lock *bpf_wakeup_sources_read_lock(void)
+{
+	return (struct bpf_ws_lock *)(long)(wakeup_sources_read_lock() + 1);
+}
+
+/**
+ * bpf_wakeup_sources_read_unlock - Release the SRCU lock for wakeup sources
+ * @lock: The opaque pointer returned by bpf_wakeup_sources_read_lock()
+ *
+ * The BPF verifier guarantees that @lock is a valid, unreleased pointer from
+ * the acquire function. We decode the pointer back into the integer SRCU index
+ * by subtracting 1 and release the lock.
+ */
+__bpf_kfunc void bpf_wakeup_sources_read_unlock(struct bpf_ws_lock *lock)
+{
+	wakeup_sources_read_unlock((int)(long)lock - 1);
+}
+
+__bpf_kfunc_end_defs();
+
+BTF_KFUNCS_START(wakeup_source_kfunc_ids)
+BTF_ID_FLAGS(func, bpf_wakeup_sources_read_lock, KF_ACQUIRE)
+BTF_ID_FLAGS(func, bpf_wakeup_sources_read_unlock, KF_RELEASE)
+BTF_KFUNCS_END(wakeup_source_kfunc_ids)
+
+static const struct btf_kfunc_id_set wakeup_source_kfunc_set = {
+	.owner = THIS_MODULE,
+	.set   = &wakeup_source_kfunc_ids,
+};
+
+static void __init wakeup_sources_bpf_init(void)
+{
+	if (register_btf_kfunc_id_set(BPF_PROG_TYPE_SYSCALL, &wakeup_source_kfunc_set))
+		pm_pr_dbg("Wakeup: failed to register BTF kfuncs\n");
+}
+#else
+static inline void wakeup_sources_bpf_init(void) {}
+#endif /* CONFIG_BPF_SYSCALL */
+
+static int __init wakeup_sources_init(void)
 {
 	debugfs_create_file("wakeup_sources", 0444, NULL, NULL,
 			    &wakeup_sources_stats_fops);
+	wakeup_sources_bpf_init();
+
 	return 0;
 }
 
-postcore_initcall(wakeup_sources_debugfs_init);
+postcore_initcall(wakeup_sources_init);
-- 
2.53.0.959.g497ff81fa9-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v1 2/2] PM: Add config flag to gate sysfs wakeup_sources
  2026-03-20 16:00 [PATCH v1 0/2] *** Support BPF traversal of wakeup sources *** Samuel Wu
  2026-03-20 16:00 ` [PATCH v1 1/2] PM: wakeup: Add kfuncs to lock/unlock wakeup_sources Samuel Wu
@ 2026-03-20 16:00 ` Samuel Wu
  2026-03-20 16:09   ` Rafael J. Wysocki
  2026-03-21 17:51 ` [PATCH v1 0/2] *** Support BPF traversal of wakeup sources *** Kumar Kartikeya Dwivedi
  2 siblings, 1 reply; 8+ messages in thread
From: Samuel Wu @ 2026-03-20 16:00 UTC (permalink / raw)
  To: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich
  Cc: andrii, memxor, bpf, Samuel Wu, kernel-team, linux-pm,
	driver-core, linux-kernel

Add a config flag that gates the creation of
/sys/class/wakeup_sources/*. This has the benefit of eliminating the
work needed to create the nodes and corresponding attributes; and
between kernfs, dentry, and malloc, there are some memory savings
depending on the number of wakeup sources.

Signed-off-by: Samuel Wu <wusamuel@google.com>
---
 drivers/base/power/Makefile |  3 ++-
 drivers/base/power/power.h  | 14 ++++++++++++++
 kernel/power/Kconfig        | 13 +++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index 2989e42d0161..5933dadc0dd9 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_PM)	+= sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o
-obj-$(CONFIG_PM_SLEEP)	+= main.o wakeup.o wakeup_stats.o
+obj-$(CONFIG_PM_SLEEP)	+= main.o wakeup.o
+obj-$(CONFIG_PM_WAKEUP_STATS_SYSFS)	+= wakeup_stats.o
 obj-$(CONFIG_PM_TRACE_RTC)	+= trace.o
 obj-$(CONFIG_HAVE_CLK)	+= clock_ops.o
 obj-$(CONFIG_PM_QOS_KUNIT_TEST) += qos-test.o
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 922ed457db19..364ca5512b4f 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -125,11 +125,25 @@ static inline bool device_pm_initialized(struct device *dev)
 }
 
 /* drivers/base/power/wakeup_stats.c */
+#ifdef CONFIG_PM_WAKEUP_STATS_SYSFS
 extern int wakeup_source_sysfs_add(struct device *parent,
 				   struct wakeup_source *ws);
 extern void wakeup_source_sysfs_remove(struct wakeup_source *ws);
 
 extern int pm_wakeup_source_sysfs_add(struct device *parent);
+#else /* !CONFIG_PM_WAKEUP_STATS_SYSFS */
+static inline int wakeup_source_sysfs_add(struct device *parent,
+					  struct wakeup_source *ws)
+{
+	return 0;
+}
+static inline void wakeup_source_sysfs_remove(struct wakeup_source *ws) {}
+
+static inline int pm_wakeup_source_sysfs_add(struct device *parent)
+{
+	return 0;
+}
+#endif /* !CONFIG_PM_WAKEUP_STATS_SYSFS */
 
 #else /* !CONFIG_PM_SLEEP */
 
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index 05337f437cca..6945083ab053 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -202,6 +202,19 @@ config PM_WAKELOCKS_GC
 	depends on PM_WAKELOCKS
 	default y
 
+config PM_WAKEUP_STATS_SYSFS
+	bool "Sysfs wakeup statistics"
+	depends on PM_SLEEP
+	default y
+	help
+	  Enable this for wakeup statistics in sysfs under /sys/class/wakeup/
+
+	  Disabling this option eliminates the work of creating the wakeup
+	  sources and each of their attributes in sysfs. Depending on the
+	  number of wakeup sources, this can also have a non-negligible memory
+	  impact. Regardless of this config option's value, wakeup statistics
+	  are still available via debugfs and BPF.
+
 config PM_QOS_CPU_SYSTEM_WAKEUP
 	bool "User space interface for CPU system wakeup QoS"
 	depends on CPU_IDLE
-- 
2.53.0.959.g497ff81fa9-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 2/2] PM: Add config flag to gate sysfs wakeup_sources
  2026-03-20 16:00 ` [PATCH v1 2/2] PM: Add config flag to gate sysfs wakeup_sources Samuel Wu
@ 2026-03-20 16:09   ` Rafael J. Wysocki
  2026-03-21  0:46     ` Samuel Wu
  0 siblings, 1 reply; 8+ messages in thread
From: Rafael J. Wysocki @ 2026-03-20 16:09 UTC (permalink / raw)
  To: Samuel Wu
  Cc: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, andrii, memxor, bpf, kernel-team, linux-pm,
	driver-core, linux-kernel

On Fri, Mar 20, 2026 at 5:01 PM Samuel Wu <wusamuel@google.com> wrote:
>
> Add a config flag that gates the creation of
> /sys/class/wakeup_sources/*. This has the benefit of eliminating the
> work needed to create the nodes and corresponding attributes; and
> between kernfs, dentry, and malloc, there are some memory savings
> depending on the number of wakeup sources.
>
> Signed-off-by: Samuel Wu <wusamuel@google.com>
> ---
>  drivers/base/power/Makefile |  3 ++-
>  drivers/base/power/power.h  | 14 ++++++++++++++
>  kernel/power/Kconfig        | 13 +++++++++++++
>  3 files changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
> index 2989e42d0161..5933dadc0dd9 100644
> --- a/drivers/base/power/Makefile
> +++ b/drivers/base/power/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier: GPL-2.0
>  obj-$(CONFIG_PM)       += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o
> -obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o wakeup_stats.o
> +obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o
> +obj-$(CONFIG_PM_WAKEUP_STATS_SYSFS)    += wakeup_stats.o
>  obj-$(CONFIG_PM_TRACE_RTC)     += trace.o
>  obj-$(CONFIG_HAVE_CLK) += clock_ops.o
>  obj-$(CONFIG_PM_QOS_KUNIT_TEST) += qos-test.o
> diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
> index 922ed457db19..364ca5512b4f 100644
> --- a/drivers/base/power/power.h
> +++ b/drivers/base/power/power.h
> @@ -125,11 +125,25 @@ static inline bool device_pm_initialized(struct device *dev)
>  }
>
>  /* drivers/base/power/wakeup_stats.c */
> +#ifdef CONFIG_PM_WAKEUP_STATS_SYSFS
>  extern int wakeup_source_sysfs_add(struct device *parent,
>                                    struct wakeup_source *ws);
>  extern void wakeup_source_sysfs_remove(struct wakeup_source *ws);
>
>  extern int pm_wakeup_source_sysfs_add(struct device *parent);
> +#else /* !CONFIG_PM_WAKEUP_STATS_SYSFS */
> +static inline int wakeup_source_sysfs_add(struct device *parent,
> +                                         struct wakeup_source *ws)
> +{
> +       return 0;
> +}
> +static inline void wakeup_source_sysfs_remove(struct wakeup_source *ws) {}
> +
> +static inline int pm_wakeup_source_sysfs_add(struct device *parent)
> +{
> +       return 0;
> +}
> +#endif /* !CONFIG_PM_WAKEUP_STATS_SYSFS */
>
>  #else /* !CONFIG_PM_SLEEP */
>
> diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
> index 05337f437cca..6945083ab053 100644
> --- a/kernel/power/Kconfig
> +++ b/kernel/power/Kconfig
> @@ -202,6 +202,19 @@ config PM_WAKELOCKS_GC
>         depends on PM_WAKELOCKS
>         default y
>
> +config PM_WAKEUP_STATS_SYSFS
> +       bool "Sysfs wakeup statistics"
> +       depends on PM_SLEEP
> +       default y
> +       help
> +         Enable this for wakeup statistics in sysfs under /sys/class/wakeup/
> +
> +         Disabling this option eliminates the work of creating the wakeup
> +         sources and each of their attributes in sysfs. Depending on the
> +         number of wakeup sources, this can also have a non-negligible memory
> +         impact. Regardless of this config option's value, wakeup statistics
> +         are still available via debugfs and BPF.

Well, except that otherwise it may be hard to figure out which device
the given wakeup source belongs to, so I'd rather not do that.

> +
>  config PM_QOS_CPU_SYSTEM_WAKEUP
>         bool "User space interface for CPU system wakeup QoS"
>         depends on CPU_IDLE
> --

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 2/2] PM: Add config flag to gate sysfs wakeup_sources
  2026-03-20 16:09   ` Rafael J. Wysocki
@ 2026-03-21  0:46     ` Samuel Wu
  0 siblings, 0 replies; 8+ messages in thread
From: Samuel Wu @ 2026-03-21  0:46 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Pavel Machek, Len Brown, Greg Kroah-Hartman, Danilo Krummrich,
	andrii, memxor, bpf, kernel-team, linux-pm, driver-core,
	linux-kernel

On Fri, Mar 20, 2026 at 9:09 AM Rafael J. Wysocki <rafael@kernel.org> wrote:
>

[ ... ]

> >
> > +config PM_WAKEUP_STATS_SYSFS
> > +       bool "Sysfs wakeup statistics"
> > +       depends on PM_SLEEP
> > +       default y
> > +       help
> > +         Enable this for wakeup statistics in sysfs under /sys/class/wakeup/
> > +
> > +         Disabling this option eliminates the work of creating the wakeup
> > +         sources and each of their attributes in sysfs. Depending on the
> > +         number of wakeup sources, this can also have a non-negligible memory
> > +         impact. Regardless of this config option's value, wakeup statistics
> > +         are still available via debugfs and BPF.
>
> Well, except that otherwise it may be hard to figure out which device
> the given wakeup source belongs to, so I'd rather not do that.
>

Since the config flag defaults to yes, this wouldn't affect current
users right? And then the idea is that other users who don't need this
sysfs node can turn the flag off to save some cycles and memory.

[ ... ]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 0/2] *** Support BPF traversal of wakeup sources ***
  2026-03-20 16:00 [PATCH v1 0/2] *** Support BPF traversal of wakeup sources *** Samuel Wu
  2026-03-20 16:00 ` [PATCH v1 1/2] PM: wakeup: Add kfuncs to lock/unlock wakeup_sources Samuel Wu
  2026-03-20 16:00 ` [PATCH v1 2/2] PM: Add config flag to gate sysfs wakeup_sources Samuel Wu
@ 2026-03-21 17:51 ` Kumar Kartikeya Dwivedi
  2026-03-23 16:20   ` Samuel Wu
  2 siblings, 1 reply; 8+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2026-03-21 17:51 UTC (permalink / raw)
  To: Samuel Wu
  Cc: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, andrii, bpf, kernel-team, linux-pm, driver-core,
	linux-kernel

On Fri, 20 Mar 2026 at 17:01, Samuel Wu <wusamuel@google.com> wrote:
>
> This patchset adds requisite kfuncs for BPF programs to safely traverse
> wakeup_sources, and puts a config flag around the sysfs interface.
>
> Currently, a traversal of wakeup sources require going through
> /sys/class/wakeup/* or /d/wakeup_sources/*. The repeated syscalls to query
> sysfs is inefficient, as there can be hundreds of wakeup_sources, with each
> wakeup source also having multiple attributes. debugfs is unstable and
> insecure.
>
> Adding kfuncs to lock/unlock wakeup sources allows BPF program to safely
> traverse the wakeup sources list. The head address of wakeup_sources can
> safely be resolved through BPF helper functions or variable attributes.
>
> On a quiescent Pixel 6 traversing 150 wakeup_sources, I am seeing ~34x
> speedup (sampled 75 times in table below). For a device under load, the
> speedup is greater.
> +-------+----+----------+----------+
> |       | n  | AVG (ms) | STD (ms) |
> +-------+----+----------+----------+
> | sysfs | 75 | 44.9     | 12.6     |
> +-------+----+----------+----------+
> | BPF   | 75 | 1.3      | 0.7      |
> +-------+----+----------+----------+
>
> On the memory side, between kernfs, dentry, and kmalloc, each wakeup source
> removed from sysfs saves at least 10kB.
>
> The initial attempts for BPF traversal of wakeup_sources was with BPF
> iterators [1]. However, BPF already allows for traversing of a simple list
> with bpf_for(), and this current patchset has the added benefit of being
> ~2-3x more performant than BPF iterators.

See, it ended up being faster ;-).

That said, I didn't understand why you dropped the test. We still need
unit tests that ensure the verifier causes the bpf_ws_lock to be
released before exit, and an example program (like the one you
benchmarked with) to demonstrate usage. Both are mandatory. See
various *_fail.c files in progs/ and RUN_TESTS() macro for running
negative tests easily. I doubt we will have any wakeup_sources in the
CI environment, but the example has value nonetheless.

pw-bot: cr

>
> [1]: https://lore.kernel.org/all/20260225210820.177674-1-wusamuel@google.com/
>
> Samuel Wu (2):
>   PM: wakeup: Add kfuncs to lock/unlock wakeup_sources
>   PM: Add config flag to gate sysfs wakeup_sources
>
>  drivers/base/power/Makefile |  3 +-
>  drivers/base/power/power.h  | 14 +++++++++
>  drivers/base/power/wakeup.c | 63 +++++++++++++++++++++++++++++++++++--
>  kernel/power/Kconfig        | 13 ++++++++
>  4 files changed, 90 insertions(+), 3 deletions(-)
>
> --
> 2.53.0.959.g497ff81fa9-goog
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 1/2] PM: wakeup: Add kfuncs to lock/unlock wakeup_sources
  2026-03-20 16:00 ` [PATCH v1 1/2] PM: wakeup: Add kfuncs to lock/unlock wakeup_sources Samuel Wu
@ 2026-03-23 12:33   ` kernel test robot
  0 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2026-03-23 12:33 UTC (permalink / raw)
  To: Samuel Wu, Rafael J. Wysocki, Len Brown, Pavel Machek,
	Greg Kroah-Hartman, Danilo Krummrich
  Cc: oe-kbuild-all, andrii, memxor, bpf, Samuel Wu, kernel-team,
	linux-pm, driver-core, linux-kernel

Hi Samuel,

kernel test robot noticed the following build warnings:

[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge linus/master v7.0-rc5 next-20260320]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Samuel-Wu/PM-wakeup-Add-kfuncs-to-lock-unlock-wakeup_sources/20260323-064540
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link:    https://lore.kernel.org/r/20260320160055.4114055-2-wusamuel%40google.com
patch subject: [PATCH v1 1/2] PM: wakeup: Add kfuncs to lock/unlock wakeup_sources
config: x86_64-randconfig-121-20260323 (https://download.01.org/0day-ci/archive/20260323/202603232018.pdjbZ3eL-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.4.0-5) 12.4.0
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260323/202603232018.pdjbZ3eL-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603232018.pdjbZ3eL-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/base/power/wakeup.c:1189:32: sparse: sparse: symbol 'bpf_wakeup_sources_read_lock' was not declared. Should it be static?
>> drivers/base/power/wakeup.c:1202:18: sparse: sparse: symbol 'bpf_wakeup_sources_read_unlock' was not declared. Should it be static?

vim +/bpf_wakeup_sources_read_lock +1189 drivers/base/power/wakeup.c

  1177	
  1178	/**
  1179	 * bpf_wakeup_sources_read_lock - Acquire the SRCU lock for wakeup sources
  1180	 *
  1181	 * The underlying SRCU lock returns an integer index. However, the BPF verifier
  1182	 * requires a pointer (PTR_TO_BTF_ID) to strictly track the state of acquired
  1183	 * resources using KF_ACQUIRE and KF_RELEASE semantics. We use an opaque
  1184	 * structure pointer (struct bpf_ws_lock *) to satisfy the verifier while
  1185	 * safely encoding the integer index within the pointer address itself.
  1186	 *
  1187	 * Return: An opaque pointer encoding the SRCU lock index + 1 (to avoid NULL).
  1188	 */
> 1189	__bpf_kfunc struct bpf_ws_lock *bpf_wakeup_sources_read_lock(void)
  1190	{
  1191		return (struct bpf_ws_lock *)(long)(wakeup_sources_read_lock() + 1);
  1192	}
  1193	
  1194	/**
  1195	 * bpf_wakeup_sources_read_unlock - Release the SRCU lock for wakeup sources
  1196	 * @lock: The opaque pointer returned by bpf_wakeup_sources_read_lock()
  1197	 *
  1198	 * The BPF verifier guarantees that @lock is a valid, unreleased pointer from
  1199	 * the acquire function. We decode the pointer back into the integer SRCU index
  1200	 * by subtracting 1 and release the lock.
  1201	 */
> 1202	__bpf_kfunc void bpf_wakeup_sources_read_unlock(struct bpf_ws_lock *lock)
  1203	{
  1204		wakeup_sources_read_unlock((int)(long)lock - 1);
  1205	}
  1206	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v1 0/2] *** Support BPF traversal of wakeup sources ***
  2026-03-21 17:51 ` [PATCH v1 0/2] *** Support BPF traversal of wakeup sources *** Kumar Kartikeya Dwivedi
@ 2026-03-23 16:20   ` Samuel Wu
  0 siblings, 0 replies; 8+ messages in thread
From: Samuel Wu @ 2026-03-23 16:20 UTC (permalink / raw)
  To: Kumar Kartikeya Dwivedi
  Cc: Rafael J. Wysocki, Pavel Machek, Len Brown, Greg Kroah-Hartman,
	Danilo Krummrich, andrii, bpf, kernel-team, linux-pm, driver-core,
	linux-kernel

On Sat, Mar 21, 2026 at 10:52 AM Kumar Kartikeya Dwivedi
<memxor@gmail.com> wrote:
>

[ ... ]

> >
> > The initial attempts for BPF traversal of wakeup_sources was with BPF
> > iterators [1]. However, BPF already allows for traversing of a simple list
> > with bpf_for(), and this current patchset has the added benefit of being
> > ~2-3x more performant than BPF iterators.
>
> See, it ended up being faster ;-).

Yup, thanks for the suggestion!

>
> That said, I didn't understand why you dropped the test. We still need
> unit tests that ensure the verifier causes the bpf_ws_lock to be
> released before exit, and an example program (like the one you
> benchmarked with) to demonstrate usage. Both are mandatory. See
> various *_fail.c files in progs/ and RUN_TESTS() macro for running
> negative tests easily. I doubt we will have any wakeup_sources in the
> CI environment, but the example has value nonetheless.
>
> pw-bot: cr
>

Sounds good, in v2 I can add a test for the lock/unlock kfunc. And
thanks for the thorough feedback, let me take a look at the *_fail.c
files and test macros.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-03-23 16:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 16:00 [PATCH v1 0/2] *** Support BPF traversal of wakeup sources *** Samuel Wu
2026-03-20 16:00 ` [PATCH v1 1/2] PM: wakeup: Add kfuncs to lock/unlock wakeup_sources Samuel Wu
2026-03-23 12:33   ` kernel test robot
2026-03-20 16:00 ` [PATCH v1 2/2] PM: Add config flag to gate sysfs wakeup_sources Samuel Wu
2026-03-20 16:09   ` Rafael J. Wysocki
2026-03-21  0:46     ` Samuel Wu
2026-03-21 17:51 ` [PATCH v1 0/2] *** Support BPF traversal of wakeup sources *** Kumar Kartikeya Dwivedi
2026-03-23 16:20   ` Samuel Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox