diff options
| author | Thomas Zimmermann <[email protected]> | 2024-03-13 08:43:21 +0000 |
|---|---|---|
| committer | Thomas Zimmermann <[email protected]> | 2024-03-13 08:43:21 +0000 |
| commit | a2e7496b453eaa577425858d6f8b854800ed7343 (patch) | |
| tree | 35d05023d51161a28768a29115c8e03e65599fe5 /tools/testing/selftests/bpf/prog_tests/read_vsyscall.c | |
| parent | nouveau/dmem: handle kcalloc() allocation failure (diff) | |
| parent | nouveau: lock the client object tree. (diff) | |
| download | kernel-a2e7496b453eaa577425858d6f8b854800ed7343.tar.gz kernel-a2e7496b453eaa577425858d6f8b854800ed7343.zip | |
Merge drm/drm-fixes into drm-misc-fixes
Backmerging to sync before merging the patchset at [1].
[1] https://lore.kernel.org/all/[email protected]/
Signed-off-by: Thomas Zimmermann <[email protected]>
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/read_vsyscall.c')
| -rw-r--r-- | tools/testing/selftests/bpf/prog_tests/read_vsyscall.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/read_vsyscall.c b/tools/testing/selftests/bpf/prog_tests/read_vsyscall.c new file mode 100644 index 000000000000..3405923fe4e6 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/read_vsyscall.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2024. Huawei Technologies Co., Ltd */ +#include "test_progs.h" +#include "read_vsyscall.skel.h" + +#if defined(__x86_64__) +/* For VSYSCALL_ADDR */ +#include <asm/vsyscall.h> +#else +/* To prevent build failure on non-x86 arch */ +#define VSYSCALL_ADDR 0UL +#endif + +struct read_ret_desc { + const char *name; + int ret; +} all_read[] = { + { .name = "probe_read_kernel", .ret = -ERANGE }, + { .name = "probe_read_kernel_str", .ret = -ERANGE }, + { .name = "probe_read", .ret = -ERANGE }, + { .name = "probe_read_str", .ret = -ERANGE }, + { .name = "probe_read_user", .ret = -EFAULT }, + { .name = "probe_read_user_str", .ret = -EFAULT }, + { .name = "copy_from_user", .ret = -EFAULT }, + { .name = "copy_from_user_task", .ret = -EFAULT }, +}; + +void test_read_vsyscall(void) +{ + struct read_vsyscall *skel; + unsigned int i; + int err; + +#if !defined(__x86_64__) + test__skip(); + return; +#endif + skel = read_vsyscall__open_and_load(); + if (!ASSERT_OK_PTR(skel, "read_vsyscall open_load")) + return; + + skel->bss->target_pid = getpid(); + err = read_vsyscall__attach(skel); + if (!ASSERT_EQ(err, 0, "read_vsyscall attach")) + goto out; + + /* userspace may don't have vsyscall page due to LEGACY_VSYSCALL_NONE, + * but it doesn't affect the returned error codes. + */ + skel->bss->user_ptr = (void *)VSYSCALL_ADDR; + usleep(1); + + for (i = 0; i < ARRAY_SIZE(all_read); i++) + ASSERT_EQ(skel->bss->read_ret[i], all_read[i].ret, all_read[i].name); +out: + read_vsyscall__destroy(skel); +} |
