From patchwork Thu Feb 10 08:58:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: luofei X-Patchwork-Id: 12741572 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35308C433EF for ; Thu, 10 Feb 2022 08:59:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 842446B0071; Thu, 10 Feb 2022 03:59:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F24F6B0073; Thu, 10 Feb 2022 03:59:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E0846B0075; Thu, 10 Feb 2022 03:59:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id 5B99E6B0071 for ; Thu, 10 Feb 2022 03:59:03 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2303A98C21 for ; Thu, 10 Feb 2022 08:59:03 +0000 (UTC) X-FDA: 79126270566.30.63ACDBF Received: from spam.unicloud.com (eage.unicloud.com [220.194.70.58]) by imf24.hostedemail.com (Postfix) with ESMTP id A9DC6180002 for ; Thu, 10 Feb 2022 08:59:00 +0000 (UTC) Received: from eage.unicloud.com ([220.194.70.35]) by spam.unicloud.com with ESMTP id 21A8wsoE022471; Thu, 10 Feb 2022 16:58:54 +0800 (GMT-8) (envelope-from luofei@unicloud.com) Received: from localhost.localdomain (10.10.1.7) by zgys-ex-mb09.Unicloud.com (10.10.0.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2375.17; Thu, 10 Feb 2022 16:58:54 +0800 From: luofei To: , CC: , , luofei Subject: [PATCH] mm/hwpoison: In-use hugepage need filter judgement and filter return value should be consistent Date: Thu, 10 Feb 2022 03:58:46 -0500 Message-ID: <20220210085846.902394-1-luofei@unicloud.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Originating-IP: [10.10.1.7] X-ClientProxiedBy: zgys-ex-mb07.Unicloud.com (10.10.0.27) To zgys-ex-mb09.Unicloud.com (10.10.0.24) X-DNSRBL: X-MAIL: spam.unicloud.com 21A8wsoE022471 X-Rspamd-Queue-Id: A9DC6180002 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of luofei@unicloud.com designates 220.194.70.58 as permitted sender) smtp.mailfrom=luofei@unicloud.com; dmarc=none X-Stat-Signature: zpk9h3xmkf7nqi6xzxhqnh47koyku3bo X-Rspamd-Server: rspam04 X-HE-Tag: 1644483540-679020 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: After successfully obtaining the reference count of the huge page, it is still necessary to call hwpoison_filter() to make a filter judgement, otherwise the filter page will be unmaped and the related process may be killed. Also when the huge page meets the filter conditions, it should not be regarded as successful memory_failure() processing, but should return an error code to inform the caller, otherwise the caller regards the error page has been identified and isolated, which may lead to calling set_mce_nospec() to change page attribute. Meanwhile, when calling hwpoison_filter() to determine that a page needs to be filtered, it is better to keep the same EBUSY return value, so that the caller can recognize that memory_failure() did not successfully process the error page. Signed-off-by: luofei --- mm/hwpoison-inject.c | 2 +- mm/memory-failure.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mm/hwpoison-inject.c b/mm/hwpoison-inject.c index aff4d27ec235..4ecd77cd1ded 100644 --- a/mm/hwpoison-inject.c +++ b/mm/hwpoison-inject.c @@ -44,7 +44,7 @@ static int hwpoison_inject(void *data, u64 val) */ err = hwpoison_filter(hpage); if (err) - return 0; + return -EBUSY; inject: pr_info("Injecting memory failure at pfn %#lx\n", pfn); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 97a9ed8f87a9..acf97fb2659a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1526,7 +1526,7 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags) if (TestClearPageHWPoison(head)) num_poisoned_pages_dec(); unlock_page(head); - return 0; + return -EBUSY; } unlock_page(head); res = MF_FAILED; @@ -1545,6 +1545,13 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags) lock_page(head); page_flags = head->flags; + if (hwpoison_filter(p)) { + if (TestClearPageHWPoison(head)) + num_poisoned_pages_dec(); + unlock_page(head); + res = -EBUSY + goto out; + } /* * TODO: hwpoison for pud-sized hugetlb doesn't work right now, so * simply disable it. In order to make it work properly, we need @@ -1613,7 +1620,7 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, goto out; if (hwpoison_filter(page)) { - rc = 0; + rc = -EBUSY; goto unlock; } @@ -1837,6 +1844,7 @@ int memory_failure(unsigned long pfn, int flags) num_poisoned_pages_dec(); unlock_page(p); put_page(p); + res = -EBUSY; goto unlock_mutex; }