Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4126517rdb; Thu, 14 Sep 2023 12:33:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhp4KAZeELCefRK9dWpaXi/kO2sfi37Posyl6xPJXFZNq3VqFGpZKjLbQRHoTIjtXkyepB X-Received: by 2002:a05:6300:808a:b0:159:b7a6:38da with SMTP id ap10-20020a056300808a00b00159b7a638damr3704219pzc.0.1694720021507; Thu, 14 Sep 2023 12:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694720021; cv=none; d=google.com; s=arc-20160816; b=PRbra6/G+schlfWMWdeKF3c9HDoGiCYVvv6gKMCY9H/ZTYG5i/iFQ5fNMxJShjDCvc ztMsgBlIRTKfZ1IFg9LrD1VBSoW1PtrzgvB026IVPEYPdioV634aKyiO1/ODhrVss1n8 UZpUoYgI64Rsp90CRUCV1M8uxrmmEusQ15UmaCtMtQcC7KM2J9n7gRZiEqD05AlRxU8l dmc5NGs4uyP+s0Hn9L9DA5rsUgEmAarUrKAiE3O8/8V9qOe/oULaeV0D7GNTgKZw6Te3 5ydd85KOXm+0eeC3ySNqtLohleQj4xceaY4zgWPL6OAHqC0U5BU8RexrmNSegAYNi7/4 i5aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=o44G06hAJziml8pp0cuaTUEtEYfmyNkmKHXY38oO1WM=; fh=eI8NuVgVZIMU0Sz3ncHar3b9YX+y3ExSczt5ociPVdQ=; b=X9bcBL8MFOIdexSt0jT9eDRM1o1e5GmVrUoadlyQUoeAHEqZK1BPoRdO4J/k0Rc2ee WjqbuVF6W0hU7tAlcX+6vbApdfegZKmV1pLhz0ylPK4p37QwGA39xemdKD3PqN1GSgCr bNItukDOnniKii3gzGfd4rc9ffYRIBDAD8H+hTH6hE0ajpBF+GnFzN8YXy3G2+ZrtMNi KIL1xI9xsHQckYfUR3VzAYAwaJTUIboyeUelWB32cDvHGIZdnPSbdv21yTzhBKjGXrJY SD11+BptrPNs2mmPgh1WliyRhDsW8VoDN78TWrAMAIcY9FPSIjB8ezpBuXCiCdwNYTtB RIAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RMsZxdwU; dkim=neutral (no key) header.i=@linutronix.de header.b=Ho8CWlgG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id bz34-20020a056a02062200b00565f7f1eacdsi2246465pgb.80.2023.09.14.12.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 12:33:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RMsZxdwU; dkim=neutral (no key) header.i=@linutronix.de header.b=Ho8CWlgG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0743182F3481; Thu, 14 Sep 2023 07:22:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239984AbjINOWe (ORCPT + 99 others); Thu, 14 Sep 2023 10:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239861AbjINOWd (ORCPT ); Thu, 14 Sep 2023 10:22:33 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62541D7; Thu, 14 Sep 2023 07:22:29 -0700 (PDT) Date: Thu, 14 Sep 2023 14:22:26 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1694701347; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o44G06hAJziml8pp0cuaTUEtEYfmyNkmKHXY38oO1WM=; b=RMsZxdwU0Mj2Rk539pjdzWvKAWrCLvdESw/Ncy+zz5ApNm2i8NPsi+zszMmwSlECgrJVH8 8Rxw+bTSsZn6+ovHmIiVsY63EW4CYfv41MIdeMgHn8sCTHm4bz7hxI0E8o7LNeRvF9ajYn v9xmKMsz98ujOa21UPVWO4n4RFVRzjvOEFgST6CC1MxFmQGUdbDXJYjW0qGGtxtEABHDbc P6fAs6DZ5+Pb7XUhnD8lBpdfTs/C58c7DceCviY9GaXQDUVQgofovCXKmuS4ND2PvX8QKZ TTrymiRZok1/8kdGMXeyBK70icWTshGIPuITKxI2CJD5l+A/IoVnVdp4UVquEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1694701347; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o44G06hAJziml8pp0cuaTUEtEYfmyNkmKHXY38oO1WM=; b=Ho8CWlgGmZiQAYPycuqAmvGz+WOk7HTNgg87JaqsLjE9UPyG8/YVucIgUO+uC11fu+b3/K NruSPm/CozCYutCw== From: "tip-bot2 for Kirill A. Shutemov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/boot/compressed: Reserve more memory for page tables Cc: Aaron Lu , "Kirill A. Shutemov" , Ingo Molnar , Linus Torvalds , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230914123001.27659-1-kirill.shutemov@linux.intel.com> References: <20230914123001.27659-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Message-ID: <169470134628.27769.10667514395726055409.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Sep 2023 07:22:41 -0700 (PDT) The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 7362132a6408d23244b95025ea85dd3dc41e5332 Gitweb: https://git.kernel.org/tip/7362132a6408d23244b95025ea85dd3dc41e5332 Author: Kirill A. Shutemov AuthorDate: Thu, 14 Sep 2023 15:30:01 +03:00 Committer: Ingo Molnar CommitterDate: Thu, 14 Sep 2023 16:12:28 +02:00 x86/boot/compressed: Reserve more memory for page tables The decompressor has a hard limit on the number of page tables it can allocate. This limit is defined at compile-time and will cause boot failure if it is reached. The kernel is very strict and calculates the limit precisely for the worst-case scenario based on the current configuration. However, it is easy to forget to adjust the limit when a new use-case arises. The worst-case scenario is rarely encountered during sanity checks. In the case of enabling 5-level paging, a use-case was overlooked. The limit needs to be increased by one to accommodate the additional level. This oversight went unnoticed until Aaron attempted to run the kernel via kexec with 5-level paging and unaccepted memory enabled. To address this issue, let's allocate some extra space for page tables. 128K should be sufficient for any use-case. The logic can be simplified by using a single value for all kernel configurations. Fixes: 34bbb0009f3b ("x86/boot/compressed: Enable 5-level paging during decompression stage") Reported-by: Aaron Lu Signed-off-by: Kirill A. Shutemov Signed-off-by: Ingo Molnar Cc: Linus Torvalds Link: https://lore.kernel.org/r/20230914123001.27659-1-kirill.shutemov@linux.intel.com --- arch/x86/include/asm/boot.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h index 4ae1433..d2caae2 100644 --- a/arch/x86/include/asm/boot.h +++ b/arch/x86/include/asm/boot.h @@ -40,23 +40,20 @@ #ifdef CONFIG_X86_64 # define BOOT_STACK_SIZE 0x4000 +/* + * Used by decompressor's startup_32() to allocate page tables for identity + * mapping of the 4G of RAM in 4-level paging mode. + * + * The additional page table needed for 5-level paging is allocated from + * trampoline_32bit memory. + */ # 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. + * Total number of page table kernel_add_identity_map() can allocate, + * including page tables consumed by startup_32(). */ -# 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 (32*4096) #else /* !CONFIG_X86_64 */ # define BOOT_STACK_SIZE 0x1000