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=-8.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 0DDF5C433E1 for ; Fri, 21 Aug 2020 21:56:31 +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 CA97E207DA for ; Fri, 21 Aug 2020 21:56:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LKOZFTLf"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Evq2/cQs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA97E207DA 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-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xdAFugb0DOxZ9MX/0tVeag/s6+3AsetpLhopYwk6z/Q=; b=LKOZFTLfmuM7ZmwcGIQyR+MUr 70yZpcEmeELbRp5ScL7beNLIEcLOZlRsZP1RQVWvyrwH8ULmYOK3u9QDIGuvcxsTOuy3d3cBc/vAq wiNWh8BpOy8HKzltlTL7eXWPuWlbxKfmLoXXySn1ZzpsgKDuPbLQlWNgOghMG5tpgGIKrDCvE1SLJ EeFnAwPQCCsClmzFTJk81jM373XhlgaON5zd9aThNAcoMdVsx1LOhtT1ntUfKAVz5YY0Q6NEFadXV j/YjclmK2XdQKEjsD6RqQRVoOtXVdKv0vuGADRAdc7y9bhhKfu0Di7Ba3sY9ueplw99o8/fAiNRdG 6Amk9CHBA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k9F00-00022T-JX; Fri, 21 Aug 2020 21:55:00 +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 1k9Ezy-00021z-GH for linux-arm-kernel@lists.infradead.org; Fri, 21 Aug 2020 21:54:59 +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 36432207CD; Fri, 21 Aug 2020 21:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598046896; bh=bL4NiA+607SPTz1dCVWcuuv/kcU/o89mP6EexJMco6Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Evq2/cQsv8aA37GwFTL9vDwi7DRKh1cfZMzhFv1D/It6ukSJQhUvyyzlCF8FuWKY3 GB1LsiDSi9yzxZ6bl/Ut7onZ9rdXZs3YQdhVDiaJzGkq9Otwa70WYcMiG7ib2d/dNy aLHzMG9a2u8D3PpwQNQKuke6w70wtaWXqr7nOy6Q= Date: Fri, 21 Aug 2020 22:54:23 +0100 From: Mark Brown To: Dave Martin Subject: Re: [PATCH v3 7/8] arm64/sve: Don't disable SVE on syscalls return Message-ID: <20200821215423.GJ4870@sirena.org.uk> References: <20200629133556.39825-1-broonie@kernel.org> <20200629133556.39825-8-broonie@kernel.org> <20200715165230.GF30452@arm.com> MIME-Version: 1.0 In-Reply-To: <20200715165230.GF30452@arm.com> X-Cookie: divorce, n: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200821_175458_676582_5C5DE602 X-CRM114-Status: GOOD ( 36.11 ) 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 , Catalin Marinas , zhang.lei@jp.fujitsu.com, Julien Grall , Will Deacon , linux-arm-kernel@lists.infradead.org, Daniel Kiss Content-Type: multipart/mixed; boundary="===============1250762964123952537==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============1250762964123952537== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="MzdA25v054BPvyZa" Content-Disposition: inline --MzdA25v054BPvyZa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 15, 2020 at 05:52:31PM +0100, Dave Martin wrote: > On Mon, Jun 29, 2020 at 02:35:55PM +0100, Mark Brown wrote: > > @@ -1163,6 +1184,17 @@ void fpsimd_restore_current_state(void) > > fpsimd_bind_task_to_cpu(); > > } > > =20 > > + if (system_supports_sve() && > > + test_and_clear_thread_flag(TIF_SVE_NEEDS_FLUSH)) { > This if() and the previous one should be mutually exclusive, right? No, TIF_FOREIGN_FPSTATE is set without looking at the SVE state in several places and we can get both set simultaneously (with fun concurrency issues which would be hard to unpick) - it basically just means a restore is needed, not that it's plain FPSIMD state in particular that needs to be restored. > It looks a bit weird to load the regs and then flush, but this won't > happen if TIF_FOREIGN_FPSTATE and TIF_SVE_NEEDS_FLUSH are never set at > the same time. The code is currently relying on task_fpsimd_load() to get the vector length and the first 128 bits of each value configured if they don't correspond to the current state. I'll add a comment explaining what's going on here and also a note in the comment documenting the new flag saying that it's valid with TIF_FOREIGN_FPSTATE and what should happen there. > > + /* > > + * The userspace had SVE enabled on entry to the kernel > > + * and requires the state to be flushed. > > + */ > > + sve_flush_live(); > > + sve_user_enable(); >=20 > Can we actually get here with SVE still disabled via CPACR_EL1 for EL0? > This might become true if future patches allow for a dynamic decision > about whether to disable SVE or flush the regs in place, but for now I > wonder whether it's possible: this patch removes the sve_user_disable() > call from sve_user_discard() after all. > Could be worth a comment, if nothing else. We will be able to after patch 8 which uses TIF_SVE_NEEDS_FLUSH in the SVE access trap. > > diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c > > index 68b7f34a08f5..aed7230b1fb8 100644 > > --- a/arch/arm64/kernel/ptrace.c > > +++ b/arch/arm64/kernel/ptrace.c > > @@ -900,6 +900,11 @@ static int sve_set(struct task_struct *target, > > ret =3D __fpr_set(target, regset, pos, count, kbuf, ubuf, > > SVE_PT_FPSIMD_OFFSET); > > clear_tsk_thread_flag(target, TIF_SVE); > > + /* > > + * If ptrace requested to use FPSIMD, then don't try to > > + * re-enable SVE when the task is running again. > > + */ > > + clear_tsk_thread_flag(target, TIF_SVE_NEEDS_FLUSH); > I wonder whether we also want to do this when loading the SVE regs. We do clear TIF_SVE_NEEDS_FLUSH when loading the SVE regs already as far as I can see unless I'm misunderstanding you? It should be redundant ATM but it seems as well to have the code handle this ATM since it's simple enough. > What happens if the task is at the syscall exit trap (so > TIF_SVE_NEEDS_FLUSH is set), and we try to update the SVE regs? Do they > get flushed again before target re-enters userspace? Setting the regs will clear TIF_SVE_NEEDS_FLUSH with the current code. > Similarly, what should we do if the tracer wants to read the regs and > TIF_SVE_NEEDS_FLUSH is set? Should we give the tracer flushed versions > of the regs? > Or is TIF_SVE_NEEDS_FLUSH always clear, due fpsimd_save() being called > when target stopped? In that case, we might reduce this to > if (test_and_clear_tsk_thread_flag(target, TIF_SVE_NEEDS_FLUSH)) > WARN(); It should be clear AFAICT. I'll add the WARN() to make sure this is being handled, it seems like should it need to be handled we should be returning flushed registers. --MzdA25v054BPvyZa Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAl9AQo4ACgkQJNaLcl1U h9ARLQf9GrYd13ijiezpdaUVBgnF5PNlpT2ZMv6eyjM12Yrh+DGSh7SmHL5Dmghy DBPCosL+B6Hf0KuV8uCrntHpBdaaaP59Yft6QE5ZBrcetVayU1v81JlJz35mVSnN KqdgXZOg8pgRK1FptrV7D5PtGfonLk+MPFl4VGYiynKaeoUyEObb6cd4kdZxWaya W5RHWmsgZtOs65n+TwSp/zjwG2u1Sd0UaCjOMG5oRup5IoH4nnwO8IPs4ZpjTEfu M5QCWcexb44GGL+GF3d7xWplU6pJ9RxxayXjQW/MIoiYDMXCXZKDJrIeFmTEwf7n FrRl6q4sPbXXuNbleW+M66VV4jNXjg== =F+Y1 -----END PGP SIGNATURE----- --MzdA25v054BPvyZa-- --===============1250762964123952537== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============1250762964123952537==--