All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jose E. Marchesi" <jemarch@gnu.org>
To: Vineet Gupta <vineet.gupta@linux.dev>
Cc: Hari Bathini <hbathini@linux.ibm.com>,
	 Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	 Eduard <eddyz87@gmail.com>,  bpf <bpf@vger.kernel.org>,
	 Alexei Starovoitov <ast@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Shuah Khan <shuah@kernel.org>,
	 "open list:KERNEL SELFTEST FRAMEWORK"
	<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH] selftests/bpf: improve test coverage for kfunc call
Date: Wed, 11 Mar 2026 23:05:37 +0100	[thread overview]
Message-ID: <87pl5af2dq.fsf@gnu.org> (raw)
In-Reply-To: <bc410b38-f5ab-47cf-a434-fa4f43751921@linux.dev>


> On 3/11/26 11:03 AM, Hari Bathini wrote:
>>
>> On 11/03/26 9:32 pm, Alexei Starovoitov wrote:
>>> On Wed, Mar 11, 2026 at 8:10 AM Hari Bathini
>>> <hbathini@linux.ibm.com> wrote:
>>>>
>>>>>
>>>>>> +
>>>>>> +       /* Check zero-extension */
>>>>>> +       if (val != (unsigned long)a)
>>>>>> +               return 1;
>>>>>> +       /* Check no sign-extension */
>>>>>> +       if (val < 0)
>>>>>> +               return 2;
>>>>>> +
>>>>>> +       val = b;
>>>>>> +       if (val != (unsigned long)b)
>>>>>> +               return 3;
>>>>>> +       if (val < 0)
>>>>>> +               return 4;
>>>>>> +
>>>>>> +       val = c;
>>>>>> +       if (val != (unsigned long)c)
>>>>>> +               return 5;
>>>>>> +       if (val < 0)
>>>>>> +               return 6;
>>>>>> +
>>>>>> +       return 0;
>>>>>> +}
>>>>>
>>>>> Overall this looks very useful.
>>>>> I would expand with another test where a,b,c are s8,s16,s32.
>>>>
>>>> Slightly different approach but kfunc_call_test4/bpf_kfunc_call_test4
>>>> cover signed arguments already?
>>>
>>> Ahh. Then may be tweak it to adopt similar fine grained
>>> error reporting as your bpf_kfunc_call_test5()
>>
>> I Prefer this.
>>
>> Does the below change to bpf_kfunc_call_test4 look fine:
>>
>> diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
>> b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
>> index 48dcaf93bb9f..6237c2222633 100644
>> --- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
>> +++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
>> @@ -760,8 +760,30 @@ __bpf_kfunc struct sock
>> *bpf_kfunc_call_test3(struct sock *sk)
>>
>>  __bpf_kfunc long noinline bpf_kfunc_call_test4(signed char a, short
>> b, int c, long d)
>
> I might regret for bringing this up as it could be yet another ABI
> fiasco between gcc and llvm.

char is signed in BPF in both compilers, matching x86.

> As per C standard, sign of unadorned char (i.e. w/o explicit signed or
> unsigned prefix) is ABI defined.
> For gcc-bpf char is specified to be signed.
> So test4 has s8, while new test5 has u8. Would it make sense to have
> an additional test without signed/unsigned annotation for char ?
> This will flag any discrepancy between the two compilers.
>
> Thx,
> -Vineet
>
>>  {
>> +       /*
>> +        * Make val as volatile to avoid compiler optimizations.
>> +        * Verify that negative signed values remain negative after
>> +        * sign-extension (JIT must sign-extend, not zero-extend).
>> +        */
>> +       volatile long val;
>> +
>> +       /* val will be positive, if JIT does zero-extension instead
>> of sign-extension */
>> +       val = a;
>> +       if (val >= 0)
>> +               return 1;
>> +
>> +       val = b;
>> +       if (val >= 0)
>> +               return 2;
>> +
>> +       val = c;
>> +       if (val >= 0)
>> +               return 3;
>> +
>>         /* Provoke the compiler to assume that the caller has
>> sign-extended a,
>>          * b and c on platforms where this is required (e.g. s390x).
>> +        *
>> +        * Original behavior: return sum for backward compatibility
>>          */
>>         return (long)a + (long)b + (long)c + d;
>>  }
>>
>>
>> - Hari

      reply	other threads:[~2026-03-11 22:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03 13:14 [PATCH] selftests/bpf: improve test coverage for kfunc call Hari Bathini
2026-03-09 17:07 ` Alexei Starovoitov
2026-03-11 15:10   ` Hari Bathini
2026-03-11 16:02     ` Alexei Starovoitov
2026-03-11 18:03       ` Hari Bathini
2026-03-11 20:11         ` Alexei Starovoitov
2026-03-11 21:42         ` Vineet Gupta
2026-03-11 22:05           ` Jose E. Marchesi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pl5af2dq.fsf@gnu.org \
    --to=jemarch@gnu.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=hbathini@linux.ibm.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=vineet.gupta@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.