From: Steve Sistare <steven.sistare@oracle.com>
To: qemu-devel@nongnu.org
Cc: Jason Wang <jasowang@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>,
Hamza Khan <hamza.khan@nutanix.com>,
Steve Sistare <steven.sistare@oracle.com>
Subject: [RFC V2 8/8] tap: postload fix for cpr
Date: Thu, 17 Jul 2025 11:39:28 -0700 [thread overview]
Message-ID: <1752777568-236368-9-git-send-email-steven.sistare@oracle.com> (raw)
In-Reply-To: <1752777568-236368-1-git-send-email-steven.sistare@oracle.com>
After cpr of a multi-queue NIC, if any queues are unused, then the
corresponding tap is marked enabled in userland, but it is disabled in the
kernel for the fd that was preserved. One cannot call tap_disable() during
postload, because that eventually calls IFF_DETACH_QUEUE, which fails
because the queue is already detached. Define tap_disable_postload to
avoid IFF_DETACH_QUEUE.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
include/net/tap.h | 1 +
hw/net/virtio-net.c | 20 ++++++++++++++++++++
net/tap-win32.c | 5 +++++
net/tap.c | 17 +++++++++++++++++
4 files changed, 43 insertions(+)
diff --git a/include/net/tap.h b/include/net/tap.h
index 5d58551..9456abe 100644
--- a/include/net/tap.h
+++ b/include/net/tap.h
@@ -30,6 +30,7 @@
int tap_enable(NetClientState *nc);
int tap_disable(NetClientState *nc);
+void tap_disable_postload(NetClientState *nc);
int tap_get_fd(NetClientState *nc);
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index eb93607..b45128e 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -730,6 +730,25 @@ static int peer_detach(VirtIONet *n, int index)
return tap_disable(nc->peer);
}
+/*
+ * Set the disabled flag on unused queue pairs after vmstate load, without
+ * calling IFF_DETACH_QUEUE, which fails because the queue is already detached.
+ */
+static void virtio_net_postload_queue_pairs(VirtIONet *n)
+{
+ int i;
+ MigMode mode = migrate_mode();
+
+ if (mode == MIG_MODE_CPR_TRANSFER) {
+ for (i = n->curr_queue_pairs; i < n->max_queue_pairs; i++) {
+ NetClientState *nc = qemu_get_subqueue(n->nic, i);
+ if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_TAP) {
+ tap_disable_postload(nc->peer);
+ }
+ }
+ }
+}
+
static void virtio_net_set_queue_pairs(VirtIONet *n)
{
int i;
@@ -3106,6 +3125,7 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
*/
n->saved_guest_offloads = n->curr_guest_offloads;
+ virtio_net_postload_queue_pairs(n);
virtio_net_set_queue_pairs(n);
/* Find the first multicast entry in the saved MAC filter */
diff --git a/net/tap-win32.c b/net/tap-win32.c
index 671dee9..66be7c9 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -771,3 +771,8 @@ int tap_disable(NetClientState *nc)
{
abort();
}
+
+void tap_disable_postload(NetClientState *nc)
+{
+ abort();
+}
diff --git a/net/tap.c b/net/tap.c
index 6a12751..c7f9023 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -1079,3 +1079,20 @@ int tap_disable(NetClientState *nc)
return ret;
}
}
+
+/*
+ * On cpr restart, the tap is marked enabled in userland, but it might be
+ * disabled in the kernel, and IFF_DETACH_QUEUE will fail because it is
+ * already detached. This function disables without calling IFF_DETACH_QUEUE.
+ */
+void tap_disable_postload(NetClientState *nc)
+{
+ TAPState *s = DO_UPCAST(TAPState, nc, nc);
+
+ if (!s->cpr || s->enabled == 0) {
+ return;
+ } else {
+ s->enabled = false;
+ tap_update_fd_handler(s);
+ }
+}
--
1.8.3.1
next prev parent reply other threads:[~2025-07-17 20:45 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-17 18:39 [RFC V2 0/8] Live update: tap and vhost Steve Sistare
2025-07-17 18:39 ` [RFC V2 1/8] migration: stop vm earlier for cpr Steve Sistare
2025-07-17 18:39 ` [RFC V2 2/8] migration: cpr setup notifier Steve Sistare
2025-07-17 18:39 ` [RFC V2 3/8] vhost: reset vhost devices for cpr Steve Sistare
2025-08-27 11:29 ` Vladimir Sementsov-Ogievskiy
2025-08-27 18:38 ` Steven Sistare
2025-07-17 18:39 ` [RFC V2 4/8] cpr: delete all fds Steve Sistare
2025-07-17 18:39 ` [RFC V2 5/8] Revert "vhost-backend: remove vhost_kernel_reset_device()" Steve Sistare
2025-08-22 18:26 ` Steven Sistare
2025-07-17 18:39 ` [RFC V2 6/8] tap: common return label Steve Sistare
2025-07-17 18:39 ` [RFC V2 7/8] tap: cpr support Steve Sistare
2025-07-17 18:39 ` Steve Sistare [this message]
2025-07-18 8:48 ` [RFC V2 0/8] Live update: tap and vhost Lei Yang
2025-07-18 17:31 ` Steven Sistare
2025-07-24 5:46 ` Lei Yang
2025-08-05 13:54 ` Fabiano Rosas
2025-08-05 19:53 ` Steven Sistare
2025-08-06 15:51 ` Peter Xu
2025-08-11 18:24 ` Steven Sistare
2025-08-23 21:53 ` Vladimir Sementsov-Ogievskiy
2025-08-28 15:48 ` Steven Sistare
2025-08-29 19:37 ` Steven Sistare
2025-09-01 11:44 ` Vladimir Sementsov-Ogievskiy
2025-09-02 15:33 ` Steven Sistare
2025-09-02 17:09 ` Vladimir Sementsov-Ogievskiy
2025-09-05 16:16 ` Peter Xu
2025-09-08 9:55 ` Vladimir Sementsov-Ogievskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1752777568-236368-9-git-send-email-steven.sistare@oracle.com \
--to=steven.sistare@oracle.com \
--cc=farosas@suse.de \
--cc=hamza.khan@nutanix.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).