From: Jeff Garzik <jgarzik@mandrakesoft.com>
To: "Hen, Shmulik" <shmulik.hen@intel.com>
Cc: "'LKML'" <linux-kernel@vger.kernel.org>,
"'LNML'" <linux-net@vger.kernel.org>
Subject: Re: Locking Between User Context and Soft IRQs in 2.4.0
Date: Sat, 04 Nov 2000 04:45:33 -0500 [thread overview]
Message-ID: <3A03DABD.AF4B9AD5@mandrakesoft.com> (raw)
In-Reply-To: <07E6E3B8C072D211AC4100A0C9C5758302B27077@hasmsx52.iil.intel.com>
[-- Attachment #1: Type: text/plain, Size: 2604 bytes --]
"Hen, Shmulik" wrote:
> We are trying to port a network driver from 2.2.x to 2.4.x and have some
> question regarding locks.
> According to the kernel locking HOWTO, we have to take extra care when
> locking between user context threads and BH/tasklet/softIRQ,
> so we learned (the hard way ;-) that when running the ioctl system call from
> an application we should use spin_lock/unlock_bh() and not
> spin_lock/unlock() inside dev->do_ioctl().
That is not necessarily true. If you have timers or tasklets going,
sure. I prefer kernel threads for a lot of tasks nowadays, because you
only have two cases for locking -- user and interrupt -- and you can
sleep all you want to in a kernel thread.
> * What about the other entry points implemented in net_device ?
I wrote the attached doc, after tracing through the code. It has not
been reviewed yet so it is not canonical, but hopefully it is
informative...
> * We've got dev->get_stats, dev->set_mac_address,
> dev->set_mutlicast_list and others that are all called from running
> 'ifconfig' which is an application. Are they considered user context too ?
You are inside a spinlock in get_stats, so you cannot sleep. But you
can sleep in set_multicast_list. Not sure about set_mac_address.
> * What about dev->open and dev->stop ?
Sleep all you want, we'll leave the light on for ya.
> * We figured that dev->hard_start_xmit() and timer callbacks are not
> considered user context, but how can I find out if they are being run as
> SoftIRQ or as tasklets or as Bottom Halves ? (their different definitions
> require different types of protections)
I'm not sure about the context from which hard_start_xmit is called...
Its inside a spinlock, so you shouldn't be sleeping. timers are unique
unto themselves... but you lock against them using spin_lock_bh outside
the timer, and spin_lock inside the timer.
> wrap entire operations from top to bottom. For example, our
> dev->hard_start_xmit() will have a spin_lock() at the beginning and a
> spin_unlock() at the end of the function.
Why? dev->xmit_lock is obtained before dev->hard_start_xmit is called,
and released after it returns.
> * What about other calls to the kernel ? can the running thread be
> switched out of context when calling kernel entries and not be switched back
> in when they finish ? should I beware of deadlocks in such case ?
You should always beware of deadlocks!
Jeff
--
Jeff Garzik | Dinner is ready when
Building 1024 | the smoke alarm goes off.
MandrakeSoft | -/usr/games/fortune
[-- Attachment #2: netdevices.txt --]
[-- Type: text/plain, Size: 785 bytes --]
struct net_device synchronization rules
=======================================
dev->open:
Locking: Inside rtnl_lock() semaphore.
Sleeping: OK
dev->stop:
Locking: Inside rtnl_lock() semaphore.
Sleeping: OK
dev->do_ioctl:
Locking: Inside rtnl_lock() semaphore.
Sleeping: OK
dev->get_stats:
Locking: Inside dev_base_lock spinlock.
Sleeping: NO
dev->hard_start_xmit:
Locking: Inside dev->xmit_lock spinlock.
Sleeping: NO[1]
dev->tx_timeout:
Locking: Inside dev->xmit_lock spinlock.
Sleeping: NO[1]
dev->set_multicast_list:
Locking: Inside dev->xmit_lock spinlock.
Sleeping: NO[1]
NOTE [1]: On principle, you should not sleep when a spinlock is held.
However, since this spinlock is per-net-device, we only block ourselves
if we sleep, so the effect is mitigated.
next prev parent reply other threads:[~2000-11-04 9:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-10-30 14:10 Locking Between User Context and Soft IRQs in 2.4.0 Hen, Shmulik
2000-11-04 9:45 ` Jeff Garzik [this message]
2000-11-04 10:19 ` Andi Kleen
2000-11-04 15:36 ` Jeff Garzik
2000-11-04 16:56 ` Andi Kleen
2000-11-04 17:07 ` Jeff Garzik
2000-11-05 0:38 ` Andi Kleen
2000-11-05 1:28 ` Andrew Morton
2000-11-05 1:52 ` Andrew Morton
2000-11-05 2:32 ` Andi Kleen
2000-11-05 3:39 ` Keith Owens
2000-11-05 3:47 ` Keith Owens
2000-11-05 11:45 ` Andrew Morton
2000-11-06 2:20 ` Paul Gortmaker
2000-11-06 9:55 ` Andrew Morton
2000-11-06 10:05 ` Jeff Garzik
2000-11-06 12:37 ` Keith Owens
2000-11-06 12:49 ` Jeff Garzik
2000-11-06 12:58 ` Keith Owens
2000-11-06 13:09 ` Jeff Garzik
2000-11-06 13:18 ` Keith Owens
2000-11-07 2:23 ` Rusty Russell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3A03DABD.AF4B9AD5@mandrakesoft.com \
--to=jgarzik@mandrakesoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-net@vger.kernel.org \
--cc=shmulik.hen@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox