From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16BA8C07E96 for ; Tue, 6 Jul 2021 08:39:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C9CDA61988 for ; Tue, 6 Jul 2021 08:39:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9CDA61988 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0gbz-00085X-Rm for qemu-devel@archiver.kernel.org; Tue, 06 Jul 2021 04:39:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRs-0002hg-5B for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53905) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0gRo-00033T-UN for qemu-devel@nongnu.org; Tue, 06 Jul 2021 04:28:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625560132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oJKBKdAaOavCFEs8ktlHnyZoxvvuEkTCPfF8ZHgd/9s=; b=S5MhGB7VmObMJn/zzSB8/0hr6bUby3UA+PNbPbQc9JKv4PYdQwykJYyxiFcf0suKsrJE38 b5v5glHvzMiGAmiJgmEmz3jwYg7SHy8xLn4X+TDv8+L2l0RV0Ob+07t4BbihV/f7Obfem5 6XnHLj0/3sXSPH39LKfVQflxtlQOeoU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-372-U0GiZGjANmG3ipoZLeD50g-1; Tue, 06 Jul 2021 04:28:51 -0400 X-MC-Unique: U0GiZGjANmG3ipoZLeD50g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 38CAA100C661; Tue, 6 Jul 2021 08:28:50 +0000 (UTC) Received: from localhost.localdomain (ovpn-13-227.pek2.redhat.com [10.72.13.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C12A2EB19; Tue, 6 Jul 2021 08:28:43 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, mst@redhat.com, jasowang@redhat.com Subject: [PATCH V2 17/18] virtio-net: vhost control virtqueue support Date: Tue, 6 Jul 2021 16:27:16 +0800 Message-Id: <20210706082717.37730-18-jasowang@redhat.com> In-Reply-To: <20210706082717.37730-1-jasowang@redhat.com> References: <20210706082717.37730-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eperezma@redhat.com, elic@nvidia.com, lingshan.zhu@intel.com, lulu@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This patch implements the control virtqueue support for vhost. This requires virtio-net to figure out the datapath queue pairs and control virtqueue via is_datapath and pass the number of those two types of virtqueues to vhost_net_start()/vhost_net_stop(). Signed-off-by: Jason Wang --- hw/net/virtio-net.c | 21 ++++++++++++++++++--- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 36bd197087..f003687579 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -244,6 +244,7 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) VirtIODevice *vdev = VIRTIO_DEVICE(n); NetClientState *nc = qemu_get_queue(n->nic); int qps = n->multiqueue ? n->max_qps : 1; + int cvq = n->max_ncs - n->max_qps; if (!get_vhost_net(nc->peer)) { return; @@ -285,14 +286,14 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) } n->vhost_started = 1; - r = vhost_net_start(vdev, n->nic->ncs, qps, 0); + r = vhost_net_start(vdev, n->nic->ncs, qps, cvq); if (r < 0) { error_report("unable to start vhost net: %d: " "falling back on userspace virtio", -r); n->vhost_started = 0; } } else { - vhost_net_stop(vdev, n->nic->ncs, qps, 0); + vhost_net_stop(vdev, n->nic->ncs, qps, cvq); n->vhost_started = 0; } } @@ -3367,7 +3368,21 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) return; } - n->max_qps = MAX(n->nic_conf.peers.queues, 1); + n->max_ncs = MAX(n->nic_conf.peers.queues, 1); + + /* + * Figure out the datapath queue pairs since the backend could + * provide control queue via peers as well. + */ + if (n->nic_conf.peers.queues) { + for (i = 0; i < n->max_ncs; i++) { + if (n->nic_conf.peers.ncs[i]->is_datapath) { + ++n->max_qps; + } + } + } + n->max_qps = MAX(n->max_qps, 1); + if (n->max_qps * 2 + 1 > VIRTIO_QUEUE_MAX) { error_setg(errp, "Invalid number of qps (= %" PRIu32 "), " "must be a positive integer less than %d.", diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index a9b6dc252e..ed4659c189 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -194,6 +194,7 @@ struct VirtIONet { NICConf nic_conf; DeviceState *qdev; int multiqueue; + uint16_t max_ncs; uint16_t max_qps; uint16_t curr_qps; size_t config_size; -- 2.25.1