From nobody Tue Apr 7 19:57:12 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 913C2363C5E; Fri, 27 Feb 2026 17:56:12 +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=1772214973; cv=none; b=XVZc0HZk/Lkd4e7uji2BdB7mrP2LFGToMgJdJZMqEm/I01Kg4WIrE2hZ5GIN9XDeDQXMpFzr7cUyU5CQ7t5u8I5B+ae+7WaSJZvssU9BxXN4exy/lhv6C5vRF0xTvvXYHXBdWA/zwTrM3c2mxzIo0kdbv32Pl65amYLid5CIkmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772214973; c=relaxed/simple; bh=D7bIFvyFz262zpHwJ809ug5nezR6D5/ktR2+OvYES+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MQ567GB6EEozo/YxV9Ge8wgZ3y0V+oyvkisGa9vQfQvdYZOtzsg0SncgXCBic5sXrliNqFzvMl/lM/53fxCsEMkZHjI9gB71IWC6btT+SU75/6ObkczceywcB1Y+NiwmMM4wOcPm+0mFQC437QpgcTsZw/T50SgjiiCW79NQbYk= 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 601051516; Fri, 27 Feb 2026 09:56:05 -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 49FE03F73B; Fri, 27 Feb 2026 09:56:07 -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 06/30] arm64: set_memory: Implement set_memory_pkey() Date: Fri, 27 Feb 2026 17:54:54 +0000 Message-ID: <20260227175518.3728055-7-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" Implement set_memory_pkey() using POE. Signed-off-by: Kevin Brodsky --- arch/arm64/include/asm/set_memory.h | 4 ++++ arch/arm64/mm/pageattr.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arch/arm64/include/asm/set_memory.h b/arch/arm64/include/asm/s= et_memory.h index 90f61b17275e..b6cd6de34abf 100644 --- a/arch/arm64/include/asm/set_memory.h +++ b/arch/arm64/include/asm/set_memory.h @@ -19,4 +19,8 @@ bool kernel_page_present(struct page *page); int set_memory_encrypted(unsigned long addr, int numpages); int set_memory_decrypted(unsigned long addr, int numpages); =20 +#ifdef CONFIG_ARCH_HAS_KPKEYS +int set_memory_pkey(unsigned long addr, int numpages, int pkey); +#endif + #endif /* _ASM_ARM64_SET_MEMORY_H */ diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c index 358d1dc9a576..d2a7e104a5c2 100644 --- a/arch/arm64/mm/pageattr.c +++ b/arch/arm64/mm/pageattr.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include =20 #include #include @@ -359,6 +361,30 @@ int set_direct_map_valid_noflush(struct page *page, un= signed nr, bool valid) return set_memory_valid(addr, nr, valid); } =20 +#ifdef CONFIG_ARCH_HAS_KPKEYS +int set_memory_pkey(unsigned long addr, int numpages, int pkey) +{ + unsigned long set_prot =3D 0; + + if (!arch_kpkeys_enabled()) + return 0; + + if (!__is_lm_address(addr)) + return -EINVAL; + + if (pkey >=3D arch_max_pkey()) + return -EINVAL; + + set_prot |=3D pkey & BIT(0) ? PTE_PO_IDX_0 : 0; + set_prot |=3D pkey & BIT(1) ? PTE_PO_IDX_1 : 0; + set_prot |=3D pkey & BIT(2) ? PTE_PO_IDX_2 : 0; + + return __change_memory_common(addr, PAGE_SIZE * numpages, + __pgprot(set_prot), + __pgprot(PTE_PO_IDX_MASK)); +} +#endif + #ifdef CONFIG_DEBUG_PAGEALLOC /* * This is - apart from the return value - doing the same --=20 2.51.2