linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vhost: reduce stack usage in log_used
@ 2020-09-11 15:09 Li Wang
  2020-09-14  2:42 ` Jason Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Li Wang @ 2020-09-11 15:09 UTC (permalink / raw)
  To: mst, jasowang; +Cc: kvm, virtualization, netdev, linux-kernel

Fix the warning: [-Werror=-Wframe-larger-than=]

drivers/vhost/vhost.c: In function log_used:
drivers/vhost/vhost.c:1906:1:
warning: the frame size of 1040 bytes is larger than 1024 bytes

Signed-off-by: Li Wang <li.wang@windriver.com>
---
 drivers/vhost/vhost.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index b45519c..41769de 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1884,25 +1884,31 @@ static int log_write_hva(struct vhost_virtqueue *vq, u64 hva, u64 len)
 
 static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len)
 {
-	struct iovec iov[64];
+	struct iovec *iov;
 	int i, ret;
 
 	if (!vq->iotlb)
 		return log_write(vq->log_base, vq->log_addr + used_offset, len);
 
+	iov = kcalloc(64, sizeof(*iov), GFP_KERNEL);
+	if (!iov)
+		return -ENOMEM;
+
 	ret = translate_desc(vq, (uintptr_t)vq->used + used_offset,
 			     len, iov, 64, VHOST_ACCESS_WO);
 	if (ret < 0)
-		return ret;
+		goto out;
 
 	for (i = 0; i < ret; i++) {
 		ret = log_write_hva(vq,	(uintptr_t)iov[i].iov_base,
 				    iov[i].iov_len);
 		if (ret)
-			return ret;
+			goto out;
 	}
 
-	return 0;
+out:
+	kfree(iov);
+	return ret;
 }
 
 int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
-- 
2.7.4


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

* Re: [PATCH] vhost: reduce stack usage in log_used
  2020-09-11 15:09 [PATCH] vhost: reduce stack usage in log_used Li Wang
@ 2020-09-14  2:42 ` Jason Wang
  2020-09-14 18:08   ` Li Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Wang @ 2020-09-14  2:42 UTC (permalink / raw)
  To: Li Wang; +Cc: mst, kvm, virtualization, netdev, linux-kernel



----- Original Message -----
> Fix the warning: [-Werror=-Wframe-larger-than=]
> 
> drivers/vhost/vhost.c: In function log_used:
> drivers/vhost/vhost.c:1906:1:
> warning: the frame size of 1040 bytes is larger than 1024 bytes
> 
> Signed-off-by: Li Wang <li.wang@windriver.com>
> ---
>  drivers/vhost/vhost.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index b45519c..41769de 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1884,25 +1884,31 @@ static int log_write_hva(struct vhost_virtqueue *vq,
> u64 hva, u64 len)
>  
>  static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len)
>  {
> -	struct iovec iov[64];
> +	struct iovec *iov;
>  	int i, ret;
>  
>  	if (!vq->iotlb)
>  		return log_write(vq->log_base, vq->log_addr + used_offset, len);
>  
> +	iov = kcalloc(64, sizeof(*iov), GFP_KERNEL);
> +	if (!iov)
> +		return -ENOMEM;

Let's preallocate it in e.g vhost_net_open().

We don't want to fail the log due to -ENOMEM.

Thanks

> +
>  	ret = translate_desc(vq, (uintptr_t)vq->used + used_offset,
>  			     len, iov, 64, VHOST_ACCESS_WO);
>  	if (ret < 0)
> -		return ret;
> +		goto out;
>  
>  	for (i = 0; i < ret; i++) {
>  		ret = log_write_hva(vq,	(uintptr_t)iov[i].iov_base,
>  				    iov[i].iov_len);
>  		if (ret)
> -			return ret;
> +			goto out;
>  	}
>  
> -	return 0;
> +out:
> +	kfree(iov);
> +	return ret;
>  }
>  
>  int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
> --
> 2.7.4
> 
> 


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

* [PATCH] vhost: reduce stack usage in log_used
  2020-09-14  2:42 ` Jason Wang
@ 2020-09-14 18:08   ` Li Wang
  2020-09-15  7:53     ` Jason Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Li Wang @ 2020-09-14 18:08 UTC (permalink / raw)
  To: mst, jasowang; +Cc: kvm, virtualization, netdev, linux-kernel

Fix the warning: [-Werror=-Wframe-larger-than=]

drivers/vhost/vhost.c: In function log_used:
drivers/vhost/vhost.c:1906:1:
warning: the frame size of 1040 bytes is larger than 1024 bytes

Signed-off-by: Li Wang <li.wang@windriver.com>
---
 drivers/vhost/vhost.c | 2 +-
 drivers/vhost/vhost.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index b45519c..31837a5
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1884,7 +1884,7 @@ static int log_write_hva(struct vhost_virtqueue *vq, u64 hva, u64 len)
 
 static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len)
 {
-	struct iovec iov[64];
+	struct iovec *iov = vq->log_iov;
 	int i, ret;
 
 	if (!vq->iotlb)
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 9032d3c..5fe4b47
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -123,6 +123,7 @@ struct vhost_virtqueue {
 	/* Log write descriptors */
 	void __user *log_base;
 	struct vhost_log *log;
+	struct iovec log_iov[64];
 
 	/* Ring endianness. Defaults to legacy native endianness.
 	 * Set to true when starting a modern virtio device. */
-- 
2.7.4


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

* Re: [PATCH] vhost: reduce stack usage in log_used
  2020-09-14 18:08   ` Li Wang
@ 2020-09-15  7:53     ` Jason Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2020-09-15  7:53 UTC (permalink / raw)
  To: Li Wang, mst; +Cc: kvm, virtualization, netdev, linux-kernel


On 2020/9/15 上午2:08, Li Wang wrote:
> Fix the warning: [-Werror=-Wframe-larger-than=]
>
> drivers/vhost/vhost.c: In function log_used:
> drivers/vhost/vhost.c:1906:1:
> warning: the frame size of 1040 bytes is larger than 1024 bytes
>
> Signed-off-by: Li Wang <li.wang@windriver.com>
> ---
>   drivers/vhost/vhost.c | 2 +-
>   drivers/vhost/vhost.h | 1 +
>   2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index b45519c..31837a5
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1884,7 +1884,7 @@ static int log_write_hva(struct vhost_virtqueue *vq, u64 hva, u64 len)
>   
>   static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len)
>   {
> -	struct iovec iov[64];
> +	struct iovec *iov = vq->log_iov;
>   	int i, ret;
>   
>   	if (!vq->iotlb)
> diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
> index 9032d3c..5fe4b47
> --- a/drivers/vhost/vhost.h
> +++ b/drivers/vhost/vhost.h
> @@ -123,6 +123,7 @@ struct vhost_virtqueue {
>   	/* Log write descriptors */
>   	void __user *log_base;
>   	struct vhost_log *log;
> +	struct iovec log_iov[64];
>   
>   	/* Ring endianness. Defaults to legacy native endianness.
>   	 * Set to true when starting a modern virtio device. */


Acked-by: Jason Wang <jasowang@redhat.com>



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

end of thread, other threads:[~2020-09-15  7:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11 15:09 [PATCH] vhost: reduce stack usage in log_used Li Wang
2020-09-14  2:42 ` Jason Wang
2020-09-14 18:08   ` Li Wang
2020-09-15  7:53     ` Jason Wang

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).