From patchwork Mon Dec 19 12:00:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tong Tiangen X-Patchwork-Id: 13076502 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 4833DC10F1B for ; Mon, 19 Dec 2022 12:00:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A80418E0003; Mon, 19 Dec 2022 07:00:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A2FF58E0001; Mon, 19 Dec 2022 07:00:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F6B28E0003; Mon, 19 Dec 2022 07:00:46 -0500 (EST) 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 803B38E0001 for ; Mon, 19 Dec 2022 07:00:46 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2BE10160B15 for ; Mon, 19 Dec 2022 12:00:46 +0000 (UTC) X-FDA: 80258914092.04.A882C75 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf12.hostedemail.com (Postfix) with ESMTP id DFFC14000D for ; Mon, 19 Dec 2022 12:00:42 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.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=1671451243; 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=WNhk9CFgEgukzoHbRsO98T7cEkYKNoKzrzUU/0C7L5o=; b=x1vFpC4Y7tkT89zcwQFpV5lEc/+l14JetPK+n6YJ61A/0Jz3c6ugaqSFetafXYRR1fQNGf wyyHs+P1uhRQj3dhF1J0YZiLJ7jxFnTX1UbLX9M4teyNy1oLogulA6vM30YFvFW7cU3XmM J7ByJmc7WDxc4xbVPNAFlP+ptm+gzZU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.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=1671451243; a=rsa-sha256; cv=none; b=SFcHir68q7M4KQ5FxJT72wc5nZHWzavxqlqbqzsizca4NkADW3NHyLRwTTQxRZuKeXFT+P 9Od4bxi3+p9WvKHzS1TEd8pFKkWkRtFKdme3icy/kzSx/GLof7kMlLPi6LeRx3YuoemuYY a7fHszRNUl9i+keaONZouNivGPaksHs= Received: from kwepemm600017.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NbJ8024v8zqT9Q; Mon, 19 Dec 2022 19:56:16 +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:37 +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 1/4] uaccess: add generic fallback version of copy_mc_to_user() Date: Mon, 19 Dec 2022 12:00:05 +0000 Message-ID: <20221219120008.3818828-2-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: rspam04 X-Rspamd-Queue-Id: DFFC14000D X-Stat-Signature: kqypn7n3hq8gursxpmsgqujg6j6y4twb X-HE-Tag: 1671451242-801910 X-HE-Meta: U2FsdGVkX1+MdrI1gqIejLzxXPPeRx4Y4pgQmpalDiNIPGubZV9GflnRrpFnA1OdT7ko0jTf50bm0FUnowuWR9c+abVI5JRewjDJnRDl/V2OeVj+7gLsFGJ9BQOFHn6qrKPNDngXJJKVVVarpfqVJagChuV9RbtajP3HxnqoqegNdVsm8viPLpe81AdJjzRHVBnTiGvC6cW8C0bldUdVdVq50g4tRadAUJGxFR6h+GzTAVhl/UdtGLjLiTj0G+MmhNGnIQY5AcjhEsXwlfIUo9NP1K0qTEntcmzQuz+2VUymLBIaWOWaXLFA0MbRsPGza1VwTrLQaLl9LY+sv2WMQNSrmys73KJ5xuLoWE11RWPr3pMa/Y9nudUTZWnGOo1EMus5dm0za4rOUx+pcx2xwi5BwnPuuQfubmAB9NmMjTno5z/RNWRfKlGrIqa1Q6Zqnsz9E1bVrz5hf7kCSRF5DkPIQTKatP9qtehAYgRrlA22WuxsgEJh/Xd3bcExddzW1ITj6nvWzyTDvD7dNnuYhq/e4F7ZC/7VaHahzDeSIKv7EzDvbcfKjJ8HTn3gze5ThwmfUCo492z3+X6NDBbmplBb9uTjCJylX4D02/QNX52hzB666CIrXpcgs40C0v4XesKlROOsNnSreGAyxhneIrPAjPkjDDvl8pOvoFb+XqcI8DVhkL5RbeVR/2cS7SKxPmL3XnQa7Ok7uKZQKnj1aV4WlTb7fD5ZvwI3dgDBar0qUp/6/2NSvIhmCzJn+LRoi1mxXcRMjlQk9AhKidG2o7U3WKqLWvyyvKhsF9t/lfY5CRCJuYaZSD/Qn86OByXi6YDzytuGdiBML1dcGVnfJ8GfXRZwzwA1SoblRQkMfhl+PuimLpL6X7FFKOSJwCqTRAEDhueS61swDcTOtS99lUYQrhV9lzpd 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: x86/powerpc has it's implementation of copy_mc_to_user(), we add generic fallback in include/linux/uaccess.h prepare for other architechures to enable CONFIG_ARCH_HAS_COPY_MC. Signed-off-by: Tong Tiangen Acked-by: Michael Ellerman --- arch/powerpc/include/asm/uaccess.h | 1 + arch/x86/include/asm/uaccess.h | 1 + include/linux/uaccess.h | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h index 3ddc65c63a49..82dc55707c4b 100644 --- a/arch/powerpc/include/asm/uaccess.h +++ b/arch/powerpc/include/asm/uaccess.h @@ -357,6 +357,7 @@ copy_mc_to_user(void __user *to, const void *from, unsigned long n) return n; } +#define copy_mc_to_user copy_mc_to_user #endif extern long __copy_from_user_flushcache(void *dst, const void __user *src, diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 1d2c79246681..71a4d7bf9e38 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -559,6 +559,7 @@ copy_mc_to_kernel(void *to, const void *from, unsigned len); unsigned long __must_check copy_mc_to_user(void *to, const void *from, unsigned len); +#define copy_mc_to_user copy_mc_to_user #endif /* diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 46680189d761..8726260e5508 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -198,6 +198,15 @@ copy_mc_to_kernel(void *dst, const void *src, size_t cnt) } #endif +#ifndef copy_mc_to_user +static inline unsigned long __must_check +copy_mc_to_user(void *dst, const void *src, size_t cnt) +{ + check_object_size(src, cnt, true); + return raw_copy_to_user(dst, src, cnt); +} +#endif + static __always_inline void pagefault_disabled_inc(void) { current->pagefault_disabled++; 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; } From patchwork Mon Dec 19 12:00:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tong Tiangen X-Patchwork-Id: 13076504 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 61D33C4332F for ; Mon, 19 Dec 2022 12:00:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D660D8E0006; Mon, 19 Dec 2022 07:00:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1C188E0001; Mon, 19 Dec 2022 07:00:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C04868E0006; Mon, 19 Dec 2022 07:00:52 -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 B1C658E0001 for ; Mon, 19 Dec 2022 07:00:52 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7F20F80AD9 for ; Mon, 19 Dec 2022 12:00:52 +0000 (UTC) X-FDA: 80258914344.19.8FBB4C6 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf19.hostedemail.com (Postfix) with ESMTP id 3E9F91A0020 for ; Mon, 19 Dec 2022 12:00:48 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.255 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=1671451249; 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=jQKhpRFZYNSMJJ68eyFcWrh5PEMv/jS/d7zTq+MXzzs=; b=1KAewVtpfG+IrezvbUPfGqkmvyq9oLs258WNNraCCKFMrulpyJA9M3O32stHDDzRcgJS8t gpHFX02ew17i1n8dScTI1YRTslrL6YZwYeiE7oQStUnXN0GTRGr341vlPEx7Vt6rwqzzO9 TcKs57BV2jufdq3+4VLAPge+it3wQck= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671451249; a=rsa-sha256; cv=none; b=t361qP3fGRtQBkrLVNSjOaPS61S5vCcGxxh156PZOa+Yjq2FKLPTZ7RzK3g0iBAmDlZRJO xVU+jFWPaspneadz6mE/T4p+1ds8dz779Gh5DFY92xHc/Xj8tTFhnggTKb+8fOk8w7RP9v +t1eeBxRckQQR2oC3nXOg4CNGFQPVn4= Received: from kwepemm600017.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NbJCw4NTTz16Lkj; Mon, 19 Dec 2022 19:59:40 +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:44 +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 3/4] arm64: add uaccess to machine check safe Date: Mon, 19 Dec 2022 12:00:07 +0000 Message-ID: <20221219120008.3818828-4-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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3E9F91A0020 X-Rspam-User: X-Stat-Signature: yqa7rquj6hhaj8ce9cc8gacksjikzeph X-HE-Tag: 1671451248-981715 X-HE-Meta: U2FsdGVkX18Qtef6WRU5YhFY4ucVBWzyD5/k86EzhYYOjtJexMNi1bD+7l894sO9NVweHwNXPPM2ak3Sp5RBVWpWpxePitGMmL/d4Nu5WknPCG0tGr+oVNfkLYRTy6NVldXLrkata5FqRkBhcsowj4/zS4PJ56VNxrndxo+wNLFfZXSjuyxNc/pvjb6Irv0zr2OJFV7BGaATKeBZlJoIB2A5U62NWmlAnPcGFybw3fwivyPnprN+VZPsU8VDKkrgUTIYmtaQI1qT9M4Ts7sWhHJreQ4U/ZQA1AwLYhW8ghfvSgIJHxmlHU9VjgMq9xtF6iluTWJqbGCFeatgEcVyDtvWuNM0AkMv0BjohvuEqhhJK5ZmaGWpclfVYo3GWa8AqW6Vth4/C0KtLCKrZoj0BjahQ758OKIyt60EtkcRDWKwVfr6ghv8qv4KJ4lwJvlmubszxjerdePdHIMTjJDJZwbsRDmfnZhmN91i+x/ZJOxDadn9Mx82Gsq0MojghEMVtHayulyq3fdiC2dYPW8RiQQmAHz/psxV6Dju4jTY/XRme3cISYx6YPjAlXYhNpVEEF0aH1c0qsnLv+KLj6SUpy8vJMIKCTinuO0xwcdUC6jNybDSXjKqFY2vKK6Wj/KI23LM9HWVLqbBelII2Xg/zWdwMUj5b0kYhHqJAc1tSGCDagLrM08BtlFxXUhvO6eeX6UfRFsX+hsnN+kVGFaKLpulb/KRhFc5KA4ExA7z8PNNw2/WDInXXP+sKP3ogVbF4KbNsB25OTTQ3gvGzbnulxHkjBnwY4qwwDzG0W4yY/ZU51E19hlVmZ+L+qr15v8R869WQ9nfFDYo+bbLLpvrtuLyLxyPsppJH5eC7lhbWJU= 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: If user access fail due to hardware memory error, only the relevant processes are affected, so killing the user process and isolate the error page with hardware memory errors is a more reasonable choice than kernel panic. Signed-off-by: Tong Tiangen --- arch/arm64/mm/extable.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c index 478e639f8680..28ec35e3d210 100644 --- a/arch/arm64/mm/extable.c +++ b/arch/arm64/mm/extable.c @@ -85,10 +85,10 @@ bool fixup_exception_mc(struct pt_regs *regs) if (!ex) return false; - /* - * This is not complete, More Machine check safe extable type can - * be processed here. - */ + switch (ex->type) { + case EX_TYPE_UACCESS_ERR_ZERO: + return ex_handler_uaccess_err_zero(ex, regs); + } return false; } From patchwork Mon Dec 19 12:00:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tong Tiangen X-Patchwork-Id: 13076505 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 1BF17C4167B for ; Mon, 19 Dec 2022 12:00:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACDA28E0007; Mon, 19 Dec 2022 07:00:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A7F6C8E0001; Mon, 19 Dec 2022 07:00:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 799598E0007; Mon, 19 Dec 2022 07:00:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 691FD8E0001 for ; Mon, 19 Dec 2022 07:00:54 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 35DD71C4E75 for ; Mon, 19 Dec 2022 12:00:54 +0000 (UTC) X-FDA: 80258914428.29.26ED78E Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf14.hostedemail.com (Postfix) with ESMTP id CA8F3100026 for ; Mon, 19 Dec 2022 12:00:51 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.255 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=1671451252; 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=21vofo293Pi0XllbIrDnxteCgzDFzV64juv4Mz4EIpQ=; b=5Ud/uH/195tQVNzvXXBxeW8fMHZl9sND4vwRorT4jM0lrmU2A9USxNKFKQwO4n3zpbo1UM 9yAkmHF/t3TJKSjSbN0es4ADvvWR76Ar8NOU8ooe12bAbdSJjUqtBqMyHg6lmEuplBIoZF b2LHkxlDL8F/BA207TqVK12kajKTlOI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of tongtiangen@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=tongtiangen@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671451252; a=rsa-sha256; cv=none; b=V7CE8i0R53l/AURGsCOxR6XjDXVCnbIZ1t6FTT1zmA0IF5bOAIDBLrVqfMrHDMMX07TxNv mfe6OOvtDEZimJIsBh6LaPrLlu3r3G5lcwTxp5E9oaJhURn4U96AnVPy3twt23cVRQf/iA kL/ciw0kgTa+OfBHw58nl2ke54W5Hy8= Received: from kwepemm600017.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NbJCy5tD6z16Lkt; Mon, 19 Dec 2022 19:59:42 +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:46 +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 4/4] arm64: add cow to machine check safe Date: Mon, 19 Dec 2022 12:00:08 +0000 Message-ID: <20221219120008.3818828-5-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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: CA8F3100026 X-Stat-Signature: jdgk5ryd89c53oraky385up5o14yko5m X-Rspam-User: X-HE-Tag: 1671451251-881154 X-HE-Meta: U2FsdGVkX18sqBXGnXIenpbikIp/HpjHmJtN24ryVMBQPvjHpR51TInQtmCM3kR5fYk/e9uyAGljYY7lzMERNj7yhR2b+LwUXLFWHN+TIPybsvzIOu2qHYn+RwOYOO7uhL8N03pD7ZyzR0XcRZKR+ELJroPA6WlaUfGu/AqOaGHYrcZJULOnQxjNUfBZIXcDLRd+keCwP5ohRfW90R/Pyzaphkcu25+dGi3HOlsFCu/uZ4CT9oMfWoOHSzxGt41pfn3F8GO4reD9faI+Wy9D83IUWouwWO93Rzx74eTcY5m3TBT1hCk31b5VOUiBcht2GSoQW+3aHEuKRMP9pJxRclAkfmXB+6dmCi/U8U2ZcsG6G3OfkUJM7hVqedAw26TgQIACeo4MbsoH0x4/lRFUGsw5h+tGAXXnB7r/CEBwhfsYANS0VV7if6Kdmcueua3tOy1agu5lvQpivAeHi3LHXCKDPS0gWQOxvJ8MAh3Ir/9T0KM+UKsvR5u6pKvd1HW7MUmlP2MHuUi95myrTDTqozirOQm1vpPATeLHWKbS8D3o9vEBjQQEdvN3CL5RKlzyMMuYRRx7URL0Z5ROE3ITHqe0jXSWF4BQWv0v1KgX5WVTImsXAA3f975h75idAa+L+Rshmg2e6IJEbrQ/lKnnvsLI33z21rF4R2YemzTUvofCdOD139FVj9186sHZEtB3x72MsmYuy/Qib2xT/ddEUWou4ouaox8qUfEUwAI5+GmsxAyfCXvAsLFWp86QOhKklvSKibMD8fd6klXfQ7sUZ2NGfG2BwNlkWezo+jWjHPLT+nKdy5PyECLEvT2kHc1PZThZD/iB4lZwJjZFiuqbpX7FjRrq8ZUoQGn7l80PtSk= 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: At present, Recover from poison consumption from copy-on-write has been supported[1], arm64 should also support this mechanism. Add new helper copy_mc_page() which provide a page copy implementation with machine check safe. At present, only used in cow. In the future, we can expand more scenes. As long as the consequences of page copy failure are not fatal(eg: only affect user process), we can use this helper. The copy_mc_page() in copy_page_mc.S is largely borrows from copy_page() in copy_page.S and the main difference is copy_mc_page() add extable entry to every load/store insn to support machine check safe. largely to keep the patch simple. If needed those optimizations can be folded in. Add new extable type EX_TYPE_COPY_MC_PAGE which used in copy_mc_page(). [1]https://lore.kernel.org/lkml/20221031201029.102123-1-tony.luck@intel.com/ Signed-off-by: Tong Tiangen --- arch/arm64/include/asm/asm-extable.h | 5 ++ arch/arm64/include/asm/assembler.h | 4 ++ arch/arm64/include/asm/mte.h | 4 ++ arch/arm64/include/asm/page.h | 10 ++++ arch/arm64/lib/Makefile | 2 + arch/arm64/lib/copy_mc_page.S | 82 ++++++++++++++++++++++++++++ arch/arm64/lib/mte.S | 19 +++++++ arch/arm64/mm/copypage.c | 42 ++++++++++++-- arch/arm64/mm/extable.c | 9 +++ include/linux/highmem.h | 2 + 10 files changed, 173 insertions(+), 6 deletions(-) create mode 100644 arch/arm64/lib/copy_mc_page.S diff --git a/arch/arm64/include/asm/asm-extable.h b/arch/arm64/include/asm/asm-extable.h index 980d1dd8e1a3..32625c2839fb 100644 --- a/arch/arm64/include/asm/asm-extable.h +++ b/arch/arm64/include/asm/asm-extable.h @@ -10,6 +10,7 @@ #define EX_TYPE_UACCESS_ERR_ZERO 2 #define EX_TYPE_KACCESS_ERR_ZERO 3 #define EX_TYPE_LOAD_UNALIGNED_ZEROPAD 4 +#define EX_TYPE_COPY_MC_PAGE 5 /* Data fields for EX_TYPE_UACCESS_ERR_ZERO */ #define EX_DATA_REG_ERR_SHIFT 0 @@ -59,6 +60,10 @@ _ASM_EXTABLE_UACCESS(\insn, \fixup) .endm + .macro _asm_extable_copy_mc_page, insn, fixup + __ASM_EXTABLE_RAW(\insn, \fixup, EX_TYPE_COPY_MC_PAGE, 0) + .endm + /* * Create an exception table entry for `insn` if `fixup` is provided. Otherwise * do nothing. diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 376a980f2bad..547ab2f85888 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -154,6 +154,10 @@ lr .req x30 // link register #define CPU_LE(code...) code #endif +#define CPY_MC(l, x...) \ +9999: x; \ + _asm_extable_copy_mc_page 9999b, l + /* * Define a macro that constructs a 64-bit value by concatenating two * 32-bit registers. Note that on big endian systems the order of the diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h index 20dd06d70af5..a7a888ef9dbf 100644 --- a/arch/arm64/include/asm/mte.h +++ b/arch/arm64/include/asm/mte.h @@ -92,6 +92,7 @@ static inline bool try_page_mte_tagging(struct page *page) void mte_zero_clear_page_tags(void *addr); void mte_sync_tags(pte_t old_pte, pte_t pte); void mte_copy_page_tags(void *kto, const void *kfrom); +void mte_copy_mc_page_tags(void *kto, const void *kfrom); void mte_thread_init_user(void); void mte_thread_switch(struct task_struct *next); void mte_cpu_setup(void); @@ -128,6 +129,9 @@ static inline void mte_sync_tags(pte_t old_pte, pte_t pte) static inline void mte_copy_page_tags(void *kto, const void *kfrom) { } +static inline void mte_copy_mc_page_tags(void *kto, const void *kfrom) +{ +} static inline void mte_thread_init_user(void) { } diff --git a/arch/arm64/include/asm/page.h b/arch/arm64/include/asm/page.h index 993a27ea6f54..0780ac57ac27 100644 --- a/arch/arm64/include/asm/page.h +++ b/arch/arm64/include/asm/page.h @@ -29,6 +29,16 @@ void copy_user_highpage(struct page *to, struct page *from, void copy_highpage(struct page *to, struct page *from); #define __HAVE_ARCH_COPY_HIGHPAGE +#ifdef CONFIG_ARCH_HAS_COPY_MC +extern void copy_mc_page(void *to, const void *from); +void copy_mc_highpage(struct page *to, struct page *from); +#define __HAVE_ARCH_COPY_MC_HIGHPAGE + +int copy_mc_user_highpage(struct page *to, struct page *from, + unsigned long vaddr, struct vm_area_struct *vma); +#define __HAVE_ARCH_COPY_MC_USER_HIGHPAGE +#endif + struct page *alloc_zeroed_user_highpage_movable(struct vm_area_struct *vma, unsigned long vaddr); #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE_MOVABLE diff --git a/arch/arm64/lib/Makefile b/arch/arm64/lib/Makefile index 29490be2546b..a2fd865b816d 100644 --- a/arch/arm64/lib/Makefile +++ b/arch/arm64/lib/Makefile @@ -15,6 +15,8 @@ endif lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o +lib-$(CONFIG_ARCH_HAS_COPY_MC) += copy_mc_page.o + obj-$(CONFIG_CRC32) += crc32.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o diff --git a/arch/arm64/lib/copy_mc_page.S b/arch/arm64/lib/copy_mc_page.S new file mode 100644 index 000000000000..03d657a182f6 --- /dev/null +++ b/arch/arm64/lib/copy_mc_page.S @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2012 ARM Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include + +/* + * Copy a page from src to dest (both are page aligned) with machine check + * + * Parameters: + * x0 - dest + * x1 - src + */ +SYM_FUNC_START(__pi_copy_mc_page) +alternative_if ARM64_HAS_NO_HW_PREFETCH + // Prefetch three cache lines ahead. + prfm pldl1strm, [x1, #128] + prfm pldl1strm, [x1, #256] + prfm pldl1strm, [x1, #384] +alternative_else_nop_endif + +CPY_MC(9998f, ldp x2, x3, [x1]) +CPY_MC(9998f, ldp x4, x5, [x1, #16]) +CPY_MC(9998f, ldp x6, x7, [x1, #32]) +CPY_MC(9998f, ldp x8, x9, [x1, #48]) +CPY_MC(9998f, ldp x10, x11, [x1, #64]) +CPY_MC(9998f, ldp x12, x13, [x1, #80]) +CPY_MC(9998f, ldp x14, x15, [x1, #96]) +CPY_MC(9998f, ldp x16, x17, [x1, #112]) + + add x0, x0, #256 + add x1, x1, #128 +1: + tst x0, #(PAGE_SIZE - 1) + +alternative_if ARM64_HAS_NO_HW_PREFETCH + prfm pldl1strm, [x1, #384] +alternative_else_nop_endif + +CPY_MC(9998f, stnp x2, x3, [x0, #-256]) +CPY_MC(9998f, ldp x2, x3, [x1]) +CPY_MC(9998f, stnp x4, x5, [x0, #16 - 256]) +CPY_MC(9998f, ldp x4, x5, [x1, #16]) +CPY_MC(9998f, stnp x6, x7, [x0, #32 - 256]) +CPY_MC(9998f, ldp x6, x7, [x1, #32]) +CPY_MC(9998f, stnp x8, x9, [x0, #48 - 256]) +CPY_MC(9998f, ldp x8, x9, [x1, #48]) +CPY_MC(9998f, stnp x10, x11, [x0, #64 - 256]) +CPY_MC(9998f, ldp x10, x11, [x1, #64]) +CPY_MC(9998f, stnp x12, x13, [x0, #80 - 256]) +CPY_MC(9998f, ldp x12, x13, [x1, #80]) +CPY_MC(9998f, stnp x14, x15, [x0, #96 - 256]) +CPY_MC(9998f, ldp x14, x15, [x1, #96]) +CPY_MC(9998f, stnp x16, x17, [x0, #112 - 256]) +CPY_MC(9998f, ldp x16, x17, [x1, #112]) + + add x0, x0, #128 + add x1, x1, #128 + + b.ne 1b + +CPY_MC(9998f, stnp x2, x3, [x0, #-256]) +CPY_MC(9998f, stnp x4, x5, [x0, #16 - 256]) +CPY_MC(9998f, stnp x6, x7, [x0, #32 - 256]) +CPY_MC(9998f, stnp x8, x9, [x0, #48 - 256]) +CPY_MC(9998f, stnp x10, x11, [x0, #64 - 256]) +CPY_MC(9998f, stnp x12, x13, [x0, #80 - 256]) +CPY_MC(9998f, stnp x14, x15, [x0, #96 - 256]) +CPY_MC(9998f, stnp x16, x17, [x0, #112 - 256]) + +9998: ret + +SYM_FUNC_END(__pi_copy_mc_page) +SYM_FUNC_ALIAS(copy_mc_page, __pi_copy_mc_page) +EXPORT_SYMBOL(copy_mc_page) diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S index 5018ac03b6bf..bf4dd861c41c 100644 --- a/arch/arm64/lib/mte.S +++ b/arch/arm64/lib/mte.S @@ -80,6 +80,25 @@ SYM_FUNC_START(mte_copy_page_tags) ret SYM_FUNC_END(mte_copy_page_tags) +/* + * Copy the tags from the source page to the destination one wiht machine check safe + * x0 - address of the destination page + * x1 - address of the source page + */ +SYM_FUNC_START(mte_copy_mc_page_tags) + mov x2, x0 + mov x3, x1 + multitag_transfer_size x5, x6 +1: +CPY_MC(2f, ldgm x4, [x3]) + stgm x4, [x2] + add x2, x2, x5 + add x3, x3, x5 + tst x2, #(PAGE_SIZE - 1) + b.ne 1b +2: ret +SYM_FUNC_END(mte_copy_mc_page_tags) + /* * Read tags from a user buffer (one tag per byte) and set the corresponding * tags at the given kernel address. Used by PTRACE_POKEMTETAGS. diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c index 8dd5a8fe64b4..005ee2a3cb4e 100644 --- a/arch/arm64/mm/copypage.c +++ b/arch/arm64/mm/copypage.c @@ -14,21 +14,30 @@ #include #include -void copy_highpage(struct page *to, struct page *from) +static void do_mte(struct page *to, struct page *from, void *kto, void *kfrom, bool mc) { - void *kto = page_address(to); - void *kfrom = page_address(from); - - copy_page(kto, kfrom); if (system_supports_mte() && page_mte_tagged(from)) { page_kasan_tag_reset(to); /* It's a new page, shouldn't have been tagged yet */ WARN_ON_ONCE(!try_page_mte_tagging(to)); - mte_copy_page_tags(kto, kfrom); + if (mc) + mte_copy_mc_page_tags(kto, kfrom); + else + mte_copy_page_tags(kto, kfrom); + set_page_mte_tagged(to); } } + +void copy_highpage(struct page *to, struct page *from) +{ + void *kto = page_address(to); + void *kfrom = page_address(from); + + copy_page(kto, kfrom); + do_mte(to, from, kto, kfrom, false); +} EXPORT_SYMBOL(copy_highpage); void copy_user_highpage(struct page *to, struct page *from, @@ -38,3 +47,24 @@ void copy_user_highpage(struct page *to, struct page *from, flush_dcache_page(to); } EXPORT_SYMBOL_GPL(copy_user_highpage); + +#ifdef CONFIG_ARCH_HAS_COPY_MC +void copy_mc_highpage(struct page *to, struct page *from) +{ + void *kto = page_address(to); + void *kfrom = page_address(from); + + copy_mc_page(kto, kfrom); + do_mte(to, from, kto, kfrom, true); +} +EXPORT_SYMBOL(copy_mc_highpage); + +int copy_mc_user_highpage(struct page *to, struct page *from, + unsigned long vaddr, struct vm_area_struct *vma) +{ + copy_mc_highpage(to, from); + flush_dcache_page(to); + return 0; +} +EXPORT_SYMBOL_GPL(copy_mc_user_highpage); +#endif diff --git a/arch/arm64/mm/extable.c b/arch/arm64/mm/extable.c index 28ec35e3d210..0fdab18f2f07 100644 --- a/arch/arm64/mm/extable.c +++ b/arch/arm64/mm/extable.c @@ -16,6 +16,13 @@ get_ex_fixup(const struct exception_table_entry *ex) return ((unsigned long)&ex->fixup + ex->fixup); } +static bool ex_handler_fixup(const struct exception_table_entry *ex, + struct pt_regs *regs) +{ + regs->pc = get_ex_fixup(ex); + return true; +} + static bool ex_handler_uaccess_err_zero(const struct exception_table_entry *ex, struct pt_regs *regs) { @@ -88,6 +95,8 @@ bool fixup_exception_mc(struct pt_regs *regs) switch (ex->type) { case EX_TYPE_UACCESS_ERR_ZERO: return ex_handler_uaccess_err_zero(ex, regs); + case EX_TYPE_COPY_MC_PAGE: + return ex_handler_fixup(ex, regs); } return false; diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 44242268f53b..3ad39d4d81d5 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -319,6 +319,7 @@ static inline void copy_user_highpage(struct page *to, struct page *from, #endif +#ifndef __HAVE_ARCH_COPY_MC_USER_HIGHPAGE #ifdef copy_mc_to_kernel static inline int copy_mc_user_highpage(struct page *to, struct page *from, unsigned long vaddr, struct vm_area_struct *vma) @@ -344,6 +345,7 @@ static inline int copy_mc_user_highpage(struct page *to, struct page *from, return 0; } #endif +#endif #ifndef __HAVE_ARCH_COPY_HIGHPAGE