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 4EAADCF9C69 for ; Sun, 22 Sep 2024 05:49:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 665986B007B; Sun, 22 Sep 2024 01:49:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EE7B6B0082; Sun, 22 Sep 2024 01:49:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48F4C6B0085; Sun, 22 Sep 2024 01:49:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 281456B007B for ; Sun, 22 Sep 2024 01:49:24 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 76ADA1C4F1C for ; Sun, 22 Sep 2024 05:49:23 +0000 (UTC) X-FDA: 82591296606.14.04A435A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id C1941180006 for ; Sun, 22 Sep 2024 05:49:21 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GMzlE5wf; spf=pass (imf06.hostedemail.com: domain of aneesh.kumar@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=aneesh.kumar@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726984102; a=rsa-sha256; cv=none; b=h5RHHeejHVnvrwm/jannurDTdkNQScrmcfQ1Xfgd65L/z+KBv5UstYLx0N6Bh2EJqumGgy pHEr4XfHZtl9k2iHpmtgzUu2Awgl7Yu6hvoXbrtH9AifSbUAsTpE70tQdGuZl0SVj/lXw3 m0HAl03nrFWop/G1nNLmwKXQZRHg8vM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GMzlE5wf; spf=pass (imf06.hostedemail.com: domain of aneesh.kumar@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=aneesh.kumar@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726984102; 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:dkim-signature; bh=KJ8GAuvRoBE4TDtP68hjGmNnnkm8bz6sL6UDzZVIijI=; b=p/EvlK5OaHW9zfLQaiOQ3v2PZx8PNbF3mXo7g2G2n6t7PZRB6MpDEtdvzd2EEMBfhbohGM LUcnRgPvp1u4ScF+FrLPa2XpDX7sODMAsCYM0aK8H5bBm6Noj4HT9vB0z41XTXAEIQKfKW hzQSWK+wqTsrwY0LQwWoMIJf5pGTDTY= 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-Stat-Signature: ndarq4qu45yj86nmbqq7a94j91ahmr7p X-Rspamd-Queue-Id: C1941180006 X-Rspam-User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lNB91KljclT1WyyVgBDLWvuI/MWPMSX3K57oQeFBDgo+gVaBu5b9E3O6CHwkpR06OwpIoBeeoSG0I+yNAWhllBlWjFrm2G2PGdizClnt6KvsD+pSsws1ZcczoLVlhrpxdcd8homg6Z9K3xTdGXN1w+5/1BjhUtPACC6fbSZNMk5ODXBQwECjyeUAFsFKm9mcQ7wMUEw== 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: 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