Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1396522pxb; Sun, 17 Jan 2021 07:24:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxo82haRRcZsumaNtkGEx/U62E/GkL5jRw+YkZzOn6It5SFzmZnqxfKP0ozCUouBE2FWTp6 X-Received: by 2002:aa7:db01:: with SMTP id t1mr16298857eds.185.1610897051099; Sun, 17 Jan 2021 07:24:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610897051; cv=none; d=google.com; s=arc-20160816; b=0m2ZSxzuc0ocnpDbuS/nPs9lYKA92FWZFHnQjvz72Z/h/sm5oAxq0ZMiEphvWbcKDt W2l1C0OrbK0tNmddD0mM2il/tS5UFTMm0+I2qKTUrmOCY6vlMR5K4Rg0T7XII0+icW9P +4wo+zXaZ/Pu0C1lWn0VqH7JZcd752LIuFkXZy9wL4KR6kc0fDEVwo0s1oHTiX4JbuAv 5t0MlmNyVZyr5q1Qk0vwCGqtjp8xTTPVSA3alp2xBy9Iclq1UksWtPk9wKSyDj8kZXGb QU0MT1RkVGlwc4LZ27jlOW7rkt82JlayblegFaHsRoYWQ1nzTebz+qnV2XKT4u8vlg0P ZP0w== 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=tAzAJAw7JBXGA5wVumCYbe7IIg4huGuKzHI34tpedh0=; b=ck/jkIViMV+C91AnGrmLXDZzzdrqeejXVPqOVX7plUt4wXANMbL1BODJzreYiEomxA Ou6UJVOk/cxIn1lygPL8XakrJHKnEdCFT0YjJ1UbvZEQVgeKFfVQcA5up590TrTstoDT cOS4xSH4rrhAygxW8K7ijwSxjnAKBLPMjEGxZkH1hfGjA6zRKQrTBqTrxPZEsrRd27sD 3XoX6uhjk2iGqzDh4JnLmGrzRFPLQkFXv7FwqWVgDWf6yTpya+pDxbaqQc47haCb9/IZ SwnqCGqPaDy82Yag5iWuXNSluUCWACtLM5B/lH92w0oVQhIBssPFy7KrIF5Qe5V/R19g gb8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=KTUr9bgv; 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 a20si5885535edn.43.2021.01.17.07.23.47; Sun, 17 Jan 2021 07:24:11 -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=KTUr9bgv; 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 S1729552AbhAQPUe (ORCPT + 99 others); Sun, 17 Jan 2021 10:20:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729504AbhAQPPW (ORCPT ); Sun, 17 Jan 2021 10:15:22 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7485C0613CF for ; Sun, 17 Jan 2021 07:14:41 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id md11so7847070pjb.0 for ; Sun, 17 Jan 2021 07:14:41 -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=tAzAJAw7JBXGA5wVumCYbe7IIg4huGuKzHI34tpedh0=; b=KTUr9bgvGRfZY7zXyuwqqHtpRf08YVqRbt+LDLJU7qpqnjsV8fzOF/1SuTd2UmsSpW mGlYwlOtzOcINqgu4C5bZ1e93d+XOozvOTgYxbuejQG+mvigc4Z7OXdbWEjfXbhW45pr grL/MeFRczzi5E2HbJ3K9zLMQ5nKra2Ed6nKyQX1Zr3nWiHUBSaF8W3GnWun90ZMqdmG TMSIxi2AQWQ9Ni3I2zfoUC0zvJqa99AyQvzd+bUHhdEANd1Ky8yDKSwzXKSRRkeGTYSs N5J5MtL78j0A4Pa+APQ/OvmwiQmzGXnIcPi9FQ5wVzLLcuRUU5DHBiBSOlUT9EyWNCX1 Nuqw== 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=tAzAJAw7JBXGA5wVumCYbe7IIg4huGuKzHI34tpedh0=; b=GyOB+gkIssAajECVUFG4Wgaac4VEnmM9Yj1teYUuO3ag14XuuyFVTWy+8KBoJlZCZs pBpah3Ddo385TcpSrPDMuCp80p7rnII6cjMFdrgIsgGR0cuOJmXRaAaKleXg37LKGGKC 60D1J883UwwRdZceyK1mTzudsarh5D+X4SOSaO3hvGUB8NLjmK4UzTi4ZaTV3yxlF5DM X+R8glUXwXNq2AGI8us4+XD6eacf6DxyeVfnXhblAwSXmuXB3UkXIdmVWIDTCd/5F3Rm YhknOw2H2jDgJuosBMVqz5hlrp0KxXHdpgC5zI89ClNc4GKZiXcALdy7YCuxy1EmYwHp 80cw== X-Gm-Message-State: AOAM5322oDOQeYlSdYqMXOrB9NTQRECI4cETcNzr91k0q86YWWWxjv26 wSV4L9SPBJ9e+DHoyQ/PA08XYg== X-Received: by 2002:a17:90a:e006:: with SMTP id u6mr20691095pjy.201.1610896481318; Sun, 17 Jan 2021 07:14:41 -0800 (PST) Received: from localhost.bytedance.net ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id i22sm9247915pjv.35.2021.01.17.07.14.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Jan 2021 07:14:40 -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 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 v13 06/12] mm: hugetlb: set the PageHWPoison to the raw error page Date: Sun, 17 Jan 2021 23:10:47 +0800 Message-Id: <20210117151053.24600-7-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210117151053.24600-1-songmuchun@bytedance.com> References: <20210117151053.24600-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 a tail page. So we can use the head[4].private to record the real error page index and set the raw error page PageHWPoison later. Signed-off-by: Muchun Song Reviewed-by: Oscar Salvador --- mm/hugetlb.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d11c32fcdb38..6caaa7e5dd2a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1358,6 +1358,63 @@ static inline void __update_and_free_page(struct hstate *h, struct page *page) schedule_work(&hpage_update_work); } +#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); + } +} + +#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); + } +} +#endif + static void update_and_free_page(struct hstate *h, struct page *page) { if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) @@ -1373,6 +1430,8 @@ static void __free_hugepage(struct hstate *h, struct page *page) { int i; + hwpoison_subpage_deliver(h, page); + for (i = 0; i < pages_per_huge_page(h); i++) { page[i].flags &= ~(1 << PG_locked | 1 << PG_error | 1 << PG_referenced | 1 << PG_dirty | @@ -1845,14 +1904,8 @@ int dissolve_free_huge_page(struct page *page) int nid = page_to_nid(head); if (h->free_huge_pages - h->resv_huge_pages == 0) goto out; - /* - * 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]--; -- 2.11.0