Support swap entries for contiguous pte hugepages
Subsystems (18)
v2 cover Support swap entries for contiguous pte hugepages
While trying to enable memory failure handling on arm64 I ran into few issues resulting from the incorrect handling of contiguous pte hugepages. When contiguous pte hugepage size is enabled, in certain instances the architecture code does not have the necessary size information required to manipulate the page table entries leaving the page tables in an inconsistent state.
Since the previous postings[0][1], I've discovered a few more helpers that need updating. The patchset can be grouped by related changes as-
* huge_pte_offset() - Patches 1-2
- patch 1 adds a hugepage size parameter to huge_pte_offset() and updates callsites
- patch 2 uses the hugepage size to find appropriate page table offset on arm64 (even if the pte contains a swap entry)
* huge_pte_clear() - Patches 3-4
- patch 3 adds a size parameter to huge_pte_clear() and makes it a weak function to allow overriding by architecture * set_huge_pte_at()
- override huge_pte_clear() for arm64 to clear multiple ptes for contiguous hugepages
* set_huge_pte_at() - Patches 5-7
- introduces an alternate helper set_huge_swap_pte_at() which is to be used to put down swap huge ptes. Default implementation defaults to calling set_huge_pte_at()
- update try_to_unmap_one() to use set_huge_swap_pte_at() when poisoning hugepages
- override the set_huge_swap_pte_at() for arm64 to correctly deal with contiguous pte hugepages
* enable memory corruption - Patches 8-9
- these patches enable memory corruption handling for arm64 and are included for completeness.
The patchset depends on a cleanup/fix series for contiguous pte hugepages from Steve[2]. I've been using hwpoison testsuite from mce-test[3] on arm64 hardware. Compile tested on s390 and x86.
All feedback welcome. As well, I'd appreciate input on structuring the patchset to make it easier for merging.
Thanks,
Punit
v1 -> v2
* switch huge_pte_offset() to use size instead of hstate for consistency with the rest of the api
* Expand the series to address huge_pte_clear() and set_huge_pte_at()
RFC -> v1
* Fixed a missing conversion of huge_pte_offset() prototype to add hstate parameter. Reported by 0-day.
[0] https://lkml.org/lkml/2017/3/23/293
[1] https://lkml.org/lkml/2017/3/30/770
[2] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-March/497027.html
[3] https://git.kernel.org/pub/scm/utils/cpu/mce/mce-test.git
Jonathan (Zhixiong) Zhang (2):
arm64: hwpoison: add VM_FAULT_HWPOISON[_LARGE] handling
arm64: kconfig: allow support for memory failure handling
Punit Agrawal (7):
mm/hugetlb: add size parameter to huge_pte_offset()
arm64: hugetlbpages: Support handling swap entries in
huge_pte_offset()
mm/hugetlb: Allow architectures to override huge_pte_clear()
arm64: hugetlb: Override huge_pte_clear() to support contiguous
hugepages
mm/hugetlb: Introduce set_huge_swap_pte_at() helper
arm64: hugetlb: Override set_huge_swap_pte_at() to support contiguous
hugepages
mm: rmap: Use correct helper when poisoning hugepages
arch/arm64/Kconfig | 1 + arch/arm64/mm/fault.c | 22 ++++++++++++-- arch/arm64/mm/hugetlbpage.c | 66 +++++++++++++++++++++++++++++++---------- arch/ia64/mm/hugetlbpage.c | 4 +-- arch/metag/mm/hugetlbpage.c | 3 +- arch/mips/mm/hugetlbpage.c | 3 +- arch/parisc/mm/hugetlbpage.c | 3 +- arch/powerpc/mm/hugetlbpage.c | 2 +- arch/s390/include/asm/hugetlb.h | 10 ++----- arch/s390/mm/hugetlbpage.c | 12 +++++++- arch/sh/mm/hugetlbpage.c | 3 +- arch/sparc/mm/hugetlbpage.c | 3 +- arch/tile/mm/hugetlbpage.c | 3 +- arch/x86/mm/hugetlbpage.c | 2 +- drivers/acpi/apei/Kconfig | 1 + fs/userfaultfd.c | 7 +++-- include/asm-generic/hugetlb.h | 7 ++--- include/linux/hugetlb.h | 7 +++-- mm/hugetlb.c | 45 ++++++++++++++++++++-------- mm/page_vma_mapped.c | 3 +- mm/pagewalk.c | 3 +- mm/rmap.c | 8 +++-- 22 files changed, 154 insertions(+), 64 deletions(-)
Signature · 1 line
2.11.0
PATCH v2 1/9 mm/hugetlb: add size parameter to huge_pte_offset()
A poisoned or migrated hugepage is stored as a swap entry in the page tables. On architectures that support hugepages consisting of contiguous page table entries (such as on arm64) this leads to ambiguity in determining the page table entry to return in huge_pte_offset() when a poisoned entry is encountered.
Let's remove the ambiguity by adding a size parameter to convey additional information about the requested address. Also fixup the definition/usage of huge_pte_offset() throughout the tree.
--- arch/arm64/mm/hugetlbpage.c | 3 ++- arch/ia64/mm/hugetlbpage.c | 4 ++-- arch/metag/mm/hugetlbpage.c | 3 ++- arch/mips/mm/hugetlbpage.c | 3 ++- arch/parisc/mm/hugetlbpage.c | 3 ++- arch/powerpc/mm/hugetlbpage.c | 2 +- arch/s390/mm/hugetlbpage.c | 3 ++- arch/sh/mm/hugetlbpage.c | 3 ++- arch/sparc/mm/hugetlbpage.c | 3 ++- arch/tile/mm/hugetlbpage.c | 3 ++- arch/x86/mm/hugetlbpage.c | 2 +- fs/userfaultfd.c | 7 +++++-- include/linux/hugetlb.h | 5 +++-- mm/hugetlb.c | 23 ++++++++++++++--------- mm/page_vma_mapped.c | 3 ++- mm/pagewalk.c | 3 ++- 16 files changed, 46 insertions(+), 27 deletions(-)
arch/arm64/mm/hugetlbpage.c +2 -1
@@ -189,7 +189,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,return pte; } -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm, +unsigned long addr,unsigned long sz) {pgd_t *pgd;pud_t *pud;
arch/ia64/mm/hugetlbpage.c +2 -2
@@ -44,7 +44,7 @@ huge_pte_alloc(struct mm_struct *mm, unsigned long addr, unsigned long sz) }pte_t * -huge_pte_offset (struct mm_struct *mm,unsigned long addr) +huge_pte_offset (struct mm_struct *mm,unsigned long addr,unsigned long sz) {unsigned long taddr =htlbpage_to_page (addr);pgd_t *pgd;
@@ -92,7 +92,7 @@ struct page *follow_huge_addr(struct mm_struct *mm, unsigned long addr, int writif (REGION_NUMBER (addr) !=RGN_HPAGE )return ERR_PTR (-EINVAL ); - ptep =huge_pte_offset (mm, addr); + ptep =huge_pte_offset (mm, addr,HPAGE_SIZE );if (!ptep ||pte_none (*ptep))return NULL ; page =pte_page (*ptep);
arch/metag/mm/hugetlbpage.c +2 -1
@@ -74,7 +74,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,return pte; } -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm, +unsigned long addr,unsigned long sz) {pgd_t *pgd;pud_t *pud;
arch/mips/mm/hugetlbpage.c +2 -1
@@ -36,7 +36,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr,return pte; } -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr, +unsigned long sz) {pgd_t *pgd;pud_t *pud;
arch/parisc/mm/hugetlbpage.c +2 -1
@@ -69,7 +69,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,return pte; } -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm, +unsigned long addr,unsigned long sz) {pgd_t *pgd;pud_t *pud;
arch/powerpc/mm/hugetlbpage.c +1 -1
@@ -55,7 +55,7 @@ static unsigned nr_gpages;#define hugepd_none (hpd) (hpd_val(hpd) == 0) -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr,unsigned long sz) {/* Only called for hugetlbfs pages, hence can ignore THP */ return __find_linux_pte_or_hugepte (mm->pgd, addr,NULL ,NULL );
arch/s390/mm/hugetlbpage.c +2 -1
@@ -176,7 +176,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,return (pte_t *) pmdp; } -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm, +unsigned long addr,unsigned long sz) {pgd_t *pgdp;pud_t *pudp;
arch/sh/mm/hugetlbpage.c +2 -1
@@ -42,7 +42,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,return pte; } -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm, +unsigned long addr,unsigned long sz) {pgd_t *pgd;pud_t *pud;
arch/sparc/mm/hugetlbpage.c +2 -1
@@ -270,7 +270,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,return pte; } -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm, +unsigned long addr,unsigned long sz) {pgd_t *pgd;pud_t *pud;
arch/tile/mm/hugetlbpage.c +2 -1
@@ -102,7 +102,8 @@ static pte_t *get_pte(pte_t *base, int index, int level)return ptep; } -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm, +unsigned long addr,unsigned long sz) {pgd_t *pgd;pud_t *pud;
arch/x86/mm/hugetlbpage.c +1 -1
@@ -31,7 +31,7 @@ follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)if (!vma || !is_vm_hugetlb_page (vma))return ERR_PTR (-EINVAL ); - pte =huge_pte_offset (mm, address); + pte =huge_pte_offset (mm, address,vma_mmu_pagesize (vma));/* hugetlb should be locked, and hence, prefaulted */ WARN_ON (!pte ||pte_none (*pte));
fs/userfaultfd.c +5 -2
@@ -214,6 +214,7 @@ static inline struct uffd_msg userfault_msg(unsigned long address,* hugepmd ranges. */ static inline bool userfaultfd_huge_must_wait (struct userfaultfd_ctx *ctx, +struct vm_area_struct *vma,unsigned long address,unsigned long flags,unsigned long reason)
@@ -224,7 +225,7 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx,VM_BUG_ON (!rwsem_is_locked (&mm->mmap_sem)); - pte =huge_pte_offset (mm, address); + pte =huge_pte_offset (mm, address,vma_mmu_pagesize (vma));if (!pte) goto out;
@@ -243,6 +244,7 @@ static inline bool userfaultfd_huge_must_wait(struct userfaultfd_ctx *ctx, }#else static inline bool userfaultfd_huge_must_wait (struct userfaultfd_ctx *ctx, +struct vm_area_struct *vma,unsigned long address,unsigned long flags,unsigned long reason)
@@ -435,7 +437,8 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason) must_wait =userfaultfd_must_wait (ctx, vmf->address, vmf->flags, reason); else - must_wait =userfaultfd_huge_must_wait (ctx, vmf->address, + must_wait =userfaultfd_huge_must_wait (ctx, vmf->vma, + vmf->address, vmf->flags, reason);up_read (&mm->mmap_sem);
include/linux/hugetlb.h +3 -2
@@ -113,7 +113,8 @@ extern struct list_head huge_boot_pages;pte_t *huge_pte_alloc (struct mm_struct *mm,unsigned long addr,unsigned long sz); -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr); +pte_t *huge_pte_offset (struct mm_struct *mm, +unsigned long addr,unsigned long sz);int huge_pmd_unshare (struct mm_struct *mm,unsigned long *addr,pte_t *ptep);struct page *follow_huge_addr (struct mm_struct *mm,unsigned long address,int write);
@@ -157,7 +158,7 @@ static inline void hugetlb_show_meminfo(void)#define hugetlb_fault (mm, vma, addr, flags) ({ BUG(); 0; })#define hugetlb_mcopy_atomic_pte (dst_mm, dst_pte, dst_vma, dst_addr, \ src_addr, pagep) ({ BUG(); 0; }) -#define huge_pte_offset (mm, address) 0 +#define huge_pte_offset (mm, address, sz) 0static inline int dequeue_hwpoisoned_huge_page (struct page *page) {return 0 ;
mm/hugetlb.c +14 -9
@@ -3233,7 +3233,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,for (addr = vma->vm_start; addr < vma->vm_end; addr += sz) {spinlock_t *src_ptl, *dst_ptl; - src_pte =huge_pte_offset (src, addr); + src_pte =huge_pte_offset (src, addr, sz);if (!src_pte)continue ; dst_pte =huge_pte_alloc (dst, addr, sz);
@@ -3317,7 +3317,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,mmu_notifier_invalidate_range_start (mm, mmun_start, mmun_end); address = start;for (; address < end; address += sz) { - ptep =huge_pte_offset (mm, address); + ptep =huge_pte_offset (mm, address, sz);if (!ptep)continue ;
@@ -3535,7 +3535,8 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,unmap_ref_private (mm, vma, old_page, address);BUG_ON (huge_pte_none (pte));spin_lock (ptl); - ptep =huge_pte_offset (mm, address &huge_page_mask (h)); + ptep =huge_pte_offset (mm, address &huge_page_mask (h), +huge_page_size (h));if (likely (ptep &&pte_same (huge_ptep_get (ptep), pte))) goto retry_avoidcopy;
@@ -3574,7 +3575,8 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,* before the page tables are altered */ spin_lock (ptl); - ptep =huge_pte_offset (mm, address &huge_page_mask (h)); + ptep =huge_pte_offset (mm, address &huge_page_mask (h), +huge_page_size (h));if (likely (ptep &&pte_same (huge_ptep_get (ptep), pte))) {ClearPagePrivate (new_page);
@@ -3861,7 +3863,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, address &=huge_page_mask (h); - ptep =huge_pte_offset (mm, address); + ptep =huge_pte_offset (mm, address,huge_page_size (h));if (ptep) { entry =huge_ptep_get (ptep);if (unlikely (is_hugetlb_entry_migration (entry))) {
@@ -4118,7 +4120,8 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma,* * Note that page table lock is not held when pte is null. */ - pte =huge_pte_offset (mm, vaddr &huge_page_mask (h)); + pte =huge_pte_offset (mm, vaddr &huge_page_mask (h), +huge_page_size (h));if (pte) ptl =huge_pte_lock (h, mm, pte); absent = !pte ||huge_pte_none (huge_ptep_get (pte));
@@ -4252,7 +4255,7 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,i_mmap_lock_write (vma->vm_file->f_mapping);for (; address < end; address +=huge_page_size (h)) {spinlock_t *ptl; - ptep =huge_pte_offset (mm, address); + ptep =huge_pte_offset (mm, address,huge_page_size (h));if (!ptep)continue ; ptl =huge_pte_lock (h, mm, ptep);
@@ -4516,7 +4519,8 @@ pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud) saddr =page_table_shareable (svma, vma, addr, idx);if (saddr) { - spte =huge_pte_offset (svma->vm_mm, saddr); + spte =huge_pte_offset (svma->vm_mm, saddr, +vma_mmu_pagesize (svma));if (spte) {get_page (virt_to_page (spte));break ;
@@ -4612,7 +4616,8 @@ pte_t *huge_pte_alloc(struct mm_struct *mm,return pte; } -pte_t *huge_pte_offset (struct mm_struct *mm,unsigned long addr) +pte_t *huge_pte_offset (struct mm_struct *mm, +unsigned long addr,unsigned long sz) {pgd_t *pgd;p4d_t *p4d;
mm/page_vma_mapped.c +2 -1
@@ -120,7 +120,8 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)if (unlikely (PageHuge (pvmw->page))) {/* when pud is not present, pte will be NULL */ - pvmw->pte =huge_pte_offset (mm, pvmw->address); + pvmw->pte =huge_pte_offset (mm, pvmw->address, +PAGE_SIZE <<compound_order (page));if (!pvmw->pte)return false;
mm/pagewalk.c +2 -1
@@ -180,12 +180,13 @@ static int walk_hugetlb_range(unsigned long addr, unsigned long end,struct hstate *h =hstate_vma (vma);unsigned long next;unsigned long hmask =huge_page_mask (h); +unsigned long sz =huge_page_size (h);pte_t *pte;int err =0 ; do { next = hugetlb_entry_end(h, addr, end); - pte = huge_pte_offset(walk->mm, addr & hmask); + pte = huge_pte_offset(walk->mm, addr & hmask, sz); if (pte && walk->hugetlb_entry) err = walk->hugetlb_entry(pte, hmask, addr, next, walk); if (err)
Signature · 1 line
2.11.0
PATCH v2 2/9 arm64: hugetlbpages: Support handling swap entries in huge_pte_offset()
In reply to Punit Agrawalhuge_pte_offset() does not correctly handle poisoned or migration page table entries. It returns NULL instead of the offset when it encounters a swap entry. This leads to errors such as
[ 344.165544] mm/pgtable-generic.c:33: bad pmd 000000083af00074.
in the kernel log when unmapping memory on process exit.
huge_pte_offset() is now provided with the size of the hugepage being accessed. Use the size to find the correct page table entry to return.
--- arch/arm64/mm/hugetlbpage.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
arch/arm64/mm/hugetlbpage.c +15 -15
@@ -194,36 +194,36 @@ pte_t *huge_pte_offset(struct mm_struct *mm, {pgd_t *pgd;pud_t *pud; -pmd_t *pmd =NULL ; -pte_t *pte =NULL ; +pmd_t *pmd; +pte_t *pte; pgd =pgd_offset (mm, addr);pr_debug ("%s: addr:0x%lx pgd:%p\n" , __func__, addr, pgd);if (!pgd_present (*pgd))return NULL ; + pud =pud_offset (pgd, addr); -if (!pud_present (*pud)) +if (pud_none (*pud) && sz !=PUD_SIZE )return NULL ; - -if (pud_huge (*pud)) +else if (!pud_table (*pud))return (pte_t *)pud; + +if (sz ==CONT_PMD_SIZE ) + addr &=CONT_PMD_MASK ; + pmd =pmd_offset (pud, addr); -if (!pmd_present (*pmd)) +if (pmd_none (*pmd) && + !(sz ==PMD_SIZE || sz ==CONT_PMD_SIZE ))return NULL ; - -if (pte_cont (pmd_pte (*pmd))) { - pmd =pmd_offset ( - pud, (addr &CONT_PMD_MASK )); -return (pte_t *)pmd; - } -if (pmd_huge (*pmd)) +else if (!pmd_table (*pmd))return (pte_t *)pmd; - pte =pte_offset_kernel (pmd, addr); -if (pte_present (*pte) &&pte_cont (*pte)) { + +if (sz ==CONT_PTE_SIZE ) { pte =pte_offset_kernel ( pmd, (addr &CONT_PTE_MASK ));return pte; } +return NULL ; }
Signature · 1 line
2.11.0
PATCH v2 3/9 mm/hugetlb: Allow architectures to override huge_pte_clear()
In reply to Punit AgrawalWhen unmapping a hugepage range, huge_pte_clear() is used to clear the page table entries that are marked as not present. huge_pte_clear() internally just ends up calling pte_clear() which does not correctly deal with hugepages consisting of contiguous page table entries.
Add a size argument and implement huge_pte_clear() as a weak function to allow architectures to override the default implementation.
Update the s390 to use the new mechanism to override huge_pte_clear().
--- arch/s390/include/asm/hugetlb.h | 10 ++-------- arch/s390/mm/hugetlbpage.c | 9 +++++++++ include/asm-generic/hugetlb.h | 7 ++----- mm/hugetlb.c | 8 +++++++- 4 files changed, 20 insertions(+), 14 deletions(-)
arch/s390/include/asm/hugetlb.h +2 -8
@@ -38,14 +38,8 @@ static inline int prepare_hugepage_range(struct file *file,#define arch_clear_hugepage_flags (page) do { } while (0) -static inline void huge_pte_clear (struct mm_struct *mm,unsigned long addr, -pte_t *ptep) -{ -if ((pte_val (*ptep) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) -pte_val (*ptep) = _REGION3_ENTRY_EMPTY; -else -pte_val (*ptep) = _SEGMENT_ENTRY_EMPTY; -} +void huge_pte_clear (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,unsigned long sz);static inline void huge_ptep_clear_flush (struct vm_area_struct *vma,unsigned long address,pte_t *ptep)
arch/s390/mm/hugetlbpage.c +9 -0
@@ -144,6 +144,15 @@ pte_t huge_ptep_get(pte_t *ptep)return __rste_to_pte (pte_val (*ptep)); } +void huge_pte_clear (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,unsigned long sz) +{ +if ((pte_val (*ptep) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) +pte_val (*ptep) = _REGION3_ENTRY_EMPTY; +else +pte_val (*ptep) = _SEGMENT_ENTRY_EMPTY; +} +pte_t huge_ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) {
include/asm-generic/hugetlb.h +2 -5
@@ -31,10 +31,7 @@ static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot) return pte_modify(pte, newprot); } -static inline void huge_pte_clear (struct mm_struct *mm,unsigned long addr, -pte_t *ptep) -{ -pte_clear (mm, addr, ptep); -} +void huge_pte_clear (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,unsigned long sz);#endif /* _ASM_GENERIC_HUGETLB_H */
mm/hugetlb.c +7 -1
@@ -3289,6 +3289,12 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,return ret; } +void __weak huge_pte_clear (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,unsigned long sz) +{ +pte_clear (mm, addr, ptep); +} +void __unmap_hugepage_range (struct mmu_gather *tlb,struct vm_area_struct *vma,unsigned long start,unsigned long end,struct page *ref_page)
@@ -3338,7 +3344,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,* unmapped and its refcount is dropped, so just clear pte here. */ if (unlikely (!pte_present (pte))) { -huge_pte_clear (mm, address, ptep); +huge_pte_clear (mm, address, ptep, sz);spin_unlock (ptl);continue ; }
Signature · 1 line
2.11.0
PATCH v2 4/9 arm64: hugetlb: Override huge_pte_clear() to support contiguous hugepages
In reply to Punit AgrawalThe default huge_pte_clear() implementation does not clear contiguous page table entries when it encounters contiguous hugepages that are supported on arm64.
Fix this by overriding the default implementation to clear all the entries associated with contiguous hugepages.
--- arch/arm64/mm/hugetlbpage.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
arch/arm64/mm/hugetlbpage.c +16 -0
@@ -243,6 +243,22 @@ pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,return entry; } +void huge_pte_clear (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,unsigned long sz) +{ +int ncontig, i; +size_t pgsize; + +if (sz ==PUD_SIZE || sz ==PMD_SIZE ) { +pte_clear (mm, addr, ptep); +return ; + } + + ncontig =find_num_contig (mm, addr, ptep, &pgsize); +for (i =0 ; i < ncontig; i++, addr += pgsize, ptep++) +pte_clear (mm, addr, ptep); +} +pte_t huge_ptep_get_and_clear (struct mm_struct *mm,unsigned long addr,pte_t *ptep) {
Signature · 1 line
2.11.0
kbuild test robot
build botRe: [PATCH v2 4/9] arm64: hugetlb: Override huge_pte_clear() to support contiguous hugepages
reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…
Hi Punit,
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on v4.11-rc5 next-20170405]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Punit-Agrawal/Support-swap-entries-for-contiguous-pte-hugepages/20170406-090327 base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core config: arm64-allmodconfig (attached as .config) compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64
All errors (new ones prefixed by >>):
arch/arm64/mm/hugetlbpage.c: In function 'huge_pte_clear':
>> arch/arm64/mm/hugetlbpage.c:200:44: error: incompatible type for argument 4 of 'find_num_contig'
ncontig = find_num_contig(mm, addr, ptep, &pgsize);
^
arch/arm64/mm/hugetlbpage.c:44:12: note: expected 'pte_t {aka struct <anonymous>}' but argument is of type 'size_t * {aka long unsigned int *}'
static int find_num_contig(struct mm_struct *mm, unsigned long addr,
^~~~~~~~~~~~~~~
>> arch/arm64/mm/hugetlbpage.c:200:12: error: too few arguments to function 'find_num_contig'
ncontig = find_num_contig(mm, addr, ptep, &pgsize);
^~~~~~~~~~~~~~~
arch/arm64/mm/hugetlbpage.c:44:12: note: declared here
static int find_num_contig(struct mm_struct *mm, unsigned long addr,
^~~~~~~~~~~~~~~
arch/arm64/mm/hugetlbpage.c: In function 'huge_ptep_get_and_clear':
arch/arm64/mm/hugetlbpage.c:216:10: error: too few arguments to function 'huge_pte_offset'
cpte = huge_pte_offset(mm, addr);
^~~~~~~~~~~~~~~
arch/arm64/mm/hugetlbpage.c:135:8: note: declared here
pte_t *huge_pte_offset(struct mm_struct *mm,
^~~~~~~~~~~~~~~
arch/arm64/mm/hugetlbpage.c: In function 'huge_ptep_set_access_flags':
arch/arm64/mm/hugetlbpage.c:254:10: error: too few arguments to function 'huge_pte_offset'
cpte = huge_pte_offset(vma->vm_mm, addr);
^~~~~~~~~~~~~~~
arch/arm64/mm/hugetlbpage.c:135:8: note: declared here
pte_t *huge_pte_offset(struct mm_struct *mm,
^~~~~~~~~~~~~~~
arch/arm64/mm/hugetlbpage.c: In function 'huge_ptep_set_wrprotect':
arch/arm64/mm/hugetlbpage.c:279:10: error: too few arguments to function 'huge_pte_offset'
cpte = huge_pte_offset(mm, addr);
^~~~~~~~~~~~~~~
arch/arm64/mm/hugetlbpage.c:135:8: note: declared here
pte_t *huge_pte_offset(struct mm_struct *mm,
^~~~~~~~~~~~~~~
arch/arm64/mm/hugetlbpage.c: In function 'huge_ptep_clear_flush':
arch/arm64/mm/hugetlbpage.c:296:10: error: too few arguments to function 'huge_pte_offset'
cpte = huge_pte_offset(vma->vm_mm, addr);
^~~~~~~~~~~~~~~ arch/arm64/mm/hugetlbpage.c:135:8: note: declared here
pte_t *huge_pte_offset(struct mm_struct *mm,
^~~~~~~~~~~~~~~
vim +/find_num_contig +200 arch/arm64/mm/hugetlbpage.c
194
195 if (sz == PUD_SIZE || sz == PMD_SIZE) {
196 pte_clear(mm, addr, ptep);
197 return;
198 }
199
> 200 ncontig = find_num_contig(mm, addr, ptep, &pgsize);
201 for (i = 0; i < ncontig; i++, addr += pgsize, ptep++)
202 pte_clear(mm, addr, ptep);
203 }
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 54634 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170406/72a1d341/attachment-0001.gz>
PATCH v2 5/9 mm/hugetlb: Introduce set_huge_swap_pte_at() helper
In reply to Punit Agrawalset_huge_pte_at(), an architecture callback to populate hugepage ptes, does not provide the range of virtual memory that is targetted. This leads to ambiguity when dealing with swap entries on architectures that support hugepages consisting of contiguous ptes.
Fix the problem by introducing an overridable helper that is called when populating the page tables with swap entries. The size of the targetted region is provided to the helper to help determine the number of entries to be updated.
Provide a default implementation that maintains the current behaviour.
--- include/linux/hugetlb.h | 2 ++ mm/hugetlb.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-)
include/linux/hugetlb.h +2 -0
@@ -127,6 +127,8 @@ int pud_huge(pud_t pud);unsigned long hugetlb_change_protection (struct vm_area_struct *vma,unsigned long address,unsigned long end,pgprot_t newprot); +void set_huge_swap_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned long sz);#else /* !CONFIG_HUGETLB_PAGE */ static inline void reset_vma_resv_huge_pages (struct vm_area_struct *vma)
mm/hugetlb.c +11 -3
@@ -3211,6 +3211,12 @@ static int is_hugetlb_entry_hwpoisoned(pte_t pte)return 0 ; } +void __weak set_huge_swap_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned long sz) +{ +set_huge_pte_at (mm, addr, ptep, pte); +} +int copy_hugetlb_page_range (struct mm_struct *dst,struct mm_struct *src,struct vm_area_struct *vma) {
@@ -3263,9 +3269,10 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src,*/ make_migration_entry_read (&swp_entry); entry =swp_entry_to_pte (swp_entry); -set_huge_pte_at (src, addr, src_pte, entry); +set_huge_swap_pte_at (src, addr, src_pte, + entry, sz); } -set_huge_pte_at (dst, addr, dst_pte, entry); +set_huge_swap_pte_at (dst, addr, dst_pte, entry, sz); }else {if (cow) {huge_ptep_set_wrprotect (src, addr, src_pte);
@@ -4283,7 +4290,8 @@ unsigned long hugetlb_change_protection(struct vm_area_struct *vma,make_migration_entry_read (&entry); newpte =swp_entry_to_pte (entry); -set_huge_pte_at (mm, address, ptep, newpte); +set_huge_swap_pte_at (mm, address, ptep, + newpte,huge_page_size (h)); pages++; }spin_unlock (ptl);
Signature · 1 line
2.11.0
PATCH v2 6/9 mm: rmap: Use correct helper when poisoning hugepages
In reply to Punit AgrawalUsing set_pte_at() does not do the right thing when putting down HWPOISON swap entries for hugepages on architectures that support contiguous ptes.
Fix this problem by using set_huge_swap_pte_at() which was introduced to fix exactly this problem.
--- mm/rmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/rmap.c +6 -2
@@ -1386,15 +1386,19 @@ static int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,update_hiwater_rss (mm);if (PageHWPoison (page) && !(flags &TTU_IGNORE_HWPOISON )) { + pteval =swp_entry_to_pte (make_hwpoison_entry (subpage));if (PageHuge (page)) {int nr =1 <<compound_order (page);hugetlb_count_sub (nr, mm); +set_huge_swap_pte_at (mm, address, + pvmw.pte, pteval, +vma_mmu_pagesize (vma)); }else {dec_mm_counter (mm,mm_counter (page)); +set_pte_at (mm, address, pvmw.pte, pteval); } - pteval =swp_entry_to_pte (make_hwpoison_entry (subpage)); -set_pte_at (mm, address, pvmw.pte, pteval); + }else if (pte_unused (pteval)) {/* * The guest indicated that the page content is of no
Signature · 1 line
2.11.0
kbuild test robot
build botRe: [PATCH v2 6/9] mm: rmap: Use correct helper when poisoning hugepages
reproduce:
Hi Punit,
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on v4.11-rc5 next-20170405]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Punit-Agrawal/Support-swap-entries-for-contiguous-pte-hugepages/20170406-090327 base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core config: i386-tinyconfig (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
mm/rmap.c: In function 'try_to_unmap_one':
>> mm/rmap.c:1393:5: error: implicit declaration of function 'set_huge_swap_pte_at' [-Werror=implicit-function-declaration]
set_huge_swap_pte_at(mm, address,
^~~~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +/set_huge_swap_pte_at +1393 mm/rmap.c
1387
1388 if (PageHWPoison(page) && !(flags & TTU_IGNORE_HWPOISON)) {
1389 pteval = swp_entry_to_pte(make_hwpoison_entry(subpage));
1390 if (PageHuge(page)) {
1391 int nr = 1 << compound_order(page);
1392 hugetlb_count_sub(nr, mm);
> 1393 set_huge_swap_pte_at(mm, address,
1394 pvmw.pte, pteval,
1395 vma_mmu_pagesize(vma));
1396 } else {
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 6518 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170406/f26f6f20/attachment.gz>
PATCH v2 7/9 arm64: hugetlb: Override set_huge_swap_pte_at() to support contiguous hugepages
In reply to Punit AgrawalThe default implementation of set_huge_swap_pte_at() does not support hugepages consisting of contiguous ptes. Override it to add support for contiguous hugepages.
--- arch/arm64/mm/hugetlbpage.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/arm64/mm/hugetlbpage.c +17 -0
@@ -143,6 +143,23 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, } } +void set_huge_swap_pte_at (struct mm_struct *mm,unsigned long addr, +pte_t *ptep,pte_t pte,unsigned long sz) +{ +size_t pgsize; +int i; +int ncontig; + +if (sz ==PUD_SIZE || sz ==PMD_SIZE ) { +set_pte (ptep, pte); +return ; + } + + ncontig =find_num_contig (mm, addr, ptep, &pgsize); +for (i =0 ; i < ncontig; i++, ptep++) +set_pte (ptep, pte); +} +pte_t *huge_pte_alloc (struct mm_struct *mm,unsigned long addr,unsigned long sz) {
Signature · 1 line
2.11.0
PATCH v2 8/9 arm64: hwpoison: add VM_FAULT_HWPOISON[_LARGE] handling
In reply to Punit AgrawalFrom: "Jonathan (Zhixiong) Zhang" <[email protected]>
Add VM_FAULT_HWPOISON[_LARGE] handling to the arm64 page fault handler. Handling of VM_FAULT_HWPOISON[_LARGE] is very similar to VM_FAULT_OOM, the only difference is that a different si_code (BUS_MCEERR_AR) is passed to user space and si_addr_lsb field is initialized.
--- arch/arm64/mm/fault.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
arch/arm64/mm/fault.c +19 -3
@@ -31,6 +31,7 @@#include <linux/highmem.h> #include <linux/perf_event.h> #include <linux/preempt.h> +#include <linux/hugetlb.h> #include <asm/bug.h> #include <asm/cpufeature.h>
@@ -194,9 +195,10 @@ static void __do_kernel_fault(struct mm_struct *mm, unsigned long addr,*/ static void __do_user_fault (struct task_struct *tsk,unsigned long addr,unsigned int esr,unsigned int sig,int code, -struct pt_regs *regs) +struct pt_regs *regs,int fault) {struct siginfo si; +unsigned int lsb =0 ;if (unhandled_signal (tsk, sig) &&show_unhandled_signals_ratelimited ()) { pr_info("%s[%d]: unhandled %s (%d) at 0x%08lx, esr 0x%03x\n",
@@ -212,6 +214,17 @@ static void __do_user_fault(struct task_struct *tsk, unsigned long addr, si.si_errno =0 ; si.si_code = code; si.si_addr = (void __user *)addr; +/* +* Either small page or large page may be poisoned. +* In other words, VM_FAULT_HWPOISON_LARGE and +* VM_FAULT_HWPOISON are mutually exclusive. +*/ +if (fault &VM_FAULT_HWPOISON_LARGE ) + lsb =hstate_index_to_shift (VM_FAULT_GET_HINDEX (fault)); +else if (fault &VM_FAULT_HWPOISON ) + lsb =PAGE_SHIFT ; + si.si_addr_lsb = lsb; +force_sig_info (sig, &si, tsk); }
@@ -225,7 +238,7 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re* handle this fault with. */ if (user_mode (regs)) -__do_user_fault (tsk, addr, esr,SIGSEGV ,SEGV_MAPERR , regs); +__do_user_fault (tsk, addr, esr,SIGSEGV ,SEGV_MAPERR , regs,0 );else __do_kernel_fault (mm, addr, esr, regs); }
@@ -427,6 +440,9 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr,*/ sig =SIGBUS ; code =BUS_ADRERR ; + }else if (fault & (VM_FAULT_HWPOISON |VM_FAULT_HWPOISON_LARGE )) { + sig =SIGBUS ; + code =BUS_MCEERR_AR ; }else {/* * Something tried to access memory that isn't in our memory
@@ -437,7 +453,7 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, SEGV_ACCERR :SEGV_MAPERR ; } -__do_user_fault (tsk, addr, esr, sig, code, regs); +__do_user_fault (tsk, addr, esr, sig, code, regs, fault);return 0 ; no_context:
Signature · 1 line
2.11.0
PATCH v2 9/9 arm64: kconfig: allow support for memory failure handling
In reply to Punit AgrawalFrom: "Jonathan (Zhixiong) Zhang" <[email protected]>
If ACPI_APEI and MEMORY_FAILURE is configured, select ACPI_APEI_MEMORY_FAILURE. This enables memory failure recovery when such memory failure is reported through ACPI APEI. APEI (ACPI Platform Error Interfaces) provides a means for the platform to convey error information to the kernel. APEI bits
Declare ARCH_SUPPORTS_MEMORY_FAILURE, as arm64 does support memory failure recovery attempt.
--- arch/arm64/Kconfig | 1 + drivers/acpi/apei/Kconfig | 1 + 2 files changed, 2 insertions(+)
arch/arm64/Kconfig +1 -0
@@ -19,6 +19,7 @@ config ARM64 select ARCH_HAS_STRICT_MODULE_RWX select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST select ARCH_USE_CMPXCHG_LOCKREF + select ARCH_SUPPORTS_MEMORY_FAILURE select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_NUMA_BALANCING select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
drivers/acpi/apei/Kconfig +1 -0
@@ -9,6 +9,7 @@ config ACPI_APEI select MISC_FILESYSTEMS select PSTORE select UEFI_CPER + select ACPI_APEI_MEMORY_FAILURE if MEMORY_FAILURE depends on HAVE_ACPI_APEI help APEI allows to report errors (for example from the chipset)
Signature · 1 line
2.11.0