From patchwork Mon May 8 01:44:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tong Tiangen X-Patchwork-Id: 13233994 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 8C729C7EE26 for ; Mon, 8 May 2023 01:45:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3F526B007E; Sun, 7 May 2023 21:45:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC8266B0080; Sun, 7 May 2023 21:45:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8E216B0081; Sun, 7 May 2023 21:45:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CABCD6B007E for ; Sun, 7 May 2023 21:45:02 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 97C4212032B for ; Mon, 8 May 2023 01:45:02 +0000 (UTC) X-FDA: 80765394444.20.A88A1FE Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf16.hostedemail.com (Postfix) with ESMTP id D7D55180003 for ; Mon, 8 May 2023 01:44:59 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683510300; 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:in-reply-to:references:references; bh=QjuZkIP7hYnIzRYJNO8BhtA6qSDslyffDnsR7IPtQX4=; b=oNf/4qpvyFkKKGuWJN8NqHK2v7CThdOMSFn0ugKZkyom55zAyUA9KuzgNtLqub8iNg+t+5 wsjXXI9KeAoeyhxtUqmubVY/muU1MrDox/9WGEEUbY5xNMCOCJR94VCmkb3Oxp9FY5wfLq UZoyhi+3Ify6jlh0lvX+elLN6vPIXss= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683510300; a=rsa-sha256; cv=none; b=fDdFk7WW7aoUfxjAcUpXELIwJ20cWW7ZCkhBqyMbEbjfKAZHj9gf3+40/VeRZDzq2OXVey pgPYcLxFgI/up3jD0D2kgwiuqq+Ja9GEpAVY9yCcJljr46WzR/SoQKjkk+xJleSkmLqzRl kHaWGjm9sBJHrKi/Ij+hyLocJXkkn0g= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from kwepemm600017.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4QF3sD5MZFz18KyN; Mon, 8 May 2023 09:40:48 +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.23; Mon, 8 May 2023 09:44:55 +0800 From: Tong Tiangen To: Catalin Marinas , Mark Rutland , James Morse , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Robin Murphy , Dave Hansen , Will Deacon , Alexander Viro , , "H . Peter Anvin" CC: , , , Kefeng Wang , Guohanjun , Xie XiuQi , Tong Tiangen Subject: [PATCH -next v9 2/5] arm64: add support for machine check error safe Date: Mon, 8 May 2023 09:44:33 +0800 Message-ID: <20230508014436.198717-3-tongtiangen@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230508014436.198717-1-tongtiangen@huawei.com> References: <20230508014436.198717-1-tongtiangen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D7D55180003 X-Stat-Signature: eb8ij7jxwe96nbor3hbs7bhtdmjz11dm X-Rspam-User: X-HE-Tag: 1683510299-412660 X-HE-Meta: U2FsdGVkX18PA0Gvm1iP/OriZndIyuIV67lbD3OtMVmTR2VcMik89lTEua4B437Uno4xk4WOrKgGhK0XKCtNP21qqJTUkwF6LqgjwtgrmUNQfUOAgbpHrqtMLCfRF3yO9N/7RKCisc+1EHJqZrjlAsfdP+JipMQngcliEzjsRgg0r2AR4EZFOLVh6rWsFgb9yJn7kEkQ+IbiRG2uQvTRy1kXemLmk7a2liEeAyHjReGC4UyIM0FI9WNxL0IsF83RPbq1h8urSSXEdpgVNidfOcS/7YuWh+59z1bSR6sszdpFkfc6qlM1AbvxeDAfwLSVUikW4e6AlH3+HgS/b6FW1bCUQ5tKvT1J52jqs987nIkC2eONI4vVo3qQu1gf1Cv1wAeax6h9oDiU8vMB+zYgEAIZSdfUoeH2CX0TYWq3YEfV1w/lG3Fove3asD8uUd8BHjucM7VQyW7BjUgKYTuOb9F4nN5Kl8f+Hgn3ivm+wpApmkUDWdc80wRMLdVj6oCaj+IOfn5G7B08cY9FbYUNYVhQ+/Z3wp1dFd9GtkT2gpifyE4jmYdeFCrejYh3kEwe2zN7+UWFOG/nR4NqQB10Dzl+eFhLnhCIrSgYGGXyXONxLLH/sbulQhR+uJgXgRw1/RTPklrJ3SgxNC7PQDMpGiPW06VDRWEwwu+FmDIKXooGDs03c5s74r9yo0sLMdVUGcBPa+1kpMoK41osU0wu/dRK6RRCmfsw/5uGK+0I/vwUk4PK/zaYZdFQ6gABv5AklZD0PeJjZSNGx7ba1QruxvKvlQCHzUhzDsTEFvGZUlM+P8f+dhNjxLn99Fsd7TS+XRHzFtni+471gDvdsRdD/pT8jCjQSA32fgVpRB+6P44az3vmiKihFG+ZicFz6RXT3q/F/7xDTB+Qm6CcH/8j5ufLyiFLhoDSnO6xM3GDHwpoT8PbQZRwnAu+tsoSh4T9o0YK/ju6nY5Oa6BiuRw GCJd6lfh UCPar9hyE7hddQURURoqs3b8CD+5SZ8eeIUx+H9w8B/6WPf1y1wRPeIoPDbOuL2gDtDCX3ZfGWP9s3yhsSQlEYMr21yFmQJV9T/QL3eQP6oXXEXjx/GmLx1R4XM1/NPtZ380cy46re0KmBJrlfWUiFJLz49n5bBK/dx6zDWsIo5zC0Bzr7X4d1Di0iA== 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: For the arm64 kernel, when it processes hardware memory errors for synchronize notifications(do_sea()), if the errors is consumed within 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. Killing the user process and isolating the corrupt page is a better choice. This patch only enable machine error check framework and adds an exception fixup before the 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 b1201d25a8a4..730b815acfca 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 9e0db5c387e3..4d490d820f1a 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -749,6 +749,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; @@ -774,7 +799,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; }