Patchwork virtio-serial: Check if more max_ports specified than we can handle

login
register
mail settings
Submitter Amit Shah
Date July 21, 2010, 9:38 a.m.
Message ID <ac3adb4808572fd77ebbd50485898851d215153b.1279705091.git.amit.shah@redhat.com>
Download mbox | patch
Permalink /patch/59426/
State New
Headers show

Comments

Amit Shah - July 21, 2010, 9:38 a.m.
Currently virtio-serial supports a maximum of 31 ports. Specifying the
'max_ports' parameter to be > 31 on the cmd line causes badness.

Ensure we initialise virtio-serial only if max_ports is within the
supported range.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 hw/virtio-serial-bus.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
Aurelien Jarno - July 30, 2010, 9:01 p.m.
On Wed, Jul 21, 2010 at 03:08:30PM +0530, Amit Shah wrote:
> Currently virtio-serial supports a maximum of 31 ports. Specifying the
> 'max_ports' parameter to be > 31 on the cmd line causes badness.
> 
> Ensure we initialise virtio-serial only if max_ports is within the
> supported range.
> 
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
> ---
>  hw/virtio-serial-bus.c |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)

Thanks, applied.

> diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
> index 8e611c0..0586b89 100644
> --- a/hw/virtio-serial-bus.c
> +++ b/hw/virtio-serial-bus.c
> @@ -734,11 +734,19 @@ VirtIODevice *virtio_serial_init(DeviceState *dev, uint32_t max_nr_ports)
>  {
>      VirtIOSerial *vser;
>      VirtIODevice *vdev;
> -    uint32_t i;
> +    uint32_t i, max_supported_ports;
>  
>      if (!max_nr_ports)
>          return NULL;
>  
> +    /* Each port takes 2 queues, and one pair is for the control queue */
> +    max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1;
> +
> +    if (max_nr_ports > max_supported_ports) {
> +        error_report("maximum ports supported: %u", max_supported_ports);
> +        return NULL;
> +    }
> +
>      vdev = virtio_common_init("virtio-serial", VIRTIO_ID_CONSOLE,
>                                sizeof(struct virtio_console_config),
>                                sizeof(VirtIOSerial));
> -- 
> 1.7.1.1
> 
> 
>

Patch

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 8e611c0..0586b89 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -734,11 +734,19 @@  VirtIODevice *virtio_serial_init(DeviceState *dev, uint32_t max_nr_ports)
 {
     VirtIOSerial *vser;
     VirtIODevice *vdev;
-    uint32_t i;
+    uint32_t i, max_supported_ports;
 
     if (!max_nr_ports)
         return NULL;
 
+    /* Each port takes 2 queues, and one pair is for the control queue */
+    max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1;
+
+    if (max_nr_ports > max_supported_ports) {
+        error_report("maximum ports supported: %u", max_supported_ports);
+        return NULL;
+    }
+
     vdev = virtio_common_init("virtio-serial", VIRTIO_ID_CONSOLE,
                               sizeof(struct virtio_console_config),
                               sizeof(VirtIOSerial));