public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] fixups for pci passthrough
@ 2008-03-26 21:09 Glauber Costa
  2008-03-26 21:09 ` [PATCH 1/3] [PATCH] passthrough Glauber Costa
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Glauber Costa @ 2008-03-26 21:09 UTC (permalink / raw)
  To: kvm-devel; +Cc: avi

Amit,

those fixups apply ontop of your kvm-userspace tree.
They are general small fixups for the whole thing

thanks



-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

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

* [PATCH 1/3] [PATCH] passthrough
  2008-03-26 21:09 [PATCH 0/3] fixups for pci passthrough Glauber Costa
@ 2008-03-26 21:09 ` Glauber Costa
  2008-03-27  7:49   ` Avi Kivity
  2008-03-26 21:09 ` [PATCH 2/3] [PATCH] unregister pci device Glauber Costa
  2008-03-26 21:09 ` [PATCH 3/3] [PATCH] remove warnings Glauber Costa
  2 siblings, 1 reply; 8+ messages in thread
From: Glauber Costa @ 2008-03-26 21:09 UTC (permalink / raw)
  To: kvm-devel; +Cc: avi

add -passthrough usage string

Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
 qemu/vl.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/qemu/vl.c b/qemu/vl.c
index f5b2665..d36cfe3 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -8053,6 +8053,7 @@ #ifdef USE_KVM
 #ifndef NO_CPU_EMULATION
 	   "-no-kvm         disable KVM hardware virtualization\n"
 #endif
+	   "-passthrough name/bus:dev.func-intr expose a pci device to the guest OS \n"
 	   "-no-kvm-irqchip disable KVM kernel mode PIC/IOAPIC/LAPIC\n"
 #endif
 #ifdef TARGET_I386
-- 
1.4.2


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

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

* [PATCH 2/3] [PATCH] unregister pci device
  2008-03-26 21:09 [PATCH 0/3] fixups for pci passthrough Glauber Costa
  2008-03-26 21:09 ` [PATCH 1/3] [PATCH] passthrough Glauber Costa
@ 2008-03-26 21:09 ` Glauber Costa
  2008-03-27  7:50   ` Avi Kivity
  2008-03-26 21:09 ` [PATCH 3/3] [PATCH] remove warnings Glauber Costa
  2 siblings, 1 reply; 8+ messages in thread
From: Glauber Costa @ 2008-03-26 21:09 UTC (permalink / raw)
  To: kvm-devel; +Cc: avi

If we fail after we have allocated the pci device, we have
to get rid of it. Otherwise, a bogus device will be found on
the bus

Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
 qemu/hw/passthrough/passthrough.c |   11 +++++++----
 qemu/hw/pci.c                     |    6 ++++++
 qemu/hw/pci.h                     |    2 ++
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/qemu/hw/passthrough/passthrough.c b/qemu/hw/passthrough/passthrough.c
index a416098..64f0af9 100644
--- a/qemu/hw/passthrough/passthrough.c
+++ b/qemu/hw/passthrough/passthrough.c
@@ -389,13 +389,13 @@ pt_dev_t *register_real_device(PCIBus * 
 	if (pt_get_real_device(pci_dev, r_bus, r_dev, r_func)) {
 		fprintf(logfile, "register_real_device: Error: Couldn't get "
 			"real device (%s)!\n", e_dev_name);
-		return NULL;
+		goto out;
 	}
 
 	/* handle real device's MMIO/PIO BARs */
 	if (pt_register_regions(pci_dev->real_device.regions,
 				pci_dev->real_device.region_number, pci_dev))
-		return (NULL);
+		goto out;
 
 	/* handle interrupt routing */
 	e_device = (pci_dev->dev.devfn >> 3) & 0x1f;
@@ -412,7 +412,7 @@ pt_dev_t *register_real_device(PCIBus * 
 		if (rc) {
 			fprintf(logfile, "pt_bind %d failed rc=%d\n",
 				pci_dev->mirq, rc);
-			return NULL;
+			goto out;
 		}
 		sprintf(pci_dev->sirq, "%d", pci_dev->mirq);
 	}
@@ -433,7 +433,7 @@ pt_dev_t *register_real_device(PCIBus * 
 			fprintf(stderr, "Could not notify kernel about "
 				"passthrough device\n");
 			perror("pt-ioctl:");
-			return NULL;
+			goto out;
 		}
 		fprintf(logfile, "Registered host PCI device %02x:%02x.%1x as "
 			"guest device %02x:%02x.%1x with hypercall support\n",
@@ -445,6 +445,9 @@ pt_dev_t *register_real_device(PCIBus * 
 		r_bus, r_dev, r_func, e_dev_name);
 
 	return (pci_dev);
+out:
+	pci_unregister_device(e_bus, &pci_dev->dev);
+	return NULL;
 }
 
 #define	MAX_PTDEVS 4
diff --git a/qemu/hw/pci.c b/qemu/hw/pci.c
index 72b65db..b605744 100644
--- a/qemu/hw/pci.c
+++ b/qemu/hw/pci.c
@@ -185,6 +185,12 @@ PCIDevice *pci_register_device(PCIBus *b
     return pci_dev;
 }
 
+void pci_unregister_device(PCIBus *bus, PCIDevice *dev)
+{
+	bus->devices[dev->devfn] = NULL;
+	qemu_free(dev);
+}
+
 void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func)
diff --git a/qemu/hw/pci.h b/qemu/hw/pci.h
index e870987..220189f 100644
--- a/qemu/hw/pci.h
+++ b/qemu/hw/pci.h
@@ -70,6 +70,8 @@ PCIDevice *pci_register_device(PCIBus *b
                                PCIConfigReadFunc *config_read,
                                PCIConfigWriteFunc *config_write);
 
+void pci_unregister_device(PCIBus *bus, PCIDevice *dev);
+
 void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func);
-- 
1.4.2


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

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

* [PATCH 3/3] [PATCH] remove warnings
  2008-03-26 21:09 [PATCH 0/3] fixups for pci passthrough Glauber Costa
  2008-03-26 21:09 ` [PATCH 1/3] [PATCH] passthrough Glauber Costa
  2008-03-26 21:09 ` [PATCH 2/3] [PATCH] unregister pci device Glauber Costa
@ 2008-03-26 21:09 ` Glauber Costa
  2 siblings, 0 replies; 8+ messages in thread
From: Glauber Costa @ 2008-03-26 21:09 UTC (permalink / raw)
  To: kvm-devel; +Cc: avi

everytime there is a warning, god kills a kitten

Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
 libkvm/libkvm.h                   |    2 ++
 qemu/hw/passthrough/passthrough.c |    8 ++++++--
 qemu/hw/pc.h                      |    1 +
 qemu/hw/pci.h                     |    2 ++
 4 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h
index 34d188b..f345f48 100644
--- a/libkvm/libkvm.h
+++ b/libkvm/libkvm.h
@@ -23,6 +23,8 @@ #if defined(__x86_64__) || defined(__i38
 struct kvm_msr_list *kvm_get_msr_list(kvm_context_t);
 int kvm_get_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
 int kvm_set_msrs(kvm_context_t, int vcpu, struct kvm_msr_entry *msrs, int n);
+int kvm_assign_pv_pci_device(kvm_context_t kvm,
+			     struct kvm_pv_passthrough_dev *pv_pci_dev);
 #endif
 
 /*!
diff --git a/qemu/hw/passthrough/passthrough.c b/qemu/hw/passthrough/passthrough.c
index 64f0af9..844c0e8 100644
--- a/qemu/hw/passthrough/passthrough.c
+++ b/qemu/hw/passthrough/passthrough.c
@@ -17,6 +17,9 @@ #include "neo_pci_tree.h"
 typedef u64 resource_size_t;
 #define __deprecated 
 
+#include "hw/pci.h"
+#include "hw/pc.h"
+
 #include <linux/ioport.h>
 #include "passthrough.h"
 
@@ -352,7 +355,7 @@ pt_get_real_device(pt_dev_t *pci_dev, ui
 		rp->valid = 1;
 		rp->base_addr = start;
 		rp->size = size;
-		fprintf(logfile, "region %d size %d start 0x%x type %d "
+		fprintf(logfile, "region %d size %d start 0x%llx type %d "
 			"resource_fd %d\n", r, rp->size, start, rp->type,
 			rp->resource_fd);
 	}
@@ -468,7 +471,7 @@ static pt_dev_t **apicv[0xfe]; //0x10 - 
 #define IRQHOOK_DEV "/dev/irqhook"
 static pthread_t irqthread;
 
-void pt_irq(void *arg)
+void *pt_irq(void *arg)
 {
 	char buf[20];
 	int irq;
@@ -500,6 +503,7 @@ void pt_irq(void *arg)
 				dev->run = 1;
 		qemu_bh_schedule(ptbh);
 	}
+	return NULL;
 }
 
 static void pt_bh(void *p)
diff --git a/qemu/hw/pc.h b/qemu/hw/pc.h
index f640395..aec98d4 100644
--- a/qemu/hw/pc.h
+++ b/qemu/hw/pc.h
@@ -101,6 +101,7 @@ int pcspk_audio_init(AudioState *, qemu_
 PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic);
 void i440fx_set_smm(PCIDevice *d, int val);
 int piix3_init(PCIBus *bus, int devfn);
+int piix3_get_pin(int pic_irq);
 void i440fx_init_memory_mappings(PCIDevice *d);
 
 int piix4_init(PCIBus *bus, int devfn);
diff --git a/qemu/hw/pci.h b/qemu/hw/pci.h
index 220189f..4858e3e 100644
--- a/qemu/hw/pci.h
+++ b/qemu/hw/pci.h
@@ -91,6 +91,8 @@ PCIBus *pci_register_bus(pci_set_irq_fn 
 void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn);
 void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);
 uint32_t pci_data_read(void *opaque, uint32_t addr, int len);
+int pci_map_irq(PCIDevice *pci_dev, int pin);
+
 int pci_bus_num(PCIBus *s);
 void pci_for_each_device(int bus_num, void (*fn)(PCIDevice *d));
 
-- 
1.4.2


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

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

* Re: [PATCH 1/3] [PATCH] passthrough
  2008-03-26 21:09 ` [PATCH 1/3] [PATCH] passthrough Glauber Costa
@ 2008-03-27  7:49   ` Avi Kivity
  0 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2008-03-27  7:49 UTC (permalink / raw)
  To: Glauber Costa; +Cc: kvm-devel

Glauber Costa wrote:
> add -passthrough usage string
>
> Signed-off-by: Glauber Costa <gcosta@redhat.com>
> ---
>  qemu/vl.c |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
>
> diff --git a/qemu/vl.c b/qemu/vl.c
> index f5b2665..d36cfe3 100644
> --- a/qemu/vl.c
> +++ b/qemu/vl.c
> @@ -8053,6 +8053,7 @@ #ifdef USE_KVM
>  #ifndef NO_CPU_EMULATION
>  	   "-no-kvm         disable KVM hardware virtualization\n"
>  #endif
> +	   "-passthrough name/bus:dev.func-intr expose a pci device to the guest OS \n"
>  	   "-no-kvm-irqchip disable KVM kernel mode PIC/IOAPIC/LAPIC\n"
>  #endif
>  #ifdef TARGET_I386
>   

Not this patch's fault, of course, but it would be better to name the 
option -pcidevice, to be consistent with -usbdevice, and to show only 
pci devices are allowed.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

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

* Re: [PATCH 2/3] [PATCH] unregister pci device
  2008-03-26 21:09 ` [PATCH 2/3] [PATCH] unregister pci device Glauber Costa
@ 2008-03-27  7:50   ` Avi Kivity
  2008-03-27 11:40     ` Glauber Costa
  0 siblings, 1 reply; 8+ messages in thread
From: Avi Kivity @ 2008-03-27  7:50 UTC (permalink / raw)
  To: Glauber Costa; +Cc: kvm-devel

Glauber Costa wrote:
> If we fail after we have allocated the pci device, we have
> to get rid of it. Otherwise, a bogus device will be found on
> the bus
>   

Maybe, alter the order so the device is registered last thing.  This may 
help avoid races with pci passthrough hotplug.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

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

* Re: [PATCH 2/3] [PATCH] unregister pci device
  2008-03-27  7:50   ` Avi Kivity
@ 2008-03-27 11:40     ` Glauber Costa
  2008-03-27 11:43       ` Avi Kivity
  0 siblings, 1 reply; 8+ messages in thread
From: Glauber Costa @ 2008-03-27 11:40 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel

Avi Kivity wrote:
> Glauber Costa wrote:
>> If we fail after we have allocated the pci device, we have
>> to get rid of it. Otherwise, a bogus device will be found on
>> the bus
>>   
> 
> Maybe, alter the order so the device is registered last thing.  This may 
> help avoid races with pci passthrough hotplug.
> 
That's the first thing I thought, but it makes things much more 
complicated. If really deserved, I can try again.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

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

* Re: [PATCH 2/3] [PATCH] unregister pci device
  2008-03-27 11:40     ` Glauber Costa
@ 2008-03-27 11:43       ` Avi Kivity
  0 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2008-03-27 11:43 UTC (permalink / raw)
  To: Glauber Costa; +Cc: kvm-devel

Glauber Costa wrote:
> Avi Kivity wrote:
>> Glauber Costa wrote:
>>> If we fail after we have allocated the pci device, we have
>>> to get rid of it. Otherwise, a bogus device will be found on
>>> the bus
>>>   
>>
>> Maybe, alter the order so the device is registered last thing.  This 
>> may help avoid races with pci passthrough hotplug.
>>
> That's the first thing I thought, but it makes things much more 
> complicated. If really deserved, I can try again.

I don't think it's that critical at this stage.

-- 
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

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

end of thread, other threads:[~2008-03-27 11:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-26 21:09 [PATCH 0/3] fixups for pci passthrough Glauber Costa
2008-03-26 21:09 ` [PATCH 1/3] [PATCH] passthrough Glauber Costa
2008-03-27  7:49   ` Avi Kivity
2008-03-26 21:09 ` [PATCH 2/3] [PATCH] unregister pci device Glauber Costa
2008-03-27  7:50   ` Avi Kivity
2008-03-27 11:40     ` Glauber Costa
2008-03-27 11:43       ` Avi Kivity
2008-03-26 21:09 ` [PATCH 3/3] [PATCH] remove warnings Glauber Costa

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