Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8495610rwi; Tue, 25 Oct 2022 07:23:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7j9ou1j2MHSX8r7m/ybS7MLu6859UabZ1p1I3QFBhTtzuzakWImz87Az5arTPTOO8aSrnT X-Received: by 2002:a05:6402:1c88:b0:461:94a0:33df with SMTP id cy8-20020a0564021c8800b0046194a033dfmr14158881edb.0.1666707786824; Tue, 25 Oct 2022 07:23:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666707786; cv=none; d=google.com; s=arc-20160816; b=eo4Pzfo8/pb/yqELlXZLFX2mynkkY7cv8iNj+purOlZUscCqSHzvSk26KYEMf8b4jZ dmP4ZyGuMp69k8T1onRXlAftfGNU9mPyZ9sLkIWBBca2yKb3hv8HvrsyTda7duYY0SS9 JZSwmj3zx1fOuDeQbhKwaypGQlWcvGmaYZmVFDnepfrmhLjtPf0WeB9quqk4wjazpZ8+ xQf3bkar5WJPqbvDO5Je3Bg37kE3BmmNdrtphcIK8IISDJb0Vt1QTb06o5Msz1EA10uf aonxviYhe6Z0pH6d4B88rhjvJgcha3grXeCaoKLo3Bv8rSIqpwCs/4ny06I+Y/J5MOyj 1Osg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=Aefb2KxY8wEcsAL+nOTqxSi0oyRs3zJQN8d4KjyQNvc=; b=igNdovhaz3prFdd7gjasrqeTR++KBHXcB7dDp21GVn+qOJq0GYeGNbHnX0w9vuFku7 YHS5mwUnrOWN12ICKZ8XEwD4tgLy3KMjheZ5ufXlMxcWU5JwvWS0gYUZZ2i2qYu8GQh8 Nputu1+PKw3n1cKF5troXODtvx9E5Uq39HLRr+mh+V/fRv5uwtwIkpUEI+xKjifpbt/R 5iMfyzjsWfUMMPjZFRHCFw1OMVp+mFTtkxOUx1WAZASKYWYzwTmG0l12VVXkmBuWD8s8 XU93w+huV58UH4sdR5lTl5tTayNCS5bSlpB6w9Eu9ZD5MJVdCAvti0lrXunPZ34G2WD+ cWGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=lUXCK8FD; 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=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw30-20020a1709066a1e00b0078df3bd80b9si3224496ejc.46.2022.10.25.07.22.40; Tue, 25 Oct 2022 07:23:06 -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=@ispras.ru header.s=default header.b=lUXCK8FD; 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=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232989AbiJYON2 (ORCPT + 99 others); Tue, 25 Oct 2022 10:13:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232810AbiJYONU (ORCPT ); Tue, 25 Oct 2022 10:13:20 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68E509C7C0; Tue, 25 Oct 2022 07:13:19 -0700 (PDT) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 8142B419E9DE; Tue, 25 Oct 2022 14:13:16 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 8142B419E9DE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1666707196; bh=Aefb2KxY8wEcsAL+nOTqxSi0oyRs3zJQN8d4KjyQNvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lUXCK8FDt1OfckZRH01rWpwujnXnMfwWb9W1vnuL/a13vX/dA7f7mttzDmcDlMYcd Wm9Mb18LyqhHC0bK0YjgpXcU7g564zjgFL0KdwsJxGLRwofXtaLgU2cg0CcTJFj8UL 8L9fmyzGJ02cQvCnEka3c66FGNI3jx2Jy201XFKY= From: Evgeniy Baskov To: Ard Biesheuvel Cc: Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2 04/23] x86/boot: Increase boot page table size Date: Tue, 25 Oct 2022 17:12:42 +0300 Message-Id: <7a4ead3a0790f5b88b6e6dc2529aebe3fb5b2129.1666705333.git.baskov@ispras.ru> X-Mailer: git-send-email 2.37.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 Previous upper limit ignored pages implicitly mapped from #PF handler by code accessing ACPI tables (boot/compressed/{acpi.c,efi.c}), so theoretical upper limit is higher than it was set. Using 4KB pages is desirable for better memory protection granularity. Approximately twice as much memory is required for those. Increase initial page table size to 64 4KB page tables. Signed-off-by: Evgeniy Baskov --- arch/x86/include/asm/boot.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h index 9191280d9ea3..024d972c248e 100644 --- a/arch/x86/include/asm/boot.h +++ b/arch/x86/include/asm/boot.h @@ -41,22 +41,24 @@ # define BOOT_STACK_SIZE 0x4000 # define BOOT_INIT_PGT_SIZE (6*4096) -# ifdef CONFIG_RANDOMIZE_BASE /* * Assuming all cross the 512GB boundary: * 1 page for level4 - * (2+2)*4 pages for kernel, param, cmd_line, and randomized kernel - * 2 pages for first 2M (video RAM: CONFIG_X86_VERBOSE_BOOTUP). - * Total is 19 pages. + * (3+3)*2 pages for param and cmd_line + * (2+2+S)*2 pages for kernel and randomized kernel, where S is total number + * of sections of kernel. Explanation: 2+2 are upper level page tables. + * We can have only S unaligned parts of section: 1 at the end of the kernel + * and (S-1) at the section borders. The start address of the kernel is + * aligned, so an extra page table. There are at most S=6 sections in + * vmlinux ELF image. + * 3 pages for first 2M (video RAM: CONFIG_X86_VERBOSE_BOOTUP). + * Total is 36 pages. + * + * Some pages are also required for UEFI memory map and + * ACPI table mappings, so we need to add extra space. + * FIXME: Figure out exact amount of pages. */ -# ifdef CONFIG_X86_VERBOSE_BOOTUP -# define BOOT_PGT_SIZE (19*4096) -# else /* !CONFIG_X86_VERBOSE_BOOTUP */ -# define BOOT_PGT_SIZE (17*4096) -# endif -# else /* !CONFIG_RANDOMIZE_BASE */ -# define BOOT_PGT_SIZE BOOT_INIT_PGT_SIZE -# endif +# define BOOT_PGT_SIZE (64*4096) #else /* !CONFIG_X86_64 */ # define BOOT_STACK_SIZE 0x1000 -- 2.37.4