: Change FDT memory typpe from runtime data to acpi reclaim
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type to EFI_ACPI_RECLAIM_MEMORY
--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/bootefi.c +2 -2
@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret =efi_allocate_pages (EFI_ALLOCATE_MAX_ADDRESS , -EFI_RUNTIME_SERVICES_DATA , fdt_pages, +EFI_ACPI_RECLAIM_MEMORY , fdt_pages, &new_fdt_addr);if (ret !=EFI_SUCCESS ) {/* If we can't put it there, put it somewhere */ new_fdt_addr = (ulong )memalign (EFI_PAGE_SIZE , fdt_size); ret =efi_allocate_pages (EFI_ALLOCATE_MAX_ADDRESS , -EFI_RUNTIME_SERVICES_DATA , fdt_pages, +EFI_ACPI_RECLAIM_MEMORY , fdt_pages, &new_fdt_addr);if (ret !=EFI_SUCCESS ) {printf ("ERROR: Failed to reserve space for FDT\n" );
Signature · 1 line
2.7.4
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 8 lines · Ilias Apalodimas
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>
It makes sense to mention that this actually fixes the boot issue you were seeing with the ARM Linux kernel when using short descriptors.
Quoted 27 lines
--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +2
-3@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret =efi_allocate_pages (EFI_ALLOCATE_MAX_ADDRESS , -EFI_RUNTIME_SERVICES_DATA , fdt_pages, +EFI_ACPI_RECLAIM_MEMORY , fdt_pages, &new_fdt_addr);if (ret !=EFI_SUCCESS ) {/* If we can't put it there, put it somewhere */ new_fdt_addr = (ulong )memalign (EFI_PAGE_SIZE , fdt_size); ret =efi_allocate_pages (EFI_ALLOCATE_MAX_ADDRESS , -EFI_RUNTIME_SERVICES_DATA , fdt_pages, +EFI_ACPI_RECLAIM_MEMORY , fdt_pages, &new_fdt_addr);if (ret !=EFI_SUCCESS ) {printf ("ERROR: Failed to reserve space for FDT\n" ); --2.7.4
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Hi Ard,
Quoted 8 lines
Quoted 6 lines · Ilias Apalodimas
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORY
Quoted 6 lines
Quoted 2 lines
Suggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>It makes sense to mention that this actually fixes the boot issue you were seeing with the ARM Linux kernel when using short descriptors.
I mentioned that in the original mail thread as you were typing this mail. Since i still think there *is* a kernel issue that should be fixed this just 'avoids' the problem. Not sure if it makes too much sense to include it here
Thanks
/Ilias
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
In reply to Ilias ApalodimasQuoted 16 lines · Ilias Apalodimas
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0
cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,
GRUB uses EfiLoaderCode when installing its modified version of the FDT.
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
How about functions efi_smbios_register() and efi_acpi_register()?
How about systab.tables assigned in efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.
The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
The FDT_TABLE_GUID or DEVICE_TREE_GUID as Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?
Best regards
Heinrich
Quoted 11 lines
cmd/bootefi.c +1
-1&new_fdt_addr);if (ret !=EFI_SUCCESS ) {/* If we can't put it there, put it somewhere */ new_fdt_addr = (ulong )memalign (EFI_PAGE_SIZE , fdt_size); ret =efi_allocate_pages (EFI_ALLOCATE_MAX_ADDRESS , -EFI_RUNTIME_SERVICES_DATA , fdt_pages, +EFI_ACPI_RECLAIM_MEMORY , fdt_pages, &new_fdt_addr);if (ret !=EFI_SUCCESS ) {printf ("ERROR: Failed to reserve space for FDT\n" );
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Hi Heinrich,
Quoted 34 lines · Ilias Apalodimas
Quoted 16 lines
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
How about functions
efi_smbios_register()andefi_acpi_register()?How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.
Quoted 7 lines
The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?
What about using EFI_BOOT_SERVICES_DATA instead of EFI_ACPI_RECLAIM_MEMORY? This still fixes the issue and doesn't cause any of the potential problems you mentioned
Thanks
/Ilias
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 39 lines · Ilias Apalodimas
Hi Heinrich,
Quoted 38 lines · Ilias Apalodimas
Quoted 16 lines
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
How about functions
efi_smbios_register()andefi_acpi_register()?How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
Quoted 7 lines
Quoted 3 lines
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?What about using
EFI_BOOT_SERVICES_DATAinstead ofEFI_ACPI_RECLAIM_MEMORY? This still fixes the issue and doesn't cause any of the potential problems you mentioned
Why services data and not loader data?
As said above we should consider all three supported tables ACPI, SMBIOS, and FDT when thinking about a fix. The UEFI spec describes that the addresses inside ACPI and SMBIOS tables are not fixed up when entering runtime.
This indicates that at least these tables have to be accessible at runtime. Why do you think that the FDT table should be treated differently to the ACPI table?
Best regards
Heinrich
Quoted 4 lines
Thanks
/Ilias
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 45 lines · Heinrich Schuchardt
Quoted 43 lines · Ilias Apalodimas
Hi Heinrich,
Quoted 41 lines · Ilias Apalodimas
Quoted 16 lines
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
How about functions
efi_smbios_register()andefi_acpi_register()?How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?
Quoted 6 lines
Quoted 3 lines
What about using
EFI_BOOT_SERVICES_DATAinstead ofEFI_ACPI_RECLAIM_MEMORY? This still fixes the issue and doesn't cause any of the potential problems you mentionedWhy services data and not loader data?
Services data is used by the boot services and loader data by the loader. GRUB is a loader so it uses loader data, u-boot is both boot services and a loader so it could arguably use both, but boot services data is more idiomatic.
From the pov of the OS, it makes no difference at all.
Quoted 7 lines
As said above we should consider all three supported tables ACPI, SMBIOS, and FDT when thinking about a fix. The UEFI spec describes that the addresses inside ACPI and SMBIOS tables are not fixed up when entering runtime.
This indicates that at least these tables have to be accessible at runtime.
Accessible at runtime but *not* by the runtime services themselves.
Quoted 2 lines
Why do you think that the FDT table should be treated> differently to the ACPI table?
Same thing. Accessible at runtime but not by the firmware services themselves.
Only data structures that the runtime services need to access in order to implement the functionality they expose to the OS should be in runtime services data memory. This applies to DT, ACPI and SMBIOS tables alike, but as I mentioned, for historical reasons, SMBIOS tables are usually exposed via runtime services data. Interestingly, the UEFI spec mentions that smbios tables should be located in runtime services data but no virtual mapping should be requested for them, and this is actually impossible in EDK2, so the current practice of using rtservicesdata for SMBIOS with the EFI_MEMORY_RUNTIME attribute set also violates the UEFI spec.
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 75 lines · Ard Biesheuvel
Quoted 45 lines · Heinrich Schuchardt
Quoted 43 lines · Ilias Apalodimas
Hi Heinrich,
Quoted 41 lines · Ilias Apalodimas
Quoted 16 lines
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
How about functions
efi_smbios_register()andefi_acpi_register()?How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?Quoted 6 lines
Quoted 3 lines
What about using
EFI_BOOT_SERVICES_DATAinstead ofEFI_ACPI_RECLAIM_MEMORY? This still fixes the issue and doesn't cause any of the potential problems you mentionedWhy services data and not loader data?
Services data is used by the boot services and loader data by the loader. GRUB is a loader so it uses loader data, u-boot is both boot services and a loader so it could arguably use both, but boot services data is more idiomatic.
Quoted 9 lines
From the pov of the OS, it makes no difference at all.
As said above we should consider all three supported tables ACPI, SMBIOS, and FDT when thinking about a fix. The UEFI spec describes that the addresses inside ACPI and SMBIOS tables are not fixed up when entering runtime.
This indicates that at least these tables have to be accessible at runtime.
Accessible at runtime but *not* by the runtime services themselves.
Quoted 2 lines
Why do you think that the FDT table should be treated> differently to the ACPI table?
Same thing. Accessible at runtime but not by the firmware services themselves.
Quoted 11 lines
Only data structures that the runtime services need to access in order to implement the functionality they expose to the OS should be in runtime services data memory. This applies to DT, ACPI and SMBIOS tables alike, but as I mentioned, for historical reasons, SMBIOS tables are usually exposed via runtime services data. Interestingly, the UEFI spec mentions that smbios tables should be located in runtime services data but no virtual mapping should be requested for them, and this is actually impossible in EDK2, so the current practice of using rtservicesdata for SMBIOS with the
EFI_MEMORY_RUNTIMEattribute set also violates the UEFI spec.
Hello Ilias, hello Ard,
please, have a look at this patch:
efi_loader: update virtual address in efi_mem_carve_out
https://lists.denx.de/pipermail/u-boot/2019-April/364937.html
Possibly the bug reported here could have contributed the Linux crash you experienced.
Best regards
Heinrich
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 91 lines · Heinrich Schuchardt
Quoted 75 lines · Ard Biesheuvel
Quoted 45 lines · Heinrich Schuchardt
Quoted 43 lines · Ilias Apalodimas
Hi Heinrich,
Quoted 41 lines · Ilias Apalodimas
Quoted 16 lines
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
How about functions
efi_smbios_register()andefi_acpi_register()?How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?Quoted 6 lines
Quoted 3 lines
What about using
EFI_BOOT_SERVICES_DATAinstead ofEFI_ACPI_RECLAIM_MEMORY? This still fixes the issue and doesn't cause any of the potential problems you mentionedWhy services data and not loader data?
Services data is used by the boot services and loader data by the loader. GRUB is a loader so it uses loader data, u-boot is both boot services and a loader so it could arguably use both, but boot services data is more idiomatic.
Quoted 9 lines
From the pov of the OS, it makes no difference at all.
As said above we should consider all three supported tables ACPI, SMBIOS, and FDT when thinking about a fix. The UEFI spec describes that the addresses inside ACPI and SMBIOS tables are not fixed up when entering runtime.
This indicates that at least these tables have to be accessible at runtime.
Accessible at runtime but *not* by the runtime services themselves.
Quoted 2 lines
Why do you think that the FDT table should be treated> differently to the ACPI table?
Same thing. Accessible at runtime but not by the firmware services themselves.
Quoted 11 lines
Only data structures that the runtime services need to access in order to implement the functionality they expose to the OS should be in runtime services data memory. This applies to DT, ACPI and SMBIOS tables alike, but as I mentioned, for historical reasons, SMBIOS tables are usually exposed via runtime services data. Interestingly, the UEFI spec mentions that smbios tables should be located in runtime services data but no virtual mapping should be requested for them, and this is actually impossible in EDK2, so the current practice of using rtservicesdata for SMBIOS with the
EFI_MEMORY_RUNTIMEattribute set also violates the UEFI spec.Hello Ilias, hello Ard,
Quoted 8 lines
please, have a look at this patch:
efi_loader: update virtual address inefi_mem_carve_out
https://lists.denx.de/pipermail/u-boot/2019-April/364937.htmlPossibly the bug reported here could have contributed the Linux crash you experienced.
Hello Heinrich,
That patch looks completely unrelated, to be honest.
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 97 lines · Ard Biesheuvel
Quoted 96 lines · Heinrich Schuchardt
Quoted 75 lines · Ard Biesheuvel
Quoted 45 lines · Heinrich Schuchardt
Quoted 43 lines · Ilias Apalodimas
Hi Heinrich,
Quoted 41 lines · Ilias Apalodimas
Quoted 16 lines
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
How about functions
efi_smbios_register()andefi_acpi_register()?How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?Quoted 6 lines
Quoted 3 lines
What about using
EFI_BOOT_SERVICES_DATAinstead ofEFI_ACPI_RECLAIM_MEMORY? This still fixes the issue and doesn't cause any of the potential problems you mentionedWhy services data and not loader data?
Services data is used by the boot services and loader data by the loader. GRUB is a loader so it uses loader data, u-boot is both boot services and a loader so it could arguably use both, but boot services data is more idiomatic.
Quoted 9 lines
From the pov of the OS, it makes no difference at all.
As said above we should consider all three supported tables ACPI, SMBIOS, and FDT when thinking about a fix. The UEFI spec describes that the addresses inside ACPI and SMBIOS tables are not fixed up when entering runtime.
This indicates that at least these tables have to be accessible at runtime.
Accessible at runtime but *not* by the runtime services themselves.
Quoted 2 lines
Why do you think that the FDT table should be treated> differently to the ACPI table?
Same thing. Accessible at runtime but not by the firmware services themselves.
Quoted 11 lines
Only data structures that the runtime services need to access in order to implement the functionality they expose to the OS should be in runtime services data memory. This applies to DT, ACPI and SMBIOS tables alike, but as I mentioned, for historical reasons, SMBIOS tables are usually exposed via runtime services data. Interestingly, the UEFI spec mentions that smbios tables should be located in runtime services data but no virtual mapping should be requested for them, and this is actually impossible in EDK2, so the current practice of using rtservicesdata for SMBIOS with the
EFI_MEMORY_RUNTIMEattribute set also violates the UEFI spec.Hello Ilias, hello Ard,
please, have a look at this patch:
efi_loader: update virtual address inefi_mem_carve_out
https://lists.denx.de/pipermail/u-boot/2019-April/364937.html
Quoted 8 lines
Quoted 3 lines
Possibly the bug reported here could have contributed the Linux crash you experienced.
Hello Heinrich,
That patch looks completely unrelated, to be honest.
I wondered if virtual address != physical address could be the cause why the Linux memory management is incorrectly initialized.
---
GRUB uses EfiLoaderCode when installing its modified version of the FDT.
In EDK II EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.c function DtPlatformLoadDtb() calls function AllocateCopyPool().
In MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c function AllocateCopyPool() uses EfiBootServicesData for the device tree
So I think using EfiBootServicesData in U-Boot should be safe.
Please, update the patch accordingly.
Best regards
Heinrich
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 103 lines · Heinrich Schuchardt
Quoted 101 lines · Ard Biesheuvel
Quoted 99 lines · Heinrich Schuchardt
Quoted 75 lines · Ard Biesheuvel
Quoted 45 lines · Heinrich Schuchardt
Quoted 43 lines · Ilias Apalodimas
Hi Heinrich,
Quoted 41 lines · Ilias Apalodimas
Quoted 16 lines
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
How about functions
efi_smbios_register()andefi_acpi_register()?How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?Quoted 6 lines
Quoted 3 lines
What about using
EFI_BOOT_SERVICES_DATAinstead ofEFI_ACPI_RECLAIM_MEMORY? This still fixes the issue and doesn't cause any of the potential problems you mentionedWhy services data and not loader data?
Services data is used by the boot services and loader data by the loader. GRUB is a loader so it uses loader data, u-boot is both boot services and a loader so it could arguably use both, but boot services data is more idiomatic.
Quoted 9 lines
From the pov of the OS, it makes no difference at all.
As said above we should consider all three supported tables ACPI, SMBIOS, and FDT when thinking about a fix. The UEFI spec describes that the addresses inside ACPI and SMBIOS tables are not fixed up when entering runtime.
This indicates that at least these tables have to be accessible at runtime.
Accessible at runtime but *not* by the runtime services themselves.
Quoted 2 lines
Why do you think that the FDT table should be treated> differently to the ACPI table?
Same thing. Accessible at runtime but not by the firmware services themselves.
Quoted 11 lines
Only data structures that the runtime services need to access in order to implement the functionality they expose to the OS should be in runtime services data memory. This applies to DT, ACPI and SMBIOS tables alike, but as I mentioned, for historical reasons, SMBIOS tables are usually exposed via runtime services data. Interestingly, the UEFI spec mentions that smbios tables should be located in runtime services data but no virtual mapping should be requested for them, and this is actually impossible in EDK2, so the current practice of using rtservicesdata for SMBIOS with the
EFI_MEMORY_RUNTIMEattribute set also violates the UEFI spec.Hello Ilias, hello Ard,
please, have a look at this patch:
efi_loader: update virtual address inefi_mem_carve_out
https://lists.denx.de/pipermail/u-boot/2019-April/364937.htmlPossibly the bug reported here could have contributed the Linux crash you experienced.
Quoted 8 lines
Quoted 4 lines
Hello Heinrich,
That patch looks completely unrelated, to be honest.
I wondered if virtual address != physical address could be the cause why the Linux memory management is incorrectly initialized.
The virtual address field is completely ignored by the early linux code, except for the case when it sets it itself, when passing back the memory map to SetVirtualAddressMap().
The only point where we inspect the virtual address field is when creating the runtime mapping based on the VA layout created by the stub (and passed into SetVirtualAddressMap()).
Quoted 8 lines
---
GRUB uses EfiLoaderCode when installing its modified version of the FDT.
In EDK II
EmbeddedPkg/Library/DxeDtPlatformDtbLoaderLibDefault/DxeDtPlatformDtbLoaderLibDefault.cfunctionDtPlatformLoadDtb()calls functionAllocateCopyPool().
Quoted 7 lines
In
MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.cfunctionAllocateCopyPool()uses EfiBootServicesData for the device treeSo I think using EfiBootServicesData in U-Boot should be safe.
Please, update the patch accordingly.
Either ACPI reclaim or BS data works for me
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
In reply to Heinrich SchuchardtHi Heinrich,
Quoted 11 lines
Hello Ilias, hello Ard,
please, have a look at this patch:
efi_loader: update virtual address inefi_mem_carve_out
https://lists.denx.de/pipermail/u-boot/2019-April/364937.htmlPossibly the bug reported here could have contributed the Linux crash you experienced.
Thanks for the heads up.
Unfortunately i've already tried that. I was talking to Patrick before he posted the patch upstream. This seems unrelated anyway (all my tests were with the patch applied regardless)
https://lore.kernel.org/linux-arm-kernel/20190411151320.GA23031 at apalos/ This has an explanation on the problem.
The tl;dr version (quoting Russell)
"It is also designed to allow hardware-section sized mappings (making it possible to map sections on 1MB granularity) but as a single Linux page table always occupies 2MB, it is not permitted for the unused half of an aligned 2MB slot to be used for a page table mapping - hence this BUG_ON().
The ARM early mapping routines are intentionally designed such that areas of memory that they are asked to map are non-overlapping - it is the caller's responsibility to ensure this."
In order to make sure this won't trigger we got to make sure that the fdt is placed on the first 1mb boundary of the memory (of any 2mb aligned area) thus forcing the kernel to init the pte's correctly,
instead of trying to do section mappings for the memory in that area.
The problem happens when you have a small no-map section within a 2MB region, and it does cross the even-odd 1MB boundary.
So fdt at 0x7f00000 (or any other are after that like 0xc7f01000) will crash the kernel with a BUG_ON().
Placing it in 0x7e01000-7eFF000 would be fine (on armv7's with LPAE off in the kernel)
Thanks
/Ilias
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 36 lines · Ilias Apalodimas
Hi Heinrich,
Quoted 11 lines
Hello Ilias, hello Ard,
please, have a look at this patch:
efi_loader: update virtual address inefi_mem_carve_out
https://lists.denx.de/pipermail/u-boot/2019-April/364937.htmlPossibly the bug reported here could have contributed the Linux crash you experienced.
Thanks for the heads up.
Unfortunately i've already tried that. I was talking to Patrick before he posted the patch upstream. This seems unrelated anyway (all my tests were with the patch applied regardless)
https://lore.kernel.org/linux-arm-kernel/20190411151320.GA23031 at apalos/ This has an explanation on the problem.The tl;dr version (quoting Russell)
"It is also designed to allow hardware-section sized mappings (making it possible to map sections on 1MB granularity) but as a single Linux page table always occupies 2MB, it is not permitted for the unused half of an aligned 2MB slot to be used for a page table mapping - hence this
BUG_ON().
The ARM early mapping routines are intentionally designed such that areas of memory that they are asked to map are non-overlapping - it is the caller's responsibility to ensure this."In order to make sure this won't trigger we got to make sure that the fdt is placed on the first 1mb boundary of the memory (of any 2mb aligned area) thus forcing the kernel to init the pte's correctly,
instead of trying to do section mappings for the memory in that area.
Quoted 7 lines
The problem happens when you have a small no-map section within a 2MB region, and it does cross the even-odd 1MB boundary.
So fdt at0x7f00000(or any other are after that like0xc7f01000) will crash the kernel with aBUG_ON().
Placing it in 0x7e01000-7eFF000 would be fine (on armv7's with LPAE off in the kernel)
I think Linux cannot make any assumptions about UEFI memory layout if it is not explicitly specified in the UEFI spec. Everything is simply a Linux bug.
Concerning FDT I suggest to stick to what EDK II does: use EfiBootServicesData.
Best regards
Heinrich
Quoted 3 lines
Thanks
/Ilias
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
In reply to Heinrich Schuchardt(+ Leif)
Quoted 26 lines · Heinrich Schuchardt
Quoted 16 lines · Ilias Apalodimas
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
Quoted 4 lines
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
In spite of the name, ACPI reclaim memory is fully specified by the UEFI spec, so whether you actually use ACPI or not is irrelevant. It is memory that can be treated by the OS as conventional memory if it doesn't care about preserving the contents.
Quoted 2 lines
How about functions
efi_smbios_register()andefi_acpi_register()?
SMBIOS uses RuntimeServicesData memory for historical reasons, but that is basically a mistake.
ACPI tables should use ACPI reclaim memory, and even the allocations they refer to (such as the bitmap referenced by the BGRT table) should use ACPI reclaim memory, which is another thing we are trying to get fixed in the spec.
Quoted 7 lines
How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
Indeed. So it is up to the publisher to update the reference, but I am not aware of any firmware implementations that do this in practice. It is typically assumed that a firmware component that is still active at runtime holds its own reference to data exposed via a configuration table, and updates the reference during SetVirtualAddressMap.
There is also a known bug in EDK2 where the ESRT table is passed in boot services memory, but the capsule update code actually tries to access it at runtime, so this isn't as clean as we'd like it to be.
Quoted 4 lines
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?
No, its de facto specification is in the EDK2 source tree.
Since there is no reason the firmware itself would need to consume the device tree at runtime, there is no point in keeping it in EfiRuntimeServicesData memory or in updating the configuration table entry.
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 67 lines · Ard Biesheuvel
(+ Leif)
Quoted 26 lines · Heinrich Schuchardt
Quoted 16 lines · Ilias Apalodimas
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
Quoted 4 lines
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
In spite of the name, ACPI reclaim memory is fully specified by the UEFI spec, so whether you actually use ACPI or not is irrelevant. It is memory that can be treated by the OS as conventional memory if it doesn't care about preserving the contents.
Quoted 2 lines
How about functions
efi_smbios_register()andefi_acpi_register()?SMBIOS uses RuntimeServicesData memory for historical reasons, but that is basically a mistake.
ACPI tables should use ACPI reclaim memory, and even the allocations they refer to (such as the bitmap referenced by the BGRT table) should use ACPI reclaim memory, which is another thing we are trying to get fixed in the spec.Quoted 7 lines
How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
Indeed. So it is up to the publisher to update the reference, but I am not aware of any firmware implementations that do this in practice. It is typically assumed that a firmware component that is still active at runtime holds its own reference to data exposed via a configuration table, and updates the reference during SetVirtualAddressMap.
There is also a known bug in EDK2 where the ESRT table is passed in boot services memory, but the capsule update code actually tries to access it at runtime, so this isn't as clean as we'd like it to be.
Quoted 6 lines
Quoted 4 lines
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?No, its de facto specification is in the EDK2 source tree.
As all ARM systems use it I guess this GUID should move into the UEFI spec. Maybe Linaro could raise this issue.
Best regards
Heinrich
Quoted 6 lines
Since there is no reason the firmware itself would need to consume the device tree at runtime, there is no point in keeping it in EfiRuntimeServicesData memory or in updating the configuration table entry.
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
Quoted 74 lines · Heinrich Schuchardt
Quoted 72 lines · Ard Biesheuvel
(+ Leif)
Quoted 26 lines · Heinrich Schuchardt
Quoted 16 lines · Ilias Apalodimas
Following Ard's suggestion:
Runtime data sections are intended for data that is used by the runtime services implementations.
Let's change they type toEFI_ACPI_RECLAIM_MEMORYSuggested-by Ard Biesheuvel <[email protected]>Signed-off-by Ilias Apalodimas <[email protected]>--- cmd/bootefi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)cmd/bootefi.c +0
-0cmd/bootefi.c static efi_status_t copy_fdt(void **fdtp) · line 114
Quoted 5 lines
cmd/bootefi.c +1
-1@@ -111,13 +111,13 @@ static efi_status_t copy_fdt(void **fdtp) new_fdt_addr = (uintptr_t )map_sysmem (fdt_ram_start +0x7f00000 + fdt_size,0 ); ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, - EFI_RUNTIME_SERVICES_DATA, fdt_pages, + EFI_ACPI_RECLAIM_MEMORY, fdt_pages,GRUB uses EfiLoaderCode when installing its modified version of the FDT.
Quoted 4 lines
The "Embedded Base Boot Requirements (EBBR) Specification, Release v1.0" does not require ACPI support. Can we expect EfiACPIReclaimMemory to be supported if we do not have any ACPI table?
In spite of the name, ACPI reclaim memory is fully specified by the UEFI spec, so whether you actually use ACPI or not is irrelevant. It is memory that can be treated by the OS as conventional memory if it doesn't care about preserving the contents.
Quoted 2 lines
How about functions
efi_smbios_register()andefi_acpi_register()?SMBIOS uses RuntimeServicesData memory for historical reasons, but that is basically a mistake.
ACPI tables should use ACPI reclaim memory, and even the allocations they refer to (such as the bitmap referenced by the BGRT table) should use ACPI reclaim memory, which is another thing we are trying to get fixed in the spec.Quoted 7 lines
How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
Indeed. So it is up to the publisher to update the reference, but I am not aware of any firmware implementations that do this in practice. It is typically assumed that a firmware component that is still active at runtime holds its own reference to data exposed via a configuration table, and updates the reference during SetVirtualAddressMap.
There is also a known bug in EDK2 where the ESRT table is passed in boot services memory, but the capsule update code actually tries to access it at runtime, so this isn't as clean as we'd like it to be.
Quoted 4 lines
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?
Quoted 5 lines
Quoted 1 line
No, its de facto specification is in the EDK2 source tree.
As all ARM systems use it I guess this GUID should move into the UEFI spec. Maybe Linaro could raise this issue.
The whole purpose of using GUIDs is that they are guaranteed to be unique, and so they don't all have to be recorded in the same spec in order to be usable safely in combination. So we could add it to the UEFI spec, or to some other spec, or not at all, but it is not really relevant to the discussion.
PATCH 1/1 : Change FDT memory typpe from runtime data to acpi reclaim
In reply to Heinrich SchuchardtQuoted 18 lines · Heinrich Schuchardt
Quoted 18 lines
Quoted 7 lines
How about systab.tables assigned in
efi_initialize_system_table()? Which of the addresses in systab.tables should be updated upon relocation.The EFI Spec is really hazy: "A pointer to the table associated with VendorGuid. Whether this pointer is a physical address or a virtual address during runtime is determined by the VendorGuid."
Indeed. So it is up to the publisher to update the reference, but I am not aware of any firmware implementations that do this in practice. It is typically assumed that a firmware component that is still active at runtime holds its own reference to data exposed via a configuration table, and updates the reference during SetVirtualAddressMap.
There is also a known bug in EDK2 where the ESRT table is passed in boot services memory, but the capsule update code actually tries to access it at runtime, so this isn't as clean as we'd like it to be.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
The
FDT_TABLE_GUIDorDEVICE_TREE_GUIDas Linux calls it is not defined in the UEFI spec. So we can marvel about expected behavior. Is there any other document specifying it?No, its de facto specification is in the EDK2 source tree.
Well, in reality, it appeared simultanously-ish in Linux and GRUB, and I think is entry into the EDK2 codebase came later :)
Quoted 2 lines
As all ARM systems use it I guess this GUID should move into the UEFI spec. Maybe Linaro could raise this issue.
While the UEFI specification does list the ACPI, ACPI_20, SMBIOS, and some other common GUIDs, this is not where they are defined. If it needs to go into some specification, that would probably be the devicetree.org one.
/
Leif