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 45E5FCD37B4 for ; Wed, 4 Sep 2024 12:55:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D11DE6B014B; Wed, 4 Sep 2024 08:55:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC07E6B014F; Wed, 4 Sep 2024 08:55:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA1336B014C; Wed, 4 Sep 2024 08:55:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8870B6B00DC for ; Wed, 4 Sep 2024 08:55:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3087AA0478 for ; Wed, 4 Sep 2024 12:55:15 +0000 (UTC) X-FDA: 82527051390.08.47C4508 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf05.hostedemail.com (Postfix) with ESMTP id 88E32100006 for ; Wed, 4 Sep 2024 12:55:12 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf05.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725454489; a=rsa-sha256; cv=none; b=cVadefCayjPxeEfsQXFcWRUacgcbkdwKi6/NiVRds3HQJBoKkAigGuRXBdBPcibZdQlPGU 4P1xVd2XNxCtGxEn8T/iBfD/w3IlPoUnMcA8+Lcp504k3kNUua+NqlloTfZQp3bVd8L8o+ /6GwC4GiFU8/Let07w9kMqfRJ6K6gDk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf05.hostedemail.com: domain of joey.gouly@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=joey.gouly@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725454489; 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=Vcsv9bvioKD8zrCjVbG9oMpKYf2rGSiavnM+dIHCh4w=; b=gNnZmKBDyzPiub8Qrov6DkpcHV++WKTYjFxLSxVmwiftYdhD74tCwyZYsJUJyeZsoB1c+l amUPH60LIkNekIpnabCEbto8FkAWLCZJk3hmyy26KeDH6Xuh3K6L/HIJwZai3aC+btZlND aIQHcRY0aJKHCK0boQWfT3WzhZn1pPI= 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 9FBD8FEC; Wed, 4 Sep 2024 05:55:37 -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 369393F73B; Wed, 4 Sep 2024 05:55:08 -0700 (PDT) Date: Wed, 4 Sep 2024 13:55:03 +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: <20240904125503.GA3901671@e124191.cambridge.arm.com> References: <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> <20240904113221.GA3891700@e124191.cambridge.arm.com> <20240904114301.GA13550@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240904114301.GA13550@willie-the-truck> X-Rspam-User: X-Rspamd-Queue-Id: 88E32100006 X-Rspamd-Server: rspam01 X-Stat-Signature: xyxnhxt5g4hbti6dnksn1csayup9wzc8 X-HE-Tag: 1725454512-563766 X-HE-Meta: U2FsdGVkX19RuHH/3KD1Y/yyKEcRgPbDkdv05tLbh3vQXWM/DWqBpumR6TXV06d7lT4+jSQvk3M46YPh2PvzHXG+dXrHlycELDCaOz3iDIVuDY1QtggckqXdD6QKoXAoMseeCUu2niJtNfxZMh+ZG5omTCQ8lkh6JnDDksg6uCT1aas57d/LerWurRIgjkGvwMWSj6lATqyelYJQhp4LfNpiRSAEz/XZ/FzqdN+WZ1QPFW6hdUfU0CU9nljhE3chKn+zsw544W6Ge233F/wdSKsVl44n9C0UNrmWFwg8w+NfbbAz7TvfYKA+YeOnnq1RkFSw47DYlrPEd76PDnbBWqn4ELLdn4RKRR4A8dk2NQC6PHcpbpt9375VRKBzJv/Z+vivESYI3W8K4bWOSH2cPuGiRBoUPFDYBxn2WT7wnDCS9p61cU/F4IcToNjlVPXWkc4NSN7YCy0uYhFja40VyfwZoE3yLxYszrDGSSDkyyJk/6U5NHo/5I/tPp+b1v+MutAt+5KXdUXdJgx/cHh5KjRIkADW9j5AzE+3irXQR38V3r2NeOBa+O6TyiPAwcnSRAXCu2e54btQDo2qIyHRKj/wtEDO9Ekc0VvSCz08C/JRY8j2VONZPWCCnI2GqMANGDl0h4JYJlEoq02pk+czie3kvS0r8n/SJh6/Aa8d8BDwjShU3j/ouwfPbNUU5xvz9cwid5tia2EWA1NCA8ZKpUNEFZdOsMFveQGkhIfVl0UloVbEHZsNarGe2t1mb3zqNRNlB1cZsH7Q+Y0QAoeCrXbCp0e+T9daCp6jvjUSaBCv9KszpwsB24DRZk9Qx+vyI4D5uwG2aLfkwnRh/1X44DDdfOj6vTOm81ods5eyKrVwM1NyHzVzWvllXhU9WvJ2loz8Fr2rWqwMw9cqXNGCZa/+sHt9kHzROkijAMR6BsCLN8KBF4Ye/gfnixbt0+ShwXpBrFKFgxMKw902wR7 wgCoTabB RY7eVHiGZ5AwIeLeZsv0xpBhAjrrMpmTubCJ8wkzYXvhJXwKRd3Lz9oKPJ6EHBQ1uZl2tcG44UYjDHO/GfDo7RogM3SyRnn1UnWB+bO/8EdjX/CVf1Gl5Zf0WblMinV8/t47jOgUlTagS/P0uCTP2SCcWXOa4pRmSm8RcaZnD+Ic1Y5bAGCVfBI0Wm0VhqMsgzmyMZ33lih1kcTspDfZGoc3S8dLlAq1EbD/fGHJWt/KuaFwfef1Gg6UL046EsuQZ7gbFQ9Z8WumMiP7SWlm2BgpdPA== 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 12:43:02PM +0100, Will Deacon wrote: > On Wed, Sep 04, 2024 at 12:32:21PM +0100, Joey Gouly wrote: > > 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. > > Right, there's quite a lot I need to do: > > - Uncorrupt your patches > - Fix the conflict in the kvm selftests > - Drop the unnecessary ISBs > - Fix the ESR checking > - Fix the el2_setup labels > - Reorder the patches > - Drop the patch that is already in kvmarm > > Working on it... Sorry! I'm happy to rebase onto some arm64 branch if that will help, just let me know. > > Will >