Commit 80215095 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'linux-kselftest-next-5.12-rc1' of...

Merge tag 'linux-kselftest-next-5.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull Kselftest updates from Shuah Khan:

 - dmabuf-heaps test fixes and cleanups from John Stultz

 - seccomp test fix to accept any valid fd in user_notification_addfd

 - Minor fixes to breakpoints and vDSO tests

 - Minor code cleanups to ipc and x86 tests

* tag 'linux-kselftest-next-5.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests/seccomp: Accept any valid fd in user_notification_addfd
  selftests/timens: add futex binary to .gitignore
  selftests: breakpoints: Use correct error messages in breakpoint_test_arm64.c
  selftests/vDSO: fix ABI selftest on riscv
  selftests/x86/ldt_gdt: remove unneeded semicolon
  selftests/ipc: remove unneeded semicolon
  kselftests: dmabuf-heaps: Add extra checking that allocated buffers are zeroed
  kselftests: dmabuf-heaps: Cleanup test output
  kselftests: dmabuf-heaps: Softly fail if don't find a vgem device
  kselftests: dmabuf-heaps: Add clearer checks on DMABUF_BEGIN/END_SYNC
  kselftests: dmabuf-heaps: Fix Makefile's inclusion of the kernel's usr/include dir
parents 0e63a5c6 e0c0840a
...@@ -145,7 +145,7 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp) ...@@ -145,7 +145,7 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) { if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
ksft_print_msg( ksft_print_msg(
"ptrace(PTRACE_SINGLESTEP) failed: %s\n", "ptrace(PTRACE_CONT) failed: %s\n",
strerror(errno)); strerror(errno));
return false; return false;
} }
...@@ -159,7 +159,7 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp) ...@@ -159,7 +159,7 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
} }
alarm(0); alarm(0);
if (WIFEXITED(status)) { if (WIFEXITED(status)) {
ksft_print_msg("child did not single-step\n"); ksft_print_msg("child exited prematurely\n");
return false; return false;
} }
if (!WIFSTOPPED(status)) { if (!WIFSTOPPED(status)) {
......
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
CFLAGS += -static -O3 -Wl,-no-as-needed -Wall -I../../../../usr/include CFLAGS += -static -O3 -Wl,-no-as-needed -Wall
TEST_GEN_PROGS = dmabuf-heap TEST_GEN_PROGS = dmabuf-heap
......
...@@ -130,16 +130,13 @@ static int dmabuf_heap_alloc(int fd, size_t len, unsigned int flags, ...@@ -130,16 +130,13 @@ static int dmabuf_heap_alloc(int fd, size_t len, unsigned int flags,
dmabuf_fd); dmabuf_fd);
} }
static void dmabuf_sync(int fd, int start_stop) static int dmabuf_sync(int fd, int start_stop)
{ {
struct dma_buf_sync sync = { struct dma_buf_sync sync = {
.flags = start_stop | DMA_BUF_SYNC_RW, .flags = start_stop | DMA_BUF_SYNC_RW,
}; };
int ret;
ret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync); return ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
if (ret)
printf("sync failed %d\n", errno);
} }
#define ONE_MEG (1024 * 1024) #define ONE_MEG (1024 * 1024)
...@@ -151,16 +148,14 @@ static int test_alloc_and_import(char *heap_name) ...@@ -151,16 +148,14 @@ static int test_alloc_and_import(char *heap_name)
void *p = NULL; void *p = NULL;
int ret; int ret;
printf("Testing heap: %s\n", heap_name);
heap_fd = dmabuf_heap_open(heap_name); heap_fd = dmabuf_heap_open(heap_name);
if (heap_fd < 0) if (heap_fd < 0)
return -1; return -1;
printf("Allocating 1 MEG\n"); printf(" Testing allocation and importing: ");
ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0, &dmabuf_fd); ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0, &dmabuf_fd);
if (ret) { if (ret) {
printf("Allocation Failed!\n"); printf("FAIL (Allocation Failed!)\n");
ret = -1; ret = -1;
goto out; goto out;
} }
...@@ -172,11 +167,10 @@ static int test_alloc_and_import(char *heap_name) ...@@ -172,11 +167,10 @@ static int test_alloc_and_import(char *heap_name)
dmabuf_fd, dmabuf_fd,
0); 0);
if (p == MAP_FAILED) { if (p == MAP_FAILED) {
printf("mmap() failed: %m\n"); printf("FAIL (mmap() failed)\n");
ret = -1; ret = -1;
goto out; goto out;
} }
printf("mmap passed\n");
dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START); dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
memset(p, 1, ONE_MEG / 2); memset(p, 1, ONE_MEG / 2);
...@@ -186,25 +180,31 @@ static int test_alloc_and_import(char *heap_name) ...@@ -186,25 +180,31 @@ static int test_alloc_and_import(char *heap_name)
importer_fd = open_vgem(); importer_fd = open_vgem();
if (importer_fd < 0) { if (importer_fd < 0) {
ret = importer_fd; ret = importer_fd;
printf("Failed to open vgem\n"); printf("(Could not open vgem - skipping): ");
goto out; } else {
ret = import_vgem_fd(importer_fd, dmabuf_fd, &handle);
if (ret < 0) {
printf("FAIL (Failed to import buffer)\n");
goto out;
}
} }
ret = import_vgem_fd(importer_fd, dmabuf_fd, &handle); ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
if (ret < 0) { if (ret < 0) {
printf("Failed to import buffer\n"); printf("FAIL (DMA_BUF_SYNC_START failed!)\n");
goto out; goto out;
} }
printf("import passed\n");
dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
memset(p, 0xff, ONE_MEG); memset(p, 0xff, ONE_MEG);
dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END); ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END);
printf("syncs passed\n"); if (ret < 0) {
printf("FAIL (DMA_BUF_SYNC_END failed!)\n");
goto out;
}
close_handle(importer_fd, handle); close_handle(importer_fd, handle);
ret = 0; ret = 0;
printf(" OK\n");
out: out:
if (p) if (p)
munmap(p, ONE_MEG); munmap(p, ONE_MEG);
...@@ -218,6 +218,84 @@ static int test_alloc_and_import(char *heap_name) ...@@ -218,6 +218,84 @@ static int test_alloc_and_import(char *heap_name)
return ret; return ret;
} }
static int test_alloc_zeroed(char *heap_name, size_t size)
{
int heap_fd = -1, dmabuf_fd[32];
int i, j, ret;
void *p = NULL;
char *c;
printf(" Testing alloced %ldk buffers are zeroed: ", size / 1024);
heap_fd = dmabuf_heap_open(heap_name);
if (heap_fd < 0)
return -1;
/* Allocate and fill a bunch of buffers */
for (i = 0; i < 32; i++) {
ret = dmabuf_heap_alloc(heap_fd, size, 0, &dmabuf_fd[i]);
if (ret < 0) {
printf("FAIL (Allocation (%i) failed)\n", i);
goto out;
}
/* mmap and fill with simple pattern */
p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf_fd[i], 0);
if (p == MAP_FAILED) {
printf("FAIL (mmap() failed!)\n");
ret = -1;
goto out;
}
dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_START);
memset(p, 0xff, size);
dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_END);
munmap(p, size);
}
/* close them all */
for (i = 0; i < 32; i++)
close(dmabuf_fd[i]);
/* Allocate and validate all buffers are zeroed */
for (i = 0; i < 32; i++) {
ret = dmabuf_heap_alloc(heap_fd, size, 0, &dmabuf_fd[i]);
if (ret < 0) {
printf("FAIL (Allocation (%i) failed)\n", i);
goto out;
}
/* mmap and validate everything is zero */
p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, dmabuf_fd[i], 0);
if (p == MAP_FAILED) {
printf("FAIL (mmap() failed!)\n");
ret = -1;
goto out;
}
dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_START);
c = (char *)p;
for (j = 0; j < size; j++) {
if (c[j] != 0) {
printf("FAIL (Allocated buffer not zeroed @ %i)\n", j);
break;
}
}
dmabuf_sync(dmabuf_fd[i], DMA_BUF_SYNC_END);
munmap(p, size);
}
/* close them all */
for (i = 0; i < 32; i++)
close(dmabuf_fd[i]);
close(heap_fd);
printf("OK\n");
return 0;
out:
while (i > 0) {
close(dmabuf_fd[i]);
i--;
}
close(heap_fd);
return ret;
}
/* Test the ioctl version compatibility w/ a smaller structure then expected */ /* Test the ioctl version compatibility w/ a smaller structure then expected */
static int dmabuf_heap_alloc_older(int fd, size_t len, unsigned int flags, static int dmabuf_heap_alloc_older(int fd, size_t len, unsigned int flags,
int *dmabuf_fd) int *dmabuf_fd)
...@@ -292,23 +370,24 @@ static int test_alloc_compat(char *heap_name) ...@@ -292,23 +370,24 @@ static int test_alloc_compat(char *heap_name)
if (heap_fd < 0) if (heap_fd < 0)
return -1; return -1;
printf("Testing (theoretical)older alloc compat\n"); printf(" Testing (theoretical)older alloc compat: ");
ret = dmabuf_heap_alloc_older(heap_fd, ONE_MEG, 0, &dmabuf_fd); ret = dmabuf_heap_alloc_older(heap_fd, ONE_MEG, 0, &dmabuf_fd);
if (ret) { if (ret) {
printf("Older compat allocation failed!\n"); printf("FAIL (Older compat allocation failed!)\n");
ret = -1; ret = -1;
goto out; goto out;
} }
close(dmabuf_fd); close(dmabuf_fd);
printf("OK\n");
printf("Testing (theoretical)newer alloc compat\n"); printf(" Testing (theoretical)newer alloc compat: ");
ret = dmabuf_heap_alloc_newer(heap_fd, ONE_MEG, 0, &dmabuf_fd); ret = dmabuf_heap_alloc_newer(heap_fd, ONE_MEG, 0, &dmabuf_fd);
if (ret) { if (ret) {
printf("Newer compat allocation failed!\n"); printf("FAIL (Newer compat allocation failed!)\n");
ret = -1; ret = -1;
goto out; goto out;
} }
printf("Ioctl compatibility tests passed\n"); printf("OK\n");
out: out:
if (dmabuf_fd >= 0) if (dmabuf_fd >= 0)
close(dmabuf_fd); close(dmabuf_fd);
...@@ -327,17 +406,17 @@ static int test_alloc_errors(char *heap_name) ...@@ -327,17 +406,17 @@ static int test_alloc_errors(char *heap_name)
if (heap_fd < 0) if (heap_fd < 0)
return -1; return -1;
printf("Testing expected error cases\n"); printf(" Testing expected error cases: ");
ret = dmabuf_heap_alloc(0, ONE_MEG, 0x111111, &dmabuf_fd); ret = dmabuf_heap_alloc(0, ONE_MEG, 0x111111, &dmabuf_fd);
if (!ret) { if (!ret) {
printf("Did not see expected error (invalid fd)!\n"); printf("FAIL (Did not see expected error (invalid fd)!)\n");
ret = -1; ret = -1;
goto out; goto out;
} }
ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0x111111, &dmabuf_fd); ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0x111111, &dmabuf_fd);
if (!ret) { if (!ret) {
printf("Did not see expected error (invalid heap flags)!\n"); printf("FAIL (Did not see expected error (invalid heap flags)!)\n");
ret = -1; ret = -1;
goto out; goto out;
} }
...@@ -345,12 +424,12 @@ static int test_alloc_errors(char *heap_name) ...@@ -345,12 +424,12 @@ static int test_alloc_errors(char *heap_name)
ret = dmabuf_heap_alloc_fdflags(heap_fd, ONE_MEG, ret = dmabuf_heap_alloc_fdflags(heap_fd, ONE_MEG,
~(O_RDWR | O_CLOEXEC), 0, &dmabuf_fd); ~(O_RDWR | O_CLOEXEC), 0, &dmabuf_fd);
if (!ret) { if (!ret) {
printf("Did not see expected error (invalid fd flags)!\n"); printf("FAIL (Did not see expected error (invalid fd flags)!)\n");
ret = -1; ret = -1;
goto out; goto out;
} }
printf("Expected error checking passed\n"); printf("OK\n");
ret = 0; ret = 0;
out: out:
if (dmabuf_fd >= 0) if (dmabuf_fd >= 0)
...@@ -379,10 +458,20 @@ int main(void) ...@@ -379,10 +458,20 @@ int main(void)
if (!strncmp(dir->d_name, "..", 3)) if (!strncmp(dir->d_name, "..", 3))
continue; continue;
printf("Testing heap: %s\n", dir->d_name);
printf("=======================================\n");
ret = test_alloc_and_import(dir->d_name); ret = test_alloc_and_import(dir->d_name);
if (ret) if (ret)
break; break;
ret = test_alloc_zeroed(dir->d_name, 4 * 1024);
if (ret)
break;
ret = test_alloc_zeroed(dir->d_name, ONE_MEG);
if (ret)
break;
ret = test_alloc_compat(dir->d_name); ret = test_alloc_compat(dir->d_name);
if (ret) if (ret)
break; break;
......
...@@ -69,7 +69,7 @@ int restore_queue(struct msgque_data *msgque) ...@@ -69,7 +69,7 @@ int restore_queue(struct msgque_data *msgque)
printf("msgsnd failed (%m)\n"); printf("msgsnd failed (%m)\n");
ret = -errno; ret = -errno;
goto destroy; goto destroy;
}; }
} }
return 0; return 0;
...@@ -180,7 +180,7 @@ int fill_msgque(struct msgque_data *msgque) ...@@ -180,7 +180,7 @@ int fill_msgque(struct msgque_data *msgque)
IPC_NOWAIT) != 0) { IPC_NOWAIT) != 0) {
printf("First message send failed (%m)\n"); printf("First message send failed (%m)\n");
return -errno; return -errno;
}; }
msgbuf.mtype = ANOTHER_MSG_TYPE; msgbuf.mtype = ANOTHER_MSG_TYPE;
memcpy(msgbuf.mtext, ANOTHER_TEST_STRING, sizeof(ANOTHER_TEST_STRING)); memcpy(msgbuf.mtext, ANOTHER_TEST_STRING, sizeof(ANOTHER_TEST_STRING));
...@@ -188,7 +188,7 @@ int fill_msgque(struct msgque_data *msgque) ...@@ -188,7 +188,7 @@ int fill_msgque(struct msgque_data *msgque)
IPC_NOWAIT) != 0) { IPC_NOWAIT) != 0) {
printf("Second message send failed (%m)\n"); printf("Second message send failed (%m)\n");
return -errno; return -errno;
}; }
return 0; return 0;
} }
......
...@@ -4019,18 +4019,14 @@ TEST(user_notification_addfd) ...@@ -4019,18 +4019,14 @@ TEST(user_notification_addfd)
/* Verify we can set an arbitrary remote fd */ /* Verify we can set an arbitrary remote fd */
fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd); fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);
/* EXPECT_GE(fd, 0);
* The child has fds 0(stdin), 1(stdout), 2(stderr), 3(memfd),
* 4(listener), so the newly allocated fd should be 5.
*/
EXPECT_EQ(fd, 5);
EXPECT_EQ(filecmp(getpid(), pid, memfd, fd), 0); EXPECT_EQ(filecmp(getpid(), pid, memfd, fd), 0);
/* Verify we can set an arbitrary remote fd with large size */ /* Verify we can set an arbitrary remote fd with large size */
memset(&big, 0x0, sizeof(big)); memset(&big, 0x0, sizeof(big));
big.addfd = addfd; big.addfd = addfd;
fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD_BIG, &big); fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD_BIG, &big);
EXPECT_EQ(fd, 6); EXPECT_GE(fd, 0);
/* Verify we can set a specific remote fd */ /* Verify we can set a specific remote fd */
addfd.newfd = 42; addfd.newfd = 42;
......
# SPDX-License-Identifier: GPL-2.0-only # SPDX-License-Identifier: GPL-2.0-only
clock_nanosleep clock_nanosleep
exec exec
futex
gettime_perf gettime_perf
gettime_perf_cold gettime_perf_cold
procfs procfs
......
...@@ -47,10 +47,12 @@ ...@@ -47,10 +47,12 @@
#elif defined(__x86_64__) #elif defined(__x86_64__)
#define VDSO_VERSION 0 #define VDSO_VERSION 0
#define VDSO_NAMES 1 #define VDSO_NAMES 1
#elif defined(__riscv__) #elif defined(__riscv__) || defined(__riscv)
#define VDSO_VERSION 5 #define VDSO_VERSION 5
#define VDSO_NAMES 1 #define VDSO_NAMES 1
#if __riscv_xlen == 32
#define VDSO_32BIT 1 #define VDSO_32BIT 1
#endif
#else /* nds32 */ #else /* nds32 */
#define VDSO_VERSION 4 #define VDSO_VERSION 4
#define VDSO_NAMES 1 #define VDSO_NAMES 1
......
...@@ -607,7 +607,7 @@ static void do_multicpu_tests(void) ...@@ -607,7 +607,7 @@ static void do_multicpu_tests(void)
failures++; failures++;
asm volatile ("mov %0, %%ss" : : "rm" (orig_ss)); asm volatile ("mov %0, %%ss" : : "rm" (orig_ss));
}; }
ftx = 100; /* Kill the thread. */ ftx = 100; /* Kill the thread. */
syscall(SYS_futex, &ftx, FUTEX_WAKE, 0, NULL, NULL, 0); syscall(SYS_futex, &ftx, FUTEX_WAKE, 0, NULL, NULL, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment