Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4212541rwe; Mon, 17 Apr 2023 09:22:57 -0700 (PDT) X-Google-Smtp-Source: AKy350YDRevda/mU8W0Vbpal3M7xAqQ6K+zu6Pt0I8l72dvmiULAaM+aPRJM5P3KT2iSsjC64jNr X-Received: by 2002:a05:6a00:23c1:b0:638:b77e:4a0e with SMTP id g1-20020a056a0023c100b00638b77e4a0emr24106019pfc.16.1681748577137; Mon, 17 Apr 2023 09:22:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681748577; cv=none; d=google.com; s=arc-20160816; b=QpLvP0HXsT/Qnz901KsgG6joqix31M3nSUQEDOmRF3zLDIhyb8EwHyXjkD+XF9QVMr zV2F4cdcjy1cP7b6dANnmvleuD/+8oeDCcL/wjMmYXoaMjltV5UzQLiMa2rkFWwyx3Ob i2MKlo9jmmHSkdvgkbHu1ES1DPTWSzO0pFKRGn8TcyH9EaeRGuhXx8aY7c8iTJD/PJiw Uos1ynfvidzu0bswhAXsB/GAP2Rqy+WhH+htokv/IExRmMLQhN735yFwYXIJ9vJb+xp2 Cvm6IGcq7EmyHHCNkiuIuTsWRg/Kzwqd8ABfor8IKZEaRj4zI3SazlunFKYoZRa3bJQJ QMmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=QbAPrFQ/vgZaDh5D85V0F0/ilkHZgckgDh5mNt0Q0VE=; b=TbAVFvdbdcEcoFbL6AlrKenUmSpLL7rUEwcwOllqrtxTCTOYnvDgJrl+EMikP/MqgP lmUp0Lv216eFi63f0vgkmn0/kfi8NbGVix6SSPs8n8Dymeqij7Izv5rsw+6PCCu61kTV HrhlmPOnKW4izAywCD1UeDZHrSOlGUWtLGugCWOJRGda9TEYDwic8bI65IbTePdxPWnw h1jMRq/8z54JtXH5qDNbCJgyoI0MMzp3Zlq9JJcIk69e7xYdyG6EVfQ0ZWJGxCyxuAQv 1SoKQiUHwIKWoLRtVHFjLxWAXhJKwvHHzvWn/mnAJTHlJ+9me5pGcUpvtVZ2Fu3vUrSI BZgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 128-20020a630186000000b0051f0d0d6359si624518pgb.118.2023.04.17.09.22.42; Mon, 17 Apr 2023 09:22:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229682AbjDQQSS (ORCPT + 99 others); Mon, 17 Apr 2023 12:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbjDQQSR (ORCPT ); Mon, 17 Apr 2023 12:18:17 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B063B65A5 for ; Mon, 17 Apr 2023 09:18:12 -0700 (PDT) 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 25A331691; Mon, 17 Apr 2023 09:18:56 -0700 (PDT) Received: from [10.57.68.227] (unknown [10.57.68.227]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 380B03F5A1; Mon, 17 Apr 2023 09:18:11 -0700 (PDT) Message-ID: <5219d157-27b1-c721-cb88-ce4f8f4f9807@arm.com> Date: Mon, 17 Apr 2023 17:18:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH v3 32/60] arm64: head: allocate more pages for the kernel mapping Content-Language: en-US To: Ard Biesheuvel Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Anshuman Khandual , Kees Cook References: <20230307140522.2311461-1-ardb@kernel.org> <20230307140522.2311461-33-ardb@kernel.org> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/04/2023 17:11, Ard Biesheuvel wrote: > On Mon, 17 Apr 2023 at 17:48, Ryan Roberts wrote: >> >> On 07/03/2023 14:04, Ard Biesheuvel wrote: >>> 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 4d13c73171e1e360..50b5c145358a5d8e 100644 >>> --- a/arch/arm64/include/asm/kernel-pgtable.h >>> +++ b/arch/arm64/include/asm/kernel-pgtable.h >>> @@ -80,7 +80,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, EARLY_KASLR)) >>> +#define INIT_DIR_SIZE (PAGE_SIZE * (EARLY_PAGES(KIMAGE_VADDR, _end, EARLY_KASLR) + EARLY_SEGMENT_EXTRA_PAGES)) >>> >>> /* the initial ID map may need two extra pages if it needs to be extended */ >>> #if VA_BITS < 48 >>> @@ -101,6 +101,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) >> >> I'm guessing the block size for 4K pages is PMD, so you need these extra pages >> to define PTEs for the case where the section start/end addresses are not on >> exact 2MB boundaries? But in that case, isn't it possible that you would need 2 >> extra PTE tables per segment - one for the start and one for the end? >> > > The end of one segment is the start of another, so we need one at the > start, plus one each for each segment end. Ahh, of course. Thanks.