All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch
@ 2016-05-07  8:17 Heinrich Schuchardt
  2016-05-09  5:25 ` Juergen Gross
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Heinrich Schuchardt @ 2016-05-07  8:17 UTC (permalink / raw)
  To: Boris Ostrovsky, David Vrabel, Juergen Gross
  Cc: xen-devel, linux-kernel, Heinrich Schuchardt

Commit a4cdb556cae0 ("xen/gntdev: add ioctl for grant copy")
leads to a warning
xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy’:
xen/gntdev.c:949:1: warning: the frame size of 1248 bytes
is larger than 1024 bytes [-Wframe-larger-than=]

This can be avoided by using kmalloc instead of the stack.

Testing requires CONFIG_XEN_GNTDEV.

Fixes: a4cdb556cae0 ("xen/gntdev: add ioctl for grant copy")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 drivers/xen/gntdev.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index dc49538..e8aec48 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -915,36 +915,43 @@ 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;
 
+	batch = kmalloc(sizeof(struct gntdev_copy_batch), GFP_KERNEL);
+	if (!batch)
+		return -ENOMEM;
+
 	if (copy_from_user(&copy, u, sizeof(copy)))
 		return -EFAULT;
 
-	batch.nr_ops = 0;
-	batch.nr_pages = 0;
+	batch->nr_ops = 0;
+	batch->nr_pages = 0;
 
 	for (i = 0; i < copy.count; i++) {
 		struct gntdev_grant_copy_segment seg;
 
 		if (copy_from_user(&seg, &copy.segments[i], sizeof(seg))) {
 			ret = -EFAULT;
-			goto out;
+			goto failed;
 		}
 
-		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;
+			goto failed;
 
 		cond_resched();
 	}
-	if (batch.nr_ops)
-		ret = gntdev_copy(&batch);
-	return ret;
+	if (batch->nr_ops)
+		ret = gntdev_copy(batch);
+	goto out;
 
-  out:
-	gntdev_put_pages(&batch);
+failed:
+	gntdev_put_pages(batch);
+out:
+	kfree(batch);
 	return ret;
 }
 
-- 
2.1.4

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

* Re: [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch
  2016-05-07  8:17 [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch Heinrich Schuchardt
  2016-05-09  5:25 ` Juergen Gross
@ 2016-05-09  5:25 ` Juergen Gross
  2016-05-09  6:06 ` Jan Beulich
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Juergen Gross @ 2016-05-09  5:25 UTC (permalink / raw)
  To: Heinrich Schuchardt, Boris Ostrovsky, David Vrabel
  Cc: xen-devel, linux-kernel

On 07/05/16 10:17, Heinrich Schuchardt wrote:
> Commit a4cdb556cae0 ("xen/gntdev: add ioctl for grant copy")
> leads to a warning
> xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy’:
> xen/gntdev.c:949:1: warning: the frame size of 1248 bytes
> is larger than 1024 bytes [-Wframe-larger-than=]
> 
> This can be avoided by using kmalloc instead of the stack.
> 
> Testing requires CONFIG_XEN_GNTDEV.
> 
> Fixes: a4cdb556cae0 ("xen/gntdev: add ioctl for grant copy")
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Acked-by: Juergen Gross <jgross@suse.com>

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

* Re: [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch
  2016-05-07  8:17 [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch Heinrich Schuchardt
@ 2016-05-09  5:25 ` Juergen Gross
  2016-05-09  5:25 ` Juergen Gross
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Juergen Gross @ 2016-05-09  5:25 UTC (permalink / raw)
  To: Heinrich Schuchardt, Boris Ostrovsky, David Vrabel
  Cc: xen-devel, linux-kernel

On 07/05/16 10:17, Heinrich Schuchardt wrote:
> Commit a4cdb556cae0 ("xen/gntdev: add ioctl for grant copy")
> leads to a warning
> xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy’:
> xen/gntdev.c:949:1: warning: the frame size of 1248 bytes
> is larger than 1024 bytes [-Wframe-larger-than=]
> 
> This can be avoided by using kmalloc instead of the stack.
> 
> Testing requires CONFIG_XEN_GNTDEV.
> 
> Fixes: a4cdb556cae0 ("xen/gntdev: add ioctl for grant copy")
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Acked-by: Juergen Gross <jgross@suse.com>

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

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

* Re: [Xen-devel] [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch
  2016-05-07  8:17 [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch Heinrich Schuchardt
                   ` (2 preceding siblings ...)
  2016-05-09  6:06 ` Jan Beulich
@ 2016-05-09  6:06 ` Jan Beulich
  2016-05-09 10:30 ` David Vrabel
  2016-05-09 10:30 ` David Vrabel
  5 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2016-05-09  6:06 UTC (permalink / raw)
  To: xypron.glpk
  Cc: david.vrabel, xen-devel, boris.ostrovsky, Juergen Gross, linux-kernel

>>> Heinrich Schuchardt <xypron.glpk@gmx.de> 05/08/16 8:13 AM >>>
>--- a/drivers/xen/gntdev.c
>+++ b/drivers/xen/gntdev.c
>@@ -915,36 +915,43 @@ 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;
 >
>+    batch = kmalloc(sizeof(struct gntdev_copy_batch), GFP_KERNEL);
>+    if (!batch)
>+        return -ENOMEM;
>+
>if (copy_from_user(&copy, u, sizeof(copy)))
>return -EFAULT;
 
You carefully fix up all other error return paths below, but not the one above,
resulting in a memory leak.

>-  out:
>-    gntdev_put_pages(&batch);
>+failed:
>+    gntdev_put_pages(batch);
>+out:
>+    kfree(batch);

I'm not sure what the conventions are for label placement in the kernel sources,
but "out" having been indented by one space (which you ditch) avoided diff's -p
option picking up the label instead of the function head as context.

Jan

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

* Re: [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch
  2016-05-07  8:17 [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch Heinrich Schuchardt
  2016-05-09  5:25 ` Juergen Gross
  2016-05-09  5:25 ` Juergen Gross
@ 2016-05-09  6:06 ` Jan Beulich
  2016-05-09  6:06 ` [Xen-devel] " Jan Beulich
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2016-05-09  6:06 UTC (permalink / raw)
  To: xypron.glpk
  Cc: Juergen Gross, xen-devel, boris.ostrovsky, david.vrabel, linux-kernel

>>> Heinrich Schuchardt <xypron.glpk@gmx.de> 05/08/16 8:13 AM >>>
>--- a/drivers/xen/gntdev.c
>+++ b/drivers/xen/gntdev.c
>@@ -915,36 +915,43 @@ 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;
 >
>+    batch = kmalloc(sizeof(struct gntdev_copy_batch), GFP_KERNEL);
>+    if (!batch)
>+        return -ENOMEM;
>+
>if (copy_from_user(&copy, u, sizeof(copy)))
>return -EFAULT;
 
You carefully fix up all other error return paths below, but not the one above,
resulting in a memory leak.

>-  out:
>-    gntdev_put_pages(&batch);
>+failed:
>+    gntdev_put_pages(batch);
>+out:
>+    kfree(batch);

I'm not sure what the conventions are for label placement in the kernel sources,
but "out" having been indented by one space (which you ditch) avoided diff's -p
option picking up the label instead of the function head as context.

Jan


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

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

* Re: [Xen-devel] [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch
  2016-05-07  8:17 [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch Heinrich Schuchardt
                   ` (3 preceding siblings ...)
  2016-05-09  6:06 ` [Xen-devel] " Jan Beulich
@ 2016-05-09 10:30 ` David Vrabel
  2016-05-09 10:30 ` David Vrabel
  5 siblings, 0 replies; 7+ messages in thread
From: David Vrabel @ 2016-05-09 10:30 UTC (permalink / raw)
  To: Heinrich Schuchardt, Boris Ostrovsky, David Vrabel, Juergen Gross
  Cc: xen-devel, linux-kernel

On 07/05/16 09:17, Heinrich Schuchardt wrote:
> Commit a4cdb556cae0 ("xen/gntdev: add ioctl for grant copy")
> leads to a warning
> xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy’:
> xen/gntdev.c:949:1: warning: the frame size of 1248 bytes
> is larger than 1024 bytes [-Wframe-larger-than=]
> 
> This can be avoided by using kmalloc instead of the stack.
> 
> Testing requires CONFIG_XEN_GNTDEV.

Thanks, but I've applied the following patch instead.

David

8<-------------
xen/gntdev: reduce copy batch size to 16

IOCTL_GNTDEV_GRANT_COPY batches copy operations to reduce the number
of hypercalls.  The stack is used to avoid a memory allocation in a
hot path. However, a batch size of 24 requires more than 1024 bytes of
stack which in some configurations causes a compiler warning.

    xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy’:
    xen/gntdev.c:949:1: warning: the frame size of 1248 bytes is
    larger than 1024 bytes [-Wframe-larger-than=]

This is a harmless warning as there is still plenty of stack spare,
but people keep trying to "fix" it.  Reduce the batch size to 16 to
reduce stack usage to less than 1024 bytes.  This should have minimal
impact on performance.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
 drivers/xen/gntdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index dc49538..6793957 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -748,7 +748,7 @@ static long gntdev_ioctl_notify(struct gntdev_priv
*priv, void __user *u)
 	return rc;
 }

-#define GNTDEV_COPY_BATCH 24
+#define GNTDEV_COPY_BATCH 16

 struct gntdev_copy_batch {
 	struct gnttab_copy ops[GNTDEV_COPY_BATCH];
-- 
2.1.4

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

* Re: [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch
  2016-05-07  8:17 [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch Heinrich Schuchardt
                   ` (4 preceding siblings ...)
  2016-05-09 10:30 ` David Vrabel
@ 2016-05-09 10:30 ` David Vrabel
  5 siblings, 0 replies; 7+ messages in thread
From: David Vrabel @ 2016-05-09 10:30 UTC (permalink / raw)
  To: Heinrich Schuchardt, Boris Ostrovsky, David Vrabel, Juergen Gross
  Cc: xen-devel, linux-kernel

On 07/05/16 09:17, Heinrich Schuchardt wrote:
> Commit a4cdb556cae0 ("xen/gntdev: add ioctl for grant copy")
> leads to a warning
> xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy’:
> xen/gntdev.c:949:1: warning: the frame size of 1248 bytes
> is larger than 1024 bytes [-Wframe-larger-than=]
> 
> This can be avoided by using kmalloc instead of the stack.
> 
> Testing requires CONFIG_XEN_GNTDEV.

Thanks, but I've applied the following patch instead.

David

8<-------------
xen/gntdev: reduce copy batch size to 16

IOCTL_GNTDEV_GRANT_COPY batches copy operations to reduce the number
of hypercalls.  The stack is used to avoid a memory allocation in a
hot path. However, a batch size of 24 requires more than 1024 bytes of
stack which in some configurations causes a compiler warning.

    xen/gntdev.c: In function ‘gntdev_ioctl_grant_copy’:
    xen/gntdev.c:949:1: warning: the frame size of 1248 bytes is
    larger than 1024 bytes [-Wframe-larger-than=]

This is a harmless warning as there is still plenty of stack spare,
but people keep trying to "fix" it.  Reduce the batch size to 16 to
reduce stack usage to less than 1024 bytes.  This should have minimal
impact on performance.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
 drivers/xen/gntdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index dc49538..6793957 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -748,7 +748,7 @@ static long gntdev_ioctl_notify(struct gntdev_priv
*priv, void __user *u)
 	return rc;
 }

-#define GNTDEV_COPY_BATCH 24
+#define GNTDEV_COPY_BATCH 16

 struct gntdev_copy_batch {
 	struct gnttab_copy ops[GNTDEV_COPY_BATCH];
-- 
2.1.4


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

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

end of thread, other threads:[~2016-05-09 10:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-07  8:17 [PATCH 1/1] xen/gntdev: kmalloc structure gntdev_copy_batch Heinrich Schuchardt
2016-05-09  5:25 ` Juergen Gross
2016-05-09  5:25 ` Juergen Gross
2016-05-09  6:06 ` Jan Beulich
2016-05-09  6:06 ` [Xen-devel] " Jan Beulich
2016-05-09 10:30 ` David Vrabel
2016-05-09 10:30 ` 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.