Skip to contentSkip to conversation

nmi watchdog in kvm

RFC In review Balaji Rao 4 participants 11 messages Jan 28, 2008 – Jan 30, 2008 8 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Balaji Rao

author
#0 lore raw

RFC 1/1 nmi watchdog in kvm

Hello,

I was trying to enable the use of nmi watchdog within a linux guest running in kvm. I have done it by allowing direct access to perfmon msrs using the MSR_BITMAP field in vmcs region.

Most of the times the NMI Watchdog Test in the guest fails, but with a finite number of NMI's received by the guest. But randomly it does work! Whenever it fails, i get this vmwrite error :

vmwrite error: reg 4016 value 80000202 (err 164061)

I have a few questions.

1. How are NMI's supposed to be delivered to the guest ? I did this by adding a new op to kvm_x86_ops.
2. How am I supposed to handle perfmon MSRs ? Direct access may pose problems during migration. But am not sure how costly emulation by abstraction would be..
I have not yet considered saving the MSRS upon vmexits to allow multiple VMs use the MSRs. I think i can do them easily when i get this working.

Here's the code. Please tell me what dumb mistake I am doing.

arch/x86/kernel/cpu/perfctr-watchdog.c +1 -1
index c02541e..276048a 100644
@@ -342,7 +342,7 @@ static const struct wd_ops k7_wd_ops = {
 #define P6_EVNTSEL_INT		(1 << 20)
 #define P6_EVNTSEL_OS		(1 << 17)
 #define P6_EVNTSEL_USR		(1 << 16)
-#define P6_EVENT_CPU_CLOCKS_NOT_HALTED	0x79
+#define P6_EVENT_CPU_CLOCKS_NOT_HALTED	0x3C
 #define P6_NMI_EVENT		P6_EVENT_CPU_CLOCKS_NOT_HALTED
 
 static int setup_p6_watchdog(unsigned nmi_hz)
arch/x86/kvm/lapic.c +20 -1
index 2cbee94..73e9361 100644
@@ -25,6 +25,8 @@
 #include <linux/hrtimer.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/kdebug.h>
+#include <linux/notifier.h>
 #include <asm/processor.h>
 #include <asm/msr.h>
 #include <asm/page.h>
@@ -740,9 +742,12 @@ static void apic_mmio_write(struct kvm_io_device *this,
 		apic_set_reg(apic, APIC_ICR2, val & 0xff000000);
 		break;
 
+	case APIC_LVTPC:
+		/* Enable PC NMI*/
+		if (val == APIC_DM_NMI)
+			apic_write(APIC_LVTPC,val);
 	case APIC_LVTT:
 	case APIC_LVTTHMR:
-	case APIC_LVTPC:
 	case APIC_LVT0:
 	case APIC_LVT1:
 	case APIC_LVTERR:
@@ -790,6 +795,18 @@ static int apic_mmio_range(struct kvm_io_device *this, gpa_t addr)
 	return ret;
 }
 
+static int nmi_notify(struct notifier_block *self,unsigned long val, void *data) {
+
+        struct kvm *kvm;
+        kvm  = list_entry(vm_list.next, struct kvm, vm_list);
+	kvm_x86_ops->inject_nmi(kvm->vcpus[0]);
+        return NOTIFY_STOP;
+}
+
+static struct notifier_block nmi_notifier = {
+                .notifier_call = nmi_notify,
+};
+
 void kvm_free_lapic(struct kvm_vcpu *vcpu)
 {
 	if (!vcpu->arch.apic)
@@ -801,6 +818,7 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu)
 		__free_page(vcpu->arch.apic->regs_page);
 
 	kfree(vcpu->arch.apic);
+	unregister_die_notifier(&nmi_notifier);
 }
 
 /*
@@ -1005,6 +1023,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
 	apic->dev.in_range = apic_mmio_range;
 	apic->dev.private = apic;
 
+	register_die_notifier(&nmi_notifier);
 	return 0;
 nomem_free_apic:
 	kfree(apic);
arch/x86/kvm/vmx.c +33 -3
index 00a00e4..fcffab1 100644
@@ -89,6 +89,7 @@ static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
 
 static struct page *vmx_io_bitmap_a;
 static struct page *vmx_io_bitmap_b;
+static struct page *vmx_msr_bitmap;
 
 static DECLARE_BITMAP(vmx_vpid_bitmap, VMX_NR_VPIDS);
 static DEFINE_SPINLOCK(vmx_vpid_lock);
@@ -982,7 +983,7 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
 	u32 _vmexit_control = 0;
 	u32 _vmentry_control = 0;
 
-	min = PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING;
+	min = PIN_BASED_EXT_INTR_MASK;
 	opt = 0;
 	if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PINBASED_CTLS,
 				&_pin_based_exec_control) < 0)
@@ -994,8 +995,10 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
 	      CPU_BASED_CR8_STORE_EXITING |
 #endif
 	      CPU_BASED_USE_IO_BITMAPS |
+	      CPU_BASED_USE_MSR_BITMAPS |
 	      CPU_BASED_MOV_DR_EXITING |
 	      CPU_BASED_USE_TSC_OFFSETING;
+
 	opt = CPU_BASED_TPR_SHADOW |
 	      CPU_BASED_ACTIVATE_SECONDARY_CONTROLS;
 	if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PROCBASED_CTLS,
@@ -1568,6 +1571,9 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
 	vmcs_write64(IO_BITMAP_A, page_to_phys(vmx_io_bitmap_a));
 	vmcs_write64(IO_BITMAP_B, page_to_phys(vmx_io_bitmap_b));
 
+	/* MSR BITMAP */
+	vmcs_write64(MSR_BITMAP, page_to_phys(vmx_msr_bitmap));
+
 	vmcs_write64(VMCS_LINK_POINTER, -1ull); /* 22.3.1.5 */
 
 	/* Control */
@@ -1786,6 +1792,14 @@ out:
 	return ret;
 }
 
+static void vmx_inject_nmi(struct kvm_vcpu *vcpu) {
+
+	struct vcpu_vmx * vmx = to_vmx(vcpu);
+		if (vmx->launched)
+		vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
+			2 | INTR_TYPE_NMI | INTR_INFO_VALID_MASK);
+}
+
 static void vmx_inject_irq(struct kvm_vcpu *vcpu, int irq)
 {
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -2686,6 +2700,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
 	.exception_injected = vmx_exception_injected,
 	.inject_pending_irq = vmx_intr_assist,
 	.inject_pending_vectors = do_interrupt_requests,
+	.inject_nmi = vmx_inject_nmi,
 
 	.set_tss_addr = vmx_set_tss_addr,
 };
@@ -2700,7 +2715,11 @@ static int __init vmx_init(void)
 		return -ENOMEM;
 
 	vmx_io_bitmap_b = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
-	if (!vmx_io_bitmap_b) {
+	if (!vmx_io_bitmap_b)
+		r = -ENOMEM;
+
+	vmx_msr_bitmap = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
+	if (!vmx_msr_bitmap) {
 		r = -ENOMEM;
 		goto out;
 	}
@@ -2718,6 +2737,15 @@ static int __init vmx_init(void)
 	memset(iova, 0xff, PAGE_SIZE);
 	kunmap(vmx_io_bitmap_b);
 
+	iova = kmap(vmx_msr_bitmap);
+	memset(iova, 0xff, PAGE_SIZE);
+	/* Enable direct access to first perfmon MSR */
+	clear_bit(MSR_P6_PERFCTR0, iova);
+	clear_bit(MSR_P6_EVNTSEL0, iova);
+	clear_bit(MSR_P6_PERFCTR0, iova + 2048);
+	clear_bit(MSR_P6_EVNTSEL0, iova + 2048);
+	kunmap(vmx_msr_bitmap);
+
 	set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */
 
 	r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), THIS_MODULE);
@@ -2730,8 +2758,9 @@ static int __init vmx_init(void)
 	return 0;
 
 out1:
-	__free_page(vmx_io_bitmap_b);
+	__free_page(vmx_msr_bitmap);
 out:
+	__free_page(vmx_io_bitmap_b);
 	__free_page(vmx_io_bitmap_a);
 	return r;
 }
@@ -2740,6 +2769,7 @@ static void __exit vmx_exit(void)
 {
 	__free_page(vmx_io_bitmap_b);
 	__free_page(vmx_io_bitmap_a);
+	__free_page(vmx_msr_bitmap);
 
 	kvm_exit();
 }
arch/x86/kvm/vmx.h +1 -0
index 436ce0f..1b6d6a8 100644
@@ -242,6 +242,7 @@ enum vmcs_field {
 #define VECTORING_INFO_VALID_MASK       	INTR_INFO_VALID_MASK
 
 #define INTR_TYPE_EXT_INTR              (0 << 8) /* external interrupt */
+#define INTR_TYPE_NMI			(2 << 8)
 #define INTR_TYPE_EXCEPTION             (3 << 8) /* processor exception */
 #define INTR_TYPE_SOFT_INTR             (4 << 8) /* software interrupt */
 
include/asm-x86/kvm_host.h +1 -0
index 67ae307..f17248d 100644
@@ -387,6 +387,7 @@ struct kvm_x86_ops {
 	void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr,
 				bool has_error_code, u32 error_code);
 	bool (*exception_injected)(struct kvm_vcpu *vcpu);
+	void (*inject_nmi)(struct kvm_vcpu *vcpu);
 	void (*inject_pending_irq)(struct kvm_vcpu *vcpu);
 	void (*inject_pending_vectors)(struct kvm_vcpu *vcpu,
 				       struct kvm_run *run);

---

thanks,
balaji rao

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

#2 lore raw
In reply to a message not in the archive
Quoted 3 lines · Balaji Rao

I was trying to enable the use of nmi watchdog within a linux guest running in kvm. I have done it by allowing direct access to perfmon msrs using the MSR_BITMAP field in vmcs region.

your patch looks pretty clean and simple to me - and it would make quite a bit of sense from the "completeness of architecture" POV to inject NMIs into KVM - even though it's obviously not that hard to interrupt a KVM guest context via other means ;-)

at the least this would test the correctness of guest kernel NMI handling. We could even test things by injecting a very large stream of NMIs, which is not that easy on native hardware, etc.

( the emulation of "NMI reason" IO port could be accelerated too
perhaps, instead of passing it over to qemu. )

so it's a good idea IMO.

Ingo

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

#3 lore raw
In reply to a message not in the archive
Quoted 4 lines · Balaji Rao

Hello,

I was trying to enable the use of nmi watchdog within a linux guest running in kvm. I have done it by allowing direct access to perfmon msrs using the MSR_BITMAP field in vmcs region.

Is there a proper virtualization of the performance counter MSRs on Intel? If not this patch will destroy any host side performance monitoring.

Quoted 5 lines

Most of the times the NMI Watchdog Test in the guest fails, but with a finite number of NMI's received by the guest. But randomly it does work! Whenever it fails, i get this vmwrite error :

vmwrite error: reg 4016 value 80000202 (err 164061)

Quoted 8 lines

I have a few questions.

1. How are NMI's supposed to be delivered to the guest ? I did this by adding a new op to kvm_x86_ops.
2. How am I supposed to handle perfmon MSRs ? Direct access may pose problems during migration. But am not sure how costly emulation by abstraction would be..
I have not yet considered saving the MSRS upon vmexits to allow multiple VMs use the MSRs. I think i can do them easily when i get this working.

This patch kills the ability of KVM to migrate between AMD and Intel because the Intel performance counters are not available on AMD and vice verca.

include/asm-x86/kvm_host.h struct kvm_x86_ops { · line 390

Quoted 9 lines
include/asm-x86/kvm_host.h +1 -0
index 67ae307..f17248d 100644
@@ -387,6 +387,7 @@ struct kvm_x86_ops {
 	void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr,
 				bool has_error_code, u32 error_code);
 	bool (*exception_injected)(struct kvm_vcpu *vcpu);
+	void (*inject_nmi)(struct kvm_vcpu *vcpu);

The implementation of this new callback for SVM is missing.

Quoted 4 lines
include/asm-x86/kvm_host.h +0 -1
 	void (*inject_pending_irq)(struct kvm_vcpu *vcpu);
 	void (*inject_pending_vectors)(struct kvm_vcpu *vcpu,
 				       struct kvm_run *run);
---
Signature · 13 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
author
#5 lore raw
In reply to a message not in the archive
Quoted 11 lines · Joerg Roedel
Quoted 5 lines · Balaji Rao

Hello,

I was trying to enable the use of nmi watchdog within a linux guest running in kvm. I have done it by allowing direct access to perfmon msrs using the MSR_BITMAP field in vmcs region.

Is there a proper virtualization of the performance counter MSRs on Intel? If not this patch will destroy any host side performance monitoring.

No. It has to be handled by the VMM. I shall do this in a later patch. This is just a quick and dirty attempt to solve this problem.

<snip>

Quoted 4 lines

This patch kills the ability of KVM to migrate between AMD and Intel because the Intel performance counters are not available on AMD and vice verca.

Yes. The way we should solve this is by emulating the MSRs. Am not sure about the overhead involved. What are your thoughts on this ?

Quoted 11 lines

include/asm-x86/kvm_host.h struct kvm_x86_ops { · line 390

Quoted 9 lines
include/asm-x86/kvm_host.h +1 -0
index 67ae307..f17248d 100644
@@ -387,6 +387,7 @@ struct kvm_x86_ops {
 	void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr,
 				bool has_error_code, u32 error_code);
 	bool (*exception_injected)(struct kvm_vcpu *vcpu);
+	void (*inject_nmi)(struct kvm_vcpu *vcpu);

The implementation of this new callback for SVM is missing.

I just wanted to get it running on my hardware first! :) Will implement it for SVM once I get the approach right.

Quoted 5 lines

include/asm-x86/kvm_host.h struct kvm_x86_ops {

Quoted 5 lines
include/asm-x86/kvm_host.h +0 -1
 	void (*inject_pending_irq)(struct kvm_vcpu *vcpu);
 	void (*inject_pending_vectors)(struct kvm_vcpu *vcpu,
 				       struct kvm_run *run);
---

thank you for the comments,

regards,
balaji rao

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

#7 lore raw
In reply to a message not in the archive
Quoted 7 lines · Balaji Rao
Quoted 4 lines · Joerg Roedel

This patch kills the ability of KVM to migrate between AMD and Intel because the Intel performance counters are not available on AMD and vice verca.

Yes. The way we should solve this is by emulating the MSRs. Am not sure about the overhead involved. What are your thoughts on this ?

I think you can't do this with performance counters in KVM (except you emulate the Intel PerfCtrs on AMD and the AMD PerfCtrs on Intel, which might not be possible, at least very painfull). I think the best solution to implement a watchdog for KVM is to implement another NMI source, e.g. emulating a watchdog PCI card in QEMU.

Quoted 26 lines
Quoted 11 lines

include/asm-x86/kvm_host.h struct kvm_x86_ops { · line 390

Quoted 9 lines
include/asm-x86/kvm_host.h +1 -0
index 67ae307..f17248d 100644
@@ -387,6 +387,7 @@ struct kvm_x86_ops {
 	void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr,
 				bool has_error_code, u32 error_code);
 	bool (*exception_injected)(struct kvm_vcpu *vcpu);
+	void (*inject_nmi)(struct kvm_vcpu *vcpu);

The implementation of this new callback for SVM is missing.

I just wanted to get it running on my hardware first! :) Will implement it for SVM once I get the approach right.

Quoted 5 lines

include/asm-x86/kvm_host.h struct kvm_x86_ops {

Quoted 5 lines
include/asm-x86/kvm_host.h +0 -1
 	void (*inject_pending_irq)(struct kvm_vcpu *vcpu);
 	void (*inject_pending_vectors)(struct kvm_vcpu *vcpu,
 				       struct kvm_run *run);
---

thank you for the comments,

regards,
balaji rao

Signature · 13 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
author
#9 lore raw
In reply to a message not in the archive
Quoted 6 lines · Joerg Roedel
Quoted 5 lines · Balaji Rao
Quoted 3 lines · Joerg Roedel

This patch kills the ability of KVM to migrate between AMD and Intel because the Intel performance counters are not available on AMD and vice verca.

Quoted 9 lines
Quoted 2 lines

Yes. The way we should solve this is by emulating the MSRs. Am not sure about the overhead involved. What are your thoughts on this ?

I think you can't do this with performance counters in KVM (except you emulate the Intel PerfCtrs on AMD and the AMD PerfCtrs on Intel, which might not be possible, at least very painfull). I think the best solution to implement a watchdog for KVM is to implement another NMI source, e.g. emulating a watchdog PCI card in QEMU.

Yes, it would be painful to emulate non native perform counters..

But having a PCI device for generating NMIs would solve the problem of NMI Watchdogs. But we still wouldn't be able to provide perfmon counters to the guest.. But before that, we need to decide whether it is needed to provide perfmon counters to the guest or not.

To make the guest use QEmu's PCI we need to pass another kernel param (say, nmi_watchdog=3) which is not very nice.So, can't we implement NMI watchdog using paravirt ?

Or the other option would be to probe for the NMI Watchdog PCI card before trying to use other means of generating NMIs..

Could anyone please point me to any docs on writing a QEmu PCI device driver ?

regards,
balaji rao

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

#10 lore raw
In reply to a message not in the archive
Quoted 8 lines · Balaji Rao

Hello,

I was trying to enable the use of nmi watchdog within a linux guest running in kvm. I have done it by allowing direct access to perfmon msrs using the MSR_BITMAP field in vmcs region.

Most of the times the NMI Watchdog Test in the guest fails, but with a finite number of NMI's received by the guest. But randomly it does work! Whenever it fails, i get this vmwrite error :

Quoted 7 lines

vmwrite error: reg 4016 value 80000202 (err 164061)

I have a few questions.

1. How are NMI's supposed to be delivered to the guest ? I did this by adding a new op to kvm_x86_ops.

That's fine. ops are there to be extended.

Quoted 5 lines

2. How am I supposed to handle perfmon MSRs ? Direct access may pose problems during migration. But am not sure how costly emulation by abstraction would be..
I have not yet considered saving the MSRS upon vmexits to allow multiple VMs use the MSRs. I think i can do them easily when i get this working.

I don't think there's a sane way to emulate the non-architectural perfmon counters. It may be possible to do so for the architectural ones, but I'm not sure. So pass-through (with saving and restoring) is the only option.

Quoted 8 lines

Here's the code. Please tell me what dumb mistake I am doing.

arch/x86/kernel/cpu/perfctr-watchdog.c +0 -0
index c02541e..276048a 100644

arch/x86/kernel/cpu/perfctr-watchdog.c static const struct wd_ops k7_wd_ops = { · line 347

Quoted 7 lines
arch/x86/kernel/cpu/perfctr-watchdog.c +1 -1
@@ -342,7 +342,7 @@ static const struct wd_ops k7_wd_ops = {
 #define P6_EVNTSEL_INT		(1 << 20)
 #define P6_EVNTSEL_OS		(1 << 17)
 #define P6_EVNTSEL_USR		(1 << 16)
-#define P6_EVENT_CPU_CLOCKS_NOT_HALTED	0x79
+#define P6_EVENT_CPU_CLOCKS_NOT_HALTED	0x3C
 #define P6_NMI_EVENT		P6_EVENT_CPU_CLOCKS_NOT_HALTED
 

What's this?

Quoted 16 lines
arch/x86/kernel/cpu/perfctr-watchdog.c +0 -0
 static int setup_p6_watchdog(unsigned nmi_hz)
arch/x86/kvm/lapic.c +2 -0
index 2cbee94..73e9361 100644
@@ -25,6 +25,8 @@
 #include <linux/hrtimer.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/kdebug.h>
+#include <linux/notifier.h>
 #include <asm/processor.h>
 #include <asm/msr.h>
 #include <asm/page.h>

arch/x86/kvm/lapic.c static void apic_mmio_write(struct kvm_io_device *this, · line 749

Quoted 8 lines
arch/x86/kvm/lapic.c +4 -0
@@ -740,9 +742,12 @@ static void apic_mmio_write(struct kvm_io_device *this,
 		apic_set_reg(apic, APIC_ICR2, val & 0xff000000);
 		break;
 
+	case APIC_LVTPC:
+		/* Enable PC NMI*/
+		if (val == APIC_DM_NMI)
+			apic_write(APIC_LVTPC,val);
 

You're writing to the precious host apic here.

- need to disallow if the host is using it
- need to prevent illegal values
- need to use some sort of perfmon api rather than directly banging on the apic

arch/x86/kvm/lapic.c static int apic_mmio_range(struct kvm_io_device *this, gpa_t addr) · line 805

Quoted 12 lines
arch/x86/kvm/lapic.c +7 -0
@@ -790,6 +795,18 @@ static int apic_mmio_range(struct kvm_io_device *this, gpa_t addr)
 	return ret;
 }
 
+static int nmi_notify(struct notifier_block *self,unsigned long val, void *data) {
+
+        struct kvm *kvm;
+        kvm  = list_entry(vm_list.next, struct kvm, vm_list);
+	kvm_x86_ops->inject_nmi(kvm->vcpus[0]);
+        return NOTIFY_STOP;
+}
 

You're not guaranteed to be in vcpu context here, that's what's causing the vmwrite errors.

Enabling on guest entry and disabling on guest exit is critical, both for accuracy and correctness.

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 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
author
#12 lore raw
In reply to a message not in the archive
Quoted 4 lines · Avi Kivity
Quoted 4 lines
(quoted diff) +0 -0
@@ -790,6 +795,18 @@ static int apic_mmio_range(struct kvm_io_device
 *this, gpa_t addr) return ret;
 }
 
Quoted 11 lines

arch/x86/kvm/lapic.c static int apic_mmio_range(struct kvm_io_device *this, gpa_t addr) · line 804

Quoted 7 lines
(quoted diff) +1 -0
+static int nmi_notify(struct notifier_block *self,unsigned long val,

void *data) { +

arch/x86/kvm/lapic.c +5 -0
+        struct kvm *kvm;
+        kvm  = list_entry(vm_list.next, struct kvm, vm_list);
+	kvm_x86_ops->inject_nmi(kvm->vcpus[0]);
+        return NOTIFY_STOP;
+}

You're not guaranteed to be in vcpu context here, that's what's causing the vmwrite errors.

I intended to do this here. Looks like its not the right way to check for presence in vcpu context. How do i do it ? please explain.

+static void vmx_inject_nmi(struct kvm_vcpu *vcpu) {
+
+       struct vcpu_vmx * vmx = to_vmx(vcpu);
+               if (vmx->launched)
+               vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, +                       2 | INTR_TYPE_NMI | INTR_INFO_VALID_MASK); +}

regards,
balaji rao

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

#14 lore raw
In reply to a message not in the archive
Quoted 23 lines · Balaji Rao
Quoted 4 lines · Avi Kivity
Quoted 4 lines
(quoted diff) +0 -0
@@ -790,6 +795,18 @@ static int apic_mmio_range(struct kvm_io_device
 *this, gpa_t addr) return ret;
 }
 
Quoted 12 lines

arch/x86/kvm/lapic.c static int apic_mmio_range(struct kvm_io_device *this, gpa_t addr) · line 804

Quoted 8 lines
(quoted diff) +1 -0
+static int nmi_notify(struct notifier_block *self,unsigned long val,

void *data) { +

arch/x86/kvm/lapic.c +5 -0
+        struct kvm *kvm;
+        kvm  = list_entry(vm_list.next, struct kvm, vm_list);
+	kvm_x86_ops->inject_nmi(kvm->vcpus[0]);
+        return NOTIFY_STOP;
+}

You're not guaranteed to be in vcpu context here, that's what's causing the vmwrite errors.

I intended to do this here. Looks like its not the right way to check for presence in vcpu context. How do i do it ? please explain.

arch/x86/kvm/vmx.c out: · line 1801

Quoted 7 lines
arch/x86/kvm/vmx.c +7 -0
+static void vmx_inject_nmi(struct kvm_vcpu *vcpu) {
+
+       struct vcpu_vmx * vmx = to_vmx(vcpu);
+               if (vmx->launched)
+               vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
+                       2 | INTR_TYPE_NMI | INTR_INFO_VALID_MASK);
+}

No, this is the wrong place. If you have a vcpu, you'd better be in vcpu context.

The way to do it is to set a bit in vcpu->requests and force an IPI to vcpu->cpu. You can look at kvm_flush_remote_tlbs() for an example (another example is in the lapic IPI code, actually a better one since it also wakes the cpu up if it is in hlt state).

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 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
author
#16 lore raw
In reply to a message not in the archive
Quoted 4 lines · Avi Kivity
Quoted 4 lines

I intended to do this here. Looks like its not the right way to check for presence in vcpu context. How do i do it ? please explain.

Quoted 10 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+static void vmx_inject_nmi(struct kvm_vcpu *vcpu) {
+
+       struct vcpu_vmx * vmx = to_vmx(vcpu);
+               if (vmx->launched)
+               vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
+                       2 | INTR_TYPE_NMI | INTR_INFO_VALID_MASK);
+}

No, this is the wrong place. If you have a vcpu, you'd better be in vcpu context.

Oh.. ok. Looks like I have not understood the vcpu concept correctly. Will put more thought into it and understand it before I attempt to fix this.

thank you,
balaji rao

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

#18 lore raw
In reply to a message not in the archive
Quoted 16 lines · Balaji Rao
Quoted 14 lines · Avi Kivity

Review

Quoted 11 lines

I intended to do this here. Looks like its not the right way to check for presence in vcpu context. How do i do it ? please explain.

(quoted diff) +7 -0
+static void vmx_inject_nmi(struct kvm_vcpu *vcpu) {
+
+       struct vcpu_vmx * vmx = to_vmx(vcpu);
+               if (vmx->launched)
+               vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
+                       2 | INTR_TYPE_NMI | INTR_INFO_VALID_MASK);
+}

No, this is the wrong place. If you have a vcpu, you'd better be in vcpu context.

Quoted 4 lines

Oh.. ok. Looks like I have not understood the vcpu concept correctly. Will put more thought into it and understand it before I attempt to fix this.

To be clear, vcpu context is the time between vcpu_load() and vcpu_put(), holding vcpu->mutex.

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 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/