From patchwork Sat Feb 18 00:28:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13145394 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6579FC6379F for ; Sat, 18 Feb 2023 00:29:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C8AA280018; Fri, 17 Feb 2023 19:29:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 87893280002; Fri, 17 Feb 2023 19:29:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CD51280018; Fri, 17 Feb 2023 19:29:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5DDE5280002 for ; Fri, 17 Feb 2023 19:29:14 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3CFB380799 for ; Sat, 18 Feb 2023 00:29:14 +0000 (UTC) X-FDA: 80478528228.05.125A0CB Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf10.hostedemail.com (Postfix) with ESMTP id 73D2FC0007 for ; Sat, 18 Feb 2023 00:29:12 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YN0Pytyi; spf=pass (imf10.hostedemail.com: domain of 31xvwYwoKCPQfpdkqcdpkjckkcha.Ykihejqt-iigrWYg.knc@flex--jthoughton.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=31xvwYwoKCPQfpdkqcdpkjckkcha.Ykihejqt-iigrWYg.knc@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676680152; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1rCBHumdufOlTcJkqiypODYa1r7LDyl4S1gdc35TorQ=; b=MBQETJbUM/T7t895gmVtHRqIiZOlkp7Q/U633cCB4YdVRJVXgY2485dstM3Exs9med2Z1J nfkoqfMipRhm11HAwdNMQ3VQGWRCznW0nlpQqF7aCVRgGRtCC78e39WV+P5USv81MA5MXi QDKXT0e36RLv2MNJP0tjMppY2X+fDfM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YN0Pytyi; spf=pass (imf10.hostedemail.com: domain of 31xvwYwoKCPQfpdkqcdpkjckkcha.Ykihejqt-iigrWYg.knc@flex--jthoughton.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=31xvwYwoKCPQfpdkqcdpkjckkcha.Ykihejqt-iigrWYg.knc@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676680152; a=rsa-sha256; cv=none; b=d9ab+x9vw4z+ar/xe6sYcOPCyE5enFBNMG+kbfkplo+gn39ruz5TxUJeJVSx0neAaf6VTN yhZQBNSOKLieNbIyn5FhzVKrh+qQGZ1g1UNpGmHNDLTZ5hCbv1Kv0lB+5YJI0YknU5EMpo bAenD+wuz1k3KMDUME7aC/sPcE5bzAs= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5365741ec51so24410207b3.1 for ; Fri, 17 Feb 2023 16:29:12 -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=1rCBHumdufOlTcJkqiypODYa1r7LDyl4S1gdc35TorQ=; b=YN0PytyiHYPIu8m+M2E6v1NUQCnHXY6ytZcGKXyuh7z/uqk1m7+gCvJsZq1js1+Nyk aWy2chcaY0oSjM7oplmnZTRau4yrS7eatEn1k9ey5wfeHKB+fHXyH3hpyjtsmTvEZjCC 943Dvm4iECKIUtQU6bNEzs0C/hZeHT7vfxnkuu/ImNucvgQ6NZzZ5BLuTjeDWoY/lNEN mppTbWX+d43SPhJRbQNNU06lgt5y4Yc251XxwreuYdKf65ASB8UzsacjLW/LKF5eAHUL AdfT5Xxv2SVRLajtE01G0LVCPjbrRrRShVjKlJ9kluNRT6aaGpxY/8iNFGTbZhsxLO7k +hCw== 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=1rCBHumdufOlTcJkqiypODYa1r7LDyl4S1gdc35TorQ=; b=L3GsITZDlydjm4x6YR/81uR8Gr2AeLV77LbVSyhp6I0hE4xRjD6Z8KJGVmp3LHM5kq Fta572BP3taKATUx5Gt88MsrwJ92+fVE4LziSQhVPEzhJ/Ra4ENxXH8hY5qD2UxRcl+c D6hHUFrgZvGxgcswN9hV73lys8WYDXObCAdKWWg23WlbzyjGAxgkf3AQV9+L6F/A9f24 V4sJvQCnsLyRmuwattlALbQUFklLzJpQILaHCryZ3I8zz10AuRMiwy/mp5KTEfJce3DK 2hmc3/mxgbsPOylXD9Y1Sk/cditjES8mLbxGiFPosCHLfH+iWVtSV6KDxbP2qanm8uTO 2sXw== X-Gm-Message-State: AO0yUKVot7A8IMD2Ks+94G/HpPFGjJYiTEzIbsG0QoEy8vvGomPCsNoK FLCoYB6PENY4zSE2ukoQPadwToMc3avcDWfz X-Google-Smtp-Source: AK7set+LO+JnPnboVPieFkXX7WpathP3qjh8yyUr3ixLzVkV8bA9em/CG8b88d9+skAi+Y+zl4Jc6Pv1vnp/FebD X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a5b:910:0:b0:927:a3c1:b2de with SMTP id a16-20020a5b0910000000b00927a3c1b2demr200123ybq.7.1676680151721; Fri, 17 Feb 2023 16:29:11 -0800 (PST) Date: Sat, 18 Feb 2023 00:28:01 +0000 In-Reply-To: <20230218002819.1486479-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230218002819.1486479-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230218002819.1486479-29-jthoughton@google.com> Subject: [PATCH v2 28/46] mm: rmap: in try_to_{migrate,unmap}, check head page for hugetlb page flags From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu , Andrew Morton 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 , Frank van der Linden , Jiaqi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 73D2FC0007 X-Stat-Signature: junxxkpuqcmdybe5smunbuk5cy111tto X-Rspam-User: X-HE-Tag: 1676680152-841058 X-HE-Meta: U2FsdGVkX18FfONQ1l+Lzua4iEEsbFeRuYaT8rRA6NHABiX7nEXmmvnc3UD+3S4FkoS/B7BkD3RKw2tMLOpSgRvd21usrAuvtaEGJOAe96NWF4EMRKbrzZyc7R8zo3Y56idj/+IfMjNnYvofqWmyX7VxKzRfMycr0NYgpYuS0W1HPPhHrxdQbKDYqwqQDrHoA7cs4Ly8HRTFAMgyajPuxZjC7NSRg+y4w+7mPg3BZjPhxQBenXemBnsu3pnh9Wzl4h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1WAEqJTJ96nhg2sEiQxMRrBL7Mxivi9zrqpU2L+W9zyxiwOrwdntFKsK0gLDNTOgXIrAV5KdF0sFmxPMhK5K/bCpKyJNEjzwBeEFvrRD3s6LvXEn+/hfSm9g+ZFgeH4kieX0Mroams1tWEDjljgQI/Jz9ALQdPQNOCGrVjF8DDpuxroD7ndcGfKZe43TNq0qRZoMsoywLzTrvf5dy8xn6ITR38mWFtkeCoxoHUXWPZff1tVe5CZPnrmBECJqXNbgPbD1P5XYoGaYllZl11gVx98XHXv4h2+mF7VfTPrxGTLtNNR5Cv6B9uqLiScTyandmIJtrq5kj1epop/zWoTjmfhGlgkePifRZNAnYu4KIpv9ZRbIgxJaAzbMHbpXSYOd8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 diff --git a/mm/rmap.c b/mm/rmap.c index 0a019ae32f04..4908ede83173 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. @@ -1822,7 +1833,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; @@ -1902,9 +1913,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); @@ -2023,7 +2041,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);