Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4211909rwe; Mon, 17 Apr 2023 09:22:30 -0700 (PDT) X-Google-Smtp-Source: AKy350YlrYN7iDVWmsgZ5ywSWjkpjI6dny0ZA+wzOljbL9lqCkf5bNGo2ngcJNUQMnZSijNrGLlj X-Received: by 2002:a05:6a00:1885:b0:639:28de:a91e with SMTP id x5-20020a056a00188500b0063928dea91emr21659116pfh.17.1681748549874; Mon, 17 Apr 2023 09:22:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681748549; cv=none; d=google.com; s=arc-20160816; b=qmeOceaAhRUix73+bAa1UTtTdYFSHEtox9nBH0o/E/EoINxVzXjzE62w4DyxBaPPMf AVXhylov/Kkm8jqZewQaUOyzBuJWjK5OwmoBsWw4wkRtymgmMvSEiCO6AVvJ9srtzi4Y bidSviY0VGJWiuQF2FLKg3InBpkgjyxWRNF+KbSf/CpKVYwpyKUaLOWIx1ILMnk1Ddzn 9P7nY5UYXKDqU42kWcxyLD9vQcEvtVhQox74G/BLpxeicHIB/8NTvOIEakhHJaZ4wGca qauyl4DzLGFJA42mniYvyBct4viYbBdzrPDLYsl4sBqbffwpbfSog6t4/vXrGJE2V5Br JanQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ZhjFdjP+zBpNqm4BSGBcqazETNy/tYxYC1M1+K+/Nck=; b=dW5FcllqRbxejDQXzGsSZULsC2W27oppEX2nmsnBGlDmeeY1ZB6XcXQeSp4U99Ji9D E05c60clNZdhzQqIe1UidvyDudNfil/QCoiR3hqQM31/LgHEOl0zMIC+Eg3XEMbwI+t6 56tY9nf3J0qh4LSgFMs07PuYwHlP3vfjL+NbqsFBKDlGtORC6FO6Q3DenWOPA1yDKoCb XptEgK6y3x8VnKyL1qIi/5BVeREROK96ZUgSqCJCaCTqWmSJmNjwErCZ8w+0QZYWWWTf OK7J1FaYlYdVf4qNg4SohrZkGlHuvRrBYPqNp717yroN7BwXMIKZByc8xVNRHJmJLnWO c/IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m3EUMWk2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a26-20020aa795ba000000b0063732344e2fsi5033942pfk.190.2023.04.17.09.22.09; Mon, 17 Apr 2023 09:22:29 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m3EUMWk2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230300AbjDQQLT (ORCPT + 99 others); Mon, 17 Apr 2023 12:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjDQQLR (ORCPT ); Mon, 17 Apr 2023 12:11:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0EC744BC for ; Mon, 17 Apr 2023 09:11:16 -0700 (PDT) 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 7B4436123C for ; Mon, 17 Apr 2023 16:11:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8342C433A0 for ; Mon, 17 Apr 2023 16:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681747875; bh=C4EGbHWRWvbf1Co/9B86Lo/bmJDEE5g2SO9siCbNkcA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=m3EUMWk2gKUfej1jQKjBD/waFLtLWtvn0ZCztXNqxWO3VRimLxys92V2GQ2DoNPDs J5bbAqDmYjYthQXTW1XU7wxuPS2NiDUEQy7aHR5cF3s6aaod2nPLzIdk6DU8LPHQRm gUOZiMVmmHuGH9s9avzdks+dvV7PgXV/zXrl+RVFmQToJo8Gjg3rBRF3B4z8GrRiGz 6G+USir5uSXdgeCBszktP4ymZchO7e+dyxoH1DCPvZDWR+d+i/dZn6hd+zYukBiRTV oRTwgSI/XqulsUikDBOpdPWSZP7d0//JXxpqNi/G/OlgPe30VNija/NOEQzIdWvyVj JysAw1FjlUDkg== Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-187878a90e6so17113156fac.0 for ; Mon, 17 Apr 2023 09:11:15 -0700 (PDT) X-Gm-Message-State: AAQBX9dKMZgEUlfEktld4MbElqdGUeqarLVlE4L2DqoEEt8IAwWP/tvZ riHWscHqYxz+GaSFwBujfJw8mTKqA08THefkFFE= X-Received: by 2002:a05:6870:7006:b0:17e:71a3:e509 with SMTP id u6-20020a056870700600b0017e71a3e509mr7324868oae.8.1681747874979; Mon, 17 Apr 2023 09:11:14 -0700 (PDT) MIME-Version: 1.0 References: <20230307140522.2311461-1-ardb@kernel.org> <20230307140522.2311461-33-ardb@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Mon, 17 Apr 2023 18:11:01 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 32/60] arm64: head: allocate more pages for the kernel mapping To: Ryan Roberts Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Anshuman Khandual , Kees Cook Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 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.