From patchwork Mon Jan 29 13:46:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tong Tiangen X-Patchwork-Id: 13535674 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 53ADEC47DDB for ; Mon, 29 Jan 2024 13:47:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 65F5E6B00A5; Mon, 29 Jan 2024 08:47:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 60C826B00A7; Mon, 29 Jan 2024 08:47:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C3876B00A8; Mon, 29 Jan 2024 08:47:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 28AAD6B00A5 for ; Mon, 29 Jan 2024 08:47:08 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 06A3D1C0B25 for ; Mon, 29 Jan 2024 13:47:08 +0000 (UTC) X-FDA: 81732474936.01.0D2440A Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf09.hostedemail.com (Postfix) with ESMTP id 49381140023 for ; Mon, 29 Jan 2024 13:47:04 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.189 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=1706536026; 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=Sze+W7/VXzN9lUi+wiYHH7plMoEL8Mu63vaCr1k3jh4=; b=Y+3gmvrQXHxpxwvy0PkM+E9y3YemR1Ctsur1Y8gNvNvP5NZEskpGJoommxhQUbhnAjgY39 jV/wPixrDMpFUrwu/7+hesJa5hwLEM/b0P6r4QnGHtTNpM3hQvmkMbeC85pOyqYRq+/upr zfvQf2VeYOUZ7caxEewDSRHN9Eii/aM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706536026; a=rsa-sha256; cv=none; b=2Uu97pKImfUOFRsIsHCzoid8oaxSssSsIEXTT67iGHFx1hrFmycdEXaGiGesIFvFIucyYC UC71EeP6sOAXaEhY17ZPhNOgwzZLsM3kzSQeUijkWmBkj/49i1wHsxqPBXbYOhlRd5pRmO ZGNYGCWseBTLmGlKy8B3v4zbRsuN2wo= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4TNqMF3pN7zNkcY; Mon, 29 Jan 2024 21:46:01 +0800 (CST) Received: from kwepemm600017.china.huawei.com (unknown [7.193.23.234]) by mail.maildlp.com (Postfix) with ESMTPS id DA46B18005E; Mon, 29 Jan 2024 21:46:59 +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; Mon, 29 Jan 2024 21:46:57 +0800 From: Tong Tiangen To: Catalin Marinas , Will Deacon , Mark Rutland , James Morse , Robin Murphy , Andrey Ryabinin , Alexander Potapenko , Alexander Viro , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Aneesh Kumar K.V , "Naveen N. Rao" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" CC: , , , , , Tong Tiangen , , Guohanjun Subject: [PATCH v10 2/6] arm64: add support for machine check error safe Date: Mon, 29 Jan 2024 21:46:48 +0800 Message-ID: <20240129134652.4004931-3-tongtiangen@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240129134652.4004931-1-tongtiangen@huawei.com> References: <20240129134652.4004931-1-tongtiangen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600017.china.huawei.com (7.193.23.234) X-Rspamd-Queue-Id: 49381140023 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5mu3pw643hbqj8ykzddhfquheik1oiax X-HE-Tag: 1706536024-598131 X-HE-Meta: U2FsdGVkX18C8NXTm+0nY3G7lQk5dGf2DSPzyMqP2xMbbOUeQK1CXr3i+rwV5ogYkZbNULBgZrjMgEShT6A+WEbT3UgDzYa+eQcokupjPsIQLJ2ymv/qeU4bFH+FWV6h+wMGvVhHHcSFoT6L74M2snayoUIwEWwbpTSOpsS+Qxus9TypM6jct+tGMRkVHvzJlKeho5G/pEVzzhx8neqzmhDwmEuDb0Wk1KMBraBNoyoGAcDpwYnb+R0eGdBh+uwEUWuulyPI7+xA774msajOdHOrBEHyVDjvrE6T1gsgOyn3mLJuq03yceoNEPsU9otl4n0fHykRnd892wmepTDwJ6UZxt1h+nC4xeStGttwto+iJabepVbLJeZRqOq04bkEQOY26m3ingU3Pq/7GmOf6rwJiIiujWso0vDxZuUzY8Y0A8QwMaqbyr/gaTBZe3NL+J/Smz7OMXlNRf+hk7jqatDfOFxSHURDEfWk2hOl5JkBAIZXoYm5qHebcfGCOUPP2TYFT9IM9FYSge8tSR5gStik6UKULaWJJhTe4R6Yzldrc82oOOL7jjaQMtAL+XhdwADNnGst2dhgwMUTjFsxBFR/MbDWSvuz/yFaslY6UgRD78s+wkLz+OqYiPkvVzw9BTERj3uyw+QgvBdc2cHcrMKOZrNLttDOod1ANaqxDRZXFuRq5e0WzEEKEYptFmzMl2XuZDO+Pk8pgYabqsV1V7NkzrbOR5nTiccg/1dRlLgrlqoQ8HB85VxcEOtgIYADNaprklDrAB9KpjdFRrEY40ai8Rj93TCdMGiFrK8hQXqpslVcaTwPVNgyDkpKwHrulkE9j86J8Ed3wMTuWOqhD/2hpJAVsd/lyiPBXmvXBA9IyE837kDNyvXh6ZJK4ZIAzU4+7tID10gx/2BL7y3RooPAIWhO74xv8Hzak+B7igLizinSbb2bZaYHD768FVzgOlepsIgnVduzkU1ki4q WIjFJo/L QSLKAWmevQ1P3D+lItPA3ia7IILnapyAtzc0uaeO+wNO91Y3XkDzWcJGlHy2QGi3cVXIaEF0ZFPbxArL1vEX9wa4HjEoJSh5eDQ/n2LwV1uTsfl5q58CUC9eBEqDxo0wz5XgFdZuew5L2NToncesoHxZz/4UvOzivjGto/mSF7j1vcUgr9NghQxno+XY9Iu2q53Bb+2Dn2EzRVHp2fpkt5yqV9fVc3kxjj77uOJ950Hchp5qjAhSuaM8AcHK3uxK1RCnP 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: List-Subscribe: List-Unsubscribe: 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 aa7c1d435139..2cc34b5e7abb 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 55f6455a8284..312932dc100b 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -730,6 +730,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; @@ -755,7 +780,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; }