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 X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91298C433ED for ; Wed, 12 May 2021 11:34:04 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D4E9161175 for ; Wed, 12 May 2021 11:34:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4E9161175 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=k/BTGFrKrG5edDDLroF8ayWP+FFh1aTdOCsUQeHg6K8=; b=euNCiowcJzDKrcPohFo/KZ814 BmZLxsDXwiwtZIkbR4BiJ+FHs0mrnacP6OVoe1Sbf6emuTxwENIbwRD1ICAV1dBMcOWuALgNAONS7 MAU/eIe90JZdi4TBDbpV1xqClz5LWFpp550RP6/UNeTC0ehENMk9j1kqbXqypn9N/QM2ed77McVd2 TxZRq+725o0J5tJ/KfETaizLTJpWt/MKuSitzFxqhssssvEG95QUstbvfwVM80oH6umFypUErlO3A ka2YrEZB1pix6BsW/ZVX1UPz+hF4nZExjoUE4VuIZ5QfVRhAKT9DbRlIoCpcQUeOU8Q22iIKWaDw+ R4MUBPpFQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgn5q-002cKl-QE; Wed, 12 May 2021 11:31:59 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgn5o-002cKZ-Rz for linux-arm-kernel@desiato.infradead.org; Wed, 12 May 2021 11:31:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To: Subject:Sender:Reply-To:Content-ID:Content-Description; bh=j6n8Bp1L9bWZPCZy4852wEJgSkeqipjQW6WKB4jkxZA=; b=CrWsgUWHx/SgVcuHBvUtOwRrMW TYR/1CjES5CHWXhPK9WfHITNGk6jQx6tbzL0ovT1zj2W7sT5d1PBKPisgyEdeWpuci06DG4xktDTO RS0+wL/YLb5GAAHeS5VHBM0bjC4dSWq/k2Tt4vehA4MkCHZDTTYNn1fTosK3hjZNdqOsTzIvReH8z vpXAuiAVeGLJ1ubljVSR+duhkqmv6rIUtDq8bfKUv4BnXthedSkWCjtLUfMoCVnBn+d40yfs8foAm 7bISGwJU2WMfTC8eAqn+llkvF7ywTlGDcFqCkIC67HU46RSsDsPQWpDstrrxJ5uT8RNX0Orn7HWvN xVfYBlyQ==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgn5l-00AJMZ-K7 for linux-arm-kernel@lists.infradead.org; Wed, 12 May 2021 11:31:55 +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 8226631B; Wed, 12 May 2021 04:31:45 -0700 (PDT) Received: from [10.57.59.124] (unknown [10.57.59.124]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6626F3F719; Wed, 12 May 2021 04:31:44 -0700 (PDT) Subject: Re: [PATCH 8/8] arm64: Rewrite __arch_clear_user() To: Mark Rutland Cc: will@kernel.org, catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org, yangyingliang@huawei.com, shenkai8@huawei.com References: <76a1700b0316b50fb5881da603f2daf3c81468f4.1620738177.git.robin.murphy@arm.com> <20210512104833.GD88854@C02TD0UTHF1T.local> From: Robin Murphy Message-ID: Date: Wed, 12 May 2021 12:31:39 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210512104833.GD88854@C02TD0UTHF1T.local> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210512_043153_792854_B3E742AA X-CRM114-Status: GOOD ( 27.51 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2021-05-12 11:48, Mark Rutland wrote: > On Tue, May 11, 2021 at 05:12:38PM +0100, Robin Murphy wrote: >> Now that we're always using STTR variants rather than abstracting two >> different addressing modes, the user_ldst macro here is frankly more >> obfuscating than helpful. > > FWIW, I completely agree; the user_ldst macros are a historical artifact > and I'm happy to see them go! > >> Rewrite __arch_clear_user() with regular >> USER() annotations so that it's clearer what's going on, and take the >> opportunity to minimise the branchiness in the most common paths, which >> also allows the exception fixup to return a more accurate result. > > IIUC this isn't always accurate for the {4,2,1}-byte cases; example > below. I'm not sure whether that's intentional since the commit message > says "more accurate" rather than "accurate". Indeed, the "more" was definitely significant :) >> Signed-off-by: Robin Murphy >> --- >> arch/arm64/lib/clear_user.S | 42 +++++++++++++++++++------------------ >> 1 file changed, 22 insertions(+), 20 deletions(-) >> >> diff --git a/arch/arm64/lib/clear_user.S b/arch/arm64/lib/clear_user.S >> index af9afcbec92c..1005345b4066 100644 >> --- a/arch/arm64/lib/clear_user.S >> +++ b/arch/arm64/lib/clear_user.S >> @@ -1,12 +1,9 @@ >> /* SPDX-License-Identifier: GPL-2.0-only */ >> /* >> - * Based on arch/arm/lib/clear_user.S >> - * >> - * Copyright (C) 2012 ARM Ltd. >> + * Copyright (C) 2021 Arm Ltd. >> */ >> -#include >> >> -#include >> +#include >> #include >> >> .text >> @@ -19,25 +16,30 @@ >> * >> * Alignment fixed up by hardware. >> */ >> + .p2align 4 >> SYM_FUNC_START(__arch_clear_user) > > Say we're called with size in x1 == 0x7 > >> - mov x2, x1 // save the size for fixup return >> + add x2, x0, x1 >> subs x1, x1, #8 >> b.mi 2f > > ... here we'll skip to the 4-byte case at 2f ... > >> 1: >> -user_ldst 9f, sttr, xzr, x0, 8 >> +USER(9f, sttr xzr, [x0]) >> + add x0, x0, #8 >> subs x1, x1, #8 >> - b.pl 1b >> -2: adds x1, x1, #4 >> - b.mi 3f >> -user_ldst 9f, sttr, wzr, x0, 4 >> - sub x1, x1, #4 >> -3: adds x1, x1, #2 >> - b.mi 4f >> -user_ldst 9f, sttrh, wzr, x0, 2 >> - sub x1, x1, #2 >> -4: adds x1, x1, #1 >> - b.mi 5f >> -user_ldst 9f, sttrb, wzr, x0, 0 >> + b.hi 1b >> +USER(9f, sttr xzr, [x2, #-8]) >> + mov x0, #0 >> + ret >> + >> +2: tbz x1, #2, 3f > > ... bit 2 is non-zero, so we continue ... > >> +USER(9f, sttr wzr, [x0]) > > ... and if this faults, the fixup will report the correct address ... > >> +USER(9f, sttr wzr, [x2, #-4]) > > ... but if this faults, teh fixup handler will report that we didn't > copy all 7 bytes, rather than just the last 3, since we didn't update x0 > after the first 4-byte STTR. > > We could update x0 inline, or add separate fixup handlers to account for > that out-of-line. > > If we think that under-estimating is fine, I reckon it'd be worth a > comment to make that clear. Indeed for smaller amounts there's no change in fixup behaviour at all, but I have to assume that underestimating by up to 100% is probably OK since we've been underestimating by fully 100% for nearly 10 years now. I don't believe it's worth having any more complexity than necessary for the fault case - grepping for clear_user() usage suggests that nobody really cares about the return value beyond whether it's zero or not, so the minor "improvement" here is more of a nice-to-have TBH. The existing comment doesn't actually explain anything either, which is why I didn't replace it, but I'm happy to add something if you like. Cheers, Robin. > > Thanks, > Mark. > >> + mov x0, #0 >> + ret >> + >> +3: tbz x1, #1, 4f >> +USER(9f, sttrh wzr, [x0]) >> +4: tbz x1, #0, 5f >> +USER(9f, sttrb wzr, [x2, #-1]) >> 5: mov x0, #0 >> ret >> SYM_FUNC_END(__arch_clear_user) >> @@ -45,6 +47,6 @@ EXPORT_SYMBOL(__arch_clear_user) >> >> .section .fixup,"ax" >> .align 2 >> -9: mov x0, x2 // return the original size >> +9: sub x0, x2, x0 >> ret >> .previous >> -- >> 2.21.0.dirty >> >> >> _______________________________________________ >> 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