1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Locking Between User Context and Softirqs</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Locking"><link rel="up" href="locks.html" title="Chapter&#160;3.&#160;Locking in the Linux Kernel"><link rel="prev" href="usercontextlocking.html" title="Locking Only In User Context"><link rel="next" href="lock-user-tasklet.html" title="Locking Between User Context and Tasklets"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Locking Between User Context and Softirqs</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="usercontextlocking.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;3.&#160;Locking in the Linux Kernel</th><td width="20%" align="right">&#160;<a accesskey="n" href="lock-user-tasklet.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="lock-user-bh"></a>Locking Between User Context and Softirqs</h2></div></div></div><p>
2      If a <a class="firstterm" href="glossary.html#gloss-softirq"><em class="firstterm">softirq</em></a> shares
3      data with user context, you have two problems.  Firstly, the current 
4      user context can be interrupted by a softirq, and secondly, the
5      critical region could be entered from another CPU.  This is where
6      <code class="function">spin_lock_bh()</code> 
7      (<code class="filename">include/linux/spinlock.h</code>) is
8      used.  It disables softirqs on that CPU, then grabs the lock.
9      <code class="function">spin_unlock_bh()</code> does the reverse.  (The
10      '_bh' suffix is a historical reference to "Bottom Halves", the
11      old name for software interrupts.  It should really be
12      called spin_lock_softirq()' in a perfect world).
13    </p><p>
14      Note that you can also use <code class="function">spin_lock_irq()</code>
15      or <code class="function">spin_lock_irqsave()</code> here, which stop
16      hardware interrupts as well: see <a class="xref" href="hardirq-context.html" title="Chapter&#160;4.&#160;Hard IRQ Context">Chapter&#160;4, <i>Hard IRQ Context</i></a>.
17    </p><p>
18      This works perfectly for <a class="firstterm" href="glossary.html#gloss-up"><em class="firstterm"><acronym class="acronym">UP
19      </acronym></em></a> as well: the spin lock vanishes, and this macro 
20      simply becomes <code class="function">local_bh_disable()</code>
21      (<code class="filename">include/linux/interrupt.h</code>), which
22      protects you from the softirq being run.
23    </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="usercontextlocking.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="locks.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="lock-user-tasklet.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Locking Only In User Context&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Locking Between User Context and Tasklets</td></tr></table></div></body></html>
24