From nobody Mon Feb 9 20:59:37 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FEAE298CDB for ; Fri, 11 Apr 2025 09:17:13 +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=1744363035; cv=none; b=nEAO+o+RJ63/ZSWVRSrq/bKoQmJueKbsn1lv8rZJ1GtxgfG6Vj9uONYl6irPqAOTlWjhdZgKhIwJUM8Mgd532DmJUwjPZM2ds0vXaA50RK/RfaDZ9Grr9oJJXEmtAerUQ06WFCJt2mizF3rygweDoc2LjKvlwK9OeIoBK9Z56AQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744363035; c=relaxed/simple; bh=q75ZUPXHeSeBj0GatwftSHk9cxcSJcb6ahGLJ9NR2oA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rLb81sR/IoRSVduz9YucBU8NL+poy2JMGpaWrZ2gbebn9myHkLFP7UWWq5Sh6unoBxuH6s24kOWvPbgFP5Lu4GpqnCV2Sb6nq0gE/8mVR/GNP+MWxHVgVIXQYz/cmU/Ec55wcdVaB8VxHkvsaUcLFiadFhFAfUiqt4hfLsJZKto= 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 3F8CD1596; Fri, 11 Apr 2025 02:17:13 -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 AC79A3F6A8; Fri, 11 Apr 2025 02:17:09 -0700 (PDT) From: Kevin Brodsky To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Kevin Brodsky , Andrew Morton , Mark Brown , Catalin Marinas , Dave Hansen , David Hildenbrand , Ira Weiny , Jann Horn , Jeff Xu , Joey Gouly , Kees Cook , Linus Walleij , Andy Lutomirski , Marc Zyngier , Peter Zijlstra , Pierre Langlois , Quentin Perret , Rick Edgecombe , "Mike Rapoport (IBM)" , Ryan Roberts , Thomas Gleixner , Will Deacon , Matthew Wilcox , Qi Zheng , linux-arm-kernel@lists.infradead.org, x86@kernel.org Subject: [RFC PATCH v4 04/18] arm64: Introduce por_elx_set_pkey_perms() helper Date: Fri, 11 Apr 2025 10:16:17 +0100 Message-ID: <20250411091631.954228-5-kevin.brodsky@arm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250411091631.954228-1-kevin.brodsky@arm.com> References: <20250411091631.954228-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 8fcf59ba39db..89a331e699d2 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1578,8 +1578,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; @@ -1593,25 +1593,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