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=-5.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no 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 95908C433ED for ; Wed, 7 Apr 2021 12:50:18 +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 2480761279 for ; Wed, 7 Apr 2021 12:50:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2480761279 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-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:Cc: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=YA5I4Gh2zTlgBbOL3Jy19GrABW8taP+qBWI5R8IArx4=; b=b5TH+IxgRmgSE+tmEFVRMKA2F L3AHtNHehj8VkcFClZmy3xAyq/VE5wrJfFeKs2HVmb7BVre9jvDZpZH7D0ThXL04Fj9PHOJWvyqOM z5st8L0J6NvcIB80qMS6bGpof3k5pG6fMFqAEOj0EcEZLV7QeAx5tOx64TrSzxwYrV2fnw+UeOQiz Gmob8bGvB/49W0yN8hzWHFkhDqfe88RDRmZM0g2cC474ky3rjjgd+SA4tJWHcSqaGTTcS29f/uD6t MarsHpvwaH+yJW+zpm5BTN2uYYI2YBaVRiKATH+e8oQh/fOCYfIT9rE7DJmilYc52M6tcUJvwyGgu uJJyFIL4A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lU7bi-004zKH-DS; Wed, 07 Apr 2021 12:48:30 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lU7bd-004zJb-Mb for linux-arm-kernel@lists.infradead.org; Wed, 07 Apr 2021 12:48:27 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id BB00561279; Wed, 7 Apr 2021 12:48:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617799704; bh=XyGw1tspWr698eJ1YH9SDAAda7yYeC/JlgdrU4lRK5o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FPxyHRLHKVPlX8UFiIx88YCsN95bh6qOsPanQ4qqEOsMWbjB94bxW7cbRNnUVcgWv BEXOTVNdfskogGK143wB6nYV68eG9q6uWL6HxFtpLv1sIxVT0cR3X049uQDKfl85Ye u4ulA9sv34bK0UyxSFp1+7RVdi0/e4ngt6gIK3xO2M06n6Ea0vu22lrhhpzo1asE8g OpWg0MUsAeQ3QYJiNSH3nL43shvKxUtoMnrqdGSDixIIbIuolidN++bFpxzSvekyEV J1wLAnlIqIvgrAaLsHyA6e2gNO45KbXsFgEVPI+EWPoUYfWZNkea/XPNBVpg1w11Qw fTh0By7IIcMFw== Date: Wed, 7 Apr 2021 13:48:06 +0100 From: Mark Brown To: Catalin Marinas Cc: Will Deacon , Julien Grall , Zhang Lei , Dave Martin , Daniel Kiss , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] arm64/sve: Rework SVE access trap to convert state in registers Message-ID: <20210407124806.GC5510@sirena.org.uk> References: <20210312190313.24598-1-broonie@kernel.org> <20210407114511.GA21451@arm.com> MIME-Version: 1.0 In-Reply-To: <20210407114511.GA21451@arm.com> X-Cookie: Dry clean only. 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-20210407_134826_222913_05A83564 X-CRM114-Status: GOOD ( 32.38 ) 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: multipart/mixed; boundary="===============6326284199705516158==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============6326284199705516158== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="p2kqVDKq5asng8Dg" Content-Disposition: inline --p2kqVDKq5asng8Dg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Apr 07, 2021 at 12:45:12PM +0100, Catalin Marinas wrote: > On Fri, Mar 12, 2021 at 07:03:13PM +0000, Mark Brown wrote: > > - /* Force ret_to_user to reload the registers: */ > > - fpsimd_flush_task_state(current); > Just to make sure I understand: in the current code, if > TIF_FOREIGN_FPSTATE is cleared and we trapped (TIF_SVE is also cleared), > the FPSIMD state is transferred to the SVE one in memory and both > TIF_SVE and TIF_FOREIGN_FPSTATE get set. The (potentially stale) SVE Right, TIF_FOREIGN_FPSTATE is unconditionally set in the current code. > state is subsequently restored via do_notify_resume(). I couldn't find > where we actually zero the in-memory SVE state or save the latest one > via do_el0_svc(). So it looks like we may restore some old SVE state > after a syscall (maybe I'm missing something but it would be nice to > follow zero or preserved approach). The state is currently converted via the fpsimd_to_sve() call in the trap handler, that *should* be dealing with anything required for conversion. You're right that this seems to miss zeroing anything outside of the values it immediately writes - I might be missing something though. It's only going to leak information from the current task and it is within the documented behaviour so it's not a bug but as such but it does seem cleaner, ought to have a memset() in there somewhere. > With your patch in the above scenario, we no longer restore the SVE > state from memory. We just flush the live SVE registers and disable > trapping. The assumption here is that (1) when TIF_SVE is cleared, we no > longer care about any of the SVE state (memory or regs) and (2) we only > trap if TIF_SVE was cleared (i.e. we don't have a different scenario of > lazy restoring where TIF_SVE but we still trap). That's fine by me and Indeed. > matches the code paths but it wasn't entirely clear in the TIF_SVE > description higher up in this file. I'm not seeing what's missing from the discussion there? It explicitly says that if TIF_SVE is set we don't trap and if it's clear then we do trap and which registers are valid in each state which I think makes the behaviour here clear but perhaps I've been looking at this too much, or you were looking for this in a slightly different place. > The other case is TIF_FOREIGN_FPSTATE being set in do_sve_acc(). Since > we never return to user with this flag set, when can we actually hit the > 'else' path in your patch? We'd have to have been preempted between entering the kernel and actually handling the access trap, I can't think of a scenario where that would happen but it seemed easier to have the code to handle it than to make absolutely sure that there was no possible case that I was missing. I think we should have the detection code either way in case it does end up happening somehow but it could be changed to use WARN_ON_ONCE() or something instead of silently handling it? --p2kqVDKq5asng8Dg Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmBtqgUACgkQJNaLcl1U h9DOewf+JDlSolVDV8Vk2PluBAMrsUYVNY1QsRET7AI3EMd28Cb93jWM2YFgT9wy j3G1yX0/Eo4HjmIXVR3tnk5GwIeIZGg9+ZKE6xncNWvPV996vJdYR9nOb+FCV7+p tKpF9b6mKT4HxmUXwC+LtYPu7OFXyP/0YEgTTA85y4MkmXV/O0H/nUwJ5U+k22Gm uWlJVdvfMJiWqigDfgzefa8BZDNDWJOcWe+2RPIvio1E3ZhnSwW+dIe0aV+s9ICD RNSrnX7eMqG8jUhczAGfTP4mMRVUn86wdBlh6zUVJ0KGwgxQrzy4V1MMOv6Mh4ep /l3DlOFMX3nfSfLSfP5tO0o1pY9Lrg== =cuFW -----END PGP SIGNATURE----- --p2kqVDKq5asng8Dg-- --===============6326284199705516158== 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 --===============6326284199705516158==--