From patchwork Mon Dec 19 12:00:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tong Tiangen X-Patchwork-Id: 13076503 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 66AABC4332F for ; Mon, 19 Dec 2022 12:00:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA1D68E0005; Mon, 19 Dec 2022 07:00:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C52178E0001; Mon, 19 Dec 2022 07:00:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACBEC8E0005; Mon, 19 Dec 2022 07:00:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9E79A8E0001 for ; Mon, 19 Dec 2022 07:00:49 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 20898AB06F for ; Mon, 19 Dec 2022 12:00:49 +0000 (UTC) X-FDA: 80258914218.30.C14AD1B Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf23.hostedemail.com (Postfix) with ESMTP id 66D93140011 for ; Mon, 19 Dec 2022 12:00:45 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671451247; a=rsa-sha256; cv=none; b=8X99QBrqMKyPaSyLEkCOjX9U7SlVgY9DIEFEJwm+gMxTCZlej1GUNE1f2eXLX8+YOwq80d /hBrwhBr0et4BXCzSaQlEoA+Kj4vmYojVd/xmBnjnME8ko7yojIGcgyKl4jbkK5NxndDFP SuiocdJ4NIYCPnoeukoWivFVFH//qGc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671451247; 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=ad/sRi2N9SHI8XEZyNRnwSsbjdNzJ2wR79CUheGcWdc=; b=CHZlm5VnTFBiH7jzz0ZoW3USamL6W8z5Vz6/JI+qZF7GgiBv1YkCe2lqnIuD41fg4j8jn7 +gDXh53J+cVFrwOITV0zo8YQHl36mkVGbxYmpI4TBUJRSeaYLtBj+fdiU2hSCmpmxqXULa nih/WB3Tu0yPvIA1fcZZ4qPQiWgNqNw= 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 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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 66D93140011 X-Stat-Signature: sezqkr8xjpy7afw5rj4a19ekpz6cmi1s X-HE-Tag: 1671451245-248204 X-HE-Meta: U2FsdGVkX18P+fqKE8xZKgWDGxKFD6KBIL8i9kVtl+Ntkx7wQzs+nJ1KG+puLmLuJnWrVIH9aCG+ksgac5fcogpPHxbr7d7/oWuf2+i4X8aeaQnhOoK+3vYQlCBPflJShtrgS24jVbUdUTtAE3eGLfpzigRGVptYuHvQPYQO2tDaxTdK2cuHBQm5Q6b0Sj8z28QGWevGHSMzDSjiOO1iy6SowgL/+pTEyPViejyVUQ0UkEI88G5Io3q64qWMs6CMMhTaUIRfWxDBMdZavxXZKmJ20k6Xgocuysq30ZQzhkNH4sY/94M/gcQBDf9R1Ky0ySezpi7KBSksF/n/4YD+C3vl1ik1JgjMnpba7fOf+s08mHPL93ftN/IiziLvrJcNBYkHOePDV6lfbfNpHkzUE/1vcm6P5S2AHfbEmE5LAck9bE8REUJEGoLyQZ8ongD77KLize6xbHJ2W35F5F6GaDu4bsdoUkIUKUAPkX4SqAJdEMKolZdmD7JAXVdiQkVPTIMo9st+J5qL755JscrkI6nFKRQ93jg79MxbrDnOkA017mVvYv9rNpjr/pMPocBeS52qaJOMmaAFTFcvfICYIauHyn4Y/GoaDdZPvWEvW4nX6A+ubWSl6FBSpuAL9gvMVCtytKc+kXlLNlRZFMz4GIU/Mpmp0/7XC+PdsNIaWCV96q8gUHdXuPxJX8lLX6zXDSp4gYKI4sX7ZKukl+oPCa7DeqsYdqKpalHrXQq+uHj1JsDNnRccXXrLx56WpE94wwuaHXYz7npgBijrwifXbw7z8RIoyIKpCdqWpoSTLbIWQvwWnINC2nSFNWNmKqHKPjXFVQTRSBONHirM79pgIVO8QJHAEFnPfppQBckvVlcQJOGExsgwtw== 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: 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; }