From patchwork Thu Sep 30 21:53:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12529369 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53221C43217 for ; Thu, 30 Sep 2021 21:53:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EC930619F8 for ; Thu, 30 Sep 2021 21:53:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EC930619F8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8C3CC9400D5; Thu, 30 Sep 2021 17:53:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84E2294003A; Thu, 30 Sep 2021 17:53:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C5D89400D5; Thu, 30 Sep 2021 17:53:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5B81C94003A for ; Thu, 30 Sep 2021 17:53:20 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 126A3180AC498 for ; Thu, 30 Sep 2021 21:53:20 +0000 (UTC) X-FDA: 78645591360.36.F2A499D Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf25.hostedemail.com (Postfix) with ESMTP id B385BB0001B2 for ; Thu, 30 Sep 2021 21:53:19 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id me5-20020a17090b17c500b0019af76b7bb4so7779349pjb.2 for ; Thu, 30 Sep 2021 14:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WNfb7Z+wUBDNis53ymmcIpFweUVDBAEhTaRnY1TJVBw=; b=G9QLs9Qn5P/4JdctPSPNBA4PEalzsnjwlft8+Q81RMPBqVZGcv4i6y+gomgUSyMnnu JeeIOYnbJx+m/3ntVOiNWPjEYmAkksmDmqA1FY+ajgKAa65tACZNQ+nLrnNM+hQbqn5f i1gh5mbRKXaZ7whEDz6y/7MpP0yLPbCh3102O3B8espKozZHWjNnca6PsoYGxqIf695c GZoGLL5rsokg0Wfx2aKGLXt4NPJQar03Z9FbvCVBDdUTpyKZPkxIdBMR/oNMyTmkUd7+ //TSqaH+4hZ92j0LPWS92+2MSaz5DD2X/F2mCLTFimOQtmvQ7Q5WAd78xxZ0j/NygBB+ T8Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WNfb7Z+wUBDNis53ymmcIpFweUVDBAEhTaRnY1TJVBw=; b=AVbOby54CTwLREDmsJqM6pMsqXxfZ1Wp6tGCsbVHFa0kRxUwU+Pgu19HS4URI6iGnl AG5iZV1sGsc1GpY3fPVr0rMUnClI2rJzOAGP4xYey3qln0ce4DdMh0WxVh+L9X0m8bHX x0tHh1QZDYQEL1e1lxXoO8WeGTdSB7BEAbculvp2nwh0/ccFBKJqsNzhP1HceYy58IN5 WbV0hvKWE2ZeltzydwxtBlyglUBx33cu++K/U5AIKq/4nPQQx2TLugOsAfD0Yqzpfn6x KHUiTEgkRn9QgJaOULdoxumXXv44aeuJCSUFZIpjBQzihprB1vZHYnNd2IMJubvF37cf BgBg== X-Gm-Message-State: AOAM532o/tMcGYTUpxEAhK6Xo0SOlZgN8hDTNWqqqBPsOdSHk/Ad8cvj Xanh9BpmUy036ns9pPJt7Qk= X-Google-Smtp-Source: ABdhPJw1QT6Dh2Fy4U+xoL6nuH+kzP+CzA+JWdXmqXlj3S5NHYicwmkhVpyivlcJIlmw3AhsXXFidw== X-Received: by 2002:a17:90a:6649:: with SMTP id f9mr8798856pjm.15.1633038798483; Thu, 30 Sep 2021 14:53:18 -0700 (PDT) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id p17sm5647535pjg.54.2021.09.30.14.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 14:53:17 -0700 (PDT) From: Yang Shi To: naoya.horiguchi@nec.com, hughd@google.com, kirill.shutemov@linux.intel.com, willy@infradead.org, peterx@redhat.com, osalvador@suse.de, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 1/5] mm: hwpoison: remove the unnecessary THP check Date: Thu, 30 Sep 2021 14:53:07 -0700 Message-Id: <20210930215311.240774-2-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210930215311.240774-1-shy828301@gmail.com> References: <20210930215311.240774-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B385BB0001B2 X-Stat-Signature: 5nf58sgf9fabag8fyj5yfryz5dai7k5s Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=G9QLs9Qn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-HE-Tag: 1633038799-824130 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: When handling THP hwpoison checked if the THP is in allocation or free stage since hwpoison may mistreat it as hugetlb page. After commit 415c64c1453a ("mm/memory-failure: split thp earlier in memory error handling") the problem has been fixed, so this check is no longer needed. Remove it. The side effect of the removal is hwpoison may report unsplit THP instead of unknown error for shmem THP. It seems not like a big deal. The following patch depends on this, which fixes shmem THP with hwpoisoned subpage(s) are mapped PMD wrongly. So this patch needs to be backported to -stable as well. Cc: Suggested-by: Naoya Horiguchi Signed-off-by: Yang Shi Acked-by: Naoya Horiguchi --- mm/memory-failure.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 54879c339024..ed28eba50f98 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1147,20 +1147,6 @@ static int __get_hwpoison_page(struct page *page) if (!HWPoisonHandlable(head)) return -EBUSY; - if (PageTransHuge(head)) { - /* - * Non anonymous thp exists only in allocation/free time. We - * can't handle such a case correctly, so let's give it up. - * This should be better than triggering BUG_ON when kernel - * tries to touch the "partially handled" page. - */ - if (!PageAnon(head)) { - pr_err("Memory failure: %#lx: non anonymous thp\n", - page_to_pfn(page)); - return 0; - } - } - if (get_page_unless_zero(head)) { if (head == compound_head(page)) return 1; From patchwork Thu Sep 30 21:53:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12529371 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12EBEC433F5 for ; Thu, 30 Sep 2021 21:53:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B44ED619F8 for ; Thu, 30 Sep 2021 21:53:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B44ED619F8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5B8BF9400D6; Thu, 30 Sep 2021 17:53:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53F7E94003A; Thu, 30 Sep 2021 17:53:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E0FE9400D6; Thu, 30 Sep 2021 17:53:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id 2593894003A for ; Thu, 30 Sep 2021 17:53:22 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DFA558249980 for ; Thu, 30 Sep 2021 21:53:21 +0000 (UTC) X-FDA: 78645591402.13.DD60633 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf12.hostedemail.com (Postfix) with ESMTP id 801471001504 for ; Thu, 30 Sep 2021 21:53:21 +0000 (UTC) Received: by mail-pj1-f53.google.com with SMTP id rm6-20020a17090b3ec600b0019ece2bdd20so5827558pjb.1 for ; Thu, 30 Sep 2021 14:53:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z0G7c4LhSRNiug469gqOVXc04H0fSoJM9Qw97+kE9Ts=; b=eFmxGV3bchn1BICobO1NnIZdYcBe58nEf/iELJBeCWqx+fsviFRsH93Ayp7NAWyNUD jIMSKA1q2vGcPrglfM3speGFsp6hDmYykDb1RMRHRdFkH9j2lu2O7SqGzN7RWu4kR5NS QYuDVPsO+Dqvq/A2zRp+4PHxT2OukGk6zxdVk64iugobN7Mj1Hq+DnJX+ry9iA7ejhIj FHrIzrvu8OzGoyPLmmjUQihNwrSATqDYAxyGN4VRuzymxTtpwZDjR+aT6En0bQVV6SZJ r1vYJlUEABF0LBWD9W7PJg8SNj1DJ7MEPsX6MxaEXdD+30p98DroDTrHqnc7Ro2/7GvE 5h8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z0G7c4LhSRNiug469gqOVXc04H0fSoJM9Qw97+kE9Ts=; b=YQAdkD/+kbD5eVrTUdAD8cUbeMEvxcb0PZPy2MlC8GugqJ5NdDn+uRfcn44ub4W5Jk 2ApQkuuicBuqG5qMqcRzDK+xtJMwNJ0E6G2R1GE19xJhBESwNk/NPXngiKikw4Q78txu N6KNMyhVqjYwWi+LpHMaiECAutx4IOHIi+tIHj1gIdOPLUiOCsM0qyVuyoHfCWHkg9C1 ruuTiFQqnTzEfQp2k0JJY4dIWxcsWeyZLWAHnldxxxvE7JccpL+nn4jlpF+VBuPVTT1K 0lU+rv9ju1G2nWXDYcip/WGb+CayKkr+IhTAaZeNZpvXseZZFEdw+EtJqAB6iZjYJV2y GCng== X-Gm-Message-State: AOAM533J6deVyPSuO/I09eCAMK6XbQRv2JdCevN6RUhvQvYkH9LJeWaz EGhS1WZVJLUWffmveA6oHcI= X-Google-Smtp-Source: ABdhPJwhI2byiEFnBzgAZYP6i3J1aHhDP3W/uCSEfbEU6YqlBJpNfrBIWGov9VljG1ZkgE14gyVrqQ== X-Received: by 2002:a17:902:ab8c:b0:13a:22d1:88d with SMTP id f12-20020a170902ab8c00b0013a22d1088dmr7446550plr.33.1633038800317; Thu, 30 Sep 2021 14:53:20 -0700 (PDT) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id p17sm5647535pjg.54.2021.09.30.14.53.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 14:53:19 -0700 (PDT) From: Yang Shi To: naoya.horiguchi@nec.com, hughd@google.com, kirill.shutemov@linux.intel.com, willy@infradead.org, peterx@redhat.com, osalvador@suse.de, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 2/5] mm: filemap: check if THP has hwpoisoned subpage for PMD page fault Date: Thu, 30 Sep 2021 14:53:08 -0700 Message-Id: <20210930215311.240774-3-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210930215311.240774-1-shy828301@gmail.com> References: <20210930215311.240774-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 801471001504 X-Stat-Signature: edhq7f6561y1chf87nuotaw9nm1xqhdf Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=eFmxGV3b; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-HE-Tag: 1633038801-47921 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: When handling shmem page fault the THP with corrupted subpage could be PMD mapped if certain conditions are satisfied. But kernel is supposed to send SIGBUS when trying to map hwpoisoned page. There are two paths which may do PMD map: fault around and regular fault. Before commit f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths") the thing was even worse in fault around path. The THP could be PMD mapped as long as the VMA fits regardless what subpage is accessed and corrupted. After this commit as long as head page is not corrupted the THP could be PMD mapped. In the regular fault path the THP could be PMD mapped as long as the corrupted page is not accessed and the VMA fits. This loophole could be fixed by iterating every subpage to check if any of them is hwpoisoned or not, but it is somewhat costly in page fault path. So introduce a new page flag called HasHWPoisoned on the first tail page. It indicates the THP has hwpoisoned subpage(s). It is set if any subpage of THP is found hwpoisoned by memory failure and cleared when the THP is freed or split. Fixes: 800d8c63b2e9 ("shmem: add huge pages support") Cc: Suggested-by: Kirill A. Shutemov Signed-off-by: Yang Shi Reported-by: Linux Kernel Functional Testing --- include/linux/page-flags.h | 19 +++++++++++++++++++ mm/filemap.c | 12 ++++++------ mm/huge_memory.c | 2 ++ mm/memory-failure.c | 6 +++++- mm/memory.c | 9 +++++++++ mm/page_alloc.c | 4 +++- 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index a558d67ee86f..a357b41b3057 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -171,6 +171,11 @@ enum pageflags { /* Compound pages. Stored in first tail page's flags */ PG_double_map = PG_workingset, +#ifdef CONFIG_MEMORY_FAILURE + /* Compound pages. Stored in first tail page's flags */ + PG_has_hwpoisoned = PG_mappedtodisk, +#endif + /* non-lru isolated movable page */ PG_isolated = PG_reclaim, @@ -668,6 +673,20 @@ PAGEFLAG_FALSE(DoubleMap) TESTSCFLAG_FALSE(DoubleMap) #endif +#if defined(CONFIG_MEMORY_FAILURE) && defined(CONFIG_TRANSPARENT_HUGEPAGE) +/* + * PageHasPoisoned indicates that at least on subpage is hwpoisoned in the + * compound page. + * + * This flag is set by hwpoison handler. Cleared by THP split or free page. + */ +PAGEFLAG(HasHWPoisoned, has_hwpoisoned, PF_SECOND) + TESTSCFLAG(HasHWPoisoned, has_hwpoisoned, PF_SECOND) +#else +PAGEFLAG_FALSE(HasHWPoisoned) + TESTSCFLAG_FALSE(HasHWPoisoned) +#endif + /* * Check if a page is currently marked HWPoisoned. Note that this check is * best effort only and inherently racy: there is no way to synchronize with diff --git a/mm/filemap.c b/mm/filemap.c index dae481293b5d..2acc2b977f66 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3195,12 +3195,12 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct page *page) } if (pmd_none(*vmf->pmd) && PageTransHuge(page)) { - vm_fault_t ret = do_set_pmd(vmf, page); - if (!ret) { - /* The page is mapped successfully, reference consumed. */ - unlock_page(page); - return true; - } + vm_fault_t ret = do_set_pmd(vmf, page); + if (!ret) { + /* The page is mapped successfully, reference consumed. */ + unlock_page(page); + return true; + } } if (pmd_none(*vmf->pmd)) { diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 5e9ef0fc261e..0574b1613714 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2426,6 +2426,8 @@ static void __split_huge_page(struct page *page, struct list_head *list, /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ lruvec = lock_page_lruvec(head); + ClearPageHasHWPoisoned(head); + for (i = nr - 1; i >= 1; i--) { __split_huge_page_tail(head, i, lruvec, list); /* Some pages can be beyond EOF: drop them from page cache */ diff --git a/mm/memory-failure.c b/mm/memory-failure.c index ed28eba50f98..a79a38374a14 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1148,8 +1148,12 @@ static int __get_hwpoison_page(struct page *page) return -EBUSY; if (get_page_unless_zero(head)) { - if (head == compound_head(page)) + if (head == compound_head(page)) { + if (PageTransHuge(head)) + SetPageHasHWPoisoned(head); + return 1; + } pr_info("Memory failure: %#lx cannot catch tail\n", page_to_pfn(page)); diff --git a/mm/memory.c b/mm/memory.c index adf9b9ef8277..c52be6d6b605 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3906,6 +3906,15 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) if (compound_order(page) != HPAGE_PMD_ORDER) return ret; + /* + * Just backoff if any subpage of a THP is corrupted otherwise + * the corrupted page may mapped by PMD silently to escape the + * check. This kind of THP just can be PTE mapped. Access to + * the corrupted subpage should trigger SIGBUS as expected. + */ + if (unlikely(PageHasHWPoisoned(page))) + return ret; + /* * Archs like ppc64 need additional space to store information * related to pte entry. Use the preallocated table for that. diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b37435c274cf..7f37652f0287 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1312,8 +1312,10 @@ static __always_inline bool free_pages_prepare(struct page *page, VM_BUG_ON_PAGE(compound && compound_order(page) != order, page); - if (compound) + if (compound) { ClearPageDoubleMap(page); + ClearPageHasHWPoisoned(page); + } for (i = 1; i < (1 << order); i++) { if (compound) bad += free_tail_pages_check(page, page + i); From patchwork Thu Sep 30 21:53:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12529373 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FA2DC433F5 for ; Thu, 30 Sep 2021 21:53:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A176861994 for ; Thu, 30 Sep 2021 21:53:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A176861994 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 124889400D7; Thu, 30 Sep 2021 17:53:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2B5994003A; Thu, 30 Sep 2021 17:53:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA8949400D7; Thu, 30 Sep 2021 17:53:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id BBCF694003A for ; Thu, 30 Sep 2021 17:53:23 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 83A303C7BB for ; Thu, 30 Sep 2021 21:53:23 +0000 (UTC) X-FDA: 78645591486.18.7B24601 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf27.hostedemail.com (Postfix) with ESMTP id 445F5700194F for ; Thu, 30 Sep 2021 21:53:23 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id e7so7589414pgk.2 for ; Thu, 30 Sep 2021 14:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EXCBEmsIB/auz3tN4e5eo6JtWLopC6/weoEfTAHMsIc=; b=jDGC0J2eHVHx1JluXNWBbo+5rrEB1cF5gou3XlsEpkt4JCr2YyH4Bvhmm+zxUXmXW2 C/lgXQJdLc0OiDcHwdj+HqXbsRiBqopXiO09KvpLBFBQpYhZyXM9gNKCfvfT8VdW8oou /sItrQmlyQS91bQ+iZaw223BbB/qQqA719j0b9xZlIi/iclClMKxDt6/bs94byaJM6L8 ZNWPgmJX/5QekdlVdCF9Ub6xxuSrIrTtOXYvOSe87lWDvRDzDENO6o8EgCOPHANANeh9 C3m5cq1CH+012LI6qHleF9EhfLKDY/gicPAjiojOdCpkbtvPGg/jwMqU9azBE0XWf7PN WtpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EXCBEmsIB/auz3tN4e5eo6JtWLopC6/weoEfTAHMsIc=; b=Ui0QoD9ci+H6HLAwEiU5zMpHYnamp80132fFQcyGMrLXHPGHJLUnlvKLw/XRO/yuzk a+hkxK0a+FrK2KBNNUKr0kD68zVVdZU0aL3ypR2bceSx7Gf6yRymK/BQowka5IgXNX7e 8giZ05DoT8yAuTlaSmbcjPch34TXI91l1Jf/0cwG1qjEuicHQfIrD86Ez5B5ln/2+uGK bCQ3qA4CPWi+IJ64ciSRb/9XcvldCzD+vyruuScyxXbCn5G0wFLSjmCdwgrd2/W9cVoa nuUlxA5WvgOoA7NxcNOIlf4OMRDkd1Dkx7LMBlr/KawLa0UmZrtYTXCXYaVAWdxUGpk/ u6uQ== X-Gm-Message-State: AOAM530FoPup8eU+yiwL3H+3zK4ddwSENf44WHz21n3YrS8MsZqwW2H4 yHqXJcff2/1y9XYHbcS3ofw= X-Google-Smtp-Source: ABdhPJxdTlIxFMCPUXMZpu8U5cpexygYEibvfa+dl59ZIRm7rFFCQLqy2BGlfvHE+CDD7su2juniXw== X-Received: by 2002:a63:f94c:: with SMTP id q12mr6649824pgk.171.1633038802201; Thu, 30 Sep 2021 14:53:22 -0700 (PDT) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id p17sm5647535pjg.54.2021.09.30.14.53.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 14:53:21 -0700 (PDT) From: Yang Shi To: naoya.horiguchi@nec.com, hughd@google.com, kirill.shutemov@linux.intel.com, willy@infradead.org, peterx@redhat.com, osalvador@suse.de, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 3/5] mm: hwpoison: refactor refcount check handling Date: Thu, 30 Sep 2021 14:53:09 -0700 Message-Id: <20210930215311.240774-4-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210930215311.240774-1-shy828301@gmail.com> References: <20210930215311.240774-1-shy828301@gmail.com> MIME-Version: 1.0 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jDGC0J2e; spf=pass (imf27.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 445F5700194F X-Stat-Signature: 53gttpxe18pjqdiwipzaxionkoct4aft X-HE-Tag: 1633038803-966748 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: Memory failure will report failure if the page still has extra pinned refcount other than from hwpoison after the handler is done. Actually the check is not necessary for all handlers, so move the check into specific handlers. This would make the following keeping shmem page in page cache patch easier. Suggested-by: Naoya Horiguchi Signed-off-by: Naoya Horiguchi Signed-off-by: Yang Shi --- mm/memory-failure.c | 93 +++++++++++++++++++++++++++++++-------------- 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index a79a38374a14..562bcf335bd2 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -806,12 +806,44 @@ static int truncate_error_page(struct page *p, unsigned long pfn, return ret; } +struct page_state { + unsigned long mask; + unsigned long res; + enum mf_action_page_type type; + + /* Callback ->action() has to unlock the relevant page inside it. */ + int (*action)(struct page_state *ps, struct page *p); +}; + +/* + * Return true if page is still referenced by others, otherwise return + * false. + * + * The dec is true when one extra refcount is expected. + */ +static bool has_extra_refcount(struct page_state *ps, struct page *p, + bool dec) +{ + int count = page_count(p) - 1; + + if (dec) + count -= 1; + + if (count > 0) { + pr_err("Memory failure: %#lx: %s still referenced by %d users\n", + page_to_pfn(p), action_page_types[ps->type], count); + return true; + } + + return false; +} + /* * Error hit kernel page. * Do nothing, try to be lucky and not touch this instead. For a few cases we * could be more sophisticated. */ -static int me_kernel(struct page *p, unsigned long pfn) +static int me_kernel(struct page_state *ps, struct page *p) { unlock_page(p); return MF_IGNORED; @@ -820,9 +852,9 @@ static int me_kernel(struct page *p, unsigned long pfn) /* * Page in unknown state. Do nothing. */ -static int me_unknown(struct page *p, unsigned long pfn) +static int me_unknown(struct page_state *ps, struct page *p) { - pr_err("Memory failure: %#lx: Unknown page state\n", pfn); + pr_err("Memory failure: %#lx: Unknown page state\n", page_to_pfn(p)); unlock_page(p); return MF_FAILED; } @@ -830,7 +862,7 @@ static int me_unknown(struct page *p, unsigned long pfn) /* * Clean (or cleaned) page cache page. */ -static int me_pagecache_clean(struct page *p, unsigned long pfn) +static int me_pagecache_clean(struct page_state *ps, struct page *p) { int ret; struct address_space *mapping; @@ -867,9 +899,13 @@ static int me_pagecache_clean(struct page *p, unsigned long pfn) * * Open: to take i_rwsem or not for this? Right now we don't. */ - ret = truncate_error_page(p, pfn, mapping); + ret = truncate_error_page(p, page_to_pfn(p), mapping); out: unlock_page(p); + + if (has_extra_refcount(ps, p, false)) + ret = MF_FAILED; + return ret; } @@ -878,7 +914,7 @@ static int me_pagecache_clean(struct page *p, unsigned long pfn) * Issues: when the error hit a hole page the error is not properly * propagated. */ -static int me_pagecache_dirty(struct page *p, unsigned long pfn) +static int me_pagecache_dirty(struct page_state *ps, struct page *p) { struct address_space *mapping = page_mapping(p); @@ -922,7 +958,7 @@ static int me_pagecache_dirty(struct page *p, unsigned long pfn) mapping_set_error(mapping, -EIO); } - return me_pagecache_clean(p, pfn); + return me_pagecache_clean(ps, p); } /* @@ -944,9 +980,10 @@ static int me_pagecache_dirty(struct page *p, unsigned long pfn) * Clean swap cache pages can be directly isolated. A later page fault will * bring in the known good data from disk. */ -static int me_swapcache_dirty(struct page *p, unsigned long pfn) +static int me_swapcache_dirty(struct page_state *ps, struct page *p) { int ret; + bool dec = false; ClearPageDirty(p); /* Trigger EIO in shmem: */ @@ -954,10 +991,17 @@ static int me_swapcache_dirty(struct page *p, unsigned long pfn) ret = delete_from_lru_cache(p) ? MF_FAILED : MF_DELAYED; unlock_page(p); + + if (ret == MF_DELAYED) + dec = true; + + if (has_extra_refcount(ps, p, dec)) + ret = MF_FAILED; + return ret; } -static int me_swapcache_clean(struct page *p, unsigned long pfn) +static int me_swapcache_clean(struct page_state *ps, struct page *p) { int ret; @@ -965,6 +1009,10 @@ static int me_swapcache_clean(struct page *p, unsigned long pfn) ret = delete_from_lru_cache(p) ? MF_FAILED : MF_RECOVERED; unlock_page(p); + + if (has_extra_refcount(ps, p, false)) + ret = MF_FAILED; + return ret; } @@ -974,7 +1022,7 @@ static int me_swapcache_clean(struct page *p, unsigned long pfn) * - Error on hugepage is contained in hugepage unit (not in raw page unit.) * To narrow down kill region to one page, we need to break up pmd. */ -static int me_huge_page(struct page *p, unsigned long pfn) +static int me_huge_page(struct page_state *ps, struct page *p) { int res; struct page *hpage = compound_head(p); @@ -985,7 +1033,7 @@ static int me_huge_page(struct page *p, unsigned long pfn) mapping = page_mapping(hpage); if (mapping) { - res = truncate_error_page(hpage, pfn, mapping); + res = truncate_error_page(hpage, page_to_pfn(p), mapping); unlock_page(hpage); } else { res = MF_FAILED; @@ -1003,6 +1051,9 @@ static int me_huge_page(struct page *p, unsigned long pfn) } } + if (has_extra_refcount(ps, p, false)) + res = MF_FAILED; + return res; } @@ -1028,14 +1079,7 @@ static int me_huge_page(struct page *p, unsigned long pfn) #define slab (1UL << PG_slab) #define reserved (1UL << PG_reserved) -static struct page_state { - unsigned long mask; - unsigned long res; - enum mf_action_page_type type; - - /* Callback ->action() has to unlock the relevant page inside it. */ - int (*action)(struct page *p, unsigned long pfn); -} error_states[] = { +static struct page_state error_states[] = { { reserved, reserved, MF_MSG_KERNEL, me_kernel }, /* * free pages are specially detected outside this table: @@ -1095,19 +1139,10 @@ static int page_action(struct page_state *ps, struct page *p, unsigned long pfn) { int result; - int count; /* page p should be unlocked after returning from ps->action(). */ - result = ps->action(p, pfn); + result = ps->action(ps, p); - count = page_count(p) - 1; - if (ps->action == me_swapcache_dirty && result == MF_DELAYED) - count--; - if (count > 0) { - pr_err("Memory failure: %#lx: %s still referenced by %d users\n", - pfn, action_page_types[ps->type], count); - result = MF_FAILED; - } action_result(pfn, ps->type, result); /* Could do more checks here if page looks ok */ From patchwork Thu Sep 30 21:53:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12529375 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8240EC43217 for ; Thu, 30 Sep 2021 21:53:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1BBB4619F5 for ; Thu, 30 Sep 2021 21:53:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1BBB4619F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 47D659400D8; Thu, 30 Sep 2021 17:53:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4068494003A; Thu, 30 Sep 2021 17:53:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A6E49400D8; Thu, 30 Sep 2021 17:53:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0233.hostedemail.com [216.40.44.233]) by kanga.kvack.org (Postfix) with ESMTP id 1274E94003A for ; Thu, 30 Sep 2021 17:53:26 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C5BFB3C7A8 for ; Thu, 30 Sep 2021 21:53:25 +0000 (UTC) X-FDA: 78645591570.24.A62EFA1 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf29.hostedemail.com (Postfix) with ESMTP id 84EBE9000676 for ; Thu, 30 Sep 2021 21:53:25 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id me5-20020a17090b17c500b0019af76b7bb4so7779525pjb.2 for ; Thu, 30 Sep 2021 14:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h+26h9Sv4vHl46H8SxokcbKyYQ9NxeiIl/SfRJf9HZw=; b=Djy5drgdl22dEGglF63rH52PgcXQfNUhldeQ/QMjK3qtlY3T3LP8KFviIAyUTa7lIF VEt3AVn6B+Y6pQXf05pOz0Pk5lO3P9ci2211v0ZL1MbGqx7KYy+atFaNVOMoeYjF1rX7 Wv/UDjijd/gUekQXIZFlG1aBcZsPwVrfBf2CR1NyT8Ffb1y0gaebBTgkXyyci0Zpl0qw 7LmYoCC6768fKFYG3j7c3vOWUXobYSzp4jsTjWk8wLZ8Z1bQxJ0CSUiOJrDFHAfdInBp NcQ7FAnpmTmEw6sCeWCVx4Tx+BOVWhyfDvtqiKvTUwlkc/nBDfySTuLEfakDVcQ4hmfB bWtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h+26h9Sv4vHl46H8SxokcbKyYQ9NxeiIl/SfRJf9HZw=; b=QQebnLC4jWz53MbnVYLw2sTSVF2Tb/OCPe/MFiqeCJldAMEx/ha2muVLdeKosbff5e nuoZ+Kkgd9kRBn6K/uWAJs7jeI5E5N1G8M8svMg/5FPmUpyhLtsdssMAVT+gtiFQtOjX sFNJeoU0qJZPExmZ0RGWqA5cNYaokWjQvfassXAd2RYmX5QN5+kuf/gGCGIVyts2OTSQ lOx/7PZyp5VBPt4MkrypY/0NkT7W7sykZgNXGg9Z5tJAe21M6CLrJEB2B9O5uxKlUKtb kzhzusPK0oTYjmZ9ikpxBk2xa98W96m1LcBnr0YJ/+cIfiO8TCjmrCh9qJIYQeFiFAdo +2/w== X-Gm-Message-State: AOAM532ZV3VSWEo+ZETulx95sxS9Wq4dqi49awrasKdXJgk93nyL/5Ic KHHl+DglbCNHmL3fJT+FGtM= X-Google-Smtp-Source: ABdhPJxmGL0nQKDZ15pCq04wQt05mZnD3pmd18L/LfPhVGMA+5VddqOZo4soEdXmWx6MUCZuuPL9iQ== X-Received: by 2002:a17:902:8495:b0:13e:6a01:f5fb with SMTP id c21-20020a170902849500b0013e6a01f5fbmr5810851plo.61.1633038804435; Thu, 30 Sep 2021 14:53:24 -0700 (PDT) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id p17sm5647535pjg.54.2021.09.30.14.53.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 14:53:23 -0700 (PDT) From: Yang Shi To: naoya.horiguchi@nec.com, hughd@google.com, kirill.shutemov@linux.intel.com, willy@infradead.org, peterx@redhat.com, osalvador@suse.de, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 4/5] mm: shmem: don't truncate page if memory failure happens Date: Thu, 30 Sep 2021 14:53:10 -0700 Message-Id: <20210930215311.240774-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210930215311.240774-1-shy828301@gmail.com> References: <20210930215311.240774-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 84EBE9000676 X-Stat-Signature: a5waxiar3p9swzugkot973n94ebn3e4b Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Djy5drgd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-HE-Tag: 1633038805-302862 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 current behavior of memory failure is to truncate the page cache regardless of dirty or clean. If the page is dirty the later access will get the obsolete data from disk without any notification to the users. This may cause silent data loss. It is even worse for shmem since shmem is in-memory filesystem, truncating page cache means discarding data blocks. The later read would return all zero. The right approach is to keep the corrupted page in page cache, any later access would return error for syscalls or SIGBUS for page fault, until the file is truncated, hole punched or removed. The regular storage backed filesystems would be more complicated so this patch is focused on shmem. This also unblock the support for soft offlining shmem THP. Signed-off-by: Yang Shi --- mm/memory-failure.c | 10 +++++++++- mm/shmem.c | 31 +++++++++++++++++++++++++++++-- mm/userfaultfd.c | 5 +++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 562bcf335bd2..176883cd080f 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -57,6 +57,7 @@ #include #include #include +#include #include "internal.h" #include "ras/ras_event.h" @@ -866,6 +867,7 @@ static int me_pagecache_clean(struct page_state *ps, struct page *p) { int ret; struct address_space *mapping; + bool dec; delete_from_lru_cache(p); @@ -894,6 +896,12 @@ static int me_pagecache_clean(struct page_state *ps, struct page *p) goto out; } + /* + * The shmem page is kept in page cache instead of truncating + * so need decrement the refcount from page cache. + */ + dec = shmem_mapping(mapping); + /* * Truncation is a bit tricky. Enable it per file system for now. * @@ -903,7 +911,7 @@ static int me_pagecache_clean(struct page_state *ps, struct page *p) out: unlock_page(p); - if (has_extra_refcount(ps, p, false)) + if (has_extra_refcount(ps, p, dec)) ret = MF_FAILED; return ret; diff --git a/mm/shmem.c b/mm/shmem.c index 88742953532c..75c36b6a405a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2456,6 +2456,7 @@ shmem_write_begin(struct file *file, struct address_space *mapping, struct inode *inode = mapping->host; struct shmem_inode_info *info = SHMEM_I(inode); pgoff_t index = pos >> PAGE_SHIFT; + int ret = 0; /* i_rwsem is held by caller */ if (unlikely(info->seals & (F_SEAL_GROW | @@ -2466,7 +2467,17 @@ shmem_write_begin(struct file *file, struct address_space *mapping, return -EPERM; } - return shmem_getpage(inode, index, pagep, SGP_WRITE); + ret = shmem_getpage(inode, index, pagep, SGP_WRITE); + + if (*pagep) { + if (PageHWPoison(*pagep)) { + unlock_page(*pagep); + put_page(*pagep); + ret = -EIO; + } + } + + return ret; } static int @@ -2555,6 +2566,11 @@ static ssize_t shmem_file_read_iter(struct kiocb *iocb, struct iov_iter *to) unlock_page(page); } + if (page && PageHWPoison(page)) { + error = -EIO; + break; + } + /* * We must evaluate after, since reads (unlike writes) * are called without i_rwsem protection against truncate @@ -3772,6 +3788,13 @@ static void shmem_destroy_inodecache(void) kmem_cache_destroy(shmem_inode_cachep); } +/* Keep the page in page cache instead of truncating it */ +static int shmem_error_remove_page(struct address_space *mapping, + struct page *page) +{ + return 0; +} + const struct address_space_operations shmem_aops = { .writepage = shmem_writepage, .set_page_dirty = __set_page_dirty_no_writeback, @@ -3782,7 +3805,7 @@ const struct address_space_operations shmem_aops = { #ifdef CONFIG_MIGRATION .migratepage = migrate_page, #endif - .error_remove_page = generic_error_remove_page, + .error_remove_page = shmem_error_remove_page, }; EXPORT_SYMBOL(shmem_aops); @@ -4193,6 +4216,10 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, page = ERR_PTR(error); else unlock_page(page); + + if (PageHWPoison(page)) + page = ERR_PTR(-EIO); + return page; #else /* diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 7a9008415534..b688d5327177 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -233,6 +233,11 @@ static int mcontinue_atomic_pte(struct mm_struct *dst_mm, goto out; } + if (PageHWPoison(page)) { + ret = -EIO; + goto out_release; + } + ret = mfill_atomic_install_pte(dst_mm, dst_pmd, dst_vma, dst_addr, page, false, wp_copy); if (ret) From patchwork Thu Sep 30 21:53:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12529377 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 468C7C433F5 for ; Thu, 30 Sep 2021 21:53:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D94B861994 for ; Thu, 30 Sep 2021 21:53:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D94B861994 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 71BD99400D9; Thu, 30 Sep 2021 17:53:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62B8E94003A; Thu, 30 Sep 2021 17:53:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CAB09400D9; Thu, 30 Sep 2021 17:53:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id 3829994003A for ; Thu, 30 Sep 2021 17:53:29 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id F1E913C7C4 for ; Thu, 30 Sep 2021 21:53:28 +0000 (UTC) X-FDA: 78645591696.36.94BE2F5 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf03.hostedemail.com (Postfix) with ESMTP id BE9F830039BF for ; Thu, 30 Sep 2021 21:53:28 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id q23so6187314pfs.9 for ; Thu, 30 Sep 2021 14:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J8Io/l9XN5d+My1zgLHEsMOIQE36whO468vLIFQxbEE=; b=ANoJfsQGyxPOv21Ujus8FInXNyo9gJKRfdN9mHZYYMspzN9e+u4HZTFKb8Mr5xb8m5 DrBbPXDmQBDTGo45qi7mcEQuzzy6GWU96fbeby9IczZUGrFMmTG7R6qr9bzE3yvesSvH w1yT3aryV4lCcSw+vpo693h07Dp1X0qgh2qPndaC8ZYZfIBMSp5VlTLVeAFKuTHbqwi4 b0R2Cy2Z9QjwGAf8s3Ul0463UmU3zCIGeNhz5zlvzydbvHIBCD89IIl3BqUG+s3Og+FY KqLqzA/Bl0rL+Cr6UiOuNK/h5POJNxvZc+ZPASqsnn6XQRgFA8jPy3j5fDAeohbpwIb9 3N8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J8Io/l9XN5d+My1zgLHEsMOIQE36whO468vLIFQxbEE=; b=uiWba3tgjBZBCBQ4/DoBuPCiHJ0Wy7cTHaRJXK+lrY7eb1PZa3thzq8hmCYvZ9wNvz 7RPuuQwcokWIOg3N8opkFuLtXD2SxpEljsJPiNieJ3GiAwl/2Q3NmHxI9wckdFFo7jlz jSgAVM9I9XOkMoE2RUuro3Q/S+gBkCRiMFIyslsxrQhf+yUDyB435L4ws+ojsuSbtlQM lm3JxmAB9LTSfrw0Ss7x1XAQ57D0A+vwaYhOPowBuHLXXi8187yK0h8OQiAlN9nRLkFs b379KoJqJZXXjEKdw8RPpML2HvjnhCzY83dIexPLMbhTzd5Y9alxIAmeb+GOOvlutraK WSBw== X-Gm-Message-State: AOAM533dm8NUUELjT9lF0phig149jFBIIZ4wh5HfQMd5akLsoJ5EXJp5 jfd+nQ20S6SZCrCUrLluHNM= X-Google-Smtp-Source: ABdhPJzmhdjDnYdU4WOSRyEbQBjz17y/lhOpbsBtQ/Uw538tEKw0Phs73G6Y9DttpgyF5zbMMrGyKQ== X-Received: by 2002:a62:6544:0:b0:44b:508b:d05c with SMTP id z65-20020a626544000000b0044b508bd05cmr6698352pfb.56.1633038806584; Thu, 30 Sep 2021 14:53:26 -0700 (PDT) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id p17sm5647535pjg.54.2021.09.30.14.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 14:53:25 -0700 (PDT) From: Yang Shi To: naoya.horiguchi@nec.com, hughd@google.com, kirill.shutemov@linux.intel.com, willy@infradead.org, peterx@redhat.com, osalvador@suse.de, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 5/5] mm: hwpoison: handle non-anonymous THP correctly Date: Thu, 30 Sep 2021 14:53:11 -0700 Message-Id: <20210930215311.240774-6-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210930215311.240774-1-shy828301@gmail.com> References: <20210930215311.240774-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: BE9F830039BF X-Stat-Signature: iqhj1afi8go94eyyjjg9gaqra1kuis5e Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ANoJfsQG; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-HE-Tag: 1633038808-306081 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: Currently hwpoison doesn't handle non-anonymous THP, but since v4.8 THP support for tmpfs and read-only file cache has been added. They could be offlined by split THP, just like anonymous THP. Signed-off-by: Yang Shi Acked-by: Naoya Horiguchi --- mm/memory-failure.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 176883cd080f..88866bf4f4a9 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1447,14 +1447,11 @@ static int identify_page_state(unsigned long pfn, struct page *p, static int try_to_split_thp_page(struct page *page, const char *msg) { lock_page(page); - if (!PageAnon(page) || unlikely(split_huge_page(page))) { + if (unlikely(split_huge_page(page))) { unsigned long pfn = page_to_pfn(page); unlock_page(page); - if (!PageAnon(page)) - pr_info("%s: %#lx: non anonymous thp\n", msg, pfn); - else - pr_info("%s: %#lx: thp split failed\n", msg, pfn); + pr_info("%s: %#lx: thp split failed\n", msg, pfn); put_page(page); return -EBUSY; }