Skip to content

Commit 332c151

Browse files
pccakpm00
authored andcommitted
arm64: mte: simplify swap tag restoration logic
As a result of the patches "mm: Call arch_swap_restore() from do_swap_page()" and "mm: Call arch_swap_restore() from unuse_pte()", there are no circumstances in which a swapped-in page is installed in a page table without first having arch_swap_restore() called on it. Therefore, we no longer need the logic in set_pte_at() that restores the tags, so remove it. Link: https://lkml.kernel.org/r/20230523004312.1807357-4-pcc@google.com Link: https://linux-review.googlesource.com/id/I8ad54476f3b2d0144ccd8ce0c1d7a2963e5ff6f3 Signed-off-by: Peter Collingbourne <pcc@google.com> Reviewed-by: Steven Price <steven.price@arm.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Cc: Alexandru Elisei <alexandru.elisei@arm.com> Cc: Chinwen Chang <chinwen.chang@mediatek.com> Cc: David Hildenbrand <david@redhat.com> Cc: Evgenii Stepanov <eugenis@google.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: kasan-dev@googlegroups.com Cc: kasan-dev <kasan-dev@googlegroups.com> Cc: "Kuan-Ying Lee (李冠穎)" <Kuan-Ying.Lee@mediatek.com> Cc: Qun-Wei Lin <qun-wei.lin@mediatek.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Cc: Will Deacon <will@kernel.org> Cc: "Huang, Ying" <ying.huang@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b53e24c commit 332c151

File tree

3 files changed

+11
-44
lines changed

3 files changed

+11
-44
lines changed

arch/arm64/include/asm/mte.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static inline bool try_page_mte_tagging(struct page *page)
9090
}
9191

9292
void mte_zero_clear_page_tags(void *addr);
93-
void mte_sync_tags(pte_t old_pte, pte_t pte);
93+
void mte_sync_tags(pte_t pte);
9494
void mte_copy_page_tags(void *kto, const void *kfrom);
9595
void mte_thread_init_user(void);
9696
void mte_thread_switch(struct task_struct *next);
@@ -122,7 +122,7 @@ static inline bool try_page_mte_tagging(struct page *page)
122122
static inline void mte_zero_clear_page_tags(void *addr)
123123
{
124124
}
125-
static inline void mte_sync_tags(pte_t old_pte, pte_t pte)
125+
static inline void mte_sync_tags(pte_t pte)
126126
{
127127
}
128128
static inline void mte_copy_page_tags(void *kto, const void *kfrom)

arch/arm64/include/asm/pgtable.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,8 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
337337
* don't expose tags (instruction fetches don't check tags).
338338
*/
339339
if (system_supports_mte() && pte_access_permitted(pte, false) &&
340-
!pte_special(pte)) {
341-
pte_t old_pte = READ_ONCE(*ptep);
342-
/*
343-
* We only need to synchronise if the new PTE has tags enabled
344-
* or if swapping in (in which case another mapping may have
345-
* set tags in the past even if this PTE isn't tagged).
346-
* (!pte_none() && !pte_present()) is an open coded version of
347-
* is_swap_pte()
348-
*/
349-
if (pte_tagged(pte) || (!pte_none(old_pte) && !pte_present(old_pte)))
350-
mte_sync_tags(old_pte, pte);
351-
}
340+
!pte_special(pte) && pte_tagged(pte))
341+
mte_sync_tags(pte);
352342

353343
__check_safe_pte_update(mm, ptep, pte);
354344

arch/arm64/kernel/mte.c

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,18 @@ DEFINE_STATIC_KEY_FALSE(mte_async_or_asymm_mode);
3535
EXPORT_SYMBOL_GPL(mte_async_or_asymm_mode);
3636
#endif
3737

38-
static void mte_sync_page_tags(struct page *page, pte_t old_pte,
39-
bool check_swap, bool pte_is_tagged)
40-
{
41-
if (check_swap && is_swap_pte(old_pte)) {
42-
swp_entry_t entry = pte_to_swp_entry(old_pte);
43-
44-
if (!non_swap_entry(entry))
45-
mte_restore_tags(entry, page);
46-
}
47-
48-
if (!pte_is_tagged)
49-
return;
50-
51-
if (try_page_mte_tagging(page)) {
52-
mte_clear_page_tags(page_address(page));
53-
set_page_mte_tagged(page);
54-
}
55-
}
56-
57-
void mte_sync_tags(pte_t old_pte, pte_t pte)
38+
void mte_sync_tags(pte_t pte)
5839
{
5940
struct page *page = pte_page(pte);
6041
long i, nr_pages = compound_nr(page);
61-
bool check_swap = nr_pages == 1;
62-
bool pte_is_tagged = pte_tagged(pte);
63-
64-
/* Early out if there's nothing to do */
65-
if (!check_swap && !pte_is_tagged)
66-
return;
6742

6843
/* if PG_mte_tagged is set, tags have already been initialised */
69-
for (i = 0; i < nr_pages; i++, page++)
70-
if (!page_mte_tagged(page))
71-
mte_sync_page_tags(page, old_pte, check_swap,
72-
pte_is_tagged);
44+
for (i = 0; i < nr_pages; i++, page++) {
45+
if (try_page_mte_tagging(page)) {
46+
mte_clear_page_tags(page_address(page));
47+
set_page_mte_tagged(page);
48+
}
49+
}
7350

7451
/* ensure the tags are visible before the PTE is set */
7552
smp_wmb();

0 commit comments

Comments
 (0)