lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.02.1306191029530.4013@ionos.tec.linutronix.de>
Date:	Wed, 19 Jun 2013 10:41:21 +0200 (CEST)
From:	Thomas Gleixner <tglx@...utronix.de>
To:	Chen Gang <gang.chen@...anux.com>
cc:	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] kernel/timer.c: using spin_lock_irqsave instead of
 spin_lock + local_irq_save, especially when CONFIG_LOCKDEP not defined

On Wed, 19 Jun 2013, Chen Gang wrote:

> 
> When CONFIG_LOCKDEP is not defined, spin_lock_irqsave() is not equal to
> spin_lock() + local_irq_save().
> 
> In __mod_timer(), After call spin_lock_irqsave() with 'base->lock' in
> lock_timer_base(), it may use spin_lock() with the 'new_base->lock'.
> 
> It may let original call do_raw_spin_lock_flags() with 'base->lock',
> but new  call LOCK_CONTENDED() with 'new_base->lock'.
> 
> In fact, we need both of them call do_raw_spin_lock_flags(), so use
> spin_lock_irqsave() instead of spin_lock() + local_irq_save().

Why do we need to do that? There is no reason to do so and it's
totally irrelevant whether CONFIG_LOCKDEP is enabled or not.

The code is written intentionally this way.

What's the difference between:

       spin_lock_irqsave(&l1, flags);
       spin_unlock(&l1);
       spin_lock(l2);
       spin_unlock_irqrestore(&l2, flags);

and

       spin_lock_irqsave(&l1, flags);
       spin_unlock_irqrestore(&l1);
       spin_lock_irqsave(l2, flags);
       spin_unlock_irqrestore(&l2, flags);

The difference is that we avoid to touch the interrupt disable in the
cpu, which might be an expensive operation depending on the cpu model.

There is no point in reenabling interrupts just to disable them
again a few instruction cycles later.

And lockdep is perfectly fine with that code. All lockdep cares about
is whether the lock context (interrupts disabled) is correct or
not.

Thanks,

	tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ