From patchwork Tue Jan 23 14:53:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13527729 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 785B5C47DDF for ; Tue, 23 Jan 2024 16:01: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:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=mSjMe1/k197A6FLeCq00zWTy1PpxLrhU5FqN4QjOEm0=; b=m0XC6qyQvaSItJUwbWlmFzffgo Zyipw1Y6JRicPH4/jo49UaC1MIxz+8VvFdhPB2vFflM9kdNCvxo0CaMtaKaJZwIdy9qIjVyky59mZ wnHpFHqBUxKGsFgUrviNGhEYCnMWSSJzRJeLoIHpTeOe+xulrPvVfz3JjIvzVcT/xAaADLlwL2Zwq Vvv7U7EqFLW3C6nDQDRSXcN0WDISW2LB4AcIAXM3pAiQzuxDhGqx6hzidBPJLYwFKKs9deY1NZp2J wRRzzbDRrC3hL+S3UDrPJuoodU4XCLPCcW36EWmGRwrdD/YSvUuMrU2q8Nw83br3jZ0d0aDS4TK77 awRUI6lg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rSJCU-00HAtP-1n; Tue, 23 Jan 2024 16:00:34 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rSIBE-00GtyM-0x for linux-arm-kernel@lists.infradead.org; Tue, 23 Jan 2024 14:55:14 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5ffac5f7afeso44952167b3.0 for ; Tue, 23 Jan 2024 06:55:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706021711; x=1706626511; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Uy1Vj/NfeSeXiLCQRi32LsAk8kkB+RPPEQasS6jcwuo=; b=DWtzlXBjUbFk/AiM0kY1wnSLUHtczKRsx7Xucjy7wpSRrWHzIJ4J6seI+ycxWeY2GW npiGnyOpQY00uRUf9grUJlZuIqhLH6/CjYdJoXmoKOTprBH76UAuS0+LjfKRqkGX8tZn 3zSDmW7CeXzECrGupe8B+dQ7g35bxBF43wk5ad/XzPUBJpnFPV16GTVnQDYFHivchp+0 qUv4J23yvUhH+kMrFleaslzarjvlDW5dooVDu6iBZoPllxVpuUEOvDLpgJxfE2hvnpIs 5OGAyCePmoxhwW8zQdberRgzIx6aTgvX10MnfocVO5lM5Vxl8UIgYk0ytwUpGJQHrAly yU1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706021711; x=1706626511; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Uy1Vj/NfeSeXiLCQRi32LsAk8kkB+RPPEQasS6jcwuo=; b=s9qWge+V10kJAeDonsaLXjXyA088/TOzMhHaJ+7cXs124zUo6TdJM2p39ECKXwBUuv p+75FS9/Ck0P4t8UYjGLXxIAOPMuP0MbLLwE64myyk4gyn/oxZMf0BLz5o9AkXgBxXNz NES4qXpNt1igmEX9Y8kawwIXW6VHhMUFxAYxpYIOdSjsmKRgJqSjuXnkd/wxBQBtSPD3 iR8yRiTzqA6pmmg+uNvuZjxeSt9/9fK546VdBbAuDRZFIhGSEHVKS5s2ay1fYLk3jgh6 ThRIYsenW2IpJZXoz3G4jEf25Um2ocDxUEyuaKBRTkDWDhiYCic7aYvNJj7hAB0tewcw sVuQ== X-Gm-Message-State: AOJu0Yw7DidQGOwi2roCfgGhWC6fl/lAftKQ90qbkvGUxxwdFERBrdM2 wa8bsofWpWi2JOwwBNj7Rn7vvR0TYY9+rd1pVCIxWa0v412FDnzaoYAkZycX7kpvVgIi06iUOzP gqxn2qdl0C22Q/cSEu+9Zl8tnR5fUZMuIFHQqgNzi85qaPQI/5WxK9fiUgGVUDUbSwWBWHtT5cP ud1Pooz6ATBsoA9Ew39hJHJMHGPYUs247l6WpgDcfJ X-Google-Smtp-Source: AGHT+IHOMSjLlgyngzm0Ir4FvJIOwJWjvz2KuUtwO3dc09qTTNSHgCBV3fA/lpFkFrLAonR/Nw0ay5IF X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a5b:a42:0:b0:dc2:46c5:649a with SMTP id z2-20020a5b0a42000000b00dc246c5649amr2594671ybq.12.1706021710786; Tue, 23 Jan 2024 06:55:10 -0800 (PST) Date: Tue, 23 Jan 2024 15:53:20 +0100 In-Reply-To: <20240123145258.1462979-52-ardb+git@google.com> Mime-Version: 1.0 References: <20240123145258.1462979-52-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1834; i=ardb@kernel.org; h=from:subject; bh=RdZd8uoP/KZBVeewE8k4d/d2vzCDE5jaFUp/FdYLmLg=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXX9pYeshnqv+Zo2GN7ZYXvVZtLh16p2xnLLHNN7b03Ku hSbcTW+o5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAExk2yRGhkOr962uOpNbOcdh yt3IGWsfaun8m3uXIfbgrN8azukqAdsY/nCsvFibeG5etlzSzw3bmzk1HOslWl2n7vOexP7rae1 6cQYA X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240123145258.1462979-73-ardb+git@google.com> Subject: [PATCH v7 21/50] arm64: head: allocate more pages for the kernel mapping From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240123_065512_375849_8866ABB0 X-CRM114-Status: GOOD ( 13.86 ) 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 From: Ard Biesheuvel In preparation for switching to an early kernel mapping routine that maps each segment according to its precise boundaries, and with the correct attributes, let's allocate some extra pages for page tables for the 4k page size configuration. This is necessary because the start and end of each segment may not be aligned to the block size, and so we'll need an extra page table at each segment boundary. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/kernel-pgtable.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h index 83ddb14b95a5..0631604995ee 100644 --- a/arch/arm64/include/asm/kernel-pgtable.h +++ b/arch/arm64/include/asm/kernel-pgtable.h @@ -68,7 +68,7 @@ + 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, EXTRA_PAGE)) +#define INIT_DIR_SIZE (PAGE_SIZE * (EARLY_PAGES(KIMAGE_VADDR, _end, EXTRA_PAGE) + EARLY_SEGMENT_EXTRA_PAGES)) /* the initial ID map may need two extra pages if it needs to be extended */ #if VA_BITS < 48 @@ -89,6 +89,15 @@ #define SWAPPER_TABLE_SHIFT PMD_SHIFT #endif +/* The number of segments in the kernel image (text, rodata, inittext, initdata, data+bss) */ +#define KERNEL_SEGMENT_COUNT 5 + +#if SWAPPER_BLOCK_SIZE > SEGMENT_ALIGN +#define EARLY_SEGMENT_EXTRA_PAGES (KERNEL_SEGMENT_COUNT + 1) +#else +#define EARLY_SEGMENT_EXTRA_PAGES 0 +#endif + /* * Initial memory map attributes. */