From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CD2EC433FE for ; Thu, 12 May 2022 20:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358298AbiELUSq (ORCPT ); Thu, 12 May 2022 16:18:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357941AbiELUSp (ORCPT ); Thu, 12 May 2022 16:18:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEC8913CA16 for ; Thu, 12 May 2022 13:18:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 62C3661D93 for ; Thu, 12 May 2022 20:18:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBFF2C385B8; Thu, 12 May 2022 20:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1652386721; bh=HNFkdeUpPq0f2Au3T0a9a1IQOzn5+C4z2fr31DYtTww=; h=Date:To:From:Subject:From; b=AXx67wYa3FBwevSmOezMOR9lVAUBpHTrLMT5KvY+rEMu/AKUCuPfssxXyRo1oY4Tk Mib2NEKERKqQ81dc+9JGYepO++vno4I2dlrvCKxM3w3h1imPWKSSlcw7jJwbiWGZ/H Y6kvUqWesGXLLwAa7OU8a+dnTM664OFrVgfDC9n4= Date: Thu, 12 May 2022 13:18:41 -0700 To: mm-commits@vger.kernel.org, ying.huang@intel.com, songmuchun@bytedance.com, naoya.horiguchi@nec.com, mike.kravetz@oracle.com, mgorman@techsingularity.net, hch@lst.de, dhowells@redhat.com, david@redhat.com, cl@linux.com, linmiaohe@huawei.com, akpm@linux-foundation.org From: Andrew Morton Subject: [to-be-updated] mm-migration-fix-potential-pte_unmap-on-an-not-mapped-pte.patch removed from -mm tree Message-Id: <20220512201841.BBFF2C385B8@smtp.kernel.org> Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The quilt patch titled Subject: mm/migration: fix potential pte_unmap on an not mapped pte has been removed from the -mm tree. Its filename was mm-migration-fix-potential-pte_unmap-on-an-not-mapped-pte.patch This patch was dropped because an updated version will be merged ------------------------------------------------------ From: Miaohe Lin Subject: mm/migration: fix potential pte_unmap on an not mapped pte __migration_entry_wait and migration_entry_wait_on_locked assume pte is always mapped from caller. But this is not the case when it's called from migration_entry_wait_huge and follow_huge_pmd. Add a hugetlbfs variant that calls hugetlb_migration_entry_wait(ptep == NULL) to fix this issue. Link: https://lkml.kernel.org/r/20220425132723.34824-5-linmiaohe@huawei.com Fixes: 30dad30922cc ("mm: migration: add migrate_entry_wait_huge()") Signed-off-by: Miaohe Lin Suggested-by: David Hildenbrand Reviewed-by: David Hildenbrand Cc: Christoph Hellwig Cc: Christoph Lameter Cc: David Howells Cc: Huang Ying Cc: Mike Kravetz Cc: Muchun Song Cc: Naoya Horiguchi Cc: Mel Gorman Signed-off-by: Andrew Morton --- include/linux/swapops.h | 12 ++++++++---- mm/hugetlb.c | 4 ++-- mm/migrate.c | 23 +++++++++++++++++++---- 3 files changed, 29 insertions(+), 10 deletions(-) --- a/include/linux/swapops.h~mm-migration-fix-potential-pte_unmap-on-an-not-mapped-pte +++ a/include/linux/swapops.h @@ -244,8 +244,10 @@ extern void __migration_entry_wait(struc spinlock_t *ptl); extern void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, unsigned long address); -extern void migration_entry_wait_huge(struct vm_area_struct *vma, - struct mm_struct *mm, pte_t *pte); +#ifdef CONFIG_HUGETLB_PAGE +extern void __migration_entry_wait_huge(pte_t *ptep, spinlock_t *ptl); +extern void migration_entry_wait_huge(struct vm_area_struct *vma, pte_t *pte); +#endif #else static inline swp_entry_t make_readable_migration_entry(pgoff_t offset) { @@ -271,8 +273,10 @@ static inline void __migration_entry_wai spinlock_t *ptl) { } static inline void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, unsigned long address) { } -static inline void migration_entry_wait_huge(struct vm_area_struct *vma, - struct mm_struct *mm, pte_t *pte) { } +#ifdef CONFIG_HUGETLB_PAGE +static inline void __migration_entry_wait_huge(pte_t *ptep, spinlock_t *ptl) { } +static inline void migration_entry_wait_huge(struct vm_area_struct *vma, pte_t *pte) { } +#endif static inline int is_writable_migration_entry(swp_entry_t entry) { return 0; --- a/mm/hugetlb.c~mm-migration-fix-potential-pte_unmap-on-an-not-mapped-pte +++ a/mm/hugetlb.c @@ -5694,7 +5694,7 @@ vm_fault_t hugetlb_fault(struct mm_struc */ entry = huge_ptep_get(ptep); if (unlikely(is_hugetlb_entry_migration(entry))) { - migration_entry_wait_huge(vma, mm, ptep); + migration_entry_wait_huge(vma, ptep); return 0; } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) return VM_FAULT_HWPOISON_LARGE | @@ -6912,7 +6912,7 @@ retry: } else { if (is_hugetlb_entry_migration(pte)) { spin_unlock(ptl); - __migration_entry_wait(mm, (pte_t *)pmd, ptl); + __migration_entry_wait_huge((pte_t *)pmd, ptl); goto retry; } /* --- a/mm/migrate.c~mm-migration-fix-potential-pte_unmap-on-an-not-mapped-pte +++ a/mm/migrate.c @@ -315,12 +315,27 @@ void migration_entry_wait(struct mm_stru __migration_entry_wait(mm, ptep, ptl); } -void migration_entry_wait_huge(struct vm_area_struct *vma, - struct mm_struct *mm, pte_t *pte) +#ifdef CONFIG_HUGETLB_PAGE +void __migration_entry_wait_huge(pte_t *ptep, spinlock_t *ptl) { - spinlock_t *ptl = huge_pte_lockptr(hstate_vma(vma), mm, pte); - __migration_entry_wait(mm, pte, ptl); + pte_t pte; + + spin_lock(ptl); + pte = huge_ptep_get(ptep); + + if (unlikely(!is_hugetlb_entry_migration(pte))) + spin_unlock(ptl); + else + migration_entry_wait_on_locked(pte_to_swp_entry(pte), NULL, ptl); +} + +void migration_entry_wait_huge(struct vm_area_struct *vma, pte_t *pte) +{ + spinlock_t *ptl = huge_pte_lockptr(hstate_vma(vma), vma->vm_mm, pte); + + __migration_entry_wait_huge(pte, ptl); } +#endif #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION void pmd_migration_entry_wait(struct mm_struct *mm, pmd_t *pmd) _ Patches currently in -mm which might be from linmiaohe@huawei.com are mm-swapfile-unuse_pte-can-map-random-data-if-swap-read-fails.patch mm-swapfile-fix-lost-swap-bits-in-unuse_pte.patch mm-vmscan-take-min_slab_pages-into-account-when-try-to-call-shrink_node.patch mm-vmscan-add-a-comment-about-madv_free-pages-check-in-folio_check_dirty_writeback.patch mm-vmscan-introduce-helper-function-reclaim_page_list.patch mm-vmscan-take-all-base-pages-of-thp-into-account-when-race-with-speculative-reference.patch mm-vmscan-remove-obsolete-comment-in-kswapd_run.patch mm-vmscan-use-helper-folio_is_file_lru.patch mm-vmscan-use-helper-folio_is_file_lru-fix.patch mm-z3fold-fix-sheduling-while-atomic.patch mm-z3fold-fix-possible-null-pointer-dereferencing.patch mm-z3fold-remove-buggy-use-of-stale-list-for-allocation.patch mm-z3fold-throw-warning-on-failure-of-trylock_page-in-z3fold_alloc.patch revert-mm-z3foldc-allow-__gfp_highmem-in-z3fold_alloc.patch mm-z3fold-put-z3fold-page-back-into-unbuddied-list-when-reclaim-or-migration-fails.patch mm-z3fold-always-clear-page_claimed-under-z3fold-page-lock.patch mm-z3fold-fix-z3fold_reclaim_page-races-with-z3fold_free.patch mm-z3fold-fix-z3fold_page_migrate-races-with-z3fold_map.patch mm-swap-use-helper-is_swap_pte-in-swap_vma_readahead.patch mm-swap-use-helper-macro-__attr_rw.patch mm-swap-fold-__swap_info_get-into-its-sole-caller.patch mm-swap-remove-unneeded-return-value-of-free_swap_slot.patch mm-swap-print-bad-swap-offset-entry-in-get_swap_device.patch mm-swap-remove-buggy-cache-nr-check-in-refill_swap_slots_cache.patch mm-swap-remove-unneeded-p-=-null-check-in-__swap_duplicate.patch mm-swap-make-page_swapcount-and-__lru_add_drain_all.patch mm-swap-avoid-calling-swp_swap_info-when-try-to-check-swp_stable_writes.patch mm-swap-add-helper-swap_offset_available.patch mm-swap-fix-the-obsolete-comment-for-swp_type_shift.patch mm-swap-clean-up-the-comment-of-find_next_to_unuse.patch mm-swap-fix-the-comment-of-get_kernel_pages.patch mm-swap-fix-comment-about-swap-extent.patch