From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DD8C3CD3427 for ; Tue, 5 May 2026 16:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8pvlGeIz4wnhgCGR7um1VoK2EQsgLLVLhUgC1XznHtg=; b=1gpNXFy/UymhTQM92Z+AIjMOgN 8MfXQelDWjMUClA30mTPg2la0qZITIsSUy7HmadNPLR9/LyAcn34q0FWmD8e1XJsKjzCtjb0Bdjyd usSNDDz0q7AZ1ghC+I/4tFb3IYUW2fAq0IkF/1wKDr8Wg4N0Chwd1pJDx7NZeESIxBzFwSQj91mEX 8iTnfeqS/xwbTdCg24E6ROWZr4shzJsHfNuQkk2L6zOQnXA6/BmUOOWt6js2Qz7fBzC45hpfyOHWf rRio+Q2G/p4DklwXZt6EPqRVm9LOBc5okpmxHfU8tMOVRhLsket9aIPFsqWyjSogvsAiuh03cFnWi 74lh5DXw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wKIK1-0000000Go58-40lW; Tue, 05 May 2026 16:08:33 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wKIJy-0000000Go09-0LB0 for linux-arm-kernel@lists.infradead.org; Tue, 05 May 2026 16:08:33 +0000 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 28DB02681; Tue, 5 May 2026 09:08:24 -0700 (PDT) Received: from localhost.localdomain (e123572-lin.cambridge.arm.com [10.1.194.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6231B3F905; Tue, 5 May 2026 09:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1777997309; bh=qhiAk4es+a9hrujAuX98hvQ0rPx9R/Rfcb8FmcZAQcU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cwz5o39njUMufkFV/E0d9BSYsSXSRyEQfsh89MROrUiaAJ3fKPzBPCLmV2jNcMgkV TKtMDmvPWNszl76CME8z6Oxk9MxGe8zGwM2FZR5elYgo/eU/0yUnM+4Fp+oigj7s+2 MsKdMBhxpuw9E21Th13mvhGN5KyDk4faXlOjRrik= From: Kevin Brodsky Date: Tue, 05 May 2026 17:06:08 +0100 Subject: [PATCH RFC v7 19/24] arm64: kpkeys: Protect early page tables MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260505-kpkeys-v7-19-20c0bdd97197@arm.com> References: <20260505-kpkeys-v7-0-20c0bdd97197@arm.com> In-Reply-To: <20260505-kpkeys-v7-0-20c0bdd97197@arm.com> To: linux-hardening@vger.kernel.org Cc: Kevin Brodsky , Andrew Morton , Andy Lutomirski , Catalin Marinas , Dave Hansen , "David Hildenbrand (Arm)" , Ira Weiny , Jann Horn , Jeff Xu , Joey Gouly , Kees Cook , Linus Walleij , Marc Zyngier , Mark Brown , Matthew Wilcox , Maxwell Bland , "Mike Rapoport (IBM)" , Peter Zijlstra , Pierre Langlois , Quentin Perret , Rick Edgecombe , Ryan Roberts , Will Deacon , Yang Shi , Yeoreum Yun , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, x86@kernel.org, Lorenzo Stoakes , Thomas Gleixner , Vlastimil Babka X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1777997220; l=1150; i=kevin.brodsky@arm.com; s=20260427; h=from:subject:message-id; bh=qhiAk4es+a9hrujAuX98hvQ0rPx9R/Rfcb8FmcZAQcU=; b=ceZ8Tc3q1QQobD2wPmnrxyVPJRe6Vy2svFEKe6fDbmwCJ4eSrjWNuIiq0QYIrPVjTZSfk81sU W02DQ8PfNnJAMPnkA0VoACZYdH+p6i2wuTjpUcrNQtYJXla/WnL1wEL X-Developer-Key: i=kevin.brodsky@arm.com; a=ed25519; pk=N2QG+eJKrvkNovwhhwJhnJ4+ScVfsGCHldmqLfcMTFs= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260505_090832_037625_739FE609 X-CRM114-Status: GOOD ( 13.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use the dedicated kpkeys allocator for early page tables (used to create the linear map) when the kpkeys_hardened_pgtables feature is enabled. CPU features have not been detected at this stage so we use the early_enabled() helper. This is not a concern as kpkeys_physmem_pgtable_alloc() does not itself use POE or set_memory_pkey(). Signed-off-by: Kevin Brodsky --- arch/arm64/mm/mmu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index f79e82c0674a..4b9218483dd2 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -109,8 +109,11 @@ static phys_addr_t __init early_pgtable_alloc(enum pgtable_level pgtable_level) { phys_addr_t phys; - phys = memblock_phys_alloc_range(PAGE_SIZE, PAGE_SIZE, 0, - MEMBLOCK_ALLOC_NOLEAKTRACE); + if (kpkeys_hardened_pgtables_early_enabled()) + phys = kpkeys_physmem_pgtable_alloc(); + else + phys = memblock_phys_alloc_range(PAGE_SIZE, PAGE_SIZE, 0, + MEMBLOCK_ALLOC_NOLEAKTRACE); if (!phys) panic("Failed to allocate page table page\n"); -- 2.51.2