From nobody Mon Apr 6 15:36:55 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 7D2A03AA50C for ; Thu, 19 Mar 2026 09:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773911179; cv=none; b=hHwiV0bViMyU97WOvUaQCEu/0CZyL9eF+J8i/xIZVyKpGnvPb1DX85WEzhLUB6xnzS/u/xTteu7fXEWEtYr/vzCniXW4Sq7FDH+dCwZM4QoO8oKlaUJmY3i4d4vxONPSkG12SMpHU0uRtqAnbfj/FjkVsoYAs1B0q6U4R4fPjFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773911179; c=relaxed/simple; bh=cbbspSu/En8wMoIk09xHoGHLe/eK50A9ypzP7V+nnys=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dVvtWiLpsZKLxW4zrvFMMuzxcN+qGYtK3dazBex/Su2xBWePd5kLl3bdLjthMzOlBcGje+jWIqcpyq3xFIV+FqZdI1gfVO7GzareMrQTC25GFu0L6MzGbBKhHmI4Z3ZwyoCH+TGFeL8kf1XWn3cf7Vg2SkEVq6KVsUoh3WxQdG4= 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=mOJ+CmKc; arc=none smtp.client-ip=209.85.221.74 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="mOJ+CmKc" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-43b3d3d2d22so339421f8f.0 for ; Thu, 19 Mar 2026 02:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773911176; x=1774515976; 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=GGWJD/oSO/zqs1fjiBr8BSE5CyULnCYZrvaP5HxSasQ=; b=mOJ+CmKcl0jL/+RmqPXEjUDAYrV/4wecURM4r3Lo0o2YuqwzW5AvXbpUD6iUNW9Woz vYCCSxctTrixfVsDItjFlW/+ZbYbkEqm/KOR5+3lF6Pc3dgECEGK6smTXU3faeyQJKlk o7Kw4SgYDWHDSyEdmMQXEAq69KQdLv/CtGVeXWZ+W/IAMelclXMU6jFlnEUzJ7eSrbig u1u0CCaOWlh+IKSGzdJsB7ELmyAVhnUKkYm0h3g1NmSHWmfOzS1M2yCfwu2zmRp37Opy M2ZuRRg+1SJMA/DJANOK91NAjBHROi/d63TueYLlJQNzOBZZGG8PX8PKK3m/r/66Yrn7 ryIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773911176; x=1774515976; 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=GGWJD/oSO/zqs1fjiBr8BSE5CyULnCYZrvaP5HxSasQ=; b=sHlqNErZkUbzo1eSCXbC87oqSuiygzBn29fu1YmH2QB9jVystPZ46gYJLKxbFQIKuo jCY42A4crcg1dzyvUT6mO74EaTdlajAPbIHUq2LurcrVLLyULsYG7xXq7FIQzVJ34UHw IsUi57k/tqaw55PCGmIyIYn2/gPPCD1Elzu8hqCIGvab4pCEuUmPpqeUWOfDV56rToBC ixzrA6pP4wRQFpn9Ujb5h0k+ug9fsmPvOIK8OmdZhTBsuovAsBXcfJHGZ6sbui3mpy0i ptXtOmDA8gQQkZEC+TVi3i+usxYZjiUqDDURRbkYu7m9GvVXljXc933HIeBQnK5PdFEU +Z+g== X-Gm-Message-State: AOJu0Yx3f835dyihQPFjPwwE6esfTEVoxFHuakCuiIBTtwtc1Kwpp4Fq 32sTZLDfnN8v/7/eaA2qbApWnAqZHQ8M3uN94JGfeneNE034Tp6oXEFsiAq9gUnfqMIM4MuLNsC oLzAqawCkvVfGNPd+zyhfTNQHZiWNs33lEM4Mpv1BV8HYaFhmoCjYR0UY01lBiwY0byNUjjzROr 2hpWfZ9cCBO1WmOPOuzryAGBDXAokalg0zJA== X-Received: from wmlz10.prod.google.com ([2002:a05:600c:220a:b0:485:32b2:6b8d]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1c2a:b0:485:2c61:9457 with SMTP id 5b1f17b1804b1-486f44379a6mr102042845e9.10.1773911174993; Thu, 19 Mar 2026 02:06:14 -0700 (PDT) Date: Thu, 19 Mar 2026 10:05:42 +0100 In-Reply-To: <20260319090529.1091660-21-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: <20260319090529.1091660-21-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4144; i=ardb@kernel.org; h=from:subject; bh=MRuY0aJg5kwsKdStVH+fBQF2uFes8p/NfZYMA6nA7UM=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIXP3nsxfJaU2qo+XFZ7qXemwsXv/0+q2Spbyy0kb5Pwzl JXPBU3sKGVhEONikBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABMJKmVkuGy7Wvf3x+uaGy4x Zz97LLJh65PFQn8vZew5Jzn/yuQMc2dGhks8HrYabPrfmVbYe34NLDAsCwu2yJo2J+OHnn2/yYY EbgA= X-Mailer: git-send-email 2.53.0.851.ga537e3e6e9-goog Message-ID: <20260319090529.1091660-33-ardb+git@google.com> Subject: [PATCH v2 12/19] 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 Content-Transfer-Encoding: quoted-printable 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 bott= om-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 b01dd639bf62..44cdd3c1055e 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); =20 +#ifdef CONFIG_X86_32 +void efi_merge_regions(void); +#else +static inline void efi_merge_regions(void) {} +#endif + extern u64 efi_setup; =20 #ifdef CONFIG_EFI diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 183cca8fe4a6..a6081e3f1b88 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(); } =20 -/* Merge contiguous regions of the same type and attribute */ -static void __init efi_merge_regions(void) -{ - efi_memory_desc_t *md, *prev_md =3D NULL; - - for_each_efi_memory_desc(md) { - u64 prev_size; - - if (!prev_md) { - prev_md =3D md; - continue; - } - - if (prev_md->type !=3D md->type || - prev_md->attribute !=3D md->attribute) { - prev_md =3D md; - continue; - } - - prev_size =3D prev_md->num_pages << EFI_PAGE_SHIFT; - - if (md->phys_addr =3D=3D (prev_md->phys_addr + prev_size)) { - prev_md->num_pages +=3D md->num_pages; - md->type =3D EFI_RESERVED_TYPE; - md->attribute =3D 0; - continue; - } - prev_md =3D 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 =3D NULL; + + for_each_efi_memory_desc(md) { + u64 prev_size; + + if (!prev_md) { + prev_md =3D md; + continue; + } + + if (prev_md->type !=3D md->type || + prev_md->attribute !=3D md->attribute) { + prev_md =3D md; + continue; + } + + prev_size =3D prev_md->num_pages << EFI_PAGE_SHIFT; + + if (md->phys_addr =3D=3D (prev_md->phys_addr + prev_size)) { + prev_md->num_pages +=3D md->num_pages; + md->type =3D EFI_RESERVED_TYPE; + md->attribute =3D 0; + continue; + } + prev_md =3D md; + } +} --=20 2.53.0.851.ga537e3e6e9-goog