[PATCH 0/7] efi/libstub: Avoid UTF-16 conversion busywork

Ard Biesheuvel posted 7 patches 2 weeks, 6 days ago
There is a newer version of this series
arch/x86/boot/compressed/error.c               |  19 ---
arch/x86/boot/compressed/error.h               |   1 -
arch/x86/boot/compressed/mem.c                 |   2 +-
drivers/firmware/efi/libstub/Makefile          |   3 +-
drivers/firmware/efi/libstub/efi-stub-helper.c |  59 +++-----
drivers/firmware/efi/libstub/efistub.h         |   6 +-
drivers/firmware/efi/libstub/gop.c             |   6 +-
drivers/firmware/efi/libstub/printk.c          |  93 ++----------
drivers/firmware/efi/libstub/vsprintf.c        | 148 +++++++-------------
lib/ucs2_string.c                              |   2 +-
10 files changed, 87 insertions(+), 252 deletions(-)
[PATCH 0/7] efi/libstub: Avoid UTF-16 conversion busywork
Posted by Ard Biesheuvel 2 weeks, 6 days ago
The EFI libstub performs some redundant conversions between UTF-16 and
UTF-8 and back again, which includes dealing with surrogate pairs, which
UEFI implementations themselves simply ignore.

So drop all the homegrown code, and use the existing UCS-2 (== UTF-16
without surrogate pairs) library code where conversion to UTF-8 is
actually needed (the kernel command line).

The remaining handling involves the EFI console, which supports wide
characters natively, so just use those directly.

Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: x86@kernel.org

Ard Biesheuvel (7):
  x86/boot: Drop pointless re-implementation of panic()
  lib/ucs2_string: Avoid WARN in library code
  efi/libstub: Use ucs2_string library for UTF-16 to UTF-8 conversion
  efi/libstub: Avoid efi_puts() for compile time constant strings
  efi/libstub: Output UTF-16 directly from vsnprintf()
  efi/libstub: Add support for printing human readable GUIDs
  efi/libstub: Add efi_snprintf() to construct wide strings

 arch/x86/boot/compressed/error.c               |  19 ---
 arch/x86/boot/compressed/error.h               |   1 -
 arch/x86/boot/compressed/mem.c                 |   2 +-
 drivers/firmware/efi/libstub/Makefile          |   3 +-
 drivers/firmware/efi/libstub/efi-stub-helper.c |  59 +++-----
 drivers/firmware/efi/libstub/efistub.h         |   6 +-
 drivers/firmware/efi/libstub/gop.c             |   6 +-
 drivers/firmware/efi/libstub/printk.c          |  93 ++----------
 drivers/firmware/efi/libstub/vsprintf.c        | 148 +++++++-------------
 lib/ucs2_string.c                              |   2 +-
 10 files changed, 87 insertions(+), 252 deletions(-)

-- 
2.47.3
Re: [PATCH 0/7] efi/libstub: Avoid UTF-16 conversion busywork
Posted by Vincent Mailhol 2 weeks, 6 days ago
On 06/09/2026 at 15:08, Ard Biesheuvel wrote:
> The EFI libstub performs some redundant conversions between UTF-16 and
> UTF-8 and back again, which includes dealing with surrogate pairs, which
> UEFI implementations themselves simply ignore.
> 
> So drop all the homegrown code, and use the existing UCS-2 (== UTF-16
> without surrogate pairs) library code where conversion to UTF-8 is
> actually needed (the kernel command line).
> 
> The remaining handling involves the EFI console, which supports wide
> characters natively, so just use those directly.
> 
> Cc: Vincent Mailhol <mailhol@kernel.org>
> Cc: x86@kernel.org

With the panic() dependency now resolved, this compiles and run well.
I rebased my BLI series on top of it and could confirm the good
behaviour of efi_snprintf(). I just sent a v3 of my BLI patch.

Link: https://lore.kernel.org/linux-efi/20260906-efi_stub_bli-v3-1-e7dc0d6b8fcd@kernel.org/


That said, sashiko has a few findings which looks relevant to me:

Link: https://sashiko.dev/#/patchset/20260906130817.1151961-9-ardb%40kernel.org

with the two most concerning findings being the correct handling of
ucs2_as_utf8()'s options argument when it is NULL and the correct
NUL-termination of the kernel cmdline.

I didn't try to reproduce those issues, but the report looked legit to
me.


Yours sincerely,
Vincent Mailhol