Skip to contentSkip to conversation

tests/kms_atomic: Read the error msg on atomic_ioctl failure

PATCH New Arun R Murthy 2 participants 7 messages Aug 22, 2025 – Mar 31

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/kms_atomic: Read the error msg on atomic_ioctl failure

On atomic_ioctl failure compare the failure flag with the expected invalid reason and pass if same else fail the test.

The corresponding KMD changes are pushed for review @
https://patchwork.freedesktop.org/series/152276/

---
 tests/kms_atomic.c | 6 ++++++
 1 file changed, 6 insertions(+)
tests/kms_atomic.c +6 -0
index 474df3fa4..c335c8999 100644
@@ -996,13 +996,17 @@ static void crtc_invalid_params_fence(data_t *data, igt_output_t *output)
 static void atomic_invalid_params(data_t *data, igt_output_t *output)
 {
 	struct drm_mode_atomic ioc;
+	struct drm_mode_atomic_err_code *err_code;
 	uint32_t obj_raw[16]; /* array of objects (sized by count_objs) */
 	uint32_t num_props_raw[16]; /* array of num props per obj (ditto) */
 	uint32_t props_raw[256]; /* array of props (sum of count_props) */
 	uint64_t values_raw[256]; /* array of values for properties (ditto) */
 	int i;
 
+	err_code = malloc(sizeof(struct drm_mode_atomic_err_code));
+	memset(err_code, 0, sizeof(struct drm_mode_atomic_err_code));
 	memset(&ioc, 0, sizeof(ioc));
+	ioc.reserved = (uintptr_t)err_code;
 
 	/* An empty request should do nothing. */
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
@@ -1027,10 +1031,12 @@ static void atomic_invalid_params(data_t *data, igt_output_t *output)
 	/* Valid noop, but with event set should fail. */
 	ioc.flags = DRM_MODE_PAGE_FLIP_EVENT;
 	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	igt_assert_eq(err_code->failure_flags, DRM_MODE_ATOMIC_CAP_NOT_ENABLED);
 
 	/* Nonsense flags. */
 	ioc.flags = 0xdeadbeef;
 	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	igt_assert_eq(err_code->failure_flags, DRM_MODE_ATOMIC_INVALID_FLAG);
 
 	ioc.flags = 0;
 	/* Safety check that flags is reset properly. */
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 tests/kms_atomic: Read the error msg on atomic_ioctl failure

On atomic_ioctl failure compare the failure flag with the expected invalid reason and pass if same else fail the test.

The corresponding KMD changes are pushed for review @
https://patchwork.freedesktop.org/series/152276/

---
 tests/kms_atomic.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tests/kms_atomic.c +10 -2
index fa321cc3c..a609a9f14 100644
@@ -1041,13 +1041,17 @@ static void crtc_invalid_params_fence(data_t *data, igt_output_t *output)
 static void atomic_invalid_params(data_t *data, igt_output_t *output)
 {
 	struct drm_mode_atomic ioc;
+	struct drm_mode_atomic_err_code *err_code;
 	uint32_t obj_raw[16]; /* array of objects (sized by count_objs) */
 	uint32_t num_props_raw[16]; /* array of num props per obj (ditto) */
 	uint32_t props_raw[256]; /* array of props (sum of count_props) */
 	uint64_t values_raw[256]; /* array of values for properties (ditto) */
 	int i;
 
+	err_code = malloc(sizeof(struct drm_mode_atomic_err_code));
+	memset(err_code, 0, sizeof(struct drm_mode_atomic_err_code));
 	memset(&ioc, 0, sizeof(ioc));
+	ioc.reserved = (uintptr_t)err_code;
 
 	/* An empty request should do nothing. */
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
@@ -1076,14 +1080,18 @@ static void atomic_invalid_params(data_t *data, igt_output_t *output)
 	/* Nonsense flags. */
 	ioc.flags = 0xdeadbeef;
 	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	if (igt_has_drm_cap(data->drm_fd, DRM_CAP_ATOMIC_ERROR_REPORTING))
+		igt_assert_eq(err_code->failure_code, DRM_MODE_ATOMIC_INVALID_API_USAGE);
 
 	ioc.flags = 0;
 	/* Safety check that flags is reset properly. */
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
 
 	/* Reserved/MBZ. */
-	ioc.reserved = 1;
-	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	if (!igt_has_drm_cap(data->drm_fd, DRM_CAP_ATOMIC_ERROR_REPORTING)) {
+		ioc.reserved = 1;
+		do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	}
 	ioc.reserved = 0;
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
 
Signature · 1 line
2.25.1
#2 lore raw

Hi Arun,

Quoted 18 lines · Arun R Murthy

On atomic_ioctl failure compare the failure flag with the expected invalid reason and pass if same else fail the test.

The corresponding KMD changes are pushed for review @
https://patchwork.freedesktop.org/series/152276/

---
 tests/kms_atomic.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tests/kms_atomic.c +0 -0
index fa321cc3c..a609a9f14 100644
@@ -1041,13 +1041,17 @@ static void crtc_invalid_params_fence(data_t *data, igt_output_t *output)
 static void atomic_invalid_params(data_t *data, igt_output_t *output)
 {

tests/kms_atomic.c static void crtc_invalid_params_fence(data_t *data, igt_output_t *output) · line 1052

Quoted 10 lines
tests/kms_atomic.c +3 -0
 	struct drm_mode_atomic ioc;
+	struct drm_mode_atomic_err_code *err_code;
 	uint32_t obj_raw[16]; /* array of objects (sized by count_objs) */
 	uint32_t num_props_raw[16]; /* array of num props per obj (ditto) */
 	uint32_t props_raw[256]; /* array of props (sum of count_props) */
 	uint64_t values_raw[256]; /* array of values for properties (ditto) */
 	int i;
 
+	err_code = malloc(sizeof(struct drm_mode_atomic_err_code));
+	memset(err_code, 0, sizeof(struct drm_mode_atomic_err_code));

Use calloc.

tests/kms_atomic.c static void crtc_invalid_params_fence(data_t *data, igt_output_t *output) · line 1054

Quoted 2 lines
tests/kms_atomic.c +1 -0
 	memset(&ioc, 0, sizeof(ioc));
+	ioc.reserved = (uintptr_t)err_code;

It is better using function to_user_pointer()

Quoted 13 lines
tests/kms_atomic.c +2 -0
 	/* An empty request should do nothing. */
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
@@ -1076,14 +1080,18 @@ static void atomic_invalid_params(data_t *data, igt_output_t *output)
 	/* Nonsense flags. */
 	ioc.flags = 0xdeadbeef;
 	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	if (igt_has_drm_cap(data->drm_fd, DRM_CAP_ATOMIC_ERROR_REPORTING))
+		igt_assert_eq(err_code->failure_code, DRM_MODE_ATOMIC_INVALID_API_USAGE);
 
 	ioc.flags = 0;
 	/* Safety check that flags is reset properly. */
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);

tests/kms_atomic.c static void atomic_invalid_params(data_t *data, igt_output_t *output) · line 1096

Quoted 10 lines
tests/kms_atomic.c +4 -2
 
 	/* Reserved/MBZ. */
-	ioc.reserved = 1;
-	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	if (!igt_has_drm_cap(data->drm_fd, DRM_CAP_ATOMIC_ERROR_REPORTING)) {
+		ioc.reserved = 1;
+		do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	}
 	ioc.reserved = 0;
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);

Where is free(err_code)?

Regards,
Kamil

Quoted 4 lines
Signature · 2 lines
-- 
2.25.1
#3 lore raw

Hi Kamil,

    Thanks for the review.
Sorry I forgot to add [DO_NOT_REVIEW] tag for this patch.
This patch was pushed just to get to know the usage from user for reviewing the KMD patch. I will be enhance the test and will push the patch for review.

Thanks and Regards,
Arun R Murthy
--------------------

Quoted 67 lines · Kamil Konieczny

Hi Arun,

Quoted 18 lines · Arun R Murthy

On atomic_ioctl failure compare the failure flag with the expected invalid reason and pass if same else fail the test.

The corresponding KMD changes are pushed for review @
https://patchwork.freedesktop.org/series/152276/

---
  tests/kms_atomic.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
tests/kms_atomic.c +0 -0
index fa321cc3c..a609a9f14 100644
@@ -1041,13 +1041,17 @@ static void crtc_invalid_params_fence(data_t *data, igt_output_t *output)
  static void atomic_invalid_params(data_t *data, igt_output_t *output)
  {

tests/kms_atomic.c static void crtc_invalid_params_fence(data_t *data, igt_output_t *output) · line 1052

Quoted 10 lines
tests/kms_atomic.c +3 -0
  	struct drm_mode_atomic ioc;
+	struct drm_mode_atomic_err_code *err_code;
  	uint32_t obj_raw[16]; /* array of objects (sized by count_objs) */
  	uint32_t num_props_raw[16]; /* array of num props per obj (ditto) */
  	uint32_t props_raw[256]; /* array of props (sum of count_props) */
  	uint64_t values_raw[256]; /* array of values for properties (ditto) */
  	int i;
 
+	err_code = malloc(sizeof(struct drm_mode_atomic_err_code));
+	memset(err_code, 0, sizeof(struct drm_mode_atomic_err_code));

Use calloc.

tests/kms_atomic.c static void crtc_invalid_params_fence(data_t *data, igt_output_t *output) · line 1054

Quoted 2 lines
tests/kms_atomic.c +1 -0
  	memset(&ioc, 0, sizeof(ioc));
+	ioc.reserved = (uintptr_t)err_code;

It is better using function to_user_pointer()

Quoted 13 lines
tests/kms_atomic.c +2 -0
  	/* An empty request should do nothing. */
  	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
@@ -1076,14 +1080,18 @@ static void atomic_invalid_params(data_t *data, igt_output_t *output)
  	/* Nonsense flags. */
  	ioc.flags = 0xdeadbeef;
  	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	if (igt_has_drm_cap(data->drm_fd, DRM_CAP_ATOMIC_ERROR_REPORTING))
+		igt_assert_eq(err_code->failure_code, DRM_MODE_ATOMIC_INVALID_API_USAGE);
 
  	ioc.flags = 0;
  	/* Safety check that flags is reset properly. */
  	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);

tests/kms_atomic.c static void atomic_invalid_params(data_t *data, igt_output_t *output) · line 1096

Quoted 10 lines
tests/kms_atomic.c +4 -2
 
  	/* Reserved/MBZ. */
-	ioc.reserved = 1;
-	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	if (!igt_has_drm_cap(data->drm_fd, DRM_CAP_ATOMIC_ERROR_REPORTING)) {
+		ioc.reserved = 1;
+		do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	}
  	ioc.reserved = 0;
  	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);

Where is free(err_code)?

Regards,
Kamil

Quoted 4 lines
Signature · 2 lines
-- 
2.25.1
#4 lore raw

PATCH 1/3 include/drm-uapi: Add atomic_ioctl error codes

In reply to Arun R Murthy

KMD adds a new feature to return a user readable error code on atomic_ioctl failure. This error code can be used to take corrective measurements and also be used for error/debug logging. The corresponding KMD patches are under review @
https://patchwork.freedesktop.org/series/152275/

---
 include/drm-uapi/drm_mode.h | 56 +++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
include/drm-uapi/drm_mode.h +56 -0
index de10ce859..f5e88cd7a 100644
@@ -45,6 +45,7 @@ extern "C" {
 #define DRM_CONNECTOR_NAME_LEN	32
 #define DRM_DISPLAY_MODE_LEN	32
 #define DRM_PROP_NAME_LEN	32
+#define DRM_MODE_ATOMIC_FAILURE_STRING_LEN	128
 
 #define DRM_MODE_TYPE_BUILTIN	(1<<0) /* deprecated */
 #define DRM_MODE_TYPE_CLOCK_C	((1<<1) | DRM_MODE_TYPE_BUILTIN) /* deprecated */
@@ -1241,6 +1242,61 @@ struct drm_mode_destroy_dumb {
 		DRM_MODE_ATOMIC_NONBLOCK |\
 		DRM_MODE_ATOMIC_ALLOW_MODESET)
 
+/**
+ * enum drm_mode_atomic_failure_codes -  error codes for failures in atomic_ioctl
+ * @DRM_MODE_ATOMIC_UNSPECIFIED_ERROR: this is the default/unspecified error.
+ * @DRM_MODE_ATOMIC_INVALID_API_USAGE: invallid API usage(DRM_ATOMIC not
+ *				       enabled, invalid falg, page_flip event
+ *				       with test-only, etc)
+ * @DRM_MODE_ATOMIC_NEED_FULL_MODESET: Need full modeset on all connected crtc's
+ * @DRM_MODE_ATOMIC_ASYNC_PROP_CHANGED: Property changed in async flip
+ * @DRM_MODE_ATOMIC_SCANOUT_BW: For a given resolution, refresh rate and the
+ *                              color depth cannot be accomodated. Resolution
+ *                              is to lower the refresh rate or color depth.
+ * @DRM_MODE_ATOMIC_CONNECTOR_BW: Refers to the limitation on the link rate on
+ *                                a given connector.
+ * @DRM_MODE_ATOMIC_PIPE_BW: Limitation on the pipe, either pipe not available
+ *                           or the pipe scaling factor limitation.
+ * @DRM_MODE_ATOMIC_MEMORY_DOMAIN: Any other memory/bandwidth related limitation
+ *                                 other then the ones specified above.
+ * @DRM_MODE_ATOMIC_SPEC_VIOLOATION: Limitation of a particular feature on that
+ *                                   hardware. To get to know the feature, the
+ *                                   property/object causing this is being sent
+ *                                   back to user @failure_objs_ptr in the
+ *                                   struct drm_mode_atomic_err_code
+ */
+enum drm_mode_atomic_failure_codes {
+	DRM_MODE_ATOMIC_UNSPECIFIED_ERROR,
+	DRM_MODE_ATOMIC_INVALID_API_USAGE,
+	DRM_MODE_ATOMIC_NEED_FULL_MODESET,
+	DRM_MODE_ATOMIC_ASYNC_PROP_CHANGED,
+	DRM_MODE_ATOMIC_SCANOUT_BW,
+	DRM_MODE_ATTOMIC_CONNECTOR_BW,
+	DRM_MODE_ATTOMIC_PIPE_BW,
+	DRM_MODE_ATOMIC_MEMORY_DOMAIN,
+	DRM_MODE_ATOMIC_SPEC_VIOLOATION,
+};
+
+/**
+ * struct drm_mode_atomic_err_code - struct to store the error code
+ *
+ * pointer to this struct will be stored in reserved variable of
+ * struct drm_mode_atomic to report the failure cause to the user.
+ *
+ * @failure_code: error codes defined in enum drm_moide_atomic_failure_code
+ * @failure_objs_ptr: pointer to the drm_object that caused error
+ * @reserved: reserved for future use
+ * @count_objs: count of drm_objects if multiple drm_objects caused error
+ * @failure_string: user readable error message string
+ */
+struct drm_mode_atomic_err_code {
+	__u64 failure_code;
+	__u64 failure_objs_ptr;
+	__u64 reserved;
+	__u32 count_objs;
+	char failure_string[DRM_MODE_ATOMIC_FAILURE_STRING_LEN];
+};
+
 struct drm_mode_atomic {
 	__u32 flags;
 	__u32 count_objs;
Signature · 1 line
2.25.1
#5 lore raw

PATCH 2/3 include/drm-uapi: Add ERROR_REPORTING capability

KMD adds error reporting on atomic_ioctl failure. A capability has been added for the same to check the compatability.

KMD patch is under review @
https://patchwork.freedesktop.org/series/152275/

---
 include/drm-uapi/drm.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/drm-uapi/drm.h +7 -0
index baa620e3f..dd3fa4350 100644
@@ -775,6 +775,13 @@ struct drm_gem_open {
  * commits.
  */
 #define DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP	0x15
+/**
+ * DRM_CAP_ATOMIC_ERROR_REPORTING
+ *
+ * If set to 1, the driver supports reporting of failure codes on error in
+ * atomic ioctl().
+ */
+#define DRM_CAP_ATOMIC_ERROR_REPORTING	0x16
 
 /* DRM_IOCTL_GET_CAP ioctl argument type */
 struct drm_get_cap {
Signature · 1 line
2.25.1
#6 lore raw

PATCH 3/3 tests/kms_atomic: Read the error msg on atomic_ioctl failure

In reply to Arun R Murthy

On atomic_ioctl failure compare the failure flag with the expected invalid reason and pass if same else fail the test.

The corresponding KMD changes are pushed for review @
https://patchwork.freedesktop.org/series/152276/

---
 tests/kms_atomic.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
tests/kms_atomic.c +8 -2
index ce5b00cd3..b28714981 100644
@@ -1043,6 +1043,7 @@ static void crtc_invalid_params_fence(data_t *data, igt_output_t *output)
 static void atomic_invalid_params(data_t *data, igt_output_t *output)
 {
 	struct drm_mode_atomic ioc;
+	struct drm_mode_atomic_err_code err_code;
 	uint32_t obj_raw[16]; /* array of objects (sized by count_objs) */
 	uint32_t num_props_raw[16]; /* array of num props per obj (ditto) */
 	uint32_t props_raw[256]; /* array of props (sum of count_props) */
@@ -1050,6 +1051,7 @@ static void atomic_invalid_params(data_t *data, igt_output_t *output)
 	int i;
 
 	memset(&ioc, 0, sizeof(ioc));
+	ioc.reserved = to_user_pointer(&err_code);
 
 	/* An empty request should do nothing. */
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
@@ -1078,14 +1080,18 @@ static void atomic_invalid_params(data_t *data, igt_output_t *output)
 	/* Nonsense flags. */
 	ioc.flags = 0xdeadbeef;
 	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	if (igt_has_drm_cap(data->drm_fd, DRM_CAP_ATOMIC_ERROR_REPORTING))
+		igt_assert_eq(err_code.failure_code, DRM_MODE_ATOMIC_INVALID_API_USAGE);
 
 	ioc.flags = 0;
 	/* Safety check that flags is reset properly. */
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
 
 	/* Reserved/MBZ. */
-	ioc.reserved = 1;
-	do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	if (!igt_has_drm_cap(data->drm_fd, DRM_CAP_ATOMIC_ERROR_REPORTING)) {
+		ioc.reserved = 1;
+		do_ioctl_err(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc, EINVAL);
+	}
 	ioc.reserved = 0;
 	do_ioctl(data->drm_fd, DRM_IOCTL_MODE_ATOMIC, &ioc);
 
Signature · 1 line
2.25.1