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 849A5356A38 for ; Thu, 23 Apr 2026 15:21:11 +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=1776957673; cv=none; b=XwJxmiZ2Rsj1RXMDv+wj1mt0GUtMKkkzzFgWmqGKlZafeauSkc4D7kyv1ocKoHHcjAGiP8WyQrFxe6zTCMBp+CesmKGwee2IU/BelYBUOMV7YIZNE/3G/jvQIZrlmnq0Tnh5ylgwNACJhmrEpF9RIwZCeZQTg4f9REqf+1pMEJ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776957673; c=relaxed/simple; bh=tnB6iuZ6E5vbcxeFaPRRMPwzhcy4pO9KyeduoWMF7rE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iRL3RzAmhUEBWjO6k7BjXMXYNT1/ktdUqCXV4E+bDaz8+BN3B2mSoDPToOW/hfeVITwNcohfgoOq9uUb6/rUGn15wJdgVwl7vmx9p9RY9oKpiqYqw7Ips5+2VzzOpTJRr8AmdbZHSCwJczyDdx+SUVvlIgXguGw33dXTJk/Xac4= 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=SHDd7lWz; 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="SHDd7lWz" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-488cc31ea57so53029495e9.3 for ; Thu, 23 Apr 2026 08:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776957670; x=1777562470; 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=RFFa0eyeL35xeyu45ExmOZX3U0AnLJJNTndQMnU6Phc=; b=SHDd7lWzZi3z/3436vI0/dPhQr8kp5ZIW8ZzWCEcKo0EwK+EHHTEZCxwUV0+SNQ1kO 0yTcdy0u6HsMglM0LkYRa/pXJBJ5ump+FMvwz0iyYkQ4h4bb06ul5IrCruaiTwStCdU1 1bhMYyjleGg0imiACvkdi8wgvxcS3VIZE7P+LNK5oU3UO6gZhs277org7rjBixZYiwMN GI14S1u+O9tXR7uHsO9fwajqMtKpCEj9s06W605nJN63U09hSP6sSBiKHe9KmY5zBHS1 NpwisSxcDDHH0AQ7gne0u3sTtoTGaFhmYu3DTA7CP7Har1AC7O/S89VqQ6N1P6CL3lCs sixA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776957670; x=1777562470; 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=RFFa0eyeL35xeyu45ExmOZX3U0AnLJJNTndQMnU6Phc=; b=OPtIVNciihrDImtUBK8Yxs168ART/qOFzbVlsLBHtayXM3yo2OghdfEbdgVarQVl5w V0XjsKm3Rvio0pCR1Pd0Owm0sNjmK6peGEZUA8tJOhZ53liRsx7q+IlDHU9eGfV2Z19q b44tccU+qtevNCiehIWl9/fDzZz1JqNDd2pE3NAChf6TNZc9IJkrFMSRkwyA3QP0WWMR CqfQfpU2TxofGJ7nFk4lyrc8O+9kb8C7oveoAyQr0fr/1tLgyTE1/vW00GIHHtC128WG SDOiiPzlYum7vkpjll5tcJi1KaTJgi/0xcEbt0iPHXekIU1yHIIpR4/TIAXK7+IXiOep dGhQ== X-Gm-Message-State: AOJu0YzpJEKGuEWGXgYPbLJGZsF75vWEUSQbAjPxKSAtUAGgtiYB7JB+ pYaXbzYHvpxncK2TRJU76gbHvbUDNXvuB+7Nd0nUczqRrnJ0OogMj6xxLanEpN+OfozhHAKASez YZxVNWSDGdQe81VLSMCC2UsR1kKgY/y57Q0i1G6kzEyYW4+phHpEz/m41w3NKN/rEn+p8+SRVrS 9WbXSbxRtWQx+Isg5mDpaXIIVusHmxyrApiQ== X-Received: from wmbgz9-n2.prod.google.com ([2002:a05:600c:8889:20b0:483:27fd:cf2b]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4ec8:b0:485:7f02:afd5 with SMTP id 5b1f17b1804b1-488fb755caamr407991925e9.13.1776957669759; Thu, 23 Apr 2026 08:21:09 -0700 (PDT) Date: Thu, 23 Apr 2026 17:20:34 +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=2056; i=ardb@kernel.org; h=from:subject; bh=jc52JwSM1lqsY0b8j2g3nRYFPgUE93s/+qfuH/7VRek=; b=owGbwMvMwCVmkMcZplerG8N4Wi2JIfOVxbGysBDho4vj7f/fasxW4QxWD1e52xv61MdFUOj3Q wPjV6UdpSwMYlwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCJ7/jH8d9vyLcv7Li/3Jraf AiKppit1Nf5FdWow+Ns8kpNSzF2WzsjwK7vot4Jk6ia9ivuGC7fuW9sX/IFf6tIkJ7Yryg563KV 8AA== X-Mailer: git-send-email 2.54.0.rc2.544.gc7ae2d5bb8-goog Message-ID: <20260423152024.1098465-28-ardb+git@google.com> Subject: [PATCH v3 09/17] x86/efi: Intersect ranges_to_free with MEMBLOCK_RSRV_KERN regions 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 efi_mem_reserve() will mark reservations in memblock with the MEMBLOCK_RSRV_KERN attribute, so take this into account when building the ranges_to_free array. This removes the need to split EFI memory map entries and tag them with the EFI_MEMORY_RUNTIME attribute. Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/quirks.c | 44 +++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index ce452e5c2f0a..ce06a388fc11 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -406,19 +406,41 @@ static int num_to_free __initdata; static int __init efi_add_range_to_free(u64 range_start, u64 range_end) { + struct memblock_region *region; static int idx __initdata; - ranges_to_free[idx].start = range_start; - ranges_to_free[idx].end = range_end; - - if (++idx >= num_to_free) { - num_to_free *= 2; - ranges_to_free = krealloc_array(ranges_to_free, - num_to_free, - sizeof(ranges_to_free[0]), - GFP_KERNEL); - if (!ranges_to_free) - return -ENOMEM; + for_each_reserved_mem_region(region) { + u64 region_end = region->base + region->size; + u64 start, end; + + /* memblock tables are sorted so no need to carry on */ + if (region->base >= range_end) + break; + + if (region_end < range_start) + continue; + + if (region->flags & MEMBLOCK_RSRV_KERN) + continue; + + start = PAGE_ALIGN(max(range_start, region->base)); + end = PAGE_ALIGN_DOWN(min(range_end, region_end)); + + if (start >= end) + continue; + + ranges_to_free[idx].start = start; + ranges_to_free[idx].end = end; + + if (++idx >= num_to_free) { + num_to_free *= 2; + ranges_to_free = krealloc_array(ranges_to_free, + num_to_free, + sizeof(ranges_to_free[0]), + GFP_KERNEL); + if (!ranges_to_free) + return -ENOMEM; + } } /* add a terminating entry at the end */ -- 2.54.0.rc2.544.gc7ae2d5bb8-goog