History

bpf: Introduce opaque bpf_refcount struct and add btf_record plumbing

A 'struct bpf_refcount' is added to the set of opaque uapi/bpf.h types meant for use in BPF programs. Similarly to other opaque types like bpf_spin_lock and bpf_rbtree_node, the verifier needs to know where in user-defined struct types a bpf_refcount can be located, so necessary btf_record plumbing is added to enable this. bpf_refcount is sized to hold a refcount_t. Similarly to bpf_spin_lock, the offset of a bpf_refcount is cached in btf_record as refcount_off in addition to being in the field array. Caching refcount_off makes sense for this field because further patches in the series will modify functions that take local kptrs (e.g. bpf_obj_drop) to change their behavior if the type they're operating on is refcounted. So enabling fast "is this type refcounted?" checks is desirable. No such verifier behavior changes are introduced in this patch, just logic to recognize 'struct bpf_refcount' in btf_record.

Dave Marchevsky committed 3 years ago

Commit d54730b1 parent cd2a8075 files · +32 −2Browse files

Showing the changes to include/uapi (1 of 5 files). Show all

Unified · Split

include/uapi/linux/bpf.h+4−0
@@ -6985,6 +6985,10 @@ struct bpf_rb_node { · 6984 unmodified lines
69856985 __u64 :64;
69866986 } __attribute__((aligned(8)));
69876987
6988+struct bpf_refcount {
6989+ __u32 :32;
6990+} __attribute__((aligned(4)));
6991+
69886992 struct bpf_sysctl {
69896993 __u32 write; /* Sysctl is being read (= 0) or written (= 1).
69906994 * Allows 1,2,4-byte read, but no write.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t