Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp469670pxj; Thu, 3 Jun 2021 11:03:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtRfBgeZSv03VigHxY6fmk9F8qRpaSV0Jf6t2jBh9oKKVWTpBYstGtVYANDKhhJORsJrez X-Received: by 2002:a17:906:d1ce:: with SMTP id bs14mr550116ejb.183.1622743416767; Thu, 03 Jun 2021 11:03:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622743416; cv=none; d=google.com; s=arc-20160816; b=bqACNZJlyhu4O6Hu17VNDRwcz0g8EOTVIyflGO0hA3w1AQEm7bvRArKa/NCuW7MGbI eN+lappYqruGWtMwAHRJGZ7qCCHwK7FMuxpez2dpSJFVqQLEKsmroNTcmKNurVIjEBnA xgbo2b9KLsSQ0wM/GjmrCx0pQw3m9MBlkIi2MBTREEWQ9V8Ze4DPN2kUdFw09t3q0u9O 27QaxxgAu7OFSMpb9d4ODr3DsWmopeHdYvd5rtW4AxkgiFl/3O8wGA6izXhoyBZ0+ZQb ttZWq+uj0IHHz98YW7efI2GELCehBiyVFcDsVErJl7K1vTcHars0IjJi2IVqup5mFdLw H8Vg== 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=reATOpn4TXZ939pAVyG79/jskmMCt9M+3Qq2ZyXo/TE=; b=aHB1pOMQc7V8NV8UrKxYhGLPapw4lBHU3a9Ll4xRa5pOZ6e5gf4DT4qi4oR0ae3Cxa BQJnQv38MhL2dfLdfD6lT/fqk5vwqr9pQatu5C8cUfk8XM2s8nFTyTvqbUVYZqCp6IXL RxnLhe9A9O6sgD45JhaXS2tBskaLzj8PkSMiZI4n0oWUHubKt9y/otxxSd3Bmf3O53c3 kzACF7y5B1UXsufn3EeQNFOBZaBNda7cBItWM8xEQ0ShAEWfwu78SiO0Az9Mnw/5nGhX aRWhPvFQHLiOo11WcViw7IgOygLNVvePr2H87uMlDjLbhtPEZqmElCZNUWWaK9SQgJQX 0QQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ow90GZDN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=GeTR7GVj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hd11si2608035ejc.83.2021.06.03.11.03.09; Thu, 03 Jun 2021 11:03:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ow90GZDN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=GeTR7GVj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbhFCSDq (ORCPT + 99 others); Thu, 3 Jun 2021 14:03:46 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:47994 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbhFCSDl (ORCPT ); Thu, 3 Jun 2021 14:03:41 -0400 Date: Thu, 03 Jun 2021 18:01:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1622743306; 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=reATOpn4TXZ939pAVyG79/jskmMCt9M+3Qq2ZyXo/TE=; b=ow90GZDNX3XIqw/9+edPw+QabA8JdBc1+6AQt8jv75bhSRfvJhWllKi2fkckTYbLd9y/E5 31kVXWHaYt13VpYJq3biJ8wBlndCIDnpHj3HXUHqUUYygzFQ71TlXtRbGRnMYKXFMofc00 /xo6GTQMiyXxRkryrd60J71dOfCB5hg0A/K4nAxCYdCrsGPMNvAPagwO+jFGSXZnycq5na H6TgKg19ZXPB7nSO93vEr4WX+OF7v5iQ+ZHGQCdnCBAW4LkeTN2kIH70TEBkRF1mvhYw0r yS9ON90SxDaoZviHzjekhZRF5bFh27XJUvd6V4m2fXIj0C+D4awqSZcumO5KDg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1622743306; 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=reATOpn4TXZ939pAVyG79/jskmMCt9M+3Qq2ZyXo/TE=; b=GeTR7GVjDTmmHW9u8vKXLQMc/5AhaavST1lW4cwQ2fhtFYFn2AWkv6VrRGZk0+m3CuhSct GIHFy8mA6RFWvLBg== From: "tip-bot2 for Mike Rapoport" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/setup: Always reserve the first 1M of RAM Cc: Mike Rapoport , Borislav Petkov , Hugh Dickins , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20210601075354.5149-2-rppt@kernel.org> References: <20210601075354.5149-2-rppt@kernel.org> MIME-Version: 1.0 Message-ID: <162274330352.29796.17521974349959809425.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 The following commit has been merged into the x86/urgent branch of tip: Commit-ID: f1d4d47c5851b348b7713007e152bc68b94d728b Gitweb: https://git.kernel.org/tip/f1d4d47c5851b348b7713007e152bc68b94d728b Author: Mike Rapoport AuthorDate: Tue, 01 Jun 2021 10:53:52 +03:00 Committer: Borislav Petkov CommitterDate: Thu, 03 Jun 2021 19:57:55 +02:00 x86/setup: Always reserve the first 1M of RAM There are BIOSes that are known to corrupt the memory under 1M, or more precisely under 640K because the memory above 640K is anyway reserved for the EGA/VGA frame buffer and BIOS. To prevent usage of the memory that will be potentially clobbered by the kernel, the beginning of the memory is always reserved. The exact size of the reserved area is determined by CONFIG_X86_RESERVE_LOW build time and the "reservelow=" command line option. The reserved range may be from 4K to 640K with the default of 64K. There are also configurations that reserve the entire 1M range, like machines with SandyBridge graphic devices or systems that enable crash kernel. In addition to the potentially clobbered memory, EBDA of unknown size may be as low as 128K and the memory above that EBDA start is also reserved early. It would have been possible to reserve the entire range under 1M unless for the real mode trampoline that must reside in that area. To accommodate placement of the real mode trampoline and keep the memory safe from being clobbered by BIOS, reserve the first 64K of RAM before memory allocations are possible and then, after the real mode trampoline is allocated, reserve the entire range from 0 to 1M. Update trim_snb_memory() and reserve_real_mode() to avoid redundant reservations of the same memory range. Also make sure the memory under 1M is not getting freed by efi_free_boot_services(). [ bp: Massage commit message and comments. ] Fixes: a799c2bd29d1 ("x86/setup: Consolidate early memory reservations") Signed-off-by: Mike Rapoport Signed-off-by: Borislav Petkov Tested-by: Hugh Dickins Link: https://bugzilla.kernel.org/show_bug.cgi?id=213177 Link: https://lkml.kernel.org/r/20210601075354.5149-2-rppt@kernel.org --- arch/x86/kernel/setup.c | 35 +++++++++++++++++++-------------- arch/x86/platform/efi/quirks.c | 12 +++++++++++- arch/x86/realmode/init.c | 14 +++++++------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index ff653d6..1e72062 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -638,11 +638,11 @@ static void __init trim_snb_memory(void) * them from accessing certain memory ranges, namely anything below * 1M and in the pages listed in bad_pages[] above. * - * To avoid these pages being ever accessed by SNB gfx devices - * reserve all memory below the 1 MB mark and bad_pages that have - * not already been reserved at boot time. + * To avoid these pages being ever accessed by SNB gfx devices reserve + * bad_pages that have not already been reserved at boot time. + * All memory below the 1 MB mark is anyway reserved later during + * setup_arch(), so there is no need to reserve it here. */ - memblock_reserve(0, 1<<20); for (i = 0; i < ARRAY_SIZE(bad_pages); i++) { if (memblock_reserve(bad_pages[i], PAGE_SIZE)) @@ -734,14 +734,14 @@ static void __init early_reserve_memory(void) * The first 4Kb of memory is a BIOS owned area, but generally it is * not listed as such in the E820 table. * - * Reserve the first memory page and typically some additional - * memory (64KiB by default) since some BIOSes are known to corrupt - * low memory. See the Kconfig help text for X86_RESERVE_LOW. + * Reserve the first 64K of memory since some BIOSes are known to + * corrupt low memory. After the real mode trampoline is allocated the + * rest of the memory below 640k is reserved. * * In addition, make sure page 0 is always reserved because on * systems with L1TF its contents can be leaked to user processes. */ - memblock_reserve(0, ALIGN(reserve_low, PAGE_SIZE)); + memblock_reserve(0, SZ_64K); early_reserve_initrd(); @@ -752,6 +752,7 @@ static void __init early_reserve_memory(void) reserve_ibft_region(); reserve_bios_regions(); + trim_snb_memory(); } /* @@ -1082,14 +1083,20 @@ void __init setup_arch(char **cmdline_p) (max_pfn_mapped<