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 4328ECD343D for ; Tue, 3 Sep 2024 14:54:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE3788D018D; Tue, 3 Sep 2024 10:54:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9C8C8D018A; Tue, 3 Sep 2024 10:54:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B33A98D018D; Tue, 3 Sep 2024 10:54:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 939B88D018A for ; Tue, 3 Sep 2024 10:54:21 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 353211404D8 for ; Tue, 3 Sep 2024 14:54:21 +0000 (UTC) X-FDA: 82523722722.12.34FCAB0 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf29.hostedemail.com (Postfix) with ESMTP id 804A7120004 for ; Tue, 3 Sep 2024 14:54:19 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.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=1725375164; 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=VjuuqLf/9rXW2UFK/uUCHtpHp+8tvUyJXh4GW6V1oSg=; b=UlNczG1fCGfOfJkiVtNVCoaEfZ0fwkUpggG5u7Y/AFr2iWfFR6AxKIhnfTlb9+ejoPxkR+ SqIw91U9ocMPvqC0rTwHS3PRKr2clpSRsZ3JxPKxs5AV6qztp20wRufmmkMWO5rit9aW99 cOzRmh3oZ2NrvB9ND381NDfoYr2oHuU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725375164; a=rsa-sha256; cv=none; b=wQU1g+cZgvrVAm+nAvDjGFgHrBqSk2twYCeAn8/+q6oJpqph6LGbiZP2bOeIBMpiwtSSqI 8PJuIvwRHjxofecjGkI8Hd869mPD/hLO1u1hXG+rl2+jPzHhe6gdzumX6T53Gw5hTuC781 OEPxiqnMfHqCKndU2h/K9JsJfmy3EDA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.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 E4FE4FEC; Tue, 3 Sep 2024 07:54:44 -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 37AF13F66E; Tue, 3 Sep 2024 07:54:15 -0700 (PDT) Date: Tue, 3 Sep 2024 15:54:13 +0100 From: Joey Gouly To: Catalin Marinas Cc: Will Deacon , 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: <20240903145413.GB3669886@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: 8fibdg15t1j1pwder3dmit4o8gppa3bu X-Rspamd-Queue-Id: 804A7120004 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725375259-203205 X-HE-Meta: U2FsdGVkX1/McoNL3w6gApXKCl20X1lCFcMfn65OAhffIh+IWde6d4bt8nQ2VvQiCRrpuLZhXK1Rsw3PKZQ7dKltLM2Qqq9y1QKkrD4qkl+zTOKokpk3JJ5fOf73F+8jtufqH2luc2QhlVlmKBe+d5nBfVmt7ifrRawF0rapQDUlCfRGqEoQccH/n0imXr3fXx0te9tc78JWQCRkRWXplPJLPPZKEpXhWk5HsUfmDmgVKN80uadBTb3DgwQ7VxdrlwX2UtyBTD2vVDrmOWfhsZ+ZS4VoePh2U+ChJ0l+ugYwBrDDX/2kVCUa63CGjFbgj4Z93rsvyODzmQIomyfM/Y9WkzCCDHeCDtPFH3KbFyDSdoo9ld0Fu9u0XdB8RTgLqEIZdzlnVqwlqT4dHHnJ7X/zXHKa+X2KpuR7NjjNsqn2upgyoeirCD3hwDrFDsV/JHPU+EaQ7CXb5b6jp8xxRJppvqMt/YQPz9LETGED++xM/b/3XvjdGaDKG/8qB7NBhAi+MtjV6AM2qU1Zyz/Um+nRzVBFKpVn5KlE/B8S0xlq1zuujv7QUCzzsFfS9x8gU3kqTsOMVH0c+gzL7+9pt8FnlRr8yXb8krIb6KUOuZgTWYwKHSrU2/oGXVSk7yoe77qLAJ5aGkehoFBLjGiCUk3zFD49V3Yl/CRfJaPF6+n5EbhQs5WJBaw5j3yNEb0yqu9MLfTtupJ+18XNk9T9/kOQIzG3tttGnVXa5eiX8c6xTiYzexlHRkycs7eh73OKy0uxfZ7jxhaQnZaz2UH4ETxcrI1TsizCflMFh+uCBw2Ut1K+9dcdJB/JhUleScmv340frWHmNp54lSRaEDQzWNdoDOaQZgtoNlExnGAcEMwZml0nOrpl+Md1OieY4h+Sx/T1ip83uOUKsfXSw/KR0F2uqdvQKeOmd8Lhxg40rnR+n6n18jKLnnU2JtHM3QGoetk6do/U80qyk8pQCZ7 mzGyfbVr nekTKSpO2oo1peaQsDhWGRprPd8mc8CBWBaKQq1rJq0sTFrSpMjj9k6vvv1/6PNx38voD0lIeOjheSezG4XqfilpRciwcr09J4/3syD9bzCDkHwyrR5YzP8y/aZ/PZzA7WVoDj3X8cSNv3sAVe28sM7kjbgzEJBEeSIB7nM+9juNXdWl6uMtpPbvP9n/8AR9VjmHwf+Cl94r79lKyDEy/HVuUHCT14b6PkCV7rW6ELk4QGgpn9pkN2nN2JtZE+jXUX2e3T9gIRVOZF12kuLLiOzI9K3AHwaJNPyM35qWwuhT++ia2By+0/V39Pw== 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 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(); - } } /* 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? Thanks, Joey [1] https://lore.kernel.org/all/20240903144823.GA3669886@e124191.cambridge.arm.com/