pass-through PCI device hotplug support
PATCH 1/1 pass-through PCI device hotplug support
Keir,
This patch is the new version against 17051 to enable HVM guest VT-d device hotplug.
** Currently only 2 virtual pci slots(6~7) are made as being capable of hotplug, so more than 2 vtd dev can't be hotplugged, but we can easily extend it in future.
Three new commands are added:
"xm pci-list domid" show the current assigned vtd device, like:
VSlt domain bus slot func0x6 0x0 0x02 0x00 0x0
"xm pci-detach" hot remove the specified vtd device by the virtual slot, like:
xm pci-detach EdwinHVMDomainVtd 6
"xm pci-attach DomainID dom bus dev func [vslot]" hot add a new vtd device in the vslot. If no vslot specified, a free slot will be picked up. e.g. to insert '0000:03:00.0':
xm pci-attach EdwinHVMDomainVtd 0 3 0 0
** guest pci hotplug
linux: pls. use 2.6.X and enable ACPI PCI hotplug ( Bus options=> PCI hotplug => ACPI PCI hotplug driver)
windows: 2000/xp/2003/vista are all okay
Thanks a lot.
Signature · 2 lines
best rgds, edwin
# HG changeset patch
# User Edwin Zhai <[email protected]>
# Date 1203080965 -28800
# Node ID 9f83f4f3eb5e4581136a80fdb22d6c0f7a84f04b
# Parent bac4536f5e840a52626f0c938ed5c88e8d444fbc Enable HVM guest VT-d device hotplug via a simple ACPI hotplug device model.
tools/firmware/hvmloader/acpi/dsdt.asl +118 -0
@@ -79,6 +79,12 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, Name (_UID, 0x00) Name (_ADR, 0x00) Name (_BBN, 0x00) + Method (_HPP, 0) + { + Store (0x99, \_GPE.DPT1) + Return (Package(0x4){0x10, 0x40, 0x00, 0x00}) + } + Method (_CRS, 0, NotSerialized) {
@@ -713,6 +719,118 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, }) } } + + /********************************************************************* + * Each PCI hotplug slot need at least 2 methods to handle ACPI event: + * _EJ0: eject a device + * _STA: return a device's status, e.g. enabled or removed + * other methods are optional: + * _PS0/3, _HPP... put them here for debug purpose + * + * Eject button would generate a general-purpose event, then the + * control method for this event uses Notify() to inform OSPM which + * action happen on which device. + * + * Pls. refer "6.3 Device Insertion, Removal, and Status Objects" + * in ACPI spec 3.0b for details. + * + * QEMU provides a simple hotplug controller with some I/O to handle + * the hotplug action and status, which is beyond the ACPI scope. + */ + + Device (S1F0) + { + Name (_ADR, 0x00060000) /* Dev 6, Func 0 */ + Name (_SUN, 0x00000001) + + Method (_PS0, 0) + { + Store (0x80, \_GPE.DPT2) + } + + Method (_PS3, 0) + { + Store (0x83, \_GPE.DPT2) + } + + Method (_EJ0, 1) + { + Store (0x88, \_GPE.DPT2) + Store (0x1, \_GPE.PHP1) /* eject php slot 1*/ + } + + Method (_STA, 0) + { + Store (0x89, \_GPE.DPT2) + Return ( \_GPE.PHP1 ) /* IN status as the _STA */ + } + } + + Device (S2F0) + { + Name (_ADR, 0x00070000) /* Dev 7, Func 0 */ + Name (_SUN, 0x00000002) + + Method (_PS0, 0) + { + Store (0x90, \_GPE.DPT2) + } + + Method (_PS3, 0) + { + Store (0x93, \_GPE.DPT2) + } + + Method (_EJ0, 1) + { + Store (0x98, \_GPE.DPT2) + Store (0x1, \_GPE.PHP2) /* eject php slot 1*/ + } + + Method (_STA, 0) + { + Store (0x99, \_GPE.DPT2) + Return ( \_GPE.PHP2 ) /* IN status as the _STA */ + } + } + } + } + Scope (\_GPE) + { + OperationRegion (PHP, SystemIO, 0x10c0, 0x03) + Field (PHP, ByteAcc, NoLock, Preserve) + { + PSTA, 8, /* hotplug controller status reg */ + PHP1, 8, /* hotplug slot 1 control reg */ + PHP2, 8 /* hotplug slot 2 control reg */ + } + OperationRegion (DG1, SystemIO, 0xb044, 0x04) + Field (DG1, ByteAcc, NoLock, Preserve) + { + DPT1, 8, + DPT2, 8 + } + Method (_L03, 0, NotSerialized) + { + /* detect slot and event(remove/add) */ + Name (SLT, 0x0) + Name (EVT, 0x0) + Store (PSTA, Local1) + ShiftRight (Local1, 0x4, SLT) + And (Local1, 0xf, EVT) + + /* debug */ + Store (SLT, DPT1) + Store (EVT, DPT2) + + If ( LEqual(SLT, 0x1) ) + { + Notify (\_SB.PCI0.S1F0, EVT) + } + ElseIf ( LEqual(SLT, 0x2) ) + { + Notify (\_SB.PCI0.S2F0, EVT) + } } } }
tools/firmware/hvmloader/acpi/dsdt.c +501 -441
970 lines not on this page · raw message
tools/firmware/hvmloader/acpi/static_tables.c +2 -0
@@ -59,9 +59,11 @@ struct acpi_20_fadt Fadt = { .pm1a_evt_blk = ACPI_PM1A_EVT_BLK_ADDRESS, .pm1a_cnt_blk = ACPI_PM1A_CNT_BLK_ADDRESS, .pm_tmr_blk = ACPI_PM_TMR_BLK_ADDRESS, + .gpe0_blk = ACPI_GPE0_BLK_ADDRESS, .pm1_evt_len = ACPI_PM1A_EVT_BLK_BIT_WIDTH / 8, .pm1_cnt_len = ACPI_PM1A_CNT_BLK_BIT_WIDTH / 8, .pm_tmr_len = ACPI_PM_TMR_BLK_BIT_WIDTH / 8, + .gpe0_blk_len = ACPI_GPE0_BLK_LEN, .p_lvl2_lat = 0x0fff, /* >100, means we do not support C2 state */ .p_lvl3_lat = 0x0fff, /* >1000, means we do not support C3 state */
tools/ioemu/hw/pass-through.c +331 -14
415 lines not on this page · raw message
tools/ioemu/hw/pc.c +4 -2
@@ -945,8 +945,10 @@ static void pc_init1(uint64_t ram_size, }#ifdef CONFIG_PASSTHROUGH -/* Pass-through Initialization */ -if ( pci_enabled && direct_pci ) +/* Pass-through Initialization +* init libpci even direct_pci is null, as can hotplug a dev runtime +*/ +if ( pci_enabled ) { rc =pt_init (pci_bus, direct_pci);if ( rc <0 )
tools/ioemu/hw/pci.c +8 -1
@@ -107,7 +107,8 @@ PCIDevice *pci_register_device(PCIBus *bif (devfn <0 ) {for (devfn = bus->devfn_min ; devfn <256 ; devfn +=8 ) { -if (!bus->devices[devfn]) +if ( !bus->devices[devfn] && + !( devfn >=PHP_DEVFN_START && devfn <PHP_DEVFN_END ) ) goto found; }return NULL ;
@@ -130,6 +131,12 @@ PCIDevice *pci_register_device(PCIBus *b pci_dev->irq_index = pci_irq_index++; bus->devices[devfn] = pci_dev;return pci_dev; +} + +void pci_hide_device (PCIDevice *pci_dev) +{ +PCIBus *bus = pci_dev->bus; + bus->devices[pci_dev->devfn] =NULL ; } void pci_register_io_region(PCIDevice *pci_dev, int region_num,
tools/ioemu/hw/piix4acpi.c +354 -0
383 lines not on this page · raw message
tools/ioemu/monitor.c +6 -0
@@ -1288,6 +1288,12 @@ static term_cmd_t term_cmds[] = { "device", "add USB device (e.g. 'host:bus.addr' or 'host:vendor_id:product_id')" }, {"usb_del" ,"s" , do_usb_del, "device", "remove USB device 'bus.addr'" }, +#ifdef CONFIG_PHP_DEBUG + { "pci_add", "s", do_pci_add, + "device", "insert PCI pass-through device by BDF,e.g. (dom, bus, dev, func) by hex '0x0, 0x3, 0x0, 0x0'" }, + { "pci_del", "s", do_pci_del, + "device", "remove PCI pass-through device by BDF,e.g. (dom, bus, dev, func) by hex '0x0, 0x3, 0x0, 0x0'" }, +#endif #ifndef CONFIG_DM { "cpu", "i", do_cpu_set, "index", "set the default CPU" },
tools/ioemu/vl.c +20 -4
@@ -4382,6 +4382,24 @@ void usb_info(void) } } +void do_pci_del (char *devname) +{ +int pci_slot; + pci_slot =bdf_to_slot (devname); + +acpi_php_del (pci_slot); +} + +void do_pci_add (char *devname) +{ +int pci_slot; + + pci_slot =insert_to_pci_slot (devname); + +acpi_php_add (pci_slot); +} + +/***********************************************************/ /* pid file */
@@ -7067,7 +7085,7 @@ int main(int argc, char **argv)#endif sigset_t set;char qemu_dm_logfilename[128 ]; -const char *direct_pci =NULL ; +const char *direct_pci = direct_pci_str;#if !defined(__sun__) && !defined(CONFIG_STUBDOM )/* Maximise rlimits. Needed where default constraints are tight (*BSD). */
@@ -7590,9 +7608,6 @@ int main(int argc, char **argv)case QEMU_OPTION_vncunused: vncunused++;break ; -case QEMU_OPTION_pci: - direct_pci = optarg; -break ; } } }
@@ -7970,5 +7985,6 @@ int main(int argc, char **argv)main_loop ();quit_timers (); +pt_uninit ();return 0 ; }
tools/ioemu/vl.h +28 -0
@@ -817,10 +817,14 @@ struct PCIDevice {int irq_state[4 ]; }; +extern char direct_pci_str[]; +PCIDevice *pci_register_device (PCIBus *bus,const char *name,int instance_size,int devfn,PCIConfigReadFunc *config_read,PCIConfigWriteFunc *config_write); + +void pci_hide_device (PCIDevice *pci_dev); void pci_register_io_region(PCIDevice *pci_dev, int region_num, uint32_t size, int type,
@@ -849,6 +853,22 @@ void pci_info(void);void pci_info (void );PCIBus *pci_bridge_init (PCIBus *bus,int devfn,uint32_t id,pci_map_irq_fn map_irq,const char *name); + +/* PCI slot 6~7 support ACPI PCI hot plug */ +#define PHP_SLOT_START (6) +#define PHP_SLOT_END (8) +#define PHP_SLOT_LEN (PHP_SLOT_END - PHP_SLOT_START) +#define PHP_TO_PCI_SLOT (x) (x + PHP_SLOT_START) +#define PCI_TO_PHP_SLOT (x) (x - PHP_SLOT_START) +#define PHP_DEVFN_START (PHP_SLOT_START << 3) +#define PHP_DEVFN_END (PHP_SLOT_END << 3) + +int insert_to_pci_slot (char *); +int test_pci_slot (int ); +int bdf_to_slot (char *); +int power_on_php_slot (int ); +int power_off_php_slot (int ); +void pt_uninit (void );/* prep_pci.c */ PCIBus *pci_prep_init (void );
@@ -1120,6 +1140,9 @@ void tpm_tis_init(SetIRQFunc *set_irq, v/* piix4acpi.c */ extern void pci_piix4_acpi_init (PCIBus *bus,int devfn); +void acpi_php_add (int ); +void acpi_php_del (int ); +/* pc.c */ extern QEMUMachine pc_machine;
@@ -1320,6 +1343,9 @@ void do_usb_del(const char *devname);void do_usb_del (const char *devname);void usb_info (void ); +void do_pci_add (char *devname); +void do_pci_del (char *devname); +/* scsi-disk.c */ enum scsi_reason {SCSI_REASON_DONE ,/* Command complete. */
@@ -1466,10 +1492,12 @@ void xenstore_parse_domain_config(int dovoid xenstore_parse_domain_config (int domid);int xenstore_fd (void );void xenstore_process_event (void *opaque); +void xenstore_record_dm (char *subpath,char *state);void xenstore_record_dm_state (char *state);void xenstore_check_new_media_present (int timeout);void xenstore_write_vncport (int vnc_display);void xenstore_read_vncpasswd (int domid,char *pwbuf,size_t pwbuflen); +void xenstore_write_vslots (char *vslots);int xenstore_domain_has_devtype (struct xs_handle *handle,const char *devtype);
tools/ioemu/xenstore.c +98 -14
156 lines not on this page · raw message
tools/libxc/xc_domain.c +44 -0
56 lines not on this page · raw message
tools/libxc/xenctrl.h +13 -0
@@ -914,6 +914,10 @@ int xc_test_assign_device(int xc_handle,uint32_t domid, uint32_t machine_bdf); +int xc_deassign_device (int xc_handle, +uint32_t domid, +uint32_t machine_bdf); + int xc_domain_memory_mapping(int xc_handle, uint32_t domid, unsigned long first_gfn,
@@ -937,6 +941,15 @@ int xc_domain_bind_pt_irq(int xc_handle,uint8_t intx, uint8_t isa_irq); +int xc_domain_unbind_pt_irq (int xc_handle, +uint32_t domid, +uint8_t machine_irq, +uint8_t irq_type, +uint8_t bus, +uint8_t device, +uint8_t intx, +uint8_t isa_irq); + int xc_domain_bind_pt_pci_irq(int xc_handle, uint32_t domid, uint8_t machine_irq,
tools/python/xen/xend/XendDomainInfo.py +202 -0
241 lines not on this page · raw message
tools/python/xen/xend/image.py +25 -6
@@ -300,23 +300,42 @@ class ImageHandler: self.vm.storeDom("image/device-model-pid", self.pid) log.info("device model pid: %d", self.pid) - def saveDeviceModel(self): + def signalDeviceModel(self, cmd, ret, par = None): if self.device_model is None: return - # Signal the device model to pause itself and save its state + # Signal the device model to for action + if cmd is '' or ret is '': + raise VmError('need valid command and result when signal device model') + + orig_state = xstransact.Read("/local/domain/0/device-model/%i/state" + % self.vm.getDomid()) + + if par is not None: + xstransact.Store("/local/domain/0/device-model/%i" + % self.vm.getDomid(), ('parameter', par)) + xstransact.Store("/local/domain/0/device-model/%i" - % self.vm.getDomid(), ('command', 'save')) + % self.vm.getDomid(), ('command', cmd)) # Wait for confirmation. Could do this with a watch but we'd # still end up spinning here waiting for the watch to fire. state = '' count = 0 - while state != 'paused': + while state != ret: state = xstransact.Read("/local/domain/0/device-model/%i/state" % self.vm.getDomid()) time.sleep(0.1) count += 1 if count > 100: - raise VmError('Timed out waiting for device model to save') + raise VmError('Timed out waiting for device model action') + + #resotre orig state + xstransact.Store("/local/domain/0/device-model/%i" + % self.vm.getDomid(), ('state', orig_state)) + log.info("signalDeviceModel:restore dm state to %s", orig_state) + + def saveDeviceModel(self): + # Signal the device model to pause itself and save its state + self.signalDeviceModel('save', 'paused') def resumeDeviceModel(self): if self.device_model is None:
@@ -479,7 +498,7 @@ class HVMImageHandler(ImageHandler): dmargs = [ 'boot', 'fda', 'fdb', 'soundhw', 'localtime', 'serial', 'stdvga', 'isa', - 'acpi', 'usb', 'usbdevice', 'pci' ] + 'acpi', 'usb', 'usbdevice' ] for a in dmargs: v = vmConfig['platform'].get(a)
tools/python/xen/xend/server/DevController.py +8 -0
@@ -412,6 +412,14 @@ class DevController: return result + def removeBackend(self, devid, *args): + frontpath = self.frontendPath(devid) + backpath = xstransact.Read(frontpath, "backend") + if backpath: + return xstransact.Remove(backpath, *args) + else: + raise VmError("Device %s not connected" % devid) + def readBackend(self, devid, *args): frontpath = self.frontendPath(devid) backpath = xstransact.Read(frontpath, "backend")
tools/python/xen/xend/server/pciif.py +46 -2
87 lines not on this page · raw message
tools/python/xen/xm/main.py +67 -0
103 lines not on this page · raw message
xen/arch/x86/domctl.c +45 -0
57 lines not on this page · raw message
xen/arch/x86/hvm/irq.c +1 -1
@@ -211,7 +211,7 @@ void hvm_set_pci_link_route(struct domaiclear_bit (old_isa_irq, &hvm_irq->dpci->isairq_map);for ( i =0 ; i <NR_LINK ; i++ ) -if (test_bit (i, &hvm_irq->dpci->link_map) && +if ( hvm_irq->dpci->link_cnt[i] >0 && hvm_irq->pci_link.route[i] )set_bit (hvm_irq->pci_link.route[i], &hvm_irq->dpci->isairq_map);
xen/arch/x86/hvm/vmx/vtd/intel-iommu.c +2 -2
@@ -1441,6 +1441,8 @@ void reassign_device_ownership( bus,PCI_SLOT (devfn),PCI_FUNC (devfn), source->domain_id, target->domain_id); +pdev_flr (bus, devfn); +for_each_pdev ( source, pdev ) {if ( (pdev->bus != bus) || (pdev->devfn != devfn) )
@@ -1476,7 +1478,6 @@ void return_devices_to_dom0(struct domai dprintk(XENLOG_INFO VTDPREFIX,"return_devices_to_dom0: bdf = %x:%x:%x\n" , pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); -pdev_flr (pdev->bus, pdev->devfn);reassign_device_ownership (d, dom0, pdev->bus, pdev->devfn); }
@@ -1930,7 +1931,6 @@ int intel_iommu_assign_device(struct dom"assign_device: bus = %x dev = %x func = %x\n" , bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); -pdev_flr (bus, devfn);reassign_device_ownership (dom0, d, bus, devfn);/* Setup rmrr identify mapping */
xen/arch/x86/hvm/vmx/vtd/io.c +60 -1
73 lines not on this page · raw message
xen/include/asm-x86/hvm/irq.h +1 -1
@@ -64,7 +64,7 @@ struct hvm_irq_dpci {/* Record of mapped ISA IRQs */ DECLARE_BITMAP (isairq_map,NR_ISAIRQS );/* Record of mapped Links */ -DECLARE_BITMAP (link_map,NR_LINK ); +uint8_t link_cnt[NR_LINK ];struct timer hvm_timer[NR_IRQS ]; };
xen/include/asm-x86/iommu.h +5 -0
@@ -74,6 +74,9 @@ void iommu_domain_destroy(struct domainvoid iommu_domain_destroy (struct domain *d);int device_assigned (u8 bus,u8 devfn);int assign_device (struct domain *d,u8 bus,u8 devfn); +void reassign_device_ownership (struct domain *source, +struct domain *target, +u8 bus,u8 devfn);int iommu_map_page (struct domain *d,unsigned long gfn,unsigned long mfn);int iommu_unmap_page (struct domain *d,unsigned long gfn);void iommu_flush (struct domain *d,unsigned long gfn,u64 *p2m_entry);
@@ -83,6 +86,8 @@ int dpci_ioport_intercept(ioreq_t *p);int dpci_ioport_intercept (ioreq_t *p);int pt_irq_create_bind_vtd (struct domain *d,xen_domctl_bind_pt_irq_t *pt_irq_bind); +int pt_irq_destroy_bind_vtd (struct domain *d, +xen_domctl_bind_pt_irq_t *pt_irq_bind);unsigned int io_apic_read_remap_rte (unsigned int apic,unsigned int reg); void io_apic_write_remap_rte(unsigned int apic,
xen/include/public/domctl.h +2 -0
@@ -439,6 +439,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_sendt/* Assign PCI device to HVM guest. Sets up IOMMU structures. */ #define XEN_DOMCTL_assign_device 37#define XEN_DOMCTL_test_assign_device 45 +#define XEN_DOMCTL_deassign_device 47struct xen_domctl_assign_device {uint32_t machine_bdf;/* machine PCI ID of assigned device */ };
@@ -448,6 +449,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_assig/* Pass-through interrupts: bind real irq -> hvm devfn. */ #define XEN_DOMCTL_bind_pt_irq 38 +#define XEN_DOMCTL_unbind_pt_irq 48
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Part of the diff is not shown here. View the raw message.
Quoted 7 lines · Edwin
This patch is the new version against 17051 to enable HVM guest VT-d device hotplug.
** Currently only 2 virtual pci slots(6~7) are made as being capable of hotplug,
so more than 2 vtd dev can't be hotplugged, but we can easily extend it in future.
Now applied, but perhaps too hastily. I found it broke the !CONFIG_PASSTHROUGH build and in fixing that I noticed that you dumped code in a bunch of random places in qemu. Perhaps all passthrough stuff should be gathered in one place? Alternatively at least the device model changes (in piix4acpi.c) should be decoupled a bit from the backend logic in passthrough.c, so the former can cleanly build without the latter. I also killed pt_uninit() because I couldn't even find where pci_cleanup() was defined. No passthrough function should be in vl.c: I #ifdef'ed in the for now but the functions should probably be moved. And you did a big dump of random crap into vl.h.
-- Keir
Keir,
c/s 17056 also works for AMD-IOMMU, attached patch introduces a new vendor independent interface for device detachment. Thanks,
Wei
Signature · 12 lines
AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Geschäftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplementär: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Geschäftsführer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
Quoted 21 lines · Keir Fraser
Quoted 7 lines · Edwin
This patch is the new version against 17051 to enable HVM guest VT-d device hotplug.
** Currently only 2 virtual pci slots(6~7) are made as being capable of hotplug,
so more than 2 vtd dev can't be hotplugged, but we can easily extend it in future.Now applied, but perhaps too hastily. I found it broke the !CONFIG_PASSTHROUGH build and in fixing that I noticed that you dumped code in a bunch of random places in qemu. Perhaps all passthrough stuff should be gathered in one place? Alternatively at least the device model changes (in
piix4acpi.c) should be decoupled a bit from the backend logic inpassthrough.c, so the former can cleanly build without the latter. I also killedpt_uninit()because I couldn't even find wherepci_cleanup()was defined. No passthrough function should be invl.c: I #ifdef'ed in the for now but the functions should probably be moved. And you did a big dump of random crap intovl.h.
Quoted 10 lines
-- Keir
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
xen/arch/x86/domctl.c +1 -1
@@ -601,7 +601,7 @@ long arch_do_domctl(if ( !device_assigned (bus, devfn) )break ; -reassign_device_ownership (d, dom0, bus, devfn); +deassign_device (d, bus, devfn);gdprintk (XENLOG_INFO ,"XEN_DOMCTL_deassign_device: bdf = %x:%x:%x\n" , bus,PCI_SLOT (devfn),PCI_FUNC (devfn));put_domain (d);
xen/arch/x86/hvm/iommu.c +10 -0
@@ -133,3 +133,13 @@ int iommu_unmap_page(struct domain *d, ureturn hd->platform_ops->unmap_page (d, gfn); } + +void deassign_device (struct domain *d,u8 bus,u8 devfn) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops) +return ; + +return hd->platform_ops->reassign_device (d, dom0, bus, devfn); +}
xen/arch/x86/hvm/svm/amd_iommu/pci-amd-iommu.c +7 -0
@@ -562,10 +562,17 @@ void amd_iommu_domain_destroy(struct domrelease_domain_devices (d); } +void amd_iommu_return_device (struct domain *s,struct domain *t,u8 bus,u8 devfn) +{ +pdev_flr (bus, devfn); +reassign_device (s, t, bus, devfn); +} +struct iommu_ops amd_iommu_ops = { .init = amd_iommu_domain_init, .assign_device = amd_iommu_assign_device, .teardown = amd_iommu_domain_destroy, .map_page = amd_iommu_map_page, .unmap_page = amd_iommu_unmap_page, + .reassign_device = amd_iommu_return_device, };
xen/arch/x86/hvm/vmx/vtd/intel-iommu.c +1 -0
@@ -2164,6 +2164,7 @@ struct iommu_ops intel_iommu_ops = { .teardown = iommu_domain_teardown, .map_page = intel_iommu_map_page, .unmap_page = intel_iommu_unmap_page, + .reassign_device = reassign_device_ownership, };/*
xen/include/asm-x86/iommu.h +2 -0
@@ -74,6 +74,7 @@ void iommu_domain_destroy(struct domainvoid iommu_domain_destroy (struct domain *d);int device_assigned (u8 bus,u8 devfn);int assign_device (struct domain *d,u8 bus,u8 devfn); +void deassign_device (struct domain *d,u8 bus,u8 devfn);void reassign_device_ownership (struct domain *source,struct domain *target,u8 bus,u8 devfn);
@@ -102,6 +103,7 @@ struct iommu_ops {void (*teardown)(struct domain *d);int (*map_page)(struct domain *d,unsigned long gfn,unsigned long mfn);int (*unmap_page)(struct domain *d,unsigned long gfn); + void (*reassign_device)(struct domain *s, struct domain *t, u8 bus, u8 devfn); };#endif /* _IOMMU_H_ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Adding a signed off line.
--
AMD Saxony, Dresden, Germany
Operating System Research Center
Legal Information:
AMD Saxony Limited Liability Company & Co. KG Sitz (Geschäftsanschrift):
Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland
Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplementär:
AMD Saxony LLC (Sitz Wilmington, Delaware, USA)
Geschäftsführer der AMD Saxony LLC:
Dr. Hans-R. Deppe, Thomas McCoy
Quoted 10 lines · On Fri, 2008-02-15 at 18:19 +0100, Wei Wang2 wrote:
Keir,
c/s 17056 also works for AMD-IOMMU, attached patch introduces a new vendor independent interface for device detachment. Thanks,Wei
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
xen/arch/x86/domctl.c +1 -1
@@ -601,7 +601,7 @@ long arch_do_domctl(if ( !device_assigned (bus, devfn) )break ; -reassign_device_ownership (d, dom0, bus, devfn); +deassign_device (d, bus, devfn);gdprintk (XENLOG_INFO ,"XEN_DOMCTL_deassign_device: bdf = %x:%x:%x\n" , bus,PCI_SLOT (devfn),PCI_FUNC (devfn));put_domain (d);
xen/arch/x86/hvm/iommu.c +10 -0
@@ -133,3 +133,13 @@ int iommu_unmap_page(struct domain *d, ureturn hd->platform_ops->unmap_page (d, gfn); } + +void deassign_device (struct domain *d,u8 bus,u8 devfn) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops) +return ; + +return hd->platform_ops->reassign_device (d, dom0, bus, devfn); +}
xen/arch/x86/hvm/svm/amd_iommu/pci-amd-iommu.c +7 -0
@@ -562,10 +562,17 @@ void amd_iommu_domain_destroy(struct domrelease_domain_devices (d); } +void amd_iommu_return_device (struct domain *s,struct domain *t,u8 bus,u8 devfn) +{ +pdev_flr (bus, devfn); +reassign_device (s, t, bus, devfn); +} +struct iommu_ops amd_iommu_ops = { .init = amd_iommu_domain_init, .assign_device = amd_iommu_assign_device, .teardown = amd_iommu_domain_destroy, .map_page = amd_iommu_map_page, .unmap_page = amd_iommu_unmap_page, + .reassign_device = amd_iommu_return_device, };
xen/arch/x86/hvm/vmx/vtd/intel-iommu.c +1 -0
@@ -2164,6 +2164,7 @@ struct iommu_ops intel_iommu_ops = { .teardown = iommu_domain_teardown, .map_page = intel_iommu_map_page, .unmap_page = intel_iommu_unmap_page, + .reassign_device = reassign_device_ownership, };/*
xen/include/asm-x86/iommu.h +2 -0
@@ -74,6 +74,7 @@ void iommu_domain_destroy(struct domainvoid iommu_domain_destroy (struct domain *d);int device_assigned (u8 bus,u8 devfn);int assign_device (struct domain *d,u8 bus,u8 devfn); +void deassign_device (struct domain *d,u8 bus,u8 devfn);void reassign_device_ownership (struct domain *source,struct domain *target,u8 bus,u8 devfn);
@@ -102,6 +103,7 @@ struct iommu_ops {void (*teardown)(struct domain *d);int (*map_page)(struct domain *d,unsigned long gfn,unsigned long mfn);int (*unmap_page)(struct domain *d,unsigned long gfn); + void (*reassign_device)(struct domain *s, struct domain *t, u8 bus, u8 devfn); };#endif /* _IOMMU_H_ */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 5 lines · Keir Fraser
Quoted 3 lines · Edwin
This patch is the new version against 17051 to enable HVM guest VT-d device hotplug.
Quoted 7 lines
Quoted 4 lines
** Currently only 2 virtual pci slots(6~7) are made as being capable of hotplug,
so more than 2 vtd dev can't be hotplugged, but we can easily extend it in future.Now applied, but perhaps too hastily. I found it broke the !CONFIG_PASSTHROUGH build and in fixing that I noticed that you dumped code
I assumed CONFIG_PASSTHROUGH is always on by default:( So maybe need more #ifdef.
Quoted 3 lines
in a bunch of random places in qemu. Perhaps all passthrough stuff should be gathered in one place? Alternatively at least the device model changes (in
piix4acpi.c) should be decoupled a bit from the backend logic in
Agree with you. passthrough.c manage all the pass-through device info, while piix4acpi.c manage GPE & hotplug controller and call into passthough.c in some condition(say a IO indicating hot removal arrive).
So at least one pair of passthrough function should be in the piix4acpi and ifdef'ed, but we can move all the xenstore logic to it as you said.
Quoted 2 lines
passthrough.c, so the former can cleanly build without the latter. I also killedpt_uninit()because I couldn't even find wherepci_cleanup()was
pci_cleanup() is in the libpci, which should be called for clean up in theory. But things goes well without it.
Quoted 1 line
defined. No passthrough function should be in
vl.c: I #ifdef'ed in the for
Our plan is making this hotplug generic besides passthough device, even for virtual PCI device on native QEMU. So leaving do_pci_add/del in vl.c should be okay like do_usb_xxx.
Quoted 6 lines
now but the functions should probably be moved. And you did a big dump of random crap into
vl.h.-- Keir
Signature · 2 lines
best rgds, edwin
Quoted 5 lines · Edwin
Quoted 2 lines
passthrough.c, so the former can cleanly build without the latter. I also killedpt_uninit()because I couldn't even find wherepci_cleanup()was
pci_cleanup()is in the libpci, which should be called for clean up in theory. But things goes well without it.
Well, you can add it back in then.
Quoted 5 lines
Quoted 1 line
defined. No passthrough function should be in
vl.c: I #ifdef'ed in the forOur plan is making this hotplug generic besides passthough device, even for virtual PCI device on native QEMU. So leaving do_pci_add/del in
vl.cshould be okay likedo_usb_xxx.
Isn't there a generic pci source file where they might more sensibly belong?
-- Keir
Hi,
Just for your information,
I have been working on pass-through PCI device hotplug for PV domains, and now pci-attach/detach for PV domains worked successfully. I think I can submit an RFC patch in a few days.
Thanks,
-----------------
Yosuke Iwamatsu
NEC Corporation
Quoted 39 lines · Edwin
Keir,
This patch is the new version against 17051 to enable HVM guest VT-d device hotplug.
** Currently only 2 virtual pci slots(6~7) are made as being capable of hotplug, so more than 2 vtd dev can't be hotplugged, but we can easily extend it in future.
Three new commands are added:
"xm pci-list domid" show the current assigned vtd device, like:
VSlt domain bus slot func0x60x00x020x000x0"xm pci-detach" hot remove the specified vtd device by the virtual slot, like:
xm pci-detach EdwinHVMDomainVtd 6"xm pci-attach DomainID dom bus dev func [vslot]" hot add a new vtd device in the vslot. If no vslot specified, a free slot will be picked up. e.g. to insert '0000:03:00.0':
xm pci-attach EdwinHVMDomainVtd 0 3 0 0** guest pci hotplug
linux: pls. use 2.6.X and enable ACPI PCI hotplug ( Bus options=> PCI hotplug => ACPI PCI hotplug driver)
windows: 2000/xp/2003/vista are all okayThanks a lot.
------------------------------------------------------------------------
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Thanks for you info.
Did you change the PCI dev config in xend, which is not friendly to hotplug? (only one dev node for all pass-through devices)
Do you have a HVM PV driver for pass-through device?
Thanks,
Quoted 60 lines · Yosuke Iwamatsu
Hi,
Just for your information,
I have been working on pass-through PCI device hotplug for PV domains, and now pci-attach/detach for PV domains worked successfully. I think I can submit an RFC patch in a few days.Thanks,
-----------------
Yosuke Iwamatsu
NEC CorporationQuoted 33 lines · Edwin
Keir,
This patch is the new version against 17051 to enable HVM guest VT-d device hotplug.
** Currently only 2 virtual pci slots(6~7) are made as being capable of hotplug, so more than 2 vtd dev can't be hotplugged, but we can easily extend it in future.
Three new commands are added:
"xm pci-list domid" show the current assigned vtd device, like:
VSlt domain bus slot func0x60x00x020x000x0"xm pci-detach" hot remove the specified vtd device by the virtual slot, like:
xm pci-detach EdwinHVMDomainVtd 6"xm pci-attach DomainID dom bus dev func [vslot]" hot add a new vtd device in the vslot. If no vslot specified, a free slot will be picked up. e.g. to insert '0000:03:00.0':
xm pci-attach EdwinHVMDomainVtd 0 3 0 0** guest pci hotplug
linux: pls. use 2.6.X and enable ACPI PCI hotplug ( Bus options=> PCI hotplug => ACPI PCI hotplug driver)
windows: 2000/xp/2003/vista are all okayThanks a lot.
Quoted 6 lines
------------------------------------------------------------------------
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Signature · 2 lines
best rgds, edwin
PATCH 1/1 pass-through PCI device hotplug support
Quoted 4 lines · Edwin
Thanks for you info.
Did you change the PCI dev config in xend, which is not friendly to hotplug? (only one dev node for all pass-through devices)
No, I left it as it was.
Quoted 2 lines
Do you have a HVM PV driver for pass-through device?
No, I included hotplug handling methods in pcifront driver which work only on PV linux.
Thanks,
----------
Yosuke
Quoted 60 lines
Thanks,
Quoted 53 lines · Yosuke Iwamatsu
Hi,
Just for your information,
I have been working on pass-through PCI device hotplug for PV domains, and now pci-attach/detach for PV domains worked successfully. I think I can submit an RFC patch in a few days.Thanks,
-----------------
Yosuke Iwamatsu
NEC CorporationQuoted 27 lines · Edwin
Keir,
This patch is the new version against 17051 to enable HVM guest VT-d device hotplug.
** Currently only 2 virtual pci slots(6~7) are made as being capable of hotplug, so more than 2 vtd dev can't be hotplugged, but we can easily extend it in future.
Three new commands are added:
"xm pci-list domid" show the current assigned vtd device, like:
VSlt domain bus slot func0x60x00x020x000x0"xm pci-detach" hot remove the specified vtd device by the virtual slot, like:
xm pci-detach EdwinHVMDomainVtd 6"xm pci-attach DomainID dom bus dev func [vslot]" hot add a new vtd device in the vslot. If no vslot specified, a free slot will be picked up. e.g. to insert '0000:03:00.0':
xm pci-attach EdwinHVMDomainVtd 0 3 0 0** guest pci hotplug
linux: pls. use 2.6.X and enable ACPI PCI hotplug ( Bus options=> PCI hotplug => ACPI PCI hotplug driver)
windows: 2000/xp/2003/vista are all okayThanks a lot.
Quoted 6 lines
------------------------------------------------------------------------
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel