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 1A672EEB58D for ; Thu, 12 Sep 2024 10:51:57 +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=ucU8Q63oewK+tuS4kUnV8XmPvKsCRMTocoVPaCv29qI=; b=1FOIqX9u6os3DmbSRBZIO/gXWl nsc6IWwZkwRaTF5t6aHs3a+WFoTGOX5sZSSoxxZdR4BWPYpsSsyV20aHnokWac0A61hjw1NxGzXJA 3bHFxAmqayI7T1cQJPEpXe4omL/GMNUMhapczoWPEQzxCNVu8eOJIW7qru7foqCe39gD0piXS1XXf pXjwZBuBu1RtwVO+KpBW+NsiZNm8FbtUpQ1ntlIHO1o79K09LUQTwipPpC3C3dputfcMLYWAjhngP ikS2HwqBKqHH5fD07Da6YQdMBd4IhHhWOgq0JQJ+mFOLkDtq1Q7ejLKwisJucbQ2IZ20+5TlGH+aP BGcVj/sA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sohQQ-0000000CkYH-3s2E; Thu, 12 Sep 2024 10:51:46 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sohPN-0000000CkMi-2asB for linux-arm-kernel@bombadil.infradead.org; Thu, 12 Sep 2024 10:50:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ucU8Q63oewK+tuS4kUnV8XmPvKsCRMTocoVPaCv29qI=; b=HDxEbJAKv8RRfZgIb5urTAy/Vo tf8QQxZEir1cAOMlFmNzCPPa5hpAzFIUQZ0ctaNeZ+MKTtVsIsco/anx0/3Mc8d7mcE5tvkeMWJb5 4G0bFkhkMtt8C6q8f11UiPxbBJYaBUy3Gq9B08/x5qk6iTazWVSD8xzZRAEJJG9QNU6EZ2KnzOb/2 rg4N6lppWwhCZNh98EPyl+xVj63zABJVJkjzLkY7svesCnaeRJ0FPqXhvXomdS7eWxzcQDkiZVwh/ aUwim5OtWmyIutpBhNxz7ijhmwab5U1ki1XuFKNrZTR1oXxcsk++LH7Fu/kh20rSy806cfZC8qig9 CkH4cr2A==; Received: from nyc.source.kernel.org ([2604:1380:45d1:ec00::3]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sohPJ-00000000R3x-1TDd for linux-arm-kernel@lists.infradead.org; Thu, 12 Sep 2024 10:50:40 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240912_115037_667804_64B06276 X-CRM114-Status: GOOD ( 27.11 ) 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 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