xen-hvm: stop faking I/O to access PCI config space
PATCH 1/1 xen-hvm: stop faking I/O to access PCI config space
This patch removes the current hackery where IOREQ_TYPE_PCI_CONFIG reqyests are handled by faking PIO to 0xcf8 and 0xcfc and replaces it with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.
NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit to PCIE_CONFIG_SPACE_SIZE when Xen gains the ability to emulate MCFG table accesses.
--
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
--- hw/i386/xen/trace-events | 2 + hw/i386/xen/xen-hvm.c | 101 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 20 deletions(-)
hw/i386/xen/trace-events +2 -0
@@ -15,6 +15,8 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, uint64 cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t size) "I/O=%p pio read reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t size) "I/O=%p pio write reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_move(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=%p copy dir=%d df=%d ptr=%d port=0x%"PRIx64" data=0x%"PRIx64" count=%d size=%d" +cpu_ioreq_config_read(void *req, uint32_t sbdf, uint32_t reg, uint32_t size, uint32_t data) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" +cpu_ioreq_config_write(void *req, uint32_t sbdf, uint32_t reg, uint32_t size, uint32_t data) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" # xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64
hw/i386/xen/xen-hvm.c +81 -20
152 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 5 lines · Paul Durrant
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.
No objection!
Thanks,
Paolo
Quoted 190 lines
NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to emulate MCFG table accesses.Signed-off-by Paul Durrant <[email protected]>--
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>--- hw/i386/xen/trace-events | 2 + hw/i386/xen/xen-hvm.c | 101 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 20 deletions(-)hw/i386/xen/trace-events +2
-0@@ -15,6 +15,8 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, uint64 cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t size) "I/O=%p pio read reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t size) "I/O=%p pio write reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_move(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=%p copy dir=%d df=%d ptr=%d port=0x%"PRIx64" data=0x%"PRIx64" count=%d size=%d" +cpu_ioreq_config_read(void *req, uint32_t sbdf, uint32_t reg, uint32_t size, uint32_t data) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" +cpu_ioreq_config_write(void *req, uint32_t sbdf, uint32_t reg, uint32_t size, uint32_t data) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" # xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64hw/i386/xen/xen-hvm.c +80
-20@@ -12,6 +12,7 @@#include "cpu.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "hw/xen/xen_common.h" @@ -86,6 +87,12 @@ typedef struct XenPhysmap {QLIST_ENTRY (XenPhysmap) list; } XenPhysmap; +typedef struct XenPciDevice { +PCIDevice *pci_dev; +uint32_t sbdf; +QLIST_ENTRY (XenPciDevice) entry; +}XenPciDevice ; + typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page;@@ -105,6 +112,7 @@ typedef struct XenIOState {struct xs_handle *xenstore;MemoryListener memory_listener;MemoryListener io_listener; + QLIST_HEAD(, XenPciDevice) dev_list;DeviceListener device_listener; QLIST_HEAD(, XenPhysmap) physmap;hwaddr free_phys_offset;@@ -569,6 +577,12 @@ static void xen_device_realize(DeviceListener *listener,if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev =g_new (XenPciDevice,1 ); + + xendev->pci_dev = pci_dev; + xendev->sbdf =PCI_BUILD_BDF (pci_dev_bus_num (pci_dev), + pci_dev->devfn); +QLIST_INSERT_HEAD (&state->dev_list, xendev, entry);xen_map_pcidev (xen_domid, state->ioservid, pci_dev); }@@ -581,8 +595,17 @@ static void xen_device_unrealize(DeviceListener *listener,if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev, *next;xen_unmap_pcidev (xen_domid, state->ioservid, pci_dev); + + QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { +if (xendev->pci_dev == pci_dev) { +QLIST_REMOVE (xendev, entry); +g_free (xendev); +break ; + } + } } }@@ -903,6 +926,61 @@ static void cpu_ioreq_move(ioreq_t *req) } } +static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) { +if (!req->data_is_ptr) { + req->data =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +trace_cpu_ioreq_config_read (req, sbdf, reg, req->size, + req->data); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp; + + tmp =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +write_phys_req_item (req->data, req, i, &tmp); + } + } + }else if (req->dir ==IOREQ_WRITE ) { +if (!req->data_is_ptr) { +trace_cpu_ioreq_config_write (req, sbdf, reg, req->size, + req->data); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , req->data, + req->size); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp =0 ; + +read_phys_req_item (req->data, req, i, &tmp); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , tmp, + req->size); + } + } + } + } +} +static void regs_to_cpu (vmware_regs_t *vmport_regs,ioreq_t *req) {X86CPU *cpu;@@ -975,27 +1053,9 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)case IOREQ_TYPE_INVALIDATE :xen_invalidate_map_cache ();break ; -case IOREQ_TYPE_PCI_CONFIG : { -uint32_t sbdf = req->addr >>32 ; -uint32_t val; - -/* Fake a write to port 0xCF8 so that -* the config space access will target the -* correct device model. -*/ - val = (1u <<31 ) | - ((req->addr &0x0f00 ) <<16 ) | - ((sbdf &0xffff ) <<8 ) | - (req->addr &0xfc ); -do_outp (0xcf8 ,4 , val); - -/* Now issue the config space access via -* port 0xCFC -*/ - req->addr =0xcfc | (req->addr &0x03 ); -cpu_ioreq_pio (req); +case IOREQ_TYPE_PCI_CONFIG : +cpu_ioreq_config (state, req);break ; - }default :hw_error ("Invalid ioreq type 0x%x\n" , req->type); }
hw/i386/xen/xen-hvm.c void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) · line 1432
Quoted 7 lines
hw/i386/xen/xen-hvm.c +1
-0@@ -1366,6 +1426,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)memory_listener_register (&state->io_listener, &address_space_io); state->device_listener = xen_device_listener; +QLIST_INIT (&state->dev_list);device_listener_register (&state->device_listener);/* Initialize backend core & drivers */
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · On Thu, 3 May 2018 12:18:40 +0100 Paul Durrant <[email protected]> wrote:
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.
Quoted 6 lines
NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to emulate MCFG table accesses.Signed-off-by Paul Durrant <[email protected]>
Minor problem here is a possible incompatibility with PCI-PCI bridges which we'll need to use eventually for Q35 PT -- IIRC changing secondary bus numbers do not cause unrealize/realize pair to be called for affected PCI devices. This means that dev_list may contain stale BDF information if any related bus number change.
Anyway, PCI-PCI bridges and their secondary bus numbers must be handled specifically, so it can be ignored for now.
I'll try to reuse this patch for my Xen patch for supporting MMCONFIG ioreq forwarding to multiple ioreq servers.
Quoted 206 lines
--
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
---
hw/i386/xen/trace-events | 2 +hw/i386/xen/xen-hvm.c| 101
+++++++++++++++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 20 deletions(-)hw/i386/xen/trace-events +0
-0@@ -15,6 +15,8 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df,
uint32_tdata_is_ptr, uint64cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t size)"I/O=%p pio read reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d"cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t size)"I/O=%p pio write reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_move(void *req,uint32_tdir,uint32_tdf,uint32_tdata_is_ptr,uint64_taddr,uint64_tdata,uint32_tcount,uint32_tsize) "I/O=%p copy dir=%d df=%d ptr=%d port=0x%"PRIx64" data=0x%"PRIx64" count=%d size=%d" +cpu_ioreq_config_read(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" +cpu_ioreq_config_write(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x"# xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64hw/i386/xen/xen-hvm.c +14
-0@@ -12,6 +12,7 @@#include "cpu.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "hw/xen/xen_common.h" @@ -86,6 +87,12 @@ typedef struct XenPhysmap {QLIST_ENTRY (XenPhysmap) list; } XenPhysmap; +typedef struct XenPciDevice { +PCIDevice *pci_dev; +uint32_t sbdf; +QLIST_ENTRY (XenPciDevice) entry; +}XenPciDevice ; + typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page;@@ -105,6 +112,7 @@ typedef struct XenIOState {struct xs_handle *xenstore;MemoryListener memory_listener;MemoryListener io_listener; + QLIST_HEAD(, XenPciDevice) dev_list;DeviceListener device_listener; QLIST_HEAD(, XenPhysmap) physmap;hwaddr free_phys_offset;@@ -569,6 +577,12 @@ static void xen_device_realize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev =g_new (XenPciDevice,1 ); + + xendev->pci_dev = pci_dev; + xendev->sbdf =PCI_BUILD_BDF (pci_dev_bus_num (pci_dev), + pci_dev->devfn); +QLIST_INSERT_HEAD (&state->dev_list, xendev, entry);xen_map_pcidev (xen_domid, state->ioservid, pci_dev);}hw/i386/xen/xen-hvm.c +64
-0@@ -581,8 +595,17 @@ static void xen_device_unrealize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev, *next;xen_unmap_pcidev (xen_domid, state->ioservid, pci_dev); + + QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { +if (xendev->pci_dev == pci_dev) { +QLIST_REMOVE (xendev, entry); +g_free (xendev); +break ; + } + } } }@@ -903,6 +926,61 @@ static void cpu_ioreq_move(ioreq_t *req) } } +static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) { +if (!req->data_is_ptr) { + req->data =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +trace_cpu_ioreq_config_read (req, sbdf, reg, req->size, + req->data); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp; + + tmp =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +write_phys_req_item (req->data, req, i, &tmp); + } + } + }else if (req->dir ==IOREQ_WRITE ) { +if (!req->data_is_ptr) { +trace_cpu_ioreq_config_write (req, sbdf, reg, req->size, + req->data); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , req->data, + req->size); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp =0 ; + +read_phys_req_item (req->data, req, i, &tmp); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , tmp, + req->size); + } + } + } + } +} +static void
regs_to_cpu(vmware_regs_t *vmport_regs, ioreq_t *req){ X86CPU *cpu;hw/i386/xen/xen-hvm.c +2
-20@@ -975,27 +1053,9 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)case IOREQ_TYPE_INVALIDATE :xen_invalidate_map_cache ();break ; -case IOREQ_TYPE_PCI_CONFIG : { -uint32_t sbdf = req->addr >>32 ; -uint32_t val; - -/* Fake a write to port 0xCF8 so that -* the config space access will target the -* correct device model. -*/ - val = (1u <<31 ) | - ((req->addr &0x0f00 ) <<16 ) | - ((sbdf &0xffff ) <<8 ) | - (req->addr &0xfc ); -do_outp (0xcf8 ,4 , val); - -/* Now issue the config space access via -* port 0xCFC -*/ - req->addr =0xcfc | (req->addr &0x03 ); -cpu_ioreq_pio (req); +case IOREQ_TYPE_PCI_CONFIG : +cpu_ioreq_config (state, req);break ; - }default :hw_error ("Invalid ioreq type 0x%x\n" , req->type);}hw/i386/xen/xen-hvm.c +1
-0@@ -1366,6 +1426,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) memory_listener_register(&state->io_listener, &address_space_io); state->device_listener = xen_device_listener; +QLIST_INIT (&state->dev_list);device_listener_register (&state->device_listener);
Quoted 1 line
/* Initialize backend core & drivers */
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 27 lines
-----Original Message-----
From: Alexey G [mailto:[email protected]]
Sent: 03 May 2018 13:41
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; Stefano Stabellini <[email protected]>; Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Marcel Apfelbaum <[email protected]>; Anthony Perard <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [Qemu-devel] [PATCH] xen-hvm: stop faking I/O to access PCI config spaceQuoted 11 lines · On Thu, 3 May 2018 12:18:40 +0100 Paul Durrant <[email protected]> wrote:
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to emulate MCFG table accesses.
Quoted 7 lines
Quoted 1 line
Signed-off-by Paul Durrant <[email protected]>Minor problem here is a possible incompatibility with PCI-PCI bridges which we'll need to use eventually for Q35 PT -- IIRC changing secondary bus numbers do not cause unrealize/realize pair to be called for affected PCI devices. This means that
dev_listmay contain stale BDF information if any related bus number change.
It also means that emulation won't work in general since, unless the devices are re-registered with Xen under their new BDFs things are not going to get steered correctly. This patch will not change that behaviour so no regression is introduced by removing the I/O fakery.
Quoted 4 lines
Anyway, PCI-PCI bridges and their secondary bus numbers must be handled specifically, so it can be ignored for now.
As we're discussed before, Xen needs to own the topology so it knows what's going on.
Quoted 3 lines
I'll try to reuse this patch for my Xen patch for supporting MMCONFIG ioreq forwarding to multiple ioreq servers.
It should be ok (with the increased limit of course).
Paul
Quoted 203 lines
Quoted 4 lines
--
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>Quoted 8 lines
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
---
hw/i386/xen/trace-events | 2 +hw/i386/xen/xen-hvm.c| 101
+++++++++++++++++++++++++++++++++++++---------- 2 files changed,83
Quoted 190 lines
insertions(+), 20 deletions(-)
hw/i386/xen/trace-events +0
-0@@ -15,6 +15,8 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df,
uint32_tdata_is_ptr, uint64cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t size)"I/O=%p pio read reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d"cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t size)"I/O=%p pio write reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_move(void *req,uint32_tdir,uint32_tdf,uint32_tdata_is_ptr,uint64_taddr,uint64_tdata,uint32_tcount,uint32_tsize) "I/O=%p copy dir=%d df=%d ptr=%d port=0x%"PRIx64" data=0x%"PRIx64" count=%d size=%d" +cpu_ioreq_config_read(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" +cpu_ioreq_config_write(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x"# xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64hw/i386/xen/xen-hvm.c +14
-0@@ -12,6 +12,7 @@#include "cpu.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "hw/xen/xen_common.h" @@ -86,6 +87,12 @@ typedef struct XenPhysmap {QLIST_ENTRY (XenPhysmap) list; } XenPhysmap; +typedef struct XenPciDevice { +PCIDevice *pci_dev; +uint32_t sbdf; +QLIST_ENTRY (XenPciDevice) entry; +}XenPciDevice ; + typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page;@@ -105,6 +112,7 @@ typedef struct XenIOState {struct xs_handle *xenstore;MemoryListener memory_listener;MemoryListener io_listener; + QLIST_HEAD(, XenPciDevice) dev_list;DeviceListener device_listener; QLIST_HEAD(, XenPhysmap) physmap;hwaddr free_phys_offset;@@ -569,6 +577,12 @@ static void xen_device_realize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev =g_new (XenPciDevice,1 ); + + xendev->pci_dev = pci_dev; + xendev->sbdf =PCI_BUILD_BDF (pci_dev_bus_num (pci_dev), + pci_dev->devfn); +QLIST_INSERT_HEAD (&state->dev_list, xendev, entry);xen_map_pcidev (xen_domid, state->ioservid, pci_dev);}hw/i386/xen/xen-hvm.c +64
-0@@ -581,8 +595,17 @@ static void xen_device_unrealize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev, *next;xen_unmap_pcidev (xen_domid, state->ioservid, pci_dev); + + QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { +if (xendev->pci_dev == pci_dev) { +QLIST_REMOVE (xendev, entry); +g_free (xendev); +break ; + } + } } }@@ -903,6 +926,61 @@ static void cpu_ioreq_move(ioreq_t *req) } } +static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) { +if (!req->data_is_ptr) { + req->data =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +trace_cpu_ioreq_config_read (req, sbdf, reg, req->size, + req->data); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp; + + tmp =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +write_phys_req_item (req->data, req, i, &tmp); + } + } + }else if (req->dir ==IOREQ_WRITE ) { +if (!req->data_is_ptr) { +trace_cpu_ioreq_config_write (req, sbdf, reg, req->size, + req->data); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , req->data, + req->size); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp =0 ; + +read_phys_req_item (req->data, req, i, &tmp); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , tmp, + req->size); + } + } + } + } +} +static void
regs_to_cpu(vmware_regs_t *vmport_regs, ioreq_t *req){ X86CPU *cpu;hw/i386/xen/xen-hvm.c +2
-20@@ -975,27 +1053,9 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)case IOREQ_TYPE_INVALIDATE :xen_invalidate_map_cache ();break ; -case IOREQ_TYPE_PCI_CONFIG : { -uint32_t sbdf = req->addr >>32 ; -uint32_t val; - -/* Fake a write to port 0xCF8 so that -* the config space access will target the -* correct device model. -*/ - val = (1u <<31 ) | - ((req->addr &0x0f00 ) <<16 ) | - ((sbdf &0xffff ) <<8 ) | - (req->addr &0xfc ); -do_outp (0xcf8 ,4 , val); - -/* Now issue the config space access via -* port 0xCFC -*/ - req->addr =0xcfc | (req->addr &0x03 ); -cpu_ioreq_pio (req); +case IOREQ_TYPE_PCI_CONFIG : +cpu_ioreq_config (state, req);break ; - }default :hw_error ("Invalid ioreq type 0x%x\n" , req->type);}hw/i386/xen/xen-hvm.c +0
-0@@ -1366,6 +1426,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) memory_listener_register(&state->io_listener, &address_space_io);
Quoted 5 lines
Quoted 5 lines
hw/i386/xen/xen-hvm.c +1
-0state->device_listener = xen_device_listener; +QLIST_INIT (&state->dev_list);device_listener_register (&state->device_listener);/* Initialize backend core & drivers */
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 19 lines · On Thu, 3 May 2018 12:49:59 +0000 Paul Durrant <[email protected]> wrote:
Quoted 11 lines
Quoted 11 lines
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing
the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to
emulate MCFG table accesses.Quoted 7 lines
Quoted 1 line
Signed-off-by Paul Durrant <[email protected]>Minor problem here is a possible incompatibility with PCI-PCI bridges which we'll need to use eventually for Q35 PT -- IIRC changing secondary bus numbers do not cause unrealize/realize pair to be called for affected PCI devices. This means that
dev_listmay contain stale BDF information if any related bus number change.
Quoted 4 lines
It also means that emulation won't work in general since, unless the devices are re-registered with Xen under their new BDFs things are not going to get steered correctly. This patch will not change that behaviour so no regression is introduced by removing the I/O fakery.
Completely agree, this was what I meant by "PCI-PCI bridges must be handled specifically".
Quoted 5 lines
Quoted 4 lines
Anyway, PCIPCI bridges and their secondary bus numbers must be handled specifically, so it can be ignored for now.
Quoted 8 lines
As we're discussed before, Xen needs to own the topology so it knows what's going on.
Quoted 3 lines
I'll try to reuse this patch for my Xen patch for supporting MMCONFIG ioreq forwarding to multiple ioreq servers.
It should be ok (with the increased limit of course).
I've adjusted limits for PCI conf size in one of Q35 RFC patches (which are still waiting for review):
xen/pt: add support for PCIe Extended Capabilities and larger config space
http://lists.gnu.org/archive/html/qemu-devel/2018-03/msg03594.html
Also, for hw/xen/xen-pt*.c one patch from upstream QEMU needed which currently still missing in the qemu-xen repo. (the one which defaults is_express for 'xen-pci-passthrough' devices). Otherwise new limits won't work due to is_express=0.
Quoted 209 lines
Paul
Quoted 207 lines
Quoted 4 lines
--
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>Quoted 8 lines
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
---
hw/i386/xen/trace-events | 2 +hw/i386/xen/xen-hvm.c| 101
+++++++++++++++++++++++++++++++++++++---------- 2 files changed,83
Quoted 194 lines
insertions(+), 20 deletions(-)
hw/i386/xen/trace-events +0
-0@@ -15,6 +15,8 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_tdf,
uint32_tdata_is_ptr, uint64cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t size)"I/O=%p pio read reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d"cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t size)"I/O=%p pio write reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_move(void *req,uint32_tdir,uint32_tdf,uint32_tdata_is_ptr,uint64_taddr,uint64_tdata,uint32_tcount,uint32_tsize) "I/O=%p copy dir=%d df=%d ptr=%d port=0x%"PRIx64" data=0x%"PRIx64" count=%d size=%d"
+cpu_ioreq_config_read(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" +cpu_ioreq_config_write(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x"# xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64hw/i386/xen/xen-hvm.c +14
-0@@ -12,6 +12,7 @@#include "cpu.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "hw/xen/xen_common.h" @@ -86,6 +87,12 @@ typedef struct XenPhysmap {QLIST_ENTRY (XenPhysmap) list; } XenPhysmap; +typedef struct XenPciDevice { +PCIDevice *pci_dev; +uint32_t sbdf; +QLIST_ENTRY (XenPciDevice) entry; +}XenPciDevice ; + typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page;@@ -105,6 +112,7 @@ typedef struct XenIOState {struct xs_handle *xenstore;MemoryListener memory_listener;MemoryListener io_listener; + QLIST_HEAD(, XenPciDevice) dev_list;DeviceListener device_listener; QLIST_HEAD(, XenPhysmap) physmap;hwaddr free_phys_offset;@@ -569,6 +577,12 @@ static void xen_device_realize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev =g_new (XenPciDevice,1 ); + + xendev->pci_dev = pci_dev; + xendev->sbdf =PCI_BUILD_BDF (pci_dev_bus_num (pci_dev), + pci_dev->devfn); +QLIST_INSERT_HEAD (&state->dev_list, xendev, entry);xen_map_pcidev (xen_domid, state->ioservid, pci_dev);}hw/i386/xen/xen-hvm.c +49
-0@@ -581,8 +595,17 @@ static void xen_device_unrealize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev, *next;xen_unmap_pcidev (xen_domid, state->ioservid, pci_dev); + + QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { +if (xendev->pci_dev == pci_dev) { +QLIST_REMOVE (xendev, entry); +g_free (xendev); +break ; + } + } } }@@ -903,6 +926,61 @@ static void cpu_ioreq_move(ioreq_t *req) } } +static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) { +if (!req->data_is_ptr) { + req->data =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +trace_cpu_ioreq_config_read (req, sbdf, reg, req->size, + req->data); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp; + + tmp =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +write_phys_req_item (req->data, req, i, &tmp); + } + } + }else if (req->dir ==IOREQ_WRITE ) { +if (!req->data_is_ptr) { +trace_cpu_ioreq_config_write (req, sbdf, reg, req->size, + req->data); + pci_host_config_write_common( + xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE,
req->data,hw/i386/xen/xen-hvm.c +8
-0+ req->size); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp =0 ; + +read_phys_req_item (req->data, req, i, &tmp); + pci_host_config_write_common( + xendev->pci_dev, reg,
PCI_CONFIG_SPACE_SIZE, tmp,hw/i386/xen/xen-hvm.c +7
-0+ req->size); + } + } + } + } +} +static void
regs_to_cpu(vmware_regs_t *vmport_regs, ioreq_t *req){ X86CPU *cpu;hw/i386/xen/xen-hvm.c +2
-20@@ -975,27 +1053,9 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)case IOREQ_TYPE_INVALIDATE :xen_invalidate_map_cache ();break ; -case IOREQ_TYPE_PCI_CONFIG : { -uint32_t sbdf = req->addr >>32 ; -uint32_t val; - -/* Fake a write to port 0xCF8 so that -* the config space access will target the -* correct device model. -*/ - val = (1u <<31 ) | - ((req->addr &0x0f00 ) <<16 ) | - ((sbdf &0xffff ) <<8 ) | - (req->addr &0xfc ); -do_outp (0xcf8 ,4 , val); - -/* Now issue the config space access via -* port 0xCFC -*/ - req->addr =0xcfc | (req->addr &0x03 ); -cpu_ioreq_pio (req); +case IOREQ_TYPE_PCI_CONFIG : +cpu_ioreq_config (state, req);break ; - }default :hw_error ("Invalid ioreq type 0x%x\n" , req->type);}hw/i386/xen/xen-hvm.c +0
-0@@ -1366,6 +1426,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) memory_listener_register(&state->io_listener, &address_space_io);
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
hw/i386/xen/xen-hvm.c +1
-0state->device_listener = xen_device_listener; +QLIST_INIT (&state->dev_list);device_listener_register (&state->device_listener);/* Initialize backend core & drivers */
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 19 lines · On Thu, 3 May 2018 12:49:59 +0000 Paul Durrant <[email protected]> wrote:
Quoted 11 lines
Quoted 11 lines
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing
the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to
emulate MCFG table accesses.Quoted 7 lines
Quoted 1 line
Signed-off-by Paul Durrant <[email protected]>Minor problem here is a possible incompatibility with PCI-PCI bridges which we'll need to use eventually for Q35 PT -- IIRC changing secondary bus numbers do not cause unrealize/realize pair to be called for affected PCI devices. This means that
dev_listmay contain stale BDF information if any related bus number change.
Quoted 4 lines
It also means that emulation won't work in general since, unless the devices are re-registered with Xen under their new BDFs things are not going to get steered correctly. This patch will not change that behaviour so no regression is introduced by removing the I/O fakery.
Completely agree, this was what I meant by "PCI-PCI bridges must be handled specifically".
Quoted 5 lines
Quoted 4 lines
Anyway, PCIPCI bridges and their secondary bus numbers must be handled specifically, so it can be ignored for now.
Quoted 8 lines
As we're discussed before, Xen needs to own the topology so it knows what's going on.
Quoted 3 lines
I'll try to reuse this patch for my Xen patch for supporting MMCONFIG ioreq forwarding to multiple ioreq servers.
It should be ok (with the increased limit of course).
I've adjusted limits for PCI conf size in one of Q35 RFC patches (which are still waiting for review):
xen/pt: add support for PCIe Extended Capabilities and larger config space
http://lists.gnu.org/archive/html/qemu-devel/2018-03/msg03594.html
Also, for hw/xen/xen-pt*.c one patch from upstream QEMU needed which currently still missing in the qemu-xen repo. (the one which defaults is_express for 'xen-pci-passthrough' devices). Otherwise new limits won't work due to is_express=0.
Quoted 215 lines
Paul
Quoted 212 lines
Quoted 4 lines
--
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>Quoted 8 lines
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
---
hw/i386/xen/trace-events | 2 +hw/i386/xen/xen-hvm.c| 101
+++++++++++++++++++++++++++++++++++++---------- 2 files changed,83
Quoted 199 lines
insertions(+), 20 deletions(-)
hw/i386/xen/trace-events +0
-0@@ -15,6 +15,8 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_tdf,
uint32_tdata_is_ptr, uint64cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t size)"I/O=%p pio read reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d"cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t size)"I/O=%p pio write reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_move(void *req,uint32_tdir,uint32_tdf,uint32_tdata_is_ptr,uint64_taddr,uint64_tdata,uint32_tcount,uint32_tsize) "I/O=%p copy dir=%d df=%d ptr=%d port=0x%"PRIx64" data=0x%"PRIx64" count=%d size=%d"
+cpu_ioreq_config_read(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" +cpu_ioreq_config_write(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x"# xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64hw/i386/xen/xen-hvm.c +14
-0@@ -12,6 +12,7 @@#include "cpu.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "hw/xen/xen_common.h" @@ -86,6 +87,12 @@ typedef struct XenPhysmap {QLIST_ENTRY (XenPhysmap) list; } XenPhysmap; +typedef struct XenPciDevice { +PCIDevice *pci_dev; +uint32_t sbdf; +QLIST_ENTRY (XenPciDevice) entry; +}XenPciDevice ; + typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page;@@ -105,6 +112,7 @@ typedef struct XenIOState {struct xs_handle *xenstore;MemoryListener memory_listener;MemoryListener io_listener; + QLIST_HEAD(, XenPciDevice) dev_list;DeviceListener device_listener; QLIST_HEAD(, XenPhysmap) physmap;hwaddr free_phys_offset;@@ -569,6 +577,12 @@ static void xen_device_realize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev =g_new (XenPciDevice,1 ); + + xendev->pci_dev = pci_dev; + xendev->sbdf =PCI_BUILD_BDF (pci_dev_bus_num (pci_dev), + pci_dev->devfn); +QLIST_INSERT_HEAD (&state->dev_list, xendev, entry);xen_map_pcidev (xen_domid, state->ioservid, pci_dev);}hw/i386/xen/xen-hvm.c +49
-0@@ -581,8 +595,17 @@ static void xen_device_unrealize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev, *next;xen_unmap_pcidev (xen_domid, state->ioservid, pci_dev); + + QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { +if (xendev->pci_dev == pci_dev) { +QLIST_REMOVE (xendev, entry); +g_free (xendev); +break ; + } + } } }@@ -903,6 +926,61 @@ static void cpu_ioreq_move(ioreq_t *req) } } +static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) { +if (!req->data_is_ptr) { + req->data =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +trace_cpu_ioreq_config_read (req, sbdf, reg, req->size, + req->data); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp; + + tmp =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +write_phys_req_item (req->data, req, i, &tmp); + } + } + }else if (req->dir ==IOREQ_WRITE ) { +if (!req->data_is_ptr) { +trace_cpu_ioreq_config_write (req, sbdf, reg, req->size, + req->data); + pci_host_config_write_common( + xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE,
req->data,hw/i386/xen/xen-hvm.c +8
-0+ req->size); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp =0 ; + +read_phys_req_item (req->data, req, i, &tmp); + pci_host_config_write_common( + xendev->pci_dev, reg,
PCI_CONFIG_SPACE_SIZE, tmp,hw/i386/xen/xen-hvm.c +7
-0+ req->size); + } + } + } + } +} +static void
regs_to_cpu(vmware_regs_t *vmport_regs, ioreq_t *req){ X86CPU *cpu;hw/i386/xen/xen-hvm.c +2
-20@@ -975,27 +1053,9 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)case IOREQ_TYPE_INVALIDATE :xen_invalidate_map_cache ();break ; -case IOREQ_TYPE_PCI_CONFIG : { -uint32_t sbdf = req->addr >>32 ; -uint32_t val; - -/* Fake a write to port 0xCF8 so that -* the config space access will target the -* correct device model. -*/ - val = (1u <<31 ) | - ((req->addr &0x0f00 ) <<16 ) | - ((sbdf &0xffff ) <<8 ) | - (req->addr &0xfc ); -do_outp (0xcf8 ,4 , val); - -/* Now issue the config space access via -* port 0xCFC -*/ - req->addr =0xcfc | (req->addr &0x03 ); -cpu_ioreq_pio (req); +case IOREQ_TYPE_PCI_CONFIG : +cpu_ioreq_config (state, req);break ; - }default :hw_error ("Invalid ioreq type 0x%x\n" , req->type);}hw/i386/xen/xen-hvm.c +1
-0@@ -1366,6 +1426,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) memory_listener_register(&state->io_listener, &address_space_io); state->device_listener = xen_device_listener; +QLIST_INIT (&state->dev_list);device_listener_register (&state->device_listener);/* Initialize backend core & drivers */
Anthony, Stefano,
Ping?
Paul
Quoted 226 lines
-----Original Message-----
From: Paul Durrant [mailto:[email protected]]
Sent: 03 May 2018 12:19
To: [email protected]; [email protected]
Cc: Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Anthony Perard <[email protected]>; Michael S. Tsirkin <[email protected]>; Marcel Apfelbaum <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>; Eduardo Habkost <[email protected]>
Subject: [PATCH] xen-hvm: stop faking I/O to access PCI config spaceThis patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to emulate MCFG table accesses.Signed-off-by Paul Durrant <[email protected]>--
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>--- hw/i386/xen/trace-events | 2 + hw/i386/xen/xen-hvm.c | 101 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 20 deletions(-)hw/i386/xen/trace-events +0
-0@@ -15,6 +15,8 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df,
uint32_tdata_is_ptr, uint64
cpu_ioreq_pio_read_reg(void *req,uint64_tdata,uint64_taddr,uint32_t
size) "I/O=%p pio read reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d"
cpu_ioreq_pio_write_reg(void *req,uint64_tdata,uint64_taddr,uint32_t
size) "I/O=%p pio write reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d"
cpu_ioreq_move(void *req,uint32_tdir,uint32_tdf,uint32_tdata_is_ptr,uint64_taddr,uint64_tdata,uint32_tcount,uint32_tsize) "I/O=%p copy dir=%d df=%d ptr=%d port=0x%"PRIx64" data=0x%"PRIx64" count=%d size=%d"
+cpu_ioreq_config_read(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" +cpu_ioreq_config_write(void *req,uint32_tsbdf,uint32_treg,uint32_tsize,uint32_tdata) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x"# xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64hw/i386/xen/xen-hvm.c +14
-0@@ -12,6 +12,7 @@#include "cpu.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "hw/xen/xen_common.h" @@ -86,6 +87,12 @@ typedef struct XenPhysmap {QLIST_ENTRY (XenPhysmap) list; } XenPhysmap; +typedef struct XenPciDevice { +PCIDevice *pci_dev; +uint32_t sbdf; +QLIST_ENTRY (XenPciDevice) entry; +}XenPciDevice ; + typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page;@@ -105,6 +112,7 @@ typedef struct XenIOState {struct xs_handle *xenstore;MemoryListener memory_listener;MemoryListener io_listener; + QLIST_HEAD(, XenPciDevice) dev_list;DeviceListener device_listener; QLIST_HEAD(, XenPhysmap) physmap;hwaddr free_phys_offset;@@ -569,6 +577,12 @@ static void xen_device_realize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev =g_new (XenPciDevice,1 ); + + xendev->pci_dev = pci_dev; + xendev->sbdf =PCI_BUILD_BDF (pci_dev_bus_num (pci_dev), + pci_dev->devfn); +QLIST_INSERT_HEAD (&state->dev_list, xendev, entry);xen_map_pcidev (xen_domid, state->ioservid, pci_dev);}hw/i386/xen/xen-hvm.c +66
-20@@ -581,8 +595,17 @@ static void xen_device_unrealize(DeviceListener *listener, if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev, *next;xen_unmap_pcidev (xen_domid, state->ioservid, pci_dev); + + QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { +if (xendev->pci_dev == pci_dev) { +QLIST_REMOVE (xendev, entry); +g_free (xendev); +break ; + } + } } }@@ -903,6 +926,61 @@ static void cpu_ioreq_move(ioreq_t *req) } } +static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) { +if (!req->data_is_ptr) { + req->data =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +trace_cpu_ioreq_config_read (req, sbdf, reg, req->size, + req->data); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp; + + tmp =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +write_phys_req_item (req->data, req, i, &tmp); + } + } + }else if (req->dir ==IOREQ_WRITE ) { +if (!req->data_is_ptr) { +trace_cpu_ioreq_config_write (req, sbdf, reg, req->size, + req->data); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , req->data, + req->size); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp =0 ; + +read_phys_req_item (req->data, req, i, &tmp); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , tmp, + req->size); + } + } + } + } +} +static void regs_to_cpu (vmware_regs_t *vmport_regs,ioreq_t *req) {X86CPU *cpu;@@ -975,27 +1053,9 @@ static void handle_ioreq(XenIOState *state, ioreq_t *req)case IOREQ_TYPE_INVALIDATE :xen_invalidate_map_cache ();break ; -case IOREQ_TYPE_PCI_CONFIG : { -uint32_t sbdf = req->addr >>32 ; -uint32_t val; - -/* Fake a write to port 0xCF8 so that -* the config space access will target the -* correct device model. -*/ - val = (1u <<31 ) | - ((req->addr &0x0f00 ) <<16 ) | - ((sbdf &0xffff ) <<8 ) | - (req->addr &0xfc ); -do_outp (0xcf8 ,4 , val); - -/* Now issue the config space access via -* port 0xCFC -*/ - req->addr =0xcfc | (req->addr &0x03 ); -cpu_ioreq_pio (req); +case IOREQ_TYPE_PCI_CONFIG : +cpu_ioreq_config (state, req);break ; - }default :hw_error ("Invalid ioreq type 0x%x\n" , req->type);}hw/i386/xen/xen-hvm.c +1
-0@@ -1366,6 +1426,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) memory_listener_register(&state->io_listener, &address_space_io); state->device_listener = xen_device_listener; +QLIST_INIT (&state->dev_list);device_listener_register (&state->device_listener);/* Initialize backend core & drivers */
Quoted 2 lines
--
2.1.4
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Paul Durrant
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to emulate MCFG table accesses.
Thanks for doing this. I'm not a QEMU maintainer but:
Quoted 103 lines
Signed-off-by Paul Durrant <[email protected]>--
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>--- hw/i386/xen/trace-events | 2 + hw/i386/xen/xen-hvm.c | 101 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 20 deletions(-)hw/i386/xen/trace-events +2
-0@@ -15,6 +15,8 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, uint64 cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t size) "I/O=%p pio read reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t size) "I/O=%p pio write reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_move(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=%p copy dir=%d df=%d ptr=%d port=0x%"PRIx64" data=0x%"PRIx64" count=%d size=%d" +cpu_ioreq_config_read(void *req, uint32_t sbdf, uint32_t reg, uint32_t size, uint32_t data) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" +cpu_ioreq_config_write(void *req, uint32_t sbdf, uint32_t reg, uint32_t size, uint32_t data) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" # xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64hw/i386/xen/xen-hvm.c +31
-0@@ -12,6 +12,7 @@#include "cpu.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "hw/xen/xen_common.h" @@ -86,6 +87,12 @@ typedef struct XenPhysmap {QLIST_ENTRY (XenPhysmap) list; } XenPhysmap; +typedef struct XenPciDevice { +PCIDevice *pci_dev; +uint32_t sbdf; +QLIST_ENTRY (XenPciDevice) entry; +}XenPciDevice ; + typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page;@@ -105,6 +112,7 @@ typedef struct XenIOState {struct xs_handle *xenstore;MemoryListener memory_listener;MemoryListener io_listener; + QLIST_HEAD(, XenPciDevice) dev_list;DeviceListener device_listener; QLIST_HEAD(, XenPhysmap) physmap;hwaddr free_phys_offset;@@ -569,6 +577,12 @@ static void xen_device_realize(DeviceListener *listener,if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev =g_new (XenPciDevice,1 ); + + xendev->pci_dev = pci_dev; + xendev->sbdf =PCI_BUILD_BDF (pci_dev_bus_num (pci_dev), + pci_dev->devfn); +QLIST_INSERT_HEAD (&state->dev_list, xendev, entry);xen_map_pcidev (xen_domid, state->ioservid, pci_dev); }@@ -581,8 +595,17 @@ static void xen_device_unrealize(DeviceListener *listener,if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev, *next;xen_unmap_pcidev (xen_domid, state->ioservid, pci_dev); + + QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { +if (xendev->pci_dev == pci_dev) { +QLIST_REMOVE (xendev, entry); +g_free (xendev); +break ; + } + } } }@@ -903,6 +926,61 @@ static void cpu_ioreq_move(ioreq_t *req) } } +static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size);
hw/i386/xen/xen-hvm.c static void cpu_ioreq_move(ioreq_t *req) · line 946
Quoted 10 lines
hw/i386/xen/xen-hvm.c +10
-0+ } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) {
I would have used a switch here, but that's just personal taste.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Paul Durrant
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to emulate MCFG table accesses.
Thanks for doing this. I'm not a QEMU maintainer but:
Quoted 103 lines
Signed-off-by Paul Durrant <[email protected]>--
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>--- hw/i386/xen/trace-events | 2 + hw/i386/xen/xen-hvm.c | 101 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 83 insertions(+), 20 deletions(-)hw/i386/xen/trace-events +2
-0@@ -15,6 +15,8 @@ cpu_ioreq_pio(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, uint64 cpu_ioreq_pio_read_reg(void *req, uint64_t data, uint64_t addr, uint32_t size) "I/O=%p pio read reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_pio_write_reg(void *req, uint64_t data, uint64_t addr, uint32_t size) "I/O=%p pio write reg data=0x%"PRIx64" port=0x%"PRIx64" size=%d" cpu_ioreq_move(void *req, uint32_t dir, uint32_t df, uint32_t data_is_ptr, uint64_t addr, uint64_t data, uint32_t count, uint32_t size) "I/O=%p copy dir=%d df=%d ptr=%d port=0x%"PRIx64" data=0x%"PRIx64" count=%d size=%d" +cpu_ioreq_config_read(void *req, uint32_t sbdf, uint32_t reg, uint32_t size, uint32_t data) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" +cpu_ioreq_config_write(void *req, uint32_t sbdf, uint32_t reg, uint32_t size, uint32_t data) "I/O=%p sbdf=0x%x reg=%u size=%u data=0x%x" # xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64hw/i386/xen/xen-hvm.c +31
-0@@ -12,6 +12,7 @@#include "cpu.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "hw/i386/apic-msidef.h" #include "hw/xen/xen_common.h" @@ -86,6 +87,12 @@ typedef struct XenPhysmap {QLIST_ENTRY (XenPhysmap) list; } XenPhysmap; +typedef struct XenPciDevice { +PCIDevice *pci_dev; +uint32_t sbdf; +QLIST_ENTRY (XenPciDevice) entry; +}XenPciDevice ; + typedef struct XenIOState { ioservid_t ioservid; shared_iopage_t *shared_page;@@ -105,6 +112,7 @@ typedef struct XenIOState {struct xs_handle *xenstore;MemoryListener memory_listener;MemoryListener io_listener; + QLIST_HEAD(, XenPciDevice) dev_list;DeviceListener device_listener; QLIST_HEAD(, XenPhysmap) physmap;hwaddr free_phys_offset;@@ -569,6 +577,12 @@ static void xen_device_realize(DeviceListener *listener,if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev =g_new (XenPciDevice,1 ); + + xendev->pci_dev = pci_dev; + xendev->sbdf =PCI_BUILD_BDF (pci_dev_bus_num (pci_dev), + pci_dev->devfn); +QLIST_INSERT_HEAD (&state->dev_list, xendev, entry);xen_map_pcidev (xen_domid, state->ioservid, pci_dev); }@@ -581,8 +595,17 @@ static void xen_device_unrealize(DeviceListener *listener,if (object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE )) {PCIDevice *pci_dev =PCI_DEVICE (dev); +XenPciDevice *xendev, *next;xen_unmap_pcidev (xen_domid, state->ioservid, pci_dev); + + QLIST_FOREACH_SAFE(xendev, &state->dev_list, entry, next) { +if (xendev->pci_dev == pci_dev) { +QLIST_REMOVE (xendev, entry); +g_free (xendev); +break ; + } + } } }@@ -903,6 +926,61 @@ static void cpu_ioreq_move(ioreq_t *req) } } +static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size);
hw/i386/xen/xen-hvm.c static void cpu_ioreq_move(ioreq_t *req) · line 946
Quoted 10 lines
hw/i386/xen/xen-hvm.c +10
-0+ } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) {
I would have used a switch here, but that's just personal taste.
Roger.
Quoted 2 lines · Paul Durrant
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it
^ requests
Quoted 32 lines
with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.
NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to emulate MCFG table accesses.Signed-off-by Paul Durrant <[email protected]>hw/i386/xen/xen-hvm.c +21
-0+static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) { +if (!req->data_is_ptr) { + req->data = pci_host_config_read_common( + xendev->pci_dev, reg, PCI_CONFIG_SPACE_SIZE,
hw/i386/xen/xen-hvm.c static void cpu_ioreq_move(ioreq_t *req) · line 959
Quoted 10 lines
hw/i386/xen/xen-hvm.c +10
-0+ req->size); +trace_cpu_ioreq_config_read (req, sbdf, reg, req->size, + req->data); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp; + + tmp =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size);
So, if data is a pointer, we just keep reading the same address req->count time?
Quoted 23 lines
hw/i386/xen/xen-hvm.c +23
-0+write_phys_req_item (req->data, req, i, &tmp); + } + } + }else if (req->dir ==IOREQ_WRITE ) { +if (!req->data_is_ptr) { +trace_cpu_ioreq_config_write (req, sbdf, reg, req->size, + req->data); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , req->data, + req->size); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp =0 ; + +read_phys_req_item (req->data, req, i, &tmp); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , tmp, + req->size); + } + } + } + } +}
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines
-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 17 May 2018 17:31
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; Stefano Stabellini <[email protected]>; Michael S. Tsirkin <[email protected]>; Marcel Apfelbaum <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>; Eduardo Habkost <[email protected]>
Subject: Re: [PATCH] xen-hvm: stop faking I/O to access PCI config space
Quoted 5 lines
Quoted 2 lines · Paul Durrant
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it^ requests
Ok.
Quoted 38 lines
Quoted 38 lines
with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.
NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to emulate MCFG table accesses.Signed-off-by Paul Durrant <[email protected]>hw/i386/xen/xen-hvm.c +26
-0+static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) { +if (!req->data_is_ptr) { + req->data =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +trace_cpu_ioreq_config_read (req, sbdf, reg, req->size, + req->data); + }else { +for (i =0 ; i < req->count; i++) {
Quoted 9 lines
hw/i386/xen/xen-hvm.c static void cpu_ioreq_move(ioreq_t *req) · line 959
Quoted 5 lines
hw/i386/xen/xen-hvm.c +5
-0+uint32_t tmp; + + tmp =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size);So, if data is a pointer, we just keep reading the same address
req->counttime?
That's what would have happened before AFAICT, since the old scheme used port I/O. I think you're right that it is probably worth changing to MMIO semantics with this change though.
Paul
Quoted 18 lines
Quoted 18 lines
hw/i386/xen/xen-hvm.c +18
-0+write_phys_req_item (req->data, req, i, &tmp); + } + } + }else if (req->dir ==IOREQ_WRITE ) { +if (!req->data_is_ptr) { +trace_cpu_ioreq_config_write (req, sbdf, reg, req->size, + req->data); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , req->data, + req->size); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp =0 ; + +read_phys_req_item (req->data, req, i, &tmp); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , tmp, + req->size);
Quoted 8 lines
hw/i386/xen/xen-hvm.c static void cpu_ioreq_move(ioreq_t *req) · line 978
Quoted 5 lines
hw/i386/xen/xen-hvm.c +5
-0+ } + } + } + } +}--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines
-----Original Message-----
From: Anthony PERARD [mailto:[email protected]]
Sent: 17 May 2018 17:31
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; Stefano Stabellini <[email protected]>; Michael S. Tsirkin <[email protected]>; Marcel Apfelbaum <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>; Eduardo Habkost <[email protected]>
Subject: Re: [PATCH] xen-hvm: stop faking I/O to access PCI config space
Quoted 5 lines
Quoted 2 lines · Paul Durrant
This patch removes the current hackery where
IOREQ_TYPE_PCI_CONFIGreqyests are handled by faking PIO to0xcf8and0xcfcand replaces it^ requests
Ok.
Quoted 38 lines
Quoted 38 lines
with direct calls to pci_host_config_read/write_common(). Doing so necessitates mapping BDFs to PCIDevices but maintaining a simple QLIST in xen_device_realize/unrealize() will suffice.
NOTE: whilst config space accesses are currently limited to
PCI_CONFIG_SPACE_SIZE, this patch paves the way to increasing the limit toPCIE_CONFIG_SPACE_SIZEwhen Xen gains the ability to emulate MCFG table accesses.Signed-off-by Paul Durrant <[email protected]>hw/i386/xen/xen-hvm.c +26
-0+static void cpu_ioreq_config (XenIOState *state,ioreq_t *req) +{ +uint32_t sbdf = req->addr >>32 ; +uint32_t reg = req->addr; +XenPciDevice *xendev; + +if (req->size >sizeof (uint32_t )) { +hw_error ("PCI config access: bad size (%u)" , req->size); + } + + QLIST_FOREACH(xendev, &state->dev_list, entry) { +unsigned int i; + +if (xendev->sbdf != sbdf) { +continue ; + } + +if (req->dir ==IOREQ_READ ) { +if (!req->data_is_ptr) { + req->data =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size); +trace_cpu_ioreq_config_read (req, sbdf, reg, req->size, + req->data); + }else { +for (i =0 ; i < req->count; i++) {
Quoted 9 lines
hw/i386/xen/xen-hvm.c static void cpu_ioreq_move(ioreq_t *req) · line 959
Quoted 5 lines
hw/i386/xen/xen-hvm.c +5
-0+uint32_t tmp; + + tmp =pci_host_config_read_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , + req->size);So, if data is a pointer, we just keep reading the same address
req->counttime?
That's what would have happened before AFAICT, since the old scheme used port I/O. I think you're right that it is probably worth changing to MMIO semantics with this change though.
Paul
Quoted 26 lines
Quoted 13 lines
hw/i386/xen/xen-hvm.c +13
-0+write_phys_req_item (req->data, req, i, &tmp); + } + } + }else if (req->dir ==IOREQ_WRITE ) { +if (!req->data_is_ptr) { +trace_cpu_ioreq_config_write (req, sbdf, reg, req->size, + req->data); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , req->data, + req->size); + }else { +for (i =0 ; i < req->count; i++) { +uint32_t tmp =0 ;hw/i386/xen/xen-hvm.c static void cpu_ioreq_move(ioreq_t *req) · line 982
Quoted 10 lines
hw/i386/xen/xen-hvm.c +10
-0+ +read_phys_req_item (req->data, req, i, &tmp); +pci_host_config_write_common ( + xendev->pci_dev, reg,PCI_CONFIG_SPACE_SIZE , tmp, + req->size); + } + } + } + } +}--
Anthony PERARD