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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 28D46CD343E for ; Tue, 3 Sep 2024 14:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: 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=VjuuqLf/9rXW2UFK/uUCHtpHp+8tvUyJXh4GW6V1oSg=; b=JmXGI++BXyt6+dMcf4664Ds6+W xw2lD1AymewHPv91P3ivTwz/TG8gJXiDVGuI/apRLc2xwZIqPtfqfiQ3c1GEv0exa17of3e825xKy 0AAZG1lMmWHQUkkYyiKluRG4JofcBPasEGlp8nj4bvfmgsvxcBcslCsIsmK4d8mXLIhhTs+AdPFDF LZz3ymLoSOSJydZ3MeyZQCnWgwf/424vuv64n5aWFkxqNCB0ISsO7g8tTJH1+ccGNUzVI1ooZXRtL a+lGU3ESBdW+mTmOkpY8dRiXwvbXiLtvPZ6Gfxy5c+Slpsxu9uTmkr1hmmixBGls4dHItQvdOVMvN 94l/Xozg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slUwF-00000000hVW-0Aj0; Tue, 03 Sep 2024 14:55:23 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slUvF-00000000h5i-1Jvm for linux-arm-kernel@lists.infradead.org; Tue, 03 Sep 2024 14:54:23 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240903_075421_573852_65FAE496 X-CRM114-Status: GOOD ( 29.69 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/