linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm: Use kvzalloc for allocating blob property memory
@ 2018-06-29 14:27 Michel Dänzer
  2018-06-29 14:50 ` Alex Deucher
  2018-06-29 16:12 ` Ville Syrjälä
  0 siblings, 2 replies; 6+ messages in thread
From: Michel Dänzer @ 2018-06-29 14:27 UTC (permalink / raw)
  To: Gustavo Padovan, Maarten Lankhorst, Sean Paul, David Airlie
  Cc: dri-devel, linux-kernel

From: Michel Dänzer <michel.daenzer@amd.com>

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 <michel.daenzer@amd.com>
---
 drivers/gpu/drm/drm_property.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
index 1f8031e30f53..cdb10f885a4f 100644
--- a/drivers/gpu/drm/drm_property.c
+++ b/drivers/gpu/drm/drm_property.c
@@ -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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm: Use kvzalloc for allocating blob property memory
  2018-06-29 14:27 [PATCH] drm: Use kvzalloc for allocating blob property memory Michel Dänzer
@ 2018-06-29 14:50 ` Alex Deucher
  2018-06-29 16:12 ` Ville Syrjälä
  1 sibling, 0 replies; 6+ messages in thread
From: Alex Deucher @ 2018-06-29 14:50 UTC (permalink / raw)
  To: Michel Dänzer
  Cc: Gustavo Padovan, Maarten Lankhorst, Sean Paul, David Airlie,
	LKML, Maling list - DRI developers

On Fri, Jun 29, 2018 at 10:27 AM, Michel Dänzer <michel@daenzer.net> wrote:
> From: Michel Dänzer <michel.daenzer@amd.com>
>
> 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 <michel.daenzer@amd.com>

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/drm_property.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
> index 1f8031e30f53..cdb10f885a4f 100644
> --- a/drivers/gpu/drm/drm_property.c
> +++ b/drivers/gpu/drm/drm_property.c
> @@ -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
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm: Use kvzalloc for allocating blob property memory
  2018-06-29 14:27 [PATCH] drm: Use kvzalloc for allocating blob property memory Michel Dänzer
  2018-06-29 14:50 ` Alex Deucher
@ 2018-06-29 16:12 ` Ville Syrjälä
  2018-06-29 16:27   ` Michel Dänzer
  1 sibling, 1 reply; 6+ messages in thread
From: Ville Syrjälä @ 2018-06-29 16:12 UTC (permalink / raw)
  To: Michel Dänzer
  Cc: Gustavo Padovan, Maarten Lankhorst, Sean Paul, David Airlie,
	linux-kernel, dri-devel

On Fri, Jun 29, 2018 at 04:27:10PM +0200, Michel Dänzer wrote:
> From: Michel Dänzer <michel.daenzer@amd.com>
> 
> 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.

> 
> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
> ---
>  drivers/gpu/drm/drm_property.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
> index 1f8031e30f53..cdb10f885a4f 100644
> --- a/drivers/gpu/drm/drm_property.c
> +++ b/drivers/gpu/drm/drm_property.c
> @@ -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
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Ville Syrjälä
Intel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm: Use kvzalloc for allocating blob property memory
  2018-06-29 16:12 ` Ville Syrjälä
@ 2018-06-29 16:27   ` Michel Dänzer
  2018-06-29 16:38     ` Ville Syrjälä
  0 siblings, 1 reply; 6+ messages in thread
From: Michel Dänzer @ 2018-06-29 16:27 UTC (permalink / raw)
  To: Ville Syrjälä; +Cc: David Airlie, linux-kernel, dri-devel

On 2018-06-29 06:12 PM, Ville Syrjälä wrote:
> On Fri, Jun 29, 2018 at 04:27:10PM +0200, Michel Dänzer wrote:
>> From: Michel Dänzer <michel.daenzer@amd.com>
>>
>> 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.

The failure I was seeing was for a gamma LUT, so a size limit alone
cannot solve the issue.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm: Use kvzalloc for allocating blob property memory
  2018-06-29 16:27   ` Michel Dänzer
@ 2018-06-29 16:38     ` Ville Syrjälä
  2018-07-02  8:07       ` Daniel Vetter
  0 siblings, 1 reply; 6+ messages in thread
From: Ville Syrjälä @ 2018-06-29 16:38 UTC (permalink / raw)
  To: Michel Dänzer; +Cc: David Airlie, linux-kernel, dri-devel

On Fri, Jun 29, 2018 at 06:27:28PM +0200, Michel Dänzer wrote:
> On 2018-06-29 06:12 PM, Ville Syrjälä wrote:
> > On Fri, Jun 29, 2018 at 04:27:10PM +0200, Michel Dänzer wrote:
> >> From: Michel Dänzer <michel.daenzer@amd.com>
> >>
> >> 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.
> 
> 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.

-- 
Ville Syrjälä
Intel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] drm: Use kvzalloc for allocating blob property memory
  2018-06-29 16:38     ` Ville Syrjälä
@ 2018-07-02  8:07       ` Daniel Vetter
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Vetter @ 2018-07-02  8:07 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Michel Dänzer, David Airlie, linux-kernel, dri-devel

On Fri, Jun 29, 2018 at 07:38:32PM +0300, Ville Syrjälä wrote:
> On Fri, Jun 29, 2018 at 06:27:28PM +0200, Michel Dänzer wrote:
> > On 2018-06-29 06:12 PM, Ville Syrjälä wrote:
> > > On Fri, Jun 29, 2018 at 04:27:10PM +0200, Michel Dänzer wrote:
> > >> From: Michel Dänzer <michel.daenzer@amd.com>
> > >>
> > >> 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.
> > 
> > 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
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-07-02  8:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-29 14:27 [PATCH] drm: Use kvzalloc for allocating blob property memory Michel Dänzer
2018-06-29 14:50 ` Alex Deucher
2018-06-29 16:12 ` Ville Syrjälä
2018-06-29 16:27   ` Michel Dänzer
2018-06-29 16:38     ` Ville Syrjälä
2018-07-02  8:07       ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).