From patchwork Tue Sep 14 18:37:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12494427 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 34928C433F5 for ; Tue, 14 Sep 2021 18:37:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D1DA2610E6 for ; Tue, 14 Sep 2021 18:37:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D1DA2610E6 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 F39AF940007; Tue, 14 Sep 2021 14:37:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4B986B0075; Tue, 14 Sep 2021 14:37:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB5576B0078; Tue, 14 Sep 2021 14:37:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id A6F806B0074 for ; Tue, 14 Sep 2021 14:37:40 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4EBE31829794E for ; Tue, 14 Sep 2021 18:37:40 +0000 (UTC) X-FDA: 78587037480.32.29B7F07 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf28.hostedemail.com (Postfix) with ESMTP id 1716890000A1 for ; Tue, 14 Sep 2021 18:37:39 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id me5-20020a17090b17c500b0019af76b7bb4so2247352pjb.2 for ; Tue, 14 Sep 2021 11:37:39 -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=+QEr/go/GTpU7Rjfc4KC/IEXZ29vumfEE1Xw4ha+DtA=; b=hGIOmUo0dI9QRjWTNJ0++NGUaLs7m410h6aj1jfFYUwSQIndsHJqOG2IEB3U0jZQ2y BtZ0bX3w+jdCOyP48P8fz6pcr3NjeIHEtlBCKABnjmU/lgYMEUH3qLrFfjUkzxgUJlDj q5zHi1TzMoWGOypCtlMzg3XmIJyzsQijTr6p8/meHv0tbpENrRiI2A8msEQXD//mbS+w /RkZOqIjTJOb6UIidmw/CTSDIZ+sZUJkBzVSxjAT6yXIbzY4uVwsolmU5i4qu3NlDtpP MXJuRRMAFJsQ6pNyeMpOaD1js3/O6dLMRGsaXuUgCHShkLnuYZj+Fbxr+fkRofNwucUJ qzqQ== 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=+QEr/go/GTpU7Rjfc4KC/IEXZ29vumfEE1Xw4ha+DtA=; b=2w8KHPEnq/Pnbyube+Js1hAhBp092GCQ+4l+i7yu++KxxMazofOVkImg6t3zB7LH/Q i/8vondHgjizOwBaa4Y0osOfIAmJnhhxphkv24EABqfsRTNJqpdGz1VD62VdAfvW632Q FTkpIddJKmD1ugLQ8Ad9WTKHtVYXbldYFr9OBb07w20K6cZMaWNHwSFQ1Ob2X+GgtWCp KBF9jgEoSgW7IeBddDxarOd7arddOdGMPwyrdfweDFyFDqZzCS1P464+sEVTXVadvlD4 0fD4wHaaNtMZ4WIbJ+prxuLUxJxsL4lDqmtYxvq8cXtskH+W0sAlBUGDbctf8XZXho8F yNUQ== X-Gm-Message-State: AOAM531I1Fwb+wb8RNx5w29JQllgJcjwg5Iei60zxfJAmHFprkwwejeQ igVkN9UmU3IcLSz5zhwHk1Q= X-Google-Smtp-Source: ABdhPJwLHyNOLnJIL5N7uW7LsNkxaZra7i3+ERtT/jDHWXVzQaxvTyMOQaAc7gHhlP+YS/zE7S1ZQA== X-Received: by 2002:a17:90a:1991:: with SMTP id 17mr3646240pji.149.1631644659271; Tue, 14 Sep 2021 11:37:39 -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 y3sm12003965pge.44.2021.09.14.11.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 11:37:38 -0700 (PDT) From: Yang Shi To: naoya.horiguchi@nec.com, hughd@google.com, kirill.shutemov@linux.intel.com, willy@infradead.org, 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: [PATCH 4/4] mm: hwpoison: handle non-anonymous THP correctly Date: Tue, 14 Sep 2021 11:37:18 -0700 Message-Id: <20210914183718.4236-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210914183718.4236-1-shy828301@gmail.com> References: <20210914183718.4236-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: z3164kj8xpgq1ppp5kctqzynn83zsyq5 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hGIOmUo0; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 1716890000A1 X-HE-Tag: 1631644659-712870 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 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 3e06cb9d5121..6f72aab8ec4a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1150,13 +1150,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; } @@ -1415,12 +1418,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);