From patchwork Fri Feb 18 09:40:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: luofei X-Patchwork-Id: 12751161 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 B5C9DC433F5 for ; Fri, 18 Feb 2022 09:41:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0500C6B0074; Fri, 18 Feb 2022 04:41:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F41AD6B0075; Fri, 18 Feb 2022 04:41:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E08FB6B0078; Fri, 18 Feb 2022 04:41:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id CF52F6B0074 for ; Fri, 18 Feb 2022 04:41:45 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 9CBA58062A for ; Fri, 18 Feb 2022 09:41:45 +0000 (UTC) X-FDA: 79155408570.02.B8F446A Received: from spam.unicloud.com (mx.uniclinxens.com [220.194.70.58]) by imf28.hostedemail.com (Postfix) with ESMTP id 45E46C0004 for ; Fri, 18 Feb 2022 09:41:43 +0000 (UTC) Received: from eage.unicloud.com ([220.194.70.35]) by spam.unicloud.com with ESMTP id 21I9f935052082; Fri, 18 Feb 2022 17:41:09 +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; Fri, 18 Feb 2022 17:41:08 +0800 From: luofei To: , , , , , , , CC: , , , , luofei Subject: [PATCH v3 1/2] hw/poison: Avoid the impact of hwpoison_filter() return value on mce handler Date: Fri, 18 Feb 2022 04:40:56 -0500 Message-ID: <20220218094056.2056251-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-mb10.Unicloud.com (10.10.0.6) To zgys-ex-mb09.Unicloud.com (10.10.0.24) X-DNSRBL: X-MAIL: spam.unicloud.com 21I9f935052082 Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of luofei@unicloud.com designates 220.194.70.58 as permitted sender) smtp.mailfrom=luofei@unicloud.com; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 45E46C0004 X-Stat-Signature: n8mesi4uryfc4b9c8h64u3dphh97npjx X-HE-Tag: 1645177303-589581 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 the hwpoison page meets the filter conditions, it should not be regarded as successful memory_failure() processing for mce handler, but should return a value(-EHWPOISON), otherwise mce handler regards the error page has been identified and isolated, which may lead to calling set_mce_nospec() to change page attribute, etc. Here a new MF_MCE__HANDLE flag is introdulced to identify the call from the mce handler and instruct hwpoison_filter() to return -EHWPOISON, other return 0 for compatibility with the hwpoison injector. Signed-off-by: luofei Acked-by: Naoya Horiguchi --- arch/x86/kernel/cpu/mce/core.c | 15 +++++++++------ include/linux/mm.h | 1 + mm/memory-failure.c | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 5818b837fd4d..de29165c65b6 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -612,7 +612,7 @@ static int uc_decode_notifier(struct notifier_block *nb, unsigned long val, return NOTIFY_DONE; pfn = mce->addr >> PAGE_SHIFT; - if (!memory_failure(pfn, 0)) { + if (!memory_failure(pfn, MF_MCE_HANDLE)) { set_mce_nospec(pfn, whole_page(mce)); mce->kflags |= MCE_HANDLED_UC; } @@ -1286,7 +1286,7 @@ static void kill_me_now(struct callback_head *ch) static void kill_me_maybe(struct callback_head *cb) { struct task_struct *p = container_of(cb, struct task_struct, mce_kill_me); - int flags = MF_ACTION_REQUIRED; + int flags = MF_ACTION_REQUIRED | MF_MCE_HANDLE; int ret; p->mce_count = 0; @@ -1303,9 +1303,12 @@ static void kill_me_maybe(struct callback_head *cb) } /* - * -EHWPOISON from memory_failure() means that it already sent SIGBUS - * to the current process with the proper error info, so no need to - * send SIGBUS here again. + * -EHWPOISON from memory_failure() means that memory_failure() did + * not handle the error event for the following reason: + * - SIGBUS has already been sent to the current process with the + * proper error info, or + * - hwpoison_filter() filtered the event, + * so no need to deal with it more. */ if (ret == -EHWPOISON) return; @@ -1320,7 +1323,7 @@ static void kill_me_never(struct callback_head *cb) p->mce_count = 0; pr_err("Kernel accessed poison in user space at %llx\n", p->mce_addr); - if (!memory_failure(p->mce_addr >> PAGE_SHIFT, 0)) + if (!memory_failure(p->mce_addr >> PAGE_SHIFT, MF_MCE_HANDLE)) set_mce_nospec(p->mce_addr >> PAGE_SHIFT, p->mce_whole_page); } diff --git a/include/linux/mm.h b/include/linux/mm.h index 213cc569b192..f4703f948e9a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3188,6 +3188,7 @@ enum mf_flags { MF_MUST_KILL = 1 << 2, MF_SOFT_OFFLINE = 1 << 3, MF_UNPOISON = 1 << 4, + MF_MCE_HANDLE = 1 << 5, }; extern int memory_failure(unsigned long pfn, int flags); extern void memory_failure_queue(unsigned long pfn, int flags); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 97a9ed8f87a9..59d6d939a752 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1526,7 +1526,10 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags) if (TestClearPageHWPoison(head)) num_poisoned_pages_dec(); unlock_page(head); - return 0; + if (flags & MF_MCE_HANDLE) + return -EHWPOISON; + else + return 0; } unlock_page(head); res = MF_FAILED; @@ -1613,7 +1616,10 @@ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, goto out; if (hwpoison_filter(page)) { - rc = 0; + if (flags & MF_MCE_HANDLE) + rc = -EHWPOISON; + else + rc = 0; goto unlock; } @@ -1837,6 +1843,10 @@ int memory_failure(unsigned long pfn, int flags) num_poisoned_pages_dec(); unlock_page(p); put_page(p); + if (flags & MF_MCE_HANDLE) + res = -EHWPOISON; + else + res = 0; goto unlock_mutex; } From patchwork Fri Feb 18 09:42:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: luofei X-Patchwork-Id: 12751162 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 4D673C433F5 for ; Fri, 18 Feb 2022 09:43:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5C9B6B0074; Fri, 18 Feb 2022 04:43:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C0B7D6B0075; Fri, 18 Feb 2022 04:43:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD4596B0078; Fri, 18 Feb 2022 04:43:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id A0FE46B0074 for ; Fri, 18 Feb 2022 04:43:09 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6512195C9B for ; Fri, 18 Feb 2022 09:43:09 +0000 (UTC) X-FDA: 79155412098.18.E084214 Received: from spam.unicloud.com (mx.uniclinxens.com [220.194.70.58]) by imf14.hostedemail.com (Postfix) with ESMTP id 6B748100006 for ; Fri, 18 Feb 2022 09:43:08 +0000 (UTC) Received: from eage.unicloud.com ([220.194.70.35]) by spam.unicloud.com with ESMTP id 21I9gtqS053033; Fri, 18 Feb 2022 17:42:55 +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; Fri, 18 Feb 2022 17:42:54 +0800 From: luofei To: , CC: , , luofei Subject: [PATCH v3 2/2] hw/poison: Add in-use hugepage hwpoison filter judgement Date: Fri, 18 Feb 2022 04:42:42 -0500 Message-ID: <20220218094242.2056346-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-mb06.Unicloud.com (10.10.0.52) To zgys-ex-mb09.Unicloud.com (10.10.0.24) X-DNSRBL: X-MAIL: spam.unicloud.com 21I9gtqS053033 X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of luofei@unicloud.com designates 220.194.70.58 as permitted sender) smtp.mailfrom=luofei@unicloud.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6B748100006 X-Stat-Signature: 4dekuxhgd1pen66cip13j5ah1s6zch57 X-HE-Tag: 1645177388-625759 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 hugepage will be unmaped and the related process may be killed. Signed-off-by: luofei Acked-by: Naoya Horiguchi --- mm/memory-failure.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 59d6d939a752..17a7b0a94ab9 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1548,6 +1548,17 @@ 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(); + put_page(p); + if (flags & MF_MCE_HANDLE) + res = -EHWPOISON; + else + res = 0; + 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