1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter 10. What Functions Are Safe To Call From Interrupts?</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="index.html" title="Unreliable Guide To Locking"><link rel="prev" href="mostly-hardirq.html" title="Data Which Mostly Used By An IRQ Handler"><link rel="next" href="dont-sleep.html" title="Some Functions Which Don't Sleep"></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 10. What Functions Are Safe To Call From Interrupts?</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="mostly-hardirq.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="dont-sleep.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="sleeping-things"></a>Chapter 10. What Functions Are Safe To Call From Interrupts?</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect1"><a href="sleeping-things.html#sleeping">Some Functions Which Sleep</a></span></dt><dt><span class="sect1"><a href="dont-sleep.html">Some Functions Which Don't Sleep</a></span></dt></dl></div><p> 2 Many functions in the kernel sleep (ie. call schedule()) 3 directly or indirectly: you can never call them while holding a 4 spinlock, or with preemption disabled. This also means you need 5 to be in user context: calling them from an interrupt is illegal. 6 </p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sleeping"></a>Some Functions Which Sleep</h2></div></div></div><p> 7 The most common ones are listed below, but you usually have to 8 read the code to find out if other calls are safe. If everyone 9 else who calls it can sleep, you probably need to be able to 10 sleep, too. In particular, registration and deregistration 11 functions usually expect to be called from user context, and can 12 sleep. 13 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p> 14 Accesses to 15 <a class="firstterm" href="glossary.html#gloss-userspace"><em class="firstterm">userspace</em></a>: 16 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p> 17 <code class="function">copy_from_user()</code> 18 </p></li><li class="listitem"><p> 19 <code class="function">copy_to_user()</code> 20 </p></li><li class="listitem"><p> 21 <code class="function">get_user()</code> 22 </p></li><li class="listitem"><p> 23 <code class="function">put_user()</code> 24 </p></li></ul></div></li><li class="listitem"><p> 25 <code class="function">kmalloc(GFP_KERNEL)</code> 26 </p></li><li class="listitem"><p> 27 <code class="function">mutex_lock_interruptible()</code> and 28 <code class="function">mutex_lock()</code> 29 </p><p> 30 There is a <code class="function">mutex_trylock()</code> which does not 31 sleep. Still, it must not be used inside interrupt context since 32 its implementation is not safe for that. 33 <code class="function">mutex_unlock()</code> will also never sleep. 34 It cannot be used in interrupt context either since a mutex 35 must be released by the same task that acquired it. 36 </p></li></ul></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="mostly-hardirq.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="dont-sleep.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Data Which Mostly Used By An IRQ Handler </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Some Functions Which Don't Sleep</td></tr></table></div></body></html> 37