• Barry Song's avatar
    arm64: mm: swap: support THP_SWAP on hardware with MTE · f238b8c3
    Barry Song authored
    Commit d0637c50 ("arm64: enable THP_SWAP for arm64") brings up
    THP_SWAP on ARM64, but it doesn't enable THP_SWP on hardware with MTE as
    the MTE code works with the assumption tags save/restore is always
    handling a folio with only one page.
    
    The limitation should be removed as more and more ARM64 SoCs have this
    feature.  Co-existence of MTE and THP_SWAP becomes more and more
    important.
    
    This patch makes MTE tags saving support large folios, then we don't need
    to split large folios into base pages for swapping out on ARM64 SoCs with
    MTE any more.
    
    arch_prepare_to_swap() should take folio rather than page as parameter
    because we support THP swap-out as a whole.  It saves tags for all pages
    in a large folio.
    
    As now we are restoring tags based-on folio, in arch_swap_restore(), we
    may increase some extra loops and early-exitings while refaulting a large
    folio which is still in swapcache in do_swap_page().  In case a large
    folio has nr pages, do_swap_page() will only set the PTE of the particular
    page which is causing the page fault.  Thus do_swap_page() runs nr times,
    and each time, arch_swap_restore() will loop nr times for those subpages
    in the folio.  So right now the algorithmic complexity becomes O(nr^2).
    
    Once we support mapping large folios in do_swap_page(), extra loops and
    early-exitings will decrease while not being completely removed as a large
    folio might get partially tagged in corner cases such as, 1.  a large
    folio in swapcache can be partially unmapped, thus, MTE tags for the
    unmapped pages will be invalidated; 2.  users might use mprotect() to set
    MTEs on a part of a large folio.
    
    arch_thp_swp_supported() is dropped since ARM64 MTE was the only one who
    needed it.
    
    Link: https://lkml.kernel.org/r/20240322114136.61386-2-21cnbao@gmail.comSigned-off-by: default avatarBarry Song <v-songbaohua@oppo.com>
    Reviewed-by: default avatarSteven Price <steven.price@arm.com>
    Acked-by: default avatarChris Li <chrisl@kernel.org>
    Reviewed-by: default avatarRyan Roberts <ryan.roberts@arm.com>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: Will Deacon <will@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Kemeng Shi <shikemeng@huaweicloud.com>
    Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Cc: Peter Collingbourne <pcc@google.com>
    Cc: Yosry Ahmed <yosryahmed@google.com>
    Cc: Peter Xu <peterx@redhat.com>
    Cc: Lorenzo Stoakes <lstoakes@gmail.com>
    Cc: "Mike Rapoport (IBM)" <rppt@kernel.org>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
    Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    f238b8c3
mteswap.c 2.55 KB