xen-hvm: use new resource mapping API
v3 cover xen-hvm: use new resource mapping API
This series modifies QEMU to use the new guest resource mapping API (available in Xen 4.11+) to map ioreq pages.
v2:
- Add a patch to checkpatch to avoid misparsing of Xen stable API handles
Paul Durrant (3):
xen-hvm: create separate function for ioreq server initialization
checkpatch: generalize xen handle matching in the list of types
xen-hvm: try to use xenforeignmemory_map_resource() to map ioreq pages
configure | 5 ++ hw/i386/xen/trace-events | 1 + hw/i386/xen/xen-hvm.c | 112 ++++++++++++++++++++++++++++++++------------ include/hw/xen/xen_common.h | 16 +++++++ scripts/checkpatch.pl | 2 +- 5 files changed, 105 insertions(+), 31 deletions(-)
---
Cc: Anthony Perard <[email protected]>
Cc: Daniel P. Berrange <[email protected]>
Cc: Eric Blake <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 1/3 xen-hvm: create separate function for ioreq server initialization
The code is sufficiently substantial that it improves code readability to put it in a new function called by xen_hvm_init() rather than having it inline.
---
Cc: Stefano Stabellini <[email protected]>
--- hw/i386/xen/xen-hvm.c | 76 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 30 deletions(-)
hw/i386/xen/xen-hvm.c +46 -30
@@ -95,7 +95,8 @@ typedef struct XenIOState {CPUState **cpu_by_vcpu_id;/* the evtchn port for polling the notification, */ evtchn_port_t *ioreq_local_port; -/* evtchn local port for buffered io */ +/* evtchn remote and local ports for buffered io */ +evtchn_port_t bufioreq_remote_port;evtchn_port_t bufioreq_local_port;/* the evtchn fd for polling */ xenevtchn_handle *xce_handle;
@@ -1236,12 +1237,52 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)xc_set_hvm_param (xen_xc, xen_domid,HVM_PARAM_ACPI_S_STATE ,0 ); } -void xen_hvm_init (PCMachineState *pcms,MemoryRegion **ram_memory) +static int xen_map_ioreq_server (XenIOState *state) { -int i, rc;xen_pfn_t ioreq_pfn;xen_pfn_t bufioreq_pfn;evtchn_port_t bufioreq_evtchn; +int rc; + + rc =xen_get_ioreq_server_info (xen_domid, state->ioservid, + &ioreq_pfn, &bufioreq_pfn, + &bufioreq_evtchn); +if (rc <0 ) { +error_report ("failed to get ioreq server info: error %d handle=%p" , + errno, xen_xc); +return rc; + } + +DPRINTF ("shared page at pfn %lx\n" , ioreq_pfn); +DPRINTF ("buffered io page at pfn %lx\n" , bufioreq_pfn); +DPRINTF ("buffered io evtchn is %x\n" , bufioreq_evtchn); + + state->shared_page =xenforeignmemory_map (xen_fmem, xen_domid, +PROT_READ |PROT_WRITE , +1 , &ioreq_pfn,NULL ); +if (state->shared_page ==NULL ) { +error_report ("map shared IO page returned error %d handle=%p" , + errno, xen_xc); +return -1 ; + } + + state->buffered_io_page =xenforeignmemory_map (xen_fmem, xen_domid, +PROT_READ |PROT_WRITE , +1 , &bufioreq_pfn,NULL ); +if (state->buffered_io_page ==NULL ) { +error_report ("map buffered IO page returned error %d" , errno); +return -1 ; + } + + state->bufioreq_remote_port = bufioreq_evtchn; + +return 0 ; +} + +void xen_hvm_init (PCMachineState *pcms,MemoryRegion **ram_memory) +{ +int i, rc; +xen_pfn_t ioreq_pfn;XenIOState *state; state =g_malloc0 (sizeof (XenIOState));
@@ -1269,25 +1310,8 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) state->wakeup.notify = xen_wakeup_notifier;qemu_register_wakeup_notifier (&state->wakeup); - rc =xen_get_ioreq_server_info (xen_domid, state->ioservid, - &ioreq_pfn, &bufioreq_pfn, - &bufioreq_evtchn); + rc =xen_map_ioreq_server (state);if (rc <0 ) { -error_report ("failed to get ioreq server info: error %d handle=%p" , - errno, xen_xc); - goto err; - } - -DPRINTF ("shared page at pfn %lx\n" , ioreq_pfn); -DPRINTF ("buffered io page at pfn %lx\n" , bufioreq_pfn); -DPRINTF ("buffered io evtchn is %x\n" , bufioreq_evtchn); - - state->shared_page =xenforeignmemory_map (xen_fmem, xen_domid, -PROT_READ |PROT_WRITE , -1 , &ioreq_pfn,NULL ); -if (state->shared_page ==NULL ) { -error_report ("map shared IO page returned error %d handle=%p" , - errno, xen_xc); goto err; }
@@ -1308,14 +1332,6 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) goto err; } - state->buffered_io_page =xenforeignmemory_map (xen_fmem, xen_domid, -PROT_READ |PROT_WRITE , -1 , &bufioreq_pfn,NULL ); -if (state->buffered_io_page ==NULL ) { -error_report ("map buffered IO page returned error %d" , errno); - goto err; - } -/* Note: cpus is empty at this point in init */ state->cpu_by_vcpu_id =g_malloc0 (max_cpus *sizeof (CPUState *));
@@ -1340,7 +1356,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) } rc =xenevtchn_bind_interdomain (state->xce_handle, xen_domid, - bufioreq_evtchn); + state->bufioreq_remote_port);if (rc ==-1 ) {error_report ("buffered evtchn bind error %d" , errno); goto err;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 2/3 checkpatch: generalize xen handle matching in the list of types
In reply to Paul DurrantAll the xen stable APIs define handle types of the form:
xen<subject of API>_handle
and some define additional handle types of the form:
xen<subject of API>_<purpose of handle>_handle
Examples of these are xenforeignmemory_handle andxenforeignmemory_resource_handle.
Both of these types will be misparsed by checkpatch if they appear as the first token in a line since, as types defined by an external library, they do not conform to the QEMU CODING_STYLE, which suggests CamelCase.
A previous patch (5ac067a24a8) added xendevicemodel_handle to the list of types. This patch changes that to xen\w+_handle such that it will match all Xen stable API handles of the forms detailed above.
---
Cc: Paolo Bonzini <[email protected]>
Cc: Daniel P. Berrange <[email protected]>
v3:
- Adjusted commit comment slightly as suggested by Eric
v2:
- New in this version
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -271,7 +271,7 @@ our @typeList = ( qr{hwaddr}, # external libraries qr{xml${Ident}}, - qr{xendevicemodel_handle}, + qr{xen\w+_handle}, # Glib definitions qr{gchar}, qr{gshort},
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH v3 3/3 xen-hvm: try to use xenforeignmemory_map_resource() to map ioreq pages
In reply to Paul DurrantXen 4.11 has a new API to directly map guest resources. Among the resources that can be mapped using this API are ioreq pages.
This patch modifies QEMU to attempt to use the new API should it exist, falling back to the previous mechanism if it is unavailable.
---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>
v3:
- Addressed comments from Anthony
- Verified build against Xen 4.10
--- configure | 5 ++++ hw/i386/xen/trace-events | 1 + hw/i386/xen/xen-hvm.c | 66 ++++++++++++++++++++++++++++++++++----------- include/hw/xen/xen_common.h | 16 +++++++++++ 4 files changed, 73 insertions(+), 15 deletions(-)
configure +5 -0
@@ -2231,12 +2231,17 @@ EOF #undef XC_WANT_COMPAT_DEVICEMODEL_API #define __XEN_TOOLS__ #include <xendevicemodel.h> +#include <xenforeignmemory.h> int main(void) { xendevicemodel_handle *xd; + xenforeignmemory_handle *xfmem; xd = xendevicemodel_open(0, 0); xendevicemodel_pin_memory_cacheattr(xd, 0, 0, 0, 0); + xfmem = xenforeignmemory_open(0, 0); + xenforeignmemory_map_resource(xfmem, 0, 0, 0, 0, 0, NULL, 0, 0); + return 0; } EOF
hw/i386/xen/trace-events +1 -0
@@ -15,6 +15,7 @@ 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" +xen_map_resource_ioreq(uint32_t id, void *addr) "id: %u addr: %p" # xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want 0x%"PRIx64
hw/i386/xen/xen-hvm.c +51 -15
91 lines not on this page · raw message
include/hw/xen/xen_common.h +16 -0
@@ -119,6 +119,22 @@ static inline int xendevicemodel_pin_memory_cacheattr( return xc_domain_pin_memory_cacheattr(xen_xc, domid, start, end, type); } +typedef void xenforeignmemory_resource_handle ; + +#define XENMEM_resource_ioreq_server 0 + +#define XENMEM_resource_ioreq_server_frame_bufioreq 0 +#define XENMEM_resource_ioreq_server_frame_ioreq (n) (1 + (n)) + +static inline xenforeignmemory_resource_handle *xenforeignmemory_map_resource ( +xenforeignmemory_handle *fmem,domid_t domid,unsigned int type, +unsigned int id,unsigned long frame,unsigned long nr_frames, +void **paddr,int prot,int flags) +{ + errno =EOPNOTSUPP ; +return NULL ; +} +#endif /* CONFIG_XEN_CTRL_INTERFACE_VERSION < 41100 */ #if CONFIG_XEN_CTRL_INTERFACE_VERSION <41000
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [Qemu-devel] [PATCH v3 3/3] xen-hvm: try to use xenforeignmemory_map_resource() to map ioreq pages
Quoted 7 lines · Paul Durrant
Xen 4.11 has a new API to directly map guest resources. Among the resources that can be mapped using this API are ioreq pages.
This patch modifies QEMU to attempt to use the new API should it exist, falling back to the previous mechanism if it is unavailable.
Signed-off-by Paul Durrant <[email protected]>
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel