All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/5] Make struct bpf_cpumask RCU safe
@ 2023-03-16  5:40 David Vernet
  2023-03-16  5:40 ` [PATCH bpf-next v2 1/5] bpf: Free struct bpf_cpumask in call_rcu handler David Vernet
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: David Vernet @ 2023-03-16  5:40 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, linux-kernel, kernel-team

The struct bpf_cpumask type is currently not RCU safe. It uses the
bpf_mem_cache_{alloc,free}() APIs to allocate and release cpumasks, and
those allocations may be reused before an RCU grace period has elapsed.
We want to be able to enable using this pattern in BPF programs:

private(MASK) static struct bpf_cpumask __kptr *global;

int BPF_PROG(prog, ...)
{
	struct bpf_cpumask *cpumask;

	bpf_rcu_read_lock();
	cpumask = global;
	if (!cpumask) {
		bpf_rcu_read_unlock();
		return -1;
	}
	bpf_cpumask_setall(cpumask);
	...
	bpf_rcu_read_unlock();
}

In other words, to be able to pass a kptr to KF_RCU bpf_cpumask kfuncs
without requiring the acquisition and release of refcounts using
bpf_cpumask_kptr_get(). This patchset enables this by making the struct
bpf_cpumask type RCU safe, and removing the bpf_cpumask_kptr_get()
function.

---
v1: https://lore.kernel.org/all/20230316014122.678082-2-void@manifault.com/

Changelog:
----------
v1 -> v2:
- Add doxygen comment for new @rcu field in struct bpf_cpumask.

David Vernet (5):
  bpf: Free struct bpf_cpumask in call_rcu handler
  bpf: Mark struct bpf_cpumask as rcu protected
  bpf/selftests: Test using global cpumask kptr with RCU
  bpf: Remove bpf_cpumask_kptr_get() kfunc
  bpf,docs: Remove bpf_cpumask_kptr_get() from documentation

 Documentation/bpf/cpumasks.rst                | 30 +++-----
 kernel/bpf/cpumask.c                          | 38 +++--------
 kernel/bpf/verifier.c                         |  1 +
 .../selftests/bpf/prog_tests/cpumask.c        |  2 +-
 .../selftests/bpf/progs/cpumask_common.h      |  7 +-
 .../selftests/bpf/progs/cpumask_failure.c     | 68 +++++++++++++++----
 .../selftests/bpf/progs/cpumask_success.c     | 29 ++++----
 7 files changed, 96 insertions(+), 79 deletions(-)

-- 
2.39.0

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

end of thread, other threads:[~2023-03-16 19:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16  5:40 [PATCH bpf-next v2 0/5] Make struct bpf_cpumask RCU safe David Vernet
2023-03-16  5:40 ` [PATCH bpf-next v2 1/5] bpf: Free struct bpf_cpumask in call_rcu handler David Vernet
2023-03-16  5:40 ` [PATCH bpf-next v2 2/5] bpf: Mark struct bpf_cpumask as rcu protected David Vernet
2023-03-16  5:40 ` [PATCH bpf-next v2 3/5] bpf/selftests: Test using global cpumask kptr with RCU David Vernet
2023-03-16  5:40 ` [PATCH bpf-next v2 4/5] bpf: Remove bpf_cpumask_kptr_get() kfunc David Vernet
2023-03-16  5:40 ` [PATCH bpf-next v2 5/5] bpf,docs: Remove bpf_cpumask_kptr_get() from documentation David Vernet
2023-03-16 19:40 ` [PATCH bpf-next v2 0/5] Make struct bpf_cpumask RCU safe patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.