qemu-trad: stop using the default IOREQ server
PATCH 1/1 qemu-trad: stop using the default IOREQ server
Because qemu-trad is using the legacy HVM param mechanism of hooking into Xen, it means that Xen has to maintain the notion of a 'default' IOREQ server which is where all I/O goes if no other device model claims it. Maintaining this code in Xen has a cost and it would be good if the project no longer had to pay it.
This patch makes the necessary minimal changes to the qemu-trad to use the IOREQ server API to hook into Xen. This means the default IOREQ server will no longer be in use and thus it no longer needs to be maintained.
---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
--- hw/pci.c | 3 +++ hw/xen_machine_fv.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++------ i386-dm/exec-dm.c | 10 ++++--- i386-dm/helper2.c | 30 +++++++++++++++------ qemu-xen.h | 8 ++++++ 5 files changed, 107 insertions(+), 19 deletions(-)
hw/pci.c +3 -0
@@ -263,6 +263,8 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name, pci_dev->config_write = config_write; bus->devices[devfn] = pci_dev; pci_dev->irq =qemu_allocate_irqs (pci_set_irq, pci_dev,4 ); + +map_pci_dev (pci_dev->devfn);return pci_dev; }
@@ -305,6 +307,7 @@ int pci_unregister_device(PCIDevice *pci_dev) {int ret =0 ; +unmap_pci_dev (pci_dev->devfn);if (pci_dev->unregister) ret = pci_dev->unregister (pci_dev);if (ret)
hw/xen_machine_fv.c +67 -8
117 lines not on this page · raw message
i386-dm/exec-dm.c +7 -3
@@ -294,8 +294,10 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr,for (i =0 ; i < mmio_cnt; i++) {if (mmio[i].start == start_addr) { +unmap_mmio_range (start_addr, mmio[i].size); mmio[i].io_index = phys_offset; mmio[i].size = size; +map_mmio_range (start_addr, size);return ; } }
@@ -308,6 +310,7 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr, mmio[mmio_cnt].io_index = phys_offset; mmio[mmio_cnt].start = start_addr; mmio[mmio_cnt++].size = size; +map_mmio_range (start_addr, size); }static int get_free_io_mem_idx (void )
@@ -360,9 +363,10 @@ void cpu_unregister_io_memory(int io_table_address)int io_index = io_table_address >>IO_MEM_SHIFT ;for (i =0 ; i < mmio_cnt; i++) { -if (mmio[i].io_index == io_index) { - mmio[i].start = mmio[i].size =0 ; -break ; +if (mmio[i].io_index == io_index) { +unmap_mmio_range (mmio[i].start, mmio[i].size); + mmio[i].start = mmio[i].size =0 ; +break ; } }
i386-dm/helper2.c +22 -8
@@ -98,6 +98,10 @@ int domid_backend = 0;long time_offset =0 ; +xen_pfn_t ioreq_pfn; +xen_pfn_t bufioreq_pfn; +evtchn_port_t bufioreq_evtchn; +shared_iopage_t *shared_page =NULL ;#define BUFFER_IO_MAX_DELAY 100
@@ -120,7 +124,6 @@ CPUX86State *cpu_x86_init(const char *cpu_model)CPUX86State *env;static int inited;int i, rc; -unsigned long bufioreq_evtchn; env =qemu_mallocz (sizeof (CPUX86State));if (!env)
@@ -158,13 +161,6 @@ CPUX86State *cpu_x86_init(const char *cpu_model) } ioreq_local_port[i] = rc; } - rc =xc_get_hvm_param (xc_handle, domid,HVM_PARAM_BUFIOREQ_EVTCHN , - &bufioreq_evtchn); -if (rc <0 ) { -fprintf (logfile,"failed to get HVM_PARAM_BUFIOREQ_EVTCHN error=%d\n" , - errno); -return NULL ; - } rc =xenevtchn_bind_interdomain (xce_handle, domid, (uint32_t )bufioreq_evtchn);if (rc ==-1 ) {fprintf (logfile,"bind interdomain ioctl error %d\n" , errno);
@@ -489,6 +485,22 @@ static void __handle_ioreq(CPUState *env, ioreq_t *req)case IOREQ_TYPE_INVALIDATE :qemu_invalidate_map_cache ();break ; +case IOREQ_TYPE_PCI_CONFIG : { +uint32_t sbdf = req->addr >>32 ; +uint32_t val; + +/* Fake out to 0xcf8 */ + val = (1u <<31 ) | + ((req->addr &0x0f00 ) <<16 ) | + ((sbdf &0xffff ) <<8 ) | + (req->addr &0xfc ); +do_outp (env,0xcf8 ,4 , val); + +/* Now fake I/O to 0xcfc */ + req->addr =0xcfc | (req->addr &0x03 ); +cpu_ioreq_pio (env, req); +break ; + }default :hw_error ("Invalid ioreq type 0x%x\n" , req->type); }
@@ -645,6 +657,7 @@ int main_loop(void)/* Save the device state */ asprintf (&qemu_file,"/var/lib/xen/qemu-save.%d" , domid); +xen_disable_io ();do_savevm (qemu_file);free (qemu_file);
@@ -658,6 +671,7 @@ int main_loop(void)xenstore_process_event (NULL ); } +xen_enable_io ();xenstore_record_dm_state ("running" ); }
qemu-xen.h +8 -0
@@ -138,4 +138,12 @@ int has_tpm_device_danger(void);static void vga_dirty_log_start (void *s) { }static void vga_dirty_log_stop (void *s) { } +void xen_enable_io (void ); +void xen_disable_io (void ); + +void map_mmio_range (target_phys_addr_t start_addr,ram_addr_t size); +void unmap_mmio_range (target_phys_addr_t start_addr,ram_addr_t size); +void map_pci_dev (int devfn); +void unmap_pci_dev (int devfn); +#endif /*QEMU_XEN_H*/
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Paul Durrant
Because qemu-trad is using the legacy HVM param mechanism of hooking into Xen, it means that Xen has to maintain the notion of a 'default' IOREQ server which is where all I/O goes if no other device model claims it. Maintaining this code in Xen has a cost and it would be good if the project no longer had to pay it.
This patch makes the necessary minimal changes to the qemu-trad to use the IOREQ server API to hook into Xen. This means the default IOREQ server will no longer be in use and thus it no longer needs to be maintained.
Signed-off-by Paul Durrant <[email protected]>
While qemu-trad is supposed to be in deep-freeze, this small change will allow for substantial cleanup and simplification in the hypervisor.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Paul Durrant writes ("[PATCH] qemu-trad: stop using the default IOREQ server"):
Quoted 9 lines
Because qemu-trad is using the legacy HVM param mechanism of hooking into Xen, it means that Xen has to maintain the notion of a 'default' IOREQ server which is where all I/O goes if no other device model claims it. Maintaining this code in Xen has a cost and it would be good if the project no longer had to pay it.
This patch makes the necessary minimal changes to the qemu-trad to use the IOREQ server API to hook into Xen. This means the default IOREQ server will no longer be in use and thus it no longer needs to be maintained.
That is a good thing.
I looked overr the patch. Most of it is about what I would have expected.
But I did want to query this:
Quoted 6 lines
i386-dm/helper2.c +6
-0+case IOREQ_TYPE_PCI_CONFIG : { +uint32_t sbdf = req->addr >>32 ; +uint32_t val; + +/* Fake out to 0xcf8 */ + val = (1u << 31) |
i386-dm/helper2.c static void __handle_ioreq(CPUState *env, ioreq_t *req) · line 503
Quoted 10 lines
i386-dm/helper2.c +10
-0+ ((req->addr &0x0f00 ) <<16 ) | + ((sbdf &0xffff ) <<8 ) | + (req->addr &0xfc ); +do_outp (env,0xcf8 ,4 , val); + +/* Now fake I/O to 0xcfc */ + req->addr =0xcfc | (req->addr &0x03 ); +cpu_ioreq_pio (env, req); +break ; + }
This looks messy. Can someone please explain why this is needed and why it is best to do it this way ?
(I'm don't know much about PCI, which is probably a contributory factor in my querying this. Sorry about that.)
Regards,
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/1 qemu-trad: stop using the default IOREQ server
Quoted 36 lines · Ian Jackson
Paul Durrant writes ("[PATCH] qemu-trad: stop using the default IOREQ server"):
Quoted 9 lines
Because qemu-trad is using the legacy HVM param mechanism of hooking into Xen, it means that Xen has to maintain the notion of a 'default' IOREQ server which is where all I/O goes if no other device model claims it. Maintaining this code in Xen has a cost and it would be good if the project no longer had to pay it.
This patch makes the necessary minimal changes to the qemu-trad to use the IOREQ server API to hook into Xen. This means the default IOREQ server will no longer be in use and thus it no longer needs to be maintained.
That is a good thing.
I looked overr the patch. Most of it is about what I would have expected.
But I did want to query this:
Quoted 6 lines
i386-dm/helper2.c +6
-0+case IOREQ_TYPE_PCI_CONFIG : { +uint32_t sbdf = req->addr >>32 ; +uint32_t val; + +/* Fake out to 0xcf8 */ + val = (1u << 31) |i386-dm/helper2.c static void __handle_ioreq(CPUState *env, ioreq_t *req) · line 503
Quoted 10 lines
i386-dm/helper2.c +10
-0+ ((req->addr &0x0f00 ) <<16 ) | + ((sbdf &0xffff ) <<8 ) | + (req->addr &0xfc ); +do_outp (env,0xcf8 ,4 , val); + +/* Now fake I/O to 0xcfc */ + req->addr =0xcfc | (req->addr &0x03 ); +cpu_ioreq_pio (env, req); +break ; + }This looks messy. Can someone please explain why this is needed and why it is best to do it this way ?
Quoted 2 lines
(I'm don't know much about PCI, which is probably a contributory factor in my querying this. Sorry about that.)
Paul is OoO for a while, so replying on his behalf.
Qemu-trad has no support for MMCFG, which is the memory mapped interface which supersedes the more legacy cfc/cf8 handling for PCI config space accesses.
Xen's interface passes the requisite information in MMCFG format, which is the most efficient way to do it. This piece of (admittedly messy) code converts the information to the legacy interface which is the one which Qemu understands.
tl;dr, It's messy, but it is correct, and is the best (/only, short of implementing MMCFG support in qemu-trad) way of doing it.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Andrew Cooper writes ("[PATCH] qemu-trad: stop using the default IOREQ server"):
Quoted 1 line
Paul is OoO for a while, so replying on his behalf.
Thank you.
Quoted 11 lines
Qemu-trad has no support for MMCFG, which is the memory mapped interface which supersedes the more legacy cfc/cf8 handling for PCI config space accesses.
Xen's interface passes the requisite information in MMCFG format, which is the most efficient way to do it. This piece of (admittedly messy) code converts the information to the legacy interface which is the one which Qemu understands.
tl;dr, It's messy, but it is correct, and is the best (/only, short of implementing MMCFG support in qemu-trad) way of doing it.
Thanks for this excelent explanation. Can you please add it to the commit message and/or to a comment in the code ? You may then add my ack. I will then commit the patch :-).
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel