x86/vmx: Correct the long mode check in vmx_cpuid_intercept()
PATCH 1/2 x86/vmx: Correct the long mode check in vmx_cpuid_intercept()
%cs.L may be set in a legacy mode segment, or clear in a compatibility mode segment; it is not the correct way to check for long mode being active.
Both of these situations result in incorrect visibility of the SYSCALL feature in CPUID, and by extension, incorrect behaviour in hvm_efer_valid().
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
--- xen/arch/x86/hvm/vmx/vmx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +1 -3
@@ -2407,7 +2407,6 @@ static void vmx_cpuid_intercept( unsigned int *ecx, unsigned int *edx) {unsigned int input = *eax; -struct segment_register cs;struct vcpu *v = current;hvm_cpuid (input, eax, ebx, ecx, edx);
@@ -2416,8 +2415,7 @@ static void vmx_cpuid_intercept( {case 0x80000001 :/* SYSCALL is visible iff running in long mode. */ -vmx_get_segment_register (v, x86_seg_cs, &cs); -if ( cs.attr.fields.l ) +if (hvm_long_mode_enabled (v) ) *edx |=cpufeat_mask (X86_FEATURE_SYSCALL );else *edx &= ~(cpufeat_mask (X86_FEATURE_SYSCALL ));
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/2 x86/traps: Don't call hvm_hypervisor_cpuid_leaf() for PV guests
Luckily, hvm_hypervisor_cpuid_leaf() and vmx_hypervisor_cpuid_leaf() are safe to execute in the context of a PV guest, but HVM-specific feature flags shouldn't be visible to PV guests.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/traps.c | 5 +++++ 1 file changed, 5 insertions(+)
xen/arch/x86/traps.c +5 -0
@@ -928,6 +928,11 @@ int cpuid_hypervisor_leaves( uint32_t idx, uint32_t sub_idx,break ;case 4 : +if ( !has_hvm_container_domain (currd) ) + { + *eax = *ebx = *ecx = *edx =0 ; +break ; + }hvm_hypervisor_cpuid_leaf (sub_idx, eax, ebx, ecx, edx);break ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH for-4.8 2/2] x86/traps: Don't call hvm_hypervisor_cpuid_leaf() for PV guests
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 14.11.16 at 12:01, <[email protected]> wrote:
Luckily,
hvm_hypervisor_cpuid_leaf()andvmx_hypervisor_cpuid_leaf()are safe to execute in the context of a PV guest, but HVM-specific feature flags shouldn't be visible to PV guests.Signed-off-by Andrew Cooper <[email protected]>
albeit ...
xen/arch/x86/traps.c int cpuid_hypervisor_leaves( uint32_t idx, uint32_t sub_idx, · line 937
Quoted 13 lines
xen/arch/x86/traps.c +5
-0@@ -928,6 +928,11 @@ int cpuid_hypervisor_leaves( uint32_t idx, uint32_t sub_idx,break ;case 4 : +if ( !has_hvm_container_domain (currd) ) + { + *eax = *ebx = *ecx = *edx =0 ; +break ; + }hvm_hypervisor_cpuid_leaf (sub_idx, eax, ebx, ecx, edx);break ;
... this being the last leaf, wouldn't we better limit the number of leaves (reported in leaf 0) to 3 for PV?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH for-4.8 2/2] x86/traps: Don't call hvm_hypervisor_cpuid_leaf() for PV guests
Quoted 14 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 14.11.16 at 12:01, <[email protected]> wrote:
Luckily,
hvm_hypervisor_cpuid_leaf()andvmx_hypervisor_cpuid_leaf()are safe to execute in the context of a PV guest, but HVM-specific feature flags shouldn't be visible to PV guests.Signed-off-by Andrew Cooper <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit ...
Quoted 5 lines
xen/arch/x86/traps.c +0
-0@@ -928,6 +928,11 @@ int cpuid_hypervisor_leaves( uint32_t idx, uint32_t sub_idx,break ;
Quoted 10 lines
xen/arch/x86/traps.c int cpuid_hypervisor_leaves( uint32_t idx, uint32_t sub_idx, · line 937
Quoted 8 lines
xen/arch/x86/traps.c +5
-0case 4 : +if ( !has_hvm_container_domain (currd) ) + { + *eax = *ebx = *ecx = *edx =0 ; +break ; + }hvm_hypervisor_cpuid_leaf (sub_idx, eax, ebx, ecx, edx);break ;... this being the last leaf, wouldn't we better limit the number of leaves (reported in leaf 0) to 3 for PV?
I considered this, but decided not to.
The current max leaf handling is fragile, owing to some dubious control from the toolstack, and the existence of XEN_CPUID_MAX_NUM_LEAVES in the public API is absolutely broken.
I am going to need to rework this all anyway, and its not clear whether we can/should report less than 4 leaves to PV guests.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 14.11.16 at 12:01, <[email protected]> wrote:
%cs.L may be set in a legacy mode segment, or clear in a compatibility mode segment; it is not the correct way to check for long mode being active.
Both of these situations result in incorrect visibility of the SYSCALL feature in CPUID, and by extension, incorrect behaviour in
hvm_efer_valid().Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 7 lines · Andrew Cooper
%cs.L may be set in a legacy mode segment, or clear in a compatibility mode segment; it is not the correct way to check for long mode being active.
Both of these situations result in incorrect visibility of the SYSCALL feature in CPUID, and by extension, incorrect behaviour in
hvm_efer_valid().Signed-off-by Andrew Cooper <[email protected]>
Both patches:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 10 lines
From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, November 14, 2016 7:01 PM%cs.L may be set in a legacy mode segment, or clear in a compatibility mode segment; it is not the correct way to check for long mode being active.
Both of these situations result in incorrect visibility of the SYSCALL feature in CPUID, and by extension, incorrect behaviour in
hvm_efer_valid().Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel