Skip to content

Commit 4682f10

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf-next/master' into for-next
Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 872a38d + 0768e98 commit 4682f10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+752
-357
lines changed

arch/arm64/net/bpf_jit_comp.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,11 +2240,6 @@ static int calc_arg_aux(const struct btf_func_model *m,
22402240

22412241
/* the rest arguments are passed through stack */
22422242
for (; i < m->nr_args; i++) {
2243-
/* We can not know for sure about exact alignment needs for
2244-
* struct passed on stack, so deny those
2245-
*/
2246-
if (m->arg_flags[i] & BTF_FMODEL_STRUCT_ARG)
2247-
return -ENOTSUPP;
22482243
stack_slots = (m->arg_size[i] + 7) / 8;
22492244
a->bstack_for_args += stack_slots * 8;
22502245
a->ostack_for_args = a->ostack_for_args + stack_slots * 8;

drivers/net/netkit.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ struct netkit {
3232
struct netkit_link {
3333
struct bpf_link link;
3434
struct net_device *dev;
35-
u32 location;
3635
};
3736

3837
static __always_inline int
@@ -733,8 +732,8 @@ static void netkit_link_fdinfo(const struct bpf_link *link, struct seq_file *seq
733732

734733
seq_printf(seq, "ifindex:\t%u\n", ifindex);
735734
seq_printf(seq, "attach_type:\t%u (%s)\n",
736-
nkl->location,
737-
nkl->location == BPF_NETKIT_PRIMARY ? "primary" : "peer");
735+
link->attach_type,
736+
link->attach_type == BPF_NETKIT_PRIMARY ? "primary" : "peer");
738737
}
739738

740739
static int netkit_link_fill_info(const struct bpf_link *link,
@@ -749,7 +748,7 @@ static int netkit_link_fill_info(const struct bpf_link *link,
749748
rtnl_unlock();
750749

751750
info->netkit.ifindex = ifindex;
752-
info->netkit.attach_type = nkl->location;
751+
info->netkit.attach_type = link->attach_type;
753752
return 0;
754753
}
755754

@@ -775,8 +774,7 @@ static int netkit_link_init(struct netkit_link *nkl,
775774
struct bpf_prog *prog)
776775
{
777776
bpf_link_init(&nkl->link, BPF_LINK_TYPE_NETKIT,
778-
&netkit_link_lops, prog);
779-
nkl->location = attr->link_create.attach_type;
777+
&netkit_link_lops, prog, attr->link_create.attach_type);
780778
nkl->dev = dev;
781779
return bpf_link_prime(&nkl->link, link_primer);
782780
}

include/linux/bpf-cgroup.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ struct bpf_cgroup_storage {
103103
struct bpf_cgroup_link {
104104
struct bpf_link link;
105105
struct cgroup *cgroup;
106-
enum bpf_attach_type type;
107106
};
108107

109108
struct bpf_prog_list {

include/linux/bpf.h

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,19 +1729,22 @@ struct bpf_link {
17291729
enum bpf_link_type type;
17301730
const struct bpf_link_ops *ops;
17311731
struct bpf_prog *prog;
1732-
/* whether BPF link itself has "sleepable" semantics, which can differ
1733-
* from underlying BPF program having a "sleepable" semantics, as BPF
1734-
* link's semantics is determined by target attach hook
1735-
*/
1736-
bool sleepable;
1732+
17371733
u32 flags;
1734+
enum bpf_attach_type attach_type;
1735+
17381736
/* rcu is used before freeing, work can be used to schedule that
17391737
* RCU-based freeing before that, so they never overlap
17401738
*/
17411739
union {
17421740
struct rcu_head rcu;
17431741
struct work_struct work;
17441742
};
1743+
/* whether BPF link itself has "sleepable" semantics, which can differ
1744+
* from underlying BPF program having a "sleepable" semantics, as BPF
1745+
* link's semantics is determined by target attach hook
1746+
*/
1747+
bool sleepable;
17451748
};
17461749

17471750
struct bpf_link_ops {
@@ -1781,7 +1784,6 @@ struct bpf_shim_tramp_link {
17811784

17821785
struct bpf_tracing_link {
17831786
struct bpf_tramp_link link;
1784-
enum bpf_attach_type attach_type;
17851787
struct bpf_trampoline *trampoline;
17861788
struct bpf_prog *tgt_prog;
17871789
};
@@ -2034,11 +2036,13 @@ int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog,
20342036

20352037
#if defined(CONFIG_CGROUP_BPF) && defined(CONFIG_BPF_LSM)
20362038
int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog,
2037-
int cgroup_atype);
2039+
int cgroup_atype,
2040+
enum bpf_attach_type attach_type);
20382041
void bpf_trampoline_unlink_cgroup_shim(struct bpf_prog *prog);
20392042
#else
20402043
static inline int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog,
2041-
int cgroup_atype)
2044+
int cgroup_atype,
2045+
enum bpf_attach_type attach_type)
20422046
{
20432047
return -EOPNOTSUPP;
20442048
}
@@ -2350,6 +2354,7 @@ extern const struct super_operations bpf_super_ops;
23502354
extern const struct file_operations bpf_map_fops;
23512355
extern const struct file_operations bpf_prog_fops;
23522356
extern const struct file_operations bpf_iter_fops;
2357+
extern const struct file_operations bpf_token_fops;
23532358

23542359
#define BPF_PROG_TYPE(_id, _name, prog_ctx_type, kern_ctx_type) \
23552360
extern const struct bpf_prog_ops _name ## _prog_ops; \
@@ -2528,10 +2533,11 @@ int bpf_map_new_fd(struct bpf_map *map, int flags);
25282533
int bpf_prog_new_fd(struct bpf_prog *prog);
25292534

25302535
void bpf_link_init(struct bpf_link *link, enum bpf_link_type type,
2531-
const struct bpf_link_ops *ops, struct bpf_prog *prog);
2536+
const struct bpf_link_ops *ops, struct bpf_prog *prog,
2537+
enum bpf_attach_type attach_type);
25322538
void bpf_link_init_sleepable(struct bpf_link *link, enum bpf_link_type type,
25332539
const struct bpf_link_ops *ops, struct bpf_prog *prog,
2534-
bool sleepable);
2540+
enum bpf_attach_type attach_type, bool sleepable);
25352541
int bpf_link_prime(struct bpf_link *link, struct bpf_link_primer *primer);
25362542
int bpf_link_settle(struct bpf_link_primer *primer);
25372543
void bpf_link_cleanup(struct bpf_link_primer *primer);
@@ -2546,6 +2552,9 @@ void bpf_token_inc(struct bpf_token *token);
25462552
void bpf_token_put(struct bpf_token *token);
25472553
int bpf_token_create(union bpf_attr *attr);
25482554
struct bpf_token *bpf_token_get_from_fd(u32 ufd);
2555+
int bpf_token_get_info_by_fd(struct bpf_token *token,
2556+
const union bpf_attr *attr,
2557+
union bpf_attr __user *uattr);
25492558

25502559
bool bpf_token_allow_cmd(const struct bpf_token *token, enum bpf_cmd cmd);
25512560
bool bpf_token_allow_map_type(const struct bpf_token *token, enum bpf_map_type type);
@@ -2883,13 +2892,13 @@ bpf_prog_inc_not_zero(struct bpf_prog *prog)
28832892

28842893
static inline void bpf_link_init(struct bpf_link *link, enum bpf_link_type type,
28852894
const struct bpf_link_ops *ops,
2886-
struct bpf_prog *prog)
2895+
struct bpf_prog *prog, enum bpf_attach_type attach_type)
28872896
{
28882897
}
28892898

28902899
static inline void bpf_link_init_sleepable(struct bpf_link *link, enum bpf_link_type type,
28912900
const struct bpf_link_ops *ops, struct bpf_prog *prog,
2892-
bool sleepable)
2901+
enum bpf_attach_type attach_type, bool sleepable)
28932902
{
28942903
}
28952904

@@ -2944,6 +2953,13 @@ static inline struct bpf_token *bpf_token_get_from_fd(u32 ufd)
29442953
return ERR_PTR(-EOPNOTSUPP);
29452954
}
29462955

2956+
static inline int bpf_token_get_info_by_fd(struct bpf_token *token,
2957+
const union bpf_attr *attr,
2958+
union bpf_attr __user *uattr)
2959+
{
2960+
return -EOPNOTSUPP;
2961+
}
2962+
29472963
static inline void __dev_flush(struct list_head *flush_list)
29482964
{
29492965
}

include/net/tcx.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct tcx_entry {
2020
struct tcx_link {
2121
struct bpf_link link;
2222
struct net_device *dev;
23-
u32 location;
2423
};
2524

2625
static inline void tcx_set_ingress(struct sk_buff *skb, bool ingress)

include/uapi/linux/bpf.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ union bpf_iter_link_info {
450450
* * **struct bpf_map_info**
451451
* * **struct bpf_btf_info**
452452
* * **struct bpf_link_info**
453+
* * **struct bpf_token_info**
453454
*
454455
* Return
455456
* Returns zero on success. On error, -1 is returned and *errno*
@@ -6803,6 +6804,13 @@ struct bpf_link_info {
68036804
};
68046805
} __attribute__((aligned(8)));
68056806

6807+
struct bpf_token_info {
6808+
__u64 allowed_cmds;
6809+
__u64 allowed_maps;
6810+
__u64 allowed_progs;
6811+
__u64 allowed_attachs;
6812+
} __attribute__((aligned(8)));
6813+
68066814
/* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
68076815
* by user and intended to be used by socket (e.g. to bind to, depends on
68086816
* attach type).

kernel/bpf/arena.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,34 @@ static void arena_free_pages(struct bpf_arena *arena, long uaddr, long page_cnt)
550550
}
551551
}
552552

553+
/*
554+
* Reserve an arena virtual address range without populating it. This call stops
555+
* bpf_arena_alloc_pages from adding pages to this range.
556+
*/
557+
static int arena_reserve_pages(struct bpf_arena *arena, long uaddr, u32 page_cnt)
558+
{
559+
long page_cnt_max = (arena->user_vm_end - arena->user_vm_start) >> PAGE_SHIFT;
560+
long pgoff;
561+
int ret;
562+
563+
if (uaddr & ~PAGE_MASK)
564+
return 0;
565+
566+
pgoff = compute_pgoff(arena, uaddr);
567+
if (pgoff + page_cnt > page_cnt_max)
568+
return -EINVAL;
569+
570+
guard(mutex)(&arena->lock);
571+
572+
/* Cannot guard already allocated pages. */
573+
ret = is_range_tree_set(&arena->rt, pgoff, page_cnt);
574+
if (ret)
575+
return -EBUSY;
576+
577+
/* "Allocate" the region to prevent it from being allocated. */
578+
return range_tree_clear(&arena->rt, pgoff, page_cnt);
579+
}
580+
553581
__bpf_kfunc_start_defs();
554582

555583
__bpf_kfunc void *bpf_arena_alloc_pages(void *p__map, void *addr__ign, u32 page_cnt,
@@ -573,11 +601,26 @@ __bpf_kfunc void bpf_arena_free_pages(void *p__map, void *ptr__ign, u32 page_cnt
573601
return;
574602
arena_free_pages(arena, (long)ptr__ign, page_cnt);
575603
}
604+
605+
__bpf_kfunc int bpf_arena_reserve_pages(void *p__map, void *ptr__ign, u32 page_cnt)
606+
{
607+
struct bpf_map *map = p__map;
608+
struct bpf_arena *arena = container_of(map, struct bpf_arena, map);
609+
610+
if (map->map_type != BPF_MAP_TYPE_ARENA)
611+
return -EINVAL;
612+
613+
if (!page_cnt)
614+
return 0;
615+
616+
return arena_reserve_pages(arena, (long)ptr__ign, page_cnt);
617+
}
576618
__bpf_kfunc_end_defs();
577619

578620
BTF_KFUNCS_START(arena_kfuncs)
579621
BTF_ID_FLAGS(func, bpf_arena_alloc_pages, KF_TRUSTED_ARGS | KF_SLEEPABLE | KF_ARENA_RET | KF_ARENA_ARG2)
580622
BTF_ID_FLAGS(func, bpf_arena_free_pages, KF_TRUSTED_ARGS | KF_SLEEPABLE | KF_ARENA_ARG2)
623+
BTF_ID_FLAGS(func, bpf_arena_reserve_pages, KF_TRUSTED_ARGS | KF_SLEEPABLE | KF_ARENA_ARG2)
581624
BTF_KFUNCS_END(arena_kfuncs)
582625

583626
static const struct btf_kfunc_id_set common_kfunc_set = {

kernel/bpf/bpf_iter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ int bpf_iter_link_attach(const union bpf_attr *attr, bpfptr_t uattr,
552552
if (!link)
553553
return -ENOMEM;
554554

555-
bpf_link_init(&link->link, BPF_LINK_TYPE_ITER, &bpf_iter_link_lops, prog);
555+
bpf_link_init(&link->link, BPF_LINK_TYPE_ITER, &bpf_iter_link_lops, prog,
556+
attr->link_create.attach_type);
556557
link->tinfo = tinfo;
557558

558559
err = bpf_link_prime(&link->link, &link_primer);

kernel/bpf/bpf_struct_ops.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
808808
goto reset_unlock;
809809
}
810810
bpf_link_init(&link->link, BPF_LINK_TYPE_STRUCT_OPS,
811-
&bpf_struct_ops_link_lops, prog);
811+
&bpf_struct_ops_link_lops, prog, prog->expected_attach_type);
812812
*plink++ = &link->link;
813813

814814
ksym = kzalloc(sizeof(*ksym), GFP_USER);
@@ -1351,7 +1351,8 @@ int bpf_struct_ops_link_create(union bpf_attr *attr)
13511351
err = -ENOMEM;
13521352
goto err_out;
13531353
}
1354-
bpf_link_init(&link->link, BPF_LINK_TYPE_STRUCT_OPS, &bpf_struct_ops_map_lops, NULL);
1354+
bpf_link_init(&link->link, BPF_LINK_TYPE_STRUCT_OPS, &bpf_struct_ops_map_lops, NULL,
1355+
attr->link_create.attach_type);
13551356

13561357
err = bpf_link_prime(&link->link, &link_primer);
13571358
if (err)

kernel/bpf/btf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6200,8 +6200,7 @@ int get_kern_ctx_btf_id(struct bpf_verifier_log *log, enum bpf_prog_type prog_ty
62006200
return kctx_type_id;
62016201
}
62026202

6203-
BTF_ID_LIST(bpf_ctx_convert_btf_id)
6204-
BTF_ID(struct, bpf_ctx_convert)
6203+
BTF_ID_LIST_SINGLE(bpf_ctx_convert_btf_id, struct, bpf_ctx_convert)
62056204

62066205
static struct btf *btf_parse_base(struct btf_verifier_env *env, const char *name,
62076206
void *data, unsigned int data_size)

0 commit comments

Comments
 (0)