diff options
author | Catalin Marinas <catalin.marinas@arm.com> | 2020-05-04 14:42:36 +0100 |
---|---|---|
committer | Catalin Marinas <catalin.marinas@arm.com> | 2020-09-04 12:46:06 +0100 |
commit | 34bfeea4a9e9cdae713637541f240c3adfdfede3 (patch) | |
tree | b4e13c4df48e00547764673d4d6ceec187ecf5b3 /arch/arm64/kernel/mte.c | |
parent | 72e6afa08e988744822f9bf18043fc04c4df2178 (diff) | |
download | linux-34bfeea4a9e9cdae713637541f240c3adfdfede3.tar.bz2 |
arm64: mte: Clear the tags when a page is mapped in user-space with PROT_MTE
Pages allocated by the kernel are not guaranteed to have the tags
zeroed, especially as the kernel does not (yet) use MTE itself. To
ensure the user can still access such pages when mapped into its address
space, clear the tags via set_pte_at(). A new page flag - PG_mte_tagged
(PG_arch_2) - is used to track pages with valid allocation tags.
Since the zero page is mapped as pte_special(), it won't be covered by
the above set_pte_at() mechanism. Clear its tags during early MTE
initialisation.
Co-developed-by: Steven Price <steven.price@arm.com>
Signed-off-by: Steven Price <steven.price@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Diffstat (limited to 'arch/arm64/kernel/mte.c')
-rw-r--r-- | arch/arm64/kernel/mte.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 032016823957..5bf9bbed5a25 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -3,12 +3,26 @@ * Copyright (C) 2020 ARM Ltd. */ +#include <linux/bitops.h> +#include <linux/mm.h> #include <linux/thread_info.h> #include <asm/cpufeature.h> #include <asm/mte.h> #include <asm/sysreg.h> +void mte_sync_tags(pte_t *ptep, pte_t pte) +{ + struct page *page = pte_page(pte); + long i, nr_pages = compound_nr(page); + + /* if PG_mte_tagged is set, tags have already been initialised */ + for (i = 0; i < nr_pages; i++, page++) { + if (!test_and_set_bit(PG_mte_tagged, &page->flags)) + mte_clear_page_tags(page_address(page)); + } +} + void flush_mte_state(void) { if (!system_supports_mte()) |