From nobody Sat Oct 4 15:59:06 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE5BB2E7173; Fri, 15 Aug 2025 08:56:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755248167; cv=none; b=fObiAXcHczJStGxxd9L/ubFcxJd+R8BVFt3C0cpOoZcRjbDzLHBbighVlhMguOmCuIT87Hngf4qFBnR3AASxfj38KjtXo8bDKYjYuQIG64OTaSwS+kmaHPzo3pcKIIfKnzjpmD7OW86rcP26Gigyl461p/CcsYGp7flePEvXstE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755248167; c=relaxed/simple; bh=L4s+cOmjrRIeXaCKlqYsCN5eaWROkhsJoYnk1vEKkOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OJ0XcLVKnImJHBA9b4LDskSRdsQ0XWvEuMQHS3y+lESMnfIub681XvKCl7+mMSoNsjFqCpgpxmqw2nDWuB2jEFaDkP+yk39bwgsivOQq788TVE3kxjV1+KdflNAHNuRQg217qnDj2sPFTsgPsD3TSEzPM9ADVI9kjLwoF1Zp+HA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 1BC321688; Fri, 15 Aug 2025 01:55:57 -0700 (PDT) Received: from e123572-lin.arm.com (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B4F573F63F; Fri, 15 Aug 2025 01:56:00 -0700 (PDT) From: Kevin Brodsky To: linux-hardening@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , Andy Lutomirski , Catalin Marinas , Dave Hansen , David Hildenbrand , Ira Weiny , Jann Horn , Jeff Xu , Joey Gouly , Kees Cook , Linus Walleij , Lorenzo Stoakes , Marc Zyngier , Mark Brown , Matthew Wilcox , Maxwell Bland , "Mike Rapoport (IBM)" , Peter Zijlstra , Pierre Langlois , Quentin Perret , Rick Edgecombe , Ryan Roberts , Thomas Gleixner , Vlastimil Babka , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, x86@kernel.org Subject: [RFC PATCH v5 08/18] arm64: Context-switch POR_EL1 Date: Fri, 15 Aug 2025 09:55:02 +0100 Message-ID: <20250815085512.2182322-9-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250815085512.2182322-1-kevin.brodsky@arm.com> References: <20250815085512.2182322-1-kevin.brodsky@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" POR_EL1 is about to be used by the kpkeys framework, modifying it for (typically small) sections of code. If an exception occurs during that window and scheduling occurs, we must ensure that POR_EL1 is context-switched as needed (saving the old value and restoring the new one). An ISB is needed to ensure the write takes effect, so we skip it if the new value is the same as the old, like for POR_EL0. Signed-off-by: Kevin Brodsky --- arch/arm64/include/asm/processor.h | 1 + arch/arm64/kernel/process.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/pr= ocessor.h index 61d62bfd5a7b..9340e94a27f6 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -187,6 +187,7 @@ struct thread_struct { u64 svcr; u64 tpidr2_el0; u64 por_el0; + u64 por_el1; #ifdef CONFIG_ARM64_GCS unsigned int gcs_el0_mode; unsigned int gcs_el0_locked; diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 96482a1412c6..f698839f018f 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -428,6 +428,9 @@ int copy_thread(struct task_struct *p, const struct ker= nel_clone_args *args) =20 ptrauth_thread_init_kernel(p); =20 + if (system_supports_poe()) + p->thread.por_el1 =3D read_sysreg_s(SYS_POR_EL1); + if (likely(!args->fn)) { *childregs =3D *current_pt_regs(); childregs->regs[0] =3D 0; @@ -678,6 +681,12 @@ static void permission_overlay_switch(struct task_stru= ct *next) * of POR_EL0. */ } + + current->thread.por_el1 =3D read_sysreg_s(SYS_POR_EL1); + if (current->thread.por_el1 !=3D next->thread.por_el1) { + write_sysreg_s(next->thread.por_el1, SYS_POR_EL1); + isb(); + } } =20 /* --=20 2.47.0