From mboxrd@z Thu Jan 1 00:00:00 1970 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 069F5C433E0 for ; Thu, 25 Feb 2021 13:24:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6DFD864F06 for ; Thu, 25 Feb 2021 13:24:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6DFD864F06 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 E37738D0024; Thu, 25 Feb 2021 08:24:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DE6878D0005; Thu, 25 Feb 2021 08:24:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFF2E8D0024; Thu, 25 Feb 2021 08:24:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id BB1218D0005 for ; Thu, 25 Feb 2021 08:24:31 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 77D061804EE3A for ; Thu, 25 Feb 2021 13:24:31 +0000 (UTC) X-FDA: 77856859542.23.91CA525 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf03.hostedemail.com (Postfix) with ESMTP id C3A95C0007CC for ; Thu, 25 Feb 2021 13:24:27 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id b145so3608297pfb.4 for ; Thu, 25 Feb 2021 05:24:30 -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=vCS+yi4FQEcYV3QuXltaFkVQ0yQluHl+1qNlK3wFCCA=; b=erxLSBf5h20SirJAItdp/RRKXmAFqy0tCXbBdqAdA1U4hLCBOEzCEKjSZUpkJkRFPp bm+g0tnaeGA1+Jm0k4341aeyl7XuVIcRkAHW4vtwvzdM7sp+jJ/BGlmouwv3+1dAjnwq 69c1nDI4DuNRwtiOUEIcgWSaFp+W/m/EHBJuKX72VYwRd3fcyWvsyBOsZnXpGPiYYRTJ W/jZDpqNtACw2kQBFADhBoEIqWAsdsuRnm4EibYa7ibDqNaD4MpsoekBJb+9r+4fB3WZ 9IWjYRPvCJWaf/aY+sMr8wGweLc/6FvFqfIcecfxe9TwSuOU/MI1nRN8n+5UKHxeGz5t dsiQ== 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=vCS+yi4FQEcYV3QuXltaFkVQ0yQluHl+1qNlK3wFCCA=; b=ousL0oNKrok3NYcfMu3s/VcKA2aXUpC1+aQa37DENT2yOhk4ElQo3LCzKNpyqXH6jG SWOKU4oqqHx3cC1yvEgzChFWUTXUOYauyBJU8MAoKYxqItH8ezxOxI0O/IvCb8MCQzmK V08PnHqz95ZwIBbTN6CZbRBbBiLwKLJCn8JlEkgHDwpdkkVXSVZarLOJ8m4ZSHXV1ZFU thrL21UVF23lQkgTHLjWYYxZ3TKm7ft3YLH+SwVR1kBltlBApOYTUjAZldNItIYAuxv+ kisTxoRC1kXFzVhdI4brLQQu0KSEOI706jHIlKc7VBSb6hncuqrSQ1ImhyPxDrPhyw+H 8NQg== X-Gm-Message-State: AOAM532dt9zbS/cCGYf6lYNL3knGBvrxB3I2eBxlujJXdpzl743VrPh/ 9r/9S+KIVBivkiJfm30YUx2GCQ== X-Google-Smtp-Source: ABdhPJw3y7ROzg9OQ2a0vx0Co7aebFMTYs2UosINX3/4J5/+VEb4/z5L8//VT0lad9XYnbmnNmyTDw== X-Received: by 2002:a63:221b:: with SMTP id i27mr3009806pgi.44.1614259469960; Thu, 25 Feb 2021 05:24:29 -0800 (PST) Received: from localhost.localdomain ([139.177.225.236]) by smtp.gmail.com with ESMTPSA id x190sm6424676pfx.166.2021.02.25.05.24.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Feb 2021 05:24:29 -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 Subject: [PATCH v17 5/9] mm: hugetlb: set the PageHWPoison to the raw error page Date: Thu, 25 Feb 2021 21:21:26 +0800 Message-Id: <20210225132130.26451-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210225132130.26451-1-songmuchun@bytedance.com> References: <20210225132130.26451-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C3A95C0007CC X-Stat-Signature: 45iafq4awyqaj5n6hzrdgmri5x8r3cwo Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=mail-pf1-f174.google.com; client-ip=209.85.210.174 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614259467-136384 Content-Transfer-Encoding: quoted-printable 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 --- mm/hugetlb.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++= ------ 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b6e4e3f31ad2..bccb6907833f 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 =20 +#ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP +static inline void hwpoison_subpage_deliver(struct hstate *h, struct pag= e *head) +{ + struct page *page; + + if (!PageHWPoison(head) || !free_vmemmap_pages_per_hpage(h)) + return; + + page =3D 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 !=3D head) { + SetPageHWPoison(page); + ClearPageHWPoison(head); + } +} + +static inline void hwpoison_subpage_set(struct hstate *h, struct page *h= ead, + struct page *page) +{ + if (!PageHWPoison(head)) + return; + + if (free_vmemmap_pages_per_hpage(h)) { + set_page_private(head + 4, page - head); + } else if (page !=3D 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 pag= e *head) +{ +} + +static inline void hwpoison_subpage_set(struct hstate *h, struct page *h= ead, + struct page *page) +{ + if (PageHWPoison(head) && page !=3D 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, s= truct page *page) return -ENOMEM; } =20 + hwpoison_subpage_deliver(h, page); + for (i =3D 0; i < pages_per_huge_page(h); i++, subpage =3D mem_map_next(subpage, page, i)) { subpage->flags &=3D ~(1 << PG_locked | 1 << PG_error | @@ -1801,14 +1871,7 @@ int dissolve_free_huge_page(struct page *page) goto retry; } =20 - /* - * 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 !=3D 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: --=20 2.11.0