From patchwork Fri Aug 26 16:48:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12956307 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 957DFECAAA3 for ; Fri, 26 Aug 2022 16:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=i4F5aDaAU4YztIyTh8qMGxBrij//+UmqWJXXIr1yySs=; b=2G8TZaXL5sOXIS ro3GmKBjrWmQk7y/zyYcXHyRbp99k0aEKEK4cGB7p1M4ntV3nkqCIMsx+8yFmIdVrj7kP+s8VUVXy vvL5MMDwnOxboZmWCdsa0NlwJ71kd27WnewYNAqlmGNi+GJUHkXZuRwVEMlaqdKwu4FKMPJv+tI+f yaBwdsXRtinSjn3GEU0Ln749CeIfDW7eJVP1fzlQMJjoSdIe+HLFuWt+H7LTVpijaeTi0K8j6zfJ1 v3Mklzhs/+I1QJNF/vIJqMwKgZHJZQWsXGyqsxEg5aOuBNeIJ5vt0YBmHOFyrKsFSzJBqtIpbku9e j9WF1ZOJQh2vEyFOMZsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRcWE-008aY0-Tc; Fri, 26 Aug 2022 16:49:19 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oRcWB-008aQ1-4W for linux-arm-kernel@lists.infradead.org; Fri, 26 Aug 2022 16:49:16 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A6162615E9; Fri, 26 Aug 2022 16:49:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 801D2C433D6; Fri, 26 Aug 2022 16:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661532554; bh=RWaMVLf7scZll7gE8nnybNiPTlA1e7xs2pNOspfC4p8=; h=From:To:Cc:Subject:Date:From; b=Tjg7DxSk0vOJN10rHHxgGrYRsJaNp9gZRpM9SQbqjSN9Ayg+z8qh7lz5OaWF/zWnY g3lY/SV5N5UUZ4w95Cjgh5AjrfAB/Jys59Uz+IgyfqUJ7eShFs7ZItVfK27QDren7h rAvUkN+rzwKbBvmTRfNqh2aEjv/0fviEJo34sQeGYEKML+QyAFVxXE81qR2Ag6cm9k U9Wla3Y+aS+K2hLMsfIUaYy6T0Q3BI01OtJ5jh6kMQ21pAU/qxR4Pm0tMpAXMWywAU DuEbx3j6gxOAx+6wYl6LdjXW4IHAuUtAA5gzy6pBbzgsqBTpKymH2qm332SnwgtCZv 2kiVE9EPLdEWg== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, maz@kernel.org, keescook@chromium.org, Ard Biesheuvel Subject: [PATCH] arm64: mm: Reserve enough pages for the initial ID map Date: Fri, 26 Aug 2022 18:48:00 +0200 Message-Id: <20220826164800.2059148-1-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3309; i=ardb@kernel.org; h=from:subject; bh=RWaMVLf7scZll7gE8nnybNiPTlA1e7xs2pNOspfC4p8=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjCPk/Dy8slXbXDGZE2HL6DwiOMD6P2oT/Tu9OIbNK Teil/Y6JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYwj5PwAKCRDDTyI5ktmPJL0sC/ 93wE4rIx/v6v/V4815MzBNC7VelV4sWDlA+yr0srUZ/f7Y4LbihH29qFg84YP8koWHAPU40zRLGhs9 +0NfgEOL9u7G6kL02f6pFDZ5FQRarR0yv7jD5E6wnIDxK6dp9RtE1v4aClkwNuxymqfmsZeMmHaYr0 RPqGjIDtqRrxNbBBzwLoa2AVnIL0CskvKdjJShc10Tt703Pn5DbAgeXCWcMV+4VqNy0nNormNX3njK ZDy0ZETlp8bJEIzkn/WjL4F/qnpF+hmaubDcIwU0F3e+4CQmm6NYqBPBucoEBe7zhHW2PB2AaHAvf/ 8j/3CiPhkDkKHjNYkrr3e87ofsUkLHAAZWqG8+QK47O5TnjTYA5XfvHFZZ195rdsocU6V5Fjkk5/MD l7S/5ivMzHDxSSYrd9WUtRtzI/9xzius9oWztGvHZ3fMKwL2v256ca5qqXbx0MPRII79Zk0ypSvzba z8xUU32xkV5A4veNU7QkM/mlsu7TohsbV1MpWkbx5xh2E= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220826_094915_274754_13760D4E X-CRM114-Status: GOOD ( 14.38 ) 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 The logic that conditionally allocates one additional page at each swapper page table level if KASLR is enabled is also applied to the initial ID map, now that we have started using the same set of macros to allocate the space for it. However, the placement of the kernel in physical memory might result in additional pages being needed at any level, even if KASLR is disabled in the build. So account for this in the computation. Fixes: c3cee924bd85 ("arm64: head: cover entire kernel image in initial ID map") Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/kernel-pgtable.h | 26 ++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h index 02e59fa8f293..32d14f481f0c 100644 --- a/arch/arm64/include/asm/kernel-pgtable.h +++ b/arch/arm64/include/asm/kernel-pgtable.h @@ -64,28 +64,28 @@ #define EARLY_KASLR (0) #endif -#define EARLY_ENTRIES(vstart, vend, shift) \ - ((((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1 + EARLY_KASLR) +#define EARLY_ENTRIES(vstart, vend, shift, add) \ + ((((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1 + add) -#define EARLY_PGDS(vstart, vend) (EARLY_ENTRIES(vstart, vend, PGDIR_SHIFT)) +#define EARLY_PGDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, PGDIR_SHIFT, add)) #if SWAPPER_PGTABLE_LEVELS > 3 -#define EARLY_PUDS(vstart, vend) (EARLY_ENTRIES(vstart, vend, PUD_SHIFT)) +#define EARLY_PUDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, PUD_SHIFT, add)) #else -#define EARLY_PUDS(vstart, vend) (0) +#define EARLY_PUDS(vstart, vend, add) (0) #endif #if SWAPPER_PGTABLE_LEVELS > 2 -#define EARLY_PMDS(vstart, vend) (EARLY_ENTRIES(vstart, vend, SWAPPER_TABLE_SHIFT)) +#define EARLY_PMDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, SWAPPER_TABLE_SHIFT, add)) #else -#define EARLY_PMDS(vstart, vend) (0) +#define EARLY_PMDS(vstart, vend, add) (0) #endif -#define EARLY_PAGES(vstart, vend) ( 1 /* PGDIR page */ \ - + EARLY_PGDS((vstart), (vend)) /* each PGDIR needs a next level page table */ \ - + EARLY_PUDS((vstart), (vend)) /* each PUD needs a next level page table */ \ - + EARLY_PMDS((vstart), (vend))) /* each PMD needs a next level page table */ -#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end)) +#define EARLY_PAGES(vstart, vend, add) ( 1 /* PGDIR page */ \ + + EARLY_PGDS((vstart), (vend), add) /* each PGDIR needs a next level page table */ \ + + EARLY_PUDS((vstart), (vend), add) /* each PUD needs a next level page table */ \ + + EARLY_PMDS((vstart), (vend), add)) /* each PMD needs a next level page table */ +#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end, EARLY_KASLR)) /* the initial ID map may need two extra pages if it needs to be extended */ #if VA_BITS < 48 @@ -93,7 +93,7 @@ #else #define INIT_IDMAP_DIR_SIZE (INIT_IDMAP_DIR_PAGES * PAGE_SIZE) #endif -#define INIT_IDMAP_DIR_PAGES EARLY_PAGES(KIMAGE_VADDR, _end + MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE) +#define INIT_IDMAP_DIR_PAGES EARLY_PAGES(KIMAGE_VADDR, _end + MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE, 1) /* Initial memory map size */ #if ARM64_KERNEL_USES_PMD_MAPS