Skip to content

Commit 4660e16

Browse files
committed
Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
Pull arm64 fixes from Will Deacon: "The main changes are a fix to the way in which we manage the access flag setting for mappings using the contiguous bit and a fix for a hang on the kexec/hibernation path. Summary: - Fix kexec/hibernation hang due to bogus read-only mappings - Fix sparse warnings in our cmpxchg() implementation - Prevent runtime-const being used in modules, just like x86 - Fix broken elision of access flag modifications for contiguous entries on systems without support for hardware updates - Fix a broken SVE selftest that was testing the wrong instruction" * tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: selftest/arm64: Fix sve2p1_sigill() to hwcap test arm64: contpte: fix set_access_flags() no-op check for SMMU/ATS faults arm64: make runtime const not usable by modules arm64: mm: Add PTE_DIRTY back to PAGE_KERNEL* to fix kexec/hibernation arm64: Silence sparse warnings caused by the type casting in (cmp)xchg
2 parents e0c505c + d87c828 commit 4660e16

5 files changed

Lines changed: 67 additions & 16 deletions

File tree

arch/arm64/include/asm/cmpxchg.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ __XCHG_GEN(_mb)
9191
#define __xchg_wrapper(sfx, ptr, x) \
9292
({ \
9393
__typeof__(*(ptr)) __ret; \
94-
__ret = (__typeof__(*(ptr))) \
95-
__arch_xchg##sfx((unsigned long)(x), (ptr), sizeof(*(ptr))); \
94+
__ret = (__force __typeof__(*(ptr))) \
95+
__arch_xchg##sfx((__force unsigned long)(x), (ptr), \
96+
sizeof(*(ptr))); \
9697
__ret; \
9798
})
9899

@@ -175,9 +176,10 @@ __CMPXCHG_GEN(_mb)
175176
#define __cmpxchg_wrapper(sfx, ptr, o, n) \
176177
({ \
177178
__typeof__(*(ptr)) __ret; \
178-
__ret = (__typeof__(*(ptr))) \
179-
__cmpxchg##sfx((ptr), (unsigned long)(o), \
180-
(unsigned long)(n), sizeof(*(ptr))); \
179+
__ret = (__force __typeof__(*(ptr))) \
180+
__cmpxchg##sfx((ptr), (__force unsigned long)(o), \
181+
(__force unsigned long)(n), \
182+
sizeof(*(ptr))); \
181183
__ret; \
182184
})
183185

arch/arm64/include/asm/pgtable-prot.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050

5151
#define _PAGE_DEFAULT (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL))
5252

53-
#define _PAGE_KERNEL (PROT_NORMAL)
54-
#define _PAGE_KERNEL_RO ((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY)
55-
#define _PAGE_KERNEL_ROX ((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY)
56-
#define _PAGE_KERNEL_EXEC (PROT_NORMAL & ~PTE_PXN)
57-
#define _PAGE_KERNEL_EXEC_CONT ((PROT_NORMAL & ~PTE_PXN) | PTE_CONT)
53+
#define _PAGE_KERNEL (PROT_NORMAL | PTE_DIRTY)
54+
#define _PAGE_KERNEL_RO ((PROT_NORMAL & ~PTE_WRITE) | PTE_RDONLY | PTE_DIRTY)
55+
#define _PAGE_KERNEL_ROX ((PROT_NORMAL & ~(PTE_WRITE | PTE_PXN)) | PTE_RDONLY | PTE_DIRTY)
56+
#define _PAGE_KERNEL_EXEC ((PROT_NORMAL & ~PTE_PXN) | PTE_DIRTY)
57+
#define _PAGE_KERNEL_EXEC_CONT ((PROT_NORMAL & ~PTE_PXN) | PTE_CONT | PTE_DIRTY)
5858

5959
#define _PAGE_SHARED (_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE)
6060
#define _PAGE_SHARED_EXEC (_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_WRITE)

arch/arm64/include/asm/runtime-const.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#ifndef _ASM_RUNTIME_CONST_H
33
#define _ASM_RUNTIME_CONST_H
44

5+
#ifdef MODULE
6+
#error "Cannot use runtime-const infrastructure from modules"
7+
#endif
8+
59
#include <asm/cacheflush.h>
610

711
/* Sigh. You can still run arm64 in BE mode */

arch/arm64/mm/contpte.c

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,27 @@ void contpte_clear_young_dirty_ptes(struct vm_area_struct *vma,
599599
}
600600
EXPORT_SYMBOL_GPL(contpte_clear_young_dirty_ptes);
601601

602+
static bool contpte_all_subptes_match_access_flags(pte_t *ptep, pte_t entry)
603+
{
604+
pte_t *cont_ptep = contpte_align_down(ptep);
605+
/*
606+
* PFNs differ per sub-PTE. Match only bits consumed by
607+
* __ptep_set_access_flags(): AF, DIRTY and write permission.
608+
*/
609+
const pteval_t cmp_mask = PTE_RDONLY | PTE_AF | PTE_WRITE | PTE_DIRTY;
610+
pteval_t entry_cmp = pte_val(entry) & cmp_mask;
611+
int i;
612+
613+
for (i = 0; i < CONT_PTES; i++) {
614+
pteval_t pte_cmp = pte_val(__ptep_get(cont_ptep + i)) & cmp_mask;
615+
616+
if (pte_cmp != entry_cmp)
617+
return false;
618+
}
619+
620+
return true;
621+
}
622+
602623
int contpte_ptep_set_access_flags(struct vm_area_struct *vma,
603624
unsigned long addr, pte_t *ptep,
604625
pte_t entry, int dirty)
@@ -608,13 +629,37 @@ int contpte_ptep_set_access_flags(struct vm_area_struct *vma,
608629
int i;
609630

610631
/*
611-
* Gather the access/dirty bits for the contiguous range. If nothing has
612-
* changed, its a noop.
632+
* Check whether all sub-PTEs in the CONT block already match the
633+
* requested access flags/write permission, using raw per-PTE values
634+
* rather than the gathered ptep_get() view.
635+
*
636+
* __ptep_set_access_flags() can update AF, dirty and write
637+
* permission, but only to make the mapping more permissive.
638+
*
639+
* ptep_get() gathers AF/dirty state across the whole CONT block,
640+
* which is correct for a CPU with FEAT_HAFDBS. But page-table
641+
* walkers that evaluate each descriptor individually (e.g. a CPU
642+
* without DBM support, or an SMMU without HTTU, or with HA/HD
643+
* disabled in CD.TCR) can keep faulting on the target sub-PTE if
644+
* only a sibling has been updated. Gathering can therefore cause
645+
* false no-ops when only a sibling has been updated:
646+
* - write faults: target still has PTE_RDONLY (needs PTE_RDONLY cleared)
647+
* - read faults: target still lacks PTE_AF
648+
*
649+
* Per Arm ARM (DDI 0487) D8.7.1, any sub-PTE in a CONT range may
650+
* become the effective cached translation, so all entries must have
651+
* consistent attributes. Check the full CONT block before returning
652+
* no-op, and when any sub-PTE mismatches, proceed to update the whole
653+
* range.
613654
*/
614-
orig_pte = pte_mknoncont(ptep_get(ptep));
615-
if (pte_val(orig_pte) == pte_val(entry))
655+
if (contpte_all_subptes_match_access_flags(ptep, entry))
616656
return 0;
617657

658+
/*
659+
* Use raw target pte (not gathered) for write-bit unfold decision.
660+
*/
661+
orig_pte = pte_mknoncont(__ptep_get(ptep));
662+
618663
/*
619664
* We can fix up access/dirty bits without having to unfold the contig
620665
* range. But if the write bit is changing, we must unfold.

tools/testing/selftests/arm64/abi/hwcap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ static void sve2_sigill(void)
475475

476476
static void sve2p1_sigill(void)
477477
{
478-
/* BFADD Z0.H, Z0.H, Z0.H */
479-
asm volatile(".inst 0x65000000" : : : "z0");
478+
/* LD1Q {Z0.Q}, P0/Z, [Z0.D, X0] */
479+
asm volatile(".inst 0xC400A000" : : : "z0");
480480
}
481481

482482
static void sve2p2_sigill(void)

0 commit comments

Comments
 (0)