From patchwork Tue Nov 22 11:12:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeniy Baskov X-Patchwork-Id: 24272 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2137973wrr; Tue, 22 Nov 2022 03:15:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf73HVG6vksZCq5uctDiFKIZ/8ag10VpU4Eglfe2eDekTOnIOS8VTh6NEgH6l+ADc5tmMYwS X-Received: by 2002:a05:6402:1a2e:b0:461:2915:e41d with SMTP id be14-20020a0564021a2e00b004612915e41dmr20288482edb.184.1669115756565; Tue, 22 Nov 2022 03:15:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669115756; cv=none; d=google.com; s=arc-20160816; b=nj6CWpDbMe6E0r8RIRtmtMbn3Aj1MhyY7jLEYSXpyipnShin30C3ovSjlc19mAiTZy xxVqtzN+tKpp7roVj63o/0jk51lGtjcwJ4org0s2xa/peRcccVxvfTSzlGxQesLC/IHb N/RBG5+66cYc+2jlXlKxlVx7UliYElFI/DfnfuOavALxAZvC/fV2xDcI16aSQr/fqCB4 Zr27oMrfG8VQINgS3TiaFjG2goliXZvnljp1xF23vp6jyNfQVd1LvdACDJy/qASJAdP/ NQDZ7cQfOhvv9tLGBOMcA4k67W6kHanEpJwbK3bK2Et4blgwCYO+1KY2V+9uKG17nUvD eLeQ== 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=2OgHhvX0+NKEpZn5NMyzaoGQPiwdR+Cd155qSqPChrY=; b=YRjy2D0kfr3yi7dWJ/cK+plHmX8LEMNM1YPUyuqXs6Wje8l5A97qv6QT183eDWGPTu zaWTyzVcTLQmBvtdSgk8qy9FOAM1ZWiSGRYNM7v1sfto+vbzT7QN0emmuS7qVhjI1UCs RIeT/au945X413gKEs4G/J6aOUfMdBDii0L2aUhwXqOQkmTysb3iuhwSHkvAK4yXcrFv bOduZC98B21lhOM1VT5s8hOd7WdVlamHpJsCmhib6TRB/C/GS1tpLeg+DmenR3WaQ67d 9QurzuPqttozFv6UTk52lK2zoK5cMPrPW4qnMh07bjmFVjnEyjm+BqsNKP2XQh89RCW8 3GkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=KLz8q0MM; 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 hs40-20020a1709073ea800b007ad976163f4si344188ejc.254.2022.11.22.03.15.32; Tue, 22 Nov 2022 03:15:56 -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=KLz8q0MM; 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 S233060AbiKVLNB (ORCPT + 99 others); Tue, 22 Nov 2022 06:13:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232523AbiKVLMq (ORCPT ); Tue, 22 Nov 2022 06:12:46 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83471D8F; Tue, 22 Nov 2022 03:12:44 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 1F10140737BC; Tue, 22 Nov 2022 11:12:41 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 1F10140737BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1669115561; bh=2OgHhvX0+NKEpZn5NMyzaoGQPiwdR+Cd155qSqPChrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KLz8q0MMIyC5hmzfbPOkVty4Msd4Og74V5Gkwmoa+152kRZT4ObOLpYa+KPyaSCC5 hDzv+vG5RFomXnx1ZY/eM0iNu6NArTDIEqUM68/mURRV9c5nuTYHh84Rrh8RxW+rqH HtkloXpaE8sxoWT6kHcXu/UjK9LdvX9DCSw2W5n4= 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 , "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 v3 04/24] x86/boot: Increase boot page table size Date: Tue, 22 Nov 2022 14:12:13 +0300 Message-Id: <5fe439aefdbbe52908512f5229d975dbd7780628.1668958803.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 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?1750194723575879314?= X-GMAIL-MSGID: =?utf-8?q?1750194723575879314?= 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 | 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