x86: Drop cross-vendor support
v5 cover x86: Drop cross-vendor support
Hi,
Patches 2, 4 and 5 missing acks.
Patch 2 now does a minimal diff change, while 4 and 5 perform the meat of what v4/patch2 used to do.
I had patches 4 and 5 appended to the end in the hopes of having 1-3 committed sooner.
v1: https://lore.kernel.org/xen-devel/[email protected]/
v2: https://lore.kernel.org/xen-devel/[email protected]/
v3: https://lore.kernel.org/xen-devel/[email protected]/
v4: https://lore.kernel.org/xen-devel/[email protected]/
Cheers,
Alejandro
Alejandro Vallejo (5):
x86: Reject CPU policies with vendors other than the host's x86/hvm: Disable cross-vendor handling in #UD handler x86/hvm: Remove cross-vendor checks from MSR handlers. x86/svm: Drop emulation of Intel's SYSENTER MSR behaviour x86/hvm: Un-indent the HVM_FEP block in the #UD handler
CHANGELOG.md | 5 ++ tools/tests/cpu-policy/test-cpu-policy.c | 27 +++++++++++ xen/arch/x86/hvm/hvm.c | 62 +++++++++--------------- xen/arch/x86/hvm/svm/svm.c | 45 ++++++++--------- xen/arch/x86/hvm/svm/vmcb.c | 3 ++ xen/arch/x86/hvm/vmx/vmx.c | 3 +- xen/arch/x86/include/asm/hvm/svm-types.h | 10 ---- xen/arch/x86/lib/cpu-policy/policy.c | 5 +- xen/arch/x86/msr.c | 8 ++- 9 files changed, 86 insertions(+), 82 deletions(-)
base-commit: a3a1e61ce9a00c5a0c8003bad8f1285360399cf4
Signature · 1 line
2.43.0
PATCH v5 1/5 x86: Reject CPU policies with vendors other than the host's
While in principle it's possible to have a vendor virtualising another, this is fairly tricky in practice and comes with the world's supply of security issues.
Reject any CPU policy with vendors not matching the host's.
--- CHANGELOG.md | 5 +++++ tools/tests/cpu-policy/test-cpu-policy.c | 27 ++++++++++++++++++++++++ xen/arch/x86/lib/cpu-policy/policy.c | 5 ++++- 3 files changed, 36 insertions(+), 1 deletion(-)
CHANGELOG.md +5 -0
@@ -23,6 +23,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Xenoprofile support. Oprofile themselves removed support for Xen in 2014 prior to the version 1.0 release, and there has been no development since before then in Xen. + - Domains can no longer run on a system with CPUs of a vendor different from + the one they were initially launched on. This affects live migrations and + save/restore workflows across mixed-vendor hosts. Cross-vendor emulation + has always been unreliable, but since 2017 with the advent of speculation + security it became unsustainably so. - Removed xenpm tool on non-x86 platforms as it doesn't actually provide anything useful outside of x86.
tools/tests/cpu-policy/test-cpu-policy.c +27 -0
@@ -586,6 +586,19 @@ static void test_is_compatible_success(void) .platform_info.cpuid_faulting = true, }, }, + { + .name = "Host CPU vendor == Guest CPU vendor (both unknown)", + .host = { + .basic.vendor_ebx = X86_VENDOR_AMD_EBX + 1, + .basic.vendor_ecx = X86_VENDOR_AMD_ECX, + .basic.vendor_edx = X86_VENDOR_AMD_EDX, + }, + .guest = { + .basic.vendor_ebx = X86_VENDOR_AMD_EBX + 1, + .basic.vendor_ecx = X86_VENDOR_AMD_ECX, + .basic.vendor_edx = X86_VENDOR_AMD_EDX, + }, + }, };struct cpu_policy_errors no_errors =INIT_CPU_POLICY_ERRORS ;
@@ -629,6 +642,20 @@ static void test_is_compatible_failure(void) }, .e = { -1, -1, 0xce }, }, + { + .name ="Host CPU vendor != Guest CPU vendor (both unknown)" , + .host = { + .basic.vendor_ebx =X86_VENDOR_AMD_EBX +1 , + .basic.vendor_ecx = X86_VENDOR_AMD_ECX, + .basic.vendor_edx = X86_VENDOR_AMD_EDX, + }, + .guest = { + .basic.vendor_ebx =X86_VENDOR_AMD_EBX +2 , + .basic.vendor_ecx = X86_VENDOR_AMD_ECX, + .basic.vendor_edx = X86_VENDOR_AMD_EDX, + }, + .e = { 0, -1, -1 }, + }, };printf ("Testing policy compatibility failure:\n" );
xen/arch/x86/lib/cpu-policy/policy.c +4 -1
@@ -15,7 +15,10 @@ int x86_cpu_policies_are_compatible(const struct cpu_policy *host,#define FAIL_MSR (m) \ do { e.msr = (m); goto out; } while ( 0 ) -if ( guest->basic.max_leaf > host->basic.max_leaf ) +if ( (guest->basic.vendor_ebx != host->basic.vendor_ebx) || + (guest->basic.vendor_ecx != host->basic.vendor_ecx) || + (guest->basic.vendor_edx != host->basic.vendor_edx) || + (guest->basic.max_leaf > host->basic.max_leaf) )FAIL_CPUID (0 ,NA );if ( guest->feat.max_subleaf > host->feat.max_subleaf )
Signature · 1 line
2.43.0
Re: [PATCH v5 1/5] x86: Reject CPU policies with vendors other than the host's
Quoted 19 lines · Alejandro Vallejo
While in principle it's possible to have a vendor virtualising another, this is fairly tricky in practice and comes with the world's supply of security issues.
Reject any CPU policy with vendors not matching the host's.
Signed-off-by Alejandro Vallejo <[email protected]>Reviewed-by Jan Beulich <[email protected]>--- CHANGELOG.md | 5 +++++ tools/tests/cpu-policy/test-cpu-policy.c | 27 ++++++++++++++++++++++++ xen/arch/x86/lib/cpu-policy/policy.c | 5 ++++- 3 files changed, 36 insertions(+), 1 deletion(-)CHANGELOG.md +0
-0
CHANGELOG.md The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) · line 30
Quoted 8 lines
CHANGELOG.md +5
-0@@ -23,6 +23,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Xenoprofile support. Oprofile themselves removed support for Xen in 2014 prior to the version 1.0 release, and there has been no development since before then in Xen. + - Domains can no longer run on a system with CPUs of a vendor different from + the one they were initially launched on. This affects live migrations and + save/restore workflows across mixed-vendor hosts. Cross-vendor emulation + has always been unreliable, but since 2017 with the advent of speculation + security it became unsustainably so.
c/s 0f1cb96e9785294f149ab3c7feb90c0eb9daeede was when it got added to Xen.
I'm certain there's a whitepaper somewhere from AMD about this, but I can't locate it. It was partly marketing about how you could buy AMD hardware (which was cheaper) and live-migrate your Intel VMs without interruption. It would have been nice to find for posterity.
For the changelog, can I suggest this:
CHANGELOG.md +0 -0
@@ -23,6 +23,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Xenoprofile support. Oprofile themselves removed support for Xen in 2014 prior to the version 1.0 release, and there has been no development since before then in Xen.
+ - Cross-vendor support; guests can now only be configured as the same + vendor as the host CPU. When added back in 2009, with enough trickery + Intel and AMD CPUs could be made to be compatible enough to live migrate + a guest, but the vendors have been diverging since then in ways that Xen + cannot compensate for, and the advent of speculative security issues has + put to rest any possibility of this being a viable option.
- Removed xenpm tool on non-x86 platforms as it doesn't actually provide anything useful outside of x86.
which is closer to the style of the surrounding bullet points. Also s/domain/guest/ which is a subtle but important distinction made by the Security Team when discussing configurations.
~Andrew
Re: [PATCH v5 1/5] x86: Reject CPU policies with vendors other than the host's
Quoted 57 lines · Andrew Cooper
Quoted 19 lines · Alejandro Vallejo
While in principle it's possible to have a vendor virtualising another, this is fairly tricky in practice and comes with the world's supply of security issues.
Reject any CPU policy with vendors not matching the host's.
Signed-off-by Alejandro Vallejo <[email protected]>Reviewed-by Jan Beulich <[email protected]>--- CHANGELOG.md | 5 +++++ tools/tests/cpu-policy/test-cpu-policy.c | 27 ++++++++++++++++++++++++ xen/arch/x86/lib/cpu-policy/policy.c | 5 ++++- 3 files changed, 36 insertions(+), 1 deletion(-)CHANGELOG.md +0
-0CHANGELOG.md The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) · line 30
Quoted 8 lines
CHANGELOG.md +5
-0@@ -23,6 +23,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Xenoprofile support. Oprofile themselves removed support for Xen in 2014 prior to the version 1.0 release, and there has been no development since before then in Xen. + - Domains can no longer run on a system with CPUs of a vendor different from + the one they were initially launched on. This affects live migrations and + save/restore workflows across mixed-vendor hosts. Cross-vendor emulation + has always been unreliable, but since 2017 with the advent of speculation + security it became unsustainably so.c/s
0f1cb96e9785294f149ab3c7feb90c0eb9daeedewas when it got added to Xen.I'm certain there's a whitepaper somewhere from AMD about this, but I can't locate it. It was partly marketing about how you could buy AMD hardware (which was cheaper) and live-migrate your Intel VMs without interruption. It would have been nice to find for posterity.
For the changelog, can I suggest this:
CHANGELOG.md +0
-0@@ -23,6 +23,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)- Xenoprofile support. Oprofile themselves removed support for Xen in 2014 prior to the version 1.0 release, and there has been no development since before then in Xen.
+ - Cross-vendor support; guests can now only be configured as the same + vendor as the host CPU. When added back in 2009, with enough trickery + Intel and AMD CPUs could be made to be compatible enough to live migrate + a guest, but the vendors have been diverging since then in ways that Xen + cannot compensate for, and the advent of speculative security issues has + put to rest any possibility of this being a viable option.
- Removed xenpm tool on non-x86 platforms as it doesn't actually provide anything useful outside of x86.
Quoted 3 lines
which is closer to the style of the surrounding bullet points. Also s/domain/guest/ which is a subtle but important distinction made by the Security Team when discussing configurations.
Sure on both accounts. I don't mind the contents so long as there is any.
Should I consider these on the "doable on commit" camp? Or do you want a v6?
Cheers,
Alejandro
Oleksii Kurochko
Acked-byRe: [PATCH v5 1/5] x86: Reject CPU policies with vendors other than the host's
In reply to Andrew CooperQuoted 57 lines · Andrew Cooper
Quoted 19 lines · Alejandro Vallejo
While in principle it's possible to have a vendor virtualising another, this is fairly tricky in practice and comes with the world's supply of security issues.
Reject any CPU policy with vendors not matching the host's.
Signed-off-by Alejandro Vallejo <[email protected]>Reviewed-by Jan Beulich <[email protected]>--- CHANGELOG.md | 5 +++++ tools/tests/cpu-policy/test-cpu-policy.c | 27 ++++++++++++++++++++++++ xen/arch/x86/lib/cpu-policy/policy.c | 5 ++++- 3 files changed, 36 insertions(+), 1 deletion(-)CHANGELOG.md +0
-0CHANGELOG.md The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) · line 30
Quoted 8 lines
CHANGELOG.md +5
-0@@ -23,6 +23,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Xenoprofile support. Oprofile themselves removed support for Xen in 2014 prior to the version 1.0 release, and there has been no development since before then in Xen. + - Domains can no longer run on a system with CPUs of a vendor different from + the one they were initially launched on. This affects live migrations and + save/restore workflows across mixed-vendor hosts. Cross-vendor emulation + has always been unreliable, but since 2017 with the advent of speculation + security it became unsustainably so.c/s
0f1cb96e9785294f149ab3c7feb90c0eb9daeedewas when it got added to Xen.I'm certain there's a whitepaper somewhere from AMD about this, but I can't locate it. It was partly marketing about how you could buy AMD hardware (which was cheaper) and live-migrate your Intel VMs without interruption. It would have been nice to find for posterity.
For the changelog, can I suggest this:
CHANGELOG.md +6
-0@@ -23,6 +23,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Xenoprofile support. Oprofile themselves removed support for Xen in 2014 prior to the version 1.0 release, and there has been no development since before then in Xen. + - Cross-vendor support; guests can now only be configured as the same + vendor as the host CPU. When added back in 2009, with enough trickery + Intel and AMD CPUs could be made to be compatible enough to live migrate + a guest, but the vendors have been diverging since then in ways that Xen + cannot compensate for, and the advent of speculative security issues has + put to rest any possibility of this being a viable option. - Removed xenpm tool on non-x86 platforms as it doesn't actually provide anything useful outside of x86.
Quoted 3 lines
which is closer to the style of the surrounding bullet points. Also s/domain/guest/ which is a subtle but important distinction made by the Security Team when discussing configurations.
With applying of suggested changes to CHANGELOG.md:
Thanks.
~ Oleksii
PATCH v5 2/5 x86/hvm: Disable cross-vendor handling in #UD handler
In reply to Alejandro VallejoRemove cross-vendor support now that VMs can no longer have a different vendor than the host.
No functional change intended.
---
v5:
* This patch now performs a minimal diff, with the other parts appended to the tail of the series.
--- xen/arch/x86/hvm/hvm.c | 19 ++----------------- xen/arch/x86/hvm/svm/svm.c | 3 +-- xen/arch/x86/hvm/vmx/vmx.c | 3 +-- 3 files changed, 4 insertions(+), 21 deletions(-)
xen/arch/x86/hvm/hvm.c +2 -17
@@ -3832,28 +3832,13 @@ int hvm_descriptor_access_intercept(uint64_t exit_info,return X86EMUL_OKAY ; } -static bool cf_check is_cross_vendor( -const struct x86_emulate_state *state,const struct x86_emulate_ctxt *ctxt) -{ -switch ( ctxt->opcode ) - { -case X86EMUL_OPC (0x0f ,0x05 ):/* syscall */ -case X86EMUL_OPC (0x0f ,0x34 ):/* sysenter */ -case X86EMUL_OPC (0x0f ,0x35 ):/* sysexit */ -return true; - } - -return false; -} -void hvm_ud_intercept (struct cpu_user_regs *regs) {struct vcpu *cur = current; -bool should_emulate = - cur->domain->arch.cpuid->x86_vendor != boot_cpu_data.x86_vendor; +bool should_emulate = false;struct hvm_emulate_ctxt ctxt; -hvm_emulate_init_once (&ctxt, opt_hvm_fep ?NULL : is_cross_vendor, regs); +hvm_emulate_init_once (&ctxt,NULL , regs);if ( opt_hvm_fep ) {
xen/arch/x86/hvm/svm/svm.c +1 -2
@@ -589,8 +589,7 @@ static void cf_check svm_cpuid_policy_changed(struct vcpu *v)const struct cpu_policy *cp = v->domain->arch.cpu_policy;u32 bitmap =vmcb_get_exception_intercepts (vmcb); -if ( opt_hvm_fep || - (v->domain->arch.cpuid->x86_vendor != boot_cpu_data.x86_vendor) ) +if ( opt_hvm_fep ) bitmap |= (1U <<X86_EXC_UD );else bitmap &= ~(1U <<X86_EXC_UD );
xen/arch/x86/hvm/vmx/vmx.c +1 -2
@@ -803,8 +803,7 @@ static void cf_check vmx_cpuid_policy_changed(struct vcpu *v)const struct cpu_policy *cp = v->domain->arch.cpu_policy;int rc =0 ; -if ( opt_hvm_fep || - (v->domain->arch.cpuid->x86_vendor != boot_cpu_data.x86_vendor) ) +if ( opt_hvm_fep ) v->arch.hvm.vmx.exception_bitmap |= (1U <<X86_EXC_UD );else v->arch.hvm.vmx.exception_bitmap &= ~(1U <<X86_EXC_UD );
Signature · 1 line
2.43.0
Re: [PATCH v5 2/5] x86/hvm: Disable cross-vendor handling in #UD handler
Quoted 6 lines · Alejandro Vallejo
Remove cross-vendor support now that VMs can no longer have a different vendor than the host.
No functional change intended.
Signed-off-by Alejandro Vallejo <[email protected]>
PATCH v5 3/5 x86/hvm: Remove cross-vendor checks from MSR handlers.
In reply to Alejandro VallejoNot a functional change now that cross-vendor guests are not launchable.
--- xen/arch/x86/msr.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
xen/arch/x86/msr.c +3 -5
@@ -169,9 +169,9 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)break ;case MSR_IA32_PLATFORM_ID : -if ( !(cp->x86_vendor &X86_VENDOR_INTEL ) || - !(boot_cpu_data.vendor &X86_VENDOR_INTEL ) ) +if ( boot_cpu_data.vendor !=X86_VENDOR_INTEL ) goto gp_fault; +rdmsrl (MSR_IA32_PLATFORM_ID , *val);break ;
@@ -189,9 +189,7 @@ int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val)* from Xen's last microcode load, which can be forwarded straight to * the guest. */ -if ( !(cp->x86_vendor & (X86_VENDOR_INTEL |X86_VENDOR_AMD )) || - !(boot_cpu_data.vendor & - (X86_VENDOR_INTEL |X86_VENDOR_AMD )) || +if ( !(boot_cpu_data.vendor & (X86_VENDOR_INTEL |X86_VENDOR_AMD )) ||rdmsr_safe (MSR_AMD_PATCHLEVEL , val) ) goto gp_fault;break ;
Signature · 1 line
2.43.0
PATCH v5 4/5 x86/svm: Drop emulation of Intel's SYSENTER MSR behaviour
In reply to Alejandro VallejoWith cross-vendor support gone, it's no longer needed.
AMD CPUs ignore the top 32 bits of the SYSENTER/SYSEXIT MSRs, which is not how this emulation worked due to the need for cross-vendor support. Any AMD VMs storing state in the top 32bits of the SEP MSRs will lose it.
It's very unlikely to affect any production VM because having 64bit width just isn't how real AMD CPUs behave.
---
v5:
* New title
--- xen/arch/x86/hvm/svm/svm.c | 42 +++++++++++------------- xen/arch/x86/hvm/svm/vmcb.c | 3 ++ xen/arch/x86/include/asm/hvm/svm-types.h | 10 ------ 3 files changed, 22 insertions(+), 33 deletions(-)
xen/arch/x86/hvm/svm/svm.c +19 -23
@@ -401,10 +401,6 @@ static int svm_vmcb_save(struct vcpu *v, struct hvm_hw_cpu *c) {struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb; - c->sysenter_cs = v->arch.hvm.svm.guest_sysenter_cs; - c->sysenter_esp = v->arch.hvm.svm.guest_sysenter_esp; - c->sysenter_eip = v->arch.hvm.svm.guest_sysenter_eip; -if ( vmcb->event_inj.v &&hvm_event_needs_reinjection (vmcb->event_inj.type, vmcb->event_inj.vector) )
@@ -468,11 +464,6 @@ static int svm_vmcb_restore(struct vcpu *v, struct hvm_hw_cpu *c)svm_update_guest_cr (v,0 ,0 );svm_update_guest_cr (v,4 ,0 ); -/* Load sysenter MSRs into both VMCB save area and VCPU fields. */ - vmcb->sysenter_cs = v->arch.hvm.svm.guest_sysenter_cs = c->sysenter_cs; - vmcb->sysenter_esp = v->arch.hvm.svm.guest_sysenter_esp = c->sysenter_esp; - vmcb->sysenter_eip = v->arch.hvm.svm.guest_sysenter_eip = c->sysenter_eip; -if (paging_mode_hap (v->domain) ) {vmcb_set_np (vmcb, true);
@@ -501,6 +492,9 @@ static void svm_save_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data) {struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb; + data->sysenter_cs = vmcb->sysenter_cs; + data->sysenter_esp = vmcb->sysenter_esp; + data->sysenter_eip = vmcb->sysenter_eip; data->shadow_gs = vmcb->kerngsbase; data->msr_lstar = vmcb->lstar; data->msr_star = vmcb->star;
@@ -512,11 +506,14 @@ static void svm_load_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data) {struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb; - vmcb->kerngsbase = data->shadow_gs; - vmcb->lstar = data->msr_lstar; - vmcb->star = data->msr_star; - vmcb->cstar = data->msr_cstar; - vmcb->sfmask = data->msr_syscall_mask; + vmcb->lstar = data->msr_lstar; + vmcb->star = data->msr_star; + vmcb->cstar = data->msr_cstar; + vmcb->sfmask = data->msr_syscall_mask; + vmcb->kerngsbase = data->shadow_gs; + vmcb->sysenter_cs = data->sysenter_cs; + vmcb->sysenter_esp = data->sysenter_esp; + vmcb->sysenter_eip = data->sysenter_eip; v->arch.hvm.guest_efer = data->msr_efer;svm_update_guest_efer (v); }
@@ -1734,12 +1731,9 @@ static int cf_check svm_msr_read_intercept(switch ( msr ) { -/* -* Sync not needed while the cross-vendor logic is in unilateral effect. case MSR_IA32_SYSENTER_CS :case MSR_IA32_SYSENTER_ESP :case MSR_IA32_SYSENTER_EIP : -*/ case MSR_STAR :case MSR_LSTAR :case MSR_CSTAR :
@@ -1754,13 +1748,15 @@ static int cf_check svm_msr_read_intercept(switch ( msr ) {case MSR_IA32_SYSENTER_CS : - *msr_content = v->arch.hvm.svm.guest_sysenter_cs; + *msr_content = vmcb->sysenter_cs;break ; +case MSR_IA32_SYSENTER_ESP : - *msr_content = v->arch.hvm.svm.guest_sysenter_esp; + *msr_content = vmcb->sysenter_esp;break ; +case MSR_IA32_SYSENTER_EIP : - *msr_content = v->arch.hvm.svm.guest_sysenter_eip; + *msr_content = vmcb->sysenter_eip;break ;case MSR_STAR :
@@ -1954,11 +1950,11 @@ static int cf_check svm_msr_write_intercept(switch ( msr ) {case MSR_IA32_SYSENTER_ESP : - vmcb->sysenter_esp = v->arch.hvm.svm.guest_sysenter_esp = msr_content; + vmcb->sysenter_esp = msr_content;break ;case MSR_IA32_SYSENTER_EIP : - vmcb->sysenter_eip = v->arch.hvm.svm.guest_sysenter_eip = msr_content; + vmcb->sysenter_eip = msr_content;break ;case MSR_LSTAR :
@@ -1984,7 +1980,7 @@ static int cf_check svm_msr_write_intercept(break ;case MSR_IA32_SYSENTER_CS : - vmcb->sysenter_cs = v->arch.hvm.svm.guest_sysenter_cs = msr_content; + vmcb->sysenter_cs = msr_content;break ;case MSR_STAR :
xen/arch/x86/hvm/svm/vmcb.c +3 -0
@@ -97,6 +97,9 @@ static int construct_vmcb(struct vcpu *v)svm_disable_intercept_for_msr (v,MSR_LSTAR );svm_disable_intercept_for_msr (v,MSR_STAR );svm_disable_intercept_for_msr (v,MSR_SYSCALL_MASK ); +svm_disable_intercept_for_msr (v,MSR_IA32_SYSENTER_CS ); +svm_disable_intercept_for_msr (v,MSR_IA32_SYSENTER_EIP ); +svm_disable_intercept_for_msr (v,MSR_IA32_SYSENTER_ESP ); vmcb->_msrpm_base_pa =virt_to_maddr (svm->msrpm); vmcb->_iopm_base_pa =__pa (v->domain->arch.hvm.io_bitmap);
xen/arch/x86/include/asm/hvm/svm-types.h +0 -10
@@ -27,16 +27,6 @@ struct svm_vcpu {/* VMCB has a cached instruction from #PF/#NPF Decode Assist? */ uint8_t cached_insn_len;/* Zero if no cached instruction. */ - -/* -* Upper four bytes are undefined in the VMCB, therefore we can't use the -* fields in the VMCB. Write a 64bit value and then read a 64bit value is -* fine unless there's a VMRUN/VMEXIT in between which clears the upper -* four bytes. -*/ -uint64_t guest_sysenter_cs; -uint64_t guest_sysenter_esp; -uint64_t guest_sysenter_eip; };struct nestedsvm {
Signature · 1 line
2.43.0
PATCH v5 5/5 x86/hvm: Un-indent the HVM_FEP block in the #UD handler
In reply to Alejandro VallejoFEP is now the only reason for the #UD handler to run.
--- xen/arch/x86/hvm/hvm.c | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-)
xen/arch/x86/hvm/hvm.c +21 -22
@@ -3837,35 +3837,34 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)struct vcpu *cur = current;bool should_emulate = false;struct hvm_emulate_ctxt ctxt; +const struct segment_register *cs; +uint32_t walk; +unsigned long addr; +char sig[5 ];/* ud2; .ascii "xen" */ hvm_emulate_init_once (&ctxt,NULL , regs); -if ( opt_hvm_fep ) + cs = &ctxt.seg_reg[x86_seg_cs]; + walk = ((ctxt.seg_reg[x86_seg_ss].dpl ==3 ) + ? PFEC_user_mode :0 ) | PFEC_insn_fetch; + +if (hvm_virtual_to_linear_addr (x86_seg_cs, cs, regs->rip, +sizeof (sig), hvm_access_insn_fetch, + cs, &addr) && + (hvm_copy_from_guest_linear (sig, addr,sizeof (sig), + walk,NULL ) == HVMTRANS_okay) && + (memcmp (sig,"\xf\xb" "xen" ,sizeof (sig)) ==0 ) ) { -const struct segment_register *cs = &ctxt.seg_reg[x86_seg_cs]; -uint32_t walk = ((ctxt.seg_reg[x86_seg_ss].dpl ==3 ) - ? PFEC_user_mode :0 ) | PFEC_insn_fetch; -unsigned long addr; -char sig[5 ];/* ud2; .ascii "xen" */ - -if (hvm_virtual_to_linear_addr (x86_seg_cs, cs, regs->rip, -sizeof (sig), hvm_access_insn_fetch, - cs, &addr) && - (hvm_copy_from_guest_linear (sig, addr,sizeof (sig), - walk,NULL ) == HVMTRANS_okay) && - (memcmp (sig,"\xf\xb" "xen" ,sizeof (sig)) ==0 ) ) - { - regs->rip +=sizeof (sig); - regs->eflags &= ~X86_EFLAGS_RF ; + regs->rip +=sizeof (sig); + regs->eflags &= ~X86_EFLAGS_RF ; -/* Zero the upper 32 bits of %rip if not in 64bit mode. */ -if ( !(hvm_long_mode_active (cur) && cs->l) ) - regs->rip = (uint32_t )regs->rip; +/* Zero the upper 32 bits of %rip if not in 64bit mode. */ +if ( !(hvm_long_mode_active (cur) && cs->l) ) + regs->rip = (uint32_t )regs->rip; -add_taint (TAINT_HVM_FEP ); +add_taint (TAINT_HVM_FEP ); - should_emulate = true; - } + should_emulate = true; }if ( !should_emulate )
Signature · 1 line
2.43.0
Re: [PATCH v5 5/5] x86/hvm: Un-indent the HVM_FEP block in the #UD handler
Quoted 7 lines · Alejandro Vallejo
xen/arch/x86/hvm/hvm.c +1
-0@@ -3837,35 +3837,34 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)struct vcpu *cur = current;bool should_emulate = false;struct hvm_emulate_ctxt ctxt; +const struct segment_register *cs;
xen/arch/x86/hvm/hvm.c void hvm_ud_intercept(struct cpu_user_regs *regs) · line 3849
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +6
-1+uint32_t walk; +unsigned long addr; +char sig[5 ];/* ud2; .ascii "xen" */ hvm_emulate_init_once (&ctxt,NULL , regs); -if ( opt_hvm_fep ) + cs = &ctxt.seg_reg[x86_seg_cs]; + walk = ((ctxt.seg_reg[x86_seg_ss].dpl ==3 ) + ? PFEC_user_mode :0 ) | PFEC_insn_fetch;
While of course functionally everything's fine this way, I'm now entirely lost:
Why are what were ...
xen/arch/x86/hvm/hvm.c void hvm_ud_intercept(struct cpu_user_regs *regs) · line 3847
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +6
-3+if (hvm_virtual_to_linear_addr (x86_seg_cs, cs, regs->rip, +sizeof (sig), hvm_access_insn_fetch, + cs, &addr) && + (hvm_copy_from_guest_linear (sig, addr,sizeof (sig), + walk,NULL ) == HVMTRANS_okay) && + (memcmp (sig,"\xf\xb" "xen" ,sizeof (sig)) ==0 ) ) { -const struct segment_register *cs = &ctxt.seg_reg[x86_seg_cs]; -uint32_t walk = ((ctxt.seg_reg[x86_seg_ss].dpl ==3 ) - ? PFEC_user_mode :0 ) | PFEC_insn_fetch;
... initializers before not initializers anymore, when all you're doing is (supposedly) re-indentation (and, necessarily, moving decls up to the top of the scope they need to live in)?
Quoted 21 lines
xen/arch/x86/hvm/hvm.c +5
-15-unsigned long addr; -char sig[5 ];/* ud2; .ascii "xen" */ - -if (hvm_virtual_to_linear_addr (x86_seg_cs, cs, regs->rip, -sizeof (sig), hvm_access_insn_fetch, - cs, &addr) && - (hvm_copy_from_guest_linear (sig, addr,sizeof (sig), - walk,NULL ) == HVMTRANS_okay) && - (memcmp (sig,"\xf\xb" "xen" ,sizeof (sig)) ==0 ) ) - { - regs->rip +=sizeof (sig); - regs->eflags &= ~X86_EFLAGS_RF ; + regs->rip +=sizeof (sig); + regs->eflags &= ~X86_EFLAGS_RF ; -/* Zero the upper 32 bits of %rip if not in 64bit mode. */ -if ( !(hvm_long_mode_active (cur) && cs->l) ) - regs->rip = (uint32_t )regs->rip; +/* Zero the upper 32 bits of %rip if not in 64bit mode. */ +if ( !(hvm_long_mode_active (cur) && cs->l) ) + regs->rip = (uint32_t )regs->rip;
xen/arch/x86/hvm/hvm.c void hvm_ud_intercept(struct cpu_user_regs *regs) · line 3870
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +2
-3-add_taint (TAINT_HVM_FEP ); +add_taint (TAINT_HVM_FEP ); - should_emulate = true; - } + should_emulate = true; }if ( !should_emulate )
With this, the purpose of the should_emulate variable effectively vanishes, without it actually being purged (unlike you had it earlier).
Jan
Re: [PATCH v5 5/5] x86/hvm: Un-indent the HVM_FEP block in the #UD handler
Quoted 33 lines · Jan Beulich
Quoted 7 lines · Alejandro Vallejo
xen/arch/x86/hvm/hvm.c +1
-0@@ -3837,35 +3837,34 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)struct vcpu *cur = current;bool should_emulate = false;struct hvm_emulate_ctxt ctxt; +const struct segment_register *cs;xen/arch/x86/hvm/hvm.c void hvm_ud_intercept(struct cpu_user_regs *regs) · line 3849
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +6
-1+uint32_t walk; +unsigned long addr; +char sig[5 ];/* ud2; .ascii "xen" */ hvm_emulate_init_once (&ctxt,NULL , regs); -if ( opt_hvm_fep ) + cs = &ctxt.seg_reg[x86_seg_cs]; + walk = ((ctxt.seg_reg[x86_seg_ss].dpl ==3 ) + ? PFEC_user_mode :0 ) | PFEC_insn_fetch;While of course functionally everything's fine this way, I'm now entirely lost:
Why are what were ...xen/arch/x86/hvm/hvm.c void hvm_ud_intercept(struct cpu_user_regs *regs) · line 3847
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +6
-3+if (hvm_virtual_to_linear_addr (x86_seg_cs, cs, regs->rip, +sizeof (sig), hvm_access_insn_fetch, + cs, &addr) && + (hvm_copy_from_guest_linear (sig, addr,sizeof (sig), + walk,NULL ) == HVMTRANS_okay) && + (memcmp (sig,"\xf\xb" "xen" ,sizeof (sig)) ==0 ) ) { -const struct segment_register *cs = &ctxt.seg_reg[x86_seg_cs]; -uint32_t walk = ((ctxt.seg_reg[x86_seg_ss].dpl ==3 ) - ? PFEC_user_mode :0 ) | PFEC_insn_fetch;
Quoted 3 lines
... initializers before not initializers anymore, when all you're doing is (supposedly) re-indentation (and, necessarily, moving decls up to the top of the scope they need to live in)?
walk cannot be initialised at the delcaration site because it relies on hvm_emulate_init_once() having run and you made a strong argument to preserve the current form so I left cs next to walk, as it was before.
Quoted 31 lines
Quoted 31 lines
xen/arch/x86/hvm/hvm.c +7
-18-unsigned long addr; -char sig[5 ];/* ud2; .ascii "xen" */ - -if (hvm_virtual_to_linear_addr (x86_seg_cs, cs, regs->rip, -sizeof (sig), hvm_access_insn_fetch, - cs, &addr) && - (hvm_copy_from_guest_linear (sig, addr,sizeof (sig), - walk,NULL ) == HVMTRANS_okay) && - (memcmp (sig,"\xf\xb" "xen" ,sizeof (sig)) ==0 ) ) - { - regs->rip +=sizeof (sig); - regs->eflags &= ~X86_EFLAGS_RF ; + regs->rip +=sizeof (sig); + regs->eflags &= ~X86_EFLAGS_RF ; -/* Zero the upper 32 bits of %rip if not in 64bit mode. */ -if ( !(hvm_long_mode_active (cur) && cs->l) ) - regs->rip = (uint32_t )regs->rip; +/* Zero the upper 32 bits of %rip if not in 64bit mode. */ +if ( !(hvm_long_mode_active (cur) && cs->l) ) + regs->rip = (uint32_t )regs->rip; -add_taint (TAINT_HVM_FEP ); +add_taint (TAINT_HVM_FEP ); - should_emulate = true; - } + should_emulate = true; }
Quoted 4 lines
xen/arch/x86/hvm/hvm.c void hvm_ud_intercept(struct cpu_user_regs *regs) · line 3870
Quoted 1 line
xen/arch/x86/hvm/hvm.c +0
-0if ( !should_emulate )With this, the purpose of the
should_emulatevariable effectively vanishes, without it actually being purged (unlike you had it earlier).
That goes away with patch 6, that I neglected to send before.
Quoted 2 lines
Jan
Quoted 1 line · Alejandro Vallejo
Patches 2, 4 and 5 missing acks.
What's missing for patch 4?
Jan
Quoted 6 lines · Jan Beulich
Quoted 1 line · Alejandro Vallejo
Patches 2, 4 and 5 missing acks.
What's missing for patch 4?
Jan
Ah, nothing. Just off by one patch. That's meant to be 2, 5 and 6. There's a sixth patch missing.
Incoming...
Cheers,
Alejandro
[PATCH v5 6/5] x86/hvm: Add a non-FEP path to the #UD handler
In reply to Alejandro VallejoWhile the #UD handler is dead code when CONFIG_HVM_FEP is disabled it's helpful to keep the function around. Reinject #UD in the non-FEP case so DCE can remove the rest.
--- xen/arch/x86/hvm/hvm.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
xen/arch/x86/hvm/hvm.c +9 -9
@@ -3835,13 +3835,18 @@ int hvm_descriptor_access_intercept(uint64_t exit_info,void hvm_ud_intercept (struct cpu_user_regs *regs) {struct vcpu *cur = current; -bool should_emulate = false;struct hvm_emulate_ctxt ctxt;const struct segment_register *cs;uint32_t walk;unsigned long addr;char sig[5 ];/* ud2; .ascii "xen" */ +if ( !opt_hvm_fep ) + { +ASSERT_UNREACHABLE (); + goto reinject; + } +hvm_emulate_init_once (&ctxt,NULL , regs); cs = &ctxt.seg_reg[x86_seg_cs];
@@ -3863,20 +3868,15 @@ void hvm_ud_intercept(struct cpu_user_regs *regs) regs->rip = (uint32_t )regs->rip;add_taint (TAINT_HVM_FEP ); - - should_emulate = true; - } - -if ( !should_emulate ) - { -hvm_inject_hw_exception (X86_EXC_UD ,X86_EVENT_NO_EC ); -return ; } +else + goto reinject;switch (hvm_emulate_one (&ctxt, VIO_no_completion) ) {case X86EMUL_UNHANDLEABLE :case X86EMUL_UNIMPLEMENTED : + reinject:hvm_inject_hw_exception (X86_EXC_UD ,X86_EVENT_NO_EC );break ;case X86EMUL_EXCEPTION :
Signature · 1 line
2.43.0
Re: [PATCH v5 6/5] x86/hvm: Add a non-FEP path to the #UD handler
Quoted 3 lines · Alejandro Vallejo
While the #UD handler is dead code when
CONFIG_HVM_FEPis disabled it's helpful to keep the function around. Reinject #UD in the non-FEP case so DCE can remove the rest.
For the code change - I don't think this should be a separate change. I also didn't understand Andrew's earlier request to split the original change to go this far.
As to the "dead code" aspect (using Misra terminology it's really "unreachable code" aiui), we may need to deal with that, as we've accepted that rule. Yes, Eclair is unlikely to be able to spot this, yet that doesn't make the issue go away.
Jan
Quoted 46 lines
xen/arch/x86/hvm/hvm.c +9
-9@@ -3835,13 +3835,18 @@ int hvm_descriptor_access_intercept(uint64_t exit_info,void hvm_ud_intercept (struct cpu_user_regs *regs) {struct vcpu *cur = current; -bool should_emulate = false;struct hvm_emulate_ctxt ctxt;const struct segment_register *cs;uint32_t walk;unsigned long addr;char sig[5 ];/* ud2; .ascii "xen" */ +if ( !opt_hvm_fep ) + { +ASSERT_UNREACHABLE (); + goto reinject; + } +hvm_emulate_init_once (&ctxt,NULL , regs); cs = &ctxt.seg_reg[x86_seg_cs];@@ -3863,20 +3868,15 @@ void hvm_ud_intercept(struct cpu_user_regs *regs) regs->rip = (uint32_t )regs->rip;add_taint (TAINT_HVM_FEP ); - - should_emulate = true; - } - -if ( !should_emulate ) - { -hvm_inject_hw_exception (X86_EXC_UD ,X86_EVENT_NO_EC ); -return ; } +else + goto reinject;switch (hvm_emulate_one (&ctxt, VIO_no_completion) ) {case X86EMUL_UNHANDLEABLE :case X86EMUL_UNIMPLEMENTED : + reinject:hvm_inject_hw_exception (X86_EXC_UD ,X86_EVENT_NO_EC );break ;case X86EMUL_EXCEPTION :
Re: [PATCH v5 6/5] x86/hvm: Add a non-FEP path to the #UD handler
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Alejandro Vallejo
While the #UD handler is dead code when
CONFIG_HVM_FEPis disabled it's helpful to keep the function around. Reinject #UD in the non-FEP case so DCE can remove the rest.For the code change - I don't think this should be a separate change. I also didn't understand Andrew's earlier request to split the original change to go this far.
I don't mind either way. Fold it with the prior patch if you think it's better that way.
Quoted 5 lines
As to the "dead code" aspect (using Misra terminology it's really "unreachable code" aiui), we may need to deal with that, as we've accepted that rule. Yes, Eclair is unlikely to be able to spot this, yet that doesn't make the issue go away.
That's also the case for handlers of other VMEXIT error codes under certain configurations. The original patch I sent fully removed the #UD handler to restrict the unreachable part to just a BUG_ON(). But even that was incomplete.
The solution is some creative filtering at the switch condition, but that's something I haven't had time to experiment with yet.
Cheers,
Alejandro