Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1775765rdb; Sun, 4 Feb 2024 00:26:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3XCvnqcKjQV86Wi1PNUvSvhM201QTnciTLlhSVKDUCnKegLCkHU2wRfsLG6NxXDhsSiBg X-Received: by 2002:a2e:a608:0:b0:2d0:a7cc:dd2d with SMTP id v8-20020a2ea608000000b002d0a7ccdd2dmr359544ljp.19.1707035211719; Sun, 04 Feb 2024 00:26:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707035211; cv=pass; d=google.com; s=arc-20160816; b=kXzDMmrUSnUV2XW1wn9JSVXi91CtzUslG5xvR47m4mFc86AHj8qV0GpAstEC+dy0Dq xlQjQq5kYdUKzLSyu3kLoRnp1U76WYKoEUPwpFBgSelHOuTGgyMNwcAmWx/eaoTEb1Of X5/PAVn5+D6VUToZqRSXgyFscM4QVVxmB9pUIpDK0slV+QUt8v49alTiGjCPHOx7/d/s 566QbfjmVail6pG7+luKQreG8fwGV5PVb5A4luY5uK3XF6JDHH+OYLDBUzmJEzDUkE1E OfJN52OqDu1xksN9BwxZ9Xb/Jo/2vLWwEeUrXDFMB1dRYyOrFZISZ/MdyFauOWnI6SYO sKXg== ARC-Message-Signature: i=2; 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=1/hfG/AoTUNScs9lTyBC3Hj5z+BtwGolZlOronaGEbY=; fh=1Hy0Sccgj6MQLQ/3LQacsDkcvgE/dvCkM1ubX3a+p7A=; b=YWH7V26HSU84QhY4rbbbIwj5peYByBS6xjbULd6VpUODNP6V6ajsdOVo/r4zPzinav 1TJlbDEH4BNhEJvfF5gw5lM3yaMmV/mqtbOZo77k+hlDSiKxSBDWoO7e602wGZcMgTF8 IM6MeIkUu7zjxBf58HqGMhzdJpebBIQs4Gwjr1o/pC0Ix42diCjagbL2Kdcy67sUdl5p 5FSVPGPvtOS2hjYZrhBje+JmI7owo3XwK2c0o+ALOphuLcqiNNo/xjqMeZ+KOfzi/1f7 QRZyWypvF84KfghdL0+DKuMB0Ahrp4KRKNLQk+moHNwun88rx8O+0cDedlz7EWylx0Eb UTQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-51521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51521-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com X-Forwarded-Encrypted: i=1; AJvYcCU4LIJbQrnCe+UTwU3cwhvnsvvIjj8Ep29ThEIOPCL/w+/SpCesm9TinMKTDjAaKVytycKPvINrRz2MCFcNfRLBPmbScU4onUoGpM+Ouw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u22-20020a50a416000000b0055ffc80281csi2303903edb.456.2024.02.04.00.26.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 00:26:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-51521-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51521-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 577FA1F237AB for ; Sun, 4 Feb 2024 08:26:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A085C125C8; Sun, 4 Feb 2024 08:26:40 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 75F1C12B6C; Sun, 4 Feb 2024 08:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707035200; cv=none; b=LchtFqPj9NwU9A3AHese6ms0DY+GSBff6e22B3G4xXlf5Vak6gbsm21aXT3cUxey7x8SpftC51NH3+PuxztQsjlIuOXHmOw/svm+G5rZ2YdNd0OqgOhRcEeaRm/SWp4cgR6ftpIKgMYn6DxB1t8AC/PlUbin7eeOmupAsM0mPzI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707035200; c=relaxed/simple; bh=4zXDJkLQztiGlvBIDP7y8d8iYlaOAyzhpsC76GSWYcE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Le25qlFP+rPIsm0yypZKpC762HD3w3ElZxYmlvXQ4HOvFD6FU+LkrGAZGiENeuOP/8FbxR8SClKdjMhvcc48yHCdcUM4eTtcr4AifUqVywkAxNxkYEoC043kinBjint0mf2mjSFdji31HEo78ZAvG0ExkMSXr6DEudMyr4DmjG4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 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.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4TSMyQ0lJtzsWrZ; Sun, 4 Feb 2024 16:25:18 +0800 (CST) Received: from kwepemm600017.china.huawei.com (unknown [7.193.23.234]) by mail.maildlp.com (Postfix) with ESMTPS id 3DF7618001A; Sun, 4 Feb 2024 16:26:35 +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; Sun, 4 Feb 2024 16:26:33 +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 v5 2/3] x86/mce: set MCE_IN_KERNEL_COPYIN for DEFAULT_MCE_SAFE exception Date: Sun, 4 Feb 2024 16:26:26 +0800 Message-ID: <20240204082627.3892816-3-tongtiangen@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240204082627.3892816-1-tongtiangen@huawei.com> References: <20240204082627.3892816-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: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600017.china.huawei.com (7.193.23.234) From: Kefeng Wang Currently, some kernel memory copy scenarios[1][2][3] which use copy_mc_{user_}highpage() to safely abort copy and report 'bytes not copied' when accessing the poisoned source page, a recoverable synchronous exception generated in the processing and the fixup type EX_TYPE_DEFAULT_MCE_SAFE is used to distinguish from other exceptions, and an asynchronous memory_failure_queue() is called to handle memory failure of the source page , but scheduling someone else to handle it at some future point is unpredictable and risky. The better way is immediately deal with it during current context, fortunately, there is already a framework to synchronously call memory_failure(), see kill_me_never() in do_machine_check(), a task work is triggered once MCE_IN_KERNEL_COPYIN is set, in order to fix above issue, setting MCE_IN_KERNEL_COPYIN for EX_TYPE_DEFAULT_MCE_SAFE case too. [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 bca780fa5e57..b2cce1b6c96d 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_COPYIN; 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 8d14ba440929..ee06a8f766ab 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2846,10 +2846,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; } @@ -6179,10 +6177,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; } @@ -6199,10 +6195,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