Re: [PATCH bpf-next v5 09/11] selftests/bpf: Add C tests for 16-byte returns in R0:R2
| Newsgroups | org.kernel.vger.bpf |
|---|---|
| Message-ID | <2435b43ae3c7dfdfac13b28256ec34050ed7a7d6b358337263b2c52003476ece@mail.kernel.org> |
> diff --git a/tools/testing/selftests/bpf/progs/aggregate_ret_struct_c.c b/tools/testing/selftests/bpf/progs/aggregate_ret_struct_c.c
> new file mode 100644
> index 000000000000..83b1a3751988
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/aggregate_ret_struct_c.c
[ ... ]
> +struct pair {
> + __u64 hi; /* R0 */
> + __u64 lo; /* R2 */
> +};
> +
> +union upair {
> + __u64 halves[2];
> + struct {
> + __u64 lo; /* R0 */
> + __u64 hi; /* R2 */
> + } parts;
> +};
This isn't a bug, but struct pair puts hi in R0 while union upair's
parts puts lo in R0 - was the inverted naming in the union deliberate,
or would matching the struct's order (or first/second) make the R0:R2
mapping easier to follow?
> +
> +static __noinline struct pair make_pair(__u64 a, __u64 b)
> +{
> + struct pair p = { .hi = a + b, .lo = a - b };
> +
> + return p;
> +}
> +
> +SEC("tc")
> +__load_if_JITed()
> +__success __retval(0)
> +int aggregate_ret_struct_c_test(struct __sk_buff *skb)
> +{
> + __u64 a = skb->len ^ MIX_A;
> + __u64 b = skb->len ^ MIX_B;
> + struct pair p;
> +
> + p = make_pair(a, b);
> + if (p.hi != a + b)
> + return 1;
> + if (p.lo != a - b)
> + return 2;
> +
> + return 0;
> +}
[ ... ]
> +static __noinline union upair make_upair(__u64 a, __u64 b)
> +{
> + union upair p;
> +
> + p.halves[0] = a + b;
> + p.halves[1] = a - b;
> + return p;
> +}
> +
> +SEC("tc")
> +__load_if_JITed()
> +__success __retval(0)
> +int aggregate_ret_union_c_test(struct __sk_buff *skb)
> +{
> + __u64 a = skb->len ^ MIX_A;
> + __u64 b = skb->len ^ MIX_B;
> + union upair p;
> +
> + p = make_upair(a, b);
> + if (p.parts.lo != a + b)
> + return 1;
> + if (p.parts.hi != a - b)
> + return 2;
> +
> + return 0;
> +}
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31740414277