linux-kselftest-next-5.12-rc1

This Kselftest update for Linux 5.12-rc1 consists of:
 
 - 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.
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEPZKym/RZuOCGeA/kCwJExA0NQxwFAmAtpXcACgkQCwJExA0N
 QxxJ3w//d0VQGTMp7XBmEx04Tlh31grs/pHorvN5t9TOn/3QVq1OQhHIIq7Y6Zgx
 hOjKOldCzgILvNTTstCfwwQv6BA0EkD0+j27yXUOHUEB0h5bNbdirP2zohxvXq0x
 1MTch89rO+fFyUeeqZujs1EuMhNirENKp8Dpbe3Lw6wdBSqlkcZ/AfZJGIXlZKw2
 1rIaqk80eNhXnzLSFGS/zUJCmHwxpu+xp5a6n1qNk/SYGWWUbUzyanSfCSkH/Znt
 0zqG1EI6rgziUHI7Nscggj7pLQgB+udGS64Nk3RqrX85b0bfVDK947znCrlkaa5S
 YqSf/ldsK1AyE3qFW6MoK/ZWk0z9iLFuS/+EjWP5FlM85PDTG8UPgy6pOaVE/XrN
 2z4pJadUtItLtWMYiU9x7fY9BYk679a3UJaWyW1265VZkBk4UjbCA3Xz4Y/e4RSp
 K6UqCAZ/OwkDFRpSt1j8PSvm3Xi17qUJZyG+TZf7lzkL2kSOnj9kjHXfwrNpud2w
 dk/F8Fb0uwgaPY1iRfKSQCUWvJR/ze9FcmY7+hm12k5xKH17izidutDChV9L1apn
 cB5mHoyIEW9v/rPFPLubTy6mv9VdJKTmGg2BeT6FL/9FkbtLcW0tvyZoKzRpy/vv
 HLi52H72HCuEGOVMmw4439uwx1j89igewUAYzm6/lRCjpjI8f+4=
 =CTFH
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Linus Torvalds 2021-02-22 11:01:53 -08:00
commit 80215095ce
8 changed files with 132 additions and 44 deletions

View file

@ -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) {
ksft_print_msg(
"ptrace(PTRACE_SINGLESTEP) failed: %s\n",
"ptrace(PTRACE_CONT) failed: %s\n",
strerror(errno));
return false;
}
@ -159,7 +159,7 @@ static bool run_test(int wr_size, int wp_size, int wr, int wp)
}
alarm(0);
if (WIFEXITED(status)) {
ksft_print_msg("child did not single-step\n");
ksft_print_msg("child exited prematurely\n");
return false;
}
if (!WIFSTOPPED(status)) {

View file

@ -1,5 +1,5 @@
# 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

View file

@ -130,16 +130,13 @@ static int dmabuf_heap_alloc(int fd, size_t len, unsigned int flags,
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 = {
.flags = start_stop | DMA_BUF_SYNC_RW,
};
int ret;
ret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
if (ret)
printf("sync failed %d\n", errno);
return ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
}
#define ONE_MEG (1024 * 1024)
@ -151,16 +148,14 @@ static int test_alloc_and_import(char *heap_name)
void *p = NULL;
int ret;
printf("Testing heap: %s\n", heap_name);
heap_fd = dmabuf_heap_open(heap_name);
if (heap_fd < 0)
return -1;
printf("Allocating 1 MEG\n");
printf(" Testing allocation and importing: ");
ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0, &dmabuf_fd);
if (ret) {
printf("Allocation Failed!\n");
printf("FAIL (Allocation Failed!)\n");
ret = -1;
goto out;
}
@ -172,11 +167,10 @@ static int test_alloc_and_import(char *heap_name)
dmabuf_fd,
0);
if (p == MAP_FAILED) {
printf("mmap() failed: %m\n");
printf("FAIL (mmap() failed)\n");
ret = -1;
goto out;
}
printf("mmap passed\n");
dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
memset(p, 1, ONE_MEG / 2);
@ -186,25 +180,31 @@ static int test_alloc_and_import(char *heap_name)
importer_fd = open_vgem();
if (importer_fd < 0) {
ret = importer_fd;
printf("Failed to open vgem\n");
goto out;
printf("(Could not open vgem - skipping): ");
} 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) {
printf("Failed to import buffer\n");
printf("FAIL (DMA_BUF_SYNC_START failed!)\n");
goto out;
}
printf("import passed\n");
dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START);
memset(p, 0xff, ONE_MEG);
dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END);
printf("syncs passed\n");
ret = dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END);
if (ret < 0) {
printf("FAIL (DMA_BUF_SYNC_END failed!)\n");
goto out;
}
close_handle(importer_fd, handle);
ret = 0;
printf(" OK\n");
out:
if (p)
munmap(p, ONE_MEG);
@ -218,6 +218,84 @@ static int test_alloc_and_import(char *heap_name)
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 */
static int dmabuf_heap_alloc_older(int fd, size_t len, unsigned int flags,
int *dmabuf_fd)
@ -292,23 +370,24 @@ static int test_alloc_compat(char *heap_name)
if (heap_fd < 0)
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);
if (ret) {
printf("Older compat allocation failed!\n");
printf("FAIL (Older compat allocation failed!)\n");
ret = -1;
goto out;
}
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);
if (ret) {
printf("Newer compat allocation failed!\n");
printf("FAIL (Newer compat allocation failed!)\n");
ret = -1;
goto out;
}
printf("Ioctl compatibility tests passed\n");
printf("OK\n");
out:
if (dmabuf_fd >= 0)
close(dmabuf_fd);
@ -327,17 +406,17 @@ static int test_alloc_errors(char *heap_name)
if (heap_fd < 0)
return -1;
printf("Testing expected error cases\n");
printf(" Testing expected error cases: ");
ret = dmabuf_heap_alloc(0, ONE_MEG, 0x111111, &dmabuf_fd);
if (!ret) {
printf("Did not see expected error (invalid fd)!\n");
printf("FAIL (Did not see expected error (invalid fd)!)\n");
ret = -1;
goto out;
}
ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0x111111, &dmabuf_fd);
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;
goto out;
}
@ -345,12 +424,12 @@ static int test_alloc_errors(char *heap_name)
ret = dmabuf_heap_alloc_fdflags(heap_fd, ONE_MEG,
~(O_RDWR | O_CLOEXEC), 0, &dmabuf_fd);
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;
goto out;
}
printf("Expected error checking passed\n");
printf("OK\n");
ret = 0;
out:
if (dmabuf_fd >= 0)
@ -379,10 +458,20 @@ int main(void)
if (!strncmp(dir->d_name, "..", 3))
continue;
printf("Testing heap: %s\n", dir->d_name);
printf("=======================================\n");
ret = test_alloc_and_import(dir->d_name);
if (ret)
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);
if (ret)
break;

View file

@ -69,7 +69,7 @@ int restore_queue(struct msgque_data *msgque)
printf("msgsnd failed (%m)\n");
ret = -errno;
goto destroy;
};
}
}
return 0;
@ -180,7 +180,7 @@ int fill_msgque(struct msgque_data *msgque)
IPC_NOWAIT) != 0) {
printf("First message send failed (%m)\n");
return -errno;
};
}
msgbuf.mtype = ANOTHER_MSG_TYPE;
memcpy(msgbuf.mtext, ANOTHER_TEST_STRING, sizeof(ANOTHER_TEST_STRING));
@ -188,7 +188,7 @@ int fill_msgque(struct msgque_data *msgque)
IPC_NOWAIT) != 0) {
printf("Second message send failed (%m)\n");
return -errno;
};
}
return 0;
}

View file

@ -4019,18 +4019,14 @@ TEST(user_notification_addfd)
/* Verify we can set an arbitrary remote fd */
fd = ioctl(listener, SECCOMP_IOCTL_NOTIF_ADDFD, &addfd);
/*
* 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_GE(fd, 0);
EXPECT_EQ(filecmp(getpid(), pid, memfd, fd), 0);
/* Verify we can set an arbitrary remote fd with large size */
memset(&big, 0x0, sizeof(big));
big.addfd = addfd;
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 */
addfd.newfd = 42;

View file

@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
clock_nanosleep
exec
futex
gettime_perf
gettime_perf_cold
procfs

View file

@ -47,10 +47,12 @@
#elif defined(__x86_64__)
#define VDSO_VERSION 0
#define VDSO_NAMES 1
#elif defined(__riscv__)
#elif defined(__riscv__) || defined(__riscv)
#define VDSO_VERSION 5
#define VDSO_NAMES 1
#if __riscv_xlen == 32
#define VDSO_32BIT 1
#endif
#else /* nds32 */
#define VDSO_VERSION 4
#define VDSO_NAMES 1

View file

@ -607,7 +607,7 @@ static void do_multicpu_tests(void)
failures++;
asm volatile ("mov %0, %%ss" : : "rm" (orig_ss));
};
}
ftx = 100; /* Kill the thread. */
syscall(SYS_futex, &ftx, FUTEX_WAKE, 0, NULL, NULL, 0);