drm: Use kvzalloc for allocating blob property memory
Subsystems (2)
PATCH 1/1 drm: Use kvzalloc for allocating blob property memory
From: Michel Dänzer <[email protected]>
The property size may be controlled by userspace, can be large (I've seen failure with order 4, i.e. 16 pages / 64 KB) and doesn't need to be physically contiguous.
--- drivers/gpu/drm/drm_property.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_property.c +3 -3
@@ -532,7 +532,7 @@ static void drm_property_free_blob(struct kref *kref)drm_mode_object_unregister (blob->dev, &blob->base); -kfree (blob); +kvfree (blob); }/**
@@ -559,7 +559,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,if (!length || length >ULONG_MAX -sizeof (struct drm_property_blob ))return ERR_PTR (-EINVAL ); - blob =kzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL ); + blob =kvzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL );if (!blob)return ERR_PTR (-ENOMEM );
@@ -576,7 +576,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length, ret =__drm_mode_object_add (dev, &blob->base,DRM_MODE_OBJECT_BLOB , true, drm_property_free_blob);if (ret) { -kfree (blob); +kvfree (blob);return ERR_PTR (-EINVAL ); }
Signature · 6 lines
2.18.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 7 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
The property size may be controlled by userspace, can be large (I've seen failure with order 4, i.e. 16 pages / 64 KB) and doesn't need to be physically contiguous.
Signed-off-by Michel Dänzer <[email protected]>
Quoted 38 lines
--- drivers/gpu/drm/drm_property.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_property.c +3
-4@@ -532,7 +532,7 @@ static void drm_property_free_blob(struct kref *kref)drm_mode_object_unregister (blob->dev, &blob->base); -kfree (blob); +kvfree (blob); }/** @@ -559,7 +559,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,if (!length || length >ULONG_MAX -sizeof (struct drm_property_blob ))return ERR_PTR (-EINVAL ); - blob =kzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL ); + blob =kvzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL );if (!blob)return ERR_PTR (-ENOMEM );@@ -576,7 +576,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length, ret =__drm_mode_object_add (dev, &blob->base,DRM_MODE_OBJECT_BLOB , true, drm_property_free_blob);if (ret) { -kfree (blob); +kvfree (blob);return ERR_PTR (-EINVAL ); } --2.18.0
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 5 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
The property size may be controlled by userspace, can be large (I've seen failure with order 4, i.e. 16 pages / 64 KB) and doesn't need to be physically contiguous.
I wonder if we should enforce some kind of reasonable limit on the blob size. Looks like we allow anything up to ULONG_MAX currently. We can't tell at createblob time how the thing is going to be used, so can't have any kind of property specific limit unfortunately.
Quoted 44 lines
Signed-off-by Michel Dänzer <[email protected]>--- drivers/gpu/drm/drm_property.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_property.c +3
-3@@ -532,7 +532,7 @@ static void drm_property_free_blob(struct kref *kref)drm_mode_object_unregister (blob->dev, &blob->base); -kfree (blob); +kvfree (blob); }/** @@ -559,7 +559,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length,if (!length || length >ULONG_MAX -sizeof (struct drm_property_blob ))return ERR_PTR (-EINVAL ); - blob =kzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL ); + blob =kvzalloc (sizeof (struct drm_property_blob )+length,GFP_KERNEL );if (!blob)return ERR_PTR (-ENOMEM );@@ -576,7 +576,7 @@ drm_property_create_blob(struct drm_device *dev, size_t length, ret =__drm_mode_object_add (dev, &blob->base,DRM_MODE_OBJECT_BLOB , true, drm_property_free_blob);if (ret) { -kfree (blob); +kvfree (blob);return ERR_PTR (-EINVAL ); }Signature · 6 lines
2.18.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä Intel _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 7 lines · Ville Syrjälä
Quoted 5 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
The property size may be controlled by userspace, can be large (I've seen failure with order 4, i.e. 16 pages / 64 KB) and doesn't need to be physically contiguous.
Quoted 5 lines
I wonder if we should enforce some kind of reasonable limit on the blob size. Looks like we allow anything up to
ULONG_MAXcurrently. We can't tell at createblob time how the thing is going to be used, so can't have any kind of property specific limit unfortunately.
The failure I was seeing was for a gamma LUT, so a size limit alone cannot solve the issue.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 8 lines · Michel Dänzer
Quoted 7 lines · Ville Syrjälä
Quoted 5 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
The property size may be controlled by userspace, can be large (I've seen failure with order 4, i.e. 16 pages / 64 KB) and doesn't need to be physically contiguous.
Quoted 8 lines
Quoted 5 lines
I wonder if we should enforce some kind of reasonable limit on the blob size. Looks like we allow anything up to
ULONG_MAXcurrently. We can't tell at createblob time how the thing is going to be used, so can't have any kind of property specific limit unfortunately.The failure I was seeing was for a gamma LUT, so a size limit alone cannot solve the issue.
Sure. I was just thinking that maybe we shouldn't allow someone to allocate unlimited amounts of kernel memory via this interface. But to do that effectively we'd also need to limit the total amount used by all blobs.
Signature · 6 lines
Ville Syrjälä Intel _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 15 lines · Ville Syrjälä
Quoted 14 lines · Michel Dänzer
Quoted 12 lines · Ville Syrjälä
Quoted 5 lines · Michel Dänzer
From: Michel Dänzer <[email protected]>
The property size may be controlled by userspace, can be large (I've seen failure with order 4, i.e. 16 pages / 64 KB) and doesn't need to be physically contiguous.
I wonder if we should enforce some kind of reasonable limit on the blob size. Looks like we allow anything up to
ULONG_MAXcurrently. We can't tell at createblob time how the thing is going to be used, so can't have any kind of property specific limit unfortunately.
Quoted 7 lines
Quoted 2 lines
The failure I was seeing was for a gamma LUT, so a size limit alone cannot solve the issue.
Sure. I was just thinking that maybe we shouldn't allow someone to allocate unlimited amounts of kernel memory via this interface. But to do that effectively we'd also need to limit the total amount used by all blobs.
People with drm master rights are allowed to pin enormous amounts of memory (through pinning of display buffers) ... I think simply requiring DRM_MASTER for the ioctl would be good enough. Atm anyone can abuse createblob to waste memory, which is a bit much.
We haven't marked it with DRM_RENDER_ALLOW, so I think this is just an oversight really. I'll type a patch.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel