qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 1/4] virtio: protect non-modern devices from too big virtq


From: Michael S. Tsirkin
Subject: Re: [PATCH v1 1/4] virtio: protect non-modern devices from too big virtqueue size setting
Date: Tue, 5 Nov 2019 15:56:43 -0500

On Tue, Nov 05, 2019 at 07:11:02PM +0300, Denis Plotnikov wrote:
> The patch protects from creating illegal virtio device configuration
> via direct virtqueue size property setting.
> 
> Signed-off-by: Denis Plotnikov <address@hidden>
> ---
>  hw/virtio/virtio-blk-pci.c  |  9 +++++++++
>  hw/virtio/virtio-scsi-pci.c | 10 ++++++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/hw/virtio/virtio-blk-pci.c b/hw/virtio/virtio-blk-pci.c
> index 60c9185c39..6177ff1df8 100644
> --- a/hw/virtio/virtio-blk-pci.c
> +++ b/hw/virtio/virtio-blk-pci.c
> @@ -48,6 +48,15 @@ static void virtio_blk_pci_realize(VirtIOPCIProxy 
> *vpci_dev, Error **errp)
>  {
>      VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
>      DeviceState *vdev = DEVICE(&dev->vdev);
> +    bool modern = virtio_pci_modern(vpci_dev);
> +    uint32_t queue_size = dev->vdev.conf.queue_size;
> +
> +    if (!modern && queue_size > 128) {
> +        error_setg(errp,
> +                   "too big queue size (%u, max: 128) "
> +                   "for non-modern virtio device", queue_size);
> +        return;
> +    }


this enables for transitional so still visible to legacy
interface. I am guessing you want to check whether
device is accessed through the modern interface instead.

>      if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
>          vpci_dev->nvectors = dev->vdev.conf.num_queues + 1;

> diff --git a/hw/virtio/virtio-scsi-pci.c b/hw/virtio/virtio-scsi-pci.c
> index 2830849729..6e6790fda5 100644
> --- a/hw/virtio/virtio-scsi-pci.c
> +++ b/hw/virtio/virtio-scsi-pci.c
> @@ -17,6 +17,7 @@
>  
>  #include "hw/virtio/virtio-scsi.h"
>  #include "virtio-pci.h"
> +#include "qapi/error.h"
>  
>  typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
>  
> @@ -47,6 +48,15 @@ static void virtio_scsi_pci_realize(VirtIOPCIProxy 
> *vpci_dev, Error **errp)
>      VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
>      DeviceState *proxy = DEVICE(vpci_dev);
>      char *bus_name;
> +    bool modern = virtio_pci_modern(vpci_dev);
> +    uint32_t virtqueue_size = vs->conf.virtqueue_size;
> +
> +    if (!modern && virtqueue_size > 128) {
> +        error_setg(errp,
> +                   "too big virtqueue size (%u, max: 128) "
> +                   "for non-modern virtio device", virtqueue_size);
> +        return;
> +    }

why? what is illegal about 256 for legacy?

>  
>      if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
>          vpci_dev->nvectors = vs->conf.num_queues + 3;
> -- 
> 2.17.0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]