Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1659226rdd; Thu, 11 Jan 2024 05:57:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIemilXKOdRWDd+UMKcCfiS1dc3Az5LbbpzFMaLQWuUjxs5fb3X7Hh3IQSMbfH/h81cLCb X-Received: by 2002:a05:6a20:f393:b0:19a:30ed:955b with SMTP id qr19-20020a056a20f39300b0019a30ed955bmr835615pzb.68.1704981449511; Thu, 11 Jan 2024 05:57:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704981449; cv=none; d=google.com; s=arc-20160816; b=CptS8xZNtKH6mkiilJtr+mSsSmbHeBLzkWL140G26CEma3c8NZg28mcOQ440RceWMC Y40HkKINcZKkHTJsz+hxPk0JNNuvwim4TqRs6Xx7ZFaO3+Y96gC5hOKiTPZ6Slox+dMV L+YDtM3haVAby3j+x0TUg024XBSqWhDhZkkYgtcsEtHTwNxtDVIZbv0iaoj8+BcDIThF 1v/rSvjl7H1B255C26UX0F4JSXsQhrl07lFWnu5/c9E0LfVnRxInTu9AHoq7Eecqoz5q PF/3B87vfLHxd+2S6QYjgy2gGpj/1p6XRxZTIoTdDti7fOSpGVO4bsUaplPuNhdDqgPU gBGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=XKVffCLzV//oo/2yIDd4XvK33IiZmZFYlL1Wbukj5jw=; fh=fozFfmvOB2OH6LioO+nm/i/X+k2E+hTLuoXcoSn9Ark=; b=Ik2bz07bvnrNDMv2fZm/Wh9FoGNFKQhsEExakDfIGGIxMW6xGmcsQhM16Spw+s2nMw ze7RAJh2ckX/Tpwu8tBgl6HbaYTGwXtEw+LCryZTMt/M2+H3gv2zaim8KyEXQ/mNg6Po 99zLpriTdvD8bCtVr3eA2E4kn3hJBHBVMvMvTkLKwubv2Y8AZCLjLSS5dKVRTXoeCmgb /AZYGvUBy4A58skxgcrVyHSyzus3QIjEpeUWPhICQORMy+V3jUKvB601fdfe8rvTfcwI jkd1W2LwL24luCm5AfvEtG9RLMW6X1cDULkYZnjID+j0g92tm0ALuhdjL71xJkqz39yu fKuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23690-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23690-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id z129-20020a633387000000b0058974d3c296si1178640pgz.815.2024.01.11.05.57.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 05:57:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23690-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23690-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23690-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 13AB8B2499B for ; Thu, 11 Jan 2024 13:56:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1EA03D980; Thu, 11 Jan 2024 13:56:07 +0000 (UTC) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16F823C062; Thu, 11 Jan 2024 13:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4T9mQK3ZqxzNkn4; Thu, 11 Jan 2024 21:55:21 +0800 (CST) Received: from kwepemm600017.china.huawei.com (unknown [7.193.23.234]) by mail.maildlp.com (Postfix) with ESMTPS id 6A93B180077; Thu, 11 Jan 2024 21:56:00 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 11 Jan 2024 21:55:59 +0800 From: Tong Tiangen To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , , Dave Hansen , , "H. Peter Anvin" , Tony Luck , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Naoya Horiguchi CC: , , , Tong Tiangen , Guohanjun Subject: [PATCH -next v4 3/3] x86/mce: set MCE_IN_KERNEL_COPY_MC for DEFAULT_MCE_SAFE exception Date: Thu, 11 Jan 2024 21:55:48 +0800 Message-ID: <20240111135548.3207437-4-tongtiangen@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240111135548.3207437-1-tongtiangen@huawei.com> References: <20240111135548.3207437-1-tongtiangen@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600017.china.huawei.com (7.193.23.234) From: Kefeng Wang If an MCE has happened in kernel space and the kernel can recover, mce.kflags MCE_IN_KERNEL_RECOV will set in error_context(). With the setting of MCE_IN_KERNEL_RECOV, the MCE is handled in do_machine_check(). But due to lack of MCE_IN_KERNEL_COPY_MC, although the kernel won't panic, the corrupted page don't be isolated, new one maybe consume it again, which is not what we expected. In order to avoid above issue, some hwpoison recover process[1][2][3], memory_failure_queue() is called to cope with such unhandled corrupted pages, also there are some other already existed MC-safe copy scenarios, eg, nvdimm, dm-writecache, dax, which don't isolate corrupted pages. The best way to fix them is set MCE_IN_KERNEL_COPY_MC for MC-Safe Copy, then let the core do_machine_check() to isolate corrupted page instead of doing it one-by-one. EX_TYPE_FAULT_MCE_SAFE is used for the FPU. Here, we do not touch the logic of FPU. We only modify the logic of EX_TYPE_DEFAULT_MCE_SAFE which is used in the scenarios described above. [1] commit d302c2398ba2 ("mm, hwpoison: when copy-on-write hits poison, take page offline") [2] commit 1cb9dc4b475c ("mm: hwpoison: support recovery from HugePage copy-on-write faults") [3] commit 6b970599e807 ("mm: hwpoison: support recovery from ksm_might_need_to_copy()") Reviewed-by: Naoya Horiguchi Reviewed-by: Tony Luck Signed-off-by: Kefeng Wang Signed-off-by: Tong Tiangen --- arch/x86/kernel/cpu/mce/severity.c | 4 ++-- mm/ksm.c | 1 - mm/memory.c | 13 ++++--------- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/severity.c index df67a7a13034..b4b1d028cbb3 100644 --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -292,11 +292,11 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs) case EX_TYPE_UACCESS: if (!copy_user) return IN_KERNEL; + fallthrough; + case EX_TYPE_DEFAULT_MCE_SAFE: m->kflags |= MCE_IN_KERNEL_COPY_MC; fallthrough; - case EX_TYPE_FAULT_MCE_SAFE: - case EX_TYPE_DEFAULT_MCE_SAFE: m->kflags |= MCE_IN_KERNEL_RECOV; return IN_KERNEL_RECOV; diff --git a/mm/ksm.c b/mm/ksm.c index 8c001819cf10..ba9d324ea1c6 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3084,7 +3084,6 @@ struct folio *ksm_might_need_to_copy(struct folio *folio, if (copy_mc_user_highpage(folio_page(new_folio, 0), page, addr, vma)) { folio_put(new_folio); - memory_failure_queue(folio_pfn(folio), 0); return ERR_PTR(-EHWPOISON); } folio_set_dirty(new_folio); diff --git a/mm/memory.c b/mm/memory.c index c66af4520958..33d8903ab2af 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2843,10 +2843,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; } @@ -6176,10 +6174,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; } @@ -6196,10 +6192,9 @@ static int copy_subpage(unsigned long addr, int idx, void *arg) struct page *dst = nth_page(copy_arg->dst, idx); struct page *src = nth_page(copy_arg->src, idx); - if (copy_mc_user_highpage(dst, src, addr, copy_arg->vma)) { - memory_failure_queue(page_to_pfn(src), 0); + if (copy_mc_user_highpage(dst, src, addr, copy_arg->vma)) return -EHWPOISON; - } + return 0; } -- 2.25.1