From patchwork Tue Mar 14 10:13:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 69437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1673707wrd; Tue, 14 Mar 2023 03:26:20 -0700 (PDT) X-Google-Smtp-Source: AK7set/PaUkb+/VlGah64U9yd3zEDrtc7ukkuKwHCQAAuW3surnW03Z+2N8p35uu/Cr7HuBy8wYX X-Received: by 2002:a05:6a21:338d:b0:cb:c4de:a20 with SMTP id yy13-20020a056a21338d00b000cbc4de0a20mr44261703pzb.55.1678789580217; Tue, 14 Mar 2023 03:26:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678789580; cv=none; d=google.com; s=arc-20160816; b=gD7ZOoFZHJ9rqeOQSY2Iuytm6Wdv5DYnv63Wvp50s8ydvol+4npwZx1TgEhlZMC+co 5336SE6DAc97nWBCbP7ZkC9q6k4VTiceGsdJBqNm6/BMNij46fOdmVIGgDHj/dYwLr/i 0IBmrNRt9d2mUTq8d/+An54qvnue/cog0bOfkjtRk8vtSKg+7xqJl8e4q3igLzTeXPjg dfqRbFTMexS5lL41IKbavrjd6MuQwvMnv9vz+1Km4690oAeIdrkIt+1j0yjbQBAA5M/M IvBDMzmL/WkCDpi5m4qPurQLmXMW5khQ1cYL3+AyBP7wrgbQmX4K/ut9Hbi0yggfoHAG spOg== 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=cFWBUuzFVvbMswZ9kJ4Z4Ih3xSnlu+Hxv2+4lFZbnHc=; b=CuUhMcvddGAVELjfnaZtC67y8EV3ektbWxMtLFO5IN1iZXHMuhyhERT4vPgHMa0DIJ xbyZzrsGXREW6zSZ/SHp+xMEGgBy/rNj64/FhxmVExZXIGLhZUJoEk5WZNrcnuAu3C6h Y/7I7DkWyHFhYn/FdZGpgjpz4aR3U58Kkstgsg8rSKEIMjd+6nDUha53q33GEELUPpez OQuuCLpudO6LG4fusvTIeJXyvCJ7R1/7vapIeAl+5Mc6dDVWMl7CoY4de0S6jr823Gna lO0NYOzpoXd8GyZvXYwszMkobsRW9pvFb3Ja2cWL535rX3WzdxzQgxRBpzHMTcbLiiao kp/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=n5rFFQU+; 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 66-20020a620545000000b0058d9266a507si1727930pff.376.2023.03.14.03.26.05; Tue, 14 Mar 2023 03:26:20 -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=n5rFFQU+; 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 S229977AbjCNKXS (ORCPT + 99 others); Tue, 14 Mar 2023 06:23:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbjCNKWn (ORCPT ); Tue, 14 Mar 2023 06:22:43 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A841B93D7; Tue, 14 Mar 2023 03:22:17 -0700 (PDT) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 431324076B3C; Tue, 14 Mar 2023 10:14:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 431324076B3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1678788841; bh=cFWBUuzFVvbMswZ9kJ4Z4Ih3xSnlu+Hxv2+4lFZbnHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n5rFFQU+Q7LukU1VZJbrAiymnkGlmrNvnMb+ciFh+N/qDexZb2DcC1Ldo7d4lQ048 g9suTTvlVA9H/oHRN8L/QLkjQsnPM42oafXHw8YLa7QXUWeWZ2lB6WgkhY39S5ARr1 0hFa3eTdXJLcB2gJA/jvNPJMgeShOklNZnFU+dNs= 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 , Gerd Hoffmann , "Limonciello, Mario" , joeyli , lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v5 04/27] x86/boot: Increase boot page table size Date: Tue, 14 Mar 2023 13:13:31 +0300 Message-Id: <92dcca146e54c6d2093be399261bb5c38d37c9be.1678785672.git.baskov@ispras.ru> X-Mailer: git-send-email 2.39.2 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?1760338462615911157?= X-GMAIL-MSGID: =?utf-8?q?1760338462615911157?= 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 Signed-off-by: Evgeniy Baskov --- arch/x86/include/asm/boot.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h index 9191280d9ea3..88836067f88c 100644 --- a/arch/x86/include/asm/boot.h +++ b/arch/x86/include/asm/boot.h @@ -41,22 +41,26 @@ # 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 number of page tables is also required for the ACPI and UEFI table + * mappings, so we round up 36 to 64. Since ACPI tables are generally getting + * allocated in a few contiguous regions of memory, they are very unlikely to be + * spread out enough to require more than 28 extra page tables and this + * would work fine in all more or less sane environments. */ -# 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