From: george anzinger <george@mvista.com>
To: sivakumar.kuppusamy@wipro.com
Cc: Linux-Kernel <linux-kernel@vger.kernel.org>
Subject: Re: Locks in kernel
Date: Sun, 04 Nov 2001 08:47:53 -0800 [thread overview]
Message-ID: <3BE57139.4971ED0F@mvista.com> (raw)
In-Reply-To: <001701c1638e$9bd332e0$5f08720a@wipro.com>
Sivakumar Kuppusamy wrote:
>
> Hi All,
> I am having doubts in locking mechanism in Linux 2.2 kernel code.
>
> We have done modifications in the Linux kernel code to support our
> application which runs at the user space. The modification done in
> the Linux kernel is to maintain a table of data(like a routing table),
> which will be updated by the applicaition with appropriate data. This
> data will be used by the kernel for other processing.
>
> We are using "up" & "down" functions for locking global data in the kernel.
> Our code in kernel will get called when a IP packet is received. During
> that time we are trying to lock that global data and retrieve some
> info from that. Is this a correct way to do. We are also locking
> the global data when it gets updated from the application. Since
> ip_rcv() gets called from bottom_half(), can we do any locking
> stuff there? We faced kernel panicking when the application locked
> the global data and got scheduled to continue later(with lock held).
> That time ip_rcv() got called and we are trying to acquire the lock
> which is held by the scheduled process. This made the kernel panic.
>
> How should we approach this problem? Shouldn't we use any locking in
> the code which is called by the bottom_half()?
>
As I am sure you are beginning to suspect, you need to NOT hold locks in
tasks that can sleep which are also accessed from an interrupt context
(bottom_half). Among the locks that allow (or even force) sleeping are
the "up" "down" locks. These must NOT be used from the interrupt
context. Locks that can be used from the interrupt context are the
spinlocks. Of these you would need to use the "irq" versions. In this
group you will also find the read/ write locks which allow several
readers at a time, while writers are given exclusive access.
If you must allow sleeping locks, you will have to promote the interrupt
code to a kernel task which can sleep. This is done using wait queues.
There are various versions of these, but they all end up having the
"consumer" sleep until the "producer" calls "wake_up". Again, there are
various wrappers that can be used here. The key is that the interrupt
context calls the "wake_up" side and the kernel task calls the sleep
side.
Then you will most likely need to use one of the spinlock_irq locks to
synchronize the interrupt context with the kernel task, but remember,
the kernel task must NOT sleep while holding a spinlock.
This is an overview. You can find much more detail in the
kernel-hacking-HOWTO
http://www.linuxgrill.com/anonymous/fire/netfilter/kernel-hacking-HOWTO-5.html
or try Google.
George
prev parent reply other threads:[~2001-11-04 18:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-02 11:07 Locks in kernel Sivakumar Kuppusamy
2001-11-04 16:47 ` george anzinger [this message]
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=3BE57139.4971ED0F@mvista.com \
--to=george@mvista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sivakumar.kuppusamy@wipro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.