Skip to contentSkip to conversation

Add support for nested SVM (userspace)

RFC PATCH In review Alexander Graf 4 participants 11 messages Sep 1, 2008 – Sep 3, 2008 KVM

lore
Share & tools
lore
#0 lore raw

cover Add support for nested SVM (userspace)

This is the userspace part of the nested SVM series. It enables building the nested SVM code as external module and passes through the SVM CPUID bit to the VM.

Alexander Graf (2):
Add SVM CPUID feature define for backwards compatibility Allow the SVM CPUID bit in a VM

 kernel/x86/external-module-compat.h |    4 ++++
 qemu/qemu-kvm-x86.c                 |    3 ---
 2 files changed, 4 insertions(+), 3 deletions(-)
#1 lore raw

PATCH 1/2 Add SVM CPUID feature define for backwards compatibility

Add the SVM capability to the external module compat header, so we can use it when the kernel does not know about this define.

---
 kernel/x86/external-module-compat.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
kernel/x86/external-module-compat.h +4 -0
index c53e0d6..c4def59 100644
@@ -201,6 +201,10 @@ static inline void preempt_notifier_sys_exit(void) {}
 #define X86_FEATURE_NX (1*32+20)
 #endif
 
+#ifndef X86_FEATURE_SVM
+#define X86_FEATURE_SVM (6*32+2)
+#endif
+
 #undef true
 #define true 1
 #undef false
Signature · 1 line
1.5.6
#2 lore raw

PATCH 2/2 Allow the SVM CPUID bit in a VM

Usually the qemu-kvm-bridge removes the SVM capability flag. Since KVM now supports nested SVM, this is no longer necessary.

---
 qemu/qemu-kvm-x86.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
qemu/qemu-kvm-x86.c +0 -3
index 5daedd1..cfc533f 100644
@@ -489,9 +489,6 @@ static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function,
 	// nx
 	if ((h_edx & 0x00100000) == 0)
 	    e->edx &= ~0x00100000u;
-	// svm
-	if (e->ecx & 4)
-	    e->ecx &= ~4u;
     }
     // sysenter isn't supported on compatibility mode on AMD.  and syscall
     // isn't supported in compatibility mode on Intel.  so advertise the
Signature · 1 line
1.5.6
#3 lore raw

Re: [PATCH 2/2] Allow the SVM CPUID bit in a VM

Quoted 13 lines · Alexander Graf

Usually the qemu-kvm-bridge removes the SVM capability flag. Since KVM now supports nested SVM, this is no longer necessary.

---
 qemu/qemu-kvm-x86.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
qemu/qemu-kvm-x86.c +0 -0
index 5daedd1..cfc533f 100644

qemu/qemu-kvm-x86.c static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function, · line 493

Quoted 8 lines
qemu/qemu-kvm-x86.c +0 -3
@@ -489,9 +489,6 @@ static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function,
 	// nx
 	if ((h_edx & 0x00100000) == 0)
 	    e->edx &= ~0x00100000u;
-	// svm
-	if (e->ecx & 4)
-	    e->ecx &= ~4u;
     }
 

Needs to be predicated on a KVM_CAP_ test, so we don't enable this on older kvms.

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw

Re: [PATCH 2/2] Allow the SVM CPUID bit in a VM

Quoted 9 lines · Avi Kivity
Quoted 8 lines · Alexander Graf

Usually the qemu-kvm-bridge removes the SVM capability flag. Since KVM now supports nested SVM, this is no longer necessary.

---
qemu/qemu-kvm-x86.c | 3 ---

1 files changed, 0 insertions(+), 3 deletions(-)
Quoted 16 lines
Quoted 5 lines
qemu/qemu-kvm-x86.c +0 -0
index 5daedd1..cfc533f 100644

qemu/qemu-kvm-x86.c static void do_cpuid_ent(struct kvm_cpuid_entry · line 494

Quoted 9 lines
qemu/qemu-kvm-x86.c +0 -3
@@ -489,9 +489,6 @@ static void do_cpuid_ent(struct kvm_cpuid_entry  
 *e, uint32_t function,
 	// nx
 	if ((h_edx & 0x00100000) == 0)
 	    e->edx &= ~0x00100000u;
-	// svm
-	if (e->ecx & 4)
-	    e->ecx &= ~4u;
    }
 

Needs to be predicated on a KVM_CAP_ test, so we don't enable this on older kvms.

Is this a real problem? We don't allow setting SVME on older kernels anyways.

Alex

#5 lore raw

Re: [PATCH 2/2] Allow the SVM CPUID bit in a VM

Quoted 29 lines · Alexander Graf
Quoted 9 lines · Avi Kivity
Quoted 8 lines · Alexander Graf

Usually the qemu-kvm-bridge removes the SVM capability flag. Since KVM now supports nested SVM, this is no longer necessary.

---
qemu/qemu-kvm-x86.c | 3 ---

1 files changed, 0 insertions(+), 3 deletions(-)
Quoted 16 lines
Quoted 5 lines
qemu/qemu-kvm-x86.c +0 -0
index 5daedd1..cfc533f 100644

qemu/qemu-kvm-x86.c static void do_cpuid_ent(struct · line 494

Quoted 9 lines
qemu/qemu-kvm-x86.c +0 -3
@@ -489,9 +489,6 @@ static void do_cpuid_ent(struct  
 kvm_cpuid_entry *e, uint32_t function,
 	// nx
 	if ((h_edx & 0x00100000) == 0)
 	    e->edx &= ~0x00100000u;
-	// svm
-	if (e->ecx & 4)
-	    e->ecx &= ~4u;
   }
 

Needs to be predicated on a KVM_CAP_ test, so we don't enable this on older kvms.

Quoted 1 line

Is this a real problem? We don't allow setting SVME on older kernels anyways.

On a sidenote I'm really not fond of the userspace CPUID capability restrictions in the first place. Shouldn't this all be determined in the kernel module? It doesn't make since IMHO to restrict NX usage from userspace. The kernel module knows best what it's capable of.

Alex

Quoted 7 lines

Alex
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

RE: [PATCH 2/2] Allow the SVM CPUID bit in a VM

Userspace may know better, for example when you want to allow live migration between multiple hosts and want to calculate lowest common denominator between them.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alexander Graf
Sent: Tuesday, September 02, 2008 20:54 PM
To: Alexander Graf
Cc: Avi Kivity; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/2] Allow the SVM CPUID bit in a VM

Quoted 31 lines · Alexander Graf
Quoted 19 lines · Avi Kivity
Quoted 18 lines · Alexander Graf

Usually the qemu-kvm-bridge removes the SVM capability flag. Since KVM now
supports nested SVM, this is no longer necessary.

---
qemu/qemu-kvm-x86.c | 3 ---

1 files changed, 0 insertions(+), 3 deletions(-)
qemu/qemu-kvm-x86.c +0 -0
index 5daedd1..cfc533f 100644
@@ -489,9 +489,6 @@ static void do_cpuid_ent(struct  
 kvm_cpuid_entry *e, uint32_t function,
 	// nx
 	if ((h_edx & 0x00100000) == 0)
 	    e->edx &= ~0x00100000u;
Quoted 8 lines

qemu/qemu-kvm-x86.c static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function,

Quoted 5 lines
qemu/qemu-kvm-x86.c +0 -3
-	// svm
-	if (e->ecx & 4)
-	    e->ecx &= ~4u;
   }
 

Needs to be predicated on a KVM_CAP_ test, so we don't enable this on older kvms.

Quoted 2 lines

Is this a real problem? We don't allow setting SVME on older kernels anyways.

On a sidenote I'm really not fond of the userspace CPUID capability restrictions in the first place. Shouldn't this all be determined in the kernel module? It doesn't make since IMHO to restrict NX usage from userspace. The kernel module knows best what it's capable of.

Alex

Quoted 7 lines

Alex
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

Re: [PATCH 2/2] Allow the SVM CPUID bit in a VM

In reply to Alexander Graf

Hi,

Quoted 4 lines

On a sidenote I'm really not fond of the userspace CPUID capability restrictions in the first place. Shouldn't this all be determined in the kernel module? It doesn't make since IMHO to restrict NX usage from userspace. The kernel module knows best what it's capable of.

I think cpuid handling will be a quite interesting when it comes to merging qemu and kvm. Doing it completely in the kernel isn't going to work. There are several reasons why you might want to change the cpuid presented to the guest.

First, you might want to mask out cpuid bits not supported by all machines in your pool, for migration compatibility.

Second, you might want to present a specific CPU to the guest (like qemu -cpu pentium). At least as close as possible, of course there are some restrictions. I think even if you mask out the sse cpuid bit sse instructions will actually work. Also having a virtual intel cpu on amd and visa versa probably isn't going to work unless we'll fall back to the emulator for the missing instructions.

Third, there is the hypervisor cpuid range (0x40000000+). That one needs to be configurable by userspace as well.

cheers,
Gerd

#8 lore raw

Re: [PATCH 2/2] Allow the SVM CPUID bit in a VM

Quoted 23 lines · Gerd Hoffmann

Hi,

Quoted 4 lines

On a sidenote I'm really not fond of the userspace CPUID capability restrictions in the first place. Shouldn't this all be determined in the kernel module? It doesn't make since IMHO to restrict NX usage from userspace. The kernel module knows best what it's capable of.

I think cpuid handling will be a quite interesting when it comes to merging qemu and kvm. Doing it completely in the kernel isn't going to work. There are several reasons why you might want to change the cpuid presented to the guest.

First, you might want to mask out cpuid bits not supported by all machines in your pool, for migration compatibility.

Second, you might want to present a specific CPU to the guest (like qemu -cpu pentium). At least as close as possible, of course there are some
restrictions. I think even if you mask out the sse cpuid bit sse instructions will actually work. Also having a virtual intel cpu on amd and visa versa probably isn't going to work unless we'll fall back to the emulator for the missing instructions.

Quoted 2 lines

Third, there is the hypervisor cpuid range (0x40000000+). That one needs to be configurable by userspace as well.

I guess I didn't express myself correctly, sorry for that :-). I think that kvm kernel module capabilities should be masked out in the kernel module, while "other" stuff, like migration masking or additional CPUIDs (do these work atm?) should of course reside in the userspace.

The code I was referring to was the removal of the NX bit and the SVM bit. These are definitely kernel capabilities. If the kernel module doesn't implement these, it should just mask them out instead of having userspace figure out what's there and what isn't.

I hope I didn't completely confuse everybody now :-). On a sidenote: We really need to switch to the newer cpuid kernel<->userspace interface. The way it currently is, CPUID 4 is severely broken.

Alex

#10 lore raw

Re: [PATCH 2/2] Allow the SVM CPUID bit in a VM

In reply to Alexander Graf
Quoted 4 lines · Alexander Graf
Quoted 2 lines

Needs to be predicated on a KVM_CAP_ test, so we don't enable this on older kvms.

Is this a real problem? We don't allow setting SVME on older kernels anyways.

Actually the kernel exports its supported cpuid bits via KVM_GET_SUPPORTED_CPUID.

Signature · 1 line
error compiling committee.c: too many arguments to function
#9 lore raw

Re: [PATCH 2/2] Allow the SVM CPUID bit in a VM

In reply to Alexander Graf
Quoted 2 lines · Alexander Graf

I guess I didn't express myself correctly, sorry for that :-). I think that kvm kernel module capabilities should be masked out in the kernel module, while "other" stuff, like migration masking or additional CPUIDs (do these work atm?) should of course reside in the userspace.

But then userspace needs to know when capabilities userspace actually sees.

Quoted 2 lines

The code I was referring to was the removal of the NX bit and the SVM bit. These are definitely kernel capabilities. If the kernel module doesn't implement these, it should just mask them out instead of having userspace figure out what's there and what isn't.

The flow I have in mind is:

- kernel exports which cpuid bits it supports (global information; not tied to a guest; this way it can be used to calculate g-c-d)
- userspace merges this information with its own ideas
- userspace tells the kernel what cpuid bits to present to the guest (lying is allowed)

This gives the maximum flexibility and visibility.

NX and SVM are masked for backward compatibility with older userspace; we could probably remove this masking now.

Quoted 2 lines

I hope I didn't completely confuse everybody now :-). On a sidenote: We really need to switch to the newer cpuid kernel<->userspace interface. The way it currently is, CPUID 4 is severely broken.

There is a new interface in place (quite old by now), unfortunately it isn't used by qemu.

Signature · 1 line
error compiling committee.c: too many arguments to function