From nobody Thu Apr 9 17:57:50 2026 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.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 EB3393ECBFF for ; Fri, 6 Mar 2026 15:57:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772812645; cv=none; b=Uuul4zIDbEwatjwkoiUEVvGDkzrxswYGeRgaRHNQBLIXzEGBJCMG3N2V3ogTYYw4ZUvDBtpnCUN3RiQu4ouI9+s0jHJ1IYNwwgos3ffMeMswnq7KMIo6C5SFMV3TQ+Sv6t/Ytoxd4Sp7LAARpnbzs3eibgsOO0T+b8fd0FYvA38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772812645; c=relaxed/simple; bh=ZTnS4RveV5BcCOB3XTR/KA1YUAH3LEITzjMxI69JZuQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VIFAAJqFiGwZUYFPHUXP2WlNhl7qUUzPPH1krvo/nGjHchMg/iM9W8UT8nUzuZ7Eke41iM5bPxg27tLeJ0/h/4C0ZaGZSRyPY/KPUtcUY0zjX+ai2Ym14Em9A/4qt9BkNcMEH+LULDtj+QVjD6aRLMpnbwlAhWKB2e/PQHnjaMQ= 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=abpJgkS2; arc=none smtp.client-ip=209.85.208.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="abpJgkS2" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-660af6dee06so5029046a12.3 for ; Fri, 06 Mar 2026 07:57:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772812642; x=1773417442; 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=pemDVNzQpQnPK8E+QcSXNZ28feWHqXpZeP4jd6MxjXo=; b=abpJgkS2I83f6noK0Kkn6TYYYZojjrnXymvZ4g0qS2uqK7wuEWI/jJXDZ2OvKtq35B jJujoR3UgsPiaAigf8QoFarbg2t5GDmxMBkmHD5zmZDTg/3CYDXvLFQv8Jdg4GS5OMti 2qgP5LaO3HEjQALIgYyAy8vBZcdzAV4+KDA2pgIa29mq7JtWRIsw+aGovRq5fvTT75SZ tOuZXFJdUKHayd78uGHlz/P2fdRNjCfLH40UkZxjoQGGYT/gTTzgM9yLpiTjyOnjY9VS 6KJ0IGQTcqjO0fa+qJsc5VRWOTKYwm+R5/oSNxAv9A8MgZ8QxR012ty7PuW8tTgFVCnZ NL9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772812642; x=1773417442; 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=pemDVNzQpQnPK8E+QcSXNZ28feWHqXpZeP4jd6MxjXo=; b=xMm34W9iwfartFD27Q/fCgntMMSsggsOxUx32HiMvlUM428aE0Z/Zmk4E7dEkwsOTj miCQcY+e3Hoppv7dMvCGZ2VYBcJPO13HjelogI2GGk8mlOKQEM7EQtbH0nvzkqbvgLSb PetEZlPBhPhosl6KU8vdEUnsRTatgkNSTuEXaxwYBv7jk2VounDAukmccJEUKUGuF1Wp Ygct5MCxXaK85bzZoLy12XtpdobhWGhww2KJYPaM6im1/TNfuKyi9o7zwfgJMQE3jj+a wpxPVKlPNA0uNie6KHNqLsvy0fHdR20Nplh4+Hthr/UoI9pFmwnQVy8p7zhuNxWweYGj YVMw== X-Gm-Message-State: AOJu0YwiB27+WuWkd07vkXTwlNSJPDYUDBROf8RWehPmqPKY5VXV7gB4 h88IKzEDQluySfiOTV5k1kAqrCwKZ1PpSXofU4BS2bIvQ9zORkAUXPaCReVOifIjy6N9Neu/aaL 1oo6n+9i9KA8Iizcfk7eUcH7IFjGoDvwB65D7hiFvyRw5m11CCRaJ63BtIxv8WAVn5feXOSIcVO 4v7bmDeNbxckH37GhzMQVW4Iwaivn3yiEQRQ== X-Received: from edcy15.prod.google.com ([2002:a05:6402:358f:b0:658:115a:7265]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:520b:b0:65f:aecc:4f0e with SMTP id 4fb4d7f45d1cf-6619d5274c9mr1386700a12.19.1772812641980; Fri, 06 Mar 2026 07:57:21 -0800 (PST) Date: Fri, 6 Mar 2026 16:57:08 +0100 In-Reply-To: <20260306155703.815272-12-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: <20260306155703.815272-12-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1664; i=ardb@kernel.org; h=from:subject; bh=EeSnSz6nXHhpEi61P5BRppL/JAG5B1Jjj0fvpIrf2nk=; b=kA0DAAoWMG4JVi59LVwByyZiAGmq+VKjBinn9SsHx0HzQYNL4p/cP/eaDyxrHBrlmpnpshxTM Ih1BAAWCgAdFiEEEJv97rnLkRp9Q5odMG4JVi59LVwFAmmq+VIACgkQMG4JVi59LVw8kAD/Q3j+ rAfLCupT/TsV8nAZg4bilFrBYtQPH2fEwGiACM4A/1r6ZLGhfH7UgYqkLjkVkRpq10pUntP74mz TKx7qHWAK X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog Message-ID: <20260306155703.815272-16-ardb+git@google.com> Subject: [RFC PATCH 4/9] x86/efi: Defer sub-1M check from unmap to free stage 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 As a first step towards moving the free logic to a later stage altogether, and only keeping the unmap and the realmode trampoline hack during the early stage of freeing the boot service code and data regions, move the logic that avoids freeing memory below 1M to the later stage. Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/quirks.c | 21 ++++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index f896930cecda..58d00ffb1d59 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -475,18 +475,6 @@ void __init efi_unmap_boot_services(void) size -=3D rm_size; } =20 - /* - * Don't free memory under 1M for two reasons: - * - BIOS might clobber it - * - Crash kernel needs it to be reserved - */ - if (start + size < SZ_1M) - continue; - if (start < SZ_1M) { - size -=3D (SZ_1M - start); - start =3D SZ_1M; - } - /* * With CONFIG_DEFERRED_STRUCT_PAGE_INIT parts of the memory * map are still not initialized and we can't reliably free @@ -579,7 +567,14 @@ static int __init efi_free_boot_services(void) return 0; =20 while (range->start) { - freed +=3D efi_free_unreserved_subregions(range->start, range->end); + /* + * Don't free memory under 1M for two reasons: + * - BIOS might clobber it + * - Crash kernel needs it to be reserved + */ + u64 start =3D max(range->start, SZ_1M); + + freed +=3D efi_free_unreserved_subregions(start, range->end); range++; } kfree(ranges_to_free); --=20 2.53.0.473.g4a7958ca14-goog