Re: catch 22 - porting net driver from 2.2 to 2.4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Hen, Shmulik" wrote:
> Is there a time limit on holding a lock ?

None other than "not long."  Spinlocks --should not-- be held for a long
period of time.  If you do this, IMHO that is a clear design bug that
should be fixed.

One RULE though:  never, ever, call a function that might sleep while
holding a spinlock.  If you are locking all your functions with
spin_lock_bh or similar, it sounds like you are doing this.


> We had to choose spin_lock_bh inside do_ioctl since it is run as user
> context and if hard_start_xmit was called the same time and tried to lock
> too we would be in a deadlock (actually ,this is how we found out about
> spin_*_bh :-).

Why is spin_lock_bh appropriate for this case?

Anyway, for preventing Tx:
	spin_lock(&dev->xmit_lock);
	netif_stop_queue(dev);
	spin_unlock(&dev->xmit_lock);

For preventing Rx, if this is a hardware device, you should disable
interrupts (using the card's interrupt mask register not cli...) to
prevent Rx packets from arriving while the topology is changing.


> We have to use a single lock since we don't know in advance what topology
> changes could happen during do_ioctl so we need to halt all Tx/Rx until we
> know for sure we can forward a packet to one of the base drivers we're bound
> to etc. (I didn't want to bore everyone with code excerpts, but if you think
> it would help, then...).

It still sounds to me like a single spinlock here is wrong.  Read the
existing netdev code, especially net/core/dev.c and
include/linux/netdevices.h.

	Jeff


-- 
Jeff Garzik             |
Building 1024           | Would you like a Twinkie?
MandrakeSoft            |
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux