From: Mark Rutland <mark.rutland@arm.com>
To: Marc Zyngier <maz@kernel.org>
Cc: Will Deacon <will@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Thomas Gleixner <tglx@linutronix.de>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, kernel-team@android.com
Subject: Re: [PATCH v2 4/4] arm64: Rework ARM_ERRATUM_1414080 handling
Date: Mon, 6 Jul 2020 18:12:48 +0100 [thread overview]
Message-ID: <20200706171248.GC61340@C02TD0UTHF1T.local> (raw)
In-Reply-To: <20200706163802.1836732-5-maz@kernel.org>
On Mon, Jul 06, 2020 at 05:38:02PM +0100, Marc Zyngier wrote:
> The current handling of erratum 1414080 has the side effect that
> cntkctl_el1 can get changed for both 32 and 64bit tasks.
>
> This isn't a problem so far, but if we ever need to mitigate another
> of these errata on the 64bit side, we'd better keep the messing with
> cntkctl_el1 local to 32bit tasks.
>
> For that, make sure that on entering the kernel from a 32bit tasks,
> userspace access to cntvct gets enabled, and disabled returning to
> userspace, while it never gets changed for 64bit tasks.
>
> Signed-off-by: Marc Zyngier <maz@kernel.org>
The asm looks sound to me. Suggestion below, but either way:
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
> ---
> arch/arm64/kernel/entry.S | 40 +++++++++++++++++++++++----------------
> 1 file changed, 24 insertions(+), 16 deletions(-)
>
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 5304d193c79d..8f51f3273bc7 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -167,6 +167,19 @@ alternative_cb_end
> stp x28, x29, [sp, #16 * 14]
>
> .if \el == 0
> + .if \regsize == 32
> + // If we come back from a 32bit task on a system affected by
> + // 1418040, let's reenable userspace access to the virtual counter.
> +#ifdef CONFIG_ARM64_ERRATUM_1418040
> +alternative_if_not ARM64_WORKAROUND_1418040
> + b .L__entry_skip_wa_1418040\@
> +alternative_else_nop_endif
> + mrs x0, cntkctl_el1
> + orr x0, x0, #2 // ARCH_TIMER_USR_VCT_ACCESS_EN
> + msr cntkctl_el1, x0
> +.L__entry_skip_wa_1418040\@:
> +#endif
Given this is only 3 instructions, it might be clearer to remove the branch
and label and NOP the whole thing for legibility:
| #ifdef CONFIG_ARM64_ERRATUM_1418040
| alternative_if ARM64_WORKAROUND_1418040
| mrs x0. cntkctl_el1
| orr x0, x0, #2 // ARCH_TIMER_USR_VCT_ACCESS_EN
| msr cntkctl_el1, x0
| alternative_else_nop_endif
| #endif
... and likewise for the clearing case.
Regardless, this looks sound to me, so take your pick. :)
Mark.
> + .endif
> clear_gp_regs
> mrs x21, sp_el0
> ldr_this_cpu tsk, __entry_task, x20
> @@ -318,7 +331,17 @@ alternative_else_nop_endif
> ldr x23, [sp, #S_SP] // load return stack pointer
> msr sp_el0, x23
> tst x22, #PSR_MODE32_BIT // native task?
> - b.eq 3f
> + b.eq 4f
> +
> +#ifdef CONFIG_ARM64_ERRATUM_1418040
> +alternative_if_not ARM64_WORKAROUND_1418040
> + b 3f
> +alternative_else_nop_endif
> + mrs x1, cntkctl_el1
> + bic x1, x1, #2 // ARCH_TIMER_USR_VCT_ACCESS_EN
> + msr cntkctl_el1, x1
> +3:
> +#endif
>
> #ifdef CONFIG_ARM64_ERRATUM_845719
> alternative_if ARM64_WORKAROUND_845719
> @@ -330,22 +353,7 @@ alternative_if ARM64_WORKAROUND_845719
> #endif
> alternative_else_nop_endif
> #endif
> -3:
> -#ifdef CONFIG_ARM64_ERRATUM_1418040
> -alternative_if_not ARM64_WORKAROUND_1418040
> - b 4f
> -alternative_else_nop_endif
> - /*
> - * if (x22.mode32 == cntkctl_el1.el0vcten)
> - * cntkctl_el1.el0vcten = ~cntkctl_el1.el0vcten
> - */
> - mrs x1, cntkctl_el1
> - eon x0, x1, x22, lsr #3
> - tbz x0, #1, 4f
> - eor x1, x1, #2 // ARCH_TIMER_USR_VCT_ACCESS_EN
> - msr cntkctl_el1, x1
> 4:
> -#endif
> scs_save tsk, x0
>
> /* No kernel C function calls after this as user keys are set. */
> --
> 2.27.0
>
next prev parent reply other threads:[~2020-07-06 17:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-06 16:37 [PATCH v2 0/4] arm64: Allow the compat vdso to be disabled at runtime Marc Zyngier
2020-07-06 16:37 ` [PATCH v2 1/4] arm64: Introduce a way to disable the 32bit vdso Marc Zyngier
2020-07-06 16:38 ` [PATCH v2 2/4] arm64: arch_timer: Allow an workaround descriptor to disable compat vdso Marc Zyngier
2020-07-06 16:55 ` Mark Rutland
2020-07-06 16:38 ` [PATCH v2 3/4] arm64: arch_timer: Disable the compat vdso for cores affected by ARM64_WORKAROUND_1418040 Marc Zyngier
2020-07-06 16:57 ` Mark Rutland
2020-07-06 16:38 ` [PATCH v2 4/4] arm64: Rework ARM_ERRATUM_1414080 handling Marc Zyngier
2020-07-06 17:12 ` Mark Rutland [this message]
2020-07-08 22:02 ` [PATCH v2 0/4] arm64: Allow the compat vdso to be disabled at runtime Will Deacon
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=20200706171248.GC61340@C02TD0UTHF1T.local \
--to=mark.rutland@arm.com \
--cc=catalin.marinas@arm.com \
--cc=daniel.lezcano@linaro.org \
--cc=kernel-team@android.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=tglx@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--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).