From patchwork Mon Mar 22 12:24:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12154691 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=-16.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,URIBL_BLOCKED,USER_AGENT_GIT 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 E2811C433DB for ; Mon, 22 Mar 2021 12:29: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 7502A6198D for ; Mon, 22 Mar 2021 12:29:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7502A6198D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOJgS-00032n-Gx for qemu-devel@archiver.kernel.org; Mon, 22 Mar 2021 08:29:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOJcF-00085J-OW for qemu-devel@nongnu.org; Mon, 22 Mar 2021 08:25:03 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:42811) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOJcE-0005Zb-0Y for qemu-devel@nongnu.org; Mon, 22 Mar 2021 08:25:03 -0400 Received: by mail-wm1-x32b.google.com with SMTP id b2-20020a7bc2420000b029010be1081172so9152430wmj.1 for ; Mon, 22 Mar 2021 05:25:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OJriT6OHsNVPmr/xBcOCwHqhfooctMGjJPAgbRBfHXA=; b=RNNjWRRUobdCzFz5mNVkBfFGHPvgoGIomO/DGYGu4WCRJv1cgTz4v0b2R4gfvPMLIA B6qAGIrZub3+r8cWtcCI/uDr+ckcgOYSOMRVPwP/my2ooiGKKtVNK/bPX+TyljEz262M tJJRZOG3KBjjlckSM0cJLe/w8vwa2Ft/sHxVmF7LRpZ0ehE4GowOCPEV0c2KkfblC4J2 IeROpKuRofAoKoXhPhuWRAS2W9I2laByr6+5Yy6opMlU4yKpkETKutSoV2K23szHx4+Q O4QbNBeRm/DFBDtjnepYZyIakFi260EIKY95nTxKEeKpQz3nKukdmoCCD3zOnLpS0P1W w8Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OJriT6OHsNVPmr/xBcOCwHqhfooctMGjJPAgbRBfHXA=; b=YIl/BAGypo6lJAQ+PbdtOeHdLZNRozguqBXAY/Zv7atXlVZvlIH2kt8fMTy2YGKsIS fJCMcDE5TpDwpKYLN1z2XGE1dQlqyrKkk+zGbC+Xn7N5GPlQOQJ+cO9qel5t0K/BLnKD 4qbi5C95YPXPhH3UWW3RPhXS4OFG/LZHjbkyHV313YX97FFpoCW6YBUmEnA7P3ts/ydc WOlNjaowXIYzumyAVNFGeEpNc4KJIBYX6+76gPwWRpHJS56FrHfMfPlbrAriteW9armj L4fpWHwPpCnfZd9yLp+AK+Te54oYkOsPvLBWQcYQmudKjzGm77HyLBhCoYKV4OIR+Xpn R9LQ== X-Gm-Message-State: AOAM530nBc9QTEb+V8s5ZMV2p79Ifd5INWoWOuROgDKyd35Cl37cyPNP 3Bt9tECr+SCXa+K7CqhE1PYUHA== X-Google-Smtp-Source: ABdhPJw5PqLan5VyjNVJb1e2H9/NU+NsinTsZq1dqwko7dAEDA+39A0v7QLPoS5uulPRHgprcVjyag== X-Received: by 2002:a1c:5f54:: with SMTP id t81mr15779689wmb.84.1616415900611; Mon, 22 Mar 2021 05:25:00 -0700 (PDT) Received: from f1.Home (bzq-79-176-30-57.red.bezeqint.net. [79.176.30.57]) by smtp.gmail.com with ESMTPSA id w132sm16785325wmg.39.2021.03.22.05.24.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 05:25:00 -0700 (PDT) From: Yuri Benditovich To: mst@redhat.com, jasowang@redhat.com, berrange@redhat.com Subject: [RFC PATCH v2 1/3] net: add ability to hide (disable) vhost_net Date: Mon, 22 Mar 2021 14:24:50 +0200 Message-Id: <20210322122452.369750-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322122452.369750-1-yuri.benditovich@daynix.com> References: <20210322122452.369750-1-yuri.benditovich@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::32b; envelope-from=yuri.benditovich@daynix.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: yan@daynix.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" If 'vhost_net_disabled' in the NetClientState of the net device, get_vhost_net for TAP returns NULL. Network adapters can use this ability to hide the vhost_net temporary between resets in case some active features contradict with vhost. Signed-off-by: Yuri Benditovich --- hw/net/vhost_net.c | 4 +++- include/net/net.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 24d555e764..6660efd9ea 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -436,7 +436,9 @@ VHostNetState *get_vhost_net(NetClientState *nc) switch (nc->info->type) { case NET_CLIENT_DRIVER_TAP: - vhost_net = tap_get_vhost_net(nc); + if (!nc->vhost_net_disabled) { + vhost_net = tap_get_vhost_net(nc); + } break; #ifdef CONFIG_VHOST_NET_USER case NET_CLIENT_DRIVER_VHOST_USER: diff --git a/include/net/net.h b/include/net/net.h index a02949f6db..a938211524 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -103,6 +103,7 @@ struct NetClientState { int vring_enable; int vnet_hdr_len; bool is_netdev; + bool vhost_net_disabled; QTAILQ_HEAD(, NetFilterState) filters; }; From patchwork Mon Mar 22 12:24:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12154705 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=-16.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,URIBL_BLOCKED,USER_AGENT_GIT 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 007B9C433C1 for ; Mon, 22 Mar 2021 12:32:24 +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 96EE0619A3 for ; Mon, 22 Mar 2021 12:32:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96EE0619A3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOJjK-0005b6-Jx for qemu-devel@archiver.kernel.org; Mon, 22 Mar 2021 08:32:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOJcL-00088I-MB for qemu-devel@nongnu.org; Mon, 22 Mar 2021 08:25:10 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:38787) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOJcF-0005aZ-Jy for qemu-devel@nongnu.org; Mon, 22 Mar 2021 08:25:09 -0400 Received: by mail-wr1-x42c.google.com with SMTP id z2so16487253wrl.5 for ; Mon, 22 Mar 2021 05:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hxON1Qr7rb7hFg/JIyQs/CCbfbSPzw+UVS/lLPV7U0w=; b=Dl0NOOKcxsXkZFrdBmrwToBObb3519KfbJFPuF6eqWNqTjFdpKv/XuVFXNtMwtjHkj lHTlWHcZ6YCnlsXhaktnAKHK+/l6LuOcBT5EmRrHvmBs/8EKvL6tqP4Cv4BUjtO/ZBoL uL17NWFifydFezExsDi2a7+ad9zkWurdIgB1GdOQA/EPXxyvz2P9UM950hgcfNIgZo/6 rtRHin/cerlX/VMF7eqc+qSoo4NKOe4cCyQj/kpn59ZFM26Q43B0oosGGWOClGij25Iu yB4n3zvRUZ75+Y3xX33X59BWr/RwOE5ZvdVXkXQ2VherCgvLLCnilXp5eu4ZEFIpMgK7 5Huw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hxON1Qr7rb7hFg/JIyQs/CCbfbSPzw+UVS/lLPV7U0w=; b=IMTu2OJ6xi82h7qRhKdFT5nYuVZpE6Z4QrkUrEpWgsPKyzBhgufl9KpiFxj1Op86sC Ql0CDTlwsHVIzMBxFyVnGgrEZQgSAixFIF3NcListYawpHT4QGf3UsV9EEe7JvAVm72U sLKpoA5jDNT+8IUGuQRx9KFev4RGYYBq3gV6ksn1FrrO2ljCtnOe85hlBnHOl04PYqRE RN9Zfem9N0IWPJXp3ratkHhurTRvu+6yqj2YZrQgWyW82YR8Yrm/YPVbHKl4bxLxMzX4 8fZBiseFHY9yVatAvQLtZhu1/n2OyRPfNVai14+7EXIag38tBi1KtG84wV2GwptiRawl +z5w== X-Gm-Message-State: AOAM530qzZRYfCtP+5a2Ke4OJwFSzlIPnIJu/36S1s3rRL+x5jq5A/wZ AovYMFAVHWibd8S2O/uzkT/hcA== X-Google-Smtp-Source: ABdhPJzHkvV3pfdCx8gtsbuBQ6+MXzbUiuthrdFQ/55YqBqjc+luZwvDkJVL/FMVkmzxPzRtdEeWIw== X-Received: by 2002:adf:c70b:: with SMTP id k11mr18261180wrg.165.1616415902037; Mon, 22 Mar 2021 05:25:02 -0700 (PDT) Received: from f1.Home (bzq-79-176-30-57.red.bezeqint.net. [79.176.30.57]) by smtp.gmail.com with ESMTPSA id w132sm16785325wmg.39.2021.03.22.05.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 05:25:01 -0700 (PDT) From: Yuri Benditovich To: mst@redhat.com, jasowang@redhat.com, berrange@redhat.com Subject: [RFC PATCH v2 2/3] virtio: introduce 'missing_features_migrated' device callback Date: Mon, 22 Mar 2021 14:24:51 +0200 Message-Id: <20210322122452.369750-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322122452.369750-1-yuri.benditovich@daynix.com> References: <20210322122452.369750-1-yuri.benditovich@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::42c; envelope-from=yuri.benditovich@daynix.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: yan@daynix.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This optional callback addresses migration problem in case some of negotiated features not present on the destination system. The device has a chance to avoid migration failure. Signed-off-by: Yuri Benditovich --- hw/virtio/virtio.c | 8 ++++++++ include/hw/virtio/virtio.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 07f4e60b30..36dcac75e5 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3107,6 +3107,14 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) vdev->device_endian = virtio_default_endian(); } + if (vdc->missing_features_migrated) { + uint64_t missing = (vdev->guest_features & ~(vdev->host_features)); + if (missing && vdc->missing_features_migrated(vdev, missing)) { + vdev->host_features = + vdc->get_features(vdev, vdev->host_features, NULL); + } + } + if (virtio_64bit_features_needed(vdev)) { /* * Subsection load filled vdev->guest_features. Run them diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index b7ece7a6a8..fbfbec6ef2 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -158,6 +158,14 @@ struct VirtioDeviceClass { * processed, e.g. for bounds checking. */ int (*post_load)(VirtIODevice *vdev); + /* In case when some of negotiated features are missing on the destination + system, the migration is expected to fail. To avoid such failure, the + device may implement this callback and apply graceful configuration + change to extend host features (for example, disable vhost). + If the device returns true the virtio reinitializes the host features + and further set_features call may succeed. + */ + bool (*missing_features_migrated)(VirtIODevice *vdev, uint64_t val); const VMStateDescription *vmsd; bool (*primary_unplug_pending)(void *opaque); }; From patchwork Mon Mar 22 12:24:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12154707 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=-16.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,URIBL_BLOCKED,USER_AGENT_GIT 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 A84A1C433DB for ; Mon, 22 Mar 2021 12:33:52 +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 5E23D619A4 for ; Mon, 22 Mar 2021 12:33:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E23D619A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=daynix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOJkl-000749-G2 for qemu-devel@archiver.kernel.org; Mon, 22 Mar 2021 08:33:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOJcN-00088n-Q1 for qemu-devel@nongnu.org; Mon, 22 Mar 2021 08:25:16 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:39508) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOJcH-0005bY-AB for qemu-devel@nongnu.org; Mon, 22 Mar 2021 08:25:11 -0400 Received: by mail-wm1-x335.google.com with SMTP id d8-20020a1c1d080000b029010f15546281so8980877wmd.4 for ; Mon, 22 Mar 2021 05:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fLcpOzPll1cJxC9iX7UzZaPl9AO2DsZ8ElInXHDxMfQ=; b=H7GT01aT++UN079YkvDUL6zrzORUuJ/doxaaQTSG3gXGO2aGrEnejp7wm8/q+Qm8OT 7R+uzhEPByLzg1W/b/UnvOYq22N2sVQODLd/RPxTr7QNce89xX8AHRhKyRwCobWquolK 5/ACP+ZuYR7iZJ88IkmzqKx7VGeZwCE5nwFLWVzFLuxCOQgKYWbflgxnMckKb+4F0P3O AlzUgtubeV9Z9ZITHOsrNEONqiBKmlghryLgAegLa75HxJaGhlCfYXqWnnhKTyKdwumq ItumckKubKzKcM1GJsnuJnGHUh/UWpb7tCJRbsNP8Ica2SkcwnCpu2BJhJFKHBiUC2Tb /qbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fLcpOzPll1cJxC9iX7UzZaPl9AO2DsZ8ElInXHDxMfQ=; b=UtsWqplPyJjMZMWBqHrTRkm+J9vK5iaUfUrYJyfDaQ6qak/oj0gfOoF7JBvoETywDz UciZDliC5+egWqIxIkcb1GqTjqTlZodpvrlF+ztkHqdI7KZVH2qHHurS9gKNM44hjkhw Bo0Unr/tK9uOYXXKBARdWgWf9WeOF9lmwa98MPr2NDS3XH5YQ7HS3Qk4rxMMtG1VNBdy uqij8QxKCRoQ3ZaryRxrYINGdi+J5MtAlS8JGyB+arqTvdmaweDP1eHPM7pSKzIQYpdN 7DXvc/pdkC6XzZTuQcE7+76nQj2vT6h6yJtaxk8gPbLRZx2t+8UsvorjCpeK6EgV49Sb 6Qhw== X-Gm-Message-State: AOAM530JoSTduDOYP5WQfYN0sYIRmQP2x96dhpaCAkqobD8fGg+ipuLw 3cpM0q7Xy/1mg2NjHlwx08H+uz7rf+QRtw== X-Google-Smtp-Source: ABdhPJxkdgglDKmf9rJLHgDXR+A5ndGrUeHqmVuTyR6SPGzXwH/Bfbpp0EWtIb0xZz6CINqxFnjnJg== X-Received: by 2002:a1c:e388:: with SMTP id a130mr16166166wmh.187.1616415903558; Mon, 22 Mar 2021 05:25:03 -0700 (PDT) Received: from f1.Home (bzq-79-176-30-57.red.bezeqint.net. [79.176.30.57]) by smtp.gmail.com with ESMTPSA id w132sm16785325wmg.39.2021.03.22.05.25.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 05:25:02 -0700 (PDT) From: Yuri Benditovich To: mst@redhat.com, jasowang@redhat.com, berrange@redhat.com Subject: [RFC PATCH v2 3/3] virtio-net: implement missing_features_migrated callback Date: Mon, 22 Mar 2021 14:24:52 +0200 Message-Id: <20210322122452.369750-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210322122452.369750-1-yuri.benditovich@daynix.com> References: <20210322122452.369750-1-yuri.benditovich@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::335; envelope-from=yuri.benditovich@daynix.com; helo=mail-wm1-x335.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: yan@daynix.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Graceful drop to userspace virtio in case selected features are missing on the destination system. Currently used for 3 features that might be supported by the vhost kernel on the source machine and not supported on the destination machine: rss, hash reporting, packed ring. Signed-off-by: Yuri Benditovich --- hw/net/virtio-net.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 96a3cc8357..97afca34e7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -527,6 +527,15 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) return info; } +static void virtio_net_allow_vhost(VirtIONet *n, bool allow) +{ + int i; + for (i = 0; i < n->max_queues; i++) { + NetClientState *nc = qemu_get_subqueue(n->nic, i)->peer; + nc->vhost_net_disabled = !allow; + } +} + static void virtio_net_reset(VirtIODevice *vdev) { VirtIONet *n = VIRTIO_NET(vdev); @@ -564,6 +573,7 @@ static void virtio_net_reset(VirtIODevice *vdev) assert(!virtio_net_get_subqueue(nc)->async_tx.elem); } } + virtio_net_allow_vhost(n, true); } static void peer_test_vnet_hdr(VirtIONet *n) @@ -701,6 +711,27 @@ static void virtio_net_set_queues(VirtIONet *n) } } +static bool can_disable_vhost(VirtIONet *n) +{ + NetClientState *peer = qemu_get_queue(n->nic)->peer; + NetdevInfo *ndi; + if (!get_vhost_net(peer)) { + return false; + } + if (!peer) { + return true; + } + if (peer->info->type != NET_CLIENT_DRIVER_TAP) { + return false; + } + ndi = peer->stored_config; + if (ndi && ndi->u.tap.has_vhostforce && ndi->u.tap.vhostforce) { + printf("vhost forced, can't drop it\n"); + return false; + } + return true; +} + static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue); static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, @@ -3433,6 +3464,25 @@ static bool dev_unplug_pending(void *opaque) return vdc->primary_unplug_pending(dev); } +static bool virtio_net_missing_features_migrated(VirtIODevice *vdev, + uint64_t missing) +{ + VirtIONet *n = VIRTIO_NET(vdev); + bool disable_vhost = false; + if (virtio_has_feature(missing, VIRTIO_NET_F_HASH_REPORT) || + virtio_has_feature(missing, VIRTIO_NET_F_RSS) || + virtio_has_feature(missing, VIRTIO_F_RING_PACKED)) { + disable_vhost = true; + } + disable_vhost = disable_vhost && can_disable_vhost(n); + if (disable_vhost) { + warn_report("falling back to userspace virtio due to missing" + " features %lx", missing); + virtio_net_allow_vhost(n, false); + } + return disable_vhost; +} + static const VMStateDescription vmstate_virtio_net = { .name = "virtio-net", .minimum_version_id = VIRTIO_NET_VM_VERSION, @@ -3527,6 +3577,7 @@ static void virtio_net_class_init(ObjectClass *klass, void *data) vdc->get_features = virtio_net_get_features; vdc->set_features = virtio_net_set_features; vdc->bad_features = virtio_net_bad_features; + vdc->missing_features_migrated = virtio_net_missing_features_migrated; vdc->reset = virtio_net_reset; vdc->set_status = virtio_net_set_status; vdc->guest_notifier_mask = virtio_net_guest_notifier_mask;