From: Vincent Mailhol <mailhol@kernel.org>
To: Ard Biesheuvel <ardb@kernel.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org
Subject: Re: [PATCH v2] efi/libstub: populate LoaderDevicePartUUID
Date: Sat, 5 Sep 2026 14:05:41 +0200 [thread overview]
Message-ID: <d0a41184-e65f-4b3c-9c65-eef123ffa5e0@kernel.org> (raw)
In-Reply-To: <d6b7cdae-8b99-49a2-9d9d-03eb77deb1dd@kernel.org>
On 05/09/2026 at 00:06, Vincent Mailhol wrote:
> On 04/09/2026 at 18:12, Ard Biesheuvel wrote:
>> Hello Vincent,
>>
>> On Thu, 3 Sep 2026, at 23:19, Vincent Mailhol wrote:
>>> The Boot Loader Interface [1] defines LoaderDevicePartUUID. That EFI
>>> variable records the GPT partition UUID of the partition containing the
>>> boot loader.
>>>
>>> This is used, for example, by systemd-gpt-auto-generator [2] to identify
>>> the disk the boot loader was launched from and automatically detect and
>>> mount partitions on it.
>>>
>>> GRUB [3] and systemd-boot [4] populate it, but when the kernel is
>>> started directly by EFI firmware, there is no conventional external boot
>>> loader to provide the variable. In that case, because the EFI stub
>>> performs the boot loader role, it should provide the variable itself.
>>>
>>
>> Fair enough.
>>
>> But shouldn't it set LoaderInfo as well then?
>
> Sure. This is quite easy to do.
>
> Any preference of what to put in that variable? I am thinking of
> adding the release number like this:
>
> #define EFI_BLI_LOADER_INFO L"Linux EFI stub " UTS_RELEASE
>
> This looks consistent with what the other boot loaders are doing:
>
> $ cat /sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cfb6c7-440b29bb8c4f
> GRUB 2.12
>
> Also, this gave me an idea. Maybe we can use the LoaderInfo variable
> as a sentinel for all other variables:
>
> void efi_bli_set_variables(efi_loaded_image_t *image)
> {
> unsigned long size = 0;
>
> if (get_efi_var(L"LoaderInfo", &loader_entry_guid,
> NULL, &size, NULL) != EFI_NOT_FOUND)
> return;
>
> efi_bli_populate_loader_info();
> efi_bli_populate_loader_part_uuid(image);
> }
>
> If it is set, we bail out, otherwise, we assume that the earlier boot
> stage did not implement BLI and we blindly populate everything. No
> more additional check on whether LoaderDevicePartUUID or other
> variables are set!
FYI, this is my latest WIP:
void efi_bli_set_variables(efi_loaded_image_t *image)
{
static efi_char16_t loader_info[] = L"Linux EFI stub " UTS_RELEASE;
unsigned long size = 0;
if (get_efi_var(L"LoaderInfo", &loader_entry_guid,
NULL, &size, NULL) != EFI_NOT_FOUND)
return;
if (set_efi_var(L"LoaderInfo", &loader_entry_guid,
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof(loader_info), loader_info) != EFI_SUCCESS)
return;
efi_bli_populate_loader_part_uuid(image);
}
The idea is that the sentinel check will not only be the presence of
LoaderInfo but also the fact that we could successfully set it. The
other variables (LoaderDevicePartUUID and whatever might comme in the
future) are set without further check and failure to set them is
silencely ignored.
> Does this approach make sense?
(...)
>> I'm reluctant to add this kind of code as a special one-off, so I got a
>> bit carried away and took this code and put it in the stub's printf
>> layer.
>
> Thanks for the extra work!
>
>> Could you please check whether the first two patches at [0] are
>> sufficient for efi_bli_guid_to_str() to be replaced by a simple
>> efi_snprintf("%pUl", ...) call here?
>
> Ack. I already rebased and did a compile test, OK so far. The runtime
> test will come later. If I find an issue, I will send you a fix. If
> not, I will just send the v3 rebased on top of your
> efi-libstub-native-utf16 branch.
I spoke a bit too quick. Compiling
drivers/firmware/efi/libstub/lib.a
worked well, but in a full build,
arch/x86/boot/compressed/error.c
failed to link because it expects libstub to provide vsnprintf()
(c.f. comment above panic()) which you removed in commit edbd49dfea2a
("efi/libstub: Add widestring support to vsnprintf()").
You need to squash this in that commit:
---8<---
diff --git a/drivers/firmware/efi/libstub/vsprintf.c b/drivers/firmware/efi/libstub/vsprintf.c
index 521bdace031df..337326ce00488 100644
--- a/drivers/firmware/efi/libstub/vsprintf.c
+++ b/drivers/firmware/efi/libstub/vsprintf.c
@@ -663,6 +663,11 @@ int snprintf(char *buf, size_t size, const char *fmt, ...)
return i;
}
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
+{
+ return efi_vsnprintf(buf, size, fmt, args, false, false);
+}
+
int efi_snprintf(efi_char16_t *buf, size_t size, const char *fmt, ...)
{
va_list args;
---8<---
or modify arch/x86/boot/compressed/error.c to take another vsnprintf()
variant.
Yours sincerely,
Vincent Mailhol
prev parent reply other threads:[~2026-09-05 12:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 21:19 [PATCH v2] efi/libstub: populate LoaderDevicePartUUID Vincent Mailhol
2026-09-04 16:12 ` Ard Biesheuvel
2026-09-04 22:06 ` Vincent Mailhol
2026-09-05 12:05 ` Vincent Mailhol [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=d0a41184-e65f-4b3c-9c65-eef123ffa5e0@kernel.org \
--to=mailhol@kernel.org \
--cc=ardb@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox