Message ID | 71444a474b94ed69dbc4bc6b1592b10fad4e42a5.1671098103.git.baskov@ispras.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp325941wrn; Thu, 15 Dec 2022 04:39:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf43/P1pncaYrqtYBFXgGWl0su5KH+CTuMTMoSTtk/f8J2Z9JXF07UNsy0FnDneSTRb0sO5o X-Received: by 2002:a17:90b:19d7:b0:219:ccbc:ed8e with SMTP id nm23-20020a17090b19d700b00219ccbced8emr29009801pjb.20.1671107973315; Thu, 15 Dec 2022 04:39:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671107973; cv=none; d=google.com; s=arc-20160816; b=pI2HL8uww1a1qjnWxGYDeF6GwtEUH7DnhgaIUr4rFMXs/pMXPt3AKbARr/FHNzTYnM GHZxAwbCOC9E1dFBlMspgT6bVDPTNakWMVGkCD/S9M3TJLBGfgj2+DcPvyJr/A/Yyjqb 6e8oD2gkAMRUHJCB0xWD0hWkAIMPrDLHu+heXLLB8Q6MA/N/v2gl5Do25exwTc9/xDaz uOZsZFiKxYaPd0sQUYJy4gYDyGlTXqnISmWUDwK2T1fr+vlHM77/28ns/wFDPIL15LxL VOTT63V+8QIwZcF/ZTIoPvFGt88zLPwPnTfnlqPlASbppE5I6vVv3DdqioDB7/JN5o8c P+Ug== 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=1F14ng0uLHc/D7bnuLtuXVTUn3HgOEnB5AX6fPcjqBs=; b=J4m4X8axyKwYmJZlpmSNi/Y3SSD5DJGdTixePm5AOl/soKDDKnkFL3QrVmlpO7HYqL sa4KN/Ig6WE7ermDXowGRncPU94erKTt9kPIkZMdSyvAxeF/ditoAyj+2Baz9fVdZIzO /drAKFxBKaH3ycOWpdiY8eIkt8zfxvWxMOh3q9KJdo0MVC/i4X48c+NsTO91bC0GfKec NdCEzm8ffBYtoexR/heGmhjCyAWFQwKFVJcFHbQfFfdkvlXCyg61X5BzUpVQVgtkSduP GgGt7Zp2ZGagiqViBBvuqlN7S6+6m1G8DYc+IjyB5qSMf3GsT5XYRR+u+vK9AqmJ5Xtg ir3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=SZV5LPnF; 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 np9-20020a17090b4c4900b0020af2b9dd80si5131181pjb.69.2022.12.15.04.39.19; Thu, 15 Dec 2022 04:39:33 -0800 (PST) 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=SZV5LPnF; 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 S229907AbiLOMjH (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Thu, 15 Dec 2022 07:39:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbiLOMij (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 15 Dec 2022 07:38:39 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 860BE2EF73; Thu, 15 Dec 2022 04:38:25 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 2592440737A4; Thu, 15 Dec 2022 12:38:22 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 2592440737A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1671107902; bh=1F14ng0uLHc/D7bnuLtuXVTUn3HgOEnB5AX6fPcjqBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SZV5LPnFRRwOxLW9AgC7+BiUVkUyPiE5XGxWQI1ygUg2UA0XM2otaW7W/o4VWSzNt o52yfkqykKgst8Cxp/l3xrbB4k8RmuW1J3rsm8cl86lOkprezWF6Gp6Rx7mIrW/wcp qZCHZNDQvL2Pr/Brg7SJ3teeqsG4A8Mz8Gc8aFDg= From: Evgeniy Baskov <baskov@ispras.ru> To: Ard Biesheuvel <ardb@kernel.org> Cc: Evgeniy Baskov <baskov@ispras.ru>, Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>, Dave Hansen <dave.hansen@linux.intel.com>, Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Alexey Khoroshilov <khoroshilov@ispras.ru>, Peter Jones <pjones@redhat.com>, "Limonciello, Mario" <mario.limonciello@amd.com>, joeyli <jlee@suse.com>, lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 04/26] x86/boot: Increase boot page table size Date: Thu, 15 Dec 2022 15:37:55 +0300 Message-Id: <71444a474b94ed69dbc4bc6b1592b10fad4e42a5.1671098103.git.baskov@ispras.ru> X-Mailer: git-send-email 2.37.4 In-Reply-To: <cover.1671098103.git.baskov@ispras.ru> References: <cover.1671098103.git.baskov@ispras.ru> 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 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752283714175321894?= X-GMAIL-MSGID: =?utf-8?q?1752283714175321894?= |
Series |
x86_64: Improvements at compressed kernel stage
|
|
Commit Message
Evgeniy Baskov
Dec. 15, 2022, 12:37 p.m. UTC
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. Tested-by: Mario Limonciello <mario.limonciello@amd.com> Tested-by: Peter Jones <pjones@redhat.com> Signed-off-by: Evgeniy Baskov <baskov@ispras.ru> --- arch/x86/include/asm/boot.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
Comments
On Thu, 15 Dec 2022 at 13:38, Evgeniy Baskov <baskov@ispras.ru> wrote: > > 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. > > Tested-by: Mario Limonciello <mario.limonciello@amd.com> > Tested-by: Peter Jones <pjones@redhat.com> > Signed-off-by: Evgeniy Baskov <baskov@ispras.ru> > --- > 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. So you are rounding up 36 to 64 to account for these pages, right? So we should either drop the FIXME and explain that this is fine, or fix it - we cannot merge it like this. Thanks, Ard. > */ > -# 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 >
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