Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp2399737rwj; Mon, 19 Dec 2022 04:10:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXujPMitfX6TJO0j37t5jBFCWq9yggOIWw18eTZjr9xgQ0DBlXlvReydvDLRvsAfqENoKuT/ X-Received: by 2002:a05:6a20:7daa:b0:aa:23e1:f8ce with SMTP id v42-20020a056a207daa00b000aa23e1f8cemr13047276pzj.59.1671451850796; Mon, 19 Dec 2022 04:10:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671451850; cv=none; d=google.com; s=arc-20160816; b=ZqEvI0/okf6S8Fl3NMZp1siye2f8+japJddZkEjT/8yif+yaU+R6R2+sdoecRUqwrO qCxYMj3MNTbKSwmJy8FKXd9jObkrHI92pU3kCxgD6LqE1barLer+iN436w7C8g6KPlbX /jHWsMfUS0kAln3TxJh51vz6jsNXip4TFcjMiht5k49iNKrfpacUxfL3JGmsdpH83hwT 1UvjbSvqwcekLR79vCrZjFGPbMO5fD6ej9nbfGEU19mwN4rm4UTyxzMOX3QV5WCPkGai p9+NXvgNC5bZuyAs+FV9sszKoME6X6CKWrGZ1pknf8exgujiRjRLRXn/DAycOWwbI8iu p+xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ad/sRi2N9SHI8XEZyNRnwSsbjdNzJ2wR79CUheGcWdc=; b=NIedMSFfykS6yoAquOyOiv0IIUuxorMUPXMH6hPvY2UfOCA2X7YTWn/Z3kPeKAmyul bqulGGpLhZFbUm6dv7r6K3PgqaUIVw4erOFcc+tMAFHEiqhnlzAroQsNfns65glM+T+w mj4lZOp1laEzXTVgcxwIFmVWqyeH3biwuCZ5zgUHgzSd59xSwMr66yltEnEO9GaFAuQ/ ig73E39uuGniw/63M7YlomX1svVKyZKzVZjCKbZEkmWKaeRebapz8mqWDttrWquWR/P+ 5idvwTM5vRwy1W6Z9PWb4+C8ntiaJZPNqSKTiNZI2gO1gs6T7hPL6JRsB5/StCFhHuqY lk6A== 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 e14-20020a63d94e000000b00477cfa54894si10146113pgj.300.2022.12.19.04.10.41; Mon, 19 Dec 2022 04:10:50 -0800 (PST) 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 S232017AbiLSMCc (ORCPT + 70 others); Mon, 19 Dec 2022 07:02:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231812AbiLSMBZ (ORCPT ); Mon, 19 Dec 2022 07:01:25 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D453BCEA for ; Mon, 19 Dec 2022 04:00:44 -0800 (PST) Received: from kwepemm600017.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NbJ841w3SzqT1r; Mon, 19 Dec 2022 19:56:20 +0800 (CST) Received: from ubuntu.huawei.com (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.2375.34; Mon, 19 Dec 2022 20:00:41 +0800 From: Tong Tiangen To: Mark Rutland , James Morse , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Robin Murphy , Dave Hansen , Catalin Marinas , Will Deacon , Alexander Viro , , "H . Peter Anvin" CC: , , , Kefeng Wang , Guohanjun , Xie XiuQi , Tong Tiangen Subject: [PATCH -next v8 2/4] arm64: add support for machine check error safe Date: Mon, 19 Dec 2022 12:00:06 +0000 Message-ID: <20221219120008.3818828-3-tongtiangen@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221219120008.3818828-1-tongtiangen@huawei.com> References: <20221219120008.3818828-1-tongtiangen@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.125] 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=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 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(). Signed-off-by: Tong Tiangen --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/extable.h | 1 + arch/arm64/mm/extable.c | 16 ++++++++++++++++ arch/arm64/mm/fault.c | 29 ++++++++++++++++++++++++++++- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 03934808b2ed..cb0adee2eb8f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -20,6 +20,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..478e639f8680 100644 --- a/arch/arm64/mm/extable.c +++ b/arch/arm64/mm/extable.c @@ -76,3 +76,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 1d832c92cbe8..3021047873d6 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -713,6 +713,31 @@ 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)) + return false; + + if (apei_claim_sea(regs) < 0) + return false; + + if (!fixup_exception_mc(regs)) + return false; + + if (current->flags & PF_KTHREAD) + return true; + + set_thread_esr(0, esr); + arm64_force_sig_fault(sig, code, addr, + "Uncorrected memory error on access to user memory\n"); + + return true; +} + static int do_sea(unsigned long far, unsigned long esr, struct pt_regs *regs) { const struct fault_info *inf; @@ -738,7 +763,9 @@ static int do_sea(unsigned long far, unsigned long esr, struct pt_regs *regs) */ siaddr = untagged_addr(current->mm, 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