From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2U4y-000584-7H for qemu-devel@nongnu.org; Thu, 25 Jul 2013 18:32:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2U4v-0007Y4-RM for qemu-devel@nongnu.org; Thu, 25 Jul 2013 18:32:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4133) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2U4v-0007Wc-JR for qemu-devel@nongnu.org; Thu, 25 Jul 2013 18:32:09 -0400 Date: Fri, 26 Jul 2013 01:33:17 +0300 From: "Michael S. Tsirkin" Message-ID: <20130725223317.GA28632@redhat.com> References: <1374759463-6351-1-git-send-email-peter.maydell@linaro.org> <1374759463-6351-2-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1374759463-6351-2-git-send-email-peter.maydell@linaro.org> Subject: Re: [Qemu-devel] [PATCH 1/2] hw/virtio/virtio: Don't allow guests to add/remove queues List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Anthony Liguori , KONRAD Frederic , kvmarm@lists.cs.columbia.edu, qemu-devel@nongnu.org, patches@linaro.org On Thu, Jul 25, 2013 at 02:37:42PM +0100, Peter Maydell wrote: > A queue size of 0 is used to indicate a nonexistent queue, so > don't allow the guest to flip a queue between zero-size and > non-zero-size. Don't permit setting of negative queue sizes > either. > > Signed-off-by: Peter Maydell > --- > hw/virtio/virtio.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c > index 09f62c6..d5b0502 100644 > --- a/hw/virtio/virtio.c > +++ b/hw/virtio/virtio.c > @@ -673,10 +673,14 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n) > > void virtio_queue_set_num(VirtIODevice *vdev, int n, int num) > { > - if (num <= VIRTQUEUE_MAX_SIZE) { > - vdev->vq[n].vring.num = num; > - virtqueue_init(&vdev->vq[n]); > + if ((num == 0 && vdev->vq[n].vring.num != 0) || > + (num != 0 && vdev->vq[n].vring.num == 0) || Cleaner (imho) !num != !vdev->vq[n].vring.num > + (num > VIRTQUEUE_MAX_SIZE) || Pls don't put () around simple math. It has natural precedence wrt <> so it just makes it look like lisp. > + (num < 0)) { How does it ever get negative? assert (num >= 0) instead? > + return; > } > + vdev->vq[n].vring.num = num; > + virtqueue_init(&vdev->vq[n]); > } > > int virtio_queue_get_num(VirtIODevice *vdev, int n) > -- > 1.7.9.5