Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp422053pxb; Thu, 7 Apr 2022 09:01:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7IdBJBEnBI33vAiwc3qaj++5OnBUJrqH2oiPtcPqlCyinINp8w4ehcp0yIgjG7ZaGVx+g X-Received: by 2002:a05:6a00:1687:b0:4e1:45d:3ded with SMTP id k7-20020a056a00168700b004e1045d3dedmr14965635pfc.0.1649347304416; Thu, 07 Apr 2022 09:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649347304; cv=none; d=google.com; s=arc-20160816; b=iTzlmspCZUkw++mt9njEprKw2hfMTE8xLYCmkSiV6ar2evSKPNcVyF9ixVGNCjT319 zLfEcIdEoHykWQqCtGUsfjNaIZ0NSFNR/IJVqX8YyDAGk0WfFvFXhMZGBiv2aBiX/3ie 0n3ANsnWS/cVLXsy4AbBeaesWQbqGT/FbMGM3yeQ6v7R5U04pF/3xbvClDvJCnTB3fG2 GSW7mLjRtX3euYDOBxyl0jHgZ0BPwdZNfQG3s9OTvQQpqxpQD+pGnBKwjQX/1KR+pJL6 DZzxz88ydAQ0Ov8JmJZ9+NUvZ9lOsZBbsB7DvWp4pg7jQJW18y+LW+Qm8PLsg4CAjqC7 WWpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=Ee3B0Iz4AATTPy8PFC2/lO1IS0TCZV5ZrYfv0CDHwNE=; b=kzbqlf9++8G/HY7a4MN3//Gr/iePYPWps/VQoF+BiyQzbBVI5BHrlGWPLuyZbopcsJ 8iHRzJdRatCs7mAawvcvGolRTTCBMH356zLk6VjdcoAq8UOy05tYgoOBin5lfgzS1cmF Wcj5MHzGI7F2pu45fbfS3fBKSJpe66hSAIbVMUm3TWSJCUpHAC+x89MQFRopSZvKgt6F ik1lro3fiPuNHzuY/W6SJxDUMJgCfMmOHNKxpfY9R505Y6lWwrQTIBvLkiGIUL1vmsnP /hLak0AOwtpSTcic93ULB3bCW3NPfARUlTj7AcYToKtUmh7JPScTXoz8zAb9w3UjNTXk gslQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a170902f54300b00153b2d1647csi93268plf.132.2022.04.07.09.01.26; Thu, 07 Apr 2022 09:01:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343932AbiDGOaK (ORCPT + 99 others); Thu, 7 Apr 2022 10:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbiDGOaI (ORCPT ); Thu, 7 Apr 2022 10:30:08 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A24911903F2 for ; Thu, 7 Apr 2022 07:28:07 -0700 (PDT) Received: from kwepemi100006.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KZ3cl5TFKzdZcX; Thu, 7 Apr 2022 22:27:35 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi100006.china.huawei.com (7.221.188.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 7 Apr 2022 22:28:04 +0800 Received: from [10.174.179.234] (10.174.179.234) 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.2308.21; Thu, 7 Apr 2022 22:28:02 +0800 Message-ID: <9788a324-05b2-80d7-d062-4bb10cc4d0ee@huawei.com> Date: Thu, 7 Apr 2022 22:28:02 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [RFC PATCH -next V2 4/7] arm64: add copy_from_user to machine check safe To: Mark Rutland CC: Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Catalin Marinas , Will Deacon , Alexander Viro , , "H. Peter Anvin" , , , References: <20220406091311.3354723-1-tongtiangen@huawei.com> <20220406091311.3354723-5-tongtiangen@huawei.com> From: Tong Tiangen In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.234] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 在 2022/4/6 19:19, Mark Rutland 写道: > 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. OK, missing that, will be fixed in next verison. Thanks, Tong. > >> // 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 > .