From patchwork Thu Jan 5 10:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 39451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp228004wrt; Thu, 5 Jan 2023 02:23:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXtXXnAoIHeZo7FzqpQOHIaYUMtM2jF19Y3kosWNQptEKh8LMNig41H96E8WyJ91Sw7Do5+B X-Received: by 2002:a05:6a20:93a7:b0:b0:42a5:fe24 with SMTP id x39-20020a056a2093a700b000b042a5fe24mr66726955pzh.4.1672914202187; Thu, 05 Jan 2023 02:23:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672914202; cv=none; d=google.com; s=arc-20160816; b=jEbkgS0ZuC73Qs/P9rE11Aglv68lwokkiItVWWUqritsXIF6wirDjvnlGFm5jqr8bR F0EOG4Jb1Gl1sZvSzWAEGzwRzEyUFsfVduHdPsDCvxYvnPF78gTaZYIQ0vssfNFhkr7+ 1oLAGH5lqqwyyoAxFA0AjYm897BqpREjHF/c8DbB5EzYAx0vre5dT/pJsfqa1Z9Zh3Dd 7m0tb4t5IqERbjHACNAxU45lEWUlB/cxmCUh3XWsdyYZCsbdaDMIY0x7JdsntpXKW8mN J2N1zN6csRC1q/x+bKRNvmvZcB/63phWrDOAtHc71o6WbiQw2DPCU/CytsSO0zxWavnT 24zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=/OkucptRSHaE2jww1tz6Gz5twfCMvXYe7c+PeOdayik=; b=q/UYNheN4i1Mk3a6WeM8yyBWg/PIvAnFgIkqa9wuYKxjty9QuAGSZG+SsNJnRvA4Sr 8fTMaeuPa+a3hky7Uexr5Sflw3KSjWESwuUGsPBsnqM3bP4qD8CaP5sDmKkn1jYkxmmy IvdUhKvvKUPrH+Z5Kq4U21+jUF8MV1Cf/GtlmGT1939ti58GFaEDMkKot0WVQ4IHMDXp N/C942WBcn2KHdrjLjZJRCJPUyYAC2rk/jSXVxvT52qLUufrjILqZBZDNbycXGnoFOVn b1d4pDJ7X/aR2jjU1F5h8zcO2BwXR7tHh8bvgkqFwBjRIDLavz8w0oTDTPYZAUthANRM rVVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=iSGNYib6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a5-20020a631a45000000b004794a80d855si35475053pgm.708.2023.01.05.02.23.06; Thu, 05 Jan 2023 02:23:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=iSGNYib6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232721AbjAEKWU (ORCPT + 99 others); Thu, 5 Jan 2023 05:22:20 -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-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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754177682517792348?= X-GMAIL-MSGID: =?utf-8?q?1754177682517792348?= 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, struct vm_area_struct *vma, struct mm_struct *mm = 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 = true; struct mmu_notifier_range range; enum ttu_flags flags = (enum ttu_flags)(long)arg; + bool page_poisoned; /* * When racing against e.g. zap_pte_range() on another cpu, @@ -1512,9 +1513,17 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, subpage = 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 = folio_test_hugetlb(folio) + ? &folio->page + : subpage; + page_poisoned = PageHWPoison(page_flags_page); address = pvmw.address; anon_exclusive = folio_test_anon(folio) && - PageAnonExclusive(subpage); + PageAnonExclusive(page_flags_page); if (folio_test_hugetlb(folio)) { bool anon = folio_test_anon(folio); @@ -1523,7 +1532,7 @@ static bool try_to_unmap_one(struct folio *folio, struct 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, struct vm_area_struct *vma, /* Update high watermark before we lower rss */ update_hiwater_rss(mm); - if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) { + if (page_poisoned && !(flags & TTU_IGNORE_HWPOISON)) { pteval = 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, struct vm_area_struct *vma, mmu_notifier_invalidate_range(mm, address, address + PAGE_SIZE); } else if (folio_test_anon(folio)) { - swp_entry_t entry = { .val = page_private(subpage) }; + swp_entry_t entry = { + .val = 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, struct vm_area_struct *vma, struct mm_struct *mm = 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 = true; struct mmu_notifier_range range; enum ttu_flags flags = (enum ttu_flags)(long)arg; @@ -1911,9 +1922,16 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, subpage = 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 = folio_test_hugetlb(folio) + ? &folio->page + : subpage; address = pvmw.address; anon_exclusive = folio_test_anon(folio) && - PageAnonExclusive(subpage); + PageAnonExclusive(page_flags_page); if (folio_test_hugetlb(folio)) { bool anon = folio_test_anon(folio); @@ -2032,7 +2050,7 @@ static bool try_to_migrate_one(struct folio *folio, struct 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 = swp_entry_to_pte(make_hwpoison_entry(subpage)); if (folio_test_hugetlb(folio)) { hugetlb_count_sub(1L << pvmw.pte_order, mm);