[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f933b06a-0f4a-3bdb-86ef-644ac0a16163@arm.com>
Date: Fri, 21 Dec 2018 14:57:15 +0000
From: James Morse <james.morse@....com>
To: Julien Thierry <julien.thierry@....com>
Cc: linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
mingo@...hat.com, peterz@...radead.org, catalin.marinas@....com,
will.deacon@....com, hpa@...or.com
Subject: Re: [PATCH v2 2/2] arm64: uaccess: Implement unsafe accessors
Hi Julien,
On 03/12/2018 13:55, Julien Thierry wrote:
> Current implementation of get/put_user_unsafe default to get/put_user
> which toggle PAN before each access, despite having been told by the caller
> that multiple accesses to user memory were about to happen.
>
> Provide implementations for user_access_begin/end to turn PAN off/on and
> implement unsafe accessors that assume PAN was already turned off.
> diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
> index 842fb95..4e6477b 100644
> --- a/arch/arm64/include/asm/sysreg.h
> +++ b/arch/arm64/include/asm/sysreg.h
> @@ -108,6 +108,8 @@
> #define SYS_DC_CSW sys_insn(1, 0, 7, 10, 2)
> #define SYS_DC_CISW sys_insn(1, 0, 7, 14, 2)
>
> +#define SYS_PSTATE_PAN sys_reg(3, 0, 4, 2, 3)
Nit: Could we keep this list in encoding order please.
(it makes conflicts easier to resolve in the future)
> #define SYS_OSDTRRX_EL1 sys_reg(2, 0, 0, 0, 2)
> #define SYS_MDCCINT_EL1 sys_reg(2, 0, 0, 2, 0)
> #define SYS_MDSCR_EL1 sys_reg(2, 0, 0, 2, 2)
> diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
> index 07c3408..cabfcae 100644
> --- a/arch/arm64/include/asm/uaccess.h
> +++ b/arch/arm64/include/asm/uaccess.h
> @@ -233,6 +233,23 @@ static inline void uaccess_enable_not_uao(void)
> __uaccess_enable(ARM64_ALT_PAN_NOT_UAO);
> }
>
> +#define unsafe_user_region_active uaccess_region_active
> +static inline bool uaccess_region_active(void)
> +{
> + if (system_uses_ttbr0_pan()) {
> + u64 ttbr;
> +
> + ttbr = read_sysreg(ttbr1_el1);
> + return ttbr & TTBR_ASID_MASK;
> + } else if (cpus_have_const_cap(ARM64_ALT_PAN_NOT_UAO)) {
> + return (read_sysreg(sctlr_el1) & SCTLR_EL1_SPAN) ?
> + false :
> + !read_sysreg_s(SYS_PSTATE_PAN);
> + }
> +
> + return false;
> +}
(Reading the SCTLR bit is a bit of a heavy-hammer, as suggested elsewhere on the
thread, can we use alternatives_applied here?)
It may be worth splitting this into three patches, so the 'unsafe' bits can be
merged without the debug option.
Either way, for the unsafe parts:
Reviewed-by: James Morse <james.morse@....com>
Thanks!
James
Powered by blists - more mailing lists