Patchwork [2/2] hw/virtio/virtio-mmio: Make QueueNumMax read 0 for unavailable queues

login
register
mail settings
Submitter Peter Maydell
Date July 25, 2013, 1:37 p.m.
Message ID <1374759463-6351-3-git-send-email-peter.maydell@linaro.org>
Download mbox | patch
Permalink /patch/261700/
State New
Headers show

Comments

Peter Maydell - July 25, 2013, 1:37 p.m.
The virtio-mmio spec says that QueueNumMax must read zero for queues
which are unavailable; implement this, rather than always returning
VIRTQUEUE_MAX_SIZE.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/virtio/virtio-mmio.c |    3 +++
 1 file changed, 3 insertions(+)
Michael S. Tsirkin - July 25, 2013, 10:34 p.m.
On Thu, Jul 25, 2013 at 02:37:43PM +0100, Peter Maydell wrote:
> The virtio-mmio spec says that QueueNumMax must read zero for queues
> which are unavailable; implement this, rather than always returning
> VIRTQUEUE_MAX_SIZE.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  hw/virtio/virtio-mmio.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
> index 54d6679..aefb7e4 100644
> --- a/hw/virtio/virtio-mmio.c
> +++ b/hw/virtio/virtio-mmio.c
> @@ -151,6 +151,9 @@ static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
>          }
>          return proxy->host_features;
>      case VIRTIO_MMIO_QUEUENUMMAX:
> +        if (virtio_queue_get_num(vdev, vdev->queue_sel) == 0) {
> +            return 0;
> +        }

All other callers do:
       if (!virtio_queue_get_num(vdev, vdev->queue_sel)) {

So please make this one consistent and use the shorter form.


>          return VIRTQUEUE_MAX_SIZE;
>      case VIRTIO_MMIO_QUEUEPFN:
>          return virtio_queue_get_addr(vdev, vdev->queue_sel)
> -- 
> 1.7.9.5
Peter Maydell - July 25, 2013, 10:37 p.m.
On 25 July 2013 23:34, Michael S. Tsirkin <mst@redhat.com> wrote:
> On Thu, Jul 25, 2013 at 02:37:43PM +0100, Peter Maydell wrote:
>>      case VIRTIO_MMIO_QUEUENUMMAX:
>> +        if (virtio_queue_get_num(vdev, vdev->queue_sel) == 0) {
>> +            return 0;
>> +        }
>
> All other callers do:
>        if (!virtio_queue_get_num(vdev, vdev->queue_sel)) {
>
> So please make this one consistent and use the shorter form.

OK.

-- PMM

Patch

diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
index 54d6679..aefb7e4 100644
--- a/hw/virtio/virtio-mmio.c
+++ b/hw/virtio/virtio-mmio.c
@@ -151,6 +151,9 @@  static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
         }
         return proxy->host_features;
     case VIRTIO_MMIO_QUEUENUMMAX:
+        if (virtio_queue_get_num(vdev, vdev->queue_sel) == 0) {
+            return 0;
+        }
         return VIRTQUEUE_MAX_SIZE;
     case VIRTIO_MMIO_QUEUEPFN:
         return virtio_queue_get_addr(vdev, vdev->queue_sel)