Skip to contentSkip to conversation

Refactor hypercall infrastructure (v2)

PATCH In review Anthony Liguori 4 participants 9 messages Sep 15, 2007 – Dec 3, 2007 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Refactor hypercall infrastructure (v2)

This patch refactors the current hypercall infrastructure to better support live migration and SMP. It eliminates the hypercall page by trapping the UD exception that would occur if you used the wrong hypercall instruction for the underlying architecture and replacing it with the right one lazily.

It also introduces the infrastructure to probe for hypercall available via CPUID leaves 0x40001000. CPUID leaf 0x40001001 should be filled out by userspace.

A fall-out of this patch is that the unhandled hypercalls no longer trap to userspace. There is very little reason though to use a hypercall to communicate with userspace as PIO or MMIO can be used. There is no code in tree that uses userspace hypercalls.

Since the last patchset, I've changed the CPUID leaves to better avoid Xen's CPUID range and fixed a bug spotted by Muli in masking off hypercall arguments.

drivers/kvm/kvm.h +4 -4
index ad08138..1cde572 100644
@@ -46,6 +46,7 @@
 #define KVM_MAX_CPUID_ENTRIES 40
 
 #define DE_VECTOR 0
+#define UD_VECTOR 6
 #define NM_VECTOR 7
 #define DF_VECTOR 8
 #define TS_VECTOR 10
@@ -317,9 +318,6 @@ struct kvm_vcpu {
 	unsigned long cr0;
 	unsigned long cr2;
 	unsigned long cr3;
-	gpa_t para_state_gpa;
-	struct page *para_state_page;
-	gpa_t hypercall_gpa;
 	unsigned long cr4;
 	unsigned long cr8;
 	u64 pdptrs[4]; /* pae */
@@ -622,7 +620,9 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
 int kvm_mmu_load(struct kvm_vcpu *vcpu);
 void kvm_mmu_unload(struct kvm_vcpu *vcpu);
 
-int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
+int kvm_emulate_hypercall(struct kvm_vcpu *vcpu);
+
+int kvm_fix_hypercall(struct kvm_vcpu *vcpu);
 
 static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
 				     u32 error_code)
drivers/kvm/kvm_main.c +60 -111

216 lines not on this page · raw message

drivers/kvm/svm.c +16 -3
index 729f1cd..d09a9f5 100644
@@ -476,7 +476,8 @@ static void init_vmcb(struct vmcb *vmcb)
 					INTERCEPT_DR5_MASK |
 					INTERCEPT_DR7_MASK;
 
-	control->intercept_exceptions = 1 << PF_VECTOR;
+	control->intercept_exceptions = (1 << PF_VECTOR) |
+					(1 << UD_VECTOR);
 
 
 	control->intercept = 	(1ULL << INTERCEPT_INTR) |
@@ -970,6 +971,17 @@ static int pf_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 	return 0;
 }
 
+static int ud_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
+{
+	int er;
+	
+	er = emulate_instruction(&svm->vcpu, kvm_run, 0, 0);
+	if (er != EMULATE_DONE)
+		inject_ud(&svm->vcpu);
+
+	return 1;
+}
+
 static int nm_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 {
 	svm->vmcb->control.intercept_exceptions &= ~(1 << NM_VECTOR);
@@ -1036,7 +1048,8 @@ static int vmmcall_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 {
 	svm->next_rip = svm->vmcb->save.rip + 3;
 	skip_emulated_instruction(&svm->vcpu);
-	return kvm_hypercall(&svm->vcpu, kvm_run);
+	kvm_emulate_hypercall(&svm->vcpu);
+	return 1;
 }
 
 static int invalid_op_interception(struct vcpu_svm *svm,
@@ -1232,6 +1245,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm,
 	[SVM_EXIT_WRITE_DR3]			= emulate_on_interception,
 	[SVM_EXIT_WRITE_DR5]			= emulate_on_interception,
 	[SVM_EXIT_WRITE_DR7]			= emulate_on_interception,
+	[SVM_EXIT_EXCP_BASE + UD_VECTOR]	= ud_interception,
 	[SVM_EXIT_EXCP_BASE + PF_VECTOR] 	= pf_interception,
 	[SVM_EXIT_EXCP_BASE + NM_VECTOR] 	= nm_interception,
 	[SVM_EXIT_INTR] 			= nop_on_interception,
@@ -1664,7 +1678,6 @@ svm_patch_hypercall(struct kvm_vcpu *vcpu, unsigned char *hypercall)
 	hypercall[0] = 0x0f;
 	hypercall[1] = 0x01;
 	hypercall[2] = 0xd9;
-	hypercall[3] = 0xc3;
 }
 
 static void svm_check_processor_compat(void *rtn)
drivers/kvm/vmx.c +27 -3
index 4f115a8..a71564c 100644
@@ -164,6 +164,13 @@ static inline int is_no_device(u32 intr_info)
 		(INTR_TYPE_EXCEPTION | NM_VECTOR | INTR_INFO_VALID_MASK);
 }
 
+static inline int is_invalid_opcode(u32 intr_info)
+{
+	return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
+			     INTR_INFO_VALID_MASK)) ==
+		(INTR_TYPE_EXCEPTION | UD_VECTOR | INTR_INFO_VALID_MASK);
+}
+
 static inline int is_external_interrupt(u32 intr_info)
 {
 	return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK))
@@ -315,7 +322,7 @@ static void update_exception_bitmap(struct kvm_vcpu *vcpu)
 {
 	u32 eb;
 
-	eb = 1u << PF_VECTOR;
+	eb = (1u << PF_VECTOR) | (1u << UD_VECTOR);
 	if (!vcpu->fpu_active)
 		eb |= 1u << NM_VECTOR;
 	if (vcpu->guest_debug.enabled)
@@ -558,6 +565,15 @@ static void vmx_inject_gp(struct kvm_vcpu *vcpu, unsigned error_code)
 		     INTR_INFO_VALID_MASK);
 }
 
+static void vmx_inject_ud(struct kvm_vcpu *vcpu)
+{
+	vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
+		     GP_VECTOR |
+		     INTR_TYPE_EXCEPTION |
+		     INTR_INFO_DELIEVER_CODE_MASK |
+		     INTR_INFO_VALID_MASK);
+}
+
 /*
  * Swap MSR entry in host/guest MSR entry array.
  */
@@ -1770,6 +1786,14 @@ static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 		return 1;
 	}
 
+	if (is_invalid_opcode(intr_info)) {
+		er = emulate_instruction(vcpu, kvm_run, 0, 0);
+		if (er != EMULATE_DONE)
+			vmx_inject_ud(vcpu);
+
+		return 1;
+	}
+
 	error_code = 0;
 	rip = vmcs_readl(GUEST_RIP);
 	if (intr_info & INTR_INFO_DELIEVER_CODE_MASK)
@@ -1872,7 +1896,6 @@ vmx_patch_hypercall(struct kvm_vcpu *vcpu, unsigned char *hypercall)
 	hypercall[0] = 0x0f;
 	hypercall[1] = 0x01;
 	hypercall[2] = 0xc1;
-	hypercall[3] = 0xc3;
 }
 
 static int handle_cr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
@@ -2058,7 +2081,8 @@ static int handle_halt(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 static int handle_vmcall(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 {
 	skip_emulated_instruction(vcpu);
-	return kvm_hypercall(vcpu, kvm_run);
+	kvm_emulate_hypercall(vcpu);
+	return 1;
 }
 
 /*
drivers/kvm/x86_emulate.c +24 -6
index 18c2b2c..1362082 100644
@@ -1301,19 +1301,37 @@ twobyte_insn:
 			u16 size;
 			unsigned long address;
 
-		case 2: /* lgdt */
-			rc = read_descriptor(ctxt, ops, src.ptr,
-					     &size, &address, op_bytes);
+		case 0: /* vmcall */
+			if (modrm_mod != 3 || modrm_rm != 1)
+				goto cannot_emulate;
+
+			rc = kvm_fix_hypercall(ctxt->vcpu);
 			if (rc)
 				goto done;
-			realmode_lgdt(ctxt->vcpu, size, address);
+
+			kvm_emulate_hypercall(ctxt->vcpu);
 			break;
-		case 3: /* lidt */
+		case 2: /* lgdt */
 			rc = read_descriptor(ctxt, ops, src.ptr,
 					     &size, &address, op_bytes);
 			if (rc)
 				goto done;
-			realmode_lidt(ctxt->vcpu, size, address);
+			realmode_lgdt(ctxt->vcpu, size, address);
+			break;
+		case 3: /* lidt/vmmcall */
+			if (modrm_mod == 3 && modrm_rm == 1) {
+				rc = kvm_fix_hypercall(ctxt->vcpu);
+				if (rc)
+					goto done;
+				kvm_emulate_hypercall(ctxt->vcpu);
+			} else {
+				rc = read_descriptor(ctxt, ops, src.ptr,
+						     &size, &address,
+						     op_bytes);
+				if (rc)
+					goto done;
+				realmode_lidt(ctxt->vcpu, size, address);
+			}
 			break;
 		case 4: /* smsw */
 			if (modrm_mod != 3)
include/linux/kvm_para.h +85 -66

158 lines not on this page · raw message

A message that is not in the archive (sent off-list or not yet received): 11898788932902-git-send-email-aliguori-r/[email protected]

#2 lore raw

PATCH 1/1 Add the paravirtualization CPUID entry to QEMU (v2)

This adds a CPUID entry for the paravirtualization feature bitmap. We can do this unconditionally because the guest requires that both the feature CPUID entry and the signature CPUID entry exists to enable paravirtualization.

This means that guest will never enable paravirtualization if either userspace or kernelspace doesn't support paravirtualization.

qemu/qemu-kvm.c +6 -0
index 4843a74..395f8d3 100644
@@ -1113,12 +1113,18 @@ static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function,
 int kvm_qemu_init_env(CPUState *cenv)
 {
     struct kvm_cpuid_entry cpuid_ent[100];
+    struct kvm_cpuid_entry *pv_features;
     int cpuid_nent = 0;
     CPUState copy;
     uint32_t i, limit;
 
     copy = *cenv;
 
+    pv_features = &cpuid_ent[cpuid_nent++];
+    memset(pv_features, 0, sizeof(*pv_features));
+    pv_features->function = KVM_CPUID_FEATURES;
+    pv_features->eax = 0;
+
     copy.regs[R_EAX] = 0;
     qemu_kvm_cpuid_on_env(&copy);
     limit = copy.regs[R_EAX];
user/kvmctl.h +1 -0
index 109d81c..74db1ba 100644
@@ -10,6 +10,7 @@
 #endif
 
 #include <linux/kvm.h>
+#include <linux/kvm_para.h>
 #include <stdint.h>
 #include <signal.h>
 

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

#3 lore raw
In reply to Anthony Liguori
Quoted 26 lines · Anthony Liguori

This patch refactors the current hypercall infrastructure to better support live migration and SMP. It eliminates the hypercall page by trapping the UD exception that would occur if you used the wrong hypercall instruction for the underlying architecture and replacing it with the right one lazily.

It also introduces the infrastructure to probe for hypercall available via CPUID leaves 0x40001000. CPUID leaf 0x40001001 should be filled out by userspace.

A fall-out of this patch is that the unhandled hypercalls no longer trap to userspace. There is very little reason though to use a hypercall to communicate with userspace as PIO or MMIO can be used. There is no code in tree that uses userspace hypercalls.

Since the last patchset, I've changed the CPUID leaves to better avoid Xen's CPUID range and fixed a bug spotted by Muli in masking off hypercall arguments.

drivers/kvm/kvm_main.c +3 -0
@@ -1721,6 +1657,18 @@ void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
 	vcpu->regs[VCPU_REGS_RBX] = 0;
 	vcpu->regs[VCPU_REGS_RCX] = 0;
 	vcpu->regs[VCPU_REGS_RDX] = 0;
+
+	if (function == KVM_CPUID_SIGNATURE) {
+		u32 signature[3];

drivers/kvm/kvm_main.c void kvm_emulate_cpuid(struct kvm_vcpu *vcpu) · line 1672

Quoted 10 lines
drivers/kvm/kvm_main.c +9 -0
+
+		memcpy(signature, "LinuxPVLinux", 12);
+		vcpu->regs[VCPU_REGS_RAX] = 0;
+		vcpu->regs[VCPU_REGS_RBX] = signature[0];
+		vcpu->regs[VCPU_REGS_RCX] = signature[1];
+		vcpu->regs[VCPU_REGS_RDX] = signature[2];
+		goto out;
+	}
+
 

This needs to be done from userspace, so that kvm can pretend not to have this leaf.

(I have no objection to our userspace doing it unconditionally; but I don't want to force it on others)

Also, the signature string is too generic.

drivers/kvm/x86_emulate.c

Quoted 5 lines
drivers/kvm/x86_emulate.c +0 -0
index 18c2b2c..1362082 100644

Please split out the emulator changes.

Quoted 7 lines

- *
- * 64-bit parameters 1-6 are in the standard gcc x86_64 calling convention
- * order: RDI, RSI, RDX, RCX, R8, R9.
- *
- * 32-bit index is EBX, parameters are: EAX, ECX, EDX, ESI, EDI, EBP.
- * (the first 3 are according to the gcc regparm calling convention)

Please document the new ABI.

Signature · 7 lines
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
#4 lore raw
In reply to Anthony Liguori
Quoted 4 lines · Anthony Liguori

This patch refactors the current hypercall infrastructure to better support live migration and SMP. It eliminates the hypercall page by trapping the UD exception that would occur if you used the wrong hypercall instruction for the underlying architecture and replacing it with the right one lazily.

This doesn't work right for SVM. It keeps looping indefinitely; on a kvm_stat run, I get about 230,000 light vm exits per second, with the hypercall never returning to the guest.

...

Quoted 56 lines
drivers/kvm/svm.c +16 -3
index 729f1cd..d09a9f5 100644
@@ -476,7 +476,8 @@ static void init_vmcb(struct vmcb *vmcb)
 					INTERCEPT_DR5_MASK |
 					INTERCEPT_DR7_MASK;
 
-	control->intercept_exceptions = 1 << PF_VECTOR;
+	control->intercept_exceptions = (1 << PF_VECTOR) |
+					(1 << UD_VECTOR);
 
 
 	control->intercept = 	(1ULL << INTERCEPT_INTR) |
@@ -970,6 +971,17 @@ static int pf_interception(struct vcpu_svm *svm,
 struct kvm_run *kvm_run) return 0;
 }
 
+static int ud_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
+{
+	int er;
+
+	er = emulate_instruction(&svm->vcpu, kvm_run, 0, 0);
+	if (er != EMULATE_DONE)
+		inject_ud(&svm->vcpu);
+
+	return 1;
+}
+
 static int nm_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 {
 	svm->vmcb->control.intercept_exceptions &= ~(1 << NM_VECTOR);
@@ -1036,7 +1048,8 @@ static int vmmcall_interception(struct vcpu_svm *svm,
 struct kvm_run *kvm_run) {
 	svm->next_rip = svm->vmcb->save.rip + 3;
 	skip_emulated_instruction(&svm->vcpu);
-	return kvm_hypercall(&svm->vcpu, kvm_run);
+	kvm_emulate_hypercall(&svm->vcpu);
+	return 1;
 }
 
 static int invalid_op_interception(struct vcpu_svm *svm,
@@ -1232,6 +1245,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm
 *svm, [SVM_EXIT_WRITE_DR3]			= emulate_on_interception,
 	[SVM_EXIT_WRITE_DR5]			= emulate_on_interception,
 	[SVM_EXIT_WRITE_DR7]			= emulate_on_interception,
+	[SVM_EXIT_EXCP_BASE + UD_VECTOR]	= ud_interception,
 	[SVM_EXIT_EXCP_BASE + PF_VECTOR] 	= pf_interception,
 	[SVM_EXIT_EXCP_BASE + NM_VECTOR] 	= nm_interception,
 	[SVM_EXIT_INTR] 			= nop_on_interception,
@@ -1664,7 +1678,6 @@ svm_patch_hypercall(struct kvm_vcpu *vcpu, unsigned
 char *hypercall) hypercall[0] = 0x0f;
 	hypercall[1] = 0x01;
 	hypercall[2] = 0xd9;
-	hypercall[3] = 0xc3;
 }

...

drivers/kvm/svm.c

Quoted 4 lines

+/* This instruction is vmcall. On non-VT architectures, it will generate a + * trap that we will then rewrite to the appropriate instruction. */

drivers/kvm/svm.c +1 -1
-#define __NR_hypercalls			0
+#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"

.. which never happens.

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4

#5 lore raw
Quoted 10 lines · Amit Shah
Quoted 5 lines · Anthony Liguori

This patch refactors the current hypercall infrastructure to better support live migration and SMP. It eliminates the hypercall page by trapping the UD exception that would occur if you used the wrong hypercall instruction for the underlying architecture and replacing it with the right one lazily.

This doesn't work right for SVM. It keeps looping indefinitely; on a kvm_stat run, I get about 230,000 light vm exits per second, with the hypercall never returning to the guest.

I just tested kvm.git with (the new) hypercall.flat testcase. Seems to work fine.

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw
In reply to Amit Shah
Quoted 8 lines · Amit Shah
Quoted 5 lines · Anthony Liguori

This patch refactors the current hypercall infrastructure to better support live migration and SMP. It eliminates the hypercall page by trapping the UD exception that would occur if you used the wrong hypercall instruction for the underlying architecture and replacing it with the right one lazily.

Quoted 6 lines

This doesn't work right for SVM. It keeps looping indefinitely; on a kvm_stat run, I get about 230,000 light vm exits per second, with the hypercall never returning to the guest.

...

What are you using to issue the hypercall?

Regards,

Anthony Liguori

Quoted 61 lines
Quoted 57 lines
drivers/kvm/svm.c +16 -3
index 729f1cd..d09a9f5 100644
@@ -476,7 +476,8 @@ static void init_vmcb(struct vmcb *vmcb)
 					INTERCEPT_DR5_MASK |
 					INTERCEPT_DR7_MASK;
 
-	control->intercept_exceptions = 1 << PF_VECTOR;
+	control->intercept_exceptions = (1 << PF_VECTOR) |
+					(1 << UD_VECTOR);
 
 
 	control->intercept = 	(1ULL << INTERCEPT_INTR) |
@@ -970,6 +971,17 @@ static int pf_interception(struct vcpu_svm *svm,
 struct kvm_run *kvm_run) return 0;
 }
 
+static int ud_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
+{
+	int er;
+
+	er = emulate_instruction(&svm->vcpu, kvm_run, 0, 0);
+	if (er != EMULATE_DONE)
+		inject_ud(&svm->vcpu);
+
+	return 1;
+}
+
 static int nm_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 {
 	svm->vmcb->control.intercept_exceptions &= ~(1 << NM_VECTOR);
@@ -1036,7 +1048,8 @@ static int vmmcall_interception(struct vcpu_svm *svm,
 struct kvm_run *kvm_run) {
 	svm->next_rip = svm->vmcb->save.rip + 3;
 	skip_emulated_instruction(&svm->vcpu);
-	return kvm_hypercall(&svm->vcpu, kvm_run);
+	kvm_emulate_hypercall(&svm->vcpu);
+	return 1;
 }
 
 static int invalid_op_interception(struct vcpu_svm *svm,
@@ -1232,6 +1245,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm
 *svm, [SVM_EXIT_WRITE_DR3]			= emulate_on_interception,
 	[SVM_EXIT_WRITE_DR5]			= emulate_on_interception,
 	[SVM_EXIT_WRITE_DR7]			= emulate_on_interception,
+	[SVM_EXIT_EXCP_BASE + UD_VECTOR]	= ud_interception,
 	[SVM_EXIT_EXCP_BASE + PF_VECTOR] 	= pf_interception,
 	[SVM_EXIT_EXCP_BASE + NM_VECTOR] 	= nm_interception,
 	[SVM_EXIT_INTR] 			= nop_on_interception,
@@ -1664,7 +1678,6 @@ svm_patch_hypercall(struct kvm_vcpu *vcpu, unsigned
 char *hypercall) hypercall[0] = 0x0f;
 	hypercall[1] = 0x01;
 	hypercall[2] = 0xd9;
-	hypercall[3] = 0xc3;
 }
 

...

Quoted 8 lines

drivers/kvm/svm.c

Quoted 5 lines

+/* This instruction is vmcall. On non-VT architectures, it will generate a + * trap that we will then rewrite to the appropriate instruction. */

drivers/kvm/svm.c +1 -1
-#define __NR_hypercalls			0
+#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"

.. which never happens.

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4

#7 lore raw
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · Amit Shah

* Anthony Liguori wrote:

Quoted 5 lines

This patch refactors the current hypercall infrastructure to better support live migration and SMP.  It eliminates the hypercall page by trapping the UD exception that would occur if you used the wrong hypercall instruction for the underlying architecture and replacing it with the right one lazily.

Quoted 8 lines
Quoted 6 lines

This doesn't work right for SVM. It keeps looping indefinitely; on a kvm_stat run, I get about 230,000 light vm exits per second, with the hypercall never returning to the guest.

...

What are you using to issue the hypercall?

+ r = kvm_hypercall1(KVM_PV_PCI_DEVICE, page_gfn);

Setup is done by:

+ if (!kvm_para_available()) {

+               printk(KERN_ERR "KVM paravirt support not available\n");
+               r = -ENODEV;
+               goto out_dereg;

+ }

I also couldn't get the has_feature to work properly.

See:

http://lkml.org/lkml/2007/11/7/129

I had to change the hypercall address to 0f 01 d9 for it to get working.

Quoted 4 lines

Regards,

Anthony Liguori

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4

#8 lore raw
Quoted 29 lines · Amit Shah
Quoted 12 lines · Anthony Liguori
Quoted 10 lines · Amit Shah
Quoted 6 lines · Anthony Liguori

This patch refactors the current hypercall infrastructure to better support live migration and SMP. It eliminates the hypercall page by trapping the UD exception that would occur if you used the wrong hypercall instruction for the underlying architecture and replacing it with the right one lazily.

Quoted 9 lines
Quoted 7 lines

This doesn't work right for SVM. It keeps looping indefinitely; on a kvm_stat run, I get about 230,000 light vm exits per second, with the hypercall never returning to the guest.

...

What are you using to issue the hypercall?

+ r = kvm_hypercall1(KVM_PV_PCI_DEVICE, page_gfn);

Setup is done by:

Review

Quoted 5 lines
(quoted diff) +5 -0
+       if (!kvm_para_available()) {
+               printk(KERN_ERR "KVM paravirt support not available\n");
+               r = -ENODEV;
+               goto out_dereg;
+       }

There was a bug where instructions with a modrm byte specifying a register would try to access memory. In the memory was not mapped, emulation would fail. vmcall is one such instruction. This was fixed by

commit f83562246921d6a8a7de8b76853a6835ace3699d

Author: Aurelien Jarno <[email protected]>
Date:   Wed Oct 17 19:30:41 2007 +0200

KVM: x86 emulator: fix access registers for instructions with ModR/M
byte and Mod = 3

The patch belows changes the access type to register from memory for instructions that are declared as SrcMem or DstMem, but have a ModR/M byte with Mod = 3.

It fixes (at least) the lmsw and smsw instructions on an AMD64 CPU, which are needed for FreeBSD.

drivers/kvm/x86_emulate.c +8 -0
index 7c95ae5..8c50496 100644
@@ -835,6 +835,14 @@ modrm_done:
               if (c->twobyte && c->b == 0x01
                                   && c->modrm_reg == 7)
                       break;
+               /*
+                * For instructions with a ModR/M byte, switch to register
+                * access if Mod = 3.
+                */
+               if ((c->d & ModRM) && c->modrm_mod == 3) {
+                       c->src.type = OP_REG;
+                       break;
+               }

srcmem_common:

               c->src.type = OP_MEM;
               break;
@@ -897,7 +905,14 @@ srcmem_common:
               }
               break;
       case DstMem:
-               c->dst.type = OP_MEM;
+               /*
+                * For instructions with a ModR/M byte, switch to register
+                * access if Mod = 3.
+                */
+               if ((c->d & ModRM) && c->modrm_mod == 3)
+                       c->dst.type = OP_REG;
+               else
+                       c->dst.type = OP_MEM;
               break;
       }
Signature · 1 line
error compiling committee.c: too many arguments to function
#9 lore raw
Quoted 25 lines · Avi Kivity
Quoted 11 lines · Amit Shah

* Anthony Liguori wrote:

Quoted 5 lines

Amit Shah wrote:

What are you using to issue the hypercall?

+       r = kvm_hypercall1(KVM_PV_PCI_DEVICE, page_gfn);

Quoted 8 lines

Setup is done by:

+       if (!kvm_para_available()) {
+               printk(KERN_ERR "KVM paravirt support not available\n");
+               r = -ENODEV;
+               goto out_dereg;
+       }

There was a bug where instructions with a modrm byte specifying a register would try to access memory.  In the memory was not mapped, emulation would fail. vmcall is one such instruction.  This was fixed by

Quoted 6 lines

commit f83562246921d6a8a7de8b76853a6835ace3699d
Author: Aurelien Jarno <[email protected]>
Date:   Wed Oct 17 19:30:41 2007 +0200

    KVM: x86 emulator: fix access registers for instructions with ModR/M byte and Mod = 3

Thanks, and thank you, Aurelien!

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4