BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>,
	Alan Maguire <alan.maguire@oracle.com>
Subject: Re: [PATCH bpf-next v2 1/2] selftests/bpf: Fix task_local_data failure with 64K page
Date: Thu, 22 Jan 2026 16:23:56 -0800	[thread overview]
Message-ID: <e72cf753-0661-4619-95fe-f2a77ae42c1d@linux.dev> (raw)
In-Reply-To: <CAMB2axMiOHCw3p6WFhF14JbKY98OKpa2SjjPRkpcN=T7a5bnjw@mail.gmail.com>



On 1/22/26 3:47 PM, Amery Hung wrote:
> On Thu, Jan 22, 2026 at 2:58 PM Yonghong Song <yonghong.song@linux.dev> wrote:
>>
>>
>> On 1/22/26 1:49 PM, Amery Hung wrote:
>>> On Thu, Jan 22, 2026 at 8:54 AM Yonghong Song <yonghong.song@linux.dev> wrote:
>>>> On arm64 systems with 64K pages, the selftest task_local_data has the following
>>>> failures:
>>>>     ...
>>>>     test_task_local_data_basic:PASS:tld_create_key 0 nsec
>>>>     test_task_local_data_basic:FAIL:tld_create_key unexpected tld_create_key: actual 0 != expected -28
>>>>     ...
>>>>     test_task_local_data_basic_thread:PASS:run task_main 0 nsec
>>>>     test_task_local_data_basic_thread:FAIL:task_main retval unexpected error: 2 (errno 0)
>>>>     test_task_local_data_basic_thread:FAIL:tld_get_data value0 unexpected tld_get_data value0: actual 0 != expected 6268
>>>>     ...
>>>>     #447/1   task_local_data/task_local_data_basic:FAIL
>>>>     ...
>>>>     #447/2   task_local_data/task_local_data_race:FAIL
>>>>     #447     task_local_data:FAIL
>>>>
>>>> When TLD_DYN_DATA_SIZE is 64K page size, for
>>>>     struct tld_meta_u {
>>>>          _Atomic __u8 cnt;
>>>>          __u16 size;
>>>>           struct tld_metadata metadata[];
>>>>     };
>>>> fields 'cnt' and 'size' would overflow. For example,
>>>> for 4K page, 'cnt' will be 4096/64 = 64. But for 64K page,
>>>> 'cnt' will be 65536/64 = 1024 and 'cnt' is not enough for 1024.
>>>> For field 'size', it is okay for value 4K, but it is not enough
>>>> for 64K as maximum 'size' value is '64K - 1'.
>>>>
>>>> To accommodate 64K page, '_Atomic __u8 cnt' becomes '_Atomic __u16 cnt'
>>>> and '__u16 size' becomes '__u32 size'. A few other places are adjusted
>>>> accordingly.
>>>>
>>>> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
>>>> Tested-by: Alan Maguire <alan.maguire@oracle.com>
>>>> Cc: Amery Hung <ameryhung@gmail.com>
>>>> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
>>>> ---
>>>>    tools/testing/selftests/bpf/prog_tests/task_local_data.h    | 6 +++---
>>>>    .../testing/selftests/bpf/prog_tests/test_task_local_data.c | 2 +-
>>>>    tools/testing/selftests/bpf/progs/task_local_data.bpf.h     | 4 ++--
>>>>    3 files changed, 6 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/tools/testing/selftests/bpf/prog_tests/task_local_data.h b/tools/testing/selftests/bpf/prog_tests/task_local_data.h
>>>> index 2de38776a2d4..4c38f9a7bc90 100644
>>>> --- a/tools/testing/selftests/bpf/prog_tests/task_local_data.h
>>>> +++ b/tools/testing/selftests/bpf/prog_tests/task_local_data.h
>>>> @@ -94,8 +94,8 @@ struct tld_metadata {
>>>>    };
>>>>
>>>>    struct tld_meta_u {
>>>> -       _Atomic __u8 cnt;
>>>> -       __u16 size;
>>>> +       _Atomic __u16 cnt;
>>>> +       __u32 size;
>>> Agree cnt should be __u16.
>>>
>>> size can remain to be __u16 as maximum data size is page_size - 8
>>> byte. The 8 byte is tld_data_u->start recording thread-specific offset
>>> of data in a page.
>> In test_task_local_data.c, I made the change like below
>>      #define TLD_DYN_DATA_SIZE getpagesize()
>> so TLD_DYN_DATA_SIZE will be 64K for 64K page.
>>
>> In function __tld_init_meta_p(), we have
>>     meta->size = TLD_DYN_DATA_SIZE;
>>
>> So size needs to be 32 bit in order to hold the value 0x10000.
>>
>> Are you saying
>>       #define TLD_DYN_DATA_SIZE getpagesize()
>> is not correct?
>> The previous one is
>>       #define TLD_DYN_DATA_SIZE 4096
>> for 4K page system. For 64K, I naturally tried
>> to replace the above 4096 with getpagesize().
>> Did I miss anything?
> It should be getpagesize() - 8 to be more precise, but that does not
> matter to the user.
>
> We currently do not do a sanity check on TLD_DYN_DATA_SIZE, but the
> check in __tld_create_key() will make sure data cannot exceed
> page_size - 8 byte:
>
> if (off + TLD_ROUND_UP(size, 8) > TLD_PAGE_SIZE - sizeof(struct tld_data_u))
>          return (tld_key_t){-E2BIG};
>
> TLD_DYN_DATA_SIZE in the common use case should be small or even zero
> if all tld is known at compile time (i.e., declared with
> TLD_DEFINE_KEY) to avoid memory wastage.

So TLD_DYN_DATA_SIZE should at most be
TLD_PAGE_SIZE - sizeof(struct tld_data_u).

Okay, I will make a change to
    #define TLD_DYN_DATA_SIZE (getpagesize() - 8)
and restore the original type for field 'size'.

>
>>>>           struct tld_metadata metadata[];
>>>>    };
>>>>
>>>> @@ -217,7 +217,7 @@ static int __tld_init_data_p(int map_fd)
>>>>    static tld_key_t __tld_create_key(const char *name, size_t size, bool dyn_data)
>>>>    {
>>>>           int err, i, sz, off = 0;
>>>> -       __u8 cnt;
>>>> +       __u16 cnt;
>>>>
>>>>           if (!TLD_READ_ONCE(tld_meta_p)) {
>>>>                   err = __tld_init_meta_p();
>>>> diff --git a/tools/testing/selftests/bpf/prog_tests/test_task_local_data.c b/tools/testing/selftests/bpf/prog_tests/test_task_local_data.c
>>>> index 9fd6306b455c..cc4d49222d9d 100644
>>>> --- a/tools/testing/selftests/bpf/prog_tests/test_task_local_data.c
>>>> +++ b/tools/testing/selftests/bpf/prog_tests/test_task_local_data.c
>>>> @@ -4,7 +4,7 @@
>>>>    #include <test_progs.h>
>>>>
>>>>    #define TLD_FREE_DATA_ON_THREAD_EXIT
>>>> -#define TLD_DYN_DATA_SIZE 4096
>>>> +#define TLD_DYN_DATA_SIZE getpagesize()
>>>>    #include "task_local_data.h"
>>>>
>>>>    struct test_tld_struct {
>>>> diff --git a/tools/testing/selftests/bpf/progs/task_local_data.bpf.h b/tools/testing/selftests/bpf/progs/task_local_data.bpf.h
>>>> index 432fff2af844..e13f239b46b0 100644
>>>> --- a/tools/testing/selftests/bpf/progs/task_local_data.bpf.h
>>>> +++ b/tools/testing/selftests/bpf/progs/task_local_data.bpf.h
>>>> @@ -80,8 +80,8 @@ struct tld_metadata {
>>>>    };
>>>>
>>>>    struct tld_meta_u {
>>>> -       __u8 cnt;
>>>> -       __u16 size;
>>>> +       __u16 cnt;
>>>> +       __u32 size;
>>> Same here. We can keep __u16 size.

Same here. Will keep the original '__u16 size'.

>>>
>>>>           struct tld_metadata metadata[TLD_MAX_DATA_CNT];
>>>>    };
>>>>
>>>> --
>>>> 2.47.3
>>>>
>>>>


      reply	other threads:[~2026-01-23  0:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-22 16:26 [PATCH bpf-next v2 1/2] selftests/bpf: Fix task_local_data failure with 64K page Yonghong Song
2026-01-22 16:26 ` [PATCH bpf-next v2 2/2] selftests/bpf: Fix xdp_pull_data " Yonghong Song
2026-01-22 21:18   ` Amery Hung
2026-01-22 21:28     ` Yonghong Song
2026-01-22 21:38     ` Yonghong Song
2026-01-22 21:53       ` Amery Hung
2026-01-22 21:49 ` [PATCH bpf-next v2 1/2] selftests/bpf: Fix task_local_data " Amery Hung
2026-01-22 22:58   ` Yonghong Song
2026-01-22 23:34     ` Alexei Starovoitov
2026-01-22 23:47     ` Amery Hung
2026-01-23  0:23       ` Yonghong Song [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=e72cf753-0661-4619-95fe-f2a77ae42c1d@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=alan.maguire@oracle.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox