From: "Jan Beulich" Subject: [PATCH 1/2] x86/EFI: pass boot services variable info to runtime code Date: Mon, 22 Apr 2013 11:08:05 +0100 Message-ID: <5175282502000078000CF6EE@nat28.tlf.novell.com> References: <5175272902000078000CF6D6@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part55657C15.1__=" Return-path: In-Reply-To: <5175272902000078000CF6D6@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: George Dunlap , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part55657C15.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline EFI variables can be flagged as being accessible only within boot = services. This makes it awkward for us to figure out how much space they use at runtime. In theory we could figure this out by simply comparing the = results from QueryVariableInfo() to the space used by all of our variables, but that fails if the platform doesn't garbage collect on every boot. = Thankfully, calling QueryVariableInfo() while still inside boot services gives a more reliable answer. This patch passes that information from the EFI boot stub up to the efi platform code. Based on a similarly named Linux patch by Matthew Garrett . Signed-off-by: Jan Beulich --- a/xen/arch/x86/efi/boot.c +++ b/xen/arch/x86/efi/boot.c @@ -1231,6 +1231,23 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SY /* Collect PCI ROM contents. */ setup_efi_pci(); =20 + /* Get snapshot of variable store parameters. */ + status =3D efi_rs->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + &efi_boot_max_var_store_size, + &efi_boot_remain_var_store_size, + &efi_boot_max_var_size); + if ( EFI_ERROR(status) ) + { + efi_boot_max_var_store_size =3D 0; + efi_boot_remain_var_store_size =3D 0; + efi_boot_max_var_size =3D status; + PrintStr(L"Warning: Could not query variable store: "); + DisplayUint(status, 0); + PrintStr(newline); + } + /* Allocate space for trampoline (in first Mb). */ cfg.addr =3D 0x100000; cfg.size =3D trampoline_end - trampoline_start; --- a/xen/arch/x86/efi/efi.h +++ b/xen/arch/x86/efi/efi.h @@ -32,5 +32,8 @@ extern l4_pgentry_t *efi_l4_pgtable; =20 extern const struct efi_pci_rom *efi_pci_roms; =20 +extern UINT64 efi_boot_max_var_store_size, efi_boot_remain_var_store_size,= + efi_boot_max_var_size; + unsigned long efi_rs_enter(void); void efi_rs_leave(unsigned long); --- a/xen/arch/x86/efi/runtime.c +++ b/xen/arch/x86/efi/runtime.c @@ -28,6 +28,10 @@ UINTN __read_mostly efi_memmap_size; UINTN __read_mostly efi_mdesc_size; void *__read_mostly efi_memmap; =20 +UINT64 __read_mostly efi_boot_max_var_store_size; +UINT64 __read_mostly efi_boot_remain_var_store_size; +UINT64 __read_mostly efi_boot_max_var_size; + struct efi __read_mostly efi =3D { .acpi =3D EFI_INVALID_TABLE_ADDR, .acpi20 =3D EFI_INVALID_TABLE_ADDR, @@ -464,6 +468,35 @@ int efi_runtime_call(struct xenpf_efi_ru break; =20 case XEN_EFI_query_variable_info: + if ( op->misc & ~XEN_EFI_VARINFO_BOOT_SNAPSHOT ) + return -EINVAL; + + if ( op->misc & XEN_EFI_VARINFO_BOOT_SNAPSHOT ) + { + if ( (op->u.query_variable_info.attr + & ~EFI_VARIABLE_APPEND_WRITE) !=3D + (EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS) ) + return -EINVAL; + + op->u.query_variable_info.max_store_size =3D + efi_boot_max_var_store_size; + op->u.query_variable_info.remain_store_size =3D + efi_boot_remain_var_store_size; + if ( efi_boot_max_var_store_size ) + { + op->u.query_variable_info.max_size =3D efi_boot_max_var_si= ze; + status =3D EFI_SUCCESS; + } + else + { + op->u.query_variable_info.max_size =3D 0; + status =3D efi_boot_max_var_size; + } + break; + } + cr3 =3D efi_rs_enter(); if ( (efi_rs->Hdr.Revision >> 16) < 2 ) { @@ -480,6 +513,9 @@ int efi_runtime_call(struct xenpf_efi_ru =20 case XEN_EFI_query_capsule_capabilities: case XEN_EFI_update_capsule: + if ( op->misc ) + return -EINVAL; + cr3 =3D efi_rs_enter(); if ( (efi_rs->Hdr.Revision >> 16) < 2 ) { --- a/xen/include/public/platform.h +++ b/xen/include/public/platform.h @@ -184,6 +184,7 @@ struct xenpf_efi_runtime_call { struct xenpf_efi_guid vendor_guid; } get_next_variable_name; =20 +#define XEN_EFI_VARINFO_BOOT_SNAPSHOT 0x00000001 struct { uint32_t attr; uint64_t max_store_size; --- a/xen/include/efi/efiapi.h +++ b/xen/include/efi/efiapi.h @@ -213,6 +213,10 @@ VOID #define EFI_VARIABLE_NON_VOLATILE 0x00000001 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002 #define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004 +#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008 +#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010 +#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020 +#define EFI_VARIABLE_APPEND_WRITE 0x00000040 =20 // Variable size limitation #define EFI_MAXIMUM_VARIABLE_SIZE 1024 --=__Part55657C15.1__= Content-Type: text/plain; name="x86-EFI-var-info-boot.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-EFI-var-info-boot.patch" x86/EFI: pass boot services variable info to runtime code=0A=0AEFI = variables can be flagged as being accessible only within boot services.=0AT= his makes it awkward for us to figure out how much space they use = at=0Aruntime. In theory we could figure this out by simply comparing the = results=0Afrom QueryVariableInfo() to the space used by all of our = variables, but=0Athat fails if the platform doesn't garbage collect on = every boot. Thankfully,=0Acalling QueryVariableInfo() while still inside = boot services gives a more=0Areliable answer. This patch passes that = information from the EFI boot stub=0Aup to the efi platform code.=0A=0ABase= d on a similarly named Linux patch by Matthew Garrett .=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/efi/boot.c=0A+++ b/xen/arch/x86/efi/boot.c=0A@@ -1231,6 = +1231,23 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SY=0A /* Collect PCI = ROM contents. */=0A setup_efi_pci();=0A =0A+ /* Get snapshot of = variable store parameters. */=0A+ status =3D efi_rs->QueryVariableInfo(E= FI_VARIABLE_NON_VOLATILE |=0A+ = EFI_VARIABLE_BOOTSERVICE_ACCESS |=0A+ = EFI_VARIABLE_RUNTIME_ACCESS,=0A+ = &efi_boot_max_var_store_size,=0A+ = &efi_boot_remain_var_store_size,=0A+ = &efi_boot_max_var_size);=0A+ if ( EFI_ERROR(status) )=0A+ {=0A+ = efi_boot_max_var_store_size =3D 0;=0A+ efi_boot_remain_var_store_s= ize =3D 0;=0A+ efi_boot_max_var_size =3D status;=0A+ = PrintStr(L"Warning: Could not query variable store: ");=0A+ = DisplayUint(status, 0);=0A+ PrintStr(newline);=0A+ }=0A+=0A = /* Allocate space for trampoline (in first Mb). */=0A cfg.addr =3D = 0x100000;=0A cfg.size =3D trampoline_end - trampoline_start;=0A--- = a/xen/arch/x86/efi/efi.h=0A+++ b/xen/arch/x86/efi/efi.h=0A@@ -32,5 +32,8 = @@ extern l4_pgentry_t *efi_l4_pgtable;=0A =0A extern const struct = efi_pci_rom *efi_pci_roms;=0A =0A+extern UINT64 efi_boot_max_var_store_size= , efi_boot_remain_var_store_size,=0A+ efi_boot_max_var_size;= =0A+=0A unsigned long efi_rs_enter(void);=0A void efi_rs_leave(unsigned = long);=0A--- a/xen/arch/x86/efi/runtime.c=0A+++ b/xen/arch/x86/efi/runtime.= c=0A@@ -28,6 +28,10 @@ UINTN __read_mostly efi_memmap_size;=0A UINTN = __read_mostly efi_mdesc_size;=0A void *__read_mostly efi_memmap;=0A = =0A+UINT64 __read_mostly efi_boot_max_var_store_size;=0A+UINT64 __read_most= ly efi_boot_remain_var_store_size;=0A+UINT64 __read_mostly efi_boot_max_var= _size;=0A+=0A struct efi __read_mostly efi =3D {=0A .acpi =3D = EFI_INVALID_TABLE_ADDR,=0A .acpi20 =3D EFI_INVALID_TABLE_ADDR,=0A@@ = -464,6 +468,35 @@ int efi_runtime_call(struct xenpf_efi_ru=0A = break;=0A =0A case XEN_EFI_query_variable_info:=0A+ if ( = op->misc & ~XEN_EFI_VARINFO_BOOT_SNAPSHOT )=0A+ return = -EINVAL;=0A+=0A+ if ( op->misc & XEN_EFI_VARINFO_BOOT_SNAPSHOT = )=0A+ {=0A+ if ( (op->u.query_variable_info.attr=0A+ = & ~EFI_VARIABLE_APPEND_WRITE) !=3D=0A+ = (EFI_VARIABLE_NON_VOLATILE |=0A+ EFI_VARIABLE_BOOTSERVICE_= ACCESS |=0A+ EFI_VARIABLE_RUNTIME_ACCESS) )=0A+ = return -EINVAL;=0A+=0A+ op->u.query_variable_info.max_store= _size =3D=0A+ efi_boot_max_var_store_size;=0A+ = op->u.query_variable_info.remain_store_size =3D=0A+ = efi_boot_remain_var_store_size;=0A+ if ( efi_boot_max_var_store_= size )=0A+ {=0A+ op->u.query_variable_info.max_si= ze =3D efi_boot_max_var_size;=0A+ status =3D EFI_SUCCESS;=0A= + }=0A+ else=0A+ {=0A+ = op->u.query_variable_info.max_size =3D 0;=0A+ status =3D = efi_boot_max_var_size;=0A+ }=0A+ break;=0A+ = }=0A+=0A cr3 =3D efi_rs_enter();=0A if ( (efi_rs->Hdr.Revis= ion >> 16) < 2 )=0A {=0A@@ -480,6 +513,9 @@ int efi_runtime_call(st= ruct xenpf_efi_ru=0A =0A case XEN_EFI_query_capsule_capabilities:=0A = case XEN_EFI_update_capsule:=0A+ if ( op->misc )=0A+ = return -EINVAL;=0A+=0A cr3 =3D efi_rs_enter();=0A if ( = (efi_rs->Hdr.Revision >> 16) < 2 )=0A {=0A--- a/xen/include/public/= platform.h=0A+++ b/xen/include/public/platform.h=0A@@ -184,6 +184,7 @@ = struct xenpf_efi_runtime_call {=0A struct xenpf_efi_guid = vendor_guid;=0A } get_next_variable_name;=0A =0A+#define XEN_EFI_VA= RINFO_BOOT_SNAPSHOT 0x00000001=0A struct {=0A = uint32_t attr;=0A uint64_t max_store_size;=0A--- a/xen/include/= efi/efiapi.h=0A+++ b/xen/include/efi/efiapi.h=0A@@ -213,6 +213,10 @@ = VOID=0A #define EFI_VARIABLE_NON_VOLATILE 0x00000001=0A #define = EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002=0A #define EFI_VARIABLE_RUNT= IME_ACCESS 0x00000004=0A+#define EFI_VARIABLE_HARDWARE_ERROR_RECORD= 0x00000008=0A+#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010= =0A+#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020= =0A+#define EFI_VARIABLE_APPEND_WRITE 0x00000040=0A =0A // = Variable size limitation=0A #define EFI_MAXIMUM_VARIABLE_SIZE = 1024=0A --=__Part55657C15.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part55657C15.1__=--