From patchwork Mon May 8 02:22:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13234003 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 B9D7AC7EE2A for ; Mon, 8 May 2023 02:09:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EDC96B0078; Sun, 7 May 2023 22:09:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 19E166B007D; Sun, 7 May 2023 22:09:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03E9F6B007E; Sun, 7 May 2023 22:09:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E43046B0078 for ; Sun, 7 May 2023 22:09:31 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A96B9C076E for ; Mon, 8 May 2023 02:09:31 +0000 (UTC) X-FDA: 80765456142.05.9D68BD3 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf02.hostedemail.com (Postfix) with ESMTP id 34D5180006 for ; Mon, 8 May 2023 02:09:27 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683511769; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=z9kQ340/YozssMs9GMvc9XLaOYdIKzCFrwb9AwkGXvU=; b=kQeCysOSOOWdAnyozaox996xlt3SHMao8EFUk+9QQmoZCmxk6uR5u7ICzbNUOVBN04R1/3 feQlZ5rvOIa2jErX8p++kiuWYQWKhG3NX3Eslh7JIMCfu12Uz4+rGo/MZAOfos4bAQo5/R 9ktAT67aQHb8l50kQ2h42iXZMqSmExs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683511769; a=rsa-sha256; cv=none; b=NkzOwCcTb44zlGrk3c79uFEZSfIvnXm4rjOtAt0lF+UQzVJtxEH6e+fmp6b38w5lDSbfWv gyAvcudsHwN1hvvYNT4nRAaNXTF1XVpooE2iEKWiUsA8hoVT7/9ATH5qwESMpDuqlZk4Ej yHICC7+Klnsb7xUVhyf6kE7Y20XPdMQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QF4Qy28c7zLntj; Mon, 8 May 2023 10:06:34 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 8 May 2023 10:09:22 +0800 From: Kefeng Wang To: Tony Luck , Borislav Petkov , Naoya Horiguchi CC: Thomas Gleixner , Ingo Molnar , Dave Hansen , , Andrew Morton , , , , , Kefeng Wang Subject: [PATCH] x86/mce: set MCE_IN_KERNEL_COPYIN for all MC-Safe Copy Date: Mon, 8 May 2023 10:22:33 +0800 Message-ID: <20230508022233.13890-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Stat-Signature: iekdhzksk44nmobo84fxad9e4xjus9z6 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 34D5180006 X-Rspam-User: X-HE-Tag: 1683511767-288869 X-HE-Meta: U2FsdGVkX1+u4WHs28G54AiH1Qa1xTaPxXiFlaGdxqOIHNBjOkt44xO5uSziGXFLUMsigq4fKSICDk77jmQztdLbxQqaKrQiv31Fqn+d47DNbRwEBixn6V17bx1A39vmXq84/C8E53Q13viopV9TTuGE11iuFc7EfKDLxTo+9ljt04tmkH3kfKmFmm4x0vD5uF6n+zrF9Nqio8K4G0yjqtl4+E0Rikm49xXf7/jOa4ka87g0S9Lfury0eqEJYpggLR82DDQcuTBxxyi1W5pGn+Lln0qFKtipL48KYTooeEIKQ+yezE38sqUwPiogUL13xf1xtMpGIyXzGZfcBcGX4pqtE2vCKL1V5+BgEdLqdnqVYvv102gcisZISDCYpa/agau28kbQE2Sgx++9fyHPXRURvp9/z/TkgL8/2juRrGlfsJG5O4nUElxb+icnOXY5IcSCtcTVh2mr1GSn0RChY6etnKctCgzuHP/1bnmWuyEad96PWSCtERIg3NZtpVdkHQ6PSosTBs7gx2v2PXK5EMY4hUfhTmY94j/w/Jf19NoVgm/jc8IGtS2GOWsXp2XLHA1iJl7zjiUx3QdSLEQCfKp4Wgb4lEXsjLeT+OrU4ZCLY4TmVMwJ/aLKgYadRJKk39l44CcVCTSf8VN+AYQuxWaJxYuyf/CopLFdJKATBXHdSbyHdjPdiWRF29UmJzyO355ooqcTgJ6NmZu2UrUGNAg7FH3c/k5y04yNJDfqklE7Q4Nl6hakQg0JIyI9pIjMMZ5rMZPuHI8Tf1EeGGIaxtcro80iZ5R8uw42M9DH7RtOGgSVByOQQF8ToVbgT58+D37o1wIZwRubaDu+qhSHKv7UTonm7JymzAzRHsM1c14MBwzv1Ieo/jS60CHC8FMK5WNgz99SX+jKDZKt6L4TcIKY188cbMjiBUXushMaV2OGk3RG15JP4lwilYJI8upjz4eUN03qfjNttZsgmLl ZjEh6sZ2 6i5xeNWguBL4xamq/RR7MOjN2FLwoOaZG62MT5fgI7WMeUoaQ6yqH7PEeHUiOg50j2Pf9Orwy50KRvU8ZfQd2jlAnRC5L1OY3SqO6PrvxD9vtmFED82hOVmWs1t4KGdNNZc0FalEiDLF2TZsoK85AtxkN1JfBDTCmCrCxzvt6oQAi1qJqZZN0+wtCLJuQt8LUnCzuFslx5efhjpJeCkbuPFuzY0dVjsFK6h5Ht5N/itYvKT/zxnTXvv+/9RdX1jna8uO6 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: Both EX_TYPE_FAULT_MCE_SAFE and EX_TYPE_DEFAULT_MCE_SAFE exception fixup types are used to identify fixups which allow in kernel #MC recovery, that is the Machine Check Safe Copy. For now, the MCE_IN_KERNEL_COPYIN flag is only set for EX_TYPE_COPY and EX_TYPE_UACCESS when copy from user, and corrupted page is isolated in this case, for MC-safe copy, memory_failure() is not always called, some places, like __wp_page_copy_user, copy_subpage, copy_user_gigantic_page and ksm_might_need_to_copy manually call memory_failure_queue() to cope with such unhandled error pages, recently coredump hwposion recovery support[1] is asked to do the same thing, and there are some other already existed MC-safe copy scenarios, eg, nvdimm, dm-writecache, dax, which has similar issue. The best way to fix them is set MCE_IN_KERNEL_COPYIN to MCE_SAFE exception, then kill_me_never() will be queued to call memory_failure() in do_machine_check() to isolate corrupted page, which avoid calling memory_failure_queue() after every MC-safe copy return. [1] https://lkml.kernel.org/r/20230417045323.11054-1-wangkefeng.wang@huawei.com Signed-off-by: Kefeng Wang Reviewed-by: Naoya Horiguchi Reviewed-by: Tony Luck --- arch/x86/kernel/cpu/mce/severity.c | 3 +-- mm/ksm.c | 1 - mm/memory.c | 12 +++--------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/severity.c index c4477162c07d..63e94484c5d6 100644 --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -293,12 +293,11 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs) case EX_TYPE_COPY: if (!copy_user) return IN_KERNEL; - m->kflags |= MCE_IN_KERNEL_COPYIN; fallthrough; case EX_TYPE_FAULT_MCE_SAFE: case EX_TYPE_DEFAULT_MCE_SAFE: - m->kflags |= MCE_IN_KERNEL_RECOV; + m->kflags |= MCE_IN_KERNEL_RECOV | MCE_IN_KERNEL_COPYIN; return IN_KERNEL_RECOV; default: diff --git a/mm/ksm.c b/mm/ksm.c index 0156bded3a66..7abdf4892387 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2794,7 +2794,6 @@ struct page *ksm_might_need_to_copy(struct page *page, if (new_page) { if (copy_mc_user_highpage(new_page, page, address, vma)) { put_page(new_page); - memory_failure_queue(page_to_pfn(page), 0); return ERR_PTR(-EHWPOISON); } SetPageDirty(new_page); diff --git a/mm/memory.c b/mm/memory.c index 5e2c6b1fc00e..c0f586257017 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2814,10 +2814,8 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src, unsigned long addr = vmf->address; if (likely(src)) { - if (copy_mc_user_highpage(dst, src, addr, vma)) { - memory_failure_queue(page_to_pfn(src), 0); + if (copy_mc_user_highpage(dst, src, addr, vma)) return -EHWPOISON; - } return 0; } @@ -5852,10 +5850,8 @@ static int copy_user_gigantic_page(struct folio *dst, struct folio *src, cond_resched(); if (copy_mc_user_highpage(dst_page, src_page, - addr + i*PAGE_SIZE, vma)) { - memory_failure_queue(page_to_pfn(src_page), 0); + addr + i*PAGE_SIZE, vma)) return -EHWPOISON; - } } return 0; } @@ -5871,10 +5867,8 @@ static int copy_subpage(unsigned long addr, int idx, void *arg) struct copy_subpage_arg *copy_arg = arg; if (copy_mc_user_highpage(copy_arg->dst + idx, copy_arg->src + idx, - addr, copy_arg->vma)) { - memory_failure_queue(page_to_pfn(copy_arg->src + idx), 0); + addr, copy_arg->vma)) return -EHWPOISON; - } return 0; }