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 A4DDFCA0ED3 for ; Wed, 4 Sep 2024 11:32:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 214DC8D0252; Wed, 4 Sep 2024 07:32:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 19D488D0003; Wed, 4 Sep 2024 07:32:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0170F8D0252; Wed, 4 Sep 2024 07:32:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CCE3A8D0003 for ; Wed, 4 Sep 2024 07:32:34 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 306A9AA6AD for ; Wed, 4 Sep 2024 11:32:34 +0000 (UTC) X-FDA: 82526843028.25.7371711 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf27.hostedemail.com (Postfix) with ESMTP id 8794E40006 for ; Wed, 4 Sep 2024 11:32:31 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725449456; 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=XaneE4Zm9viCUwI2i30AJN1KzU9QhV+FZIiB7VAfzHQ=; b=7SnNzcZznRO7W1on7XO9Ful4AOkgGhpb0q+R2uqixkqjhg/6fjPiIZ+JYZnsdTv0A4cpYx Zjuw5mRMU8JhbR6l52qBwj+ChwqiNjayM0N/pJS+e7yDEIo2zf3LIr5uDwBdvjstpaZRLt RIPgDRwD6OKwnRUkskUMOODJ/4bnfcE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725449456; a=rsa-sha256; cv=none; b=zGU/CjoIPFah2sdy2hVj13MKn9Y8jl4K/2tiozkSDjTVvGJc1w68bbv2yK3ovd2fVO3VDn FNsP6aUQIJbLevSwYwi3X7xR4VJlzzcxr4QzYCPDYfEWKWENcW92GCzeRUP8XljmMreL6y ZieVCdQfifZTvonSlgqMfoFP/ay8rb8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CDB9DFEC; Wed, 4 Sep 2024 04:32:56 -0700 (PDT) Received: from e124191.cambridge.arm.com (e124191.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 356413F73F; Wed, 4 Sep 2024 04:32:27 -0700 (PDT) Date: Wed, 4 Sep 2024 12:32:21 +0100 From: Joey Gouly To: Will Deacon Cc: Catalin Marinas , 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: <20240904113221.GA3891700@e124191.cambridge.arm.com> 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> <20240903145413.GB3669886@e124191.cambridge.arm.com> <20240904102254.GA13280@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240904102254.GA13280@willie-the-truck> X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8794E40006 X-Stat-Signature: zm4kutfsyehtjr8fnnyfkfeegsrm8sfw X-HE-Tag: 1725449551-204007 X-HE-Meta: U2FsdGVkX19DxKCLXoyL62nIeNPU4W7OeMk9Cy6WnNqeMNt7V9lNOa3EzDevfrs0t7GYJ9d+I4VF4oGvIJDk6wICFQCBvkyids+gGMQMZpVcdgjolqOw3F3tr+UEL85eLceIDOnA/UlcY4RRDlpkwX9mbWNh/In/ou1+Cv0DzvwEai4UjGDmlBmEzEJIBNyTDQcPGw1nxZ+qFCypmJ9fR/gakqe9bmUjBNPWAMQOSYa97XGnEbd6mKLyvZX4X24F2nYZIUrw9hiQbmAaBdKwOyvSLfUP0NYR2eAGLUmS54vTpddytqCK3TCUKeXBMaYco33QtsxoRymikkAOWvW8Yuyj5whBO+T8VFKwoUo1yybuiCY5cMC+RAs9oCaAIXY95OZ0aEqlwol9az8Pi8hcGqnbOd66oCHnEcQVfjaQzqr2bDl9ZjcsDhVPpZ+O1hHc80kJvpvp72pthQJKLiPWd2HC3KlR1kA9L3UlnYZYa4vRO1MxNJC0HSKSqFb8+6hxRbs6ld8t5WaDi5do+BIrBIYbZC1dud2VFHDXm4SJN+t1KC27AzJ+gVTlK8Z5s9jGjkASd1QHy2exK8JD5l5eXl+1zbHAo6GZJ/j0j6yZ+sCsSlMNEpfbcV/+dlhS3/57cXRWWOliUICgpVNBRi3NnvY8RXtcwRBNbzsKuGFtBLLcegjVsyFR3lNRvadRVZlLPFDlZ3ChtFjYqKRJemWgPbJTuTFzuJW+8UWiCLGMK/gpVLt3tvbY6XFeBiHHZ6bQeBiDnPwlFK8gjDxq+WWhaTaJe8dLpKK4KDGA8bhUkJ34qz3Ni9s9QuiKdNJk7fUm2ple+Nyle26MFq/bO9+/Am6+Zjz+YsTBRl/X0WbZMnzRlnwpE/qPiDUKanD1OsblTgY3X8A39VI0kN0BIECywS6cuj7wxpgkuZPNmbDYcVLwyBYznf0+fygaA/gH9lyev25VdyC1PcxX/mVfX/d Ldc0g0QR rbtl7AQlkPBtP4P4lH28LFOUE+EmtL533Envhlvd6rTJOFihHY6elaApsq70FVeN9KdaoAgbdQVZ/8Ysw7dzzF2C88ph/YPSAeB1ZyBiDfCZKZKE5jNMYElFdQ9sbwbaLaA9m5CyewZjOvG6LJ3seZaGRWdqqFOy+UfVLNEEgHJM7u5jo7ARSFaH+xckcFKmv0VwSDu/U6cpnOHYhW5CuV+smcow34YM8P3Olb7w4LANTGsJWLQFDRHN6p5gjsO/MKpqUCaR8DrxnGK1SWM6H7EUtgA== 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 Wed, Sep 04, 2024 at 11:22:54AM +0100, Will Deacon wrote: > On Tue, Sep 03, 2024 at 03:54:13PM +0100, Joey Gouly wrote: > > On Mon, Sep 02, 2024 at 08:08:08PM +0100, Catalin Marinas wrote: > > > 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. > > > > > > > commit 3141fb86bee8d48ae47cab1594dad54f974a8899 > > Author: Joey Gouly > > Date: Tue Sep 3 15:47:26 2024 +0100 > > > > fixup! arm64: context switch POR_EL0 register > > > > diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c > > index a3a61ecdb165..c224b0955f1a 100644 > > --- a/arch/arm64/kernel/process.c > > +++ b/arch/arm64/kernel/process.c > > @@ -515,11 +515,8 @@ static void permission_overlay_switch(struct task_struct *next) > > return; > > > > current->thread.por_el0 = read_sysreg_s(SYS_POR_EL0); > > - if (current->thread.por_el0 != next->thread.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 */ > > - isb(); > > - } > > } > > What about the one in flush_poe()? I'm inclined to drop that as well. Yes I guess that one can be removed too. Catalin any comments? > > > Will, do you want me to re-send the series with this and the permissions > > diff from the other thread [1], > > or you ok with applying them when you pull it in? > > I'll have a crack now, but if it fails miserably then I'll let you know. Thanks! Just to make sure, you should pick the patch up from https://lore.kernel.org/linux-arm-kernel/20240903152937.GA3768522@e124191.cambridge.arm.com/ Not the one I linked to in [1] in my previous e-mail. Thanks, Joey