From nobody Sun May 12 05:25:05 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 1628529307518321.34691631325006; Mon, 9 Aug 2021 10:15:07 -0700 (PDT) Received: from localhost ([::1]:57402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mD8ri-0006Cj-Im for importer@patchew.org; Mon, 09 Aug 2021 13:15:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mD8qf-0004zh-N3 for qemu-devel@nongnu.org; Mon, 09 Aug 2021 13:14:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mD8qe-0004kp-0m for qemu-devel@nongnu.org; Mon, 09 Aug 2021 13:14:01 -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-491-IcPeWbwCPRuhlUWDaVc_3A-1; Mon, 09 Aug 2021 13:13:58 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25E1F107ACF5 for ; Mon, 9 Aug 2021 17:13:57 +0000 (UTC) Received: from thinkpad.redhat.com (unknown [10.39.194.218]) by smtp.corp.redhat.com (Postfix) with ESMTP id A592C5DF21; Mon, 9 Aug 2021 17:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628529239; 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=Q0p5WhJfZl3Kma45czLYahy111/GBe94Y4IWP4BL+rY=; b=QipVWZXhGdTj2xNwK0EaImvrIi7kaRonAmNhScM1veZXWh7IHbdtXqUeoVBXDv6bg0EQSj S3j7szfzoLBuWPdwyzAKnMOnpL7aeICLW97JMK4AsorQMe4GsscIZehXcjbmtl/AR7rDka 5pKrZJpBA/v4I4ZpOoJuiasMHF8ScqA= X-MC-Unique: IcPeWbwCPRuhlUWDaVc_3A-1 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH v2 1/1] virtio: failover: define the default device to use in case of error Date: Mon, 9 Aug 2021 19:13:42 +0200 Message-Id: <20210809171342.18146-2-lvivier@redhat.com> In-Reply-To: <20210809171342.18146-1-lvivier@redhat.com> References: <20210809171342.18146-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.702, 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_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.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: 1628529308841100001 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 | 49 +++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) 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..972c03232a96 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -935,12 +935,23 @@ static void virtio_net_set_features(VirtIODevice *vde= v, uint64_t features) memset(n->vlans, 0xff, MAX_VLAN >> 3); } =20 - if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) { - qapi_event_send_failover_negotiated(n->netclient_name); - qatomic_set(&n->failover_primary_hidden, false); - failover_add_primary(n, &err); - if (err) { - warn_report_err(err); + /* + * if the virtio-net driver has the STANDBY feature, we can plug the p= rimary + * if not but is not the default failover device, + * we need to plug the primary alone and the virtio-net driver will + * be disabled in the validate_features() function but validate_featur= es() + * is only available with virtio 1.0 spec + */ + if (n->failover) { + if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY) || + (virtio_has_feature(features, VIRTIO_F_VERSION_1) && + !n->failover_default)) { + qapi_event_send_failover_negotiated(n->netclient_name); + qatomic_set(&n->failover_primary_hidden, false); + failover_add_primary(n, &err); + if (err) { + warn_report_err(err); + } } } } @@ -3625,9 +3636,34 @@ 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 +/* validate_features() is only available with VIRTIO_F_VERSION_1 */ +static int failover_validate_features(VirtIODevice *vdev) +{ + VirtIONet *n =3D VIRTIO_NET(vdev); + + /* + * 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. In this case, 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 && + !virtio_vdev_has_feature(vdev, VIRTIO_NET_F_STANDBY)) { + /* disable virtio-net */ + return -ENODEV; + } + + return 0; +} + static void virtio_net_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -3651,6 +3687,7 @@ static void virtio_net_class_init(ObjectClass *klass,= void *data) vdc->post_load =3D virtio_net_post_load_virtio; vdc->vmsd =3D &vmstate_virtio_net_device; vdc->primary_unplug_pending =3D primary_unplug_pending; + vdc->validate_features =3D failover_validate_features; } =20 static const TypeInfo virtio_net_info =3D { --=20 2.31.1