Skip to content

Commit 49f67f3

Browse files
iii-iAlexei Starovoitov
authored andcommitted
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>
1 parent 0f0e5f5 commit 49f67f3

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

include/linux/bpf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,12 @@ enum bpf_cgroup_storage_type {
899899
/* The argument is a structure. */
900900
#define BTF_FMODEL_STRUCT_ARG BIT(0)
901901

902+
/* The argument is signed. */
903+
#define BTF_FMODEL_SIGNED_ARG BIT(1)
904+
902905
struct btf_func_model {
903906
u8 ret_size;
907+
u8 ret_flags;
904908
u8 nr_args;
905909
u8 arg_size[MAX_BPF_FUNC_ARGS];
906910
u8 arg_flags[MAX_BPF_FUNC_ARGS];

include/linux/btf.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ static inline bool btf_type_is_small_int(const struct btf_type *t)
236236
return btf_type_is_int(t) && t->size <= sizeof(u64);
237237
}
238238

239+
static inline u8 btf_int_encoding(const struct btf_type *t)
240+
{
241+
return BTF_INT_ENCODING(*(u32 *)(t + 1));
242+
}
243+
244+
static inline bool btf_type_is_signed_int(const struct btf_type *t)
245+
{
246+
return btf_type_is_int(t) && (btf_int_encoding(t) & BTF_INT_SIGNED);
247+
}
248+
239249
static inline bool btf_type_is_enum(const struct btf_type *t)
240250
{
241251
return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM;
@@ -306,11 +316,6 @@ static inline u8 btf_int_offset(const struct btf_type *t)
306316
return BTF_INT_OFFSET(*(u32 *)(t + 1));
307317
}
308318

309-
static inline u8 btf_int_encoding(const struct btf_type *t)
310-
{
311-
return BTF_INT_ENCODING(*(u32 *)(t + 1));
312-
}
313-
314319
static inline bool btf_type_is_scalar(const struct btf_type *t)
315320
{
316321
return btf_type_is_int(t) || btf_type_is_enum(t);

kernel/bpf/btf.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6453,6 +6453,18 @@ static int __get_type_size(struct btf *btf, u32 btf_id,
64536453
return -EINVAL;
64546454
}
64556455

6456+
static u8 __get_type_fmodel_flags(const struct btf_type *t)
6457+
{
6458+
u8 flags = 0;
6459+
6460+
if (__btf_type_is_struct(t))
6461+
flags |= BTF_FMODEL_STRUCT_ARG;
6462+
if (btf_type_is_signed_int(t))
6463+
flags |= BTF_FMODEL_SIGNED_ARG;
6464+
6465+
return flags;
6466+
}
6467+
64566468
int btf_distill_func_proto(struct bpf_verifier_log *log,
64576469
struct btf *btf,
64586470
const struct btf_type *func,
@@ -6473,6 +6485,7 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
64736485
m->arg_flags[i] = 0;
64746486
}
64756487
m->ret_size = 8;
6488+
m->ret_flags = 0;
64766489
m->nr_args = MAX_BPF_FUNC_REG_ARGS;
64776490
return 0;
64786491
}
@@ -6492,6 +6505,7 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
64926505
return -EINVAL;
64936506
}
64946507
m->ret_size = ret;
6508+
m->ret_flags = __get_type_fmodel_flags(t);
64956509

64966510
for (i = 0; i < nargs; i++) {
64976511
if (i == nargs - 1 && args[i].type == 0) {
@@ -6516,7 +6530,7 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
65166530
return -EINVAL;
65176531
}
65186532
m->arg_size[i] = ret;
6519-
m->arg_flags[i] = __btf_type_is_struct(t) ? BTF_FMODEL_STRUCT_ARG : 0;
6533+
m->arg_flags[i] = __get_type_fmodel_flags(t);
65206534
}
65216535
m->nr_args = nargs;
65226536
return 0;

0 commit comments

Comments
 (0)