1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter&#160;5.&#160;Recipes for Deadlock</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="up" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="prev" href="ioctls.html" title="Chapter&#160;4.&#160;ioctls: Not writing a new system call"><link rel="next" href="common-routines.html" title="Chapter&#160;6.&#160;Common Routines"></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">Chapter&#160;5.&#160;Recipes for Deadlock</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ioctls.html">Prev</a>&#160;</td><th width="60%" align="center">&#160;</th><td width="20%" align="right">&#160;<a accesskey="n" href="common-routines.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="deadlock-recipes"></a>Chapter&#160;5.&#160;Recipes for Deadlock</h1></div></div></div><p>
2   You cannot call any routines which may sleep, unless:
3  </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
4     You are in user context.
5    </p></li><li class="listitem"><p>
6     You do not own any spinlocks.
7    </p></li><li class="listitem"><p>
8     You have interrupts enabled (actually, Andi Kleen says
9     that the scheduling code will enable them for you, but
10     that's probably not what you wanted).
11    </p></li></ul></div><p>
12   Note that some functions may sleep implicitly: common ones are
13   the user space access functions (*_user) and memory allocation
14   functions without <span class="symbol">GFP_ATOMIC</span>.
15  </p><p>
16   You should always compile your kernel
17   <span class="symbol">CONFIG_DEBUG_ATOMIC_SLEEP</span> on, and it will warn
18   you if you break these rules.  If you <span class="emphasis"><em>do</em></span> break
19   the rules, you will eventually lock up your box.
20  </p><p>
21   Really.
22  </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ioctls.html">Prev</a>&#160;</td><td width="20%" align="center">&#160;</td><td width="40%" align="right">&#160;<a accesskey="n" href="common-routines.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;4.&#160;ioctls: Not writing a new system call&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Chapter&#160;6.&#160;Common Routines</td></tr></table></div></body></html>
23