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=-10.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 560D0C433E1 for ; Tue, 30 Jun 2020 19:49:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31B4F206B6 for ; Tue, 30 Jun 2020 19:49:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728586AbgF3TtE (ORCPT ); Tue, 30 Jun 2020 15:49:04 -0400 Received: from foss.arm.com ([217.140.110.172]:32962 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728504AbgF3Tsz (ORCPT ); Tue, 30 Jun 2020 15:48:55 -0400 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 D4469106F; Tue, 30 Jun 2020 12:48:54 -0700 (PDT) Received: from seattle-bionic.arm.com.Home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E892C3F73C; Tue, 30 Jun 2020 12:48:53 -0700 (PDT) From: Oliver Swede To: Will Deacon , Catalin Marinas Cc: Robin Murphy , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 10/14] arm64: Store the arguments to copy_*_user on the stack Date: Tue, 30 Jun 2020 19:48:18 +0000 Message-Id: <20200630194822.1082-11-oli.swede@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200630194822.1082-1-oli.swede@arm.com> References: <20200630194822.1082-1-oli.swede@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This preserves the initial arguments of the user copy calls so that they can be restored by the fixup routines. The values in the relevant three registers (x0/dstin, x1/src, x2/count) may be modified by the optimized memcpy algorithm for large copy sizes, and this stores them before it begins executing. The stack is used instead of other general-purpose registers due to resource constraints: the algorithm is optimized with respect to the Procedure Call Standard in the Arm ABI, which assumes that x0-x17 can be used as scratch registers and utilizes all of them during copying, but leaves alone the rest that have specific uses in the broader system. As there are no more temporary registers, the stack can be used to preserve the initial arguments to provide fixup routines with more information to use in the calculation of the number of bytes that failed to copy. The stack pointer is restored to its initial position, either from the fixup code in the case of a fault, or at the end of the copy algorithm otherwise (uaccess_finish is extended to restore the sp, and this code is also moved to copy_template_user.S as it is common to all of the copy routines that access userspace memory). Signed-off-by: Oliver Swede --- arch/arm64/lib/copy_from_user.S | 3 --- arch/arm64/lib/copy_in_user.S | 3 --- arch/arm64/lib/copy_template_user.S | 6 ++++++ arch/arm64/lib/copy_to_user.S | 3 --- arch/arm64/lib/copy_user_fixup.S | 1 + 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/arm64/lib/copy_from_user.S b/arch/arm64/lib/copy_from_user.S index fa319f27a42b..cd3042e98394 100644 --- a/arch/arm64/lib/copy_from_user.S +++ b/arch/arm64/lib/copy_from_user.S @@ -110,9 +110,6 @@ SYM_FUNC_START(__arch_copy_from_user) #include "copy_template_user.S" -.Luaccess_finish: - mov x0, #0 - ret SYM_FUNC_END(__arch_copy_from_user) EXPORT_SYMBOL(__arch_copy_from_user) #include "copy_user_fixup.S" diff --git a/arch/arm64/lib/copy_in_user.S b/arch/arm64/lib/copy_in_user.S index 6b9bb6091dd8..fe035e513b34 100644 --- a/arch/arm64/lib/copy_in_user.S +++ b/arch/arm64/lib/copy_in_user.S @@ -117,9 +117,6 @@ SYM_FUNC_START(__arch_copy_in_user) #include "copy_template_user.S" -.Luaccess_finish: - mov x0, #0 - ret SYM_FUNC_END(__arch_copy_in_user) EXPORT_SYMBOL(__arch_copy_in_user) #include "copy_user_fixup.S" diff --git a/arch/arm64/lib/copy_template_user.S b/arch/arm64/lib/copy_template_user.S index 3db24dcdab05..1d13daf314b0 100644 --- a/arch/arm64/lib/copy_template_user.S +++ b/arch/arm64/lib/copy_template_user.S @@ -21,4 +21,10 @@ L(copy_non_uao): #undef L #define L(l) .Lnuao ## l + str x2, [sp, #-16]! // count + stp x0, x1, [sp, #-16]! // dstin, src #include "copy_template.S" +.Luaccess_finish: + add sp, sp, 32 + mov x0, #0 + ret diff --git a/arch/arm64/lib/copy_to_user.S b/arch/arm64/lib/copy_to_user.S index 23af6af254da..de0af211b3ba 100644 --- a/arch/arm64/lib/copy_to_user.S +++ b/arch/arm64/lib/copy_to_user.S @@ -110,9 +110,6 @@ SYM_FUNC_START(__arch_copy_to_user) #include "copy_template_user.S" -.Luaccess_finish: - mov x0, #0 - ret SYM_FUNC_END(__arch_copy_to_user) EXPORT_SYMBOL(__arch_copy_to_user) #include "copy_user_fixup.S" diff --git a/arch/arm64/lib/copy_user_fixup.S b/arch/arm64/lib/copy_user_fixup.S index 117c37598691..fe9f5ac19605 100644 --- a/arch/arm64/lib/copy_user_fixup.S +++ b/arch/arm64/lib/copy_user_fixup.S @@ -5,5 +5,6 @@ addr .req x15 .align 2 9998: // TODO: add accurate fixup + add sp, sp, 32 ret -- 2.17.1 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=-10.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 40E8AC433DF for ; Tue, 30 Jun 2020 19:52:09 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 F0BD2206A1 for ; Tue, 30 Jun 2020 19:52:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Mdt4Ny9K" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F0BD2206A1 Authentication-Results: mail.kernel.org; dmarc=none (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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zDx0piIRTXHY4SZsuwvHZNbE86lns7rBqjUA9vJT+wo=; b=Mdt4Ny9KJ0wWxMOQY2ZTmONzUS NoZVHMVJVkP/M4HC+mlrrF7mceRAYb/Ybbxt2Ftsxjhj/XK0iBCB5PUgF8pIL+dzXnutr8JWiOzas v867jYy9Rww1HR0QGLQo+3C3D+b/bNYV89yaa+Tdb72NJCAEVZ9kseAjG1nHMZIYqgcAnCIblnIiG qFUyw86VjCMI/vKInxyFQETft1+W/+gT9Brfi712vK8aGnMgAye03eMKokhqlBRMlfOXqwhNzw6IZ AGPVZpRLQrZhxSRIAZmdPz+YkLXrXodFE2tA7yNeRQPC57/Q2HkQWBxJRpDX97nS7noO+C/b+enjW cSypTS/g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqMGI-0002hv-KK; Tue, 30 Jun 2020 19:49:46 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqMFT-0002Oz-0V for linux-arm-kernel@lists.infradead.org; Tue, 30 Jun 2020 19:48:59 +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 D4469106F; Tue, 30 Jun 2020 12:48:54 -0700 (PDT) Received: from seattle-bionic.arm.com.Home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E892C3F73C; Tue, 30 Jun 2020 12:48:53 -0700 (PDT) From: Oliver Swede To: Will Deacon , Catalin Marinas Subject: [PATCH v4 10/14] arm64: Store the arguments to copy_*_user on the stack Date: Tue, 30 Jun 2020 19:48:18 +0000 Message-Id: <20200630194822.1082-11-oli.swede@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200630194822.1082-1-oli.swede@arm.com> References: <20200630194822.1082-1-oli.swede@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200630_154855_257584_5D6A929E X-CRM114-Status: GOOD ( 13.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Robin Murphy , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 This preserves the initial arguments of the user copy calls so that they can be restored by the fixup routines. The values in the relevant three registers (x0/dstin, x1/src, x2/count) may be modified by the optimized memcpy algorithm for large copy sizes, and this stores them before it begins executing. The stack is used instead of other general-purpose registers due to resource constraints: the algorithm is optimized with respect to the Procedure Call Standard in the Arm ABI, which assumes that x0-x17 can be used as scratch registers and utilizes all of them during copying, but leaves alone the rest that have specific uses in the broader system. As there are no more temporary registers, the stack can be used to preserve the initial arguments to provide fixup routines with more information to use in the calculation of the number of bytes that failed to copy. The stack pointer is restored to its initial position, either from the fixup code in the case of a fault, or at the end of the copy algorithm otherwise (uaccess_finish is extended to restore the sp, and this code is also moved to copy_template_user.S as it is common to all of the copy routines that access userspace memory). Signed-off-by: Oliver Swede --- arch/arm64/lib/copy_from_user.S | 3 --- arch/arm64/lib/copy_in_user.S | 3 --- arch/arm64/lib/copy_template_user.S | 6 ++++++ arch/arm64/lib/copy_to_user.S | 3 --- arch/arm64/lib/copy_user_fixup.S | 1 + 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/arm64/lib/copy_from_user.S b/arch/arm64/lib/copy_from_user.S index fa319f27a42b..cd3042e98394 100644 --- a/arch/arm64/lib/copy_from_user.S +++ b/arch/arm64/lib/copy_from_user.S @@ -110,9 +110,6 @@ SYM_FUNC_START(__arch_copy_from_user) #include "copy_template_user.S" -.Luaccess_finish: - mov x0, #0 - ret SYM_FUNC_END(__arch_copy_from_user) EXPORT_SYMBOL(__arch_copy_from_user) #include "copy_user_fixup.S" diff --git a/arch/arm64/lib/copy_in_user.S b/arch/arm64/lib/copy_in_user.S index 6b9bb6091dd8..fe035e513b34 100644 --- a/arch/arm64/lib/copy_in_user.S +++ b/arch/arm64/lib/copy_in_user.S @@ -117,9 +117,6 @@ SYM_FUNC_START(__arch_copy_in_user) #include "copy_template_user.S" -.Luaccess_finish: - mov x0, #0 - ret SYM_FUNC_END(__arch_copy_in_user) EXPORT_SYMBOL(__arch_copy_in_user) #include "copy_user_fixup.S" diff --git a/arch/arm64/lib/copy_template_user.S b/arch/arm64/lib/copy_template_user.S index 3db24dcdab05..1d13daf314b0 100644 --- a/arch/arm64/lib/copy_template_user.S +++ b/arch/arm64/lib/copy_template_user.S @@ -21,4 +21,10 @@ L(copy_non_uao): #undef L #define L(l) .Lnuao ## l + str x2, [sp, #-16]! // count + stp x0, x1, [sp, #-16]! // dstin, src #include "copy_template.S" +.Luaccess_finish: + add sp, sp, 32 + mov x0, #0 + ret diff --git a/arch/arm64/lib/copy_to_user.S b/arch/arm64/lib/copy_to_user.S index 23af6af254da..de0af211b3ba 100644 --- a/arch/arm64/lib/copy_to_user.S +++ b/arch/arm64/lib/copy_to_user.S @@ -110,9 +110,6 @@ SYM_FUNC_START(__arch_copy_to_user) #include "copy_template_user.S" -.Luaccess_finish: - mov x0, #0 - ret SYM_FUNC_END(__arch_copy_to_user) EXPORT_SYMBOL(__arch_copy_to_user) #include "copy_user_fixup.S" diff --git a/arch/arm64/lib/copy_user_fixup.S b/arch/arm64/lib/copy_user_fixup.S index 117c37598691..fe9f5ac19605 100644 --- a/arch/arm64/lib/copy_user_fixup.S +++ b/arch/arm64/lib/copy_user_fixup.S @@ -5,5 +5,6 @@ addr .req x15 .align 2 9998: // TODO: add accurate fixup + add sp, sp, 32 ret -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel