Skip to contentSkip to conversation

x86 EFI: Bypass call to fdt_check_header()

RFC PATCH Superseded Pavan Kumar Paluri 4 participants 13 messages Mar 25, 2024 – Mar 26, 2024

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/3 x86 EFI: Bypass call to fdt_check_header()

Issuing a call to fdt_check_header() prevents running any of x86 UEFI enabled tests. Bypass this call for x86 in order to enable UEFI supported tests for KUT x86 arch.

Fixes 9632ce446b8f ("arm64: efi: Improve device tree discovery")
---
 lib/efi.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/efi.c +4 -0
index 5314eaa81e66..124e77685230 100644
@@ -328,6 +328,10 @@ static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
 		return NULL;
 	}
 
+#ifdef __x86_64__
+	return fdt;
+#endif
+
 	return fdt_check_header(fdt) == 0 ? fdt : NULL;
 }
 
Signature · 1 line
2.34.1
#1 lore raw

RFC PATCH 2/3 x86/efi: Retry call to efi exit boot services

In some cases, KUT guest might fail to exit boot services due to a possible memory map update that might have taken place between efi_get_memory_map() and efi_exit_boot_services() calls. As per UEFI spec 2.10 (Section 7.4.6 EFI_BOOT_SERVICES.ExitBootServices()), we need to update the memory map and retry call to exit boot services.

---
 lib/efi.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
lib/efi.c +18 -5
index 124e77685230..9d066bfad0b6 100644
@@ -458,14 +458,27 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
 	}
 #endif
 
-	/* 
+	/*
 	 * Exit EFI boot services, let kvm-unit-tests take full control of the
-	 * guest
+	 * guest.
 	 */
 	status = efi_exit_boot_services(handle, &efi_bootinfo.mem_map);
-	if (status != EFI_SUCCESS) {
-		printf("Failed to exit boot services\n");
-		goto efi_main_error;
+
+	/*
+	 * There is a possibility that memory map might have changed
+	 * between efi_get_memory_map() and efi_exit_boot_services in
+	 * which case status is EFI_INVALID_PARAMETER. As per UEFI spec
+	 * 2.10, we need to get the updated memory map and try again.
+	 */
+	if (status == EFI_INVALID_PARAMETER) {
+		efi_get_memory_map(&efi_bootinfo.mem_map);
+
+		status = efi_exit_boot_services(handle,
+						&efi_bootinfo.mem_map);
+		if (status != EFI_SUCCESS) {
+			printf("Failed to exit boot services\n");
+			goto efi_main_error;
+		}
 	}
 
 	/* Set up arch-specific resources */
Signature · 1 line
2.34.1
#2 lore raw

Re: [kvm-unit-tests RFC PATCH 2/3] x86/efi: Retry call to efi exit boot services

Quoted 28 lines · Pavan Kumar Paluri

In some cases, KUT guest might fail to exit boot services due to a possible memory map update that might have taken place between efi_get_memory_map() and efi_exit_boot_services() calls. As per UEFI spec 2.10 (Section 7.4.6 EFI_BOOT_SERVICES.ExitBootServices()), we need to update the memory map and retry call to exit boot services.

---
 lib/efi.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
lib/efi.c +2 -3
index 124e77685230..9d066bfad0b6 100644
@@ -458,14 +458,27 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
 	}
 #endif
 
-	/* 
+	/*
 	 * Exit EFI boot services, let kvm-unit-tests take full control of the
-	 * guest
+	 * guest.
 	 */
 	status = efi_exit_boot_services(handle, &efi_bootinfo.mem_map);
-	if (status != EFI_SUCCESS) {

lib/efi.c efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) · line 473

Quoted 10 lines
lib/efi.c +8 -2
-		printf("Failed to exit boot services\n");
-		goto efi_main_error;
+
+	/*
+	 * There is a possibility that memory map might have changed
+	 * between efi_get_memory_map() and efi_exit_boot_services in
+	 * which case status is EFI_INVALID_PARAMETER. As per UEFI spec
+	 * 2.10, we need to get the updated memory map and try again.
+	 */
+	if (status == EFI_INVALID_PARAMETER) {

Shouldn't we loop on this? The spec doesn't make it clear that the second try should always work.

Quoted 14 lines
lib/efi.c +8 -0
+		efi_get_memory_map(&efi_bootinfo.mem_map);
+
+		status = efi_exit_boot_services(handle,
+						&efi_bootinfo.mem_map);
+		if (status != EFI_SUCCESS) {
+			printf("Failed to exit boot services\n");
+			goto efi_main_error;
+		}
 	}
 
 	/* Set up arch-specific resources */
Signature · 1 line
2.34.1

Thanks,
drew

#3 lore raw

Re: [kvm-unit-tests RFC PATCH 2/3] x86/efi: Retry call to efi exit boot services

Quoted 34 lines · Andrew Jones
Quoted 33 lines · Pavan Kumar Paluri

In some cases, KUT guest might fail to exit boot services due to a possible memory map update that might have taken place between efi_get_memory_map() and efi_exit_boot_services() calls. As per UEFI spec 2.10 (Section 7.4.6 EFI_BOOT_SERVICES.ExitBootServices()), we need to update the memory map and retry call to exit boot services.

---
 lib/efi.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
lib/efi.c +5 -5
index 124e77685230..9d066bfad0b6 100644
@@ -458,14 +458,27 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
 	}
 #endif
 
-	/* 
+	/*
 	 * Exit EFI boot services, let kvm-unit-tests take full control of the
-	 * guest
+	 * guest.
 	 */
 	status = efi_exit_boot_services(handle, &efi_bootinfo.mem_map);
-	if (status != EFI_SUCCESS) {
-		printf("Failed to exit boot services\n");
-		goto efi_main_error;
+
+	/*
+	 * There is a possibility that memory map might have changed
Quoted 9 lines

lib/efi.c efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) · line 473

Quoted 5 lines
lib/efi.c +5 -0
+	 * between efi_get_memory_map() and efi_exit_boot_services in
+	 * which case status is EFI_INVALID_PARAMETER. As per UEFI spec
+	 * 2.10, we need to get the updated memory map and try again.
+	 */
+	if (status == EFI_INVALID_PARAMETER) {

Shouldn't we loop on this? The spec doesn't make it clear that the second try should always work.

Indeed, will plug in a do-while to loop on it.

Thanks,
Pavan

Quoted 17 lines
Quoted 14 lines
lib/efi.c +8 -0
+		efi_get_memory_map(&efi_bootinfo.mem_map);
+
+		status = efi_exit_boot_services(handle,
+						&efi_bootinfo.mem_map);
+		if (status != EFI_SUCCESS) {
+			printf("Failed to exit boot services\n");
+			goto efi_main_error;
+		}
 	}
 
 	/* Set up arch-specific resources */
Signature · 1 line
2.34.1

Thanks,
drew

#4 lore raw

Re: [kvm-unit-tests RFC PATCH 2/3] x86/efi: Retry call to efi exit boot services

In reply to Pavan Kumar Paluri
Quoted 20 lines · Pavan Kumar Paluri

In some cases, KUT guest might fail to exit boot services due to a possible memory map update that might have taken place between efi_get_memory_map() and efi_exit_boot_services() calls. As per UEFI spec 2.10 (Section 7.4.6 EFI_BOOT_SERVICES.ExitBootServices()), we need to update the memory map and retry call to exit boot services.

---
 lib/efi.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
lib/efi.c +0 -0
index 124e77685230..9d066bfad0b6 100644
@@ -458,14 +458,27 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
 	}
 #endif
 

lib/efi.c efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) · line 468

Quoted 10 lines
lib/efi.c +2 -5
-	/* 
+	/*
 	 * Exit EFI boot services, let kvm-unit-tests take full control of the
-	 * guest
+	 * guest.
 	 */
 	status = efi_exit_boot_services(handle, &efi_bootinfo.mem_map);
-	if (status != EFI_SUCCESS) {
-		printf("Failed to exit boot services\n");
-		goto efi_main_error;

With this change, error codes other than EFI_INVALID_PARAMETER are only handled if the first failure is EFI_INVALID_PARAMETER. Need to to re-add the previous handling for when the first EBS failure is something other than EFI_INVALID_PARAMETER.

-Mike

Quoted 22 lines
lib/efi.c +16 -0
+
+	/*
+	 * There is a possibility that memory map might have changed
+	 * between efi_get_memory_map() and efi_exit_boot_services in
+	 * which case status is EFI_INVALID_PARAMETER. As per UEFI spec
+	 * 2.10, we need to get the updated memory map and try again.
+	 */
+	if (status == EFI_INVALID_PARAMETER) {
+		efi_get_memory_map(&efi_bootinfo.mem_map);
+
+		status = efi_exit_boot_services(handle,
+						&efi_bootinfo.mem_map);
+		if (status != EFI_SUCCESS) {
+			printf("Failed to exit boot services\n");
+			goto efi_main_error;
+		}
 	}
 
 	/* Set up arch-specific resources */
Signature · 1 line
2.34.1
#5 lore raw

Re: [kvm-unit-tests RFC PATCH 2/3] x86/efi: Retry call to efi exit boot services

Hi Mike,

Quoted 21 lines · Michael Roth
Quoted 20 lines · Pavan Kumar Paluri

In some cases, KUT guest might fail to exit boot services due to a possible memory map update that might have taken place between efi_get_memory_map() and efi_exit_boot_services() calls. As per UEFI spec 2.10 (Section 7.4.6 EFI_BOOT_SERVICES.ExitBootServices()), we need to update the memory map and retry call to exit boot services.

---
 lib/efi.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
lib/efi.c +0 -0
index 124e77685230..9d066bfad0b6 100644
@@ -458,14 +458,27 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
 	}
 #endif
 
Quoted 16 lines

lib/efi.c efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) · line 468

Quoted 10 lines
lib/efi.c +2 -5
-	/* 
+	/*
 	 * Exit EFI boot services, let kvm-unit-tests take full control of the
-	 * guest
+	 * guest.
 	 */
 	status = efi_exit_boot_services(handle, &efi_bootinfo.mem_map);
-	if (status != EFI_SUCCESS) {
-		printf("Failed to exit boot services\n");
-		goto efi_main_error;

With this change, error codes other than EFI_INVALID_PARAMETER are only handled if the first failure is EFI_INVALID_PARAMETER. Need to to re-add the previous handling for when the first EBS failure is something other than EFI_INVALID_PARAMETER.

But the status codes that could be returned from efi_exit_boot_services() are only EFI_INVALID_PARAMETER/EFI_SUCCESS [1].

[1] UEFI 2.10 Section 7.4.6.

Thanks,
Pavan

Quoted 24 lines

-Mike

Quoted 22 lines
lib/efi.c +16 -0
+
+	/*
+	 * There is a possibility that memory map might have changed
+	 * between efi_get_memory_map() and efi_exit_boot_services in
+	 * which case status is EFI_INVALID_PARAMETER. As per UEFI spec
+	 * 2.10, we need to get the updated memory map and try again.
+	 */
+	if (status == EFI_INVALID_PARAMETER) {
+		efi_get_memory_map(&efi_bootinfo.mem_map);
+
+		status = efi_exit_boot_services(handle,
+						&efi_bootinfo.mem_map);
+		if (status != EFI_SUCCESS) {
+			printf("Failed to exit boot services\n");
+			goto efi_main_error;
+		}
 	}
 
 	/* Set up arch-specific resources */
Signature · 1 line
2.34.1
#6 lore raw

Re: [kvm-unit-tests RFC PATCH 2/3] x86/efi: Retry call to efi exit boot services

Quoted 40 lines · PavanKumar

Hi Mike,

Quoted 21 lines · Michael Roth
Quoted 20 lines · Pavan Kumar Paluri

In some cases, KUT guest might fail to exit boot services due to a possible memory map update that might have taken place between efi_get_memory_map() and efi_exit_boot_services() calls. As per UEFI spec 2.10 (Section 7.4.6 EFI_BOOT_SERVICES.ExitBootServices()), we need to update the memory map and retry call to exit boot services.

---
 lib/efi.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
lib/efi.c +0 -0
index 124e77685230..9d066bfad0b6 100644
@@ -458,14 +458,27 @@ efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab)
 	}
 #endif
 
Quoted 16 lines

lib/efi.c efi_status_t efi_main(efi_handle_t handle, efi_system_table_t *sys_tab) · line 468

Quoted 10 lines
lib/efi.c +2 -5
-	/* 
+	/*
 	 * Exit EFI boot services, let kvm-unit-tests take full control of the
-	 * guest
+	 * guest.
 	 */
 	status = efi_exit_boot_services(handle, &efi_bootinfo.mem_map);
-	if (status != EFI_SUCCESS) {
-		printf("Failed to exit boot services\n");
-		goto efi_main_error;

With this change, error codes other than EFI_INVALID_PARAMETER are only handled if the first failure is EFI_INVALID_PARAMETER. Need to to re-add the previous handling for when the first EBS failure is something other than EFI_INVALID_PARAMETER.

Quoted 4 lines

But the status codes that could be returned from efi_exit_boot_services() are only EFI_INVALID_PARAMETER/EFI_SUCCESS [1].

[1] UEFI 2.10 Section 7.4.6.

New error codes can be added over time. Also, the block you added handles !EFI_SUCCESS generally for the 2nd call, so for consistency it makes sense to continue handling it similarly for the 1st call as well.

-Mike

Quoted 28 lines

Thanks,
Pavan

Quoted 24 lines

-Mike

Quoted 22 lines
lib/efi.c +16 -0
+
+	/*
+	 * There is a possibility that memory map might have changed
+	 * between efi_get_memory_map() and efi_exit_boot_services in
+	 * which case status is EFI_INVALID_PARAMETER. As per UEFI spec
+	 * 2.10, we need to get the updated memory map and try again.
+	 */
+	if (status == EFI_INVALID_PARAMETER) {
+		efi_get_memory_map(&efi_bootinfo.mem_map);
+
+		status = efi_exit_boot_services(handle,
+						&efi_bootinfo.mem_map);
+		if (status != EFI_SUCCESS) {
+			printf("Failed to exit boot services\n");
+			goto efi_main_error;
+		}
 	}
 
 	/* Set up arch-specific resources */
Signature · 1 line
2.34.1
#7 lore raw

RFC PATCH 3/3 x86 AMD SEV-ES: Setup a new page table and install level 1 PTEs

In reply to Pavan Kumar Paluri

KUT's UEFI tests don't currently have support for page allocation. SEV-ES/SNP tests will need this later, so the support for page allocation is provided via setup_vm().

SEV-ES/SNP guest uses GHCB page to communicate with the host. Such a page should remain unencrypted (its c-bit should be unset). Therefore, call setup_ghcb_pte() in the path of setup_vm() to make sure c-bit of GHCB's pte is unset.

---
 lib/x86/vm.c  | 6 ++++++
 x86/amd_sev.c | 7 +++++++
 2 files changed, 13 insertions(+)
lib/x86/vm.c +6 -0
index 90f73fbb2dfd..ce2063aee75d 100644
@@ -3,6 +3,7 @@
 #include "vmalloc.h"
 #include "alloc_page.h"
 #include "smp.h"
+#include "amd_sev.h"
 
 static pteval_t pte_opt_mask;
 
@@ -197,6 +198,11 @@ void *setup_mmu(phys_addr_t end_of_memory, void *opt_mask)
     init_alloc_vpage((void*)(3ul << 30));
 #endif
 
+#ifdef CONFIG_EFI
+	if (amd_sev_es_enabled())
+		setup_ghcb_pte(cr3);
+#endif
+
     write_cr3(virt_to_phys(cr3));
 #ifndef __x86_64__
     write_cr4(X86_CR4_PSE);
x86/amd_sev.c +7 -0
index 7757d4f85b7a..03636e581dfe 100644
@@ -14,6 +14,8 @@
 #include "x86/processor.h"
 #include "x86/amd_sev.h"
 #include "msr.h"
+#include "x86/vm.h"
+#include "alloc_page.h"
 
 #define EXIT_SUCCESS 0
 #define EXIT_FAILURE 1
@@ -89,9 +91,14 @@ static void test_stringio(void)
 int main(void)
 {
 	int rtn;
+	unsigned long *vaddr;
 	rtn = test_sev_activation();
 	report(rtn == EXIT_SUCCESS, "SEV activation test.");
 	test_sev_es_activation();
 	test_stringio();
+	setup_vm();
+	vaddr = alloc_page();
+	if (!vaddr)
+		assert_msg(vaddr, "Page allocation Failure");
 	return report_summary();
 }
Signature · 1 line
2.34.1
#8 lore raw

Re: [kvm-unit-tests RFC PATCH 3/3] x86 AMD SEV-ES: Setup a new page table and install level 1 PTEs

Quoted 8 lines · Pavan Kumar Paluri

KUT's UEFI tests don't currently have support for page allocation. SEV-ES/SNP tests will need this later, so the support for page allocation is provided via setup_vm().

SEV-ES/SNP guest uses GHCB page to communicate with the host. Such a page should remain unencrypted (its c-bit should be unset). Therefore, call setup_ghcb_pte() in the path of setup_vm() to make sure c-bit of GHCB's pte is unset.

This looks like it should be 2 separate patches. One for supporting page allocation and one for setting the GHCB page attributes.

Thanks,
Tom

Quoted 59 lines
---
  lib/x86/vm.c  | 6 ++++++
  x86/amd_sev.c | 7 +++++++
  2 files changed, 13 insertions(+)
lib/x86/vm.c +6 -0
index 90f73fbb2dfd..ce2063aee75d 100644
@@ -3,6 +3,7 @@
  #include "vmalloc.h"
  #include "alloc_page.h"
  #include "smp.h"
+#include "amd_sev.h"
 
  static pteval_t pte_opt_mask;
 
@@ -197,6 +198,11 @@ void *setup_mmu(phys_addr_t end_of_memory, void *opt_mask)
      init_alloc_vpage((void*)(3ul << 30));
  #endif
 
+#ifdef CONFIG_EFI
+	if (amd_sev_es_enabled())
+		setup_ghcb_pte(cr3);
+#endif
+
      write_cr3(virt_to_phys(cr3));
  #ifndef __x86_64__
      write_cr4(X86_CR4_PSE);
x86/amd_sev.c +7 -0
index 7757d4f85b7a..03636e581dfe 100644
@@ -14,6 +14,8 @@
  #include "x86/processor.h"
  #include "x86/amd_sev.h"
  #include "msr.h"
+#include "x86/vm.h"
+#include "alloc_page.h"
 
  #define EXIT_SUCCESS 0
  #define EXIT_FAILURE 1
@@ -89,9 +91,14 @@ static void test_stringio(void)
  int main(void)
  {
  	int rtn;
+	unsigned long *vaddr;
  	rtn = test_sev_activation();
  	report(rtn == EXIT_SUCCESS, "SEV activation test.");
  	test_sev_es_activation();
  	test_stringio();
+	setup_vm();
+	vaddr = alloc_page();
+	if (!vaddr)
+		assert_msg(vaddr, "Page allocation Failure");
  	return report_summary();
  }
#9 lore raw

Re: [kvm-unit-tests RFC PATCH 3/3] x86 AMD SEV-ES: Setup a new page table and install level 1 PTEs

Quoted 5 lines · Tom Lendacky
Quoted 4 lines · Pavan Kumar Paluri

KUT's UEFI tests don't currently have support for page allocation. SEV-ES/SNP tests will need this later, so the support for page allocation is provided via setup_vm().

Quoted 8 lines
Quoted 4 lines

SEV-ES/SNP guest uses GHCB page to communicate with the host. Such a page should remain unencrypted (its c-bit should be unset). Therefore, call setup_ghcb_pte() in the path of setup_vm() to make sure c-bit of GHCB's pte is unset.

This looks like it should be 2 separate patches. One for supporting page allocation and one for setting the GHCB page attributes.

Sure, I will separate this into 2 patches, the GHCB page attribute patch followed by the page allocation support.

Thanks,
Pavan

Quoted 3 lines

Thanks,
Tom

#10 lore raw
In reply to Pavan Kumar Paluri
Quoted 3 lines · Pavan Kumar Paluri

Issuing a call to fdt_check_header() prevents running any of x86 UEFI enabled tests. Bypass this call for x86 in order to enable UEFI supported tests for KUT x86 arch.

Ouch! Sorry about that. I think I prefer something like below, though.

Thanks,
drew

lib/efi.c +7 -0
index 5314eaa81e66..335b66d26092 100644
@@ -312,6 +312,7 @@ static void* efi_get_var(efi_handle_t handle, struct efi_loaded_image_64 *image,
        return val;
 }
 
+#if defined(__aarch64__) || defined(__riscv)
 static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
 {
        efi_char16_t var[] = ENV_VARNAME_DTBFILE;
@@ -330,6 +331,12 @@ static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
 
        return fdt_check_header(fdt) == 0 ? fdt : NULL;
 }
+#else
+static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
+{
+       return NULL;
+}
+#endif
 
 static const struct {
        struct efi_vendor_dev_path      vendor;
Quoted 25 lines
Fixes 9632ce446b8f ("arm64: efi: Improve device tree discovery")
---
 lib/efi.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/efi.c +4 -0
index 5314eaa81e66..124e77685230 100644
@@ -328,6 +328,10 @@ static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
 		return NULL;
 	}
 
+#ifdef __x86_64__
+	return fdt;
+#endif
+
 	return fdt_check_header(fdt) == 0 ? fdt : NULL;
 }
 
Signature · 1 line
2.34.1
#11 lore raw
Quoted 26 lines · Andrew Jones
Quoted 3 lines · Pavan Kumar Paluri

Issuing a call to fdt_check_header() prevents running any of x86 UEFI enabled tests. Bypass this call for x86 in order to enable UEFI supported tests for KUT x86 arch.

Ouch! Sorry about that. I think I prefer something like below, though.

Thanks,
drew

lib/efi.c +1 -0
index 5314eaa81e66..335b66d26092 100644
@@ -312,6 +312,7 @@ static void* efi_get_var(efi_handle_t handle, struct efi_loaded_image_64 *image,
        return val;
 }
 
+#if defined(__aarch64__) || defined(__riscv)
 static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
 {
        efi_char16_t var[] = ENV_VARNAME_DTBFILE;
@@ -330,6 +331,12 @@ static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
 
        return fdt_check_header(fdt) == 0 ? fdt : NULL;

lib/efi.c static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image) · line 342

Quoted 10 lines
lib/efi.c +6 -0
 }
+#else
+static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
+{
+       return NULL;
+}
+#endif
 
 static const struct {
        struct efi_vendor_dev_path      vendor;

Thanks for the review, this looks better. I will soon send out a v2 with the changes.

Thanks,
Pavan

Quoted 25 lines
Quoted 25 lines
Fixes 9632ce446b8f ("arm64: efi: Improve device tree discovery")
---
 lib/efi.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/efi.c +4 -0
index 5314eaa81e66..124e77685230 100644
@@ -328,6 +328,10 @@ static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
 		return NULL;
 	}
 
+#ifdef __x86_64__
+	return fdt;
+#endif
+
 	return fdt_check_header(fdt) == 0 ? fdt : NULL;
 }
 
Signature · 1 line
2.34.1
#12 lore raw
In reply to Andrew Jones
Quoted 15 lines · Andrew Jones
Quoted 3 lines · Pavan Kumar Paluri

Issuing a call to fdt_check_header() prevents running any of x86 UEFI enabled tests. Bypass this call for x86 in order to enable UEFI supported tests for KUT x86 arch.

Ouch! Sorry about that. I think I prefer something like below, though.

Thanks,
drew

lib/efi.c +0 -0
index 5314eaa81e66..335b66d26092 100644

lib/efi.c static void* efi_get_var(efi_handle_t handle, struct efi_loaded_image_64 *image, · line 315

Quoted 4 lines
lib/efi.c +1 -0
@@ -312,6 +312,7 @@ static void* efi_get_var(efi_handle_t handle, struct efi_loaded_image_64 *image,
        return val;
 }
 
+#if defined(__aarch64__) || defined(__riscv)

I just realized, I had to move this line all the way upto efi_get_var in order to avoid the following compilation warnings/errors (for x86 build):

lib/efi.c:299:14: error: ‘efi_get_var’ defined but not used [-Werror=unused-function]
299 | static void* efi_get_var(efi_handle_t handle, struct
efi_loaded_image_64 *image, efi_char16_t *var)

      |              ^~~~~~~~~~~

lib/efi.c:210:13: error: ‘efi_load_image’ defined but not used [-Werror=unused-function]
210 | static void efi_load_image(efi_handle_t handle, struct
efi_loaded_image_64 *image, void **data,

      |             ^~~~~~~~~~~~~~

cc1: all warnings being treated as errors

Diff after applying the change below:

lib/efi.c +0 -0
index 5314eaa81e66..8a74a22834a4 100644
@@ -204,6 +204,7 @@ static char *efi_convert_cmdline(struct

efi_loaded_image_64 *image, int *cmd_lin

        return (char *)cmdline_addr;

}

+#if defined(__aarch64__) || defined(__riscv)
/*
* Open the file and read it into a buffer.
*/
@@ -330,6 +331,12 @@ static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)

        return fdt_check_header(fdt) == 0 ? fdt : NULL;

}
+#else
+static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
+{
+ return NULL;
+}
+#endif

 static const struct {
        struct efi_vendor_dev_path      vendor;
Quoted 7 lines
lib/efi.c +0 -0
 static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
 {
        efi_char16_t var[] = ENV_VARNAME_DTBFILE;
@@ -330,6 +331,12 @@ static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
 
        return fdt_check_header(fdt) == 0 ? fdt : NULL;

lib/efi.c static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image) · line 342

Quoted 10 lines
lib/efi.c +6 -0
 }
+#else
+static void *efi_get_fdt(efi_handle_t handle, struct efi_loaded_image_64 *image)
+{
+       return NULL;
+}
+#endif
 
 static const struct {
        struct efi_vendor_dev_path      vendor;

Thanks,
Pavan