diff mbox series

[v2,2/4] hw/virtio: gracefully handle unset vhost_dev vdev

Message ID 20220728135503.1060062-3-alex.bennee@linaro.org
State Superseded
Headers show
Series virtio fixes (split from virtio-gpio series) | expand

Commit Message

Alex Bennée July 28, 2022, 1:55 p.m. UTC
I've noticed asserts firing because we query the status of vdev after
a vhost connection is closed down. Rather than faulting on the NULL
indirect just quietly reply false.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20220726192150.2435175-8-alex.bennee@linaro.org>
---
 hw/virtio/vhost.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Michael S. Tsirkin Aug. 17, 2022, 11:01 a.m. UTC | #1
On Thu, Jul 28, 2022 at 02:55:01PM +0100, Alex Bennée wrote:
> I've noticed asserts firing because we query the status of vdev after
> a vhost connection is closed down. Rather than faulting on the NULL
> indirect just quietly reply false.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Message-Id: <20220726192150.2435175-8-alex.bennee@linaro.org>

Please do not include this header when you post.


> ---
>  hw/virtio/vhost.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
> index 0827d631c0..f758f177bb 100644
> --- a/hw/virtio/vhost.c
> +++ b/hw/virtio/vhost.c
> @@ -306,7 +306,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size)
>      dev->log_size = size;
>  }
>  
> -static int vhost_dev_has_iommu(struct vhost_dev *dev)
> +static bool vhost_dev_has_iommu(struct vhost_dev *dev)
>  {
>      VirtIODevice *vdev = dev->vdev;
>  
> @@ -316,8 +316,12 @@ static int vhost_dev_has_iommu(struct vhost_dev *dev)
>       * does not have IOMMU, there's no need to enable this feature
>       * which may cause unnecessary IOTLB miss/update transactions.
>       */
> -    return virtio_bus_device_iommu_enabled(vdev) &&
> -           virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
> +    if (vdev) {
> +        return virtio_bus_device_iommu_enabled(vdev) &&
> +            virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
> +    } else {
> +        return false;
> +    }
>  }
>  
>  static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr,
> -- 
> 2.30.2
Alex Bennée Aug. 18, 2022, 6:35 a.m. UTC | #2
"Michael S. Tsirkin" <mst@redhat.com> writes:

> On Thu, Jul 28, 2022 at 02:55:01PM +0100, Alex Bennée wrote:
>> I've noticed asserts firing because we query the status of vdev after
>> a vhost connection is closed down. Rather than faulting on the NULL
>> indirect just quietly reply false.
>> 
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Message-Id: <20220726192150.2435175-8-alex.bennee@linaro.org>
>
> Please do not include this header when you post.

What the message id? It's added by b4 to track when the message was last
posted. On my PRs I often have two message id's, one from the series
where I picked it up and one from the last time my series was posted. I
usually only edit them down so I'm not repeating it for each iteration
of a series.

>
>
>> ---
>>  hw/virtio/vhost.c | 10 +++++++---
>>  1 file changed, 7 insertions(+), 3 deletions(-)
>> 
>> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
>> index 0827d631c0..f758f177bb 100644
>> --- a/hw/virtio/vhost.c
>> +++ b/hw/virtio/vhost.c
>> @@ -306,7 +306,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size)
>>      dev->log_size = size;
>>  }
>>  
>> -static int vhost_dev_has_iommu(struct vhost_dev *dev)
>> +static bool vhost_dev_has_iommu(struct vhost_dev *dev)
>>  {
>>      VirtIODevice *vdev = dev->vdev;
>>  
>> @@ -316,8 +316,12 @@ static int vhost_dev_has_iommu(struct vhost_dev *dev)
>>       * does not have IOMMU, there's no need to enable this feature
>>       * which may cause unnecessary IOTLB miss/update transactions.
>>       */
>> -    return virtio_bus_device_iommu_enabled(vdev) &&
>> -           virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
>> +    if (vdev) {
>> +        return virtio_bus_device_iommu_enabled(vdev) &&
>> +            virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
>> +    } else {
>> +        return false;
>> +    }
>>  }
>>  
>>  static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr,
>> -- 
>> 2.30.2
diff mbox series

Patch

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 0827d631c0..f758f177bb 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -306,7 +306,7 @@  static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size)
     dev->log_size = size;
 }
 
-static int vhost_dev_has_iommu(struct vhost_dev *dev)
+static bool vhost_dev_has_iommu(struct vhost_dev *dev)
 {
     VirtIODevice *vdev = dev->vdev;
 
@@ -316,8 +316,12 @@  static int vhost_dev_has_iommu(struct vhost_dev *dev)
      * does not have IOMMU, there's no need to enable this feature
      * which may cause unnecessary IOTLB miss/update transactions.
      */
-    return virtio_bus_device_iommu_enabled(vdev) &&
-           virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
+    if (vdev) {
+        return virtio_bus_device_iommu_enabled(vdev) &&
+            virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
+    } else {
+        return false;
+    }
 }
 
 static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr,