2018-12-17 19:47:04

by Ard Biesheuvel

[permalink] [raw]
Subject: [GIT PULL 0/2] Final EFI fixes for v4.20

The following changes since commit 7566ec393f4161572ba6f11ad5171fd5d59b0fbd:

Linux 4.20-rc7 (2018-12-16 15:46:55 -0800)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git tags/efi-urgent

for you to fetch changes up to 7b671e6a4917594a4e9ffd64111b8ac2e0323837:

efi: efi_guid_t must be 64-bit aligned (2018-12-17 10:42:26 +0100)

Note that applying Qian's patch will result in a conflict with the EFI
changes queued for the next window - the solution is to simply drop the
kmemleak_ignore() call since it is not required for page based
allocations.

----------------------------------------------------------------
Final EFI fixes for v4.20:
- prevent false positives from kmemleak for persistent memory reservations
- use the correct alignment for EFI GUIDs, preventing potential crashes in
firmware calls on 32-bit ARM

----------------------------------------------------------------
Heinrich Schuchardt (1):
efi: efi_guid_t must be 64-bit aligned

Qian Cai (1):
efi: let kmemleak ignore false positives

drivers/firmware/efi/efi.c | 3 +++
include/linux/efi.h | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)


2018-12-17 19:47:41

by Ard Biesheuvel

[permalink] [raw]
Subject: [PATCH 2/2] efi: efi_guid_t must be 64-bit aligned

From: Heinrich Schuchardt <[email protected]>

The UEFI Specification Version 2.7 Errata A defines:

"EFI_GUID
128-bit buffer containing a unique identifier value.
Unless otherwise specified, aligned on a 64-bit boundary."

Before this patch efi_guid_t was 8-bit aligned.

Note that this could potentially trigger alignment faults during
EFI runtime services calls on 32-bit ARM, given that it does not
permit load/store double or load/store multiple instructions to
operate on memory addresses that are not 32-bit aligned.

Cc: <[email protected]> # v4.9+, or earlier if possible
Signed-off-by: Heinrich Schuchardt <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
---
include/linux/efi.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/efi.h b/include/linux/efi.h
index 100ce4a4aff6..e6480c805932 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -48,7 +48,7 @@ typedef u16 efi_char16_t; /* UNICODE character */
typedef u64 efi_physical_addr_t;
typedef void *efi_handle_t;

-typedef guid_t efi_guid_t;
+typedef guid_t efi_guid_t __aligned(8);

#define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
--
2.17.1


2018-12-17 19:49:31

by Ard Biesheuvel

[permalink] [raw]
Subject: [PATCH 1/2] efi: let kmemleak ignore false positives

From: Qian Cai <[email protected]>

unreferenced object 0xffff8096c1acf580 (size 128):
comm "swapper/63", pid 0, jiffies 4294937418 (age 1201.230s)
hex dump (first 32 bytes):
80 87 b5 c1 96 00 00 00 00 00 cc c2 16 00 00 00 ................
00 00 01 00 00 00 00 00 6b 6b 6b 6b 6b 6b 6b 6b ........kkkkkkkk
backtrace:
[<000000001d2549ba>] kmem_cache_alloc_trace+0x430/0x500
[<0000000093a6dfab>] efi_mem_reserve_persistent+0x50/0xf8
[<000000000a730828>] its_cpu_init_lpis+0x394/0x4b8
[<00000000edf04e07>] its_cpu_init+0x104/0x150
[<000000004d0342c5>] gic_starting_cpu+0x34/0x40
[<000000005d9da772>] cpuhp_invoke_callback+0x228/0x1d68
[<0000000061eace9b>] notify_cpu_starting+0xc0/0x118
[<0000000048bc2dc5>] secondary_start_kernel+0x23c/0x3b0
[<0000000015137d6a>] 0xffffffffffffffff

efi_mem_reserve_persistent+0x50/0xf8:
kmalloc at include/linux/slab.h:546
(inlined by) efi_mem_reserve_persistent at drivers/firmware/efi/efi.c:979

This line,

rsv = kmalloc(sizeof(*rsv), GFP_ATOMIC);

Kmemleak has a known limitation that can only track pointers in the kernel
virtual space. Hence, it will report false positives due to "rsv" will only
reference to other physical addresses,

rsv->next = efi_memreserve_root->next;
efi_memreserve_root->next = __pa(rsv);

Signed-off-by: Qian Cai <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
---
drivers/firmware/efi/efi.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 415849bab233..7fcfe8a7ae98 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -31,6 +31,7 @@
#include <linux/acpi.h>
#include <linux/ucs2_string.h>
#include <linux/memblock.h>
+#include <linux/kmemleak.h>

#include <asm/early_ioremap.h>

@@ -1000,6 +1001,8 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
if (!rsv)
return -ENOMEM;

+ kmemleak_ignore(rsv);
+
rsv->base = addr;
rsv->size = size;

--
2.17.1


Subject: [tip:efi/urgent] efi: Let kmemleak ignore false positives

Commit-ID: a0fc5578f1d63ba6e80d9509991b4c14f6eaf488
Gitweb: https://git.kernel.org/tip/a0fc5578f1d63ba6e80d9509991b4c14f6eaf488
Author: Qian Cai <[email protected]>
AuthorDate: Mon, 17 Dec 2018 19:02:13 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Mon, 17 Dec 2018 19:12:47 +0100

efi: Let kmemleak ignore false positives

Address this kmemleak false positive :

unreferenced object 0xffff8096c1acf580 (size 128):
comm "swapper/63", pid 0, jiffies 4294937418 (age 1201.230s)
hex dump (first 32 bytes):
80 87 b5 c1 96 00 00 00 00 00 cc c2 16 00 00 00 ................
00 00 01 00 00 00 00 00 6b 6b 6b 6b 6b 6b 6b 6b ........kkkkkkkk
backtrace:
[<000000001d2549ba>] kmem_cache_alloc_trace+0x430/0x500
[<0000000093a6dfab>] efi_mem_reserve_persistent+0x50/0xf8
[<000000000a730828>] its_cpu_init_lpis+0x394/0x4b8
[<00000000edf04e07>] its_cpu_init+0x104/0x150
[<000000004d0342c5>] gic_starting_cpu+0x34/0x40
[<000000005d9da772>] cpuhp_invoke_callback+0x228/0x1d68
[<0000000061eace9b>] notify_cpu_starting+0xc0/0x118
[<0000000048bc2dc5>] secondary_start_kernel+0x23c/0x3b0
[<0000000015137d6a>] 0xffffffffffffffff

efi_mem_reserve_persistent+0x50/0xf8:
kmalloc at include/linux/slab.h:546
(inlined by) efi_mem_reserve_persistent at drivers/firmware/efi/efi.c:979

It's allocated by this line:

rsv = kmalloc(sizeof(*rsv), GFP_ATOMIC);

Kmemleak has a known limitation that can only track pointers in the kernel
virtual space. Hence, it will report false positives due to "rsv" will only
reference to other physical addresses:

rsv->next = efi_memreserve_root->next;
efi_memreserve_root->next = __pa(rsv);

So tell kmemleak to ignore the 'rsv' object.

[ mingo: Improved the changelog. ]

Signed-off-by: Qian Cai <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
drivers/firmware/efi/efi.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 415849bab233..7fcfe8a7ae98 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -31,6 +31,7 @@
#include <linux/acpi.h>
#include <linux/ucs2_string.h>
#include <linux/memblock.h>
+#include <linux/kmemleak.h>

#include <asm/early_ioremap.h>

@@ -1000,6 +1001,8 @@ int __ref efi_mem_reserve_persistent(phys_addr_t addr, u64 size)
if (!rsv)
return -ENOMEM;

+ kmemleak_ignore(rsv);
+
rsv->base = addr;
rsv->size = size;


Subject: [tip:efi/urgent] efi: Align 'efi_guid_t' to 64 bits

Commit-ID: 793423cf07e51e3185b8680167115813589c057d
Gitweb: https://git.kernel.org/tip/793423cf07e51e3185b8680167115813589c057d
Author: Heinrich Schuchardt <[email protected]>
AuthorDate: Mon, 17 Dec 2018 19:02:14 +0100
Committer: Ingo Molnar <[email protected]>
CommitDate: Mon, 17 Dec 2018 19:12:48 +0100

efi: Align 'efi_guid_t' to 64 bits

The UEFI Specification Version 2.7 Errata A defines:

"EFI_GUID
128-bit buffer containing a unique identifier value.
Unless otherwise specified, aligned on a 64-bit boundary."

Before this patch efi_guid_t was only 8-bit aligned.

Note that this could potentially trigger alignment faults during
EFI runtime services calls on 32-bit ARM, given that it does not
permit load/store double or load/store multiple instructions to
operate on memory addresses that are not 32-bit aligned.

Signed-off-by: Heinrich Schuchardt <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
Cc: <[email protected]> # v4.9+, or earlier if possible
Cc: Andy Lutomirski <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Qian Cai <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
include/linux/efi.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/efi.h b/include/linux/efi.h
index 100ce4a4aff6..e6480c805932 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -48,7 +48,7 @@ typedef u16 efi_char16_t; /* UNICODE character */
typedef u64 efi_physical_addr_t;
typedef void *efi_handle_t;

-typedef guid_t efi_guid_t;
+typedef guid_t efi_guid_t __aligned(8);

#define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)

2018-12-17 23:25:07

by Heinrich Schuchardt

[permalink] [raw]
Subject: Re: [tip:efi/urgent] efi: Align 'efi_guid_t' to 64 bits

On 12/17/18 7:16 PM, tip-bot for Heinrich Schuchardt wrote:
> Commit-ID: 793423cf07e51e3185b8680167115813589c057d
> Gitweb: https://git.kernel.org/tip/793423cf07e51e3185b8680167115813589c057d
> Author: Heinrich Schuchardt <[email protected]>
> AuthorDate: Mon, 17 Dec 2018 19:02:14 +0100
> Committer: Ingo Molnar <[email protected]>
> CommitDate: Mon, 17 Dec 2018 19:12:48 +0100
>
> efi: Align 'efi_guid_t' to 64 bits
>
> The UEFI Specification Version 2.7 Errata A defines:
>
> "EFI_GUID
> 128-bit buffer containing a unique identifier value.
> Unless otherwise specified, aligned on a 64-bit boundary."
>
> Before this patch efi_guid_t was only 8-bit aligned.
>
> Note that this could potentially trigger alignment faults during
> EFI runtime services calls on 32-bit ARM, given that it does not
> permit load/store double or load/store multiple instructions to
> operate on memory addresses that are not 32-bit aligned.
>
> Signed-off-by: Heinrich Schuchardt <[email protected]>
> Signed-off-by: Ard Biesheuvel <[email protected]>
> Cc: <[email protected]> # v4.9+, or earlier if possible
> Cc: Andy Lutomirski <[email protected]>
> Cc: Borislav Petkov <[email protected]>
> Cc: Dave Hansen <[email protected]>
> Cc: H. Peter Anvin <[email protected]>
> Cc: Linus Torvalds <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: Qian Cai <[email protected]>
> Cc: Rik van Riel <[email protected]>
> Cc: Thomas Gleixner <[email protected]>
> Cc: [email protected]
> Link: http://lkml.kernel.org/r/[email protected]
> Signed-off-by: Ingo Molnar <[email protected]>
> ---
> include/linux/efi.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/efi.h b/include/linux/efi.h
> index 100ce4a4aff6..e6480c805932 100644
> --- a/include/linux/efi.h
> +++ b/include/linux/efi.h
> @@ -48,7 +48,7 @@ typedef u16 efi_char16_t; /* UNICODE character */
> typedef u64 efi_physical_addr_t;
> typedef void *efi_handle_t;
>
> -typedef guid_t efi_guid_t;
> +
>
> #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
> GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
>

Before rushing this patch in, we should carefully review its side
effects, e.g. on 32bit system this changes the size of
efi_config_table_32_t from 20 to 24, which is part of the interface to
the UEFI firmware.

Best regards

Heinrich

2018-12-17 23:25:36

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: [tip:efi/urgent] efi: Align 'efi_guid_t' to 64 bits

On Mon, 17 Dec 2018 at 23:33, Heinrich Schuchardt <[email protected]> wrote:
>
> On 12/17/18 7:16 PM, tip-bot for Heinrich Schuchardt wrote:
> > Commit-ID: 793423cf07e51e3185b8680167115813589c057d
> > Gitweb: https://git.kernel.org/tip/793423cf07e51e3185b8680167115813589c057d
> > Author: Heinrich Schuchardt <[email protected]>
> > AuthorDate: Mon, 17 Dec 2018 19:02:14 +0100
> > Committer: Ingo Molnar <[email protected]>
> > CommitDate: Mon, 17 Dec 2018 19:12:48 +0100
> >
> > efi: Align 'efi_guid_t' to 64 bits
> >
> > The UEFI Specification Version 2.7 Errata A defines:
> >
> > "EFI_GUID
> > 128-bit buffer containing a unique identifier value.
> > Unless otherwise specified, aligned on a 64-bit boundary."
> >
> > Before this patch efi_guid_t was only 8-bit aligned.
> >
> > Note that this could potentially trigger alignment faults during
> > EFI runtime services calls on 32-bit ARM, given that it does not
> > permit load/store double or load/store multiple instructions to
> > operate on memory addresses that are not 32-bit aligned.
> >
> > Signed-off-by: Heinrich Schuchardt <[email protected]>
> > Signed-off-by: Ard Biesheuvel <[email protected]>
> > Cc: <[email protected]> # v4.9+, or earlier if possible
> > Cc: Andy Lutomirski <[email protected]>
> > Cc: Borislav Petkov <[email protected]>
> > Cc: Dave Hansen <[email protected]>
> > Cc: H. Peter Anvin <[email protected]>
> > Cc: Linus Torvalds <[email protected]>
> > Cc: Peter Zijlstra <[email protected]>
> > Cc: Qian Cai <[email protected]>
> > Cc: Rik van Riel <[email protected]>
> > Cc: Thomas Gleixner <[email protected]>
> > Cc: [email protected]
> > Link: http://lkml.kernel.org/r/[email protected]
> > Signed-off-by: Ingo Molnar <[email protected]>
> > ---
> > include/linux/efi.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/include/linux/efi.h b/include/linux/efi.h
> > index 100ce4a4aff6..e6480c805932 100644
> > --- a/include/linux/efi.h
> > +++ b/include/linux/efi.h
> > @@ -48,7 +48,7 @@ typedef u16 efi_char16_t; /* UNICODE character */
> > typedef u64 efi_physical_addr_t;
> > typedef void *efi_handle_t;
> >
> > -typedef guid_t efi_guid_t;
> > +
> >
> > #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
> > GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
> >
>
> Before rushing this patch in, we should carefully review its side
> effects, e.g. on 32bit system this changes the size of
> efi_config_table_32_t from 20 to 24, which is part of the interface to
> the UEFI firmware.
>

grmbl.

Thanks for spotting that.

The UEFI spec defines a GUID struct as { UINT32; UINT16; UINT16;
UINT8[8]; } so its natural alignment is 32 bits not 64 bits. The
alignment issue on ARM would be solved by using __aligned(4) rather
than __aligned(8), while not affecting the size of the config table
struct (and potentially others) on 32-bit architectures.

Ingo, apologies for the breakage. Do you prefer a replacement patch or
a followup patch?

2018-12-17 23:28:07

by Heinrich Schuchardt

[permalink] [raw]
Subject: Re: [tip:efi/urgent] efi: Align 'efi_guid_t' to 64 bits

On 12/17/18 11:42 PM, Ard Biesheuvel wrote:
> On Mon, 17 Dec 2018 at 23:33, Heinrich Schuchardt <[email protected]> wrote:
>>
>> On 12/17/18 7:16 PM, tip-bot for Heinrich Schuchardt wrote:
>>> Commit-ID: 793423cf07e51e3185b8680167115813589c057d
>>> Gitweb: https://git.kernel.org/tip/793423cf07e51e3185b8680167115813589c057d
>>> Author: Heinrich Schuchardt <[email protected]>
>>> AuthorDate: Mon, 17 Dec 2018 19:02:14 +0100
>>> Committer: Ingo Molnar <[email protected]>
>>> CommitDate: Mon, 17 Dec 2018 19:12:48 +0100
>>>
>>> efi: Align 'efi_guid_t' to 64 bits
>>>
>>> The UEFI Specification Version 2.7 Errata A defines:
>>>
>>> "EFI_GUID
>>> 128-bit buffer containing a unique identifier value.
>>> Unless otherwise specified, aligned on a 64-bit boundary."
>>>
>>> Before this patch efi_guid_t was only 8-bit aligned.
>>>
>>> Note that this could potentially trigger alignment faults during
>>> EFI runtime services calls on 32-bit ARM, given that it does not
>>> permit load/store double or load/store multiple instructions to
>>> operate on memory addresses that are not 32-bit aligned.
>>>
>>> Signed-off-by: Heinrich Schuchardt <[email protected]>
>>> Signed-off-by: Ard Biesheuvel <[email protected]>
>>> Cc: <[email protected]> # v4.9+, or earlier if possible
>>> Cc: Andy Lutomirski <[email protected]>
>>> Cc: Borislav Petkov <[email protected]>
>>> Cc: Dave Hansen <[email protected]>
>>> Cc: H. Peter Anvin <[email protected]>
>>> Cc: Linus Torvalds <[email protected]>
>>> Cc: Peter Zijlstra <[email protected]>
>>> Cc: Qian Cai <[email protected]>
>>> Cc: Rik van Riel <[email protected]>
>>> Cc: Thomas Gleixner <[email protected]>
>>> Cc: [email protected]
>>> Link: http://lkml.kernel.org/r/[email protected]
>>> Signed-off-by: Ingo Molnar <[email protected]>
>>> ---
>>> include/linux/efi.h | 2 +-
>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/include/linux/efi.h b/include/linux/efi.h
>>> index 100ce4a4aff6..e6480c805932 100644
>>> --- a/include/linux/efi.h
>>> +++ b/include/linux/efi.h
>>> @@ -48,7 +48,7 @@ typedef u16 efi_char16_t; /* UNICODE character */
>>> typedef u64 efi_physical_addr_t;
>>> typedef void *efi_handle_t;
>>>
>>> -typedef guid_t efi_guid_t;
>>> +
>>>
>>> #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
>>> GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
>>>
>>
>> Before rushing this patch in, we should carefully review its side
>> effects, e.g. on 32bit system this changes the size of
>> efi_config_table_32_t from 20 to 24, which is part of the interface to
>> the UEFI firmware.
>>
>
> grmbl.
>
> Thanks for spotting that.
>
> The UEFI spec defines a GUID struct as { UINT32; UINT16; UINT16;
> UINT8[8]; } so its natural alignment is 32 bits not 64 bits. The
> alignment issue on ARM would be solved by using __aligned(4) rather
> than __aligned(8), while not affecting the size of the config table
> struct (and potentially others) on 32-bit architectures.
>
> Ingo, apologies for the breakage. Do you prefer a replacement patch or
> a followup patch?
>

The UEFI spec explicitly requires EFI_GUID to be 64-bit aligned. On the
other hand neither EDK2 nor GRUB not U-Boot cared about this requirement
up to now. So the array of efi_config_table_32_t had 20 byte long
members at least on Linux, EDK2, GRUB, U-Boot, and possibly on other
UEFI implementations though the UEFI spec does not mention packing here.

As the 4.20 kernel release is imminent, please, keep this patch out
before causing breakage.

Best regards

Heinrich

2018-12-19 22:51:51

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: [tip:efi/urgent] efi: Align 'efi_guid_t' to 64 bits

On Tue, 18 Dec 2018 at 00:20, Heinrich Schuchardt <[email protected]> wrote:
>
> On 12/17/18 11:42 PM, Ard Biesheuvel wrote:
> > On Mon, 17 Dec 2018 at 23:33, Heinrich Schuchardt <[email protected]> wrote:
> >>
> >> On 12/17/18 7:16 PM, tip-bot for Heinrich Schuchardt wrote:
> >>> Commit-ID: 793423cf07e51e3185b8680167115813589c057d
> >>> Gitweb: https://git.kernel.org/tip/793423cf07e51e3185b8680167115813589c057d
> >>> Author: Heinrich Schuchardt <[email protected]>
> >>> AuthorDate: Mon, 17 Dec 2018 19:02:14 +0100
> >>> Committer: Ingo Molnar <[email protected]>
> >>> CommitDate: Mon, 17 Dec 2018 19:12:48 +0100
> >>>
> >>> efi: Align 'efi_guid_t' to 64 bits
> >>>
> >>> The UEFI Specification Version 2.7 Errata A defines:
> >>>
> >>> "EFI_GUID
> >>> 128-bit buffer containing a unique identifier value.
> >>> Unless otherwise specified, aligned on a 64-bit boundary."
> >>>
> >>> Before this patch efi_guid_t was only 8-bit aligned.
> >>>
> >>> Note that this could potentially trigger alignment faults during
> >>> EFI runtime services calls on 32-bit ARM, given that it does not
> >>> permit load/store double or load/store multiple instructions to
> >>> operate on memory addresses that are not 32-bit aligned.
> >>>
> >>> Signed-off-by: Heinrich Schuchardt <[email protected]>
> >>> Signed-off-by: Ard Biesheuvel <[email protected]>
> >>> Cc: <[email protected]> # v4.9+, or earlier if possible
> >>> Cc: Andy Lutomirski <[email protected]>
> >>> Cc: Borislav Petkov <[email protected]>
> >>> Cc: Dave Hansen <[email protected]>
> >>> Cc: H. Peter Anvin <[email protected]>
> >>> Cc: Linus Torvalds <[email protected]>
> >>> Cc: Peter Zijlstra <[email protected]>
> >>> Cc: Qian Cai <[email protected]>
> >>> Cc: Rik van Riel <[email protected]>
> >>> Cc: Thomas Gleixner <[email protected]>
> >>> Cc: [email protected]
> >>> Link: http://lkml.kernel.org/r/[email protected]
> >>> Signed-off-by: Ingo Molnar <[email protected]>
> >>> ---
> >>> include/linux/efi.h | 2 +-
> >>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/include/linux/efi.h b/include/linux/efi.h
> >>> index 100ce4a4aff6..e6480c805932 100644
> >>> --- a/include/linux/efi.h
> >>> +++ b/include/linux/efi.h
> >>> @@ -48,7 +48,7 @@ typedef u16 efi_char16_t; /* UNICODE character */
> >>> typedef u64 efi_physical_addr_t;
> >>> typedef void *efi_handle_t;
> >>>
> >>> -typedef guid_t efi_guid_t;
> >>> +
> >>>
> >>> #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
> >>> GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
> >>>
> >>
> >> Before rushing this patch in, we should carefully review its side
> >> effects, e.g. on 32bit system this changes the size of
> >> efi_config_table_32_t from 20 to 24, which is part of the interface to
> >> the UEFI firmware.
> >>
> >
> > grmbl.
> >
> > Thanks for spotting that.
> >
> > The UEFI spec defines a GUID struct as { UINT32; UINT16; UINT16;
> > UINT8[8]; } so its natural alignment is 32 bits not 64 bits. The
> > alignment issue on ARM would be solved by using __aligned(4) rather
> > than __aligned(8), while not affecting the size of the config table
> > struct (and potentially others) on 32-bit architectures.
> >
> > Ingo, apologies for the breakage. Do you prefer a replacement patch or
> > a followup patch?
> >
>
> The UEFI spec explicitly requires EFI_GUID to be 64-bit aligned. On the
> other hand neither EDK2 nor GRUB not U-Boot cared about this requirement
> up to now. So the array of efi_config_table_32_t had 20 byte long
> members at least on Linux, EDK2, GRUB, U-Boot, and possibly on other
> UEFI implementations though the UEFI spec does not mention packing here.
>
> As the 4.20 kernel release is imminent, please, keep this patch out
> before causing breakage.
>

Ingo,

Let's just drop Heinrich's patch for now, and I will come back to it
for the next release. There is very little EFI on 32-bit ARM in the
field, and this patch in its current form will break IA-32 as well, so
a quick followup fix is probably not the best approach here.

2018-12-21 07:56:29

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: [tip:efi/urgent] efi: Align 'efi_guid_t' to 64 bits

On Wed, 19 Dec 2018 at 23:50, Ard Biesheuvel <[email protected]> wrote:
>
> On Tue, 18 Dec 2018 at 00:20, Heinrich Schuchardt <[email protected]> wrote:
> >
> > On 12/17/18 11:42 PM, Ard Biesheuvel wrote:
> > > On Mon, 17 Dec 2018 at 23:33, Heinrich Schuchardt <[email protected]> wrote:
> > >>
> > >> On 12/17/18 7:16 PM, tip-bot for Heinrich Schuchardt wrote:
> > >>> Commit-ID: 793423cf07e51e3185b8680167115813589c057d
> > >>> Gitweb: https://git.kernel.org/tip/793423cf07e51e3185b8680167115813589c057d
> > >>> Author: Heinrich Schuchardt <[email protected]>
> > >>> AuthorDate: Mon, 17 Dec 2018 19:02:14 +0100
> > >>> Committer: Ingo Molnar <[email protected]>
> > >>> CommitDate: Mon, 17 Dec 2018 19:12:48 +0100
> > >>>
> > >>> efi: Align 'efi_guid_t' to 64 bits
> > >>>
> > >>> The UEFI Specification Version 2.7 Errata A defines:
> > >>>
> > >>> "EFI_GUID
> > >>> 128-bit buffer containing a unique identifier value.
> > >>> Unless otherwise specified, aligned on a 64-bit boundary."
> > >>>
> > >>> Before this patch efi_guid_t was only 8-bit aligned.
> > >>>
> > >>> Note that this could potentially trigger alignment faults during
> > >>> EFI runtime services calls on 32-bit ARM, given that it does not
> > >>> permit load/store double or load/store multiple instructions to
> > >>> operate on memory addresses that are not 32-bit aligned.
> > >>>
> > >>> Signed-off-by: Heinrich Schuchardt <[email protected]>
> > >>> Signed-off-by: Ard Biesheuvel <[email protected]>
> > >>> Cc: <[email protected]> # v4.9+, or earlier if possible
> > >>> Cc: Andy Lutomirski <[email protected]>
> > >>> Cc: Borislav Petkov <[email protected]>
> > >>> Cc: Dave Hansen <[email protected]>
> > >>> Cc: H. Peter Anvin <[email protected]>
> > >>> Cc: Linus Torvalds <[email protected]>
> > >>> Cc: Peter Zijlstra <[email protected]>
> > >>> Cc: Qian Cai <[email protected]>
> > >>> Cc: Rik van Riel <[email protected]>
> > >>> Cc: Thomas Gleixner <[email protected]>
> > >>> Cc: [email protected]
> > >>> Link: http://lkml.kernel.org/r/[email protected]
> > >>> Signed-off-by: Ingo Molnar <[email protected]>
> > >>> ---
> > >>> include/linux/efi.h | 2 +-
> > >>> 1 file changed, 1 insertion(+), 1 deletion(-)
> > >>>
> > >>> diff --git a/include/linux/efi.h b/include/linux/efi.h
> > >>> index 100ce4a4aff6..e6480c805932 100644
> > >>> --- a/include/linux/efi.h
> > >>> +++ b/include/linux/efi.h
> > >>> @@ -48,7 +48,7 @@ typedef u16 efi_char16_t; /* UNICODE character */
> > >>> typedef u64 efi_physical_addr_t;
> > >>> typedef void *efi_handle_t;
> > >>>
> > >>> -typedef guid_t efi_guid_t;
> > >>> +
> > >>>
> > >>> #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
> > >>> GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
> > >>>
> > >>
> > >> Before rushing this patch in, we should carefully review its side
> > >> effects, e.g. on 32bit system this changes the size of
> > >> efi_config_table_32_t from 20 to 24, which is part of the interface to
> > >> the UEFI firmware.
> > >>
> > >
> > > grmbl.
> > >
> > > Thanks for spotting that.
> > >
> > > The UEFI spec defines a GUID struct as { UINT32; UINT16; UINT16;
> > > UINT8[8]; } so its natural alignment is 32 bits not 64 bits. The
> > > alignment issue on ARM would be solved by using __aligned(4) rather
> > > than __aligned(8), while not affecting the size of the config table
> > > struct (and potentially others) on 32-bit architectures.
> > >
> > > Ingo, apologies for the breakage. Do you prefer a replacement patch or
> > > a followup patch?
> > >
> >
> > The UEFI spec explicitly requires EFI_GUID to be 64-bit aligned. On the
> > other hand neither EDK2 nor GRUB not U-Boot cared about this requirement
> > up to now. So the array of efi_config_table_32_t had 20 byte long
> > members at least on Linux, EDK2, GRUB, U-Boot, and possibly on other
> > UEFI implementations though the UEFI spec does not mention packing here.
> >
> > As the 4.20 kernel release is imminent, please, keep this patch out
> > before causing breakage.
> >
>
> Ingo,
>
> Let's just drop Heinrich's patch for now, and I will come back to it
> for the next release. There is very little EFI on 32-bit ARM in the
> field, and this patch in its current form will break IA-32 as well, so
> a quick followup fix is probably not the best approach here.

Ingo,

Could you please let me know what your plans are with this patch? It
has been pulled into -next now.

Please either drop it or revert it.