From: Jason Wang <jasowang@redhat.com>
To: qemu-devel@nongnu.org
Cc: Jonah Palmer <jonah.palmer@oracle.com>,
David Woodhouse <dwmw2@infradead.org>,
Jason Wang <jasowang@redhat.com>
Subject: [PULL 1/5] net/hub: make net_hub_port_cleanup idempotent
Date: Fri, 14 Nov 2025 11:48:02 +0800 [thread overview]
Message-ID: <20251114034806.2440-2-jasowang@redhat.com> (raw)
In-Reply-To: <20251114034806.2440-1-jasowang@redhat.com>
From: Jonah Palmer <jonah.palmer@oracle.com>
Makes the net_hub_port_cleanup function idempotent to avoid double
removals by guarding its QLIST_REMOVE with a flag.
When using a Xen networking device with hubport backends, e.g.:
-accel kvm,xen-version=0x40011
-netdev hubport,...
-device xen-net-device,...
the shutdown order starts with net_cleanup, which walks the list and
deletes netdevs (including hubports). Then Xen's xen_device_unrealize is
called, which eventually leads to a second net_hub_port_cleanup call,
resulting in a segfault.
Fixes: e7891c57 ("net: move backend cleanup to NIC cleanup")
Reported-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Jonah Palmer <jonah.palmer@oracle.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
net/hub.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/net/hub.c b/net/hub.c
index e3b58b1c4f..ee5881f6d5 100644
--- a/net/hub.c
+++ b/net/hub.c
@@ -34,6 +34,7 @@ typedef struct NetHubPort {
QLIST_ENTRY(NetHubPort) next;
NetHub *hub;
int id;
+ bool listed;
} NetHubPort;
struct NetHub {
@@ -129,7 +130,10 @@ static void net_hub_port_cleanup(NetClientState *nc)
{
NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc);
- QLIST_REMOVE(port, next);
+ if (port->listed) {
+ QLIST_REMOVE(port, next);
+ port->listed = false;
+ }
}
static NetClientInfo net_hub_port_info = {
@@ -159,8 +163,10 @@ static NetHubPort *net_hub_port_new(NetHub *hub, const char *name,
port = DO_UPCAST(NetHubPort, nc, nc);
port->id = id;
port->hub = hub;
+ port->listed = false;
QLIST_INSERT_HEAD(&hub->ports, port, next);
+ port->listed = true;
return port;
}
--
2.42.0
next prev parent reply other threads:[~2025-11-14 3:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 3:48 [PULL 0/5] Net patches Jason Wang
2025-11-14 3:48 ` Jason Wang [this message]
2025-11-14 3:48 ` [PULL 2/5] hw/net/e1000e_core: Don't advance desc_offset for NULL buffer RX descriptors Jason Wang
2025-11-14 3:48 ` [PULL 3/5] hw/net/e1000e_core: Correct rx oversize packet checks Jason Wang
2025-11-14 3:48 ` [PULL 4/5] hw/net/e1000e_core: Adjust e1000e_write_payload_frag_to_rx_buffers() assert Jason Wang
2025-11-14 3:48 ` [PULL 5/5] net: pad packets to minimum length in qemu_receive_packet() Jason Wang
2025-11-14 16:58 ` [PULL 0/5] Net patches Richard Henderson
2025-11-21 4:02 ` Jason Wang
2025-11-21 12:27 ` Peter Maydell
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=20251114034806.2440-2-jasowang@redhat.com \
--to=jasowang@redhat.com \
--cc=dwmw2@infradead.org \
--cc=jonah.palmer@oracle.com \
--cc=qemu-devel@nongnu.org \
/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).