From nobody Tue Apr 7 19:49:35 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6CF33644BA; Fri, 27 Feb 2026 17:56:21 +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=1772214983; cv=none; b=tQInqOZwn3s5DlgYbb0FLqnbSkUDELZgirMG4+BnuYTPa4vCaCPElqdI95mtCrS59ZuWx0AFrJEfETYZmKrINiY6YtFITvBch22VW0j+tLrrKmYAzm6c7pxZkqpo7oGZBw0HSi5fPqjyrauxO4KZeYJ9Ml3NBYtR7zr0Zv87vME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772214983; c=relaxed/simple; bh=EdrvvtHwiyrZ/E6jsWM62wI7KTCsp5pd4mpliFXCjrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ot+ms/FXGDjjhnUITwUjbZ2k9Xb/+HSD8Ez+CZMc2EyVojEYbd2MJa78/I2EdMH0aqDiygXdjsjgFe5qO5dCCTFkInMRhwf2b4F77j78bE42W5ziIFQFkPntNP/8uL4jW0ViLXHtVu9I1G5xF+96pDuwZVP/32b423xHcxDF9I4= 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 BE29819F0; Fri, 27 Feb 2026 09:56:14 -0800 (PST) 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 AA6363F73B; Fri, 27 Feb 2026 09:56:16 -0800 (PST) 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 , Yang Shi , Yeoreum Yun , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, x86@kernel.org Subject: [PATCH v6 08/30] arm64: Context-switch POR_EL1 Date: Fri, 27 Feb 2026 17:54:56 +0000 Message-ID: <20260227175518.3728055-9-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: <20260227175518.3728055-1-kevin.brodsky@arm.com> References: <20260227175518.3728055-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 e30c4c8e3a7a..6095322343fc 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -192,6 +192,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 489554931231..618fb5ce1c1d 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -429,6 +429,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; @@ -679,6 +682,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.51.2