From patchwork Tue Oct 25 14:12:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 10819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1033003wru; Tue, 25 Oct 2022 07:15:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7r1GsliVsQ2UwHLByjkpTPH8l4wbZXeaeLNFLBxC81Ouyohy+tfitzWpLUq/KpDFrWHNLC X-Received: by 2002:a17:90b:1c0c:b0:213:1455:131f with SMTP id oc12-20020a17090b1c0c00b002131455131fmr11559945pjb.129.1666707315476; Tue, 25 Oct 2022 07:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666707315; cv=none; d=google.com; s=arc-20160816; b=BhOS0+iZLjE/o33Co4pZhe9OmUG3Q6qvfooDTtDanQ/MbY/FKxU1Ljv5m1rlfllZn4 hk822rFDC0R4B6tIHO8/ZUWs03fYjrqg5TRI6VpUXG2R2b7CUO9C/zcIy7TlC8q+PJr4 D/Ay5ODCYfNNQI/x2Ifrpfs4izUV+8ITYYTrKU+GeQJiSjzMSsDF1f85+nqItgq1qJbL ccY0SYZPzI6yK2OAmg3y7EFCIWCCJz9HgAasVXmrPNyDzlwxTU5cBN4qPLrchvTfb9LF LkB/0bhaouvef0DtuoAauowxI80fmrdSn3o7DRqCUF9s8W/vsTfwGq+oTOcevagdI5/a 8aNA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lw5-20020a17090b180500b0020a7d457b5asi14292499pjb.169.2022.10.25.07.15.00; Tue, 25 Oct 2022 07:15:15 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747669290162902857?= X-GMAIL-MSGID: =?utf-8?q?1747669290162902857?= 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