From: Joey Gouly <joey.gouly@arm.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com,
james.morse@arm.com, maz@kernel.org, will@kernel.org
Subject: Re: [PATCH 2/4] arm64: entry: clarify entry/exit helpers
Date: Tue, 3 Aug 2021 12:53:50 +0100 [thread overview]
Message-ID: <20210803115350.GA52119@e124191.cambridge.arm.com> (raw)
In-Reply-To: <20210802140733.52716-3-mark.rutland@arm.com>
On Mon, Aug 02, 2021 at 03:07:31PM +0100, Mark Rutland wrote:
> When entering an exception, we must perform irq/context state management
> before we can use instrumentable C code. Similary, when exiting an
typo: Similarily
> exception we cannot use instrumentable C code after we perform
> irq/context state management.
>
> Originally, we'd intended that the enter_from_*() and exit_to_*()
> helpers would enforce this by virtue of being the first and last
> functions called, respectively, in an exception handler. However, as
> they now call instrumentable code themselves, this is not as clearly
> true.
>
> To make this more robust, this patch splits the irq/context state
> management into separate helpers, with all the helpers commented to make
> their intended purpose more obvious.
>
> In exit_to_kernel_mode() we'll now check TFSR_EL1 before we assert that
> IRQs are disabled, but this ordering is not important, and other than
> this there should be no functional change as a result of this patch.
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: James Morse <james.morse@arm.com>
> Cc: Joey Gouly <joey.gouly@arm.com>
> Cc: Marc Zyngier <maz@kernel.org>
> Cc: Will Deacon <will@kernel.org>
> ---
> arch/arm64/kernel/entry-common.c | 70 ++++++++++++++++++++++++++++++++++++----
> 1 file changed, 63 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c
> index 6f7a98d8d60f..6dc64f99f185 100644
> --- a/arch/arm64/kernel/entry-common.c
> +++ b/arch/arm64/kernel/entry-common.c
> @@ -26,10 +26,14 @@
> #include <asm/system_misc.h>
>
> /*
> + * Handle IRQ/context state management when entering from kernel mode.
> + * Before this function is called it is not safe to call regular kernel code,
> + * intrumentable code, or any code which may trigger an exception.
> + *
> * This is intended to match the logic in irqentry_enter(), handling the kernel
> * mode transitions only.
> */
> -static void noinstr enter_from_kernel_mode(struct pt_regs *regs)
> +static __always_inline void __enter_from_kernel_mode(struct pt_regs *regs)
> {
> regs->exit_rcu = false;
>
> @@ -45,20 +49,26 @@ static void noinstr enter_from_kernel_mode(struct pt_regs *regs)
> lockdep_hardirqs_off(CALLER_ADDR0);
> rcu_irq_enter_check_tick();
> trace_hardirqs_off_finish();
> +}
>
> +static void noinstr enter_from_kernel_mode(struct pt_regs *regs)
> +{
> + __enter_from_kernel_mode(regs);
> mte_check_tfsr_entry();
> }
>
> /*
> + * Handle irq/context state management when exiting to kernel mode.
Uppercase IRQ to match the other comments.
> + * after this function returns it is not safe to call regular kernel code,
'After' to match the other comments.
> + * intrumentable code, or any code which may trigger an exception.
> + *
> * This is intended to match the logic in irqentry_exit(), handling the kernel
> * mode transitions only, and with preemption handled elsewhere.
> */
> -static void noinstr exit_to_kernel_mode(struct pt_regs *regs)
> +static __always_inline void __exit_to_kernel_mode(struct pt_regs *regs)
> {
> lockdep_assert_irqs_disabled();
>
> - mte_check_tfsr_exit();
> -
> if (interrupts_enabled(regs)) {
> if (regs->exit_rcu) {
> trace_hardirqs_on_prepare();
> @@ -75,7 +85,18 @@ static void noinstr exit_to_kernel_mode(struct pt_regs *regs)
Reviewed-by: Joey Gouly <joey.gouly@arm.com>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-08-03 12:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-02 14:07 [PATCH 0/4] arm64: entry: rework user return handling Mark Rutland
2021-08-02 14:07 ` [PATCH 1/4] arm64: entry: consolidate entry/exit helpers Mark Rutland
2021-08-03 12:07 ` Joey Gouly
2021-08-02 14:07 ` [PATCH 2/4] arm64: entry: clarify " Mark Rutland
2021-08-03 11:53 ` Joey Gouly [this message]
2021-08-02 14:07 ` [PATCH 3/4] arm64: entry: move bulk of ret_to_user to C Mark Rutland
2021-08-03 12:06 ` Joey Gouly
2021-08-02 14:07 ` [PATCH 4/4] arm64: entry: call exit_to_user_mode() from C Mark Rutland
2021-08-03 12:17 ` Joey Gouly
2021-08-05 13:38 ` [PATCH 0/4] arm64: entry: rework user return handling Catalin Marinas
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=20210803115350.GA52119@e124191.cambridge.arm.com \
--to=joey.gouly@arm.com \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=will@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;
as well as URLs for NNTP newsgroup(s).