[PATCH bpf-next 0/5] bpf: Add bpf_rcu_read_lock() support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently, without rcu attribute info in BTF, the verifier treats
rcu tagged pointer as a normal pointer. This might be a problem
for sleepable program where rcu_read_lock()/unlock() is not available.
For example, for a sleepable fentry program, if rcu protected memory
access is interleaved with a sleepable helper/kfunc, it is possible
the memory access after the sleepable helper/kfunc might be invalid
since the object might have been freed then. Even without
a sleepable helper/kfunc, without rcu_read_lock() protection,
it is possible that the rcu protected object might be release
in the middle of bpf program execution which may cause incorrect
result.

To prevent above cases, enable btf_type_tag("rcu") attributes,
introduce new bpf_rcu_read_lock/unlock() helpers and add verifier support.
In the rest of patch set, Patch 1 enabled btf_type_tag for __rcu
attribute. Patch 2 added new bpf_rcu_read_lock/unlock() helpers.
Patch 3 added verifier support and Patch 4 enabled sleepable
program support for cgrp local storage. Patch 5 added some tests
for new helpers and verifier support.

Yonghong Song (5):
  compiler_types: Define __rcu as __attribute__((btf_type_tag("rcu")))
  bpf: Add bpf_rcu_read_lock/unlock helper
  bpf: Add rcu btf_type_tag verifier support
  bpf: Enable sleeptable support for cgrp local storage
  selftests/bpf: Add tests for bpf_rcu_read_lock()

 include/linux/bpf.h                           |   5 +
 include/linux/bpf_verifier.h                  |   1 +
 include/linux/compiler_types.h                |   3 +-
 include/uapi/linux/bpf.h                      |  14 +
 kernel/bpf/btf.c                              |  11 +
 kernel/bpf/core.c                             |   2 +
 kernel/bpf/helpers.c                          |  26 ++
 kernel/bpf/verifier.c                         | 129 +++++++++-
 tools/include/uapi/linux/bpf.h                |  14 +
 .../selftests/bpf/prog_tests/rcu_read_lock.c  | 101 ++++++++
 .../selftests/bpf/progs/rcu_read_lock.c       | 241 ++++++++++++++++++
 11 files changed, 537 insertions(+), 10 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/rcu_read_lock.c
 create mode 100644 tools/testing/selftests/bpf/progs/rcu_read_lock.c

-- 
2.30.2





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux