public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: elver@google.com, paulmck@kernel.org, peterz@infradead.org,
	catalin.marinas@arm.com, james.morse@arm.com,
	linux-arm-kernel@lists.infradead.org, dvyukov@google.com
Subject: Re: [PATCH 09/11] arm64: entry: fix non-NMI kernel<->kernel transitions
Date: Mon, 30 Nov 2020 11:22:09 +0000	[thread overview]
Message-ID: <20201130112209.GD24098@willie-the-truck> (raw)
In-Reply-To: <20201126123602.23454-10-mark.rutland@arm.com>

On Thu, Nov 26, 2020 at 12:36:00PM +0000, Mark Rutland wrote:
> There are periods in kernel mode when RCU is not watching and/or the
> scheduler tick is disabled, but we can still take exceptions such as
> interrupts. The arm64 exception handlers do not account for this, and
> it's possible that RCU is not watching while an exception handler runs.
> 
> The x86/generic entry code handles this by ensuring that all (non-NMI)
> kernel exception handlers call irqentry_enter() and irqentry_exit(),
> which handle RCU, lockdep, and IRQ flag tracing. We can't yet move to
> the generic entry code, and already hadnle the user<->kernel transitions
> elsewhere, so we add new kernel<->kernel transition helpers alog the
> lines of the generic entry code.
> 
> Since we now track interrupts becoming masked when an exception is
> taken, local_daif_inherit() is modified to track interrupts becoming
> re-enabled when the original context is inherited. To balance the
> entry/exit paths, each handler masks all DAIF exceptions before
> exit_to_kernel_mode().
> 
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Will Deacon <will@kernel.org>
> ---
>  arch/arm64/include/asm/daifflags.h |  3 ++
>  arch/arm64/kernel/entry-common.c   | 59 ++++++++++++++++++++++++++++++++++++--
>  2 files changed, 59 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h
> index ec213b4a1650..1c26d7baa67f 100644
> --- a/arch/arm64/include/asm/daifflags.h
> +++ b/arch/arm64/include/asm/daifflags.h
> @@ -128,6 +128,9 @@ static inline void local_daif_inherit(struct pt_regs *regs)
>  {
>  	unsigned long flags = regs->pstate & DAIF_MASK;
>  
> +	if (interrupts_enabled(regs))
> +		trace_hardirqs_on();
> +
>  	/*
>  	 * We can't use local_daif_restore(regs->pstate) here as
>  	 * system_has_prio_mask_debugging() won't restore the I bit if it can
> diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
> index 49d1c1dd9baf..526e98cec86e 100644
> --- a/arch/arm64/kernel/entry-common.c
> +++ b/arch/arm64/kernel/entry-common.c
> @@ -17,12 +17,50 @@
>  #include <asm/mmu.h>
>  #include <asm/sysreg.h>
>  
> +static void noinstr enter_from_kernel_mode(struct pt_regs *regs)
> +{
> +	regs->exit_rcu = false;
> +
> +	if (!IS_ENABLED(CONFIG_TINY_RCU) && is_idle_task(current)) {
> +		lockdep_hardirqs_off(CALLER_ADDR0);
> +		rcu_irq_enter();
> +		trace_hardirqs_off_finish();
> +
> +		regs->exit_rcu = true;
> +		return;
> +	}
> +
> +	lockdep_hardirqs_off(CALLER_ADDR0);
> +	rcu_irq_enter_check_tick();
> +	trace_hardirqs_off_finish();
> +}
> +
> +static void noinstr exit_to_kernel_mode(struct pt_regs *regs)
> +{
> +	lockdep_assert_irqs_disabled();
> +
> +	if (interrupts_enabled(regs)) {
> +		if (regs->exit_rcu) {
> +			trace_hardirqs_on_prepare();
> +			lockdep_hardirqs_on_prepare(CALLER_ADDR0);
> +			rcu_irq_exit();
> +			lockdep_hardirqs_on(CALLER_ADDR0);
> +			return;
> +		}
> +
> +		trace_hardirqs_on();
> +	} else {
> +		if (regs->exit_rcu)
> +			rcu_irq_exit();
> +	}
> +}

Hmm. I'd prefer to rework this to avoid the nested early return:

e.g:

	// exit_to_kernel_mode()
	if (!interrupts_enabled(regs)) {
		if (regs->exit_rcu)
			rcu_irq_exit()
	} else if (regs->exit_rcu) {
		trace_hardirqs_on_prepare();
		...
	} else {
		trace_hardirqs_on();
	}


but I see you're following the pattern in kernel/entry/common.c, which
makes sense given that the long-term goal should be to move over to that.

In which case, can you add a comment somewhere that this is deliberately
structured to map to the common code?

Cheers,

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-11-30 11:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 12:35 [PATCH 00/11] arm64: entry lockdep/rcu/tracing fixes Mark Rutland
2020-11-26 12:35 ` [PATCH 01/11] arm64: syscall: exit userspace before unmasking exceptions Mark Rutland
2020-11-26 12:35 ` [PATCH 02/11] arm64: mark idle code as noinstr Mark Rutland
2020-11-26 12:35 ` [PATCH 03/11] arm64: entry: mark entry " Mark Rutland
2020-11-26 12:35 ` [PATCH 04/11] arm64: entry: move enter_from_user_mode to entry-common.c Mark Rutland
2020-11-26 12:35 ` [PATCH 05/11] arm64: entry: prepare ret_to_user for function call Mark Rutland
2020-11-26 12:35 ` [PATCH 06/11] arm64: entry: move el1 irq/nmi logic to C Mark Rutland
2020-11-26 12:35 ` [PATCH 07/11] arm64: entry: fix non-NMI user<->kernel transitions Mark Rutland
2020-11-30 11:22   ` Will Deacon
2020-11-26 12:35 ` [PATCH 08/11] arm64: ptrace: prepare for EL1 irq/rcu tracking Mark Rutland
2020-11-30 11:01   ` Will Deacon
2020-11-26 12:36 ` [PATCH 09/11] arm64: entry: fix non-NMI kernel<->kernel transitions Mark Rutland
2020-11-30 11:22   ` Will Deacon [this message]
2020-11-26 12:36 ` [PATCH 10/11] arm64: entry: fix NMI {user, kernel}->kernel transitions Mark Rutland
2020-11-26 18:41   ` [PATCH 10/11] arm64: entry: fix NMI {user,kernel}->kernel transitions Mark Rutland
2020-11-26 21:00     ` Will Deacon
2020-11-26 12:36 ` [PATCH 11/11] arm64: entry: fix EL1 debug transitions Mark Rutland
2020-11-30 11:23 ` [PATCH 00/11] arm64: entry lockdep/rcu/tracing fixes Will Deacon
2020-11-30 12:03 ` Marco Elver
2020-11-30 12:38   ` Mark Rutland
     [not found]     ` <20201130133245.GA1307615@elver.google.com>
2020-11-30 16:54       ` Mark Rutland

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=20201130112209.GD24098@willie-the-truck \
    --to=will@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.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