Skip to contentSkip to conversation

drm/atomic: Reject properties not part of the object.

PATCH New Maarten Lankhorst 3 participants 6 messages Sep 5, 2016 – Sep 12, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Maarten Lankhorst

author maintainer
#0 lore raw

PATCH 1/1 drm/atomic: Reject properties not part of the object.

The legacy setprop ioctl doesn't attempt to set properties that are not enumerated on the object. The atomic ioctl does, fix this by validating first.

---
 drivers/gpu/drm/drm_atomic.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c +10 -1
index 5cb2e22d5d55..a5126e5c05ee 100644
@@ -1609,7 +1609,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
 	struct drm_crtc_state *crtc_state;
 	unsigned plane_mask;
 	int ret = 0;
-	unsigned int i, j;
+	unsigned int i, j, k;
 
 	/* disallow for drivers not supporting atomic: */
 	if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
@@ -1691,6 +1691,15 @@ retry:
 				goto out;
 			}
 
+			for (k = 0; k < obj->properties->count; k++)
+				if (obj->properties->properties[k]->base.id == prop_id)
+					break;
+
+			if (k == obj->properties->count) {
+				ret = -EINVAL;
+				goto out;
+			}
+
 			prop = drm_property_find(dev, prop_id);
 			if (!prop) {
 				drm_mode_object_unreference(obj);
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

✗ Fi.CI.BAT: failure for drm/atomic: Reject properties not part of the object.

== Series Details ==

== Series Details ==

Series: drm/atomic: Reject properties not part of the object.
URL : https://patchwork.freedesktop.org/series/11993/
State : failure

== Summary ==

Series 11993v1 drm/atomic: Reject properties not part of the object.
http://patchwork.freedesktop.org/api/1.0/series/11993/revisions/1/mbox/

Test gem_exec_gttfill:

        Subgroup basic:
                pass       -> SKIP       (fi-snb-2600)
Test kms_cursor_legacy:
        Subgroup basic-cursor-vs-flip-varying-size:
                pass       -> FAIL       (fi-hsw-4770k)
Test kms_flip:
        Subgroup basic-flip-vs-dpms:
                dmesg-fail -> PASS       (fi-hsw-4770k)
        Subgroup basic-flip-vs-modeset:
                dmesg-warn -> PASS       (fi-hsw-4770k)
        Subgroup basic-flip-vs-wf_vblank:
                dmesg-warn -> PASS       (fi-hsw-4770k)
Test kms_pipe_crc_basic:
        Subgroup nonblocking-crc-pipe-b:
                skip       -> PASS       (fi-hsw-4770r)
        Subgroup read-crc-pipe-b:
                skip       -> PASS       (fi-skl-6260u)
        Subgroup read-crc-pipe-c:
                skip       -> PASS       (fi-hsw-4770r)
        Subgroup suspend-read-crc-pipe-c:
                pass       -> INCOMPLETE (fi-hsw-4770k)
fi-bdw-5557u     total:252  pass:233  dwarn:2   dfail:1   fail:1   skip:15 
fi-bsw-n3050     total:252  pass:203  dwarn:1   dfail:1   fail:1   skip:46 
fi-byt-n2820     total:252  pass:206  dwarn:2   dfail:1   fail:2   skip:41 
fi-hsw-4770k     total:216  pass:194  dwarn:0   dfail:0   fail:1   skip:20 
fi-hsw-4770r     total:252  pass:222  dwarn:2   dfail:1   fail:1   skip:26 
fi-ivb-3520m     total:252  pass:217  dwarn:2   dfail:1   fail:1   skip:31 
fi-skl-6260u     total:252  pass:234  dwarn:2   dfail:1   fail:1   skip:14 
fi-skl-6700k     total:252  pass:219  dwarn:3   dfail:1   fail:1   skip:28 
fi-snb-2520m     total:252  pass:204  dwarn:2   dfail:1   fail:2   skip:43 
fi-snb-2600      total:252  pass:204  dwarn:2   dfail:1   fail:1   skip:44 

Results at /archive/results/CI_IGT_test/Patchwork_2467/

9baa666b3e48f71b46c5f63541f57d2a95a1b1c0 drm-intel-nightly: 2016y-09m-03d-12h-12m-15s UTC integration manifest 979edcd drm/atomic: Reject properties not part of the object.

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

A message that is not in the archive (sent off-list or not yet received): CAOw6vbLFoEEOFuAMBmFd2udPPpjfBQnTUcJHeQE6fcHM0F3s6g@mail.gmail.com

author maintainer
#3 lore raw

PATCH 1/1 drm: Move property validation to a helper.

Property lifetimes are equal to the device lifetime, so the separate drm_property_find is not needed. The pointer can be retrieved from the properties member, which saves us some locking and a extra lookup.

The lifetime for properties is until the device is destroyed, which happens late in the device unload path.

Testcase: kms_properties

---
 drivers/gpu/drm/drm_atomic.c        | 16 ++++------------
 drivers/gpu/drm/drm_crtc_internal.h |  2 ++
 drivers/gpu/drm/drm_mode_object.c   | 31 ++++++++++++++++---------------
 3 files changed, 22 insertions(+), 27 deletions(-)
drivers/gpu/drm/drm_atomic.c +4 -12
index fac156c43506..8bec8466781c 100644
@@ -1609,7 +1609,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
 	struct drm_crtc_state *crtc_state;
 	unsigned plane_mask;
 	int ret = 0;
-	unsigned int i, j, k;
+	unsigned int i, j;
 
 	/* disallow for drivers not supporting atomic: */
 	if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
@@ -1691,19 +1691,11 @@ retry:
 				goto out;
 			}
 
-			for (k = 0; k < obj->properties->count; k++)
-				if (obj->properties->properties[k]->base.id == prop_id)
-					break;
-
-			if (k == obj->properties->count) {
-				ret = -EINVAL;
-				goto out;
-			}
-
-			prop = drm_property_find(dev, prop_id);
+			prop = drm_mode_obj_find_prop_id(obj, prop_id);
 			if (!prop) {
 				drm_mode_object_unreference(obj);
-				ret = -ENOENT;
+				DRM_DEBUG_ATOMIC("cannot find property %u for obj %u\n", prop_id, obj_id);
+				ret = -EINVAL;
 				goto out;
 			}
 
drivers/gpu/drm/drm_crtc_internal.h +2 -0
index a3622644bccf..444e609078cc 100644
@@ -115,6 +115,8 @@ int drm_mode_object_get_properties(struct drm_mode_object *obj, bool atomic,
 				   uint32_t __user *prop_ptr,
 				   uint64_t __user *prop_values,
 				   uint32_t *arg_count_props);
+struct drm_property *drm_mode_obj_find_prop_id(struct drm_mode_object *obj,
+					       uint32_t prop_id);
 
 /* IOCTL */
 
drivers/gpu/drm/drm_mode_object.c +16 -15
index 6edda8382a4c..9f17085b1fdd 100644
@@ -372,14 +372,25 @@ out:
 	return ret;
 }
 
+struct drm_property *drm_mode_obj_find_prop_id(struct drm_mode_object *obj,
+					       uint32_t prop_id)
+{
+	int i;
+
+	for (i = 0; i < obj->properties->count; i++)
+		if (obj->properties->properties[i]->base.id == prop_id)
+			return obj->properties->properties[i];
+
+	return NULL;
+}
+
 int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
 				    struct drm_file *file_priv)
 {
 	struct drm_mode_obj_set_property *arg = data;
 	struct drm_mode_object *arg_obj;
-	struct drm_mode_object *prop_obj;
 	struct drm_property *property;
-	int i, ret = -EINVAL;
+	int ret = -EINVAL;
 	struct drm_mode_object *ref;
 
 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
@@ -392,23 +403,13 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
 		ret = -ENOENT;
 		goto out;
 	}
-	if (!arg_obj->properties)
-		goto out_unref;
-
-	for (i = 0; i < arg_obj->properties->count; i++)
-		if (arg_obj->properties->properties[i]->base.id == arg->prop_id)
-			break;
 
-	if (i == arg_obj->properties->count)
+	if (!arg_obj->properties)
 		goto out_unref;
 
-	prop_obj = drm_mode_object_find(dev, arg->prop_id,
-					DRM_MODE_OBJECT_PROPERTY);
-	if (!prop_obj) {
-		ret = -ENOENT;
+	property = drm_mode_obj_find_prop_id(arg_obj, arg->prop_id);
+	if (!property)
 		goto out_unref;
-	}
-	property = obj_to_property(prop_obj);
 
 	if (!drm_property_change_valid_get(property, arg->value, &ref))
 		goto out_unref;
Signature · 7 lines
2.7.4


_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#4 lore raw

Re: [PATCH] drm: Move property validation to a helper.

Op 07-09-16 om 10:58 schreef Maarten Lankhorst:

Quoted 39 lines

Property lifetimes are equal to the device lifetime, so the separate drm_property_find is not needed. The pointer can be retrieved from the properties member, which saves us some locking and a extra lookup.

The lifetime for properties is until the device is destroyed, which happens late in the device unload path.

Testcase: kms_properties

---
 drivers/gpu/drm/drm_atomic.c        | 16 ++++------------
 drivers/gpu/drm/drm_crtc_internal.h |  2 ++
 drivers/gpu/drm/drm_mode_object.c   | 31 ++++++++++++++++---------------
 3 files changed, 22 insertions(+), 27 deletions(-)
drivers/gpu/drm/drm_atomic.c +1 -7
index fac156c43506..8bec8466781c 100644
@@ -1609,7 +1609,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
 	struct drm_crtc_state *crtc_state;
 	unsigned plane_mask;
 	int ret = 0;
-	unsigned int i, j, k;
+	unsigned int i, j;
 
 	/* disallow for drivers not supporting atomic: */
 	if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
@@ -1691,19 +1691,11 @@ retry:
 				goto out;
 			}
 
-			for (k = 0; k < obj->properties->count; k++)
-				if (obj->properties->properties[k]->base.id == prop_id)
-					break;
-
-			if (k == obj->properties->count) {
-				ret = -EINVAL;

drivers/gpu/drm/drm_atomic.c retry: · line 1698

Quoted 10 lines
drivers/gpu/drm/drm_atomic.c +3 -5
-				goto out;
-			}
-
-			prop = drm_property_find(dev, prop_id);
+			prop = drm_mode_obj_find_prop_id(obj, prop_id);
 			if (!prop) {
 				drm_mode_object_unreference(obj);
-				ret = -ENOENT;
+				DRM_DEBUG_ATOMIC("cannot find property %u for obj %u\n", prop_id, obj_id);
+				ret = -EINVAL;

This needs to stay -ENOENT it seems. kms_atomic testcase relies on it.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#5 lore raw

PATCH v2 1/1 drm: Move property validation to a helper, v2.

In reply to Maarten Lankhorst

Property lifetimes are equal to the device lifetime, so the separate drm_property_find is not needed. The pointer can be retrieved from the properties member, which saves us some locking and a extra lookup. The lifetime for properties is until the device is destroyed, which happens late in the device unload path.

kms_atomic is also testing for invalid properties which returns -ENOENT, to be consistent return -ENOENT for valid properties that don't appear on the object property list.

Changes since v1:
- Return -ENOENT for invalid properties to make kms_atomic pass.
- Change commit message slightly to take this into account.

Testcase: kms_atomic
Testcase: kms_properties

Fixes 4e9951d96093 ("drm/atomic: Reject properties not part of the object.")
---
 drivers/gpu/drm/drm_atomic.c        | 13 ++-----------
 drivers/gpu/drm/drm_crtc_internal.h |  2 ++
 drivers/gpu/drm/drm_mode_object.c   | 31 ++++++++++++++++---------------
 3 files changed, 20 insertions(+), 26 deletions(-)
drivers/gpu/drm/drm_atomic.c +2 -11
index fac156c43506..23739609427d 100644
@@ -1609,7 +1609,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
 	struct drm_crtc_state *crtc_state;
 	unsigned plane_mask;
 	int ret = 0;
-	unsigned int i, j, k;
+	unsigned int i, j;
 
 	/* disallow for drivers not supporting atomic: */
 	if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
@@ -1691,16 +1691,7 @@ retry:
 				goto out;
 			}
 
-			for (k = 0; k < obj->properties->count; k++)
-				if (obj->properties->properties[k]->base.id == prop_id)
-					break;
-
-			if (k == obj->properties->count) {
-				ret = -EINVAL;
-				goto out;
-			}
-
-			prop = drm_property_find(dev, prop_id);
+			prop = drm_mode_obj_find_prop_id(obj, prop_id);
 			if (!prop) {
 				drm_mode_object_unreference(obj);
 				ret = -ENOENT;
drivers/gpu/drm/drm_crtc_internal.h +2 -0
index a3622644bccf..444e609078cc 100644
@@ -115,6 +115,8 @@ int drm_mode_object_get_properties(struct drm_mode_object *obj, bool atomic,
 				   uint32_t __user *prop_ptr,
 				   uint64_t __user *prop_values,
 				   uint32_t *arg_count_props);
+struct drm_property *drm_mode_obj_find_prop_id(struct drm_mode_object *obj,
+					       uint32_t prop_id);
 
 /* IOCTL */
 
drivers/gpu/drm/drm_mode_object.c +16 -15
index 6edda8382a4c..9f17085b1fdd 100644
@@ -372,14 +372,25 @@ out:
 	return ret;
 }
 
+struct drm_property *drm_mode_obj_find_prop_id(struct drm_mode_object *obj,
+					       uint32_t prop_id)
+{
+	int i;
+
+	for (i = 0; i < obj->properties->count; i++)
+		if (obj->properties->properties[i]->base.id == prop_id)
+			return obj->properties->properties[i];
+
+	return NULL;
+}
+
 int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
 				    struct drm_file *file_priv)
 {
 	struct drm_mode_obj_set_property *arg = data;
 	struct drm_mode_object *arg_obj;
-	struct drm_mode_object *prop_obj;
 	struct drm_property *property;
-	int i, ret = -EINVAL;
+	int ret = -EINVAL;
 	struct drm_mode_object *ref;
 
 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
@@ -392,23 +403,13 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
 		ret = -ENOENT;
 		goto out;
 	}
-	if (!arg_obj->properties)
-		goto out_unref;
-
-	for (i = 0; i < arg_obj->properties->count; i++)
-		if (arg_obj->properties->properties[i]->base.id == arg->prop_id)
-			break;
 
-	if (i == arg_obj->properties->count)
+	if (!arg_obj->properties)
 		goto out_unref;
 
-	prop_obj = drm_mode_object_find(dev, arg->prop_id,
-					DRM_MODE_OBJECT_PROPERTY);
-	if (!prop_obj) {
-		ret = -ENOENT;
+	property = drm_mode_obj_find_prop_id(arg_obj, arg->prop_id);
+	if (!property)
 		goto out_unref;
-	}
-	property = obj_to_property(prop_obj);
 
 	if (!drm_property_change_valid_get(property, arg->value, &ref))
 		goto out_unref;
Signature · 7 lines
2.7.4


_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

Re: [PATCH v2] drm: Move property validation to a helper, v2.

Quoted 14 lines · Maarten Lankhorst

Property lifetimes are equal to the device lifetime, so the separate drm_property_find is not needed. The pointer can be retrieved from the properties member, which saves us some locking and a extra lookup. The lifetime for properties is until the device is destroyed, which happens late in the device unload path.

kms_atomic is also testing for invalid properties which returns -ENOENT, to be consistent return -ENOENT for valid properties that don't appear on the object property list.

Changes since v1:
- Return -ENOENT for invalid properties to make kms_atomic pass.
- Change commit message slightly to take this into account.

Quoted 5 lines

Testcase: kms_atomic
Testcase: kms_properties

Fixes 4e9951d96093 ("drm/atomic: Reject properties not part of the object.")

Nice cleanup! applied to drm-misc

Sean

Quoted 110 lines
---
 drivers/gpu/drm/drm_atomic.c        | 13 ++-----------
 drivers/gpu/drm/drm_crtc_internal.h |  2 ++
 drivers/gpu/drm/drm_mode_object.c   | 31 ++++++++++++++++---------------
 3 files changed, 20 insertions(+), 26 deletions(-)
drivers/gpu/drm/drm_atomic.c +2 -11
index fac156c43506..23739609427d 100644
@@ -1609,7 +1609,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
        struct drm_crtc_state *crtc_state;
        unsigned plane_mask;
        int ret = 0;
-       unsigned int i, j, k;
+       unsigned int i, j;
 
        /* disallow for drivers not supporting atomic: */
        if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
@@ -1691,16 +1691,7 @@ retry:
                                goto out;
                        }
 
-                       for (k = 0; k < obj->properties->count; k++)
-                               if (obj->properties->properties[k]->base.id == prop_id)
-                                       break;
-
-                       if (k == obj->properties->count) {
-                               ret = -EINVAL;
-                               goto out;
-                       }
-
-                       prop = drm_property_find(dev, prop_id);
+                       prop = drm_mode_obj_find_prop_id(obj, prop_id);
                        if (!prop) {
                                drm_mode_object_unreference(obj);
                                ret = -ENOENT;
drivers/gpu/drm/drm_crtc_internal.h +2 -0
index a3622644bccf..444e609078cc 100644
@@ -115,6 +115,8 @@ int drm_mode_object_get_properties(struct drm_mode_object *obj, bool atomic,
                                   uint32_t __user *prop_ptr,
                                   uint64_t __user *prop_values,
                                   uint32_t *arg_count_props);
+struct drm_property *drm_mode_obj_find_prop_id(struct drm_mode_object *obj,
+                                              uint32_t prop_id);
 
 /* IOCTL */
 
drivers/gpu/drm/drm_mode_object.c +16 -16
index 6edda8382a4c..9f17085b1fdd 100644
@@ -372,14 +372,25 @@ out:
        return ret;
 }
 
+struct drm_property *drm_mode_obj_find_prop_id(struct drm_mode_object *obj,
+                                              uint32_t prop_id)
+{
+       int i;
+
+       for (i = 0; i < obj->properties->count; i++)
+               if (obj->properties->properties[i]->base.id == prop_id)
+                       return obj->properties->properties[i];
+
+       return NULL;
+}
+
 int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
                                    struct drm_file *file_priv)
 {
        struct drm_mode_obj_set_property *arg = data;
        struct drm_mode_object *arg_obj;
-       struct drm_mode_object *prop_obj;
        struct drm_property *property;
-       int i, ret = -EINVAL;
+       int ret = -EINVAL;
        struct drm_mode_object *ref;
 
        if (!drm_core_check_feature(dev, DRIVER_MODESET))
@@ -392,23 +403,13 @@ int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
                ret = -ENOENT;
                goto out;
        }
-       if (!arg_obj->properties)
-               goto out_unref;
-
-       for (i = 0; i < arg_obj->properties->count; i++)
-               if (arg_obj->properties->properties[i]->base.id == arg->prop_id)
-                       break;
 
-       if (i == arg_obj->properties->count)
+       if (!arg_obj->properties)
                goto out_unref;
 
-       prop_obj = drm_mode_object_find(dev, arg->prop_id,
-                                       DRM_MODE_OBJECT_PROPERTY);
-       if (!prop_obj) {
-               ret = -ENOENT;
+       property = drm_mode_obj_find_prop_id(arg_obj, arg->prop_id);
+       if (!property)
                goto out_unref;
-       }
-       property = obj_to_property(prop_obj);
 
        if (!drm_property_change_valid_get(property, arg->value, &ref))
                goto out_unref;
--
Quoted 3 lines

2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel