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,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 56839C433E1 for ; Mon, 29 Jun 2020 13:43:07 +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 28D8A23D67 for ; Mon, 29 Jun 2020 13:43:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1T5VRTIf"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Fz6pQsws" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28D8A23D67 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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=5Th7IwOtSbBM73zMxUJZoHcLrXvrYPGoH/OVoy7CRUw=; b=1T5VRTIf6XE3mLLTdKid4DK++ ang2Ch8q6KzUl56ETEHmmDFZCPf5Hto5ifF7SWIKufpOSqPvGsPjXY/UCg5XqQuDlyzK2FIXsCrLr krT680UHTHLk5MIe0Jm8SsG3CCwlcFFDP4eADsGC8kc24ff6ftf8b0X9wgz5ssC2hQutvzeRRGMYd BJ4V7NiiFuAtBkLWdQrCKszDvVQneTbY2TlPI4fzZBYBJHyRBnpvV6UwKP2kReotRWQxnH1JlXrl0 ESXn/glgtn++Ah6yMgvGDXjpMaC7gwo5/8dm6u2OnvDkPbfysvsnzUsJrV8GTrCxUQmHmBNsczhX3 CYFYfcdtA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpu2X-000199-St; Mon, 29 Jun 2020 13:41:41 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jpu2D-00011q-HH for linux-arm-kernel@lists.infradead.org; Mon, 29 Jun 2020 13:41:23 +0000 Received: from localhost (fw-tnat.cambridge.arm.com [217.140.96.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 87D9423B06; Mon, 29 Jun 2020 13:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593438080; bh=kn9mVxqHsZedCTgu9g2LjyQvqxI7etUp8/WpBOPEZsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fz6pQswsV0YQ58yGiCdwLWL5ivpVOnriYOsFq+Lkrewu/iA9zz1Sg2vs+TUrdGpnk dE2S63nToZfbRQXfbgtAJqsTubJoAuqSeGCG9nIoQQCcZbj1/ZQl6QJJ48eWwlxq2y TaSauzjdNeNWyTl67MJZYTDAFmkJ+2/hn3k3m5fY= From: Mark Brown To: Catalin Marinas , Will Deacon Subject: [PATCH v3 8/8] arm64/sve: Rework SVE trap access to use TIF_SVE_NEEDS_FLUSH Date: Mon, 29 Jun 2020 14:35:56 +0100 Message-Id: <20200629133556.39825-9-broonie@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200629133556.39825-1-broonie@kernel.org> References: <20200629133556.39825-1-broonie@kernel.org> MIME-Version: 1.0 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: Julien Grall , zhang.lei@jp.fujitsu.com, Julien Grall , Mark Brown , Dave Martin , linux-arm-kernel@lists.infradead.org, Daniel Kiss 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 From: Julien Grall SVE state will be flushed on the first SVE access trap. At the moment, the SVE state will be generated from the FPSIMD state in software and then loaded in memory. It is possible to use the newly introduce flag TIF_SVE_NEEDS_FLUSH to avoid a lot of memory access. If the FPSIMD state is in memory, the SVE state will be loaded on return to userspace from the FPSIMD state. If the FPSIMD state is loaded, then we need to set the vector-length before relying on return to userspace to flush the SVE registers. This is because the vector length is only set when loading from memory. We also need to rebind the task to the CPU so the newly allocated SVE state is used when the task is saved. Signed-off-by: Julien Grall Signed-off-by: Mark Brown --- arch/arm64/include/asm/fpsimd.h | 2 ++ arch/arm64/kernel/entry-fpsimd.S | 5 +++++ arch/arm64/kernel/fpsimd.c | 35 ++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h index bec5f14b622a..e60aa4ebb351 100644 --- a/arch/arm64/include/asm/fpsimd.h +++ b/arch/arm64/include/asm/fpsimd.h @@ -74,6 +74,8 @@ 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 5b1a9adfb00b..476c8837a7e5 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 ccbc38b71069..dfe2e19ce591 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -944,10 +944,10 @@ 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. + * Storage is allocated for the full SVE state so that the code + * running subsequently has somewhere to save the SVE registers to. We + * then rely on ret_to_user to actually convert the FPSIMD registers + * to SVE state by flushing as required. * * TIF_SVE should be clear on entry: otherwise, fpsimd_restore_current_state() * would have disabled the SVE access trap for userspace during @@ -965,14 +965,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); + set_thread_flag(TIF_SVE_NEEDS_FLUSH); + /* + * We should not be here with SVE enabled. TIF_SVE will be set + * before returning to userspace by fpsimd_restore_current_state(). + */ + WARN_ON(test_thread_flag(TIF_SVE)); - fpsimd_to_sve(current); - if (test_and_set_thread_flag(TIF_SVE)) - WARN_ON(1); /* SVE access shouldn't have trapped */ + /* + * When the FPSIMD state is loaded: + * - The return path (see fpsimd_restore_current_state) requires + * the vector length t be loaded beforehand. + * - We need to rebind the task to the CPU so the newly allocated + * SVE state is used when the task is saved. + */ + if (!test_thread_flag(TIF_FOREIGN_FPSTATE)) { + sve_set_vq(sve_vq_from_vl(current->thread.sve_vl) - 1); + fpsimd_bind_task_to_cpu(); + } put_cpu_fpsimd_context(); } @@ -1189,6 +1199,9 @@ void fpsimd_restore_current_state(void) /* * The userspace had SVE enabled on entry to the kernel * and requires the state to be flushed. + * + * We rely on the Vector-Length to be set correctly before-hand + * when converting a loaded FPSIMD state to SVE state. */ sve_flush_live(); sve_user_enable(); -- 2.20.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel