xen-hvm: use new resource mapping API
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.
Paul Durrant (2):
xen-hvm: create separate function for ioreq server initialization
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 | 114 ++++++++++++++++++++++++++++++++------------ include/hw/xen/xen_common.h | 14 ++++++ 4 files changed, 104 insertions(+), 30 deletions(-)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/2 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]>
Cc: Anthony Perard <[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 2/2 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]>
--- configure | 5 ++++ hw/i386/xen/trace-events | 1 + hw/i386/xen/xen-hvm.c | 68 +++++++++++++++++++++++++++++++++++---------- include/hw/xen/xen_common.h | 14 ++++++++++ 4 files changed, 73 insertions(+), 15 deletions(-)
configure +5 -0
@@ -2229,12 +2229,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 +53 -15
93 lines not on this page · raw message
include/hw/xen/xen_common.h +14 -0
@@ -119,6 +119,20 @@ 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_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 -1 ; +} +#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
This series seems to have some coding style problems. See output below for more information:
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH 0/2] xen-hvm: use new resource mapping API
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'16691ff49e xen-hvm: try to use xenforeignmemory_map_resource() to map ioreq pages d4bcd68252 xen-hvm: create separate function for ioreq server initialization
=== OUTPUT BEGIN ===
Checking PATCH 1/2: xen-hvm: create separate function for ioreq server initialization... Checking PATCH 2/2: xen-hvm: try to use xenforeignmemory_map_resource() to map ioreq pages...
ERROR: spaces required around that '*' (ctx:WxV)
#164: FILE: include/hw/xen/xen_common.h:128:
+ xenforeignmemory_handle *fmem, domid_t domid, unsigned int type,
^
total: 1 errors, 0 warnings, 138 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 67 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: 09 May 2018 17:02
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; xen- [email protected]; Paul Durrant <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 0/2] xen-hvm: use new resource mapping APIHi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH 0/2] xen-hvm: use new resource mapping API=== TEST SCRIPT BEGIN ===
#!/bin/bashBASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogramcommits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..." if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then failed=1 echo fi n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===Updating
3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/20180509154604.25530-1-
[email protected] -> patchew/20180509154604.25530-1- [email protected]
* [new tag] patchew/20180509154849.27979-1-
[email protected] -> patchew/20180509154849.27979-1- [email protected]
* [new tag] patchew/[email protected] ->
patchew/[email protected]
Switched to a new branch 'test'16691ff49exen-hvm: try to usexenforeignmemory_map_resource()to map ioreq pagesd4bcd68252xen-hvm: create separate function for ioreq server initialization=== OUTPUT BEGIN ===
Checking PATCH 1/2: xen-hvm: create separate function for ioreq server initialization...
Checking PATCH 2/2: xen-hvm: try to usexenforeignmemory_map_resource()to map ioreq pages...
ERROR: spaces required around that '*' (ctx:WxV)
#164: FILE:include/hw/xen/xen_common.h:128:
+xenforeignmemory_handle*fmem,domid_tdomid, unsigned int type,
Quoted 7 lines
^total: 1 errors, 0 warnings, 138 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.
This style warning appears to be spurious.
Paul
Quoted 9 lines
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 6 lines · Paul Durrant
Quoted 6 lines
xenforeignmemory_map_resource()to map ioreq pages...
ERROR: spaces required around that '*' (ctx:WxV) #164: FILE:include/hw/xen/xen_common.h:128:
+xenforeignmemory_handle*fmem,domid_tdomid, unsigned int type,^
Quoted 7 lines
Quoted 5 lines
total: 1 errors, 0 warnings, 138 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.This style warning appears to be spurious.
Yep, and it's because xenforeignmemory_handle doesn't follow our usual conventions for a type name. See commit 5ac067a if you want to add it to the list of whitelisted exception type names, to silence messages like this.
Signature · 8 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 23 lines
-----Original Message-----
From: Eric Blake [mailto:[email protected]]
Sent: 09 May 2018 18:26
To: Paul Durrant <[email protected]>; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH 0/2] xen-hvm: use new resource mapping APIQuoted 4 lines · Paul Durrant
Quoted 4 lines
xenforeignmemory_map_resource()to map ioreq pages...
ERROR: spaces required around that '*' (ctx:WxV) #164: FILE:include/hw/xen/xen_common.h:128:
+xenforeignmemory_handle*fmem,domid_tdomid, unsigned inttype,
Quoted 8 lines
Quoted 7 lines
^total: 1 errors, 0 warnings, 138 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.
Quoted 6 lines
Quoted 1 line
This style warning appears to be spurious.
Yep, and it's because
xenforeignmemory_handledoesn't follow our usual conventions for a type name. See commit 5ac067a if you want to add it to the list of whitelisted exception type names, to silence messages like this.
Thanks Eric. I'll send a v2 series with a suitable additional patch.
Cheers,
Paul
Quoted 5 lines
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 23 lines
-----Original Message-----
From: Eric Blake [mailto:[email protected]]
Sent: 09 May 2018 18:26
To: Paul Durrant <[email protected]>; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [Qemu-devel] [PATCH 0/2] xen-hvm: use new resource mapping APIQuoted 4 lines · Paul Durrant
Quoted 4 lines
xenforeignmemory_map_resource()to map ioreq pages...
ERROR: spaces required around that '*' (ctx:WxV) #164: FILE:include/hw/xen/xen_common.h:128:
+xenforeignmemory_handle*fmem,domid_tdomid, unsigned inttype,
Quoted 8 lines
Quoted 7 lines
^total: 1 errors, 0 warnings, 138 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in
MAINTAINERS.
Quoted 6 lines
Quoted 1 line
This style warning appears to be spurious.
Yep, and it's because
xenforeignmemory_handledoesn't follow our usual conventions for a type name. See commit 5ac067a if you want to add it to the list of whitelisted exception type names, to silence messages like this.
Thanks Eric. I'll send a v2 series with a suitable additional patch.
Cheers,
Paul
Quoted 5 lines
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org