Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp393810pxb; Thu, 25 Feb 2021 05:31:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYvJA1m7UNlZdX3CBH6Fxkz+80nKrXIvO3wnWAfD/3IUgEYmpj9t226xlCZRZvhjm+8yo0 X-Received: by 2002:a17:907:728b:: with SMTP id dt11mr2661672ejc.321.1614259912765; Thu, 25 Feb 2021 05:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614259912; cv=none; d=google.com; s=arc-20160816; b=Acc6XJSjfcWdLs5KyKtQKfcNw/VbThFcmjmX7rCml5j4KCmnMLNkGElZEcOvbXEI3S fvc/tik8WHETx1cmVRnMH0941tAazKU94Sgm2xH+WiL3YbI14uHx2oXsPZzsvSeRJ/Xn 19BtxJ9G6YnbWA0CHY/z5r03SqtXhIN95HLH9vJEf1FMvldfOzUN2K8j4K2jHOfaNh6f EcllR3ajHBne/UyYrg/KZDBVhe+bC8xDnsjLAwesI4HEGzWbO07eFxagi3rrseRC8tfZ PSH+9nGozDDCCkPYYwsnNgq0ISoCEdB//N4L8V3kX3LBawcvNFcsJprFQIiPZYbSzL/N 21EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vCS+yi4FQEcYV3QuXltaFkVQ0yQluHl+1qNlK3wFCCA=; b=d1d0iYaM2WI96az5HRNfNVrh7LQeNRS39B1jWmTNq1bW827eq+RlH/8VvDzQAG0GuU o9AbP7COfhKArJWo4vrylMNE5gEhy/DFDT7TquPzWt9r23Q/3adq4DmWFviLHJEtby7y /ZI6tPqJYLyvAqa/mimwQH9uqZaznbk4EI/ZN1gYpQsnsFoiap/WlndKO0IilHshm0cO K7m/AINN4aSCHdUzuWhE1PskfAm2qE5N5FHBqyvHkSWsZVKgNzoCKBrhEB27/GN93bxt C4HdJX1SJhwRzkRkNzEJ/0UkybY1DSbXZhBK/jjyv0kRLxetb8K9AI0wPOHUpN75QUw+ Eg1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=erxLSBf5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q21si3049052edt.445.2021.02.25.05.31.30; Thu, 25 Feb 2021 05:31:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=erxLSBf5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232310AbhBYN2Q (ORCPT + 99 others); Thu, 25 Feb 2021 08:28:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232557AbhBYNZn (ORCPT ); Thu, 25 Feb 2021 08:25:43 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F0E1C06121D for ; Thu, 25 Feb 2021 05:24:30 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id r5so3574468pfh.13 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=GHeRaoR8hi6cKu+yd8qpVgEuesTelHUvDQORGkXdepaWGcYd0gsLSEzj5oLFbq9F12 FrdEY68365inNuLW31KJCJ6puy701LRR1k2zLp6KN+LiYWF4PVV7utCjbbko1p7KdJvG ly8Y8kN/MQXzFjdeVUBE9Jon1r8Qa/slMMnrSbUWjxNIFHmbTRIeNJ9fPBEYThavClt4 mmAD2jXHrcmh2LrxRjz7OXODr2TzvBn4/aOZUYlaMhH1AYhF7R2DvirF/V21vP28v6y+ wLFYSDYQuCrQbq925z/XB9WcI00z7q57P7TejHkPqDqIko3s28udBhC2n2kFI+EQ5+/q jYZQ== X-Gm-Message-State: AOAM531jWkhOGsNsQo2u3fNxMfDj56K/i8k/TnmIJW2o//vM5GnBnI+D fYkEN4euo5bX7mjv/QyY7S1nQQ== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 +#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: -- 2.11.0