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 18A8FEEB58C for ; Thu, 12 Sep 2024 10:50:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7383E6B007B; Thu, 12 Sep 2024 06:50:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E8906B0082; Thu, 12 Sep 2024 06:50:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AF926B0083; Thu, 12 Sep 2024 06:50:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3E1206B007B for ; Thu, 12 Sep 2024 06:50:30 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8AC6B1A0B1B for ; Thu, 12 Sep 2024 10:50:29 +0000 (UTC) X-FDA: 82555767378.29.C7C90CC Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf24.hostedemail.com (Postfix) with ESMTP id D9D74180007 for ; Thu, 12 Sep 2024 10:50:27 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JTtjO0Cf; spf=pass (imf24.hostedemail.com: domain of will@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=will@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=1726138199; 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=ucU8Q63oewK+tuS4kUnV8XmPvKsCRMTocoVPaCv29qI=; b=frytSNlmm2AQ/meZuroBCFyGGiD79LzSBwrByu4erW7DMJXyzGA7ezp7j4saVxqfC/pv1e 7TOkeuH+g/LYT4MOPrG7lYB8b20d1csR64+um1Lz5kQ9U1ET41mLc4OiZNbDtvTShpfAaQ eDrMcQvYY+bGc1ACTWnnnBhLcYU0v1g= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JTtjO0Cf; spf=pass (imf24.hostedemail.com: domain of will@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=will@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726138199; a=rsa-sha256; cv=none; b=V5ZApAoqC/PI4x//+tgKlUUrwE98W9Et88aOoaTquwSILBjTA1fFZTbbM8Xs43VumEdEsb ZEfratSEsHsrixopi54z69ZRmZWwSJleIXj8kYnKyBHyYkQ2gGbiI7X7Vcnzz1VAdiNs6L dqyMidN6Me/Pu15QTy2RImVKGkt+r9M= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 6DACBA43DB1; Thu, 12 Sep 2024 10:50:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91F63C4CEC3; Thu, 12 Sep 2024 10:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726138226; bh=qZoGoOh6X8sZEkgedzpNuHuqZxsxfBCZB2KTDdNYKss=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JTtjO0Cfd7tkU1BMgFiga+fsrzZ9RZLla49qSZtD6IB+wb//kcv1pcCBoGV6o4I4m G1wXKo0/D/uODveW0Dj266lXbV6cEBbn8DzNEx7nGus4bUNZK5XKZHYZE/cxZmjguq h9sjj8h+uq8aq6VA2If3DNsj8fEoZ/PZYgilsV1hwIpsBp5q7mQ597FhFm9pCzPsmV WhFLRH7P9gQzrwbFzg4HfakU6ZdPiILkcPais1me+xmBZfigLQXauBvJZx0GqSMgHK M80cWMxsBzCWfU/+AfeLZt9ASKvx0eEt/Pjpfh74bKbs6F0WFUlIRAy7BMaYsMh8C/ HJW6qTM5+QJSg== Date: Thu, 12 Sep 2024 11:50:18 +0100 From: Will Deacon To: Dave Hansen Cc: Kevin Brodsky , Joey Gouly , 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, 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, 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: <20240912105017.GA22788@willie-the-truck> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6c8ad091-a56b-41ba-b403-2e3c2e578100@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspam-User: X-Stat-Signature: okiptbfkf55m5mdzjjcwks8pjbyfpssu X-Rspamd-Queue-Id: D9D74180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iw+MiFlUFWa7XNWHIq8qYhkeYravyspMlknB6Z9CWojKnBhUc+xurXJI8QUnTS+dQiHs72Tzk39GF+8Kh0+lYJdLzKy0CAKmfXSySwnBuh6TUTSymnw6r6d7l/Iva5LsdnBFGUebQKAg/SOQkUBNe0vwwcvGEmheGXigcZjhgnuZ+Zkrffi3ofcpHUPl/nAVaYDIvw== 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: Hi Dave, On Wed, Sep 11, 2024 at 08:33:54AM -0700, Dave Hansen wrote: > 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. I agree. > Either way, it would be nice to get an io_uring test in here that > actually spawns kthreads: > > tools/testing/selftests/mm/protection_keys.c It would be good to update Documentation/core-api/protection-keys.rst as well, since the example with read() raises more questions than it answers! Kevin, Joey -- I've got this series queued in arm64 as-is, so perhaps you could send some patches on top so we can iron this out in time for 6.12? I'll also be at LPC next week if you're about. Cheers, Will