提交 2c7e541c 编写于 作者: A Alexei Starovoitov 提交者: Zheng Zengkai

bpf: Rename btf_member accessors.

mainline inclusion
from mainline-5.17-rc1
commit 8293eb99
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8293eb995f349aed28006792cad4cb48091919dd

-------------------------------------------------

Rename btf_member_bit_offset() and btf_member_bitfield_size() to
avoid conflicts with similarly named helpers in libbpf's btf.h.
Rename the kernel helpers, since libbpf helpers are part of uapi.
Suggested-by: NAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Acked-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211201181040.23337-3-alexei.starovoitov@gmail.com
(cherry picked from commit 8293eb99)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>

Conflicts:
	net/ipv4/bpf_tcp_ca.c
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 9891acee
...@@ -192,15 +192,15 @@ static inline bool btf_type_kflag(const struct btf_type *t) ...@@ -192,15 +192,15 @@ static inline bool btf_type_kflag(const struct btf_type *t)
return BTF_INFO_KFLAG(t->info); return BTF_INFO_KFLAG(t->info);
} }
static inline u32 btf_member_bit_offset(const struct btf_type *struct_type, static inline u32 __btf_member_bit_offset(const struct btf_type *struct_type,
const struct btf_member *member) const struct btf_member *member)
{ {
return btf_type_kflag(struct_type) ? BTF_MEMBER_BIT_OFFSET(member->offset) return btf_type_kflag(struct_type) ? BTF_MEMBER_BIT_OFFSET(member->offset)
: member->offset; : member->offset;
} }
static inline u32 btf_member_bitfield_size(const struct btf_type *struct_type, static inline u32 __btf_member_bitfield_size(const struct btf_type *struct_type,
const struct btf_member *member) const struct btf_member *member)
{ {
return btf_type_kflag(struct_type) ? BTF_MEMBER_BITFIELD_SIZE(member->offset) return btf_type_kflag(struct_type) ? BTF_MEMBER_BITFIELD_SIZE(member->offset)
: 0; : 0;
......
...@@ -161,7 +161,7 @@ void bpf_struct_ops_init(struct btf *btf, struct bpf_verifier_log *log) ...@@ -161,7 +161,7 @@ void bpf_struct_ops_init(struct btf *btf, struct bpf_verifier_log *log)
break; break;
} }
if (btf_member_bitfield_size(t, member)) { if (__btf_member_bitfield_size(t, member)) {
pr_warn("bit field member %s in struct %s is not supported\n", pr_warn("bit field member %s in struct %s is not supported\n",
mname, st_ops->name); mname, st_ops->name);
break; break;
...@@ -292,7 +292,7 @@ static int check_zero_holes(const struct btf_type *t, void *data) ...@@ -292,7 +292,7 @@ static int check_zero_holes(const struct btf_type *t, void *data)
const struct btf_type *mtype; const struct btf_type *mtype;
for_each_member(i, t, member) { for_each_member(i, t, member) {
moff = btf_member_bit_offset(t, member) / 8; moff = __btf_member_bit_offset(t, member) / 8;
if (moff > prev_mend && if (moff > prev_mend &&
memchr_inv(data + prev_mend, 0, moff - prev_mend)) memchr_inv(data + prev_mend, 0, moff - prev_mend))
return -EINVAL; return -EINVAL;
...@@ -369,7 +369,7 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key, ...@@ -369,7 +369,7 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
u32 moff; u32 moff;
u32 flags; u32 flags;
moff = btf_member_bit_offset(t, member) / 8; moff = __btf_member_bit_offset(t, member) / 8;
ptype = btf_type_resolve_ptr(btf_vmlinux, member->type, NULL); ptype = btf_type_resolve_ptr(btf_vmlinux, member->type, NULL);
if (ptype == module_type) { if (ptype == module_type) {
if (*(void **)(udata + moff)) if (*(void **)(udata + moff))
......
...@@ -2967,7 +2967,7 @@ static s32 btf_struct_check_meta(struct btf_verifier_env *env, ...@@ -2967,7 +2967,7 @@ static s32 btf_struct_check_meta(struct btf_verifier_env *env,
return -EINVAL; return -EINVAL;
} }
offset = btf_member_bit_offset(t, member); offset = __btf_member_bit_offset(t, member);
if (is_union && offset) { if (is_union && offset) {
btf_verifier_log_member(env, t, member, btf_verifier_log_member(env, t, member,
"Invalid member bits_offset"); "Invalid member bits_offset");
...@@ -3099,7 +3099,7 @@ int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t) ...@@ -3099,7 +3099,7 @@ int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t)
if (off != -ENOENT) if (off != -ENOENT)
/* only one 'struct bpf_spin_lock' is allowed */ /* only one 'struct bpf_spin_lock' is allowed */
return -E2BIG; return -E2BIG;
off = btf_member_bit_offset(t, member); off = __btf_member_bit_offset(t, member);
if (off % 8) if (off % 8)
/* valid C code cannot generate such BTF */ /* valid C code cannot generate such BTF */
return -EINVAL; return -EINVAL;
...@@ -3133,8 +3133,8 @@ static void __btf_struct_show(const struct btf *btf, const struct btf_type *t, ...@@ -3133,8 +3133,8 @@ static void __btf_struct_show(const struct btf *btf, const struct btf_type *t,
btf_show_start_member(show, member); btf_show_start_member(show, member);
member_offset = btf_member_bit_offset(t, member); member_offset = __btf_member_bit_offset(t, member);
bitfield_size = btf_member_bitfield_size(t, member); bitfield_size = __btf_member_bitfield_size(t, member);
bytes_offset = BITS_ROUNDDOWN_BYTES(member_offset); bytes_offset = BITS_ROUNDDOWN_BYTES(member_offset);
bits8_offset = BITS_PER_BYTE_MASKED(member_offset); bits8_offset = BITS_PER_BYTE_MASKED(member_offset);
if (bitfield_size) { if (bitfield_size) {
...@@ -4935,7 +4935,7 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf, ...@@ -4935,7 +4935,7 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,
if (array_elem->nelems != 0) if (array_elem->nelems != 0)
goto error; goto error;
moff = btf_member_bit_offset(t, member) / 8; moff = __btf_member_bit_offset(t, member) / 8;
if (off < moff) if (off < moff)
goto error; goto error;
...@@ -4958,14 +4958,14 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf, ...@@ -4958,14 +4958,14 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,
for_each_member(i, t, member) { for_each_member(i, t, member) {
/* offset of the field in bytes */ /* offset of the field in bytes */
moff = btf_member_bit_offset(t, member) / 8; moff = __btf_member_bit_offset(t, member) / 8;
if (off + size <= moff) if (off + size <= moff)
/* won't find anything, field is already too far */ /* won't find anything, field is already too far */
break; break;
if (btf_member_bitfield_size(t, member)) { if (__btf_member_bitfield_size(t, member)) {
u32 end_bit = btf_member_bit_offset(t, member) + u32 end_bit = __btf_member_bit_offset(t, member) +
btf_member_bitfield_size(t, member); __btf_member_bitfield_size(t, member);
/* off <= moff instead of off == moff because clang /* off <= moff instead of off == moff because clang
* does not generate a BTF member for anonymous * does not generate a BTF member for anonymous
......
...@@ -196,7 +196,7 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t, ...@@ -196,7 +196,7 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t,
utcp_ca = (const struct tcp_congestion_ops *)udata; utcp_ca = (const struct tcp_congestion_ops *)udata;
tcp_ca = (struct tcp_congestion_ops *)kdata; tcp_ca = (struct tcp_congestion_ops *)kdata;
moff = btf_member_bit_offset(t, member) / 8; moff = __btf_member_bit_offset(t, member) / 8;
switch (moff) { switch (moff) {
case offsetof(struct tcp_congestion_ops, flags): case offsetof(struct tcp_congestion_ops, flags):
if (utcp_ca->flags & ~TCP_CONG_MASK) if (utcp_ca->flags & ~TCP_CONG_MASK)
...@@ -226,7 +226,7 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t, ...@@ -226,7 +226,7 @@ static int bpf_tcp_ca_init_member(const struct btf_type *t,
static int bpf_tcp_ca_check_member(const struct btf_type *t, static int bpf_tcp_ca_check_member(const struct btf_type *t,
const struct btf_member *member) const struct btf_member *member)
{ {
if (is_unsupported(btf_member_bit_offset(t, member) / 8)) if (is_unsupported(__btf_member_bit_offset(t, member) / 8))
return -ENOTSUPP; return -ENOTSUPP;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册