From nobody Fri May 3 21:54:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499110229074150.64635918497208; Mon, 3 Jul 2017 12:30:29 -0700 (PDT) Received: from localhost ([::1]:36907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dS73D-0000QZ-Gt for importer@patchew.org; Mon, 03 Jul 2017 15:30:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dS72M-0008KL-66 for qemu-devel@nongnu.org; Mon, 03 Jul 2017 15:29:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dS72J-0000zB-30 for qemu-devel@nongnu.org; Mon, 03 Jul 2017 15:29:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55190) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dS72I-0000ym-TO for qemu-devel@nongnu.org; Mon, 03 Jul 2017 15:29:31 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDDA7C049E32; Mon, 3 Jul 2017 19:29:29 +0000 (UTC) Received: from redhat.com (ovpn-120-211.rdu2.redhat.com [10.10.120.211]) by smtp.corp.redhat.com (Postfix) with SMTP id 523EB5D9C9; Mon, 3 Jul 2017 19:29:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BDDA7C049E32 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mst@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BDDA7C049E32 Date: Mon, 3 Jul 2017 22:29:28 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1499110159-15894-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 03 Jul 2017 19:29:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] virtio-net: fix tx queue size for !vhost-user X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wei Wang , Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Current code segfaults when no nic peer is specified. Fix it up - fall back to default queue size. Fixes: 526e8fa8b872 ("virtio-net: enable configurable tx queue size") Cc: Wei Wang Signed-off-by: Michael S. Tsirkin --- hw/net/virtio-net.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index a1fc0db..5630a9e 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -498,6 +498,24 @@ static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, i= nt mergeable_rx_bufs, } } =20 +static int virtio_net_max_tx_queue_size(VirtIONet *n) +{ + NetClientState *peer =3D n->nic_conf.peers.ncs[0]; + + /* + * Backends other than vhost-user don't support max queue size. + */ + if (!peer) { + return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; + } + + if (peer->info->type !=3D NET_CLIENT_DRIVER_VHOST_USER) { + return VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; + } + + return VIRTQUEUE_MAX_SIZE; +} + static int peer_attach(VirtIONet *n, int index) { NetClientState *nc =3D qemu_get_subqueue(n->nic, index); @@ -1964,14 +1982,8 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) error_report("Defaulting to \"bh\""); } =20 - /* - * Currently, backends other than vhost-user don't support 1024 queue - * size. - */ - if (n->net_conf.tx_queue_size =3D=3D VIRTQUEUE_MAX_SIZE && - n->nic_conf.peers.ncs[0]->info->type !=3D NET_CLIENT_DRIVER_VHOST_= USER) { - n->net_conf.tx_queue_size =3D VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE; - } + n->net_conf.tx_queue_size =3D MIN(virtio_net_max_tx_queue_size(n), + n->net_conf.tx_queue_size); =20 for (i =3D 0; i < n->max_queues; i++) { virtio_net_add_queue(n, i); --=20 MST