From patchwork Mon Mar 8 10:28:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12121905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 455D7C433E0 for ; Mon, 8 Mar 2021 10:31:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC02A65132 for ; Mon, 8 Mar 2021 10:31:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC02A65132 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5E7EE8D0015; Mon, 8 Mar 2021 05:31:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BE9E8D000F; Mon, 8 Mar 2021 05:31:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 411DE8D0015; Mon, 8 Mar 2021 05:31:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0120.hostedemail.com [216.40.44.120]) by kanga.kvack.org (Postfix) with ESMTP id 240618D000F for ; Mon, 8 Mar 2021 05:31:24 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DABA4180AD83B for ; Mon, 8 Mar 2021 10:31:23 +0000 (UTC) X-FDA: 77896340046.19.5983B6F Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf24.hostedemail.com (Postfix) with ESMTP id 151BDA0009EB for ; Mon, 8 Mar 2021 10:31:19 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id 18so6873191pfo.6 for ; Mon, 08 Mar 2021 02:31:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u/7q5jKbe1h7Dqnn8YQgFTLIuxg0NiRfhwLI2F7iM04=; b=2D1Ds2tzTzq9fkHg3X+MAmOL7avtFF8QmPD5PdZb96jlfAYlr8/IujR7UrYRSsdIci l9LjwVRPJ9VvTkLg5ftFw3UJhxUC8A/O9ZSVn/G22/4JNMa6JdO4UX78eBjnmj2UVyF3 lJotzLN7vo//HeYFb3FnhQ3tVIn6lLTmLaHrW7mVc2PLoiVNJQ1wZNMHV2bcD7ao3ByY +rx12aJAD5s1yLZLWgj5zFMOMuX2ylhCRXBY6Km8qa/pJBR0kwyjD+Ss2ns3Br9ESB+j nkQJFmncnwd2btkDnhDASU41F6Uv7JbBnsjnSwqAHfstvWtpd1s6ZV/TV48D0nLNaLbj 9PUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u/7q5jKbe1h7Dqnn8YQgFTLIuxg0NiRfhwLI2F7iM04=; b=OxALvw5ttua640khFovV1FLe1J2ZkkZ4PFw89r34P0c5Fu8V8LS16CXXIMCirxaUgH nrOf6ejCnrlvSeaT2byhUMmBjFxVr2nazK6EXYJdwgiwmfU6+hgJeidTNo1upyer5Sss A5JA/eUFGAMEbQUuz/dYETi/vGEllf4u2z+dmWpesSNCzvJZYW+uAGyLM5T3G1xQ5Rff UOhK7ZvWrymVBSq1Yi/CdQAh91aF+n9SdAhXXLWIP0KwLYfbPkbGKRrQPG8aOghSCvNV lKVSEW3qzrSLlFcFdV1zk2Cl3ODo2X57GBUzFSfoD6kz4I8j07WYAMaXTPojO0juQ1oq jfVw== X-Gm-Message-State: AOAM531fvbNf/28QXfqc0v45HIVPDXbpFLLwKAWrk6AoR0VF5LmiYQRJ U3xzo3bfQDj/N9sU8S8/UAH8xw== X-Google-Smtp-Source: ABdhPJxZeyIEv6Ck0syTAoATaWCVajWwmZMOl8Mfs7LYXnyPhBCO6WxfzZJZdQmq03z8S9g976TLOg== X-Received: by 2002:aa7:9f52:0:b029:1ee:db83:dac6 with SMTP id h18-20020aa79f520000b02901eedb83dac6mr19909392pfr.45.1615199482118; Mon, 08 Mar 2021 02:31:22 -0800 (PST) Received: from localhost.localdomain ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id ge16sm10744705pjb.43.2021.03.08.02.31.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Mar 2021 02:31:21 -0800 (PST) From: Muchun Song To: corbet@lwn.net, mike.kravetz@oracle.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, rdunlap@infradead.org, oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, almasrymina@google.com, rientjes@google.com, willy@infradead.org, osalvador@suse.de, mhocko@suse.com, song.bao.hua@hisilicon.com, david@redhat.com, naoya.horiguchi@nec.com, joao.m.martins@oracle.com Cc: duanxiongchun@bytedance.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Muchun Song , Chen Huang , Bodeddula Balasubramaniam Subject: [PATCH v18 5/9] mm: hugetlb: set the PageHWPoison to the raw error page Date: Mon, 8 Mar 2021 18:28:03 +0800 Message-Id: <20210308102807.59745-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210308102807.59745-1-songmuchun@bytedance.com> References: <20210308102807.59745-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: f99thfcophjrfyxhmn3d16jkmfja4chp X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 151BDA0009EB Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=mail-pf1-f169.google.com; client-ip=209.85.210.169 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615199479-330753 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: Because we reuse the first tail vmemmap page frame and remap it with read-only, we cannot set the PageHWPosion on some tail pages. So we can use the head[4].private (There are at least 128 struct page structures associated with the optimized HugeTLB page, so using head[4].private is safe) to record the real error page index and set the raw error page PageHWPoison later. Signed-off-by: Muchun Song Reviewed-by: Oscar Salvador Acked-by: David Rientjes Tested-by: Chen Huang Tested-by: Bodeddula Balasubramaniam --- mm/hugetlb.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 377e0c1b283f..c0c1b7635ca9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1304,6 +1304,74 @@ static inline void destroy_compound_gigantic_page(struct page *page, unsigned int order) { } #endif +#ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP +static inline void hwpoison_subpage_deliver(struct hstate *h, struct page *head) +{ + struct page *page; + + if (!PageHWPoison(head) || !free_vmemmap_pages_per_hpage(h)) + return; + + page = head + page_private(head + 4); + + /* + * Move PageHWPoison flag from head page to the raw error page, + * which makes any subpages rather than the error page reusable. + */ + if (page != head) { + SetPageHWPoison(page); + ClearPageHWPoison(head); + } +} + +static inline void hwpoison_subpage_set(struct hstate *h, struct page *head, + struct page *page) +{ + if (!PageHWPoison(head)) + return; + + if (free_vmemmap_pages_per_hpage(h)) { + set_page_private(head + 4, page - head); + } else if (page != head) { + /* + * Move PageHWPoison flag from head page to the raw error page, + * which makes any subpages rather than the error page reusable. + */ + SetPageHWPoison(page); + ClearPageHWPoison(head); + } +} + +static inline void hwpoison_subpage_clear(struct hstate *h, struct page *head) +{ + if (!PageHWPoison(head) || !free_vmemmap_pages_per_hpage(h)) + return; + + set_page_private(head + 4, 0); +} +#else +static inline void hwpoison_subpage_deliver(struct hstate *h, struct page *head) +{ +} + +static inline void hwpoison_subpage_set(struct hstate *h, struct page *head, + struct page *page) +{ + if (PageHWPoison(head) && page != head) { + /* + * Move PageHWPoison flag from head page to the raw error page, + * which makes any subpages rather than the error page reusable. + */ + SetPageHWPoison(page); + ClearPageHWPoison(head); + } +} + +static inline void hwpoison_subpage_clear(struct hstate *h, struct page *head) +{ +} +#endif + static int update_and_free_page(struct hstate *h, struct page *page) __releases(&hugetlb_lock) __acquires(&hugetlb_lock) { @@ -1357,6 +1425,8 @@ static int update_and_free_page(struct hstate *h, struct page *page) return -ENOMEM; } + hwpoison_subpage_deliver(h, page); + for (i = 0; i < pages_per_huge_page(h); i++, subpage = mem_map_next(subpage, page, i)) { subpage->flags &= ~(1 << PG_locked | 1 << PG_error | @@ -1801,14 +1871,7 @@ int dissolve_free_huge_page(struct page *page) goto retry; } - /* - * Move PageHWPoison flag from head page to the raw error page, - * which makes any subpages rather than the error page reusable. - */ - if (PageHWPoison(head) && page != head) { - SetPageHWPoison(page); - ClearPageHWPoison(head); - } + hwpoison_subpage_set(h, head, page); list_del(&head->lru); h->free_huge_pages--; h->free_huge_pages_node[nid]--; @@ -1818,6 +1881,7 @@ int dissolve_free_huge_page(struct page *page) h->surplus_huge_pages--; h->surplus_huge_pages_node[nid]--; h->max_huge_pages++; + hwpoison_subpage_clear(h, head); } } out: