Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1094787pxb; Wed, 6 Apr 2022 08:35:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+BBHdheiTW2QI3ydvJLkhdG02QBtM+Ibj/Jr133YozrYly4rgI5DBuitaQGbeXfbLjaze X-Received: by 2002:a05:6870:a79c:b0:dd:e5ad:ba00 with SMTP id x28-20020a056870a79c00b000dde5adba00mr4212176oao.64.1649259335769; Wed, 06 Apr 2022 08:35:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649259335; cv=none; d=google.com; s=arc-20160816; b=gb7GryGVISuT/4j/+AA+FVcxUFBvoHA9lJ40TyoQ39XpSmOQq1bGQVibKPHpZ5Rk1V aa5WPdlJxKxpIzfmsGGA/NuduOIm2BR7gD4mbDkhR+MXFUt1l0B6lsDjuiK1Fo+qO4GL 3Ca6CTUqLfFtCOTkCEWtyCb0Etep99l5jB2/kcbbrg/xgZGMKd9Ca9VRqtMNt+55JesZ udAQ6zSwp45khwRT9LbKbQlaGCPuf8McLghmpmMeTh2wracKAAquaqorXWYA/qPkDKrr n1RHkJEHRv71foQS8Zus94SI5/XMwzWNhYghAbfzSsWLAPrOMkiGtBV2pf8+46POXNXe wSsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=NL3ilO8ywoBAx/kvtaQdAqf3jd51q2pPMVwwSYT5JKY=; b=u44N8RoI7I/I/rmIiKTyW4JNliIyq2QQ19bTlN309LMZ7F430VcMpLmm0anH1JIlmv pCV7X7vpv7gAME0ExC427n2vif5TATMihX6VKl6jrgdzleJVrXvZeDCXdjPlU+1B7jwF 0tYUvX/5g/yecBTQSWXOKr7k/vDdLs+183ex1NhqLj9BtQYfkWC4jVvBj7DgCvmlcH+M zKhnh4eZx4hCQYUNBGXQr4p9LHJgptc0lCsH7gcnlR0zJb81fKCAauN3SDuykPSXz6b7 9J+vmgoz76xrtUU52zBnYf3uXK1c/tXpudCNp7xV23vJFm65x0zEvI8oweqCn+7j0jf7 yV1g== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id p37-20020a4a95e8000000b00324618ec796si8973970ooi.84.2022.04.06.08.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 08:35:35 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DE0521FE56A; Wed, 6 Apr 2022 06:48:40 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233855AbiDFNud (ORCPT + 99 others); Wed, 6 Apr 2022 09:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233947AbiDFNt5 (ORCPT ); Wed, 6 Apr 2022 09:49:57 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DC3096D8DD2 for ; Wed, 6 Apr 2022 04:19:54 -0700 (PDT) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220406091311.3354723-5-tongtiangen@huawei.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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