From: dev12124 <joaoanandalima@gmail.com>
To: Alvaro Parker <alparkerdf@gmail.com>
Cc: ardb@kernel.org, linux-efi@vger.kernel.org,
ilias.apalodimas@linaro.org, tglx@linutronix.de,
mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com,
x86@kernel.org, hpa@zytor.com, linux-pm@vger.kernel.org,
rafael@kernel.org, jlee@suse.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/efi: Map firmware runtime regions before boot services regions
Date: Sat, 5 Dec 2026 09:07:29 -0300 (Hora oficial do Brasil) [thread overview]
Message-ID: <ddc65dd8-17f7-6b06-c67f-59f02b290fed@gmail.com> (raw)
In-Reply-To: <20261203153018.26852-1-alparkerdf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2428 bytes --]
Hi,
Analyzing the code, have a few points:
I. The good side
[ x ] - Why it would break during S4 (Hibernation)
During the resumption from hibernation, the new kernel must map the EFI Runtime Services regions (RTCode and RTData)
to the exact
same virtual addresses used in the previous session, ensuring that
`SetVirtualAddressMap()` and the firmware pointers remain valid.
[ x ] - The failure of the old algorithm
Since efi_map_regions() traversed the memory table from top to bottom, mapping everything in a single pass,
any change in the size of Boot Services regions (BSCode/BSData)—which the firmware might
allocate differently between a normal boot and an S4 wake—would shift all subsequent virtual addresses
of the Runtime regions, causing an immediate page fault in efi_call_rts().
[ x ] - The two-pass correction (pass 0 and pass 1)
Separating the loop to first map all pure runtime regions (pass == 0)
and only subsequently mapping the reserved boot services regions (pass == 1)
isolates the virtual layout of the runtime services.
II. The bad side
[ ] - Confusing and hard-to-read Boolean condition in the loop (pass == 0)
In line:
if (efi_is_firmware_runtime_region(md) != (pass == 0))
continue;
Comparing the return value of a `bool` function—or
an equality expression like `(pass == 0)`—using `!=` works in C (since both evaluate to 0 or 1), but it makes the code unnecessarily dense
and prone to errors during future maintenance. Using a clear `enum` (e.g., `PASS_RUNTIME`, `PASS_BOOT_SERVICES`)
or a direct check makes the intent
immediately obvious.
[ ] - Incompatibility of hibernation layout without a bump in RESTORE_MAGIC (Risk of silent regression)
Regarding your notes: why shouldn't the x86 `RESTORE_MAGIC` be incremented, or, alternatively, shouldn't a consistency
check be performed before calling `efi.runtime`?
[ ] - Check the impact of ordering when EFI_PROPERTIES_TABLE is present
Is this validated on firmwares that expose the EFI_PROPERTIES_TABLE? Given that the original interleaving between BS
(Boot Services) and RT (Runtime Services) can alter the 2M page alignment(EFI_VAR_START).
This is a good solution (but, with a `small bugs`).
Cheers,
João.
prev parent reply other threads:[~2026-12-05 12:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 15:30 [PATCH] x86/efi: Map firmware runtime regions before boot services regions Alvaro Parker
2026-12-03 16:02 ` sashiko-bot
2026-12-05 12:07 ` dev12124 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ddc65dd8-17f7-6b06-c67f-59f02b290fed@gmail.com \
--to=joaoanandalima@gmail.com \
--cc=alparkerdf@gmail.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=hpa@zytor.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jlee@suse.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rafael@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.