Skip to contentSkip to conversation

vhost: reduce stack usage in log_used

PATCH In review Li Wang 2 participants 4 messages Sep 11, 2020 – Sep 15, 2020

Subsystems (5)
lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH 1/1 vhost: reduce stack usage in log_used

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

---
 drivers/vhost/vhost.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/vhost/vhost.c +10 -4
index b45519c..41769de 100644
@@ -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,
Signature · 1 line
2.7.4
#1 lore raw

----- Original Message -----

Quoted 20 lines

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

---
 drivers/vhost/vhost.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/vhost/vhost.c +0 -0
index b45519c..41769de 100644
@@ -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)
 {

drivers/vhost/vhost.c static int log_write_hva(struct vhost_virtqueue *vq, · line 1896

Quoted 10 lines
drivers/vhost/vhost.c +4 -1
-	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

Quoted 26 lines
drivers/vhost/vhost.c +6 -3
+
 	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

author
#2 lore raw

PATCH 1/1 vhost: reduce stack usage in log_used

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

---
 drivers/vhost/vhost.c | 2 +-
 drivers/vhost/vhost.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vhost.c +1 -1
index b45519c..31837a5
@@ -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)
drivers/vhost/vhost.h +1 -0
index 9032d3c..5fe4b47
@@ -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. */
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#3 lore raw
Quoted 30 lines · Li Wang

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

---
  drivers/vhost/vhost.c | 2 +-
  drivers/vhost/vhost.h | 1 +
  2 files changed, 2 insertions(+), 1 deletion(-)
drivers/vhost/vhost.c +1 -1
index b45519c..31837a5
@@ -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)
drivers/vhost/vhost.h +0 -0
index 9032d3c..5fe4b47

drivers/vhost/vhost.h struct vhost_virtqueue { · line 129

Quoted 7 lines
drivers/vhost/vhost.h +1 -0
@@ -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. */

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization