From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FE0E351C3B for ; Thu, 23 Apr 2026 15:21:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776957665; cv=none; b=EtoQUnLmMGPsEMtWt8p5HJKo/h65J2DO4i774IhCTglD8NYEuSPPIlpG/qj4F7HYaAaQnRWrR6FQVH0v20tcJFLC5I8B9TxSkK5h2xWhuNMI+M7sj9UwkTjS003PlyK5pNZtnNszqn0Bfd35yaDtkNXqxa+9LxpSFOeojBeNZKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776957665; c=relaxed/simple; bh=bUHL//Am2oa5BMc+mwzx9NssfOKaE6GrNTig/ad9cCM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dFlg4tfX5RPMyQwMQcIDMRhl8770oqkQSufPcVyNdJAQqeeGC0bb9YIGuxpR6MurXsXNAp9TgNxiZzjW0LI/wPkk/UTwy6S5CNZE+cA76jW+vZEYcTykz8kcgSuODhlAJK4JvPWU7h2fkn37z1D3STmVv2ffCO+64KLaIyfOPp8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pIUo69hT; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pIUo69hT" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-488e097a270so48719135e9.1 for ; Thu, 23 Apr 2026 08:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776957663; x=1777562463; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aUJqvSaANOdDR9L/33SKcbzCGTEvwMTq0jUvoX5ntMM=; b=pIUo69hT3PbZoap+eZIxurVMtruqgcyjtlqi/3o+dqrYMkmsBd2x4+ae9i5X7mapZK lTPaLGDeVo+/kVb4C2i8Vq5Bz7y/xalNHtrC7XhlCPQe+6upP1lNo7m6gWuTWsHu/8G0 vF4+c0YMF4wycE/7phkQ6SdFnFji+bS1YAwLePtneJjZZZREgAcTdL2NzvRqboV4aiHY TWE8eYGV0G7e+18f9oXeqCWiMnGD34APNS3JASUheNrbelKzgl/8VTG7Hg1gGTr79yXY pxUylIUMMFp1ZWJUZMchBu6z68DMtDUatgHFgO1EnyVuaVTR7gBxwMWlFimJWOnSH2lD jj4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776957663; x=1777562463; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aUJqvSaANOdDR9L/33SKcbzCGTEvwMTq0jUvoX5ntMM=; b=KjR9dSN09Wg9j2STxmXNHQoyXTLr8214PpCvOXMcYzhhlGC62TtfywtuKCz4rYILcb KunkS+WzacZkKZlvQtDcfKbDCB9D+B7ksGei4IiBNG4zS7KMWMvM1sG6jbdTE7QhEjOb TSlFZWfTaplLp9NfUySjYy3wKzEbcl3RFoy347VCjm8rRO/TS0k1pu1aHFULRvLcZ26f dWjFvx2XHrhAxCq0FWIrcc7+LXAUZQYEATIJmb8StYgRIo63HVJ8JS0aNJPq3LMSRthD 89JmPa3WbacUm4mCNO0U8MiIN4Y09OL5/k5SdH/vu8VnSKvhB9YZo+EB+SCdiZWZ7Grs Yiaw== X-Gm-Message-State: AOJu0YzAeoUPFKdHpWV5XY5rFrKs88cO1nOuLlXXOemeBIX884/nCaCM WgJ/VJk53ab5ljEnWGw6baEXPK/rOqr9a+9h689lE0lZPgXRxhFR4bmeEvZKHk+AptC7s9qfRNE XIANWJzNgH6tOldBq7kSrS1604fwq1fF8zSicRaRiLG4ibLXv+GFrkvcuOQ/lNDtKVsiXShb2D4 PSL+19lbEYP9Zv+lojol0TILVUtuOrGa+55w== X-Received: from wma5.prod.google.com ([2002:a05:600c:8905:b0:485:3aa2:da59]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8b38:b0:487:59c:2bb8 with SMTP id 5b1f17b1804b1-488fb7925dcmr383448975e9.27.1776957662443; Thu, 23 Apr 2026 08:21:02 -0700 (PDT) Date: Thu, 23 Apr 2026 17:20:28 +0200 In-Reply-To: <20260423152024.1098465-19-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260423152024.1098465-19-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4148; i=ardb@kernel.org; h=from:subject; bh=HyyOeSodMSg9BQJay8XzIUTfk5/dlS8V1D5JXM1rIKc=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIfOVxV7NotIf/rZvlhwLPnv68pXIQ33PrY5IdDOszpW0e bKMt8e5o5SFQYyLQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEzk1kxGhhu39jrfT/FRyZ91 efEy5zOrDj3cuEjg6a1Xa4v7fpVJ+jxnZDj8UXjNFYXd+2T+XN0lJ/n/7e0m5f0RqwN73lYEFO5 6/owFAA== X-Mailer: git-send-email 2.54.0.rc2.544.gc7ae2d5bb8-goog Message-ID: <20260423152024.1098465-22-ardb+git@google.com> Subject: [PATCH v3 03/17] x86/efi: Only merge EFI memory map entries on 32-bit systems From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-efi@vger.kernel.org, x86@kernel.org, Ard Biesheuvel , "Mike Rapoport (Microsoft)" , Benjamin Herrenschmidt , Dave Young , Gregory Price Content-Type: text/plain; charset="UTF-8" From: Ard Biesheuvel Commit 202f9d0a4180 ("x86, efi: Merge contiguous memory regions of the same type and attribute") introduced a pass over the EFI memory map, ensuring that contiguous regions of the same type and attribute are coalesced into a single entry. This was needed because relative references may exist between those regions, and so the virtual remapping needs to preserve the relative placement of these regions. This virtual remapping was based on ioremap() at the time, which does not guarantee that adjacent physical addresses are mapped adjacently in the virtual space. Commit d2f7cbe7b26a ("x86/efi: Runtime services virtual mapping") introduced a new strategy for virtually remapping the EFI runtime services, which is now the only remaining one, and commit a5caa209ba9c ("x86/efi: Fix boot crash by mapping EFI memmap entries bottom-up at runtime, instead of top-down") tweaked the logic to ensure that the relative offset of adjacent regions of any type is preserved on 64-bit systems, by reversing the order in which the EFI memory map is traversed when choosing the virtual placement. This means that merging regions is no longer needed on 64-bit, given that the relative placement of adjacent regions is guaranteed to be preserved in the virtual space. So make this hack 32-bit only. Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 6 ++++ arch/x86/platform/efi/efi.c | 31 -------------------- arch/x86/platform/efi/efi_32.c | 31 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index dc8fe1361c18..f291845b403a 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -143,6 +143,12 @@ extern void efi_unmap_boot_services(void); void arch_efi_call_virt_setup(void); void arch_efi_call_virt_teardown(void); +#ifdef CONFIG_X86_32 +void efi_merge_regions(void); +#else +static inline void efi_merge_regions(void) {} +#endif + extern u64 efi_setup; #ifdef CONFIG_EFI diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 1b7a0cd54d08..c0195b5eab21 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -502,37 +502,6 @@ void __init efi_init(void) efi_print_memmap(); } -/* Merge contiguous regions of the same type and attribute */ -static void __init efi_merge_regions(void) -{ - efi_memory_desc_t *md, *prev_md = NULL; - - for_each_efi_memory_desc(md) { - u64 prev_size; - - if (!prev_md) { - prev_md = md; - continue; - } - - if (prev_md->type != md->type || - prev_md->attribute != md->attribute) { - prev_md = md; - continue; - } - - prev_size = prev_md->num_pages << EFI_PAGE_SHIFT; - - if (md->phys_addr == (prev_md->phys_addr + prev_size)) { - prev_md->num_pages += md->num_pages; - md->type = EFI_RESERVED_TYPE; - md->attribute = 0; - continue; - } - prev_md = md; - } -} - static void *realloc_pages(void *old_memmap, int old_shift) { void *ret; diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c index b2cc7b4552a1..886ede4117b5 100644 --- a/arch/x86/platform/efi/efi_32.c +++ b/arch/x86/platform/efi/efi_32.c @@ -152,3 +152,34 @@ void arch_efi_call_virt_teardown(void) firmware_restrict_branch_speculation_end(); efi_fpu_end(); } + +/* Merge contiguous regions of the same type and attribute */ +void __init efi_merge_regions(void) +{ + efi_memory_desc_t *md, *prev_md = NULL; + + for_each_efi_memory_desc(md) { + u64 prev_size; + + if (!prev_md) { + prev_md = md; + continue; + } + + if (prev_md->type != md->type || + prev_md->attribute != md->attribute) { + prev_md = md; + continue; + } + + prev_size = prev_md->num_pages << EFI_PAGE_SHIFT; + + if (md->phys_addr == (prev_md->phys_addr + prev_size)) { + prev_md->num_pages += md->num_pages; + md->type = EFI_RESERVED_TYPE; + md->attribute = 0; + continue; + } + prev_md = md; + } +} -- 2.54.0.rc2.544.gc7ae2d5bb8-goog