Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1172870iog; Sat, 18 Jun 2022 02:43:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vqJVL0MjTD4kgucQtDsO53GcsYN0jl21d0TsKijnT/mB3xaoVOP9GUU464vQT/yUYZzJG0 X-Received: by 2002:a05:6402:750:b0:435:68bb:8552 with SMTP id p16-20020a056402075000b0043568bb8552mr5078741edy.155.1655545386964; Sat, 18 Jun 2022 02:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655545386; cv=none; d=google.com; s=arc-20160816; b=VmkuDffzFI+Utx2mgKtgdevasxEQyDfqL2JYk66ukFBYcgmEy5OE1xBNZzu3wCvPyb IR2cSviI0/SlUUpDAGE7q33/zXtd6GM3ZFhu08c50EWvwqX9tMWXNbx69BghdNWmlqGg WoB0i5lawgKJaQO0GnodfX+1FKSdw8khmH8lNKTrdb7N90D8RlwxRD0WI+/KpAVVzLYn YJqcEJVralkAgHHeyvABlpveR8OIdgsAtxpiyVyPr5+heW7eqQXChK3sLpHqAsqX/hl1 y4umbbiJhJEfFWo/sVaiI+5LIOfolhEXrIae3xQx0tRThq1NeUMWp+tYV3RsN1L4jMAf MhsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=RhnhKe2CWmp+hvV4UwoZB/kSya2tB/z2z8kzo1Fg6/U=; b=OjenwCbG+oUOm6Wvqnh+SF4HzLrcjZYJOPevvQuYZG39jrOgvDMMzIP8OwP3OfcWM0 NY78LRnp/0zEEmk/Kpj+7rHJxacTjdYlMyeLg62yqmosIfGRl/KGLZySTOhW4sm5tGwD CUWokMtsoNh/5pRkB6+43bFLK3JiioqKK27Ga68vDhSYTejlCKioImcEKDZPcgnW1Ecl pSjH8vTj3+t510d9B2U1mP+ibccaTlJjuxgmyvh8likzsALqVzv1O7/KsCnjkYyLqGSW WQY1lXW9+EqbzyQqKUygWmLDY5vkamZ1DYr5ldwHAuqjfqd6MBURHP6GcCmtX9fE4sUI 6RnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c72-20020a509fce000000b00425ebf85fe4si8079838edf.558.2022.06.18.02.42.40; Sat, 18 Jun 2022 02:43:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbiFRJTD (ORCPT + 99 others); Sat, 18 Jun 2022 05:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229525AbiFRJTC (ORCPT ); Sat, 18 Jun 2022 05:19:02 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C5126110 for ; Sat, 18 Jun 2022 02:19:00 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LQ9HY3JHWzBt0p; Sat, 18 Jun 2022 17:15:37 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 18 Jun 2022 17:18:58 +0800 Received: from [10.174.179.234] (10.174.179.234) 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.2375.24; Sat, 18 Jun 2022 17:18:56 +0800 Message-ID: <4aa8b109-c79b-8da0-db89-85ca128f1049@huawei.com> Date: Sat, 18 Jun 2022 17:18:55 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH -next v5 6/8] arm64: add support for machine check error safe To: Mark Rutland CC: James Morse , Andrew Morton , Thomas Gleixner , "Ingo Molnar" , Borislav Petkov , Robin Murphy , Dave Hansen , "Catalin Marinas" , Will Deacon , "Alexander Viro" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , , "H . Peter Anvin" , , , , , Kefeng Wang , Xie XiuQi , Guohanjun References: <20220528065056.1034168-1-tongtiangen@huawei.com> <20220528065056.1034168-7-tongtiangen@huawei.com> From: Tong Tiangen In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.234] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/6/17 16:55, Mark Rutland 写道: > On Sat, May 28, 2022 at 06:50:54AM +0000, Tong Tiangen wrote: >> During the processing of arm64 kernel hardware memory errors(do_sea()), if >> the errors is consumed in the kernel, the current processing is panic. >> However, it is not optimal. >> >> Take uaccess for example, if the uaccess operation fails due to memory >> error, only the user process will be affected, kill the user process >> and isolate the user page with hardware memory errors is a better choice. >> >> This patch only enable machine error check framework, it add exception >> fixup before kernel panic in do_sea() and only limit the consumption of >> hardware memory errors in kernel mode triggered by user mode processes. >> If fixup successful, panic can be avoided. >> >> Signed-off-by: Tong Tiangen >> --- >> arch/arm64/Kconfig | 1 + >> arch/arm64/include/asm/extable.h | 1 + >> arch/arm64/mm/extable.c | 17 +++++++++++++++++ >> arch/arm64/mm/fault.c | 27 ++++++++++++++++++++++++++- >> 4 files changed, 45 insertions(+), 1 deletion(-) >> >> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig >> index aaeb70358979..a3b12ff0cd7f 100644 >> --- a/arch/arm64/Kconfig >> +++ b/arch/arm64/Kconfig >> @@ -19,6 +19,7 @@ config ARM64 >> select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2 >> select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE >> select ARCH_HAS_CACHE_LINE_SIZE >> + select ARCH_HAS_COPY_MC if ACPI_APEI_GHES >> select ARCH_HAS_CURRENT_STACK_POINTER >> select ARCH_HAS_DEBUG_VIRTUAL >> select ARCH_HAS_DEBUG_VM_PGTABLE >> diff --git a/arch/arm64/include/asm/extable.h b/arch/arm64/include/asm/extable.h >> index 72b0e71cc3de..f80ebd0addfd 100644 >> --- a/arch/arm64/include/asm/extable.h >> +++ b/arch/arm64/include/asm/extable.h >> @@ -46,4 +46,5 @@ bool ex_handler_bpf(const struct exception_table_entry *ex, >> #endif /* !CONFIG_BPF_JIT */ >> >> bool fixup_exception(struct pt_regs *regs); >> +bool fixup_exception_mc(struct pt_regs *regs); >> #endif >> diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c >> index 228d681a8715..c301dcf6335f 100644 >> --- a/arch/arm64/mm/extable.c >> +++ b/arch/arm64/mm/extable.c >> @@ -9,6 +9,7 @@ >> >> #include >> #include >> +#include >> >> static inline unsigned long >> get_ex_fixup(const struct exception_table_entry *ex) >> @@ -76,3 +77,19 @@ bool fixup_exception(struct pt_regs *regs) >> >> BUG(); >> } >> + >> +bool fixup_exception_mc(struct pt_regs *regs) >> +{ >> + const struct exception_table_entry *ex; >> + >> + ex = search_exception_tables(instruction_pointer(regs)); >> + if (!ex) >> + return false; >> + >> + /* >> + * This is not complete, More Machine check safe extable type can >> + * be processed here. >> + */ >> + >> + return false; >> +} >> diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c >> index c5e11768e5c1..b262bd282a89 100644 >> --- a/arch/arm64/mm/fault.c >> +++ b/arch/arm64/mm/fault.c >> @@ -696,6 +696,29 @@ static int do_bad(unsigned long far, unsigned long esr, struct pt_regs *regs) >> return 1; /* "fault" */ >> } >> >> +static bool arm64_do_kernel_sea(unsigned long addr, unsigned int esr, >> + struct pt_regs *regs, int sig, int code) >> +{ >> + if (!IS_ENABLED(CONFIG_ARCH_HAS_COPY_MC)) >> + return false; >> + >> + if (user_mode(regs) || !current->mm) >> + return false; > > What's the `!current->mm` check for? At first, I considered that only user processes have the opportunity to recover when they trigger memory error. But it seems that this restriction is unreasonable. When the kernel thread triggers memory error, it can also be recovered. for instance: https://lore.kernel.org/linux-mm/20220527190731.322722-1-jiaqiyan@google.com/ And i think if(!current->mm) shoud be added below: if(!current->mm) { set_thread_esr(0, esr); arm64_force_sig_fault(...); } return true; > >> + >> + if (apei_claim_sea(regs) < 0) >> + return false; >> + >> + if (!fixup_exception_mc(regs)) >> + return false; > > I thought we still wanted to signal the task in this case? Or do you expect to > add that into `fixup_exception_mc()` ? Yeah, here return false and will signal to task in do_sea() -> arm64_notify_die(). > >> + >> + set_thread_esr(0, esr); > > Why are we not setting the address? Is that deliberate, or an oversight? Here set fault_address to 0, i refer to the logic of arm64_notify_die(). void arm64_notify_die(...) { if (user_mode(regs)) { WARN_ON(regs != current_pt_regs()); current->thread.fault_address = 0; current->thread.fault_code = err; arm64_force_sig_fault(signo, sicode, far, str); } else { die(str, regs, err); } } I don't know exactly why and do you know why arm64_notify_die() did this? :) > >> + >> + arm64_force_sig_fault(sig, code, addr, >> + "Uncorrected hardware memory error in kernel-access\n"); > > I think the wording here is misleading since we don't expect to recover from > accesses to kernel memory, and would be better as something like: > > "Uncorrected memory error on access to user memory\n" OK, agreed. Thanks, Tong. > > Thanks, > Mark. > >> + >> + return true; >> +} >> + >> static int do_sea(unsigned long far, unsigned long esr, struct pt_regs *regs) >> { >> const struct fault_info *inf; >> @@ -721,7 +744,9 @@ static int do_sea(unsigned long far, unsigned long esr, struct pt_regs *regs) >> */ >> siaddr = untagged_addr(far); >> } >> - arm64_notify_die(inf->name, regs, inf->sig, inf->code, siaddr, esr); >> + >> + if (!arm64_do_kernel_sea(siaddr, esr, regs, inf->sig, inf->code)) >> + arm64_notify_die(inf->name, regs, inf->sig, inf->code, siaddr, esr); >> >> return 0; >> } >> -- >> 2.25.1 >> > > .