From nobody Tue Apr 23 18:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627586558808898.04735633184; Thu, 29 Jul 2021 12:22:38 -0700 (PDT) Received: from localhost ([::1]:60988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9Bc5-0001wd-Qs for importer@patchew.org; Thu, 29 Jul 2021 15:22:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9BZ3-0006Dn-G1 for qemu-devel@nongnu.org; Thu, 29 Jul 2021 15:19:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9BZ2-0005ad-1t for qemu-devel@nongnu.org; Thu, 29 Jul 2021 15:19:29 -0400 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-325-qo7vUl55M5OYccKxVEeEuw-1; Thu, 29 Jul 2021 15:19:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D11BF1015184 for ; Thu, 29 Jul 2021 19:19:21 +0000 (UTC) Received: from thinkpad.redhat.com (unknown [10.39.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88D5E6E0B7; Thu, 29 Jul 2021 19:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627586366; 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=BxJIOvxN6/904s3i8r5luoZt/VaoWyeQ9KkEYOJWTPk=; b=hehKNgnc+1vJIAcCB4ieKMZ+QgiO7OEO+2OEHdSEPsAy8di8sckdmgd61INyhGVewXdFW4 4U5FmNchY5P4JvXztDwVJZbieDBbJMOQ02AbcF/vQvi/HcPanxXv2DgvRJ1N7Ahqja3q1E zkv1lkmcwEd0ewTqci2A1Z+HPXUh5KY= X-MC-Unique: qo7vUl55M5OYccKxVEeEuw-1 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH 1/2] virtio: add a way to disable a queue Date: Thu, 29 Jul 2021 21:19:09 +0200 Message-Id: <20210729191910.317114-2-lvivier@redhat.com> In-Reply-To: <20210729191910.317114-1-lvivier@redhat.com> References: <20210729191910.317114-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lvivier@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=lvivier@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, 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_H3=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: Juan Quintela , Jason Wang , Jens Freimann , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627586560370100001 Content-Type: text/plain; charset="utf-8" Add virtio_queue_disable()/virtio_queue_enable() to disable/enable a queue by setting vring.num to 0 (or num_default). This is needed to be able to disable a guest driver from the host side Signed-off-by: Laurent Vivier --- include/hw/virtio/virtio.h | 2 ++ hw/virtio/virtio.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 8bab9cfb7507..6a3f71b4cd88 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -251,6 +251,8 @@ void virtio_config_modern_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data); void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr); hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n); +void virtio_queue_enable(VirtIODevice *vdev, int n); +void virtio_queue_disable(VirtIODevice *vdev, int n); void virtio_queue_set_num(VirtIODevice *vdev, int n, int num); int virtio_queue_get_num(VirtIODevice *vdev, int n); int virtio_queue_get_max_num(VirtIODevice *vdev, int n); diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 874377f37a70..fa5228c1a2d6 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2244,6 +2244,16 @@ void virtio_queue_set_rings(VirtIODevice *vdev, int = n, hwaddr desc, virtio_init_region_cache(vdev, n); } =20 +void virtio_queue_disable(VirtIODevice *vdev, int n) +{ + vdev->vq[n].vring.num =3D 0; +} + +void virtio_queue_enable(VirtIODevice *vdev, int n) +{ + vdev->vq[n].vring.num =3D vdev->vq[n].vring.num_default; +} + void virtio_queue_set_num(VirtIODevice *vdev, int n, int num) { /* Don't allow guest to flip queue between existent and --=20 2.31.1 From nobody Tue Apr 23 18:01:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627586507597715.6742437342967; Thu, 29 Jul 2021 12:21:47 -0700 (PDT) Received: from localhost ([::1]:58920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m9BbG-0000Ti-J3 for importer@patchew.org; Thu, 29 Jul 2021 15:21:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9BZr-0007Bw-5k for qemu-devel@nongnu.org; Thu, 29 Jul 2021 15:20:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m9BZp-00066y-Dd for qemu-devel@nongnu.org; Thu, 29 Jul 2021 15:20:18 -0400 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-479-aSboEl4bOAyx-0A6wN_adg-1; Thu, 29 Jul 2021 15:19:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79D4C3482F for ; Thu, 29 Jul 2021 19:19:23 +0000 (UTC) Received: from thinkpad.redhat.com (unknown [10.39.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31061369A; Thu, 29 Jul 2021 19:19:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627586416; 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=cpisueJxgFlIT8wxh2HjvXQpKaEAT4rXIT8y1vLGI4I=; b=S79DpjqnWR+Gv92H3txE7tRrWAxxSwnf/8fJU3pqQ2hl0jX8u70S7Cb94bKRyBWN4Cms2Y F9PTQ4yWl+dxs0XapyHZhCcoBvQntSFMhrdVP6B6jWz6gMF+MpnzPOFz9zgIPa+Cyuk79l uDcfwt7vDi4M6ADA4Afwsx/VaLibtcg= X-MC-Unique: aSboEl4bOAyx-0A6wN_adg-1 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH 2/2] virtio: failover: define the default device to use in case of error Date: Thu, 29 Jul 2021 21:19:10 +0200 Message-Id: <20210729191910.317114-3-lvivier@redhat.com> In-Reply-To: <20210729191910.317114-1-lvivier@redhat.com> References: <20210729191910.317114-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lvivier@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=lvivier@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, 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_H3=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: Juan Quintela , Jason Wang , Jens Freimann , "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627586507849100001 Content-Type: text/plain; charset="utf-8" If the guest driver doesn't support the STANDBY feature, by default we keep the virtio-net device and don't hotplug the VFIO device, but in some cases, user can prefer to use the VFIO device rather than the virtio-net one. We can't unplug the virtio-net device (because on migration it is expected on the destination side) but we can force the guest driver to be disabled. Then, we can hotplug the VFIO device that will be unplugged before the migration like in the normal failover migration but without the failover device. This patch adds a new property to virtio-net device: "failover-default". By default, "failover-default" is set to true and thus the default NIC to use if the failover cannot be enabled is the virtio-net device (this is what is done until now with the virtio-net failover). If "failover-default" is set to false, in case of error, the virtio-net device is not the default anymore and the failover primary device is used instead. If the STANDBY feature is supported by guest and host, the virtio-net failover acts as usual. Signed-off-by: Laurent Vivier --- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 824a69c23f06..ab77930a327e 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -208,6 +208,7 @@ struct VirtIONet { /* primary failover device is hidden*/ bool failover_primary_hidden; bool failover; + bool failover_default; DeviceListener primary_listener; Notifier migration_state; VirtioNetRssData rss_data; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 16d20cdee52a..6fe0a09a263b 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -891,6 +891,39 @@ static void virtio_net_set_features(VirtIODevice *vdev= , uint64_t features) Error *err =3D NULL; int i; =20 + /* + * If the guest driver doesn't support the STANDBY feature, by default + * we keep the virtio-net device and don't hotplug the VFIO device, + * but in some cases, user can prefer to use the VFIO device rather + * than the virtio-net one. We can't unplug the virtio-net device + * (because on migration it is expected on the destination side) + * but we can force the guest driver to be disabled. Then, we can + * hotplug the VFIO device that will be unplugged before the migration + * like in the normal failover migration but without the failover devi= ce. + */ + if (n->failover && !n->failover_default) { + if (!virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) { + /* disable the first queue to disable the driver */ + virtio_queue_disable(vdev, 0); + /* + * as the virtio-net driver is disable we can plug back the + * failover primary device + */ + qatomic_set(&n->failover_primary_hidden, false); + failover_add_primary(n, &err); + if (err) { + warn_report_err(err); + } + return; + } else { + /* + * if the driver renegotiates features, we need to re-enable + * the queue + */ + virtio_queue_enable(vdev, 0); + } + } + if (n->mtu_bypass_backend && !virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_MTU))= { features &=3D ~(1ULL << VIRTIO_NET_F_MTU); @@ -3625,6 +3658,7 @@ static Property virtio_net_properties[] =3D { DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN), DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str), DEFINE_PROP_BOOL("failover", VirtIONet, failover, false), + DEFINE_PROP_BOOL("failover-default", VirtIONet, failover_default, true= ), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.31.1