Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+67 -16
+7 -5
arch/arm64/include/asm/cmpxchg.h
··· 91 91 #define __xchg_wrapper(sfx, ptr, x) \ 92 92 ({ \ 93 93 __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))); \ 96 97 __ret; \ 97 98 }) 98 99 ··· 176 175 #define __cmpxchg_wrapper(sfx, ptr, o, n) \ 177 176 ({ \ 178 177 __typeof__(*(ptr)) __ret; \ 179 - __ret = (__typeof__(*(ptr))) \ 180 - __cmpxchg##sfx((ptr), (unsigned long)(o), \ 181 - (unsigned long)(n), sizeof(*(ptr))); \ 178 + __ret = (__force __typeof__(*(ptr))) \ 179 + __cmpxchg##sfx((ptr), (__force unsigned long)(o), \ 180 + (__force unsigned long)(n), \ 181 + sizeof(*(ptr))); \ 182 182 __ret; \ 183 183 }) 184 184
+5 -5
arch/arm64/include/asm/pgtable-prot.h
··· 50 50 51 51 #define _PAGE_DEFAULT (_PROT_DEFAULT | PTE_ATTRINDX(MT_NORMAL)) 52 52 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) 58 58 59 59 #define _PAGE_SHARED (_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_UXN | PTE_WRITE) 60 60 #define _PAGE_SHARED_EXEC (_PAGE_DEFAULT | PTE_USER | PTE_RDONLY | PTE_NG | PTE_PXN | PTE_WRITE)
+4
arch/arm64/include/asm/runtime-const.h
··· 2 2 #ifndef _ASM_RUNTIME_CONST_H 3 3 #define _ASM_RUNTIME_CONST_H 4 4 5 + #ifdef MODULE 6 + #error "Cannot use runtime-const infrastructure from modules" 7 + #endif 8 + 5 9 #include <asm/cacheflush.h> 6 10 7 11 /* Sigh. You can still run arm64 in BE mode */
+49 -4
arch/arm64/mm/contpte.c
··· 599 599 } 600 600 EXPORT_SYMBOL_GPL(contpte_clear_young_dirty_ptes); 601 601 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 + 602 623 int contpte_ptep_set_access_flags(struct vm_area_struct *vma, 603 624 unsigned long addr, pte_t *ptep, 604 625 pte_t entry, int dirty) ··· 629 608 int i; 630 609 631 610 /* 632 - * Gather the access/dirty bits for the contiguous range. If nothing has 633 - * changed, its a noop. 611 + * Check whether all sub-PTEs in the CONT block already match the 612 + * requested access flags/write permission, using raw per-PTE values 613 + * rather than the gathered ptep_get() view. 614 + * 615 + * __ptep_set_access_flags() can update AF, dirty and write 616 + * permission, but only to make the mapping more permissive. 617 + * 618 + * ptep_get() gathers AF/dirty state across the whole CONT block, 619 + * which is correct for a CPU with FEAT_HAFDBS. But page-table 620 + * walkers that evaluate each descriptor individually (e.g. a CPU 621 + * without DBM support, or an SMMU without HTTU, or with HA/HD 622 + * disabled in CD.TCR) can keep faulting on the target sub-PTE if 623 + * only a sibling has been updated. Gathering can therefore cause 624 + * false no-ops when only a sibling has been updated: 625 + * - write faults: target still has PTE_RDONLY (needs PTE_RDONLY cleared) 626 + * - read faults: target still lacks PTE_AF 627 + * 628 + * Per Arm ARM (DDI 0487) D8.7.1, any sub-PTE in a CONT range may 629 + * become the effective cached translation, so all entries must have 630 + * consistent attributes. Check the full CONT block before returning 631 + * no-op, and when any sub-PTE mismatches, proceed to update the whole 632 + * range. 634 633 */ 635 - orig_pte = pte_mknoncont(ptep_get(ptep)); 636 - if (pte_val(orig_pte) == pte_val(entry)) 634 + if (contpte_all_subptes_match_access_flags(ptep, entry)) 637 635 return 0; 636 + 637 + /* 638 + * Use raw target pte (not gathered) for write-bit unfold decision. 639 + */ 640 + orig_pte = pte_mknoncont(__ptep_get(ptep)); 638 641 639 642 /* 640 643 * We can fix up access/dirty bits without having to unfold the contig
+2 -2
tools/testing/selftests/arm64/abi/hwcap.c
··· 475 475 476 476 static void sve2p1_sigill(void) 477 477 { 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"); 480 480 } 481 481 482 482 static void sve2p2_sigill(void)