From: "Jan Beulich" Subject: [PATCH 2/3] EFI: allow to suppress the use of runtime services Date: Thu, 23 Oct 2014 14:45:18 +0100 Message-ID: <5449228E0200007800041771@mail.emea.novell.com> References: <54492111020000780004175B@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part0D381D7E.0__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XhIhe-0007rC-Au for xen-devel@lists.xenproject.org; Thu, 23 Oct 2014 13:45:22 +0000 In-Reply-To: <54492111020000780004175B@mail.emea.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 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. --=__Part0D381D7E.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On certain systems some of the memory map entries designated for use by runtime services cannot be mapped (frequently due to firmware bugs). On others, some of the memory map entries aren't even marked for runtime services use, yet are being used by them. For both cases give people a way to suppress use of runtime services altogether. Signed-off-by: Jan Beulich --- a/docs/misc/xen-command-line.markdown +++ b/docs/misc/xen-command-line.markdown @@ -565,6 +565,13 @@ Either force retrieval of monitor EDID i disable it (edid=3Dno). This option should not normally be required except for debugging purposes. =20 +### efi-rs +> `=3D ` + +> Default: `true` + +Force or disable use of EFI runtime services. + ### extra\_guest\_irqs > `=3D [][,]` =20 --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -1072,6 +1072,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SY } =20 #ifndef CONFIG_ARM /* TODO - runtime service support */ + +static bool_t __initdata efi_rs_enable =3D 1; +boolean_param("efi-rs", efi_rs_enable); + #ifndef USE_SET_VIRTUAL_ADDRESS_MAP static __init void copy_mapping(unsigned long mfn, unsigned long end, bool_t (*is_valid)(unsigned long smfn, @@ -1145,7 +1149,7 @@ void __init efi_init_memory(void) desc->PhysicalStart, desc->PhysicalStart + len - 1, desc->Type, desc->Attribute); =20 - if ( !(desc->Attribute & EFI_MEMORY_RUNTIME) ) + if ( !efi_rs_enable || !(desc->Attribute & EFI_MEMORY_RUNTIME) ) continue; =20 desc->VirtualStart =3D INVALID_VIRTUAL_ADDRESS; @@ -1209,6 +1213,12 @@ void __init efi_init_memory(void) } } =20 + if ( !efi_rs_enable ) + { + efi_fw_vendor =3D NULL; + return; + } + #ifdef USE_SET_VIRTUAL_ADDRESS_MAP efi_rs->SetVirtualAddressMap(efi_memmap_size, efi_mdesc_size, mdesc_ver, efi_memmap); --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -56,6 +56,9 @@ unsigned long efi_rs_enter(void) static const u32 mxcsr =3D MXCSR_DEFAULT; unsigned long cr3 =3D read_cr3(); =20 + if ( !efi_l4_pgtable ) + return 0; + save_fpu_enable(); asm volatile ( "fldcw %0" :: "m" (fcw) ); asm volatile ( "ldmxcsr %0" :: "m" (mxcsr) ); @@ -83,6 +86,8 @@ unsigned long efi_rs_enter(void) =20 void efi_rs_leave(unsigned long cr3) { + if ( !cr3 ) + return; write_cr3(cr3); if ( is_pv_vcpu(current) && !is_idle_vcpu(current) ) { @@ -100,7 +105,7 @@ void efi_rs_leave(unsigned long cr3) =20 paddr_t efi_rs_page_table(void) { - return virt_to_maddr(efi_l4_pgtable); + return efi_l4_pgtable ? virt_to_maddr(efi_l4_pgtable) : 0; } =20 unsigned long efi_get_time(void) @@ -109,6 +114,8 @@ unsigned long efi_get_time(void) EFI_STATUS status; unsigned long cr3 =3D efi_rs_enter(), flags; =20 + if ( !cr3 ) + return 0; spin_lock_irqsave(&rtc_lock, flags); status =3D efi_rs->GetTime(&time, NULL); spin_unlock_irqrestore(&rtc_lock, flags); @@ -126,6 +133,8 @@ void efi_halt_system(void) EFI_STATUS status; unsigned long cr3 =3D efi_rs_enter(); =20 + if ( !cr3 ) + return; status =3D efi_rs->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, = NULL); efi_rs_leave(cr3); =20 @@ -137,6 +146,8 @@ void efi_reset_system(bool_t warm) EFI_STATUS status; unsigned long cr3 =3D efi_rs_enter(); =20 + if ( !cr3 ) + return; status =3D efi_rs->ResetSystem(warm ? EfiResetWarm : EfiResetCold, EFI_SUCCESS, 0, NULL); efi_rs_leave(cr3); @@ -161,6 +172,8 @@ int efi_get_info(uint32_t idx, union xen { unsigned long cr3 =3D efi_rs_enter(); =20 + if ( !cr3 ) + return -EOPNOTSUPP; info->version =3D efi_rs->Hdr.Revision; efi_rs_leave(cr3); break; @@ -170,6 +183,8 @@ int efi_get_info(uint32_t idx, union xen info->cfg.nent =3D efi_num_ct; break; case XEN_FW_EFI_VENDOR: + if ( !efi_fw_vendor ) + return -EOPNOTSUPP; info->vendor.revision =3D efi_fw_revision; n =3D info->vendor.bufsz / sizeof(*efi_fw_vendor); if ( !guest_handle_okay(guest_handle_cast(info->vendor.name, @@ -292,6 +307,8 @@ int efi_runtime_call(struct xenpf_efi_ru return -EINVAL; =20 cr3 =3D efi_rs_enter(); + if ( !cr3 ) + return -EOPNOTSUPP; spin_lock_irqsave(&rtc_lock, flags); status =3D efi_rs->GetTime(cast_time(&op->u.get_time.time), = &caps); spin_unlock_irqrestore(&rtc_lock, flags); @@ -312,6 +329,8 @@ int efi_runtime_call(struct xenpf_efi_ru return -EINVAL; =20 cr3 =3D efi_rs_enter(); + if ( !cr3 ) + return -EOPNOTSUPP; spin_lock_irqsave(&rtc_lock, flags); status =3D efi_rs->SetTime(cast_time(&op->u.set_time)); spin_unlock_irqrestore(&rtc_lock, flags); @@ -326,6 +345,8 @@ int efi_runtime_call(struct xenpf_efi_ru return -EINVAL; =20 cr3 =3D efi_rs_enter(); + if ( !cr3 ) + return -EOPNOTSUPP; spin_lock_irqsave(&rtc_lock, flags); status =3D efi_rs->GetWakeupTime(&enabled, &pending, cast_time(&op->u.get_wakeup_time));= @@ -348,6 +369,8 @@ int efi_runtime_call(struct xenpf_efi_ru return -EINVAL; =20 cr3 =3D efi_rs_enter(); + if ( !cr3 ) + return -EOPNOTSUPP; spin_lock_irqsave(&rtc_lock, flags); status =3D efi_rs->SetWakeupTime(!!(op->misc & XEN_EFI_SET_WAKEUP_TIME_ENABLE),= @@ -366,7 +389,10 @@ int efi_runtime_call(struct xenpf_efi_ru return -EINVAL; =20 cr3 =3D efi_rs_enter(); - status =3D efi_rs->GetNextHighMonotonicCount(&op->misc); + if ( cr3 ) + status =3D efi_rs->GetNextHighMonotonicCount(&op->misc); + else + rc =3D -EOPNOTSUPP; efi_rs_leave(cr3); break; =20 @@ -402,15 +428,20 @@ int efi_runtime_call(struct xenpf_efi_ru data =3D NULL; =20 cr3 =3D efi_rs_enter(); - status =3D efi_rs->GetVariable( - name, cast_guid(&op->u.get_variable.vendor_guid), - &op->misc, &size, data); - efi_rs_leave(cr3); + if ( cr3 ) + { + status =3D efi_rs->GetVariable( + name, cast_guid(&op->u.get_variable.vendor_guid), + &op->misc, &size, data); + efi_rs_leave(cr3); =20 - if ( !EFI_ERROR(status) && - copy_to_guest(op->u.get_variable.data, data, size) ) - rc =3D -EFAULT; - op->u.get_variable.size =3D size; + if ( !EFI_ERROR(status) && + copy_to_guest(op->u.get_variable.data, data, size) ) + rc =3D -EFAULT; + op->u.get_variable.size =3D size; + } + else + rc =3D -EOPNOTSUPP; =20 xfree(data); xfree(name); @@ -440,9 +471,12 @@ int efi_runtime_call(struct xenpf_efi_ru else { cr3 =3D efi_rs_enter(); - status =3D efi_rs->SetVariable( - name, cast_guid(&op->u.set_variable.vendor_guid), - op->misc, op->u.set_variable.size, data); + if ( cr3 ) + status =3D efi_rs->SetVariable( + name, cast_guid(&op->u.set_variable.vendor_guid), + op->misc, op->u.set_variable.size, data); + else + rc =3D -EOPNOTSUPP; efi_rs_leave(cr3); } =20 @@ -474,15 +508,21 @@ int efi_runtime_call(struct xenpf_efi_ru } =20 cr3 =3D efi_rs_enter(); - status =3D efi_rs->GetNextVariableName( - &size, name.str, - cast_guid(&op->u.get_next_variable_name.vendor_guid)); - efi_rs_leave(cr3); + if ( cr3 ) + { + status =3D efi_rs->GetNextVariableName( + &size, name.str, + cast_guid(&op->u.get_next_variable_name.vendor_guid)); + efi_rs_leave(cr3); =20 - if ( !EFI_ERROR(status) && - copy_to_guest(op->u.get_next_variable_name.name, name.raw, = size) ) - rc =3D -EFAULT; - op->u.get_next_variable_name.size =3D size; + if ( !EFI_ERROR(status) && + copy_to_guest(op->u.get_next_variable_name.name, + name.raw, size) ) + rc =3D -EFAULT; + op->u.get_next_variable_name.size =3D size; + } + else + rc =3D -EOPNOTSUPP; =20 xfree(name.raw); } @@ -519,7 +559,7 @@ int efi_runtime_call(struct xenpf_efi_ru } =20 cr3 =3D efi_rs_enter(); - if ( (efi_rs->Hdr.Revision >> 16) < 2 ) + if ( !cr3 || (efi_rs->Hdr.Revision >> 16) < 2 ) { efi_rs_leave(cr3); return -EOPNOTSUPP; @@ -538,7 +578,7 @@ int efi_runtime_call(struct xenpf_efi_ru return -EINVAL; =20 cr3 =3D efi_rs_enter(); - if ( (efi_rs->Hdr.Revision >> 16) < 2 ) + if ( !cr3 || (efi_rs->Hdr.Revision >> 16) < 2 ) { efi_rs_leave(cr3); return -EOPNOTSUPP; --=__Part0D381D7E.0__= Content-Type: text/plain; name="EFI-suppress-RS.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="EFI-suppress-RS.patch" EFI: allow to suppress the use of runtime services=0A=0AOn certain systems = some of the memory map entries designated for use by=0Aruntime services = cannot be mapped (frequently due to firmware bugs). On=0Aothers, some of = the memory map entries aren't even marked for runtime=0Aservices use, yet = are being used by them. For both cases give people a=0Away to suppress use = of runtime services altogether.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/docs/misc/xen-command-line.markdown=0A+++ b/docs/misc/x= en-command-line.markdown=0A@@ -565,6 +565,13 @@ Either force retrieval of = monitor EDID i=0A disable it (edid=3Dno). This option should not normally = be required=0A except for debugging purposes.=0A =0A+### efi-rs=0A+> `=3D = `=0A+=0A+> Default: `true`=0A+=0A+Force or disable use of EFI = runtime services.=0A+=0A ### extra\_guest\_irqs=0A > `=3D [][,= ]`=0A =0A--- a/xen/common/efi/boot.c=0A+++ b/xen/common/efi/bo= ot.c=0A@@ -1072,6 +1072,10 @@ efi_start(EFI_HANDLE ImageHandle, EFI_SY=0A = }=0A =0A #ifndef CONFIG_ARM /* TODO - runtime service support */=0A+=0A+sta= tic bool_t __initdata efi_rs_enable =3D 1;=0A+boolean_param("efi-rs", = efi_rs_enable);=0A+=0A #ifndef USE_SET_VIRTUAL_ADDRESS_MAP=0A static = __init void copy_mapping(unsigned long mfn, unsigned long end,=0A = bool_t (*is_valid)(unsigned long smfn,=0A@@ -1145,7 = +1149,7 @@ void __init efi_init_memory(void)=0A desc->Physic= alStart, desc->PhysicalStart + len - 1,=0A desc->Type, = desc->Attribute);=0A =0A- if ( !(desc->Attribute & EFI_MEMORY_RUNTIM= E) )=0A+ if ( !efi_rs_enable || !(desc->Attribute & EFI_MEMORY_RUNTI= ME) )=0A continue;=0A =0A desc->VirtualStart =3D = INVALID_VIRTUAL_ADDRESS;=0A@@ -1209,6 +1213,12 @@ void __init efi_init_memo= ry(void)=0A }=0A }=0A =0A+ if ( !efi_rs_enable )=0A+ = {=0A+ efi_fw_vendor =3D NULL;=0A+ return;=0A+ }=0A+=0A = #ifdef USE_SET_VIRTUAL_ADDRESS_MAP=0A efi_rs->SetVirtualAddressMap(efi_= memmap_size, efi_mdesc_size,=0A mdesc_ver,= efi_memmap);=0A--- a/xen/common/efi/runtime.c=0A+++ b/xen/common/efi/runti= me.c=0A@@ -56,6 +56,9 @@ unsigned long efi_rs_enter(void)=0A static = const u32 mxcsr =3D MXCSR_DEFAULT;=0A unsigned long cr3 =3D read_cr3();= =0A =0A+ if ( !efi_l4_pgtable )=0A+ return 0;=0A+=0A = save_fpu_enable();=0A asm volatile ( "fldcw %0" :: "m" (fcw) );=0A = asm volatile ( "ldmxcsr %0" :: "m" (mxcsr) );=0A@@ -83,6 +86,8 @@ unsigned = long efi_rs_enter(void)=0A =0A void efi_rs_leave(unsigned long cr3)=0A = {=0A+ if ( !cr3 )=0A+ return;=0A write_cr3(cr3);=0A if ( = is_pv_vcpu(current) && !is_idle_vcpu(current) )=0A {=0A@@ -100,7 = +105,7 @@ void efi_rs_leave(unsigned long cr3)=0A =0A paddr_t efi_rs_page_t= able(void)=0A {=0A- return virt_to_maddr(efi_l4_pgtable);=0A+ return = efi_l4_pgtable ? virt_to_maddr(efi_l4_pgtable) : 0;=0A }=0A =0A unsigned = long efi_get_time(void)=0A@@ -109,6 +114,8 @@ unsigned long efi_get_time(vo= id)=0A EFI_STATUS status;=0A unsigned long cr3 =3D efi_rs_enter(), = flags;=0A =0A+ if ( !cr3 )=0A+ return 0;=0A spin_lock_irqsave= (&rtc_lock, flags);=0A status =3D efi_rs->GetTime(&time, NULL);=0A = spin_unlock_irqrestore(&rtc_lock, flags);=0A@@ -126,6 +133,8 @@ void = efi_halt_system(void)=0A EFI_STATUS status;=0A unsigned long cr3 = =3D efi_rs_enter();=0A =0A+ if ( !cr3 )=0A+ return;=0A = status =3D efi_rs->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);=0A = efi_rs_leave(cr3);=0A =0A@@ -137,6 +146,8 @@ void efi_reset_system(bool= _t warm)=0A EFI_STATUS status;=0A unsigned long cr3 =3D efi_rs_ente= r();=0A =0A+ if ( !cr3 )=0A+ return;=0A status =3D efi_rs->Re= setSystem(warm ? EfiResetWarm : EfiResetCold,=0A = EFI_SUCCESS, 0, NULL);=0A efi_rs_leave(cr3);=0A@@ -161,6 +172,8 = @@ int efi_get_info(uint32_t idx, union xen=0A {=0A unsigned = long cr3 =3D efi_rs_enter();=0A =0A+ if ( !cr3 )=0A+ = return -EOPNOTSUPP;=0A info->version =3D efi_rs->Hdr.Revision;=0A = efi_rs_leave(cr3);=0A break;=0A@@ -170,6 +183,8 @@ int = efi_get_info(uint32_t idx, union xen=0A info->cfg.nent =3D = efi_num_ct;=0A break;=0A case XEN_FW_EFI_VENDOR:=0A+ if = ( !efi_fw_vendor )=0A+ return -EOPNOTSUPP;=0A info->vend= or.revision =3D efi_fw_revision;=0A n =3D info->vendor.bufsz / = sizeof(*efi_fw_vendor);=0A if ( !guest_handle_okay(guest_handle_cas= t(info->vendor.name,=0A@@ -292,6 +307,8 @@ int efi_runtime_call(struct = xenpf_efi_ru=0A return -EINVAL;=0A =0A cr3 =3D = efi_rs_enter();=0A+ if ( !cr3 )=0A+ return -EOPNOTSUPP;= =0A spin_lock_irqsave(&rtc_lock, flags);=0A status =3D = efi_rs->GetTime(cast_time(&op->u.get_time.time), &caps);=0A = spin_unlock_irqrestore(&rtc_lock, flags);=0A@@ -312,6 +329,8 @@ int = efi_runtime_call(struct xenpf_efi_ru=0A return -EINVAL;=0A =0A = cr3 =3D efi_rs_enter();=0A+ if ( !cr3 )=0A+ = return -EOPNOTSUPP;=0A spin_lock_irqsave(&rtc_lock, flags);=0A = status =3D efi_rs->SetTime(cast_time(&op->u.set_time));=0A = spin_unlock_irqrestore(&rtc_lock, flags);=0A@@ -326,6 +345,8 @@ int = efi_runtime_call(struct xenpf_efi_ru=0A return -EINVAL;=0A =0A = cr3 =3D efi_rs_enter();=0A+ if ( !cr3 )=0A+ = return -EOPNOTSUPP;=0A spin_lock_irqsave(&rtc_lock, flags);=0A = status =3D efi_rs->GetWakeupTime(&enabled, &pending,=0A = cast_time(&op->u.get_wakeup_time));=0A@@ -348,6 = +369,8 @@ int efi_runtime_call(struct xenpf_efi_ru=0A return = -EINVAL;=0A =0A cr3 =3D efi_rs_enter();=0A+ if ( !cr3 )=0A+ = return -EOPNOTSUPP;=0A spin_lock_irqsave(&rtc_lock, = flags);=0A status =3D efi_rs->SetWakeupTime(!!(op->misc &=0A = XEN_EFI_SET_WAKEUP_TIME_ENABLE),=0A@@ = -366,7 +389,10 @@ int efi_runtime_call(struct xenpf_efi_ru=0A = return -EINVAL;=0A =0A cr3 =3D efi_rs_enter();=0A- status = =3D efi_rs->GetNextHighMonotonicCount(&op->misc);=0A+ if ( cr3 = )=0A+ status =3D efi_rs->GetNextHighMonotonicCount(&op->misc);= =0A+ else=0A+ rc =3D -EOPNOTSUPP;=0A efi_rs_leave= (cr3);=0A break;=0A =0A@@ -402,15 +428,20 @@ int efi_runtime_call(s= truct xenpf_efi_ru=0A data =3D NULL;=0A =0A cr3 =3D = efi_rs_enter();=0A- status =3D efi_rs->GetVariable(=0A- = name, cast_guid(&op->u.get_variable.vendor_guid),=0A- &op->misc,= &size, data);=0A- efi_rs_leave(cr3);=0A+ if ( cr3 )=0A+ = {=0A+ status =3D efi_rs->GetVariable(=0A+ = name, cast_guid(&op->u.get_variable.vendor_guid),=0A+ = &op->misc, &size, data);=0A+ efi_rs_leave(cr3);=0A =0A- = if ( !EFI_ERROR(status) &&=0A- copy_to_guest(op->u.get_variable= .data, data, size) )=0A- rc =3D -EFAULT;=0A- op->u.get_va= riable.size =3D size;=0A+ if ( !EFI_ERROR(status) &&=0A+ = copy_to_guest(op->u.get_variable.data, data, size) )=0A+ = rc =3D -EFAULT;=0A+ op->u.get_variable.size =3D size;=0A+ = }=0A+ else=0A+ rc =3D -EOPNOTSUPP;=0A =0A = xfree(data);=0A xfree(name);=0A@@ -440,9 +471,12 @@ int efi_runtime= _call(struct xenpf_efi_ru=0A else=0A {=0A cr3 = =3D efi_rs_enter();=0A- status =3D efi_rs->SetVariable(=0A- = name, cast_guid(&op->u.set_variable.vendor_guid),=0A- = op->misc, op->u.set_variable.size, data);=0A+ if ( cr3 = )=0A+ status =3D efi_rs->SetVariable(=0A+ = name, cast_guid(&op->u.set_variable.vendor_guid),=0A+ = op->misc, op->u.set_variable.size, data);=0A+ else=0A+ = rc =3D -EOPNOTSUPP;=0A efi_rs_leave(cr3);=0A = }=0A =0A@@ -474,15 +508,21 @@ int efi_runtime_call(struct xenpf_efi_ru=0A = }=0A =0A cr3 =3D efi_rs_enter();=0A- status =3D = efi_rs->GetNextVariableName(=0A- &size, name.str,=0A- = cast_guid(&op->u.get_next_variable_name.vendor_guid));=0A- = efi_rs_leave(cr3);=0A+ if ( cr3 )=0A+ {=0A+ = status =3D efi_rs->GetNextVariableName(=0A+ &size, = name.str,=0A+ cast_guid(&op->u.get_next_variable_name.vendor= _guid));=0A+ efi_rs_leave(cr3);=0A =0A- if ( !EFI_ERROR(s= tatus) &&=0A- copy_to_guest(op->u.get_next_variable_name.name, = name.raw, size) )=0A- rc =3D -EFAULT;=0A- op->u.get_next_= variable_name.size =3D size;=0A+ if ( !EFI_ERROR(status) &&=0A+ = copy_to_guest(op->u.get_next_variable_name.name,=0A+ = name.raw, size) )=0A+ rc =3D = -EFAULT;=0A+ op->u.get_next_variable_name.size =3D size;=0A+ = }=0A+ else=0A+ rc =3D -EOPNOTSUPP;=0A =0A = xfree(name.raw);=0A }=0A@@ -519,7 +559,7 @@ int efi_runtime_call(struct= xenpf_efi_ru=0A }=0A =0A cr3 =3D efi_rs_enter();=0A- = if ( (efi_rs->Hdr.Revision >> 16) < 2 )=0A+ if ( !cr3 || = (efi_rs->Hdr.Revision >> 16) < 2 )=0A {=0A efi_rs_leave= (cr3);=0A return -EOPNOTSUPP;=0A@@ -538,7 +578,7 @@ int = efi_runtime_call(struct xenpf_efi_ru=0A return -EINVAL;=0A =0A = cr3 =3D efi_rs_enter();=0A- if ( (efi_rs->Hdr.Revision >> = 16) < 2 )=0A+ if ( !cr3 || (efi_rs->Hdr.Revision >> 16) < 2 )=0A = {=0A efi_rs_leave(cr3);=0A return -EOPNOTSUPP;= =0A --=__Part0D381D7E.0__= 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 --=__Part0D381D7E.0__=--