All of lore.kernel.org
 help / color / mirror / Atom feed
From: Deborah Brouwer <deborah.brouwer@collabora.com>
To: igt-dev@lists.freedesktop.org
Cc: boris.brezillon@collabora.com, adrian.larumbe@collabora.com,
	 liviu.dudau@arm.com, steven.price@arm.com,
	daniel.almeida@collabora.com,  kamil.konieczny@linux.intel.com,
	 Deborah Brouwer <deborah.brouwer@collabora.com>
Subject: [PATCH i-g-t 2/2] panthor: test dev_query buffer size variations
Date: Thu, 15 Oct 2026 16:44:58 -0700	[thread overview]
Message-ID: <20261015-b4-dev_query-v1-2-70ffafa4131e@collabora.com> (raw)
In-Reply-To: <20261015-b4-dev_query-v1-0-70ffafa4131e@collabora.com>

Add tests to check that the kernel driver will gracefully handle userspace
buffers that are smaller or larger than the kernel driver expected.

Also, add a test to ensure that the kernel driver is enforcing the
minimum buffer size and that the kernel driver will provide the size
when the userpointer is null.

This ensures UAPI compliance for DRM_IOCTL_PANTHOR_DEV_QUERY.

Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
 tests/panthor/panthor_query.c | 64 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/tests/panthor/panthor_query.c b/tests/panthor/panthor_query.c
index afd58a5bd..8ff2e9652 100644
--- a/tests/panthor/panthor_query.c
+++ b/tests/panthor/panthor_query.c
@@ -7,6 +7,10 @@
 #include "panthor_drm.h"
 #include <stdint.h>
 
+#define GPU_INFO_MIN_SIZE \
+	(offsetof(struct drm_panthor_gpu_info, tiler_present) + \
+	 sizeof(((struct drm_panthor_gpu_info *)0)->tiler_present))
+
 int igt_main() {
 	int fd = -1;
 
@@ -20,10 +24,70 @@ int igt_main() {
 		struct drm_panthor_gpu_info gpu = {};
 
 		igt_panthor_query(fd, DRM_PANTHOR_DEV_QUERY_GPU_INFO, &gpu, sizeof(gpu), 0);
+		igt_assert_neq(gpu.gpu_id, 0);
+	}
+
+	igt_describe("Ensure kernel returns a GPU_INFO size.");
+	igt_subtest("query-size-null-pointer") {
+		uint32_t size;
+
+		size = igt_panthor_query(fd, DRM_PANTHOR_DEV_QUERY_GPU_INFO, NULL, 0, 0);
+
+		/*
+		 * The kernel returns its output structure size, which may be out
+		 * of sync with the header used to build these tests, so don't expect
+		 * that the sizes will match necessarily.
+		 */
+		igt_assert(size >= GPU_INFO_MIN_SIZE);
+	}
+
+	igt_describe("Ensure kernel enforces GPU_INFO minimum size.");
+	igt_subtest("query-size-too-small") {
+		struct drm_panthor_gpu_info gpu = {};
+
+		igt_panthor_query(fd, DRM_PANTHOR_DEV_QUERY_GPU_INFO,
+				  &gpu, GPU_INFO_MIN_SIZE - 1, EINVAL);
+	}
+
+	igt_describe("Ensure kernel accepts GPU_INFO minimum size.");
+	igt_subtest("query-min-size") {
+		struct drm_panthor_gpu_info gpu = {};
+
+		igt_panthor_query(fd, DRM_PANTHOR_DEV_QUERY_GPU_INFO,
+				  &gpu, GPU_INFO_MIN_SIZE, 0);
 
 		igt_assert_neq(gpu.gpu_id, 0);
 	}
 
+	igt_describe("Ensure kernel zeros out unused part of buffer.");
+	igt_subtest("query-too-big") {
+		uint32_t size;
+		size_t buf_size;
+		uint8_t *buf;
+
+		/*
+		 * Create a buffer that is larger than necessary.
+		 * Start with the size returned by the kernel in case it is out of
+		 * sync with these tests. Then add an extra 16 bytes and initialize
+		 * the entire buffer to non-zero values.
+		 */
+		size = igt_panthor_query(fd, DRM_PANTHOR_DEV_QUERY_GPU_INFO,
+					 NULL, 0, 0);
+		buf_size = (size_t)size + 16;
+		buf = malloc(buf_size);
+		igt_assert(buf);
+		memset(buf, 0xff, buf_size);
+
+		igt_panthor_query(fd, DRM_PANTHOR_DEV_QUERY_GPU_INFO,
+				  buf, buf_size, 0);
+
+		/* Check that the extra bytes were zeroed. */
+		for (size_t i = size; i < buf_size; i++)
+			igt_assert_eq(buf[i], 0);
+
+		free(buf);
+	}
+
 	igt_fixture() {
 		drm_close_driver(fd);
 	}

-- 
2.56.0


  parent reply	other threads:[~2026-10-15 23:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 23:44 [PATCH i-g-t 0/2] panthor: add dev_query tests for userspace buffer Deborah Brouwer
2026-10-15 23:44 ` [PATCH i-g-t 1/2] panthor: Return size from PANTHOR_DEV_QUERY Deborah Brouwer
2026-10-16  9:00   ` Liviu Dudau
2026-10-15 23:44 ` Deborah Brouwer [this message]
2026-10-16  9:06   ` [PATCH i-g-t 2/2] panthor: test dev_query buffer size variations Liviu Dudau
2026-10-16  0:25 ` ✗ Xe.CI.BAT: failure for panthor: add dev_query tests for userspace buffer Patchwork
2026-10-16  0:37 ` ✓ i915.CI.BAT: success " Patchwork
2026-10-16 10:56 ` ✗ Xe.CI.FULL: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261015-b4-dev_query-v1-2-70ffafa4131e@collabora.com \
    --to=deborah.brouwer@collabora.com \
    --cc=adrian.larumbe@collabora.com \
    --cc=boris.brezillon@collabora.com \
    --cc=daniel.almeida@collabora.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=liviu.dudau@arm.com \
    --cc=steven.price@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.