Skip to contentSkip to conversation

vdpa: Protect vdpa reset with cf_mutex

PATCH Si-Wei Liu 2 participants 3 messages Jan 11, 2022 2 messages not in the archive virtio core

lore
Share & tools
lore

Si-Wei Liu

author Reviewed-by
#1 lore raw
In reply to a message not in the archive
Quoted 13 lines · Eli Cohen

Call reset using the wrapper function vdpa_reset() to make sure the operation is serialized with cf_mutex.

---
  drivers/vhost/vdpa.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vhost/vdpa.c +0 -0
index 6e7edaf2472b..fe0bbea4dab6 100644

drivers/vhost/vdpa.c static long vhost_vdpa_get_status(struct vhost_vdpa *v, u8 __user *statusp) · line 158

Quoted 4 lines
drivers/vhost/vdpa.c +0 -1
@@ -155,7 +155,6 @@ static long vhost_vdpa_get_status(struct vhost_vdpa *v, u8 __user *statusp)
  static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
  {
  	struct vdpa_device *vdpa = v->vdpa;
-	const struct vdpa_config_ops *ops = vdpa->config;

It is okay to remove this line from the patch, but a follow-up patch to remove the locking for get_status would need to reintroduce the same line. If possible please try post these two together in a same series.

drivers/vhost/vdpa.c static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp) · line 182

Quoted 12 lines
drivers/vhost/vdpa.c +1 -1
  	u8 status, status_old;
  	int ret, nvqs = v->nvqs;
  	u16 i;
@@ -177,7 +176,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
  			vhost_vdpa_unsetup_vq_irq(v, i);
 
  	if (status == 0) {
-		ret = ops->reset(vdpa);
+		ret = vdpa_reset(vdpa);
  		if (ret)
  			return ret;
  	} else

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

#2 lore raw
In reply to a message not in the archive
Quoted 4 lines · Eli Cohen

Call reset using the wrapper function vdpa_reset() to make sure the operation is serialized with cf_mutex.

The motivation is vague here, this does not really explain. Which operations are we trying to serialize? Multiple reset requests from userspace?
Is anything broken right now without this patch?

Quoted 27 lines
---
 drivers/vhost/vdpa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vhost/vdpa.c +1 -2
index 6e7edaf2472b..fe0bbea4dab6 100644
@@ -155,7 +155,6 @@ static long vhost_vdpa_get_status(struct vhost_vdpa *v, u8 __user *statusp)
 static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
 {
 	struct vdpa_device *vdpa = v->vdpa;
-	const struct vdpa_config_ops *ops = vdpa->config;
 	u8 status, status_old;
 	int ret, nvqs = v->nvqs;
 	u16 i;
@@ -177,7 +176,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
 			vhost_vdpa_unsetup_vq_irq(v, i);
 
 	if (status == 0) {
-		ret = ops->reset(vdpa);
+		ret = vdpa_reset(vdpa);
 		if (ret)
 			return ret;
 	} else
Signature · 1 line
2.34.1

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

#4 lore raw
In reply to a message not in the archive
Quoted 7 lines · Eli Cohen
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines · Eli Cohen

Call reset using the wrapper function vdpa_reset() to make sure the operation is serialized with cf_mutex.

Quoted 8 lines
Quoted 4 lines

The motivation is vague here, this does not really explain. Which operations are we trying to serialize? Multiple reset requests from userspace?
Is anything broken right now without this patch?

vdpa_reset will reset the features which can be read or even be set through devlink (see vdpa_get_config_unlocked()). So this lock ensures serialization of the operations to ensure consitent value is read.

My point is that this is the kind of thing that needs to go into commit log. A good log for a bugfix looks like this:

if XYZ triggers a vdpa reset while ABC is reading the features through devlink, with the result that EFG. Similarly for write which can lead to HIJ.

Fix this by calling reset using the wrapper function vdpa_reset() to make sure the operation is serialized with cf_mutex.

Fixes <hash> ("subject")
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
---
 drivers/vhost/vdpa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vhost/vdpa.c +0 -1
index 6e7edaf2472b..fe0bbea4dab6 100644
@@ -155,7 +155,6 @@ static long vhost_vdpa_get_status(struct vhost_vdpa *v, u8 __user *statusp)
 static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
 {
 	struct vdpa_device *vdpa = v->vdpa;
-	const struct vdpa_config_ops *ops = vdpa->config;
 	u8 status, status_old;
 	int ret, nvqs = v->nvqs;
 	u16 i;
@@ -177,7 +176,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
 			vhost_vdpa_unsetup_vq_irq(v, i);
 
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/vhost/vdpa.c +1 -1
 	if (status == 0) {
-		ret = ops->reset(vdpa);
+		ret = vdpa_reset(vdpa);
 		if (ret)
 			return ret;
 	} else
Signature · 1 line
2.34.1

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