From patchwork Thu Sep 23 03:28:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12511893 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,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 92E52C433FE for ; Thu, 23 Sep 2021 03:28:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2328960F48 for ; Thu, 23 Sep 2021 03:28:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2328960F48 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 BDDED6B006C; Wed, 22 Sep 2021 23:28:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8C3E940007; Wed, 22 Sep 2021 23:28:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7C6E6B0072; Wed, 22 Sep 2021 23:28:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0134.hostedemail.com [216.40.44.134]) by kanga.kvack.org (Postfix) with ESMTP id 996BA6B006C for ; Wed, 22 Sep 2021 23:28:50 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 54E6223E50 for ; Thu, 23 Sep 2021 03:28:50 +0000 (UTC) X-FDA: 78617406420.19.E1E3047 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf17.hostedemail.com (Postfix) with ESMTP id F37F6F000136 for ; Thu, 23 Sep 2021 03:28:49 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id j15so1687970plh.7 for ; Wed, 22 Sep 2021 20:28:49 -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=L73Wo9W9HNFfCQZNH7vnv7PBAtWSuL4iMpzvZ9oV57A=; b=DlhRfef0wm9RQIHDUoMltF6Fl1ae/QjMynQtiQjkBy7RSWyZZ1FQsfpHu1K/OjWrwD lC40P+9KDlG4G/slC65tKyQJl1UjINgwibzZpFm/z4hZjNat7i9MMhdQVe3UN/XaJniU qjMl6k7jJYNjwRv/8+GOjkxJri1K3X3ABCoZtl4TKb/+2ORx5WXlnHHfiTjRmhB93Zt+ omyAIKPUhRg2yVdwIKmdT/QI0F1hTZJgkShXU0Q7pf8TVqZIRDnEpg93c4b6soLHJ1Vt dD7gLYMe3fPzVfZPi6MVhhfEliC9AN8DeH1krSrPtC7yWBlPFS0xKiC4+wCQd0ADE5fm QA7A== 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=L73Wo9W9HNFfCQZNH7vnv7PBAtWSuL4iMpzvZ9oV57A=; b=h+ZplfKp2q1A/Xg6rOiOvzzIOnzosWNqtubnuLwQo48Y51UYz7WmO5P9Y3nPi6Ngmv FqXMEPNZ794eeBgE5T27yOB9LrR3dQfDWm1z9mwr/5Y3g3AvNUMujesiCpuv7lzSU3tv cJ11XGmHhISSGFw8lTLP9kxEQKDId6AvyAMBm2LU4TMUeXERW+/jVpGEHa891Mc3oXfk WBj5ghhKe/keReTeEPIy/PnVAaCwOZp4YVPmdG88bIhf7dXfAa+NyZpnkifBNV1UeR7J XBsbHkt28wS0e/VT6kIoK3yCvcRL6bLz3vANX6htVAWMYeYow1clxH1g3euAmJhjXLkQ 1SsA== X-Gm-Message-State: AOAM531MVB7SH6hTqZkgsANgsIbq5+xFKkCjobE2V/lwFVKUjZsUN/Ni amfcoB8h8CHqUSq+YxdHdpY= X-Google-Smtp-Source: ABdhPJw/Wx92TTkQLGU1qB4d4XVgn8HofDtq+ukKz/VKsQP0awUfmDTEQnQhjCW0uiBL5mjGlOYGeA== X-Received: by 2002:a17:902:b410:b0:13a:3f4a:db58 with SMTP id x16-20020a170902b41000b0013a3f4adb58mr2239986plr.12.1632367729074; Wed, 22 Sep 2021 20:28:49 -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 x8sm3699696pfq.131.2021.09.22.20.28.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 20:28:48 -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: [v2 PATCH 1/5] mm: filemap: check if THP has hwpoisoned subpage for PMD page fault Date: Wed, 22 Sep 2021 20:28:26 -0700 Message-Id: <20210923032830.314328-2-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210923032830.314328-1-shy828301@gmail.com> References: <20210923032830.314328-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: pqsfx8yqtf33xy6sk9w8b69u4sgk8tkk Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DlhRfef0; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: F37F6F000136 X-HE-Tag: 1632367729-125940 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 regulat 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. Cc: Suggested-by: Kirill A. Shutemov Signed-off-by: Yang Shi --- include/linux/page-flags.h | 19 +++++++++++++++++++ mm/filemap.c | 15 +++++++++------ mm/huge_memory.c | 2 ++ mm/memory-failure.c | 4 ++++ mm/memory.c | 9 +++++++++ mm/page_alloc.c | 4 +++- 6 files changed, 46 insertions(+), 7 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..740b7afe159a 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3195,12 +3195,14 @@ 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 == VM_FAULT_FALLBACK) + goto out; + if (!ret) { + /* The page is mapped successfully, reference consumed. */ + unlock_page(page); + return true; + } } if (pmd_none(*vmf->pmd)) { @@ -3220,6 +3222,7 @@ static bool filemap_map_pmd(struct vm_fault *vmf, struct page *page) return true; } +out: return false; } 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 54879c339024..93ae0ce90ab8 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1663,6 +1663,10 @@ int memory_failure(unsigned long pfn, int flags) } orig_head = hpage = compound_head(p); + + if (PageTransHuge(hpage)) + SetPageHasHWPoisoned(orig_head); + num_poisoned_pages_inc(); /* diff --git a/mm/memory.c b/mm/memory.c index 25fc46e87214..738f4e1df81e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3905,6 +3905,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 23 03:28:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12511895 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,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 D60D7C433FE for ; Thu, 23 Sep 2021 03:28:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4F60561038 for ; Thu, 23 Sep 2021 03:28:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4F60561038 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 E7869940008; Wed, 22 Sep 2021 23:28:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB020940007; Wed, 22 Sep 2021 23:28:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC6BD940008; Wed, 22 Sep 2021 23:28:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id BF4CF940007 for ; Wed, 22 Sep 2021 23:28:52 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 81ACE18187FAA for ; Thu, 23 Sep 2021 03:28:52 +0000 (UTC) X-FDA: 78617406504.19.035C55B Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf04.hostedemail.com (Postfix) with ESMTP id 4851650000A8 for ; Thu, 23 Sep 2021 03:28:52 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id k23so3527568pji.0 for ; Wed, 22 Sep 2021 20:28:51 -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=zqxrYRf/N3vvtTE2Bz0uDuFcXVTGzI9mHH/dOg3YkWg=; b=dGu8PwVvBH2tEtOY8PXE8lKZUxvymybflTtF1d3dMa57rTCzQSTRFkSN+VklTDczBj QoU7RTmWuZzc0jTgz5x9fdNtFz+cFpixSUSfvDxiOBxUisFI7+IT1msPD5maJj8YXI9a 1CEWXtK6xK2ASKrbjM6xHNF5d+vgfHlHALxBR/KK9+VcJIAcHlEAQhQ6TOvPotK6tfJ4 bPSU6J/4MG57+rNCnNpe4WaIcpDJjqgPxLOcKry2k7emhjW4rC/CIAQS6+jmzXTT7mRF YPhmDJzBbblOVvkzGwwO4kbqGQCDuhYn9VyuWJp+tcrP5zoZVfDzihRTPsF1cl11bAYO sndg== 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=zqxrYRf/N3vvtTE2Bz0uDuFcXVTGzI9mHH/dOg3YkWg=; b=koBVgpZGw5ec4B6dBE+GkpY6QazRZkHHSSnWHb06GHTIYvGkzFA8j0IziHWNtfb8DS nSSFXFuKbCazLKPhY1K+/vIsJaL2f86Db59J9n7fjM/yqJ8Ck32hU5gpwDXg//g+ehTk /NEk67P9hahy67ABSNfJOmsi7R49YAYetvX/oh9IGZ7QcXjgybj0VMuq2ay10W7LQiIZ K+ush0txpzVhldxLWSFwZZxUatHWLffP6/1eyKejwqCxJynZPyuiz00KY38+jBvZKdd8 y6zeeUo1OXsHmrtnmwI+OQBlEKOxIZgS+NyorxOabTiPftIlJ1fw7gOgwxEqATIbl4dE tKjg== X-Gm-Message-State: AOAM533qGiirIO5B51CUhpBUNFVlp4xIRo3dG2YkEN2AYGoL5s/rqY/i C74LwGQjgPngVRVoNXY+++E= X-Google-Smtp-Source: ABdhPJzFyDBbcHliT5kpE7JCZXWfoNQbHTNIGhMRQTD2/UO6KcYAlSsyRRi5O9njGGrE21cOcx6x6Q== X-Received: by 2002:a17:902:c443:b0:13c:a5e1:caf5 with SMTP id m3-20020a170902c44300b0013ca5e1caf5mr1960864plm.11.1632367731118; Wed, 22 Sep 2021 20:28:51 -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 x8sm3699696pfq.131.2021.09.22.20.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 20:28:50 -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: [v2 PATCH 2/5] mm: hwpoison: refactor refcount check handling Date: Wed, 22 Sep 2021 20:28:27 -0700 Message-Id: <20210923032830.314328-3-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210923032830.314328-1-shy828301@gmail.com> References: <20210923032830.314328-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: pjgt696mtzopfx7p3h7tc9ukq5nnz4on Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=dGu8PwVv; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4851650000A8 X-HE-Tag: 1632367732-808162 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 93ae0ce90ab8..7722197b2b9d 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 23 03:28:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12511897 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,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 681EEC433F5 for ; Thu, 23 Sep 2021 03:28:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 16E5661038 for ; Thu, 23 Sep 2021 03:28:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 16E5661038 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 AF459940009; Wed, 22 Sep 2021 23:28:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A53FB940007; Wed, 22 Sep 2021 23:28:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A70D940009; Wed, 22 Sep 2021 23:28:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0062.hostedemail.com [216.40.44.62]) by kanga.kvack.org (Postfix) with ESMTP id 7EC50940007 for ; Wed, 22 Sep 2021 23:28:54 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 39F35181B10F5 for ; Thu, 23 Sep 2021 03:28:54 +0000 (UTC) X-FDA: 78617406588.05.5160142 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf28.hostedemail.com (Postfix) with ESMTP id 0004790000A2 for ; Thu, 23 Sep 2021 03:28:53 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id q23so4437477pfs.9 for ; Wed, 22 Sep 2021 20:28:53 -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=+h8wrTzJZjjfH7tY2yFLH7NP1QBWy5O30wQKxmJymV4=; b=hqmEEybIRSWPPz61v24K2LWGIel7TrmOjaNcxtI5e/qHjYzx5fQUu5S3j2m3tBkf8S 5RGK1kiA9L9skOJDUnmUm8d7qdCFa0TxUQ1eKyizQsHCBzJOsF03YTJ+IMsH643WzDTs f+zDMKkqCAaglYRIj8kaY+bxy51Ht2CteinUWBX5Dkg4946I4P5CYdA/hInySuupCaaE 69sWCyO8FAprMMDVzqDHukw6mlTSZmr4bgdlULHlPjKy5ecKCEO+vlshczdwXgrSbHOB 02zxr70/2OVkZPtKmMBDSoHMg5XbMcguhQJyLskjCQ69DQLvzE33zX6w3ZDX0R82nxVA lZJA== 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=+h8wrTzJZjjfH7tY2yFLH7NP1QBWy5O30wQKxmJymV4=; b=aIkB8Kn+79YGNZ0cb/gHj+Djw51+yru4K5s+CQ/Dm2WOfiAhT3lZlwz2FzfU2vIi2X SeDQzsZWUQ4vk05YZHvhrhca9ZerTjSZqIrVb48wMBHE5NgcSz1eZglo3atDJO39TROZ nsUTu1DAy64RZJkFwiphXCfLQ4W61e0hmMabne2ygLBBZ9h6CqWv9LSteZYhXbSFxL3A Ka6eYy2PgAMddx6bF3pCfGcfy88L9pvCJNxYg7k17etHNdVaNJO5O8KD9vrVzq2ANew3 WozaGVQXngp/rHvEQZltAXoABzB9xfEmq0RNUHkJNAWpjZF9WYsPt6nsPcxYfOC4Z+kd Ga8w== X-Gm-Message-State: AOAM5306zGlkHV9kqzdmGj6kOjM/OwdccZNVyFcbAZHoQ7Dn3HSt4t86 QSCTVo+1Jx8O4SOj6uaJRHg= X-Google-Smtp-Source: ABdhPJzRlD1d9wNX1dSsFHR58krR8pQ+R+DP9Tv6lP9bp/AFperRcrMpoeFxbYWZgtGuQ8YtnkEkRw== X-Received: by 2002:a62:6246:0:b0:443:852a:2a2e with SMTP id w67-20020a626246000000b00443852a2a2emr2113311pfb.14.1632367733052; Wed, 22 Sep 2021 20:28:53 -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 x8sm3699696pfq.131.2021.09.22.20.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 20:28:52 -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: [v2 PATCH 3/5] mm: hwpoison: remove the unnecessary THP check Date: Wed, 22 Sep 2021 20:28:28 -0700 Message-Id: <20210923032830.314328-4-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210923032830.314328-1-shy828301@gmail.com> References: <20210923032830.314328-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0004790000A2 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hqmEEybI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Stat-Signature: btix1f3timioc8cyjymumm3gqsscypbu X-HE-Tag: 1632367733-172232 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. Suggested-by: Naoya Horiguchi Signed-off-by: Yang Shi --- mm/memory-failure.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 7722197b2b9d..5c7f1c2aabd9 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1182,20 +1182,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 23 03:28:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12511951 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 874D9C433EF for ; Thu, 23 Sep 2021 03:28:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 38CF960F48 for ; Thu, 23 Sep 2021 03:28:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 38CF960F48 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 D63E194000A; Wed, 22 Sep 2021 23:28:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC60C940007; Wed, 22 Sep 2021 23:28:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BA4D94000A; Wed, 22 Sep 2021 23:28:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 7FA84940007 for ; Wed, 22 Sep 2021 23:28:56 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 31D318249980 for ; Thu, 23 Sep 2021 03:28:56 +0000 (UTC) X-FDA: 78617406672.18.15C1A9E Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf19.hostedemail.com (Postfix) with ESMTP id F0980B0000A5 for ; Thu, 23 Sep 2021 03:28:55 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id t20so3477506pju.5 for ; Wed, 22 Sep 2021 20:28:55 -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=yW3mImt34w9s0m+L7odHrGN0UQd73DqRlDM0Drbnbq0=; b=jxB3fQZNu+GeaHBv00hPLH4J/m8FuWBxq/v04Bod2S2KuKkUeYinzZKA33aJn4nV/0 wSt+t1hRMs/h4kDb+9mdTwyuRRAD+ygz6UwNDb2YVRNaVIX0xYPauFfjupDOR7BkF1ft KKUrkPnL5zraJ2V0rKFf66I7fpV3KmP0u1ugczPuK70DnBTch04TH8idfgu0H0KM4QtX OOo/60N9FmBIlyxtlRRCOoNk5Mb9CdO8Hypzjw5z4OtRuWxW325Z+o6MMw8GJlHUgbLo WGpkDum8DJo8Pq7ihgq3wrNBy8ecrS7b27IQt5VTbTA9SI+437QpdIbSoeNSoa9DPOjG paWg== 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=yW3mImt34w9s0m+L7odHrGN0UQd73DqRlDM0Drbnbq0=; b=tlYnPTNzFdHlDtuIPDH3R7XZrcT57RVQe2KZhn09YLf3HPFJUcAsZdZtJT3ssDAMJC e59atLU5dSXdDccL469EjIeMnn7lg7Q7+Tx6ev6Ib6Is5mVccV42ELUAVqriwR1GJFrD AiEi6lOxfSHUxU3Rm5jGSGh2mPWjBShPAwTJtyCAYj8sJpBDtz6Jh9RZiy2W66VlPBRS zkrCCn5+tRQmRr0RebHPAW7QRHOaF8jr2BW+wFuQyX+x3foAU6Dx0o/hjJK+1kNc183x H41BJJgVgtc6Z/jXf0NNFLm2WS+Kfe4Q2QhUHk+iW/+VO136lWSOmXbULsUwJfXPSNwb hNzA== X-Gm-Message-State: AOAM530KHWuIlyVGEKXjS/snVR6IdOwOyb7612d6VghfCO0GDGgPk3Lp f/EUNudk04bFIM2l/PUXRMs= X-Google-Smtp-Source: ABdhPJw+bMrYlauFtFJ2kCM+HSaD4khflzoqdmQXG7VkN29NFSCdbk7y1zN5PWRYVxXfxUjEZApT5A== X-Received: by 2002:a17:90a:1a19:: with SMTP id 25mr15242818pjk.34.1632367735079; Wed, 22 Sep 2021 20:28:55 -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 x8sm3699696pfq.131.2021.09.22.20.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 20:28:54 -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: [v2 PATCH 4/5] mm: shmem: don't truncate page if memory failure happens Date: Wed, 22 Sep 2021 20:28:29 -0700 Message-Id: <20210923032830.314328-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210923032830.314328-1-shy828301@gmail.com> References: <20210923032830.314328-1-shy828301@gmail.com> MIME-Version: 1.0 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jxB3fQZN; spf=pass (imf19.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: iat78ge9fcyhq6ppp8twrxgp1ijj6c9r X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: F0980B0000A5 X-HE-Tag: 1632367735-393111 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 5c7f1c2aabd9..3824bc708e55 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 23 03:28:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12511953 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 7A40CC433F5 for ; Thu, 23 Sep 2021 03:28:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2841D60F48 for ; Thu, 23 Sep 2021 03:28:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2841D60F48 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 BDFBE94000B; Wed, 22 Sep 2021 23:28:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A06BA940007; Wed, 22 Sep 2021 23:28:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80DF594000B; Wed, 22 Sep 2021 23:28:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0039.hostedemail.com [216.40.44.39]) by kanga.kvack.org (Postfix) with ESMTP id 671E4940007 for ; Wed, 22 Sep 2021 23:28:58 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1BC4A2DD75 for ; Thu, 23 Sep 2021 03:28:58 +0000 (UTC) X-FDA: 78617406756.33.3517D43 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf06.hostedemail.com (Postfix) with ESMTP id D2CBA801A89C for ; Thu, 23 Sep 2021 03:28:57 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id y1so3089519plk.10 for ; Wed, 22 Sep 2021 20:28:57 -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=mufzV1rPs7RSEi7IGGVM9toNzAQChP8eST1zCDl+0j0=; b=a3H/PjnC3mHIrU/Dz1HjgLY8ZABe/dn5M0rM4dKdgaq8xHbRoQbRVN4Y+/prn4VQ6G bziLsmnaZCxzFY//q7wpnL6BHO4KtLQ/DO26CDOfbGir8Ujr9jy31E+1xBesSpGk9f/U Hy8K5PF5FuAPn4RHdvQY35SZexZ7NBWMhNtb+N+5QAckXNd8/a0QIewQ5SObeTSqOEH7 zC41oz2uvZRBDKZSbaRLuu/ygh+DcjXqpWP2bq9UeYdR1UDctpUeoIn945q+jOMDN9+3 +ObIc+P7IAslbSVK4+dFUXY/GcdoA+JOLNDwIhVj3PxBh6fmk4Tt1vNT0hqA4j0Ckc7v F7VQ== 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=mufzV1rPs7RSEi7IGGVM9toNzAQChP8eST1zCDl+0j0=; b=eoYdkBKvWmN8Q6oeKzsSJV4LLdW3Qu7g/jC9jp6htgEVgGHZ8WXmNsyEggf9N5E30m 6ysTaRSLcyL6jv50RvUJPjxoJD3QZ4oPCabxfs9Fful/NVwhuRhjJnTajPz215Z+I/st y05LyRWMlQcO4ig362sApnmZEGc5yU4rFs21Lh/KF+l0G8djZ/eTJHhTXaIHGM8XoxOn OdqDGeXzVvX6UxqtVbvroYrJXd9jpoHrCncsecHxU7d68BEq6Jjbfu6EYSrzEv3+Uokc eyu+tgys2ka2PlRdSHEblQl/jTC+0UqRNhMRAdkSVopOu3JdrW76LxUl5POXRgbiJPXF oRWA== X-Gm-Message-State: AOAM531cgdB3w9mApnkduQB7oQlUH5GGchvHwVz0DqPOzYtCtJL6oQbt tQNUzSxlNR2UP2i6MCZZ9nM= X-Google-Smtp-Source: ABdhPJxE/7FYG7IJ37yN6cBJHRQo7cXfobkaQIfJsJ6JoHQKPSdWaAqhKADJ29U4rK2ujWoua3VnuA== X-Received: by 2002:a17:90a:ac05:: with SMTP id o5mr15334262pjq.205.1632367737057; Wed, 22 Sep 2021 20:28:57 -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 x8sm3699696pfq.131.2021.09.22.20.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 20:28:56 -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: [v2 PATCH 5/5] mm: hwpoison: handle non-anonymous THP correctly Date: Wed, 22 Sep 2021 20:28:30 -0700 Message-Id: <20210923032830.314328-6-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210923032830.314328-1-shy828301@gmail.com> References: <20210923032830.314328-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: nxysdutwukomrssi9fgftfsnq7pcchan Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="a3H/PjnC"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: D2CBA801A89C X-HE-Tag: 1632367737-437136 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 --- 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 3824bc708e55..e60224b3a315 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1443,14 +1443,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; }