From nobody Mon Feb 9 04:14:56 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1667221969; cv=none; d=zohomail.com; s=zohoarc; b=BzI1LShsTYezSEAsH06JGUx1zn1SFTWLMHe4WHkwSDh44ZBq4nDn5p5RqZ+Hu7x2oE8Z5GI06vf4LpgUIayf6CeIjAcBnRDg4MdQgRZuqKRSUg6K7CniPgAAKPfCm0cb0cU4snd5f7B1KcZV3UZ/WMe+UM/Vn1P5apJsMj2j0TY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667221969; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=k3h2/R6ixFTO5bNpkZpGb1wFDhh1s402BZASy50X1Mk=; b=ZpxRzPgxQL+06XaqiMcwH9k+57zjfgZl0a7Ge3YMCkL91qVzESL5MldwEbO6UUXdJUVOtFxUmFtTrk2Ps85OBiL3QwW85jZ7Axe64kpRwb7mfTaLuruoYyFQrc0CVA+OihtsxQ5I5jO05zKmHds02hEd8aTOpwYw0Y1H89sqRqQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1667221969832199.74214133779253; Mon, 31 Oct 2022 06:12:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opUII-0001by-3A; Mon, 31 Oct 2022 08:53:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opUHm-00079C-Lw for qemu-devel@nongnu.org; Mon, 31 Oct 2022 08:53:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opUHk-0002tJ-SP for qemu-devel@nongnu.org; Mon, 31 Oct 2022 08:53:02 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-495-DrwydJs7NKaV0WrIm74f7A-1; Mon, 31 Oct 2022 08:52:58 -0400 Received: by mail-wr1-f72.google.com with SMTP id n13-20020adf8b0d000000b0023658a75751so3041165wra.23 for ; Mon, 31 Oct 2022 05:52:58 -0700 (PDT) Received: from redhat.com ([2.52.15.189]) by smtp.gmail.com with ESMTPSA id q7-20020a1ce907000000b003c701c12a17sm7140371wmc.12.2022.10.31.05.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 05:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667220780; 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: in-reply-to:in-reply-to:references:references; bh=k3h2/R6ixFTO5bNpkZpGb1wFDhh1s402BZASy50X1Mk=; b=ZKAeVrySW3UjYg1dow9h+fJr31hSY1X44qCnoNAcJjUEKdiNRV9LrgAcibBUvDb+ye7m9f 9jnM1dXEvaDrSUlnwms/fBpnPWFVroklm4A6DIAiz2IvirlmOa9PzOh4zDArBUNiYZ8HwP wTkNSMZKiDpxomXFsZvREs17gSAZskE= X-MC-Unique: DrwydJs7NKaV0WrIm74f7A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=k3h2/R6ixFTO5bNpkZpGb1wFDhh1s402BZASy50X1Mk=; b=UR65zEbubzo2ujJoqzB7TEJ7nOCows57IiRTUPs7XZ5TVRDO7SnoUfxMvTpdCrx/jp YA7LtRgX+UKZrwnxgGJ8DnAUaW3ljK8xmvgKfYtfbeANpXAJ94Vvq9jfXYvjpAmyVaqa xeB5XaDSg2n+sKdA+MBapiqjWKkxk1ohjlpvPwQNi/069Z14iPT5fvMPX7MEnZ35US3u 998Hi7OB5BPJHi9WaNaC92tk2k8ehsJ5Txduzj5xcPdIsFaTPbA/SsEPe+Xj+P1aFXH9 BtsYxhs1qw9M9+FhBGHr0JKwaLGNPBbnQGPnOzjO5lqkVFdlxWn6WCpjZyk67hpzmaQd qwOA== X-Gm-Message-State: ACrzQf025qHA/JUfcG7inJj/fWeU53fIO6aSw1ToOoVp10YOUDmvZZmO iUZiRt/EkKGQuOVrc58bqHhmJ4qNWyNuhYN5w9tf/+jddalu7xfCXXY7FB7u6dWJ0GROrshZKxY 1Z2/gpqJk1YY67Ju4gNJCLdprUkKNCL2r9X3RWazW91uzIPW1PAPX9ONb3wXL X-Received: by 2002:a05:600c:3d9a:b0:3cf:4969:850f with SMTP id bi26-20020a05600c3d9a00b003cf4969850fmr7962440wmb.130.1667220777302; Mon, 31 Oct 2022 05:52:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5cgS4WJKyOP0yu14rt8kS0/sLFl7epiXI43c/StlnCD/MYJdGE2KopPNAIs/NVKzL+jXQbZQ== X-Received: by 2002:a05:600c:3d9a:b0:3cf:4969:850f with SMTP id bi26-20020a05600c3d9a00b003cf4969850fmr7962419wmb.130.1667220777038; Mon, 31 Oct 2022 05:52:57 -0700 (PDT) Date: Mon, 31 Oct 2022 08:52:54 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Kangjie Xu , Xuan Zhuo , Jason Wang Subject: [PULL 46/86] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_restart() Message-ID: <20221031124928.128475-47-mst@redhat.com> References: <20221031124928.128475-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221031124928.128475-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.048, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1667221972089100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Kangjie Xu Introduce vhost_net_virtqueue_restart(), which can restart the specific virtqueue when the vhost net started running before. If it fails to restart the virtqueue, the device will be stopped. Here we do not reuse vhost_net_start_one() or vhost_dev_start() because they work at queue pair level. The mem table and features do not change, so we can call the vhost_virtqueue_start() to restart a specific queue. This patch only considers the case of vhost-kernel, when NetClientDriver is NET_CLIENT_DRIVER_TAP. Signed-off-by: Kangjie Xu Signed-off-by: Xuan Zhuo Acked-by: Jason Wang Message-Id: <20221017092558.111082-11-xuanzhuo@linux.alibaba.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/net/vhost_net.h | 2 ++ hw/net/vhost_net-stub.c | 6 +++++ hw/net/vhost_net.c | 53 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 85d85a4957..40b9a40074 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -50,4 +50,6 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu= ); =20 void vhost_net_virtqueue_reset(VirtIODevice *vdev, NetClientState *nc, int vq_index); +int vhost_net_virtqueue_restart(VirtIODevice *vdev, NetClientState *nc, + int vq_index); #endif diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index 2d745e359c..9f7daae99c 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -107,3 +107,9 @@ void vhost_net_virtqueue_reset(VirtIODevice *vdev, NetC= lientState *nc, { =20 } + +int vhost_net_virtqueue_restart(VirtIODevice *vdev, NetClientState *nc, + int vq_index) +{ + return 0; +} diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 519dced899..f2ada02781 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -34,6 +34,7 @@ #include "standard-headers/linux/virtio_ring.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-bus.h" +#include "linux-headers/linux/vhost.h" =20 =20 /* Features supported by host kernel. */ @@ -556,3 +557,55 @@ void vhost_net_virtqueue_reset(VirtIODevice *vdev, Net= ClientState *nc, net->dev.vqs + idx, net->dev.vq_index + idx); } + +int vhost_net_virtqueue_restart(VirtIODevice *vdev, NetClientState *nc, + int vq_index) +{ + VHostNetState *net =3D get_vhost_net(nc->peer); + const VhostOps *vhost_ops =3D net->dev.vhost_ops; + struct vhost_vring_file file =3D { }; + int idx, r; + + if (!net->dev.started) { + return -EBUSY; + } + + /* should only be called after backend is connected */ + assert(vhost_ops); + + idx =3D vhost_ops->vhost_get_vq_index(&net->dev, vq_index); + + r =3D vhost_virtqueue_start(&net->dev, + vdev, + net->dev.vqs + idx, + net->dev.vq_index + idx); + if (r < 0) { + goto err_start; + } + + if (net->nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP) { + file.index =3D idx; + file.fd =3D net->backend; + r =3D vhost_net_set_backend(&net->dev, &file); + if (r < 0) { + r =3D -errno; + goto err_start; + } + } + + return 0; + +err_start: + error_report("Error when restarting the queue."); + + if (net->nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP) { + file.fd =3D VHOST_FILE_UNBIND; + file.index =3D idx; + int r =3D vhost_net_set_backend(&net->dev, &file); + assert(r >=3D 0); + } + + vhost_dev_stop(&net->dev, vdev); + + return r; +} --=20 MST