From patchwork Tue Aug 24 22:13:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12455997 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 339BDC4320A for ; Tue, 24 Aug 2021 22:13:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B9CC6611C8 for ; Tue, 24 Aug 2021 22:13:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B9CC6611C8 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 454A88D0001; Tue, 24 Aug 2021 18:13:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 404096B0071; Tue, 24 Aug 2021 18:13:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CB688D0001; Tue, 24 Aug 2021 18:13:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 0F29B6B006C for ; Tue, 24 Aug 2021 18:13:27 -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 AA2951802BE03 for ; Tue, 24 Aug 2021 22:13:26 +0000 (UTC) X-FDA: 78511376412.05.BE03F7D Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf23.hostedemail.com (Postfix) with ESMTP id 73AC090000AC for ; Tue, 24 Aug 2021 22:13:26 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id mq3so15200378pjb.5 for ; Tue, 24 Aug 2021 15:13:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=m2xpgVmxaRDEeNxf6Ahsf4OjLrfQgqJMHlbxtbe8c4g=; b=jiwpbiI6KttoYyaVaxg+Hj9lPlxy5GHsH/mnsSR8g1xY4A1zxKY6QZLq1IB+jACffE pbj2KayjMx1PpbdR9eqsxdhx1vybPkKh0FKmm1LNt9cNNyIY+9CxJ5tGeaA/6nBB0E4y C4d3zadBoR14iOC+VrMA4QzP9Q8pid9gP4ogttqA2kiTtNr5aFq6Jl8xU67E6EPIkeD9 HWmrDetFskp8cmaKf5ah/zL34RIU2iBxge+laO6nu9et8kiY6lL2CUZECchqXHQwsF0F M3ARYfOQ2hLU66gurbvwfXkYcgfMfdIv4Ma15LaUOP4K6vGna2tsSDFOBmbhYAzGR2El aL8g== 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:mime-version :content-transfer-encoding; bh=m2xpgVmxaRDEeNxf6Ahsf4OjLrfQgqJMHlbxtbe8c4g=; b=oDX/1DchmHgAaxRVclDPBVKb/HhuPf+HnJBF5L3Q3AfY/aJ1n+r9zf2p6qT+hH7y6U atZBWpddWQVQhCY9WMAws+R2I7R/R4N6Te6bAfb6QNiM1dZOVqOFiSW521S+uLdOW4Ts 162NGECijP5sCxFC+T0M+aNqxNVsuF/8bPZbenFpHm+/VF7DQBZa0uS/3XDUqOHtu+sP WwPInzXtkIro0jm0CAzPxjOfDgDJQNnhFgo0bcjWwiO+uIBQJLfOC3AP/kpOoyeMBsOL pkkzyseCHQTN6OTLVM7OwmcE0h7E1VuzMyl9brCpeFeqZTgEs8cM/uu6ycWp0IuAyOFc j6zQ== X-Gm-Message-State: AOAM530B6ugHmKSCL9P4hab/K3+eCYdXebsmC5w+SjVTwz6BS+HrvfK4 OdmM/5FSexf9qBdPx7TeAtg= X-Google-Smtp-Source: ABdhPJzqHbdKkYKaqeJm3Grcj/GXM7StHWVOFs6cPBn+YyvlFPsx+ECtqhl32qElb2bkEn4E+R6DVg== X-Received: by 2002:a17:90a:f285:: with SMTP id fs5mr6596427pjb.148.1629843205424; Tue, 24 Aug 2021 15:13:25 -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 z65sm1748123pjj.43.2021.08.24.15.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Aug 2021 15:13:24 -0700 (PDT) From: Yang Shi To: naoya.horiguchi@nec.com, osalvador@suse.de, hughd@google.com, kirill.shutemov@linux.intel.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: hwpoison: deal with page cache THP Date: Tue, 24 Aug 2021 15:13:22 -0700 Message-Id: <20210824221322.7663-1-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=jiwpbiI6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.46 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 73AC090000AC X-Stat-Signature: mmssgfipadhxatso43jdim39mf1ranm8 X-HE-Tag: 1629843206-18123 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 page cache THP, just give up and return error. It is just because the hwpoison THP support was added before page cache THP was supported. Handling page cache THP is simple, they could be offlined by splitting THP, just like anonymous THP. The question is how to distinguish them with allocating and freeing THP which can't be handled by hwpoison properly. It seems page->mapping is a good indicator, both anonymous page and file page have it populated, but it won't be populated until the page is added to rmap or page cache, in other word, instantiated. If page->mapping is populated it is definitely not in allocating or freeing. The later get_page_unless_zero() could serialize against page free paths. Cc: Naoya Horiguchi Cc: Oscar Salvador Cc: Hugh Dickins Cc: "Kirill A. Shutemov" Signed-off-by: Yang Shi --- mm/memory-failure.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 60df8fcd0444..caa0b0c1f5b8 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1149,13 +1149,16 @@ static int __get_hwpoison_page(struct page *page) 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. + * We can't handle allocating or freeing THPs, so let's give + * it up. This should be better than triggering BUG_ON when + * kernel tries to touch the "partially handled" page. + * + * page->mapping won't be initialized until the page is added + * to rmap or page cache. Use this as an indicator for if + * this is an instantiated page. */ - if (!PageAnon(head)) { - pr_err("Memory failure: %#lx: non anonymous thp\n", + if (!head->mapping) { + pr_err("Memory failure: %#lx: non instantiated thp\n", page_to_pfn(page)); return 0; } @@ -1414,12 +1417,12 @@ 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 (!page->mapping || 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); + if (!page->mapping) + pr_info("%s: %#lx: not instantiated thp\n", msg, pfn); else pr_info("%s: %#lx: thp split failed\n", msg, pfn); put_page(page);