All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
@ 2016-01-15 19:43 Boris Ostrovsky
  2016-01-15 19:50 ` [Xen-devel] " Andrew Cooper
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Boris Ostrovsky @ 2016-01-15 19:43 UTC (permalink / raw)
  To: konrad.wilk, david.vrabel; +Cc: xen-devel, linux-kernel, Boris Ostrovsky

struct gntdev_copy_batch is over 1300 bytes in size, we shouldn't
put it on stack.

Some compilers (e.g. 5.2.1) complain:
 drivers/xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy.isra.5’:
 drivers/xen/gntdev.c:949:1: warning: the frame size of 1416 bytes
  is larger than 1024 bytes [-Wframe-larger-than=]

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
 drivers/xen/gntdev.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index dc49538..43a2c1c 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -915,15 +915,19 @@ static int gntdev_grant_copy_seg(struct gntdev_copy_batch *batch,
 static long gntdev_ioctl_grant_copy(struct gntdev_priv *priv, void __user *u)
 {
 	struct ioctl_gntdev_grant_copy copy;
-	struct gntdev_copy_batch batch;
+	struct gntdev_copy_batch *batch;
 	unsigned int i;
 	int ret = 0;
 
 	if (copy_from_user(&copy, u, sizeof(copy)))
 		return -EFAULT;
 
-	batch.nr_ops = 0;
-	batch.nr_pages = 0;
+	batch = kmalloc(sizeof(*batch), GFP_KERNEL);
+	if (!batch)
+		return -ENOMEM;
+
+	batch->nr_ops = 0;
+	batch->nr_pages = 0;
 
 	for (i = 0; i < copy.count; i++) {
 		struct gntdev_grant_copy_segment seg;
@@ -933,18 +937,20 @@ static long gntdev_ioctl_grant_copy(struct gntdev_priv *priv, void __user *u)
 			goto out;
 		}
 
-		ret = gntdev_grant_copy_seg(&batch, &seg, &copy.segments[i].status);
+		ret = gntdev_grant_copy_seg(batch, &seg,
+			&copy.segments[i].status);
 		if (ret < 0)
 			goto out;
 
 		cond_resched();
 	}
-	if (batch.nr_ops)
-		ret = gntdev_copy(&batch);
+	if (batch->nr_ops)
+		ret = gntdev_copy(batch);
 	return ret;
 
   out:
-	gntdev_put_pages(&batch);
+	gntdev_put_pages(batch);
+	kfree(batch);
 	return ret;
 }
 
-- 
2.5.0

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

* Re: [Xen-devel] [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-15 19:43 [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack Boris Ostrovsky
@ 2016-01-15 19:50 ` Andrew Cooper
  2016-01-15 19:53   ` Boris Ostrovsky
  2016-01-15 19:53   ` [Xen-devel] " Boris Ostrovsky
  2016-01-15 19:50 ` Andrew Cooper
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: Andrew Cooper @ 2016-01-15 19:50 UTC (permalink / raw)
  To: Boris Ostrovsky, konrad.wilk, david.vrabel; +Cc: xen-devel, linux-kernel

On 15/01/16 19:43, Boris Ostrovsky wrote:
> struct gntdev_copy_batch is over 1300 bytes in size, we shouldn't
> put it on stack.
>
> Some compilers (e.g. 5.2.1) complain:
>  drivers/xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy.isra.5’:
>  drivers/xen/gntdev.c:949:1: warning: the frame size of 1416 bytes
>   is larger than 1024 bytes [-Wframe-larger-than=]
>
> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> ---
>  drivers/xen/gntdev.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
> index dc49538..43a2c1c 100644
> --- a/drivers/xen/gntdev.c
> +++ b/drivers/xen/gntdev.c
> @@ -915,15 +915,19 @@ static int gntdev_grant_copy_seg(struct gntdev_copy_batch *batch,
>  static long gntdev_ioctl_grant_copy(struct gntdev_priv *priv, void __user *u)
>  {
>  	struct ioctl_gntdev_grant_copy copy;
> -	struct gntdev_copy_batch batch;
> +	struct gntdev_copy_batch *batch;
>  	unsigned int i;
>  	int ret = 0;
>  
>  	if (copy_from_user(&copy, u, sizeof(copy)))
>  		return -EFAULT;
>  
> -	batch.nr_ops = 0;
> -	batch.nr_pages = 0;
> +	batch = kmalloc(sizeof(*batch), GFP_KERNEL);
> +	if (!batch)
> +		return -ENOMEM;
> +
> +	batch->nr_ops = 0;
> +	batch->nr_pages = 0;
>  
>  	for (i = 0; i < copy.count; i++) {
>  		struct gntdev_grant_copy_segment seg;
> @@ -933,18 +937,20 @@ static long gntdev_ioctl_grant_copy(struct gntdev_priv *priv, void __user *u)
>  			goto out;
>  		}
>  
> -		ret = gntdev_grant_copy_seg(&batch, &seg, &copy.segments[i].status);
> +		ret = gntdev_grant_copy_seg(batch, &seg,
> +			&copy.segments[i].status);
>  		if (ret < 0)
>  			goto out;
>  
>  		cond_resched();
>  	}
> -	if (batch.nr_ops)
> -		ret = gntdev_copy(&batch);
> +	if (batch->nr_ops)
> +		ret = gntdev_copy(batch);

You presumably want a kfree() here?

>  	return ret;
>  
>    out:
> -	gntdev_put_pages(&batch);
> +	gntdev_put_pages(batch);
> +	kfree(batch);
>  	return ret;
>  }
>  

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

* Re: [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-15 19:43 [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack Boris Ostrovsky
  2016-01-15 19:50 ` [Xen-devel] " Andrew Cooper
@ 2016-01-15 19:50 ` Andrew Cooper
  2016-01-18 11:11 ` [Xen-devel] " David Vrabel
  2016-01-18 11:11 ` David Vrabel
  3 siblings, 0 replies; 11+ messages in thread
From: Andrew Cooper @ 2016-01-15 19:50 UTC (permalink / raw)
  To: Boris Ostrovsky, konrad.wilk, david.vrabel; +Cc: xen-devel, linux-kernel

On 15/01/16 19:43, Boris Ostrovsky wrote:
> struct gntdev_copy_batch is over 1300 bytes in size, we shouldn't
> put it on stack.
>
> Some compilers (e.g. 5.2.1) complain:
>  drivers/xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy.isra.5’:
>  drivers/xen/gntdev.c:949:1: warning: the frame size of 1416 bytes
>   is larger than 1024 bytes [-Wframe-larger-than=]
>
> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> ---
>  drivers/xen/gntdev.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
> index dc49538..43a2c1c 100644
> --- a/drivers/xen/gntdev.c
> +++ b/drivers/xen/gntdev.c
> @@ -915,15 +915,19 @@ static int gntdev_grant_copy_seg(struct gntdev_copy_batch *batch,
>  static long gntdev_ioctl_grant_copy(struct gntdev_priv *priv, void __user *u)
>  {
>  	struct ioctl_gntdev_grant_copy copy;
> -	struct gntdev_copy_batch batch;
> +	struct gntdev_copy_batch *batch;
>  	unsigned int i;
>  	int ret = 0;
>  
>  	if (copy_from_user(&copy, u, sizeof(copy)))
>  		return -EFAULT;
>  
> -	batch.nr_ops = 0;
> -	batch.nr_pages = 0;
> +	batch = kmalloc(sizeof(*batch), GFP_KERNEL);
> +	if (!batch)
> +		return -ENOMEM;
> +
> +	batch->nr_ops = 0;
> +	batch->nr_pages = 0;
>  
>  	for (i = 0; i < copy.count; i++) {
>  		struct gntdev_grant_copy_segment seg;
> @@ -933,18 +937,20 @@ static long gntdev_ioctl_grant_copy(struct gntdev_priv *priv, void __user *u)
>  			goto out;
>  		}
>  
> -		ret = gntdev_grant_copy_seg(&batch, &seg, &copy.segments[i].status);
> +		ret = gntdev_grant_copy_seg(batch, &seg,
> +			&copy.segments[i].status);
>  		if (ret < 0)
>  			goto out;
>  
>  		cond_resched();
>  	}
> -	if (batch.nr_ops)
> -		ret = gntdev_copy(&batch);
> +	if (batch->nr_ops)
> +		ret = gntdev_copy(batch);

You presumably want a kfree() here?

>  	return ret;
>  
>    out:
> -	gntdev_put_pages(&batch);
> +	gntdev_put_pages(batch);
> +	kfree(batch);
>  	return ret;
>  }
>  


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [Xen-devel] [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-15 19:50 ` [Xen-devel] " Andrew Cooper
  2016-01-15 19:53   ` Boris Ostrovsky
@ 2016-01-15 19:53   ` Boris Ostrovsky
  1 sibling, 0 replies; 11+ messages in thread
From: Boris Ostrovsky @ 2016-01-15 19:53 UTC (permalink / raw)
  To: Andrew Cooper, konrad.wilk, david.vrabel; +Cc: xen-devel, linux-kernel

On 01/15/2016 02:50 PM, Andrew Cooper wrote:
> On 15/01/16 19:43, Boris Ostrovsky wrote:
>> @@ -933,18 +937,20 @@ static long gntdev_ioctl_grant_copy(struct gntdev_priv *priv, void __user *u)
>>   			goto out;
>>   		}
>>   
>> -		ret = gntdev_grant_copy_seg(&batch, &seg, &copy.segments[i].status);
>> +		ret = gntdev_grant_copy_seg(batch, &seg,
>> +			&copy.segments[i].status);
>>   		if (ret < 0)
>>   			goto out;
>>   
>>   		cond_resched();
>>   	}
>> -	if (batch.nr_ops)
>> -		ret = gntdev_copy(&batch);
>> +	if (batch->nr_ops)
>> +		ret = gntdev_copy(batch);
> You presumably want a kfree() here?

Ah, missed it. Thanks.

>
>>   	return ret;
>>   

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

* Re: [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-15 19:50 ` [Xen-devel] " Andrew Cooper
@ 2016-01-15 19:53   ` Boris Ostrovsky
  2016-01-15 19:53   ` [Xen-devel] " Boris Ostrovsky
  1 sibling, 0 replies; 11+ messages in thread
From: Boris Ostrovsky @ 2016-01-15 19:53 UTC (permalink / raw)
  To: Andrew Cooper, konrad.wilk, david.vrabel; +Cc: xen-devel, linux-kernel

On 01/15/2016 02:50 PM, Andrew Cooper wrote:
> On 15/01/16 19:43, Boris Ostrovsky wrote:
>> @@ -933,18 +937,20 @@ static long gntdev_ioctl_grant_copy(struct gntdev_priv *priv, void __user *u)
>>   			goto out;
>>   		}
>>   
>> -		ret = gntdev_grant_copy_seg(&batch, &seg, &copy.segments[i].status);
>> +		ret = gntdev_grant_copy_seg(batch, &seg,
>> +			&copy.segments[i].status);
>>   		if (ret < 0)
>>   			goto out;
>>   
>>   		cond_resched();
>>   	}
>> -	if (batch.nr_ops)
>> -		ret = gntdev_copy(&batch);
>> +	if (batch->nr_ops)
>> +		ret = gntdev_copy(batch);
> You presumably want a kfree() here?

Ah, missed it. Thanks.

>
>>   	return ret;
>>   

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

* Re: [Xen-devel] [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-15 19:43 [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack Boris Ostrovsky
  2016-01-15 19:50 ` [Xen-devel] " Andrew Cooper
  2016-01-15 19:50 ` Andrew Cooper
@ 2016-01-18 11:11 ` David Vrabel
  2016-01-19 14:26   ` Boris Ostrovsky
  2016-01-19 14:26   ` [Xen-devel] " Boris Ostrovsky
  2016-01-18 11:11 ` David Vrabel
  3 siblings, 2 replies; 11+ messages in thread
From: David Vrabel @ 2016-01-18 11:11 UTC (permalink / raw)
  To: Boris Ostrovsky, konrad.wilk, david.vrabel; +Cc: xen-devel, linux-kernel

On 15/01/16 19:43, Boris Ostrovsky wrote:
> struct gntdev_copy_batch is over 1300 bytes in size, we shouldn't
> put it on stack.
> 
> Some compilers (e.g. 5.2.1) complain:
>  drivers/xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy.isra.5’:
>  drivers/xen/gntdev.c:949:1: warning: the frame size of 1416 bytes
>   is larger than 1024 bytes [-Wframe-larger-than=]

I thought I'd already reduced the size of this enough (from a batch size
of 32 to 24) but this obviously isn't enough for 64-bit platforms.

In the absence of any performance data on the best approach I would
prefer just reducing the batch size to 16.

David

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

* Re: [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-15 19:43 [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack Boris Ostrovsky
                   ` (2 preceding siblings ...)
  2016-01-18 11:11 ` [Xen-devel] " David Vrabel
@ 2016-01-18 11:11 ` David Vrabel
  3 siblings, 0 replies; 11+ messages in thread
From: David Vrabel @ 2016-01-18 11:11 UTC (permalink / raw)
  To: Boris Ostrovsky, konrad.wilk, david.vrabel; +Cc: xen-devel, linux-kernel

On 15/01/16 19:43, Boris Ostrovsky wrote:
> struct gntdev_copy_batch is over 1300 bytes in size, we shouldn't
> put it on stack.
> 
> Some compilers (e.g. 5.2.1) complain:
>  drivers/xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy.isra.5’:
>  drivers/xen/gntdev.c:949:1: warning: the frame size of 1416 bytes
>   is larger than 1024 bytes [-Wframe-larger-than=]

I thought I'd already reduced the size of this enough (from a batch size
of 32 to 24) but this obviously isn't enough for 64-bit platforms.

In the absence of any performance data on the best approach I would
prefer just reducing the batch size to 16.

David


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [Xen-devel] [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-18 11:11 ` [Xen-devel] " David Vrabel
  2016-01-19 14:26   ` Boris Ostrovsky
@ 2016-01-19 14:26   ` Boris Ostrovsky
  2016-01-19 14:31     ` David Vrabel
  2016-01-19 14:31     ` [Xen-devel] " David Vrabel
  1 sibling, 2 replies; 11+ messages in thread
From: Boris Ostrovsky @ 2016-01-19 14:26 UTC (permalink / raw)
  To: David Vrabel, konrad.wilk; +Cc: xen-devel, linux-kernel

On 01/18/2016 06:11 AM, David Vrabel wrote:
> On 15/01/16 19:43, Boris Ostrovsky wrote:
>> struct gntdev_copy_batch is over 1300 bytes in size, we shouldn't
>> put it on stack.
>>
>> Some compilers (e.g. 5.2.1) complain:
>>   drivers/xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy.isra.5’:
>>   drivers/xen/gntdev.c:949:1: warning: the frame size of 1416 bytes
>>    is larger than 1024 bytes [-Wframe-larger-than=]
> I thought I'd already reduced the size of this enough (from a batch size
> of 32 to 24) but this obviously isn't enough for 64-bit platforms.
>
> In the absence of any performance data on the best approach I would
> prefer just reducing the batch size to 16.

That would still leave us with over 900 bytes on the stack which I think 
is rather high.

Do we expect this ioctl to be on some sort of a hot path?


-boris

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

* Re: [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-18 11:11 ` [Xen-devel] " David Vrabel
@ 2016-01-19 14:26   ` Boris Ostrovsky
  2016-01-19 14:26   ` [Xen-devel] " Boris Ostrovsky
  1 sibling, 0 replies; 11+ messages in thread
From: Boris Ostrovsky @ 2016-01-19 14:26 UTC (permalink / raw)
  To: David Vrabel, konrad.wilk; +Cc: xen-devel, linux-kernel

On 01/18/2016 06:11 AM, David Vrabel wrote:
> On 15/01/16 19:43, Boris Ostrovsky wrote:
>> struct gntdev_copy_batch is over 1300 bytes in size, we shouldn't
>> put it on stack.
>>
>> Some compilers (e.g. 5.2.1) complain:
>>   drivers/xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy.isra.5’:
>>   drivers/xen/gntdev.c:949:1: warning: the frame size of 1416 bytes
>>    is larger than 1024 bytes [-Wframe-larger-than=]
> I thought I'd already reduced the size of this enough (from a batch size
> of 32 to 24) but this obviously isn't enough for 64-bit platforms.
>
> In the absence of any performance data on the best approach I would
> prefer just reducing the batch size to 16.

That would still leave us with over 900 bytes on the stack which I think 
is rather high.

Do we expect this ioctl to be on some sort of a hot path?


-boris

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

* Re: [Xen-devel] [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-19 14:26   ` [Xen-devel] " Boris Ostrovsky
  2016-01-19 14:31     ` David Vrabel
@ 2016-01-19 14:31     ` David Vrabel
  1 sibling, 0 replies; 11+ messages in thread
From: David Vrabel @ 2016-01-19 14:31 UTC (permalink / raw)
  To: Boris Ostrovsky, konrad.wilk; +Cc: xen-devel, linux-kernel

On 19/01/16 14:26, Boris Ostrovsky wrote:
> On 01/18/2016 06:11 AM, David Vrabel wrote:
>> On 15/01/16 19:43, Boris Ostrovsky wrote:
>>> struct gntdev_copy_batch is over 1300 bytes in size, we shouldn't
>>> put it on stack.
>>>
>>> Some compilers (e.g. 5.2.1) complain:
>>>   drivers/xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy.isra.5’:
>>>   drivers/xen/gntdev.c:949:1: warning: the frame size of 1416 bytes
>>>    is larger than 1024 bytes [-Wframe-larger-than=]
>> I thought I'd already reduced the size of this enough (from a batch size
>> of 32 to 24) but this obviously isn't enough for 64-bit platforms.
>>
>> In the absence of any performance data on the best approach I would
>> prefer just reducing the batch size to 16.
> 
> That would still leave us with over 900 bytes on the stack which I think
> is rather high.

The stack depth to here isn't very deep, so I think even the ~1500 byte
frame was fine.

> Do we expect this ioctl to be on some sort of a hot path?

Yes.

David

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

* Re: [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack
  2016-01-19 14:26   ` [Xen-devel] " Boris Ostrovsky
@ 2016-01-19 14:31     ` David Vrabel
  2016-01-19 14:31     ` [Xen-devel] " David Vrabel
  1 sibling, 0 replies; 11+ messages in thread
From: David Vrabel @ 2016-01-19 14:31 UTC (permalink / raw)
  To: Boris Ostrovsky, konrad.wilk; +Cc: xen-devel, linux-kernel

On 19/01/16 14:26, Boris Ostrovsky wrote:
> On 01/18/2016 06:11 AM, David Vrabel wrote:
>> On 15/01/16 19:43, Boris Ostrovsky wrote:
>>> struct gntdev_copy_batch is over 1300 bytes in size, we shouldn't
>>> put it on stack.
>>>
>>> Some compilers (e.g. 5.2.1) complain:
>>>   drivers/xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy.isra.5’:
>>>   drivers/xen/gntdev.c:949:1: warning: the frame size of 1416 bytes
>>>    is larger than 1024 bytes [-Wframe-larger-than=]
>> I thought I'd already reduced the size of this enough (from a batch size
>> of 32 to 24) but this obviously isn't enough for 64-bit platforms.
>>
>> In the absence of any performance data on the best approach I would
>> prefer just reducing the batch size to 16.
> 
> That would still leave us with over 900 bytes on the stack which I think
> is rather high.

The stack depth to here isn't very deep, so I think even the ~1500 byte
frame was fine.

> Do we expect this ioctl to be on some sort of a hot path?

Yes.

David

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

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

end of thread, other threads:[~2016-01-19 14:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-15 19:43 [PATCH] xen/gntdev: Don't allocate struct gntdev_copy_batch on stack Boris Ostrovsky
2016-01-15 19:50 ` [Xen-devel] " Andrew Cooper
2016-01-15 19:53   ` Boris Ostrovsky
2016-01-15 19:53   ` [Xen-devel] " Boris Ostrovsky
2016-01-15 19:50 ` Andrew Cooper
2016-01-18 11:11 ` [Xen-devel] " David Vrabel
2016-01-19 14:26   ` Boris Ostrovsky
2016-01-19 14:26   ` [Xen-devel] " Boris Ostrovsky
2016-01-19 14:31     ` David Vrabel
2016-01-19 14:31     ` [Xen-devel] " David Vrabel
2016-01-18 11:11 ` David Vrabel

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.