Begin to disentangle libxenctrl and provide some stable libraries
Subsystems (2)
PATCH v8 1/1 Begin to disentangle libxenctrl and provide some stable libraries
In <[email protected]> I proposed stabilising some parts of the libxenctrl API/ABI by disaggregating into separate libraries.
This is v8 of that set of series against:
xen
qemu-xen
qemu-xen-traditional
mini-os
NB: Samuel+minios-devel will only get the mini-os side and Stefano+qemu -devel the qemu-xen side.
The code for all repos can be found in:
git://xenbits.xen.org/people/ianc/libxenctrl-split/xen.git v8git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen.git v8git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen-traditional.git v8git://xenbits.xen.org/people/ianc/libxenctrl-split/mini-os.git v8
The tip of the xen.git branch contains an extra patch hacking Config.mk to point to all the others above, which should get the correct things for the HEAD of the branch, but not further back in time.
The new libraries here are:
* libxentoollog: Common logging infrastructure (already in tree)
* libxenevtchn: Userspace access to evtchns (via /dev/xen/evtchn etc)
* libxengnttab: Userspace access to grant tables (via /dev/xen/gnt??? etc)
* libxencall: Making hypercalls (i.e. the IOCTL_PRIVCMD_HYPERCALL type functionality)
* libxenforeignmemory: Privileged mappings of foreign memory (IOCTL_PRIVCMD_MMAP et al)
The first three were actually pretty distinct within libxenctrl already and have not changed in quite some time.
Although the other two are somewhat new they are based on top of long standing stable ioctls, which gives me some confidence.
Nonetheless I would appreciate extra review of at least the interface headers of all of these with a particular eye to the suitability of these interfaces being maintained in an ABI (_B_, not _P_) stable way going forward.
Still to come would be libraries for specific out of tree purposes (device model, kexec), which would be adding new library at the same level as libxc I think, rather than underneath, i.e. also using the libraries split out here, but hopefully not libxenctrl itself.
The new libraries use linker version-scripts to hopefully make future ABI changes be possible in a compatible way.
Since last time:
* Some early bits went in.
* Rebased
* Clean up the *.so in clean, added distclean targets to each lib
* On the QEMU side use CONFIG_XEN_CTRL_INTERFACE_VERSION == 471 as the gate for this new setup (dropped a Reviewed-by).
Even with the dropped acks mini-os and qemu-xen-trad are fully acked (by Samuel+Wei and Ian J respectively), while qemu-xen and xen are mostly acked (but had a few dropped acks since last time).
Summary for qemu-xen.git:
R xen_console: correctly cleanup primary console on teardown.
R xen: Switch to libxenevtchn interface for compat shims.
R xen: Switch to libxengnttab interface for compat shims.
R xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages
M xen: Switch uses of xc_map_foreign_{pages,bulk} to use libxenforeignmemory API.
M xen: Use stable library interfaces when they are available.
A xen: domainbuild: reopen libxenctrl interface after forking for domain watcher.
R xen: make it possible to build without the Xen PV domain builder
(A == Acked by Stefano, R == Reviewed by Stefano, M == Modified in v8)
NB: qemu-xen-traditional.git, mini-os.git and xen.git are intertwined, but the qemu-xen.git part is independent and should be applied after all the rest of these series.
Summary for xen.git:
W tools/libxc: Remove osdep indirection for xc_evtchn
MWI tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
W tools: Arrange to check public headers for ANSI compatiblity
W tools/libxc: Remove osdep indirection for xc_gnt{shr,tab}
MW tools: Refactor /dev/xen/gnt{dev,shr} wrappers into libxengnttab.
W S tools/libxc: Remove osdep indirection for privcmd
MW tools: Refactor hypercall calling wrappers into libxencall.
W tools/libxc: drop xc_map_foreign_bulk_compat wrappers
W G tools: Remove xc_map_foreign_batch
W tools: Implement xc_map_foreign_range(s) in terms of common helper
MWI tools: Refactor foreign memory mapping into libxenforeignmemory
WI tools/libs/foreignmemory: provide xenforeignmemory_unmap.
WI tools/libs/foreignmemory: use size_t for size arguments.
tools/libs/foreignmemory: Mention restrictions on fork in docs.
WI tools/libs/foreignmemory: Support err == NULL to map.
WI tools/libs/foreignmemory: pull array length argument to map forward
WI tools/libs/evtchn: Review and update doc comments.
N tools/libs/evtchn: Use uint32_t for domid arguments
W tools/libs: Clean up hard tabs.
D tools/libs/gnttab: Extensive updates to API documentation.
W tools/libs/call: Update some log messages to not refer to xc.
WIR tools/libs/call: Describe return values and error semantics for xencall*
W tools/libs/call: Avoid xc_memalign in netbsd and solaris backends
tools/libs/call: linux: touch newly allocated pages after madvise lockdown tools/libs/{call,evtchn}: Document requirements around forking.
M R tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD
W tools: Update CFLAGS for qemu-xen to allow it to use new libraries
N tools/libs/*: Introduce APIs to restrict handles to a specific domain.
N == New in v8
W == Acked by Wei
R == Acked by Roger
I == Acked by Ian J
D == Acked by Daniel
G == Acked by George
S == Acked by Dave (Scott)
M == Modified (in all cases minor enough that I didn't drop acks)
Therefore needing attention from Ian and/or Wei are:
tools/libs/foreignmemory: Mention restrictions on fork in docs.
N tools/libs/evtchn: Use uint32_t for domid arguments
D tools/libs/gnttab: Extensive updates to API documentation.
tools/libs/call: linux: touch newly allocated pages after madvise l
tools/libs/{call,evtchn}: Document requirements around forking.
Rtools/libs/*: Use O_CLOEXEC on Linux and FreeBSD
N tools/libs/*:
Introduce APIs to restrict handles to a specific doma
The whole thing has been build tested on Linux (incl stubdoms), and on FreeBSD. I have runtime tested on Linux with qemu-xen, qemu-xen-trad and stubdoms.
Neither NetBSD nor Solaris have been tested at all. It's certainly not impossible that I've not got the #includes in the new files quite right.
http://xenbits.xen.org/people/ianc/libxenctrl-split/v8.html is the document I've been using to try and track what I'm doing. It may not be all that useful. The history of it is in the v8-with-doc branch of the xen.git linked to above.
Ian.
_______________________________________________
Minios-devel mailing list
[email protected]
http://lists.xenproject.org/cgi-bin/mailman/listinfo/minios-devel
v8 cover Begin to disentangle libxenctrl and provide some stable libraries
We intend to stabilise some parts of the libxenctrl interface by splitting out some functionality into separate stable libraries.
This is the xen part of the first phase of that change.
This mail is (or is intended to be) a reply to a "0/<VARIOUS>" super-intro mail covering all of the related patch series and which contains more details.
Ian Campbell (29):
tools/libxc: Remove osdep indirection for xc_evtchn
tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
tools: Arrange to check public headers for ANSI compatiblity tools/libxc: Remove osdep indirection for xc_gnt{shr,tab}
tools: Refactor /dev/xen/gnt{dev,shr} wrappers into libxengnttab. tools/libxc: Remove osdep indirection for privcmd
tools: Refactor hypercall calling wrappers into libxencall. tools/libxc: drop xc_map_foreign_bulk_compat wrappers
tools: Remove xc_map_foreign_batch
tools: Implement xc_map_foreign_range(s) in terms of common helper
tools: Refactor foreign memory mapping into libxenforeignmemory tools/libs/foreignmemory: provide xenforeignmemory_unmap. tools/libs/foreignmemory: use size_t for size arguments. tools/libs/foreignmemory: Mention restrictions on fork in docs. tools/libs/foreignmemory: Support err == NULL to map. tools/libs/foreignmemory: pull array length argument to map forward tools/libs/evtchn: Review and update doc comments. tools/libs/evtchn: Use uint32_t for domid arguments tools/libs: Clean up hard tabs.
tools/libs/gnttab: Extensive updates to API documentation. tools/libs/call: Update some log messages to not refer to xc. tools/libs/call: Describe return values and error semantics for
xencall*
tools/libs/call: Avoid xc_memalign in netbsd and solaris backends tools/libs/call: linux: touch newly allocated pages after madvise
lockdown
tools/libs/{call,evtchn}: Document requirements around forking. tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD
tools: Update CFLAGS for qemu-xen to allow it to use new libraries tools/libs/*: Introduce APIs to restrict handles to a specific domain.
HACK: Update Config.mk to pull all the right bits from my xenbits
trees
.gitignore | 9 + Config.mk | 22 +- config/FreeBSD.mk | 2 - config/NetBSD.mk | 3 - config/NetBSDRump.mk | 1 - config/StdGNU.mk | 1 - config/SunOS.mk | 1 - stubdom/Makefile | 62 +- tools/Makefile | 15 +- tools/Rules.mk | 44 +- tools/console/Makefile | 3 +- tools/console/daemon/io.c | 64 +- tools/console/daemon/utils.c | 1 - tools/console/daemon/utils.h | 1 + tools/libs/Makefile | 4 + tools/libs/call/Makefile | 71 ++ tools/libs/call/buffer.c | 192 +++++ tools/libs/call/core.c | 154 ++++ tools/libs/call/freebsd.c | 126 +++ tools/libs/call/include/xencall.h | 161 ++++ tools/libs/call/libxencall.map | 21 + tools/libs/call/linux.c | 134 +++ tools/libs/call/minios.c | 81 ++ tools/libs/call/netbsd.c | 121 +++ tools/libs/call/private.h | 68 ++ tools/libs/call/solaris.c | 97 +++ tools/libs/evtchn/Makefile | 71 ++ tools/libs/evtchn/core.c | 79 ++ tools/libs/evtchn/freebsd.c | 138 ++++ tools/libs/evtchn/include/xenevtchn.h | 199 +++++ tools/libs/evtchn/libxenevtchn.map | 21 + tools/libs/evtchn/linux.c | 140 ++++ tools/libs/evtchn/minios.c | 266 ++++++ tools/libs/evtchn/netbsd.c | 147 ++++ tools/libs/evtchn/private.h | 25 + tools/libs/evtchn/solaris.c | 135 +++ tools/libs/foreignmemory/Makefile | 71 ++ tools/libs/foreignmemory/compat.c | 72 ++ tools/libs/foreignmemory/core.c | 123 +++ tools/libs/foreignmemory/freebsd.c | 115 +++ .../libs/foreignmemory/include/xenforeignmemory.h | 150 ++++ tools/libs/foreignmemory/libxenforeignmemory.map | 11 + tools/libs/foreignmemory/linux.c | 283 +++++++ tools/libs/foreignmemory/minios.c | 69 ++ tools/libs/foreignmemory/netbsd.c | 111 +++ tools/libs/foreignmemory/private.h | 54 ++ tools/libs/foreignmemory/solaris.c | 109 +++ tools/libs/gnttab/Makefile | 73 ++ tools/libs/gnttab/gntshr_core.c | 103 +++ tools/libs/gnttab/gntshr_unimp.c | 62 ++ tools/libs/gnttab/gnttab_core.c | 131 +++ tools/libs/gnttab/gnttab_unimp.c | 89 ++ tools/libs/gnttab/include/xengnttab.h | 415 ++++++++++ tools/libs/gnttab/libxengnttab.map | 27 + tools/libs/gnttab/linux.c | 335 ++++++++ tools/libs/gnttab/minios.c | 117 +++ tools/libs/gnttab/private.h | 47 ++ tools/libs/toollog/Makefile | 5 +- tools/libs/toollog/include/xentoollog.h | 10 + tools/libs/toollog/xtl_core.c | 10 + tools/libs/toollog/xtl_logger_stdio.c | 12 +- tools/libvchan/Makefile | 8 +- tools/libvchan/init.c | 46 +- tools/libvchan/io.c | 20 +- tools/libvchan/libxenvchan.h | 9 +- tools/libxc/Makefile | 41 +- tools/libxc/include/xenctrl.h | 312 +------ tools/libxc/include/xenctrl_compat.h | 132 +++ tools/libxc/include/xenctrlosdep.h | 172 ---- tools/libxc/include/xenguest.h | 14 +- tools/libxc/xc_altp2m.c | 64 +- tools/libxc/xc_domain.c | 105 +-- tools/libxc/xc_evtchn.c | 54 +- tools/libxc/xc_evtchn_compat.c | 75 ++ tools/libxc/xc_flask.c | 8 +- tools/libxc/xc_foreign_memory.c | 119 +-- tools/libxc/xc_freebsd_osdep.c | 407 ---------- tools/libxc/xc_gnttab.c | 93 +-- tools/libxc/xc_gnttab_compat.c | 111 +++ tools/libxc/xc_hcall_buf.c | 138 +--- tools/libxc/xc_kexec.c | 36 +- tools/libxc/xc_linux_osdep.c | 904 --------------------- tools/libxc/xc_minios.c | 482 ----------- tools/libxc/xc_misc.c | 79 +- tools/libxc/xc_netbsd.c | 345 -------- tools/libxc/xc_private.c | 277 +------ tools/libxc/xc_private.h | 105 +-- tools/libxc/xc_solaris.c | 305 ------- tools/libxc/xc_sr_restore.c | 8 +- tools/libxc/xc_sr_save.c | 6 +- tools/libxc/xc_suspend.c | 18 +- tools/libxc/xc_tmem.c | 7 +- tools/libxc/xc_vm_event.c | 20 +- tools/libxc/xenctrl_osdep_ENOSYS.c | 210 ----- tools/libxc/xg_private.h | 3 +- tools/libxl/Makefile | 5 +- tools/libxl/libxl.c | 2 +- tools/libxl/libxl_dom_suspend.c | 4 +- tools/libxl/libxl_event.c | 14 +- tools/libxl/libxl_internal.h | 6 +- tools/misc/Makefile | 11 +- tools/misc/xen-hptool.c | 13 +- tools/misc/xen-lowmemd.c | 15 +- tools/misc/xen-mfndump.c | 1 + tools/ocaml/libs/eventchn/Makefile | 4 +- tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 20 +- tools/ocaml/libs/xc/xenctrl.ml | 2 - tools/ocaml/libs/xc/xenctrl.mli | 1 - tools/ocaml/libs/xc/xenctrl_stubs.c | 8 +- tools/ocaml/xenstored/domains.ml | 6 +- tools/ocaml/xenstored/xenstored.ml | 5 +- tools/python/setup.py | 7 +- tools/python/xen/lowlevel/xc/xc.c | 2 + tools/tests/mce-test/tools/xen-mceinj.c | 1 + tools/tests/mem-sharing/memshrtool.c | 1 + tools/tests/xen-access/Makefile | 3 +- tools/tests/xen-access/xen-access.c | 21 +- tools/xcutils/Makefile | 4 +- tools/xenmon/Makefile | 2 + tools/xenmon/xenbaked.c | 26 +- tools/xenpaging/Makefile | 4 +- tools/xenpaging/pagein.c | 1 - tools/xenpaging/xenpaging.c | 33 +- tools/xenpaging/xenpaging.h | 5 +- tools/xenstore/Makefile | 7 +- tools/xenstore/xenstored_core.c | 7 +- tools/xenstore/xenstored_core.h | 5 +- tools/xenstore/xenstored_domain.c | 49 +- tools/xenstore/xenstored_minios.c | 5 +- tools/xentrace/Makefile | 5 +- tools/xentrace/xenctx.c | 3 +- tools/xentrace/xentrace.c | 17 +- 132 files changed, 6054 insertions(+), 4288 deletions(-) create mode 100644 tools/libs/call/Makefile create mode 100644 tools/libs/call/buffer.c create mode 100644 tools/libs/call/core.c create mode 100644 tools/libs/call/freebsd.c create mode 100644 tools/libs/call/include/xencall.h create mode 100644 tools/libs/call/libxencall.map create mode 100644 tools/libs/call/linux.c create mode 100644 tools/libs/call/minios.c create mode 100644 tools/libs/call/netbsd.c create mode 100644 tools/libs/call/private.h create mode 100644 tools/libs/call/solaris.c create mode 100644 tools/libs/evtchn/Makefile create mode 100644 tools/libs/evtchn/core.c create mode 100644 tools/libs/evtchn/freebsd.c create mode 100644 tools/libs/evtchn/include/xenevtchn.h create mode 100644 tools/libs/evtchn/libxenevtchn.map create mode 100644 tools/libs/evtchn/linux.c create mode 100644 tools/libs/evtchn/minios.c create mode 100644 tools/libs/evtchn/netbsd.c create mode 100644 tools/libs/evtchn/private.h create mode 100644 tools/libs/evtchn/solaris.c create mode 100644 tools/libs/foreignmemory/Makefile create mode 100644 tools/libs/foreignmemory/compat.c create mode 100644 tools/libs/foreignmemory/core.c create mode 100644 tools/libs/foreignmemory/freebsd.c create mode 100644 tools/libs/foreignmemory/include/xenforeignmemory.h create mode 100644 tools/libs/foreignmemory/libxenforeignmemory.map create mode 100644 tools/libs/foreignmemory/linux.c create mode 100644 tools/libs/foreignmemory/minios.c create mode 100644 tools/libs/foreignmemory/netbsd.c create mode 100644 tools/libs/foreignmemory/private.h create mode 100644 tools/libs/foreignmemory/solaris.c create mode 100644 tools/libs/gnttab/Makefile create mode 100644 tools/libs/gnttab/gntshr_core.c create mode 100644 tools/libs/gnttab/gntshr_unimp.c create mode 100644 tools/libs/gnttab/gnttab_core.c create mode 100644 tools/libs/gnttab/gnttab_unimp.c create mode 100644 tools/libs/gnttab/include/xengnttab.h create mode 100644 tools/libs/gnttab/libxengnttab.map create mode 100644 tools/libs/gnttab/linux.c create mode 100644 tools/libs/gnttab/minios.c create mode 100644 tools/libs/gnttab/private.h create mode 100644 tools/libxc/include/xenctrl_compat.h delete mode 100644 tools/libxc/include/xenctrlosdep.h create mode 100644 tools/libxc/xc_evtchn_compat.c delete mode 100644 tools/libxc/xc_freebsd_osdep.c create mode 100644 tools/libxc/xc_gnttab_compat.c delete mode 100644 tools/libxc/xc_linux_osdep.c delete mode 100644 tools/libxc/xenctrl_osdep_ENOSYS.c
Signature · 1 line
2.1.4
PATCH v8 1/29 tools/libxc: Remove osdep indirection for xc_evtchn
The alternative backend (a xen-api/xapi shim) is no longer around and so this stuff is now just baggage which is getting in the way of refactoring libxenctrl.
Note that the intention is to move this into a separate library shortly.
Nested virt probably suffices for this use case now.
One incorrect instance of using xc_interface where xc_evtchn (in ocaml stubs) is removed, this used to work because they were typedefs to the same struct, but is no longer permitted.
--- tools/libxc/include/xenctrl.h | 2 +- tools/libxc/include/xenctrlosdep.h | 16 ----- tools/libxc/xc_evtchn.c | 45 -------------- tools/libxc/xc_freebsd_osdep.c | 79 ++++++++---------------- tools/libxc/xc_linux_osdep.c | 76 +++++++++-------------- tools/libxc/xc_minios.c | 63 ++++++++----------- tools/libxc/xc_netbsd.c | 72 ++++++++-------------- tools/libxc/xc_private.c | 37 +++++++++--- tools/libxc/xc_private.h | 17 ++++++ tools/libxc/xc_solaris.c | 71 ++++++++-------------- tools/libxc/xenctrl_osdep_ENOSYS.c | 87 --------------------------- tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 4 +- 12 files changed, 180 insertions(+), 389 deletions(-)
tools/libxc/include/xenctrl.h +1 -1
@@ -117,7 +117,7 @@*/ typedef struct xc_interface_core xc_interface ; -typedef struct xc_interface_core xc_evtchn ; +typedef struct xenevtchn_handle xc_evtchn ;typedef struct xc_interface_core xc_gnttab ;typedef struct xc_interface_core xc_gntshr ;
tools/libxc/include/xenctrlosdep.h +0 -16
@@ -51,7 +51,6 @@enum xc_osdep_type {XC_OSDEP_PRIVCMD , -XC_OSDEP_EVTCHN ,XC_OSDEP_GNTTAB ,XC_OSDEP_GNTSHR , };
@@ -90,21 +89,6 @@ struct xc_osdep_ops int nentries); } privcmd;struct { -int (*fd)(xc_evtchn *xce,xc_osdep_handle h); - -int (*notify)(xc_evtchn *xce,xc_osdep_handle h,evtchn_port_t port); - -evtchn_port_or_error_t (*bind_unbound_port)(xc_evtchn *xce,xc_osdep_handle h,int domid); -evtchn_port_or_error_t (*bind_interdomain)(xc_evtchn *xce,xc_osdep_handle h,int domid, -evtchn_port_t remote_port); -evtchn_port_or_error_t (*bind_virq)(xc_evtchn *xce,xc_osdep_handle h,unsigned int virq); - -int (*unbind)(xc_evtchn *xce,xc_osdep_handle h,evtchn_port_t port); - -evtchn_port_or_error_t (*pending)(xc_evtchn *xce,xc_osdep_handle h); -int (*unmask)(xc_evtchn *xce,xc_osdep_handle h,evtchn_port_t port); - } evtchn; -struct {#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1 void *(*grant_map)(xc_gnttab *xcg, xc_osdep_handle h, uint32_t count, int flags, int prot,
tools/libxc/xc_evtchn.c +0 -45
51 lines not on this page · raw message
tools/libxc/xc_freebsd_osdep.c +26 -53
152 lines not on this page · raw message
tools/libxc/xc_linux_osdep.c +28 -48
155 lines not on this page · raw message
tools/libxc/xc_minios.c +24 -39
138 lines not on this page · raw message
tools/libxc/xc_netbsd.c +26 -46
141 lines not on this page · raw message
tools/libxc/xc_private.c +30 -7
@@ -119,7 +119,6 @@ static const char *xc_osdep_type_name(enum xc_osdep_type type)switch ( type ) {case XC_OSDEP_PRIVCMD :return "privcmd" ; -case XC_OSDEP_EVTCHN :return "evtchn" ;case XC_OSDEP_GNTTAB :return "gnttab" ;case XC_OSDEP_GNTSHR :return "gntshr" ; }
@@ -252,20 +251,44 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)return xch->ops->u.privcmd.hypercall (xch, xch->ops_handle, hypercall); } -xc_evtchn *xc_evtchn_open (xentoollog_logger *logger, -unsigned open_flags) +xc_evtchn *xc_evtchn_open (xentoollog_logger *logger,unsigned open_flags) { -xc_evtchn *xce; +xc_evtchn *xce =malloc (sizeof (*xce)); +int rc; + +if (!xce)return NULL ; + + xce->fd =-1 ; + xce->logger = logger; + xce->logger_tofree =NULL ; - xce =xc_interface_open_common (logger,NULL , open_flags, -XC_OSDEP_EVTCHN ); +if (!xce->logger) { + xce->logger = xce->logger_tofree = + (xentoollog_logger *) +xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); +if (!xce->logger) goto err; + } + + rc =osdep_evtchn_open (xce); +if ( rc <0 ) goto err;return xce; + +err: +osdep_evtchn_close (xce); +xtl_logger_destroy (xce->logger_tofree); +free (xce); +return NULL ; }int xc_evtchn_close (xc_evtchn *xce) { -return xc_interface_close_common (xce); +int rc; + + rc =osdep_evtchn_close (xce); +xtl_logger_destroy (xce->logger_tofree); +free (xce); +return rc; } xc_gnttab *xc_gnttab_open(xentoollog_logger *logger,
tools/libxc/xc_private.h +17 -0
@@ -123,6 +123,13 @@ struct xc_interface_core {xc_osdep_handle ops_handle;/* opaque data for xc_osdep_ops */ }; +struct xenevtchn_handle { +xentoollog_logger *logger, *logger_tofree; +int fd; +}; +int osdep_evtchn_open (xc_evtchn *xce); +int osdep_evtchn_close (xc_evtchn *xce); +void xc_report_error (xc_interface *xch,int code,const char *fmt, ...) __attribute__((format (printf,3 ,4 ))); void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
@@ -446,3 +453,13 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param, uint32_t *port);#endif /* __XC_PRIVATE_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libxc/xc_solaris.c +26 -45
145 lines not on this page · raw message
tools/libxc/xenctrl_osdep_ENOSYS.c +0 -87
99 lines not on this page · raw message
tools/ocaml/libs/eventchn/xeneventchn_stubs.c +2 -2
@@ -34,14 +34,14 @@#include <caml/callback.h> #include <caml/fail.h> -#define _H (__h) ((xc_interface *)(__h)) +#define _H (__h) ((xc_evtchn *)(__h)) CAMLprim value stub_eventchn_init(void) {CAMLparam0 ();CAMLlocal1 (result); -xc_interface *xce =xc_evtchn_open (NULL ,XC_OPENFLAG_NON_REENTRANT ); +xc_evtchn *xce =xc_evtchn_open (NULL ,XC_OPENFLAG_NON_REENTRANT );if (xce ==NULL )caml_failwith ("open failed" );
Signature · 1 line
2.1.4
PATCH v8 2/29 tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
In reply to Ian Campbelllibxenevtchn will provide a stable API and ABI for accessing the evtchn device.
The functions are moved into the xenevtchn namespace to make a clean break from libxc and avoid ambiguity regarding which interfaces are stable.
All in-tree users are updated to use the new names.
Upon request (via #define XC_WANT_COMPAT_EVTCHN_API) libxenctrl will provide a compat API for the old names. This is used by qemu-xen for the time being. qemu-xen-traditional is updated in lockstep.
This leaves a few event channel related functions which go via privcmd (EVTCHNOP) rather than ioctls on the /dev/xen/evtchn device in libxenctrl. Specifically:
- xc_evtchn_alloc_unbound
- xc_evtchn_reset
- xc_evtchn_status
Note that xc_evtchn_alloc_unbound's functionality is also provided by xenevtchn_bind_unbound_port() (née xc_evtchn_bind_unbound_port) and is probably redundant.
These functions do not appear to be needed by qemu-dm, qemu-pv (provision of device model to HVM guests and PV backends respectively) or by libvchan suggesting they are not needed by non-toolstack uses of event channels. QEMU does use these in hw/xenpv/xen_domainbuild.c but that is a "toolstack use".
The new library uses a version script to ensure that only expected symbols are exported and to version them such that ABI guarantees can be kept in the future.
---
Must be applied with:
- "qemu-xen-traditional: Use libxenevtchn" and a corresponding QEMU_TAG update folded here.
- "mini-os: Include libxenevtchn with libxc"" and a corresponding bump to MINIOS_UPSTREAM_REVISION folded in here.
v2: Update doc at same time
Removed some stray compat thing
v3: Moved to tools/libs/evtchn
v4: typedef the xenevtchn_handle in xenguest.h instead of #include, to
avoid leaking the libxenevtchn namespace into callers who may not want it. (And also to avoid adding lots of -I to places like stubdom builds)
v5: Handle NULL passed to _close()
v6: Properly port xen-access to new API (instead of a single function call)
v7: Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of
open coding the recursion.
v8: Remove *.so on clean, add distclean target.
--- .gitignore | 1 + stubdom/Makefile | 17 +- tools/Makefile | 5 +- tools/Rules.mk | 14 +- tools/console/Makefile | 2 + tools/console/daemon/io.c | 43 ++-- tools/libs/Makefile | 1 + tools/libs/evtchn/Makefile | 69 +++++++ tools/libs/evtchn/core.c | 72 +++++++ tools/libs/evtchn/freebsd.c | 138 +++++++++++++ tools/libs/evtchn/include/xenevtchn.h | 150 ++++++++++++++ tools/libs/evtchn/libxenevtchn.map | 19 ++ tools/libs/evtchn/linux.c | 136 +++++++++++++ tools/libs/evtchn/minios.c | 269 ++++++++++++++++++++++++++ tools/libs/evtchn/netbsd.c | 147 ++++++++++++++ tools/libs/evtchn/private.h | 25 +++ tools/libs/evtchn/solaris.c | 135 +++++++++++++ tools/libs/toollog/include/xentoollog.h | 10 + tools/libs/toollog/xtl_core.c | 10 + tools/libs/toollog/xtl_logger_stdio.c | 10 + tools/libvchan/Makefile | 6 +- tools/libvchan/init.c | 20 +- tools/libvchan/io.c | 12 +- tools/libvchan/libxenvchan.h | 3 +- tools/libxc/Makefile | 8 +- tools/libxc/include/xenctrl.h | 99 +--------- tools/libxc/include/xenctrl_compat.h | 48 +++++ tools/libxc/include/xenguest.h | 14 +- tools/libxc/xc_evtchn_compat.c | 75 +++++++ tools/libxc/xc_freebsd_osdep.c | 101 ---------- tools/libxc/xc_linux_osdep.c | 95 --------- tools/libxc/xc_minios.c | 221 --------------------- tools/libxc/xc_netbsd.c | 109 ----------- tools/libxc/xc_private.c | 40 ---- tools/libxc/xc_private.h | 7 - tools/libxc/xc_solaris.c | 97 ---------- tools/libxc/xc_suspend.c | 18 +- tools/libxl/Makefile | 5 +- tools/libxl/libxl.c | 2 +- tools/libxl/libxl_dom_suspend.c | 4 +- tools/libxl/libxl_event.c | 14 +- tools/libxl/libxl_internal.h | 5 +- tools/misc/Makefile | 7 +- tools/misc/xen-hptool.c | 13 +- tools/misc/xen-lowmemd.c | 15 +- tools/ocaml/libs/eventchn/Makefile | 4 +- tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 20 +- tools/python/setup.py | 7 +- tools/tests/xen-access/Makefile | 3 +- tools/tests/xen-access/xen-access.c | 21 +- tools/xcutils/Makefile | 4 +- tools/xenmon/Makefile | 2 + tools/xenmon/xenbaked.c | 13 +- tools/xenpaging/Makefile | 4 +- tools/xenpaging/xenpaging.c | 18 +- tools/xenpaging/xenpaging.h | 3 +- tools/xenstore/Makefile | 5 +- tools/xenstore/xenstored_core.c | 6 +- tools/xenstore/xenstored_domain.c | 25 +-- tools/xentrace/Makefile | 5 +- tools/xentrace/xentrace.c | 13 +- 61 files changed, 1539 insertions(+), 925 deletions(-) create mode 100644 tools/libs/evtchn/Makefile create mode 100644 tools/libs/evtchn/core.c create mode 100644 tools/libs/evtchn/freebsd.c create mode 100644 tools/libs/evtchn/include/xenevtchn.h create mode 100644 tools/libs/evtchn/libxenevtchn.map create mode 100644 tools/libs/evtchn/linux.c create mode 100644 tools/libs/evtchn/minios.c create mode 100644 tools/libs/evtchn/netbsd.c create mode 100644 tools/libs/evtchn/private.h create mode 100644 tools/libs/evtchn/solaris.c create mode 100644 tools/libxc/include/xenctrl_compat.h create mode 100644 tools/libxc/xc_evtchn_compat.c
.gitignore +1 -0
@@ -62,6 +62,7 @@ stubdom/ioemu stubdom/ioemu/ stubdom/libs-* stubdom/libxc-* +stubdom/libxenevtchn-* stubdom/libxentoollog-* stubdom/lwip-* stubdom/lwip/
stubdom/Makefile +16 -1
@@ -319,6 +319,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET) ln -sf $(XEN_ROOT)/tools/libs/toollog/include/*.h . && \ ln -sf $(XEN_ROOT)/tools/libs/toollog/*.c . && \ ln -sf $(XEN_ROOT)/tools/libs/toollog/Makefile . ) + mkdir -p libs-$(XEN_TARGET_ARCH)/evtchn/include + [ -h libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/evtchn && \ + ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.h . && \ + ln -sf $(XEN_ROOT)/tools/libs/evtchn/include/*.h include/ && \ + ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.c . && \ + ln -sf $(XEN_ROOT)/tools/libs/evtchn/Makefile . ) mkdir -p libxc-$(XEN_TARGET_ARCH) [ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \ ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -351,12 +357,21 @@ libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: mk-headers-$(XEN_TARGET_ARCH) $ CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog ####### +# libxenevtchn +####### + +.PHONY: libxenevtchn +libxenevtchn: libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a +libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) + CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn + +####### # libxc ####### .PHONY: libxc libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a -libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog cross-zlib +libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn cross-zlib CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH) libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
tools/Makefile +4 -1
@@ -248,8 +248,10 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find --libdir=$(LIBEXEC_LIB) \ --includedir=$(LIBEXEC_INC) \ --source-path=$$source \ - --extra-cflags="-I$(XEN_ROOT)/tools/include \ + --extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \ + -I$(XEN_ROOT)/tools/include \ -I$(XEN_ROOT)/tools/libs/toollog/include \ + -I$(XEN_ROOT)/tools/libs/evtchn/include \ -I$(XEN_ROOT)/tools/libxc/include \ -I$(XEN_ROOT)/tools/xenstore/include \ -I$(XEN_ROOT)/tools/xenstore/compat/include \
@@ -257,6 +259,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find --extra-ldflags="-L$(XEN_ROOT)/tools/libxc \ -L$(XEN_ROOT)/tools/xenstore \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \ + -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \ $(QEMU_UPSTREAM_RPATH)" \ --bindir=$(LIBEXEC_BIN) \ --datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +10 -4
@@ -11,6 +11,7 @@ INSTALL = $(XEN_ROOT)/tools/cross-install XEN_INCLUDE = $(XEN_ROOT)/tools/include XEN_LIBXENTOOLLOG = $(XEN_ROOT)/tools/libs/toollog +XEN_LIBXENEVTCHN = $(XEN_ROOT)/tools/libs/evtchn XEN_LIBXC = $(XEN_ROOT)/tools/libxc XEN_XENLIGHT = $(XEN_ROOT)/tools/libxl XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore
@@ -82,13 +83,18 @@ SHDEPS_libxentoollog = LDLIBS_libxentoollog = $(XEN_LIBXENTOOLLOG)/libxentoollog$(libextension) SHLIB_libxentoollog = -Wl,-rpath-link=$(XEN_LIBXENTOOLLOG) +CFLAGS_libxenevtchn = -I$(XEN_LIBXENEVTCHN)/include $(CFLAGS_xeninclude) +SHDEPS_libxenevtchn = +LDLIBS_libxenevtchn = $(XEN_LIBXENEVTCHN)/libxenevtchn$(libextension) +SHLIB_libxenevtchn = -Wl,-rpath-link=$(XEN_LIBXENEVTCHN) + CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude) -SHDEPS_libxenctrl = $(SHLIB_libxentoollog) +SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension) SHLIB_libxenctrl = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC) -CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_xeninclude) -SHDEPS_libxenguest = +CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_xeninclude) +SHDEPS_libxenguest = $(SHLIB_libxenevtchn) LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_LIBXC)/libxenguest$(libextension) SHLIB_libxenguest = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC)
@@ -103,7 +109,7 @@ LDLIBS_libxenstat = $(SHDEPS_libxenstat) $(XEN_LIBXENSTAT)/libxenstat$(libexten SHLIB_libxenstat = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_LIBXENSTAT) CFLAGS_libxenvchan = -I$(XEN_LIBVCHAN) -SHDEPS_libxenvchan = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) +SHDEPS_libxenvchan = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn) LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libextension) SHLIB_libxenvchan = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
tools/console/Makefile +2 -0
@@ -3,8 +3,10 @@ include $(XEN_ROOT)/tools/Rules.mk CFLAGS += -Werror +CFLAGS += $(CFLAGS_libxenevtchn) CFLAGS += $(CFLAGS_libxenctrl) CFLAGS += $(CFLAGS_libxenstore) +LDLIBS += $(LDLIBS_libxenevtchn) LDLIBS += $(LDLIBS_libxenctrl) LDLIBS += $(LDLIBS_libxenstore) LDLIBS += $(SOCKET_LIBS)
tools/console/daemon/io.c +22 -21
165 lines not on this page · raw message
tools/libs/Makefile +1 -0
@@ -3,5 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk SUBDIRS-y := SUBDIRS-y += toollog +SUBDIRS-y += evtchn all clean install distclean: %: subdirs-%
tools/libs/evtchn/Makefile new file +69 -0
69 lines not on this page · raw message
tools/libs/evtchn/core.c new file +72 -0
72 lines not on this page · raw message
tools/libs/evtchn/freebsd.c new file +138 -0
138 lines not on this page · raw message
tools/libs/evtchn/include/xenevtchn.h new file +150 -0
150 lines not on this page · raw message
tools/libs/evtchn/libxenevtchn.map new file +19 -0
@@ -0,0 +1,19 @@ +VERS_1.0 { + global: + xenevtchn_open; + xenevtchn_close; + + xenevtchn_fd; + + xenevtchn_bind_unbound_port; + xenevtchn_bind_interdomain; + xenevtchn_bind_virq; + + xenevtchn_notify; + + xenevtchn_unbind; + xenevtchn_unmask; + + xenevtchn_pending; + local: *; /* Do not expose anything by default */ +};
tools/libs/evtchn/linux.c new file +136 -0
136 lines not on this page · raw message
tools/libs/evtchn/minios.c new file +269 -0
269 lines not on this page · raw message
tools/libs/evtchn/netbsd.c new file +147 -0
147 lines not on this page · raw message
tools/libs/evtchn/private.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef XENEVTCHN_PRIVATE_H +#define XENEVTCHN_PRIVATE_H + +#include <xentoollog.h> +#include <xenevtchn.h> + +struct xenevtchn_handle { +xentoollog_logger *logger, *logger_tofree; +int fd; +}; + +int osdep_evtchn_open (xenevtchn_handle *xce); +int osdep_evtchn_close (xenevtchn_handle *xce); + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libs/evtchn/solaris.c new file +135 -0
135 lines not on this page · raw message
tools/libs/toollog/include/xentoollog.h +10 -0
@@ -134,3 +134,13 @@ const char *xtl_level_to_string(xentoollog_level); /* never fails */#endif /* XENTOOLLOG_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libs/toollog/xtl_core.c +10 -0
@@ -81,3 +81,13 @@ void xtl_logger_destroy(struct xentoollog_logger *logger) {if (!logger)return ; logger->destroy (logger); } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libs/toollog/xtl_logger_stdio.c +10 -0
@@ -190,3 +190,13 @@ xentoollog_logger_stdiostream *xtl_createlogger_stdiostreamreturn XTL_NEW_LOGGER (stdiostream, newlogger); } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libvchan/Makefile +3 -3
@@ -10,9 +10,9 @@ NODE_OBJS = node.o NODE2_OBJS = node-select.o LIBVCHAN_PIC_OBJS = $(patsubst %.o,%.opic,$(LIBVCHAN_OBJS)) -LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) -$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxenctrl) -$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxenctrl) +LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenevtchn) +$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) +$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) MAJOR = 1.0 MINOR = 0
tools/libvchan/init.c +10 -10
@@ -216,25 +216,25 @@ static int init_evt_srv(struct libxenvchan *ctrl, int domain, xentoollog_logger {evtchn_port_or_error_t port; - ctrl->event =xc_evtchn_open (logger,0 ); + ctrl->event =xenevtchn_open (logger,0 );if (!ctrl->event)return -1 ; - port =xc_evtchn_bind_unbound_port (ctrl->event, domain); + port =xenevtchn_bind_unbound_port (ctrl->event, domain);if (port <0 ) goto fail; ctrl->event_port = port; -if (xc_evtchn_unmask (ctrl->event, ctrl->event_port)) +if (xenevtchn_unmask (ctrl->event, ctrl->event_port)) goto fail;return 0 ; fail:if (port >=0 ) -xc_evtchn_unbind (ctrl->event, port); +xenevtchn_unbind (ctrl->event, port); -xc_evtchn_close (ctrl->event); +xenevtchn_close (ctrl->event); ctrl->event =NULL ;return -1 ;
@@ -346,26 +346,26 @@ static int init_evt_cli(struct libxenvchan *ctrl, int domain, xentoollog_logger {evtchn_port_or_error_t port; - ctrl->event =xc_evtchn_open (logger,0 ); + ctrl->event =xenevtchn_open (logger,0 );if (!ctrl->event)return -1 ; - port =xc_evtchn_bind_interdomain (ctrl->event, + port =xenevtchn_bind_interdomain (ctrl->event, domain, ctrl->event_port);if (port <0 ) goto fail; ctrl->event_port = port; -if (xc_evtchn_unmask (ctrl->event, ctrl->event_port)) +if (xenevtchn_unmask (ctrl->event, ctrl->event_port)) goto fail;return 0 ; fail:if (port >=0 ) -xc_evtchn_unbind (ctrl->event, port); +xenevtchn_unbind (ctrl->event, port); -xc_evtchn_close (ctrl->event); +xenevtchn_close (ctrl->event); ctrl->event =NULL ;return -1 ;
tools/libvchan/io.c +6 -6
@@ -105,7 +105,7 @@ static inline int send_notify(struct libxenvchan *ctrl, uint8_t bit) notify = ctrl->is_server ? &ctrl->ring->srv_notify : &ctrl->ring->cli_notify; prev =__sync_fetch_and_and (notify, ~bit);if (prev & bit) -return xc_evtchn_notify (ctrl->event, ctrl->event_port); +return xenevtchn_notify (ctrl->event, ctrl->event_port);else return 0 ; }
@@ -196,10 +196,10 @@ int libxenvchan_buffer_space(struct libxenvchan *ctrl)int libxenvchan_wait (struct libxenvchan *ctrl) { -int ret =xc_evtchn_pending (ctrl->event); +int ret =xenevtchn_pending (ctrl->event);if (ret <0 )return -1 ; -xc_evtchn_unmask (ctrl->event, ret); +xenevtchn_unmask (ctrl->event, ret);return 0 ; }
@@ -352,7 +352,7 @@ int libxenvchan_is_open(struct libxenvchan* ctrl)int libxenvchan_fd_for_select (struct libxenvchan *ctrl) { -return xc_evtchn_fd (ctrl->event); +return xenevtchn_fd (ctrl->event); }void libxenvchan_close (struct libxenvchan *ctrl)
@@ -374,8 +374,8 @@ void libxenvchan_close(struct libxenvchan *ctrl) }if (ctrl->event) {if (ctrl->ring) -xc_evtchn_notify (ctrl->event, ctrl->event_port); -xc_evtchn_close (ctrl->event); +xenevtchn_notify (ctrl->event, ctrl->event_port); +xenevtchn_close (ctrl->event); }if (ctrl->is_server) {if (ctrl->gntshr)
tools/libvchan/libxenvchan.h +2 -1
@@ -44,6 +44,7 @@#include <xen/io/libxenvchan.h> #include <xen/sys/evtchn.h> +#include <xenevtchn.h> #include <xenctrl.h> struct libxenvchan_ring {
@@ -71,7 +72,7 @@ struct libxenvchan {/* Pointer to shared ring page */ struct vchan_interface *ring;/* event channel interface */ -xc_evtchn *event; +xenevtchn_handle *event;uint32_t event_port;/* informative flags: are we acting as server? */ int is_server:1;
tools/libxc/Makefile +5 -3
@@ -48,6 +48,7 @@ CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c +CTRL_SRCS-y += xc_evtchn_compat.c GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c
@@ -111,6 +112,7 @@ CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE CFLAGS += $(PTHREAD_CFLAGS) CFLAGS += $(CFLAGS_libxentoollog) +CFLAGS += $(CFLAGS_libxenevtchn) CTRL_LIB_OBJS := $(patsubst %.c,%.o,$(CTRL_SRCS-y)) CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y))
@@ -164,7 +166,7 @@ install: build $(INSTALL_DATA) libxenctrl.a $(DESTDIR)$(libdir) $(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR) $(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenctrl.so - $(INSTALL_DATA) include/xenctrl.h include/xenctrlosdep.h $(DESTDIR)$(includedir) + $(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h include/xenctrlosdep.h $(DESTDIR)$(includedir) $(INSTALL_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir) $(INSTALL_DATA) libxenguest.a $(DESTDIR)$(libdir) $(SYMLINK_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenguest.so.$(MAJOR)
@@ -207,7 +209,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR) $(SYMLINK_SHLIB) $< $@ libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS) - $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) # libxenguest
@@ -230,7 +232,7 @@ xc_dom_bzimageloader.opic: CFLAGS += $(call zlib-options,D) libxenguest.so.$(MAJOR).$(MINOR): COMPRESSION_LIBS = $(call zlib-options,l) libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so - $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz $(LDLIBS_libxenctrl) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) xenctrl_osdep_ENOSYS.so: $(OSDEP_PIC_OBJS) libxenctrl.so $(CC) $(LDFLAGS) $(SHLIB_LDFLAGS) -o $@ $(OSDEP_PIC_OBJS) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
tools/libxc/include/xenctrl.h +3 -96
124 lines not on this page · raw message
tools/libxc/include/xenctrl_compat.h new file +48 -0
48 lines not on this page · raw message
tools/libxc/include/xenguest.h +10 -4
@@ -34,6 +34,12 @@#define X86_64_B_SIZE 64#define X86_32_B_SIZE 32 +/* +* User not using xc_suspend_* / xc_await_suspent may not want to +* include the full libxenevtchn API here. +*/ +typedef struct xenevtchn_handle xenevtchn_handle ; +/* callbacks provided by xc_domain_save */ struct save_callbacks {/* Called after expiration of checkpoint interval,
@@ -161,18 +167,18 @@ struct xc_hvm_firmware_module {* Sets *lockfd to -1. * Has deallocated everything even on error. */ -int xc_suspend_evtchn_release (xc_interface *xch,xc_evtchn *xce,int domid,int suspend_evtchn,int *lockfd); +int xc_suspend_evtchn_release (xc_interface *xch,xenevtchn_handle *xce,int domid,int suspend_evtchn,int *lockfd);/** * This function eats the initial notification. * xce must not be used for anything else * See xc_suspend_evtchn_init_sane re lockfd. */ -int xc_suspend_evtchn_init_exclusive (xc_interface *xch,xc_evtchn *xce, +int xc_suspend_evtchn_init_exclusive (xc_interface *xch,xenevtchn_handle *xce,int domid,int port,int *lockfd);/* xce must not be used for anything else */ -int xc_await_suspend (xc_interface *xch,xc_evtchn *xce,int suspend_evtchn); +int xc_await_suspend (xc_interface *xch,xenevtchn_handle *xce,int suspend_evtchn);/** * The port will be signaled immediately after this call
@@ -181,7 +187,7 @@ int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn);* and fed to xc_suspend_evtchn_release. (On error *lockfd is * undefined and xc_suspend_evtchn_release is not allowed.) */ -int xc_suspend_evtchn_init_sane (xc_interface *xch,xc_evtchn *xce, +int xc_suspend_evtchn_init_sane (xc_interface *xch,xenevtchn_handle *xce,int domid,int port,int *lockfd); int xc_mark_page_online(xc_interface *xch, unsigned long start,
tools/libxc/xc_evtchn_compat.c new file +75 -0
75 lines not on this page · raw message
tools/libxc/xc_freebsd_osdep.c +0 -101
118 lines not on this page · raw message
tools/libxc/xc_linux_osdep.c +0 -95
107 lines not on this page · raw message
tools/libxc/xc_minios.c +0 -221
247 lines not on this page · raw message
tools/libxc/xc_netbsd.c +0 -109
121 lines not on this page · raw message
tools/libxc/xc_private.c +0 -40
@@ -251,46 +251,6 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)return xch->ops->u.privcmd.hypercall (xch, xch->ops_handle, hypercall); } -xc_evtchn *xc_evtchn_open (xentoollog_logger *logger,unsigned open_flags) -{ -xc_evtchn *xce =malloc (sizeof (*xce)); -int rc; - -if (!xce)return NULL ; - - xce->fd =-1 ; - xce->logger = logger; - xce->logger_tofree =NULL ; - -if (!xce->logger) { - xce->logger = xce->logger_tofree = - (xentoollog_logger *) -xtl_createlogger_stdiostream (stderr,XTL_PROGRESS ,0 ); -if (!xce->logger) goto err; - } - - rc =osdep_evtchn_open (xce); -if ( rc <0 ) goto err; - -return xce; - -err: -osdep_evtchn_close (xce); -xtl_logger_destroy (xce->logger_tofree); -free (xce); -return NULL ; -} - -int xc_evtchn_close (xc_evtchn *xce) -{ -int rc; - - rc =osdep_evtchn_close (xce); -xtl_logger_destroy (xce->logger_tofree); -free (xce); -return rc; -} -xc_gnttab *xc_gnttab_open (xentoollog_logger *logger,unsigned open_flags) {
tools/libxc/xc_private.h +0 -7
@@ -123,13 +123,6 @@ struct xc_interface_core {xc_osdep_handle ops_handle;/* opaque data for xc_osdep_ops */ }; -struct xenevtchn_handle { -xentoollog_logger *logger, *logger_tofree; -int fd; -}; -int osdep_evtchn_open (xc_evtchn *xce); -int osdep_evtchn_close (xc_evtchn *xce); -void xc_report_error (xc_interface *xch,int code,const char *fmt, ...) __attribute__((format (printf,3 ,4 ))); void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
tools/libxc/xc_solaris.c +0 -97
109 lines not on this page · raw message
tools/libxc/xc_suspend.c +10 -8
@@ -16,6 +16,8 @@#include <unistd.h> #include <fcntl.h> +#include <xenevtchn.h> +#include "xc_private.h" #include "xenguest.h"
@@ -124,12 +126,12 @@ static int unlock_suspend_event(xc_interface *xch, int domid, int *lockfd)return -1 ; } -int xc_await_suspend (xc_interface *xch,xc_evtchn *xce,int suspend_evtchn) +int xc_await_suspend (xc_interface *xch,xenevtchn_handle *xce,int suspend_evtchn) {int rc; do { - rc = xc_evtchn_pending(xce); + rc = xenevtchn_pending(xce); if (rc < 0) { ERROR("error polling suspend notification channel: %d", rc); return -1;
@@ -137,7 +139,7 @@ int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn) }while (rc != suspend_evtchn);/* harmless for one-off suspend */ -if (xc_evtchn_unmask (xce, suspend_evtchn) <0 ) +if (xenevtchn_unmask (xce, suspend_evtchn) <0 )ERROR ("failed to unmask suspend notification channel: %d" , rc);return 0 ;
@@ -145,16 +147,16 @@ int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn)/* Internal callers are allowed to call this with suspend_evtchn<0 * but *lockfd>0. */ -int xc_suspend_evtchn_release (xc_interface *xch,xc_evtchn *xce, +int xc_suspend_evtchn_release (xc_interface *xch,xenevtchn_handle *xce,int domid,int suspend_evtchn,int *lockfd) {if (suspend_evtchn >=0 ) -xc_evtchn_unbind (xce, suspend_evtchn); +xenevtchn_unbind (xce, suspend_evtchn);return unlock_suspend_event (xch, domid, lockfd); } -int xc_suspend_evtchn_init_sane (xc_interface *xch,xc_evtchn *xce, +int xc_suspend_evtchn_init_sane (xc_interface *xch,xenevtchn_handle *xce,int domid,int port,int *lockfd) {int rc, suspend_evtchn =-1 ;
@@ -164,7 +166,7 @@ int xc_suspend_evtchn_init_sane(xc_interface *xch, xc_evtchn *xce, goto cleanup; } - suspend_evtchn =xc_evtchn_bind_interdomain (xce, domid, port); + suspend_evtchn =xenevtchn_bind_interdomain (xce, domid, port);if (suspend_evtchn <0 ) {ERROR ("failed to bind suspend event channel: %d" , suspend_evtchn); goto cleanup;
@@ -184,7 +186,7 @@ cleanup:return -1 ; } -int xc_suspend_evtchn_init_exclusive (xc_interface *xch,xc_evtchn *xce, +int xc_suspend_evtchn_init_exclusive (xc_interface *xch,xenevtchn_handle *xce,int domid,int port,int *lockfd) {int suspend_evtchn;
tools/libxl/Makefile +3 -2
@@ -20,12 +20,13 @@ LIBUUID_LIBS += -luuid endif LIBXL_LIBS = -LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS) +LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS) ifeq ($(CONFIG_REMUS_NETBUF),y) LIBXL_LIBS += $(LIBNL3_LIBS) endif CFLAGS_LIBXL += $(CFLAGS_libxentoollog) +CFLAGS_LIBXL += $(CFLAGS_libxenevtchn) CFLAGS_LIBXL += $(CFLAGS_libxenctrl) CFLAGS_LIBXL += $(CFLAGS_libxenguest) CFLAGS_LIBXL += $(CFLAGS_libxenstore)
@@ -159,7 +160,7 @@ $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenstore) SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o -$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) +$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) PKG_CONFIG = xenlight.pc xlutil.pc
tools/libxl/libxl.c +1 -1
@@ -186,7 +186,7 @@ int libxl_ctx_free(libxl_ctx *ctx)if (ctx->xch)xc_interface_close (ctx->xch);libxl_version_info_dispose (&ctx->version_info);if (ctx->xsh)xs_daemon_close (ctx->xsh); -if (ctx->xce)xc_evtchn_close (ctx->xce); +if (ctx->xce)xenevtchn_close (ctx->xce);libxl__poller_put (ctx, ctx->poller_app); ctx->poller_app =NULL ;
tools/libxl/libxl_dom_suspend.c +2 -2
@@ -109,9 +109,9 @@ static void domain_suspend_callback_common(libxl__egc *egc,if ((hvm_s_state ==0 ) && (dss->guest_evtchn.port >=0 )) {LOG (DEBUG ,"issuing %s suspend request via event channel" , dss->hvm ?"PVHVM" :"PV" ); - ret =xc_evtchn_notify (CTX ->xce, dss->guest_evtchn.port); + ret =xenevtchn_notify (CTX ->xce, dss->guest_evtchn.port);if (ret <0 ) { -LOG (ERROR ,"xc_evtchn_notify failed ret=%d" , ret); +LOG (ERROR ,"xenevtchn_notify failed ret=%d" , ret); rc =ERROR_FAIL ; goto err; }
tools/libxl/libxl_event.c +7 -7
@@ -739,7 +739,7 @@ static void evtchn_fd_callback(libxl__egc *egc, libxl__ev_fd *ev,/* OK, that's that workaround done. We can actually check for * work for us to do: */ - port =xc_evtchn_pending (CTX ->xce); + port =xenevtchn_pending (CTX ->xce);if (port <0 ) {if (errno ==EAGAIN )break ;
@@ -765,20 +765,20 @@ static void evtchn_fd_callback(libxl__egc *egc, libxl__ev_fd *ev, }int libxl__ctx_evtchn_init (libxl__gc *gc) { -xc_evtchn *xce; +xenevtchn_handle *xce;int rc, fd;if (CTX ->xce)return 0 ; - xce =xc_evtchn_open (CTX ->lg,0 ); + xce =xenevtchn_open (CTX ->lg,0 );if (!xce) {LOGE (ERROR ,"cannot open libxc evtchn handle" ); rc =ERROR_FAIL ; goto out; } - fd =xc_evtchn_fd (xce); + fd =xenevtchn_fd (xce);assert (fd >=0 ); rc =libxl_fd_set_nonblock (CTX , fd,1 );
@@ -788,7 +788,7 @@ int libxl__ctx_evtchn_init(libxl__gc *gc) {return 0 ; out: -xc_evtchn_close (xce); +xenevtchn_close (xce);return rc; }
@@ -810,14 +810,14 @@ int libxl__ev_evtchn_wait(libxl__gc *gc, libxl__ev_evtchn *evev)if (!libxl__ev_fd_isregistered (&CTX ->evtchn_efd)) { rc =libxl__ev_fd_register (gc, &CTX ->evtchn_efd, evtchn_fd_callback, -xc_evtchn_fd (CTX ->xce),POLLIN ); +xenevtchn_fd (CTX ->xce),POLLIN );if (rc) goto out; }if (evev->waiting)return 0 ; - r =xc_evtchn_unmask (CTX ->xce, evev->port); + r =xenevtchn_unmask (CTX ->xce, evev->port);if (r) {LOGE (ERROR ,"cannot unmask event channel %d" ,evev->port); rc =ERROR_FAIL ;
tools/libxl/libxl_internal.h +3 -2
@@ -48,6 +48,7 @@#include <sys/file.h> #include <sys/ioctl.h> +#include <xenevtchn.h> #include <xenstore.h> #include <xenctrl.h> #include <xenguest.h>
@@ -448,7 +449,7 @@ struct libxl__ctx {uint32_t watch_counter;/* helps disambiguate slot reuse */ libxl__ev_fd watch_efd; -xc_evtchn *xce;/* waiting must be done only with libxl__ev_evtchn* */ +xenevtchn_handle *xce;/* waiting must be done only with libxl__ev_evtchn* */ LIBXL_LIST_HEAD(, libxl__ev_evtchn) evtchns_waiting;libxl__ev_fd evtchn_efd;
@@ -925,7 +926,7 @@ static inline int libxl__ev_xswatch_isregistered(const libxl__ev_xswatch *xw)* When the event is signaled then the callback will be made, once. * Then you must call libxl__ev_evtchn_wait again, if desired. * -* You must NOT call xc_evtchn_unmask. wait will do that for you. +* You must NOT call xenevtchn_unmask. wait will do that for you. * * Calling libxl__ev_evtchn_cancel will arrange for libxl to disregard * future occurrences of event. Both libxl__ev_evtchn_wait and
tools/misc/Makefile +4 -3
@@ -4,6 +4,7 @@ include $(XEN_ROOT)/tools/Rules.mk CFLAGS += -Werror # Include configure output (config.h) CFLAGS += -include $(XEN_ROOT)/tools/config.h +CFLAGS += $(CFLAGS_libxenevtchn) CFLAGS += $(CFLAGS_libxenctrl) CFLAGS += $(CFLAGS_xeninclude) CFLAGS += $(CFLAGS_libxenstore)
@@ -88,18 +89,18 @@ xenlockprof: xenlockprof.o # xen-hptool incorrectly uses libxc internals xen-hptool.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc xen-hptool: xen-hptool.o - $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) # xen-mfndump incorrectly uses libxc internals xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc xen-mfndump: xen-mfndump.o - $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS) xenwatchdogd: xenwatchdogd.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) xen-lowmemd: xen-lowmemd.o - $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) gtraceview: gtraceview.o $(CC) $(LDFLAGS) -o $@ $< $(CURSES_LIBS) $(TINFO_LIBS) $(APPEND_LDFLAGS)
tools/misc/xen-hptool.c +7 -6
@@ -1,3 +1,4 @@ +#include <xenevtchn.h> #include <xenctrl.h> #include <xc_private.h> #include <xc_core.h>
@@ -98,7 +99,7 @@ static int hp_mem_query_func(int argc, char *argv[])return ret; } -static int suspend_guest (xc_interface *xch,xc_evtchn *xce,int domid, +static int suspend_guest (xc_interface *xch,xenevtchn_handle *xce,int domid,int *evtchn,int *lockfd) {int port, rc, suspend_evtchn =-1 ;
@@ -123,7 +124,7 @@ static int suspend_guest(xc_interface *xch, xc_evtchn *xce, int domid, } *evtchn = suspend_evtchn; - rc =xc_evtchn_notify (xce, suspend_evtchn); + rc =xenevtchn_notify (xce, suspend_evtchn);if (rc <0 ) {fprintf (stderr,"Failed to notify suspend channel: errno %d\n" , rc);
@@ -198,8 +199,8 @@ static int hp_mem_offline_func(int argc, char *argv[])else if (status &PG_OFFLINE_OWNED ) {int result, suspend_evtchn =-1 , suspend_lockfd =-1 ; -xc_evtchn *xce; - xce =xc_evtchn_open (NULL ,0 ); +xenevtchn_handle *xce; + xce =xenevtchn_open (NULL ,0 );if (xce ==NULL ) {
@@ -214,7 +215,7 @@ static int hp_mem_offline_func(int argc, char *argv[]) {fprintf (stderr,"Failed to suspend guest %d for" " mfn %lx\n" , domid, mfn); -xc_evtchn_close (xce); +xenevtchn_close (xce);return -1 ; }
@@ -238,7 +239,7 @@ static int hp_mem_offline_func(int argc, char *argv[])xc_domain_resume (xch, domid,1 );xc_suspend_evtchn_release (xch, xce, domid, suspend_evtchn, &suspend_lockfd); -xc_evtchn_close (xce); +xenevtchn_close (xce); }break ; }
tools/misc/xen-lowmemd.c +8 -7
@@ -4,22 +4,23 @@*/ #include <stdio.h> +#include <xenevtchn.h> #include <xenctrl.h> #include <xenstore.h> #include <stdlib.h> #include <string.h> static evtchn_port_t virq_port =-1 ; -static xc_evtchn *xce_handle =NULL ; +static xenevtchn_handle *xce_handle =NULL ;static xc_interface *xch =NULL ;static struct xs_handle *xs_handle =NULL ;void cleanup (void ) {if (virq_port >-1 ) -xc_evtchn_unbind (xce_handle, virq_port); +xenevtchn_unbind (xce_handle, virq_port);if (xce_handle) -xc_evtchn_close (xce_handle); +xenevtchn_close (xce_handle);if (xch)xc_interface_close (xch);if (xs_handle)
@@ -94,7 +95,7 @@ int main(int argc, char *argv[])return 1 ; } - xce_handle =xc_evtchn_open (NULL ,0 ); + xce_handle =xenevtchn_open (NULL ,0 );if (xce_handle ==NULL ) {perror ("Failed to open evtchn device" );
@@ -108,7 +109,7 @@ int main(int argc, char *argv[])return 3 ; } -if ((rc =xc_evtchn_bind_virq (xce_handle,VIRQ_ENOMEM )) ==-1 ) +if ((rc =xenevtchn_bind_virq (xce_handle,VIRQ_ENOMEM )) ==-1 ) {perror ("Failed to bind to domain exception virq port" );return 4 ;
@@ -120,7 +121,7 @@ int main(int argc, char *argv[]) {evtchn_port_t port; -if ((port =xc_evtchn_pending (xce_handle)) ==-1 ) +if ((port =xenevtchn_pending (xce_handle)) ==-1 ) {perror ("Failed to listen for pending event channel" );return 5 ;
@@ -134,7 +135,7 @@ int main(int argc, char *argv[])return 6 ; } -if (xc_evtchn_unmask (xce_handle, port) ==-1 )
Lines of this file are not shown. View the raw message.
tools/ocaml/libs/eventchn/xeneventchn_stubs.c +10 -10
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Part of the diff is not shown here. View the raw message.
Re: [PATCH XEN v8 02/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
On Fri, 2016-01-15 at 13:22 +0000, Ian Campbell wrote:
This is the only patch which changed meaningfully in v9, so I'm just posting it that one below FTR, intra-log is:
v9: Refactor over "xenstore: move init-xenstore-domain to tools/helpers" this highlighted that init-xenstore-domain has no need for LDLIBS_xenevtchn and never did, so that hunk is simply dropped.
Only other interesting thing in v9 would have been #05 "tools: Refactor /dev/xen/gnt{dev,shr} wrappers into libxengnttab." which needed some conflict resolution due to "xenstore: move init-xenstore-domain to tools/helpers" but that was all.
Ian.
8<-------
From f63312c8d92c728ff50ee3e5777c2ef7e59aaf3f Mon Sep 17 00:00:00 2001
From: Ian Campbell <[email protected]>
Date: Mon, 1 Jun 2015 16:20:09 +0100
Subject: [PATCH] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
libxenevtchn will provide a stable API and ABI for accessing the evtchn device.
The functions are moved into the xenevtchn namespace to make a clean break from libxc and avoid ambiguity regarding which interfaces are stable.
All in-tree users are updated to use the new names.
Upon request (via #define XC_WANT_COMPAT_EVTCHN_API) libxenctrl will provide a compat API for the old names. This is used by qemu-xen for the time being. qemu-xen-traditional is updated in lockstep.
This leaves a few event channel related functions which go via privcmd (EVTCHNOP) rather than ioctls on the /dev/xen/evtchn device in libxenctrl. Specifically:
- xc_evtchn_alloc_unbound
- xc_evtchn_reset
- xc_evtchn_status
Note that xc_evtchn_alloc_unbound's functionality is also provided by xenevtchn_bind_unbound_port() (née xc_evtchn_bind_unbound_port) and is probably redundant.
These functions do not appear to be needed by qemu-dm, qemu-pv (provision of device model to HVM guests and PV backends respectively) or by libvchan suggesting they are not needed by non-toolstack uses of event channels. QEMU does use these in hw/xenpv/xen_domainbuild.c but that is a "toolstack use".
The new library uses a version script to ensure that only expected symbols are exported and to version them such that ABI guarantees can be kept in the future.
---
Must be applied with:
- "qemu-xen-traditional: Use libxenevtchn" and a corresponding QEMU_TAG update folded here.
- "mini-os: Include libxenevtchn with libxc"" and a corresponding bump to MINIOS_UPSTREAM_REVISION folded in here.
v2: Update doc at same time
Removed some stray compat thing
v3: Moved to tools/libs/evtchn
v4: typedef the xenevtchn_handle in xenguest.h instead of #include, to avoid leaking the libxenevtchn namespace into callers who may not want it. (And also to avoid adding lots of -I to places like stubdom builds)
v5: Handle NULL passed to _close()
v6: Properly port xen-access to new API (instead of a single function call)
v7: Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of open coding the recursion.
v8: Remove *.so on clean, add distclean target.
v9: Refactor over "xenstore: move init-xenstore-domain to tools/helpers" this highlighted that init-xenstore-domain has no need for LDLIBS_xenevtchn and never did, so that hunk is simply dropped.
---
.gitignore | 1 + stubdom/Makefile | 17 +- tools/Makefile | 5 +- tools/Rules.mk | 14 +- tools/console/Makefile | 2 + tools/console/daemon/io.c | 43 ++-- tools/libs/Makefile | 1 + tools/libs/evtchn/Makefile | 69 +++++++ tools/libs/evtchn/core.c | 72 +++++++ tools/libs/evtchn/freebsd.c | 138 +++++++++++++ tools/libs/evtchn/include/xenevtchn.h | 150 ++++++++++++++ tools/libs/evtchn/libxenevtchn.map | 19 ++ tools/libs/evtchn/linux.c | 136 +++++++++++++ tools/libs/evtchn/minios.c | 269 ++++++++++++++++++++++++++ tools/libs/evtchn/netbsd.c | 147 ++++++++++++++ tools/libs/evtchn/private.h | 25 +++ tools/libs/evtchn/solaris.c | 135 +++++++++++++ tools/libs/toollog/include/xentoollog.h | 10 + tools/libs/toollog/xtl_core.c | 10 + tools/libs/toollog/xtl_logger_stdio.c | 10 + tools/libvchan/Makefile | 6 +- tools/libvchan/init.c | 20 +- tools/libvchan/io.c | 12 +- tools/libvchan/libxenvchan.h | 3 +- tools/libxc/Makefile | 8 +- tools/libxc/include/xenctrl.h | 99 +--------- tools/libxc/include/xenctrl_compat.h | 48 +++++
tools/libxc/include/xenguest.h | 14 +- tools/libxc/xc_evtchn_compat.c | 75 +++++++ tools/libxc/xc_freebsd_osdep.c | 101 ---------- tools/libxc/xc_linux_osdep.c | 95 --------- tools/libxc/xc_minios.c | 221 --------------------- tools/libxc/xc_netbsd.c | 109 ----------- tools/libxc/xc_private.c | 40 ---- tools/libxc/xc_private.h | 7 - tools/libxc/xc_solaris.c | 97 ---------- tools/libxc/xc_suspend.c | 18 +-
tools/libxl/Makefile | 5 +- tools/libxl/libxl.c | 2 +- tools/libxl/libxl_dom_suspend.c | 4 +- tools/libxl/libxl_event.c | 14 +- tools/libxl/libxl_internal.h | 5 +- tools/misc/Makefile | 7 +- tools/misc/xen-hptool.c | 13 +- tools/misc/xen-lowmemd.c | 15 +- tools/ocaml/libs/eventchn/Makefile | 4 +- tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 20 +- tools/python/setup.py | 7 +- tools/tests/xen-access/Makefile | 3 +- tools/tests/xen-access/xen-access.c | 21 +- tools/xcutils/Makefile | 4 +- tools/xenmon/Makefile | 2 + tools/xenmon/xenbaked.c | 13 +- tools/xenpaging/Makefile | 4 +- tools/xenpaging/xenpaging.c | 18 +- tools/xenpaging/xenpaging.h | 3 +- tools/xenstore/Makefile | 3 +- tools/xenstore/xenstored_core.c | 6 +- tools/xenstore/xenstored_domain.c | 25 +-- tools/xentrace/Makefile | 5 +- tools/xentrace/xentrace.c | 13 +-
61 files changed, 1538 insertions(+), 924 deletions(-)
create mode 100644 tools/libs/evtchn/Makefile create mode 100644 tools/libs/evtchn/core.c create mode 100644 tools/libs/evtchn/freebsd.c create mode 100644 tools/libs/evtchn/include/xenevtchn.h create mode 100644 tools/libs/evtchn/libxenevtchn.map create mode 100644 tools/libs/evtchn/linux.c create mode 100644 tools/libs/evtchn/minios.c create mode 100644 tools/libs/evtchn/netbsd.c create mode 100644 tools/libs/evtchn/private.h create mode 100644 tools/libs/evtchn/solaris.c create mode 100644 tools/libxc/include/xenctrl_compat.h create mode 100644 tools/libxc/xc_evtchn_compat.c
.gitignore +0 -0
@@ -62,6 +62,7 @@ stubdom/ioemu
stubdom/ioemu/
stubdom/libs-*
stubdom/libxc-*
+stubdom/libxenevtchn-*
stubdom/libxentoollog-*
stubdom/lwip-*
stubdom/lwip/
stubdom/Makefile +0 -0
@@ -319,6 +319,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
ln -sf $(XEN_ROOT)/tools/libs/toollog/include/*.h . && \
ln -sf $(XEN_ROOT)/tools/libs/toollog/*.c . && \
ln -sf $(XEN_ROOT)/tools/libs/toollog/Makefile . )
+ mkdir -p libs-$(XEN_TARGET_ARCH)/evtchn/include
+ [ -h libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/evtchn && \
+ ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.h . && \
+ ln -sf $(XEN_ROOT)/tools/libs/evtchn/include/*.h include/ && \
+ ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.c . && \
+ ln -sf $(XEN_ROOT)/tools/libs/evtchn/Makefile . )
mkdir -p libxc-$(XEN_TARGET_ARCH)
[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -351,12 +357,21 @@ libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: mk-headers-$(XEN_TARGET_ARCH) $ CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog
#######
+# libxenevtchn
+#######
+
+.PHONY: libxenevtchn
+libxenevtchn: libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a +libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
+ CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn
+
+#######
# libxc ####### .PHONY: libxc libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a -libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog cross-zlib +libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn cross-zlib CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH) libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
tools/Makefile +0 -0
@@ -249,8 +249,10 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
--libdir=$(LIBEXEC_LIB) \
--includedir=$(LIBEXEC_INC) \
--source-path=$$source \
- --extra-cflags="-I$(XEN_ROOT)/tools/include \
+ --extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \
+ -I$(XEN_ROOT)/tools/include \
-I$(XEN_ROOT)/tools/libs/toollog/include \
+ -I$(XEN_ROOT)/tools/libs/evtchn/include \
-I$(XEN_ROOT)/tools/libxc/include \
-I$(XEN_ROOT)/tools/xenstore/include \
-I$(XEN_ROOT)/tools/xenstore/compat/include \
@@ -258,6 +260,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find --extra-ldflags="-L$(XEN_ROOT)/tools/libxc \
-L$(XEN_ROOT)/tools/xenstore \
-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
+ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
$(QEMU_UPSTREAM_RPATH)" \
--bindir=$(LIBEXEC_BIN) \
--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +0 -0
@@ -11,6 +11,7 @@ INSTALL = $(XEN_ROOT)/tools/cross-install
XEN_INCLUDE = $(XEN_ROOT)/tools/include
XEN_LIBXENTOOLLOG = $(XEN_ROOT)/tools/libs/toollog
+XEN_LIBXENEVTCHN = $(XEN_ROOT)/tools/libs/evtchn
XEN_LIBXC = $(XEN_ROOT)/tools/libxc
XEN_XENLIGHT = $(XEN_ROOT)/tools/libxl
XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore
@@ -82,13 +83,18 @@ SHDEPS_libxentoollog =
LDLIBS_libxentoollog = $(XEN_LIBXENTOOLLOG)/libxentoollog$(libextension) SHLIB_libxentoollog = -Wl,-rpath-link=$(XEN_LIBXENTOOLLOG)
+CFLAGS_libxenevtchn = -I$(XEN_LIBXENEVTCHN)/include $(CFLAGS_xeninclude) +SHDEPS_libxenevtchn =
+LDLIBS_libxenevtchn = $(XEN_LIBXENEVTCHN)/libxenevtchn$(libextension) +SHLIB_libxenevtchn = -Wl,-rpath-link=$(XEN_LIBXENEVTCHN)
+
CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude) -SHDEPS_libxenctrl = $(SHLIB_libxentoollog)
+SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn)
LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension) SHLIB_libxenctrl = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
-CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_xeninclude) -SHDEPS_libxenguest =
+CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_xeninclude) +SHDEPS_libxenguest = $(SHLIB_libxenevtchn)
LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_LIBXC)/libxenguest$(libextension) SHLIB_libxenguest = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC)
@@ -103,7 +109,7 @@ LDLIBS_libxenstat = $(SHDEPS_libxenstat) $(XEN_LIBXENSTAT)/libxenstat$(libexten SHLIB_libxenstat = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_LIBXENSTAT)
CFLAGS_libxenvchan = -I$(XEN_LIBVCHAN)
-SHDEPS_libxenvchan = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
+SHDEPS_libxenvchan = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn) LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libextension) SHLIB_libxenvchan = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
tools/console/Makefile +0 -0
@@ -3,8 +3,10 @@ include $(XEN_ROOT)/tools/Rules.mk
CFLAGS += -Werror
+CFLAGS += $(CFLAGS_libxenevtchn)
CFLAGS += $(CFLAGS_libxenctrl)
CFLAGS += $(CFLAGS_libxenstore)
+LDLIBS += $(LDLIBS_libxenevtchn)
LDLIBS += $(LDLIBS_libxenctrl)
LDLIBS += $(LDLIBS_libxenstore)
LDLIBS += $(SOCKET_LIBS)
tools/console/daemon/io.c +0 -0
@@ -21,6 +21,7 @@
#include "utils.h"
#include "io.h"
+#include <xenevtchn.h>
#include <xenstore.h>
#include <xen/io/console.h>
#include <xen/grant_table.h>
@@ -101,7 +102,7 @@ struct domain {
int ring_ref;
evtchn_port_or_error_t local_port;
evtchn_port_or_error_t remote_port;
- xc_evtchn *xce_handle;
+ xenevtchn_handle *xce_handle;
int xce_pollfd_idx;
struct xencons_interface *interface;
int event_count;
@@ -185,7 +186,7 @@ static void buffer_append(struct domain *dom)
xen_mb();
intf->out_cons = cons;
- xc_evtchn_notify(dom->xce_handle, dom->local_port);
+ xenevtchn_notify(dom->xce_handle, dom->local_port);
/* Get the data to the logfile as early as possible because if
* no one is listening on the console pty then it will fill up @@ -584,22 +585,22 @@ static int domain_create_ring(struct domain *dom) dom->local_port = -1;
dom->remote_port = -1;
if (dom->xce_handle != NULL)
- xc_evtchn_close(dom->xce_handle);
+ xenevtchn_close(dom->xce_handle);
/* Opening evtchn independently for each console is a bit
* wasteful, but that's how the code is structured... */
- dom->xce_handle = xc_evtchn_open(NULL, 0);
+ dom->xce_handle = xenevtchn_open(NULL, 0);
if (dom->xce_handle == NULL) {
err = errno;
goto out;
}
- rc = xc_evtchn_bind_interdomain(dom->xce_handle,
+ rc = xenevtchn_bind_interdomain(dom->xce_handle,
dom->domid, remote_port);
if (rc == -1) {
err = errno;
- xc_evtchn_close(dom->xce_handle);
+ xenevtchn_close(dom->xce_handle);
dom->xce_handle = NULL;
goto out;
}
@@ -609,7 +610,7 @@ static int domain_create_ring(struct domain *dom) if (dom->master_fd == -1) {
if (!domain_create_tty(dom)) {
err = errno;
- xc_evtchn_close(dom->xce_handle);
+ xenevtchn_close(dom->xce_handle);
dom->xce_handle = NULL;
dom->local_port = -1;
dom->remote_port = -1;
@@ -749,7 +750,7 @@ static void shutdown_domain(struct domain *d) watch_domain(d, false);
domain_unmap_interface(d);
if (d->xce_handle != NULL)
- xc_evtchn_close(d->xce_handle);
+ xenevtchn_close(d->xce_handle);
d->xce_handle = NULL;
}
@@ -839,7 +840,7 @@ static void handle_tty_read(struct domain *dom)
}
xen_wmb();
intf->in_prod = prod;
- xc_evtchn_notify(dom->xce_handle, dom->local_port);
+ xenevtchn_notify(dom->xce_handle, dom->local_port);
} else {
domain_close_tty(dom);
shutdown_domain(dom);
@@ -871,7 +872,7 @@ static void handle_ring_read(struct domain *dom) if (dom->is_dead)
return;
- if ((port = xc_evtchn_pending(dom->xce_handle)) == -1)
+ if ((port = xenevtchn_pending(dom->xce_handle)) == -1)
return;
dom->event_count++;
@@ -879,7 +880,7 @@ static void handle_ring_read(struct domain *dom) buffer_append(dom);
if (dom->event_count < RATE_LIMIT_ALLOWANCE)
- (void)xc_evtchn_unmask(dom->xce_handle, port);
+ (void)xenevtchn_unmask(dom->xce_handle, port);
}
static void handle_xs(void)
@@ -906,7 +907,7 @@ static void handle_xs(void)
free(vec);
}
-static void handle_hv_logs(xc_evtchn *xce_handle, bool force)
+static void handle_hv_logs(xenevtchn_handle *xce_handle, bool force) {
static char buffer[1024*16];
char *bufptr = buffer;
@@ -914,7 +915,7 @@ static void handle_hv_logs(xc_evtchn *xce_handle, bool force) static uint32_t index = 0;
evtchn_port_or_error_t port = -1;
- if (!force && ((port = xc_evtchn_pending(xce_handle)) == -1))
+ if (!force && ((port = xenevtchn_pending(xce_handle)) == -1))
return;
do
@@ -938,7 +939,7 @@ static void handle_hv_logs(xc_evtchn *xce_handle, bool force) } while (size == sizeof(buffer));
if (port != -1)
- (void)xc_evtchn_unmask(xce_handle, port);
+ (void)xenevtchn_unmask(xce_handle, port);
}
static void handle_log_reload(void)
@@ -1006,10 +1007,10 @@ void handle_io(void)
evtchn_port_or_error_t log_hv_evtchn = -1;
int xce_pollfd_idx = -1;
int xs_pollfd_idx = -1;
- xc_evtchn *xce_handle = NULL;
+ xenevtchn_handle *xce_handle = NULL;
if (log_hv) {
- xce_handle = xc_evtchn_open(NULL, 0);
+ xce_handle = xenevtchn_open(NULL, 0);
if (xce_handle == NULL) {
dolog(LOG_ERR, "Failed to open xce handle: %d (%s)", errno, strerror(errno));
@@ -1018,7 +1019,7 @@ void handle_io(void)
log_hv_fd = create_hv_log();
if (log_hv_fd == -1)
goto out;
- log_hv_evtchn = xc_evtchn_bind_virq(xce_handle, VIRQ_CON_RING);
+ log_hv_evtchn = xenevtchn_bind_virq(xce_handle, VIRQ_CON_RING);
if (log_hv_evtchn == -1) {
dolog(LOG_ERR, "Failed to bind to VIRQ_CON_RING: " "%d (%s)", errno, strerror(errno));
@@ -1047,7 +1048,7 @@ void handle_io(void)
xs_pollfd_idx = set_fds(xs_fileno(xs), POLLIN|POLLPRI);
if (log_hv)
- xce_pollfd_idx = set_fds(xc_evtchn_fd(xce_handle),
+ xce_pollfd_idx = set_fds(xenevtchn_fd(xce_handle),
POLLIN|POLLPRI);
if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
@@ -1066,7 +1067,7 @@ void handle_io(void)
if ((now+5) > d->next_period) {
d->next_period = now + RATE_LIMIT_PERIOD; if (d->event_count >= RATE_LIMIT_ALLOWANCE) {
- (void)xc_evtchn_unmask(d->xce_handle, d->local_port);
+ (void)xenevtchn_unmask(d->xce_handle, d->local_port);
}
d->event_count = 0;
}
@@ -1082,7 +1083,7 @@ void handle_io(void)
if (discard_overflowed_data || !d->buffer.max_capacity || d->buffer.size < d->buffer.max_capacity) {
- int evtchn_fd = xc_evtchn_fd(d->xce_handle);
+ int evtchn_fd = xenevtchn_fd(d->xce_handle);
d->xce_pollfd_idx = set_fds(evtchn_fd, POLLIN|POLLPRI); }
@@ -1202,7 +1203,7 @@ void handle_io(void)
log_hv_fd = -1;
}
if (xce_handle != NULL) {
- xc_evtchn_close(xce_handle);
+ xenevtchn_close(xce_handle);
xce_handle = NULL;
}
if (xcg_handle != NULL) {
tools/libs/Makefile +0 -0
@@ -3,5 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
SUBDIRS-y :=
SUBDIRS-y += toollog
+SUBDIRS-y += evtchn
all clean install distclean: %: subdirs-%
tools/libs/evtchn/Makefile new file +69 -0
69 lines not on this page · raw message
tools/libs/evtchn/core.c new file +72 -0
72 lines not on this page · raw message
tools/libs/evtchn/freebsd.c new file +138 -0
138 lines not on this page · raw message
tools/libs/evtchn/include/xenevtchn.h new file +150 -0
150 lines not on this page · raw message
tools/libs/evtchn/libxenevtchn.map new file +19 -0
@@ -0,0 +1,19 @@ +VERS_1.0 { + global: + xenevtchn_open; + xenevtchn_close; + + xenevtchn_fd; + + xenevtchn_bind_unbound_port; + xenevtchn_bind_interdomain; + xenevtchn_bind_virq; + + xenevtchn_notify; + + xenevtchn_unbind; + xenevtchn_unmask; + + xenevtchn_pending; + local: *; /* Do not expose anything by default */ +};
tools/libs/evtchn/linux.c new file +136 -0
136 lines not on this page · raw message
tools/libs/evtchn/minios.c new file +269 -0
269 lines not on this page · raw message
tools/libs/evtchn/netbsd.c new file +147 -0
147 lines not on this page · raw message
tools/libs/evtchn/private.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef XENEVTCHN_PRIVATE_H +#define XENEVTCHN_PRIVATE_H + +#include <xentoollog.h> +#include <xenevtchn.h> + +struct xenevtchn_handle { + xentoollog_logger *logger, *logger_tofree; + int fd; +}; + +int osdep_evtchn_open (xenevtchn_handle *xce); +int osdep_evtchn_close (xenevtchn_handle *xce); + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libs/evtchn/solaris.c new file +135 -0
135 lines not on this page · raw message
tools/libs/toollog/include/xentoollog.h +0 -0
@@ -134,3 +134,13 @@ const char *xtl_level_to_string(xentoollog_level); /* never fails */
#endif /* XENTOOLLOG_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libs/toollog/xtl_core.c +0 -0
@@ -81,3 +81,13 @@ void xtl_logger_destroy(struct xentoollog_logger *logger) {
if (!logger) return;
logger->destroy(logger);
}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libs/toollog/xtl_logger_stdio.c +0 -0
@@ -190,3 +190,13 @@ xentoollog_logger_stdiostream *xtl_createlogger_stdiostream
return XTL_NEW_LOGGER(stdiostream, newlogger); }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libvchan/Makefile +0 -0
@@ -10,9 +10,9 @@ NODE_OBJS = node.o
NODE2_OBJS = node-select.o
LIBVCHAN_PIC_OBJS = $(patsubst %.o,%.opic,$(LIBVCHAN_OBJS))
-LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl)
-$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxenctrl) -$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
+LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenevtchn) +$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) +$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn)
MAJOR = 1.0
MINOR = 0
tools/libvchan/init.c +0 -0
@@ -216,25 +216,25 @@ static int init_evt_srv(struct libxenvchan *ctrl, int domain, xentoollog_logger
{
evtchn_port_or_error_t port;
- ctrl->event = xc_evtchn_open(logger, 0);
+ ctrl->event = xenevtchn_open(logger, 0);
if (!ctrl->event)
return -1;
- port = xc_evtchn_bind_unbound_port(ctrl->event, domain);
+ port = xenevtchn_bind_unbound_port(ctrl->event, domain);
if (port < 0)
goto fail;
ctrl->event_port = port;
- if (xc_evtchn_unmask(ctrl->event, ctrl->event_port))
+ if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
goto fail;
return 0;
fail:
if (port >= 0)
- xc_evtchn_unbind(ctrl->event, port);
+ xenevtchn_unbind(ctrl->event, port);
- xc_evtchn_close(ctrl->event);
+ xenevtchn_close(ctrl->event);
ctrl->event = NULL;
return -1;
@@ -346,26 +346,26 @@ static int init_evt_cli(struct libxenvchan *ctrl, int domain, xentoollog_logger {
evtchn_port_or_error_t port;
- ctrl->event = xc_evtchn_open(logger, 0);
+ ctrl->event = xenevtchn_open(logger, 0);
if (!ctrl->event)
return -1;
- port = xc_evtchn_bind_interdomain(ctrl->event,
+ port = xenevtchn_bind_interdomain(ctrl->event,
domain, ctrl->event_port);
if (port < 0)
goto fail;
ctrl->event_port = port;
- if (xc_evtchn_unmask(ctrl->event, ctrl->event_port))
+ if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
goto fail;
return 0;
fail:
if (port >= 0)
- xc_evtchn_unbind(ctrl->event, port);
+ xenevtchn_unbind(ctrl->event, port);
- xc_evtchn_close(ctrl->event);
+ xenevtchn_close(ctrl->event);
ctrl->event = NULL;
return -1;
tools/libvchan/io.c +0 -0
@@ -105,7 +105,7 @@ static inline int send_notify(struct libxenvchan *ctrl, uint8_t bit)
notify = ctrl->is_server ? &ctrl->ring->srv_notify : &ctrl->ring->cli_notify; prev = __sync_fetch_and_and(notify, ~bit);
if (prev & bit)
- return xc_evtchn_notify(ctrl->event, ctrl->event_port);
+ return xenevtchn_notify(ctrl->event, ctrl->event_port);
else
return 0;
}
@@ -196,10 +196,10 @@ int libxenvchan_buffer_space(struct libxenvchan *ctrl)
int libxenvchan_wait(struct libxenvchan *ctrl)
{
- int ret = xc_evtchn_pending(ctrl->event);
+ int ret = xenevtchn_pending(ctrl->event);
if (ret < 0)
return -1;
- xc_evtchn_unmask(ctrl->event, ret);
+ xenevtchn_unmask(ctrl->event, ret);
return 0;
}
@@ -352,7 +352,7 @@ int libxenvchan_is_open(struct libxenvchan* ctrl)
int libxenvchan_fd_for_select(struct libxenvchan *ctrl)
{
- return xc_evtchn_fd(ctrl->event);
+ return xenevtchn_fd(ctrl->event);
}
void libxenvchan_close(struct libxenvchan *ctrl)
@@ -374,8 +374,8 @@ void libxenvchan_close(struct libxenvchan *ctrl)
}
if (ctrl->event) {
if (ctrl->ring)
- xc_evtchn_notify(ctrl->event, ctrl->event_port);
- xc_evtchn_close(ctrl->event);
+ xenevtchn_notify(ctrl->event, ctrl->event_port);
+ xenevtchn_close(ctrl->event);
}
if (ctrl->is_server) {
if (ctrl->gntshr)
tools/libvchan/libxenvchan.h +0 -0
@@ -44,6 +44,7 @@
#include <xen/io/libxenvchan.h>
#include <xen/sys/evtchn.h>
+#include <xenevtchn.h>
#include <xenctrl.h>
struct libxenvchan_ring {
@@ -71,7 +72,7 @@ struct libxenvchan {
/* Pointer to shared ring page */
struct vchan_interface *ring;
/* event channel interface */
- xc_evtchn *event;
+ xenevtchn_handle *event;
uint32_t event_port;
/* informative flags: are we acting as server? */ int is_server:1;
tools/libxc/Makefile +0 -0
@@ -48,6 +48,7 @@ CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
+CTRL_SRCS-y += xc_evtchn_compat.c
GUEST_SRCS-y :=
GUEST_SRCS-y += xg_private.c xc_suspend.c
@@ -111,6 +112,7 @@ CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
CFLAGS += $(PTHREAD_CFLAGS)
CFLAGS += $(CFLAGS_libxentoollog)
+CFLAGS += $(CFLAGS_libxenevtchn)
CTRL_LIB_OBJS := $(patsubst %.c,%.o,$(CTRL_SRCS-y))
CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y))
@@ -164,7 +166,7 @@ install: build
$(INSTALL_DATA) libxenctrl.a $(DESTDIR)$(libdir)
$(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR) $(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenctrl.so
- $(INSTALL_DATA) include/xenctrl.h include/xenctrlosdep.h $(DESTDIR)$(includedir)
+ $(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h include/xenctrlosdep.h $(DESTDIR)$(includedir)
$(INSTALL_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir) $(INSTALL_DATA) libxenguest.a $(DESTDIR)$(libdir)
$(SYMLINK_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenguest.so.$(MAJOR) @@ -207,7 +209,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR) $(SYMLINK_SHLIB) $< $@
libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
- $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+ $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
# libxenguest @@ -230,7 +232,7 @@ xc_dom_bzimageloader.opic: CFLAGS += $(call zlib-options,D) libxenguest.so.$(MAJOR).$(MINOR): COMPRESSION_LIBS = $(call zlib-options,l) libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so - $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz $(LDLIBS_libxenctrl) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) xenctrl_osdep_ENOSYS.so: $(OSDEP_PIC_OBJS) libxenctrl.so $(CC) $(LDFLAGS) $(SHLIB_LDFLAGS) -o $@ $(OSDEP_PIC_OBJS) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
tools/libxc/include/xenctrl.h +0 -0
@@ -117,7 +117,6 @@
*/
typedef struct xc_interface_core xc_interface;
-typedef struct xenevtchn_handle xc_evtchn;
typedef struct xc_interface_core xc_gnttab;
typedef struct xc_interface_core xc_gntshr;
@@ -1085,7 +1084,6 @@ int xc_cpupool_movedomain(xc_interface *xch,
*/
xc_cpumap_t xc_cpupool_freeinfo(xc_interface *xch);
-
/*
* EVENT CHANNEL FUNCTIONS
*
@@ -1120,101 +1118,7 @@ int xc_evtchn_reset(xc_interface *xch,
typedef struct evtchn_status xc_evtchn_status_t;
int xc_evtchn_status(xc_interface *xch, xc_evtchn_status_t *status);
-/*
- * Return a handle to the event channel driver, or NULL on failure, in
- * which case errno will be set appropriately.
- *
- * Note:
- * After fork a child process must not use any opened xc evtchn
- * handle inherited from their parent. They must open a new handle if
- * they want to interact with xc.
- *
- * Before Xen pre-4.1 this function would sometimes report errors with perror.
- */
-xc_evtchn *xc_evtchn_open(xentoollog_logger *logger,
- unsigned open_flags);
-/*
- * Close a handle previously allocated with xc_evtchn_open().
- */
-int xc_evtchn_close(xc_evtchn *xce);
-
-/*
- * Return an fd that can be select()ed on.
- *
- * Note that due to bugs, setting this fd to non blocking may not
- * work: you would hope that it would result in xc_evtchn_pending
- * failing with EWOULDBLOCK if there are no events signaled, but in
- * fact it may block. (Bug is present in at least Linux 3.12, and
- * perhaps on other platforms or later version.)
- *
- * To be safe, you must use poll() or select() before each call to
- * xc_evtchn_pending. If you have multiple threads (or processes)
- * sharing a single xce handle this will not work, and there is no
- * straightforward workaround. Please design your program some other
- * way.
- */
-int xc_evtchn_fd(xc_evtchn *xce);
-
-/*
- * Notify the given event channel. Returns -1 on failure, in which case
- * errno will be set appropriately.
- */
-int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port);
-
-/*
- * Returns a new event port awaiting interdomain connection from the given
- * domain ID, or -1 on failure, in which case errno will be set appropriately.
- */
-evtchn_port_or_error_t
-xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid);
-
-/*
- * Returns a new event port bound to the remote port for the given domain ID,
- * or -1 on failure, in which case errno will be set appropriately.
- */
-evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
- evtchn_port_t remote_port);
-
-/*
- * Bind an event channel to the given VIRQ. Returns the event channel bound to
- * the VIRQ, or -1 on failure, in which case errno will be set appropriately.
- */
-evtchn_port_or_error_t
-xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq);
-
-/*
- * Unbind the given event channel. Returns -1 on failure, in which case errno
- * will be set appropriately.
- */
-int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port);
-
-/*
- * Return the next event channel to become pending, or -1 on failure, in which
- * case errno will be set appropriately.
- *
- * At the hypervisor level the event channel will have been masked,
- * and then cleared, by the underlying machinery (evtchn kernel
- * driver, or equivalent). So if the event channel is signaled again
- * after it is returned here, it will be queued up, and delivered
- * again after you unmask it. (See the documentation in the Xen
- * public header event_channel.h.)
- *
- * On receiving the notification from xc_evtchn_pending, you should
- * normally: check (by other means) what work needs doing; do the
- * necessary work (if any); unmask the event channel with
- * xc_evtchn_unmask (if you want to receive any further
- * notifications).
- */
-evtchn_port_or_error_t
-xc_evtchn_pending(xc_evtchn *xce);
-
-/*
- * Unmask the given event channel. Returns -1 on failure, in which case errno
- * will be set appropriately.
- */
-int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port);
int xc_physdev_pci_access_modify(xc_interface *xch,
uint32_t domid,
@@ -2851,6 +2755,9 @@ int xc_psr_cat_get_l3_info(xc_interface *xch, uint32_t socket, bool *cdp_enabled);
#endif
+/* Compat shims */
+#include "xenctrl_compat.h"
+
#endif /* XENCTRL_H */
/*
tools/libxc/include/xenctrl_compat.h new file +48 -0
48 lines not on this page · raw message
tools/libxc/include/xenguest.h +0 -0
@@ -34,6 +34,12 @@
#define X86_64_B_SIZE 64
#define X86_32_B_SIZE 32
+/*
+ * User not using xc_suspend_* / xc_await_suspent may not want to
+ * include the full libxenevtchn API here.
+ */
+typedef struct xenevtchn_handle xenevtchn_handle;
+
/* callbacks provided by xc_domain_save */
struct save_callbacks {
/* Called after expiration of checkpoint interval,
@@ -161,18 +167,18 @@ struct xc_hvm_firmware_module {
* Sets *lockfd to -1.
* Has deallocated everything even on error.
*/
-int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn, int *lockfd); +int xc_suspend_evtchn_release(xc_interface *xch, xenevtchn_handle *xce, int domid, int suspend_evtchn, int *lockfd);
/**
* This function eats the initial notification.
* xce must not be used for anything else
* See xc_suspend_evtchn_init_sane re lockfd.
*/
-int xc_suspend_evtchn_init_exclusive(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_init_exclusive(xc_interface *xch, xenevtchn_handle *xce,
int domid, int port, int *lockfd);
/* xce must not be used for anything else */
-int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn);
+int xc_await_suspend(xc_interface *xch, xenevtchn_handle *xce, int suspend_evtchn);
/**
* The port will be signaled immediately after this call
@@ -181,7 +187,7 @@ int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn);
* and fed to xc_suspend_evtchn_release. (On error *lockfd is
* undefined and xc_suspend_evtchn_release is not allowed.)
*/
-int xc_suspend_evtchn_init_sane(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_init_sane(xc_interface *xch, xenevtchn_handle *xce,
int domid, int port, int *lockfd);
int xc_mark_page_online(xc_interface *xch, unsigned long start,
tools/libxc/xc_evtchn_compat.c new file +75 -0
75 lines not on this page · raw message
tools/libxc/xc_freebsd_osdep.c +0 -0
@@ -31,13 +31,11 @@
#include <sys/ioctl.h>
#include <xen/memory.h>
-#include <xen/sys/evtchn.h>
#include "xenctrl.h"
#include "xenctrlosdep.h"
#define PRIVCMD_DEV "/dev/xen/privcmd"
-#define EVTCHN_DEV "/dev/xen/evtchn"
#define PERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m \
" (%d = %s)", ## _a , errno, xc_strerror(xch, errno)) @@ -251,105 +249,6 @@ static struct xc_osdep_ops freebsd_privcmd_ops = { },
};
-/*-------------------------- Evtchn device interface -------------------------*/ -int osdep_evtchn_open(xc_evtchn *xce)
-{
- int fd = open(EVTCHN_DEV, O_RDWR);
- if ( fd == -1 )
- return -1;
- xce->fd = fd;
- return 0;
-}
-
-int osdep_evtchn_close(xc_evtchn *xce)
-{
- if ( xce->fd == -1 )
- return 0;
-
- return close(xce->fd);
-}
-
-int xc_evtchn_fd(xc_evtchn *xce)
-{
- return xce->fd;
-}
-
-/*------------------------------ Evtchn interface ----------------------------*/ -int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- struct ioctl_evtchn_notify notify;
-
- notify.port = port;
-
- return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) -{
- int ret, fd = xce->fd;
- struct ioctl_evtchn_bind_unbound_port bind;
-
- bind.remote_domain = domid;
-
- ret = ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
- return ( ret == 0 ) ? bind.port : ret;
-}
-
-evtchn_port_or_error_t
-xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, evtchn_port_t remote_port) -{
- int ret, fd = xce->fd;
- struct ioctl_evtchn_bind_interdomain bind;
-
- bind.remote_domain = domid;
- bind.remote_port = remote_port;
-
- ret = ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
- return ( ret == 0 ) ? bind.port : ret;
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) -{
- int ret, fd = xce->fd;
- struct ioctl_evtchn_bind_virq bind;
-
- bind.virq = virq;
-
- ret = ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
- return ( ret == 0 ) ? bind.port : ret;
-}
-
-int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- struct ioctl_evtchn_unbind unbind;
-
- unbind.port = port;
-
- return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind);
-}
-
-evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce)
-{
- int fd = xce->fd;
- evtchn_port_t port;
-
- if ( read(fd, &port, sizeof(port)) != sizeof(port) )
- return -1;
-
- return port;
-}
-
-int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
-
- if ( write(fd, &port, sizeof(port)) != sizeof(port) )
- return -1;
- return 0;
-}
-
/*---------------------------- FreeBSD interface -----------------------------*/ static struct xc_osdep_ops *
freebsd_osdep_init(xc_interface *xch, enum xc_osdep_type type)
tools/libxc/xc_linux_osdep.c +0 -0
@@ -31,7 +31,6 @@
#include <sys/ioctl.h>
#include <xen/memory.h>
-#include <xen/sys/evtchn.h>
#include <xen/sys/gntdev.h>
#include <xen/sys/gntalloc.h>
@@ -461,100 +460,6 @@ static struct xc_osdep_ops linux_privcmd_ops = {
#define DEVXEN "/dev/xen/"
-int osdep_evtchn_open(xc_evtchn *xce)
-{
- int fd = open(DEVXEN "evtchn", O_RDWR);
- if ( fd == -1 )
- return -1;
- xce->fd = fd;
- return 0;
-}
-
-int osdep_evtchn_close(xc_evtchn *xce)
-{
- if ( xce->fd == -1 )
- return 0;
-
- return close(xce->fd);
-}
-
-int xc_evtchn_fd(xc_evtchn *xce)
-{
- return xce->fd;
-}
-
-int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- struct ioctl_evtchn_notify notify;
-
- notify.port = port;
-
- return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) -{
- int fd = xce->fd;
- struct ioctl_evtchn_bind_unbound_port bind;
-
- bind.remote_domain = domid;
-
- return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, - evtchn_port_t remote_port) -{
- int fd = xce->fd;
- struct ioctl_evtchn_bind_interdomain bind;
-
- bind.remote_domain = domid;
- bind.remote_port = remote_port;
-
- return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) -{
- int fd = xce->fd;
- struct ioctl_evtchn_bind_virq bind;
-
- bind.virq = virq;
-
- return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
-}
-
-int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- struct ioctl_evtchn_unbind unbind;
-
- unbind.port = port;
-
- return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind);
-}
-
-evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce)
-{
- int fd = xce->fd;
- evtchn_port_t port;
-
- if ( read(fd, &port, sizeof(port)) != sizeof(port) )
- return -1;
-
- return port;
-}
-
-int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
-
- if ( write(fd, &port, sizeof(port)) != sizeof(port) )
- return -1;
- return 0;
-}
-
static xc_osdep_handle linux_gnttab_open(xc_gnttab *xcg)
{
int fd = open(DEVXEN "gntdev", O_RDWR);
tools/libxc/xc_minios.c +0 -0
@@ -19,14 +19,11 @@
*/
#undef NDEBUG
-#include "xen-external/bsd-sys-queue.h"
#include <mini-os/types.h>
#include <mini-os/os.h>
#include <mini-os/mm.h>
#include <mini-os/lib.h>
#include <mini-os/gntmap.h>
-#include <mini-os/events.h>
-#include <mini-os/wait.h>
#include <sys/mman.h>
#include <xen/memory.h>
@@ -41,13 +38,9 @@
#include "xc_private.h"
void minios_interface_close_fd(int fd);
-void minios_evtchn_close_fd(int fd);
void minios_gnttab_close_fd(int fd);
extern void minios_interface_close_fd(int fd);
-extern void minios_evtchn_close_fd(int fd);
-
-extern struct wait_queue_head event_queue;
static xc_osdep_handle minios_privcmd_open(xc_interface *xch)
{
@@ -197,220 +190,6 @@ static struct xc_osdep_ops minios_privcmd_ops = {
},
};
-
-/* XXX Note: This is not threadsafe */
-static struct evtchn_port_info* port_alloc(int fd) {
- struct evtchn_port_info *port_info;
- port_info = malloc(sizeof(struct evtchn_port_info));
- if (port_info == NULL)
- return NULL;
- port_info->pending = 0;
- port_info->port = -1;
- port_info->bound = 0;
-
- LIST_INSERT_HEAD(&files[fd].evtchn.ports, port_info, list);
- return port_info;
-}
-
-static void port_dealloc(struct evtchn_port_info *port_info) {
- if (port_info->bound)
- unbind_evtchn(port_info->port);
- LIST_REMOVE(port_info, list);
- free(port_info);
-}
-
-int osdep_evtchn_open(xc_evtchn *xce)
-{
- int fd = alloc_fd(FTYPE_EVTCHN);
- if ( fd == -1 )
- return -1;
- LIST_INIT(&files[fd].evtchn.ports);
- xce->fd = fd;
- printf("evtchn_open() -> %d\n", fd);
- return 0;
-}
-
-int osdep_evtchn_close(xc_evtchn *xce, xc_osdep_handle h)
-{
- if ( xce->fd == -1 )
- return 0;
-
- return close(xce->fd);
-}
-
-void minios_evtchn_close_fd(int fd)
-{
- struct evtchn_port_info *port_info, *tmp;
- LIST_FOREACH_SAFE(port_info, &files[fd].evtchn.ports, list, tmp)
- port_dealloc(port_info);
-
- files[fd].type = FTYPE_NONE;
-}
-
-int xc_evtchn_fd(xc_evtchn *xce)
-{
- return xce->fd;
-}
-
-int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
-{
- int ret;
-
- ret = notify_remote_via_evtchn(port);
-
- if (ret < 0) {
- errno = -ret;
- ret = -1;
- }
- return ret;
-}
-
-static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data)
-{
- int fd = (int)(intptr_t)data;
- struct evtchn_port_info *port_info;
- assert(files[fd].type == FTYPE_EVTCHN);
- mask_evtchn(port);
- LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) {
- if (port_info->port == port)
- goto found;
- }
- printk("Unknown port for handle %d\n", fd);
- return;
-
- found:
- port_info->pending = 1;
- files[fd].read = 1;
- wake_up(&event_queue);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid)
-{
- int fd = xce->fd;
- struct evtchn_port_info *port_info;
- int ret;
- evtchn_port_t port;
-
- assert(get_current() == main_thread);
- port_info = port_alloc(fd);
- if (port_info == NULL)
- return -1;
-
- printf("xc_evtchn_bind_unbound_port(%d)", domid);
- ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)fd, &port);
- printf(" = %d\n", ret);
-
- if (ret < 0) {
- port_dealloc(port_info);
- errno = -ret;
- return -1;
- }
- port_info->bound = 1;
- port_info->port = port;
- unmask_evtchn(port);
- return port;
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid,
- evtchn_port_t remote_port)
-{
- int fd = xce->fd;
- struct evtchn_port_info *port_info;
- evtchn_port_t local_port;
- int ret;
-
- assert(get_current() == main_thread);
- port_info = port_alloc(fd);
- if (port_info == NULL)
- return -1;
-
- printf("xc_evtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port);
- ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)fd, &local_port); - printf(" = %d\n", ret);
-
- if (ret < 0) {
- port_dealloc(port_info);
- errno = -ret;
- return -1;
- }
- port_info->bound = 1;
- port_info->port = local_port;
- unmask_evtchn(local_port);
- return local_port;
-}
-
-int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- struct evtchn_port_info *port_info;
-
- LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) {
- if (port_info->port == port) {
- port_dealloc(port_info);
- return 0;
- }
- }
- printf("Warning: couldn't find port %"PRId32" for xc handle %x\n", port, fd);
- errno = EINVAL;
- return -1;
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq)
-{
- int fd = xce->fd;
- struct evtchn_port_info *port_info;
- evtchn_port_t port;
-
- assert(get_current() == main_thread);
- port_info = port_alloc(fd);
- if (port_info == NULL)
- return -1;
-
- printf("xc_evtchn_bind_virq(%d)", virq);
- port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)fd);
-
- if (port < 0) {
- port_dealloc(port_info);
- errno = -port;
- return -1;
- }
- port_info->bound = 1;
- port_info->port = port;
- unmask_evtchn(port);
- return port;
-}
-
-evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce)
-{
- int fd = xce->fd;
- struct evtchn_port_info *port_info;
- unsigned long flags;
- evtchn_port_t ret = -1;
-
- local_irq_save(flags);
- files[fd].read = 0;
-
- LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) {
- if (port_info->port != -1 && port_info->pending) {
- if (ret == -1) {
- ret = port_info->port;
- port_info->pending = 0;
- } else {
- files[fd].read = 1;
- break;
- }
- }
- }
- local_irq_restore(flags);
- return ret;
-}
-
-int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
-{
- unmask_evtchn(port);
- return 0;
-}
-
/* Optionally flush file to disk and discard page cache */
void discard_file_cache(xc_interface *xch, int fd, int flush)
{
tools/libxc/xc_netbsd.c +0 -0
@@ -19,7 +19,6 @@
#include "xc_private.h"
-#include <xen/sys/evtchn.h>
#include <unistd.h>
#include <fcntl.h>
#include <malloc.h>
@@ -223,114 +222,6 @@ static struct xc_osdep_ops netbsd_privcmd_ops = { },
};
-#define EVTCHN_DEV_NAME "/dev/xenevt"
-
-int osdep_evtchn_open(xc_evtchn *xce)
-{
- int fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
- if ( fd == -1 )
- return -1;
- xce->fd = fd;
- return 0;
-}
-
-int osdep_evtchn_close(xc_evtchn *xce, xc_osdep_handle h)
-{
- if ( xce->fd == -1 )
- return 0;
-
- return close(xce->fd);
-}
-
-int xc_evtchn_fd(xc_evtchn *xce)
-{
- return xce->fd;
-}
-
-int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- struct ioctl_evtchn_notify notify;
-
- notify.port = port;
-
- return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn * xce, int domid) -{
- int fd = xce->fd;
- struct ioctl_evtchn_bind_unbound_port bind;
- int ret;
-
- bind.remote_domain = domid;
-
- ret = ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
- if (ret == 0)
- return bind.port;
- else
- return -1;
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, - evtchn_port_t remote_port) -{
- int fd = xce->fd;
- struct ioctl_evtchn_bind_interdomain bind;
- int ret;
-
- bind.remote_domain = domid;
- bind.remote_port = remote_port;
-
- ret = ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
- if (ret == 0)
- return bind.port;
- else
- return -1;
-}
-
-int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- struct ioctl_evtchn_unbind unbind;
-
- unbind.port = port;
-
- return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) -{
- int fd = xce->fd;
- struct ioctl_evtchn_bind_virq bind;
- int err;
-
- bind.virq = virq;
-
- err = ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
- if (err)
- return -1;
- else
- return bind.port;
-}
-
-evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce)
-{
- int fd = xce->fd;
- evtchn_port_t port;
-
- if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 )
- return -1;
-
- return port;
-}
-
-int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- return write_exact(fd, (char *)&port, sizeof(port));
-}
-
/* Optionally flush file to disk and discard page cache */
void discard_file_cache(xc_interface *xch, int fd, int flush)
{
tools/libxc/xc_private.c +0 -0
@@ -251,46 +251,6 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
return xch->ops->u.privcmd.hypercall(xch, xch->ops_handle, hypercall); }
-xc_evtchn *xc_evtchn_open(xentoollog_logger *logger, unsigned open_flags) -{
- xc_evtchn *xce = malloc(sizeof(*xce));
- int rc;
-
- if (!xce) return NULL;
-
- xce->fd = -1;
- xce->logger = logger;
- xce->logger_tofree = NULL;
-
- if (!xce->logger) {
- xce->logger = xce->logger_tofree =
- (xentoollog_logger*)
- xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0); - if (!xce->logger) goto err;
- }
-
- rc = osdep_evtchn_open(xce);
- if ( rc < 0 ) goto err;
-
- return xce;
-
-err:
- osdep_evtchn_close(xce);
- xtl_logger_destroy(xce->logger_tofree);
- free(xce);
- return NULL;
-}
-
-int xc_evtchn_close(xc_evtchn *xce)
-{
- int rc;
-
- rc = osdep_evtchn_close(xce);
- xtl_logger_destroy(xce->logger_tofree);
- free(xce);
- return rc;
-}
-
xc_gnttab *xc_gnttab_open(xentoollog_logger *logger,
unsigned open_flags)
{
tools/libxc/xc_private.h +0 -0
@@ -123,13 +123,6 @@ struct xc_interface_core {
xc_osdep_handle ops_handle; /* opaque data for xc_osdep_ops */ };
-struct xenevtchn_handle {
- xentoollog_logger *logger, *logger_tofree;
- int fd;
-};
-int osdep_evtchn_open(xc_evtchn *xce);
-int osdep_evtchn_close(xc_evtchn *xce);
-
void xc_report_error(xc_interface *xch, int code, const char *fmt, ...) __attribute__((format(printf,3,4)));
void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
tools/libxc/xc_solaris.c +0 -0
@@ -20,7 +20,6 @@
#include "xc_private.h"
#include <xen/memory.h>
-#include <xen/sys/evtchn.h>
#include <unistd.h>
#include <fcntl.h>
#include <malloc.h>
@@ -194,102 +193,6 @@ static struct xc_osdep_ops solaris_privcmd_ops = { },
};
-int osdep_evtchn_open(xc_evtchn *xce)
-{
- int fd;
-
- if ( (fd = open("/dev/xen/evtchn", O_RDWR)) == -1 )
- {
- PERROR("Could not open event channel interface");
- return -1;
- }
-
- xce->fd = fd;
- return 0;
-}
-
-int osdep_evtchn_close(xc_evtchn *xce)
-{
- if ( xce->fd == -1 )
- return 0;
-
- return close(xce->fd);
-}
-
-int xc_evtchn_fd(xc_evtchn *xce)
-{
- return xce->fd;
-}
-
-int xc_evtchn_notify(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- struct ioctl_evtchn_notify notify;
-
- notify.port = port;
-
- return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_unbound_port(xc_evtchn *xce, int domid) -{
- int fd = xce->fd;
- struct ioctl_evtchn_bind_unbound_port bind;
-
- bind.remote_domain = domid;
-
- return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_interdomain(xc_evtchn *xce, int domid, - evtchn_port_t remote_port) -{
- int fd = xce->fd;
- struct ioctl_evtchn_bind_interdomain bind;
-
- bind.remote_domain = domid;
- bind.remote_port = remote_port;
-
- return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
-}
-
-evtchn_port_or_error_t xc_evtchn_bind_virq(xc_evtchn *xce, unsigned int virq) -{
- int fd = xce->fd;
- struct ioctl_evtchn_bind_virq bind;
-
- bind.virq = virq;
-
- return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
-}
-
-int xc_evtchn_unbind(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- struct ioctl_evtchn_unbind unbind;
-
- unbind.port = port;
-
- return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind);
-}
-
-evtchn_port_or_error_t xc_evtchn_pending(xc_evtchn *xce)
-{
- int fd = xce->fd;
- evtchn_port_t port;
-
- if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 )
- return -1;
-
- return port;
-}
-
-int xc_evtchn_unmask(xc_evtchn *xce, evtchn_port_t port)
-{
- int fd = xce->fd;
- return write_exact(fd, (char *)&port, sizeof(port));
-}
-
/* Optionally flush file to disk and discard page cache */
void discard_file_cache(xc_interface *xch, int fd, int flush)
{
tools/libxc/xc_suspend.c +0 -0
@@ -16,6 +16,8 @@
#include <unistd.h>
#include <fcntl.h>
+#include <xenevtchn.h>
+
#include "xc_private.h"
#include "xenguest.h"
@@ -124,12 +126,12 @@ static int unlock_suspend_event(xc_interface *xch, int domid, int *lockfd) return -1;
}
-int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn)
+int xc_await_suspend(xc_interface *xch, xenevtchn_handle *xce, int suspend_evtchn) {
int rc;
do {
- rc = xc_evtchn_pending(xce);
+ rc = xenevtchn_pending(xce);
if (rc < 0) {
ERROR("error polling suspend notification channel: %d", rc);
return -1;
@@ -137,7 +139,7 @@ int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn) } while (rc != suspend_evtchn);
/* harmless for one-off suspend */
- if (xc_evtchn_unmask(xce, suspend_evtchn) < 0)
+ if (xenevtchn_unmask(xce, suspend_evtchn) < 0)
ERROR("failed to unmask suspend notification channel: %d", rc);
return 0;
@@ -145,16 +147,16 @@ int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn)
/* Internal callers are allowed to call this with suspend_evtchn<0
* but *lockfd>0. */
-int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_release(xc_interface *xch, xenevtchn_handle *xce,
int domid, int suspend_evtchn, int *lockfd)
{
if (suspend_evtchn >= 0)
- xc_evtchn_unbind(xce, suspend_evtchn);
+ xenevtchn_unbind(xce, suspend_evtchn);
return unlock_suspend_event(xch, domid, lockfd);
}
-int xc_suspend_evtchn_init_sane(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_init_sane(xc_interface *xch, xenevtchn_handle *xce,
int domid, int port, int *lockfd)
{
int rc, suspend_evtchn = -1;
@@ -164,7 +166,7 @@ int xc_suspend_evtchn_init_sane(xc_interface *xch, xc_evtchn *xce, goto cleanup;
}
- suspend_evtchn = xc_evtchn_bind_interdomain(xce, domid, port);
+ suspend_evtchn = xenevtchn_bind_interdomain(xce, domid, port);
if (suspend_evtchn < 0) {
ERROR("failed to bind suspend event channel: %d", suspend_evtchn);
goto cleanup;
@@ -184,7 +186,7 @@ cleanup:
return -1;
}
-int xc_suspend_evtchn_init_exclusive(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_init_exclusive(xc_interface *xch, xenevtchn_handle *xce, int domid, int port, int *lockfd)
{
int suspend_evtchn;
tools/libxl/Makefile +0 -0
@@ -20,12 +20,13 @@ LIBUUID_LIBS += -luuid
endif
LIBXL_LIBS =
-LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS) +LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS) ifeq ($(CONFIG_REMUS_NETBUF),y)
LIBXL_LIBS += $(LIBNL3_LIBS)
endif
CFLAGS_LIBXL += $(CFLAGS_libxentoollog)
+CFLAGS_LIBXL += $(CFLAGS_libxenevtchn)
CFLAGS_LIBXL += $(CFLAGS_libxenctrl)
CFLAGS_LIBXL += $(CFLAGS_libxenguest)
CFLAGS_LIBXL += $(CFLAGS_libxenstore)
@@ -155,7 +156,7 @@ $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
$(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs it.
SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o
-$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
+$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn)
PKG_CONFIG = xenlight.pc xlutil.pc
tools/libxl/libxl.c +0 -0
@@ -186,7 +186,7 @@ int libxl_ctx_free(libxl_ctx *ctx)
if (ctx->xch) xc_interface_close(ctx->xch); libxl_version_info_dispose(&ctx->version_info); if (ctx->xsh) xs_daemon_close(ctx->xsh); - if (ctx->xce) xc_evtchn_close(ctx->xce); + if (ctx->xce) xenevtchn_close(ctx->xce);
libxl__poller_put(ctx, ctx->poller_app); ctx->poller_app = NULL;
tools/libxl/libxl_dom_suspend.c +0 -0
@@ -109,9 +109,9 @@ static void domain_suspend_callback_common(libxl__egc *egc,
if ((hvm_s_state == 0) && (dss->guest_evtchn.port >= 0)) { LOG(DEBUG, "issuing %s suspend request via event channel", dss->hvm ? "PVHVM" : "PV");
- ret = xc_evtchn_notify(CTX->xce, dss->guest_evtchn.port); + ret = xenevtchn_notify(CTX->xce, dss->guest_evtchn.port); if (ret < 0) {
- LOG(ERROR, "xc_evtchn_notify failed ret=%d", ret); + LOG(ERROR, "xenevtchn_notify failed ret=%d", ret); rc = ERROR_FAIL;
goto err;
}
tools/libxl/libxl_event.c +0 -0
@@ -739,7 +739,7 @@ static void evtchn_fd_callback(libxl__egc *egc, libxl__ev_fd *ev,
/* OK, that's that workaround done. We can actually check for
* work for us to do: */
- port = xc_evtchn_pending(CTX->xce);
+ port = xenevtchn_pending(CTX->xce);
if (port < 0) {
if (errno == EAGAIN)
break;
@@ -765,20 +765,20 @@ static void evtchn_fd_callback(libxl__egc *egc, libxl__ev_fd *ev, }
int libxl__ctx_evtchn_init(libxl__gc *gc) {
- xc_evtchn *xce;
+ xenevtchn_handle *xce;
int rc, fd;
if (CTX->xce)
return 0;
- xce = xc_evtchn_open(CTX->lg, 0);
+ xce = xenevtchn_open(CTX->lg, 0);
if (!xce) {
LOGE(ERROR,"cannot open libxc evtchn handle");
rc = ERROR_FAIL;
goto out;
}
- fd = xc_evtchn_fd(xce);
+ fd = xenevtchn_fd(xce);
assert(fd >= 0);
rc = libxl_fd_set_nonblock(CTX, fd, 1);
@@ -788,7 +788,7 @@ int libxl__ctx_evtchn_init(libxl__gc *gc) {
return 0;
out:
- xc_evtchn_close(xce);
+ xenevtchn_close(xce);
return rc;
}
@@ -810,14 +810,14 @@ int libxl__ev_evtchn_wait(libxl__gc *gc, libxl__ev_evtchn *evev)
if (!libxl__ev_fd_isregistered(&CTX->evtchn_efd)) {
rc = libxl__ev_fd_register(gc, &CTX->evtchn_efd, evtchn_fd_callback, - xc_evtchn_fd(CTX->xce), POLLIN);
+ xenevtchn_fd(CTX->xce), POLLIN);
if (rc) goto out;
}
if (evev->waiting)
return 0;
- r = xc_evtchn_unmask(CTX->xce, evev->port);
+ r = xenevtchn_unmask(CTX->xce, evev->port);
if (r) {
LOGE(ERROR,"cannot unmask event channel %d",evev->port);
rc = ERROR_FAIL;
tools/libxl/libxl_internal.h +0 -0
@@ -48,6 +48,7 @@
#include <sys/file.h>
#include <sys/ioctl.h>
+#include <xenevtchn.h>
#include <xenstore.h>
#include <xenctrl.h>
#include <xenguest.h>
@@ -448,7 +449,7 @@ struct libxl__ctx {
uint32_t watch_counter; /* helps disambiguate slot reuse */
libxl__ev_fd watch_efd;
- xc_evtchn *xce; /* waiting must be done only with libxl__ev_evtchn* */
+ xenevtchn_handle *xce; /* waiting must be done only with libxl__ev_evtchn* */ LIBXL_LIST_HEAD(, libxl__ev_evtchn) evtchns_waiting;
libxl__ev_fd evtchn_efd;
@@ -925,7 +926,7 @@ static inline int libxl__ev_xswatch_isregistered(const libxl__ev_xswatch *xw)
* When the event is signaled then the callback will be made, once.
* Then you must call libxl__ev_evtchn_wait again, if desired.
*
- * You must NOT call xc_evtchn_unmask. wait will do that for you.
+ * You must NOT call xenevtchn_unmask. wait will do that for you.
*
* Calling libxl__ev_evtchn_cancel will arrange for libxl to disregard
* future occurrences of event. Both libxl__ev_evtchn_wait and
tools/misc/Makefile +0 -0
@@ -4,6 +4,7 @@ include $(XEN_ROOT)/tools/Rules.mk
CFLAGS += -Werror
# Include configure output (config.h)
CFLAGS += -include $(XEN_ROOT)/tools/config.h
+CFLAGS += $(CFLAGS_libxenevtchn)
CFLAGS += $(CFLAGS_libxenctrl)
CFLAGS += $(CFLAGS_xeninclude)
CFLAGS += $(CFLAGS_libxenstore)
@@ -88,18 +89,18 @@ xenlockprof: xenlockprof.o
# xen-hptool incorrectly uses libxc internals xen-hptool.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc xen-hptool: xen-hptool.o - $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) # xen-mfndump incorrectly uses libxc internals xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc xen-mfndump: xen-mfndump.o - $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS) xenwatchdogd: xenwatchdogd.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) xen-lowmemd: xen-lowmemd.o - $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) gtraceview: gtraceview.o $(CC) $(LDFLAGS) -o $@ $< $(CURSES_LIBS) $(TINFO_LIBS) $(APPEND_LDFLAGS)
tools/misc/xen-hptool.c +1 -0
@@ -1,3 +1,4 @@ +#include <xenevtchn.h>
#include <xenctrl.h>
#include <xc_private.h>
#include <xc_core.h>
@@ -98,7 +99,7 @@ static int hp_mem_query_func(int argc, char *argv[]) return ret;
}
-static int suspend_guest(xc_interface *xch, xc_evtchn *xce, int domid, +static int suspend_guest(xc_interface *xch, xenevtchn_handle *xce, int domid, int *evtchn, int *lockfd)
{
int port, rc, suspend_evtchn = -1;
@@ -123,7 +124,7 @@ static int suspend_guest(xc_interface *xch, xc_evtchn *xce, int domid, }
*evtchn = suspend_evtchn;
- rc = xc_evtchn_notify(xce, suspend_evtchn);
+ rc = xenevtchn_notify(xce, suspend_evtchn);
if (rc < 0)
{
fprintf(stderr, "Failed to notify suspend channel: errno %d\n", rc); @@ -198,8 +199,8 @@ static int hp_mem_offline_func(int argc, char *argv[]) else if (status & PG_OFFLINE_OWNED)
{
int result, suspend_evtchn = -1, suspend_lockfd = -1; - xc_evtchn *xce;
- xce = xc_evtchn_open(NULL, 0);
+ xenevtchn_handle *xce;
+ xce = xenevtchn_open(NULL, 0);
if (xce == NULL)
{
@@ -214,7 +215,7 @@ static int hp_mem_offline_func(int argc, char *argv[]) {
fprintf(stderr, "Failed to suspend guest %d for"
" mfn %lx\n", domid, mfn);
- xc_evtchn_close(xce);
+ xenevtchn_close(xce);
return -1;
}
@@ -238,7 +239,7 @@ static int hp_mem_offline_func(int argc, char *argv[]) xc_domain_resume(xch, domid, 1); xc_suspend_evtchn_release(xch, xce, domid, suspend_evtchn, &suspend_lockfd); - xc_evtchn_close(xce);
+ xenevtchn_close(xce);
}
break;
}
tools/misc/xen-lowmemd.c +0 -0
@@ -4,22 +4,23 @@
*/
#include <stdio.h>
+#include <xenevtchn.h>
#include <xenctrl.h>
#include <xenstore.h>
#include <stdlib.h>
#include <string.h>
static evtchn_port_t virq_port = -1;
-static xc_evtchn *xce_handle = NULL;
+static xenevtchn_handle *xce_handle = NULL;
static xc_interface *xch = NULL;
static struct xs_handle *xs_handle = NULL;
void cleanup(void)
{
if (virq_port > -1)
- xc_evtchn_unbind(xce_handle, virq_port);
+ xenevtchn_unbind(xce_handle, virq_port);
if (xce_handle)
- xc_evtchn_close(xce_handle);
+ xenevtchn_close(xce_handle);
if (xch)
xc_interface_close(xch);
if (xs_handle)
@@ -94,7 +95,7 @@ int main(int argc, char *argv[]) return 1;
}
- xce_handle = xc_evtchn_open(NULL, 0);
+ xce_handle = xenevtchn_open(NULL, 0);
if (xce_handle == NULL)
{
perror("Failed to open evtchn device");
@@ -108,7 +109,7 @@ int main(int argc, char *argv[]) return 3;
}
- if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_ENOMEM)) == -1)
+ if ((rc = xenevtchn_bind_virq(xce_handle, VIRQ_ENOMEM)) == -1)
{
perror("Failed to bind to domain exception virq port"); return 4;
@@ -120,7 +121,7 @@ int main(int argc, char *argv[])
{
evtchn_port_t port;
- if ((port = xc_evtchn_pending(xce_handle)) == -1) + if ((port = xenevtchn_pending(xce_handle)) == -1) {
perror("Failed to listen for pending event channel"); return 5;
@@ -134,7 +135,7 @@ int main(int argc, char *argv[]) return 6;
}
- if (xc_evtchn_unmask(xce_handle, port) == -1) + if (xenevtchn_unmask(xce_handle, port) == -1) {
perror("Failed to unmask port");
return 7;
tools/ocaml/libs/eventchn/Makefile +0 -0
@@ -2,13 +2,13 @@ TOPLEVEL=$(CURDIR)/../..
XEN_ROOT=$(TOPLEVEL)/../..
include $(TOPLEVEL)/common.make
-CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude) +CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_xeninclude)
OBJS = xeneventchn
INTF = $(foreach obj, $(OBJS),$(obj).cmi) LIBS = xeneventchn.cma xeneventchn.cmxa
-LIBS_xeneventchn = $(LDLIBS_libxenctrl) +LIBS_xeneventchn = $(LDLIBS_libxenevtchn)
all: $(INTF) $(LIBS) $(PROGRAMS)
tools/ocaml/libs/eventchn/xeneventchn_stubs.c +0 -0
@@ -24,7 +24,7 @@
#include <xen/sysctl.h>
#include <xen/xen.h>
#include <xen/sys/evtchn.h>
-#include <xenctrl.h>
+#include <xenevtchn.h>
#define CAML_NAME_SPACE
#include <caml/mlvalues.h>
@@ -34,14 +34,14 @@
#include <caml/callback.h>
#include <caml/fail.h>
-#define _H(__h) ((xc_evtchn *)(__h))
+#define _H(__h) ((xenevtchn_handle *)(__h))
CAMLprim value stub_eventchn_init(void)
{
CAMLparam0();
CAMLlocal1(result);
- xc_evtchn *xce = xc_evtchn_open(NULL, XC_OPENFLAG_NON_REENTRANT);
+ xenevtchn_handle *xce = xenevtchn_open(NULL, 0);
if (xce == NULL)
caml_failwith("open failed");
@@ -55,7 +55,7 @@ CAMLprim value stub_eventchn_fd(value xce) CAMLlocal1(result);
int fd;
- fd = xc_evtchn_fd(_H(xce));
+ fd = xenevtchn_fd(_H(xce));
if (fd == -1)
caml_failwith("evtchn fd failed");
@@ -69,7 +69,7 @@ CAMLprim value stub_eventchn_notify(value xce, value port) CAMLparam2(xce, port);
int rc;
- rc = xc_evtchn_notify(_H(xce), Int_val(port));
+ rc = xenevtchn_notify(_H(xce), Int_val(port));
if (rc == -1)
caml_failwith("evtchn notify failed");
@@ -83,7 +83,7 @@ CAMLprim value stub_eventchn_bind_interdomain(value xce, value domid, CAMLlocal1(port);
evtchn_port_or_error_t rc;
- rc = xc_evtchn_bind_interdomain(_H(xce), Int_val(domid), Int_val(remote_port));
+ rc = xenevtchn_bind_interdomain(_H(xce), Int_val(domid), Int_val(remote_port));
if (rc == -1)
caml_failwith("evtchn bind_interdomain failed");
port = Val_int(rc);
@@ -97,7 +97,7 @@ CAMLprim value stub_eventchn_bind_dom_exc_virq(value xce) CAMLlocal1(port);
evtchn_port_or_error_t rc;
- rc = xc_evtchn_bind_virq(_H(xce), VIRQ_DOM_EXC);
+ rc = xenevtchn_bind_virq(_H(xce), VIRQ_DOM_EXC);
if (rc == -1)
caml_failwith("evtchn bind_dom_exc_virq failed");
port = Val_int(rc);
@@ -110,7 +110,7 @@ CAMLprim value stub_eventchn_unbind(value xce, value port) CAMLparam2(xce, port);
int rc;
- rc = xc_evtchn_unbind(_H(xce), Int_val(port));
+ rc = xenevtchn_unbind(_H(xce), Int_val(port));
if (rc == -1)
caml_failwith("evtchn unbind failed");
@@ -123,7 +123,7 @@ CAMLprim value stub_eventchn_pending(value xce) CAMLlocal1(result);
evtchn_port_or_error_t port;
- port = xc_evtchn_pending(_H(xce));
+ port = xenevtchn_pending(_H(xce));
if (port == -1)
caml_failwith("evtchn pending failed");
result = Val_int(port);
@@ -137,7 +137,7 @@ CAMLprim value stub_eventchn_unmask(value xce, value _port) evtchn_port_t port;
port = Int_val(_port);
- if (xc_evtchn_unmask(_H(xce), port))
+ if (xenevtchn_unmask(_H(xce), port))
caml_failwith("evtchn unmask failed"); CAMLreturn(Val_unit);
}
tools/python/setup.py +0 -0
@@ -8,13 +8,18 @@ extra_compile_args = [ "-fno-strict-aliasing", "-Werror" ]
PATH_XEN = XEN_ROOT + "/tools/include"
PATH_LIBXENTOOLLOG = XEN_ROOT + "/tools/libs/toollog"
+PATH_LIBXENEVTCHN = XEN_ROOT + "/tools/libs/evtchn"
PATH_LIBXC = XEN_ROOT + "/tools/libxc"
PATH_LIBXL = XEN_ROOT + "/tools/libxl"
PATH_XENSTORE = XEN_ROOT + "/tools/xenstore"
xc = Extension("xc",
extra_compile_args = extra_compile_args,
- include_dirs = [ PATH_XEN, PATH_LIBXENTOOLLOG + "/include", PATH_LIBXC + "/include", "xen/lowlevel/xc" ], + include_dirs = [ PATH_XEN,
+ PATH_LIBXENTOOLLOG + "/include",
+ PATH_LIBXENEVTCHN + "/include",
+ PATH_LIBXC + "/include",
+ "xen/lowlevel/xc" ],
library_dirs = [ PATH_LIBXC ],
libraries = [ "xenctrl", "xenguest" ],
depends = [ PATH_LIBXC + "/libxenctrl.so", PATH_LIBXC + "/libxenguest.so" ],
tools/tests/xen-access/Makefile +0 -0
@@ -5,6 +5,7 @@ CFLAGS += -Werror
CFLAGS += $(CFLAGS_libxenctrl)
CFLAGS += $(CFLAGS_libxenguest)
+CFLAGS += $(CFLAGS_libxenevtchn)
CFLAGS += $(CFLAGS_xeninclude)
TARGETS-y := xen-access
@@ -24,6 +25,6 @@ clean:
distclean: clean
xen-access: xen-access.o Makefile
- $(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest)
+ $(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenevtchn)
-include $(DEPS)
tools/tests/xen-access/xen-access.c +0 -0
@@ -39,6 +39,7 @@
#include <sys/poll.h>
#include <xenctrl.h>
+#include <xenevtchn.h>
#include <xen/vm_event.h>
#if defined(__arm__) || defined(__aarch64__)
@@ -54,7 +55,7 @@
typedef struct vm_event {
domid_t domain_id;
- xc_evtchn *xce_handle;
+ xenevtchn_handle *xce_handle;
int port;
vm_event_back_ring_t back_ring;
uint32_t evtchn_port;
@@ -77,9 +78,9 @@ static void close_handler(int sig)
interrupted = sig;
}
-int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned long ms) +int xc_wait_for_event_or_timeout(xc_interface *xch, xenevtchn_handle *xce, unsigned long ms) {
- struct pollfd fd = { .fd = xc_evtchn_fd(xce), .events = POLLIN | POLLERR };
+ struct pollfd fd = { .fd = xenevtchn_fd(xce), .events = POLLIN | POLLERR };
int port;
int rc;
@@ -95,14 +96,14 @@ int xc_wait_for_event_or_timeout(xc_interface *xch, xc_evtchn *xce, unsigned lon
if ( rc == 1 )
{
- port = xc_evtchn_pending(xce);
+ port = xenevtchn_pending(xce);
if ( port == -1 )
{
ERROR("Failed to read port from event channel");
goto err;
}
- rc = xc_evtchn_unmask(xce, port);
+ rc = xenevtchn_unmask(xce, port);
if ( rc != 0 )
{
ERROR("Failed to unmask event channel port");
@@ -143,7 +144,7 @@ int xenaccess_teardown(xc_interface *xch, xenaccess_t *xenaccess) /* Unbind VIRQ */
if ( evtchn_bind )
{
- rc = xc_evtchn_unbind(xenaccess->vm_event.xce_handle,
+ rc = xenevtchn_unbind(xenaccess->vm_event.xce_handle, xenaccess->vm_event.port);
if ( rc != 0 )
{
@@ -155,7 +156,7 @@ int xenaccess_teardown(xc_interface *xch, xenaccess_t *xenaccess) /* Close event channel */
if ( evtchn_open )
{
- rc = xc_evtchn_close(xenaccess->vm_event.xce_handle);
+ rc = xenevtchn_close(xenaccess->vm_event.xce_handle);
if ( rc != 0 )
{
ERROR("Error closing event channel");
@@ -223,7 +224,7 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t domain_id) mem_access_enable = 1;
/* Open event channel */
- xenaccess->vm_event.xce_handle = xc_evtchn_open(NULL, 0);
+ xenaccess->vm_event.xce_handle = xenevtchn_open(NULL, 0);
if ( xenaccess->vm_event.xce_handle == NULL )
{
ERROR("Failed to open event channel");
@@ -232,7 +233,7 @@ xenaccess_t *xenaccess_init(xc_interface **xch_r, domid_t domain_id) evtchn_open = 1;
/* Bind event notification */
- rc = xc_evtchn_bind_interdomain(xenaccess->vm_event.xce_handle,
+ rc = xenevtchn_bind_interdomain(xenaccess->vm_event.xce_handle, xenaccess->vm_event.domain_id, xenaccess->vm_event.evtchn_port);
if ( rc < 0 )
@@ -678,7 +679,7 @@ int main(int argc, char *argv[])
}
/* Tell Xen page is ready */
- rc = xc_evtchn_notify(xenaccess->vm_event.xce_handle,
+ rc = xenevtchn_notify(xenaccess->vm_event.xce_handle, xenaccess->vm_event.port);
if ( rc != 0 )
tools/xcutils/Makefile +0 -0
@@ -16,8 +16,8 @@ PROGRAMS = readnotes lsevtchn
CFLAGS += -Werror
# incorrectly uses libxc internals -CFLAGS_readnotes.o := $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) -I$(XEN_ROOT)/tools/libxc -CFLAGS_lsevtchn.o := $(CFLAGS_libxenctrl) +CFLAGS_readnotes.o := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) -I$(XEN_ROOT)/tools/libxc +CFLAGS_lsevtchn.o := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) .PHONY: all all: build
tools/xenmon/Makefile +0 -0
@@ -14,8 +14,10 @@ XEN_ROOT=$(CURDIR)/../..
include $(XEN_ROOT)/tools/Rules.mk
CFLAGS += -Werror
+CFLAGS += $(CFLAGS_libxenevtchn)
CFLAGS += $(CFLAGS_libxenctrl)
LDLIBS += $(LDLIBS_libxenctrl)
+LDLIBS += $(LDLIBS_libxenevtchn)
SCRIPTS = xenmon.py
tools/xenmon/xenbaked.c +0 -0
@@ -37,6 +37,7 @@
#include <unistd.h>
#include <errno.h>
#include <signal.h>
+#include <xenevtchn.h>
#include <xenctrl.h>
#include <xen/xen.h>
#include <string.h>
@@ -267,7 +268,7 @@ static void log_event(int event_id) }
int virq_port;
-xc_evtchn *xce_handle = NULL;
+xenevtchn_handle *xce_handle = NULL;
/* Returns the event channel handle. */
/* Stolen from xenstore code */
@@ -279,12 +280,12 @@ static int eventchn_init(void)
if (0)
return -1;
- xce_handle = xc_evtchn_open(NULL, 0);
+ xce_handle = xenevtchn_open(NULL, 0);
if (xce_handle == NULL)
perror("Failed to open evtchn device");
- if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF)) == -1) + if ((rc = xenevtchn_bind_virq(xce_handle, VIRQ_TBUF)) == -1) perror("Failed to bind to domain exception virq port"); virq_port = rc;
@@ -304,7 +305,7 @@ static void wait_for_event(void) return;
}
- evtchn_fd = xc_evtchn_fd(xce_handle);
+ evtchn_fd = xenevtchn_fd(xce_handle);
FD_ZERO(&inset);
FD_SET(evtchn_fd, &inset);
@@ -314,13 +315,13 @@ static void wait_for_event(void) ret = select(evtchn_fd+1, &inset, NULL, NULL, &tv);
if ( (ret == 1) && FD_ISSET(evtchn_fd, &inset)) { - if ((port = xc_evtchn_pending(xce_handle)) == -1) + if ((port = xenevtchn_pending(xce_handle)) == -1) perror("Failed to read from event fd");
// if (port == virq_port)
// printf("got the event I was looking for\r\n");
- if (xc_evtchn_unmask(xce_handle, port) == -1) + if (xenevtchn_unmask(xce_handle, port) == -1) perror("Failed to write to event fd");
}
}
tools/xenpaging/Makefile +0 -0
@@ -2,8 +2,8 @@ XEN_ROOT=$(CURDIR)/../..
include $(XEN_ROOT)/tools/Rules.mk
# xenpaging.c and file_ops.c incorrectly use libxc internals -CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(PTHREAD_CFLAGS) -I$(XEN_ROOT)/tools/libxc -LDLIBS += $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(PTHREAD_LIBS) +CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(PTHREAD_CFLAGS) -I$(XEN_ROOT)/tools/libxc +LDLIBS += $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(PTHREAD_LIBS) LDFLAGS += $(PTHREAD_LDFLAGS) POLICY = default
tools/xenpaging/xenpaging.c +0 -0
@@ -73,7 +73,7 @@ static void xenpaging_mem_paging_flush_ioemu_cache(struct xenpaging *paging)
static int xenpaging_wait_for_event_or_timeout(struct xenpaging *paging)
{
xc_interface *xch = paging->xc_handle;
- xc_evtchn *xce = paging->vm_event.xce_handle;
+ xenevtchn_handle *xce = paging->vm_event.xce_handle;
char **vec, *val;
unsigned int num;
struct pollfd fd[2];
@@ -82,7 +82,7 @@ static int xenpaging_wait_for_event_or_timeout(struct xenpaging *paging) int timeout;
/* Wait for event channel and xenstore */
- fd[0].fd = xc_evtchn_fd(xce);
+ fd[0].fd = xenevtchn_fd(xce);
fd[0].events = POLLIN | POLLERR;
fd[1].fd = xs_fileno(paging->xs_handle);
fd[1].events = POLLIN | POLLERR;
@@ -146,7 +146,7 @@ static int xenpaging_wait_for_event_or_timeout(struct xenpaging *paging) if ( rc && fd[0].revents & POLLIN )
{
DPRINTF("Got event from evtchn\n");
- port = xc_evtchn_pending(xce);
+ port = xenevtchn_pending(xce);
if ( port == -1 )
{
PERROR("Failed to read port from event channel");
@@ -154,7 +154,7 @@ static int xenpaging_wait_for_event_or_timeout(struct xenpaging *paging) goto err;
}
- rc = xc_evtchn_unmask(xce, port);
+ rc = xenevtchn_unmask(xce, port);
if ( rc < 0 )
{
PERROR("Failed to unmask event channel port");
@@ -393,7 +393,7 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[]) }
/* Open event channel */
- paging->vm_event.xce_handle = xc_evtchn_open(NULL, 0);
+ paging->vm_event.xce_handle = xenevtchn_open(NULL, 0);
if ( paging->vm_event.xce_handle == NULL )
{
PERROR("Failed to open event channel");
@@ -401,7 +401,7 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[]) }
/* Bind event notification */
- rc = xc_evtchn_bind_interdomain(paging->vm_event.xce_handle,
+ rc = xenevtchn_bind_interdomain(paging->vm_event.xce_handle, paging->vm_event.domain_id, paging->vm_event.evtchn_port);
if ( rc < 0 )
@@ -531,7 +531,7 @@ static void xenpaging_teardown(struct xenpaging *paging)
}
/* Unbind VIRQ */
- rc = xc_evtchn_unbind(paging->vm_event.xce_handle, paging->vm_event.port);
+ rc = xenevtchn_unbind(paging->vm_event.xce_handle, paging->vm_event.port);
if ( rc != 0 )
{
PERROR("Error unbinding event port");
@@ -539,7 +539,7 @@ static void xenpaging_teardown(struct xenpaging *paging) paging->vm_event.port = -1;
/* Close event channel */
- rc = xc_evtchn_close(paging->vm_event.xce_handle);
+ rc = xenevtchn_close(paging->vm_event.xce_handle);
if ( rc != 0 )
{
PERROR("Error closing event channel");
@@ -692,7 +692,7 @@ static int xenpaging_resume_page(struct xenpaging *paging, vm_event_response_t * }
/* Tell Xen page is ready */
- return xc_evtchn_notify(paging->vm_event.xce_handle, paging->vm_event.port);
+ return xenevtchn_notify(paging->vm_event.xce_handle, paging->vm_event.port);
}
static int xenpaging_populate_page(struct xenpaging *paging, unsigned long gfn, int i)
tools/xenpaging/xenpaging.h +0 -0
@@ -24,6 +24,7 @@
#define __XEN_PAGING2_H__
+#include <xenevtchn.h>
#include <xc_private.h>
#include <xen/event_channel.h>
#include <xen/vm_event.h>
@@ -32,7 +33,7 @@
struct vm_event {
domid_t domain_id;
- xc_evtchn *xce_handle;
+ xenevtchn_handle *xce_handle;
int port;
vm_event_back_ring_t back_ring;
uint32_t evtchn_port;
tools/xenstore/Makefile +0 -0
@@ -9,6 +9,7 @@ CFLAGS += -I.
# Include configure output (config.h) CFLAGS += -include $(XEN_ROOT)/tools/config.h CFLAGS += -I./include
+CFLAGS += $(CFLAGS_libxenevtchn)
CFLAGS += $(CFLAGS_libxenctrl)
CFLAGS += -DXEN_LIB_STORED="\"$(XEN_LIB_STORED)\""
@@ -69,7 +70,7 @@ CFLAGS += -DHAVE_DTRACE=1 endif
xenstored: $(XENSTORED_OBJS)
- $(CC) $^ $(LDFLAGS) $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
+ $(CC) $^ $(LDFLAGS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
xenstored.a: $(XENSTORED_OBJS)
$(AR) cr $@ $^
tools/xenstore/xenstored_core.c +0 -0
@@ -40,6 +40,8 @@
#include <assert.h>
#include <setjmp.h>
+#include <xenevtchn.h>
+
#include "utils.h"
#include "list.h"
#include "talloc.h"
@@ -63,7 +65,7 @@
#include <systemd/sd-daemon.h>
#endif
-extern xc_evtchn *xce_handle; /* in xenstored_domain.c */
+extern xenevtchn_handle *xce_handle; /* in xenstored_domain.c */ static int xce_pollfd_idx = -1;
static struct pollfd *fds;
static unsigned int current_array_size;
@@ -372,7 +374,7 @@ static void initialize_fds(int sock, int *p_sock_pollfd_idx, set_fd(reopen_log_pipe[0], POLLIN|POLLPRI);
if (xce_handle != NULL)
- xce_pollfd_idx = set_fd(xc_evtchn_fd(xce_handle),
+ xce_pollfd_idx = set_fd(xenevtchn_fd(xce_handle),
POLLIN|POLLPRI);
list_for_each_entry(conn, &connections, list) {
tools/xenstore/xenstored_domain.c +0 -0
@@ -29,6 +29,7 @@
#include "xenstored_transaction.h"
#include "xenstored_watch.h"
+#include <xenevtchn.h>
#include <xenctrl.h>
#include <xen/grant_table.h>
@@ -36,7 +37,7 @@ static xc_interface **xc_handle;
xc_gnttab **xcg_handle;
static evtchn_port_t virq_port;
-xc_evtchn *xce_handle = NULL;
+xenevtchn_handle *xce_handle = NULL;
struct domain
{
@@ -128,7 +129,7 @@ static int writechn(struct connection *conn,
xen_mb();
intf->rsp_prod += len;
- xc_evtchn_notify(xce_handle, conn->domain->port);
+ xenevtchn_notify(xce_handle, conn->domain->port);
return len;
}
@@ -158,7 +159,7 @@ static int readchn(struct connection *conn, void *data, unsigned int len) xen_mb();
intf->req_cons += len;
- xc_evtchn_notify(xce_handle, conn->domain->port);
+ xenevtchn_notify(xce_handle, conn->domain->port);
return len;
}
@@ -190,7 +191,7 @@ static int destroy_domain(void *_domain) list_del(&domain->list);
if (domain->port) {
- if (xc_evtchn_unbind(xce_handle, domain->port) == -1)
+ if (xenevtchn_unbind(xce_handle, domain->port) == -1)
eprintf("> Unbinding port %i failed!\n", domain->port); }
@@ -239,13 +240,13 @@ void handle_event(void)
{
evtchn_port_t port;
- if ((port = xc_evtchn_pending(xce_handle)) == -1)
+ if ((port = xenevtchn_pending(xce_handle)) == -1)
barf_perror("Failed to read from event fd");
if (port == virq_port)
domain_cleanup();
- if (xc_evtchn_unmask(xce_handle, port) == -1)
+ if (xenevtchn_unmask(xce_handle, port) == -1)
barf_perror("Failed to write to event fd");
}
@@ -287,7 +288,7 @@ static struct domain *new_domain(void *context, unsigned int domid, talloc_set_destructor(domain, destroy_domain);
/* Tell kernel we're interested in this event. */
- rc = xc_evtchn_bind_interdomain(xce_handle, domid, port);
+ rc = xenevtchn_bind_interdomain(xce_handle, domid, port);
if (rc == -1)
return NULL;
domain->port = rc;
@@ -392,8 +393,8 @@ void do_introduce(struct connection *conn, struct buffered_data *in) } else if ((domain->mfn == mfn) && (domain->conn != conn)) {
/* Use XS_INTRODUCE for recreating the xenbus event-channel. */ if (domain->port)
- xc_evtchn_unbind(xce_handle, domain->port);
- rc = xc_evtchn_bind_interdomain(xce_handle, domid, port);
+ xenevtchn_unbind(xce_handle, domain->port);
+ rc = xenevtchn_bind_interdomain(xce_handle, domid, port);
domain->port = (rc == -1) ? 0 : rc;
domain->remote_port = port;
} else {
@@ -614,7 +615,7 @@ static int dom0_init(void)
talloc_steal(dom0->conn, dom0);
- xc_evtchn_notify(xce_handle, dom0->port);
+ xenevtchn_notify(xce_handle, dom0->port);
return 0;
}
@@ -643,7 +644,7 @@ void domain_init(void)
else
talloc_set_destructor(xcg_handle, close_xcg_handle);
- xce_handle = xc_evtchn_open(NULL, 0);
+ xce_handle = xenevtchn_open(NULL, 0);
if (xce_handle == NULL)
barf_perror("Failed to open evtchn device");
@@ -651,7 +652,7 @@ void domain_init(void)
if (dom0_init() != 0)
barf_perror("Failed to initialize dom0 state");
- if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_DOM_EXC)) == -1)
+ if ((rc = xenevtchn_bind_virq(xce_handle, VIRQ_DOM_EXC)) == -1)
barf_perror("Failed to bind to domain exception virq port"); virq_port = rc;
}
tools/xentrace/Makefile +0 -0
@@ -3,8 +3,11 @@ include $(XEN_ROOT)/tools/Rules.mk
CFLAGS += -Werror
+CFLAGS += $(CFLAGS_libxenevtchn)
CFLAGS += $(CFLAGS_libxenctrl)
-LDLIBS += $(LDLIBS_libxenctrl) $(ARGP_LDFLAGS)
+LDLIBS += $(LDLIBS_libxenevtchn)
+LDLIBS += $(LDLIBS_libxenctrl)
+LDLIBS += $(ARGP_LDFLAGS)
BIN-$(CONFIG_X86) = xenalyze
BIN = $(BIN-y)
tools/xentrace/xentrace.c +0 -0
@@ -30,6 +30,7 @@
#include <xen/xen.h>
#include <xen/trace.h>
+#include <xenevtchn.h>
#include <xenctrl.h>
#define PERROR(_m, _a...) \
@@ -74,7 +75,7 @@ settings_t opts;
int interrupted = 0; /* gets set if we get a SIGHUP */
static xc_interface *xc_handle;
-static xc_evtchn *xce_handle = NULL;
+static xenevtchn_handle *xce_handle = NULL;
static int virq_port = -1;
static int outfd = 1;
@@ -602,13 +603,13 @@ static void event_init(void)
{
int rc;
- xce_handle = xc_evtchn_open(NULL, 0);
+ xce_handle = xenevtchn_open(NULL, 0);
if (xce_handle == NULL) {
perror("event channel open");
exit(EXIT_FAILURE);
}
- rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF);
+ rc = xenevtchn_bind_virq(xce_handle, VIRQ_TBUF);
if (rc == -1) {
PERROR("failed to bind to VIRQ port");
exit(EXIT_FAILURE);
@@ -623,7 +624,7 @@ static void event_init(void)
static void wait_for_event_or_timeout(unsigned long milliseconds)
{
int rc;
- struct pollfd fd = { .fd = xc_evtchn_fd(xce_handle),
+ struct pollfd fd = { .fd = xenevtchn_fd(xce_handle),
.events = POLLIN | POLLERR };
int port;
@@ -636,7 +637,7 @@ static void wait_for_event_or_timeout(unsigned long milliseconds) }
if (rc == 1) {
- port = xc_evtchn_pending(xce_handle);
+ port = xenevtchn_pending(xce_handle);
if (port == -1) {
PERROR("failed to read port from evtchn"); exit(EXIT_FAILURE);
@@ -647,7 +648,7 @@ static void wait_for_event_or_timeout(unsigned long milliseconds) port, virq_port);
exit(EXIT_FAILURE);
}
- rc = xc_evtchn_unmask(xce_handle, port);
+ rc = xenevtchn_unmask(xce_handle, port);
if (rc == -1) {
PERROR("failed to write port to evtchn"); exit(EXIT_FAILURE);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH XEN v8 02/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
In reply to Ian CampbellQuoted 2 lines · Ian Campbell
libxenevtchn will provide a stable API and ABI for accessing the evtchn device.
I think this patch breaks the build:
root@ovs101> gcc -O1 -fno-omit-frame-pointer -m64 -g -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -O0 -g3 -D__XEN_TOOLS__ -MMD -MF .core.o.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -fno-optimize-sibling-calls -Werror -Wmissing-prototypes -I./include -I/root/xen/tools/libs/evtchn/../../../tools/include -I/root/xen/tools/libs/evtchn/../../../tools/libs/toollog/include -I/root/xen/tools/libs/evtchn/../../../tools/include -c -o core.o core.c
In file included from private.h:5,
from core.c:19:
./include/xenevtchn.h:36: error: redefinition of typedef ‘xentoollog_logger’ /root/xen/tools/libs/evtchn/../../../tools/libs/toollog/include/xentoollog.h:44: note: previous declaration of ‘xentoollog_logger’ was here
-boris
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH XEN v8 02/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
Quoted 15 lines · Boris Ostrovsky
Quoted 2 lines · Ian Campbell
libxenevtchn will provide a stable API and ABI for accessing the evtchn device.
I think this patch breaks the build:
root@ovs101> gcc -O1 -fno-omit-frame-pointer -m64 -g
(quoted diff) +0
-8-fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wdeclaration-after-statement -Wno-unused-but-set-variable -O0 -g3 -D__XEN_TOOLS__ -MMD -MF .core.o.d -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -fno-optimize-sibling-calls -Werror -Wmissing-prototypes -I./include -I/root/xen/tools/libs/evtchn/../../../tools/include -I/root/xen/tools/libs/evtchn/../../../tools/libs/toollog/include -I/root/xen/tools/libs/evtchn/../../../tools/include -c -o core.o core.c
Quoted 5 lines
In file included from private.h:5,
from core.c:19:./include/xenevtchn.h:36: error: redefinition of typedef ‘xentoollog_logger’/root/xen/tools/libs/evtchn/../../../tools/libs/toollog/include/xentoollog.h:44:
note: previous declaration of ‘xentoollog_logger’ was here
Hrm, it seems to be OK by the end of the series, in that it built for me before push and has passed smoke-test. So I may have introduced a bisection hazard (sorry) but it's too late to fix that unfortunately.
Various of the tools/libs/*/include/*.h have a
/* Callers who don't care don't need to #include <xentoollog.h> */
typedef struct xentoollog_logger xentoollog_logger;but since that typedef matches in all cases I think it is allowed to be repeated like this, isn't it?
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH XEN v8 02/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
Ian Campbell writes ("Re: [Xen-devel] [PATCH XEN v8 02/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn."):
Quoted 7 lines
Various of the
tools/libs/*/include/*.hhave a/* Callers who don't care don't need to #include <xentoollog.h> */ typedef struct xentoollog_logger xentoollog_logger;but since that typedef matches in all cases I think it is allowed to be repeated like this, isn't it?
No, I'm afraid not. It is permitted to repeatedly mention `struct xentoollog_logger', but the typedef must only occur once in any translation unit.
If it is desirable to let callers avoid including xentoollog.h, then all those headers need to say:
struct xentoollog_logger; int some_function(..., struct xentoollog_logger *lg, ...);
So in your patches something like:
struct xentoollog_logger;
xenevtchn_handle *xenevtchn_open(struct xentoollog_logger *logger,
unsigned open_flags);
The separate struct xentoollog_logger;' is needed because otherwise the struct xentoollog_logger *logger' in the formal parameters of xenevtchn_open is a declaration, rather than a reference to a previously-declared thing, and if it is a declaration its scope is only the contained function prototype, so other mentions of `struct xentoollog_logger' are treated as references to a different type. This is, of course, insane.
Ian.
Re: [PATCH XEN v8 02/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
Quoted 25 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH XEN v8 02/29] tools: Refactor
/dev/xen/evtchnwrappers into libxenevtchn."):Quoted 7 lines
Various of the
tools/libs/*/include/*.hhave a/* Callers who don't care don't need to #include <xentoollog.h> */ typedef struct xentoollog_logger xentoollog_logger;but since that typedef matches in all cases I think it is allowed to be repeated like this, isn't it?
No, I'm afraid not. It is permitted to repeatedly mention `struct
xentoollog_logger', but the typedef must only occur once in any translation unit.If it is desirable to let callers avoid including
xentoollog.h, then all those headers need to say:struct xentoollog_logger; int some_function(..., struct xentoollog_logger *lg, ...);So in your patches something like:
struct xentoollog_logger; xenevtchn_handle *xenevtchn_open(struct xentoollog_logger *logger, unsigned open_flags);
Quoted 8 lines
The separate
struct xentoollog_logger;' is needed because otherwise thestructxentoollog_logger*logger' in the formal parameters ofxenevtchn_openis a declaration, rather than a reference to a previously-declared thing, and if it is a declaration its scope is only the contained function prototype, so other mentions of `structxentoollog_logger' are treated as references to a different type. This is, of course, insane.
(I was just about to respond to IanC's earlier message)
It builds on my desktop (gcc 4.9.2) but not on an older setup (4.4.7). BTW, I should have explicitly said so: I haven't bisected to this commit --- it just looked like this ould be the culprit.
-boris
Re: [PATCH XEN v8 02/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
In reply to Ian JacksonQuoted 11 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH XEN v8 02/29] tools:
Refactor/dev/xen/evtchnwrappers into libxenevtchn."):Quoted 7 lines
Various of the
tools/libs/*/include/*.hhave a/* Callers who don't care don't need to #include <
xentoollog.h> */ typedef structxentoollog_loggerxentoollog_logger;but since that typedef matches in all cases I think it is allowed to be repeated like this, isn't it?
No, I'm afraid not.
:-/
Quoted 3 lines
It is permitted to repeatedly mention `struct
xentoollog_logger', but the typedef must only occur once in any translation unit.
For some reason I thought the typedef's could be repeated so long as they were identical.
Seems at least Debian's gcc tolerates such things (which makes me wonder how many more instances of this might have snuck in, I guess folks like Boris would have spotted them pretty quick).
Quoted 6 lines
If it is desirable to let callers avoid including
xentoollog.h, then all those headers need to say:struct
xentoollog_logger;
intsome_function(..., struct xentoollog_logger *lg, ...);
Quoted 6 lines
So in your patches something like:
struct
xentoollog_logger;
xenevtchn_handle*xenevtchn_open(structxentoollog_logger*logger, unsignedopen_flags);
I'll do something like this for tools/libs/*/include.
FYI the underlying patches are all in since Friday.
Quoted 10 lines
The separate
struct xentoollog_logger;' is needed because otherwise thestructxentoollog_logger*logger' in the formal parameters ofxenevtchn_openis a declaration, rather than a reference to a previously-declared thing, and if it is a declaration its scope is only the contained function prototype, so other mentions of `structxentoollog_logger' are treated as references to a different type. This is, of course, insane.Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH XEN v8 02/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
Quoted 31 lines · Ian Campbell
Quoted 10 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH XEN v8 02/29] tools:
Refactor/dev/xen/evtchnwrappers into libxenevtchn."):Quoted 7 lines
Various of the
tools/libs/*/include/*.hhave a/* Callers who don't care don't need to #include <xentoollog.h> */ typedef struct xentoollog_logger xentoollog_logger;but since that typedef matches in all cases I think it is allowed to be repeated like this, isn't it?
No, I'm afraid not.
:-/
Quoted 3 lines
It is permitted to repeatedly mention `struct
xentoollog_logger', but the typedef must only occur once in any translation unit.For some reason I thought the typedef's could be repeated so long as they were identical.
Seems at least Debian's gcc tolerates such things (which makes me wonder how many more instances of this might have snuck in, I guess folks like Boris would have spotted them pretty quick).
Quoted 8 lines
If it is desirable to let callers avoid including
xentoollog.h, then all those headers need to say:struct xentoollog_logger; int some_function(..., struct xentoollog_logger *lg, ...);So in your patches something like:
Quoted 7 lines
Quoted 4 lines
struct
xentoollog_logger;
xenevtchn_handle*xenevtchn_open(structxentoollog_logger*logger,unsigned open_flags);I'll do something like this for
tools/libs/*/include.FYI the underlying patches are all in since Friday.
How about doing the header strictness check on all headers at one? If repeating typedefs is a gccism, that should catch it.
~Andrew
Re: [PATCH XEN v8 02/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
Quoted 38 lines · Andrew Cooper
Quoted 37 lines · Ian Campbell
Quoted 4 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH XEN v8 02/29] tools:
Refactor/dev/xen/evtchnwrappers into libxenevtchn."):Quoted 2 lines
Various of the
tools/libs/*/include/*.hhave aQuoted 8 lines
Quoted 7 lines
/* Callers who don't care don't need to #include <
xentoollog.h> */
typedef structxentoollog_loggerxentoollog_logger;but since that typedef matches in all cases I think it is allowed to be
repeated like this, isn't it?No, I'm afraid not.
:-/
Quoted 3 lines
It is permitted to repeatedly mention `struct
xentoollog_logger', but the typedef must only occur once in any translation unit.For some reason I thought the typedef's could be repeated so long as they
were identical.Seems at least Debian's gcc tolerates such things (which makes me wonder
how many more instances of this might have snuck in, I guess folks like Boris would have spotted them pretty quick).Quoted 10 lines
If it is desirable to let callers avoid including
xentoollog.h, then all those headers need to say:struct
xentoollog_logger;
intsome_function(..., struct xentoollog_logger *lg, ...);So in your patches something like:
struct
xentoollog_logger;
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
xenevtchn_handle*xenevtchn_open(structxentoollog_logger*logger, unsignedopen_flags);I'll do something like this for
tools/libs/*/include.FYI the underlying patches are all in since Friday.
How about doing the header strictness check on all headers at one? If repeating typedefs is a gccism, that should catch it.
AFAICT the issue here is that newer gcc tolerates duplicate typedefs under many circumstances. Seems to take -pedantic-errors to make it not, and I don't see another to enable the warning.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v8 3/29 tools: Arrange to check public headers for ANSI compatiblity
In reply to Ian CampbellUsing the same rune as we use for the Xen public headers, except we do not need stdint.h here.
---
v7: Drop -pendantic: Some library headers include parts of
xen/include/public, which in turn are not -pedantic clean Retained ack, hope that's ok.
--- .gitignore | 2 ++ tools/Rules.mk | 8 ++++++++ tools/libs/evtchn/Makefile | 4 +++- tools/libs/toollog/Makefile | 5 ++++- 4 files changed, 17 insertions(+), 2 deletions(-)
.gitignore +2 -0
@@ -87,6 +87,8 @@ tools/config.cache config/Tools.mk config/Stubdom.mk config/Docs.mk +tools/libs/toollog/headers.chk +tools/libs/evtchn/headers.chk tools/blktap2/daemon/blktapctrl tools/blktap2/drivers/img2qcow tools/blktap2/drivers/lock-util
tools/Rules.mk +8 -0
@@ -176,6 +176,14 @@ INSTALL_PYTHON_PROG = \ %.opic: %.S $(CC) $(CPPFLAGS) -DPIC $(CFLAGS) $(CFLAGS.opic) -fPIC -c -o $@ $< $(APPEND_CFLAGS) +headers.chk: + for i in $(filter %.h,$^); do \ + $(CC) -x c -ansi -Wall -Werror $(CFLAGS_xeninclude) \ + -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done >[email protected] + mv [email protected] $@ + subdirs-all subdirs-clean subdirs-install subdirs-distclean: .phony @set -e; for subdir in $(SUBDIRS) $(SUBDIRS-y); do \ $(MAKE) subdir-$(patsubst subdirs-%,%,$@)-$$subdir; \
tools/libs/evtchn/Makefile +3 -1
@@ -32,8 +32,9 @@ build: $(MAKE) libs .PHONY: libs -libs: $(LIB) +libs: headers.chk $(LIB) +headers.chk: $(wildcard include/*.h) libxenevtchn.a: $(LIB_OBJS) $(AR) rc $@ $^
@@ -64,6 +65,7 @@ TAGS: clean: rm -rf *.rpm $(LIB) *~ $(DEPS) $(LIB_OBJS) $(PIC_OBJS) rm -f libxenevtchn.so.$(MAJOR).$(MINOR) libxenevtchn.so.$(MAJOR) + rm -f headers.chk .PHONY: distclean distclean: clean
tools/libs/toollog/Makefile +4 -1
@@ -27,7 +27,9 @@ build: $(MAKE) libs .PHONY: libs -libs: $(LIB) +libs: headers.chk $(LIB) + +headers.chk: $(wildcard include/*.h) libxentoollog.a: $(LIB_OBJS) $(AR) rc $@ $^
@@ -58,6 +60,7 @@ TAGS: clean: rm -rf *.rpm $(LIB) *~ $(DEPS) $(LIB_OBJS) $(PIC_OBJS) rm -f libxentoollog.so.$(MAJOR).$(MINOR) libxentoollog.so.$(MAJOR) + rm -f headers.chk .PHONY: distclean distclean: clean
Signature · 1 line
2.1.4
PATCH v8 4/29 tools/libxc: Remove osdep indirection for xc_gnt{shr, tab}
In reply to Ian CampbellThe alternative backend (a xen-api/xapi shim) is no longer around and so this stuff is now just baggage which is getting in the way of refactoring libxenctrl.
Nested virt probably suffices for this use case now.
It is now necessary to provide explicit versions of things for platforms which do not implement this functionality, since the osdep dispatcher cannot fulfil this need any more. These are provided by appropriate xc_nognt???.c files which are compiled and linked on the appropriate platforms. In them open and close return failure and everything else aborts, since if open fails they should never be called.
--- tools/libxc/Makefile | 10 ++-- tools/libxc/include/xenctrl.h | 4 +- tools/libxc/include/xenctrlosdep.h | 23 ------- tools/libxc/xc_gnttab.c | 57 ++++-------------- tools/libxc/xc_linux_osdep.c | 119 +++++++++++++++---------------------- tools/libxc/xc_minios.c | 51 ++++++---------- tools/libxc/xc_nogntshr.c | 46 ++++++++++++++ tools/libxc/xc_nognttab.c | 50 ++++++++++++++++ tools/libxc/xc_private.c | 83 +++++++++++++++++++++----- tools/libxc/xc_private.h | 24 ++++++++ 10 files changed, 274 insertions(+), 193 deletions(-) create mode 100644 tools/libxc/xc_nogntshr.c create mode 100644 tools/libxc/xc_nognttab.c
tools/libxc/Makefile +5 -5
@@ -43,11 +43,11 @@ CTRL_SRCS-y += xc_resource.c CTRL_SRCS-$(CONFIG_X86) += xc_psr.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c -CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c -CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c -CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c -CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c -CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c +CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c xc_nognttab.c xc_nogntshr.c +CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c xc_nognttab.c xc_nogntshr.c +CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c +CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c +CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_nogntshr.c CTRL_SRCS-y += xc_evtchn_compat.c GUEST_SRCS-y :=
tools/libxc/include/xenctrl.h +2 -2
@@ -117,8 +117,8 @@*/ typedef struct xc_interface_core xc_interface ; -typedef struct xc_interface_core xc_gnttab ; -typedef struct xc_interface_core xc_gntshr ; +typedef struct xengntdev_handle xc_gnttab ; +typedef struct xengntdev_handle xc_gntshr ;enum xc_error_code {XC_ERROR_NONE =0 ,
tools/libxc/include/xenctrlosdep.h +0 -23
@@ -51,8 +51,6 @@enum xc_osdep_type {XC_OSDEP_PRIVCMD , -XC_OSDEP_GNTTAB , -XC_OSDEP_GNTSHR , };/* Opaque handle internal to the backend */
@@ -88,27 +86,6 @@ struct xc_osdep_ops size_t chunksize, privcmd_mmap_entry_t entries[], int nentries); } privcmd; -struct { -#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1 -void *(*grant_map)(xc_gnttab *xcg,xc_osdep_handle h, -uint32_t count,int flags,int prot, -uint32_t *domids,uint32_t *refs, -uint32_t notify_offset, -evtchn_port_t notify_port); -int (*munmap)(xc_gnttab *xcg,xc_osdep_handle h, -void *start_address, -uint32_t count); -int (*set_max_grants)(xc_gnttab *xcg,xc_osdep_handle h,uint32_t count); - } gnttab; -struct { -void *(*share_pages)(xc_gntshr *xcg,xc_osdep_handle h, -uint32_t domid,int count, -uint32_t *refs,int writable, -uint32_t notify_offset, -evtchn_port_t notify_port); -int (*munmap)(xc_gntshr *xcg,xc_osdep_handle h, -void *start_address,uint32_t count); - } gntshr; } u; };typedef struct xc_osdep_ops xc_osdep_ops ;
tools/libxc/xc_gnttab.c +13 -44
103 lines not on this page · raw message
tools/libxc/xc_linux_osdep.c +47 -72
235 lines not on this page · raw message
tools/libxc/xc_minios.c +19 -32
97 lines not on this page · raw message
tools/libxc/xc_nogntshr.c new file +46 -0
46 lines not on this page · raw message
tools/libxc/xc_nognttab.c new file +50 -0
50 lines not on this page · raw message
tools/libxc/xc_private.c +68 -15
106 lines not on this page · raw message
tools/libxc/xc_private.h +24 -0
@@ -123,6 +123,30 @@ struct xc_interface_core {xc_osdep_handle ops_handle;/* opaque data for xc_osdep_ops */ }; +struct xengntdev_handle { +xentoollog_logger *logger, *logger_tofree; +int fd; +}; + +int osdep_gnttab_open (xc_gnttab *xgt); +int osdep_gnttab_close (xc_gnttab *xgt); + +#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1 +void *osdep_gnttab_grant_map (xc_gnttab *xgt, +uint32_t count,int flags,int prot, +uint32_t *domids,uint32_t *refs, +uint32_t notify_offset, +evtchn_port_t notify_port); + +int osdep_gntshr_open (xc_gntshr *xgs); +int osdep_gntshr_close (xc_gntshr *xgs); + +void *osdep_gntshr_share_pages (xc_gntshr *xgs, +uint32_t domid,int count, +uint32_t *refs,int writable, +uint32_t notify_offset, +evtchn_port_t notify_port); +void xc_report_error (xc_interface *xch,int code,const char *fmt, ...) __attribute__((format (printf,3 ,4 ))); void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
Signature · 1 line
2.1.4
PATCH v8 5/29 tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab.
In reply to Ian Campbelllibxengnttab will provide a stable API and ABI for accessing the grant table devices.
The functions are moved into the xengnt{tab,shr} namespace to make a clean break from libxc and avoid ambiguity regarding which interfaces are stable.
All in-tree users are updated to use the new names.
Upon request (via #define XC_WANT_COMPAT_GNTTAB_API) libxenctrl will provide a compat API for the old names. This is used by qemu-xen for the time being. qemu-xen-traditional is updated in lockstep.
This leaves a few grant table related functions which go via privcmd (GNTTABOP) rather than ioctls on the /dev/xen/gnt* devices in libxenctrl. Specifically:
- xc_gnttab_get_version
- xc_gnttab_map_table_v1
- xc_gnttab_map_table_v2
- xc_gnttab_op
These functions do not appear to be needed by qemu-dm, qemu-pv (provision of device model to HVM guests and PV backends respectively) or by libvchan suggesting they are not needed by non-toolstack uses of event channels.
The new library uses a version script to ensure that only expected symbols are exported and to version them such that ABI guarantees can be kept in the future.
After this change libxenvchan no longer needs to link against libxenctrl. It still needs xenctrl.h in one file for xen_mb and friends.
---
Must be applied with:
- "qemu-xen-traditional: Use libxengnttab" and a corresponding QEMU_TAG update folded here.
- "mini-os: Include libxengnttab with libxc"" and a corresponding bump to MINIOS_UPSTREAM_REVISION folded in here.
v3:
- Remove SHLIB_libxenctrl from SHDEPS_libxenvchan, and replace with SHLIB_libxentoollog.
- Move to tools/libs/gnttab
- Adjust for rebase over 31cf2ca75181 "tools/libxc: linux: Don't use getpagesize() when unmapping the grants"
v5: Allow _close(NULL).
v6: The extensive API document updates from the previous round of
review have been implemented in "tools/libs/gnttab: Extensive updates to API documentation." later in the series, so as not to add further functional changes than already required to this refactoring patch.
v7: Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of
open coding the recursion. s/gnttab_munmap/gnttab_unmap/ and s/gntshr_munmap/gntshr_unshare/ in the API and equivalents in the internals/osdeps etc.
v8: s/EVTCHNOP/GNTTABOP/ cut-&-paste error in commit log.
Remove *.so on clean, add distclean target.
---
.gitignore | 2 +
stubdom/Makefile | 17 +-
tools/Makefile | 3 +
tools/Rules.mk | 14 +-
tools/console/Makefile | 5 +-
tools/console/daemon/io.c | 21 +-
tools/libs/Makefile | 1 +
tools/libs/evtchn/minios.c | 5 +-
tools/libs/gnttab/Makefile | 73 +++++
tools/libs/gnttab/gntshr_core.c | 95 ++++++
.../xc_nognttab.c => libs/gnttab/gntshr_unimp.c} | 34 ++-
tools/libs/gnttab/gnttab_core.c | 124 ++++++++
tools/libs/gnttab/gnttab_unimp.c | 89 ++++++
tools/libs/gnttab/include/xengnttab.h | 216 ++++++++++++++
tools/libs/gnttab/libxengnttab.map | 23 ++
tools/libs/gnttab/linux.c | 329 +++++++++++++++++++++
tools/libs/gnttab/minios.c | 117 ++++++++
tools/libs/gnttab/private.h | 47 +++
tools/libvchan/Makefile | 8 +-
tools/libvchan/init.c | 26 +-
tools/libvchan/io.c | 8 +-
tools/libvchan/libxenvchan.h | 6 +-
tools/libxc/Makefile | 15 +-
tools/libxc/include/xenctrl.h | 168 -----------
tools/libxc/include/xenctrl_compat.h | 48 +++
tools/libxc/xc_gnttab.c | 53 ----
tools/libxc/xc_gnttab_compat.c | 111 +++++++
tools/libxc/xc_linux_osdep.c | 280 ------------------
tools/libxc/xc_minios.c | 73 -----
tools/libxc/xc_nogntshr.c | 46 ---
tools/libxc/xc_private.c | 80 -----
tools/libxc/xc_private.h | 24 --
tools/xenstore/Makefile | 4 +-
tools/xenstore/xenstored_core.h | 4 +-
tools/xenstore/xenstored_domain.c | 24 +-
tools/xenstore/xenstored_minios.c | 5 +-
36 files changed, 1397 insertions(+), 801 deletions(-)
create mode 100644 tools/libs/gnttab/Makefile
create mode 100644 tools/libs/gnttab/gntshr_core.c
rename tools/{libxc/xc_nognttab.c => libs/gnttab/gntshr_unimp.c} (52%)
create mode 100644 tools/libs/gnttab/gnttab_core.c
create mode 100644 tools/libs/gnttab/gnttab_unimp.c
create mode 100644 tools/libs/gnttab/include/xengnttab.h
create mode 100644 tools/libs/gnttab/libxengnttab.map
create mode 100644 tools/libs/gnttab/linux.c
create mode 100644 tools/libs/gnttab/minios.c
create mode 100644 tools/libs/gnttab/private.h
create mode 100644 tools/libxc/xc_gnttab_compat.c
delete mode 100644 tools/libxc/xc_nogntshr.c.gitignore +2 -0
@@ -63,6 +63,7 @@ stubdom/ioemu/ stubdom/libs-* stubdom/libxc-* stubdom/libxenevtchn-* +stubdom/libxengnttab-* stubdom/libxentoollog-* stubdom/lwip-* stubdom/lwip/
@@ -89,6 +90,7 @@ config/Stubdom.mk config/Docs.mk tools/libs/toollog/headers.chk tools/libs/evtchn/headers.chk +tools/libs/gnttab/headers.chk tools/blktap2/daemon/blktapctrl tools/blktap2/drivers/img2qcow tools/blktap2/drivers/lock-util
stubdom/Makefile +16 -1
@@ -325,6 +325,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET) ln -sf $(XEN_ROOT)/tools/libs/evtchn/include/*.h include/ && \ ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.c . && \ ln -sf $(XEN_ROOT)/tools/libs/evtchn/Makefile . ) + mkdir -p libs-$(XEN_TARGET_ARCH)/gnttab/include + [ -h libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/gnttab && \ + ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.h . && \ + ln -sf $(XEN_ROOT)/tools/libs/gnttab/include/*.h include/ && \ + ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.c . && \ + ln -sf $(XEN_ROOT)/tools/libs/gnttab/Makefile . ) mkdir -p libxc-$(XEN_TARGET_ARCH) [ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \ ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -366,12 +372,21 @@ libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(N CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn ####### +# libxengnttab +####### + +.PHONY: libxengnttab +libxengnttab: libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a +libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) + CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab + +####### # libxc ####### .PHONY: libxc libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a -libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn cross-zlib +libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab cross-zlib CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH) libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
tools/Makefile +3 -0
@@ -249,9 +249,11 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find --includedir=$(LIBEXEC_INC) \ --source-path=$$source \ --extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \ + -DXC_WANT_COMPAT_GNTTAB_API=1 \ -I$(XEN_ROOT)/tools/include \ -I$(XEN_ROOT)/tools/libs/toollog/include \ -I$(XEN_ROOT)/tools/libs/evtchn/include \ + -I$(XEN_ROOT)/tools/libs/gnttab/include \ -I$(XEN_ROOT)/tools/libxc/include \ -I$(XEN_ROOT)/tools/xenstore/include \ -I$(XEN_ROOT)/tools/xenstore/compat/include \
@@ -260,6 +262,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find -L$(XEN_ROOT)/tools/xenstore \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \ + -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \ $(QEMU_UPSTREAM_RPATH)" \ --bindir=$(LIBEXEC_BIN) \ --datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +12 -2
@@ -12,6 +12,7 @@ INSTALL = $(XEN_ROOT)/tools/cross-install XEN_INCLUDE = $(XEN_ROOT)/tools/include XEN_LIBXENTOOLLOG = $(XEN_ROOT)/tools/libs/toollog XEN_LIBXENEVTCHN = $(XEN_ROOT)/tools/libs/evtchn +XEN_LIBXENGNTTAB = $(XEN_ROOT)/tools/libs/gnttab XEN_LIBXC = $(XEN_ROOT)/tools/libxc XEN_XENLIGHT = $(XEN_ROOT)/tools/libxl XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore
@@ -88,8 +89,17 @@ SHDEPS_libxenevtchn = LDLIBS_libxenevtchn = $(XEN_LIBXENEVTCHN)/libxenevtchn$(libextension) SHLIB_libxenevtchn = -Wl,-rpath-link=$(XEN_LIBXENEVTCHN) +CFLAGS_libxengnttab = -I$(XEN_LIBXENGNTTAB)/include $(CFLAGS_xeninclude) +LDLIBS_libxengnttab = $(XEN_LIBXENGNTTAB)/libxengnttab$(libextension) +SHLIB_libxengnttab = -Wl,-rpath-link=$(XEN_LIBXENGNTTAB) + +# xengntshr_* interfaces are actually part of libxengnttab.so +CFLAGS_libxengntshr = -I$(XEN_LIBXENGNTTAB)/include $(CFLAGS_xeninclude) +LDLIBS_libxengntshr = $(XEN_LIBXENGNTTAB)/libxengnttab$(libextension) +SHLIB_libxengntshr = -Wl,-rpath-link=$(XEN_LIBXENGNTTAB) + CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude) -SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) +SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension) SHLIB_libxenctrl = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
@@ -109,7 +119,7 @@ LDLIBS_libxenstat = $(SHDEPS_libxenstat) $(XEN_LIBXENSTAT)/libxenstat$(libexten SHLIB_libxenstat = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_LIBXENSTAT) CFLAGS_libxenvchan = -I$(XEN_LIBVCHAN) -SHDEPS_libxenvchan = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn) +SHDEPS_libxenvchan = $(SHLIB_libxentoollog) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libextension) SHLIB_libxenvchan = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
tools/console/Makefile +2 -3
@@ -3,10 +3,8 @@ include $(XEN_ROOT)/tools/Rules.mk CFLAGS += -Werror -CFLAGS += $(CFLAGS_libxenevtchn) CFLAGS += $(CFLAGS_libxenctrl) CFLAGS += $(CFLAGS_libxenstore) -LDLIBS += $(LDLIBS_libxenevtchn) LDLIBS += $(LDLIBS_libxenctrl) LDLIBS += $(LDLIBS_libxenstore) LDLIBS += $(SOCKET_LIBS)
@@ -28,8 +26,9 @@ clean: .PHONY: distclean distclean: clean +daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab) xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c)) - $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_xenconsoled) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_xenconsoled) $(APPEND_LDFLAGS) xenconsole: client/_paths.h $(patsubst %.c,%.o,$(wildcard client/*.c)) $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_xenconsole) $(APPEND_LDFLAGS)
tools/console/daemon/io.c +11 -10
@@ -22,6 +22,7 @@#include "utils.h" #include "io.h" #include <xenevtchn.h> +#include <xengnttab.h> #include <xenstore.h> #include <xen/io/console.h> #include <xen/grant_table.h>
@@ -72,7 +73,7 @@ static int log_time_hv_needts = 1;static int log_time_guest_needts =1 ;static int log_hv_fd =-1 ; -static xc_gnttab *xcg_handle =NULL ; +static xengnttab_handle *xgt_handle =NULL ;static struct pollfd *fds;static unsigned int current_array_size;
@@ -520,8 +521,8 @@ static void domain_unmap_interface(struct domain *dom) {if (dom->interface ==NULL )return ; -if (xcg_handle && dom->ring_ref ==-1 ) -xc_gnttab_munmap (xcg_handle, dom->interface,1 ); +if (xgt_handle && dom->ring_ref ==-1 ) +xengnttab_unmap (xgt_handle, dom->interface,1 );else munmap (dom->interface,XC_PAGE_SIZE ); dom->interface =NULL ;
@@ -552,9 +553,9 @@ static int domain_create_ring(struct domain *dom)if (ring_ref != dom->ring_ref && dom->ring_ref !=-1 )domain_unmap_interface (dom); -if (!dom->interface && xcg_handle) { +if (!dom->interface && xgt_handle) {/* Prefer using grant table */ - dom->interface =xc_gnttab_map_grant_ref (xcg_handle, + dom->interface =xengnttab_map_grant_ref (xgt_handle, dom->domid,GNTTAB_RESERVED_CONSOLE ,PROT_READ |PROT_WRITE ); dom->ring_ref =-1 ;
@@ -1029,8 +1030,8 @@ void handle_io(void)handle_hv_logs (xce_handle, true); } - xcg_handle =xc_gnttab_open (NULL ,0 ); -if (xcg_handle ==NULL ) { + xgt_handle =xengnttab_open (NULL ,0 ); +if (xgt_handle ==NULL ) {dolog (LOG_DEBUG ,"Failed to open xcg handle: %d (%s)" , errno,strerror (errno)); }
@@ -1206,9 +1207,9 @@ void handle_io(void)xenevtchn_close (xce_handle); xce_handle =NULL ; } -if (xcg_handle !=NULL ) { -xc_gnttab_close (xcg_handle); - xcg_handle =NULL ; +if (xgt_handle !=NULL ) { +xengnttab_close (xgt_handle); + xgt_handle =NULL ; } log_hv_evtchn =-1 ; }
tools/libs/Makefile +1 -0
@@ -4,5 +4,6 @@ include $(XEN_ROOT)/tools/Rules.mk SUBDIRS-y := SUBDIRS-y += toollog SUBDIRS-y += evtchn +SUBDIRS-y += gnttab all clean install distclean: %: subdirs-%
tools/libs/evtchn/minios.c +1 -4
@@ -27,13 +27,12 @@#include <mini-os/events.h> #include <mini-os/wait.h> -#include <sys/socket.h> -#include <assert.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdint.h> +#include <unistd.h> #include <inttypes.h> #include <malloc.h>
@@ -43,8 +42,6 @@ extern void minios_evtchn_close_fd(int fd);extern struct wait_queue_head event_queue; -//void minios_evtchn_close_fd(int fd); -/* XXX Note: This is not threadsafe */ static struct evtchn_port_info *port_alloc (int fd) {struct evtchn_port_info *port_info;
tools/libs/gnttab/Makefile new file +73 -0
73 lines not on this page · raw message
tools/libs/gnttab/gntshr_core.c new file +95 -0
95 lines not on this page · raw message
tools/libs/gnttab/gntshr_unimp.c renamed from tools/libxc/xc_nognttab.c +23 -11
@@ -14,37 +14,49 @@* * You should have received a copy of the GNU Lesser General Public * License along with this library; If not, see <http://www.gnu.org/licenses/>. +* +* Split out from xc_gnttab.c */ #include <stdlib.h> -#include "xc_private.h" +#include "private.h" -int osdep_gnttab_open (xc_gnttab *xgt) +xengntshr_handle *xengntshr_open (xentoollog_logger *logger,unsigned open_flags) { -return -1 ; +return NULL ; } -int osdep_gnttab_close (xc_gnttab *xgt) +int xengntshr_close (xengntshr_handle *xgs) {return 0 ; } -int xc_gnttab_set_max_grants (xc_gnttab *xgt,uint32_t count) +void *xengntshr_share_pages (xengntshr_handle *xcg,uint32_t domid, +int count,uint32_t *refs,int writable) {abort (); } -void *osdep_gnttab_grant_map (xc_gnttab *xgt, -uint32_t count,int flags,int prot, -uint32_t *domids,uint32_t *refs, -uint32_t notify_offset, -evtchn_port_t notify_port) +void *xengntshr_share_page_notify (xengntshr_handle *xcg,uint32_t domid, +uint32_t *ref,int writable, +uint32_t notify_offset, +evtchn_port_t notify_port) {abort (); } -int xc_gnttab_munmap (xc_gnttab *xgt,void *start_address,uint32_t count) +int xengntshr_unshare (xengntshr_handle *xgs,void *start_address,uint32_t count) {abort (); } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libs/gnttab/gnttab_core.c new file +124 -0
124 lines not on this page · raw message
tools/libs/gnttab/gnttab_unimp.c new file +89 -0
89 lines not on this page · raw message
tools/libs/gnttab/include/xengnttab.h new file +216 -0
216 lines not on this page · raw message
tools/libs/gnttab/libxengnttab.map new file +23 -0
@@ -0,0 +1,23 @@ +VERS_1.0 { + global: + xengnttab_open; + xengnttab_close; + + xengnttab_set_max_grants; + + xengnttab_map_domain_grant_refs; + xengnttab_map_grant_ref; + xengnttab_map_grant_ref_notify; + xengnttab_map_grant_refs; + + xengnttab_unmap; + + xengntshr_open; + xengntshr_close; + + xengntshr_share_page_notify; + xengntshr_share_pages; + + xengntshr_unshare; + local: *; /* Do not expose anything by default */ +};
tools/libs/gnttab/linux.c new file +329 -0
329 lines not on this page · raw message
tools/libs/gnttab/minios.c new file +117 -0
117 lines not on this page · raw message
tools/libs/gnttab/private.h new file +47 -0
47 lines not on this page · raw message
tools/libvchan/Makefile +5 -3
@@ -10,15 +10,17 @@ NODE_OBJS = node.o NODE2_OBJS = node-select.o LIBVCHAN_PIC_OBJS = $(patsubst %.o,%.opic,$(LIBVCHAN_OBJS)) -LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenevtchn) -$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) -$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) +LIBVCHAN_LIBS = $(LDLIBS_libxenstore) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(LDLIBS_libxenevtchn) +$(LIBVCHAN_OBJS) $(LIBVCHAN_PIC_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr) $(CFLAGS_libxenevtchn) +$(NODE_OBJS) $(NODE2_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr) $(CFLAGS_libxenevtchn) MAJOR = 1.0 MINOR = 0 CFLAGS += -I../include -I. +io.o io.opic: CFLAGS += $(CFLAGS_libxenctrl) # for xen_mb et al + .PHONY: all all: libxenvchan.so vchan-node1 vchan-node2 libxenvchan.a
tools/libvchan/init.c +13 -13
@@ -78,7 +78,7 @@ static int init_gnt_srv(struct libxenvchan *ctrl, int domain)uint32_t ring_ref =-1 ;void *ring; - ring =xc_gntshr_share_page_notify (ctrl->gntshr, domain, + ring =xengntshr_share_page_notify (ctrl->gntshr, domain, &ring_ref,1 , offsetof(struct vchan_interface , srv_live), ctrl->event_port);
@@ -104,7 +104,7 @@ static int init_gnt_srv(struct libxenvchan *ctrl, int domain) ctrl->read.buffer = ((void *)ctrl->ring) +LARGE_RING_OFFSET ;break ;default : - ctrl->read.buffer =xc_gntshr_share_pages (ctrl->gntshr, domain, + ctrl->read.buffer =xengntshr_share_pages (ctrl->gntshr, domain, pages_left, ctrl->ring->grants,1 );if (!ctrl->read.buffer) goto out_ring;
@@ -118,7 +118,7 @@ static int init_gnt_srv(struct libxenvchan *ctrl, int domain) ctrl->write.buffer = ((void *)ctrl->ring) +LARGE_RING_OFFSET ;break ;default : - ctrl->write.buffer =xc_gntshr_share_pages (ctrl->gntshr, domain, + ctrl->write.buffer =xengntshr_share_pages (ctrl->gntshr, domain, pages_right, ctrl->ring->grants + pages_left,1 );if (!ctrl->write.buffer) goto out_unmap_left;
@@ -128,9 +128,9 @@ out:return ring_ref; out_unmap_left:if (pages_left) -xc_gntshr_munmap (ctrl->gntshr, ctrl->read.buffer, pages_left); +xengntshr_unshare (ctrl->gntshr, ctrl->read.buffer, pages_left); out_ring: -xc_gntshr_munmap (ctrl->gntshr, ring,1 ); +xengntshr_unshare (ctrl->gntshr, ring,1 ); ring_ref =-1 ; ctrl->ring =NULL ; ctrl->write.order = ctrl->read.order =0 ;
@@ -142,7 +142,7 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)int rv =-1 ;uint32_t *grants; - ctrl->ring =xc_gnttab_map_grant_ref_notify (ctrl->gnttab, + ctrl->ring =xengnttab_map_grant_ref_notify (ctrl->gnttab, domain, ring_ref,PROT_READ |PROT_WRITE , offsetof(struct vchan_interface , cli_live), ctrl->event_port);
@@ -172,7 +172,7 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)default : {int pages_left =1 << (ctrl->write.order -PAGE_SHIFT ); - ctrl->write.buffer =xc_gnttab_map_domain_grant_refs (ctrl->gnttab, + ctrl->write.buffer =xengnttab_map_domain_grant_refs (ctrl->gnttab, pages_left, domain, grants,PROT_READ |PROT_WRITE );if (!ctrl->write.buffer) goto out_unmap_ring;
@@ -190,7 +190,7 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)default : {int pages_right =1 << (ctrl->read.order -PAGE_SHIFT ); - ctrl->read.buffer =xc_gnttab_map_domain_grant_refs (ctrl->gnttab, + ctrl->read.buffer =xengnttab_map_domain_grant_refs (ctrl->gnttab, pages_right, domain, grants,PROT_READ );if (!ctrl->read.buffer) goto out_unmap_left;
@@ -202,10 +202,10 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)return rv; out_unmap_left:if (ctrl->write.order >=PAGE_SHIFT ) -xc_gnttab_munmap (ctrl->gnttab, ctrl->write.buffer, -1 << (ctrl->write.order -PAGE_SHIFT )); +xengnttab_unmap (ctrl->gnttab, ctrl->write.buffer, +1 << (ctrl->write.order -PAGE_SHIFT )); out_unmap_ring: -xc_gnttab_munmap (ctrl->gnttab, ctrl->ring,1 ); +xengnttab_unmap (ctrl->gnttab, ctrl->ring,1 ); ctrl->ring =0 ; ctrl->write.order = ctrl->read.order =0 ; rv =-1 ;
@@ -325,7 +325,7 @@ struct libxenvchan *libxenvchan_server_init(xentoollog_logger *logger, int domai ctrl->write.order =LARGE_RING_SHIFT ; } - ctrl->gntshr =xc_gntshr_open (logger,0 ); + ctrl->gntshr =xengntshr_open (logger,0 );if (!ctrl->gntshr) goto out;
@@ -413,7 +413,7 @@ struct libxenvchan *libxenvchan_client_init(xentoollog_logger *logger, int domaiif (!ctrl->event_port) goto fail; - ctrl->gnttab =xc_gnttab_open (logger,0 ); + ctrl->gnttab =xengnttab_open (logger,0 );if (!ctrl->gnttab) goto fail;
tools/libvchan/io.c +4 -4
@@ -366,10 +366,10 @@ void libxenvchan_close(struct libxenvchan *ctrl)if (ctrl->ring) {if (ctrl->is_server) { ctrl->ring->srv_live =0 ; -xc_gntshr_munmap (ctrl->gntshr, ctrl->ring,1 ); +xengntshr_unshare (ctrl->gntshr, ctrl->ring,1 ); }else { ctrl->ring->cli_live =0 ; -xc_gnttab_munmap (ctrl->gnttab, ctrl->ring,1 ); +xengnttab_unmap (ctrl->gnttab, ctrl->ring,1 ); } }if (ctrl->event) {
@@ -379,10 +379,10 @@ void libxenvchan_close(struct libxenvchan *ctrl) }if (ctrl->is_server) {if (ctrl->gntshr) -xc_gntshr_close (ctrl->gntshr); +xengntshr_close (ctrl->gntshr); }else {if (ctrl->gnttab) -xc_gnttab_close (ctrl->gnttab); +xengnttab_close (ctrl->gnttab); }free (ctrl); }
tools/libvchan/libxenvchan.h +3 -3
@@ -45,7 +45,7 @@#include <xen/io/libxenvchan.h> #include <xen/sys/evtchn.h> #include <xenevtchn.h> -#include <xenctrl.h> +#include <xengnttab.h> struct libxenvchan_ring {/* Pointer into the shared page. Offsets into buffer. */
@@ -66,8 +66,8 @@ struct libxenvchan_ring {struct libxenvchan {/* Mapping handle for shared ring page */ union { -xc_gntshr *gntshr;/* for server */ -xc_gnttab *gnttab;/* for client */ +xengntshr_handle *gntshr;/* for server */ +xengnttab_handle *gnttab;/* for client */ };/* Pointer to shared ring page */ struct vchan_interface *ring;
tools/libxc/Makefile +9 -6
@@ -43,12 +43,13 @@ CTRL_SRCS-y += xc_resource.c CTRL_SRCS-$(CONFIG_X86) += xc_psr.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c -CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c xc_nognttab.c xc_nogntshr.c -CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c xc_nognttab.c xc_nogntshr.c -CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c -CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c -CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_nogntshr.c +CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c +CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c +CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c +CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c +CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c CTRL_SRCS-y += xc_evtchn_compat.c +CTRL_SRCS-y += xc_gnttab_compat.c GUEST_SRCS-y := GUEST_SRCS-y += xg_private.c xc_suspend.c
@@ -126,6 +127,8 @@ OSDEP_PIC_OBJS := $(patsubst %.c,%.opic,$(OSDEP_SRCS-y)) $(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) $(OSDEP_LIB_OBJS) \ $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS) $(OSDEP_PIC_OBJS) : CFLAGS += -include $(XEN_ROOT)/tools/config.h +$(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr) + LIB := libxenctrl.a ifneq ($(nosharedlibs),y) LIB += libxenctrl.so libxenctrl.so.$(MAJOR) libxenctrl.so.$(MAJOR).$(MINOR)
@@ -209,7 +212,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR) $(SYMLINK_SHLIB) $< $@ libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS) - $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) # libxenguest
tools/libxc/include/xenctrl.h +0 -168
192 lines not on this page · raw message
tools/libxc/include/xenctrl_compat.h +48 -0
54 lines not on this page · raw message
tools/libxc/xc_gnttab.c +0 -53
59 lines not on this page · raw message
tools/libxc/xc_gnttab_compat.c new file +111 -0
111 lines not on this page · raw message
tools/libxc/xc_linux_osdep.c +0 -280
298 lines not on this page · raw message
tools/libxc/xc_minios.c +0 -73
91 lines not on this page · raw message
tools/libxc/xc_nogntshr.c deleted +0 -46
46 lines not on this page · raw message
tools/libxc/xc_private.c +0 -80
86 lines not on this page · raw message
tools/libxc/xc_private.h +0 -24
@@ -123,30 +123,6 @@ struct xc_interface_core {xc_osdep_handle ops_handle;/* opaque data for xc_osdep_ops */ }; -struct xengntdev_handle { -xentoollog_logger *logger, *logger_tofree; -int fd; -}; - -int osdep_gnttab_open (xc_gnttab *xgt); -int osdep_gnttab_close (xc_gnttab *xgt); - -#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1 -void *osdep_gnttab_grant_map (xc_gnttab *xgt, -uint32_t count,int flags,int prot, -uint32_t *domids,uint32_t *refs, -uint32_t notify_offset, -evtchn_port_t notify_port); - -int osdep_gntshr_open (xc_gntshr *xgs); -int osdep_gntshr_close (xc_gntshr *xgs); - -void *osdep_gntshr_share_pages (xc_gntshr *xgs, -uint32_t domid,int count, -uint32_t *refs,int writable, -uint32_t notify_offset, -evtchn_port_t notify_port); -void xc_report_error (xc_interface *xch,int code,const char *fmt, ...) __attribute__((format (printf,3 ,4 ))); void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
tools/xenstore/Makefile +3 -1
@@ -78,8 +78,10 @@ init-xenstore-domain.o: CFLAGS += $(CFLAGS_libxenguest) init-xenstore-domain: init-xenstore-domain.o $(LIBXENSTORE) $(CC) $^ $(LDFLAGS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) -o $@ $(APPEND_LDFLAGS) +$(XENSTORED_OBJS): CFLAGS += $(CFLAGS_libxengnttab) + xenstored: $(XENSTORED_OBJS) - $(CC) $^ $(LDFLAGS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS) + $(CC) $^ $(LDFLAGS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS) xenstored.a: $(XENSTORED_OBJS) $(AR) cr $@ $^
tools/xenstore/xenstored_core.h +3 -1
@@ -20,12 +20,14 @@#define _XENSTORED_CORE_H#include <xenctrl.h> +#include <xengnttab.h> #include <sys/types.h> #include <dirent.h> #include <stdbool.h> #include <stdint.h> #include <errno.h> +#include "xenstore_lib.h" #include "list.h" #include "tdb.h"
@@ -196,7 +198,7 @@ void finish_daemonize(void);/* Open a pipe for signal handling */ void init_pipe (int reopen_log_pipe[2 ]); -xc_gnttab **xcg_handle; +xengnttab_handle **xgt_handle;#endif /* _XENSTORED_CORE_H */
tools/xenstore/xenstored_domain.c +12 -12
@@ -34,7 +34,7 @@#include <xen/grant_table.h> static xc_interface **xc_handle; -xc_gnttab **xcg_handle; +xengnttab_handle **xgt_handle;static evtchn_port_t virq_port;xenevtchn_handle *xce_handle =NULL ;
@@ -166,9 +166,9 @@ static int readchn(struct connection *conn, void *data, unsigned int len)static void *map_interface (domid_t domid,unsigned long mfn) { -if (*xcg_handle !=NULL ) { +if (*xgt_handle !=NULL ) {/* this is the preferred method */ -return xc_gnttab_map_grant_ref (*xcg_handle, domid, +return xengnttab_map_grant_ref (*xgt_handle, domid,GNTTAB_RESERVED_XENSTORE ,PROT_READ |PROT_WRITE ); }else { return xc_map_foreign_range(*xc_handle, domid,
@@ -178,8 +178,8 @@ static void *map_interface(domid_t domid, unsigned long mfn)static void unmap_interface (void *interface) { -if (*xcg_handle !=NULL ) -xc_gnttab_munmap (*xcg_handle, interface,1 ); +if (*xgt_handle !=NULL ) +xengnttab_unmap (*xgt_handle, interface,1 );else munmap (interface,XC_PAGE_SIZE ); }
@@ -577,9 +577,9 @@ static int close_xc_handle(void *_handle)return 0 ; } -static int close_xcg_handle (void *_handle) +static int close_xgt_handle (void *_handle) { -xc_gnttab_close (*(xc_gnttab **)_handle); +xengnttab_close (*(xengnttab_handle **)_handle);return 0 ; }
@@ -634,15 +634,15 @@ void domain_init(void)talloc_set_destructor (xc_handle, close_xc_handle); - xcg_handle = talloc(talloc_autofree_context(), xc_gnttab*); -if (!xcg_handle) + xgt_handle = talloc(talloc_autofree_context(), xengnttab_handle*); +if (!xgt_handle)barf_perror ("Failed to allocate domain gnttab handle" ); - *xcg_handle =xc_gnttab_open (NULL ,0 ); -if (*xcg_handle ==NULL ) + *xgt_handle =xengnttab_open (NULL ,0 ); +if (*xgt_handle ==NULL )xprintf ("WARNING: Failed to open connection to gnttab\n" );else -talloc_set_destructor (xcg_handle, close_xcg_handle); +talloc_set_destructor (xgt_handle, close_xgt_handle); xce_handle =xenevtchn_open (NULL ,0 );
tools/xenstore/xenstored_minios.c +2 -3
@@ -17,7 +17,6 @@*/ #include <sys/types.h> #include <sys/mman.h> -#include <xenctrl.h> #include "xenstored_core.h" #include <xen/grant_table.h>
@@ -50,12 +49,12 @@ evtchn_port_t xenbus_evtchn(void)void *xenbus_map (void ) { -return xc_gnttab_map_grant_ref (*xcg_handle,xenbus_master_domid (), +return xengnttab_map_grant_ref (*xgt_handle,xenbus_master_domid (),GNTTAB_RESERVED_XENSTORE ,PROT_READ |PROT_WRITE ); }void unmap_xenbus (void *interface) { -xc_gnttab_munmap (*xcg_handle, interface,1 ); +xengnttab_unmap (*xgt_handle, interface,1 ); }
Signature · 1 line
2.1.4
PATCH v8 6/29 tools/libxc: Remove osdep indirection for privcmd
In reply to Ian CampbellThe alternative backend (a xen-api/xapi shim) is no longer around and so this stuff is now just baggage which is getting in the way of refactoring libxenctrl.
Nested virt probably suffices for this use case now.
This was the last component of the osdep infrastructure, so all the dynamic loading etc stuff all falls away too.
As part of this I was forced to investigate the twisty xc_map_foreign_* maze, which I have added to the toolstack-library-apis doc in the hopes of doing something sensible.
NetBSD and Solaris now call xc_map_foreign_bulk_compat directly from their xc_map_foreign_bulk, which could have been achieved by using some ifdefs around a renamed function. This will fall out in the wash when these functions move to their own library.
---
v7: Stop CCing Dave's dead citrix address.
--- config/FreeBSD.mk | 2 - config/NetBSD.mk | 3 - config/NetBSDRump.mk | 1 - config/StdGNU.mk | 1 - config/SunOS.mk | 1 - tools/libxc/Makefile | 27 ++---- tools/libxc/include/xenctrl.h | 9 -- tools/libxc/include/xenctrlosdep.h | 133 --------------------------- tools/libxc/xc_foreign_memory.c | 31 +------ tools/libxc/xc_freebsd_osdep.c | 100 ++++++--------------- tools/libxc/xc_hcall_buf.c | 6 +- tools/libxc/xc_linux_osdep.c | 88 ++++++------------ tools/libxc/xc_minios.c | 82 +++++------------ tools/libxc/xc_netbsd.c | 90 +++++++------------ tools/libxc/xc_private.c | 174 ++---------------------------------- tools/libxc/xc_private.h | 19 ++-- tools/libxc/xc_solaris.c | 90 +++++++------------ tools/libxc/xenctrl_osdep_ENOSYS.c | 123 ------------------------- tools/ocaml/libs/xc/xenctrl.ml | 2 - tools/ocaml/libs/xc/xenctrl.mli | 1 - tools/ocaml/libs/xc/xenctrl_stubs.c | 7 -- tools/ocaml/xenstored/domains.ml | 6 +- tools/ocaml/xenstored/xenstored.ml | 5 +- 23 files changed, 178 insertions(+), 823 deletions(-) delete mode 100644 tools/libxc/include/xenctrlosdep.h delete mode 100644 tools/libxc/xenctrl_osdep_ENOSYS.c
config/FreeBSD.mk +0 -2
@@ -1,6 +1,4 @@ include $(XEN_ROOT)/config/StdGNU.mk -DLOPEN_LIBS = - # No wget on FreeBSD base system WGET = ftp
config/NetBSD.mk +0 -3
@@ -1,6 +1,3 @@ include $(XEN_ROOT)/config/StdGNU.mk -# Override settings for this OS -DLOPEN_LIBS = - WGET = ftp
config/NetBSDRump.mk +0 -1
@@ -1,6 +1,5 @@ include $(XEN_ROOT)/config/StdGNU.mk -DLOPEN_LIBS = PTHREAD_LIBS = WGET = ftp
config/StdGNU.mk +0 -1
@@ -31,7 +31,6 @@ DEBUG_DIR ?= /usr/lib/debug SOCKET_LIBS = UTIL_LIBS = -lutil -DLOPEN_LIBS = -ldl SONAME_LDFLAG = -soname SHLIB_LDFLAGS = -shared
config/SunOS.mk +0 -1
@@ -27,7 +27,6 @@ SunOS_LIBDIR_x86_64 = /usr/sfw/lib/amd64 SOCKET_LIBS = -lsocket PTHREAD_LIBS = -lpthread UTIL_LIBS = -DLOPEN_LIBS = -ldl SONAME_LDFLAG = -h SHLIB_LDFLAGS = -R $(SunOS_LIBDIR) -shared
tools/libxc/Makefile +7 -20
@@ -101,8 +101,6 @@ GUEST_SRCS-y += xc_dom_decompress_unsafe_lzo1x.c GUEST_SRCS-y += xc_dom_decompress_unsafe_xz.c endif -OSDEP_SRCS-y += xenctrl_osdep_ENOSYS.c - -include $(XEN_TARGET_ARCH)/Makefile CFLAGS += -Werror -Wmissing-prototypes
@@ -121,11 +119,8 @@ CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y)) GUEST_LIB_OBJS := $(patsubst %.c,%.o,$(GUEST_SRCS-y)) GUEST_PIC_OBJS := $(patsubst %.c,%.opic,$(GUEST_SRCS-y)) -OSDEP_LIB_OBJS := $(patsubst %.c,%.o,$(OSDEP_SRCS-y)) -OSDEP_PIC_OBJS := $(patsubst %.c,%.opic,$(OSDEP_SRCS-y)) - -$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) $(OSDEP_LIB_OBJS) \ -$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS) $(OSDEP_PIC_OBJS) : CFLAGS += -include $(XEN_ROOT)/tools/config.h +$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \ +$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h $(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr)
@@ -139,17 +134,13 @@ ifneq ($(nosharedlibs),y) LIB += libxenguest.so libxenguest.so.$(MAJOR) libxenguest.so.$(MAJOR).$(MINOR) endif -ifneq ($(nosharedlibs),y) -LIB += xenctrl_osdep_ENOSYS.so -endif - genpath-target = $(call buildmakevars2header,_paths.h) $(eval $(genpath-target)) xc_private.h: _paths.h -$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) $(OSDEP_LIB_OBJS) \ -$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS) $(OSDEP_PIC_OBJS): xc_private.h +$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \ +$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): xc_private.h .PHONY: all all: build
@@ -169,7 +160,7 @@ install: build $(INSTALL_DATA) libxenctrl.a $(DESTDIR)$(libdir) $(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR) $(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenctrl.so - $(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h include/xenctrlosdep.h $(DESTDIR)$(includedir) + $(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h $(DESTDIR)$(includedir) $(INSTALL_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir) $(INSTALL_DATA) libxenguest.a $(DESTDIR)$(libdir) $(SYMLINK_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenguest.so.$(MAJOR)
@@ -185,8 +176,7 @@ clean: rm -rf *.rpm $(LIB) *~ $(DEPS) \ _paths.h \ $(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS) \ - $(GUEST_LIB_OBJS) $(GUEST_PIC_OBJS) \ - $(OSDEP_LIB_OBJS) $(OSDEP_PIC_OBJS) + $(GUEST_LIB_OBJS) $(GUEST_PIC_OBJS) .PHONY: distclean distclean: clean
@@ -212,7 +202,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR) $(SYMLINK_SHLIB) $< $@ libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS) - $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) # libxenguest
@@ -237,8 +227,5 @@ libxenguest.so.$(MAJOR).$(MINOR): COMPRESSION_LIBS = $(call zlib-options,l) libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) -xenctrl_osdep_ENOSYS.so: $(OSDEP_PIC_OBJS) libxenctrl.so - $(CC) $(LDFLAGS) $(SHLIB_LDFLAGS) -o $@ $(OSDEP_PIC_OBJS) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) - -include $(DEPS)
tools/libxc/include/xenctrl.h +0 -9
@@ -181,15 +181,6 @@ enum xc_open_flags {*/ int xc_interface_close (xc_interface *xch); -/** -* Query the active OS interface (i.e. that which would be returned by -* xc_interface_open) to find out if it is fake (i.e. backends onto -* something other than an actual Xen hypervisor). -* -* @return 0 is "real", >0 if fake, -1 on error. -*/ -int xc_interface_is_fake (void ); -/* * HYPERCALL SAFE MEMORY BUFFER *
tools/libxc/include/xenctrlosdep.h deleted +0 -133
133 lines not on this page · raw message
tools/libxc/xc_foreign_memory.c +1 -30
@@ -50,37 +50,8 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,return res; } -void *xc_map_foreign_range (xc_interface *xch,uint32_t dom, -int size,int prot,unsigned long mfn) -{ -return xch->ops->u.privcmd.map_foreign_range (xch, xch->ops_handle, - dom, size, prot, mfn); -} - -void *xc_map_foreign_ranges (xc_interface *xch,uint32_t dom, -size_t size,int prot,size_t chunksize, -privcmd_mmap_entry_t entries[],int nentries) -{ -return xch->ops->u.privcmd.map_foreign_ranges (xch, xch->ops_handle, - dom, size, prot, chunksize, entries, nentries); -} - -void *xc_map_foreign_batch (xc_interface *xch,uint32_t dom,int prot, -xen_pfn_t *arr,int num) -{ -return xch->ops->u.privcmd.map_foreign_batch (xch, xch->ops_handle, - dom, prot, arr, num); -} - -void *xc_map_foreign_bulk (xc_interface *xch,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num) -{ -return xch->ops->u.privcmd.map_foreign_bulk (xch, xch->ops_handle, - dom, prot, arr, err, num); -} -/* stub for all not yet converted OSes */ -void *xc_map_foreign_bulk_compat (xc_interface *xch,xc_osdep_handle h, +void *xc_map_foreign_bulk_compat (xc_interface *xch,uint32_t dom,int prot,const xen_pfn_t *arr,int *err,unsigned int num) {
tools/libxc/xc_freebsd_osdep.c +27 -73
173 lines not on this page · raw message
tools/libxc/xc_hcall_buf.c +3 -3
@@ -122,7 +122,7 @@ void xc__hypercall_buffer_cache_release(xc_interface *xch)while ( xch->hypercall_buffer_cache_nr >0 ) { p = xch->hypercall_buffer_cache[--xch->hypercall_buffer_cache_nr]; - xch->ops->u.privcmd.free_hypercall_buffer (xch, xch->ops_handle, p,1 ); +osdep_free_hypercall_buffer (xch, p,1 ); }hypercall_buffer_cache_unlock (xch);
@@ -133,7 +133,7 @@ void *xc__hypercall_buffer_alloc_pages(xc_interface *xch, xc_hypercall_buffer_tvoid *p =hypercall_buffer_cache_alloc (xch, nr_pages);if ( !p ) - p = xch->ops->u.privcmd.alloc_hypercall_buffer (xch, xch->ops_handle, nr_pages); + p =osdep_alloc_hypercall_buffer (xch, nr_pages);if (!p)return NULL ;
@@ -151,7 +151,7 @@ void xc__hypercall_buffer_free_pages(xc_interface *xch, xc_hypercall_buffer_t *breturn ;if ( !hypercall_buffer_cache_free (xch, b->hbuf, nr_pages) ) - xch->ops->u.privcmd.free_hypercall_buffer (xch, xch->ops_handle, b->hbuf, nr_pages); +osdep_free_hypercall_buffer (xch, b->hbuf, nr_pages); }struct allocation_header {
tools/libxc/xc_linux_osdep.c +28 -60
167 lines not on this page · raw message
tools/libxc/xc_minios.c +24 -58
148 lines not on this page · raw message
tools/libxc/xc_netbsd.c +32 -58
164 lines not on this page · raw message
tools/libxc/xc_private.c +7 -167
223 lines not on this page · raw message
tools/libxc/xc_private.h +13 -6
@@ -30,7 +30,6 @@#include "_paths.h" #include "xenctrl.h" -#include "xenctrlosdep.h" #include <xen/sys/privcmd.h>
@@ -88,7 +87,6 @@ struct iovec {#define MAX_PAGECACHE_USAGE (4*1024)struct xc_interface_core { -enum xc_osdep_type type;int flags;xentoollog_logger *error_handler, *error_handler_tofree;xentoollog_logger *dombuild_logger, *dombuild_logger_tofree;
@@ -117,12 +115,21 @@ struct xc_interface_core {int hypercall_buffer_cache_misses;int hypercall_buffer_cache_toobig; -/* Low lovel OS interface */ -xc_osdep_info_t osdep; -xc_osdep_ops *ops;/* backend operations */ -xc_osdep_handle ops_handle;/* opaque data for xc_osdep_ops */ +/* Privcmd interface */ +int privcmdfd; }; +int osdep_privcmd_open (xc_interface *xch); +int osdep_privcmd_close (xc_interface *xch); + +void *osdep_alloc_hypercall_buffer (xc_interface *xch,int npages); +void osdep_free_hypercall_buffer (xc_interface *xch,void *ptr,int npages); + +/* Stub for not yet converted OSes */ +void *xc_map_foreign_bulk_compat (xc_interface *xch, +uint32_t dom,int prot, +const xen_pfn_t *arr,int *err,unsigned int num); +void xc_report_error (xc_interface *xch,int code,const char *fmt, ...) __attribute__((format (printf,3 ,4 ))); void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
tools/libxc/xc_solaris.c +32 -58
158 lines not on this page · raw message
tools/libxc/xenctrl_osdep_ENOSYS.c deleted +0 -123
123 lines not on this page · raw message
tools/ocaml/libs/xc/xenctrl.ml +0 -2
@@ -108,8 +108,6 @@ external sizeof_xen_pfn: unit -> int = "stub_sizeof_xen_pfn" external interface_open: unit -> handle = "stub_xc_interface_open" external interface_close: handle -> unit = "stub_xc_interface_close" -external is_fake: unit -> bool = "stub_xc_interface_is_fake" - let with_intf f = let xc = interface_open () in let r = try f xc with exn -> interface_close xc; raise exn in
tools/ocaml/libs/xc/xenctrl.mli +0 -1
@@ -72,7 +72,6 @@ external sizeof_vcpu_guest_context : unit -> int = "stub_sizeof_vcpu_guest_context" external sizeof_xen_pfn : unit -> int = "stub_sizeof_xen_pfn" external interface_open : unit -> handle = "stub_xc_interface_open" -external is_fake : unit -> bool = "stub_xc_interface_is_fake" external interface_close : handle -> unit = "stub_xc_interface_close" val with_intf : (handle -> 'a) -> 'a val domain_create : handle -> int32 -> domain_create_flag list -> string -> domid
tools/ocaml/libs/xc/xenctrl_stubs.c +0 -7
@@ -126,13 +126,6 @@ CAMLprim value stub_xc_interface_open(void) } -CAMLprim value stub_xc_interface_is_fake(void) -{ -CAMLparam0 (); -int is_fake =xc_interface_is_fake (); -CAMLreturn (Val_int (is_fake)); -} - CAMLprim value stub_xc_interface_close(value xch) {CAMLparam1 (xch);
tools/ocaml/xenstored/domains.ml +2 -4
@@ -65,11 +65,9 @@ let create xc doms domid mfn port = Domain.bind_interdomain dom; dom -let create0 fake doms = +let create0 doms = let port, interface = - if fake then ( - 0, Xenctrl.with_intf (fun xc -> Xenctrl.map_foreign_range xc 0 (Xenmmap.getpagesize()) 0n) - ) else ( + ( let port = Utils.read_file_single_integer Define.xenstored_proc_port and fd = Unix.openfile Define.xenstored_proc_kva [ Unix.O_RDWR ] 0o600 in
tools/ocaml/xenstored/xenstored.ml +2 -3
@@ -176,7 +176,7 @@ let from_channel store cons doms chan = if domid > 0 then Domains.create xc doms domid mfn port else - Domains.create0 false doms + Domains.create0 doms in Connections.add_domain cons ndom; in
@@ -278,8 +278,7 @@ let _ = Store.mkdir store (Perms.Connection.create 0) localpath; if cf.domain_init then ( - let usingxiu = Xenctrl.is_fake () in - Connections.add_domain cons (Domains.create0 usingxiu domains); + Connections.add_domain cons (Domains.create0 domains); Event.bind_dom_exc_virq eventchn ); );
Signature · 1 line
2.1.4
PATCH v8 7/29 tools: Refactor hypercall calling wrappers into libxencall.
In reply to Ian Campbelllibxencall will provide a stable API and ABI for calling hypercalls (although those hypercalls themselves may not have a stable API). As well as the hypercall buffer infrastructure needed in order to safely provide pointer arguments to hypercalls.
libxenctrl encapsulates a instance of this interface, so users of that library are not currently subjected to any actual changes. However all hypercalls made internally by libxc now use the correct interface. It is expected that most users of this library will be other libraries providing a higher level interface, rather than applications directly.
Only the basic functionality to allocate hypercall safe memory is moved, the type safe stuff and bounce buffers remain in libxc.
Note that the functionality to map foreign pages using privcmd is not yet moved, meaning that an xc_interface will now contain two open privcmd file descriptors. Foreign memory mapping is logically separate functionality and will be moved into its own library.
The new library uses a version script to ensure that only expected symbols are exported and to version them such that ABI guarantees can be kept in the future.
---
Must be applied with:
- "qemu-xen-traditional: Add libxencall to rpath-link" and a corresponding QEMU_TAG update folded here.
- "mini-os: Include libxencall with libxc" and a corresponding bump to MINIOS_UPSTREAM_REVISION folded in here.
v3: Moved to tools/libs/call
Ported new wrappers (altp2m)
v5: Allow _close(NULL).
v6: Use size_t for nr_pages throughout.
Rebase over "libxc: prefer using privcmd character device"
v7: Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of
open coding the recursion.
Remove incorrect/spurious APP_LDLIBS (which anyway was removed by a later patch)
v8: Remove *.so on clean, add distclean target.
--- .gitignore | 2 + stubdom/Makefile | 17 +++- tools/Makefile | 1 + tools/Rules.mk | 7 +- tools/libs/Makefile | 1 + tools/libs/call/Makefile | 71 ++++++++++++++ tools/libs/call/buffer.c | 192 ++++++++++++++++++++++++++++++++++++++ tools/libs/call/core.c | 147 +++++++++++++++++++++++++++++ tools/libs/call/freebsd.c | 140 +++++++++++++++++++++++++++ tools/libs/call/include/xencall.h | 84 +++++++++++++++++ tools/libs/call/libxencall.map | 19 ++++ tools/libs/call/linux.c | 138 +++++++++++++++++++++++++++ tools/libs/call/minios.c | 81 ++++++++++++++++ tools/libs/call/netbsd.c | 121 ++++++++++++++++++++++++ tools/libs/call/private.h | 68 ++++++++++++++ tools/libs/call/solaris.c | 97 +++++++++++++++++++ tools/libxc/Makefile | 7 +- tools/libxc/xc_altp2m.c | 64 ++++--------- tools/libxc/xc_domain.c | 105 +++++++-------------- tools/libxc/xc_evtchn.c | 9 +- tools/libxc/xc_flask.c | 8 +- tools/libxc/xc_freebsd_osdep.c | 47 ---------- tools/libxc/xc_gnttab.c | 9 +- tools/libxc/xc_hcall_buf.c | 138 ++------------------------- tools/libxc/xc_kexec.c | 36 +++---- tools/libxc/xc_linux_osdep.c | 49 ---------- tools/libxc/xc_minios.c | 32 ------- tools/libxc/xc_misc.c | 79 ++++++---------- tools/libxc/xc_netbsd.c | 40 -------- tools/libxc/xc_private.c | 64 +++++-------- tools/libxc/xc_private.h | 76 +++++---------- tools/libxc/xc_solaris.c | 16 ---- tools/libxc/xc_tmem.c | 7 +- tools/misc/Makefile | 4 +- tools/xcutils/Makefile | 2 +- tools/xenpaging/Makefile | 2 +- 36 files changed, 1348 insertions(+), 632 deletions(-) create mode 100644 tools/libs/call/Makefile create mode 100644 tools/libs/call/buffer.c create mode 100644 tools/libs/call/core.c create mode 100644 tools/libs/call/freebsd.c create mode 100644 tools/libs/call/include/xencall.h create mode 100644 tools/libs/call/libxencall.map create mode 100644 tools/libs/call/linux.c create mode 100644 tools/libs/call/minios.c create mode 100644 tools/libs/call/netbsd.c create mode 100644 tools/libs/call/private.h create mode 100644 tools/libs/call/solaris.c
.gitignore +2 -0
@@ -62,6 +62,7 @@ stubdom/ioemu stubdom/ioemu/ stubdom/libs-* stubdom/libxc-* +stubdom/libxencall-* stubdom/libxenevtchn-* stubdom/libxengnttab-* stubdom/libxentoollog-*
@@ -91,6 +92,7 @@ config/Docs.mk tools/libs/toollog/headers.chk tools/libs/evtchn/headers.chk tools/libs/gnttab/headers.chk +tools/libs/call/headers.chk tools/blktap2/daemon/blktapctrl tools/blktap2/drivers/img2qcow tools/blktap2/drivers/lock-util
stubdom/Makefile +16 -1
@@ -331,6 +331,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET) ln -sf $(XEN_ROOT)/tools/libs/gnttab/include/*.h include/ && \ ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.c . && \ ln -sf $(XEN_ROOT)/tools/libs/gnttab/Makefile . ) + mkdir -p libs-$(XEN_TARGET_ARCH)/call/include + [ -h libs-$(XEN_TARGET_ARCH)/call/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/call && \ + ln -sf $(XEN_ROOT)/tools/libs/call/*.h . && \ + ln -sf $(XEN_ROOT)/tools/libs/call/include/*.h include/ && \ + ln -sf $(XEN_ROOT)/tools/libs/call/*.c . && \ + ln -sf $(XEN_ROOT)/tools/libs/call/Makefile . ) mkdir -p libxc-$(XEN_TARGET_ARCH) [ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \ ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -381,12 +387,21 @@ libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: mk-headers-$(XEN_TARGET_ARCH) $(N CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab ####### +# libxencall +####### + +.PHONY: libxencall +libxencall: libs-$(XEN_TARGET_ARCH)/call/libxencall.a +libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) + CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call + +####### # libxc ####### .PHONY: libxc libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a -libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab cross-zlib +libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall cross-zlib CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH) libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
tools/Makefile +1 -0
@@ -263,6 +263,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \ + -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call \ $(QEMU_UPSTREAM_RPATH)" \ --bindir=$(LIBEXEC_BIN) \ --datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +6 -1
@@ -13,6 +13,7 @@ XEN_INCLUDE = $(XEN_ROOT)/tools/include XEN_LIBXENTOOLLOG = $(XEN_ROOT)/tools/libs/toollog XEN_LIBXENEVTCHN = $(XEN_ROOT)/tools/libs/evtchn XEN_LIBXENGNTTAB = $(XEN_ROOT)/tools/libs/gnttab +XEN_LIBXENCALL = $(XEN_ROOT)/tools/libs/call XEN_LIBXC = $(XEN_ROOT)/tools/libxc XEN_XENLIGHT = $(XEN_ROOT)/tools/libxl XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore
@@ -98,8 +99,12 @@ CFLAGS_libxengntshr = -I$(XEN_LIBXENGNTTAB)/include $(CFLAGS_xeninclude) LDLIBS_libxengntshr = $(XEN_LIBXENGNTTAB)/libxengnttab$(libextension) SHLIB_libxengntshr = -Wl,-rpath-link=$(XEN_LIBXENGNTTAB) +CFLAGS_libxencall = -I$(XEN_LIBXENCALL)/include $(CFLAGS_xeninclude) +LDLIBS_libxencall = $(XEN_LIBXENCALL)/libxencall$(libextension) +SHLIB_libxencall = -Wl,-rpath-link=$(XEN_LIBXENCALL) + CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude) -SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) +SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall) LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension) SHLIB_libxenctrl = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
tools/libs/Makefile +1 -0
@@ -5,5 +5,6 @@ SUBDIRS-y := SUBDIRS-y += toollog SUBDIRS-y += evtchn SUBDIRS-y += gnttab +SUBDIRS-y += call all clean install distclean: %: subdirs-%
tools/libs/call/Makefile new file +71 -0
71 lines not on this page · raw message
tools/libs/call/buffer.c new file +192 -0
192 lines not on this page · raw message
tools/libs/call/core.c new file +147 -0
147 lines not on this page · raw message
tools/libs/call/freebsd.c new file +140 -0
140 lines not on this page · raw message
tools/libs/call/include/xencall.h new file +84 -0
84 lines not on this page · raw message
tools/libs/call/libxencall.map new file +19 -0
@@ -0,0 +1,19 @@ +VERS_1.0 { + global: + xencall_open; + xencall_close; + + xencall0; + xencall1; + xencall2; + xencall3; + xencall4; + xencall5; + xencall6; + + xencall_alloc_buffer; + xencall_free_buffer; + xencall_alloc_buffer_pages; + xencall_free_buffer_pages; + local: *; /* Do not expose anything by default */ +};
tools/libs/call/linux.c new file +138 -0
138 lines not on this page · raw message
tools/libs/call/minios.c new file +81 -0
81 lines not on this page · raw message
tools/libs/call/netbsd.c new file +121 -0
121 lines not on this page · raw message
tools/libs/call/private.h new file +68 -0
68 lines not on this page · raw message
tools/libs/call/solaris.c new file +97 -0
97 lines not on this page · raw message
tools/libxc/Makefile +6 -1
@@ -122,6 +122,11 @@ GUEST_PIC_OBJS := $(patsubst %.c,%.opic,$(GUEST_SRCS-y)) $(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \ $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h +# libxenguest includes xc_private.h, so needs this despite not using +# this functionality directly. +$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \ +$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += $(CFLAGS_libxencall) + $(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr) LIB := libxenctrl.a
@@ -202,7 +207,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR) $(SYMLINK_SHLIB) $< $@ libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS) - $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(LDLIBS_libxencall) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) # libxenguest
tools/libxc/xc_altp2m.c +16 -48
203 lines not on this page · raw message
tools/libxc/xc_domain.c +36 -69
296 lines not on this page · raw message
tools/libxc/xc_evtchn.c +3 -6
@@ -25,7 +25,6 @@ static int do_evtchn_op(xc_interface *xch, int cmd, void *arg, size_t arg_size, int silently_fail) {int ret =-1 ; -DECLARE_HYPERCALL ;DECLARE_HYPERCALL_BOUNCE (arg, arg_size,XC_HYPERCALL_BUFFER_BOUNCE_BOTH );if (xc_hypercall_bounce_pre (xch, arg) )
@@ -34,11 +33,9 @@ static int do_evtchn_op(xc_interface *xch, int cmd, void *arg, goto out; } - hypercall.op = __HYPERVISOR_event_channel_op; - hypercall.arg[0 ] = cmd; - hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (arg); - -if ((ret =do_xen_hypercall (xch, &hypercall)) <0 && !silently_fail) + ret =xencall2 (xch->xcall, __HYPERVISOR_event_channel_op, + cmd,HYPERCALL_BUFFER_AS_ARG (arg)); +if ( ret <0 && !silently_fail )ERROR ("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d" , ret);xc_hypercall_bounce_post (xch, arg);
tools/libxc/xc_flask.c +3 -5
@@ -37,7 +37,6 @@int xc_flask_op (xc_interface *xch,xen_flask_op_t *op) {int ret =-1 ; -DECLARE_HYPERCALL ;DECLARE_HYPERCALL_BOUNCE (op,sizeof (*op),XC_HYPERCALL_BUFFER_BOUNCE_BOTH ); op->interface_version =XEN_FLASK_INTERFACE_VERSION ;
@@ -48,10 +47,9 @@ int xc_flask_op(xc_interface *xch, xen_flask_op_t *op) goto out; } - hypercall.op = __HYPERVISOR_xsm_op; - hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (op); - -if ( (ret =do_xen_hypercall (xch, &hypercall)) <0 ) + ret =xencall1 (xch->xcall, __HYPERVISOR_xsm_op, +HYPERCALL_BUFFER_AS_ARG (op)); +if ( ret <0 ) {if ( errno ==EACCES )fprintf (stderr,"XSM operation failed!\n" );
tools/libxc/xc_freebsd_osdep.c +0 -47
53 lines not on this page · raw message
tools/libxc/xc_gnttab.c +2 -7
@@ -21,7 +21,6 @@int xc_gnttab_op (xc_interface *xch,int cmd,void * op,int op_size,int count) {int ret =0 ; -DECLARE_HYPERCALL ;DECLARE_HYPERCALL_BOUNCE (op, count * op_size,XC_HYPERCALL_BUFFER_BOUNCE_BOTH );if (xc_hypercall_bounce_pre (xch, op) )
@@ -30,12 +29,8 @@ int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int count) goto out1; } - hypercall.op = __HYPERVISOR_grant_table_op; - hypercall.arg[0 ] = cmd; - hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (op); - hypercall.arg[2 ] = count; - - ret =do_xen_hypercall (xch, &hypercall); + ret =xencall3 (xch->xcall, __HYPERVISOR_grant_table_op, + cmd,HYPERCALL_BUFFER_AS_ARG (op), count);xc_hypercall_bounce_post (xch, op);
tools/libxc/xc_hcall_buf.c +6 -132
176 lines not on this page · raw message
tools/libxc/xc_kexec.c +12 -24
@@ -14,7 +14,6 @@int xc_kexec_exec (xc_interface *xch,int type) { -DECLARE_HYPERCALL ;DECLARE_HYPERCALL_BUFFER (xen_kexec_exec_t, exec);int ret =-1 ;
@@ -27,11 +26,9 @@ int xc_kexec_exec(xc_interface *xch, int type) exec->type = type; - hypercall.op = __HYPERVISOR_kexec_op; - hypercall.arg[0 ] = KEXEC_CMD_kexec; - hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (exec); - - ret =do_xen_hypercall (xch, &hypercall); + ret =xencall2 (xch->xcall, __HYPERVISOR_kexec_op, + KEXEC_CMD_kexec, +HYPERCALL_BUFFER_AS_ARG (exec)); out:xc_hypercall_buffer_free (xch, exec);
@@ -42,7 +39,6 @@ out:int xc_kexec_get_range (xc_interface *xch,int range,int nr,uint64_t *size,uint64_t *start) { -DECLARE_HYPERCALL ;DECLARE_HYPERCALL_BUFFER (xen_kexec_range_t, get_range);int ret =-1 ;
@@ -56,11 +52,9 @@ int xc_kexec_get_range(xc_interface *xch, int range, int nr, get_range->range = range; get_range->nr = nr; - hypercall.op = __HYPERVISOR_kexec_op; - hypercall.arg[0 ] = KEXEC_CMD_kexec_get_range; - hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (get_range); - - ret =do_xen_hypercall (xch, &hypercall); + ret =xencall2 (xch->xcall, __HYPERVISOR_kexec_op, + KEXEC_CMD_kexec_get_range, +HYPERCALL_BUFFER_AS_ARG (get_range)); *size = get_range->size; *start = get_range->start;
@@ -76,7 +70,6 @@ int xc_kexec_load(xc_interface *xch, uint8_t type, uint16_t arch, uint32_t nr_segments, xen_kexec_segment_t *segments) { int ret = -1; -DECLARE_HYPERCALL ;DECLARE_HYPERCALL_BOUNCE (segments,sizeof (*segments) * nr_segments,XC_HYPERCALL_BUFFER_BOUNCE_IN );DECLARE_HYPERCALL_BUFFER (xen_kexec_load_t, load);
@@ -99,11 +92,9 @@ int xc_kexec_load(xc_interface *xch, uint8_t type, uint16_t arch, load->nr_segments = nr_segments;set_xen_guest_handle (load->segments.h, segments); - hypercall.op = __HYPERVISOR_kexec_op; - hypercall.arg[0 ] = KEXEC_CMD_kexec_load; - hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (load); - - ret =do_xen_hypercall (xch, &hypercall); + ret =xencall2 (xch->xcall, __HYPERVISOR_kexec_op, + KEXEC_CMD_kexec_load, +HYPERCALL_BUFFER_AS_ARG (load)); out:xc_hypercall_buffer_free (xch, load);
@@ -114,7 +105,6 @@ out:int xc_kexec_unload (xc_interface *xch,int type) { -DECLARE_HYPERCALL ;DECLARE_HYPERCALL_BUFFER (xen_kexec_unload_t, unload);int ret =-1 ;
@@ -127,11 +117,9 @@ int xc_kexec_unload(xc_interface *xch, int type) unload->type = type; - hypercall.op = __HYPERVISOR_kexec_op; - hypercall.arg[0 ] = KEXEC_CMD_kexec_unload; - hypercall.arg[1 ] =HYPERCALL_BUFFER_AS_ARG (unload); - - ret =do_xen_hypercall (xch, &hypercall); + ret =xencall2 (xch->xcall, __HYPERVISOR_kexec_op, + KEXEC_CMD_kexec_unload, +HYPERCALL_BUFFER_AS_ARG (unload)); out:xc_hypercall_buffer_free (xch, unload);
tools/libxc/xc_linux_osdep.c +0 -49
55 lines not on this page · raw message
tools/libxc/xc_minios.c +0 -32
@@ -61,38 +61,6 @@ void minios_interface_close_fd(int fd) files[fd].type =FTYPE_NONE ; } -void *osdep_alloc_hypercall_buffer (xc_interface *xch,int npages) -{ -return xc_memalign (xch,PAGE_SIZE , npages *PAGE_SIZE ); -} - -void osdep_free_hypercall_buffer (xc_interface *xch,void *ptr,int npages) -{ -free (ptr); -} - -int do_xen_hypercall (xc_interface *xch,privcmd_hypercall_t *hypercall) -{ -multicall_entry_t call; -int i, ret; - - call.op = hypercall->op; -for (i =0 ; i <ARRAY_SIZE (hypercall->arg); i++) - call.args[i] = hypercall->arg[i]; - - ret =HYPERVISOR_multicall (&call,1 ); - -if (ret <0 ) { - errno = -ret; -return -1 ; - } -if ((long ) call.result <0 ) { - errno = - (long ) call.result; -return -1 ; - } -return call.result; -} -void *xc_map_foreign_bulk (xc_interface *xch,uint32_t dom,int prot,const xen_pfn_t *arr,int *err,unsigned int num)
tools/libxc/xc_misc.c +27 -52
214 lines not on this page · raw message
tools/libxc/xc_netbsd.c +0 -40
@@ -67,46 +67,6 @@ int osdep_privcmd_close(xc_interface *xch)return close (fd); } -void *osdep_alloc_hypercall_buffer (xc_interface *xch,int npages) -{ -size_t size = npages *XC_PAGE_SIZE ; -void *p; - - p =xc_memalign (xch,XC_PAGE_SIZE , size); -if (!p) -return NULL ; - -if (mlock (p, size) <0 ) - { -free (p); -return NULL ; - } -return p; -} - -void osdep_free_hypercall_buffer (xc_interface *xch,void *ptr,int npages) -{ - (void )munlock (ptr, npages *XC_PAGE_SIZE ); -free (ptr); -} - -int do_xen_hypercall (xc_interface *xch,privcmd_hypercall_t *hypercall) -{ -int fd = xch->privcmdfd; -int error =ioctl (fd,IOCTL_PRIVCMD_HYPERCALL , hypercall); - -/* -* Since NetBSD ioctl can only return 0 on success or < 0 on -* error, if we want to return a value from ioctl we should -* do so by setting hypercall->retval, to mimic Linux ioctl -* implementation. -*/ -if (error <0 ) -return error; -else -return hypercall->retval; -} -void *xc_map_foreign_bulk (xc_interface *xch,uint32_t dom,int prot,const xen_pfn_t *arr,int *err,unsigned int num)
tools/libxc/xc_private.c +25 -39
125 lines not on this page · raw message
tools/libxc/xc_private.h +21 -55
160 lines not on this page · raw message
tools/libxc/xc_solaris.c +0 -16
@@ -67,22 +67,6 @@ int osdep_privcmd_close(xc_interface *xch)return close (fd); } -void *osdep_alloc_hypercall_buffer (xc_interface *xch,int npages) -{ -return xc_memalign (xch,XC_PAGE_SIZE , npages *XC_PAGE_SIZE ); -} - -static void osdep_free_hypercall_buffer (xc_interface *xch,void *ptr,int npages) -{ -free (ptr); -} - -int do_xen_hypercall (xc_interface *xch,privcmd_hypercall_t *hypercall) -{ -int fd = xch->privcmdfd; -return ioctl (fd,IOCTL_PRIVCMD_HYPERCALL , hypercall); -} -void *xc_map_foreign_batch (xc_interface *xch,uint32_t dom,int prot,xen_pfn_t *arr,int num)
tools/libxc/xc_tmem.c +3 -4
@@ -23,7 +23,6 @@static int do_tmem_op (xc_interface *xch,tmem_op_t *op) {int ret; -DECLARE_HYPERCALL ;DECLARE_HYPERCALL_BOUNCE (op,sizeof (*op),XC_HYPERCALL_BUFFER_BOUNCE_BOTH );if (xc_hypercall_bounce_pre (xch, op) )
@@ -32,9 +31,9 @@ static int do_tmem_op(xc_interface *xch, tmem_op_t *op)return -EFAULT ; } - hypercall.op = __HYPERVISOR_tmem_op; - hypercall.arg[0 ] =HYPERCALL_BUFFER_AS_ARG (op); -if ((ret =do_xen_hypercall (xch, &hypercall)) <0 ) + ret =xencall1 (xch->xcall, __HYPERVISOR_tmem_op, +HYPERCALL_BUFFER_AS_ARG (op)); +if ( ret <0 ) {if ( errno ==EACCES ) DPRINTF("tmem operation failed -- need to"
tools/misc/Makefile +2 -2
@@ -87,12 +87,12 @@ xenlockprof: xenlockprof.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) # xen-hptool incorrectly uses libxc internals -xen-hptool.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc +xen-hptool.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall) xen-hptool: xen-hptool.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(APPEND_LDFLAGS) # xen-mfndump incorrectly uses libxc internals -xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc +xen-mfndump.o: CFLAGS += -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall) xen-mfndump: xen-mfndump.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
tools/xcutils/Makefile +1 -1
@@ -16,7 +16,7 @@ PROGRAMS = readnotes lsevtchn CFLAGS += -Werror # incorrectly uses libxc internals -CFLAGS_readnotes.o := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) -I$(XEN_ROOT)/tools/libxc +CFLAGS_readnotes.o := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall) CFLAGS_lsevtchn.o := $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) .PHONY: all
tools/xenpaging/Makefile +1 -1
@@ -2,7 +2,7 @@ XEN_ROOT=$(CURDIR)/../.. include $(XEN_ROOT)/tools/Rules.mk # xenpaging.c and file_ops.c incorrectly use libxc internals -CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(PTHREAD_CFLAGS) -I$(XEN_ROOT)/tools/libxc +CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(PTHREAD_CFLAGS) -I$(XEN_ROOT)/tools/libxc $(CFLAGS_libxencall) LDLIBS += $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(PTHREAD_LIBS) LDFLAGS += $(PTHREAD_LDFLAGS)
Signature · 1 line
2.1.4
PATCH v8 8/29 tools/libxc: drop xc_map_foreign_bulk_compat wrappers
In reply to Ian CampbellOn Solaris and NetBSD xc_map_foreign_bulk is implemented by calling xc_map_foreign_bulk_compat and xc_map_foreign_bulk_compat is exposed as a symbol by libxenctrl.so.
Remove these wrappers and turn the compat function into the real thing surrounded by the appropriate ifdef.
As this is a compat function all new ports should instead implement xc_map_foreign_bulk properly, hence the ifdef should never be expanded.
--- tools/libxc/xc_foreign_memory.c | 13 +++++++++---- tools/libxc/xc_netbsd.c | 7 ------- tools/libxc/xc_private.h | 5 ----- tools/libxc/xc_solaris.c | 7 ------- 4 files changed, 9 insertions(+), 23 deletions(-)
tools/libxc/xc_foreign_memory.c +9 -4
@@ -50,10 +50,14 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,return res; } -/* stub for all not yet converted OSes */ -void *xc_map_foreign_bulk_compat (xc_interface *xch, -uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num) +/* +* stub for all not yet converted OSes (NetBSD and Solaris). New OSes should +* just implement xc_map_foreign_bulk. +*/ +#if defined(__NetBSD__) || defined(__sun__) +void *xc_map_foreign_bulk (xc_interface *xch, +uint32_t dom,int prot, +const xen_pfn_t *arr,int *err,unsigned int num) {xen_pfn_t *pfn;unsigned int i;
@@ -90,6 +94,7 @@ void *xc_map_foreign_bulk_compat(xc_interface *xch, return ret; } +#endif /* * Local variables:
tools/libxc/xc_netbsd.c +0 -7
@@ -67,13 +67,6 @@ int osdep_privcmd_close(xc_interface *xch)return close (fd); } -void *xc_map_foreign_bulk (xc_interface *xch, -uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num) -{ -return xc_map_foreign_bulk_compat (xch, dom, prot, arr, err, num); -} -void *xc_map_foreign_batch (xc_interface *xch,uint32_t dom,int prot,xen_pfn_t *arr,int num)
tools/libxc/xc_private.h +0 -5
@@ -107,11 +107,6 @@ int osdep_privcmd_close(xc_interface *xch);void *osdep_alloc_hypercall_buffer (xc_interface *xch,int npages);void osdep_free_hypercall_buffer (xc_interface *xch,void *ptr,int npages); -/* Stub for not yet converted OSes */ -void *xc_map_foreign_bulk_compat (xc_interface *xch, -uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num); -void xc_report_error (xc_interface *xch,int code,const char *fmt, ...) __attribute__((format (printf,3 ,4 ))); void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
tools/libxc/xc_solaris.c +0 -7
@@ -94,13 +94,6 @@ void *xc_map_foreign_batch(xc_interface *xch, } -void *xc_map_foreign_bulk (xc_interface *xch, -uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num) -{ -return xc_map_foreign_bulk_compat (xch, dom, prot, arr, err, num); -} - void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, int size, int prot,
Signature · 1 line
2.1.4
PATCH v8 9/29 tools: Remove xc_map_foreign_batch
In reply to Ian CampbellIt can trivially be replaced by xc_map_foreign_pages which is the interface I want to move to going forward (by standardising on _bulk but handling err=NULL as _pages does).
The callers of _batch are checking a mixture of a NULL return or looking to see if the top nibble of the (usually sole) mfn they pass has been modified to be non-zero to detect errors. _pages never modifies the mfn it was given (it's const) and returns NULL on failure, so adjust the error handling where necessary. Some callers use a copy of the mfn array, for reuse on failure with _batch, which is no longer necessary as _pages doesn't modify the array, however I haven't cleaned that up here.
This reduces the twist maze of xc_map_foreign_* by one, which will be useful when trying to come up with an underlying stable interface.
NetBSD and Solaris implemented xc_map_foreign_bulk in terms of xc_map_foreign_batch via a compat layer, so xc_map_foreign_batch becomes an internal osdep for them.
---
v7: Don't mention new ports implementing _bulk, which is confusing and
will be obsolete a couple of patches later.
v6: Switch to xc_map_foreign_pages not xc_map_foreign_bulk, since the
former has more similar error handling semantics to the current usage.
Dropped acks.
--- tools/libxc/include/xenctrl.h | 10 ------- tools/libxc/xc_foreign_memory.c | 4 ++- tools/libxc/xc_linux_osdep.c | 59 +++-------------------------------------- tools/libxc/xc_minios.c | 22 --------------- tools/libxc/xc_netbsd.c | 10 +++---- tools/libxc/xc_solaris.c | 6 ++--- tools/libxc/xc_vm_event.c | 18 ++++++++++--- tools/xenmon/xenbaked.c | 12 ++++++++- tools/xenpaging/xenpaging.c | 14 +++++----- tools/xentrace/xentrace.c | 3 ++- 10 files changed, 48 insertions(+), 110 deletions(-)
tools/libxc/include/xenctrl.h +0 -10
@@ -1387,16 +1387,6 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot, const xen_pfn_t *arr, int num );/** -* DEPRECATED - use xc_map_foreign_bulk() instead. -* -* Like xc_map_foreign_pages(), except it can succeeed partially. -* When a page cannot be mapped, its PFN in @arr is or'ed with -* 0xF0000000 to indicate the error. -*/ -void *xc_map_foreign_batch (xc_interface *xch,uint32_t dom,int prot, -xen_pfn_t *arr,int num ); - -/** * Like xc_map_foreign_pages(), except it can succeed partially. * When a page cannot be mapped, its respective field in @err is * set to the corresponding errno value.
tools/libxc/xc_foreign_memory.c +3 -1
@@ -55,6 +55,8 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,* just implement xc_map_foreign_bulk. */ #if defined(__NetBSD__) || defined(__sun__) +void *osdep_map_foreign_batch (xc_interface *xch,uint32_t dom,int prot, +xen_pfn_t *arr,int num );void *xc_map_foreign_bulk (xc_interface *xch,uint32_t dom,int prot,const xen_pfn_t *arr,int *err,unsigned int num)
@@ -75,7 +77,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, }memcpy (pfn, arr, num *sizeof (*arr)); - ret =xc_map_foreign_batch (xch, dom, prot, pfn, num); + ret =osdep_map_foreign_batch (xch, dom, prot, pfn, num);if (ret) {for (i =0 ; i < num; ++i)
tools/libxc/xc_linux_osdep.c +3 -56
77 lines not on this page · raw message
tools/libxc/xc_minios.c +0 -22
@@ -73,28 +73,6 @@ void *xc_map_foreign_bulk(xc_interface *xch,return map_frames_ex (arr, num,1 ,0 ,1 , dom, err, pt_prot); } -void *xc_map_foreign_batch (xc_interface *xch, -uint32_t dom,int prot, -xen_pfn_t *arr,int num) -{ -unsigned long pt_prot =0 ; -int err[num]; -int i; -unsigned long addr; - -if (prot &PROT_READ ) - pt_prot =L1_PROT_RO ; -if (prot &PROT_WRITE ) - pt_prot =L1_PROT ; - - addr = (unsigned long )map_frames_ex (arr, num,1 ,0 ,1 , dom, err, pt_prot); -for (i =0 ; i < num; i++) { -if (err[i]) - arr[i] |=0xF0000000 ; - } -return (void *) addr; -} - void *xc_map_foreign_range(xc_interface *xch, uint32_t dom, int size, int prot,
tools/libxc/xc_netbsd.c +5 -5
@@ -67,16 +67,16 @@ int osdep_privcmd_close(xc_interface *xch)return close (fd); } -void *xc_map_foreign_batch (xc_interface *xch, -uint32_t dom,int prot, -xen_pfn_t *arr,int num) +void *osdep_map_foreign_batch (xc_interface *xch, +uint32_t dom,int prot, +xen_pfn_t *arr,int num) {int fd = xch->privcmdfd;privcmd_mmapbatch_t ioctlx;void *addr; addr =mmap (NULL , num*XC_PAGE_SIZE , prot,MAP_ANON |MAP_SHARED ,-1 ,0 );if ( addr ==MAP_FAILED ) { -PERROR ("xc_map_foreign_batch: mmap failed" ); +PERROR ("osdep_map_foreign_batch: mmap failed" );return NULL ; }
@@ -87,7 +87,7 @@ void *xc_map_foreign_batch(xc_interface *xch,if (ioctl (fd,IOCTL_PRIVCMD_MMAPBATCH , &ioctlx) <0 ) {int saved_errno = errno; -PERROR ("xc_map_foreign_batch: ioctl failed" ); +PERROR ("osdep_map_foreign_batch: ioctl failed" ); (void )munmap (addr, num*XC_PAGE_SIZE ); errno = saved_errno;return NULL ;
tools/libxc/xc_solaris.c +3 -3
@@ -67,9 +67,9 @@ int osdep_privcmd_close(xc_interface *xch)return close (fd); } -void *xc_map_foreign_batch (xc_interface *xch, -uint32_t dom,int prot, -xen_pfn_t *arr,int num) +void *osdep_map_foreign_batch (xc_interface *xch, +uint32_t dom,int prot, +xen_pfn_t *arr,int num) {int fd = xch->privcmdfd;privcmd_mmapbatch_t ioctlx;
tools/libxc/xc_vm_event.c +14 -4
@@ -72,9 +72,9 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param, ring_pfn = pfn; mmap_pfn = pfn; - ring_page =xc_map_foreign_batch (xch, domain_id,PROT_READ |PROT_WRITE , + ring_page =xc_map_foreign_pages (xch, domain_id,PROT_READ |PROT_WRITE , &mmap_pfn,1 ); -if ( mmap_pfn &XEN_DOMCTL_PFINFO_XTAB ) +if ( !ring_page ) {/* Map failed, populate ring page */ rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0,
@@ -86,9 +86,9 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param, } mmap_pfn = ring_pfn; - ring_page =xc_map_foreign_batch (xch, domain_id,PROT_READ |PROT_WRITE , + ring_page =xc_map_foreign_pages (xch, domain_id,PROT_READ |PROT_WRITE , &mmap_pfn,1 ); -if ( mmap_pfn &XEN_DOMCTL_PFINFO_XTAB ) +if ( !ring_page ) {PERROR ("Could not map the ring page\n" ); goto out;
@@ -156,3 +156,13 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,return ring_page; } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/xenmon/xenbaked.c +11 -1
@@ -411,7 +411,7 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,for ( j=0 ; j<tbufs.t_info->tbuf_size; j++) pfn_list[j] = (xen_pfn_t )mfn_list[j]; - tbufs.meta[i] =xc_map_foreign_batch (xc_handle,DOMID_XEN , + tbufs.meta[i] =xc_map_foreign_pages (xc_handle,DOMID_XEN ,PROT_READ |PROT_WRITE , pfn_list, tbufs.t_info->tbuf_size);
@@ -1175,3 +1175,13 @@ static int process_record(int cpu, struct t_rec *r)return 4 + (r->cycles_included ?8 :0 ) + (r->extra_u32 *4 ); } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/xenpaging/xenpaging.c +7 -7
@@ -342,9 +342,9 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[]) HVM_PARAM_PAGING_RING_PFN, &ring_pfn); mmap_pfn = ring_pfn; paging->vm_event.ring_page = -xc_map_foreign_batch (xch, paging->vm_event.domain_id, -PROT_READ |PROT_WRITE , &mmap_pfn,1 ); -if ( mmap_pfn &XEN_DOMCTL_PFINFO_XTAB ) +xc_map_foreign_pages (xch, paging->vm_event.domain_id, +PROT_READ |PROT_WRITE , &mmap_pfn,1 ); +if ( !paging->vm_event.ring_page ) {/* Map failed, populate ring page */ rc = xc_domain_populate_physmap_exact(paging->xc_handle,
@@ -356,11 +356,11 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[]) goto err; } - mmap_pfn = ring_pfn; paging->vm_event.ring_page = -xc_map_foreign_batch (xch, paging->vm_event.domain_id, -PROT_READ |PROT_WRITE , &mmap_pfn,1 ); -if ( mmap_pfn &XEN_DOMCTL_PFINFO_XTAB ) +xc_map_foreign_pages (xch, paging->vm_event.domain_id, +PROT_READ |PROT_WRITE , + &mmap_pfn,1 ); +if ( !paging->vm_event.ring_page ) {PERROR ("Could not map the ring page\n" ); goto err;
tools/xentrace/xentrace.c +2 -1
@@ -508,7 +508,7 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,for ( j=0 ; j<tbufs.t_info->tbuf_size; j++) pfn_list[j] = (xen_pfn_t )mfn_list[j]; - tbufs.meta[i] =xc_map_foreign_batch (xc_handle,DOMID_XEN , + tbufs.meta[i] =xc_map_foreign_pages (xc_handle,DOMID_XEN ,PROT_READ |PROT_WRITE , pfn_list, tbufs.t_info->tbuf_size);
@@ -1221,6 +1221,7 @@ int main(int argc, char **argv)return ret; } +/* * Local variables: * mode: C
Signature · 1 line
2.1.4
PATCH v8 10/29 tools: Implement xc_map_foreign_range(s) in terms of common helper
In reply to Ian CampbellBoth Linux and FreeBSD already implemented these functions using identical helpers based on xc_map_foreign_pages. Make one copy of these common helpers and switch all OSes to use them, even those which previously had a specific lower level implementation of this functionality.
This is makes two fewer low level interfaces to think about.
--- tools/libxc/xc_foreign_memory.c | 50 +++++++++++++++++++++++++++++ tools/libxc/xc_freebsd_osdep.c | 50 ----------------------------- tools/libxc/xc_linux_osdep.c | 49 ----------------------------- tools/libxc/xc_minios.c | 43 ------------------------- tools/libxc/xc_netbsd.c | 70 ----------------------------------------- tools/libxc/xc_solaris.c | 67 --------------------------------------- 6 files changed, 50 insertions(+), 279 deletions(-)
tools/libxc/xc_foreign_memory.c +50 -0
@@ -50,6 +50,56 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,return res; } +void *xc_map_foreign_range (xc_interface *xch, +uint32_t dom,int size,int prot, +unsigned long mfn) +{ +xen_pfn_t *arr; +int num; +int i; +void *ret; + + num = (size +XC_PAGE_SIZE -1 ) >>XC_PAGE_SHIFT ; + arr =calloc (num,sizeof (xen_pfn_t)); +if ( arr ==NULL ) +return NULL ; + +for ( i =0 ; i < num; i++ ) + arr[i] = mfn + i; + + ret =xc_map_foreign_pages (xch, dom, prot, arr, num); +free (arr); +return ret; +} + +void *xc_map_foreign_ranges (xc_interface *xch, +uint32_t dom,size_t size, +int prot,size_t chunksize, +privcmd_mmap_entry_t entries[], +int nentries) +{ +xen_pfn_t *arr; +int num_per_entry; +int num; +int i; +int j; +void *ret; + + num_per_entry = chunksize >>XC_PAGE_SHIFT ; + num = num_per_entry * nentries; + arr =calloc (num,sizeof (xen_pfn_t)); +if ( arr ==NULL ) +return NULL ; + +for ( i =0 ; i < nentries; i++ ) +for ( j =0 ; j < num_per_entry; j++ ) + arr[i * num_per_entry + j] = entries[i].mfn + j; + + ret =xc_map_foreign_pages (xch, dom, prot, arr, num); +free (arr); +return ret; +} +/* * stub for all not yet converted OSes (NetBSD and Solaris). New OSes should * just implement xc_map_foreign_bulk.
tools/libxc/xc_freebsd_osdep.c +0 -50
56 lines not on this page · raw message
tools/libxc/xc_linux_osdep.c +0 -49
55 lines not on this page · raw message
tools/libxc/xc_minios.c +0 -43
49 lines not on this page · raw message
tools/libxc/xc_netbsd.c +0 -70
76 lines not on this page · raw message
tools/libxc/xc_solaris.c +0 -67
73 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v8 11/29 tools: Refactor foreign memory mapping into libxenforeignmemory
In reply to Ian Campbelllibxenforeignmemory will provide a stable API and ABI for mapping foreign domain memory (subject to appropriate privileges).
The new library exposes an interface equivalent to xc_map_foreign_memory_bulk, which all the other xc_map_foreign_memory_* functions (which remain in libxc) are implemented in terms of.
Upon request (via #define XC_WANT_COMPAT_MAP_FOREIGN_API) libxenctrl will provide a compat API for the old names. This is used by qemu-xen and qemu-trad as well as various in tree things (which required de-dupping various #includes in some too to get the #define before the first).
---
Must be applied with:
- "qemu-xen-traditional: qemu-xen-traditional: Add libxenforeignmemory to rpath-link" and a corresponding QEMU_TAG update folded here.
- "mini-os: mini-os: Include libxenforeignmemory with libxc" and a corresponding bump to MINIOS_UPSTREAM_REVISION folded in here.
v5: Allow close(NULL)
v6: Define XC_WANT_COMPAT_MAP_FOREIGN_API for xen-mceinj.c and memshrtool.c
Fix typo in type name in compat.c, and get the functions names to match.
Use an osdep layer for _map, to allow for future common code.
v7: Correct comment in compat.h #error due to switch to osdep layer
for map in v6
Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of open coding the recursion.
v8: Remove *.so on clean, add distclean target.
---
.gitignore | 2 +
stubdom/Makefile | 17 +++-
tools/Makefile | 2 +
tools/Rules.mk | 11 ++-
tools/console/daemon/utils.c | 1 -
tools/console/daemon/utils.h | 1 +
tools/libs/Makefile | 1 +
tools/libs/foreignmemory/Makefile | 71 ++++++++++++++
tools/libs/foreignmemory/compat.c | 72 ++++++++++++++
tools/libs/foreignmemory/core.c | 84 +++++++++++++++++
.../foreignmemory/freebsd.c} | 33 +++----
.../libs/foreignmemory/include/xenforeignmemory.h | 71 ++++++++++++++
tools/libs/foreignmemory/libxenforeignmemory.map | 7 ++
.../foreignmemory/linux.c} | 70 ++++++--------
tools/libs/foreignmemory/minios.c | 62 ++++++++++++
tools/libs/foreignmemory/netbsd.c | 105 +++++++++++++++++++++
tools/libs/foreignmemory/private.h | 53 +++++++++++
tools/libs/foreignmemory/solaris.c | 93 ++++++++++++++++++
tools/libxc/Makefile | 8 +-
tools/libxc/include/xenctrl.h | 26 -----
tools/libxc/include/xenctrl_compat.h | 36 +++++++
tools/libxc/xc_foreign_memory.c | 49 +---------
tools/libxc/xc_minios.c | 29 ------
tools/libxc/xc_netbsd.c | 73 --------------
tools/libxc/xc_private.c | 13 +--
tools/libxc/xc_private.h | 11 ++-
tools/libxc/xc_solaris.c | 73 --------------
tools/libxc/xc_sr_restore.c | 4 +-
tools/libxc/xc_sr_save.c | 4 +-
tools/libxc/xg_private.h | 3 +-
tools/libxl/libxl_internal.h | 1 +
tools/misc/xen-mfndump.c | 1 +
tools/ocaml/libs/xc/xenctrl_stubs.c | 1 +
tools/python/xen/lowlevel/xc/xc.c | 2 +
tools/tests/mce-test/tools/xen-mceinj.c | 1 +
tools/tests/mem-sharing/memshrtool.c | 1 +
tools/xenmon/xenbaked.c | 1 +
tools/xenpaging/pagein.c | 1 -
tools/xenpaging/xenpaging.c | 1 -
tools/xenpaging/xenpaging.h | 2 +
tools/xenstore/xenstored_core.c | 1 -
tools/xenstore/xenstored_core.h | 1 +
tools/xentrace/xenctx.c | 3 +-
tools/xentrace/xentrace.c | 1 +
44 files changed, 770 insertions(+), 333 deletions(-)
create mode 100644 tools/libs/foreignmemory/Makefile
create mode 100644 tools/libs/foreignmemory/compat.c
create mode 100644 tools/libs/foreignmemory/core.c
rename tools/{libxc/xc_freebsd_osdep.c => libs/foreignmemory/freebsd.c} (76%)
create mode 100644 tools/libs/foreignmemory/include/xenforeignmemory.h
create mode 100644 tools/libs/foreignmemory/libxenforeignmemory.map
rename tools/{libxc/xc_linux_osdep.c => libs/foreignmemory/linux.c} (83%)
create mode 100644 tools/libs/foreignmemory/minios.c
create mode 100644 tools/libs/foreignmemory/netbsd.c
create mode 100644 tools/libs/foreignmemory/private.h
create mode 100644 tools/libs/foreignmemory/solaris.c.gitignore +2 -0
@@ -64,6 +64,7 @@ stubdom/libs-* stubdom/libxc-* stubdom/libxencall-* stubdom/libxenevtchn-* +stubdom/libxenforeignmemory-* stubdom/libxengnttab-* stubdom/libxentoollog-* stubdom/lwip-*
@@ -93,6 +94,7 @@ tools/libs/toollog/headers.chk tools/libs/evtchn/headers.chk tools/libs/gnttab/headers.chk tools/libs/call/headers.chk +tools/libs/foreignmemory/headers.chk tools/blktap2/daemon/blktapctrl tools/blktap2/drivers/img2qcow tools/blktap2/drivers/lock-util
stubdom/Makefile +16 -1
@@ -337,6 +337,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET) ln -sf $(XEN_ROOT)/tools/libs/call/include/*.h include/ && \ ln -sf $(XEN_ROOT)/tools/libs/call/*.c . && \ ln -sf $(XEN_ROOT)/tools/libs/call/Makefile . ) + mkdir -p libs-$(XEN_TARGET_ARCH)/foreignmemory/include + [ -h libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/foreignmemory && \ + ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.h . && \ + ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/include/*.h include/ && \ + ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.c . && \ + ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/Makefile . ) mkdir -p libxc-$(XEN_TARGET_ARCH) [ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \ ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -396,12 +402,21 @@ libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLI CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call ####### +# libxenforeignmemory +####### + +.PHONY: libxenforeignmemory +libxenforeignmemory: libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a +libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) + CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory + +####### # libxc ####### .PHONY: libxc libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a -libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall cross-zlib +libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory cross-zlib CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH) libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
tools/Makefile +2 -0
@@ -250,6 +250,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find --source-path=$$source \ --extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \ -DXC_WANT_COMPAT_GNTTAB_API=1 \ + -DXC_WANT_COMPAT_MAP_FOREIGN_API=1 \ -I$(XEN_ROOT)/tools/include \ -I$(XEN_ROOT)/tools/libs/toollog/include \ -I$(XEN_ROOT)/tools/libs/evtchn/include \
@@ -264,6 +265,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call \ + -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/foreignmemory \ $(QEMU_UPSTREAM_RPATH)" \ --bindir=$(LIBEXEC_BIN) \ --datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +8 -3
@@ -14,6 +14,7 @@ XEN_LIBXENTOOLLOG = $(XEN_ROOT)/tools/libs/toollog XEN_LIBXENEVTCHN = $(XEN_ROOT)/tools/libs/evtchn XEN_LIBXENGNTTAB = $(XEN_ROOT)/tools/libs/gnttab XEN_LIBXENCALL = $(XEN_ROOT)/tools/libs/call +XEN_LIBXENFOREIGNMEMORY = $(XEN_ROOT)/tools/libs/foreignmemory XEN_LIBXC = $(XEN_ROOT)/tools/libxc XEN_XENLIGHT = $(XEN_ROOT)/tools/libxl XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore
@@ -103,12 +104,16 @@ CFLAGS_libxencall = -I$(XEN_LIBXENCALL)/include $(CFLAGS_xeninclude) LDLIBS_libxencall = $(XEN_LIBXENCALL)/libxencall$(libextension) SHLIB_libxencall = -Wl,-rpath-link=$(XEN_LIBXENCALL) -CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude) -SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall) +CFLAGS_libxenforeignmemory = -I$(XEN_LIBXENFOREIGNMEMORY)/include $(CFLAGS_xeninclude) +LDLIBS_libxenforeignmemory = $(XEN_LIBXENFOREIGNMEMORY)/libxenforeignmemory$(libextension) +SHLIB_libxenforeignmemory = -Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY) + +CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude) +SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall) $(SHLIB_libxenforeignmemory) LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension) SHLIB_libxenctrl = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC) -CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_xeninclude) +CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude) SHDEPS_libxenguest = $(SHLIB_libxenevtchn) LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_LIBXC)/libxenguest$(libextension) SHLIB_libxenguest = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC)
tools/console/daemon/utils.c +0 -1
@@ -33,7 +33,6 @@#include <string.h> #include <signal.h> -#include "xenctrl.h" #include "utils.h" struct xs_handle *xs;
tools/console/daemon/utils.h +1 -0
@@ -23,6 +23,7 @@#include <stdbool.h> #include <syslog.h> #include <stdio.h> +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h> #include <xenstore.h>
tools/libs/Makefile +1 -0
@@ -6,5 +6,6 @@ SUBDIRS-y += toollog SUBDIRS-y += evtchn SUBDIRS-y += gnttab SUBDIRS-y += call +SUBDIRS-y += foreignmemory all clean install distclean: %: subdirs-%
tools/libs/foreignmemory/Makefile new file +71 -0
71 lines not on this page · raw message
tools/libs/foreignmemory/compat.c new file +72 -0
72 lines not on this page · raw message
tools/libs/foreignmemory/core.c new file +84 -0
84 lines not on this page · raw message
tools/libs/foreignmemory/freebsd.c renamed from tools/libxc/xc_freebsd_osdep.c +13 -20
@@ -3,9 +3,6 @@* Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * -* xc_gnttab functions: -* Copyright (c) 2007-2008, D G Murray <[email protected]> -* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation;
@@ -30,14 +27,11 @@#include <sys/mman.h> #include <sys/ioctl.h> -#include <xen/memory.h> - -#include "xc_private.h" +#include "private.h" #define PRIVCMD_DEV "/dev/xen/privcmd" -/*------------------------- Privcmd device interface -------------------------*/ -int osdep_privcmd_open (xc_interface *xch) +int osdep_xenforeignmemory_open (xenforeignmemory_handle *fmem) {int flags, saved_errno;int fd =open (PRIVCMD_DEV ,O_RDWR );
@@ -46,7 +40,7 @@ int osdep_privcmd_open(xc_interface *xch) {PERROR ("Could not obtain handle on privileged command interface " PRIVCMD_DEV ); - return -1 +return -1 ; }/*
@@ -69,7 +63,7 @@ int osdep_privcmd_open(xc_interface *xch) goto error; } - xch->privcmdfd = fd; + fmem->fd = fd;return 0 ; error:
@@ -80,26 +74,25 @@ int osdep_privcmd_open(xc_interface *xch)return -1 ; } -int osdep_privcmd_close (xc_interface *xch) +int osdep_xenforeignmemory_close (xenforeignmemory_handle *fmem) { -int fd = xch->privcmdfd; +int fd = fmem->fd;if ( fd ==-1 )return 0 ;return close (fd); } -/*----------------------- Privcmd foreign map interface ----------------------*/ -void *xc_map_foreign_bulk (xc_interface *xch, -uint32_t dom,int prot, -const xen_pfn_t *arr,int *err, -unsigned int num) +void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem, +uint32_t dom,int prot, +const xen_pfn_t *arr,int *err, +unsigned int num) { -int fd = xch->privcmdfd; +int fd = fmem->fd;privcmd_mmapbatch_t ioctlx;void *addr;int rc; - addr =mmap (NULL , num <<XC_PAGE_SHIFT , prot,MAP_SHARED , fd,0 ); + addr =mmap (NULL , num <<PAGE_SHIFT , prot,MAP_SHARED , fd,0 );if ( addr ==MAP_FAILED ) {PERROR ("xc_map_foreign_bulk: mmap failed" );
@@ -117,7 +110,7 @@ void *xc_map_foreign_bulk(xc_interface *xch, {int saved_errno = errno;PERROR ("xc_map_foreign_bulk: ioctl failed" ); - (void )munmap (addr, num <<XC_PAGE_SHIFT ); + (void )munmap (addr, num <<PAGE_SHIFT ); errno = saved_errno;return NULL ; }
tools/libs/foreignmemory/include/xenforeignmemory.h new file +71 -0
71 lines not on this page · raw message
tools/libs/foreignmemory/libxenforeignmemory.map new file +7 -0
@@ -0,0 +1,7 @@ +VERS_1.0 { + global: + xenforeignmemory_open; + xenforeignmemory_close; + xenforeignmemory_map; + local: *; /* Do not expose anything by default */ +};
tools/libs/foreignmemory/linux.c renamed from tools/libxc/xc_linux_osdep.c +31 -39
175 lines not on this page · raw message
tools/libs/foreignmemory/minios.c new file +62 -0
62 lines not on this page · raw message
tools/libs/foreignmemory/netbsd.c new file +105 -0
105 lines not on this page · raw message
tools/libs/foreignmemory/private.h new file +53 -0
53 lines not on this page · raw message
tools/libs/foreignmemory/solaris.c new file +93 -0
93 lines not on this page · raw message
tools/libxc/Makefile +4 -4
@@ -42,8 +42,8 @@ CTRL_SRCS-y += xc_kexec.c CTRL_SRCS-y += xc_resource.c CTRL_SRCS-$(CONFIG_X86) += xc_psr.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c -CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c -CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c +CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c +CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
@@ -125,7 +125,7 @@ $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config. # libxenguest includes xc_private.h, so needs this despite not using # this functionality directly. $(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \ -$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += $(CFLAGS_libxencall) +$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += $(CFLAGS_libxencall) $(CFLAGS_libxenforeignmemory) $(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr)
@@ -207,7 +207,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR) $(SYMLINK_SHLIB) $< $@ libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS) - $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(LDLIBS_libxencall) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(LDLIBS_libxencall) $(LDLIBS_libxenforeignmemory) $(PTHREAD_LIBS) $(APPEND_LDFLAGS) # libxenguest
tools/libxc/include/xenctrl.h +0 -26
@@ -1369,32 +1369,6 @@ int xc_lockprof_query(xc_interface *xch,void *xc_memalign (xc_interface *xch,size_t alignment,size_t size);/** -* Memory maps a range within one domain to a local address range. Mappings -* should be unmapped with munmap and should follow the same rules as mmap -* regarding page alignment. Returns NULL on failure. -* -* @parm xch a handle on an open hypervisor interface -* @parm dom the domain to map memory from -* @parm size the amount of memory to map (in multiples of page size) -* @parm prot same flag as in mmap(). -* @parm mfn the frame address to map. -*/ -void *xc_map_foreign_range (xc_interface *xch,uint32_t dom, -int size,int prot, -unsigned long mfn ); - -void *xc_map_foreign_pages (xc_interface *xch,uint32_t dom,int prot, -const xen_pfn_t *arr,int num ); - -/** -* Like xc_map_foreign_pages(), except it can succeed partially. -* When a page cannot be mapped, its respective field in @err is -* set to the corresponding errno value. -*/ -void *xc_map_foreign_bulk (xc_interface *xch,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num); - -/** * Translates a virtual address in the context of a given domain and * vcpu returning the GFN containing the address (that is, an MFN for * PV guests, a PFN for HVM guests). Returns 0 for failure.
tools/libxc/include/xenctrl_compat.h +36 -0
@@ -12,6 +12,42 @@#ifndef XENCTRL_COMPAT_H #define XENCTRL_COMPAT_H +#ifdef XC_WANT_COMPAT_MAP_FOREIGN_API +/** +* Memory maps a range within one domain to a local address range. Mappings +* should be unmapped with munmap and should follow the same rules as mmap +* regarding page alignment. Returns NULL on failure. +* +* @parm xch a handle on an open hypervisor interface +* @parm dom the domain to map memory from +* @parm size the amount of memory to map (in multiples of page size) +* @parm prot same flag as in mmap(). +* @parm mfn the frame address to map. +*/ +void *xc_map_foreign_range (xc_interface *xch,uint32_t dom, +int size,int prot, +unsigned long mfn ); + +void *xc_map_foreign_pages (xc_interface *xch,uint32_t dom,int prot, +const xen_pfn_t *arr,int num ); + +/* Nothing within the library itself other than the compat wrapper +* itself should be using this, everything inside has access to +* xenforeignmemory_map(). +*/ +#if !defined(XC_INTERNAL_COMPAT_MAP_FOREIGN_API ) || \ + defined(XC_BUILDING_COMPAT_MAP_FOREIGN_API ) +/** +* Like xc_map_foreign_pages(), except it can succeed partially. +* When a page cannot be mapped, its respective field in @err is +* set to the corresponding errno value. +*/ +void *xc_map_foreign_bulk (xc_interface *xch,uint32_t dom,int prot, +const xen_pfn_t *arr,int *err,unsigned int num); +#endif + +#endif +#ifdef XC_WANT_COMPAT_EVTCHN_API typedef struct xenevtchn_handle xc_evtchn ;
tools/libxc/xc_foreign_memory.c +4 -45
70 lines not on this page · raw message
tools/libxc/xc_minios.c +0 -29
@@ -39,40 +39,11 @@ void minios_interface_close_fd(int fd);extern void minios_interface_close_fd (int fd); -int osdep_privcmd_open (xc_interface *xch) -{ -int fd =alloc_fd (FTYPE_XC ); - -if ( fd ==-1 ) -return -1 ; - - xch->privcmdfd = fd; -return 0 ; -} - -int osdep_privcmd_close (xc_interface *xch) -{ -int fd = xch->privcmdfd; -return close (fd); -} -void minios_interface_close_fd (int fd) { files[fd].type =FTYPE_NONE ; } -void *xc_map_foreign_bulk (xc_interface *xch, -uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num) -{ -unsigned long pt_prot =0 ; -if (prot &PROT_READ ) - pt_prot =L1_PROT_RO ; -if (prot &PROT_WRITE ) - pt_prot =L1_PROT ; -return map_frames_ex (arr, num,1 ,0 ,1 , dom, err, pt_prot); -} -/* Optionally flush file to disk and discard page cache */ void discard_file_cache (xc_interface *xch,int fd,int flush) {
tools/libxc/xc_netbsd.c +0 -73
79 lines not on this page · raw message
tools/libxc/xc_private.c +7 -6
@@ -58,11 +58,12 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,if (open_flags &XC_OPENFLAG_DUMMY )return xch;/* We are done */ -if (osdep_privcmd_open (xch) <0 ) - goto err; - xch->xcall =xencall_open (xch->error_handler, open_flags &XC_OPENFLAG_NON_REENTRANT ?XENCALL_OPENFLAG_NON_REENTRANT :0U ); +if ( xch->xcall ==NULL ) + goto err; + + xch->fmem =xenforeignmemory_open (xch->error_handler,0 );if ( xch->xcall ==NULL ) goto err;
@@ -70,7 +71,7 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,return xch; err: -osdep_privcmd_close (xch); +xencall_close (xch->xcall);xtl_logger_destroy (xch->error_handler_tofree);if (xch != &xch_buf)free (xch);return NULL ;
@@ -86,8 +87,8 @@ int xc_interface_close(xc_interface *xch) rc =xencall_close (xch->xcall);if (rc)PERROR ("Could not close xencall interface" ); - rc =osdep_privcmd_close (xch); -if (rc)PERROR ("Could not close hypervisor interface" ); + rc =xenforeignmemory_close (xch->fmem); +if (rc)PERROR ("Could not close foreign memory interface" );xtl_logger_destroy (xch->dombuild_logger_tofree);xtl_logger_destroy (xch->error_handler_tofree);
tools/libxc/xc_private.h +8 -3
@@ -29,8 +29,13 @@#include <sys/ioctl.h> #include "_paths.h" + +#define XC_WANT_COMPAT_MAP_FOREIGN_API +#define XC_INTERNAL_COMPAT_MAP_FOREIGN_API #include "xenctrl.h" +#include <xencall.h> +#include <xenforeignmemory.h> #include <xen/sys/privcmd.h>
@@ -94,11 +99,11 @@ struct xc_interface_core {FILE *dombuild_logger_file;const char *currently_progress_reporting; -/* Privcmd interface */ -int privcmdfd; -/* Hypercall interface */ xencall_handle *xcall; + +/* Foreign mappings */ +xenforeignmemory_handle *fmem; };int osdep_privcmd_open (xc_interface *xch);
tools/libxc/xc_solaris.c +0 -73
81 lines not on this page · raw message
tools/libxc/xc_sr_restore.c +2 -2
@@ -316,8 +316,8 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,if ( nr_pages ==0 ) goto done; - mapping = guest_page =xc_map_foreign_bulk ( - xch, ctx->domid,PROT_READ |PROT_WRITE , + mapping = guest_page =xenforeignmemory_map (xch->fmem, + ctx->domid,PROT_READ |PROT_WRITE , mfns, map_errs, nr_pages);if ( !mapping ) {
tools/libxc/xc_sr_save.c +2 -2
@@ -153,8 +153,8 @@ static int write_batch(struct xc_sr_context *ctx)if ( nr_pages >0 ) { - guest_mapping =xc_map_foreign_bulk ( - xch, ctx->domid,PROT_READ , mfns, errors, nr_pages); + guest_mapping =xenforeignmemory_map (xch->fmem, + ctx->domid,PROT_READ , mfns, errors, nr_pages);if ( !guest_mapping ) {PERROR ("Failed to map guest pages" );
tools/libxc/xg_private.h +1 -2
@@ -26,9 +26,8 @@#include <sys/types.h> #include <sys/stat.h> -#include "xenctrl.h" -#include "xenguest.h" #include "xc_private.h" +#include "xenguest.h" #include <xen/memory.h> #include <xen/elfnote.h>
tools/libxl/libxl_internal.h +1 -0
@@ -50,6 +50,7 @@#include <xenevtchn.h> #include <xenstore.h> +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h> #include <xenguest.h> #include <xc_dom.h>
tools/misc/xen-mfndump.c +1 -0
@@ -1,3 +1,4 @@ +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h> #include <xc_private.h> #include <xc_core.h>
tools/ocaml/libs/xc/xenctrl_stubs.c +1 -0
@@ -29,6 +29,7 @@#include <stdint.h> #include <string.h> +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h> #include "mmap_stubs.h"
tools/python/xen/lowlevel/xc/xc.c +2 -0
@@ -5,6 +5,7 @@*/ #include <Python.h> +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h> #include <fcntl.h> #include <netinet/in.h>
@@ -15,6 +16,7 @@#include <netdb.h> #include <arpa/inet.h> +#include <xen/elfnote.h> #include <xen/tmem.h> #include "xc_dom.h" #include <xen/hvm/hvm_info_table.h>
tools/tests/mce-test/tools/xen-mceinj.c +1 -0
@@ -30,6 +30,7 @@#include <signal.h> #include <stdarg.h> +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h> #include <xenguest.h> #include <inttypes.h>
tools/tests/mem-sharing/memshrtool.c +1 -0
@@ -11,6 +11,7 @@#include <string.h> #include <sys/mman.h> +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include "xenctrl.h" static int usage (const char * prog)
tools/xenmon/xenbaked.c +1 -0
@@ -38,6 +38,7 @@#include <errno.h> #include <signal.h> #include <xenevtchn.h> +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h> #include <xen/xen.h> #include <string.h>
tools/xenpaging/pagein.c +0 -1
@@ -1,6 +1,5 @@/* Trigger a page-in in a separate thread-of-execution to avoid deadlock */ #include <pthread.h> -#include <xc_private.h> #include "xenpaging.h" struct page_in_args {
tools/xenpaging/xenpaging.c +0 -1
@@ -27,7 +27,6 @@#include <signal.h> #include <unistd.h> #include <poll.h> -#include <xc_private.h> #include <xenstore.h> #include <getopt.h>
tools/xenpaging/xenpaging.h +2 -0
@@ -25,6 +25,8 @@#include <xenevtchn.h> +#define XC_WANT_COMPAT_MAP_FOREIGN_API +#include <xenctrl.h> #include <xc_private.h> #include <xen/event_channel.h> #include <xen/vm_event.h>
tools/xenstore/xenstored_core.c +0 -1
@@ -50,7 +50,6 @@#include "xenstored_watch.h" #include "xenstored_transaction.h" #include "xenstored_domain.h" -#include "xenctrl.h" #include "tdb.h" #include "hashtable.h"
tools/xenstore/xenstored_core.h +1 -0
@@ -19,6 +19,7 @@#ifndef _XENSTORED_CORE_H#define _XENSTORED_CORE_H +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h> #include <xengnttab.h>
tools/xentrace/xenctx.c +2 -1
@@ -25,7 +25,8 @@#include <getopt.h> #include <limits.h> -#include "xenctrl.h" +#define XC_WANT_COMPAT_MAP_FOREIGN_API +#include <xenctrl.h> #include <xen/foreign/x86_32.h> #include <xen/foreign/x86_64.h> #include <xen/hvm/save.h>
tools/xentrace/xentrace.c +1 -0
@@ -30,6 +30,7 @@#include <xen/xen.h> #include <xen/trace.h> +#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenevtchn.h> #include <xenctrl.h>
Signature · 1 line
2.1.4
Re: [PATCH XEN v8 11/29] tools: Refactor foreign memory mapping into libxenforeignmemory
Quoted 2 lines · Ian Campbell
libxenforeignmemory will provide a stable API and ABI for mapping foreign domain memory (subject to appropriate privileges).
I think this will break my Xen pkg build:
[ 333s] kdd-xen.c: In function 'kdd_access_physical_page': [ 333s] kdd-xen.c:508:15: warning: implicit declaration of function 'xc_map_foreign_range' [-Wimplicit-function-declaration] [ 333s] map = xc_map_foreign_range(g->xc_handle, [ 333s] ^ [ 333s] kdd-xen.c:508:13: warning: assignment makes pointer from integer without a cast [-Wint-conversion] [ 333s] map = xc_map_foreign_range(g->xc_handle, [ 333s] ^
3272230848f36eb5bbb660216898a90048a81d9f worked, 2e46e3f2539d026594ec1618e7df2c2bc8785b42 would start to fail.
Olaf
Re: [PATCH XEN v8 11/29] tools: Refactor foreign memory mapping into libxenforeignmemory
Quoted 7 lines · Olaf Hering
Quoted 2 lines · Ian Campbell
libxenforeignmemory will provide a stable API and ABI for mapping foreign domain memory (subject to appropriate privileges).
I think this will break my Xen pkg build:
Quoted 9 lines
[ 333s]
kdd-xen.c: In function 'kdd_access_physical_page':
[ 333s] kdd-xen.c:508:15: warning: implicit declaration of function 'xc_map_foreign_range' [-Wimplicit-function-declaration]
[ 333s] map = xc_map_foreign_range(g->xc_handle,
[ 333s] ^
[ 333s] kdd-xen.c:508:13: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
[ 333s] map = xc_map_foreign_range(g->xc_handle,
[ 333s] ^
I supposed this wasn't built by default and I missed it, but it looks to be built unconditionally. I wonder why I didn't see this.
Defining XC_WANT_COMPAT_MAP_FOREIGN_API while building is one way to fix, or else kdd would need to switch to the new interface. The latter is obviously better long term, but the former is done for a bunch of stuff in tree so it might as well be done here too.
The machine with the trees I used for this work is currently unavailable (network issues in our office), but I'll see if I can reproduce.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH XEN v8 11/29] tools: Refactor foreign memory mapping into libxenforeignmemory
Quoted 19 lines · Ian Campbell
Quoted 7 lines · Olaf Hering
Quoted 2 lines · Ian Campbell
libxenforeignmemory will provide a stable API and ABI for mapping foreign domain memory (subject to appropriate privileges).
I think this will break my Xen pkg build:
Quoted 10 lines
[ 333s]
kdd-xen.c: In function 'kdd_access_physical_page':
[ 333s] kdd-xen.c:508:15: warning: implicit declaration of function 'xc_map_foreign_range' [-Wimplicit-function-declaration] [ 333s] map = xc_map_foreign_range(g->xc_handle, [ 333s] ^
[ 333s] kdd-xen.c:508:13: warning: assignment makes pointer from integer
without a cast [-Wint-conversion]
[ 333s] map = xc_map_foreign_range(g->xc_handle, [ 333s] ^
Quoted 2 lines
I supposed this wasn't built by default and I missed it, but it looks to be built unconditionally. I wonder why I didn't see this.
Turns out this code doesn't use Werror, so it was failing but was lost in the noise (e.g. you can find it in http://logs.test-lab.xenproject.org/osst
est/logs/78820/build-amd64/5.ts-xen-build.log)
Quoted 7 lines
Defining
XC_WANT_COMPAT_MAP_FOREIGN_APIwhile building is one way to fix, or else kdd would need to switch to the new interface. The latter is obviously better long term, but the former is done for a bunch of stuff in tree so it might as well be done here too.The machine with the trees I used for this work is currently unavailable (network issues in our office), but I'll see if I can reproduce.
I did, I'll send a patch taking the easy way out as a reply.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 1/1 kdd: Opt in to libxc compat xc_map_foreign_* intefaces.
This:
kdd-xen.c: In function 'kdd_access_physical_page':
kdd-xen.c:508:9: warning: implicit declaration of function 'xc_map_foreign_range' [-Wimplicit-function-declaration]
map = xc_map_foreign_range(g->xc_handle,
^
kdd-xen.c:508:13: warning: assignment makes pointer from integer without a cast
map = xc_map_foreign_range(g->xc_handle,
^was caused by the refactoring of this functionality into libxenforeignmemory.
Reported by: Olaf Hering <[email protected]>
--- tools/debugger/kdd/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/debugger/kdd/Makefile +1 -0
@@ -2,6 +2,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk CFLAGS += $(CFLAGS_libxenctrl) +CFLAGS += -DXC_WANT_COMPAT_MAP_FOREIGN_API LDLIBS += $(LDLIBS_libxenctrl) CFILES := kdd.c kdd-xen.c
Signature · 1 line
2.6.1
Re: [PATCH] kdd: Opt in to libxc compat xc_map_foreign_* intefaces.
Quoted 10 lines · Ian Campbell
This:
kdd-xen.c: In function 'kdd_access_physical_page':
kdd-xen.c:508:9: warning: implicit declaration of function 'xc_map_foreign_range' [-Wimplicit-function-declaration]map = xc_map_foreign_range(g->xc_handle, ^ kdd-xen.c:508:13: warning: assignment makes pointer from integer without a cast map = xc_map_foreign_range(g->xc_handle, ^
Quoted 5 lines
was caused by the refactoring of this functionality into libxenforeignmemory.
Reported by: Olaf Hering <[email protected]>
Signed-off-by Ian Campbell <[email protected]>
Ian Campbell
AppliedRe: [PATCH] kdd: Opt in to libxc compat xc_map_foreign_* intefaces.
Quoted 13 lines · Tim Deegan
Quoted 12 lines · Ian Campbell
This:
kdd-xen.c: In function 'kdd_access_physical_page':
kdd-xen.c:508:9: warning: implicit declaration of function 'xc_map_foreign_range' [-Wimplicit-function-declaration] map = xc_map_foreign_range(g->xc_handle,
^
kdd-xen.c:508:13: warning: assignment makes pointer from integer without a cast
map = xc_map_foreign_range(g->xc_handle,
^
Quoted 7 lines
Quoted 5 lines
was caused by the refactoring of this functionality into libxenforeignmemory.
Reported by: Olaf Hering <[email protected]>
Signed-off-by Ian Campbell <[email protected]>Acked-by Tim Deegan <[email protected]>
thanks, applied.
(FTR, I skipped my usual full set of usual pre-push build tests, since the machines I use are unavailable right now. I have done an x86_64 make dist).
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH] kdd: Opt in to libxc compat xc_map_foreign_* intefaces.
In reply to Ian CampbellQuoted 1 line · Ian Campbell
Reported by: Olaf Hering <[email protected]>
Thanks,
Olaf
PATCH 1/1 kdd: build using Werror
In reply to Ian CampbellWe build most of tools using Werror and there seems to be know deliberate reason for this to be an exception.
--- tools/debugger/kdd/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/debugger/kdd/Makefile +1 -0
@@ -1,6 +1,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk +CFLAGS += -Werror CFLAGS += $(CFLAGS_libxenctrl) CFLAGS += -DXC_WANT_COMPAT_MAP_FOREIGN_API LDLIBS += $(LDLIBS_libxenctrl)
Signature · 1 line
2.6.1
Re: [PATCH] kdd: build using Werror
Quoted 2 lines · Ian Campbell
We build most of tools using Werror and there seems to be know deliberate reason for this to be an exception.
s/know/no/ ?
Olaf
Re: [PATCH] kdd: build using Werror
Quoted 6 lines · Olaf Hering
Quoted 2 lines · Ian Campbell
We build most of tools using Werror and there seems to be know deliberate reason for this to be an exception.
s/know/no/ ?
Yes, thanks!
I think I was going to write "I don't know of" and then changed my mind not quite all the way.
Quoted 1 line
Acked-by Olaf Hering <[email protected]>
Thanks.
Ian.
Re: [PATCH] kdd: build using Werror
In reply to Ian CampbellQuoted 4 lines · Ian Campbell
We build most of tools using Werror and there seems to be know deliberate reason for this to be an exception.
Signed-off-by Ian Campbell <[email protected]>
Ian Campbell
AppliedRe: [PATCH] kdd: build using Werror
Quoted 7 lines · Tim Deegan
Quoted 4 lines · Ian Campbell
We build most of tools using Werror and there seems to be know deliberate reason for this to be an exception.
Signed-off-by Ian Campbell <[email protected]>Acked-by Tim Deegan <[email protected]>
applied, thanks.
(FTR, I skipped my usual full set of usual pre-push build tests, since the machines I use are unavailable right now. I have done an x86_64 make dist).
Re: [PATCH] kdd: build using Werror
In reply to Ian CampbellQuoted 4 lines · Ian Campbell
We build most of tools using Werror and there seems to be know deliberate reason for this to be an exception.
Signed-off-by Ian Campbell <[email protected]>
This would have caught the kdd error.
Olaf
PATCH v8 12/29 tools/libs/foreignmemory: provide xenforeignmemory_unmap.
In reply to Ian CampbellAnd require it be used instead of direct munmap.
This will allow e.g. Valgrind hooks to help track incorrect use of foreign mappings.
Switch all uses of xenforeignmemory_map to use xenforeignmemory_unmap, not that foreign mappings via the libxc compat xc_map_foreign_* interface will not take advantage of this and will need converting.
---
v4: xenforeignmemory_unmap takes pages not bytes, adjust callers.
v6: Document error behaviour
Use an osdep layer, although there is no current need for common code on _unmap there is for _map so use this indirection for consistency.
--- tools/libs/foreignmemory/freebsd.c | 6 ++++++ tools/libs/foreignmemory/include/xenforeignmemory.h | 11 +++++++++-- tools/libs/foreignmemory/libxenforeignmemory.map | 1 + tools/libs/foreignmemory/linux.c | 6 ++++++ tools/libs/foreignmemory/minios.c | 6 ++++++ tools/libs/foreignmemory/netbsd.c | 6 ++++++ tools/libs/foreignmemory/solaris.c | 6 ++++++ tools/libxc/xc_sr_restore.c | 2 +- tools/libxc/xc_sr_save.c | 2 +- tools/libxc/xc_vm_event.c | 2 +- 10 files changed, 43 insertions(+), 5 deletions(-)
tools/libs/foreignmemory/freebsd.c +6 -0
@@ -118,6 +118,12 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,return addr; } +int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, +void *addr,unsigned int num) +{ +return munmap (addr, num <<PAGE_SHIFT ); +} +/* * Local variables: * mode: C
tools/libs/foreignmemory/include/xenforeignmemory.h +9 -2
@@ -44,8 +44,8 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem);/* * Maps a range within one domain to a local address range. Mappings -* should be unmapped with munmap and should follow the same rules as mmap -* regarding page alignment. +* must be unmapped with xenforeignmemory_unmap and should follow the +* same rules as mmap regarding page alignment. * * prot is as for mmap(2). *
@@ -57,6 +57,13 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem);void *xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot,const xen_pfn_t *arr,int *err,unsigned int num); +/* +* Unmap a mapping previous created with xenforeignmemory_map(). +* +* Returns 0 on success on failure sets errno and returns -1. +*/ +int xenforeignmemory_unmap (xenforeignmemory_handle *fmem, +void *addr,unsigned int num);#endif
tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
@@ -3,5 +3,6 @@ VERS_1.0 { xenforeignmemory_open; xenforeignmemory_close; xenforeignmemory_map; + xenforeignmemory_unmap; local: *; /* Do not expose anything by default */ };
tools/libs/foreignmemory/linux.c +6 -0
@@ -282,6 +282,12 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,return addr; } +int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, +void *addr,unsigned int num) +{ +return munmap (addr, (unsigned long )num <<PAGE_SHIFT ); +} +/* * Local variables: * mode: C
tools/libs/foreignmemory/minios.c +6 -0
@@ -51,6 +51,12 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,return map_frames_ex (arr, num,1 ,0 ,1 , dom, err, pt_prot); } +int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, +void *addr,unsigned int num) +{ +return munmap (addr, num <<PAGE_SHIFT ); +} +/* * Local variables: * mode: C
tools/libs/foreignmemory/netbsd.c +6 -0
@@ -94,6 +94,12 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom, } +int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, +void *addr,unsigned int num) +{ +return munmap (addr, num*XC_PAGE_SIZE ); +} +/* * Local variables: * mode: C
tools/libs/foreignmemory/solaris.c +6 -0
@@ -91,3 +91,9 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom, }return addr; } + +int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, +void *addr,unsigned int num) +{ +return munmap (addr, num*XC_PAGE_SIZE ); +}
tools/libxc/xc_sr_restore.c +1 -1
@@ -378,7 +378,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, err:if ( mapping ) -munmap (mapping, nr_pages *PAGE_SIZE ); +xenforeignmemory_unmap (xch->fmem, mapping, nr_pages);free (map_errs);free (mfns);
tools/libxc/xc_sr_save.c +1 -1
@@ -263,7 +263,7 @@ static int write_batch(struct xc_sr_context *ctx) err:free (rec_pfns);if ( guest_mapping ) -munmap (guest_mapping, nr_pages_mapped *PAGE_SIZE ); +xenforeignmemory_unmap (xch->fmem, guest_mapping, nr_pages_mapped);for ( i =0 ; local_pages && i < nr_pfns; ++i )free (local_pages[i]);free (iov);
tools/libxc/xc_vm_event.c +1 -1
@@ -148,7 +148,7 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param, }if ( ring_page ) -munmap (ring_page,XC_PAGE_SIZE ); +xenforeignmemory_unmap (xch->fmem, ring_page,1 ); ring_page =NULL ; errno = saved_errno;
Signature · 1 line
2.1.4
PATCH v8 13/29 tools/libs/foreignmemory: use size_t for size arguments.
In reply to Ian CampbellSurprisingly it appears no callers need updating.
---
v4: New patch
--- tools/libs/foreignmemory/compat.c | 2 +- tools/libs/foreignmemory/freebsd.c | 4 ++-- .../libs/foreignmemory/include/xenforeignmemory.h | 5 +++-- tools/libs/foreignmemory/linux.c | 23 +++++++++++----------- tools/libs/foreignmemory/minios.c | 4 ++-- tools/libs/foreignmemory/netbsd.c | 2 +- tools/libs/foreignmemory/solaris.c | 2 +- 7 files changed, 22 insertions(+), 20 deletions(-)
tools/libs/foreignmemory/compat.c +1 -1
@@ -23,7 +23,7 @@void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num) +const xen_pfn_t *arr,int *err,size_t num) {xen_pfn_t *pfn;unsigned int i;
tools/libs/foreignmemory/freebsd.c +2 -2
@@ -85,7 +85,7 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot,const xen_pfn_t *arr,int *err, -unsigned int num) +size_t num) {int fd = fmem->fd;privcmd_mmapbatch_t ioctlx;
@@ -119,7 +119,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, }int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, -void *addr,unsigned int num) +void *addr,size_t num) {return munmap (addr, num <<PAGE_SHIFT ); }
tools/libs/foreignmemory/include/xenforeignmemory.h +3 -2
@@ -56,14 +56,15 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem);*/ void *xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot,const xen_pfn_t *arr,int *err, -unsigned int num); +size_t pages); +/* * Unmap a mapping previous created with xenforeignmemory_map(). * * Returns 0 on success on failure sets errno and returns -1. */ int xenforeignmemory_unmap (xenforeignmemory_handle *fmem, -void *addr,unsigned int num); +void *addr,size_t pages);#endif
tools/libs/foreignmemory/linux.c +12 -11
@@ -115,10 +115,11 @@ static int map_foreign_batch_single(int fd, uint32_t dom,* This will keep the request ring full and avoids delays. */ static int retry_paged (int fd,uint32_t dom,void *addr, -const xen_pfn_t *arr,int *err,unsigned int num) +const xen_pfn_t *arr,int *err,size_t num) {privcmd_mmapbatch_v2_t ioctlx; -int rc, paged =0 , i =0 ; +int rc, paged =0 ; +size_t i =0 ; do {
@@ -134,7 +135,7 @@ static int retry_paged(int fd, uint32_t dom, void *addr,/* At least one gfn is still in paging state */ ioctlx.num =1 ; ioctlx.dom = dom; - ioctlx.addr = (unsigned long )addr + ((unsigned long )i<<PAGE_SHIFT ); + ioctlx.addr = (unsigned long )addr + (i<<PAGE_SHIFT ); ioctlx.arr = arr + i; ioctlx.err = err + i;
@@ -160,15 +161,15 @@ out:void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num) +const xen_pfn_t *arr,int *err,size_t num) {int fd = fmem->fd;privcmd_mmapbatch_v2_t ioctlx;void *addr; -unsigned int i; +size_t i;int rc; - addr =mmap (NULL , (unsigned long )num <<PAGE_SHIFT , prot,MAP_SHARED , + addr =mmap (NULL , num <<PAGE_SHIFT , prot,MAP_SHARED , fd,0 );if ( addr ==MAP_FAILED ) {
@@ -212,7 +213,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,if ( pfn ==MAP_FAILED ) {PERROR ("mmap of pfn array failed" ); - (void )munmap (addr, (unsigned long )num <<PAGE_SHIFT ); + (void )munmap (addr, num <<PAGE_SHIFT );return NULL ; } }
@@ -245,7 +246,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,continue ; } rc =map_foreign_batch_single (fd, dom, pfn + i, - (unsigned long )addr + ((unsigned long )i<<PAGE_SHIFT )); + (unsigned long )addr + (i<<PAGE_SHIFT ));if ( rc <0 ) { rc = -errno;
@@ -274,7 +275,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,int saved_errno = errno;PERROR ("ioctl failed" ); - (void )munmap (addr, (unsigned long )num <<PAGE_SHIFT ); + (void )munmap (addr, num <<PAGE_SHIFT ); errno = saved_errno;return NULL ; }
@@ -283,9 +284,9 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, }int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, -void *addr,unsigned int num) +void *addr,size_t num) { -return munmap (addr, (unsigned long )num <<PAGE_SHIFT ); +return munmap (addr, num <<PAGE_SHIFT ); }/*
tools/libs/foreignmemory/minios.c +2 -2
@@ -41,7 +41,7 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,unsigned int num) +const xen_pfn_t *arr,int *err,size_t num) {unsigned long pt_prot =0 ;if (prot &PROT_READ )
@@ -52,7 +52,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, }int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, -void *addr,unsigned int num) +void *addr,size_t num) {return munmap (addr, num <<PAGE_SHIFT ); }
tools/libs/foreignmemory/netbsd.c +1 -1
@@ -95,7 +95,7 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom, }int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, -void *addr,unsigned int num) +void *addr,size_t num) {return munmap (addr, num*XC_PAGE_SIZE ); }
tools/libs/foreignmemory/solaris.c +1 -1
@@ -93,7 +93,7 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom, }int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem, -void *addr,unsigned int num) +void *addr,size_t num) {return munmap (addr, num*XC_PAGE_SIZE ); }
Signature · 1 line
2.1.4
PATCH v8 14/29 tools/libs/foreignmemory: Mention restrictions on fork in docs.
In reply to Ian Campbell---
v6: Also discuss recovering the memory.
v7: Further clarifications regarding forking based on ML discussions.
(Dropped Wei's ack)
--- .../libs/foreignmemory/include/xenforeignmemory.h | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/include/xenforeignmemory.h +32 -1
@@ -32,13 +32,44 @@ typedef struct xentoollog_logger xentoollog_logger;typedef struct xenforeignmemory_handle xenforeignmemory_handle ;/* -* Return a handle onto the hypercall driver. Logs errors. +* Return a handle onto the foreign memory mapping driver. Logs errors. +* +* Note: After fork(2) a child process must not use any opened +* foreignmemory handle inherited from their parent, nor access any +* grant mapped areas associated with that handle. +* +* The child must open a new handle if they want to interact with +* foreignmemory. +* +* Calling exec(2) in a child will safely (and reliably) reclaim any +* resources which were allocated via a xenforeignmemory_handle in the +* parent. +* +* A child which does not call exec(2) may safely call +* xenforeignmemory_close() on a xenforeignmemory_handle inherited +* from their parent. This will attempt to reclaim any resources +* associated with that handle. Note that in some implementations this +* reclamation may not be completely effective, in this case any +* affected resources remain allocated. +* +* Calling xenforeignmemory_close() is the only safe operation on a +* xenforeignmemory_handle which has been inherited. */ xenforeignmemory_handle *xenforeignmemory_open (xentoollog_logger *logger,unsigned open_flags);/* * Close a handle previously allocated with xenforeignmemory_open(). +* +* Under normal circumstances (i.e. not in the child after a fork) +* xenforeignmemory_unmap() should be used on all mappings allocated +* by xenforeignmemory_map() prior to closing the handle in order to +* free up resources associated with those mappings. +* +* This is the only function which may be safely called on a +* xenforeignmemory_handle in a child after a +* fork. xenforeignmemory_unmap() must not be called under such +* circumstances. */ int xenforeignmemory_close (xenforeignmemory_handle *fmem);
Signature · 1 line
2.1.4
Re: [PATCH XEN v8 14/29] tools/libs/foreignmemory: Mention restrictions on fork in docs.
Quoted 40 lines · Ian Campbell
Signed-off-by Ian Campbell <[email protected]>---
v6: Also discuss recovering the memory.v7: Further clarifications regarding forking based on ML discussions.
(Dropped Wei's ack)--- .../libs/foreignmemory/include/xenforeignmemory.h | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)tools/libs/foreignmemory/include/xenforeignmemory.h +21
-1@@ -32,13 +32,44 @@ typedef struct xentoollog_logger xentoollog_logger;typedef struct xenforeignmemory_handle xenforeignmemory_handle ;/* -* Return a handle onto the hypercall driver. Logs errors. +* Return a handle onto the foreign memory mapping driver. Logs errors. +* +* Note: After fork(2) a child process must not use any opened +* foreignmemory handle inherited from their parent, nor access any +* grant mapped areas associated with that handle. +* +* The child must open a new handle if they want to interact with +* foreignmemory. +* +* Calling exec(2) in a child will safely (and reliably) reclaim any +* resources which were allocated via a xenforeignmemory_handle in the +* parent. +* +* A child which does not call exec(2) may safely call +* xenforeignmemory_close() on a xenforeignmemory_handle inherited +* from their parent. This will attempt to reclaim any resources +* associated with that handle. Note that in some implementations this +* reclamation may not be completely effective, in this case any +* affected resources remain allocated. +* +* Calling xenforeignmemory_close() is the only safe operation on a
tools/libs/foreignmemory/include/xenforeignmemory.h typedef struct xentoollog_logger xentoollog_logger; · line 65
Quoted 10 lines
tools/libs/foreignmemory/include/xenforeignmemory.h +4
-0+* xenforeignmemory_handle which has been inherited. */ xenforeignmemory_handle *xenforeignmemory_open (xentoollog_logger *logger,unsigned open_flags);/* * Close a handle previously allocated with xenforeignmemory_open(). +* +* Under normal circumstances (i.e. not in the child after a fork) +* xenforeignmemory_unmap() should be used on all mappings allocated
"Should" according to RFC 2119 has the connotation of "there might be a valid reason to ignore such action". But after reading this passage I think we should use "must" here?
Wei.
Quoted 13 lines
tools/libs/foreignmemory/include/xenforeignmemory.h +7
-0+* by xenforeignmemory_map() prior to closing the handle in order to +* free up resources associated with those mappings. +* +* This is the only function which may be safely called on a +* xenforeignmemory_handle in a child after a +* fork. xenforeignmemory_unmap() must not be called under such +* circumstances. */ int xenforeignmemory_close (xenforeignmemory_handle *fmem);Signature · 1 line
2.1.4
Re: [PATCH XEN v8 14/29] tools/libs/foreignmemory: Mention restrictions on fork in docs.
Quoted 51 lines · Wei Liu
Quoted 50 lines · Ian Campbell
Signed-off-by Ian Campbell <[email protected]>---
v6: Also discuss recovering the memory.v7: Further clarifications regarding forking based on ML discussions. (Dropped Wei's ack)
---
.../libs/foreignmemory/include/xenforeignmemory.h | 33
+++++++++++++++++++++-1 file changed, 32 insertions(+), 1 deletion(-)tools/libs/foreignmemory/include/xenforeignmemory.h +0
-0@@ -32,13 +32,44 @@ typedef struct xentoollog_logger xentoollog_logger; typedef struct xenforeignmemory_handle xenforeignmemory_handle;
/*
- * Return a handle onto the hypercall driver. Logs errors.
+ * Return a handle onto the foreign memory mapping driver. Logs errors.
+ *
+ * Note: After fork(2) a child process must not use any opened
+ * foreignmemory handle inherited from their parent, nor access any
+ * grant mapped areas associated with that handle.
+ *
+ * The child must open a new handle if they want to interact with
+ * foreignmemory.
+ *
+ * Calling exec(2) in a child will safely (and reliably) reclaim any
+ * resources which were allocated via axenforeignmemory_handlein the
+ * parent.
+ *
+ * A child which does not call exec(2) may safely call
+ *xenforeignmemory_close()on axenforeignmemory_handleinherited
+ * from their parent. This will attempt to reclaim any resources
+ * associated with that handle. Note that in some implementations this
+ * reclamation may not be completely effective, in this case any
+ * affected resources remain allocated.
+ *
+ * Callingxenforeignmemory_close()is the only safe operation on a
+ *xenforeignmemory_handlewhich has been inherited.
*/
xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,
unsignedopen_flags);
/*
Quoted 8 lines
Quoted 4 lines
* Close a handle previously allocated with
xenforeignmemory_open().
+ *
+ * Under normal circumstances (i.e. not in the child after a fork)
+ *xenforeignmemory_unmap()should be used on all mappings allocated"Should" according to RFC 2119 has the connotation of "there might be a valid reason to ignore such action". But after reading this passage I think we should use "must" here?
RFC 2119 formally defines "SHOULD" not "should" (or "Should"), and in any case in order to be subject to those formal definitions a document would need to explicitly reference RFC 2119.
I think most readers of normal English prose would probably take "must" and "should" to mean mostly the same thing.
If there are other reasons to resend I don't mind switching it to must, but I don't think it is worth a resend of this mega-series for what is a minor semantic quibble.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Wei Liu
Acked-byRe: [PATCH XEN v8 14/29] tools/libs/foreignmemory: Mention restrictions on fork in docs.
Quoted 65 lines · Ian Campbell
Quoted 51 lines · Wei Liu
Quoted 50 lines · Ian Campbell
Signed-off-by Ian Campbell <[email protected]>---
v6: Also discuss recovering the memory.v7: Further clarifications regarding forking based on ML discussions. (Dropped Wei's ack)
---
.../libs/foreignmemory/include/xenforeignmemory.h | 33
+++++++++++++++++++++-1 file changed, 32 insertions(+), 1 deletion(-)tools/libs/foreignmemory/include/xenforeignmemory.h +0
-0@@ -32,13 +32,44 @@ typedef struct xentoollog_logger xentoollog_logger; typedef struct xenforeignmemory_handle xenforeignmemory_handle;
/*
- * Return a handle onto the hypercall driver. Logs errors.
+ * Return a handle onto the foreign memory mapping driver. Logs errors.
+ *
+ * Note: After fork(2) a child process must not use any opened
+ * foreignmemory handle inherited from their parent, nor access any
+ * grant mapped areas associated with that handle.
+ *
+ * The child must open a new handle if they want to interact with
+ * foreignmemory.
+ *
+ * Calling exec(2) in a child will safely (and reliably) reclaim any
+ * resources which were allocated via axenforeignmemory_handlein the
+ * parent.
+ *
+ * A child which does not call exec(2) may safely call
+ *xenforeignmemory_close()on axenforeignmemory_handleinherited
+ * from their parent. This will attempt to reclaim any resources
+ * associated with that handle. Note that in some implementations this
+ * reclamation may not be completely effective, in this case any
+ * affected resources remain allocated.
+ *
+ * Callingxenforeignmemory_close()is the only safe operation on a
+ *xenforeignmemory_handlewhich has been inherited.
*/
xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,
unsignedopen_flags);
/*Quoted 8 lines
Quoted 4 lines
* Close a handle previously allocated with
xenforeignmemory_open().
+ *
+ * Under normal circumstances (i.e. not in the child after a fork)
+ *xenforeignmemory_unmap()should be used on all mappings allocated"Should" according to RFC 2119 has the connotation of "there might be a valid reason to ignore such action". But after reading this passage I think we should use "must" here?
RFC 2119 formally defines "SHOULD" not "should" (or "Should"), and in any case in order to be subject to those formal definitions a document would need to explicitly reference RFC 2119.
Quoted 7 lines
I think most readers of normal English prose would probably take "must" and "should" to mean mostly the same thing.
If there are other reasons to resend I don't mind switching it to must, but I don't think it is worth a resend of this mega-series for what is a minor semantic quibble.
No need to resend then.
Wei.
Quoted 1 line
Ian.
PATCH v8 15/29 tools/libs/foreignmemory: Support err == NULL to map.
In reply to Ian CampbellThe existing xc_map_foreign_bulk-like interface encourages callers to miss error checking for partial failure (by forgetting to scan the err array).
Add support for passing err==NULL which behaves in a xc_map_foreign_pages-like manner and returns a global error for any failure.
While documenting this also clarify the overall behaviour and the behaviour with err!=NULL.
With this the compat wrapper of xc_map_foreign_pages() can be simplified.
---
v7: Check for NULL when allocating err.
v6: New
--- tools/libs/foreignmemory/core.c | 33 +++++++++++++++++++++- .../libs/foreignmemory/include/xenforeignmemory.h | 24 ++++++++++++++-- tools/libxc/xc_foreign_memory.c | 22 +-------------- 3 files changed, 54 insertions(+), 25 deletions(-)
tools/libs/foreignmemory/core.c +32 -1
@@ -14,6 +14,8 @@*/ #include <stdlib.h> +#include <assert.h> +#include <errno.h> #include "private.h"
@@ -64,7 +66,36 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom, int prot, const xen_pfn_t *arr, int *err, size_t num) { - return osdep_xenforeignmemory_map(fmem, dom, prot, arr, err, num); + void *ret; +int *err_to_free =NULL ; + +if ( err ==NULL ) + err = err_to_free =malloc (num *sizeof (int )); + +if ( err ==NULL ) +return NULL ; + + ret =osdep_xenforeignmemory_map (fmem, dom, prot, arr, err, num); + +if ( ret ==0 && err_to_free ) + { +int i; + +for ( i =0 ; i < num ; i++ ) + { +if ( err[i] ) + { + errno = -err[i]; + (void )osdep_xenforeignmemory_unmap (fmem, ret, num); + ret =NULL ; +break ; + } + } + } + +free (err_to_free); + +return ret; } int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
tools/libs/foreignmemory/include/xenforeignmemory.h +21 -3
@@ -80,10 +80,28 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem);* * prot is as for mmap(2). * -* Can partially succeed. When a page cannot be mapped, its respective -* field in @err is set to the corresponding errno value. +* @arr is an array of @pages gfns to be mapped linearly in the local +* address range. @err is an (optional) output array used to report +* per-page errors, as errno values. * -* Returns NULL if no pages can be mapped. +* If @err is given (is non-NULL) then the mapping may partially +* succeed and return a valid pointer while also using @err to +* indicate the success (0) or failure (errno value) of the individual +* pages. The global errno thread local variable is not valid in this +* case. +* +* If @err is not given (is NULL) then on failure to map any page any +* successful mappings will be undone and NULL will be returned. errno +* will be set to correspond to the first failure (which may not be +* the most critical). +* +* It is also possible to return NULL due to a complete failure, +* i.e. failure to even attempt the mapping, in this case the global +* errno will have been set and the contents of @err (if given) is +* invalid. +* +* Note that it is also possible to return non-NULL with the contents +* of @err indicating failure to map every page. */ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom, int prot, const xen_pfn_t *arr, int *err,
tools/libxc/xc_foreign_memory.c +1 -21
@@ -23,32 +23,12 @@void *xc_map_foreign_pages (xc_interface *xch,uint32_t dom,int prot,const xen_pfn_t *arr,int num) { -void *res; -int i, *err; -if (num <0 ) { errno =EINVAL ;return NULL ; } - err =malloc (num *sizeof (*err)); -if (!err) -return NULL ; - - res =xenforeignmemory_map (xch->fmem, dom, prot, arr, err, num); -if (res) { -for (i =0 ; i < num; i++) { -if (err[i]) { - errno = -err[i]; -munmap (res, num *PAGE_SIZE ); - res =NULL ; -break ; - } - } - } - -free (err); -return res; +return xenforeignmemory_map (xch->fmem, dom, prot, arr,NULL , num); } void *xc_map_foreign_range(xc_interface *xch,
Signature · 1 line
2.1.4
PATCH v8 16/29 tools/libs/foreignmemory: pull array length argument to map forward
In reply to Ian CampbellBy having the "num" argument before the page and error arrays we can potentially use a variable-length-array argument ("int pages[num]") in the function prototype.
However VLAs are a C99 feature and we are currently targetting C89 and later, so we don't actually make use of this here, merely arrange that we can switch to VLAs in the future without changing the function ABI.
---
v6: New
--- tools/libs/foreignmemory/compat.c | 4 ++-- tools/libs/foreignmemory/core.c | 5 +++-- tools/libs/foreignmemory/freebsd.c | 4 ++-- tools/libs/foreignmemory/include/xenforeignmemory.h | 4 ++-- tools/libs/foreignmemory/linux.c | 3 ++- tools/libs/foreignmemory/minios.c | 3 ++- tools/libs/foreignmemory/private.h | 3 ++- tools/libxc/xc_foreign_memory.c | 4 ++-- tools/libxc/xc_sr_restore.c | 2 +- tools/libxc/xc_sr_save.c | 2 +- 10 files changed, 19 insertions(+), 15 deletions(-)
tools/libs/foreignmemory/compat.c +2 -2
@@ -22,8 +22,8 @@#include "private.h" void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem, -uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,size_t num) +uint32_t dom,int prot,size_t num, +const xen_pfn_t arr[/*num*/ ],int err[/*num*/ ]) {xen_pfn_t *pfn;unsigned int i;
tools/libs/foreignmemory/core.c +3 -2
@@ -64,7 +64,8 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem)void *xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,size_t num) +size_t num, +const xen_pfn_t arr[/*num*/ ],int err[/*num*/ ]) {void *ret;int *err_to_free =NULL ;
@@ -75,7 +76,7 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,if ( err ==NULL )return NULL ; - ret =osdep_xenforeignmemory_map (fmem, dom, prot, arr, err, num); + ret =osdep_xenforeignmemory_map (fmem, dom, prot, num, arr, err);if ( ret ==0 && err_to_free ) {
tools/libs/foreignmemory/freebsd.c +2 -2
@@ -84,8 +84,8 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err, -size_t num) +size_t num, +const xen_pfn_t arr[/*num*/ ],int err[/*num*/ ]) {int fd = fmem->fd;privcmd_mmapbatch_t ioctlx;
tools/libs/foreignmemory/include/xenforeignmemory.h +2 -2
@@ -104,8 +104,8 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem);* of @err indicating failure to map every page. */ void *xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom, -int prot,const xen_pfn_t *arr,int *err, -size_t pages); +int prot,size_t pages, +const xen_pfn_t arr[/*pages*/ ],int err[/*pages*/ ]);/* * Unmap a mapping previous created with xenforeignmemory_map().
tools/libs/foreignmemory/linux.c +2 -1
@@ -161,7 +161,8 @@ out:void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,size_t num) +size_t num, +const xen_pfn_t arr[/*num*/ ],int err[/*num*/ ]) {int fd = fmem->fd;privcmd_mmapbatch_v2_t ioctlx;
tools/libs/foreignmemory/minios.c +2 -1
@@ -41,7 +41,8 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,size_t num) +size_t num, +const xen_pfn_t arr[/*num*/ ],int err[/*num*/ ]) {unsigned long pt_prot =0 ;if (prot &PROT_READ )
tools/libs/foreignmemory/private.h +2 -1
@@ -27,7 +27,8 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem);void *osdep_xenforeignmemory_map (xenforeignmemory_handle *fmem,uint32_t dom,int prot, -const xen_pfn_t *arr,int *err,size_t num); +size_t num, +const xen_pfn_t arr[num],int err[num]);int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem,void *addr,size_t num);
tools/libxc/xc_foreign_memory.c +2 -2
@@ -28,7 +28,7 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,return NULL ; } -return xenforeignmemory_map (xch->fmem, dom, prot, arr,NULL , num); +return xenforeignmemory_map (xch->fmem, dom, prot, num, arr,NULL ); } void *xc_map_foreign_range(xc_interface *xch,
@@ -84,7 +84,7 @@ void *xc_map_foreign_ranges(xc_interface *xch,void *xc_map_foreign_bulk (xc_interface *xch,uint32_t dom,int prot,const xen_pfn_t *arr,int *err,unsigned int num) { -return xenforeignmemory_map (xch->fmem, dom, prot, arr, err, num); +return xenforeignmemory_map (xch->fmem, dom, prot, num, arr, err); }/*
tools/libxc/xc_sr_restore.c +1 -1
@@ -318,7 +318,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, mapping = guest_page =xenforeignmemory_map (xch->fmem, ctx->domid,PROT_READ |PROT_WRITE , - mfns, map_errs, nr_pages); + nr_pages, mfns, map_errs);if ( !mapping ) { rc =-1 ;
tools/libxc/xc_sr_save.c +1 -1
@@ -154,7 +154,7 @@ static int write_batch(struct xc_sr_context *ctx)if ( nr_pages >0 ) { guest_mapping =xenforeignmemory_map (xch->fmem, - ctx->domid,PROT_READ , mfns, errors, nr_pages); + ctx->domid,PROT_READ , nr_pages, mfns, errors);if ( !guest_mapping ) {PERROR ("Failed to map guest pages" );
Signature · 1 line
2.1.4
PATCH v8 17/29 tools/libs/evtchn: Review and update doc comments.
In reply to Ian CampbellRemove the reference to pre-4.1, since this is now a new library.
Fixup references to xc.
--- tools/libs/evtchn/include/xenevtchn.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/libs/evtchn/include/xenevtchn.h +2 -4
@@ -46,11 +46,9 @@ typedef struct xentoollog_logger xentoollog_logger;* which case errno will be set appropriately. * * Note: -* After fork a child process must not use any opened xc evtchn +* After fork a child process must not use any opened evtchn * handle inherited from their parent. They must open a new handle if -* they want to interact with xc. -* -* Before Xen pre-4.1 this function would sometimes report errors with perror. +* they want to interact with evtchn. */ /* Currently no flags are defined */ xenevtchn_handle *xenevtchn_open (xentoollog_logger *logger,unsigned open_flags);
Signature · 1 line
2.1.4
PATCH v8 18/29 tools/libs/evtchn: Use uint32_t for domid arguments
In reply to Ian Campbell---
v8: New
--- tools/libs/evtchn/freebsd.c | 4 ++-- tools/libs/evtchn/include/xenevtchn.h | 4 ++-- tools/libs/evtchn/linux.c | 4 ++-- tools/libs/evtchn/minios.c | 4 ++-- tools/libs/evtchn/netbsd.c | 4 ++-- tools/libs/evtchn/solaris.c | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-)
tools/libs/evtchn/freebsd.c +2 -2
@@ -62,7 +62,7 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port)return ioctl (fd,IOCTL_EVTCHN_NOTIFY , ¬ify); } -evtchn_port_or_error_t xenevtchn_bind_unbound_port (xenevtchn_handle *xce,int domid) +evtchn_port_or_error_t xenevtchn_bind_unbound_port (xenevtchn_handle *xce,uint32_t domid) {int ret, fd = xce->fd;struct ioctl_evtchn_bind_unbound_port bind;
@@ -74,7 +74,7 @@ evtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xce, int do }evtchn_port_or_error_t -xenevtchn_bind_interdomain (xenevtchn_handle *xce,int domid,evtchn_port_t remote_port) +xenevtchn_bind_interdomain (xenevtchn_handle *xce,uint_32 domid,evtchn_port_t remote_port) {int ret, fd = xce->fd;struct ioctl_evtchn_bind_interdomain bind;
tools/libs/evtchn/include/xenevtchn.h +2 -2
@@ -86,14 +86,14 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port);* domain ID, or -1 on failure, in which case errno will be set appropriately. */ evtchn_port_or_error_t -xenevtchn_bind_unbound_port (xenevtchn_handle *xce,int domid); +xenevtchn_bind_unbound_port (xenevtchn_handle *xce,uint32_t domid);/* * Returns a new event port bound to the remote port for the given domain ID, * or -1 on failure, in which case errno will be set appropriately. */ evtchn_port_or_error_t -xenevtchn_bind_interdomain (xenevtchn_handle *xce,int domid, +xenevtchn_bind_interdomain (xenevtchn_handle *xce,uint32_t domid,evtchn_port_t remote_port);/*
tools/libs/evtchn/linux.c +2 -2
@@ -61,7 +61,7 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port) }evtchn_port_or_error_t xenevtchn_bind_unbound_port (xenevtchn_handle *xce, -int domid) +uint32_t domid) {int fd = xce->fd;struct ioctl_evtchn_bind_unbound_port bind;
@@ -72,7 +72,7 @@ evtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xce, }evtchn_port_or_error_t xenevtchn_bind_interdomain (xenevtchn_handle *xce, -int domid, +uint32_t domid,evtchn_port_t remote_port) {int fd = xce->fd;
tools/libs/evtchn/minios.c +2 -2
@@ -128,7 +128,7 @@ static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data)wake_up (&event_queue); } -evtchn_port_or_error_t xenevtchn_bind_unbound_port (xenevtchn_handle *xce,int domid) +evtchn_port_or_error_t xenevtchn_bind_unbound_port (xenevtchn_handle *xce,uint32_t domid) {int fd = xce->fd;struct evtchn_port_info *port_info;
@@ -155,7 +155,7 @@ evtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xce, int doreturn port; } -evtchn_port_or_error_t xenevtchn_bind_interdomain (xenevtchn_handle *xce,int domid, +evtchn_port_or_error_t xenevtchn_bind_interdomain (xenevtchn_handle *xce,uint32_t domid,evtchn_port_t remote_port) {int fd = xce->fd;
tools/libs/evtchn/netbsd.c +2 -2
@@ -62,7 +62,7 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port)return ioctl (fd,IOCTL_EVTCHN_NOTIFY , ¬ify); } -evtchn_port_or_error_t xenevtchn_bind_unbound_port (xenevtchn_handle * xce,int domid) +evtchn_port_or_error_t xenevtchn_bind_unbound_port (xenevtchn_handle * xce,uint32_t domid) {int fd = xce->fd;struct ioctl_evtchn_bind_unbound_port bind;
@@ -77,7 +77,7 @@ evtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle * xce, int dreturn -1 ; } -evtchn_port_or_error_t xenevtchn_bind_interdomain (xenevtchn_handle *xce,int domid, +evtchn_port_or_error_t xenevtchn_bind_interdomain (xenevtchn_handle *xce,uint32_t domid,evtchn_port_t remote_port) {int fd = xce->fd;
tools/libs/evtchn/solaris.c +2 -2
@@ -65,7 +65,7 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port)return ioctl (fd,IOCTL_EVTCHN_NOTIFY , ¬ify); } -evtchn_port_or_error_t xenevtchn_bind_unbound_port (xenevtchn_handle *xce,int domid) +evtchn_port_or_error_t xenevtchn_bind_unbound_port (xenevtchn_handle *xce,uint32_t domid) {int fd = xce->fd;struct ioctl_evtchn_bind_unbound_port bind;
@@ -75,7 +75,7 @@ evtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xce, int doreturn ioctl (fd,IOCTL_EVTCHN_BIND_UNBOUND_PORT , &bind); } -evtchn_port_or_error_t xenevtchn_bind_interdomain (xenevtchn_handle *xce,int domid, +evtchn_port_or_error_t xenevtchn_bind_interdomain (xenevtchn_handle *xce,uint32_t domid,evtchn_port_t remote_port) {int fd = xce->fd;
Signature · 1 line
2.1.4
Re: [PATCH XEN v8 18/29] tools/libs/evtchn: Use uint32_t for domid arguments
Quoted 1 line · Ian Campbell
Signed-off-by Ian Campbell <[email protected]>
PATCH v8 19/29 tools/libs: Clean up hard tabs.
In reply to Ian CampbellThese were wrong in the context of libxc before this code was extracted, clean them up.
Also add some emacs magic blocks
--- tools/libs/call/buffer.c | 4 ++-- tools/libs/call/core.c | 2 +- tools/libs/call/minios.c | 4 ++-- tools/libs/evtchn/minios.c | 28 ++++++++++++++-------------- tools/libs/evtchn/netbsd.c | 12 ++++++------ tools/libs/foreignmemory/freebsd.c | 2 +- tools/libs/foreignmemory/minios.c | 6 +++--- tools/libs/foreignmemory/netbsd.c | 2 +- tools/libs/foreignmemory/private.h | 2 +- tools/libs/foreignmemory/solaris.c | 12 +++++++++++- tools/libs/gnttab/include/xengnttab.h | 4 ++-- tools/libs/gnttab/linux.c | 6 +++--- tools/libs/toollog/xtl_logger_stdio.c | 2 +- 13 files changed, 48 insertions(+), 38 deletions(-)
tools/libs/call/buffer.c +2 -2
@@ -20,7 +20,7 @@#include "private.h" #define DBGPRINTF(_m...) \ - xtl_log(xcall->logger, XTL_DEBUG, -1, "xencall:buffer", _m) + xtl_log(xcall->logger, XTL_DEBUG, -1, "xencall:buffer", _m)#define ROUNDUP (_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
@@ -86,7 +86,7 @@ static int cache_free(xencall_handle *xcall, void *p, size_t nr_pages) xcall->buffer_current_allocations--;if ( nr_pages ==1 && - xcall->buffer_cache_nr <BUFFER_CACHE_SIZE ) + xcall->buffer_cache_nr <BUFFER_CACHE_SIZE ) { xcall->buffer_cache[xcall->buffer_cache_nr++] = p; rc =1 ;
tools/libs/call/core.c +1 -1
@@ -19,7 +19,7 @@xencall_handle *xencall_open (xentoollog_logger *logger,unsigned open_flags) { -xencall_handle *xcall =malloc (sizeof (*xcall)); +xencall_handle *xcall =malloc (sizeof (*xcall));int rc;if (!xcall)return NULL ;
tools/libs/call/minios.c +2 -2
@@ -50,8 +50,8 @@ int osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall) ret =HYPERVISOR_multicall (&call,1 );if (ret <0 ) { - errno = -ret; -return -1 ; + errno = -ret; +return -1 ; }if ((long ) call.result <0 ) { errno = - (long ) call.result;
tools/libs/evtchn/minios.c +14 -14
@@ -103,8 +103,8 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port) ret =notify_remote_via_evtchn (port);if (ret <0 ) { - errno = -ret; - ret =-1 ; + errno = -ret; + ret =-1 ; }return ret; }
@@ -138,16 +138,16 @@ evtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xce, uint32assert (get_current () == main_thread); port_info =port_alloc (fd);if (port_info ==NULL ) -return -1 ; +return -1 ;printf ("xenevtchn_bind_unbound_port(%d)" , domid); ret =evtchn_alloc_unbound (domid, evtchn_handler, (void *)(intptr_t )fd, &port);printf (" = %d\n" , ret);if (ret <0 ) { -port_dealloc (port_info); - errno = -ret; -return -1 ; +port_dealloc (port_info); + errno = -ret; +return -1 ; } port_info->bound =1 ; port_info->port = port;
@@ -166,16 +166,16 @@ evtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, uint32_assert (get_current () == main_thread); port_info =port_alloc (fd);if (port_info ==NULL ) -return -1 ; +return -1 ;printf ("xenevtchn_bind_interdomain(%d, %" PRId32")" , domid, remote_port); ret =evtchn_bind_interdomain (domid, remote_port, evtchn_handler, (void *)(intptr_t )fd, &local_port);printf (" = %d\n" , ret);if (ret <0 ) { -port_dealloc (port_info); - errno = -ret; -return -1 ; +port_dealloc (port_info); + errno = -ret; +return -1 ; } port_info->bound =1 ; port_info->port = local_port;
@@ -208,15 +208,15 @@ evtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsigned int vassert (get_current () == main_thread); port_info =port_alloc (fd);if (port_info ==NULL ) -return -1 ; +return -1 ;printf ("xenevtchn_bind_virq(%d)" , virq); port =bind_virq (virq, evtchn_handler, (void *)(intptr_t )fd);if (port <0 ) { -port_dealloc (port_info); - errno = -port; -return -1 ; +port_dealloc (port_info); + errno = -port; +return -1 ; } port_info->bound =1 ; port_info->port = port;
tools/libs/evtchn/netbsd.c +6 -6
@@ -72,9 +72,9 @@ evtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle * xce, uint3 ret =ioctl (fd,IOCTL_EVTCHN_BIND_UNBOUND_PORT , &bind);if (ret ==0 ) -return bind.port; +return bind.port;else -return -1 ; +return -1 ; } evtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, uint32_t domid,
@@ -89,9 +89,9 @@ evtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, uint32_ ret =ioctl (fd,IOCTL_EVTCHN_BIND_INTERDOMAIN , &bind);if (ret ==0 ) -return bind.port; +return bind.port;else -return -1 ; +return -1 ; }int xenevtchn_unbind (xenevtchn_handle *xce,evtchn_port_t port)
@@ -114,9 +114,9 @@ evtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsigned int v err =ioctl (fd,IOCTL_EVTCHN_BIND_VIRQ , &bind);if (err) -return -1 ; +return -1 ;else -return bind.port; +return bind.port; }evtchn_port_or_error_t xenevtchn_pending (xenevtchn_handle *xce)
tools/libs/foreignmemory/freebsd.c +1 -1
@@ -121,7 +121,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem,void *addr,size_t num) { -return munmap (addr, num <<PAGE_SHIFT ); +return munmap (addr, num <<PAGE_SHIFT ); }/*
tools/libs/foreignmemory/minios.c +3 -3
@@ -46,16 +46,16 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem, {unsigned long pt_prot =0 ;if (prot &PROT_READ ) - pt_prot =L1_PROT_RO ; + pt_prot =L1_PROT_RO ;if (prot &PROT_WRITE ) - pt_prot =L1_PROT ; + pt_prot =L1_PROT ;return map_frames_ex (arr, num,1 ,0 ,1 , dom, err, pt_prot); }int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem,void *addr,size_t num) { -return munmap (addr, num <<PAGE_SHIFT ); +return munmap (addr, num <<PAGE_SHIFT ); }/*
tools/libs/foreignmemory/netbsd.c +1 -1
@@ -97,7 +97,7 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem,void *addr,size_t num) { -return munmap (addr, num*XC_PAGE_SIZE ); +return munmap (addr, num*XC_PAGE_SIZE ); }/*
tools/libs/foreignmemory/private.h +1 -1
@@ -39,7 +39,7 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,#endif #define PERROR(_f...) \ - xtl_log(fmem->logger, XTL_ERROR, errno, "xenforeignmemory", _f) + xtl_log(fmem->logger, XTL_ERROR, errno, "xenforeignmemory", _f)#endif
tools/libs/foreignmemory/solaris.c +11 -1
@@ -95,5 +95,15 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,int osdep_xenforeignmemory_unmap (xenforeignmemory_handle *fmem,void *addr,size_t num) { -return munmap (addr, num*XC_PAGE_SIZE ); +return munmap (addr, num*XC_PAGE_SIZE ); } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
tools/libs/gnttab/include/xengnttab.h +2 -2
@@ -142,7 +142,7 @@ int xengnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count);* of grants. */ int xengnttab_set_max_grants (xengnttab_handle *xgt, -uint32_t count); +uint32_t count);/* * Grant Sharing Interface (allocating and granting pages)
@@ -160,7 +160,7 @@ typedef struct xengntdev_handle xengntshr_handle;* */ xengntshr_handle *xengntshr_open (xentoollog_logger *logger, -unsigned open_flags); +unsigned open_flags);/* * Close a handle previously allocated with xengntshr_open().
tools/libs/gnttab/linux.c +3 -3
@@ -294,9 +294,9 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs, err =ioctl (fd,IOCTL_GNTALLOC_SET_UNMAP_NOTIFY , ¬ify);if (err) {GSERROR (xgs->logger,"ioctl SET_UNMAP_NOTIFY failed" ); -munmap (area, count *PAGE_SIZE ); - area =NULL ; - } +munmap (area, count *PAGE_SIZE ); + area =NULL ; + }memcpy (refs, gref_info->gref_ids, count *sizeof (uint32_t ));
tools/libs/toollog/xtl_logger_stdio.c +1 -1
@@ -135,7 +135,7 @@ static void stdiostream_progress(struct xentoollog_logger *logger_in, newpel =fprintf (lg->f,"%s%s" "%s: %lu/%lu %3d%%%s" , context?context:"" , context?": " :"" , doing_what, done, total, percent, - done == total ?"\n" :"" ); + done == total ?"\n" :"" ); extra_erase = lg->progress_erase_len - newpel;if (extra_erase >0 )
Signature · 1 line
2.1.4
PATCH v8 20/29 tools/libs/gnttab: Extensive updates to API documentation.
In reply to Ian CampbellIn particular around error handling, behaviour on fork and the unmap notification mechanism.
Behaviour of xengnttab_map_*grant_refs and xengntshr_share_pages on partial failure has been confirmed/inferred (by inspection) on Linux and Mini-os (the only two known implementations. Likewise the behaviour of the notification mechanism has been confirmed/inferred (by inspection) of the Linux implementation (currently the only implementation) and libvchan (primary known user).
These updates are not folded into "tools: Refactor /dev/xen/gnt{dev,shr} wrappers into libxengnttab." to try and reduce the amount of non-movement changes in that patch.
While I'm not convinced by javadoc/doxygen cause the existing comments which appear to use that syntax to have the appropriate /** marker.
Also fix a typo in a code comment.
---
v7: Typo.
Updates based on Ian Jackson's review.
Even more updates to the discussion of forking based on ML discussion.
v6: Rewrapped a comment.
Incorported much review from Ian on the API, retitled (was:
"tools/libs/gnttab: Review and update doc comments.") and dropped acks
--- tools/libs/gnttab/include/xengnttab.h | 201 +++++++++++++++++++++++++++++----- tools/libs/gnttab/linux.c | 12 +- 2 files changed, 181 insertions(+), 32 deletions(-)
tools/libs/gnttab/include/xengnttab.h +174 -27
@@ -31,28 +31,124 @@typedef struct xentoollog_logger xentoollog_logger ;/* +* PRODUCING AND CONSUMING GRANT REFERENCES +* ======================================== +* +* The xengnttab library contains two distinct interfaces, each with +* their own distinct handle type and entry points. The represent the +* two sides of the grant table interface, producer (gntshr) and +* consumer (gnttab). +* +* The xengnttab_* interfaces take a xengnttab_handle and provide +* mechanisms for consuming (i.e. mapping or copying to/from) grant +* references provided by a peer. +* +* The xengntshr_* interfaces take a xengntshr_handle and provide a +* mechanism to produce grantable memory and grant references to that +* memory, which can be handed to some peer. +* +* UNMAP NOTIFICATION +* ================== +* +* The xengnt{tab,shr}_*_notify interfaces implement a cooperative +* interface which is intended to allow the underlying kernel +* interfaces to attempt to notify the peer to perform graceful +* teardown upon failure (i.e. crash or exit) of the process on their +* end. +* +* These interfaces operate on a single page only and are intended for +* use on the main shared-ring page of a protocol. It is assumed that +* on teardown both ends would automatically teardown all grants +* associated with the protocol in addition to the shared ring itself. +* +* Each end is able to optionally nominate a byte offset within the +* shared page or an event channel or both. On exit of the process the +* underlying kernel driver will zero the byte at the given offset and +* signal the event channel. +* +* The event channel can be the same event channel used for regular +* ring progress notifications, or may be a dedicated event channel. +* +* Both ends may share the same notification byte offset within the +* shared page, or may have dedicated "client" and "server" status +* bytes. +* +* Since the byte is cleared on shutdown the protocol must use 0 as +* the "closed/dead" status, but is permitted to use any other non-0 +* values to indicate various other "live" states (waiting for +* connection, connected, etc). +* +* Both ends are permitted to modify (including clear) their +* respective status bytes and to signal the event channel themselves +* from userspace. +* +* Depending on the mechanisms which have been registered an +* the peer may receive a shutdown notification as: +* +* - An event channel notification on a dedicated event channel +* - Observation of the other ends's status byte being cleared +* (whether in response to an explicit notification or in the +* course of normal operation). +* +* The mechanism should be defined as part of the specific ring +* protocol. +* +* Upon receiving notification of the peer is expected to teardown any +* resources (and in particular any grant mappings) in a timely +* manner. +* +* NOTE: this protocol is intended to allow for better error behaviour +* and recovery between two cooperating peers. It does not cover the +* case of a malivious peer who may continue to hold resources open. +*/ + +/* * Grant Table Interface (making use of grants from other domains) */ typedef struct xengntdev_handle xengnttab_handle ;/* -* Note: -* After fork a child process must not use any opened xc gnttab -* handle inherited from their parent. They must open a new handle if -* they want to interact with xc. +* Returns a handle onto the grant table driver. Logs errors. +* +* Note: After fork(2) a child process must not use any opened gnttab +* handle inherited from their parent, nor access any grant mapped +* areas associated with that handle. * -* Return an fd onto the grant table driver. Logs errors. +* The child must open a new handle if they want to interact with +* gnttab. +* +* Calling exec(2) in a child will safely (and reliably) reclaim any +* resources which were allocated via a xengnttab_handle in the parent. +* +* A child which does not call exec(2) may safely call +* xengnttab_close() on a xengnttab_handle inherited from their +* parent. This will attempt to reclaim any resources associated with +* that handle. Note that in some implementations this reclamation may +* not be completely effective, in this case any affected resources +* remain allocated. +* +* Calling xengnttab_close() is the only safe operation on a +* xengnttab_handle which has been inherited. xengnttab_unmap() must +* not be called under such circumstances. */ xengnttab_handle *xengnttab_open (xentoollog_logger *logger,unsigned open_flags);/* -* Close a handle previously allocated with xengnttab_open(). -* Never logs errors. +* Close a handle previously allocated with xengnttab_open(), +* including unmaping any current grant maps. Never logs errors. +* +* Under normal circumstances (i.e. not in the child after a fork) +* xengnttab_unmap() should be used on all mappings allocated through +* a xengnttab_handle prior to closing the handle in order to free up +* resources associated with those mappings. +* +* This is the only function which may be safely called on a +* xengnttab_handle in a child after a fork. */ int xengnttab_close (xengnttab_handle *xgt); -/* +/** * Memory maps a grant reference from one domain to a local address range. * Mappings should be unmapped with xengnttab_unmap. Logs errors. *
@@ -71,6 +167,10 @@ void *xengnttab_map_grant_ref(xengnttab_handle *xgt,* contiguous local address range. Mappings should be unmapped with * xengnttab_unmap. Logs errors. * +* On failure (including partial failure) sets errno and returns +* NULL. On partial failure no mappings are established (any partial +* work is undone). +* * @parm xgt a handle on an open grant table interface * @parm count the number of grant references to be mapped * @parm domids an array of @count domain IDs by which the corresponding @refs
@@ -89,6 +189,9 @@ void *xengnttab_map_grant_refs(xengnttab_handle *xgt,* contiguous local address range. Mappings should be unmapped with * xengnttab_unmap. Logs errors. * +* This call is equivalent to calling @xengnttab_map_grant_refs with a +* @domids array with every entry set to @domid. +* * @parm xgt a handle on an open grant table interface * @parm count the number of grant references to be mapped * @parm domid the domain to map memory from
@@ -109,6 +212,11 @@ void *xengnttab_map_domain_grant_refs(xengnttab_handle *xgt,* unmapped, the byte at the given offset will be zeroed and a wakeup will be * sent to the given event channel. Logs errors. * +* On failure sets errno and returns NULL. +* +* If notify_offset or notify_port are requested and cannot be set up +* an error will be returned and no mapping will be made. +* * @parm xgt a handle on an open grant table interface * @parm domid the domain to map memory from * @parm ref the grant reference ID to map
@@ -124,15 +232,20 @@ void *xengnttab_map_grant_ref_notify(xengnttab_handle *xgt,uint32_t notify_offset, evtchn_port_t notify_port); -/* -* Unmaps the @count pages starting at @start_address, which were mapped by a -* call to xengnttab_map_grant_ref or xengnttab_map_grant_refs. Never logs. +/** +* Unmaps the @count pages starting at @start_address, which were +* mapped by a call to xengnttab_map_grant_ref, +* xengnttab_map_grant_refs or xengnttab_map_grant_ref_notify. Never +* logs. +* +* If the mapping was made using xengnttab_map_grant_ref_notify() with +* either notify_offset or notify_port then the peer will be notified. */ int xengnttab_unmap (xengnttab_handle *xgt,void *start_address,uint32_t count); -/* -* Sets the maximum number of grants that may be mapped by the given instance -* to @count. Never logs. +/** +* Sets the maximum number of grants that may be mapped by the given +* instance to @count. Never logs. * * N.B. This function must be called after opening the handle, and before any * other functions are invoked on it.
@@ -142,22 +255,37 @@ int xengnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count);* of grants. */ int xengnttab_set_max_grants (xengnttab_handle *xgt, -uint32_t count); +uint32_t nr_grants);/* -* Grant Sharing Interface (allocating and granting pages) +* Grant Sharing Interface (allocating and granting pages to others) */ typedef struct xengntdev_handle xengntshr_handle ;/* -* Return an fd onto the grant sharing driver. Logs errors. +* Returns a handle onto the grant sharing driver. Logs errors. +* +* Note: After fork(2) a child process must not use any opened gntshr +* handle inherited from their parent, nor access any grant mapped +* areas associated with that handle. +* +* The child must open a new handle if they want to interact with +* gntshr. * -* Note: -* After fork a child process must not use any opened xc gntshr -* handle inherited from their parent. They must open a new handle if -* they want to interact with xc. +* Calling exec(2) in a child will safely (and reliably) reclaim any +* resources which were allocated via a xengntshr_handle in the +* parent. * +* A child which does not call exec(2) may safely call +* xengntshr_close() on a xengntshr_handle inherited from their +* parent. This will attempt to reclaim any resources associated with +* that handle. Note that in some implementations this reclamation may +* not be completely effective, in this case any affected resources +* remain allocated. +* +* Calling xengntshr_close() is the only safe operation on a +* xengntshr_handle which has been inherited. */ xengntshr_handle *xengntshr_open (xentoollog_logger *logger,unsigned open_flags);
@@ -165,11 +293,26 @@ xengntshr_handle *xengntshr_open(xentoollog_logger *logger,/* * Close a handle previously allocated with xengntshr_open(). * Never logs errors. +* +* Under normal circumstances (i.e. not in the child after a fork) +* xengntshr_unmap() should be used on all mappings allocated through +* a xengnttab_handle prior to closing the handle in order to free up +* resources associated with those mappings. +* +* xengntshr_close() is the only function which may be safely called +* on a xengntshr_handle in a child after a fork. xengntshr_unshare() +* must not be called under such circumstances. */ int xengntshr_close (xengntshr_handle *xgs); -/* -* Creates and shares pages with another domain. +/** +* Allocates and shares pages with another domain. +* +* On failure sets errno and returns NULL. No allocations will be made. +* +* This library only provides functionality for sharing memory +* allocated via this call, memory from elsewhere (malloc, mmap etc) +* cannot be shared here. * * @parm xgs a handle to an open grant sharing instance * @parm domid the domain to share memory with
@@ -181,7 +324,7 @@ int xengntshr_close(xengntshr_handle *xgs);void *xengntshr_share_pages (xengntshr_handle *xgs,uint32_t domid,int count,uint32_t *refs,int writable); -/* +/** * Creates and shares a page with another domain, with unmap notification. * * @parm xgs a handle to an open grant sharing instance
@@ -197,9 +340,13 @@ void *xengntshr_share_page_notify(xengntshr_handle *xgs, uint32_t domid, uint32_t *ref, int writable, uint32_t notify_offset, evtchn_port_t notify_port); -/* -* Unmaps the @count pages starting at @start_address, which were mapped by a -* call to xengntshr_share_*. Never logs. + +/** +* Unmaps the @count pages starting at @start_address, which were +* mapped by a call to xengntshr_share_*. Never logs. +* +* If the mapping was made using xengntshr_share_page_notify() with +* either notify_offset or notify_port then the peer will be notified. */ int xengntshr_unshare (xengntshr_handle *xgs,void *start_address,uint32_t count);
tools/libs/gnttab/linux.c +7 -5
@@ -132,12 +132,14 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt,if (addr ==MAP_FAILED && errno ==EAGAIN ) {/* -* The grant hypercall can return EAGAIN if the granted page is -* swapped out. Since the paging daemon may be in the same domain, the -* hypercall cannot block without causing a deadlock. +* The grant hypercall can return EAGAIN if the granted page +* is swapped out. Since the paging daemon may be in the same +* domain, the hypercall cannot block without causing a +* deadlock. * -* Because there are no notificaitons when the page is swapped in, wait -* a bit before retrying, and hope that the page will arrive eventually. +* Because there are no notifications when the page is swapped +* in, wait a bit before retrying, and hope that the page will +* arrive eventually. */ usleep (1000 ); goto retry;
Signature · 1 line
2.1.4
Re: [PATCH XEN v8 20/29] tools/libs/gnttab: Extensive updates to API documentation.
Quoted 14 lines · Ian Campbell
In particular around error handling, behaviour on fork and the unmap notification mechanism.
Behaviour of xengnttab_map_*grant_refs and
xengntshr_share_pageson partial failure has been confirmed/inferred (by inspection) on Linux and Mini-os (the only two known implementations. Likewise the behaviour of the notification mechanism has been confirmed/inferred (by inspection) of the Linux implementation (currently the only implementation) and libvchan (primary known user).These updates are not folded into "tools: Refactor
/dev/xen/gnt{dev,shr}wrappers into libxengnttab." to try and reduce the amount of non-movement changes in that patch.
Quoted 8 lines
While I'm not convinced by javadoc/doxygen cause the existing comments which appear to use that syntax to have the appropriate /** marker.
Also fix a typo in a code comment.
Signed-off-by Ian Campbell <[email protected]>Reviewed-by Daniel De Graaf <[email protected]>Cc Daniel De Graaf <[email protected]>
Since Daniel and Ian have done in depth review of this so I only skim it this time. It looks sensible to me:
(one typo below)
[...]
Quoted 4 lines
+ *
+ * NOTE: this protocol is intended to allow for better error behaviour
+ * and recovery between two cooperating peers. It does not cover the
+ * case of a malivious peer who may continue to hold resources open.
"malicious"
PATCH v8 21/29 tools/libs/call: Update some log messages to not refer to xc.
In reply to Ian Campbell--- tools/libs/call/linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libs/call/linux.c +2 -2
@@ -94,7 +94,7 @@ void *osdep_alloc_pages(xencall_handle *xcall, size_t npages) p =mmap (NULL , size,PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANONYMOUS |MAP_LOCKED ,-1 ,0 );if ( p ==MAP_FAILED ) { -PERROR ("xc_alloc_hypercall_buffer: mmap failed" ); +PERROR ("alloc_pages: mmap failed" );return NULL ; }
@@ -103,7 +103,7 @@ void *osdep_alloc_pages(xencall_handle *xcall, size_t npages) rc =madvise (p, npages *PAGE_SIZE ,MADV_DONTFORK );if ( rc <0 ) { -PERROR ("xc_alloc_hypercall_buffer: madvise failed" ); +PERROR ("alloc_pages: madvise failed" ); goto out; }
Signature · 1 line
2.1.4
PATCH v8 22/29 tools/libs/call: Describe return values and error semantics for xencall*
In reply to Ian CampbellThis behaviour has been confirmed by inspection on:
- Linux
- NetBSD & FreeBSD (NB: hcall->retval is the hypercall return value only for values >= 0. For negative values the underlying privcmd driver translates the value from Xen to {Net,Free}BSD errno space and returns it as the result of the ioctl, which becomes ret=-1/errno=EFOO in userspace)
- MiniOS (which takes care of errno in this library)
---
v7: Noted NetBSD behaviour
v6: New patch
--- tools/libs/call/include/xencall.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
tools/libs/call/include/xencall.h +15 -0
@@ -46,6 +46,21 @@ int xencall_close(xencall_handle *xcall);/* * Call hypercalls with varying numbers of arguments. +* +* On success the return value of the hypercall is the return value of +* the xencall function. On error these functions set errno and +* return -1. +* +* The errno values will be either: +* - The Xen hypercall error return (from xen/include/public/errno.h) +* translated into the corresponding local value for that POSIX error. +* - An errno value produced by the OS driver or the library +* implementation. Such values may be defined by POSIX or by the OS. +* +* Note that under some circumstances it will not be possible to tell +* whether an error came from Xen or from the OS/library. +* +* These functions never log. */ int xencall0 (xencall_handle *xcall,unsigned int op); int xencall1(xencall_handle *xcall, unsigned int op,
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH v8 23/29 tools/libs/call: Avoid xc_memalign in netbsd and solaris backends
In reply to Ian CampbellThese are already arch specific, so just use the appropriate interfaces (as determined by looking at the xc_memalign backend).
--- tools/libs/call/netbsd.c | 4 ++-- tools/libs/call/solaris.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/libs/call/netbsd.c +2 -2
@@ -74,8 +74,8 @@ void *osdep_alloc_hypercall_buffer(xencall_handle *xcall, size_t npages)size_t size = npages *XC_PAGE_SIZE ;void *p; - p =xc_memalign (xcall,XC_PAGE_SIZE , size); -if (!p) + ret =posix_memalign (&p,XC_PAGE_SIZE , size); +if ( ret !=0 || !p )return NULL ;if (mlock (p, size) <0 )
tools/libs/call/solaris.c +1 -1
@@ -71,7 +71,7 @@ int osdep_xencall_close(xencall_handle *xcall)void *osdep_alloc_hypercall_buffer (xencall_handle *xcall,size_t npages) { -return xc_memalign (xcall,XC_PAGE_SIZE , npages *XC_PAGE_SIZE ); +return memalign (XC_PAGE_SIZE , npages *XC_PAGE_SIZE ); } void osdep_free_hypercall_buffer(xencall_handle *xcall, void *ptr,
Signature · 1 line
2.1.4
PATCH v8 24/29 tools/libs/call: linux: touch newly allocated pages after madvise lockdown
In reply to Ian CampbellThis avoids a potential issue with a fork after allocation but before madvise.
---
v7: New, replacing "tools/libs/call: linux: avoid forking between mmap
and madvise".
--- tools/libs/call/linux.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
tools/libs/call/linux.c +13 -1
@@ -88,7 +88,7 @@ void *osdep_alloc_pages(xencall_handle *xcall, size_t npages) {size_t size = npages *PAGE_SIZE ;void *p; -int rc, saved_errno; +int rc, i, saved_errno;/* Address returned by mmap is page aligned. */ p =mmap (NULL , size,PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANONYMOUS |MAP_LOCKED ,-1 ,0 );
@@ -107,6 +107,18 @@ void *osdep_alloc_pages(xencall_handle *xcall, size_t npages) goto out; } +/* +* Touch each page in turn to force them to be un-CoWed, in case a +* fork happened in another thread at an inopportune moment +* above. The madvise() will prevent any subsequent fork calls from +* causing the same problem. +*/ +for ( i =0 ; i < npages ; i++ ) + { +char *c = (char *)p + (i*PAGE_SIZE ); + *c =0 ; + } +return p; out:
Signature · 1 line
2.1.4
Re: [PATCH XEN v8 24/29] tools/libs/call: linux: touch newly allocated pages after madvise lockdown
tools/libs/call/linux.c
Quoted 15 lines · Ian Campbell
This avoids a potential issue with a fork after allocation but before madvise.
Signed-off-by Ian Campbell <[email protected]>---
v7: New, replacing "tools/libs/call: linux: avoid forking between mmap
and madvise".--- tools/libs/call/linux.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)tools/libs/call/linux.c +0
-0
I didn't notice you only handled this for Linux until now.
I think FreeBSD and NetBSD need similar treatment, too? But then current BSD* code doesn't even support DONTFORK in madvise.
Adding Roger for more input.
The changes in this patch look fine to me.
Wei.
Quoted 31 lines
tools/libs/call/linux.c +13
-1@@ -88,7 +88,7 @@ void *osdep_alloc_pages(xencall_handle *xcall, size_t npages) {size_t size = npages *PAGE_SIZE ;void *p; -int rc, saved_errno; +int rc, i, saved_errno;/* Address returned by mmap is page aligned. */ p =mmap (NULL , size,PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANONYMOUS |MAP_LOCKED ,-1 ,0 );@@ -107,6 +107,18 @@ void *osdep_alloc_pages(xencall_handle *xcall, size_t npages) goto out; } +/* +* Touch each page in turn to force them to be un-CoWed, in case a +* fork happened in another thread at an inopportune moment +* above. The madvise() will prevent any subsequent fork calls from +* causing the same problem. +*/ +for ( i =0 ; i < npages ; i++ ) + { +char *c = (char *)p + (i*PAGE_SIZE ); + *c =0 ; + } +return p; out:Signature · 1 line
2.1.4
Re: [PATCH XEN v8 24/29] tools/libs/call: linux: touch newly allocated pages after madvise lockdown
Quoted 19 lines · Wei Liu
tools/libs/call/linux.c
Quoted 15 lines · Ian Campbell
This avoids a potential issue with a fork after allocation but before madvise.
Signed-off-by Ian Campbell <[email protected]>---
v7: New, replacing "tools/libs/call: linux: avoid forking between mmap and madvise".
---
tools/libs/call/linux.c | 14 +++++++++++++-1 file changed, 13 insertions(+), 1 deletion(-)tools/libs/call/linux.c +0
-0I didn't notice you only handled this for Linux until now.
Quoted 2 lines
I think FreeBSD and NetBSD need similar treatment, too? But then current BSD* code doesn't even support DONTFORK in madvise.
I think any updates to the *BSD side should come as separate improvements.
If they are necessary at all, the Linux stuff comes from Linux making use of particular behaviours on mlock()'s memory (specifically, IIRC, doing things such as THP and NUMA balancing which can cause page faults on the mlock'd pages despite them being locked) which are (possibly) allowed by POSIX, but *BSD may not take the same interpretation.
Quoted 3 lines
Adding Roger for more input.
The changes in this patch look fine to me.
May I take that as an Ack?
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH XEN v8 24/29] tools/libs/call: linux: touch newly allocated pages after madvise lockdown
Quoted 31 lines · Ian Campbell
Quoted 19 lines · Wei Liu
tools/libs/call/linux.c
Quoted 15 lines · Ian Campbell
This avoids a potential issue with a fork after allocation but before madvise.
Signed-off-by Ian Campbell <[email protected]>---
v7: New, replacing "tools/libs/call: linux: avoid forking between mmap and madvise".
---
tools/libs/call/linux.c | 14 +++++++++++++-1 file changed, 13 insertions(+), 1 deletion(-)tools/libs/call/linux.c +0
-0I didn't notice you only handled this for Linux until now.
Quoted 2 lines
I think FreeBSD and NetBSD need similar treatment, too? But then current BSD* code doesn't even support DONTFORK in madvise.
I think any updates to the *BSD side should come as separate improvements.
If they are necessary at all, the Linux stuff comes from Linux making use of particular behaviours on mlock()'s memory (specifically, IIRC, doing things such as THP and NUMA balancing which can cause page faults on the mlock'd pages despite them being locked) which are (possibly) allowed by POSIX, but *BSD may not take the same interpretation.
Quoted 6 lines
Quoted 3 lines
Adding Roger for more input.
The changes in this patch look fine to me.
May I take that as an Ack?
Yes.
Re: [PATCH XEN v8 24/29] tools/libs/call: linux: touch newly allocated pages after madvise lockdown
In reply to Wei LiuEl 19/01/16 a les 14.24, Wei Liu ha escrit:
Quoted 19 lines · Ian Campbell
tools/libs/call/linux.c
Quoted 15 lines
This avoids a potential issue with a fork after allocation but before madvise.
Signed-off-by Ian Campbell <[email protected]>---
v7: New, replacing "tools/libs/call: linux: avoid forking between mmap
and madvise".--- tools/libs/call/linux.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)tools/libs/call/linux.c +0
-0I didn't notice you only handled this for Linux until now.
Quoted 4 lines
I think FreeBSD and NetBSD need similar treatment, too? But then current BSD* code doesn't even support DONTFORK in madvise.
Adding Roger for more input.
Hm, right, thanks for noticing this. I don't think FreeBSD needs a similar treatment (pre-faulting), because mlock will remove any CoW when making the pages wired.
Also, AFAICT we don't need to call madvise or minherit(2) because mlock(2) already takes care of preventing the memory region from being copied to the child on fork:
"Locked mappings are not inherited by the child process after a fork(2)." [0]
So I think we are safe on the FreeBSD side.
Roger.
Re: [PATCH XEN v8 24/29] tools/libs/call: linux: touch newly allocated pages after madvise lockdown
Quoted 29 lines · Roger Pau Monné
El 19/01/16 a les 14.24, Wei Liu ha escrit:
Quoted 19 lines · Ian Campbell
tools/libs/call/linux.c
Quoted 15 lines
This avoids a potential issue with a fork after allocation but before madvise.
Signed-off-by Ian Campbell <[email protected]>---
v7: New, replacing "tools/libs/call: linux: avoid forking between mmap
and madvise".--- tools/libs/call/linux.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)tools/libs/call/linux.c +0
-0I didn't notice you only handled this for Linux until now.
Quoted 4 lines
I think FreeBSD and NetBSD need similar treatment, too? But then current BSD* code doesn't even support DONTFORK in madvise.
Adding Roger for more input.
Hm, right, thanks for noticing this. I don't think FreeBSD needs a similar treatment (pre-faulting), because mlock will remove any CoW when making the pages wired.
Quoted 9 lines
Also, AFAICT we don't need to call madvise or minherit(2) because mlock(2) already takes care of preventing the memory region from being copied to the child on fork:
"Locked mappings are not inherited by the child process after a fork(2)." [0]
So I think we are safe on the FreeBSD side.
But what if the process forks between mmap and mlock? I think that warrants touching the area like we do for Linux here.
Wei.
Quoted 4 lines
Roger.
Re: [PATCH XEN v8 24/29] tools/libs/call: linux: touch newly allocated pages after madvise lockdown
Quoted 38 lines · Wei Liu
Quoted 37 lines · Roger Pau Monné
El 19/01/16 a les 14.24, Wei Liu ha escrit:
Quoted 21 lines · Ian Campbell
tools/libs/call/linux.c
Quoted 17 lines
This avoids a potential issue with a fork after allocation but before
madvise.Signed-off-by Ian Campbell <[email protected]>---
v7: New, replacing "tools/libs/call: linux: avoid forking between mmap
and madvise".
---
tools/libs/call/linux.c | 14 +++++++++++++-1 file changed, 13 insertions(+), 1 deletion(-)tools/libs/call/linux.c +0
-0I didn't notice you only handled this for Linux until now.
Quoted 5 lines
I think FreeBSD and NetBSD need similar treatment, too? But then current
BSD* code doesn't even support DONTFORK in madvise.Adding Roger for more input.
Hm, right, thanks for noticing this. I don't think FreeBSD needs a similar treatment (pre-faulting), because mlock will remove any CoW when
making the pages wired.Also, AFAICT we don't need to call madvise or minherit(2) because mlock(2) already takes care of preventing the memory region from being copied to the child on fork:
Quoted 8 lines
Quoted 5 lines
"Locked mappings are not inherited by the child process after a fork(2)." [0]
So I think we are safe on the FreeBSD side.
But what if the process forks between mmap and mlock? I think that warrants touching the area like we do for Linux here.
mlock guarantees the memory is populated, I think, which is equivalent to touching it.
On Linux we use madvise not mlock, which doesn't make the same claims.
Quoted 1 line
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH XEN v8 24/29] tools/libs/call: linux: touch newly allocated pages after madvise lockdown
Quoted 45 lines · Ian Campbell
Quoted 44 lines · Wei Liu
Quoted 42 lines · Roger Pau Monné
El 19/01/16 a les 14.24, Wei Liu ha escrit:
Quoted 21 lines · Ian Campbell
tools/libs/call/linux.c
Quoted 17 lines
This avoids a potential issue with a fork after allocation but before
madvise.Signed-off-by Ian Campbell <[email protected]>---
v7: New, replacing "tools/libs/call: linux: avoid forking between mmap
and madvise".
---
tools/libs/call/linux.c | 14 +++++++++++++-1 file changed, 13 insertions(+), 1 deletion(-)tools/libs/call/linux.c +0
-0I didn't notice you only handled this for Linux until now.
Quoted 5 lines
I think FreeBSD and NetBSD need similar treatment, too? But then current
BSD* code doesn't even support DONTFORK in madvise.Adding Roger for more input.
Hm, right, thanks for noticing this. I don't think FreeBSD needs a similar treatment (pre-faulting), because mlock will remove any CoW when
making the pages wired.Also, AFAICT we don't need to call madvise or minherit(2) because mlock(2) already takes care of preventing the memory region from being copied to the child on fork:
"Locked mappings are not inherited by the child process after a fork(2)." [0]
So I think we are safe on the FreeBSD side.
Quoted 8 lines
Quoted 2 lines
But what if the process forks between mmap and mlock? I think that warrants touching the area like we do for Linux here.
mlock guarantees the memory is populated, I think, which is equivalent to touching it.
On Linux we use madvise not mlock, which doesn't make the same claims.
I see. I wonder why we didn't use mlock(2) in Linux too in the first place.
Wei.
Quoted 2 lines
Quoted 1 line
Ian.
Re: [PATCH XEN v8 24/29] tools/libs/call: linux: touch newly allocated pages after madvise lockdown
Quoted 3 lines · Wei Liu
I see. I wonder why we didn't use mlock(2) in Linux too in the first place.
We did, but mlock(2) on Linux doesn't guarantee that there will be no page faults, it only guarantees that there will be no page faults which require I/O to satisfy (~= it won't swap the page out).
Some text calls faults which require I/O "major" vs "minor" page faults which don't need I/O to satisfy.
But Linux does things which can result in a supposedly locked PTE being not present or not-writable, which results minor page faults. The main cause of that is CoW due to fork (which affects both the parent and child). Other ones could include being in the middle of moving pages between NUMA nodes (current/source page is R/O) and THP (likewise content moving around).
BSD says (https://www.freebsd.org/cgi/man.cgi?query=mlock):
After an mlock() system call, the indicated pages will cause neither a
non-resident page nor address-translation fault until they are unlocked.
which I think rules out both major and minor faults (i.e. faults of any kind, which is what we need to pass the memory through to Xen).
Using madvise() instead of mlock() on Linux is really just a hack, in that it gets us closer to the semantics we need, but isn't really the same. Really we ought to provide a /dev/xen/foo from which memory can be allocated with the right properties (much like /dev/xen/gntalloc does for grantable memory).
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v8 25/29 tools/libs/{call, evtchn}: Document requirements around forking.
In reply to Ian CampbellMuch like for gnttab and foreignmemory xencall hypercall buffers need care.
Evtchn is a bit simpler (no magic mappings) but may not work from parent + child simultaneously, document "parent only" since it is consistent with the others.
---
v7: New
--- tools/libs/call/include/xencall.h | 28 ++++++++++++++++++++++++++++ tools/libs/evtchn/include/xenevtchn.h | 23 +++++++++++++++++++---- 2 files changed, 47 insertions(+), 4 deletions(-)
tools/libs/call/include/xencall.h +28 -0
@@ -36,11 +36,39 @@ typedef struct xencall_handle xencall_handle;/* * Return a handle onto the hypercall driver. Logs errors. +* * +* Note: After fork(2) a child process must not use any opened +* xencall handle inherited from their parent, nor access any +* hypercall argument buffers associated with that handle. +* +* The child must open a new handle if they want to interact with +* xencall. +* +* Calling exec(2) in a child will safely (and reliably) reclaim any +* resources which were allocated via a xencall_handle in the parent. +* +* A child which does not call exec(2) may safely call xencall_close() +* on a xencall_handle inherited from their parent. This will attempt +* to reclaim any resources associated with that handle. Note that in +* some implementations this reclamation may not be completely +* effective, in this case any affected resources remain allocated. +* +* Calling xencall_close() is the only safe operation on a +* xencall_handle which has been inherited. */ xencall_handle *xencall_open (xentoollog_logger *logger,unsigned open_flags);/* * Close a handle previously allocated with xencall_open(). +* +* Under normal circumstances (i.e. not in the child after a fork) any +* allocated hypercall argument buffers should be freed using the +* appropriate xencall_free_*() prior to closing the handle in order +* to free up resources associated with those mappings. +* +* This is the only function which may be safely called on a +* xencall_handle in a child after a fork. xencall_free_*() must not +* be called under such circumstances. */ int xencall_close (xencall_handle *xcall);
tools/libs/evtchn/include/xenevtchn.h +19 -4
@@ -45,10 +45,25 @@ typedef struct xentoollog_logger xentoollog_logger;* Return a handle to the event channel driver, or NULL on failure, in * which case errno will be set appropriately. * -* Note: -* After fork a child process must not use any opened evtchn -* handle inherited from their parent. They must open a new handle if -* they want to interact with evtchn. +* Note: After fork(2) a child process must not use any opened evtchn +* handle inherited from their parent, nor access any grant mapped +* areas associated with that handle. +* +* The child must open a new handle if they want to interact with +* evtchn. +* +* Calling exec(2) in a child will safely (and reliably) reclaim any +* allocated resources via a xenevtchn_handle in the parent. +* +* A child which does not call exec(2) may safely call +* xenevtchn_close() on a xenevtchn_handle inherited from their +* parent. This will attempt to reclaim any resources associated with +* that handle. Note that in some implementations this reclamation may +* not be completely effective, in this case any affected resources +* remain allocated. +* +* Calling xenevtchn_close() is the only safe operation on a +* xenevtchn_handle which has been inherited. */ /* Currently no flags are defined */ xenevtchn_handle *xenevtchn_open (xentoollog_logger *logger,unsigned open_flags);
Signature · 1 line
2.1.4
Re: [PATCH XEN v8 25/29] tools/libs/{call, evtchn}: Document requirements around forking.
Quoted 8 lines · Ian Campbell
Much like for gnttab and foreignmemory xencall hypercall buffers need care.
Evtchn is a bit simpler (no magic mappings) but may not work from parent + child simultaneously, document "parent only" since it is consistent with the others.
Signed-off-by Ian Campbell <[email protected]>
PATCH v8 26/29 tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD
In reply to Ian CampbellIn some cases this replaces an FD_CLOEXEC dance, in others it is new.
Linux has had O_CLOEXEC since 2.6.23 (October 2007), so we can rely on it from Xen 4.7 I think. Some libc headers may still lack the definition, so we take care of that if need be by defining to 0 (on the premise that such an old glibc might barf on O_CLOEXEC even if the kernel may or may not be so old).
All stable versions of FreeBSD support O_CLOEXEC (10.2, 9.3 and 8.4), and we assume the libc there does too.
Remove various comments about having to take responsibility for this (since really it is just hygiene, politeness, not a requirement) and the reasons for using O_CLOEXEC seem pretty straightforward.
Backends for other OSes are untouched.
---
v6: New
v7: New, replaces "tools/libs/call: Use O_CLOEXEC when opening
/dev/xen/privcmd on Linux"
v8: Define compat O_CLOEXEC of 0.
--- tools/libs/call/freebsd.c | 30 ++++++++---------------------- tools/libs/call/linux.c | 38 +++++++++++--------------------------- tools/libs/evtchn/freebsd.c | 2 +- tools/libs/evtchn/linux.c | 6 +++++- tools/libs/foreignmemory/freebsd.c | 24 ++---------------------- tools/libs/foreignmemory/linux.c | 36 +++++++++--------------------------- tools/libs/gnttab/linux.c | 6 +++++- 7 files changed, 41 insertions(+), 101 deletions(-)
tools/libs/call/freebsd.c +8 -22
@@ -35,8 +35,14 @@int osdep_xencall_open (xencall_handle *xcall) { -int flags, saved_errno; -int fd =open (PRIVCMD_DEV ,O_RDWR ); +int saved_errno; +int fd =open (PRIVCMD_DEV ,O_RDWR |O_CLOEXEC ); + +/* +* This file descriptor is opaque to the caller, thus we are +* polite and try and ensure it doesn't propagate (ie leak) +* outside the process, by using O_CLOEXEC. +*/ if ( fd ==-1 ) {
@@ -45,26 +51,6 @@ int osdep_xencall_open(xencall_handle *xcall)return -1 ; } -/* -* Although we return the file handle as the 'xc handle' the API -* does not specify / guarentee that this integer is in fact -* a file handle. Thus we must take responsiblity to ensure -* it doesn't propagate (ie leak) outside the process. -*/ -if ( (flags =fcntl (fd,F_GETFD )) <0 ) - { -PERROR ("Could not get file handle flags" ); - goto error; - } - - flags |=FD_CLOEXEC ; - -if (fcntl (fd,F_SETFD , flags) <0 ) - { -PERROR ("Could not set file handle flags" ); - goto error; - } - xcall->fd = fd;return 0 ;
tools/libs/call/linux.c +11 -27
@@ -26,15 +26,23 @@#include "private.h" +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif +int osdep_xencall_open (xencall_handle *xcall) { -int flags, saved_errno; -int fd =open ("/dev/xen/privcmd" ,O_RDWR );/* prefer this newer interface */ +int fd; + +/* +* Prefer the newer interface. +*/ + fd =open ("/dev/xen/privcmd" ,O_RDWR |O_CLOEXEC );if ( fd ==-1 && ( errno ==ENOENT || errno ==ENXIO || errno ==ENODEV )) {/* Fallback to /proc/xen/privcmd */ - fd =open ("/proc/xen/privcmd" ,O_RDWR ); + fd =open ("/proc/xen/privcmd" ,O_RDWR |O_CLOEXEC ); }if ( fd ==-1 )
@@ -43,32 +51,8 @@ int osdep_xencall_open(xencall_handle *xcall)return -1 ; } -/* Although we return the file handle as the 'xc handle' the API -does not specify / guarentee that this integer is in fact -a file handle. Thus we must take responsiblity to ensure -it doesn't propagate (ie leak) outside the process */ -if ( (flags =fcntl (fd,F_GETFD )) <0 ) - { -PERROR ("Could not get file handle flags" ); - goto error; - } - - flags |=FD_CLOEXEC ; - -if (fcntl (fd,F_SETFD , flags) <0 ) - { -PERROR ("Could not set file handle flags" ); - goto error; - } - xcall->fd = fd;return 0 ; - - error: - saved_errno = errno; -close (fd); - errno = saved_errno; -return -1 ; }int osdep_xencall_close (xencall_handle *xcall)
tools/libs/evtchn/freebsd.c +1 -1
@@ -32,7 +32,7 @@int osdep_evtchn_open (xenevtchn_handle *xce) { -int fd =open (EVTCHN_DEV ,O_RDWR ); +int fd =open (EVTCHN_DEV ,O_RDWR |O_CLOEXEC );if ( fd ==-1 )return -1 ; xce->fd = fd;
tools/libs/evtchn/linux.c +5 -1
@@ -28,9 +28,13 @@#include "private.h" +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif +int osdep_evtchn_open (xenevtchn_handle *xce) { -int fd =open ("/dev/xen/evtchn" ,O_RDWR ); +int fd =open ("/dev/xen/evtchn" ,O_RDWR |O_CLOEXEC );if ( fd ==-1 )return -1 ; xce->fd = fd;
tools/libs/foreignmemory/freebsd.c +2 -22
@@ -33,8 +33,8 @@int osdep_xenforeignmemory_open (xenforeignmemory_handle *fmem) { -int flags, saved_errno; -int fd =open (PRIVCMD_DEV ,O_RDWR ); +int saved_errno; +int fd =open (PRIVCMD_DEV ,O_RDWR |O_CLOEXEC );if ( fd ==-1 ) {
@@ -43,26 +43,6 @@ int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)return -1 ; } -/* -* Although we return the file handle as the 'xc handle' the API -* does not specify / guarentee that this integer is in fact -* a file handle. Thus we must take responsiblity to ensure -* it doesn't propagate (ie leak) outside the process. -*/ -if ( (flags =fcntl (fd,F_GETFD )) <0 ) - { -PERROR ("Could not get file handle flags" ); - goto error; - } - - flags |=FD_CLOEXEC ; - -if (fcntl (fd,F_SETFD , flags) <0 ) - { -PERROR ("Could not set file handle flags" ); - goto error; - } - fmem->fd = fd;return 0 ;
tools/libs/foreignmemory/linux.c +9 -27
@@ -30,15 +30,21 @@#define ROUNDUP (_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif +int osdep_xenforeignmemory_open (xenforeignmemory_handle *fmem) { -int flags, saved_errno; -int fd =open ("/dev/xen/privcmd" ,O_RDWR );/* prefer this newer interface */ +int fd; + +/* prefer this newer interface */ + fd =open ("/dev/xen/privcmd" ,O_RDWR |O_CLOEXEC );if ( fd ==-1 && ( errno ==ENOENT || errno ==ENXIO || errno ==ENODEV )) {/* Fallback to /proc/xen/privcmd */ - fd =open ("/proc/xen/privcmd" ,O_RDWR ); + fd =open ("/proc/xen/privcmd" ,O_RDWR |O_CLOEXEC ); }if ( fd ==-1 )
@@ -47,32 +53,8 @@ int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)return -1 ; } -/* Although we return the file handle as the 'xc handle' the API -does not specify / guarentee that this integer is in fact -a file handle. Thus we must take responsiblity to ensure -it doesn't propagate (ie leak) outside the process */ -if ( (flags =fcntl (fd,F_GETFD )) <0 ) - { -PERROR ("Could not get file handle flags" ); - goto error; - } - - flags |=FD_CLOEXEC ; - -if (fcntl (fd,F_SETFD , flags) <0 ) - { -PERROR ("Could not set file handle flags" ); - goto error; - } - fmem->fd = fd;return 0 ; - - error: - saved_errno = errno; -close (fd); - errno = saved_errno; -return -1 ; }int osdep_xenforeignmemory_close (xenforeignmemory_handle *fmem)
tools/libs/gnttab/linux.c +5 -1
@@ -43,9 +43,13 @@#define PAGE_SIZE (1UL << PAGE_SHIFT)#define PAGE_MASK (~(PAGE_SIZE-1)) +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif +int osdep_gnttab_open (xengnttab_handle *xgt) { -int fd =open (DEVXEN "gntdev" ,O_RDWR ); +int fd =open (DEVXEN "gntdev" ,O_RDWR |O_CLOEXEC );if ( fd ==-1 )return -1 ; xgt->fd = fd;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH XEN v8 26/29] tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD
Quoted 11 lines · Ian Campbell
In some cases this replaces an
FD_CLOEXECdance, in others it is new.Linux has had
O_CLOEXECsince 2.6.23 (October 2007), so we can rely on it from Xen 4.7 I think. Some libc headers may still lack the definition, so we take care of that if need be by defining to 0 (on the premise that such an old glibc might barf onO_CLOEXECeven if the kernel may or may not be so old).All stable versions of FreeBSD support
O_CLOEXEC(10.2, 9.3 and 8.4), and we assume the libc there does too.
Quoted 8 lines
Remove various comments about having to take responsibility for this (since really it is just hygiene, politeness, not a requirement) and the reasons for using
O_CLOEXECseem pretty straightforward.Backends for other OSes are untouched.
Signed-off-by Ian Campbell <[email protected]>Acked-by Roger Pau Monné <[email protected]>
PATCH v8 27/29 tools: Update CFLAGS for qemu-xen to allow it to use new libraries
In reply to Ian CampbellThis means adding -L for libxen{evtchn,gnttab,foreignmemory} so that it can link them directly (rather than using the libxenctrl compat layer exposed via -rpath-link). Also add -I for libxenforeignmemory.
--- tools/Makefile | 4 ++++ 1 file changed, 4 insertions(+)
tools/Makefile +4 -0
@@ -255,12 +255,16 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find -I$(XEN_ROOT)/tools/libs/toollog/include \ -I$(XEN_ROOT)/tools/libs/evtchn/include \ -I$(XEN_ROOT)/tools/libs/gnttab/include \ + -I$(XEN_ROOT)/tools/libs/foreignmemory/include \ -I$(XEN_ROOT)/tools/libxc/include \ -I$(XEN_ROOT)/tools/xenstore/include \ -I$(XEN_ROOT)/tools/xenstore/compat/include \ $(EXTRA_CFLAGS_QEMU_XEN)" \ --extra-ldflags="-L$(XEN_ROOT)/tools/libxc \ -L$(XEN_ROOT)/tools/xenstore \ + -L$(XEN_ROOT)/tools/libs/evtchn \ + -L$(XEN_ROOT)/tools/libs/gnttab \ + -L$(XEN_ROOT)/tools/libs/foreignmemory \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \ -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
Signature · 1 line
2.1.4
PATCH v8 28/29 tools/libs/*: Introduce APIs to restrict handles to a specific domain.
In reply to Ian CampbellThese are intended to allow user space processes (in particular QEMU) to lock down all the handles at start of day and then drop the privileges which would allow them to open any new unrestricted handles (e.g. setuid or similar). This will reduce the privileges which taking over such a process would gain an attacker wrt other domains in the system.
These are currently unimplemented on all platforms, however the API semantics are defined as the basis for discussion, and so that consumers can rely on this interface always having been present rather than requiring compile time API checks.
It is expected that these will be implemented by adding new ioctl calls on the underlying driver and that the restrictions will be enforced at the kernel interface layer (most likely by the kernel itself).
For evtchn, foreignmemory, gnttab and gntshr this is hopefully reasonably straightforward.
For call it is not so clear cut. Clearly the kernel cannot enforce these restrictions for hypercalls which are not stable (domctl et al) so they can never be on the whitelist. It may also be that potential users would like to restrict the handle further than just a given target domain, i.e. to a specific set of functionality (e.g. "things a device model might reasonably do"). I think we will also need some way to discover whether a given set of interfaces is available to a restricted handle, in order to support the addition of new functionality.
Notes:
- On many (all?) platforms libxencall and libxenforeignmemory are implemented by the same underlying privcmd driver. The platform level ioctl interface should support restricting the handle to only one or the other.
- On platforms with multiple privilege mapping ioctl variants should consider only allowing the newest/currently preferred one on a restricted handle. e.g. on Linux this would allow IOCTL_PRIVCMD_MMAPBATCH_V2 but not IOCTL_PRIVCMD_MMAPBATCH. (Of course any subsequently introduced _V3 would be subject to compatibility concerns)
---
v8: New
This applies on top of the Xen portion of "Begin to disentangle libxenctrl and provide some stable libraries", v7, plus a couple of minor fixes which will be in v8. All of this can be found in the "vwip" branch of the tree referenced by that series atgit://xenbits.xen.org/people/ianc/libxenctrl-split/xen.git.
--- tools/libs/call/core.c | 7 +++ tools/libs/call/include/xencall.h | 34 ++++++++++++++ tools/libs/call/libxencall.map | 2 + tools/libs/evtchn/core.c | 7 +++ tools/libs/evtchn/include/xenevtchn.h | 36 +++++++++++++++ tools/libs/evtchn/libxenevtchn.map | 2 + tools/libs/foreignmemory/core.c | 7 +++ .../libs/foreignmemory/include/xenforeignmemory.h | 22 +++++++++ tools/libs/foreignmemory/libxenforeignmemory.map | 3 ++ tools/libs/gnttab/gntshr_core.c | 8 ++++ tools/libs/gnttab/gnttab_core.c | 7 +++ tools/libs/gnttab/include/xengnttab.h | 52 ++++++++++++++++++++++ tools/libs/gnttab/libxengnttab.map | 8 +++- 13 files changed, 193 insertions(+), 2 deletions(-)
tools/libs/call/core.c +7 -0
@@ -14,6 +14,7 @@*/ #include <stdlib.h> +#include <errno.h> #include "private.h"
@@ -70,6 +71,12 @@ int xencall_close(xencall_handle *xcall)return rc; } +int xencall_restrict_target (xencall_handle *xcall,uint32_t domid) +{ + errno =ENOSYS ; +return -1 ; +} +int xencall0 (xencall_handle *xcall,unsigned int op) {privcmd_hypercall_t call = {
tools/libs/call/include/xencall.h +34 -0
@@ -73,6 +73,40 @@ xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags);int xencall_close (xencall_handle *xcall);/* +* Attempt to restrict the given xcall handle to only be able to +* target the given domain. +* +* On success returns 0, after which only hypercalls which are on a +* platform specific whitelist can be called and the arguments will be +* audited by the platform to ensure that the target domain is +* domid. +* +* Subsequent attempts to call any hypercall not on the platform +* specific whitelist will return -1 setting errno to ENOSYS. +* +* Subsequent attempts to call any hypercall on the platform specific +* whitelist with any other target domain return -1 setting errno to +* EPERM. +* +* These restrictions will be implemented by the platform in a way +* which cannot be circumvented by a userspace process. Further +* privilege drops (such as using setuid(2) etc) may also be required +* to prevent a compromised process from simply opening a second +* handle +* +* XXX which hypercalls are restricted, per platform list, do we need +* a way to probe? Do we want to be able to restrict to particular +* subsets of whitelisted hypercalls? +* +* On failure returns -1 and sets errno: +* ENOSYS: The platform is not able to support restricting the +* target domain. +* Other: The platform should be able to support restricting the +* target domain, but was unable to do so. +*/ +int xencall_restrict_target (xencall_handle *xcall,uint32_t domid); + +/* * Call hypercalls with varying numbers of arguments. * * On success the return value of the hypercall is the return value of
tools/libs/call/libxencall.map +2 -0
@@ -3,6 +3,8 @@ VERS_1.0 { xencall_open; xencall_close; + xencall_restrict_target; + xencall0; xencall1; xencall2;
tools/libs/evtchn/core.c +7 -0
@@ -15,6 +15,7 @@#include <unistd.h> #include <stdlib.h> +#include <errno.h> #include "private.h"
@@ -61,6 +62,12 @@ int xenevtchn_close(xenevtchn_handle *xce)return rc; } +int xenevtchn_restrict_target (xenevtchn_handle *xce,uint32_t domid) +{ + errno =ENOSYS ; +return -1 ; +} +/* * Local variables: * mode: C
tools/libs/evtchn/include/xenevtchn.h +36 -0
@@ -74,6 +74,42 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags)int xenevtchn_close (xenevtchn_handle *xce);/* +* Attempt to restrict the given evtchn handle to only operate on the +* given domain. +* +* On success returns 0, after which: +* +* - Any operations which take a peer domain as an argument can only +* be called with the specified target domain. Subsequent attempts +* to call any such interface with another domain will return -1 +* setting errno to EPERM. +* +* - Any operations which take an evtchn_port_t are not restricted +* other than by the requirement to have previously bound that +* evtchn to the handle. Therefore users of the restrict interface +* should take care not to bind any event channels relating to other +* domains prior to enforcing the restriction. The restrictions on +* xenevtchn_bind_*() (which take a domain id, see previous point) +* suffice to prevent any new such bindings being created. +* +* - xenevtchn_bind_virq is not permitted and will return -1 setting +* errno to EPERM. +* +* These restrictions will be implemented by the platform in a way +* which cannot be circumvented by a userspace process. Further +* privilege drops (such as using setuid(2) etc) may also be required +* to prevent a compromised process from simply opening a second +* handle +* +* On failure returns -1 and sets errno: +* ENOSYS: The platform is not able to support restricting the +* target domain. +* Other: The platform should be able to support restricting the +* target domain, but was unable to do so. +*/ +int xenevtchn_restrict_target (xenevtchn_handle *xce,uint32_t domid); + +/* * Return an fd that can be select()ed on. * * Note that due to bugs, setting this fd to non blocking may not
tools/libs/evtchn/libxenevtchn.map +2 -0
@@ -3,6 +3,8 @@ VERS_1.0 { xenevtchn_open; xenevtchn_close; + xenevtchn_restrict_target; + xenevtchn_fd; xenevtchn_bind_unbound_port;
tools/libs/foreignmemory/core.c +7 -0
@@ -62,6 +62,13 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem)return rc; } +int xenforeignmemory_restrict_target (xenforeignmemory_handle *fmem, +uint32_t domid) +{ + errno =ENOSYS ; +return -1 ; +} + void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom, int prot, size_t num,
tools/libs/foreignmemory/include/xenforeignmemory.h +22 -0
@@ -74,6 +74,28 @@ xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,int xenforeignmemory_close (xenforeignmemory_handle *fmem);/* +* Attempt to restrict the given handle to only target the given +* domain. +* +* On success returns 0, after which calls to xenforeignmemory_map +* which pass a domain other than the given domain will return -1 +* setting errno to EPERM. +* +* This restriction will be implemented by the platform in a way which +* cannot be circumvented by a userspace process. Further privilege +* drops (such as using setuid(2) etc) may also be required to prevent +* a compromised process from simply opening a second handle +* +* On failure returns -1 and sets errno: +* ENOSYS: The platform is not able to support restricting the +* target domain. +* Other: The platform should be able to support restricting the +* target domain, but was unable to do so. +*/ +int xenforeignmemory_restrict_target (xenforeignmemory_handle *fmem, +uint32_t domid); + +/* * Maps a range within one domain to a local address range. Mappings * must be unmapped with xenforeignmemory_unmap and should follow the * same rules as mmap regarding page alignment.
tools/libs/foreignmemory/libxenforeignmemory.map +3 -0
@@ -2,6 +2,9 @@ VERS_1.0 { global: xenforeignmemory_open; xenforeignmemory_close; + + xenforeignmemory_restrict_target; + xenforeignmemory_map; xenforeignmemory_unmap; local: *; /* Do not expose anything by default */
tools/libs/gnttab/gntshr_core.c +8 -0
@@ -19,6 +19,7 @@*/ #include <stdlib.h> +#include <errno.h> #include "private.h"
@@ -64,6 +65,13 @@ int xengntshr_close(xengntshr_handle *xgs)free (xgs);return rc; } + +int xengntshr_restrict_target (xengntshr_handle *xgs,uint32_t domid) +{ + errno =ENOSYS ; +return -1 ; +} +void *xengntshr_share_pages (xengntshr_handle *xcg,uint32_t domid,int count,uint32_t *refs,int writable) {
tools/libs/gnttab/gnttab_core.c +7 -0
@@ -19,6 +19,7 @@*/ #include <stdlib.h> +#include <errno.h> #include "private.h"
@@ -65,6 +66,12 @@ int xengnttab_close(xengnttab_handle *xgt)return rc; } +int xengnttab_restrict_target (xengnttab_handle *xgt,uint32_t domid) +{ + errno =ENOSYS ; +return -1 ; +} +int xengnttab_set_max_grants (xengnttab_handle *xgt,uint32_t count) {return osdep_gnttab_set_max_grants (xgt, count);
tools/libs/gnttab/include/xengnttab.h +52 -0
64 lines not on this page · raw message
tools/libs/gnttab/libxengnttab.map +6 -2
@@ -3,6 +3,8 @@ VERS_1.0 { xengnttab_open; xengnttab_close; + xengnttab_restrict_target; + xengnttab_set_max_grants; xengnttab_map_domain_grant_refs;
@@ -11,10 +13,12 @@ VERS_1.0 { xengnttab_map_grant_refs; xengnttab_unmap; - + xengntshr_open; xengntshr_close; - + + xengntshr_restrict_target; + xengntshr_share_page_notify; xengntshr_share_pages;
Signature · 1 line
2.1.4
Re: [PATCH XEN v8 28/29] tools/libs/*: Introduce APIs to restrict handles to a specific domain.
Quoted 30 lines · Ian Campbell
These are intended to allow user space processes (in particular QEMU) to lock down all the handles at start of day and then drop the privileges which would allow them to open any new unrestricted handles (e.g. setuid or similar). This will reduce the privileges which taking over such a process would gain an attacker wrt other domains in the system.
These are currently unimplemented on all platforms, however the API semantics are defined as the basis for discussion, and so that consumers can rely on this interface always having been present rather than requiring compile time API checks.
It is expected that these will be implemented by adding new ioctl calls on the underlying driver and that the restrictions will be enforced at the kernel interface layer (most likely by the kernel itself).
For evtchn, foreignmemory, gnttab and gntshr this is hopefully reasonably straightforward.
For call it is not so clear cut. Clearly the kernel cannot enforce these restrictions for hypercalls which are not stable (domctl et al) so they can never be on the whitelist. It may also be that potential users would like to restrict the handle further than just a given target domain, i.e. to a specific set of functionality (e.g. "things a device model might reasonably do"). I think we will also need some way to discover whether a given set of interfaces is available to a restricted handle, in order to support the addition of new functionality.
Quoted 6 lines
Notes:
- On many (all?) platforms libxencall and libxenforeignmemory are implemented by the same underlying privcmd driver. The platform level ioctl interface should support restricting the handle to only one or the other.
IIRC mini-os doesn't have ioctl. That would require some special handling -- if we want to use the new API in qemu-trad, too. We shall cross the bridge when we get there.
Quoted 8 lines
- On platforms with multiple privilege mapping ioctl variants should consider only allowing the newest/currently preferred one on a restricted handle. e.g. on Linux this would allow
IOCTL_PRIVCMD_MMAPBATCH_V2but notIOCTL_PRIVCMD_MMAPBATCH. (Of course any subsequently introduced_V3would be subject to compatibility concerns)Signed-off-by Ian Campbell <[email protected]>
[...]
Quoted 18 lines
/*
+ * Attempt to restrict the given xcall handle to only be able to
+ * target the given domain.
+ *
+ * On success returns 0, after which only hypercalls which are on a
+ * platform specific whitelist can be called and the arguments will be
+ * audited by the platform to ensure that the target domain is
+ * domid.
+ *
+ * Subsequent attempts to call any hypercall not on the platform
+ * specific whitelist will return -1 setting errno to ENOSYS.
+ *
+ * Subsequent attempts to call any hypercall on the platform specific
+ * whitelist with any other target domain return -1 setting errno to
+ * EPERM.
+ *
+ * These restrictions will be implemented by the platform in a way
+ * which cannot be circumvented by a userspace process. Further
Quoted 8 lines
+ * privilege drops (such as using setuid(2) etc) may also be required
+ * to prevent a compromised process from simply opening a second
+ * handle
+ *
+ * XXX which hypercalls are restricted, per platform list, do we need
+ * a way to probe? Do we want to be able to restrict to particular
+ * subsets of whitelisted hypercalls?
+ *
TBH given the semantics of this call is not yet clear I don't think we should rush committing this interface.
Wei.
Re: [PATCH XEN v8 28/29] tools/libs/*: Introduce APIs to restrict handles to a specific domain.
Quoted 33 lines · Wei Liu
Quoted 32 lines · Ian Campbell
These are intended to allow user space processes (in particular QEMU) to lock down all the handles at start of day and then drop the privileges which would allow them to open any new unrestricted handles (e.g. setuid or similar). This will reduce the privileges which taking over such a process would gain an attacker wrt other domains in the system.
These are currently unimplemented on all platforms, however the API semantics are defined as the basis for discussion, and so that consumers can rely on this interface always having been present rather than requiring compile time API checks.
It is expected that these will be implemented by adding new ioctl calls on the underlying driver and that the restrictions will be enforced at the kernel interface layer (most likely by the kernel itself).
For evtchn, foreignmemory, gnttab and gntshr this is hopefully reasonably straightforward.
For call it is not so clear cut. Clearly the kernel cannot enforce these restrictions for hypercalls which are not stable (domctl et al) so they can never be on the whitelist. It may also be that potential users would like to restrict the handle further than just a given target domain, i.e. to a specific set of functionality (e.g. "things a device model might reasonably do"). I think we will also need some way to discover whether a given set of interfaces is available to a restricted handle, in order to support the addition of new functionality.
Notes:
Quoted 7 lines
Quoted 4 lines
- On many (all?) platforms libxencall and libxenforeignmemory are implemented by the same underlying privcmd driver. The platform level ioctl interface should support restricting the handle to only one or the other.
IIRC mini-os doesn't have ioctl. That would require some special handling
The actual implementation of this functionality would be OS specific and therefore need to be in $os.c, where mini-os.c is under no obligation to use an ioctl if it doesn't want to.
The only reason it is done in the common code here is to avoid adding a dozen stubs prior to even one OS actually implementing this. I could add a norestrict.c to each lib, put the stub there and link it on all platforms, that would reduce the churn when someone comes to add the actual functionality.
Quoted 39 lines
-- if we want to use the new API in qemu-trad, too.
We shall cross the bridge when we get there.Quoted 8 lines
- On platforms with multiple privilege mapping ioctl variants should consider only allowing the newest/currently preferred one on a restricted handle. e.g. on Linux this would allow
IOCTL_PRIVCMD_MMAPBATCH_V2but notIOCTL_PRIVCMD_MMAPBATCH. (Of course any subsequently introduced_V3would be subject to compatibility concerns)Signed-off-by Ian Campbell <[email protected]>[...]
Quoted 18 lines
/*
+ * Attempt to restrict the given xcall handle to only be able to
+ * target the given domain.
+ *
+ * On success returns 0, after which only hypercalls which are on a
+ * platform specific whitelist can be called and the arguments will be
+ * audited by the platform to ensure that the target domain is
+ * domid.
+ *
+ * Subsequent attempts to call any hypercall not on the platform
+ * specific whitelist will return -1 setting errno to ENOSYS.
+ *
+ * Subsequent attempts to call any hypercall on the platform specific
+ * whitelist with any other target domain return -1 setting errno to
+ * EPERM.
+ *
+ * These restrictions will be implemented by the platform in a way
+ * which cannot be circumvented by a userspace process. FurtherQuoted 8 lines
+ * privilege drops (such as using setuid(2) etc) may also be required
+ * to prevent a compromised process from simply opening a second
+ * handle
+ *
+ * XXX which hypercalls are restricted, per platform list, do we need
+ * a way to probe? Do we want to be able to restrict to particular
+ * subsets of whitelisted hypercalls?
+ *
Quoted 2 lines
TBH given the semantics of this call is not yet clear I don't think we should rush committing this interface.
The intention was to try and get enough confidence that we could include the call in the initial implementation such that applications could unconditionally use it in the future.
If we can't manage a sufficient level of confidence in the proposed interface then we should skip it for now of course.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH XEN v8 28/29] tools/libs/*: Introduce APIs to restrict handles to a specific domain.
Quoted 46 lines · Ian Campbell
Quoted 33 lines · Wei Liu
Quoted 32 lines · Ian Campbell
These are intended to allow user space processes (in particular QEMU) to lock down all the handles at start of day and then drop the privileges which would allow them to open any new unrestricted handles (e.g. setuid or similar). This will reduce the privileges which taking over such a process would gain an attacker wrt other domains in the system.
These are currently unimplemented on all platforms, however the API semantics are defined as the basis for discussion, and so that consumers can rely on this interface always having been present rather than requiring compile time API checks.
It is expected that these will be implemented by adding new ioctl calls on the underlying driver and that the restrictions will be enforced at the kernel interface layer (most likely by the kernel itself).
For evtchn, foreignmemory, gnttab and gntshr this is hopefully reasonably straightforward.
For call it is not so clear cut. Clearly the kernel cannot enforce these restrictions for hypercalls which are not stable (domctl et al) so they can never be on the whitelist. It may also be that potential users would like to restrict the handle further than just a given target domain, i.e. to a specific set of functionality (e.g. "things a device model might reasonably do"). I think we will also need some way to discover whether a given set of interfaces is available to a restricted handle, in order to support the addition of new functionality.
Notes:
Quoted 7 lines
Quoted 4 lines
- On many (all?) platforms libxencall and libxenforeignmemory are implemented by the same underlying privcmd driver. The platform level ioctl interface should support restricting the handle to only one or the other.
IIRC mini-os doesn't have ioctl. That would require some special handling
The actual implementation of this functionality would be OS specific and therefore need to be in $os.c, where
mini-os.cis under no obligation to use an ioctl if it doesn't want to.
Quoted 6 lines
The only reason it is done in the common code here is to avoid adding a dozen stubs prior to even one OS actually implementing this. I could add a
norestrict.cto each lib, put the stub there and link it on all platforms, that would reduce the churn when someone comes to add the actual functionality.
I don't think you need to do that. Doing this in common code is fine by me.
Quoted 42 lines
Quoted 39 lines
-- if we want to use the new API in qemu-trad, too.
We shall cross the bridge when we get there.Quoted 8 lines
- On platforms with multiple privilege mapping ioctl variants should consider only allowing the newest/currently preferred one on a restricted handle. e.g. on Linux this would allow
IOCTL_PRIVCMD_MMAPBATCH_V2but notIOCTL_PRIVCMD_MMAPBATCH. (Of course any subsequently introduced_V3would be subject to compatibility concerns)Signed-off-by Ian Campbell <[email protected]>[...]
Quoted 18 lines
/*
+ * Attempt to restrict the given xcall handle to only be able to
+ * target the given domain.
+ *
+ * On success returns 0, after which only hypercalls which are on a
+ * platform specific whitelist can be called and the arguments will be
+ * audited by the platform to ensure that the target domain is
+ * domid.
+ *
+ * Subsequent attempts to call any hypercall not on the platform
+ * specific whitelist will return -1 setting errno to ENOSYS.
+ *
+ * Subsequent attempts to call any hypercall on the platform specific
+ * whitelist with any other target domain return -1 setting errno to
+ * EPERM.
+ *
+ * These restrictions will be implemented by the platform in a way
+ * which cannot be circumvented by a userspace process. FurtherQuoted 8 lines
+ * privilege drops (such as using setuid(2) etc) may also be required
+ * to prevent a compromised process from simply opening a second
+ * handle
+ *
+ * XXX which hypercalls are restricted, per platform list, do we need
+ * a way to probe? Do we want to be able to restrict to particular
+ * subsets of whitelisted hypercalls?
+ *Quoted 2 lines
TBH given the semantics of this call is not yet clear I don't think we should rush committing this interface.
Quoted 7 lines
The intention was to try and get enough confidence that we could include the call in the initial implementation such that applications could unconditionally use it in the future.
If we can't manage a sufficient level of confidence in the proposed interface then we should skip it for now of course.
Let's see what other people think about this particular function.
Wei.
Quoted 1 line
Ian.
PATCH v8 29/29 HACK: Update Config.mk to pull all the right bits from my xenbits trees
In reply to Ian Campbellv4: Config.mk instead of .config
--- Config.mk | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
Config.mk +11 -11
@@ -238,22 +238,22 @@ endif ifeq ($(GIT_HTTP),y) OVMF_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/ovmf.git -QEMU_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/qemu-xen.git -QEMU_TRADITIONAL_URL ?= http://xenbits.xen.org/git-http/qemu-xen-traditional.git +QEMU_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/people/ianc/libxenctrl-split/qemu-xen.git +QEMU_TRADITIONAL_URL ?= http://xenbits.xen.org/git-http/people/ianc/libxenctrl-split/qemu-xen-traditional.git SEABIOS_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/seabios.git -MINIOS_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/mini-os.git +MINIOS_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/people/ianc/libxenctrl-split/mini-os.git else OVMF_UPSTREAM_URL ?= git://xenbits.xen.org/ovmf.git -QEMU_UPSTREAM_URL ?= git://xenbits.xen.org/qemu-xen.git -QEMU_TRADITIONAL_URL ?= git://xenbits.xen.org/qemu-xen-traditional.git +QEMU_UPSTREAM_URL ?= git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen.git +QEMU_TRADITIONAL_URL ?= git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen-traditional.git SEABIOS_UPSTREAM_URL ?= git://xenbits.xen.org/seabios.git -MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/mini-os.git +MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/people/ianc/libxenctrl-split/mini-os.git endif OVMF_UPSTREAM_REVISION ?= 52a99493cce88a9d4ec8a02d7f1bd1a1001ce60d -QEMU_UPSTREAM_REVISION ?= master -MINIOS_UPSTREAM_REVISION ?= d25773c8afa2f4dbbb466116daeb60159ddd22bd -# Thu Dec 3 11:23:25 2015 +0000 -# mini-os: Include libxentoollog with libxc +QEMU_UPSTREAM_REVISION ?= origin/v8 +MINIOS_UPSTREAM_REVISION ?= origin/v8 +# Mon Nov 23 16:34:31 2015 +0000 +# Add a .gitignore SEABIOS_UPSTREAM_REVISION ?= 3403ac4313812752be6e6aac35239ca6888a8cab # Mon Dec 28 13:50:41 2015 +0100
@@ -262,7 +262,7 @@ SEABIOS_UPSTREAM_REVISION ?= 3403ac4313812752be6e6aac35239ca6888a8cab ETHERBOOT_NICS ?= rtl8139 8086100e -QEMU_TRADITIONAL_REVISION ?= 569eac99e8ddccd15fe78e8a3af5622afe780e3b +QEMU_TRADITIONAL_REVISION ?= origin/v8 # Mon Jan 4 15:34:29 2016 +0000 # MSI-X: avoid array overrun upon MSI-X table writes
Signature · 1 line
2.1.4
v8 cover Begin to disentangle libxenctrl and provide some stable libraries
In reply to Ian CampbellWe intend to stabilise some parts of the libxenctrl interface by splitting out some functionality into separate stable libraries.
This is the qemu-xen part of the first phase of that change.
This mail is (or is intended to be) a reply to a "0/<VARIOUS>" super-intro mail covering all of the related patch series and which contains more details.
Ian Campbell (8):
xen_console: correctly cleanup primary console on teardown.
xen: Switch to libxenevtchn interface for compat shims.
xen: Switch to libxengnttab interface for compat shims.
xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages
xen: Switch uses of xc_map_foreign_{pages,bulk} to use
libxenforeignmemory API.
xen: Use stable library interfaces when they are available.
xen: domainbuild: reopen libxenctrl interface after forking for domain
watcher.
xen: make it possible to build without the Xen PV domain builder
configure | 70 ++++++++++++++++++++ hw/block/xen_disk.c | 38 +++++------ hw/char/xen_console.c | 19 +++--- hw/display/xenfb.c | 28 ++++---- hw/net/xen_nic.c | 18 +++--- hw/xen/xen_backend.c | 44 +++++++------ hw/xenpv/Makefile.objs | 4 +- hw/xenpv/xen_domainbuild.c | 9 ++- hw/xenpv/xen_machine_pv.c | 15 +++-- include/hw/xen/xen_backend.h | 5 +- include/hw/xen/xen_common.h | 149 ++++++++++++++++++++++++++++++++++--------- xen-common.c | 6 ++ xen-hvm.c | 39 +++++------ xen-mapcache.c | 6 +- 14 files changed, 315 insertions(+), 135 deletions(-)
Signature · 1 line
2.1.4
v8 cover Begin to disentangle libxenctrl and provide some stable libraries
In reply to Ian CampbellWe intend to stabilise some parts of the libxenctrl interface by splitting out some functionality into separate stable libraries.
This is the qemu-xen part of the first phase of that change.
This mail is (or is intended to be) a reply to a "0/<VARIOUS>" super-intro mail covering all of the related patch series and which contains more details.
Ian Campbell (8):
xen_console: correctly cleanup primary console on teardown.
xen: Switch to libxenevtchn interface for compat shims.
xen: Switch to libxengnttab interface for compat shims.
xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages
xen: Switch uses of xc_map_foreign_{pages,bulk} to use
libxenforeignmemory API.
xen: Use stable library interfaces when they are available.
xen: domainbuild: reopen libxenctrl interface after forking for domain
watcher.
xen: make it possible to build without the Xen PV domain builder
configure | 70 ++++++++++++++++++++ hw/block/xen_disk.c | 38 +++++------ hw/char/xen_console.c | 19 +++--- hw/display/xenfb.c | 28 ++++---- hw/net/xen_nic.c | 18 +++--- hw/xen/xen_backend.c | 44 +++++++------ hw/xenpv/Makefile.objs | 4 +- hw/xenpv/xen_domainbuild.c | 9 ++- hw/xenpv/xen_machine_pv.c | 15 +++-- include/hw/xen/xen_backend.h | 5 +- include/hw/xen/xen_common.h | 149 ++++++++++++++++++++++++++++++++++--------- xen-common.c | 6 ++ xen-hvm.c | 39 +++++------ xen-mapcache.c | 6 +- 14 files changed, 315 insertions(+), 135 deletions(-)
Signature · 1 line
2.1.4
PATCH v8 1/8 xen_console: correctly cleanup primary console on teardown.
All of the work in con_disconnect applies to the primary console case (when xendev->dev is NULL). Therefore remove the early check and bail and allow it to fall through. All of the existing code is correctly conditional already.
The ->dev and ->gnttabdev handles are either both set or neither. For consistency with con_initialise() with to the former here too.
With this con_initialise and con_disconnect now mirror each other.
Fix up a hard tab in the function while editing.
---
v4: New patch based on feedback to "xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API."
--- hw/char/xen_console.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/char/xen_console.c +2 -5
@@ -265,9 +265,6 @@ static void con_disconnect(struct XenDevice *xendev) { struct XenConsole *con = container_of(xendev, struct XenConsole, xendev); -if (!xendev->dev) { -return ; - }if (con->chr) {qemu_chr_add_handlers (con->chr,NULL ,NULL ,NULL ,NULL );qemu_chr_fe_release (con->chr);
@@ -275,12 +272,12 @@ static void con_disconnect(struct XenDevice *xendev)xen_be_unbind_evtchn (&con->xendev);if (con->sring) { -if (!xendev->gnttabdev) { +if (!xendev->dev) {munmap (con->sring,XC_PAGE_SIZE ); }else {xc_gnttab_munmap (xendev->gnttabdev, con->sring,1 ); } - con->sring =NULL ; + con->sring =NULL ; } }
Signature · 1 line
2.1.4
PATCH v8 2/8 xen: Switch to libxenevtchn interface for compat shims.
In reply to Ian CampbellIn Xen 4.7 we are refactoring parts libxenctrl into a number of separate libraries which will provide backward and forward API and ABI compatiblity.
One such library will be libxenevtchn which provides access to event channels.
In preparation for this switch the compatibility layer in xen_common.h (which support building with older versions of Xen) to use what will be the new library API. This means that the evtchn shim will disappear for versions of Xen which include libxenevtchn.
To simplify things for the <= 4.0.0 support we wrap the int fd in a malloc(sizeof int) such that the handle is always a pointer. This leads to less typedef headaches and the need for XC_HANDLER_INITIAL_VALUE etc for these interfaces.
Note that this patch does not add any support for actually using libxenevtchn, it just adjusts the existing shims.
Note that xc_evtchn_alloc_unbound functionality remains in libxenctrl, since that functionality is not exposed by /dev/xen/evtchn.
---
v4: Ran checkpatch, fixed all errors
Allocate correct size for handle (i.e. not size of the ptr)
--- hw/xen/xen_backend.c | 31 ++++++++++++++++--------------- include/hw/xen/xen_backend.h | 2 +- include/hw/xen/xen_common.h | 44 ++++++++++++++++++++++++++++++++++---------- xen-hvm.c | 25 +++++++++++++------------ 4 files changed, 64 insertions(+), 38 deletions(-)
hw/xen/xen_backend.c +16 -15
@@ -243,19 +243,19 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, xendev->debug = debug; xendev->local_port =-1 ; - xendev->evtchndev =xen_xc_evtchn_open (NULL ,0 ); -if (xendev->evtchndev ==XC_HANDLER_INITIAL_VALUE ) { + xendev->evtchndev =xenevtchn_open (NULL ,0 ); +if (xendev->evtchndev ==NULL ) {xen_be_printf (NULL ,0 ,"can't open evtchn device\n" );g_free (xendev);return NULL ; } -fcntl (xc_evtchn_fd (xendev->evtchndev),F_SETFD ,FD_CLOEXEC ); +fcntl (xenevtchn_fd (xendev->evtchndev),F_SETFD ,FD_CLOEXEC );if (ops->flags &DEVOPS_FLAG_NEED_GNTDEV ) { xendev->gnttabdev =xen_xc_gnttab_open (NULL ,0 );if (xendev->gnttabdev ==XC_HANDLER_INITIAL_VALUE ) {xen_be_printf (NULL ,0 ,"can't open gnttab device\n" ); -xc_evtchn_close (xendev->evtchndev); +xenevtchn_close (xendev->evtchndev);g_free (xendev);return NULL ; }
@@ -306,8 +306,8 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)g_free (xendev->fe); } -if (xendev->evtchndev !=XC_HANDLER_INITIAL_VALUE ) { -xc_evtchn_close (xendev->evtchndev); +if (xendev->evtchndev !=NULL ) { +xenevtchn_close (xendev->evtchndev); }if (xendev->gnttabdev !=XC_HANDLER_INITIAL_VALUE ) {xc_gnttab_close (xendev->gnttabdev);
@@ -691,13 +691,14 @@ static void xen_be_evtchn_event(void *opaque)struct XenDevice *xendev = opaque;evtchn_port_t port; - port =xc_evtchn_pending (xendev->evtchndev); + port =xenevtchn_pending (xendev->evtchndev);if (port != xendev->local_port) { -xen_be_printf (xendev,0 ,"xc_evtchn_pending returned %d (expected %d)\n" , +xen_be_printf (xendev,0 , +"xenevtchn_pending returned %d (expected %d)\n" , port, xendev->local_port);return ; } -xc_evtchn_unmask (xendev->evtchndev, port); +xenevtchn_unmask (xendev->evtchndev, port);if (xendev->ops->event) { xendev->ops->event (xendev);
@@ -740,14 +741,14 @@ int xen_be_bind_evtchn(struct XenDevice *xendev)if (xendev->local_port !=-1 ) {return 0 ; } - xendev->local_port =xc_evtchn_bind_interdomain + xendev->local_port =xenevtchn_bind_interdomain (xendev->evtchndev, xendev->dom, xendev->remote_port);if (xendev->local_port ==-1 ) { -xen_be_printf (xendev,0 ,"xc_evtchn_bind_interdomain failed\n" ); +xen_be_printf (xendev,0 ,"xenevtchn_bind_interdomain failed\n" );return -1 ; }xen_be_printf (xendev,2 ,"bind evtchn port %d\n" , xendev->local_port); -qemu_set_fd_handler (xc_evtchn_fd (xendev->evtchndev), +qemu_set_fd_handler (xenevtchn_fd (xendev->evtchndev), xen_be_evtchn_event,NULL , xendev);return 0 ; }
@@ -757,15 +758,15 @@ void xen_be_unbind_evtchn(struct XenDevice *xendev)if (xendev->local_port ==-1 ) {return ; } -qemu_set_fd_handler (xc_evtchn_fd (xendev->evtchndev),NULL ,NULL ,NULL ); -xc_evtchn_unbind (xendev->evtchndev, xendev->local_port); +qemu_set_fd_handler (xenevtchn_fd (xendev->evtchndev),NULL ,NULL ,NULL ); +xenevtchn_unbind (xendev->evtchndev, xendev->local_port);xen_be_printf (xendev,2 ,"unbind evtchn port %d\n" , xendev->local_port); xendev->local_port =-1 ; }int xen_be_send_notify (struct XenDevice *xendev) { -return xc_evtchn_notify (xendev->evtchndev, xendev->local_port); +return xenevtchn_notify (xendev->evtchndev, xendev->local_port); }/*
include/hw/xen/xen_backend.h +1 -1
@@ -46,7 +46,7 @@ struct XenDevice {int remote_port;int local_port; -XenEvtchn evtchndev; +xenevtchn_handle *evtchndev;XenGnttab gnttabdev;struct XenDevOps *ops;
include/hw/xen/xen_common.h +34 -10
68 lines not on this page · raw message
xen-hvm.c +13 -12
@@ -109,7 +109,7 @@ typedef struct XenIOState {/* evtchn local port for buffered io */ evtchn_port_t bufioreq_local_port;/* the evtchn fd for polling */ -XenEvtchn xce_handle; +xenevtchn_handle *xce_handle;/* which vcpu we are serving */ int send_vcpu;
@@ -715,7 +715,7 @@ static ioreq_t *cpu_get_ioreq(XenIOState *state)int i;evtchn_port_t port; - port =xc_evtchn_pending (state->xce_handle); + port =xenevtchn_pending (state->xce_handle);if (port == state->bufioreq_local_port) {timer_mod (state->buffered_io_timer,BUFFER_IO_MAX_DELAY +qemu_clock_get_ms (QEMU_CLOCK_REALTIME ));
@@ -734,7 +734,7 @@ static ioreq_t *cpu_get_ioreq(XenIOState *state) }/* unmask the wanted port again */ -xc_evtchn_unmask (state->xce_handle, port); +xenevtchn_unmask (state->xce_handle, port);/* get the io packet from shared memory */ state->send_vcpu = i;
@@ -1041,7 +1041,7 @@ static void handle_buffered_io(void *opaque) BUFFER_IO_MAX_DELAY + qemu_clock_get_ms(QEMU_CLOCK_REALTIME)); }else {timer_del (state->buffered_io_timer); -xc_evtchn_unmask (state->xce_handle, state->bufioreq_local_port); +xenevtchn_unmask (state->xce_handle, state->bufioreq_local_port); } }
@@ -1085,7 +1085,8 @@ static void cpu_handle_ioreq(void *opaque) } req->state =STATE_IORESP_READY ; -xc_evtchn_notify (state->xce_handle, state->ioreq_local_port[state->send_vcpu]); +xenevtchn_notify (state->xce_handle, + state->ioreq_local_port[state->send_vcpu]); } }
@@ -1093,8 +1094,8 @@ static void xen_main_loop_prepare(XenIOState *state) {int evtchn_fd =-1 ; -if (state->xce_handle !=XC_HANDLER_INITIAL_VALUE ) { - evtchn_fd =xc_evtchn_fd (state->xce_handle); +if (state->xce_handle !=NULL ) { + evtchn_fd =xenevtchn_fd (state->xce_handle); } state->buffered_io_timer = timer_new_ms(QEMU_CLOCK_REALTIME, handle_buffered_io,
@@ -1132,7 +1133,7 @@ static void xen_exit_notifier(Notifier *n, void *data) {XenIOState *state =container_of (n, XenIOState, exit); -xc_evtchn_close (state->xce_handle); +xenevtchn_close (state->xce_handle);xs_daemon_close (state->xenstore); }
@@ -1207,8 +1208,8 @@ int xen_hvm_init(PCMachineState *pcms, state =g_malloc0 (sizeof (XenIOState)); - state->xce_handle =xen_xc_evtchn_open (NULL ,0 ); -if (state->xce_handle ==XC_HANDLER_INITIAL_VALUE ) { + state->xce_handle =xenevtchn_open (NULL ,0 ); +if (state->xce_handle ==NULL ) {perror ("xen: event channel open" );return -1 ; }
@@ -1288,7 +1289,7 @@ int xen_hvm_init(PCMachineState *pcms,/* FIXME: how about if we overflow the page here? */ for (i =0 ; i < max_cpus; i++) { - rc =xc_evtchn_bind_interdomain (state->xce_handle, xen_domid, + rc =xenevtchn_bind_interdomain (state->xce_handle, xen_domid,xen_vcpu_eport (state->shared_page, i));if (rc ==-1 ) {fprintf (stderr,"shared evtchn %d bind error %d\n" , i, errno);
@@ -1297,7 +1298,7 @@ int xen_hvm_init(PCMachineState *pcms, state->ioreq_local_port[i] = rc; } - rc =xc_evtchn_bind_interdomain (state->xce_handle, xen_domid, + rc =xenevtchn_bind_interdomain (state->xce_handle, xen_domid, bufioreq_evtchn);if (rc ==-1 ) {fprintf (stderr,"buffered evtchn bind error %d\n" , errno);
Signature · 1 line
2.1.4
PATCH v8 3/8 xen: Switch to libxengnttab interface for compat shims.
In reply to Ian CampbellIn Xen 4.7 we are refactoring parts libxenctrl into a number of separate libraries which will provide backward and forward API and ABI compatiblity.
One such library will be libxengnttab which provides access to grant tables.
In preparation for this switch the compatibility layer in xen_common.h (which support building with older versions of Xen) to use what will be the new library API. This means that the gnttab shim will disappear for versions of Xen which include libxengnttab.
To simplify things for the <= 4.0.0 support we wrap the int fd in a malloc(sizeof int) such that the handle is always a pointer. This leads to less typedef headaches and the need for XC_HANDLER_INITIAL_VALUE etc for these interfaces.
Note that this patch does not add any support for actually using libxengnttab, it just adjusts the existing shims.
---
v4: Ran checkpatch, fixed all errors
Allocate correct size for handle (i.e. not size of the ptr) Rebase onto "xen_console: correctly cleanup primary console on teardown."
v5: Rebase over b4f72e31b924 "hw/net/xen_nic.c: Free 'netdev->txs' when map 'netdev->rxs' fails" which added a new gnttab_munmap.
v7: s/gnttab_munmap/gnttab_unmap/ to reflect change in the library.
--- hw/block/xen_disk.c | 38 ++++++++++++++++++++------------------ hw/char/xen_console.c | 4 ++-- hw/net/xen_nic.c | 18 +++++++++--------- hw/xen/xen_backend.c | 10 +++++----- include/hw/xen/xen_backend.h | 2 +- include/hw/xen/xen_common.h | 42 ++++++++++++++++++++++++++++++++---------- 6 files changed, 69 insertions(+), 45 deletions(-)
hw/block/xen_disk.c +20 -18
@@ -171,11 +171,11 @@ static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data)static void destroy_grant (gpointer pgnt) {PersistentGrant *grant = pgnt; -XenGnttab gnt = grant->blkdev->xendev.gnttabdev; +xengnttab_handle *gnt = grant->blkdev->xendev.gnttabdev; -if (xc_gnttab_munmap (gnt, grant->page,1 ) !=0 ) { +if (xengnttab_unmap (gnt, grant->page,1 ) !=0 ) {xen_be_printf (&grant->blkdev->xendev,0 , -"xc_gnttab_munmap failed: %s\n" , +"xengnttab_unmap failed: %s\n" ,strerror (errno)); } grant->blkdev->persistent_gnt_count--;
@@ -188,11 +188,11 @@ static void remove_persistent_region(gpointer data, gpointer dev) {PersistentRegion *region = data;struct XenBlkDev *blkdev = dev; -XenGnttab gnt = blkdev->xendev.gnttabdev; +xengnttab_handle *gnt = blkdev->xendev.gnttabdev; -if (xc_gnttab_munmap (gnt, region->addr, region->num) !=0 ) { +if (xengnttab_unmap (gnt, region->addr, region->num) !=0 ) {xen_be_printf (&blkdev->xendev,0 , -"xc_gnttab_munmap region %p failed: %s\n" , +"xengnttab_unmap region %p failed: %s\n" , region->addr,strerror (errno)); } xen_be_printf(&blkdev->xendev, 3,
@@ -327,7 +327,7 @@ err:static void ioreq_unmap (struct ioreq *ioreq) { -XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev; +xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;int i;if (ioreq->num_unmap ==0 || ioreq->mapped ==0 ) {
@@ -337,8 +337,9 @@ static void ioreq_unmap(struct ioreq *ioreq)if (!ioreq->pages) {return ; } -if (xc_gnttab_munmap (gnt, ioreq->pages, ioreq->num_unmap) !=0 ) { -xen_be_printf (&ioreq->blkdev->xendev,0 ,"xc_gnttab_munmap failed: %s\n" , +if (xengnttab_unmap (gnt, ioreq->pages, ioreq->num_unmap) !=0 ) { +xen_be_printf (&ioreq->blkdev->xendev,0 , +"xengnttab_unmap failed: %s\n" ,strerror (errno)); } ioreq->blkdev->cnt_map -= ioreq->num_unmap;
@@ -348,8 +349,9 @@ static void ioreq_unmap(struct ioreq *ioreq)if (!ioreq->page[i]) {continue ; } -if (xc_gnttab_munmap (gnt, ioreq->page[i],1 ) !=0 ) { -xen_be_printf (&ioreq->blkdev->xendev,0 ,"xc_gnttab_munmap failed: %s\n" , +if (xengnttab_unmap (gnt, ioreq->page[i],1 ) !=0 ) { +xen_be_printf (&ioreq->blkdev->xendev,0 , +"xengnttab_unmap failed: %s\n" ,strerror (errno)); } ioreq->blkdev->cnt_map--;
@@ -361,7 +363,7 @@ static void ioreq_unmap(struct ioreq *ioreq)static int ioreq_map (struct ioreq *ioreq) { -XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev; +xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST ];uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST ];void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST ];
@@ -412,7 +414,7 @@ static int ioreq_map(struct ioreq *ioreq) }if (batch_maps && new_maps) { - ioreq->pages =xc_gnttab_map_grant_refs + ioreq->pages =xengnttab_map_grant_refs (gnt, new_maps, domids, refs, ioreq->prot);if (ioreq->pages ==NULL ) { xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -428,7 +430,7 @@ static int ioreq_map(struct ioreq *ioreq) ioreq->blkdev->cnt_map += new_maps; }else if (new_maps) {for (i =0 ; i < new_maps; i++) { - ioreq->page[i] =xc_gnttab_map_grant_ref + ioreq->page[i] =xengnttab_map_grant_ref (gnt, domids[i], refs[i], ioreq->prot);if (ioreq->page[i] ==NULL ) { xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -778,9 +780,9 @@ static void blk_alloc(struct XenDevice *xendev)if (xen_mode !=XEN_EMULATE ) { batch_maps =1 ; } -if (xc_gnttab_set_max_grants (xendev->gnttabdev, +if (xengnttab_set_max_grants (xendev->gnttabdev,MAX_GRANTS (max_requests,BLKIF_MAX_SEGMENTS_PER_REQUEST )) <0 ) { -xen_be_printf (xendev,0 ,"xc_gnttab_set_max_grants failed: %s\n" , +xen_be_printf (xendev,0 ,"xengnttab_set_max_grants failed: %s\n" ,strerror (errno)); } }
@@ -990,7 +992,7 @@ static int blk_connect(struct XenDevice *xendev) } } - blkdev->sring =xc_gnttab_map_grant_ref (blkdev->xendev.gnttabdev, + blkdev->sring =xengnttab_map_grant_ref (blkdev->xendev.gnttabdev, blkdev->xendev.dom, blkdev->ring_ref,PROT_READ |PROT_WRITE );
@@ -1055,7 +1057,7 @@ static void blk_disconnect(struct XenDevice *xendev)xen_be_unbind_evtchn (&blkdev->xendev);if (blkdev->sring) { -xc_gnttab_munmap (blkdev->xendev.gnttabdev, blkdev->sring,1 ); +xengnttab_unmap (blkdev->xendev.gnttabdev, blkdev->sring,1 ); blkdev->cnt_map--; blkdev->sring =NULL ; }
hw/char/xen_console.c +2 -2
@@ -233,7 +233,7 @@ static int con_initialise(struct XenDevice *xendev)PROT_READ |PROT_WRITE , con->ring_ref); }else { - con->sring =xc_gnttab_map_grant_ref (xendev->gnttabdev, con->xendev.dom, + con->sring =xengnttab_map_grant_ref (xendev->gnttabdev, con->xendev.dom, con->ring_ref,PROT_READ |PROT_WRITE ); }
@@ -275,7 +275,7 @@ static void con_disconnect(struct XenDevice *xendev)if (!xendev->dev) {munmap (con->sring,XC_PAGE_SIZE ); }else { -xc_gnttab_munmap (xendev->gnttabdev, con->sring,1 ); +xengnttab_unmap (xendev->gnttabdev, con->sring,1 ); } con->sring =NULL ; }
hw/net/xen_nic.c +9 -9
@@ -168,7 +168,7 @@ static void net_tx_packets(struct XenNetDev *netdev) (txreq.flags & NETTXF_more_data) ?" more_data" :"" , (txreq.flags & NETTXF_extra_info) ? " extra_info" : ""); - page =xc_gnttab_map_grant_ref (netdev->xendev.gnttabdev, + page =xengnttab_map_grant_ref (netdev->xendev.gnttabdev, netdev->xendev.dom, txreq.gref,PROT_READ );if (page ==NULL ) {
@@ -190,7 +190,7 @@ static void net_tx_packets(struct XenNetDev *netdev)qemu_send_packet (qemu_get_queue (netdev->nic), page + txreq.offset, txreq.size); } -xc_gnttab_munmap (netdev->xendev.gnttabdev, page,1 ); +xengnttab_unmap (netdev->xendev.gnttabdev, page,1 );net_tx_response (netdev, &txreq,NETIF_RSP_OKAY ); }if (!netdev->tx_work) {
@@ -260,7 +260,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t sizememcpy (&rxreq,RING_GET_REQUEST (&netdev->rx_ring, rc),sizeof (rxreq)); netdev->rx_ring.req_cons = ++rc; - page =xc_gnttab_map_grant_ref (netdev->xendev.gnttabdev, + page =xengnttab_map_grant_ref (netdev->xendev.gnttabdev, netdev->xendev.dom, rxreq.gref,PROT_WRITE );if (page ==NULL ) {
@@ -270,7 +270,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t sizereturn -1 ; }memcpy (page +NET_IP_ALIGN , buf, size); -xc_gnttab_munmap (netdev->xendev.gnttabdev, page,1 ); +xengnttab_unmap (netdev->xendev.gnttabdev, page,1 );net_rx_response (netdev, &rxreq,NETIF_RSP_OKAY ,NET_IP_ALIGN , size,0 );return size;
@@ -342,19 +342,19 @@ static int net_connect(struct XenDevice *xendev)return -1 ; } - netdev->txs =xc_gnttab_map_grant_ref (netdev->xendev.gnttabdev, + netdev->txs =xengnttab_map_grant_ref (netdev->xendev.gnttabdev, netdev->xendev.dom, netdev->tx_ring_ref,PROT_READ |PROT_WRITE );if (!netdev->txs) {return -1 ; } - netdev->rxs =xc_gnttab_map_grant_ref (netdev->xendev.gnttabdev, + netdev->rxs =xengnttab_map_grant_ref (netdev->xendev.gnttabdev, netdev->xendev.dom, netdev->rx_ring_ref,PROT_READ |PROT_WRITE );if (!netdev->rxs) { -xc_gnttab_munmap (netdev->xendev.gnttabdev, netdev->txs,1 ); +xengnttab_unmap (netdev->xendev.gnttabdev, netdev->txs,1 ); netdev->txs =NULL ;return -1 ; }
@@ -379,11 +379,11 @@ static void net_disconnect(struct XenDevice *xendev)xen_be_unbind_evtchn (&netdev->xendev);if (netdev->txs) { -xc_gnttab_munmap (netdev->xendev.gnttabdev, netdev->txs,1 ); +xengnttab_unmap (netdev->xendev.gnttabdev, netdev->txs,1 ); netdev->txs =NULL ; }if (netdev->rxs) { -xc_gnttab_munmap (netdev->xendev.gnttabdev, netdev->rxs,1 ); +xengnttab_unmap (netdev->xendev.gnttabdev, netdev->rxs,1 ); netdev->rxs =NULL ; } }
hw/xen/xen_backend.c +5 -5
@@ -252,15 +252,15 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,fcntl (xenevtchn_fd (xendev->evtchndev),F_SETFD ,FD_CLOEXEC );if (ops->flags &DEVOPS_FLAG_NEED_GNTDEV ) { - xendev->gnttabdev =xen_xc_gnttab_open (NULL ,0 ); -if (xendev->gnttabdev ==XC_HANDLER_INITIAL_VALUE ) { + xendev->gnttabdev =xengnttab_open (NULL ,0 ); +if (xendev->gnttabdev ==NULL ) {xen_be_printf (NULL ,0 ,"can't open gnttab device\n" );xenevtchn_close (xendev->evtchndev);g_free (xendev);return NULL ; } }else { - xendev->gnttabdev =XC_HANDLER_INITIAL_VALUE ; + xendev->gnttabdev =NULL ; }QTAILQ_INSERT_TAIL (&xendevs, xendev, next);
@@ -309,8 +309,8 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)if (xendev->evtchndev !=NULL ) {xenevtchn_close (xendev->evtchndev); } -if (xendev->gnttabdev !=XC_HANDLER_INITIAL_VALUE ) { -xc_gnttab_close (xendev->gnttabdev); +if (xendev->gnttabdev !=NULL ) { +xengnttab_close (xendev->gnttabdev); }QTAILQ_REMOVE (&xendevs, xendev, next);
include/hw/xen/xen_backend.h +1 -1
@@ -47,7 +47,7 @@ struct XenDevice {int local_port;xenevtchn_handle *evtchndev; -XenGnttab gnttabdev; +xengnttab_handle *gnttabdev;struct XenDevOps *ops;QTAILQ_ENTRY (XenDevice) next;
include/hw/xen/xen_common.h +32 -10
68 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v8 4/8 xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages
In reply to Ian CampbellIn Xen 4.7 we are refactoring parts libxenctrl into a number of separate libraries which will provide backward and forward API and ABI compatiblity.
One such library will be libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_{pages,bulk}.
In preparation for this switch all uses of xc_map_foreign_range to xc_map_foreign_pages. This is trivial because size was always XC_PAGE_SIZE so the necessary adjustments are trivial:
* Pass &mfn (an array of length 1) instead of mfn. The function takes a pointer to const, so there is no possibily of mfn changing due to this change.
* Pass nr_pages=1 instead of size=XC_PAGE_SIZE
There is one wrinkle in xen_console.c:con_initialise() where con->ring_ref is an int but can in some code paths (when !xendev->dev) be treated as an mfn. I think this is an existing latent truncation hazard on platforms where xen_pfn_t is 64-bit and int is 32-bit (e.g. amd64, both arm* variants). I'm unsure under what circumstances xendev->dev can be NULL or if anything elsewhere ensures the value fits into an int. For now I just use a temporary xen_pfn_t to in effect upcast the pointer from int* to xen_pfn_t*.
In xenfb.c:common_bind we now explicitly launder the mfn into a xen_pfn_t, so it has the correct type to be passed to xc_map_foreign_pages and doesn't provoke warnings on 32-bit x86.
---
v7: Correct type mismatch (int64 vs xen_pfn_t) on 32 bit x86 in
xenfb.c, by explicitly laundering via a xen_pfn_t variable.
v6: Switch to xc_map_foreign_pages rather than _bulk. Switching to
_bulk without checking the value of err[0] risked missing errors. The new xenforeignmemory_map coming later in this series will DTRT with err==NULL.
Dropped Stefano's Reviewed-by due to this change.
v4: Ran checkpatch, fixed all errors
Mention the const-ness of the mfn array in the commit log
fixup!xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages
--- hw/char/xen_console.c | 8 ++++---- hw/display/xenfb.c | 15 ++++++++------- xen-hvm.c | 14 +++++++------- 3 files changed, 19 insertions(+), 18 deletions(-)
hw/char/xen_console.c +4 -4
@@ -228,10 +228,10 @@ static int con_initialise(struct XenDevice *xendev) con->buffer.max_capacity = limit;if (!xendev->dev) { - con->sring =xc_map_foreign_range (xen_xc, con->xendev.dom, -XC_PAGE_SIZE , -PROT_READ |PROT_WRITE , - con->ring_ref); +xen_pfn_t mfn = con->ring_ref; + con->sring =xc_map_foreign_pages (xen_xc, con->xendev.dom, +PROT_READ |PROT_WRITE , + &mfn,1 ); }else { con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom, con->ring_ref,
hw/display/xenfb.c +8 -7
@@ -95,23 +95,24 @@ struct XenFB {static int common_bind (struct common *c) { -uint64_t mfn; +uint64_t val; +xen_pfn_t mfn; -if (xenstore_read_fe_uint64 (&c->xendev,"page-ref" , &mfn) ==-1 ) +if (xenstore_read_fe_uint64 (&c->xendev,"page-ref" , &val) ==-1 )return -1 ; -assert (mfn == (xen_pfn_t )mfn); + mfn = (xen_pfn_t )val; +assert (val == mfn);if (xenstore_read_fe_int (&c->xendev,"event-channel" , &c->xendev.remote_port) ==-1 )return -1 ; - c->page =xc_map_foreign_range (xen_xc, c->xendev.dom, -XC_PAGE_SIZE , -PROT_READ |PROT_WRITE , mfn); + c->page =xc_map_foreign_pages (xen_xc, c->xendev.dom, +PROT_READ |PROT_WRITE , &mfn,1 );if (c->page ==NULL )return -1 ;xen_be_bind_evtchn (&c->xendev); -xen_be_printf (&c->xendev,1 ,"ring mfn %" PRIx64", remote-port %d, local-port %d\n" , +xen_be_printf (&c->xendev,1 ,"ring mfn %" PRI_xen_pfn", remote-port %d, local-port %d\n" , mfn, c->xendev.remote_port, c->xendev.local_port);return 0 ;
xen-hvm.c +7 -7
@@ -1247,8 +1247,9 @@ int xen_hvm_init(PCMachineState *pcms,DPRINTF ("buffered io page at pfn %lx\n" , bufioreq_pfn);DPRINTF ("buffered io evtchn is %x\n" , bufioreq_evtchn); - state->shared_page =xc_map_foreign_range (xen_xc, xen_domid,XC_PAGE_SIZE , -PROT_READ |PROT_WRITE , ioreq_pfn); + state->shared_page =xc_map_foreign_pages (xen_xc, xen_domid, +PROT_READ |PROT_WRITE , + &ioreq_pfn,1 );if (state->shared_page ==NULL ) {hw_error ("map shared IO page returned error %d handle=" XC_INTERFACE_FMT , errno, xen_xc);
@@ -1258,8 +1259,8 @@ int xen_hvm_init(PCMachineState *pcms,if (!rc) {DPRINTF ("shared vmport page at pfn %lx\n" , ioreq_pfn); state->shared_vmport_page = -xc_map_foreign_range (xen_xc, xen_domid,XC_PAGE_SIZE , -PROT_READ |PROT_WRITE , ioreq_pfn); +xc_map_foreign_pages (xen_xc, xen_domid,PROT_READ |PROT_WRITE , + &ioreq_pfn,1 );if (state->shared_vmport_page ==NULL ) {hw_error ("map shared vmport IO page returned error %d handle=" XC_INTERFACE_FMT , errno, xen_xc);
@@ -1268,10 +1269,9 @@ int xen_hvm_init(PCMachineState *pcms,hw_error ("get vmport regs pfn returned error %d, rc=%d" , errno, rc); } - state->buffered_io_page =xc_map_foreign_range (xen_xc, xen_domid, -XC_PAGE_SIZE , + state->buffered_io_page =xc_map_foreign_pages (xen_xc, xen_domid,PROT_READ |PROT_WRITE , - bufioreq_pfn); + &bufioreq_pfn,1 );if (state->buffered_io_page ==NULL ) {hw_error ("map buffered IO page returned error %d" , errno); }
Signature · 1 line
2.1.4
PATCH v8 5/8 xen: Switch uses of xc_map_foreign_{pages, bulk} to use libxenforeignmemory API.
In reply to Ian CampbellIn Xen 4.7 we are refactoring parts libxenctrl into a number of separate libraries which will provide backward and forward API and ABI compatiblity.
One such library will be libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_{pages,bulk}.
The new xenforeignmemory_map() function behaves like xc_map_foreign_pages() when the err argument is NULL and like xc_map_foreign_bulk() when err is non-NULL, which maps into the shim here onto checking err == NULL and calling the appropriate old function.
Note that xenforeignmemory_map() takes the number of pages before the arrays themselves, in order to support potentially future use of variable-length-arrays in the prototype (in the future, when Xen's baseline toolchain requirements are new enough to ensure VLAs are supported).
In preparation for adding support for libxenforeignmemory add support to the <=4.0 and <=4.6 compat code in xen_common.h to allow us to switch to using the new API. These shims will disappear for versions of Xen which include libxenforeignmemory.
Since libxenforeignmemory will have its own handle type but for <= 4.6 the functionality is provided by using a libxenctrl handle we introduce a new global xen_fmem alongside the existing xen_xc. In fact we make xen_fmem a pointer to the existing xen_xc, which then works correctly with both <=4.0 (xc handle is an int) and <=4.6 (xc handle is a pointer). In the latter case xen_fmem is actually a double indirect pointer, but it all falls out in the wash.
Unlike libxenctrl libxenforeignmemory has an explicit unmap function, rather than just specifying that munmap should be used, so the unmap paths are updated to use xenforeignmemory_unmap, which is a shim for munmap on these versions of xen. The mappings in xen-hvm.c do not appear to be unmapped (which makes sense for a qemu-dm process)
In fb_disconnect this results in a change from simply mmap over the existing mapping (with an implicit munmap) to expliclty unmapping with xenforeignmemory_unmap and then mapping the required anonymous memory in the same hole. I don't think this is a problem since any other thread which was racily touching this region would already be running the risk of hitting the mapping halfway through the call. If this is thought to be a problem then we could consider adding an extra API to the libxenforeignmemory interface to replace a foreign mapping with anonymous shared memory, but I'd prefer not to.
---
v8: Move two copies of compat xenforeignmemory_{open,unmap} to the
common location. Guard with version 471 (which will be added in the next patch)
v7: Move two copies of compat xenforeignmemory_map to a common location.
Note that the existing xen_domain_create #ifdef will be covered by a CONFIG_XEN_PV_DOMAIN_BUILD in a later patch, and so is not a suitable place to put this function.
v6: Handle _pages as well as _bulk, due to changes in the previous
patches, including the dropping of "xen: Switch uses of xc_map_foreign_pages into xc_map_foreign_bulk" which previous preceded this patch and the change of "xen: Switch uses of xc_map_foreign_range into xc_map_foreign_bulk" into "xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages".
Handle reordering of arguments to xenforeignmemory_map().
Dropped Stefano's Reviewed-by due to these changes.
v4: Rebase onto "xen_console: correctly cleanup primary console on
teardown."
xenforeignmemory_unmap takes pages not bytes
Compat wrapper for xenforeignmemory_open instead of ifdef in code.
Run check patch and fix most issues. I did not fix:
ERROR: do not initialise globals to 0 or NULL
+xenforeignmemory_handle *xen_fmem = NULL;
=> This is consistent with all of the existing declarations.
ERROR: need consistent spacing around '*' (ctx:WxV) +typedef xc_interface *xenforeignmemory_handle;
=> I think this is a false +ve since this is a pointer "*" not a multiple "*".
reorder args to xenforeignmemory_map
--- hw/char/xen_console.c | 8 ++++---- hw/display/xenfb.c | 17 +++++++++-------- hw/xen/xen_backend.c | 3 ++- include/hw/xen/xen_backend.h | 1 + include/hw/xen/xen_common.h | 25 +++++++++++++++++++++++++ xen-common.c | 6 ++++++ xen-hvm.c | 12 ++++++------ xen-mapcache.c | 6 +++--- 8 files changed, 56 insertions(+), 22 deletions(-)
hw/char/xen_console.c +4 -4
@@ -229,9 +229,9 @@ static int con_initialise(struct XenDevice *xendev)if (!xendev->dev) {xen_pfn_t mfn = con->ring_ref; - con->sring =xc_map_foreign_pages (xen_xc, con->xendev.dom, -PROT_READ |PROT_WRITE , - &mfn,1 ); + con->sring =xenforeignmemory_map (xen_fmem, con->xendev.dom, +PROT_READ |PROT_WRITE , +1 , &mfn,NULL ); }else { con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom, con->ring_ref,
@@ -273,7 +273,7 @@ static void con_disconnect(struct XenDevice *xendev)if (con->sring) {if (!xendev->dev) { -munmap (con->sring,XC_PAGE_SIZE ); +xenforeignmemory_unmap (xen_fmem, con->sring,1 ); }else {xengnttab_unmap (xendev->gnttabdev, con->sring,1 ); }
hw/display/xenfb.c +9 -8
@@ -106,8 +106,8 @@ static int common_bind(struct common *c)if (xenstore_read_fe_int (&c->xendev,"event-channel" , &c->xendev.remote_port) ==-1 )return -1 ; - c->page =xc_map_foreign_pages (xen_xc, c->xendev.dom, -PROT_READ |PROT_WRITE , &mfn,1 ); + c->page =xenforeignmemory_map (xen_fmem, c->xendev.dom, +PROT_READ |PROT_WRITE ,1 , &mfn,NULL );if (c->page ==NULL )return -1 ;
@@ -122,7 +122,7 @@ static void common_unbind(struct common *c) {xen_be_unbind_evtchn (&c->xendev);if (c->page) { -munmap (c->page,XC_PAGE_SIZE ); +xenforeignmemory_unmap (xen_fmem, c->page,1 ); c->page =NULL ; } }
@@ -495,15 +495,15 @@ static int xenfb_map_fb(struct XenFB *xenfb) fbmfns =g_malloc0 (sizeof (xen_pfn_t) * xenfb->fbpages);xenfb_copy_mfns (mode, n_fbdirs, pgmfns, pd); - map =xc_map_foreign_pages (xen_xc, xenfb->c.xendev.dom, -PROT_READ , pgmfns, n_fbdirs); + map =xenforeignmemory_map (xen_fmem, xenfb->c.xendev.dom, +PROT_READ , n_fbdirs, pgmfns,NULL );if (map ==NULL ) goto out;xenfb_copy_mfns (mode, xenfb->fbpages, fbmfns, map); -munmap (map, n_fbdirs *XC_PAGE_SIZE ); +xenforeignmemory_unmap (xen_fmem, map, n_fbdirs); - xenfb->pixels =xc_map_foreign_pages (xen_xc, xenfb->c.xendev.dom, -PROT_READ , fbmfns, xenfb->fbpages); + xenfb->pixels =xenforeignmemory_map (xen_fmem, xenfb->c.xendev.dom, +PROT_READ , xenfb->fbpages, fbmfns,NULL );if (xenfb->pixels ==NULL ) goto out;
@@ -912,6 +912,7 @@ static void fb_disconnect(struct XenDevice *xendev)* Replacing the framebuffer with anonymous shared memory * instead. This releases the guest pages and keeps qemu happy. */ +xenforeignmemory_unmap (xen_fmem, fb->pixels, fb->fbpages); fb->pixels =mmap (fb->pixels, fb->fbpages *XC_PAGE_SIZE ,PROT_READ |PROT_WRITE ,MAP_SHARED |MAP_ANON ,-1 ,0 );
hw/xen/xen_backend.c +2 -1
@@ -45,6 +45,7 @@/* public */ XenXC xen_xc =XC_HANDLER_INITIAL_VALUE ; +xenforeignmemory_handle *xen_fmem =NULL ;struct xs_handle *xenstore =NULL ;const char *xen_protocol;
@@ -717,7 +718,7 @@ int xen_be_init(void)qemu_set_fd_handler (xs_fileno (xenstore), xenstore_update,NULL ,NULL ); -if (xen_xc ==XC_HANDLER_INITIAL_VALUE ) { +if (xen_xc ==XC_HANDLER_INITIAL_VALUE || xen_fmem ==NULL ) {/* Check if xen_init() have been called */ goto err; }
include/hw/xen/xen_backend.h +1 -0
@@ -57,6 +57,7 @@ struct XenDevice {/* variables */ extern XenXC xen_xc; +extern xenforeignmemory_handle *xen_fmem;extern struct xs_handle *xenstore;extern const char *xen_protocol;
include/hw/xen/xen_common.h +25 -0
@@ -41,6 +41,7 @@ static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,typedef int XenXC ;typedef int xenevtchn_handle ;typedef int xengnttab_handle ; +typedef int xenforeignmemory_handle ;# define XC_INTERFACE_FMT "%i"# define XC_HANDLER_INITIAL_VALUE -1
@@ -104,6 +105,8 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,return xc_interface_open (); } +/* See below for xenforeignmemory_* APIs */ +static inline int xc_fd (int xen_xc) {return xen_xc;
@@ -149,6 +152,7 @@ static inline void xs_close(struct xs_handle *xsh)#else typedef xc_interface *XenXC ; +typedef xc_interface *xenforeignmemory_handle ;typedef xc_evtchn xenevtchn_handle ;typedef xc_gnttab xengnttab_handle ;
@@ -178,6 +182,8 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,return xc_interface_open (logger, dombuild_logger, open_flags); } +/* See below for xenforeignmemory_* APIs */ +/* FIXME There is now way to have the xen fd */ static inline int xc_fd (xc_interface *xen_xc) {
@@ -501,4 +507,23 @@ static inline int xen_domain_create(XenXC xc, uint32_t ssidref, }#endif +#if CONFIG_XEN_CTRL_INTERFACE_VERSION <471 + +#define xenforeignmemory_open (l, f) &xen_xc + +static inline void *xenforeignmemory_map (XenXC *h,uint32_t dom, +int prot,size_t pages, +const xen_pfn_t arr[/*pages*/ ], +int err[/*pages*/ ]) +{ +if (err) +return xc_map_foreign_bulk (*h, dom, prot, arr, err, pages); +else +return xc_map_foreign_pages (*h, dom, prot, arr, pages); +} + +#define xenforeignmemory_unmap (h, p, s) munmap(p, s * XC_PAGE_SIZE) + +#endif +#endif /* QEMU_HW_XEN_COMMON_H */
xen-common.c +6 -0
@@ -118,6 +118,12 @@ static int xen_init(MachineState *ms)xen_be_printf (NULL ,0 ,"can't open xen interface\n" );return -1 ; } + xen_fmem =xenforeignmemory_open (0 ,0 ); +if (xen_fmem ==NULL ) { +xen_be_printf (NULL ,0 ,"can't open xen fmem interface\n" ); +xc_interface_close (xen_xc); +return -1 ; + }qemu_add_vm_change_state_handler (xen_change_state_handler,NULL );global_state_set_optional ();
xen-hvm.c +6 -6
@@ -1247,9 +1247,9 @@ int xen_hvm_init(PCMachineState *pcms,DPRINTF ("buffered io page at pfn %lx\n" , bufioreq_pfn);DPRINTF ("buffered io evtchn is %x\n" , bufioreq_evtchn); - state->shared_page =xc_map_foreign_pages (xen_xc, xen_domid, + state->shared_page =xenforeignmemory_map (xen_fmem, xen_domid,PROT_READ |PROT_WRITE , - &ioreq_pfn,1 ); +1 , &ioreq_pfn,NULL );if (state->shared_page ==NULL ) {hw_error ("map shared IO page returned error %d handle=" XC_INTERFACE_FMT , errno, xen_xc);
@@ -1259,8 +1259,8 @@ int xen_hvm_init(PCMachineState *pcms,if (!rc) {DPRINTF ("shared vmport page at pfn %lx\n" , ioreq_pfn); state->shared_vmport_page = -xc_map_foreign_pages (xen_xc, xen_domid,PROT_READ |PROT_WRITE , - &ioreq_pfn,1 ); +xenforeignmemory_map (xen_fmem, xen_domid,PROT_READ |PROT_WRITE , +1 , &ioreq_pfn,NULL );if (state->shared_vmport_page ==NULL ) {hw_error ("map shared vmport IO page returned error %d handle=" XC_INTERFACE_FMT , errno, xen_xc);
@@ -1269,9 +1269,9 @@ int xen_hvm_init(PCMachineState *pcms,hw_error ("get vmport regs pfn returned error %d, rc=%d" , errno, rc); } - state->buffered_io_page =xc_map_foreign_pages (xen_xc, xen_domid, + state->buffered_io_page =xenforeignmemory_map (xen_fmem, xen_domid,PROT_READ |PROT_WRITE , - &bufioreq_pfn,1 ); +1 , &bufioreq_pfn,NULL );if (state->buffered_io_page ==NULL ) {hw_error ("map buffered IO page returned error %d" , errno); }
xen-mapcache.c +3 -3
@@ -176,10 +176,10 @@ static void xen_remap_bucket(MapCacheEntry *entry, pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT -XC_PAGE_SHIFT )) + i; } - vaddr_base =xc_map_foreign_bulk (xen_xc, xen_domid,PROT_READ |PROT_WRITE , - pfns, err, nb_pfn); + vaddr_base =xenforeignmemory_map (xen_fmem, xen_domid,PROT_READ |PROT_WRITE , + nb_pfn, pfns, err);if (vaddr_base ==NULL ) { -perror ("xc_map_foreign_bulk" ); +perror ("xenforeignmemory_map" );exit (-1 ); }
Signature · 1 line
2.1.4