mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
Test basic operations of task local data with valid and invalid
tld_create_key().
For invalid calls, make sure they return the right error code and check
that the TLDs are not inserted by running tld_get_data("
value_not_exists") on the bpf side. The call should a null pointer.
For valid calls, first make sure the TLDs are created by calling
tld_get_data() on the bpf side. The call should return a valid pointer.
Finally, verify that the TLDs are indeed task-specific (i.e., their
addresses do not overlap) with multiple user threads. This done by
writing values unique to each thread, reading them from both user space
and bpf, and checking if the value read back matches the value written.
Signed-off-by: Amery Hung <ameryhung@gmail.com>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>
Link: https://lore.kernel.org/r/20250730185903.3574598-4-ameryhung@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
66 lines
1.2 KiB
C
66 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <vmlinux.h>
|
|
#include <errno.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
#include "task_local_data.bpf.h"
|
|
|
|
struct tld_keys {
|
|
tld_key_t value0;
|
|
tld_key_t value1;
|
|
tld_key_t value2;
|
|
tld_key_t value_not_exist;
|
|
};
|
|
|
|
struct test_tld_struct {
|
|
__u64 a;
|
|
__u64 b;
|
|
__u64 c;
|
|
__u64 d;
|
|
};
|
|
|
|
int test_value0;
|
|
int test_value1;
|
|
struct test_tld_struct test_value2;
|
|
|
|
SEC("syscall")
|
|
int task_main(void *ctx)
|
|
{
|
|
struct tld_object tld_obj;
|
|
struct test_tld_struct *struct_p;
|
|
struct task_struct *task;
|
|
int err, *int_p;
|
|
|
|
task = bpf_get_current_task_btf();
|
|
err = tld_object_init(task, &tld_obj);
|
|
if (err)
|
|
return 1;
|
|
|
|
int_p = tld_get_data(&tld_obj, value0, "value0", sizeof(int));
|
|
if (int_p)
|
|
test_value0 = *int_p;
|
|
else
|
|
return 2;
|
|
|
|
int_p = tld_get_data(&tld_obj, value1, "value1", sizeof(int));
|
|
if (int_p)
|
|
test_value1 = *int_p;
|
|
else
|
|
return 3;
|
|
|
|
struct_p = tld_get_data(&tld_obj, value2, "value2", sizeof(struct test_tld_struct));
|
|
if (struct_p)
|
|
test_value2 = *struct_p;
|
|
else
|
|
return 4;
|
|
|
|
int_p = tld_get_data(&tld_obj, value_not_exist, "value_not_exist", sizeof(int));
|
|
if (int_p)
|
|
return 5;
|
|
|
|
return 0;
|
|
}
|
|
|
|
char _license[] SEC("license") = "GPL";
|