Skip to content

efi/x86: confine type unsafe casting to mixed mode

Ard Biesheuvel linux-efi 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest21 patches 65 repliesIn review
  2. v110 patches 18 repliesSuperseded

Changes in v2 from the cover letter

- Substantially more cleanup work to simplify and hide the mixed mode handling in generic EFI code.
- Get rid of all the pointless passing around of sys_table_arg
- Incorporate an updated version of Matthew's PCI DMA disable patch using EFI events to defer poking the busmaster bits until after all the ordinary ExitBootServices() callbacks have executed.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/21efi/libstub: remove unused __efi_call_early() macroarch/arm/include/asm/efi.h arch/arm64/include/asm/efi.h arch/x86/include/asm/efi.h+0 -50 replies
2/21efi/x86: rename efi_is_native() to efi_is_mixed()arch/x86/include/asm/efi.h arch/x86/platform/efi/efi.c arch/x86/platform/efi/efi_64.c +1 more+13 -110 replies
3/21efi/libstub: use a helper to iterate over a EFI handle arrayarch/x86/boot/compressed/eboot.c drivers/firmware/efi/libstub/gop.c include/linux/efi.h+20 -160 replies
4/21efi/libstub: extend native protocol definitions with mixed_mode aliasesarch/x86/boot/compressed/eboot.h drivers/firmware/efi/libstub/arm-stub.c drivers/firmware/efi/libstub/random.c +1 more+365 -1820 replies
5/21efi/libstub: distinguish between native/mixed not 32/64 bitarch/arm/include/asm/efi.h arch/arm64/include/asm/efi.h arch/x86/boot/compressed/eboot.c +3 more+51 -460 replies
6/21efi/libstub/x86: use mixed mode helpers to populate efi_configarch/x86/boot/compressed/eboot.c arch/x86/boot/compressed/head_32.S arch/x86/include/asm/efi.h +2 more+18 -310 replies
7/21efi/libstub: drop explicit 32/64-bit protocol definitionsarch/x86/boot/compressed/eboot.h drivers/firmware/efi/libstub/random.c include/linux/efi.h+1 -2540 replies
8/21efi/libstub: use stricter typing for firmware function pointersarch/x86/boot/compressed/eboot.c arch/x86/boot/compressed/eboot.h drivers/firmware/efi/libstub/efi-stub-helper.c +2 more+22 -120 replies
9/21efi/libstub: annotate firmware routines as __efiapiarch/x86/Kconfig arch/x86/boot/compressed/eboot.h drivers/firmware/efi/libstub/random.c +1 more+96 -750 replies
10/21efi/libstub/x86: avoid thunking for native firmware callsarch/x86/boot/compressed/Makefile arch/x86/boot/compressed/efi_stub_32.S arch/x86/boot/compressed/efi_stub_64.S +4 more+17 -1279 replies
11/21efi/libstub: get rid of 'sys_table_arg' macro parameterarch/arm/include/asm/efi.h arch/arm64/include/asm/efi.h arch/x86/boot/compressed/eboot.c +3 more+27 -90 replies
12/21efi/libstub: unify the efi_char16_printk implementationsarch/x86/boot/compressed/eboot.c drivers/firmware/efi/libstub/arm-stub.c drivers/firmware/efi/libstub/efi-stub-helper.c+9 -150 replies
13/21efi/libstub/x86: drop __efi_early() export of efi_config structarch/x86/boot/compressed/eboot.c arch/x86/boot/compressed/head_32.S arch/x86/boot/compressed/head_64.S +1 more+26 -3926 replies
14/21efi/libstub: drop sys_table_arg from printk routinesarch/x86/boot/compressed/eboot.c drivers/firmware/efi/libstub/arm-stub.c drivers/firmware/efi/libstub/arm32-stub.c +7 more+75 -780 replies
15/21efi/libstub: remove 'sys_table_arg' from all function prototypesarch/arm/include/asm/efi.h arch/arm64/include/asm/efi.h arch/x86/boot/compressed/eboot.c +11 more+147 -1910 replies
16/21efi/libstub: drop protocol argument from efi_call_proto() macroarch/arm/include/asm/efi.h arch/arm64/include/asm/efi.h arch/x86/boot/compressed/eboot.c +4 more+32 -440 replies
17/21efi/libstub: drop 'table' argument from efi_table_attr() macroarch/arm/include/asm/efi.h arch/arm64/include/asm/efi.h arch/x86/boot/compressed/eboot.c +3 more+23 -380 replies
18/21efi/libstub: use 'func' not 'f' as macro parameterarch/arm64/include/asm/efi.h arch/x86/include/asm/efi.h+8 -83 replies
19/21efi/libstub: tidy up types and names of global cmdline variablesdrivers/firmware/efi/libstub/efi-stub-helper.c drivers/firmware/efi/libstub/efistub.h+20 -200 replies
20/21efi/libstub: import type definitions for creating and signalling eventsinclude/linux/efi.h+21 -20 replies
21/21efi: Allow disabling PCI busmastering on bridges during bootDocumentation/admin-guide/kernel-parameters.txt arch/x86/boot/compressed/eboot.c drivers/firmware/efi/Kconfig +6 more+166 -125 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 00/21] efi/x86: confine type unsafe casting to mixed mode

Currently, we support mixed mode (64-bit Linux running on 32-bit firmware) by explicitly reasoning about pointer sizes for every call into the
firmware: on x86, there are 32-bit and 64-bit versions of each protocol interface, and each call gets routed via one of the two, depending on the native size of the firmware.

There is a lot of casting and pointer mangling involved in this, and as a result, we end up with much less coverage in terms of type checking by the compiler, due to the indirection via an anonymous, variadic thunking routine.

This peculiarity of x86 is also leaking into generic EFI code, which is shared with ia64, arm64, ARM and likely RiscV in the future. So let's try to clean this up a bit.

The approach taken by this series is to replace the 32/64 bit distinction with a distinction between native calls and mixed mode calls, where the former can be either 32 or 64 bit [depending on the platform] and use the ordinary native protocol definitions, while mixed mode calls retain the existing casting/thunking approach based on the 32-bit protocol definitions.

Given that GCC now supports emitting function calls using the MS calling convention, we can get rid of all the wrapping and casting, and emit the indirect calls directly.

Changes since v1:
- Substantially more cleanup work to simplify and hide the mixed mode handling in generic EFI code.
- Get rid of all the pointless passing around of sys_table_arg
- Incorporate an updated version of Matthew's PCI DMA disable patch using EFI events to defer poking the busmaster bits until after all the ordinary ExitBootServices() callbacks have executed.

Code can be found here
https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=efistub-x86-cleanup-v2

Cc Hans de Goede <[email protected]>
Cc Matthew Garrett <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Arvind Sankar <[email protected]>

Ard Biesheuvel (20):
efi/libstub: remove unused __efi_call_early() macro efi/x86: rename efi_is_native() to efi_is_mixed() efi/libstub: use a helper to iterate over a EFI handle array efi/libstub: extend native protocol definitions with mixed_mode
aliases
efi/libstub: distinguish between native/mixed not 32/64 bit efi/libstub/x86: use mixed mode helpers to populate efi_config efi/libstub: drop explicit 32/64-bit protocol definitions efi/libstub: use stricter typing for firmware function pointers efi/libstub: annotate firmware routines as __efiapi efi/libstub/x86: avoid thunking for native firmware calls efi/libstub: get rid of 'sys_table_arg' macro parameter efi/libstub: unify the efi_char16_printk implementations efi/libstub/x86: drop __efi_early() export of efi_config struct efi/libstub: drop sys_table_arg from printk routines efi/libstub: remove 'sys_table_arg' from all function prototypes efi/libstub: drop protocol argument from efi_call_proto() macro efi/libstub: drop 'table' argument from efi_table_attr() macro efi/libstub: use 'func' not 'f' as macro parameter efi/libstub: tidy up types and names of global cmdline variables efi/libstub: import type definitions for creating and signalling
events

Matthew Garrett (1):
efi: Allow disabling PCI busmastering on bridges during boot

 .../admin-guide/kernel-parameters.txt         |   4 +
 arch/arm/include/asm/efi.h                    |  17 +-
 arch/arm64/include/asm/efi.h                  |  16 +-
 arch/x86/Kconfig                              |   1 +
 arch/x86/boot/compressed/Makefile             |   2 +-
 arch/x86/boot/compressed/eboot.c              | 180 ++--
 arch/x86/boot/compressed/eboot.h              |  30 +-
 arch/x86/boot/compressed/efi_stub_32.S        |  87 --
 arch/x86/boot/compressed/efi_stub_64.S        |   5 -
 arch/x86/boot/compressed/head_32.S            |   8 +-
 arch/x86/boot/compressed/head_64.S            |  16 +-
 arch/x86/include/asm/efi.h                    |  76 +-
 arch/x86/platform/efi/efi.c                   |  12 +-
 arch/x86/platform/efi/efi_64.c                |   6 +-
 arch/x86/platform/efi/quirks.c                |   2 +-
 drivers/firmware/efi/Kconfig                  |  22 +
 drivers/firmware/efi/libstub/Makefile         |   2 +-
 drivers/firmware/efi/libstub/arm-stub.c       |  98 ++-
 drivers/firmware/efi/libstub/arm32-stub.c     |  40 +-
 drivers/firmware/efi/libstub/arm64-stub.c     |  24 +-
 .../firmware/efi/libstub/efi-stub-helper.c    | 226 +++--
 drivers/firmware/efi/libstub/efistub.h        |  35 +-
 drivers/firmware/efi/libstub/fdt.c            |  53 +-
 drivers/firmware/efi/libstub/gop.c            |  30 +-
 drivers/firmware/efi/libstub/pci.c            | 116 +++
 drivers/firmware/efi/libstub/random.c         |  54 +-
 drivers/firmware/efi/libstub/secureboot.c     |   6 +-
 drivers/firmware/efi/libstub/tpm.c            |  23 +-
 include/linux/efi.h                           | 816 +++++++++---------
 29 files changed, 980 insertions(+), 1027 deletions(-)
 delete mode 100644 arch/x86/boot/compressed/efi_stub_32.S
 delete mode 100644 arch/x86/boot/compressed/efi_stub_64.S
 create mode 100644 drivers/firmware/efi/libstub/pci.c
Signature · 1 line
2.17.1