From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E045DCD13CF for ; Mon, 2 Sep 2024 19:08:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BA0D8D0102; Mon, 2 Sep 2024 15:08:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76A238D00E7; Mon, 2 Sep 2024 15:08:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 633288D0102; Mon, 2 Sep 2024 15:08:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4252F8D00E7 for ; Mon, 2 Sep 2024 15:08:18 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0A4E9C0551 for ; Mon, 2 Sep 2024 19:08:18 +0000 (UTC) X-FDA: 82520733876.17.DE972DE Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf21.hostedemail.com (Postfix) with ESMTP id 7A7AB1C0011 for ; Mon, 2 Sep 2024 19:08:16 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf21.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725304027; a=rsa-sha256; cv=none; b=gH2AIhiqRpp16DL7grLepbhzcMRSh4bqTipmj129iM/YUKiqJIamj6/CJ06dJcJfZ4AJrf JKJw5pidbEOPhCw5Hyv+/1PLPGugZ6f/Pa5SGx0PWX2HThrSCbOtnffPm22SoZ3qH/2lDe oJPDA0PBM4PBbzjNZAq/OHMX+IfUQ1c= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf21.hostedemail.com: domain of cmarinas@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725304027; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pn2nVuJ3P3f/HSlVJLpRyhFtgyUbvXYluAUxlc8oLnk=; b=DAAdmfGxU2nMtsBoTQMT7kzPwOcg71P0L0UzdXIym2FI1BKFla5LQz9I7wQKIFSds3m0F1 3Q3u2nrTpEpCz3uAvYSXl8kKTYEJevdM4xPDTKvQm+DSEYbui3Bg2CSDJQgaTOF8eyIInL lRl9y22E1sTsE661FU3h0qLeRvxgCoE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6BE76A431C9; Mon, 2 Sep 2024 19:08:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FCD8C4CEC2; Mon, 2 Sep 2024 19:08:10 +0000 (UTC) Date: Mon, 2 Sep 2024 20:08:08 +0100 From: Catalin Marinas To: Will Deacon Cc: Joey Gouly , linux-arm-kernel@lists.infradead.org, nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v5 06/30] arm64: context switch POR_EL0 register Message-ID: References: <20240822151113.1479789-1-joey.gouly@arm.com> <20240822151113.1479789-7-joey.gouly@arm.com> <20240823144531.GH32156@willie-the-truck> <20240823170835.GA1181@willie-the-truck> <20240827113803.GB4318@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240827113803.GB4318@willie-the-truck> X-Rspamd-Queue-Id: 7A7AB1C0011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ygwj63x8szhqt4z97rzaz1zit5e4xths X-HE-Tag: 1725304096-160707 X-HE-Meta: U2FsdGVkX19E/hx7lpXVWz8BVaetcRKvmKhVsrw1f1WPkVwCbafcKpy2vfNjaz+qpAa6o9yWOowKZXEUFullBZiellNnDxBZJaJGFkOaIzkMjScIOuQHBJjVjP9XMvMBQ9jeN1leDrYYrTYzpystVUzjynGlHyS6RrVR4OooZpqQ1e3MZtjGQAel6MhGy963qrRExuFMNa71Ns/dNOFx61CO0gP2z6plV8hIg/LC6nK3Nq4atQBVvU6EqX5j8fBC3YJMwgxLlhnnVqb18AV/BNnYqkhojmvtGxKdv07+sPwANX7+prnN9jQwnAZcNlT1oUGcb+xmUgp0snhD5jTzmx6PdMq//D84HGnf0hH5OmKaMAYuJ6EnqJmGN8ltLyKe7vaBlNwDbdJArlNSjt8elBhtp7j939Uk/NRn6R435y1AMQsdcYH4tD+tLGdou9fh+BwPy7oy5VEBsgxulyRkOJX8qlCoEj91mSdRyxc8V06js8xLvdnTgHzpEWM4SAzesjPnWIY47/ixDYf5IqybJoMr1EpDYbXWgffNncMdDsYYWVC+M8DQAh+5ZszMrQjl+P38Fd4Ctgc/hlgywpEeyDWvQVYsarGa8iFDbiKDsmUfW+15mIk3JXVnzw9cQvmDgmoLU6OLlkA8mBei/T/XYdobG0Xx/YJxLfrUJ6LwEOgrjhUBwqYAMycMmvqyTCP2R/0SOBbtQTqWMbOQzVnlq+U9qsyvxaSenLLmnkYQTtbj0eTWdnjqOgJsSbw3BYHTfsEnnDHsGDlrC/2RNp+GydXksWPnAld7buO38BW5QEInmrIQPzwdN9WhJjIXXC+jzj/vD1RQ7I0h//kUtJutOI/JrWt2BSIKapp25HtU/+dLywDEvavv2zZ9kbcxLKTPv+b0wwwNYBsNV7VPM0uBJgloWJzWxCSaue7UsLBd9iDGIzZqydOWKU/48pWjN7i5sGyzDhrjCn2oIivdvX4 YRo8cuq6 6mMyOLVj7ed6/ELIsH40U3GWlYKHxJzOrLfi+W5iBRMNN0H15fAPjrQI0sDpdoLNSOiGjAy9DITwS7ObsKWk3gKmDQGKtQC7NtUFjI3uJJgJtKLkkzdSkBXrjKxthvxRcNSLBPSW7VMnF0lAJpXIZCgQ8QePCM1FQL5II4hlyVMnB3Ol6wSSGEpWO652mE4D66/aQdsBgcVPTg9sFiK2z8jMXyhzJc2DOeZDCnUcElK3WSU1UAIHiDr645F8eXwTzfG6/0D84R0tY4X25aoMiomkc9oIveNDB50Gg5H5cExaRM9RSa9oyIyt/NGVR3y1GiGYCeLfsyAHusO+SAEsfIygBcu8ETMWJF23HaxktOpHuBDA7vh5L/tPWvPE8kabeFMSIta2rzlmrqjs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Aug 27, 2024 at 12:38:04PM +0100, Will Deacon wrote: > On Fri, Aug 23, 2024 at 07:40:52PM +0100, Catalin Marinas wrote: > > On Fri, Aug 23, 2024 at 06:08:36PM +0100, Will Deacon wrote: > > > On Fri, Aug 23, 2024 at 05:41:06PM +0100, Catalin Marinas wrote: > > > > On Fri, Aug 23, 2024 at 03:45:32PM +0100, Will Deacon wrote: > > > > > On Thu, Aug 22, 2024 at 04:10:49PM +0100, Joey Gouly wrote: > > > > > > +static void permission_overlay_switch(struct task_struct *next) > > > > > > +{ > > > > > > + if (!system_supports_poe()) > > > > > > + return; > > > > > > + > > > > > > + current->thread.por_el0 = read_sysreg_s(SYS_POR_EL0); > > > > > > + if (current->thread.por_el0 != next->thread.por_el0) { > > > > > > + write_sysreg_s(next->thread.por_el0, SYS_POR_EL0); > > > > > > + /* ISB required for kernel uaccess routines when chaning POR_EL0 */ > > > > > > > > > > nit: typo "chaning". > > > > > > > > > > But more substantially, is this just to prevent spurious faults in the > > > > > context of a new thread using a stale value for POR_EL0? > > > > > > > > Not just prevent faults but enforce the permissions from the new > > > > thread's POR_EL0. The kernel may continue with a uaccess routine from > > > > here, we can't tell. [...] > > > So what do we actually gain by having the uaccess routines honour this? > > > > I guess where it matters is more like not accidentally faulting because > > the previous thread had more restrictive permissions. > > That's what I wondered initially, but won't the fault handler retry in > that case? Yes, it will retry and this should be fine (I assume you are only talking about the dropping ISB in the context switch). For the case of running with a more permissive stale POR_EL0, arguably it's slightly more predictable for the user but, OTOH, some syscalls like readv() could be routed through GUP with no checks. As with MTE, we don't guarantee uaccesses honour the user permissions. That said, at some point we should sanitise this path anyway and have a single ISB at the end. In the meantime, I'm fine with dropping the ISB here. -- Catalin