Don't leak VLANClientState on PCI hot remove

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 <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Mark McLoughlin 2009-07-01 16:46:38 +01:00 committed by Anthony Liguori
parent d026fb6dab
commit ae50b2747f
9 changed files with 25 additions and 27 deletions

View File

@ -55,12 +55,7 @@ void destroy_nic(dev_match_fn *match_fn, void *arg)
nic = &nd_table[i]; nic = &nd_table[i];
if (nic->used) { if (nic->used) {
if (nic->private && match_fn(nic->private, arg)) { if (nic->private && match_fn(nic->private, arg)) {
if (nic->vlan) { qemu_del_vlan_client(nic->vc);
VLANClientState *vc;
vc = qemu_find_vlan_client(nic->vlan, nic->private);
if (vc)
qemu_del_vlan_client(vc);
}
net_client_uninit(nic); net_client_uninit(nic);
} }
} }

View File

@ -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->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s);
s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */ 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, s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
nic_receive, NULL, nic_cleanup, s); nic_can_receive, nic_receive, NULL,
nic_cleanup, s);
qemu_format_nic_info_str(s->vc, nd->macaddr); qemu_format_nic_info_str(s->vc, nd->macaddr);
qemu_register_reset(nic_reset, s); qemu_register_reset(nic_reset, s);

View File

@ -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); eth->ethregs = cpu_register_io_memory(eth_read, eth_write, eth);
cpu_register_physical_memory (base, 0x5c, eth->ethregs); cpu_register_physical_memory (base, 0x5c, eth->ethregs);
eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, eth->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
eth_can_receive, eth_receive, NULL, eth_can_receive, eth_receive,
eth_cleanup, eth); NULL, eth_cleanup, eth);
eth->vc->opaque = eth; eth->vc->opaque = eth;
eth->vc->link_status_changed = eth_set_link; eth->vc->link_status_changed = eth_set_link;

View File

@ -462,9 +462,9 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
mcf_fec_writefn, s); mcf_fec_writefn, s);
cpu_register_physical_memory(base, 0x400, s->mmio_index); cpu_register_physical_memory(base, 0x400, s->mmio_index);
s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
mcf_fec_can_receive, mcf_fec_receive, NULL, mcf_fec_can_receive, mcf_fec_receive,
mcf_fec_cleanup, s); NULL, mcf_fec_cleanup, s);
memcpy(s->macaddr, nd->macaddr, 6); memcpy(s->macaddr, nd->macaddr, 6);
qemu_format_nic_info_str(s->vc, s->macaddr); qemu_format_nic_info_str(s->vc, s->macaddr);
} }

View File

@ -263,9 +263,9 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
s->io_base = base; s->io_base = base;
s->irq = irq; s->irq = irq;
if (nd && nd->vlan) { if (nd && nd->vlan) {
s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
mipsnet_can_receive, mipsnet_receive, NULL, mipsnet_can_receive, mipsnet_receive,
mipsnet_cleanup, s); NULL, mipsnet_cleanup, s);
} else { } else {
s->vc = NULL; s->vc = NULL;
} }

View File

@ -759,9 +759,9 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
ne2000_reset(s); ne2000_reset(s);
s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
ne2000_can_receive, ne2000_receive, NULL, ne2000_can_receive, ne2000_receive,
isa_ne2000_cleanup, s); NULL, isa_ne2000_cleanup, s);
qemu_format_nic_info_str(s->vc, s->macaddr); qemu_format_nic_info_str(s->vc, s->macaddr);

View File

@ -250,8 +250,9 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev,
{ {
NICInfo *nd = dev->nd; NICInfo *nd = dev->nd;
assert(nd); assert(nd);
return qemu_new_vlan_client(nd->vlan, nd->model, nd->name, can_receive, nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, can_receive,
receive, receive_iov, cleanup, opaque); receive, receive_iov, cleanup, opaque);
return nd->vc;
} }

View File

@ -1458,11 +1458,11 @@ USBDevice *usb_net_init(NICInfo *nd)
pstrcpy(s->dev.devname, sizeof(s->dev.devname), pstrcpy(s->dev.devname, sizeof(s->dev.devname),
"QEMU USB Network Interface"); "QEMU USB Network Interface");
s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
usbnet_can_receive, usbnet_can_receive,
usbnet_receive, usbnet_receive,
NULL, NULL,
usbnet_cleanup, s); usbnet_cleanup, s);
qemu_format_nic_info_str(s->vc, s->mac); qemu_format_nic_info_str(s->vc, s->mac);

1
net.h
View File

@ -96,6 +96,7 @@ struct NICInfo {
const char *name; const char *name;
const char *devaddr; const char *devaddr;
VLANState *vlan; VLANState *vlan;
VLANClientState *vc;
void *private; void *private;
int used; int used;
int bootable; int bootable;