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=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, 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 B4A59C433E0 for ; Fri, 12 Mar 2021 19:06:06 +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 5158E64F77 for ; Fri, 12 Mar 2021 19:06:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5158E64F77 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=M9nIf2bHlAXbfk7EbTYh7aHG4yGtNHzdz7vt5HoeH+8=; b=dMLMo0QrXEccO2Q70XHgTdfGY4 JX+xhpFbJCdlFFAacPSka4/cEvR/o961IsHLoGY13rzs8bTsQapescS5We6MAqPXzXy1nOm4ePrv1 bTnYsUsikhSBEiYy9B4isvqTWLxUjIq5DgT82ZSgox+aKlXCX15BgIkPtJMkyuJnx33WXnAowvT7R nSYoa1iJRcid6Jep8iiAYy+OnG3yXXqV+IUDCRkztnm99GfzsLMnE75t8bohHGZ8K28JMvR5aXQ04 n22/kWl9RDKcLagwMTKMsZw5Ltzd5Q49bInmjgSU/UZy/IZbFiJpPXTq01/nHMRW2fGc88dmW191l TThFSTUQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lKn5T-00CFFy-2v; Fri, 12 Mar 2021 19:04:39 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lKn5O-00CFFD-PC for linux-arm-kernel@lists.infradead.org; Fri, 12 Mar 2021 19:04:37 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id E778564F73; Fri, 12 Mar 2021 19:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615575873; bh=oh1TT5o/DkP6IFxHfJTa0op+68HCZxyt1zdTr3anD5A=; h=From:To:Cc:Subject:Date:From; b=PC6cCwfHNdpI3NXMPHJxrUFlcVmRzWVFE2DYnx7L9QLEuJaQSSfpiDkBsTNMmh1ug T+4VG/qhYqyNR1qAMRW1oMFKG8hcN8aMI81GoBuI+S4rYKC8dcCzuQqkL3KmZRgWYV TjtnkPFBr/Yph5on8Eq6juHoxwL1ygnGZxQGCiX0DIM8vKoQ2vYBMbICPqmRjrv98c sR6qc8lRsWGJgRsfwpf/xUi4hnHatjRowme3PTNG22NxKeaWed06VjCnAsTevN+l6f F4bDzn7dIkmx3RjFFRkMueHxOXYI8J4bADV4S3rmoSjeBbA3/K7nZCmshLZwN4g0P3 9/H3GEE7st4Hg== From: Mark Brown To: Catalin Marinas , Will Deacon Cc: Julien Grall , Zhang Lei , Dave Martin , Daniel Kiss , linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH] arm64/sve: Rework SVE access trap to convert state in registers Date: Fri, 12 Mar 2021 19:03:13 +0000 Message-Id: <20210312190313.24598-1-broonie@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Patch-Hashes: v=1; h=sha256; i=6ikMIHZeC405u3XljGDs/VdrcdP8gWacOVWlJr6l6TA=; m=g8Cxt7FTVYPh8zhLgYVVMngntkqUc/PtEUlxVtNk/Zk=; p=vtUGsFIRliPIEQlwexUkCfPyUzX4f42txKDfGhEZKKY=; g=78be3a0a5cb56e5913c9f6ab259a7e298019fa8c X-Patch-Sig: m=pgp; i=broonie@kernel.org; s=0xC3F436CA30F5D8EB; b=iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmBLuuwACgkQJNaLcl1Uh9AuKQf9H/8 4ReL11d7X44Nk1eu5efZYk9hgVpcDdQw1242S2daD5+hNLdh3o40KPBVsaXOYrNwadpKW62sk38Kl 0bINJ4NqKJIg3A1si/lEihUa6q59TDJACGbkao1D9L3Niz6dTyj1Wvn7z2IFpJ09DurUtmJElb+8U ThNbucINbiNw+2JiEMSqciWj4sphCwesV7b85YKLxSykHDyLAgqETViPEl/04U4D6Tf8dbXgtilQL qxPdKu/lE+d2basubTIGTwgHqtmWOGUydlT9tDzsZK/D2wtlpl1oxM2Tm8PCkJt57Df2Pe5HOML9f nZhw8hiSAV5Yt3rMU+axdZfSiGQY9Ww== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210312_190435_148457_7183B96B X-CRM114-Status: GOOD ( 20.93 ) 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-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 When we enable SVE usage in userspace after taking a SVE access trap we need to ensure that the portions of the register state that are not shared with the FPSIMD registers are zeroed. Currently we do this by forcing the FPSIMD registers to be saved to the task struct and converting them there. This is wasteful in the common case where the task state is loaded into the registers and we will immediately return to userspace since we can initialise the SVE state directly in registers instead of accessing multiple copies of the register state in memory. Instead in that common case do the conversion in the registers and update the task metadata so that we can return to userspace without spilling the register state to memory unless there is some other reason to do so. Signed-off-by: Mark Brown --- This is a greatly cut down approach to what the changes in "arm64/sve: Improve performance when handling SVE access traps" [1] are aiming for, it should show a similar improvement in almost all cases to that series but is a very much less invasive change. [1] https://lore.kernel.org/linux-arm-kernel/20210303201117.24777-1-broonie@kernel.org/ arch/arm64/include/asm/fpsimd.h | 1 + arch/arm64/kernel/entry-fpsimd.S | 5 +++++ arch/arm64/kernel/fpsimd.c | 26 +++++++++++++++++--------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index bec5f14b622a..ebb263b2d3b1 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -73,6 +73,7 @@ extern void sve_flush_live(void); extern void sve_load_from_fpsimd_state(struct user_fpsimd_state const *state, unsigned long vq_minus_1); extern unsigned int sve_get_vl(void); +extern void sve_set_vq(unsigned long vq_minus_1); struct arm64_cpu_capabilities; extern void sve_kernel_enable(const struct arm64_cpu_capabilities *__unused); diff --git a/arch/arm64/kernel/entry-fpsimd.S b/arch/arm64/kernel/entry-fpsimd.S index 2ca395c25448..3ecec60d3295 100644 --- a/arch/arm64/kernel/entry-fpsimd.S +++ b/arch/arm64/kernel/entry-fpsimd.S @@ -48,6 +48,11 @@ SYM_FUNC_START(sve_get_vl) ret SYM_FUNC_END(sve_get_vl) +SYM_FUNC_START(sve_set_vq) + sve_load_vq x0, x1, x2 + ret +SYM_FUNC_END(sve_set_vq) + /* * Load SVE state from FPSIMD state. * diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 062b21f30f94..0f58e45bd3d1 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -926,9 +926,8 @@ void fpsimd_release_task(struct task_struct *dead_task) * Trapped SVE access * * Storage is allocated for the full SVE state, the current FPSIMD - * register contents are migrated across, and TIF_SVE is set so that - * the SVE access trap will be disabled the next time this task - * reaches ret_to_user. + * register contents are migrated across, and the access trap is + * disabled. * * TIF_SVE should be clear on entry: otherwise, fpsimd_restore_current_state() * would have disabled the SVE access trap for userspace during @@ -946,15 +945,24 @@ void do_sve_acc(unsigned int esr, struct pt_regs *regs) get_cpu_fpsimd_context(); - fpsimd_save(); - - /* Force ret_to_user to reload the registers: */ - fpsimd_flush_task_state(current); - - fpsimd_to_sve(current); if (test_and_set_thread_flag(TIF_SVE)) WARN_ON(1); /* SVE access shouldn't have trapped */ + /* + * Convert the FPSIMD state to SVE, zeroing all the state that + * is not shared with FPSIMD. If (as is likely) the current + * state is live in the registers then do this there and + * update our metadata for the current task including + * disabling the trap, otherwise update our in-memory copy. + */ + if (!test_thread_flag(TIF_FOREIGN_FPSTATE)) { + sve_set_vq(sve_vq_from_vl(current->thread.sve_vl) - 1); + sve_flush_live(); + fpsimd_bind_task_to_cpu(); + } else { + fpsimd_to_sve(current); + } + put_cpu_fpsimd_context(); } -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel