Skip to contentSkip to conversation

efi/libstub: arm*: Pass latest memory map to the kernel

PATCH New James Morse 3 participants 4 messages Dec 19, 2016 – Dec 20, 2016 EFI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efi/libstub: arm*: Pass latest memory map to the kernel

From: Ard Biesheuvel <[email protected]>

As reported by James, the current libstub code involving the annotated memory map only works somewhat correctly by accident, due to the fact that a pool allocation happens to be reused immediately, retaining its former contents.

Instead of juggling memory maps, which makes the code more complex than it needs to be, simply put a placholder value into the FDT, and only write the actual value after ExitBootServices() has been called.

[Update mmap-size too, remove updated_fdt()s unused params and header entry]

---
Hi Ard,

This is a v2 of your patch that updates the mmap-size too. This solves the truncated memmap problem I saw with v1 on Seattle.

The original patch was CC-stable, so I think this should also have:

Fixes ed9cc156c42f ("efi/libstub: Use efi_exit_boot_services() in FDT")

Thanks,

James

 drivers/firmware/efi/libstub/efistub.h |  8 ----
 drivers/firmware/efi/libstub/fdt.c     | 75 +++++++++++++++++++++-------------
 2 files changed, 47 insertions(+), 36 deletions(-)
drivers/firmware/efi/libstub/efistub.h +0 -8
index ee49cd23ee63..fac67992bede 100644
@@ -30,14 +30,6 @@ efi_status_t efi_file_close(void *handle);
 
 unsigned long get_dram_base(efi_system_table_t *sys_table_arg);
 
-efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
-			unsigned long orig_fdt_size,
-			void *fdt, int new_fdt_size, char *cmdline_ptr,
-			u64 initrd_addr, u64 initrd_size,
-			efi_memory_desc_t *memory_map,
-			unsigned long map_size, unsigned long desc_size,
-			u32 desc_ver);
-
 efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table,
 					    void *handle,
 					    unsigned long *new_fdt_addr,
drivers/firmware/efi/libstub/fdt.c +47 -28

134 lines not on this page · raw message

Signature · 1 line
2.10.1
#1 lore raw

PATCH v2 1/1 efi/libstub: arm*: Pass latest memory map to the kernel

Quoted 26 lines · James Morse

From: Ard Biesheuvel <[email protected]>

As reported by James, the current libstub code involving the annotated memory map only works somewhat correctly by accident, due to the fact that a pool allocation happens to be reused immediately, retaining its former contents.

Instead of juggling memory maps, which makes the code more complex than it needs to be, simply put a placholder value into the FDT, and only write the actual value after ExitBootServices() has been called.

[Update mmap-size too, remove updated_fdt()s unused params and header entry]

---
Hi Ard,

This is a v2 of your patch that updates the mmap-size too. This solves the truncated memmap problem I saw with v1 on Seattle.

The original patch was CC-stable, so I think this should also have:

Fixes ed9cc156c42f ("efi/libstub: Use efi_exit_boot_services() in FDT")
Quoted 7 lines

Thanks,

James

 drivers/firmware/efi/libstub/efistub.h |  8 ----
 drivers/firmware/efi/libstub/fdt.c     | 75 +++++++++++++++++++++-------------
 2 files changed, 47 insertions(+), 36 deletions(-)

Thanks James. I've queued this one up in the 'urgent' queue and tagged it for stable. I'll send it to tip before the end of the week.

#2 lore raw

PATCH v2 1/1 efi/libstub: arm*: Pass latest memory map to the kernel

Quoted 29 lines · Matt Fleming
Quoted 28 lines · James Morse

From: Ard Biesheuvel <[email protected]>

As reported by James, the current libstub code involving the annotated memory map only works somewhat correctly by accident, due to the fact that a pool allocation happens to be reused immediately, retaining its former contents.

Instead of juggling memory maps, which makes the code more complex than it needs to be, simply put a placholder value into the FDT, and only write the actual value after ExitBootServices() has been called.

[Update mmap-size too, remove updated_fdt()s unused params and header entry]

---
Hi Ard,

This is a v2 of your patch that updates the mmap-size too. This solves the truncated memmap problem I saw with v1 on Seattle.

The original patch was CC-stable, so I think this should also have:

Fixes ed9cc156c42f ("efi/libstub: Use efi_exit_boot_services() in FDT")

Thanks,

Quoted 8 lines
Quoted 5 lines

James

 drivers/firmware/efi/libstub/efistub.h |  8 ----
 drivers/firmware/efi/libstub/fdt.c     | 75 +++++++++++++++++++++-------------
 2 files changed, 47 insertions(+), 36 deletions(-)

Thanks James. I've queued this one up in the 'urgent' queue and tagged it for stable. I'll send it to tip before the end of the week.

Could we fold the hunk below, please?

(quoted diff) +0 -0

b/drivers/firmware/efi/libstub/fdt.c
index 9b11b0559a23..90ab96845937 100644

drivers/firmware/efi/libstub/fdt.c +0 -0
@@ -149,26 +149,25 @@ static efi_status_t

update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
static efi_status_t update_fdt_memmap(void *fdt, u64 memmap, u32 map_size)

 {
        int node = fdt_path_offset(fdt, "/chosen");

- efi_status_t status;
+ int err;

        if (node < 0)
                return EFI_LOAD_ERROR;

        memmap = cpu_to_fdt64(memmap);

- status = fdt_setprop_inplace(fdt, node, "linux,uefi-mmap-start",
- &memmap, sizeof(memmap));
+ err = fdt_setprop_inplace(fdt, node, "linux,uefi-mmap-start",
+ &memmap, sizeof(memmap));

        if (status)
                return EFI_LOAD_ERROR;

        map_size = cpu_to_fdt32(map_size);

- status = fdt_setprop_inplace(fdt, node, "linux,uefi-mmap-size",
- &map_size, sizeof(map_size));
+ err = fdt_setprop_inplace(fdt, node, "linux,uefi-mmap-size",
+ &map_size, sizeof(map_size));

        if (status)
                return EFI_LOAD_ERROR;

-

        return EFI_SUCCESS;

}

My mistake, and harmless in practice, but sloppy nonetheless

#3 lore raw

PATCH v2 1/1 efi/libstub: arm*: Pass latest memory map to the kernel

Quoted 79 lines · Ard Biesheuvel
Quoted 29 lines · Matt Fleming
Quoted 28 lines · James Morse

From: Ard Biesheuvel <[email protected]>

As reported by James, the current libstub code involving the annotated memory map only works somewhat correctly by accident, due to the fact that a pool allocation happens to be reused immediately, retaining its former contents.

Instead of juggling memory maps, which makes the code more complex than it needs to be, simply put a placholder value into the FDT, and only write the actual value after ExitBootServices() has been called.

[Update mmap-size too, remove updated_fdt()s unused params and header entry]

---
Hi Ard,

This is a v2 of your patch that updates the mmap-size too. This solves the truncated memmap problem I saw with v1 on Seattle.

The original patch was CC-stable, so I think this should also have:

Fixes ed9cc156c42f ("efi/libstub: Use efi_exit_boot_services() in FDT")

Thanks,

Quoted 8 lines
Quoted 5 lines

James

 drivers/firmware/efi/libstub/efistub.h |  8 ----
 drivers/firmware/efi/libstub/fdt.c     | 75 +++++++++++++++++++++-------------
 2 files changed, 47 insertions(+), 36 deletions(-)

Thanks James. I've queued this one up in the 'urgent' queue and tagged it for stable. I'll send it to tip before the end of the week.

Could we fold the hunk below, please?

drivers/firmware/efi/libstub/fdt.c +5 -6
index 9b11b0559a23..90ab96845937 100644
@@ -149,26 +149,25 @@ static efi_status_t
 update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
 static efi_status_t update_fdt_memmap(void *fdt, u64 memmap, u32 map_size)
 {
        int node = fdt_path_offset(fdt, "/chosen");
-       efi_status_t status;
+       int err;
 
        if (node < 0)
                return EFI_LOAD_ERROR;
 
        memmap = cpu_to_fdt64(memmap);
-       status = fdt_setprop_inplace(fdt, node, "linux,uefi-mmap-start",
-                                    &memmap, sizeof(memmap));
+       err = fdt_setprop_inplace(fdt, node, "linux,uefi-mmap-start",
+                                 &memmap, sizeof(memmap));
 
        if (status)
                return EFI_LOAD_ERROR;
 
        map_size = cpu_to_fdt32(map_size);
-       status = fdt_setprop_inplace(fdt, node, "linux,uefi-mmap-size",
-                                    &map_size, sizeof(map_size));
+       err = fdt_setprop_inplace(fdt, node, "linux,uefi-mmap-size",
+                                 &map_size, sizeof(map_size));
 
        if (status)
                return EFI_LOAD_ERROR;
 
-
        return EFI_SUCCESS;
 }
Quoted 1 line

My mistake, and harmless in practice, but sloppy nonetheless

... but with the 'if (status)' replaced as well, of course (2x)