From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFId5-0000ws-J7 for qemu-devel@nongnu.org; Wed, 15 Jul 2015 05:05:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFIcz-0002tC-1i for qemu-devel@nongnu.org; Wed, 15 Jul 2015 05:05:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57985) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFIcy-0002sq-QJ for qemu-devel@nongnu.org; Wed, 15 Jul 2015 05:05:20 -0400 Message-ID: <55A6224B.8020203@redhat.com> Date: Wed, 15 Jul 2015 17:05:15 +0800 From: Jason Wang MIME-Version: 1.0 References: <55A617E9.9080503@cn.fujitsu.com> <55A61CE1.2040200@redhat.com> <55A6222D.1040908@cn.fujitsu.com> In-Reply-To: <55A6222D.1040908@cn.fujitsu.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 for-2.4] virtio-net: remove virtio queues if the guest doesn't support multiqueue List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wen Congyang , qemu-devl , "Michael S. Tsirkin" Cc: Fam Zheng , Stefan Hajnoczi On 07/15/2015 05:04 PM, Wen Congyang wrote: > On 07/15/2015 04:42 PM, Jason Wang wrote: >> >=20 >> >=20 >> > On 07/15/2015 04:20 PM, Wen Congyang wrote: >>> >> commit da51a335 adds all queues in .realize(). But if the >>> >> guest doesn't support multiqueue, we forget to remove them. And >>> >> we cannot handle the ctrl vq corretly. The guest will hang. >>> >> >>> >> Signed-off-by: Wen Congyang >>> >> --- >>> >> hw/net/virtio-net.c | 93 ++++++++++++++++++++++++++++++++++++++++= ++++--------- >>> >> 1 file changed, 78 insertions(+), 15 deletions(-) >>> >> >>> >> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c >>> >> index e3c2db3..48c7705 100644 >>> >> --- a/hw/net/virtio-net.c >>> >> +++ b/hw/net/virtio-net.c >>> >> @@ -1306,9 +1306,86 @@ static void virtio_net_tx_bh(void *opaque) >>> >> } >>> >> } >>> >> =20 >>> >> +static void virtio_net_add_queue(VirtIONet *n, int index) >>> >> +{ >>> >> + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); >>> >> + >>> >> + n->vqs[index].rx_vq =3D virtio_add_queue(vdev, 256, virtio_ne= t_handle_rx); >>> >> + if (n->net_conf.tx && !strcmp(n->net_conf.tx, "timer")) { >>> >> + n->vqs[index].tx_vq =3D >>> >> + virtio_add_queue(vdev, 256, virtio_net_handle_tx_time= r); >>> >> + n->vqs[index].tx_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUA= L, >>> >> + virtio_net_tx_timer= , >>> >> + &n->vqs[index]); >>> >> + } else { >>> >> + n->vqs[index].tx_vq =3D >>> >> + virtio_add_queue(vdev, 256, virtio_net_handle_tx_bh); >>> >> + n->vqs[index].tx_bh =3D qemu_bh_new(virtio_net_tx_bh, &n-= >vqs[index]); >>> >> + } >>> >> + >>> >> + n->vqs[index].tx_waiting =3D 0; >>> >> + n->vqs[index].n =3D n; >>> >> +} >>> >> + >>> >> +static void virtio_net_del_queue(VirtIONet *n, int index) >>> >> +{ >>> >> + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); >>> >> + VirtIONetQueue *q =3D &n->vqs[index]; >>> >> + NetClientState *nc =3D qemu_get_subqueue(n->nic, index); >>> >> + >>> >> + qemu_purge_queued_packets(nc); >>> >> + >>> >> + virtio_del_queue(vdev, index * 2); >>> >> + if (q->tx_timer) { >>> >> + timer_del(q->tx_timer); >>> >> + timer_free(q->tx_timer); >>> >> + } else { >>> >> + qemu_bh_delete(q->tx_bh); >>> >> + } >>> >> + virtio_del_queue(vdev, index * 2 + 1); >>> >> +} >> >=20 >> > Ok, then in unrealize() you may just want to delete bhs/timers up to >> > curr_queues. Otherwise it may cause a use after free? > One question: If the max_queues in qemu is 3, and the guest set queues = to 2. > which vq is ctrl vq? vq[4] or vq[6]? Spec (5.1.2) said " 0 receiveq1 1 transmitq1 =E2=80=A6 2N receiveqN 2N+1 transmitqN 2N+2 controlq N=3D1 if VIRTIO_NET_F_MQ is not negotiated, otherwise N is set by max_virtqueue_pairs. " So should be 6. > Thanks > Wen Congyang >