Re: [PATCH 10/10] efi/libstub/x86: avoid thunking for native firmware calls
From: Ard Biesheuvel
Date: Tue Dec 17 2019 - 03:32:51 EST
On Sun, 15 Dec 2019 at 21:31, Arvind Sankar <nivedita@xxxxxxxxxxxx> wrote:
>
> On Sat, Dec 14, 2019 at 06:57:35PM +0100, Ard Biesheuvel wrote:
> >
> > @@ -232,7 +232,7 @@ static inline bool efi_is_native(void)
> > #define efi_table_attr(table, attr, instance) ({ \
> > __typeof__(((table##_t *)0)->attr) __ret; \
> > if (efi_is_native()) { \
> > - __ret = ((table##_t *)instance)->attr; \
> > + __ret = instance->attr; \
> > } else { \
> > __typeof__(((table##_32_t *)0)->attr) at; \
> > at = (((table##_32_t *)(unsigned long)instance)->attr); \
>
> Is there a reason we didn't remove this cast for native-mode earlier in
> the series?
>
Yes. In patch 9/10, I fix a couple of occurrences where the protocol
pointer is a void*, so without the cast, things break.
> > @@ -242,19 +242,25 @@ static inline bool efi_is_native(void)
> > })
> >
> > #define efi_call_proto(protocol, f, instance, ...) \
> > - __efi_early()->call((unsigned long) \
> > + efi_is_native() \
> > + ? instance->f(instance, ##__VA_ARGS__) \
> > + : efi64_thunk((unsigned long) \
> > efi_table_attr(protocol, f, instance), \
> > - instance, ##__VA_ARGS__)
> > + instance, ##__VA_ARGS__)
> >
> > #define efi_call_early(f, ...) \
> > - __efi_early()->call((unsigned long) \
> > + efi_is_native() \
> > + ? __efi_early()->boot_services->f(__VA_ARGS__) \
> > + : efi64_thunk((unsigned long) \
> > efi_table_attr(efi_boot_services, f, \
> > - __efi_early()->boot_services), __VA_ARGS__)
> > + __efi_early()->boot_services), __VA_ARGS__)
> >
> > #define efi_call_runtime(f, ...) \
> > - __efi_early()->call((unsigned long) \
> > + efi_is_native() \
> > + ? __efi_early()->runtime_services->f(__VA_ARGS__) \
> > + : efi64_thunk((unsigned long) \
> > efi_table_attr(efi_runtime_services, f, \
> > - __efi_early()->runtime_services), __VA_ARGS__)
> > + __efi_early()->runtime_services), __VA_ARGS__)
> >
> > extern bool efi_reboot_required(void);
> > extern bool efi_is_table_address(unsigned long phys_addr);
>
> For the efi_call macros, their definition should be enclosed in
> parentheses now that it's a ternary operator.
Ack