From nobody Tue Sep 16 10:51:37 2025 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 55366C3DA7D for ; Thu, 5 Jan 2023 10:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232729AbjAEKWV (ORCPT ); Thu, 5 Jan 2023 05:22:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232866AbjAEKUw (ORCPT ); Thu, 5 Jan 2023 05:20:52 -0500 Received: from mail-vs1-xe49.google.com (mail-vs1-xe49.google.com [IPv6:2607:f8b0:4864:20::e49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9215568AE for ; Thu, 5 Jan 2023 02:19:37 -0800 (PST) Received: by mail-vs1-xe49.google.com with SMTP id d187-20020a671dc4000000b003c3a754b594so8077740vsd.10 for ; Thu, 05 Jan 2023 02:19:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/OkucptRSHaE2jww1tz6Gz5twfCMvXYe7c+PeOdayik=; b=iSGNYib6WI9KvfmqIGZ0i7Vk1UHRi9UDSqMCmoRyiWYTjMJCfkdilKxemSSs37rmEB LHey9zQAKiluMdfQLrqTJC18PcagtYORncHX8xb4slmIglKAK8i5xsLn8irb+SQa5QzI 4QtmQAfki38HB20NjnEKifiLax0woXit1rzbXzd6DiZJt4TmQVa8Cw2yCoz++5MjYfVN pYOtQPvRLchwdc3u+rabZTzy1X2ezxmhCkcFxceEMFn6sa9jw6mf0hk0rjrfbLUnoyi1 4OF7tPUD2sGPQORVj4TOgSn8kcTeH6qegdWylrCr5/p3m+hVSlBOd7UYhD1rHychySU9 7SpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/OkucptRSHaE2jww1tz6Gz5twfCMvXYe7c+PeOdayik=; b=0sqPzHhhximMH3UFFyHVd5G8D9053dqgrrhpsiOqMT6x79mFT2R42ZtZ6nPJDbHQnO /zoPyvDKq8FjdkA6n9WOxr7BcvggELuFAP/1wbutc1EQ9zvy3zNg0bGRT8ITNHNi8Mb9 y9EGIGUD3UavitFwFBMfmTgygSduzuqq7rw6OlFKA0aHOP1wEUMHu6Kcz1MZaI3zR6V0 o4I3TsN6VdOn+Q6CYdHvs8z8KV6MRLHpoMZtxJ99kFr1yQ4znfeaCea1UBtnF2qaNynW lGv0u0C9+ZqXDu31KuyFoNjyGQFNK5SegHOFf8ptm42aGwui2fhux1VVwYMdYs9G4r54 WC/w== X-Gm-Message-State: AFqh2koWSrscDzhgeuVD1UpmMurIPTV3WZJgp65nZZkvh+VK3teZ3OSR +auZfQkyAiwPUJEo2ICvJggY/5buP0EvC8ae X-Google-Smtp-Source: AMrXdXuvwrh8nHt5LTtM5ZzmX7uEySb+WBxPJnc+22e/KgH4n1viiq8PVmwhxdb0dwfC5zkTILrp/OH5b2XpbHmH X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:ac5:cbcc:0:b0:3cf:a8e:4620 with SMTP id h12-20020ac5cbcc000000b003cf0a8e4620mr5931022vkn.31.1672913976826; Thu, 05 Jan 2023 02:19:36 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:27 +0000 In-Reply-To: <20230105101844.1893104-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230105101844.1893104-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105101844.1893104-30-jthoughton@google.com> Subject: [PATCH 29/46] rmap: in try_to_{migrate,unmap}_one, check head page for page flags From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The main complication here is that HugeTLB pages have their poison status stored in the head page as the HWPoison page flag. Because HugeTLB high-granularity mapping can create PTEs that point to subpages instead of always the head of a hugepage, we need to check the compound_head for page flags. Signed-off-by: James Houghton --- mm/rmap.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 076ea77010e5..a6004d6b0415 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1456,10 +1456,11 @@ static bool try_to_unmap_one(struct folio *folio, s= truct vm_area_struct *vma, struct mm_struct *mm =3D vma->vm_mm; DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0); pte_t pteval; - struct page *subpage; + struct page *subpage, *page_flags_page; bool anon_exclusive, ret =3D true; struct mmu_notifier_range range; enum ttu_flags flags =3D (enum ttu_flags)(long)arg; + bool page_poisoned; =20 /* * When racing against e.g. zap_pte_range() on another cpu, @@ -1512,9 +1513,17 @@ static bool try_to_unmap_one(struct folio *folio, st= ruct vm_area_struct *vma, =20 subpage =3D folio_page(folio, pte_pfn(*pvmw.pte) - folio_pfn(folio)); + /* + * We check the page flags of HugeTLB pages by checking the + * head page. + */ + page_flags_page =3D folio_test_hugetlb(folio) + ? &folio->page + : subpage; + page_poisoned =3D PageHWPoison(page_flags_page); address =3D pvmw.address; anon_exclusive =3D folio_test_anon(folio) && - PageAnonExclusive(subpage); + PageAnonExclusive(page_flags_page); =20 if (folio_test_hugetlb(folio)) { bool anon =3D folio_test_anon(folio); @@ -1523,7 +1532,7 @@ static bool try_to_unmap_one(struct folio *folio, str= uct vm_area_struct *vma, * The try_to_unmap() is only passed a hugetlb page * in the case where the hugetlb page is poisoned. */ - VM_BUG_ON_PAGE(!PageHWPoison(subpage), subpage); + VM_BUG_ON_FOLIO(!page_poisoned, folio); /* * huge_pmd_unshare may unmap an entire PMD page. * There is no way of knowing exactly which PMDs may @@ -1606,7 +1615,7 @@ static bool try_to_unmap_one(struct folio *folio, str= uct vm_area_struct *vma, /* Update high watermark before we lower rss */ update_hiwater_rss(mm); =20 - if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) { + if (page_poisoned && !(flags & TTU_IGNORE_HWPOISON)) { pteval =3D swp_entry_to_pte(make_hwpoison_entry(subpage)); if (folio_test_hugetlb(folio)) { hugetlb_count_sub(1UL << pvmw.pte_order, mm); @@ -1632,7 +1641,9 @@ static bool try_to_unmap_one(struct folio *folio, str= uct vm_area_struct *vma, mmu_notifier_invalidate_range(mm, address, address + PAGE_SIZE); } else if (folio_test_anon(folio)) { - swp_entry_t entry =3D { .val =3D page_private(subpage) }; + swp_entry_t entry =3D { + .val =3D page_private(page_flags_page) + }; pte_t swp_pte; /* * Store the swap location in the pte. @@ -1831,7 +1842,7 @@ static bool try_to_migrate_one(struct folio *folio, s= truct vm_area_struct *vma, struct mm_struct *mm =3D vma->vm_mm; DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0); pte_t pteval; - struct page *subpage; + struct page *subpage, *page_flags_page; bool anon_exclusive, ret =3D true; struct mmu_notifier_range range; enum ttu_flags flags =3D (enum ttu_flags)(long)arg; @@ -1911,9 +1922,16 @@ static bool try_to_migrate_one(struct folio *folio, = struct vm_area_struct *vma, subpage =3D folio_page(folio, pte_pfn(*pvmw.pte) - folio_pfn(folio)); } + /* + * We check the page flags of HugeTLB pages by checking the + * head page. + */ + page_flags_page =3D folio_test_hugetlb(folio) + ? &folio->page + : subpage; address =3D pvmw.address; anon_exclusive =3D folio_test_anon(folio) && - PageAnonExclusive(subpage); + PageAnonExclusive(page_flags_page); =20 if (folio_test_hugetlb(folio)) { bool anon =3D folio_test_anon(folio); @@ -2032,7 +2050,7 @@ static bool try_to_migrate_one(struct folio *folio, s= truct vm_area_struct *vma, * No need to invalidate here it will synchronize on * against the special swap migration pte. */ - } else if (PageHWPoison(subpage)) { + } else if (PageHWPoison(page_flags_page)) { pteval =3D swp_entry_to_pte(make_hwpoison_entry(subpage)); if (folio_test_hugetlb(folio)) { hugetlb_count_sub(1L << pvmw.pte_order, mm); --=20 2.39.0.314.g84b9a713c41-goog