Skip to contentSkip to conversation

MOD_INC_USE_COUNT

DISCUSSION Tony 4 participants 10 messages Nov 10, 2005 – Nov 16, 2005

lore
Share & tools
lore

Tony

author
#0 lore raw

Hello All,
Usually, when a net_device->open is called, it will MOD_INC_USE_COUNT on success. It is removed since 2.5.x, then should I increase the use count? how? thx.

#1 lore raw
Quoted 4 lines · Tony

Hello All,
Usually, when a net_device->open is called, it will MOD_INC_USE_COUNT on success. It is removed since 2.5.x, then should I increase the use count? how? thx.

Gone! Don't use INC or DEC_USE_COUNT anymore. The kernel takes care of that for you. Also, the count shown in lsmod no longer means anything you can use programmaticly.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.13.4 on an i686 machine (5589.55 BogoMips). Warning : 98.36% of all statistics are fiction.
.

****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

author
#2 lore raw
Quoted 19 lines · linux-os (Dick Johnson)
Quoted 4 lines · Tony

Hello All,
Usually, when a net_device->open is called, it will MOD_INC_USE_COUNT on success. It is removed since 2.5.x, then should I increase the use count? how? thx.

Gone! Don't use INC or DEC_USE_COUNT anymore. The kernel takes care of that for you. Also, the count shown in lsmod no longer means anything you can use programmaticly.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.13.4 on an i686 machine (5589.55 BogoMips). Warning : 98.36% of all statistics are fiction.
.

Quoted 5 lines

****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

But when the module is used by a net_device(interface is up), rmmod also works. Strange, isn't it?

#3 lore raw
Quoted 14 lines · Tony
Quoted 13 lines · linux-os (Dick Johnson)
Quoted 4 lines · Tony

Hello All,
Usually, when a net_device->open is called, it will MOD_INC_USE_COUNT on success. It is removed since 2.5.x, then should I increase the use count? how? thx.

Gone! Don't use INC or DEC_USE_COUNT anymore. The kernel takes care of that for you. Also, the count shown in lsmod no longer means anything you can use programmaticly.

Quoted 8 lines
Quoted 6 lines

Cheers,
Dick Johnson
Penguin : Linux version 2.6.13.4 on an i686 machine (5589.55 BogoMips). Warning : 98.36% of all statistics are fiction.

But when the module is used by a net_device(interface is up), rmmod also works. Strange, isn't it?

Yes, it does something unexpected, i.e., violates the tenant of least surprise. It shuts down the network interface, doesn't even log the event. It just __does__ it! At least M$ would put the information in the "event viewer".

Quoted 1 line

Cheers,
Dick Johnson
Penguin : Linux version 2.6.13.4 on an i686 machine (5589.55 BogoMips). Warning : 98.36% of all statistics are fiction.
.

****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

#4 lore raw
In reply to Tony
Quoted 2 lines · Tony

But when the module is used by a net_device(interface is up), rmmod also works. Strange, isn't it?

Not strange at all. The typical network driver is implemented using pci_register_driver which will set the owner filed of the driver's struct driver which then is being used for internal reference counting. Other busses or line disciplines (SLIP, PPP, AX.25 ...) need to do the equivalent or the kernel will believe reference counting isn't necessary and it's ok to unload the module at any time.

In which driver did you hit this problem?

Ralf

author
#5 lore raw
Quoted 13 lines · Ralf Baechle
Quoted 1 line · Tony

But when the module is used by a net_device(interface is up), rmmod also works. Strange, isn't it?

Not strange at all. The typical network driver is implemented using pci_register_driver which will set the owner filed of the driver's struct driver which then is being used for internal reference counting. Other busses or line disciplines (SLIP, PPP, AX.25 ...) need to do the equivalent or the kernel will believe reference counting isn't necessary and it's ok to unload the module at any time.

Quoted 4 lines

In which driver did you hit this problem?

Ralf

I have a radio connected to host using ethernet. I'm writing a radio driver that masquerade radio as a NIC. when the module is loaded, I just register_netdev a net_device struct, while unregister_netdev at module cleanup.

Tony

#6 lore raw
Quoted 7 lines · Tony
Quoted 7 lines

Not strange at all. The typical network driver is implemented using pci_register_driver which will set the owner filed of the driver's struct driver which then is being used for internal reference counting. Other busses or line disciplines (SLIP, PPP, AX.25 ...) need to do the equivalent or the kernel will believe reference counting isn't necessary and it's ok to unload the module at any time.

Quoted 8 lines
Quoted 4 lines

In which driver did you hit this problem?

Ralf

I have a radio connected to host using ethernet. I'm writing a radio driver that masquerade radio as a NIC. when the module is loaded, I just register_netdev a net_device struct, while unregister_netdev at module cleanup.

register_netdev / unregister_netdev don't deal with the .owner stuff, so your bug isn't there. If your NIC is a PCI card, it should register it's driver through pci_register_driver which would deal with the necessary reference counting. If it's implemented as a platform device you're presumably calling driver_register() before platform_device_register() and driver_register() would do the necessary magic for you. If you're using a different bus it may have it's own variant of driver_register which you should call. If you don't, you have a problem :-)

Ralf

#9 lore raw
In reply to Tony
Quoted 9 lines · On Thu, 10 Nov 2005 21:14:29 +0800 Tony <[email protected]> wrote:

Hello All,
Usually, when a net_device->open is called, it will MOD_INC_USE_COUNT on success. It is removed since 2.5.x, then should I increase the use count? how? thx.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Did you read Documentation/network/netdevices.txt?

Networking devices don't do ref counting because they should be removable at any time! Because of hotplug and failover, it just doesn't work to keep track of ref counting network devices.

What happens is that each protocol is notified on module removal of a network device. The protocol then cleans up all references to that device. If the protocol is buggy, then you will see the kernel wait and print a message that ref count is still not correct.

Signature · 2 lines
Stephen Hemminger <[email protected]>
OSDL http://developer.osdl.org/~shemminger
author
#7 lore raw
In reply to Ralf Baechle
Quoted 27 lines · Ralf Baechle
Quoted 7 lines · Tony
Quoted 7 lines

Not strange at all. The typical network driver is implemented using pci_register_driver which will set the owner filed of the driver's struct driver which then is being used for internal reference counting. Other busses or line disciplines (SLIP, PPP, AX.25 ...) need to do the equivalent or the kernel will believe reference counting isn't necessary and it's ok to unload the module at any time.

Quoted 6 lines
Quoted 4 lines

In which driver did you hit this problem?

Ralf

I have a radio connected to host using ethernet. I'm writing a radio driver that masquerade radio as a NIC. when the module is loaded, I just register_netdev a net_device struct, while unregister_netdev at module cleanup.

register_netdev / unregister_netdev don't deal with the .owner stuff, so your bug isn't there. If your NIC is a PCI card, it should register it's driver through pci_register_driver which would deal with the necessary reference counting. If it's implemented as a platform device you're presumably calling driver_register() before platform_device_register() and driver_register() would do the necessary magic for you. If you're using a different bus it may have it's own variant of driver_register which you should call. If you don't, you have a problem :-)

Quoted 2 lines

Ralf

That is indeed my problem. My driver is none of types of drivers, it's just a software virtual one. I think I should mimic the way SLIP handle it. thank a loooooooot!!!

Tony

#8 lore raw
Quoted 28 lines · Tony
Quoted 28 lines
Quoted 10 lines
Quoted 10 lines

Not strange at all. The typical network driver is implemented using pci_register_driver which will set the owner filed of the driver's struct driver which then is being used for internal reference counting. Other busses or line disciplines (SLIP, PPP, AX.25 ...) need to do the equivalent
or the kernel will believe reference counting isn't necessary and it's ok to unload the module at any time.

In which driver did you hit this problem?

Quoted 7 lines
Quoted 2 lines

Ralf

I have a radio connected to host using ethernet. I'm writing a radio driver that masquerade radio as a NIC. when the module is loaded, I just register_netdev a net_device struct, while unregister_netdev at module cleanup.

register_netdev / unregister_netdev don't deal with the .owner stuff, so your bug isn't there. If your NIC is a PCI card, it should register it's driver through pci_register_driver which would deal with the necessary reference counting. If it's implemented as a platform device you're presumably calling driver_register() before platform_device_register() and driver_register() would do the necessary magic for you. If you're using a different bus it may have it's own variant of driver_register which you should call. If you don't, you have a problem :-)

Quoted 5 lines
Quoted 2 lines

Ralf

That is indeed my problem. My driver is none of types of drivers, it's just a software virtual one. I think I should mimic the way SLIP handle it. thank a loooooooot!!!

SLIP is a line discipline; it's reference counting happens through tty_register_ldisc() but probably your code isn't a line discipline ... You however might use the platform device code - see include/linux/platform_device.h and the many users throughout the kernel. The platform device concept was really meant to support physical hardware but it should work just fine in your case. Maybe drivers/net/mipsnet.c can serve as an example - it's a driver for virtual NIC on a software emulator.

Ralf