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 9F020CF9C6C for ; Sun, 22 Sep 2024 05:50:49 +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:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From: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=KJ8GAuvRoBE4TDtP68hjGmNnnkm8bz6sL6UDzZVIijI=; b=XugA9ghe8XRVNXJeDWAEco7+z/ M8duc3sSak8VKPAIrFrd4KSFYX3ilh5jHnqEB3dZdlOsp0vpPu7YqQU93TPy3hrVOkngBUk2Zfl4D rV0ib2tjjs8xOaahGJutyUkmrr+ctw+rmPywIY00J1ChyzxdMS8b+geC6hrttyjBZy04rf93cAxQp lh+AjtETkhYGtW0Jxu9z/mokbhlCv5nD9W+sncZCs+A58hGlsZYVBK5vz9f8JxvL9raZXd9z0BE4J hEGLuSvuOocL01vfprSLAdLHyKa6DQNnHUXAJGUAMW0HKmCivz9gDKYCzFMtwuGmR6ttVygpQG8Nh 7o9CVu5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1ssFUO-0000000EkpJ-2sVR; Sun, 22 Sep 2024 05:50:32 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1ssFTG-0000000EkjF-3L00 for linux-arm-kernel@lists.infradead.org; Sun, 22 Sep 2024 05:49:24 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7F4D45C4BF4; Sun, 22 Sep 2024 05:49:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E85BBC4CEC3; Sun, 22 Sep 2024 05:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726984160; bh=jJW9B3d+KU2/i9btemTRtY7T483RJ0ApDaKU8HYkSB0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=GMzlE5wf59FKARtlJgGs2n6P5kt5vtAqTeuh9OzKTGqWA0YNUSM/use4EZK3Gg3TN 0xlIRGf6HUJRm/EOzi9BsTj8f3/JaQhU76dvvIGb5K+P3oQvXr5gC260w+FOMGsqGA B0dLfWBFoen4Sdr91RK2j18kS7kz6ve/pGOnaB0vdKo9NItHCOlavdg5GfnPWwZwk4 w2kQ6rNTlWA26ls+omY8Jj5l7bg1VpYAwB/dHmY31O0qpj0ekunANrkaW1UVsxvc9O lIdu08TLrfzzxfRfV24zyAboJdh0Avrop6trmGiu2sl5KLRNbDjmyNWFk/bdqVRukb gdn7eRvixtCOA== X-Mailer: emacs 31.0.50 (via feedmail 11-beta-1 I) From: Aneesh Kumar K.V To: Dave Hansen , Kevin Brodsky , Joey Gouly , linux-arm-kernel@lists.infradead.org Cc: nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, 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, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v5 06/30] arm64: context switch POR_EL0 register In-Reply-To: <6c8ad091-a56b-41ba-b403-2e3c2e578100@intel.com> References: <20240822151113.1479789-1-joey.gouly@arm.com> <20240822151113.1479789-7-joey.gouly@arm.com> <425b8f8c-b6b5-422a-b5f4-41dd2d1ae3bb@arm.com> <6c8ad091-a56b-41ba-b403-2e3c2e578100@intel.com> Date: Sun, 22 Sep 2024 11:19:05 +0530 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240921_224922_947725_716CD79D X-CRM114-Status: GOOD ( 19.06 ) 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 Dave Hansen writes: > On 9/11/24 08:01, Kevin Brodsky wrote: >> On 22/08/2024 17:10, Joey Gouly wrote: >>> @@ -371,6 +382,9 @@ int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) >>> if (system_supports_tpidr2()) >>> p->thread.tpidr2_el0 = read_sysreg_s(SYS_TPIDR2_EL0); >>> >>> + if (system_supports_poe()) >>> + p->thread.por_el0 = read_sysreg_s(SYS_POR_EL0); >> Here we are only reloading POR_EL0's value if the target is a user >> thread. However, as this series stands, POR_EL0 is also relevant to >> kthreads, because any uaccess or GUP done from a kthread will also be >> checked against POR_EL0. This is especially important in cases like the >> io_uring kthread, which accesses the memory of the user process that >> spawned it. To prevent such a kthread from inheriting a stale value of >> POR_EL0, it seems that we should reload POR_EL0's value in all cases >> (user and kernel thread). > > The problem with this is trying to figure out which POR_EL0 to use. The > kthread could have been spawned ages ago and might not have a POR_EL0 > which is very different from the current value of any of the threads in > the process right now. > > There's also no great way for a kthread to reach out and grab an updated > value. It's all completely inherently racy. > >> Other approaches could also be considered (e.g. resetting POR_EL0 to >> unrestricted when creating a kthread), see my reply on v4 [1]. > > I kinda think this is the only way to go. It's the only sensible, > predictable way. I _think_ it's what x86 will end up doing with PKRU, > but there's been enough churn there that I'd need to go double check > what happens in practice. > that is also what powerpc does. /* usage of kthread_use_mm() should inherit the * AMR value of the operating address space. But, the AMR value is * thread-specific and we inherit the address space and not thread * access restrictions. Because of this ignore AMR value when accessing * userspace via kernel thread. */ static __always_inline u64 current_thread_amr(void) { if (current->thread.regs) return current->thread.regs->amr; return default_amr; } -aneesh