From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MM21S-00063h-UZ for qemu-devel@nongnu.org; Wed, 01 Jul 2009 11:46:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MM21O-00061t-Am for qemu-devel@nongnu.org; Wed, 01 Jul 2009 11:46:58 -0400 Received: from [199.232.76.173] (port=39349 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MM21O-00061a-18 for qemu-devel@nongnu.org; Wed, 01 Jul 2009 11:46:54 -0400 Received: from mx2.redhat.com ([66.187.237.31]:49901) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MM21N-0003or-FS for qemu-devel@nongnu.org; Wed, 01 Jul 2009 11:46:53 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n61Fkqw7015434 for ; Wed, 1 Jul 2009 11:46:52 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n61Fkq1A004850 for ; Wed, 1 Jul 2009 11:46:52 -0400 Received: from [IPv6:::1] (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n61FkoCB023314 for ; Wed, 1 Jul 2009 11:46:51 -0400 From: Mark McLoughlin Content-Type: text/plain Date: Wed, 01 Jul 2009 16:46:38 +0100 Message-Id: <1246463198.598.75.camel@blaa> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] Don't leak VLANClientState on PCI hot remove Reply-To: Mark McLoughlin List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel destroy_nic() requires that NICInfo::private by a PCIDevice pointer, but then goes on to require that the same pointer matches VLANClientState::opaque. That is no longer the case for virtio-net since qdev and wasn't previously the case for rtl8139, ne2k_pci or eepro100. Make the situation a lot more clear by maintaining a VLANClientState pointer in NICInfo. Signed-off-by: Mark McLoughlin --- hw/device-hotplug.c | 7 +------ hw/dp8393x.c | 5 +++-- hw/etraxfs_eth.c | 6 +++--- hw/mcf_fec.c | 6 +++--- hw/mipsnet.c | 6 +++--- hw/ne2000.c | 6 +++--- hw/qdev.c | 5 +++-- hw/usb-net.c | 10 +++++----- net.h | 1 + 9 files changed, 25 insertions(+), 27 deletions(-) diff --git a/hw/device-hotplug.c b/hw/device-hotplug.c index 3bdc048..e178083 100644 --- a/hw/device-hotplug.c +++ b/hw/device-hotplug.c @@ -55,12 +55,7 @@ void destroy_nic(dev_match_fn *match_fn, void *arg) nic = &nd_table[i]; if (nic->used) { if (nic->private && match_fn(nic->private, arg)) { - if (nic->vlan) { - VLANClientState *vc; - vc = qemu_find_vlan_client(nic->vlan, nic->private); - if (vc) - qemu_del_vlan_client(vc); - } + qemu_del_vlan_client(nic->vc); net_client_uninit(nic); } } diff --git a/hw/dp8393x.c b/hw/dp8393x.c index 1a27195..e2f86b8 100644 --- a/hw/dp8393x.c +++ b/hw/dp8393x.c @@ -890,8 +890,9 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift, s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s); s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */ - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, nic_can_receive, - nic_receive, NULL, nic_cleanup, s); + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, + nic_can_receive, nic_receive, NULL, + nic_cleanup, s); qemu_format_nic_info_str(s->vc, nd->macaddr); qemu_register_reset(nic_reset, s); diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c index 58f9f4e..e1e5d8c 100644 --- a/hw/etraxfs_eth.c +++ b/hw/etraxfs_eth.c @@ -590,9 +590,9 @@ void *etraxfs_eth_init(NICInfo *nd, target_phys_addr_t base, int phyaddr) eth->ethregs = cpu_register_io_memory(eth_read, eth_write, eth); cpu_register_physical_memory (base, 0x5c, eth->ethregs); - eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, - eth_can_receive, eth_receive, NULL, - eth_cleanup, eth); + eth->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, + eth_can_receive, eth_receive, + NULL, eth_cleanup, eth); eth->vc->opaque = eth; eth->vc->link_status_changed = eth_set_link; diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c index 1676bcb..27f27a6 100644 --- a/hw/mcf_fec.c +++ b/hw/mcf_fec.c @@ -462,9 +462,9 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq) mcf_fec_writefn, s); cpu_register_physical_memory(base, 0x400, s->mmio_index); - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, - mcf_fec_can_receive, mcf_fec_receive, NULL, - mcf_fec_cleanup, s); + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, + mcf_fec_can_receive, mcf_fec_receive, + NULL, mcf_fec_cleanup, s); memcpy(s->macaddr, nd->macaddr, 6); qemu_format_nic_info_str(s->vc, s->macaddr); } diff --git a/hw/mipsnet.c b/hw/mipsnet.c index 8035229..e98c576 100644 --- a/hw/mipsnet.c +++ b/hw/mipsnet.c @@ -263,9 +263,9 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) s->io_base = base; s->irq = irq; if (nd && nd->vlan) { - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, - mipsnet_can_receive, mipsnet_receive, NULL, - mipsnet_cleanup, s); + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, + mipsnet_can_receive, mipsnet_receive, + NULL, mipsnet_cleanup, s); } else { s->vc = NULL; } diff --git a/hw/ne2000.c b/hw/ne2000.c index 66ae9ab..9265f72 100644 --- a/hw/ne2000.c +++ b/hw/ne2000.c @@ -759,9 +759,9 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd) ne2000_reset(s); - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, - ne2000_can_receive, ne2000_receive, NULL, - isa_ne2000_cleanup, s); + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, + ne2000_can_receive, ne2000_receive, + NULL, isa_ne2000_cleanup, s); qemu_format_nic_info_str(s->vc, s->macaddr); diff --git a/hw/qdev.c b/hw/qdev.c index 385e709..7fc352f 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -262,8 +262,9 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev, { NICInfo *nd = dev->nd; assert(nd); - return qemu_new_vlan_client(nd->vlan, nd->model, nd->name, can_receive, - receive, receive_iov, cleanup, opaque); + nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, can_receive, + receive, receive_iov, cleanup, opaque); + return nd->vc; } diff --git a/hw/usb-net.c b/hw/usb-net.c index 0e80ca6..8214a68 100644 --- a/hw/usb-net.c +++ b/hw/usb-net.c @@ -1458,11 +1458,11 @@ USBDevice *usb_net_init(NICInfo *nd) pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Network Interface"); - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, - usbnet_can_receive, - usbnet_receive, - NULL, - usbnet_cleanup, s); + s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, + usbnet_can_receive, + usbnet_receive, + NULL, + usbnet_cleanup, s); qemu_format_nic_info_str(s->vc, s->mac); diff --git a/net.h b/net.h index 64d5e22..6026e10 100644 --- a/net.h +++ b/net.h @@ -96,6 +96,7 @@ struct NICInfo { const char *name; const char *devaddr; VLANState *vlan; + VLANClientState *vc; void *private; int used; int bootable; -- 1.6.2.2