From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 05E23C433F5 for ; Wed, 6 Apr 2022 11:21:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rwdKNw4pZKxQ9pLGPha9pm/NAPgzUa6NsCavEdkvmkI=; b=kwQWkSE1OiGvHQ ef5TzdWfw8zmfD8qlRO1l7uaiJf9vU5e05+VSRdY98dfg1wGwxO6pd9J2RkW27lChStU1t/ltgTwx x1Qjs9MYRafCozFhsODyaucB3/GP869m4Blp2hJ/mFdnVBsuoOQIdw79tTkZxaE6lgPRhhZRcInaW ZMl+fgKlc8gUrT6gbcjwshQLr4dRlBn+RZHU3wcM7ZqYQw7IEWU1t3G7JJImBGZTM6uJkkrV+ToHh xb6VQRwWhGoebSaJ97AVyY/MJ8cbr7xhmHpdmA+uKvdgLiUQOlb1AbjDDlyZ4SxuW+yTldng5U659 ZNMmarzWQxUlpnAuu9IA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nc3hf-005ioG-Lo; Wed, 06 Apr 2022 11:19:59 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nc3hc-005imn-GT for linux-arm-kernel@lists.infradead.org; Wed, 06 Apr 2022 11:19:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 529C223A; Wed, 6 Apr 2022 04:19:54 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.10.98]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 24FC43F718; Wed, 6 Apr 2022 04:19:52 -0700 (PDT) Date: Wed, 6 Apr 2022 12:19:48 +0100 From: Mark Rutland To: Tong Tiangen Cc: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Catalin Marinas , Will Deacon , Alexander Viro , x86@kernel.org, "H. Peter Anvin" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH -next V2 4/7] arm64: add copy_from_user to machine check safe Message-ID: References: <20220406091311.3354723-1-tongtiangen@huawei.com> <20220406091311.3354723-5-tongtiangen@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220406091311.3354723-5-tongtiangen@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220406_041956_684535_7165967A X-CRM114-Status: GOOD ( 19.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Apr 06, 2022 at 09:13:08AM +0000, Tong Tiangen wrote: > Add scenarios copy_from_user to machine check safe. > > The data copied is user data and is machine check safe, so just kill > the user process and isolate the error page, not necessary panic. > > Signed-off-by: Tong Tiangen > --- > arch/arm64/include/asm/asm-uaccess.h | 16 ++++++++++++++++ > arch/arm64/lib/copy_from_user.S | 11 ++++++----- > 2 files changed, 22 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/include/asm/asm-uaccess.h b/arch/arm64/include/asm/asm-uaccess.h > index 0557af834e03..f31c8978e1af 100644 > --- a/arch/arm64/include/asm/asm-uaccess.h > +++ b/arch/arm64/include/asm/asm-uaccess.h > @@ -92,4 +92,20 @@ alternative_else_nop_endif > > _asm_extable 8888b,\l; > .endm > + > + .macro user_ldp_mc l, reg1, reg2, addr, post_inc > +8888: ldtr \reg1, [\addr]; > +8889: ldtr \reg2, [\addr, #8]; > + add \addr, \addr, \post_inc; > + > + _asm_extable_mc 8888b, \l; > + _asm_extable_mc 8889b, \l; > + .endm > + > + .macro user_ldst_mc l, inst, reg, addr, post_inc > +8888: \inst \reg, [\addr]; > + add \addr, \addr, \post_inc; > + > + _asm_extable_mc 8888b, \l; > + .endm > #endif > diff --git a/arch/arm64/lib/copy_from_user.S b/arch/arm64/lib/copy_from_user.S > index 34e317907524..d9d7c5291871 100644 > --- a/arch/arm64/lib/copy_from_user.S > +++ b/arch/arm64/lib/copy_from_user.S > @@ -21,7 +21,7 @@ > */ > > .macro ldrb1 reg, ptr, val > - user_ldst 9998f, ldtrb, \reg, \ptr, \val > + user_ldst_mc 9998f, ldtrb, \reg, \ptr, \val > .endm > > .macro strb1 reg, ptr, val > @@ -29,7 +29,7 @@ > .endm > > .macro ldrh1 reg, ptr, val > - user_ldst 9997f, ldtrh, \reg, \ptr, \val > + user_ldst_mc 9997f, ldtrh, \reg, \ptr, \val > .endm > > .macro strh1 reg, ptr, val > @@ -37,7 +37,7 @@ > .endm > > .macro ldr1 reg, ptr, val > - user_ldst 9997f, ldtr, \reg, \ptr, \val > + user_ldst_mc 9997f, ldtr, \reg, \ptr, \val > .endm > > .macro str1 reg, ptr, val > @@ -45,7 +45,7 @@ > .endm > > .macro ldp1 reg1, reg2, ptr, val > - user_ldp 9997f, \reg1, \reg2, \ptr, \val > + user_ldp_mc 9997f, \reg1, \reg2, \ptr, \val > .endm > > .macro stp1 reg1, reg2, ptr, val > @@ -62,7 +62,8 @@ SYM_FUNC_START(__arch_copy_from_user) > ret > > // Exception fixups > -9997: cmp dst, dstin > +9997: cbz x0, 9998f // Check machine check exception > + cmp dst, dstin > b.ne 9998f If you look at the copy template, you'd see that `dstin` *is* x0. Consier if we took a non-SEA fault. The the fixup handler will overwrite x0, it's likely `dst` != `dstin`, and we'll branch to the byte-by-byte copy. Or if we're doing something odd and mmap_min_addr is 0, we can do the wrong thing the other way around and *not* branch to the byte-by-byte copy when we should. So this is at best confusing, but likely broken too. Thanks, Mark. > // Before being absolutely sure we couldn't copy anything, try harder > USER(9998f, ldtrb tmp1w, [srcin]) > -- > 2.18.0.huawei.25 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel