Skip to contentSkip to conversation

virtio-vdpa: Fix unchecked call to NULL set_vq_affinity

PATCH Applied Dragos Tatulea 4 participants 11 messages May 4, 2023 – Jun 2, 2023 virtio core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-vdpa: Fix unchecked call to NULL set_vq_affinity

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading mechanism")
---
 drivers/virtio/virtio_vdpa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_vdpa.c +3 -1
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
 			err = PTR_ERR(vqs[i]);
 			goto err_setup_vq;
 		}
-		ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+		if (ops->set_vq_affinity)
+			ops->set_vq_affinity(vdpa, i, &masks[i]);
 	}
 
 	cb.callback = virtio_vdpa_config_cb;
Signature · 6 lines
2.40.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#1 lore raw
Quoted 18 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading mechanism")
---
  drivers/virtio/virtio_vdpa.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_vdpa.c +0 -0
index eb6aee8c06b2..989e2d7184ce 100644

drivers/virtio/virtio_vdpa.c static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs, · line 390

Quoted 7 lines
drivers/virtio/virtio_vdpa.c +3 -1
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
                         err = PTR_ERR(vqs[i]);
                         goto err_setup_vq;
                 }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);

if ops->set_vq_affinity is NULL, should give an error code to err, and return err

Quoted 6 lines
drivers/virtio/virtio_vdpa.c +0 -1
         }
 
         cb.callback = virtio_vdpa_config_cb;
--

2.40.1

#2 lore raw
Quoted 17 lines · Feng Liu
Quoted 14 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading

mechanism")

---
  drivers/virtio/virtio_vdpa.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 16 lines

drivers/virtio/virtio_vdpa.c static int virtio_vdpa_find_vqs(struct virtio_device · line 391

Quoted 13 lines
drivers/virtio/virtio_vdpa.c +3 -1
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device
 *vdev, unsigned int nvqs,
                          err = PTR_ERR(vqs[i]);
                          goto err_setup_vq;
                  }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);

if ops->set_vq_affinity is NULL, should give an error code to err, and return err

I don't think so: the set_vq_affinity is marked as optional.

Quoted 6 lines
Quoted 6 lines
drivers/virtio/virtio_vdpa.c +0 -0
          }
 

         cb.callback = virtio_vdpa_config_cb;
--
2.40.1

#3 lore raw
Quoted 34 lines · Dragos Tatulea
Quoted 17 lines · Feng Liu
Quoted 14 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading

mechanism")

---
   drivers/virtio/virtio_vdpa.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 16 lines

drivers/virtio/virtio_vdpa.c static int virtio_vdpa_find_vqs(struct virtio_device · line 391

Quoted 13 lines
drivers/virtio/virtio_vdpa.c +3 -1
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device
 *vdev, unsigned int nvqs,
                          err = PTR_ERR(vqs[i]);
                          goto err_setup_vq;
                  }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);

if ops->set_vq_affinity is NULL, should give an error code to err, and return err

Quoted 2 lines

I don't think so: the set_vq_affinity is marked as optional.

Yes, I see

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
drivers/virtio/virtio_vdpa.c +0 -0
          }
 

         cb.callback = virtio_vdpa_config_cb;
--
2.40.1

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

#4 lore raw
In reply to Feng Liu
Quoted 16 lines · Feng Liu
Quoted 13 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading mechanism")
---
  drivers/virtio/virtio_vdpa.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/virtio/virtio_vdpa.c static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs, · line 390

Quoted 12 lines
drivers/virtio/virtio_vdpa.c +3 -1
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
                         err = PTR_ERR(vqs[i]);
                         goto err_setup_vq;
                 }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);

if ops->set_vq_affinity is NULL, should give an error code to err, and return err

Given we ignore return code, hardly seems like a critical thing to do. Is it really important? affinity is an optimization isn't it?

Quoted 6 lines
Quoted 6 lines
drivers/virtio/virtio_vdpa.c +0 -1
         }
 
         cb.callback = virtio_vdpa_config_cb;
--

2.40.1

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

#5 lore raw
Quoted 35 lines · Michael S. Tsirkin

External email: Use caution opening links or attachments

Quoted 16 lines · Feng Liu
Quoted 13 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading mechanism")
---
   drivers/virtio/virtio_vdpa.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/virtio/virtio_vdpa.c static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs, · line 390

Quoted 12 lines
drivers/virtio/virtio_vdpa.c +3 -1
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
                          err = PTR_ERR(vqs[i]);
                          goto err_setup_vq;
                  }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);

if ops->set_vq_affinity is NULL, should give an error code to err, and return err

Quoted 3 lines

Given we ignore return code, hardly seems like a critical thing to do. Is it really important? affinity is an optimization isn't it?

Yes, it is an optimization, got it.

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
drivers/virtio/virtio_vdpa.c +0 -1
          }
 
          cb.callback = virtio_vdpa_config_cb;
--

2.40.1

#6 lore raw
In reply to Michael S. Tsirkin
Quoted 34 lines · Michael S. Tsirkin
Quoted 17 lines · Feng Liu
Quoted 14 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading

mechanism")

---
  drivers/virtio/virtio_vdpa.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 15 lines

drivers/virtio/virtio_vdpa.c static int virtio_vdpa_find_vqs(struct virtio_device · line 391

Quoted 13 lines
drivers/virtio/virtio_vdpa.c +3 -1
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device
 *vdev, unsigned int nvqs,
                          err = PTR_ERR(vqs[i]);
                          goto err_setup_vq;
                  }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);

if ops->set_vq_affinity is NULL, should give an error code to err, and return err

Quoted 4 lines

Given we ignore return code, hardly seems like a critical thing to do. Is it really important? affinity is an optimization isn't it?

Quoted 1 line
Quoted 1 line

set_vq_affinity is optional so it's not an error if the op is not implemented.

Is there anything else that needs to be done for this fix?

Thanks,
Dragos

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

#7 lore raw
Quoted 39 lines · Dragos Tatulea
Quoted 34 lines · Michael S. Tsirkin
Quoted 17 lines · Feng Liu
Quoted 14 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading

mechanism")

---
  drivers/virtio/virtio_vdpa.c | 4 +++-

  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 15 lines

drivers/virtio/virtio_vdpa.c static int virtio_vdpa_find_vqs(struct virtio_device · line 391

Quoted 13 lines
drivers/virtio/virtio_vdpa.c +3 -1
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device
 *vdev, unsigned int nvqs,
                          err = PTR_ERR(vqs[i]);
                          goto err_setup_vq;
                  }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);

if ops->set_vq_affinity is NULL, should give an error code to err, and return err

Quoted 4 lines

Given we ignore return code, hardly seems like a critical thing to do. Is it really important? affinity is an optimization isn't it?

Quoted 1 line
Quoted 1 line
Quoted 7 lines

set_vq_affinity is optional so it's not an error if the op is not implemented.

Is there anything else that needs to be done for this fix?

Thanks,
Dragos

no, it's queued already.

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

#8 lore raw
Quoted 43 lines · Michael S. Tsirkin
Quoted 41 lines · Dragos Tatulea
Quoted 34 lines · Michael S. Tsirkin
Quoted 17 lines · Feng Liu
Quoted 14 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading

mechanism")

---
   drivers/virtio/virtio_vdpa.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 15 lines

drivers/virtio/virtio_vdpa.c static int virtio_vdpa_find_vqs(struct virtio_device · line 391

Quoted 13 lines
drivers/virtio/virtio_vdpa.c +3 -1
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device
 *vdev, unsigned int nvqs,
                          err = PTR_ERR(vqs[i]);
                          goto err_setup_vq;
                  }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);

if ops->set_vq_affinity is NULL, should give an error code to err, and return err

Quoted 4 lines

Given we ignore return code, hardly seems like a critical thing to do. Is it really important? affinity is an optimization isn't it?

Quoted 1 line
Quoted 1 line

set_vq_affinity is optional so it's not an error if the op is not implemented.

Quoted 7 lines
Quoted 5 lines

Is there anything else that needs to be done for this fix?

Thanks,
Dragos

no, it's queued already.

Are these queued into a repo that is accessible? I haven't seen activity in the vhost.git where I would have expected it. After stumbling over and debugging this same problem, I was happy to see it fixed, and I'd like to pull from a repo that has the current updates.

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

maintainer Applied
#9 lore raw
Quoted 52 lines · Shannon Nelson
Quoted 43 lines · Michael S. Tsirkin
Quoted 41 lines · Dragos Tatulea
Quoted 34 lines · Michael S. Tsirkin
Quoted 17 lines · Feng Liu
Quoted 14 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading

mechanism")

---
   drivers/virtio/virtio_vdpa.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 15 lines

drivers/virtio/virtio_vdpa.c static int virtio_vdpa_find_vqs(struct virtio_device · line 391

Quoted 13 lines
drivers/virtio/virtio_vdpa.c +3 -1
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device
 *vdev, unsigned int nvqs,
                          err = PTR_ERR(vqs[i]);
                          goto err_setup_vq;
                  }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);

if ops->set_vq_affinity is NULL, should give an error code to err, and return err

Quoted 4 lines

Given we ignore return code, hardly seems like a critical thing to do. Is it really important? affinity is an optimization isn't it?

Quoted 1 line
Quoted 1 line

set_vq_affinity is optional so it's not an error if the op is not implemented.

Quoted 7 lines
Quoted 5 lines

Is there anything else that needs to be done for this fix?

Thanks,
Dragos

no, it's queued already.

Quoted 7 lines

Are these queued into a repo that is accessible? I haven't seen activity in the vhost.git where I would have expected it. After stumbling over and debugging this same problem, I was happy to see it fixed, and I'd like to pull from a repo that has the current updates.

Thanks,
sln

Pushed to next now.

Signature · 6 lines
MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Reviewed-by on v1 1/1
#10 lore raw
In reply to Dragos Tatulea
Quoted 10 lines · Dragos Tatulea

External email: Use caution opening links or attachments

The referenced patch calls set_vq_affinity without checking if the op is valid. This patch adds the check.

Fixes 3dad56823b53 ("virtio-vdpa: Support interrupt affinity spreading mechanism")

---

Quoted 19 lines
  drivers/virtio/virtio_vdpa.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_vdpa.c +3 -2
index eb6aee8c06b2..989e2d7184ce 100644
@@ -385,7 +385,9 @@ static int virtio_vdpa_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
                         err = PTR_ERR(vqs[i]);
                         goto err_setup_vq;
                 }
-               ops->set_vq_affinity(vdpa, i, &masks[i]);
+
+               if (ops->set_vq_affinity)
+                       ops->set_vq_affinity(vdpa, i, &masks[i]);
         }
 
         cb.callback = virtio_vdpa_config_cb;
--
Quoted 2 lines

2.40.1

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