<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:΢ÈíÑźÚ
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><br> <BR><div id="SkyDrivePlaceholder"></div><div>> From: mulyadi.santosa@gmail.com<br>> Date: Sun, 17 Feb 2013 12:37:21 +0700<br>> Subject: Re: spinlock deadlock<br>> To: buyit@live.cn<br>> CC: kernelnewbies@kernelnewbies.org<br>> <br>> On Fri, Feb 15, 2013 at 3:52 PM, buyitian <buyit@live.cn> wrote:<br>> > is it possible that printk cause deadlock? the path is as below:<br>> ><br>> > 1. taskA runs on CPU0, and run schedule to acqire the rq->lock.<br>> > 2. taskA calls printk while holding rq->lock.<br>> <br>> I began to get rusty on this...but, why do you grab run queue lock?<br>> <br>> </div><div> </div><div> i want to know why the authors use spinlock and semaphore like this, because the change history is very insteresting:</div><div>1. in patch 0b5e1c5255e7ee8670e077e8224e5c2281229a5b: Peter did below changes:</div><div> (1). in function console_trylock_for_printk():</div><blockquote style="margin-right: 0px;" dir="ltr"><blockquote style="margin-right: 0px;" dir="ltr"><div>if (!can_use_console(cpu)) {<br> console_locked = 0;<br>- up(&console_sem);<br>+ wake = 1;<br> retval = 0;<br> }<br> }<br> printk_cpu = UINT_MAX;<br> spin_unlock(&logbuf_lock);<br>+ if (wake)<br>+ up(&console_sem);</div></blockquote></blockquote><div> </div><div> (2). in function console_unlock():</div><div> </div><blockquote style="margin-right: 0px;" dir="ltr"><blockquote style="margin-right: 0px;" dir="ltr"><div>- up(&console_sem);<br> spin_unlock_irqrestore(&logbuf_lock, flags);<br>+ up(&console_sem);<br> if (wake_klogd)<br> wake_up_klogd();<br> } </div></blockquote></blockquote><div> </div><div> this patch is to prevent deadlock between rq->lock and logbuf_lock. i can understand this thanks to Rabin.</div><div> </div><div>2. in patch 07354eb1a74d1e1ece29f8bafe0b46e8c77a95ef, Thomas did changes as below, which reverted the change from peter, i don't know why:</div><div> in function console_trylock_for_printk():</div><div> </div><blockquote style="margin-right: 0px;" dir="ltr"><div>- spin_unlock(&logbuf_lock);<br> if (wake)<br> up(&console_sem);<br>+ raw_spin_unlock(&logbuf_lock);</div></blockquote><div> </div><div> and this change exists in the latest kernel source code. it seems that deadlock bewteen rq->lock and logbuf_lock comes back, who can explain this, thanks.</div><div> </div><div> BTW: if i place printk inside schedule(), i may get rq->lock before calling printk.</div><div><br>> -- <br>> regards,<br>> <br>> Mulyadi Santosa<br>> Freelance Linux trainer and consultant<br>> <br>> blog: the-hydra.blogspot.com<br>> training: mulyaditraining.blogspot.com<br></div>                                            </div></body>
</html>