mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
bpf: btf: Add BTF_FMODEL_SIGNED_ARG flag
s390x eBPF JIT needs to know whether a function return value is signed and which function arguments are signed, in order to generate code compliant with the s390x ABI. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Link: https://lore.kernel.org/r/20230128000650.1516334-26-iii@linux.ibm.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
0f0e5f5bd5
commit
49f67f393f
3 changed files with 29 additions and 6 deletions
|
@ -899,8 +899,12 @@ enum bpf_cgroup_storage_type {
|
|||
/* The argument is a structure. */
|
||||
#define BTF_FMODEL_STRUCT_ARG BIT(0)
|
||||
|
||||
/* The argument is signed. */
|
||||
#define BTF_FMODEL_SIGNED_ARG BIT(1)
|
||||
|
||||
struct btf_func_model {
|
||||
u8 ret_size;
|
||||
u8 ret_flags;
|
||||
u8 nr_args;
|
||||
u8 arg_size[MAX_BPF_FUNC_ARGS];
|
||||
u8 arg_flags[MAX_BPF_FUNC_ARGS];
|
||||
|
|
|
@ -236,6 +236,16 @@ static inline bool btf_type_is_small_int(const struct btf_type *t)
|
|||
return btf_type_is_int(t) && t->size <= sizeof(u64);
|
||||
}
|
||||
|
||||
static inline u8 btf_int_encoding(const struct btf_type *t)
|
||||
{
|
||||
return BTF_INT_ENCODING(*(u32 *)(t + 1));
|
||||
}
|
||||
|
||||
static inline bool btf_type_is_signed_int(const struct btf_type *t)
|
||||
{
|
||||
return btf_type_is_int(t) && (btf_int_encoding(t) & BTF_INT_SIGNED);
|
||||
}
|
||||
|
||||
static inline bool btf_type_is_enum(const struct btf_type *t)
|
||||
{
|
||||
return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM;
|
||||
|
@ -306,11 +316,6 @@ static inline u8 btf_int_offset(const struct btf_type *t)
|
|||
return BTF_INT_OFFSET(*(u32 *)(t + 1));
|
||||
}
|
||||
|
||||
static inline u8 btf_int_encoding(const struct btf_type *t)
|
||||
{
|
||||
return BTF_INT_ENCODING(*(u32 *)(t + 1));
|
||||
}
|
||||
|
||||
static inline bool btf_type_is_scalar(const struct btf_type *t)
|
||||
{
|
||||
return btf_type_is_int(t) || btf_type_is_enum(t);
|
||||
|
|
|
@ -6453,6 +6453,18 @@ static int __get_type_size(struct btf *btf, u32 btf_id,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
static u8 __get_type_fmodel_flags(const struct btf_type *t)
|
||||
{
|
||||
u8 flags = 0;
|
||||
|
||||
if (__btf_type_is_struct(t))
|
||||
flags |= BTF_FMODEL_STRUCT_ARG;
|
||||
if (btf_type_is_signed_int(t))
|
||||
flags |= BTF_FMODEL_SIGNED_ARG;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
int btf_distill_func_proto(struct bpf_verifier_log *log,
|
||||
struct btf *btf,
|
||||
const struct btf_type *func,
|
||||
|
@ -6473,6 +6485,7 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
|
|||
m->arg_flags[i] = 0;
|
||||
}
|
||||
m->ret_size = 8;
|
||||
m->ret_flags = 0;
|
||||
m->nr_args = MAX_BPF_FUNC_REG_ARGS;
|
||||
return 0;
|
||||
}
|
||||
|
@ -6492,6 +6505,7 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
|
|||
return -EINVAL;
|
||||
}
|
||||
m->ret_size = ret;
|
||||
m->ret_flags = __get_type_fmodel_flags(t);
|
||||
|
||||
for (i = 0; i < nargs; i++) {
|
||||
if (i == nargs - 1 && args[i].type == 0) {
|
||||
|
@ -6516,7 +6530,7 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
|
|||
return -EINVAL;
|
||||
}
|
||||
m->arg_size[i] = ret;
|
||||
m->arg_flags[i] = __btf_type_is_struct(t) ? BTF_FMODEL_STRUCT_ARG : 0;
|
||||
m->arg_flags[i] = __get_type_fmodel_flags(t);
|
||||
}
|
||||
m->nr_args = nargs;
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue