public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lapic3: various cleanups on user/kernel irqchip
@ 2007-08-10  6:17 He, Qing
       [not found] ` <37E52D09333DE2469A03574C88DBF40FA9C1C0-wq7ZOvIWXbM/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: He, Qing @ 2007-08-10  6:17 UTC (permalink / raw)
  To: kvm-devel

[-- Attachment #1: Type: text/plain, Size: 2048 bytes --]

KVM: cleanups on user/kernel irqchip checking

The patch removes the union of userspace irq_pending and kernel apic in
struct vcpu, which minimizes the impact of careless overwriting and
avoids accidentally dereferencing invalid apic pointer.

It also adds a protective checking on KVM_INTERRUPT ioctl, which should
only be valid when using userspace irqchips.

Signed-off-by: Qing He <qing.he-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

---

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 87ddf73..f3f2222 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -322,19 +322,17 @@ struct kvm_vcpu {
 	u64 pdptrs[4]; /* pae */
 	u64 apic_base;
 	u64 shadow_efer;
-	union {
-		struct {	/* user irqchip context */
-		       /*
-			* bit vector: 1 per word in irq_pending
-			*/
-			unsigned long irq_summary;
-			DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
-			unsigned long cr8;
-		};
-		struct {	/* kernel irqchip context */
-			struct kvm_lapic *apic;
-		};
+
+	struct {    /* user irqchip context */
+		/*
+		 * bit vector: 1 per word in irq_pending
+		 */
+		unsigned long irq_summary;
+		DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
+		unsigned long cr8;
 	};
+	struct kvm_lapic *apic;    /* kernel irqchip context */
+
 	u64 ia32_misc_enable_msr;
 
 	struct kvm_mmu mmu;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 88b0b89..fd9436e 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1079,7 +1079,7 @@ static struct kvm_io_device
*vcpu_find_pervcpu_dev(struct kvm_vcpu *vcpu,
 {
 	struct kvm_io_device *dev;
 
-	if (irqchip_in_kernel(vcpu->kvm) && vcpu->apic) {
+	if (vcpu->apic) {
 		dev = &vcpu->apic->dev;
 		if (dev->in_range(dev, addr))
 			return dev;
@@ -2394,6 +2394,8 @@ static int kvm_vcpu_ioctl_interrupt(struct
kvm_vcpu *vcpu,
 {
 	if (irq->irq < 0 || irq->irq >= 256)
 		return -EINVAL;
+	if (irqchip_in_kernel(vcpu->kvm))
+		return -ENXIO;
 	vcpu_load(vcpu);
 
 	set_bit(irq->irq, vcpu->irq_pending);

[-- Attachment #2: apic-kern-user-cleanup.diff --]
[-- Type: application/octet-stream, Size: 1536 bytes --]

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 87ddf73..f3f2222 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -322,19 +322,17 @@ struct kvm_vcpu {
 	u64 pdptrs[4]; /* pae */
 	u64 apic_base;
 	u64 shadow_efer;
-	union {
-		struct {	/* user irqchip context */
-		       /*
-			* bit vector: 1 per word in irq_pending
-			*/
-			unsigned long irq_summary;
-			DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
-			unsigned long cr8;
-		};
-		struct {	/* kernel irqchip context */
-			struct kvm_lapic *apic;
-		};
+
+	struct {    /* user irqchip context */
+		/*
+		 * bit vector: 1 per word in irq_pending
+		 */
+		unsigned long irq_summary;
+		DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
+		unsigned long cr8;
 	};
+	struct kvm_lapic *apic;    /* kernel irqchip context */
+
 	u64 ia32_misc_enable_msr;
 
 	struct kvm_mmu mmu;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 88b0b89..fd9436e 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1079,7 +1079,7 @@ static struct kvm_io_device *vcpu_find_pervcpu_dev(struct kvm_vcpu *vcpu,
 {
 	struct kvm_io_device *dev;
 
-	if (irqchip_in_kernel(vcpu->kvm) && vcpu->apic) {
+	if (vcpu->apic) {
 		dev = &vcpu->apic->dev;
 		if (dev->in_range(dev, addr))
 			return dev;
@@ -2394,6 +2394,8 @@ static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
 {
 	if (irq->irq < 0 || irq->irq >= 256)
 		return -EINVAL;
+	if (irqchip_in_kernel(vcpu->kvm))
+		return -ENXIO;
 	vcpu_load(vcpu);
 
 	set_bit(irq->irq, vcpu->irq_pending);

[-- Attachment #3: Type: text/plain, Size: 315 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

[-- Attachment #4: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-08-13 11:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-10  6:17 [PATCH] lapic3: various cleanups on user/kernel irqchip He, Qing
     [not found] ` <37E52D09333DE2469A03574C88DBF40FA9C1C0-wq7ZOvIWXbM/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-08-10 15:33   ` clean APIC_TMCCT setting in APIC timer Dong, Eddie
     [not found]     ` <10EA09EFD8728347A513008B6B0DA77A01E8DA90-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-08-10 15:34       ` Dong, Eddie
2007-08-13 11:25       ` Avi Kivity
2007-08-10 15:36   ` modify apic timer last_update to precisely reflect hrtimer fire point Dong, Eddie
     [not found]     ` <10EA09EFD8728347A513008B6B0DA77A01E8DA92-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-08-13 11:22       ` Avi Kivity
2007-08-13  7:55   ` [PATCH] lapic3: various cleanups on user/kernel irqchip Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox