Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp21882ybt; Tue, 30 Jun 2020 13:59:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4zpWFUewCmRp6wlSYPnHAboi9NFf1+cGphGa6B0oDo8kHTHGfi8eX71yWi+sHTXlQZLr6 X-Received: by 2002:a17:906:7208:: with SMTP id m8mr20686255ejk.544.1593550410050; Tue, 30 Jun 2020 13:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593550410; cv=none; d=google.com; s=arc-20160816; b=sOU+wBwoFhSnLg+Hv9vPViAY87rZCw3f+6BOjli/0Aif5qe76LMFVNL2thVITJNdpS 5yU1y3U3mz1NmdGCXrg5v/F6PqTG3sghmhk4/PhaYiiYJLvWNeIn2z4DzG+55kZSzzvX ZjBw2kGVEBSqle8RrwtiBYzhtNG/CyxOrx0WHh20sxQtGxIgDnlt126P+0x/qhZ9kxLz /4h0T1dbaVD/z7KZdcq+tJ6TXx2bAP2Xd0oHOmMPpubSNuNguUPwAgJrh6BemR/2JazP yqLl8csbDdGST148vdhCUGOrlpbvyyOFQDtvm3rfe+W0PFJdpfuWE2KoGvHzOB782A4V 59VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=XXAjt7dJwXDotPjDG/ztiVumcEnsi3hPyS8aGyztJVo=; b=uHsvWc6stR1Gu232QX0M4JqLY3zEbsBgSrDaTJH5XWuRyUBU+drnZ0QQqmOddpBvms R85gvW3gbcE19cAfD0SW86A66H3yng7lUraQ6/25GQylIliDkQoIgztEEFHSKaoLi5h+ b/7UUc5qJ/FZDxAWKOLYc0I8n043pJ7zhS48hCfoDVTFpl2WEIwN/2fmT2HqlEfSa+Oc N/SUBRRntVUh0BF2lPl1P4oNS2rRX4U2SUCmZ2vuNVpou9IpHkltLMrdb1fVi20WxC9l s0z8gp9prY4DUghJQSRLceL14yVKzBfHFHErMtvDqLviZezOnOOQldBAalCsihHOIA4g FU9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w19si2396637eju.41.2020.06.30.13.53.07; Tue, 30 Jun 2020 13:53:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728567AbgF3TtC (ORCPT + 99 others); Tue, 30 Jun 2020 15:49:02 -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