Skip to contentSkip to conversation

EFER in HVM guests

DISCUSSION Li, Xin B 4 participants 4 messages Dec 13, 2006 – Dec 15, 2006

lore
Share & tools
lore

Li, Xin B

author
#0 lore raw

Is this the framework what you want?
And we still need merge the common cases here.
-Xin

Quoted 32 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: 2006年11月30日 1:22
To: Nakajima, Jun; Jan Beulich; [email protected]; Keir Fraser
Subject: Re: [Xen-devel] EFER in HVM guests

*Please* can you make the handling of generic CPUID leaves and architectural
MSRs common HVM code? There is lots of needless code duplication right now
with niggling differences that shouldn't be necessary.

-- Keir

Quoted 13 lines · Jun
Quoted 12 lines

I think it does - allowing a guest to enable EFER.LME when the hypervisor is a 32-bit one is clearly a security problem: While I haven't tried it, I would suspect the moment you load a context with such an EFER the whole system's dead.
Not being able to access EFER is also a potential problem, as a guest should be allowed to set EFER.NX (at least) - the CPUID handling code specifically does not suppress this bit if the guest is allowed to use PAE (which we agreed a few days ago should be the default anyway).

Jan

Quoted 9 lines
Quoted 2 lines

I agree that we should allow 32-bit guests to set EFER.NX on the PAE Xen. We'll fix it. EFER.SCE should not be set on IA-32.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

xen/arch/x86/hvm/hvm.c +5 -0
diff -r 478ddc354ccd xen/arch/x86/hvm/hvm.c
@@ -384,6 +384,11 @@ int hvm_copy_from_guest_virt(void *buf, 
     return __hvm_copy(buf, vaddr, size, 0, 1);
 }
 
+void hvm_cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
+{
+    if ( !cpuid_hypervisor_leaves(*eax, eax, ebx, ecx, edx) )
+        return hvm_do_cpuid(eax, ebx, ecx, edx);
+}
 
 /* HVM specific printbuf. Mostly used for hvmloader chit-chat. */
 void hvm_print_line(struct vcpu *v, const char c)
xen/arch/x86/hvm/vmx/vmx.c +98 -116

238 lines not on this page · raw message

xen/include/asm-x86/hvm/hvm.h +10 -0
diff -r 478ddc354ccd xen/include/asm-x86/hvm/hvm.h
@@ -110,6 +110,8 @@ struct hvm_function_table {
     void (*stts)(struct vcpu *v);
     void (*set_tsc_offset)(struct vcpu *v, u64 offset);
 
+    void (*do_cpuid)(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
+
     void (*inject_exception)(unsigned int trapnr, int errcode,
                              unsigned long cr2);
 
@@ -218,6 +220,14 @@ void hvm_migrate_timers(struct vcpu *v);
 void hvm_migrate_timers(struct vcpu *v);
 void hvm_do_resume(struct vcpu *v);
 
+void hvm_cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
+
+static inline void
+hvm_do_cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
+{
+    return hvm_funcs.do_cpuid(eax, ebx, ecx, edx);
+}
+
 static inline void
 hvm_init_ap_context(struct vcpu_guest_context *ctxt,
                     int vcpuid, int trampoline_vector)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 1 line

And we still need merge the common cases here.

But that is the important part. So far you basically only renamed functions.

Jan

#2 lore raw
In reply to Li, Xin B

Not quite what I had in mind. Control starts from VMX/SVM so we shouldn't need an extra hvm_ops hook function.

What I envisage is something like:

Vmx_cpuid() {
/* CPU-specific pre-processing goes here. */
hvm_cpuid();
/* CPU-specific post-processing goes here. */
}

So VMX/SVM calls out to HVM, not vice versa. You can see that this also gives you full flexibility to do pre-processing (before calling hvm-generic function) as well as post-processing.

As Jan points out, there's little point in doing this without actually pulling out some common code at the same time. Or hvm_cpuid() will be a no-op. :-)

-- Keir

Quoted 49 lines · Xin B

Is this the framework what you want?
And we still need merge the common cases here.
-Xin

Quoted 32 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: 2006年11月30日 1:22
To: Nakajima, Jun; Jan Beulich; [email protected]; Keir Fraser
Subject: Re: [Xen-devel] EFER in HVM guests

*Please* can you make the handling of generic CPUID leaves and architectural
MSRs common HVM code? There is lots of needless code duplication right now
with niggling differences that shouldn't be necessary.

-- Keir

Quoted 13 lines · Jun
Quoted 12 lines

I think it does - allowing a guest to enable EFER.LME when the hypervisor is a 32-bit one is clearly a security problem: While I haven't tried it, I would suspect the moment you load a context with such an EFER the whole system's dead.
Not being able to access EFER is also a potential problem, as a guest should be allowed to set EFER.NX (at least) - the CPUID handling code specifically does not suppress this bit if the guest is allowed to use PAE (which we agreed a few days ago should be the default anyway).

Jan

Quoted 9 lines
Quoted 2 lines

I agree that we should allow 32-bit guests to set EFER.NX on the PAE Xen. We'll fix it. EFER.SCE should not be set on IA-32.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw

Xin, when you have a tested hvm/vmx functional patch, we can run thru SVM platforms for testing and determine if any AMD specific modifications are needed. Just post to the list the patch/changeset tested, (CC me directly if you remember). I'll have our test group run thru the boot tests first, then our usual ltp/cerberus and windows testing over a few days. Cheers,
-- Tom

Quoted 97 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: Wednesday, December 13, 2006 8:37 AM
To: Li, Xin B; Keir Fraser; Nakajima, Jun; Jan Beulich; [email protected]
Subject: Re: [Xen-devel] EFER in HVM guests

Not quite what I had in mind. Control starts from VMX/SVM so we shouldn't need an extra hvm_ops hook function.

What I envisage is something like:

Vmx_cpuid() {
   /* CPU-specific pre-processing goes here. */
   hvm_cpuid();
   /* CPU-specific post-processing goes here. */ }

So VMX/SVM calls out to HVM, not vice versa. You can see that this also gives you full flexibility to do pre-processing (before calling hvm-generic
function) as well as post-processing.

As Jan points out, there's little point in doing this without actually pulling out some common code at the same time. Or hvm_cpuid() will be a no-op. :-)

-- Keir

Quoted 10 lines · Xin B

Is this the framework what you want?
And we still need merge the common cases here.
-Xin

Quoted 6 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Keir Fraser
Sent: 2006年11月30日 1:22
To: Nakajima, Jun; Jan Beulich;

[email protected]; Keir

Quoted 9 lines
Quoted 9 lines

Fraser
Subject: Re: [Xen-devel] EFER in HVM guests

*Please* can you make the handling of generic CPUID leaves and architectural MSRs common HVM code? There is lots of needless code duplication right now with niggling differences that shouldn't be necessary.

Quoted 6 lines
Quoted 6 lines

-- Keir

Quoted 2 lines · Jun
Quoted 2 lines

I think it does - allowing a guest to enable EFER.LME when the hypervisor is a 32-bit one is clearly a security

problem: While I

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

haven't tried it, I would suspect the moment you load a context with such an EFER the whole system's dead.
Not being able to access EFER is also a potential problem, as a guest should be allowed to set EFER.NX (at least) - the CPUID handling code specifically does not suppress this bit if

the guest

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

is allowed to use PAE (which we agreed a few days ago

should be the

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

default anyway).

Jan

I agree that we should allow 32-bit guests to set EFER.NX

on the PAE

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

Xen. We'll fix it. EFER.SCE should not be set on IA-32.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel