mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	x86@kernel.org
Subject: Re: entry: Fix the incorrect ordering of lockdep and RCU check
Date: Wed, 4 Nov 2020 16:29:18 +0000	[thread overview]
Message-ID: <20201104162918.GD7577@C02TD0UTHF1T.local> (raw)
In-Reply-To: <87y2jhl19s.fsf@nanos.tec.linutronix.de>

On Wed, Nov 04, 2020 at 02:06:23PM +0100, Thomas Gleixner wrote:
> When an exception/interrupt hits kernel space and the kernel is not
> currently in the idle task then RCU must be watching.
> 
> irqentry_enter() validates this via rcu_irq_enter_check_tick(), which in
> turn invokes lockdep when taking a lock. But at that point lockdep does not
> yet know about the fact that interrupts have been disabled by the CPU,
> which triggers a lockdep splat complaining about inconsistent state.
> 
> Invoking trace_hardirqs_off() before rcu_irq_enter_check_tick() defeats the
> point of rcu_irq_enter_check_tick() because trace_hardirqs_off() uses RCU.
> 
> So use the same sequence as for the idle case and tell lockdep about the
> irq state change first, invoke the RCU check and then do the lockdep and
> tracer update.
> 
> Fixes: a5497bab5f72 ("entry: Provide generic interrupt entry/exit code")
> Reported-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: stable@vger.kernel.org

I just gave this a spin on x86_64 defconfig + PROVE_LOCKING +
DEBUG_LOCKDEP + NO_HZ_FULL + CONTEXT_TRACKING_FORCE, and it gets rid of
the boot-time splat. So FWIW:

Tested-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  kernel/entry/common.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> --- a/kernel/entry/common.c
> +++ b/kernel/entry/common.c
> @@ -337,10 +337,10 @@ noinstr irqentry_state_t irqentry_enter(
>  	 * already contains a warning when RCU is not watching, so no point
>  	 * in having another one here.
>  	 */
> +	lockdep_hardirqs_off(CALLER_ADDR0);
>  	instrumentation_begin();
>  	rcu_irq_enter_check_tick();
> -	/* Use the combo lockdep/tracing function */
> -	trace_hardirqs_off();
> +	trace_hardirqs_off_finish();
>  	instrumentation_end();
>  
>  	return ret;

  reply	other threads:[~2020-11-04 16:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-04 13:06 Thomas Gleixner
2020-11-04 16:29 ` Mark Rutland [this message]
2020-11-04 17:10 ` [tip: core/urgent] " tip-bot2 for Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201104162918.GD7577@C02TD0UTHF1T.local \
    --to=mark.rutland@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome