From: Catalin Marinas <catalin.marinas@arm.com>
To: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Will Deacon <will@kernel.org>,
Andrey Konovalov <andreyknvl@google.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linux Next Mailing List <linux-next@vger.kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>
Subject: Re: linux-next: manual merge of the akpm-current tree with the arm64 tree
Date: Thu, 3 Dec 2020 11:16:12 +0000 [thread overview]
Message-ID: <20201203111611.GD2224@gaia> (raw)
In-Reply-To: <20201203190426.5a2cc067@canb.auug.org.au>
On Thu, Dec 03, 2020 at 07:06:01PM +1100, Stephen Rothwell wrote:
> diff --cc arch/arm64/include/asm/uaccess.h
> index d841a560fae7,abb31aa1f8ca..000000000000
> --- a/arch/arm64/include/asm/uaccess.h
> +++ b/arch/arm64/include/asm/uaccess.h
> @@@ -186,64 -159,20 +159,43 @@@ static inline void __uaccess_enable_hw_
> CONFIG_ARM64_PAN));
> }
>
> - #define __uaccess_disable(alt) \
> - do { \
> - if (!uaccess_ttbr0_disable()) \
> - asm(ALTERNATIVE("nop", SET_PSTATE_PAN(1), alt, \
> - CONFIG_ARM64_PAN)); \
> - } while (0)
> -
> - #define __uaccess_enable(alt) \
> - do { \
> - if (!uaccess_ttbr0_enable()) \
> - asm(ALTERNATIVE("nop", SET_PSTATE_PAN(0), alt, \
> - CONFIG_ARM64_PAN)); \
> - } while (0)
> -
> +/*
> + * The Tag Check Flag (TCF) mode for MTE is per EL, hence TCF0
> + * affects EL0 and TCF affects EL1 irrespective of which TTBR is
> + * used.
> + * The kernel accesses TTBR0 usually with LDTR/STTR instructions
> + * when UAO is available, so these would act as EL0 accesses using
> + * TCF0.
> + * However futex.h code uses exclusives which would be executed as
> + * EL1, this can potentially cause a tag check fault even if the
> + * user disables TCF0.
> + *
> + * To address the problem we set the PSTATE.TCO bit in uaccess_enable()
> + * and reset it in uaccess_disable().
> + *
> + * The Tag check override (TCO) bit disables temporarily the tag checking
> + * preventing the issue.
> + */
> - static inline void uaccess_disable(void)
> + static inline void uaccess_disable_privileged(void)
> {
> + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(0),
> + ARM64_MTE, CONFIG_KASAN_HW_TAGS));
> +
> - __uaccess_disable(ARM64_HAS_PAN);
> + if (uaccess_ttbr0_disable())
> + return;
> +
> + __uaccess_enable_hw_pan();
> }
>
> - static inline void uaccess_enable(void)
> + static inline void uaccess_enable_privileged(void)
> {
> + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(1),
> + ARM64_MTE, CONFIG_KASAN_HW_TAGS));
> +
> - __uaccess_enable(ARM64_HAS_PAN);
> - }
> -
> - /*
> - * These functions are no-ops when UAO is present.
> - */
> - static inline void uaccess_disable_not_uao(void)
> - {
> - __uaccess_disable(ARM64_ALT_PAN_NOT_UAO);
> - }
> + if (uaccess_ttbr0_enable())
> + return;
>
> - static inline void uaccess_enable_not_uao(void)
> - {
> - __uaccess_enable(ARM64_ALT_PAN_NOT_UAO);
> + __uaccess_disable_hw_pan();
> }
>
> /*
Thanks Stephen, it looks fine. I may clean it up a bit with dedicated
functions for the asm statements but after -rc1.
--
Catalin
next prev parent reply other threads:[~2020-12-03 11:17 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-03 8:06 linux-next: manual merge of the akpm-current tree with the arm64 tree Stephen Rothwell
2020-12-03 11:16 ` Catalin Marinas [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-10-08 6:04 Stephen Rothwell
2021-10-08 7:37 ` Will Deacon
2021-04-13 8:59 Stephen Rothwell
2021-04-13 9:14 ` Catalin Marinas
2020-09-21 8:03 Stephen Rothwell
2020-09-21 8:12 ` Catalin Marinas
2020-10-13 7:34 ` Stephen Rothwell
2020-07-16 8:00 Stephen Rothwell
2020-07-16 8:23 ` Will Deacon
2020-04-30 6:26 Stephen Rothwell
2020-04-29 6:53 Stephen Rothwell
2019-08-07 6:39 Stephen Rothwell
2018-12-13 6:01 Stephen Rothwell
2018-12-13 11:12 ` Will Deacon
2018-12-11 6:11 linux-next: manual merge of the akpm-current tree with the FIXME tree Stephen Rothwell
2018-12-11 6:12 ` linux-next: manual merge of the akpm-current tree with the arm64 tree Stephen Rothwell
2018-12-11 10:39 ` Will Deacon
2018-12-11 6:02 Stephen Rothwell
2018-09-24 4:38 Stephen Rothwell
2018-09-24 9:32 ` Catalin Marinas
2018-07-27 10:55 Stephen Rothwell
2018-08-16 0:11 ` Stephen Rothwell
2017-11-06 5:33 Stephen Rothwell
2016-09-27 6:03 Stephen Rothwell
2016-06-22 4:54 Stephen Rothwell
2015-12-16 5:01 Stephen Rothwell
2015-12-16 10:14 ` Will Deacon
2014-09-23 7:23 Stephen Rothwell
2014-09-23 8:36 ` Catalin Marinas
2014-07-24 8:42 Stephen Rothwell
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=20201203111611.GD2224@gaia \
--to=catalin.marinas@arm.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=sfr@canb.auug.org.au \
--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