From nobody Sat Oct 4 15:59:08 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B07702E1C5B; Fri, 15 Aug 2025 08:55:46 +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=1755248149; cv=none; b=pBy9IZUOJ1ZxXinhGWIba7ClUigclLDqt1DRTlKxzlvKSHZ/H+65EOh5Bv3stH9k4gU5R64QGEhkWGxSjXblF1AZhOu6NNqAjX8SLC+gZzYwzF9fQIe06coX3lT3T6nNDfSDe4v1cqsVU+6nlxLY5UZVSZK+j7iJpcMiwVDtt1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755248149; c=relaxed/simple; bh=7iruIE0Meb58he1IeFy/w/2y/XvZVdjS3WuTdETTx7Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aDcO4hgF+2H2IZXjVjeO0sNjYYKNgS/i5fSNyvxr+LGNwYtxQoiXBsxXJJ9zG8MNLoGtqB93OBZPMBTF+3IZEeh8B3RUMPkbMW0WwK55HpTuWs5Z+9QwKkHdTazB8IiHXvdThwXlqfe974wvfB5NP481p1CJ7rVbMJ8NLeA6a5s= 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 A4FEC1E32; Fri, 15 Aug 2025 01:55:37 -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 4DA8C3F63F; Fri, 15 Aug 2025 01:55:41 -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 04/18] arm64: Introduce por_elx_set_pkey_perms() helper Date: Fri, 15 Aug 2025 09:54:58 +0100 Message-ID: <20250815085512.2182322-5-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" Introduce a helper that sets the permissions of a given pkey (POIndex) in the POR_ELx format, and make use of it in arch_set_user_pkey_access(). Signed-off-by: Kevin Brodsky --- arch/arm64/include/asm/por.h | 7 +++++++ arch/arm64/mm/mmu.c | 26 ++++++++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/arch/arm64/include/asm/por.h b/arch/arm64/include/asm/por.h index d913d5b529e4..bffb4d2b1246 100644 --- a/arch/arm64/include/asm/por.h +++ b/arch/arm64/include/asm/por.h @@ -31,4 +31,11 @@ static inline bool por_elx_allows_exec(u64 por, u8 pkey) return perm & POE_X; } =20 +static inline u64 por_elx_set_pkey_perms(u64 por, u8 pkey, u64 perms) +{ + u64 shift =3D POR_ELx_PERM_SHIFT(pkey); + + return (por & ~(POE_MASK << shift)) | (perms << shift); +} + #endif /* _ASM_ARM64_POR_H */ diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 34e5d78af076..e41ed9e0d799 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1597,8 +1597,8 @@ void __cpu_replace_ttbr1(pgd_t *pgdp, bool cnp) #ifdef CONFIG_ARCH_HAS_PKEYS int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned = long init_val) { - u64 new_por; - u64 old_por; + u64 new_perms; + u64 por; =20 if (!system_supports_poe()) return -ENOSPC; @@ -1612,25 +1612,19 @@ int arch_set_user_pkey_access(struct task_struct *t= sk, int pkey, unsigned long i return -EINVAL; =20 /* Set the bits we need in POR: */ - new_por =3D POE_RWX; + new_perms =3D POE_RWX; if (init_val & PKEY_DISABLE_WRITE) - new_por &=3D ~POE_W; + new_perms &=3D ~POE_W; if (init_val & PKEY_DISABLE_ACCESS) - new_por &=3D ~POE_RW; + new_perms &=3D ~POE_RW; if (init_val & PKEY_DISABLE_READ) - new_por &=3D ~POE_R; + new_perms &=3D ~POE_R; if (init_val & PKEY_DISABLE_EXECUTE) - new_por &=3D ~POE_X; + new_perms &=3D ~POE_X; =20 - /* Shift the bits in to the correct place in POR for pkey: */ - new_por =3D POR_ELx_PERM_PREP(pkey, new_por); - - /* Get old POR and mask off any old bits in place: */ - old_por =3D read_sysreg_s(SYS_POR_EL0); - old_por &=3D ~(POE_MASK << POR_ELx_PERM_SHIFT(pkey)); - - /* Write old part along with new part: */ - write_sysreg_s(old_por | new_por, SYS_POR_EL0); + por =3D read_sysreg_s(SYS_POR_EL0); + por =3D por_elx_set_pkey_perms(por, pkey, new_perms); + write_sysreg_s(por, SYS_POR_EL0); =20 return 0; } --=20 2.47.0