VirtualBox

Ignore:
Timestamp:
Jun 1, 2012 4:46:34 PM (13 years ago)
Author:
vboxsync
Message:

netflt: fix dev unregistration issues on kernels 3.2.18 and newer (#6225)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c

    r40854 r41548  
    15361536    pThis->u.s.PacketType.func = vboxNetFltLinuxPacketHandler;
    15371537    dev_add_pack(&pThis->u.s.PacketType);
     1538    ASMAtomicUoWriteBool(&pThis->u.s.fPacketHandler, true);
     1539    Log(("vboxNetFltLinuxAttachToInterface: this=%p: Packet handler installed.\n", pThis));
    15381540
    15391541#ifdef VBOXNETFLT_WITH_HOST2WIRE_FILTER
     
    15601562    }
    15611563    RTSpinlockReleaseNoInts(pThis->hSpinlock);
    1562     Log(("vboxNetFltLinuxAttachToInterface: this=%p: Packet handler installed.\n", pThis));
    15631564
    15641565    /*
     
    16041605static int vboxNetFltLinuxUnregisterDevice(PVBOXNETFLTINS pThis, struct net_device *pDev)
    16051606{
     1607    bool fRegistered;
    16061608    Assert(!pThis->fDisconnectedFromHost);
    16071609
     
    16101612#endif
    16111613
     1614    if (ASMAtomicCmpXchgBool(&pThis->u.s.fPacketHandler, false, true))
     1615    {
     1616        dev_remove_pack(&pThis->u.s.PacketType);
     1617        Log(("vboxNetFltLinuxUnregisterDevice: this=%p: packet handler removed.\n", pThis));
     1618    }
     1619
    16121620    RTSpinlockAcquire(pThis->hSpinlock);
    1613     ASMAtomicWriteBool(&pThis->u.s.fRegistered, false);
    1614     ASMAtomicWriteBool(&pThis->fDisconnectedFromHost, true);
    1615     ASMAtomicUoWriteNullPtr(&pThis->u.s.pDev);
     1621    fRegistered = ASMAtomicXchgBool(&pThis->u.s.fRegistered, false);
     1622    if (fRegistered)
     1623    {
     1624        ASMAtomicWriteBool(&pThis->fDisconnectedFromHost, true);
     1625        ASMAtomicUoWriteNullPtr(&pThis->u.s.pDev);
     1626    }
    16161627    RTSpinlockReleaseNoInts(pThis->hSpinlock);
    16171628
    1618     dev_remove_pack(&pThis->u.s.PacketType);
     1629    if (fRegistered)
     1630    {
    16191631#ifndef VBOXNETFLT_LINUX_NO_XMIT_QUEUE
    1620     skb_queue_purge(&pThis->u.s.XmitQueue);
    1621 #endif
    1622     Log(("vboxNetFltLinuxUnregisterDevice: this=%p: Packet handler removed, xmit queue purged.\n", pThis));
    1623     Log(("vboxNetFltLinuxUnregisterDevice: Device %p(%s) released. ref=%d\n",
    1624          pDev, pDev->name,
     1632        skb_queue_purge(&pThis->u.s.XmitQueue);
     1633#endif
     1634        Log(("vboxNetFltLinuxUnregisterDevice: this=%p: xmit queue purged.\n", pThis));
     1635        Log(("vboxNetFltLinuxUnregisterDevice: Device %p(%s) released. ref=%d\n",
     1636             pDev, pDev->name,
    16251637#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
    1626          netdev_refcnt_read(pDev)
     1638             netdev_refcnt_read(pDev)
    16271639#else
    1628          atomic_read(&pDev->refcnt)
    1629 #endif
    1630          ));
    1631     dev_put(pDev);
     1640             atomic_read(&pDev->refcnt)
     1641#endif
     1642           ));
     1643        dev_put(pDev);
     1644    }
    16321645
    16331646    return NOTIFY_OK;
     
    18701883     * we don't want the handler to forward packets to disconnected switch.
    18711884     */
    1872     dev_remove_pack(&pThis->u.s.PacketType);
     1885    if (ASMAtomicCmpXchgBool(&pThis->u.s.fPacketHandler, false, true))
     1886    {
     1887        dev_remove_pack(&pThis->u.s.PacketType);
     1888        Log(("vboxNetFltOsDisconnectIt: this=%p: Packet handler removed.\n", pThis));
     1889    }
    18731890    return VINF_SUCCESS;
    18741891}
     
    19171934    RTSpinlockAcquire(pThis->hSpinlock);
    19181935    pDev = ASMAtomicUoReadPtrT(&pThis->u.s.pDev, struct net_device *);
    1919     fRegistered = ASMAtomicUoReadBool(&pThis->u.s.fRegistered);
     1936    fRegistered = ASMAtomicXchgBool(&pThis->u.s.fRegistered, false);
    19201937    RTSpinlockReleaseNoInts(pThis->hSpinlock);
    19211938
     
    19271944        skb_queue_purge(&pThis->u.s.XmitQueue);
    19281945#endif
    1929         Log(("vboxNetFltOsDeleteInstance: this=%p: Packet handler removed, xmit queue purged.\n", pThis));
     1946        Log(("vboxNetFltOsDeleteInstance: this=%p: xmit queue purged.\n", pThis));
    19301947        Log(("vboxNetFltOsDeleteInstance: Device %p(%s) released. ref=%d\n",
    19311948             pDev, pDev->name,
     
    19741991     */
    19751992    ASMAtomicUoWriteNullPtr(&pThis->u.s.pDev);
    1976     pThis->u.s.fRegistered = false;
     1993    pThis->u.s.fRegistered     = false;
    19771994    pThis->u.s.fPromiscuousSet = false;
     1995    pThis->u.s.fPacketHandler  = false;
    19781996    memset(&pThis->u.s.PacketType, 0, sizeof(pThis->u.s.PacketType));
    19791997#ifndef VBOXNETFLT_LINUX_NO_XMIT_QUEUE
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette