Re: [2.6.33-rc5] starting emacs makes lockdep warning

From: Eric W. Biederman
Date: Tue Jan 26 2010 - 07:34:00 EST


AmÃrico Wang <xiyou.wangcong@xxxxxxxxx> writes:

> On Tue, Jan 26, 2010 at 5:14 PM, Eric W. Biederman
> <ebiederm@xxxxxxxxxxxx> wrote:
>> AmÃrico Wang <xiyou.wangcong@xxxxxxxxx> writes:
>>
>>> On Tue, Jan 26, 2010 at 3:45 PM, KOSAKI Motohiro
>>> <kosaki.motohiro@xxxxxxxxxxxxxx> wrote:
>>>> Hi
>>>>
>>>>> On Tue, Jan 26, 2010 at 02:01:12PM +0800, Am??rico Wang wrote:
>>>>>
>>>>> > I agree, it seems that patch is useless, since we already
>>>>> > do lock_kernel() before calling __f_setown()...
>>>>>
>>>>> What's to prevent pid from being freed under us? ÂBKL won't...
>>>>
>>>> I don't understand this issue at all. so, this is stupid dumb question.
>>>> Why can't we write following code?
>>>>
>>>>
>>>> Â Â Â Â Â Â Â Âenum pid_type type;
>>>> Â Â Â Â Â Â Â Âstruct pid *pid;
>>>> Â Â Â Â Â Â Â Âif (!waitqueue_active(&tty->read_wait))
>>>> Â Â Â Â Â Â Â Â Â Â Â Âtty->minimum_to_wake = 1;
>>>> Â Â Â Â Â Â Â Âspin_lock_irqsave(&tty->ctrl_lock, flags);
>>>> Â Â Â Â Â Â Â Âif (tty->pgrp) {
>>>> Â Â Â Â Â Â Â Â Â Â Â Âpid = tty->pgrp;
>>>> Â Â Â Â Â Â Â Â Â Â Â Âtype = PIDTYPE_PGID;
>>>> Â Â Â Â Â Â Â Â} else {
>>>> Â Â Â Â Â Â Â Â Â Â Â Âpid = task_pid(current);
>>>> Â Â Â Â Â Â Â Â Â Â Â Âtype = PIDTYPE_PID;
>>>> Â Â Â Â Â Â Â Â}
>>>> Â Â Â Â Â Â Â Âget_pid(pid) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â// insert here
>>>> Â Â Â Â Â Â Â Âspin_unlock_irqrestore(&tty->ctrl_lock, flags);
>>>> Â Â Â Â Â Â Â Âretval = __f_setown(filp, pid, type, 0);
>>>> Â Â Â Â Â Â Â Âput_pid(pid) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â// insert here
>>>>
>>>
>>> Yeah, this seems reasonable for me, but not sure if this is the best fix.
>>
>> That or tweak __f_setown to use irqsave/irqrestore variants for it's
>> locks, __f_setown is already atomic. ÂI prefer that direction because the
>> code is just a little simpler.
>>
>
> Oh, very good advice!
>
> Patch is below.
>
> -------------->
> Commit 703625118 causes a lockdep warning:
>
> [ INFO: possible irq lock inversion dependency detected ]
> 2.6.33-rc5 #77
> ---------------------------------------------------------
> emacs/1609 just changed the state of lock:
> (&(&tty->ctrl_lock)->rlock){+.....}, at: [<ffffffff8127c648>]
> tty_fasync+0xe8/0x190
> but this lock took another, HARDIRQ-unsafe lock in the past:
> (&(&sighand->siglock)->rlock){-.....}
>
> This is due to we use write_lock_irq() in __f_setown() which turns
> the IRQ on in write_unlock_irq(), causes this warning.
>
> Switch it ot write_lock_irqsave() and write_unlock_irqrestore(),
> as suggested by Eric.
>
> Reported-by: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxxxxxxx>
> Signed-off-by: WANG Cong <xiyou.wangcong@xxxxxxxxx>
>
> ----
>
> diff --git a/fs/fcntl.c b/fs/fcntl.c
> index 97e01dc..556b404 100644
> --- a/fs/fcntl.c
> +++ b/fs/fcntl.c
> @@ -199,7 +199,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
> static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
> int force)
> {
> - write_lock_irq(&filp->f_owner.lock);
> + int flags;

Minor nit. This should be "unsigned long flags;"

> + write_lock_irqsave(&filp->f_owner.lock, flags);
> if (force || !filp->f_owner.pid) {
> put_pid(filp->f_owner.pid);
> filp->f_owner.pid = get_pid(pid);
> @@ -211,7 +212,7 @@ static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
> filp->f_owner.euid = cred->euid;
> }
> }
> - write_unlock_irq(&filp->f_owner.lock);
> + write_unlock_irqrestore(&filp->f_owner.lock, flags);
> }
>
> int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,

Eric
¢éì®&Þ~º&¶¬–+-±éÝ¥Šw®žË±Êâmébžìdz¹Þ)í…æèw*jg¬±¨¶‰šŽŠÝj/êäz¹ÞŠà2ŠÞ¨è­Ú&¢)ß«a¶Úþø®G«éh®æj:+v‰¨Šwè†Ù>Wš±êÞiÛaxPjØm¶Ÿÿà -»+ƒùdš_