Skip to contentSkip to conversation

vhost: initialize vq->nheads properly

PATCH In review Jason Wang 6 participants 7 messages Jul 29, 2025 – Aug 4, 2025

Subsystems (5)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 vhost: initialize vq->nheads properly

Commit 7918bb2d19c9 ("vhost: basic in order support") introduces vq->nheads to store the number of batched used buffers per used elem but it forgets to initialize the vq->nheads to NULL in vhost_dev_init() this will cause kfree() that would try to free it without be allocated if SET_OWNER is not called.

Fixes 7918bb2d19c9 ("vhost: basic in order support")
---
 drivers/vhost/vhost.c | 1 +
 1 file changed, 1 insertion(+)
drivers/vhost/vhost.c +1 -0
index a4873d116df1..b4dfe38c7008 100644
@@ -615,6 +615,7 @@ void vhost_dev_init(struct vhost_dev *dev,
 		vq->log = NULL;
 		vq->indirect = NULL;
 		vq->heads = NULL;
+		vq->nheads = NULL;
 		vq->dev = dev;
 		mutex_init(&vq->mutex);
 		vhost_vq_reset(dev, vq);
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jason Wang

Commit 7918bb2d19c9 ("vhost: basic in order support") introduces vq->nheads to store the number of batched used buffers per used elem but it forgets to initialize the vq->nheads to NULL in vhost_dev_init() this will cause kfree() that would try to free it without be allocated if SET_OWNER is not called.

nit: as someone who is not familiar with vhost code, it took me a while to figure out you meant VHOST_SET_OWNER and the corresponding vhost_dev_set_owner()

Quoted 5 lines
Fixes 7918bb2d19c9 ("vhost: basic in order support")

Thanks,
Dawid

Tested-by on v1 1/1
#2 lore raw
In reply to Jason Wang
Quoted 10 lines · Jason Wang

Commit 7918bb2d19c9 ("vhost: basic in order support") introduces vq->nheads to store the number of batched used buffers per used elem but it forgets to initialize the vq->nheads to NULL in vhost_dev_init() this will cause kfree() that would try to free it without be allocated if SET_OWNER is not called.

Fixes 7918bb2d19c9 ("vhost: basic in order support")
Reviewed-by on v1 1/1
#3 lore raw
In reply to Jason Wang
Quoted 6 lines · Jason Wang

Commit 7918bb2d19c9 ("vhost: basic in order support") introduces vq->nheads to store the number of batched used buffers per used elem but it forgets to initialize the vq->nheads to NULL in vhost_dev_init() this will cause kfree() that would try to free it without be allocated if SET_OWNER is not called.

Quoted 7 lines
Fixes 7918bb2d19c9 ("vhost: basic in order support")

---
drivers/vhost/vhost.c | 1 +

1 file changed, 1 insertion(+)
Quoted 16 lines
drivers/vhost/vhost.c +1 -0
index a4873d116df1..b4dfe38c7008 100644
@@ -615,6 +615,7 @@ void vhost_dev_init(struct vhost_dev *dev,
 		vq->log = NULL;
 		vq->indirect = NULL;
 		vq->heads = NULL;
+		vq->nheads = NULL;
 		vq->dev = dev;
 		mutex_init(&vq->mutex);
 		vhost_vq_reset(dev, vq);
Signature · 1 line
2.39.5
Tested-by on v1 1/1
#4 lore raw
In reply to Jason Wang
Quoted 20 lines · Jason Wang

Commit 7918bb2d19c9 ("vhost: basic in order support") introduces vq->nheads to store the number of batched used buffers per used elem but it forgets to initialize the vq->nheads to NULL in vhost_dev_init() this will cause kfree() that would try to free it without be allocated if SET_OWNER is not called.

Fixes 7918bb2d19c9 ("vhost: basic in order support")
---
  drivers/vhost/vhost.c | 1 +
  1 file changed, 1 insertion(+)
drivers/vhost/vhost.c +0 -0
index a4873d116df1..b4dfe38c7008 100644

drivers/vhost/vhost.c void vhost_dev_init(struct vhost_dev *dev, · line 621

Quoted 7 lines
drivers/vhost/vhost.c +1 -0
@@ -615,6 +615,7 @@ void vhost_dev_init(struct vhost_dev *dev,
  		vq->log = NULL;
  		vq->indirect = NULL;
  		vq->heads = NULL;
+		vq->nheads = NULL;
  		vq->dev = dev;
  		mutex_init(&vq->mutex);
  		vhost_vq_reset(dev, vq);

checked and confirmed no crash occurs.
Thanks for the fast update.

author
#5 lore raw
In reply to Jason Wang

Hi Michael:

Quoted 11 lines · Jason Wang

Commit 7918bb2d19c9 ("vhost: basic in order support") introduces vq->nheads to store the number of batched used buffers per used elem but it forgets to initialize the vq->nheads to NULL in vhost_dev_init() this will cause kfree() that would try to free it without be allocated if SET_OWNER is not called.

Fixes 7918bb2d19c9 ("vhost: basic in order support")

I didn't see this in your pull request.

Thanks

#6 lore raw
Quoted 10 lines · Jason Wang

Hi Michael:

Quoted 7 lines · Jason Wang

Commit 7918bb2d19c9 ("vhost: basic in order support") introduces vq->nheads to store the number of batched used buffers per used elem but it forgets to initialize the vq->nheads to NULL in vhost_dev_init() this will cause kfree() that would try to free it without be allocated if SET_OWNER is not called.

Quoted 8 lines
Quoted 4 lines
Fixes 7918bb2d19c9 ("vhost: basic in order support")

I didn't see this in your pull request.

Thanks

in next now. Will be in the next pull, thanks!

Signature · 1 line
MST