Skip to content

workqueue: introduce BPF iterators for workqueues, worker pools and pending work - #8523

Open
kernel-patches-daemon-bpf-rc[bot] wants to merge 6 commits into
bpf-next_basefrom
series/1135671=>bpf-next
Open

workqueue: introduce BPF iterators for workqueues, worker pools and pending work#8523
kernel-patches-daemon-bpf-rc[bot] wants to merge 6 commits into
bpf-next_basefrom
series/1135671=>bpf-next

Conversation

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown

Pull request for series with
subject: workqueue: introduce BPF iterators for workqueues, worker pools and pending work
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: fdec474
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: fdec474
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: fdec474
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 2659f94
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 863f3dd
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: f0e80de
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 682b1c1
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 28e911d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 8f876c7
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 7d008cd
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 8c7f55d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 41c129f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 2b1f9f6
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: e1d9b82
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 51476f6
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: 8b365b3
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

…ues list

Add bpf_iter_workqueue_{new,next,destroy} kfuncs so BPF programs can walk
every workqueue on the global workqueues list.

The workqueues list is RCU-protected for reads and each workqueue_struct
is freed via call_rcu(), so the iterator is KF_RCU_PROTECTED i.e. the
caller must hold bpf_rcu_read_lock() across new()..destroy(), which keeps
the list and each returned wq alive between next() calls.

The kfuncs live in kernel/workqueue.c because struct workqueue_struct's
list anchor and the workqueues root are local to this file.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
Add a 'workqueue' BPF iterator target (bpftool-iter / pinnable) that
reuses the open-coded bpf_iter_workqueue_next().

Since the open-coded next() is KF_RCU_PROTECTED, the seq path supplies the
RCU section: seq_start() takes rcu_read_lock() and holds it across the read
chunk, so the returned workq and the cursor stay alive while the program
runs and next() steps; position is re-derived from *pos on each start, so
the cursor is never dereferenced across the RCU gap between chunks.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
Add bpf_iter_worker_pool_{new,next,destroy} kfuncs so BPF programs can
walk every worker_pool in the system via worker_pool_idr, in ascending
pool-id order.
This mirrors the pool enumeration in the drgn tools/workqueue/wq_dump.py
script.

The idr walk (idr_get_next) runs as kernel C, so no BPF-side idr support
is needed. worker_pool_idr is RCU-readable and each worker_pool is freed
via call_rcu(), so the iterator is KF_RCU_PROTECTED, like the workqueue
iterator: the caller holds bpf_rcu_read_lock() across new()..destroy().

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
Add a 'worker_pool' BPF iterator target, backed by the open-coded
bpf_iter_worker_pool_next() via a shared union, using the same
RCU-per-chunk scheme as the workqueue seq iterator.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
Add a seq_file BPF iterator ("workqueue_pending_work") that walks the
pending work items of every worker_pool. Unlike the workqueue and
worker_pool iterators this is deliberately not open-coded because
pool->worklist is protected by pool->lock and struct work_struct has
neither a refcount nor RCU-freeing, so a pending work cannot be kept alive
for a suspended open-coded iterator.

Instead, for each pool a bounded snapshot of its pending works (pool id,
work address, work function) is copied out while pool->lock is held and
the BPF program runs over the stable snapshot with no lock held.
worker_pool(s) are visited in worker_pool_idr order.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
Cover both the open-coded and seq_file forms of the workqueue and
worker_pool iterators, plus the pending-work seq iterator:

 - count_workqueues / count_worker_pools drive the open-coded iterators
   (inside bpf_rcu_read_lock()); userspace checks the counts are non-zero.
 - dump_workqueues / dump_worker_pools attach the seq forms and drain
   them, exercising the RCU-per-chunk seq path that reuses the open-coded
   next().
 - dump_pending attaches the workqueue_pending_work seq iterator and
   drains it, exercising the per-pool snapshot path.
 - wq_iter_fail.c checks the verifier rejects the RCU-protected
   open-coded iterators when used outside an RCU critical section.

Also declare the open-coded iterator kfuncs in bpf_experimental.h.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
@kernel-patches-daemon-bpf-rc

Copy link
Copy Markdown
Author

Upstream branch: d114bb9
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1135671
version: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant