Skip to content

Commit 12d4309

Browse files
committed
Merge branch 'bpf-persistent'
Daniel Borkmann says: ==================== BPF updates This set adds support for persistent maps/progs. Please see individual patches for further details. A man-page update to bpf(2) will be sent later on, also a iproute2 patch for support in tc. v1 -> v2: - Reworked most of patch 4 and 5 - Rebased to latest net-next ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 1d6119b + 42984d7 commit 12d4309

File tree

12 files changed

+683
-72
lines changed

12 files changed

+683
-72
lines changed

include/linux/bpf.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,18 @@ struct bpf_prog *bpf_prog_get(u32 ufd);
167167
void bpf_prog_put(struct bpf_prog *prog);
168168
void bpf_prog_put_rcu(struct bpf_prog *prog);
169169

170-
struct bpf_map *bpf_map_get(struct fd f);
170+
struct bpf_map *bpf_map_get(u32 ufd);
171+
struct bpf_map *__bpf_map_get(struct fd f);
171172
void bpf_map_put(struct bpf_map *map);
172173

173174
extern int sysctl_unprivileged_bpf_disabled;
174175

176+
int bpf_map_new_fd(struct bpf_map *map);
177+
int bpf_prog_new_fd(struct bpf_prog *prog);
178+
179+
int bpf_obj_pin_user(u32 ufd, const char __user *pathname);
180+
int bpf_obj_get_user(const char __user *pathname);
181+
175182
/* verify correctness of eBPF program */
176183
int bpf_check(struct bpf_prog **fp, union bpf_attr *attr);
177184
#else

include/uapi/linux/bpf.h

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,50 +63,16 @@ struct bpf_insn {
6363
__s32 imm; /* signed immediate constant */
6464
};
6565

66-
/* BPF syscall commands */
66+
/* BPF syscall commands, see bpf(2) man-page for details. */
6767
enum bpf_cmd {
68-
/* create a map with given type and attributes
69-
* fd = bpf(BPF_MAP_CREATE, union bpf_attr *, u32 size)
70-
* returns fd or negative error
71-
* map is deleted when fd is closed
72-
*/
7368
BPF_MAP_CREATE,
74-
75-
/* lookup key in a given map
76-
* err = bpf(BPF_MAP_LOOKUP_ELEM, union bpf_attr *attr, u32 size)
77-
* Using attr->map_fd, attr->key, attr->value
78-
* returns zero and stores found elem into value
79-
* or negative error
80-
*/
8169
BPF_MAP_LOOKUP_ELEM,
82-
83-
/* create or update key/value pair in a given map
84-
* err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size)
85-
* Using attr->map_fd, attr->key, attr->value, attr->flags
86-
* returns zero or negative error
87-
*/
8870
BPF_MAP_UPDATE_ELEM,
89-
90-
/* find and delete elem by key in a given map
91-
* err = bpf(BPF_MAP_DELETE_ELEM, union bpf_attr *attr, u32 size)
92-
* Using attr->map_fd, attr->key
93-
* returns zero or negative error
94-
*/
9571
BPF_MAP_DELETE_ELEM,
96-
97-
/* lookup key in a given map and return next key
98-
* err = bpf(BPF_MAP_GET_NEXT_KEY, union bpf_attr *attr, u32 size)
99-
* Using attr->map_fd, attr->key, attr->next_key
100-
* returns zero and stores next key or negative error
101-
*/
10272
BPF_MAP_GET_NEXT_KEY,
103-
104-
/* verify and load eBPF program
105-
* prog_fd = bpf(BPF_PROG_LOAD, union bpf_attr *attr, u32 size)
106-
* Using attr->prog_type, attr->insns, attr->license
107-
* returns fd or negative error
108-
*/
10973
BPF_PROG_LOAD,
74+
BPF_OBJ_PIN,
75+
BPF_OBJ_GET,
11076
};
11177

11278
enum bpf_map_type {
@@ -160,6 +126,11 @@ union bpf_attr {
160126
__aligned_u64 log_buf; /* user supplied buffer */
161127
__u32 kern_version; /* checked when prog_type=kprobe */
162128
};
129+
130+
struct { /* anonymous struct used by BPF_OBJ_* commands */
131+
__aligned_u64 pathname;
132+
__u32 bpf_fd;
133+
};
163134
} __attribute__((aligned(8)));
164135

165136
/* integer value in 'imm' field of BPF_CALL instruction selects which helper

include/uapi/linux/magic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@
7575
#define ANON_INODE_FS_MAGIC 0x09041934
7676
#define BTRFS_TEST_MAGIC 0x73727279
7777
#define NSFS_MAGIC 0x6e736673
78+
#define BPF_FS_MAGIC 0xcafe4a11
7879

7980
#endif /* __LINUX_MAGIC_H__ */

kernel/bpf/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
obj-y := core.o
2-
obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o hashtab.o arraymap.o helpers.o
2+
3+
obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o
4+
obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o

kernel/bpf/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
9292

9393
fp->pages = size / PAGE_SIZE;
9494
fp->aux = aux;
95+
fp->aux->prog = fp;
9596

9697
return fp;
9798
}
@@ -116,6 +117,7 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
116117

117118
memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE);
118119
fp->pages = size / PAGE_SIZE;
120+
fp->aux->prog = fp;
119121

120122
/* We keep fp->aux from fp_old around in the new
121123
* reallocated structure.
@@ -726,7 +728,6 @@ void bpf_prog_free(struct bpf_prog *fp)
726728
struct bpf_prog_aux *aux = fp->aux;
727729

728730
INIT_WORK(&aux->work, bpf_prog_free_deferred);
729-
aux->prog = fp;
730731
schedule_work(&aux->work);
731732
}
732733
EXPORT_SYMBOL_GPL(bpf_prog_free);

0 commit comments

Comments
 (0)