Commit 80215095 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

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
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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)) {
+1 −1
Original line number Diff line number Diff line
# 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

+119 −30
Original line number Diff line number Diff line
@@ -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");
		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;
+3 −3
Original line number Diff line number Diff line
@@ -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;
}

+2 −6
Original line number Diff line number Diff line
@@ -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;
Loading