Skip to content

Commit 8f24f8c

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
efi/libstub: Annotate firmware routines as __efiapi
Annotate all the firmware routines (boot services, runtime services and protocol methods) called in the boot context as __efiapi, and make it expand to __attribute__((ms_abi)) on 64-bit x86. This allows us to use the compiler to generate the calls into firmware that use the MS calling convention instead of the SysV one. Signed-off-by: Ard Biesheuvel <[email protected]> Cc: Arvind Sankar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: James Morse <[email protected]> Cc: Matt Fleming <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 960a8d0 commit 8f24f8c

File tree

4 files changed

+96
-76
lines changed

4 files changed

+96
-76
lines changed

arch/x86/Kconfig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,11 +1991,12 @@ config EFI
19911991
platforms.
19921992

19931993
config EFI_STUB
1994-
bool "EFI stub support"
1995-
depends on EFI && !X86_USE_3DNOW
1996-
select RELOCATABLE
1997-
---help---
1998-
This kernel feature allows a bzImage to be loaded directly
1994+
bool "EFI stub support"
1995+
depends on EFI && !X86_USE_3DNOW
1996+
depends on $(cc-option,-mabi=ms) || X86_32
1997+
select RELOCATABLE
1998+
---help---
1999+
This kernel feature allows a bzImage to be loaded directly
19992000
by EFI firmware without the use of a bootloader.
20002001

20012002
See Documentation/admin-guide/efi-stub.rst for more information.

arch/x86/boot/compressed/eboot.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
1616

1717
union efi_uga_draw_protocol {
1818
struct {
19-
efi_status_t (*get_mode)(efi_uga_draw_protocol_t *,
20-
u32*, u32*, u32*, u32*);
19+
efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
20+
u32*, u32*, u32*, u32*);
2121
void *set_mode;
2222
void *blt;
2323
};

drivers/firmware/efi/libstub/random.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ typedef union efi_rng_protocol efi_rng_protocol_t;
1313

1414
union efi_rng_protocol {
1515
struct {
16-
efi_status_t (*get_info)(efi_rng_protocol_t *,
17-
unsigned long *, efi_guid_t *);
18-
efi_status_t (*get_rng)(efi_rng_protocol_t *,
19-
efi_guid_t *, unsigned long, u8 *out);
16+
efi_status_t (__efiapi *get_info)(efi_rng_protocol_t *,
17+
unsigned long *,
18+
efi_guid_t *);
19+
efi_status_t (__efiapi *get_rng)(efi_rng_protocol_t *,
20+
efi_guid_t *, unsigned long,
21+
u8 *out);
2022
};
2123
struct {
2224
u32 get_info;

include/linux/efi.h

Lines changed: 82 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ typedef u16 efi_char16_t; /* UNICODE character */
4848
typedef u64 efi_physical_addr_t;
4949
typedef void *efi_handle_t;
5050

51+
#ifdef CONFIG_X86_64
52+
#define __efiapi __attribute__((ms_abi))
53+
#else
54+
#define __efiapi
55+
#endif
56+
5157
#define efi_get_handle_at(array, idx) \
5258
(efi_is_native() ? (array)[idx] \
5359
: (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
@@ -272,13 +278,16 @@ typedef union {
272278
efi_table_hdr_t hdr;
273279
void *raise_tpl;
274280
void *restore_tpl;
275-
efi_status_t (*allocate_pages)(int, int, unsigned long,
276-
efi_physical_addr_t *);
277-
efi_status_t (*free_pages)(efi_physical_addr_t, unsigned long);
278-
efi_status_t (*get_memory_map)(unsigned long *, void *, unsigned long *,
279-
unsigned long *, u32 *);
280-
efi_status_t (*allocate_pool)(int, unsigned long, void **);
281-
efi_status_t (*free_pool)(void *);
281+
efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
282+
efi_physical_addr_t *);
283+
efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
284+
unsigned long);
285+
efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
286+
unsigned long *,
287+
unsigned long *, u32 *);
288+
efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
289+
void **);
290+
efi_status_t (__efiapi *free_pool)(void *);
282291
void *create_event;
283292
void *set_timer;
284293
void *wait_for_event;
@@ -288,18 +297,22 @@ typedef union {
288297
void *install_protocol_interface;
289298
void *reinstall_protocol_interface;
290299
void *uninstall_protocol_interface;
291-
efi_status_t (*handle_protocol)(efi_handle_t, efi_guid_t *, void **);
300+
efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
301+
efi_guid_t *, void **);
292302
void *__reserved;
293303
void *register_protocol_notify;
294-
efi_status_t (*locate_handle)(int, efi_guid_t *, void *,
295-
unsigned long *, efi_handle_t *);
304+
efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
305+
void *, unsigned long *,
306+
efi_handle_t *);
296307
void *locate_device_path;
297-
efi_status_t (*install_configuration_table)(efi_guid_t *, void *);
308+
efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
309+
void *);
298310
void *load_image;
299311
void *start_image;
300312
void *exit;
301313
void *unload_image;
302-
efi_status_t (*exit_boot_services)(efi_handle_t, unsigned long);
314+
efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
315+
unsigned long);
303316
void *get_next_monotonic_count;
304317
void *stall;
305318
void *set_watchdog_timer;
@@ -310,7 +323,8 @@ typedef union {
310323
void *open_protocol_information;
311324
void *protocols_per_handle;
312325
void *locate_handle_buffer;
313-
efi_status_t (*locate_protocol)(efi_guid_t *, void *, void **);
326+
efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
327+
void **);
314328
void *install_multiple_protocol_interfaces;
315329
void *uninstall_multiple_protocol_interfaces;
316330
void *calculate_crc32;
@@ -354,10 +368,11 @@ typedef struct {
354368
typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
355369

356370
typedef
357-
efi_status_t (*efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
358-
EFI_PCI_IO_PROTOCOL_WIDTH,
359-
u32 offset, unsigned long count,
360-
void *buffer);
371+
efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
372+
EFI_PCI_IO_PROTOCOL_WIDTH,
373+
u32 offset,
374+
unsigned long count,
375+
void *buffer);
361376

362377
typedef struct {
363378
void *read;
@@ -382,11 +397,11 @@ union efi_pci_io_protocol {
382397
void *allocate_buffer;
383398
void *free_buffer;
384399
void *flush;
385-
efi_status_t (*get_location)(efi_pci_io_protocol_t *,
386-
unsigned long *segment_nr,
387-
unsigned long *bus_nr,
388-
unsigned long *device_nr,
389-
unsigned long *function_nr);
400+
efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
401+
unsigned long *segment_nr,
402+
unsigned long *bus_nr,
403+
unsigned long *device_nr,
404+
unsigned long *func_nr);
390405
void *attributes;
391406
void *get_bar_attributes;
392407
void *set_bar_attributes;
@@ -441,16 +456,17 @@ typedef union apple_properties_protocol apple_properties_protocol_t;
441456
union apple_properties_protocol {
442457
struct {
443458
unsigned long version;
444-
efi_status_t (*get)(apple_properties_protocol_t *,
445-
struct efi_dev_path *, efi_char16_t *,
446-
void *, u32 *);
447-
efi_status_t (*set)(apple_properties_protocol_t *,
448-
struct efi_dev_path *, efi_char16_t *,
449-
void *, u32);
450-
efi_status_t (*del)(apple_properties_protocol_t *,
451-
struct efi_dev_path *, efi_char16_t *);
452-
efi_status_t (*get_all)(apple_properties_protocol_t *,
453-
void *buffer, u32 *);
459+
efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
460+
struct efi_dev_path *,
461+
efi_char16_t *, void *, u32 *);
462+
efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
463+
struct efi_dev_path *,
464+
efi_char16_t *, void *, u32);
465+
efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
466+
struct efi_dev_path *,
467+
efi_char16_t *);
468+
efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
469+
void *buffer, u32 *);
454470
};
455471
struct {
456472
u32 version;
@@ -468,11 +484,11 @@ typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
468484
union efi_tcg2_protocol {
469485
struct {
470486
void *get_capability;
471-
efi_status_t (*get_event_log)(efi_handle_t,
472-
efi_tcg2_event_log_format,
473-
efi_physical_addr_t *,
474-
efi_physical_addr_t *,
475-
efi_bool_t *);
487+
efi_status_t (__efiapi *get_event_log)(efi_handle_t,
488+
efi_tcg2_event_log_format,
489+
efi_physical_addr_t *,
490+
efi_physical_addr_t *,
491+
efi_bool_t *);
476492
void *hash_log_extend_event;
477493
void *submit_command;
478494
void *get_active_pcr_banks;
@@ -575,21 +591,21 @@ typedef efi_status_t efi_query_variable_store_t(u32 attributes,
575591

576592
typedef union {
577593
struct {
578-
efi_table_hdr_t hdr;
579-
efi_get_time_t *get_time;
580-
efi_set_time_t *set_time;
581-
efi_get_wakeup_time_t *get_wakeup_time;
582-
efi_set_wakeup_time_t *set_wakeup_time;
583-
efi_set_virtual_address_map_t *set_virtual_address_map;
584-
void *convert_pointer;
585-
efi_get_variable_t *get_variable;
586-
efi_get_next_variable_t *get_next_variable;
587-
efi_set_variable_t *set_variable;
588-
efi_get_next_high_mono_count_t *get_next_high_mono_count;
589-
efi_reset_system_t *reset_system;
590-
efi_update_capsule_t *update_capsule;
591-
efi_query_capsule_caps_t *query_capsule_caps;
592-
efi_query_variable_info_t *query_variable_info;
594+
efi_table_hdr_t hdr;
595+
efi_get_time_t __efiapi *get_time;
596+
efi_set_time_t __efiapi *set_time;
597+
efi_get_wakeup_time_t __efiapi *get_wakeup_time;
598+
efi_set_wakeup_time_t __efiapi *set_wakeup_time;
599+
efi_set_virtual_address_map_t __efiapi *set_virtual_address_map;
600+
void *convert_pointer;
601+
efi_get_variable_t __efiapi *get_variable;
602+
efi_get_next_variable_t __efiapi *get_next_variable;
603+
efi_set_variable_t __efiapi *set_variable;
604+
efi_get_next_high_mono_count_t __efiapi *get_next_high_mono_count;
605+
efi_reset_system_t __efiapi *reset_system;
606+
efi_update_capsule_t __efiapi *update_capsule;
607+
efi_query_capsule_caps_t __efiapi *query_capsule_caps;
608+
efi_query_variable_info_t __efiapi *query_variable_info;
593609
};
594610
efi_runtime_services_32_t mixed_mode;
595611
} efi_runtime_services_t;
@@ -806,7 +822,7 @@ union efi_loaded_image {
806822
__aligned_u64 image_size;
807823
unsigned int image_code_type;
808824
unsigned int image_data_type;
809-
efi_status_t (*unload)(efi_handle_t image_handle);
825+
efi_status_t ( __efiapi *unload)(efi_handle_t image_handle);
810826
};
811827
struct {
812828
u32 revision;
@@ -841,18 +857,19 @@ typedef union efi_file_handle efi_file_handle_t;
841857
union efi_file_handle {
842858
struct {
843859
u64 revision;
844-
efi_status_t (*open)(efi_file_handle_t *,
845-
efi_file_handle_t **,
846-
efi_char16_t *, u64, u64);
847-
efi_status_t (*close)(efi_file_handle_t *);
860+
efi_status_t (__efiapi *open)(efi_file_handle_t *,
861+
efi_file_handle_t **,
862+
efi_char16_t *, u64, u64);
863+
efi_status_t (__efiapi *close)(efi_file_handle_t *);
848864
void *delete;
849-
efi_status_t (*read)(efi_file_handle_t *, unsigned long *,
850-
void *);
865+
efi_status_t (__efiapi *read)(efi_file_handle_t *,
866+
unsigned long *, void *);
851867
void *write;
852868
void *get_position;
853869
void *set_position;
854-
efi_status_t (*get_info)(efi_file_handle_t *, efi_guid_t *,
855-
unsigned long *, void *);
870+
efi_status_t (__efiapi *get_info)(efi_file_handle_t *,
871+
efi_guid_t *, unsigned long *,
872+
void *);
856873
void *set_info;
857874
void *flush;
858875
};
@@ -876,8 +893,8 @@ typedef union efi_file_io_interface efi_file_io_interface_t;
876893
union efi_file_io_interface {
877894
struct {
878895
u64 revision;
879-
int (*open_volume)(efi_file_io_interface_t *,
880-
efi_file_handle_t **);
896+
int (__efiapi *open_volume)(efi_file_io_interface_t *,
897+
efi_file_handle_t **);
881898
};
882899
struct {
883900
u64 revision;
@@ -1346,8 +1363,8 @@ struct efivar_entry {
13461363
union efi_simple_text_output_protocol {
13471364
struct {
13481365
void *reset;
1349-
efi_status_t (*output_string)(efi_simple_text_output_protocol_t *,
1350-
efi_char16_t *);
1366+
efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
1367+
efi_char16_t *);
13511368
void *test_string;
13521369
};
13531370
struct {

0 commit comments

Comments
 (0)