Skip to contentSkip to conversation

Begin to disentangle libxenctrl and provide some stable libraries

PATCH Superseded Ian Campbell 9 participants 55 messages Jul 15, 2015 – Sep 25, 2015 1 message not in the archive

Subsystems (2)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Begin to disentangle libxenctrl and provide some stable libraries

(this is clearly not 4.6 material, aiming for 4.7)

In <[email protected]> I proposed stabilising some parts of the libxenctrl API/ABI by disaggregating into separate libraries.

After the previous proof of concept I have now split out:
* xentoollog
* evtch
* gntdev and gntshr
* hypercalls
* privileged foreign memory mappings

These represent the core low level functionality which everything else needs, I think, and so are moving things down into a layer below libxc (i.e. libxc uses all of these).

There are 3 series, against xen.git (15 patches), mini-os.git (5 patches) and qemu-xen-trad.git (5 patches). The patches against xen.git point to the patches in the other two trees via instructions to update the relevant Config.mk field. The perils of changing unstable interfaces!

NB: minios-devel will only get the mini-os side.

The code in for all three can be found in:
git://xenbits.xen.org/people/ianc/xen.git libxenctrl-split-v2
git://xenbits.xen.org/people/ianc/qemu-xen-unstable.git libxenctrl-split-v2
git://xenbits.xen.org/people/ianc/mini-os.git libxenctrl-split-v2

The tip of the xen.git branch contains an extra patch adding a .config into the tree which should get the correct things for the HEAD of the branch, but not further back.

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.

I'm stilling mulling over putting everything into tools/libs/FOO instead of tools/libxenFOO, I still haven't but I could if people think it is worthwhile. Eventually I'd like to split libxc into libxenguest and libxenctrl to cut down on the amount of strange cross talk...

I've now completely removed the osdep layer.

The whole thing has been build and runtime tested on Linux and stubdoms, and built (but not run) on FreeBSD. 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.

The original proposal has morphed into docs/misc/toolstack-library-abis.pandoc here, and I've been trying to update in the patches which touch things, which is useful for book keeping as this work progresses.

However I'm not sure it serves a useful long term purpose (certainly not with the level of detail of the per-library function names). I shall likely keep it around for a few iterations but I think eventually I'll strip it out or replace it with something more suitable for long term documentation.

Ian

#1 lore raw

PATCH v2 1/15 docs: Partial toolstack library API/ABI stabilisation

---
DraftB:
- Feedback from Jan and Andy
- QEMU usage by functional area
- Annotated with what things are and users
- Renamed to docs/misc/toolstack-library-abis.pandoc
- Change method for gathering symbols to omit static/non-exported stuff.
- Some additional functional classification, and start to annotate the underlying interfaces plus known users.

---
 docs/Makefile                           |   2 +-
 docs/misc/toolstack-library-abis.pandoc | 849 ++++++++++++++++++++++++++++++++
 2 files changed, 850 insertions(+), 1 deletion(-)
 create mode 100644 docs/misc/toolstack-library-abis.pandoc
docs/Makefile +1 -1
index 272292c..79a17f4 100644
@@ -16,7 +16,7 @@ MARKDOWNSRC-y := $(sort $(shell find misc -name '*.markdown' -print))
 
 TXTSRC-y := $(sort $(shell find misc -name '*.txt' -print))
 
-PANDOCSRC-y := $(sort $(shell find specs -name '*.pandoc' -print))
+PANDOCSRC-y := $(sort $(shell find misc specs -name '*.pandoc' -print))
 
 # Documentation targets
 DOC_MAN1 := $(patsubst man/%.pod.1,man1/%.1,$(MAN1SRC-y))
docs/misc/toolstack-library-abis.pandoc new file +849 -0

849 lines not on this page · raw message

Signature · 1 line
2.1.4
#2 lore raw

PATCH v2 2/15 tools/Rules.mk: Properly handle libraries with recursive dependcies.

In reply to Ian Campbell

In tree libraries which link against other in tree libraries in a way which is opaque to their callers need special handling, specifically correct use of -Wl,-rpath-link for the recusively used libraries.

Currently this is rather simple, but up coming changes are going to introduce transitive dependencies more than 1 step deep.

Introduce a SHDEPS idiom to contain all the recursive deps for a library and include those in both LDLIBS (for linking) and SHLIB (for recursive uses).

Try and document the whole thing.

---
 tools/Rules.mk | 74 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 62 insertions(+), 12 deletions(-)
tools/Rules.mk +62 -12
index 2c422bd..28e84e6 100644
@@ -34,25 +34,72 @@ INSTALL_SHLIB = : install-shlib-unsupported-fail
 SYMLINK_SHLIB = : symlink-shlib-unsupported-fail
 endif
 
+# Compiling and linking against in tree libraries.
+#
+# In order to compile and link against an in-tree library various
+# cpp/compiler/linker options are required.
+#
+# For example consider a library "libfoo" which itself uses two other
+# libraries:
+#  libbar - whose use is entirely internal to libfoo and not exposed
+#           to users of libfoo at all.
+#  libbaz - whose use is entirely internal to libfoo but libfoo's
+#           public headers include libbaz's one or more of libbaz's
+#           public headers. Users of libfoo are therefore transitively
+#           using libbaz's header but not linking against libbaz.
+#
+# SHDEPS_libfoo: Flags for linking recursive dependencies of
+#                libfoo. Must contain SHLIB for every library which
+#                libfoo links against. So must contain both
+#                $(SHLIB_libbar) and $(SHLIB_libbaz).
+#
+# SHLIB_libfoo: Flags for recursively linking against libfoo. Must
+#               contains SHDEPS_libfoo and:
+#                   -Wl,-rpath-link=<directory containing libfoo.so>
+#
+# CFLAGS_libfoo: Flags for compiling against libfoo. Must add the
+#                directories containing libfoo's headers to the
+#                include path. Must recursively include
+#                $(CFLAGS_libbaz), to satisfy the transitive inclusion
+#                of the headers but not $(CFLAGS_libbar) since none of
+#                libbar's headers are required to build against
+#                libfoo.
+#
+# LDLIBS_libfoo: Flags for linking against libfoo. Must contain
+#                $(SHDEPS_libfoo) and the path to libfoo.so
+#
+# Consumers of libfoo should include $(CFLAGS_libfoo) and
+# $(LDLIBS_libfoo) in their appropriate directories. They should not
+# include any CFLAGS or LDLIBS relating to libbar or libbaz unless
+# they use those libraries directly (not via libfoo) too.
+#
+# Consumers of libfoo should not directly use $(SHDEPS_libfoo) or
+# $(SHLIB_libfoo)
+
 CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_xeninclude)
+SHDEPS_libxenctrl =
 LDLIBS_libxenctrl = $(XEN_LIBXC)/libxenctrl$(libextension)
 SHLIB_libxenctrl  = -Wl,-rpath-link=$(XEN_LIBXC)
 
 CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_xeninclude)
-LDLIBS_libxenguest = $(XEN_LIBXC)/libxenguest$(libextension)
-SHLIB_libxenguest  = -Wl,-rpath-link=L$(XEN_LIBXC)
+SHDEPS_libxenguest =
+LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_LIBXC)/libxenguest$(libextension)
+SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=L$(XEN_LIBXC)
 
 CFLAGS_libxenstore = -I$(XEN_XENSTORE)/include $(CFLAGS_xeninclude)
-LDLIBS_libxenstore = $(XEN_XENSTORE)/libxenstore$(libextension)
-SHLIB_libxenstore  = -Wl,-rpath-link=$(XEN_XENSTORE)
+SHDEPS_libxenstore =
+LDLIBS_libxenstore = $(SHDEPS_libxenguest) $(XEN_XENSTORE)/libxenstore$(libextension)
+SHLIB_libxenstore  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_XENSTORE)
 
 CFLAGS_libxenstat  = -I$(XEN_LIBXENSTAT)
-LDLIBS_libxenstat  = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(XEN_LIBXENSTAT)/libxenstat$(libextension)
-SHLIB_libxenstat  = -Wl,-rpath-link=$(XEN_LIBXENSTAT)
+SHDEPS_libxenstat  = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
+LDLIBS_libxenstat  = $(SHDEPS_libxenstat) $(XEN_LIBXENSTAT)/libxenstat$(libextension)
+SHLIB_libxenstat   = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_LIBXENSTAT)
 
 CFLAGS_libxenvchan = -I$(XEN_LIBVCHAN)
-LDLIBS_libxenvchan = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(XEN_LIBVCHAN)/libxenvchan$(libextension)
-SHLIB_libxenvchan  = -Wl,-rpath-link=$(XEN_LIBVCHAN)
+SHDEPS_libxenvchan = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
+LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libextension)
+SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
 
 ifeq ($(debug),y)
 # Disable optimizations and enable debugging information for macros
@@ -65,17 +112,20 @@ LIBXL_BLKTAP ?= $(CONFIG_BLKTAP2)
 
 ifeq ($(LIBXL_BLKTAP),y)
 CFLAGS_libblktapctl = -I$(XEN_BLKTAP2)/control -I$(XEN_BLKTAP2)/include $(CFLAGS_xeninclude)
-LDLIBS_libblktapctl = $(XEN_BLKTAP2)/control/libblktapctl$(libextension)
-SHLIB_libblktapctl  = -Wl,-rpath-link=$(XEN_BLKTAP2)/control
+SHDEPS_libblktapctl =
+LDLIBS_libblktapctl = $(SHDEPS_libblktapctl) $(XEN_BLKTAP2)/control/libblktapctl$(libextension)
+SHLIB_libblktapctl  = $(SHDEPS_libblktapctl) -Wl,-rpath-link=$(XEN_BLKTAP2)/control
 else
 CFLAGS_libblktapctl =
+SHDEPS_libblktapctl =
 LDLIBS_libblktapctl =
 SHLIB_libblktapctl  =
 endif
 
 CFLAGS_libxenlight = -I$(XEN_XENLIGHT) $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude)
-LDLIBS_libxenlight = $(XEN_XENLIGHT)/libxenlight$(libextension) $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libblktapctl)
-SHLIB_libxenlight  = -Wl,-rpath-link=$(XEN_XENLIGHT)
+SHDEPS_libxenlight = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libblktapctl)
+LDLIBS_libxenlight = $(SHDEPS_libxenlight) $(XEN_XENLIGHT)/libxenlight$(libextension)
+SHLIB_libxenlight  = $(SHDEPS_libxenlight) -Wl,-rpath-link=$(XEN_XENLIGHT)
 
 CFLAGS += -D__XEN_TOOLS__
 
Signature · 1 line
2.1.4
#3 lore raw

PATCH v2 3/15 tools: Refactor "xentoollog" into its own library

In reply to Ian Campbell

In attempting to disaggregate libxenctrl I found that many of the pieces were going to want access to this library, so split it out (as it probably should always have been).

Various build adjustments are needed. In particular things which use xtl_* themselves now need to explicity link against the library.

This has a nice side effect which is that users of libxl no longer need to link against libxenctrl just to create a logger, which was counter to the principal that applications using libxl shouldn't be required to look behind the curtain. This means that xl no longer links against libxenctrl.

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 xentoollog as a separate library" and a corresponding QEMU_TAG update folded here.
- "mini-os: Include libxentoollog with libxc" and a corresponding bump to MINIOS_UPSTREAM_REVISION folded in here.

v2: Update doc at same time

---
 .gitignore                               |   1 +
 docs/misc/toolstack-library-abis.pandoc  |  36 +++---
 stubdom/Makefile                         |  20 +++-
 stubdom/grub/Makefile                    |   1 +
 tools/Makefile                           |   3 +
 tools/Rules.mk                           |  14 ++-
 tools/libxc/Makefile                     |   7 +-
 tools/libxc/include/xentoollog.h         | 137 ----------------------
 tools/libxc/xtl_core.c                   |  84 --------------
 tools/libxc/xtl_logger_stdio.c           | 193 -------------------------------
 tools/libxentoollog/Makefile             |  59 ++++++++++
 tools/libxentoollog/include/xentoollog.h | 137 ++++++++++++++++++++++
 tools/libxentoollog/libxentoollog.map    |  12 ++
 tools/libxentoollog/xtl_core.c           |  84 ++++++++++++++
 tools/libxentoollog/xtl_logger_stdio.c   | 193 +++++++++++++++++++++++++++++++
 tools/libxl/Makefile                     |  15 +--
 tools/ocaml/Makefile.rules               |  26 ++---
 tools/ocaml/libs/xentoollog/Makefile     |   6 +-
 tools/ocaml/libs/xentoollog/genlevels.py |   2 +-
 tools/python/setup.py                    |   5 +-
 tools/xenpaging/Makefile                 |   2 +-
 21 files changed, 571 insertions(+), 466 deletions(-)
 delete mode 100644 tools/libxc/include/xentoollog.h
 delete mode 100644 tools/libxc/xtl_core.c
 delete mode 100644 tools/libxc/xtl_logger_stdio.c
 create mode 100644 tools/libxentoollog/Makefile
 create mode 100644 tools/libxentoollog/include/xentoollog.h
 create mode 100644 tools/libxentoollog/libxentoollog.map
 create mode 100644 tools/libxentoollog/xtl_core.c
 create mode 100644 tools/libxentoollog/xtl_logger_stdio.c
.gitignore +1 -0
index 464f3f4..e56487a 100644
@@ -59,6 +59,7 @@ stubdom/gcc-*
 stubdom/include
 stubdom/ioemu
 stubdom/xenstore
+stubdom/libxentoollog-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
docs/misc/toolstack-library-abis.pandoc +20 -16
index c24be81..68e6742 100644
@@ -91,6 +91,26 @@ rationalisation of what lives where.
 
 Not a candidate for API/ABI stability at this point.
 
+# Stable libraries
+ 
+These libraries will provide a stable API to all consumers going
+forward. They can be mixed and matched with Xen version.
+
+## `libxentoollog`: logging
+
+The following do not depend on any underlying Xen functionality.
+
+Interface                     Known external users
+----------------------------- --------------------
+`xtl_createlogger_stdiostream`
+`xtl_level_to_string`
+`xtl_log`
+`xtl_logger_destroy`
+`xtl_logv`
+`xtl_progress`
+`xtl_stdiostream_adjust_flags`
+`xtl_stdiostream_set_minlevel`
+
 # Unstable libraries
 
 These libraries do not provide a stable interface and are required to
@@ -124,22 +144,6 @@ Notes:
   via `...` (often a macro).
 * There are lots of static functions in the `xc_*` namespace.
 
-### Logging
-
-The following are already logically somewhat separate. They do not
-depend on any underlying Xen functionality.
-
-Interface                     Known external users
------------------------------ --------------------
-`xtl_createlogger_stdiostream`
-`xtl_level_to_string`
-`xtl_log`
-`xtl_logger_destroy`
-`xtl_logv`
-`xtl_progress`
-`xtl_stdiostream_adjust_flags`
-`xtl_stdiostream_set_minlevel`
-
 ### Basic interface
 
     - xc_interface_close
stubdom/Makefile +19 -1
index faa7c21..b8b0d43 100644
@@ -313,6 +313,11 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(wildcard $(XEN_ROOT)/tools/include/xen-foreign/*) include/xen-foreign/ && \
 	  $(MAKE) DESTDIR= -C include/xen-foreign/ && \
 	  ( [ -h include/xen/foreign ] || ln -sf ../xen-foreign include/xen/foreign )
+	mkdir -p libxentoollog-$(XEN_TARGET_ARCH)
+	[ -h libxentoollog-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxentoollog-$(XEN_TARGET_ARCH) && \
+	  ln -sf $(XEN_ROOT)/tools/libxentoollog/include/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libxentoollog/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libxentoollog/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 . && \
@@ -336,12 +341,23 @@ $(TARGETS_MINIOS): mini-os-%:
 	done
 
 #######
+# libxentoollog
+#######
+
+.PHONY: libxentoollog
+libxentoollog: libxentoollog-$(XEN_TARGET_ARCH)/libxentoollog.a
+libxentoollog-$(XEN_TARGET_ARCH)/libxentoollog.a: $(NEWLIB_STAMPFILE)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
+	$(MAKE) DESTDIR= -C $(MINI_OS) links
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxentoollog-$(XEN_TARGET_ARCH)
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog cross-zlib
 	$(MAKE) -C $(XEN_ROOT)/tools/include
 	$(MAKE) DESTDIR= -C $(MINI_OS) links
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
@@ -519,6 +535,7 @@ clean:
 	$(MAKE) -C vtpmmgr clean
 	rm -fr grub-$(XEN_TARGET_ARCH)
 	rm -f $(STUBDOMPATH)
+	[ ! -e libxentoollog-$(XEN_TARGET_ARCH)/Makefile ] || $(MAKE) DESTDIR= -C libxentoollog-$(XEN_TARGET_ARCH) clean
 	[ ! -e libxc-$(XEN_TARGET_ARCH)/Makefile ] || $(MAKE) DESTDIR= -C libxc-$(XEN_TARGET_ARCH) clean
 	-[ ! -d ioemu ] || $(MAKE) DESTDIR= -C ioemu clean
 	-[ ! -d xenstore ] || $(MAKE) DESTDIR= -C xenstore clean
@@ -529,6 +546,7 @@ crossclean: clean
 	rm -fr $(CROSS_ROOT)
 	rm -fr newlib-$(XEN_TARGET_ARCH)
 	rm -fr zlib-$(XEN_TARGET_ARCH) pciutils-$(XEN_TARGET_ARCH)
+	rm -fr libxentoollog-$(XEN_TARGET_ARCH)
 	rm -fr libxc-$(XEN_TARGET_ARCH) ioemu xenstore
 	rm -fr gmp-$(XEN_TARGET_ARCH)
 	rm -fr polarssl-$(XEN_TARGET_ARCH)
stubdom/grub/Makefile +1 -0
index 934cc4c..4969274 100644
@@ -5,6 +5,7 @@ vpath %.c ../grub-upstream
 
 BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
 
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxentoollog/include
 DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libxc/include -I$(XEN_ROOT)/tools/include -I.
 DEF_CPPFLAGS += -I../grub-upstream/stage1
 DEF_CPPFLAGS += -I../grub-upstream/stage2
tools/Makefile +3 -0
index 45cb4b2..777591a 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS-y :=
 SUBDIRS-y += include
+SUBDIRS-y += libxentoollog
 SUBDIRS-y += libxc
 SUBDIRS-$(FLASK_ENABLE) += flask
 SUBDIRS-y += xenstore
@@ -248,12 +249,14 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		--includedir=$(LIBEXEC_INC) \
 		--source-path=$$source \
 		--extra-cflags="-I$(XEN_ROOT)/tools/include \
+		-I$(XEN_ROOT)/tools/libxentoollog/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 \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxentoollog \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +10 -4
index 28e84e6..11227c7 100644
@@ -10,6 +10,7 @@ export _INSTALL := $(INSTALL)
 INSTALL = $(XEN_ROOT)/tools/cross-install
 
 XEN_INCLUDE        = $(XEN_ROOT)/tools/include
+XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libxentoollog
 XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
 XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
 XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
@@ -76,10 +77,15 @@ endif
 # Consumers of libfoo should not directly use $(SHDEPS_libfoo) or
 # $(SHLIB_libfoo)
 
-CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenctrl =
-LDLIBS_libxenctrl = $(XEN_LIBXC)/libxenctrl$(libextension)
-SHLIB_libxenctrl  = -Wl,-rpath-link=$(XEN_LIBXC)
+CFLAGS_libxentoollog = -I$(XEN_LIBXENTOOLLOG)/include $(CFLAGS_xeninclude)
+SHDEPS_libxentoollog =
+LDLIBS_libxentoollog = $(XEN_LIBXENTOOLLOG)/libxentoollog$(libextension)
+SHLIB_libxentoollog  = -Wl,-rpath-link=$(XEN_LIBXENTOOLLOG)
+
+CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude)
+SHDEPS_libxenctrl = $(SHLIB_libxentoollog) 
+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 =
tools/libxc/Makefile +3 -4
index 1aec848..feb6125 100644
@@ -38,8 +38,6 @@ CTRL_SRCS-y       += xc_memshr.c
 CTRL_SRCS-y       += xc_hcall_buf.c
 CTRL_SRCS-y       += xc_foreign_memory.c
 CTRL_SRCS-y       += xc_kexec.c
-CTRL_SRCS-y       += xtl_core.c
-CTRL_SRCS-y       += xtl_logger_stdio.c
 CTRL_SRCS-y       += xc_resource.c
 CTRL_SRCS-$(CONFIG_X86) += xc_psr.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
@@ -113,6 +111,7 @@ CFLAGS   += -I. -I./include $(CFLAGS_xeninclude)
 CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
 
 CFLAGS	+= $(PTHREAD_CFLAGS)
+CFLAGS	+= $(CFLAGS_libxentoollog)
 
 CTRL_LIB_OBJS := $(patsubst %.c,%.o,$(CTRL_SRCS-y))
 CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y))
@@ -166,7 +165,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 include/xentoollog.h $(DESTDIR)$(includedir)
+	$(INSTALL_DATA) include/xenctrl.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)
@@ -209,7 +208,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 $@ $^ $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 # libxenguest
 
tools/libxc/include/xentoollog.h deleted +0 -137

137 lines not on this page · raw message

tools/libxc/xtl_core.c deleted +0 -84

84 lines not on this page · raw message

tools/libxc/xtl_logger_stdio.c deleted +0 -193

193 lines not on this page · raw message

tools/libxentoollog/Makefile new file +59 -0

59 lines not on this page · raw message

tools/libxentoollog/include/xentoollog.h new file +137 -0

137 lines not on this page · raw message

tools/libxentoollog/libxentoollog.map new file +12 -0
new file mode 100644
index 0000000..c183cf5
@@ -0,0 +1,12 @@
+VERS_1.0 {
+	global:
+		xtl_createlogger_stdiostream;
+		xtl_level_to_string;
+		xtl_log;
+		xtl_logger_destroy;
+		xtl_logv;
+		xtl_progress;
+		xtl_stdiostream_adjust_flags;
+		xtl_stdiostream_set_minlevel;
+	local: *; /* Do not expose anything by default */
+};
tools/libxentoollog/xtl_core.c new file +84 -0

84 lines not on this page · raw message

tools/libxentoollog/xtl_logger_stdio.c new file +193 -0

193 lines not on this page · raw message

tools/libxl/Makefile +8 -7
index 6e74025..cdf350a 100644
@@ -20,11 +20,12 @@ LIBUUID_LIBS += -luuid
 endif
 
 LIBXL_LIBS =
-LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS)
+LIBXL_LIBS = $(LDLIBS_libxentoollog) $(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_libxenctrl)
 CFLAGS_LIBXL += $(CFLAGS_libxenguest)
 CFLAGS_LIBXL += $(CFLAGS_libxenstore)
@@ -148,7 +149,7 @@ CFLAGS_XL += -Wshadow
 
 XL_OBJS = xl.o xl_cmdimpl.o xl_cmdtable.o xl_sxp.o
 $(XL_OBJS) $(TEST_PROG_OBJS) _libxl.api-for-check: \
-            CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
+            CFLAGS += $(CFLAGS_libxentoollog)
 $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
 $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs it.
 
@@ -252,19 +253,19 @@ libxlutil.a: $(LIBXLU_OBJS)
 	$(AR) rcs libxlutil.a $^
 
 xl: $(XL_OBJS) libxlutil.so libxenlight.so
-	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl) -lyajl $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS)
 
 xen-init-dom0: $(XEN_INIT_DOM0_OBJS) libxenlight.so
-	$(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
 
 test_%: test_%.o test_common.o libxlutil.so libxenlight_test.so
-	$(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxenctrl) -lyajl $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS)
 
 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so
-	$(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
 
 testidl: testidl.o libxlutil.so libxenlight.so
-	$(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
 
 $(PKG_CONFIG): % : %.in Makefile
 	@sed -e 's/@@version@@/$(MAJOR).$(MINOR)/g' < $< > [email protected]
tools/ocaml/Makefile.rules +13 -13
index 1796060..45e71f2 100644
@@ -1,18 +1,18 @@
-ifdef V
-  ifeq ("$(origin V)", "command line")
-    BUILD_VERBOSE = $(V)
-  endif
-endif
-ifndef BUILD_VERBOSE
-  BUILD_VERBOSE = 0
-endif
-ifeq ($(BUILD_VERBOSE),1)
+#ifdef V
+#  ifeq ("$(origin V)", "command line")
+#    BUILD_VERBOSE = $(V)
+#  endif
+#endif
+#ifndef BUILD_VERBOSE
+#  BUILD_VERBOSE = 0
+#endif
+#ifeq ($(BUILD_VERBOSE),1)
   E = @true
   Q =
-else
-  E = @echo
-  Q = @
-endif
+#else
+#  E = @echo
+#  Q = @
+#endif
 
 .NOTPARALLEL:
 
tools/ocaml/libs/xentoollog/Makefile +3 -3
index 666eb66..084a3f4 100644
@@ -5,7 +5,7 @@ include $(TOPLEVEL)/common.make
 # allow mixed declarations and code
 CFLAGS += -Wno-declaration-after-statement
 
-CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
+CFLAGS += $(CFLAGS_libxentoollog)
 CFLAGS += $(APPEND_CFLAGS)
 OCAMLINCLUDE +=
 
@@ -13,7 +13,7 @@ OBJS = xentoollog
 INTF = xentoollog.cmi
 LIBS = xentoollog.cma xentoollog.cmxa
 
-LIBS_xentoollog = $(LDLIBS_libxenctrl)
+LIBS_xentoollog = $(LDLIBS_libxentoollog)
 
 xentoollog_OBJS = $(OBJS)
 xentoollog_C_OBJS = xentoollog_stubs
@@ -49,7 +49,7 @@ xentoollog.mli: xentoollog.mli.in _xtl_levels.mli.in
 
 libs: $(LIBS)
 
-_xtl_levels.ml.in _xtl_levels.mli.in _xtl_levels.inc: genlevels.py $(XEN_ROOT)/tools/libxc/include/xentoollog.h
+_xtl_levels.ml.in _xtl_levels.mli.in _xtl_levels.inc: genlevels.py $(XEN_ROOT)/tools/libxentoollog/include/xentoollog.h
 	$(PYTHON) genlevels.py _xtl_levels.mli.in _xtl_levels.ml.in _xtl_levels.inc
 
 .PHONY: install
tools/ocaml/libs/xentoollog/genlevels.py +1 -1
index 65d334f..4de4fb1 100755
@@ -3,7 +3,7 @@
 import sys
 
 def read_levels():
-	f = open('../../../libxc/include/xentoollog.h', 'r')
+	f = open('../../../libxentoollog/include/xentoollog.h', 'r')
 
 	levels = []
 	record = False
tools/python/setup.py +3 -2
index 5bf81be..5a03266 100644
@@ -7,16 +7,17 @@ XEN_ROOT = "../.."
 extra_compile_args  = [ "-fno-strict-aliasing", "-Werror" ]
 
 PATH_XEN      = XEN_ROOT + "/tools/include"
+PATH_LIBXENTOOLLOG = XEN_ROOT + "/tools/libxentoollog"
 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_LIBXC + "/include", "xen/lowlevel/xc" ],
+               include_dirs       = [ PATH_XEN, PATH_LIBXENTOOLLOG + "/include", PATH_LIBXC + "/include", "xen/lowlevel/xc" ],
                library_dirs       = [ PATH_LIBXC ],
                libraries          = [ "xenctrl", "xenguest" ],
-               depends            = [ PATH_LIBXC + "/libxenctrl.so", PATH_LIBXC + "/libxenguest.so" ],
+               depends            = [ PATH_LIBXC + "/libxenctrl.so", PATH_LIBXC + "/libxenguest.so",  "-Wl,-rpath-link="+PATH_LIBXENTOOLLOG ],
                sources            = [ "xen/lowlevel/xc/xc.c" ])
 
 xs = Extension("xs",
tools/xenpaging/Makefile +1 -1
index 2407a30..e63d894 100644
@@ -3,7 +3,7 @@ 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_libxenctrl) $(LDLIBS_libxenstore) $(PTHREAD_LIBS)
+LDLIBS += $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenstore) $(PTHREAD_LIBS)
 LDFLAGS += $(PTHREAD_LDFLAGS)
 
 POLICY    = default
Signature · 1 line
2.1.4
#4 lore raw

PATCH v2 4/15 tools/libxc: Remove osdep indirection for xc_evtchn

In reply to Ian Campbell

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
index ce9029c..53df9a9 100644
@@ -118,7 +118,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
index e97944b..a8b27ae 100644
@@ -52,7 +52,6 @@
 
 enum xc_osdep_type {
     XC_OSDEP_PRIVCMD,
-    XC_OSDEP_EVTCHN,
     XC_OSDEP_GNTTAB,
     XC_OSDEP_GNTSHR,
 };
@@ -91,21 +90,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
index 2ffebd9..9f0ada7 100644
@@ -120,7 +120,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";
     }
@@ -253,20 +252,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
index 247a408..4c66766 100644
@@ -124,6 +124,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,
@@ -447,3 +454,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
index abefd6b..5939e7c 100644
@@ -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
#5 lore raw

PATCH v2 5/15 tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.

In reply to Ian Campbell

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

---
 .gitignore                                    |   1 +
 docs/misc/toolstack-library-abis.pandoc       |  38 ++--
 stubdom/Makefile                              |  19 +-
 tools/Makefile                                |   6 +-
 tools/Rules.mk                                |  14 +-
 tools/console/Makefile                        |   2 +
 tools/console/daemon/io.c                     |  43 +++--
 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                |  10 +-
 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/libxenevtchn/Makefile                   |  65 +++++++
 tools/libxenevtchn/core.c                     |  70 +++++++
 tools/libxenevtchn/freebsd.c                  | 135 +++++++++++++
 tools/libxenevtchn/include/xenevtchn.h        | 147 ++++++++++++++
 tools/libxenevtchn/libxenevtchn.map           |  14 ++
 tools/libxenevtchn/linux.c                    | 133 +++++++++++++
 tools/libxenevtchn/minios.c                   | 266 ++++++++++++++++++++++++++
 tools/libxenevtchn/netbsd.c                   | 144 ++++++++++++++
 tools/libxenevtchn/private.h                  |  25 +++
 tools/libxenevtchn/solaris.c                  | 132 +++++++++++++
 tools/libxentoollog/include/xentoollog.h      |  10 +
 tools/libxentoollog/xtl_core.c                |  10 +
 tools/libxentoollog/xtl_logger_stdio.c        |  10 +
 tools/libxl/Makefile                          |   5 +-
 tools/libxl/libxl.c                           |   2 +-
 tools/libxl/libxl_dom.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/xen-access.c           |   2 +-
 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 +-
 60 files changed, 1520 insertions(+), 929 deletions(-)
 create mode 100644 tools/libxc/include/xenctrl_compat.h
 create mode 100644 tools/libxc/xc_evtchn_compat.c
 create mode 100644 tools/libxenevtchn/Makefile
 create mode 100644 tools/libxenevtchn/core.c
 create mode 100644 tools/libxenevtchn/freebsd.c
 create mode 100644 tools/libxenevtchn/include/xenevtchn.h
 create mode 100644 tools/libxenevtchn/libxenevtchn.map
 create mode 100644 tools/libxenevtchn/linux.c
 create mode 100644 tools/libxenevtchn/minios.c
 create mode 100644 tools/libxenevtchn/netbsd.c
 create mode 100644 tools/libxenevtchn/private.h
 create mode 100644 tools/libxenevtchn/solaris.c
.gitignore +1 -0
index e56487a..ed6bac6 100644
@@ -60,6 +60,7 @@ stubdom/include
 stubdom/ioemu
 stubdom/xenstore
 stubdom/libxentoollog-*
+stubdom/libxenevtchn-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
docs/misc/toolstack-library-abis.pandoc +24 -14
index 68e6742..d7ae875 100644
@@ -111,6 +111,23 @@ Interface                     Known external users
 `xtl_stdiostream_adjust_flags`
 `xtl_stdiostream_set_minlevel`
 
+## `libxenevtchn`: event channels
+
+Interacting with Event Channels via `/dev/xen/evtchn`.
+
+Interface                     Underlying interface             Known external users
+----------------------------- -------------------------------- --------------------
+`xenevtchn_bind_interdomain`  `IOCTL_EVTCHN_BIND_INTERDOMAIN`  qemu-pv
+`xenevtchn_bind_unbound_port` `IOCTL_EVTCHN_BIND_UNBOUND_PORT`
+`xenevtchn_bind_virq`         `IOCTL_EVTCHN_BIND_VIRQ`
+`xenevtchn_close`             `close(2)`                       qemu-dm
+`xenevtchn_fd`
+`xenevtchn_notify`            `IOCTL_EVTCHN_NOTIFY`            qemu-dm, qemu-pv
+`xenevtchn_open`              `open(2)`                        qemu-dm, qemu-pv
+`xenevtchn_pending`           `read(2)`                        qemu-dm, qemu-pv
+`xenevtchn_unbind`            `IOCTL_EVTCHN_UNBIND`            qemu-pv
+`xenevtchn_unmask`            `write(2)`                       qemu-dm, qemu-pv
+
 # Unstable libraries
 
 These libraries do not provide a stable interface and are required to
@@ -153,20 +170,10 @@ Notes:
 ### Event channels
 
 Interacting with Event Channels via `__HYPERVISOR_event_channel_op`
-(`EVTCHNOP_*`) or `/dev/xen/evtchn`.
+(`EVTCHNOP_*`).
 
 Interface                     Underlying interface             Known external users
 ----------------------------- -------------------------------- --------------------
-`xc_evtchn_bind_interdomain`  `IOCTL_EVTCHN_BIND_INTERDOMAIN`  qemu-pv
-`xc_evtchn_bind_unbound_port` `IOCTL_EVTCHN_BIND_UNBOUND_PORT`
-`xc_evtchn_bind_virq`         `IOCTL_EVTCHN_BIND_VIRQ`
-`xc_evtchn_close`             `close(2)`                       qemu-dm
-`xc_evtchn_fd`
-`xc_evtchn_notify`            `IOCTL_EVTCHN_NOTIFY`            qemu-dm, qemu-pv
-`xc_evtchn_open`              `open(2)`                        qemu-dm, qemu-pv
-`xc_evtchn_pending`           `read(2)`                        qemu-dm, qemu-pv
-`xc_evtchn_unbind`            `IOCTL_EVTCHN_UNBIND`            qemu-pv
-`xc_evtchn_unmask`            `write(2)`                       qemu-dm, qemu-pv
 `xc_evtchn_alloc_unbound`     `EVTCHNOP_alloc_unbound`
 `xc_evtchn_reset`             `EVTCHNOP_reset`
 `xc_evtchn_status`            `EVTCHNOP_status`
@@ -726,11 +733,14 @@ Gathered by:
     - xc_mark_page_online
     - xc_query_page_offline_status
     - xc_read_image
-    - xc_suspend_evtchn_init_exclusive
-    - xc_suspend_evtchn_init_sane
-    - xc_suspend_evtchn_release
     - xc_try_lz4_decode
 
+Use privcmd and evtchn device handles:
+
+    - xc_suspend_evtchn_init_exclusive. Used by xen-hptool and libxl.
+    - xc_suspend_evtchn_init_sane. Unused
+    - xc_suspend_evtchn_release. Used by xen-hptool and libxl.
+
 # Consumers of `libxenctrl` functionality
 
 ## `qemu`
stubdom/Makefile +18 -1
index b8b0d43..b4dd39a 100644
@@ -318,6 +318,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libxentoollog/include/*.h . && \
 	  ln -sf $(XEN_ROOT)/tools/libxentoollog/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libxentoollog/Makefile . )
+	mkdir -p libxenevtchn-$(XEN_TARGET_ARCH)/include
+	[ -h libxenevtchn-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxenevtchn-$(XEN_TARGET_ARCH) && \
+	  ln -sf $(XEN_ROOT)/tools/libxenevtchn/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libxenevtchn/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libxenevtchn/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libxenevtchn/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 . && \
@@ -352,12 +358,23 @@ libxentoollog-$(XEN_TARGET_ARCH)/libxentoollog.a: $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxentoollog-$(XEN_TARGET_ARCH)
 
 #######
+# libxenevtchn
+#######
+
+.PHONY: libxenevtchn
+libxenevtchn: libxenevtchn-$(XEN_TARGET_ARCH)/libxenevtchn.a
+libxenevtchn-$(XEN_TARGET_ARCH)/libxenevtchn.a: $(NEWLIB_STAMPFILE)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
+	$(MAKE) DESTDIR= -C $(MINI_OS) links
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxenevtchn-$(XEN_TARGET_ARCH)
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog libxenevtchn cross-zlib
 	$(MAKE) -C $(XEN_ROOT)/tools/include
 	$(MAKE) DESTDIR= -C $(MINI_OS) links
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
tools/Makefile +5 -1
index 777591a..3497c53 100644
@@ -4,6 +4,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 SUBDIRS-y :=
 SUBDIRS-y += include
 SUBDIRS-y += libxentoollog
+SUBDIRS-y += libxenevtchn
 SUBDIRS-y += libxc
 SUBDIRS-$(FLASK_ENABLE) += flask
 SUBDIRS-y += xenstore
@@ -248,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/libxentoollog/include \
+		-I$(XEN_ROOT)/tools/libxenevtchn/include \
 		-I$(XEN_ROOT)/tools/libxc/include \
 		-I$(XEN_ROOT)/tools/xenstore/include \
 		-I$(XEN_ROOT)/tools/xenstore/compat/include \
@@ -257,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/libxentoollog \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxenevtchn \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +10 -4
index 11227c7..e200eb7 100644
@@ -11,6 +11,7 @@ INSTALL = $(XEN_ROOT)/tools/cross-install
 
 XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libxentoollog
+XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libxenevtchn
 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=L$(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
index 71f8088..0141d7f 100644
@@ -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/libvchan/Makefile +3 -3
index 3c50fe6..84128a3 100644
@@ -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
index de10817..fef6c8d 100644
@@ -217,25 +217,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;
@@ -347,26 +347,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
index e66bc4e..4bd15ed 100644
@@ -106,7 +106,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;
 }
@@ -195,10 +195,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;
 }
 
@@ -351,7 +351,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)
@@ -373,8 +373,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
index 6365d36..0517dda 100644
@@ -45,6 +45,7 @@
 
 #include <xen/io/libxenvchan.h>
 #include <xen/sys/evtchn.h>
+#include <xenevtchn.h>
 #include <xenctrl.h>
 
 struct libxenvchan_ring {
@@ -72,7 +73,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
index feb6125..baf054f 100644
@@ -47,6 +47,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
@@ -112,6 +113,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))
@@ -165,7 +167,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)
@@ -208,7 +210,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
 
@@ -231,7 +233,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 +6 -4
index e95af54..584ebdc 100644
@@ -23,6 +23,8 @@
 #ifndef XENGUEST_H
 #define XENGUEST_H
 
+#include <xenevtchn.h>
+
 #define XC_NUMA_NO_NODE   (~0U)
 
 #define XCFLAGS_LIVE      (1 << 0)
@@ -288,18 +290,18 @@ int xc_hvm_build_target_mem(xc_interface *xch,
  * 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
@@ -308,7 +310,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_get_bit_size(xc_interface *xch,
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
index 9f0ada7..375430c 100644
@@ -252,46 +252,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
index 4c66766..61f2f45 100644
@@ -124,13 +124,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
index e22f4ac..139edb4 100644
@@ -17,6 +17,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <xenevtchn.h>
+
 #include "xc_private.h"
 #include "xenguest.h"
 
@@ -125,12 +127,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;
@@ -138,7 +140,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;
@@ -146,16 +148,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;
@@ -165,7 +167,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;
@@ -185,7 +187,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/libxenevtchn/Makefile new file +65 -0

65 lines not on this page · raw message

tools/libxenevtchn/core.c new file +70 -0

70 lines not on this page · raw message

tools/libxenevtchn/freebsd.c new file +135 -0

135 lines not on this page · raw message

tools/libxenevtchn/include/xenevtchn.h new file +147 -0

147 lines not on this page · raw message

tools/libxenevtchn/libxenevtchn.map new file +14 -0
new file mode 100644
index 0000000..1437940
@@ -0,0 +1,14 @@
+VERS_1.0 {
+	global:
+		xenevtchn_fd;
+		xenevtchn_bind_unbound_port;
+		xenevtchn_unbind;
+		xenevtchn_unmask;
+		xenevtchn_notify;
+		xenevtchn_bind_interdomain;
+		xenevtchn_bind_virq;
+		xenevtchn_open;
+		xenevtchn_close;
+		xenevtchn_pending;
+	local: *; /* Do not expose anything by default */
+};
tools/libxenevtchn/linux.c new file +133 -0

133 lines not on this page · raw message

tools/libxenevtchn/minios.c new file +266 -0

266 lines not on this page · raw message

tools/libxenevtchn/netbsd.c new file +144 -0

144 lines not on this page · raw message

tools/libxenevtchn/private.h new file +25 -0
new file mode 100644
index 0000000..fcd0e96
@@ -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/libxenevtchn/solaris.c new file +132 -0

132 lines not on this page · raw message

tools/libxentoollog/include/xentoollog.h +10 -0
index 85d3da9..d08456c 100644
@@ -135,3 +135,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/libxentoollog/xtl_core.c +10 -0
index 73add92..ec2b155 100644
@@ -82,3 +82,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/libxentoollog/xtl_logger_stdio.c +10 -0
index b28ef73..1518176 100644
@@ -191,3 +191,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/libxl/Makefile +3 -2
index cdf350a..ac57f66 100644
@@ -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)
@@ -158,7 +159,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
index 3fe1b99..5a5d344 100644
@@ -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.c +2 -2
index 81adb3d..dd830ac 100644
@@ -1480,9 +1480,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
index 8acecfa..6dade69 100644
@@ -744,7 +744,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;
@@ -770,20 +770,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);
@@ -793,7 +793,7 @@ int libxl__ctx_evtchn_init(libxl__gc *gc) {
     return 0;
 
  out:
-    xc_evtchn_close(xce);
+    xenevtchn_close(xce);
     return rc;
 }
 
@@ -815,14 +815,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
index 2b6b2a0..4b59cad 100644
@@ -48,6 +48,7 @@
 #include <sys/file.h>
 #include <sys/ioctl.h>
 
+#include <xenevtchn.h>
 #include <xenstore.h>
 #include <xenctrl.h>
 #include <xenguest.h>
@@ -434,7 +435,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;
 
@@ -894,7 +895,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
index c4490f3..cf6a475 100644
@@ -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
index c7561a9..ebcc9e8 100644
@@ -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
index 82ffd75..3200404 100644
@@ -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);
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

tools/ocaml/libs/eventchn/Makefile +2 -2
index 2d8d618..154efd4 100644

Lines of this file are not shown. View the raw message.

tools/ocaml/libs/eventchn/xeneventchn_stubs.c +10 -10
index 5939e7c..c2d4737 100644

Lines of this file are not shown. View the raw message.

tools/python/setup.py +6 -1
index 5a03266..e6c8b18 100644

Lines of this file are not shown. View the raw message.

tools/tests/xen-access/xen-access.c +1 -1
index e6ca9ba..545217e 100644

Lines of this file are not shown. View the raw message.

tools/xcutils/Makefile +2 -2
index fff519d..2d1f112 100644

Lines of this file are not shown. View the raw message.

tools/xenmon/Makefile +2 -0
index 5095682..fa80983 100644

Lines of this file are not shown. View the raw message.

tools/xenmon/xenbaked.c +7 -6
index dc61d14..f092aec 100644

Lines of this file are not shown. View the raw message.

tools/xenpaging/Makefile +2 -2
index e63d894..d491867 100644

Lines of this file are not shown. View the raw message.

tools/xenpaging/xenpaging.c +9 -9
index 3f4c2e9..6776896 100644

Lines of this file are not shown. View the raw message.

tools/xenpaging/xenpaging.h +2 -1
index 25d511d..6c12030 100644

Lines of this file are not shown. View the raw message.

tools/xenstore/Makefile +3 -2
index 1b4a494..c161046 100644

Lines of this file are not shown. View the raw message.

tools/xenstore/xenstored_core.c +4 -2
index b18000d..7f1e489 100644

Lines of this file are not shown. View the raw message.

tools/xenstore/xenstored_domain.c +13 -12
index 0776e39..b649107 100644

Lines of this file are not shown. View the raw message.

tools/xentrace/Makefile +4 -1
index 2f57bda..ab27284 100644

Lines of this file are not shown. View the raw message.

tools/xentrace/xentrace.c +7 -6
index 4ee1458..c970d42 100644

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.

#6 lore raw

Re: [PATCH XEN v2 05/15] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.

Quoted 6 lines · Ian Campbell
tools/libxenevtchn/include/xenevtchn.h new file +2 -0
[...]
 
+/* A port identifier is guaranteed to fit in 31 bits. */
+typedef int evtchn_port_or_error_t;

[...]

Quoted 4 lines
tools/libxenevtchn/include/xenevtchn.h new file +4 -0
+/*
+ * 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.
+ */

tools/libxenevtchn/include/xenevtchn.h line 96

Quoted 10 lines
tools/libxenevtchn/include/xenevtchn.h new file +10 -0
+evtchn_port_or_error_t
+xenevtchn_bind_unbound_port(xenevtchn_handle *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
+xenevtchn_bind_interdomain(xenevtchn_handle *xce, int domid,
+                           evtchn_port_t remote_port);

ISTR that this evtchn_port_or_error_t construct was introduce in order to correct an incorrect type used here without changing the API in annoying ways.

Given that this series is already changing the API anyway do we want to take the opportunity prior to declaring this new library ABI/API stable to rework these functions such that they return 0 or -1 and take a evtchn_port_t * output variable which they update on success?

And then abolish evtchn_port_or_error_t except for the
XC_WANT_COMPAT_EVTCHN_API case.

Ian.

#7 lore raw

PATCH v2 6/15 tools: Arrange to check public headers for ANSI compatiblity

In reply to Ian Campbell

Using the same rune as we use for the Xen public headers, except we do not need stdint.h here and we use -pedantic too.

---
 .gitignore                   | 2 ++
 tools/Rules.mk               | 8 ++++++++
 tools/libxenevtchn/Makefile  | 4 +++-
 tools/libxentoollog/Makefile | 5 ++++-
 4 files changed, 17 insertions(+), 2 deletions(-)
.gitignore +2 -0
index ed6bac6..61167d9 100644
@@ -87,6 +87,8 @@ tools/config.cache
 config/Tools.mk
 config/Stubdom.mk
 config/Docs.mk
+tools/libxentoollog/headers.chk
+tools/libxenevtchn/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
tools/Rules.mk +8 -0
index e200eb7..f675fa7 100644
@@ -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 -pedantic $(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/libxenevtchn/Makefile +3 -1
index c3ea3c2..f180cee5 100644
@@ -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 $@ $^
@@ -63,3 +64,4 @@ TAGS:
 .PHONY: clean
 clean:
 	rm -rf *.rpm $(LIB) *~ $(DEPS) $(LIB_OBJS) $(PIC_OBJS)
+	rm -f headers.chk
tools/libxentoollog/Makefile +4 -1
index 0c8be13..f8153ec 100644
@@ -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 $@ $^
@@ -57,3 +59,4 @@ TAGS:
 .PHONY: clean
 clean:
 	rm -rf *.rpm $(LIB) *~ $(DEPS) $(LIB_OBJS) $(PIC_OBJS)
+	rm -f headers.chk
Signature · 1 line
2.1.4
#8 lore raw

PATCH v2 7/15 tools/libxc: Remove osdep indirection for xc_gnt{shr, tab}

In reply to Ian Campbell

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.

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          |  44 ++++++++++++++
 tools/libxc/xc_nognttab.c          |  48 +++++++++++++++
 tools/libxc/xc_private.c           |  83 +++++++++++++++++++++-----
 tools/libxc/xc_private.h           |  24 ++++++++
 10 files changed, 270 insertions(+), 193 deletions(-)
 create mode 100644 tools/libxc/xc_nogntshr.c
 create mode 100644 tools/libxc/xc_nognttab.c
tools/libxc/Makefile +5 -5
index baf054f..19ad0df 100644
@@ -42,11 +42,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
index d7ca161..e60aa34 100644
@@ -118,8 +118,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
index a8b27ae..bad10f6 100644
@@ -52,8 +52,6 @@
 
 enum xc_osdep_type {
     XC_OSDEP_PRIVCMD,
-    XC_OSDEP_GNTTAB,
-    XC_OSDEP_GNTSHR,
 };
 
 /* Opaque handle internal to the backend */
@@ -89,27 +87,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 +44 -0

44 lines not on this page · raw message

tools/libxc/xc_nognttab.c new file +48 -0

48 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
index 61f2f45..81af034 100644
@@ -124,6 +124,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
#9 lore raw

PATCH v2 8/15 tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab.

In reply to Ian Campbell

libxengnttab 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.

XXX consider combining into a single namespace (i.e. with xengnttab_handle having two open fd's in it on Linux)

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 (EVTCHNOP) 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.

---
 .gitignore                              |   2 +
 docs/misc/toolstack-library-abis.pandoc |  38 ++--
 stubdom/Makefile                        |  19 +-
 tools/Makefile                          |   4 +
 tools/Rules.mk                          |  14 +-
 tools/console/Makefile                  |   5 +-
 tools/console/daemon/io.c               |  21 +-
 tools/libvchan/Makefile                 |   8 +-
 tools/libvchan/init.c                   |  24 +--
 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               |  44 -----
 tools/libxc/xc_nognttab.c               |  48 -----
 tools/libxc/xc_private.c                |  80 --------
 tools/libxc/xc_private.h                |  24 ---
 tools/libxenevtchn/minios.c             |   5 +-
 tools/libxengnttab/Makefile             |  69 +++++++
 tools/libxengnttab/gntshr_core.c        |  89 +++++++++
 tools/libxengnttab/gntshr_unimp.c       |  59 ++++++
 tools/libxengnttab/gnttab_core.c        | 118 ++++++++++++
 tools/libxengnttab/gnttab_unimp.c       |  86 +++++++++
 tools/libxengnttab/include/xengnttab.h  | 215 +++++++++++++++++++++
 tools/libxengnttab/libxengnttab.map     |  23 +++
 tools/libxengnttab/linux.c              | 326 ++++++++++++++++++++++++++++++++
 tools/libxengnttab/minios.c             | 114 +++++++++++
 tools/libxengnttab/private.h            |  47 +++++
 tools/xenstore/Makefile                 |   4 +-
 tools/xenstore/xenstored_core.h         |   4 +-
 tools/xenstore/xenstored_domain.c       |  24 +--
 tools/xenstore/xenstored_minios.c       |   5 +-
 37 files changed, 1432 insertions(+), 849 deletions(-)
 create mode 100644 tools/libxc/xc_gnttab_compat.c
 delete mode 100644 tools/libxc/xc_nogntshr.c
 delete mode 100644 tools/libxc/xc_nognttab.c
 create mode 100644 tools/libxengnttab/Makefile
 create mode 100644 tools/libxengnttab/gntshr_core.c
 create mode 100644 tools/libxengnttab/gntshr_unimp.c
 create mode 100644 tools/libxengnttab/gnttab_core.c
 create mode 100644 tools/libxengnttab/gnttab_unimp.c
 create mode 100644 tools/libxengnttab/include/xengnttab.h
 create mode 100644 tools/libxengnttab/libxengnttab.map
 create mode 100644 tools/libxengnttab/linux.c
 create mode 100644 tools/libxengnttab/minios.c
 create mode 100644 tools/libxengnttab/private.h
.gitignore +2 -0
index 61167d9..8cbd177 100644
@@ -61,6 +61,7 @@ stubdom/ioemu
 stubdom/xenstore
 stubdom/libxentoollog-*
 stubdom/libxenevtchn-*
+stubdom/libxengnttab-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
@@ -89,6 +90,7 @@ config/Stubdom.mk
 config/Docs.mk
 tools/libxentoollog/headers.chk
 tools/libxenevtchn/headers.chk
+tools/libxengnttab/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
docs/misc/toolstack-library-abis.pandoc +24 -14
index d7ae875..6b6146a 100644
@@ -128,6 +128,29 @@ Interface                     Underlying interface             Known external us
 `xenevtchn_unbind`            `IOCTL_EVTCHN_UNBIND`            qemu-pv
 `xenevtchn_unmask`            `write(2)`                       qemu-dm, qemu-pv
 
+## `libxengnttab`: grant tables
+
+Interacting with Grant Tables via `/dev/xen/gnt{shr,alloc}`.
+
+Interface                         Underlying interface           Known external users
+--------------------------------- ------------------------------ --------------------
+`xengnttab_map_domain_grant_refs` `IOCTL_GNTDEV_SET_MAX_GRANTS`
+`xengnttab_map_grant_ref_notify`  `IOCTL_GNTDEV_MAP_GRANT_REF`
+`xengnttab_map_grant_ref`         `IOCTL_GNTDEV_MAP_GRANT_REF`   qemu-pv
+`xengnttab_map_grant_refs`        `IOCTL_GNTDEV_SET_MAX_GRANTS`  qemu-pv
+`xengnttab_munmap`                `munmap(2)`                    qemu-pv
+`xengnttab_open`                  `open(2)`                      qemu-pv
+`xengnttab_close`                 `close(2)`                     qemu-pv
+`xengnttab_set_max_grants`        `IOCTL_GNTDEV_SET_MAX_GRANTS`
+`xengntshr_close`                 `close(2)`
+`xengntshr_munmap`                `munmap(2)`
+`xengntshr_open`                  `open(2)`
+`xengntshr_share_page_notify`     `IOCTL_GNTALLOC_ALLOC_GREF`
+`xengntshr_share_pages`           `IOCTL_GNTALLOC_ALLOC_GREF`
+
+`xengnt???_*_notify` also use `IOCTL_GNTALLOC_SET_UNMAP_NOTIFY`,
+`IOCTL_GNTALLOC_SET_UNMAP_NOTIFY`, etc
+
 # Unstable libraries
 
 These libraries do not provide a stable interface and are required to
@@ -181,23 +204,10 @@ Interface                     Underlying interface             Known external us
 ### Grant tables
 
 Interacting with Grant Tables via `__HYPERVISOR_grant_table_op`
-(`GNTTABOP_*`) or `/dev/xen/gnt{shr,alloc}`.
+(`GNTTABOP_*`)`.
 
 Interface                         Underlying interface           Known external users
 --------------------------------- ------------------------------ --------------------
-`xc_gnttab_map_domain_grant_refs` `IOCTL_GNTDEV_SET_MAX_GRANTS`
-`xc_gnttab_map_grant_ref_notify`  `IOCTL_GNTDEV_MAP_GRANT_REF`
-`xc_gnttab_map_grant_ref`         `IOCTL_GNTDEV_MAP_GRANT_REF`   qemu-pv
-`xc_gnttab_map_grant_refs`        `IOCTL_GNTDEV_SET_MAX_GRANTS`  qemu-pv
-`xc_gnttab_munmap`                `munmap(2)`                    qemu-pv
-`xc_gnttab_open`                  `open(2)`                      qemu-pv
-`xc_gnttab_close`                 `close(2)`                     qemu-pv
-`xc_gnttab_set_max_grants`        `IOCTL_GNTDEV_SET_MAX_GRANTS`
-`xc_gntshr_close`                 `close(2)`
-`xc_gntshr_munmap`                `munmap(2)`
-`xc_gntshr_open`                  `open(2)`
-`xc_gntshr_share_page_notify`     `IOCTL_GNTALLOC_ALLOC_GREF`
-`xc_gntshr_share_pages`           `IOCTL_GNTALLOC_ALLOC_GREF`
 `xc_gnttab_op`                    `__HYPERVISOR_grant_table_op`
 `xc_gnttab_get_version`           `GNTTABOP_get_version`
 `xc_gnttab_map_table_v1`          `GNTTABOP_setup_table`
stubdom/Makefile +18 -1
index b4dd39a..7eab97f 100644
@@ -324,6 +324,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libxenevtchn/include/*.h include/ && \
 	  ln -sf $(XEN_ROOT)/tools/libxenevtchn/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libxenevtchn/Makefile . )
+	mkdir -p libxengnttab-$(XEN_TARGET_ARCH)/include
+	[ -h libxengnttab-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxengnttab-$(XEN_TARGET_ARCH) && \
+	  ln -sf $(XEN_ROOT)/tools/libxengnttab/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libxengnttab/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libxengnttab/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libxengnttab/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 . && \
@@ -369,12 +375,23 @@ libxenevtchn-$(XEN_TARGET_ARCH)/libxenevtchn.a: $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxenevtchn-$(XEN_TARGET_ARCH)
 
 #######
+# libxengnttab
+#######
+
+.PHONY: libxengnttab
+libxengnttab: libxengnttab-$(XEN_TARGET_ARCH)/libxengnttab.a
+libxengnttab-$(XEN_TARGET_ARCH)/libxengnttab.a: $(NEWLIB_STAMPFILE)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
+	$(MAKE) DESTDIR= -C $(MINI_OS) links
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxengnttab-$(XEN_TARGET_ARCH)
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog libxenevtchn cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog libxenevtchn libxengnttab cross-zlib
 	$(MAKE) -C $(XEN_ROOT)/tools/include
 	$(MAKE) DESTDIR= -C $(MINI_OS) links
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
tools/Makefile +4 -0
index 3497c53..d3bf571 100644
@@ -5,6 +5,7 @@ SUBDIRS-y :=
 SUBDIRS-y += include
 SUBDIRS-y += libxentoollog
 SUBDIRS-y += libxenevtchn
+SUBDIRS-y += libxengnttab
 SUBDIRS-y += libxc
 SUBDIRS-$(FLASK_ENABLE) += flask
 SUBDIRS-y += xenstore
@@ -250,9 +251,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/libxentoollog/include \
 		-I$(XEN_ROOT)/tools/libxenevtchn/include \
+		-I$(XEN_ROOT)/tools/libxengnttab/include \
 		-I$(XEN_ROOT)/tools/libxc/include \
 		-I$(XEN_ROOT)/tools/xenstore/include \
 		-I$(XEN_ROOT)/tools/xenstore/compat/include \
@@ -261,6 +264,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-L$(XEN_ROOT)/tools/xenstore \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxentoollog \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxenevtchn \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxengnttab \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +12 -2
index f675fa7..e3923e2 100644
@@ -12,6 +12,7 @@ INSTALL = $(XEN_ROOT)/tools/cross-install
 XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libxentoollog
 XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libxenevtchn
+XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libxengnttab
 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_libxenctrl) $(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
index 0141d7f..1d4b6ae 100644
@@ -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)
@@ -27,8 +25,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: $(patsubst %.c,%.o,$(wildcard client/*.c))
 	$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_xenconsole) $(APPEND_LDFLAGS)
tools/console/daemon/io.c +11 -10
index 8829b09..7f2f861 100644
@@ -23,6 +23,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>
@@ -73,7 +74,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;
@@ -521,8 +522,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_munmap(xgt_handle, dom->interface, 1);
 	else
 		munmap(dom->interface, XC_PAGE_SIZE);
 	dom->interface = NULL;
@@ -553,9 +554,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;
@@ -1030,8 +1031,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));
 	}
@@ -1207,9 +1208,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/libvchan/Makefile +5 -3
index 84128a3..0573d2f 100644
@@ -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 +12 -12
index fef6c8d..d1c1191 100644
@@ -79,7 +79,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);
 
@@ -105,7 +105,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;
@@ -119,7 +119,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;
@@ -129,9 +129,9 @@ out:
 	return ring_ref;
 out_unmap_left:
 	if (pages_left)
-		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left);
+		xengntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left);
 out_ring:
-	xc_gntshr_munmap(ctrl->gntshr, ring, 1);
+	xengntshr_munmap(ctrl->gntshr, ring, 1);
 	ring_ref = -1;
 	ctrl->ring = NULL;
 	ctrl->write.order = ctrl->read.order = 0;
@@ -143,7 +143,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);
 
@@ -173,7 +173,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;
@@ -191,7 +191,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;
@@ -203,10 +203,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,
+		xengnttab_munmap(ctrl->gnttab, ctrl->write.buffer,
 		                 1 << (ctrl->write.order - PAGE_SHIFT));
  out_unmap_ring:
-	xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
+	xengnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
 	ctrl->ring = 0;
 	ctrl->write.order = ctrl->read.order = 0;
 	rv = -1;
@@ -326,7 +326,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;
 
@@ -414,7 +414,7 @@ struct libxenvchan *libxenvchan_client_init(xentoollog_logger *logger, int domai
 	if (!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
index 4bd15ed..439e2bd 100644
@@ -365,10 +365,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_munmap(ctrl->gntshr, ctrl->ring, 1);
 		} else {
 			ctrl->ring->cli_live = 0;
-			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
+			xengnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
 		}
 	}
 	if (ctrl->event) {
@@ -378,10 +378,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
index 0517dda..950c6e0 100644
@@ -46,7 +46,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. */
@@ -67,8 +67,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
index 19ad0df..3c939ce 100644
@@ -42,12 +42,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
@@ -127,6 +128,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)
@@ -210,7 +213,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 -44

44 lines not on this page · raw message

tools/libxc/xc_nognttab.c deleted +0 -48

48 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
index 81af034..61f2f45 100644
@@ -124,30 +124,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/libxenevtchn/minios.c +1 -4
index 1408182..aefaf2c 100644
@@ -24,13 +24,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>
 
@@ -40,8 +39,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/libxengnttab/Makefile new file +69 -0

69 lines not on this page · raw message

tools/libxengnttab/gntshr_core.c new file +89 -0

89 lines not on this page · raw message

tools/libxengnttab/gntshr_unimp.c new file +59 -0

59 lines not on this page · raw message

tools/libxengnttab/gnttab_core.c new file +118 -0

118 lines not on this page · raw message

tools/libxengnttab/gnttab_unimp.c new file +86 -0

86 lines not on this page · raw message

tools/libxengnttab/include/xengnttab.h new file +215 -0

215 lines not on this page · raw message

tools/libxengnttab/libxengnttab.map new file +23 -0
new file mode 100644
index 0000000..b46f9aa
@@ -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_munmap;
+		
+		xengntshr_open;
+		xengntshr_close;
+		
+		xengntshr_share_page_notify;
+		xengntshr_share_pages;
+		
+		xengntshr_munmap;
+	local: *; /* Do not expose anything by default */
+};
tools/libxengnttab/linux.c new file +326 -0

326 lines not on this page · raw message

tools/libxengnttab/minios.c new file +114 -0

114 lines not on this page · raw message

tools/libxengnttab/private.h new file +47 -0

47 lines not on this page · raw message

tools/xenstore/Makefile +3 -1
index c161046..178771f 100644
@@ -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
index dcf95b5..2b01076 100644
@@ -21,12 +21,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"
@@ -197,7 +199,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
index b649107..aa4d896 100644
@@ -35,7 +35,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;
@@ -167,9 +167,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,
@@ -179,8 +179,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_munmap(*xgt_handle, interface, 1);
 	else
 		munmap(interface, XC_PAGE_SIZE);
 }
@@ -578,9 +578,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;
 }
 
@@ -635,15 +635,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
index f9c921e..f929e31 100644
@@ -18,7 +18,6 @@
 */
 #include <sys/types.h>
 #include <sys/mman.h>
-#include <xenctrl.h>
 #include "xenstored_core.h"
 #include <xen/grant_table.h>
 
@@ -51,12 +50,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_munmap(*xgt_handle, interface, 1);
 }
 
Signature · 1 line
2.1.4
#10 lore raw

Re: [PATCH XEN v2 08/15] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab.

Any thoughts/preferences on this library interface regarding:

The use of a (perhaps to be added) grant_ref_t in preference to uint32_t as it is now?

The use of bool rather than int for "writeable"?

Mapping functions returning NULL on failure (rather than e.g MAP_FAILED)? (current code squashes any underlying MAP_FAILED into NULL, but of course that prevents mapping things at NULL, but then I'm not sure why we would want to support that).

Ian.

Quoted 221 lines · Ian Campbell
tools/libxengnttab/include/xengnttab.h new file +215 -0
new file mode 100644
index 0000000..b333662
@@ -0,0 +1,215 @@
+/*
+ * 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;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Split off from:
+ * xenctrl.h
+ *
+ * A library for low-level access to the Xen control interfaces.
+ *
+ * Copyright (c) 2007-2008, D G Murray <[email protected]>
+ */
+#ifndef XENGNTTAB_H
+#define XENGNTTAB_H
+
+#include 
+
+#include 
+#include 
+
+/* Callers who don't care don't need to #include  */
+typedef struct xentoollog_logger xentoollog_logger;
+
+/*
+ * 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.
+ *
+ * Return an fd onto the grant table driver.  Logs errors.
+ */
+xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned open_flags);
+
+/*
+ * Close a handle previously allocated with xengnttab_open().
+ * Never logs errors.
+ */
+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_munmap.  Logs errors.
+ *
+ * @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
+ * @parm prot same flag as in mmap()
+ */
+void *xengnttab_map_grant_ref(xengnttab_handle *xgt,
+                              uint32_t domid,
+                              uint32_t ref,
+                              int prot);
+
+/**
+ * Memory maps one or more grant references from one or more domains to a
+ * contiguous local address range. Mappings should be unmapped with
+ * xengnttab_munmap.  Logs errors.
+ *
+ * @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
+ *              were granted
+ * @parm refs an array of @count grant references to be mapped
+ * @parm prot same flag as in mmap()
+ */
+void *xengnttab_map_grant_refs(xengnttab_handle *xgt,
+                               uint32_t count,
+                               uint32_t *domids,
+                               uint32_t *refs,
+                               int prot);
+
+/**
+ * Memory maps one or more grant references from one domain to a
+ * contiguous local address range. Mappings should be unmapped with
+ * xengnttab_munmap.  Logs errors.
+ *
+ * @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
+ * @parm refs an array of @count grant references to be mapped
+ * @parm prot same flag as in mmap()
+ */
+void *xengnttab_map_domain_grant_refs(xengnttab_handle *xgt,
+                                      uint32_t count,
+                                      uint32_t domid,
+                                      uint32_t *refs,
+                                      int prot);
+
+/**
+ * Memory maps a grant reference from one domain to a local address range.
+ * Mappings should be unmapped with xengnttab_munmap. If notify_offset or
+ * notify_port are not -1, this version will attempt to set up an unmap
+ * notification at the given offset and event channel. When the page is
+ * unmapped, the byte at the given offset will be zeroed and a wakeup will be
+ * sent to the given event channel.  Logs errors.
+ *
+ * @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
+ * @parm prot same flag as in mmap()
+ * @parm notify_offset The byte offset in the page to use for unmap
+ *                     notification; -1 for none.
+ * @parm notify_port The event channel port to use for unmap notify, or -1
+ */
+void *xengnttab_map_grant_ref_notify(xengnttab_handle *xgt,
+                                     uint32_t domid,
+                                     uint32_t ref,
+                                     int prot,
+                                     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.
+ */
+int xengnttab_munmap(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.
+ *
+ * N.B. This function must be called after opening the handle, and before any
+ *      other functions are invoked on it.
+ *
+ * N.B. When variable-length grants are mapped, fragmentation may be observed,
+ *      and it may not be possible to satisfy requests up to the maximum number
+ *      of grants.
+ */
+int xengnttab_set_max_grants(xengnttab_handle *xgt,
+                            uint32_t count);
+
+/*
+ * Grant Sharing Interface (allocating and granting pages)
+ */
+
+typedef struct xengntdev_handle xengntshr_handle;
+
+/*
+ * Return an fd onto the grant sharing driver.  Logs errors.
+ *
+ * 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.
+ *
+ */
+xengntshr_handle *xengntshr_open(xentoollog_logger *logger,
+                         unsigned open_flags);
+
+/*
+ * Close a handle previously allocated with xengntshr_open().
+ * Never logs errors.
+ */
+int xengntshr_close(xengntshr_handle *xgs);
+
+/*
+ * Creates and shares pages with another domain.
+ *
+ * @parm xgs a handle to an open grant sharing instance
+ * @parm domid the domain to share memory with
+ * @parm count the number of pages to share
+ * @parm refs the grant references of the pages (output)
+ * @parm writable true if the other domain can write to the pages
+ * @return local mapping of the pages
+ */
+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
+ * @parm domid the domain to share memory with
+ * @parm refs the grant reference of the pages (output)
+ * @parm writable true if the other domain can write to the page
+ * @parm notify_offset The byte offset in the page to use for unmap
+ *                     notification; -1 for none.
+ * @parm notify_port The event channel port to use for unmap notify, or -1
+ * @return local mapping of the page
+ */
+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.
+ */
+int xengntshr_munmap(xengntshr_handle *xgs, void *start_address, uint32_t count);
+
+#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
#11 lore raw

Re: [PATCH XEN v2 08/15] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab.

Quoted 4 lines · Ian Campbell

Any thoughts/preferences on this library interface regarding:

The use of a (perhaps to be added) grant_ref_t in preference to uint32_t as it is now?

Probably a good idea. We should also introduce/use domid_t consistently through the new API as well.

Quoted 2 lines

The use of bool rather than int for "writeable"?

Depends if we go for -std=c89 or -std=c99.

Given that it is 2015, I vote for -std=c99 and all the niceties it brings, such as bool.

Quoted 5 lines

Mapping functions returning NULL on failure (rather than e.g MAP_FAILED)? (current code squashes any underlying MAP_FAILED into NULL, but of course that prevents mapping things at NULL, but then I'm not sure why we would want to support that).

+1

Anyone code choosing to try and map a grant ref at 0 can handcode the systemcalls itself. Sane software will be much happier with NULL as the failure check.

~Andrew

#12 lore raw

Re: [PATCH XEN v2 08/15] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab.

Andrew Cooper writes ("Re: [Xen-devel] [PATCH XEN v2 08/15] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab."):

Quoted 5 lines · Ian Campbell
Quoted 4 lines

Any thoughts/preferences on this library interface regarding:

The use of a (perhaps to be added) grant_ref_t in preference to uint32_t as it is now?

Is a grant_ref_t uint32_t ?

Quoted 2 lines

Probably a good idea. We should also introduce/use domid_t consistently through the new API as well.

domid_it is a uint16_t. The problem with that is that there is no space for sentinel or magic values which are assigned meanings outside the hypervisor.

Quoted 2 lines

Given that it is 2015, I vote for -std=c99 and all the niceties it brings, such as bool.

We should certainly consider some GNU extensions. I don't know which are widely available, but we should consider:
* Statement expressions
* Some of the function and data attributes, particularly format, noreturn, unused. (Maybe via some compatibility macros.)
* Anonymous struct/union members.
* typeof

Ian.

#13 lore raw

Re: [PATCH XEN v2 08/15] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab.

Quoted 10 lines · Ian Jackson

Andrew Cooper writes ("Re: [Xen-devel] [PATCH XEN v2 08/15] tools:
Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab."):

Quoted 6 lines · Ian Campbell
Quoted 5 lines

Any thoughts/preferences on this library interface regarding:

The use of a (perhaps to be added) grant_ref_t in preference to uint32_t as
it is now?

Is a grant_ref_t uint32_t ?

Yes (in xen/include/public/grant_table.h).

Quoted 7 lines
Quoted 3 lines

Probably a good idea. We should also introduce/use domid_t consistently
through the new API as well.

domid_it is a uint16_t. The problem with that is that there is no space for sentinel or magic values which are assigned meanings outside the hypervisor.

Correct.

We don't necessarily need to use the same domid_t as the hypervisor interface, but not doing so would seem confusing...

Quoted 10 lines
Quoted 2 lines

Given that it is 2015, I vote for -std=c99 and all the niceties it brings, such as bool.

We should certainly consider some GNU extensions. I don't know which are widely available, but we should consider:
* Statement expressions
* Some of the function and data attributes, particularly format, noreturn, unused. (Maybe via some compatibility macros.)
* Anonymous struct/union members.
* typeof

For the implementation side, sure, few of these seem relevant to the interface headers being discussed here (apart maybe from anon members, which is moot because none of the libraries in question have a need for such a thing AFAICT).

Ian.

#14 lore raw

PATCH v2 9/15 tools/libxc: Remove osdep indirection for privcmd

In reply to Ian Campbell

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.

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.

---
 config/FreeBSD.mk                       |   2 -
 config/NetBSD.mk                        |   3 -
 config/NetBSDRump.mk                    |   1 -
 config/StdGNU.mk                        |   1 -
 config/SunOS.mk                         |   1 -
 docs/misc/toolstack-library-abis.pandoc |  64 +++++++++++-
 tools/libxc/Makefile                    |  27 ++---
 tools/libxc/include/xenctrl.h           |   9 --
 tools/libxc/include/xenctrlosdep.h      | 134 ------------------------
 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 +-
 24 files changed, 240 insertions(+), 826 deletions(-)
 delete mode 100644 tools/libxc/include/xenctrlosdep.h
 delete mode 100644 tools/libxc/xenctrl_osdep_ENOSYS.c
config/FreeBSD.mk +0 -2
index 5a13d607..bb3a5d0 100644
@@ -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
index 21318d6..cf766e5 100644
@@ -1,6 +1,3 @@
 include $(XEN_ROOT)/config/StdGNU.mk
 
-# Override settings for this OS
-DLOPEN_LIBS =
-
 WGET = ftp
config/NetBSDRump.mk +0 -1
index 2a87218..74755a1 100644
@@ -1,6 +1,5 @@
 include $(XEN_ROOT)/config/StdGNU.mk
 
-DLOPEN_LIBS =
 PTHREAD_LIBS =
 
 WGET = ftp
config/StdGNU.mk +0 -1
index 129d5c8..39d36b2 100644
@@ -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
index db5e898..86a384d 100644
@@ -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
docs/misc/toolstack-library-abis.pandoc +62 -2

79 lines not on this page · raw message

tools/libxc/Makefile +7 -20
index 3c939ce..77d2ae1 100644
@@ -102,8 +102,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
@@ -122,11 +120,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)
 
@@ -140,17 +135,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
@@ -170,7 +161,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)
@@ -186,8 +177,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
@@ -213,7 +203,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
 
@@ -238,8 +228,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
index 9675ebb..61f68bb 100644
@@ -182,15 +182,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 -134

134 lines not on this page · raw message

tools/libxc/xc_foreign_memory.c +1 -30
index 43abf01..53b6c9a 100644
@@ -51,37 +51,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
index 932b47c..ab8bee5 100644
@@ -123,7 +123,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);
@@ -134,7 +134,7 @@ void *xc__hypercall_buffer_alloc_pages(xc_interface *xch, xc_hypercall_buffer_t
     void *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;
@@ -152,7 +152,7 @@ void xc__hypercall_buffer_free_pages(xc_interface *xch, xc_hypercall_buffer_t *b
         return;
 
     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
index 61f2f45..408b1be 100644
@@ -31,7 +31,6 @@
 
 #include "_paths.h"
 #include "xenctrl.h"
-#include "xenctrlosdep.h"
 
 #include <xen/sys/privcmd.h>
 
@@ -89,7 +88,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;
@@ -118,12 +116,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
index b7ba8b7..701b66c 100644
@@ -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
index bc4af56..3f4947c 100644
@@ -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
index 64f1137..9a201ee 100644
@@ -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
index 92e438f..395f3a9 100644
@@ -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
index bfe689b..5c7ace1 100644
@@ -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

A message that is not in the archive (sent off-list or not yet received): [email protected]

Acked-by
#16 lore raw

Re: [PATCH XEN v2 09/15] tools/libxc: Remove osdep indirection for privcmd

Quoted 17 lines · David Scott (Sales UK)

One for you I think Dave?

Sent from my iPhone

Begin forwarded message:

Quoted 8 lines

From: "Ian Campbell" <[email protected]>
To: "Ian Jackson" <[email protected]>, "Wei Liu" <[email protected]>, "[email protected]" <[email protected]>
Cc: "Stefano Stabellini" <[email protected]>, "Roger Pau Monne" <[email protected]>, "Ian Campbell" <[email protected]>, "David Scott (Sales UK)" <[email protected]>
Subject: [PATCH XEN v2 09/15] tools/libxc: Remove osdep indirection for privcmd

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.

Yes, we no longer use the fake libxenctrl (“xiu”) stuff.

Quoted 10 lines
Quoted 10 lines

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.

Quoted 7 lines
Quoted 7 lines

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.

Confusingly my email is <[email protected]> (‘dave’ rather than ‘david’) — best to avoid cc:ing ‘david.scott’ as he probably hasn’t got xen-devel email filters set up ;-)

Quoted 17 lines
Quoted 17 lines

---

config/FreeBSD.mk                       |   2 -
config/NetBSD.mk                        |   3 -
config/NetBSDRump.mk                    |   1 -
config/StdGNU.mk                        |   1 -
config/SunOS.mk                         |   1 -
docs/misc/toolstack-library-abis.pandoc |  64 +++++++++++-
tools/libxc/Makefile                    |  27 ++---
tools/libxc/include/xenctrl.h           |   9 --
tools/libxc/include/xenctrlosdep.h      | 134 ------------------------
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 ++------------------------------
Quoted 8 lines
Quoted 8 lines
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 +-

These are fine,

Thanks,
Dave

Quoted 1,821 lines
Quoted 1,821 lines
24 files changed, 240 insertions(+), 826 deletions(-)

delete mode 100644 tools/libxc/include/xenctrlosdep.h delete mode 100644 tools/libxc/xenctrl_osdep_ENOSYS.c

config/FreeBSD.mk +0 -0
index 5a13d607..bb3a5d0 100644
@@ -1,6 +1,4 @@

include $(XEN_ROOT)/config/StdGNU.mk

config/FreeBSD.mk +0 -2
-DLOPEN_LIBS =
-

# No wget on FreeBSD base system
WGET = ftp

config/NetBSD.mk +0 -0
index 21318d6..cf766e5 100644
@@ -1,6 +1,3 @@

include $(XEN_ROOT)/config/StdGNU.mk

config/NetBSD.mk +0 -3
-# Override settings for this OS
-DLOPEN_LIBS =
-

WGET = ftp

config/NetBSDRump.mk +0 -0
index 2a87218..74755a1 100644
@@ -1,6 +1,5 @@

include $(XEN_ROOT)/config/StdGNU.mk

-DLOPEN_LIBS =
PTHREAD_LIBS =

WGET = ftp

config/StdGNU.mk +0 -0
index 129d5c8..39d36b2 100644
@@ -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 -0
index db5e898..86a384d 100644
@@ -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

docs/misc/toolstack-library-abis.pandoc +62 -2
index 6b6146a..d1550a6 100644
@@ -187,7 +187,6 @@ Notes:
 ### Basic interface
 
    - xc_interface_close
-    - xc_interface_is_fake
    - xc_interface_open
 
 ### Event channels
@@ -511,7 +510,6 @@ Symbols:
    - xc_monitor_write_ctrlreg
    - xc_nodemap_alloc
    - xc_numainfo
-    - xc_osdep_log
    - xc_pcitopoinfo
    - xc_perfc_query
    - xc_perfc_query_number
@@ -871,3 +869,65 @@ functionality areas:
    - xc_kexec_load
    - xc_kexec_unload
    - xc_version
+
+# Foreign memory mapping functions
+
+The `xc_map_foreign_*` functions are a bit of a twisty maze.
+
+osdep level interfaces:
+
+Interface            Linux Minios Netbsd Freebsd Solaris
+-------------------- ----- ------ ------ ------- -------
+`map_foreign_batch`  Y     Y      Y              Y
+`map_foreign_bulk`   Y     Y      compat Y       compat
+`map_foreign_range`  Y     Y      Y      Y       Y
+`map_foreign_ranges` Y     Y      Y      Y       Y
+
+_compat_ means using `xc_map_foreign_bulk_compat`
+
+`xc_map_foreign_pages` is common and implemented using
+`xc_map_foreign_bulk`.
+
+Some osdep call other `xc_map_foreign_*` recursivley:
+
+Interface            Linux                        FreeBSD
+-------------------- ---------------------------- -------------------------
+`map_foreign_batch`  `IOCTL_PRIVCMD_MMAPBATCH`    N/A
+`map_foreign_bulk`   `IOCTL_PRIVCMD_MMAPBATCH_V2` `IOCTL_PRIVCMD_MMAPBATCH`
+`map_foreign_range`  `xc_map_foreign_pages`       `xc_map_foreign_pages`
+`map_foreign_ranges` `xc_map_foreign_pages`       `xc_map_foreign_pages`
+
+libxenctrl level interfaces:
+
+Interface               Underlying interface
+----------------------  ---------------------------
+`xc_map_foreign_pages`  `xc_map_foreign_bulk`
+`xc_map_foreign_range`  `osdep: map_foreign_range`
+`xc_map_foreign_ranges` `osdep: map_foreign_ranges`
+`xc_map_foreign_batch`  `osdep: map_foreign_batch`
+`xc_map_foreign_bulk`   `osdep: map_foreign_bulk`
+
+`osdep: *` have been collapsed since osdep layer was removed.
+
+`xc_map_foreign_bulk_compat` is an internal helper used by osdep
+backends which have not implemented there own version. It uses
+`xc_map_foreign_batch`.
+
+`xc_map_foreign_batch_single` is part of linux osdep, but name has
+leaked.
+
+Interface               Internal users               External users
+----------------------  --------------               --------------
+`xc_map_foreign_pages`  xenpaging                    qemu-pv
+`xc_map_foreign_range`  xenconsole, kdd, libxl,      qemu-dm, qemu-pv
+                        mfndump, memshrtool, xenmon,
+                        xenstored, xentrace
+`xc_map_foreign_ranges` NONE
+`xc_map_foreign_batch`  xenmon, xenpaging, xentrace
+`xc_map_foreign_bulk`   used recursively             qemu-dm
+
+Only one interface should become a stable API. Something based on
+`xc_map_foreign_bulk` seems most appropriate (it is used by
+`xc_map_foreign_pages` as well as by xc_map_foreign_range` and
+`xc_map_foreign_ranges` on Linux + FreeBSD. A compat version exists in
+terms for `xc_map_foreign_batch` for other OSes.
tools/libxc/Makefile +0 -0
index 3c939ce..77d2ae1 100644
@@ -102,8 +102,6 @@ GUEST_SRCS-y                 += xc_dom_decompress_unsafe_lzo1x.c

GUEST_SRCS-y += xc_dom_decompress_unsafe_xz.c
endif

tools/libxc/Makefile +0 -3
-OSDEP_SRCS-y                 += xenctrl_osdep_ENOSYS.c
-
-include $(XEN_TARGET_ARCH)/Makefile

CFLAGS += -Werror -Wmissing-prototypes

tools/libxc/Makefile +2 -5
@@ -122,11 +120,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)
 
@@ -140,17 +135,13 @@ ifneq ($(nosharedlibs),y)
 LIB += libxenguest.so libxenguest.so.$(MAJOR) libxenguest.so.$(MAJOR).$(MINOR)

endif

tools/libxc/Makefile +0 -4
-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

tools/libxc/Makefile +2 -3
@@ -170,7 +161,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)
@@ -186,8 +177,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

tools/libxc/Makefile +1 -1
@@ -213,7 +203,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
 
@@ -238,8 +228,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)

tools/libxc/Makefile +0 -4
-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
index 9675ebb..61f68bb 100644
@@ -182,15 +182,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 -134
deleted file mode 100644
index bad10f6..0000000
@@ -1,134 +0,0 @@
-/******************************************************************************
- *
- * Interface to OS specific low-level operations
- *
- * Copyright (c) 2010, Citrix Systems Inc.
- *
- * 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;
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-/*
- * This interface defines the interactions between the Xen control
- * libraries and the OS facilities used to communicate with the
- * hypervisor.
- *
- * It is possible to override the default (native) implementation by
- * setting the XENCTRL_OSDEP environment variable to point to a
- * plugin library. Userspace can use this facility to intercept
- * hypervisor operations. This can be used e.g. to implement a
- * userspace simulator for Xen hypercalls.
- *
- * The plugin must contain a data structure:
- *  xc_osdep_info_t xc_osdep_info;
- *
- * xc_osdep_init:
- *   Must return a suitable struct xc_osdep_ops pointer or NULL on failure.
- */
-
-#ifndef XC_OSDEP_H
-#define XC_OSDEP_H
-
-/* Tell the Xen public headers we are a user-space tools build. */
-#ifndef __XEN_TOOLS__
-#define __XEN_TOOLS__ 1
-#endif
-
-#include <sys/mman.h>
-#include <sys/types.h>
-
-#include <xen/sys/privcmd.h>
-
-enum xc_osdep_type {
-    XC_OSDEP_PRIVCMD,
-};
-
-/* Opaque handle internal to the backend */
-typedef unsigned long xc_osdep_handle;
-
-#define XC_OSDEP_OPEN_ERROR ((xc_osdep_handle)-1)
-
-struct xc_osdep_ops
-{
-    /* Opens an interface.
-     *
-     * Must return an opaque handle on success or
-     * XC_OSDEP_OPEN_ERROR on failure
-     */
-    xc_osdep_handle (*open)(xc_interface *xch);
-
-    int (*close)(xc_interface *xch, xc_osdep_handle h);
-
-    union {
-        struct {
-            void *(*alloc_hypercall_buffer)(xc_interface *xch, xc_osdep_handle h, int npages);
-            void (*free_hypercall_buffer)(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages);
-
-            int (*hypercall)(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall);
-
-            void *(*map_foreign_batch)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
-                                       xen_pfn_t *arr, int num);
-            void *(*map_foreign_bulk)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
-                                      const xen_pfn_t *arr, int *err, unsigned int num);
-            void *(*map_foreign_range)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int size, int prot,
-                                       unsigned long mfn);
-            void *(*map_foreign_ranges)(xc_interface *xch, xc_osdep_handle h, uint32_t dom, size_t size, int prot,
-                                        size_t chunksize, privcmd_mmap_entry_t entries[],
-                                        int nentries);
-        } privcmd;
-    } u;
-};
-typedef struct xc_osdep_ops xc_osdep_ops;
-
-typedef xc_osdep_ops *(*xc_osdep_init_fn)(xc_interface *xch, enum xc_osdep_type);
-
-struct xc_osdep_info
-{
-    /* Describes this backend. */
-    const char *name;
-
-    /* Returns ops function. */
-    xc_osdep_init_fn init;
-
-    /* True if this interface backs onto a fake Xen. */
-    int fake;
-
-    /* For internal use by loader. */
-    void *dl_handle;
-};
-typedef struct xc_osdep_info xc_osdep_info_t;
-
-/* All backends, including the builtin backend, must supply this structure. */
-extern xc_osdep_info_t xc_osdep_info;
-
-/* Stub for not yet converted OSes */
-void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
-                                 uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, unsigned int num);
-
-/* Report errors through xc_interface */
-void xc_osdep_log(xc_interface *xch, xentoollog_level level, int code,
-                  const char *fmt, ...) __attribute__((format(printf, 4, 5)));
-
-#endif
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
tools/libxc/xc_foreign_memory.c +1 -30
index 43abf01..53b6c9a 100644
@@ -51,37 +51,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
index d948b37..4c0e2fd 100644
@@ -33,16 +33,12 @@
 
 #include <xen/memory.h>
 
-#include "xenctrl.h"
-#include "xenctrlosdep.h"
+#include "xc_private.h"
 
 #define PRIVCMD_DEV     "/dev/xen/privcmd"
 
-#define PERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m \
-                  " (%d = %s)", ## _a , errno, xc_strerror(xch, errno))
-
 /*------------------------- Privcmd device interface -------------------------*/
-static xc_osdep_handle freebsd_privcmd_open(xc_interface *xch)
+int osdep_privcmd_open(xc_interface *xch)
 {
    int flags, saved_errno;
    int fd = open(PRIVCMD_DEV, O_RDWR);
@@ -51,7 +47,7 @@ static xc_osdep_handle freebsd_privcmd_open(xc_interface *xch)
    {
        PERROR("Could not obtain handle on privileged command interface "
               PRIVCMD_DEV);
-        return XC_OSDEP_OPEN_ERROR;
+        return -1
    }
 
    /*
@@ -74,27 +70,27 @@ static xc_osdep_handle freebsd_privcmd_open(xc_interface *xch)
        goto error;
    }
 
-    return (xc_osdep_handle)fd;
+    xch->privcmdfd = fd;
+    return 0;
 
 error:
    saved_errno = errno;
    close(fd);
    errno = saved_errno;
 
-    return XC_OSDEP_OPEN_ERROR;
+    return -1;
 }
 
-static int freebsd_privcmd_close(xc_interface *xch, xc_osdep_handle h)
+int osdep_privcmd_close(xc_interface *xch)
 {
-    int fd = (int)h;
-
+    int fd = xch->privcmdfd;
+    if ( fd == -1 )
+        return 0;
    return close(fd);
 }
 
 /*------------------------ Privcmd hypercall interface -----------------------*/
-static void *freebsd_privcmd_alloc_hypercall_buffer(xc_interface *xch,
-                                                    xc_osdep_handle h,
-                                                    int npages)
+void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages)
 {
    size_t size = npages * XC_PAGE_SIZE;
    void *p;
@@ -118,9 +114,7 @@ static void *freebsd_privcmd_alloc_hypercall_buffer(xc_interface *xch,
    return p;
 }
 
-static void freebsd_privcmd_free_hypercall_buffer(xc_interface *xch,
-                                                  xc_osdep_handle h, void *ptr,
-                                                  int npages)
+void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages)
 {
 
    int saved_errno = errno;
@@ -132,10 +126,9 @@ static void freebsd_privcmd_free_hypercall_buffer(xc_interface *xch,
    errno = saved_errno;
 }
 
-static int freebsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h,
-                                     privcmd_hypercall_t *hypercall)
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    int ret;
 
    ret = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
@@ -144,13 +137,12 @@ static int freebsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h,
 }
 
 /*----------------------- Privcmd foreign map interface ----------------------*/
-static void *freebsd_privcmd_map_foreign_bulk(xc_interface *xch,
-                                               xc_osdep_handle h,
-                                               uint32_t dom, int prot,
-                                               const xen_pfn_t *arr, int *err,
-                                               unsigned 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)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    privcmd_mmapbatch_t ioctlx;
    void *addr;
    int rc;
@@ -181,10 +173,9 @@ static void *freebsd_privcmd_map_foreign_bulk(xc_interface *xch,
    return addr;
 }
 
-static void *freebsd_privcmd_map_foreign_range(xc_interface *xch,
-                                               xc_osdep_handle h,
-                                               uint32_t dom, int size, int prot,
-                                               unsigned long mfn)
+void *xc_map_foreign_range(xc_interface *xch,
+                           uint32_t dom, int size, int prot,
+                           unsigned long mfn)
 {
    xen_pfn_t *arr;
    int num;
@@ -204,12 +195,11 @@ static void *freebsd_privcmd_map_foreign_range(xc_interface *xch,
    return ret;
 }
 
-static void *freebsd_privcmd_map_foreign_ranges(xc_interface *xch,
-                                                xc_osdep_handle h,
-                                                uint32_t dom, size_t size,
-                                                int prot, size_t chunksize,
-                                                privcmd_mmap_entry_t entries[],
-                                                int nentries)
+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;
@@ -233,42 +223,6 @@ static void *freebsd_privcmd_map_foreign_ranges(xc_interface *xch,
    return ret;
 }
 
-/*----------------------------- Privcmd handlers -----------------------------*/
-static struct xc_osdep_ops freebsd_privcmd_ops = {
-    .open = &freebsd_privcmd_open,
-    .close = &freebsd_privcmd_close,
-
-    .u.privcmd = {
-        .alloc_hypercall_buffer = &freebsd_privcmd_alloc_hypercall_buffer,
-        .free_hypercall_buffer = &freebsd_privcmd_free_hypercall_buffer,
-
-        .hypercall = &freebsd_privcmd_hypercall,
-
-        .map_foreign_bulk = &freebsd_privcmd_map_foreign_bulk,
-        .map_foreign_range = &freebsd_privcmd_map_foreign_range,
-        .map_foreign_ranges = &freebsd_privcmd_map_foreign_ranges,
-    },
-};
-
-/*---------------------------- FreeBSD interface -----------------------------*/
-static struct xc_osdep_ops *
-freebsd_osdep_init(xc_interface *xch, enum xc_osdep_type type)
-{
-    switch ( type )
-    {
-    case XC_OSDEP_PRIVCMD:
-        return &freebsd_privcmd_ops;
-    default:
-        return NULL;
-    }
-}
-
-xc_osdep_info_t xc_osdep_info = {
-    .name = "FreeBSD Native OS interface",
-    .init = &freebsd_osdep_init,
-    .fake = 0,
-};
-
 /*
 * Local variables:
 * mode: C
tools/libxc/xc_hcall_buf.c +3 -3
index 932b47c..ab8bee5 100644
@@ -123,7 +123,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);
@@ -134,7 +134,7 @@ void *xc__hypercall_buffer_alloc_pages(xc_interface *xch, xc_hypercall_buffer_t
    void *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;
@@ -152,7 +152,7 @@ void xc__hypercall_buffer_free_pages(xc_interface *xch, xc_hypercall_buffer_t *b
        return;
 
    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
index 7246b79..d17a52b 100644
@@ -34,13 +34,12 @@
 #include <xen/memory.h>
 
 #include "xenctrl.h"
-#include "xenctrlosdep.h"
 
 #include "xc_private.h"
 
 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 
-static xc_osdep_handle linux_privcmd_open(xc_interface *xch)
+int osdep_privcmd_open(xc_interface *xch)
 {
    int flags, saved_errno;
    int fd = open("/proc/xen/privcmd", O_RDWR);
@@ -48,7 +47,7 @@ static xc_osdep_handle linux_privcmd_open(xc_interface *xch)
    if ( fd == -1 )
    {
        PERROR("Could not obtain handle on privileged command interface");
-        return XC_OSDEP_OPEN_ERROR;
+        return -1;
    }
 
    /* Although we return the file handle as the 'xc handle' the API
@@ -69,22 +68,25 @@ static xc_osdep_handle linux_privcmd_open(xc_interface *xch)
        goto error;
    }
 
-    return (xc_osdep_handle)fd;
+    xch->privcmdfd = fd;
+    return 0;
 
 error:
    saved_errno = errno;
    close(fd);
    errno = saved_errno;
-    return XC_OSDEP_OPEN_ERROR;
+    return -1;
 }
 
-static int linux_privcmd_close(xc_interface *xch, xc_osdep_handle h)
+int osdep_privcmd_close(xc_interface *xch)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
+    if (fd == -1)
+        return 0;
    return close(fd);
 }
 
-static void *linux_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
+void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages)
 {
    size_t size = npages * XC_PAGE_SIZE;
    void *p;
@@ -116,7 +118,7 @@ out:
    return NULL;
 }
 
-static void linux_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
+void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages)
 {
    int saved_errno = errno;
    /* Recover the VMA flags. Maybe it's not necessary */
@@ -127,9 +129,9 @@ static void linux_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_hand
    errno = saved_errno;
 }
 
-static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
 }
 
@@ -155,11 +157,11 @@ static int xc_map_foreign_batch_single(int fd, uint32_t dom,
    return rc;
 }
 
-static void *linux_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
-                                             uint32_t dom, int prot,
-                                             xen_pfn_t *arr, int num)
+void *xc_map_foreign_batch(xc_interface *xch,
+                           uint32_t dom, int prot,
+                           xen_pfn_t *arr, int num)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    privcmd_mmapbatch_t ioctlx;
    void *addr;
    int rc;
@@ -261,11 +263,11 @@ out:
    return rc;
 }
 
-static void *linux_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
-                                            uint32_t dom, int prot,
-                                            const xen_pfn_t *arr, int *err, unsigned 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)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    privcmd_mmapbatch_v2_t ioctlx;
    void *addr;
    unsigned int i;
@@ -385,9 +387,9 @@ static void *linux_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h
    return addr;
 }
 
-static void *linux_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h,
-                                             uint32_t dom, int size, int prot,
-                                             unsigned long mfn)
+void *xc_map_foreign_range(xc_interface *xch,
+                           uint32_t dom, int size, int prot,
+                           unsigned long mfn)
 {
    xen_pfn_t *arr;
    int num;
@@ -407,10 +409,10 @@ static void *linux_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle
    return ret;
 }
 
-static void *linux_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h,
-                                              uint32_t dom, size_t size, int prot,
-                                              size_t chunksize, privcmd_mmap_entry_t entries[],
-                                              int nentries)
+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;
@@ -434,40 +436,6 @@ static void *linux_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle
    return ret;
 }
 
-static struct xc_osdep_ops linux_privcmd_ops = {
-    .open = &linux_privcmd_open,
-    .close = &linux_privcmd_close,
-
-    .u.privcmd = {
-        .alloc_hypercall_buffer = &linux_privcmd_alloc_hypercall_buffer,
-        .free_hypercall_buffer = &linux_privcmd_free_hypercall_buffer,
-
-        .hypercall = &linux_privcmd_hypercall,
-
-        .map_foreign_batch = &linux_privcmd_map_foreign_batch,
-        .map_foreign_bulk = &linux_privcmd_map_foreign_bulk,
-        .map_foreign_range = &linux_privcmd_map_foreign_range,
-        .map_foreign_ranges = &linux_privcmd_map_foreign_ranges,
-    },
-};
-
-static struct xc_osdep_ops *linux_osdep_init(xc_interface *xch, enum xc_osdep_type type)
-{
-    switch ( type )
-    {
-    case XC_OSDEP_PRIVCMD:
-        return &linux_privcmd_ops;
-    default:
-        return NULL;
-    }
-}
-
-xc_osdep_info_t xc_osdep_info = {
-    .name = "Linux Native OS interface",
-    .init = &linux_osdep_init,
-    .fake = 0,
-};
-
 /*
 * Local variables:
 * mode: C
tools/libxc/xc_minios.c +24 -58
index 947b19a..0a2ac5c 100644
@@ -40,19 +40,20 @@ void minios_interface_close_fd(int fd);
 
 extern void minios_interface_close_fd(int fd);
 
-static xc_osdep_handle minios_privcmd_open(xc_interface *xch)
+int osdep_privcmd_open(xc_interface *xch)
 {
    int fd = alloc_fd(FTYPE_XC);
 
    if ( fd == -1)
-        return XC_OSDEP_OPEN_ERROR;
+        return -1;
 
-    return (xc_osdep_handle)fd;
+    xch->privcmdfd = fd;
+    return 0;
 }
 
-static int minios_privcmd_close(xc_interface *xch, xc_osdep_handle h)
+int osdep_privcmd_close(xc_interface *xch)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    return close(fd);
 }
 
@@ -61,17 +62,17 @@ void minios_interface_close_fd(int fd)
    files[fd].type = FTYPE_NONE;
 }
 
-static void *minios_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
+void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages)
 {
    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
 }
 
-static void minios_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
+void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages)
 {
    free(ptr);
 }
 
-static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
 {
    multicall_entry_t call;
    int i, ret;
@@ -93,21 +94,21 @@ static int minios_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcm
    return call.result;
 }
 
-static void *minios_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h,
-                                             uint32_t dom, int prot,
-                                             const xen_pfn_t *arr, int *err, unsigned 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)
 {
    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);    
+    return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
 }
 
-static void *minios_privcmd_map_foreign_batch(xc_interface *xch,  xc_osdep_handle h,
-                                              uint32_t dom, int prot,
-                                              xen_pfn_t *arr, int num)
+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];
@@ -127,10 +128,10 @@ static void *minios_privcmd_map_foreign_batch(xc_interface *xch,  xc_osdep_handl
    return (void *) addr;
 }
 
-static void *minios_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h,
-                                              uint32_t dom,
-                                              int size, int prot,
-                                              unsigned long mfn)
+void *xc_map_foreign_range(xc_interface *xch,
+                           uint32_t dom,
+                           int size, int prot,
+                           unsigned long mfn)
 {
    unsigned long pt_prot = 0;
 
@@ -143,10 +144,10 @@ static void *minios_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle
    return map_frames_ex(&mfn, size / getpagesize(), 0, 1, 1, dom, NULL, pt_prot);
 }
 
-static void *minios_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h,
-                                               uint32_t dom,
-                                               size_t size, int prot, size_t chunksize,
-                                               privcmd_mmap_entry_t entries[], int nentries)
+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)
 {
    unsigned long *mfns;
    int i, j, n;
@@ -170,24 +171,6 @@ static void *minios_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handl
    return ret;
 }
 
-
-static struct xc_osdep_ops minios_privcmd_ops = {
-    .open = &minios_privcmd_open,
-    .close = &minios_privcmd_close,
-
-    .u.privcmd = {
-        .alloc_hypercall_buffer = &minios_privcmd_alloc_hypercall_buffer,
-        .free_hypercall_buffer = &minios_privcmd_free_hypercall_buffer,
-
-        .hypercall = &minios_privcmd_hypercall,
-
-        .map_foreign_batch = &minios_privcmd_map_foreign_batch,
-        .map_foreign_bulk = &minios_privcmd_map_foreign_bulk,
-        .map_foreign_range = &minios_privcmd_map_foreign_range,
-        .map_foreign_ranges = &minios_privcmd_map_foreign_ranges,
-    },
-};
-
 /* Optionally flush file to disk and discard page cache */
 void discard_file_cache(xc_interface *xch, int fd, int flush)
 {
@@ -200,23 +183,6 @@ void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
    return memalign(alignment, size);
 }
 
-static struct xc_osdep_ops *minios_osdep_init(xc_interface *xch, enum xc_osdep_type type)
-{
-    switch ( type )
-    {
-    case XC_OSDEP_PRIVCMD:
-        return &minios_privcmd_ops;
-    default:
-        return NULL;
-    }
-}
-
-xc_osdep_info_t xc_osdep_info = {
-    .name = "Minios Native OS interface",
-    .init = &minios_osdep_init,
-    .fake = 0,
-};
-
 /*
 * Local variables:
 * mode: C
tools/libxc/xc_netbsd.c +32 -58
index 48fd5d7..5361f2b 100644
@@ -25,7 +25,7 @@
 #include <malloc.h>
 #include <sys/mman.h>
 
-static xc_osdep_handle netbsd_privcmd_open(xc_interface *xch)
+int osdep_privcmd_open(xc_interface *xch)
 {
    int flags, saved_errno;
    int fd = open("/kern/xen/privcmd", O_RDWR);
@@ -33,7 +33,7 @@ static xc_osdep_handle netbsd_privcmd_open(xc_interface *xch)
    if ( fd == -1 )
    {
        PERROR("Could not obtain handle on privileged command interface");
-        return XC_OSDEP_OPEN_ERROR;
+        return -1;
    }
 
    /* Although we return the file handle as the 'xc handle' the API
@@ -52,22 +52,23 @@ static xc_osdep_handle netbsd_privcmd_open(xc_interface *xch)
        goto error;
    }
 
-    return (xc_osdep_handle)fd;
+    xch->privcmdfd = fd;
+    return 0;
 
 error:
    saved_errno = errno;
    close(fd);
    errno = saved_errno;
-    return XC_OSDEP_OPEN_ERROR;
+    return -1;
 }
 
-static int netbsd_privcmd_close(xc_interface *xch, xc_osdep_handle h)
+int osdep_privcmd_close(xc_interface *xch)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    return close(fd);
 }
 
-static void *netbsd_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
+void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages)
 {
    size_t size = npages * XC_PAGE_SIZE;
    void *p;
@@ -84,15 +85,15 @@ static void *netbsd_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_h
    return p;
 }
 
-static void netbsd_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
+void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages)
 {
    (void) munlock(ptr, npages * XC_PAGE_SIZE);
    free(ptr);
 }
 
-static int netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    int error = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
 
    /*
@@ -107,11 +108,18 @@ static int netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcm
        return hypercall->retval;
 }
 
-static void *netbsd_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
-                                              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)
 {
-    int fd = (int)h;
+    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)
+{
+    int fd = xch->privcmdfd;
    privcmd_mmapbatch_t ioctlx;
    void *addr;
    addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0);
@@ -136,12 +144,12 @@ static void *netbsd_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle
 
 }
 
-static void *netbsd_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h,
-                                              uint32_t dom,
-                                              int size, int prot,
-                                              unsigned long mfn)
+void *xc_map_foreign_range(xc_interface *xch,
+                           uint32_t dom,
+                           int size, int prot,
+                           unsigned long mfn)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    privcmd_mmap_t ioctlx;
    privcmd_mmap_entry_t entry;
    void *addr;
@@ -168,12 +176,12 @@ static void *netbsd_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle
    return addr;
 }
 
-static void *netbsd_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h,
-                                               uint32_t dom,
-                                               size_t size, int prot, size_t chunksize,
-                                               privcmd_mmap_entry_t entries[], int nentries)
+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)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
   privcmd_mmap_t ioctlx;
   int i, rc;
   void *addr;
@@ -206,23 +214,6 @@ mmap_failed:
   return NULL;
 }
 
-static struct xc_osdep_ops netbsd_privcmd_ops = {
-    .open = &netbsd_privcmd_open,
-    .close = &netbsd_privcmd_close,
-
-    .u.privcmd = {
-        .alloc_hypercall_buffer = &netbsd_privcmd_alloc_hypercall_buffer,
-        .free_hypercall_buffer = &netbsd_privcmd_free_hypercall_buffer,
-
-        .hypercall = &netbsd_privcmd_hypercall,
-
-        .map_foreign_batch = &netbsd_privcmd_map_foreign_batch,
-        .map_foreign_bulk = &xc_map_foreign_bulk_compat,
-        .map_foreign_range = &netbsd_privcmd_map_foreign_range,
-        .map_foreign_ranges = &netbsd_privcmd_map_foreign_ranges,
-    },
-};
-
 /* Optionally flush file to disk and discard page cache */
 void discard_file_cache(xc_interface *xch, int fd, int flush) 
 {
@@ -263,23 +254,6 @@ void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
    return valloc(size);
 }
 
-static struct xc_osdep_ops *netbsd_osdep_init(xc_interface *xch, enum xc_osdep_type type)
-{
-    switch ( type )
-    {
-    case XC_OSDEP_PRIVCMD:
-        return &netbsd_privcmd_ops;
-    default:
-        return NULL;
-    }
-}
-
-xc_osdep_info_t xc_osdep_info = {
-    .name = "Netbsd Native OS interface",
-    .init = &netbsd_osdep_init,
-    .fake = 0,
-};
-
 /*
 * Local variables:
 * mode: C
tools/libxc/xc_private.c +7 -167
index e411210..c56d748 100644
@@ -27,111 +27,12 @@
 #include <pthread.h>
 #include <assert.h>
 
-#ifndef __MINIOS__
-#include <dlfcn.h>
-#endif
-
-#define XENCTRL_OSDEP "XENCTRL_OSDEP"
-
-#if !defined (__MINIOS__) && !defined(__RUMPUSER_XEN__) && !defined(__RUMPRUN__)
-#define DO_DYNAMIC_OSDEP
-#endif
-
-/*
- * Returns a (shallow) copy of the xc_osdep_info_t for the
- * active OS interface.
- *
- * On success a handle to the relevant library is opened.  The user
- * must subsequently call xc_osdep_put_info() when it is
- * finished with the library.
- *
- * Logs IFF xch != NULL.
- *
- * Returns:
- *  0 - on success
- * -1 - on error
- */
-static int xc_osdep_get_info(xc_interface *xch, xc_osdep_info_t *info)
-{
-    int rc = -1;
-#ifdef DO_DYNAMIC_OSDEP
-    const char *lib = getenv(XENCTRL_OSDEP);
-    xc_osdep_info_t *pinfo;
-    void *dl_handle = NULL;
-
-    if ( lib != NULL )
-    {
-        if ( getuid() != geteuid() )
-        {
-            if ( xch ) ERROR("cannot use %s=%s with setuid application", XENCTRL_OSDEP, lib);
-            abort();
-        }
-        if ( getgid() != getegid() )
-        {
-            if ( xch ) ERROR("cannot use %s=%s with setgid application", XENCTRL_OSDEP, lib);
-            abort();
-        }
-
-        dl_handle = dlopen(lib, RTLD_LAZY|RTLD_LOCAL);
-        if ( !dl_handle )
-        {
-            if ( xch ) ERROR("unable to open osdep library %s: %s", lib, dlerror());
-            goto out;
-        }
-
-        pinfo = dlsym(dl_handle, "xc_osdep_info");
-        if ( !pinfo )
-        {
-            if ( xch ) ERROR("unable to find xc_osinteface_info in %s: %s", lib, dlerror());
-            goto out;
-        }
-
-        *info = *pinfo;
-        info->dl_handle = dl_handle;
-    }
-    else
-#endif /*DO_DYNAMIC_OSDEP*/
-    {
-        *info = xc_osdep_info;
-        info->dl_handle = NULL;
-    }
-
-    rc = 0;
-
-#ifdef DO_DYNAMIC_OSDEP
-out:
-    if ( dl_handle && rc == -1 )
-        dlclose(dl_handle);
-#endif /*DO_DYNAMIC_OSDEP*/
-
-    return rc;
-}
-
-static void xc_osdep_put(xc_osdep_info_t *info)
-{
-#ifdef DO_DYNAMIC_OSDEP
-    if ( info->dl_handle )
-        dlclose(info->dl_handle);
-#endif /*DO_DYNAMIC_OSDEP*/
-}
-
-static const char *xc_osdep_type_name(enum xc_osdep_type type)
-{
-    switch ( type )
-    {
-    case XC_OSDEP_PRIVCMD: return "privcmd";
-    }
-    return "unknown";
-}
-
-static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger,
-                                                          xentoollog_logger *dombuild_logger,
-                                                          unsigned open_flags,
-                                                          enum xc_osdep_type type)
+struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
+                                            xentoollog_logger *dombuild_logger,
+                                            unsigned open_flags)
 {
    struct xc_interface_core xch_buf, *xch = &xch_buf;
 
-    xch->type = type;
    xch->flags = open_flags;
    xch->dombuild_logger_file = 0;
    xc_clear_last_error(xch);
@@ -149,9 +50,6 @@ static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *log
    xch->hypercall_buffer_cache_misses = 0;
    xch->hypercall_buffer_cache_toobig = 0;
 
-    xch->ops_handle = XC_OSDEP_OPEN_ERROR;
-    xch->ops = NULL;
-
    if (!xch->error_handler) {
        xch->error_handler = xch->error_handler_tofree =
            (xentoollog_logger*)
@@ -169,40 +67,26 @@ static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *log
    *xch = xch_buf;
 
    if (!(open_flags & XC_OPENFLAG_DUMMY)) {
-        if ( xc_osdep_get_info(xch, &xch->osdep) < 0 )
+        if ( osdep_privcmd_open(xch) < 0 )
            goto err;
-
-        xch->ops = xch->osdep.init(xch, type);
-        if ( xch->ops == NULL )
-        {
-            DPRINTF("OSDEP: interface %d (%s) not supported on this platform",
-                  type, xc_osdep_type_name(type));
-            goto err_put_iface;
-        }
-
-        xch->ops_handle = xch->ops->open(xch);
-        if (xch->ops_handle == XC_OSDEP_OPEN_ERROR)
-            goto err_put_iface;
    }
 
    return xch;
 
-err_put_iface:
-    xc_osdep_put(&xch->osdep);
 err:
    xtl_logger_destroy(xch->error_handler_tofree);
    if (xch != &xch_buf) free(xch);
    return NULL;
 }
 
-static int xc_interface_close_common(xc_interface *xch)
+int xc_interface_close(xc_interface *xch)
 {
    int rc = 0;
 
    if (!xch)
-    return 0;
+        return 0;
 
-    rc = xch->ops->close(xch, xch->ops_handle);
+    rc = osdep_privcmd_close(xch);
    if (rc) PERROR("Could not close hypervisor interface");
 
    xc__hypercall_buffer_cache_release(xch);
@@ -214,42 +98,6 @@ static int xc_interface_close_common(xc_interface *xch)
    return rc;
 }
 
-int xc_interface_is_fake(void)
-{
-    xc_osdep_info_t info;
-
-    if ( xc_osdep_get_info(NULL, &info) < 0 )
-        return -1;
-
-    /* Have a copy of info so can release the interface now. */
-    xc_osdep_put(&info);
-
-    return info.fake;
-}
-
-xc_interface *xc_interface_open(xentoollog_logger *logger,
-                                xentoollog_logger *dombuild_logger,
-                                unsigned open_flags)
-{
-    xc_interface *xch;
-
-    xch = xc_interface_open_common(logger, dombuild_logger, open_flags,
-                                   XC_OSDEP_PRIVCMD);
-
-    return xch;
-}
-
-int xc_interface_close(xc_interface *xch)
-{
-    return xc_interface_close_common(xch);
-}
-
-
-int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
-{
-    return xch->ops->u.privcmd.hypercall(xch, xch->ops_handle, hypercall);
-}
-
 static pthread_key_t errbuf_pkey;
 static pthread_once_t errbuf_pkey_once = PTHREAD_ONCE_INIT;
 
@@ -336,14 +184,6 @@ void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
    va_end(args);
 }
 
-void xc_osdep_log(xc_interface *xch, xentoollog_level level, int code, const char *fmt, ...)
-{
-    va_list args;
-    va_start(args, fmt);
-    xc_reportv(xch, xch->error_handler, level, code, fmt, args);
-    va_end(args);
-}
-
 const char *xc_set_progress_prefix(xc_interface *xch, const char *doing)
 {
    const char *old = xch->currently_progress_reporting;
tools/libxc/xc_private.h +13 -6
index 61f2f45..408b1be 100644
@@ -31,7 +31,6 @@
 
 #include "_paths.h"
 #include "xenctrl.h"
-#include "xenctrlosdep.h"
 
 #include <xen/sys/privcmd.h>
 
@@ -89,7 +88,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;
@@ -118,12 +116,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
index 182bd7d..d719a11 100644
@@ -25,7 +25,7 @@
 #include <fcntl.h>
 #include <malloc.h>
 
-static xc_osdep_handle solaris_privcmd_open(xc_interface *xch)
+int osdep_privcmd_open(xc_interface *xch)
 {
    int flags, saved_errno;
    int fd = open("/dev/xen/privcmd", O_RDWR);
@@ -33,7 +33,7 @@ static xc_osdep_handle solaris_privcmd_open(xc_interface *xch)
    if ( fd == -1 )
    {
        PERROR("Could not obtain handle on privileged command interface");
-        return XC_OSDEP_OPEN_ERROR;
+        return -1;
    }
 
    /* Although we return the file handle as the 'xc handle' the API
@@ -52,42 +52,43 @@ static xc_osdep_handle solaris_privcmd_open(xc_interface *xch)
        goto error;
    }
 
-    return (xc_osdep_handle)fd;
+    xch->privcmdfd = fd;
+    return 0;
 
 error:
    saved_errno = errno;
    close(fd);
    errno = saved_errno;
-    return XC_OSDEP_OPEN_ERROR;
+    return -1;
 }
 
-static int solaris_privcmd_close(xc_interface *xch, xc_osdep_handle h)
+int osdep_privcmd_close(xc_interface *xch)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    return close(fd);
 }
 
-static void *solaris_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, int npages)
+void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages)
 {
    return xc_memalign(xch, XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
 }
 
-static void solaris_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)
+static void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages)
 {
    free(ptr);
 }
 
-static int solaris_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
+int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
 }
 
-static void *solaris_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h,
-                                               uint32_t dom, int prot,
-                                               xen_pfn_t *arr, int num)
+void *xc_map_foreign_batch(xc_interface *xch,
+                          uint32_t dom, int prot,
+                          xen_pfn_t *arr, int num)
 {
-    int fd = (int)h;
+    int fd = xch->privcmdfd;
    privcmd_mmapbatch_t ioctlx;
    void *addr;
    addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_SHARED, fd, 0);
@@ -110,12 +111,19 @@ static void *solaris_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handl
 
 }
 
-static void *xc_map_foreign_range(xc_interface *xch, xc_osdep_handle h,
-                                  uint32_t dom,
-                                  int size, int prot,
-                                  unsigned long mfn)
+void *xc_map_foreign_bulk(xc_interface *xch,
+                          uint32_t dom, int prot,
+                          const xen_pfn_t *arr, int *err, unsigned int num)
 {
-    int fd = (int)fd;
+    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,
+                           unsigned long mfn)
+{
+    int fd = xch->privcmdfd;
    privcmd_mmap_t ioctlx;
    privcmd_mmap_entry_t entry;
    void *addr;
@@ -139,12 +147,12 @@ static void *xc_map_foreign_range(xc_interface *xch, xc_osdep_handle h,
    return addr;
 }
 
-static void *solaric_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h,
-                                                uint32_t dom,
-                                                size_t size, int prot, size_t chunksize,
-                                                privcmd_mmap_entry_t entries[], int nentries)
+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)
 {
-    int fd = (int)fd;
+    int fd = xch->privcmdfd;
    privcmd_mmap_t ioctlx;
    int i, rc;
    void *addr;
@@ -177,23 +185,6 @@ mmap_failed:
    return NULL;
 }
 
-static struct xc_osdep_ops solaris_privcmd_ops = {
-    .open = &solaris_privcmd_open,
-    .close = &solaris_privcmd_close,
-
-    .u.privcmd = {
-        .alloc_hypercall_buffer = &solaris_privcmd_alloc_hypercall_buffer,
-        .free_hypercall_buffer = &solaris_privcmd_free_hypercall_buffer,
-
-        .hypercall = &solaris_privcmd_hypercall;
-
-        .map_foreign_batch = &solaris_privcmd_map_foreign_batch,
-        .map_foreign_bulk = &xc_map_foreign_bulk_compat,
-        .map_foreign_range = &solaris_privcmd_map_foreign_range,
-        .map_foreign_ranges = &solaris_privcmd_map_foreign_ranges,
-    },
-};
-
 /* Optionally flush file to disk and discard page cache */
 void discard_file_cache(xc_interface *xch, int fd, int flush) 
 {
@@ -205,23 +196,6 @@ void *xc_memalign(xc_interface *xch, size_t alignment, size_t size)
    return memalign(alignment, size);
 }
 
-static struct xc_osdep_ops *solaris_osdep_init(xc_interface *xch, enum xc_osdep_type type)
-{
-    switch ( type )
-    {
-    case XC_OSDEP_PRIVCMD:
-        return &solaris_privcmd_ops;
-    default:
-        return NULL;
-    }
-}
-
-xc_osdep_info_t xc_osdep_info = {
-    .name = "Solaris Native OS interface",
-    .init = &solaris_osdep_init,
-    .fake = 0,
-};
-
 /*
 * Local variables:
 * mode: C
tools/libxc/xenctrl_osdep_ENOSYS.c deleted +0 -123
deleted file mode 100644
index 5182532..0000000
@@ -1,123 +0,0 @@
-/* Dummy backend which just logs and returns ENOSYS. */
-
-#include <errno.h>
-#include <inttypes.h>
-#include <stdlib.h>
-
-#include "xenctrl.h"
-#include "xenctrlosdep.h"
-
-#define IPRINTF(_x, _f, _a...) xc_osdep_log(_x,XTL_INFO,0, _f , ## _a)
-
-#define ERROR(_x, _m, _a...)  xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## _a )
-#define PERROR(_x, _m, _a...) xc_osdep_log(_x,XTL_ERROR,XC_INTERNAL_ERROR,_m \
-                  " (%d = %s)", ## _a , errno, xc_strerror(xch, errno))
-
-static xc_osdep_handle ENOSYS_privcmd_open(xc_interface *xch)
-{
-    IPRINTF(xch, "ENOSYS_privcmd: opening handle %d\n", 1);
-    return (xc_osdep_handle)1; /*dummy*/
-}
-
-static int ENOSYS_privcmd_close(xc_interface *xch, xc_osdep_handle h)
-{
-    IPRINTF(xch, "ENOSYS_privcmd: closing handle %lx\n", h);
-    return 0;
-}
-
-static int ENOSYS_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
-{
-#if defined(__FreeBSD__) || defined(__NetBSD__)
-    IPRINTF(xch, "ENOSYS_privcmd %lx: hypercall: %02lu(%#lx,%#lx,%#lx,%#lx,%#lx)\n",
-#else
-    IPRINTF(xch, "ENOSYS_privcmd %lx: hypercall: %02lld(%#llx,%#llx,%#llx,%#llx,%#llx)\n",
-#endif
-            h, hypercall->op,
-            hypercall->arg[0], hypercall->arg[1], hypercall->arg[2],
-            hypercall->arg[3], hypercall->arg[4]);
-    return -ENOSYS;
-}
-
-static void *ENOSYS_privcmd_map_foreign_batch(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
-                                      xen_pfn_t *arr, int num)
-{
-    IPRINTF(xch, "ENOSYS_privcmd %lx: map_foreign_batch: dom%d prot %#x arr %p num %d\n", h, dom, prot, arr, num);
-    return MAP_FAILED;
-}
-
-static void *ENOSYS_privcmd_map_foreign_bulk(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int prot,
-                                     const xen_pfn_t *arr, int *err, unsigned int num)
-{
-    IPRINTF(xch, "ENOSYS_privcmd %lx map_foreign_buld: dom%d prot %#x arr %p err %p num %d\n", h, dom, prot, arr, err, num);
-    return MAP_FAILED;
-}
-
-static void *ENOSYS_privcmd_map_foreign_range(xc_interface *xch, xc_osdep_handle h, uint32_t dom, int size, int prot,
-                                      unsigned long mfn)
-{
-    IPRINTF(xch, "ENOSYS_privcmd %lx map_foreign_range: dom%d size %#x prot %#x mfn %ld\n", h, dom, size, prot, mfn);
-    return MAP_FAILED;
-}
-
-static void *ENOSYS_privcmd_map_foreign_ranges(xc_interface *xch, xc_osdep_handle h, uint32_t dom, size_t size, int prot,
-                                       size_t chunksize, privcmd_mmap_entry_t entries[],
-                                       int nentries)
-{
-    IPRINTF(xch, "ENOSYS_privcmd %lx map_foreign_ranges: dom%d size %zd prot %#x chunksize %zd entries %p num %d\n", h, dom, size, prot, chunksize, entries, nentries);
-    return MAP_FAILED;
-}
-
-static struct xc_osdep_ops ENOSYS_privcmd_ops =
-{
-    .open      = &ENOSYS_privcmd_open,
-    .close     = &ENOSYS_privcmd_close,
-    .u.privcmd   = {
-        .hypercall = &ENOSYS_privcmd_hypercall,
-
-        .map_foreign_batch = &ENOSYS_privcmd_map_foreign_batch,
-        .map_foreign_bulk = &ENOSYS_privcmd_map_foreign_bulk,
-        .map_foreign_range = &ENOSYS_privcmd_map_foreign_range,
-        .map_foreign_ranges = &ENOSYS_privcmd_map_foreign_ranges,
-    }
-};
-
-static struct xc_osdep_ops * ENOSYS_osdep_init(xc_interface *xch, enum xc_osdep_type type)
-{
-    struct xc_osdep_ops *ops;
-
-    if (getenv("ENOSYS") == NULL)
-    {
-        PERROR(xch, "ENOSYS: not configured\n");
-        return NULL;
-    }
-
-    switch ( type )
-    {
-    case XC_OSDEP_PRIVCMD:
-        ops = &ENOSYS_privcmd_ops;
-        break;
-    default:
-        ops = NULL;
-        break;
-    }
-
-    IPRINTF(xch, "ENOSYS_osdep_init: initialising handle ops at %p\n", ops);
-
-    return ops;
-}
-
-xc_osdep_info_t xc_osdep_info = {
-    .name = "Pessimistic ENOSYS OS interface",
-    .init = &ENOSYS_osdep_init,
-    .fake = 1,
-};
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
tools/ocaml/libs/xc/xenctrl.ml +0 -0
index b7ba8b7..701b66c 100644
@@ -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"

tools/ocaml/libs/xc/xenctrl.ml +0 -2
-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 -0
index bc4af56..3f4947c 100644
@@ -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
index 64f1137..9a201ee 100644
@@ -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
index 92e438f..395f3a9 100644
@@ -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 +1 -1
index bfe689b..5c7ace1 100644
@@ -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;
 
Quoted 10 lines
Quoted 10 lines
tools/ocaml/xenstored/xenstored.ml +1 -2
       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

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH XEN v2 09/15] tools/libxc: Remove osdep indirection for privcmd

On Thu, 2015-07-16 at 08:59 +0100, Dave Scott wrote:
[...]

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

Confusingly my email is <[email protected]> (‘dave’ rather than ‘david’) — best to avoid cc:ing ‘david.scott’ as he probably hasn’t got xen-devel email filters set up ;-)

Oh carp, sorry David and Dave! I'll update this branch straight away.

I'll process the rest of the comments and acks etc a bit later...

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#18 lore raw

PATCH v2 10/15 tools: Refactor hypercall calling wrappers into libxencall.

In reply to Ian Campbell

libxencall 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.

---
 .gitignore                              |   2 +
 docs/misc/toolstack-library-abis.pandoc |  29 +++--
 stubdom/Makefile                        |  19 +++-
 tools/Makefile                          |   2 +
 tools/Rules.mk                          |   7 +-
 tools/libxc/Makefile                    |   7 +-
 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/libxencall/Makefile               |  67 +++++++++++
 tools/libxencall/buffer.c               | 189 ++++++++++++++++++++++++++++++++
 tools/libxencall/core.c                 | 141 ++++++++++++++++++++++++
 tools/libxencall/freebsd.c              | 137 +++++++++++++++++++++++
 tools/libxencall/include/xencall.h      |  81 ++++++++++++++
 tools/libxencall/libxencall.map         |  19 ++++
 tools/libxencall/linux.c                | 129 ++++++++++++++++++++++
 tools/libxencall/minios.c               |  78 +++++++++++++
 tools/libxencall/netbsd.c               | 118 ++++++++++++++++++++
 tools/libxencall/private.h              |  68 ++++++++++++
 tools/libxencall/solaris.c              |  94 ++++++++++++++++
 tools/misc/Makefile                     |   4 +-
 tools/xcutils/Makefile                  |   2 +-
 tools/xenpaging/Makefile                |   2 +-
 35 files changed, 1316 insertions(+), 594 deletions(-)
 create mode 100644 tools/libxencall/Makefile
 create mode 100644 tools/libxencall/buffer.c
 create mode 100644 tools/libxencall/core.c
 create mode 100644 tools/libxencall/freebsd.c
 create mode 100644 tools/libxencall/include/xencall.h
 create mode 100644 tools/libxencall/libxencall.map
 create mode 100644 tools/libxencall/linux.c
 create mode 100644 tools/libxencall/minios.c
 create mode 100644 tools/libxencall/netbsd.c
 create mode 100644 tools/libxencall/private.h
 create mode 100644 tools/libxencall/solaris.c
.gitignore +2 -0
index 8cbd177..5841570 100644
@@ -62,6 +62,7 @@ stubdom/xenstore
 stubdom/libxentoollog-*
 stubdom/libxenevtchn-*
 stubdom/libxengnttab-*
+stubdom/libxencall-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
@@ -91,6 +92,7 @@ config/Docs.mk
 tools/libxentoollog/headers.chk
 tools/libxenevtchn/headers.chk
 tools/libxengnttab/headers.chk
+tools/libxencall/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
docs/misc/toolstack-library-abis.pandoc +19 -10
index d1550a6..8339834 100644
@@ -151,6 +151,21 @@ Interface                         Underlying interface           Known external
 `xengnt???_*_notify` also use `IOCTL_GNTALLOC_SET_UNMAP_NOTIFY`,
 `IOCTL_GNTALLOC_SET_UNMAP_NOTIFY`, etc
 
+## `libxencall`: making hypercalls
+
+Making hypercalls and allocating suitable memory to use as hypercall
+pointer ("GUEST_HANDLE") arguments.
+
+Interface                         Underlying interface           Known external users
+--------------------------------- ------------------------------ --------------------
+`xencall_open`                    `open(2)`
+`xencall_close`                   `close(2)`
+`xencall0`, ..., `xencall5`       `IOCTL_PRIVCMD_HYPERCALL`
+`xencall_alloc_buffer`            `xencall_alloc_buffer_pages`
+`xencall_alloc_buffer_pages`      `mmap(2)`, `madvise(2)`
+`xencall_free_buffer`             `xencall_free_buffer_pages`
+`xencall_free_buffer_pages`       `munmap(2)`, `madvise(2)`
+
 # Unstable libraries
 
 These libraries do not provide a stable interface and are required to
@@ -217,12 +232,6 @@ Interface                         Underlying interface           Known external
 
 ### Hypercalls
 
-#### Making hypercalls
-
-Interface                         Underlying interface           Known external users
---------------------------------- ------------------------------ --------------------
-`do_xen_hypercall`                `IOCTL_PRIVCMD_HYPERCALL`      private
-
 #### Wrappers
 
 Interface                         Known in-tree users           Known external users
@@ -440,7 +449,7 @@ Symbols:
     - xc_getcpuinfo
     - xc_get_cpumap_size
     - xc_get_device_group
-    - xc_get_hvm_param
+    - xc_get_hvm_param (Legacy, replaced by `xc_hvm_param_get`)
     - xc_get_last_error
     - xc_get_machine_memory_map. Used by kexec-tools
     - xc_get_max_cpus. Used by kexec-tools
@@ -460,8 +469,8 @@ Symbols:
     - xc_hvm_map_io_range_to_ioreq_server
     - xc_hvm_map_pcidev_to_ioreq_server
     - xc_hvm_modified_memory (`HVMOP_modified_memory`). Used by qemu-dm.
-    - xc_hvm_param_get
-    - xc_hvm_param_set
+    - xc_hvm_param_get (`HVMOP_get_param`)
+    - xc_hvm_param_set (`HVMOP_set_param`)
     - xc_hvm_set_ioreq_server_state
     - xc_hvm_set_isa_irq_level (`HVMOP_set_isa_irq_level`). Used by qemu-dm.
     - xc_hvm_set_mem_type (`HVMOP_set_mem_type`). Used by qemu-dm.
@@ -559,7 +568,7 @@ Symbols:
     - xc_set_cpufreq_gov
     - xc_set_cpufreq_para
     - xc_set_cpuidle_max_cstate
-    - xc_set_hvm_param (`HVMOP_set_param`). Used by qemu-dm.
+    - xc_set_hvm_param (`HVMOP_set_param`, legacy, replaced by `xc_hvm_param_set`). Used by qemu-dm.
     - xc_set_mem_access
     - xc_set_progress_prefix
     - xc_set_sched_opt_smt
stubdom/Makefile +18 -1
index 7eab97f..ec058ca 100644
@@ -330,6 +330,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libxengnttab/include/*.h include/ && \
 	  ln -sf $(XEN_ROOT)/tools/libxengnttab/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libxengnttab/Makefile . )
+	mkdir -p libxencall-$(XEN_TARGET_ARCH)/include
+	[ -h libxencall-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxencall-$(XEN_TARGET_ARCH) && \
+	  ln -sf $(XEN_ROOT)/tools/libxencall/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libxencall/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libxencall/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libxencall/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 . && \
@@ -386,12 +392,23 @@ libxengnttab-$(XEN_TARGET_ARCH)/libxengnttab.a: $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxengnttab-$(XEN_TARGET_ARCH)
 
 #######
+# libxencall
+#######
+
+.PHONY: libxencall
+libxencall: libxencall-$(XEN_TARGET_ARCH)/libxencall.a
+libxencall-$(XEN_TARGET_ARCH)/libxencall.a: $(NEWLIB_STAMPFILE)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
+	$(MAKE) DESTDIR= -C $(MINI_OS) links
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxencall-$(XEN_TARGET_ARCH)
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog libxenevtchn libxengnttab cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog libxenevtchn libxengnttab libxencall cross-zlib
 	$(MAKE) -C $(XEN_ROOT)/tools/include
 	$(MAKE) DESTDIR= -C $(MINI_OS) links
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
tools/Makefile +2 -0
index d3bf571..e5c8879 100644
@@ -6,6 +6,7 @@ SUBDIRS-y += include
 SUBDIRS-y += libxentoollog
 SUBDIRS-y += libxenevtchn
 SUBDIRS-y += libxengnttab
+SUBDIRS-y += libxencall
 SUBDIRS-y += libxc
 SUBDIRS-$(FLASK_ENABLE) += flask
 SUBDIRS-y += xenstore
@@ -265,6 +266,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxentoollog \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxenevtchn \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxengnttab \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxencall \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +6 -1
index e3923e2..405a6a5 100644
@@ -13,6 +13,7 @@ XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libxentoollog
 XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libxenevtchn
 XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libxengnttab
+XEN_LIBXENCALL     = $(XEN_ROOT)/tools/libxencall
 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/libxc/Makefile +6 -1
index 77d2ae1..42fbabe 100644
@@ -123,6 +123,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
@@ -203,7 +208,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_domain.c +36 -69

296 lines not on this page · raw message

tools/libxc/xc_evtchn.c +3 -6
index e6bd25c..59ba6c9 100644
@@ -26,7 +26,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) )
@@ -35,11 +34,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
index e24a2e7..07298a8 100644
@@ -38,7 +38,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;
@@ -49,10 +48,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
index 8c7e906..3ee91bc 100644
@@ -22,7 +22,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) )
@@ -31,12 +30,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
index a49cffb..1cceb5d 100644
@@ -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
index 0a2ac5c..27a4c4a 100644
@@ -62,38 +62,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
index 5361f2b..78683a2 100644
@@ -68,46 +68,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
index d719a11..cbac826 100644
@@ -68,22 +68,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
index 02797bf..bd6bcd5 100644
@@ -24,7 +24,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) )
@@ -33,9 +32,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/libxencall/Makefile new file +67 -0

67 lines not on this page · raw message

tools/libxencall/buffer.c new file +189 -0

189 lines not on this page · raw message

tools/libxencall/core.c new file +141 -0

141 lines not on this page · raw message

tools/libxencall/freebsd.c new file +137 -0

137 lines not on this page · raw message

tools/libxencall/include/xencall.h new file +81 -0

81 lines not on this page · raw message

tools/libxencall/libxencall.map new file +19 -0
new file mode 100644
index 0000000..2f96144
@@ -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/libxencall/linux.c new file +129 -0

129 lines not on this page · raw message

tools/libxencall/minios.c new file +78 -0

78 lines not on this page · raw message

tools/libxencall/netbsd.c new file +118 -0

118 lines not on this page · raw message

tools/libxencall/private.h new file +68 -0

68 lines not on this page · raw message

tools/libxencall/solaris.c new file +94 -0

94 lines not on this page · raw message

tools/misc/Makefile +2 -2
index cf6a475..a2ef0ec 100644
@@ -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
index 2d1f112..e127af8 100644
@@ -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
index d491867..64876b3 100644
@@ -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
#19 lore raw

PATCH v2 11/15 tools/libxc: drop xc_map_foreign_bulk_compat wrappers

In reply to Ian Campbell

On 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.

---
 docs/misc/toolstack-library-abis.pandoc |  4 ----
 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 -------
 5 files changed, 9 insertions(+), 27 deletions(-)
docs/misc/toolstack-library-abis.pandoc +0 -4
index 8339834..271e4b5 100644
@@ -276,10 +276,6 @@ Interface                         Underlying interface           Known external
 `xc_map_foreign_ranges`
 `xc_map_foreign_batch`
 `xc_map_foreign_bulk`             `IOCTL_PRIVCMD_MMAPBATCH_V2`   qemu-dm
-`xc_map_foreign_bulk_compat`                                     private
-
-`xc_map_foreign_bulk_compat` is a stub for all not yet converted OSes
-and is used by netbsd & solaris.
 
 ### Managing guest memory map
 
tools/libxc/xc_foreign_memory.c +9 -4
index 53b6c9a..da77e9d 100644
@@ -51,10 +51,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;
@@ -91,6 +95,7 @@ void *xc_map_foreign_bulk_compat(xc_interface *xch,
 
     return ret;
 }
+#endif
 
 /*
  * Local variables:
tools/libxc/xc_netbsd.c +0 -7
index 78683a2..a61e52f 100644
@@ -68,13 +68,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
index 2288660..c8c2bdc 100644
@@ -108,11 +108,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
index cbac826..1e1a0c4 100644
@@ -95,13 +95,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
#20 lore raw

PATCH v2 12/15 tools: Remove xc_map_foreign_batch

In reply to Ian Campbell

It can trivially be replaced by xc_map_foreign_bulk which is the interface I want to move to going forward. All in tree users are trivially converted by supplying the appropriate error array and adjusting the what error handling exists (which in many cases is not much).

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. New OS ports should always implement xc_map_foreign_bulk instead.

---
 docs/misc/toolstack-library-abis.pandoc | 17 +++-------
 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               | 25 ++++++++++----
 tools/xenmon/xenbaked.c                 | 19 ++++++++---
 tools/xenpaging/pagein.c                |  4 ++-
 tools/xenpaging/xenpaging.c             | 12 ++++---
 tools/xentrace/xentrace.c               | 10 +++---
 12 files changed, 68 insertions(+), 130 deletions(-)
docs/misc/toolstack-library-abis.pandoc +5 -12
index 271e4b5..4ad6c7d 100644
@@ -274,7 +274,6 @@ Interface                         Underlying interface           Known external
 `xc_map_foreign_pages`            `IOCTL_PRIVCMD_MMAP...`        qemu-pv
 `xc_map_foreign_range`            `IOCTL_PRIVCMD_MMAP...`        qemu-dm, and qemu-pv
 `xc_map_foreign_ranges`
-`xc_map_foreign_batch`
 `xc_map_foreign_bulk`             `IOCTL_PRIVCMD_MMAPBATCH_V2`   qemu-dm
 
 ### Managing guest memory map
@@ -883,7 +882,6 @@ osdep level interfaces:
 
 Interface            Linux Minios Netbsd Freebsd Solaris
 -------------------- ----- ------ ------ ------- -------
-`map_foreign_batch`  Y     Y      Y              Y
 `map_foreign_bulk`   Y     Y      compat Y       compat
 `map_foreign_range`  Y     Y      Y      Y       Y
 `map_foreign_ranges` Y     Y      Y      Y       Y
@@ -897,7 +895,6 @@ Some osdep call other `xc_map_foreign_*` recursivley:
 
 Interface            Linux                        FreeBSD
 -------------------- ---------------------------- -------------------------
-`map_foreign_batch`  `IOCTL_PRIVCMD_MMAPBATCH`    N/A
 `map_foreign_bulk`   `IOCTL_PRIVCMD_MMAPBATCH_V2` `IOCTL_PRIVCMD_MMAPBATCH`
 `map_foreign_range`  `xc_map_foreign_pages`       `xc_map_foreign_pages`
 `map_foreign_ranges` `xc_map_foreign_pages`       `xc_map_foreign_pages`
@@ -909,17 +906,14 @@ Interface               Underlying interface
 `xc_map_foreign_pages`  `xc_map_foreign_bulk`
 `xc_map_foreign_range`  `osdep: map_foreign_range`
 `xc_map_foreign_ranges` `osdep: map_foreign_ranges`
-`xc_map_foreign_batch`  `osdep: map_foreign_batch`
 `xc_map_foreign_bulk`   `osdep: map_foreign_bulk`
 
 `osdep: *` have been collapsed since osdep layer was removed.
 
-`xc_map_foreign_bulk_compat` is an internal helper used by osdep
-backends which have not implemented there own version. It uses
-`xc_map_foreign_batch`.
-
-`xc_map_foreign_batch_single` is part of linux osdep, but name has
-leaked.
+`xc_map_foreign_bulk` can be an internal compat helper used by oses
+which have not implemented their own version. It used to use
+`xc_map_foreign_batch` which is now an osdep for those OSes which need
+it.
 
 Interface               Internal users               External users
 ----------------------  --------------               --------------
@@ -928,11 +922,10 @@ Interface               Internal users               External users
                         mfndump, memshrtool, xenmon,
                         xenstored, xentrace
 `xc_map_foreign_ranges` NONE
-`xc_map_foreign_batch`  xenmon, xenpaging, xentrace
 `xc_map_foreign_bulk`   used recursively             qemu-dm
 
 Only one interface should become a stable API. Something based on
 `xc_map_foreign_bulk` seems most appropriate (it is used by
 `xc_map_foreign_pages` as well as by xc_map_foreign_range` and
 `xc_map_foreign_ranges` on Linux + FreeBSD. A compat version exists in
-terms for `xc_map_foreign_batch` for other OSes.
+terms of `xc_map_foreign_batch` for other OSes.
tools/libxc/include/xenctrl.h +0 -10
index 61f68bb..201fd70 100644
@@ -1367,16 +1367,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
index da77e9d..ae133a1 100644
@@ -56,6 +56,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)
@@ -76,7 +78,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
index 27a4c4a..ed20652 100644
@@ -74,28 +74,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
index a61e52f..f02015c 100644
@@ -68,16 +68,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;
     }
 
@@ -88,7 +88,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
index 1e1a0c4..0a0fd14 100644
@@ -68,9 +68,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 +18 -7
index a5b3277..4d7e7cc 100644
@@ -46,6 +46,7 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
     void *ring_page = NULL;
     uint64_t pfn;
     xen_pfn_t ring_pfn, mmap_pfn;
+    int err;
     unsigned int op, mode;
     int rc1, rc2, saved_errno;
 
@@ -73,9 +74,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,
-                                     &mmap_pfn, 1);
-    if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+    ring_page = xc_map_foreign_bulk(xch, domain_id, PROT_READ | PROT_WRITE,
+				    &mmap_pfn, &err, 1);
+    if ( !ring_page )
     {
         /* Map failed, populate ring page */
         rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0,
@@ -87,11 +88,11 @@ 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,
-                                         &mmap_pfn, 1);
-        if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+        ring_page = xc_map_foreign_bulk(xch, domain_id, PROT_READ | PROT_WRITE,
+					&mmap_pfn, &err, 1);
+        if ( !ring_page )
         {
-            PERROR("Could not map the ring page\n");
+            PERROR("Could not map the ring page: %d\n", err);
             goto out;
         }
     }
@@ -157,3 +158,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 +15 -4
index f092aec..9e2a49b 100644
@@ -408,14 +408,15 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
                                    + tbufs.t_info->mfn_offset[i];
         int j;
         xen_pfn_t pfn_list[tbufs.t_info->tbuf_size];
+        int err_list[tbufs.t_info->tbuf_size];
 
         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,
-                                             PROT_READ | PROT_WRITE,
-                                             pfn_list,
-                                             tbufs.t_info->tbuf_size);
+        tbufs.meta[i] = xc_map_foreign_bulk(xc_handle, DOMID_XEN,
+					    PROT_READ | PROT_WRITE,
+					    pfn_list, err_list,
+					    tbufs.t_info->tbuf_size);
         if ( tbufs.meta[i] == NULL )
         {
             PERROR("Failed to map cpu buffer!");
@@ -1176,3 +1177,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/pagein.c +3 -1
index 7cb0f33..18699ec 100644
@@ -23,6 +23,7 @@ static void *page_in(void *arg)
     void *page;
     int i, num;
     xen_pfn_t gfns[XENPAGING_PAGEIN_QUEUE_SIZE];
+    int errs[XENPAGING_PAGEIN_QUEUE_SIZE];
 
     while (1)
     {
@@ -42,7 +43,8 @@ static void *page_in(void *arg)
         pthread_mutex_unlock(&page_in_mutex);
 
         /* Ignore errors */
-        page = xc_map_foreign_pages(pia->xch, pia->dom, PROT_READ, gfns, num);
+        page = xc_map_foreign_bulk(pia->xch, pia->dom, PROT_READ,
+                                   gfns, errs, num);
         if (page)
             munmap(page, PAGE_SIZE * num);
     }
tools/xenpaging/xenpaging.c +7 -5
index 6776896..a819a5b 100644
@@ -282,6 +282,7 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
     char *p;
     int rc;
     unsigned long ring_pfn, mmap_pfn;
+    int mmap_err;
 
     /* Allocate memory */
     paging = calloc(1, sizeof(struct xenpaging));
@@ -343,8 +344,8 @@ 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);
+        xc_map_foreign_bulk(xch, paging->vm_event.domain_id,
+                            PROT_READ | PROT_WRITE, &mmap_pfn, &mmap_err, 1);
     if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
     {
         /* Map failed, populate ring page */
@@ -359,11 +360,12 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
 
         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);
+            xc_map_foreign_bulk(xch, paging->vm_event.domain_id,
+                                PROT_READ | PROT_WRITE,
+                                &mmap_pfn, &mmap_err, 1);
         if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
         {
-            PERROR("Could not map the ring page\n");
+            PERROR("Could not map the ring page: %d\n", mmap_err);
             goto err;
         }
     }
tools/xentrace/xentrace.c +6 -4
index c970d42..f66a77c 100644
@@ -504,14 +504,15 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
                                    + tbufs.t_info->mfn_offset[i];
         int j;
         xen_pfn_t pfn_list[tbufs.t_info->tbuf_size];
+        int pfn_err[tbufs.t_info->tbuf_size];
 
         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,
-                                             PROT_READ | PROT_WRITE,
-                                             pfn_list,
-                                             tbufs.t_info->tbuf_size);
+        tbufs.meta[i] = xc_map_foreign_bulk(xc_handle, DOMID_XEN,
+                                            PROT_READ | PROT_WRITE,
+                                            pfn_list, pfn_err,
+                                            tbufs.t_info->tbuf_size);
         if ( tbufs.meta[i] == NULL )
         {
             PERROR("Failed to map cpu buffer!");
@@ -1221,6 +1222,7 @@ int main(int argc, char **argv)
 
     return ret;
 }
+
 /*
  * Local variables:
  * mode: C
Signature · 1 line
2.1.4
Acked-by on v2 12/15
#21 lore raw

Re: [PATCH XEN v2 12/15] tools: Remove xc_map_foreign_batch

Quoted 9 lines · Ian Campbell

It can trivially be replaced by xc_map_foreign_bulk which is the interface I want to move to going forward. All in tree users are trivially converted by supplying the appropriate error array and adjusting the what error handling exists (which in many cases is not much).

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.

Quoted 7 lines

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. New OS ports should always implement xc_map_foreign_bulk instead.

xentrace and xenbaked:

(Note that I'm going to be switching to using @citrix.com in tags post-4.6)

Quoted 476 lines
---
 docs/misc/toolstack-library-abis.pandoc | 17 +++-------
 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               | 25 ++++++++++----
 tools/xenmon/xenbaked.c                 | 19 ++++++++---
 tools/xenpaging/pagein.c                |  4 ++-
 tools/xenpaging/xenpaging.c             | 12 ++++---
 tools/xentrace/xentrace.c               | 10 +++---
 12 files changed, 68 insertions(+), 130 deletions(-)
docs/misc/toolstack-library-abis.pandoc +5 -12
index 271e4b5..4ad6c7d 100644
@@ -274,7 +274,6 @@ Interface                         Underlying interface           Known external
 `xc_map_foreign_pages`            `IOCTL_PRIVCMD_MMAP...`        qemu-pv
 `xc_map_foreign_range`            `IOCTL_PRIVCMD_MMAP...`        qemu-dm, and qemu-pv
 `xc_map_foreign_ranges`
-`xc_map_foreign_batch`
 `xc_map_foreign_bulk`             `IOCTL_PRIVCMD_MMAPBATCH_V2`   qemu-dm
 
 ### Managing guest memory map
@@ -883,7 +882,6 @@ osdep level interfaces:
 
 Interface            Linux Minios Netbsd Freebsd Solaris
 -------------------- ----- ------ ------ ------- -------
-`map_foreign_batch`  Y     Y      Y              Y
 `map_foreign_bulk`   Y     Y      compat Y       compat
 `map_foreign_range`  Y     Y      Y      Y       Y
 `map_foreign_ranges` Y     Y      Y      Y       Y
@@ -897,7 +895,6 @@ Some osdep call other `xc_map_foreign_*` recursivley:
 
 Interface            Linux                        FreeBSD
 -------------------- ---------------------------- -------------------------
-`map_foreign_batch`  `IOCTL_PRIVCMD_MMAPBATCH`    N/A
 `map_foreign_bulk`   `IOCTL_PRIVCMD_MMAPBATCH_V2` `IOCTL_PRIVCMD_MMAPBATCH`
 `map_foreign_range`  `xc_map_foreign_pages`       `xc_map_foreign_pages`
 `map_foreign_ranges` `xc_map_foreign_pages`       `xc_map_foreign_pages`
@@ -909,17 +906,14 @@ Interface               Underlying interface
 `xc_map_foreign_pages`  `xc_map_foreign_bulk`
 `xc_map_foreign_range`  `osdep: map_foreign_range`
 `xc_map_foreign_ranges` `osdep: map_foreign_ranges`
-`xc_map_foreign_batch`  `osdep: map_foreign_batch`
 `xc_map_foreign_bulk`   `osdep: map_foreign_bulk`
 
 `osdep: *` have been collapsed since osdep layer was removed.
 
-`xc_map_foreign_bulk_compat` is an internal helper used by osdep
-backends which have not implemented there own version. It uses
-`xc_map_foreign_batch`.
-
-`xc_map_foreign_batch_single` is part of linux osdep, but name has
-leaked.
+`xc_map_foreign_bulk` can be an internal compat helper used by oses
+which have not implemented their own version. It used to use
+`xc_map_foreign_batch` which is now an osdep for those OSes which need
+it.
 
 Interface               Internal users               External users
 ----------------------  --------------               --------------
@@ -928,11 +922,10 @@ Interface               Internal users               External users
                         mfndump, memshrtool, xenmon,
                         xenstored, xentrace
 `xc_map_foreign_ranges` NONE
-`xc_map_foreign_batch`  xenmon, xenpaging, xentrace
 `xc_map_foreign_bulk`   used recursively             qemu-dm
 
 Only one interface should become a stable API. Something based on
 `xc_map_foreign_bulk` seems most appropriate (it is used by
 `xc_map_foreign_pages` as well as by xc_map_foreign_range` and
 `xc_map_foreign_ranges` on Linux + FreeBSD. A compat version exists in
-terms for `xc_map_foreign_batch` for other OSes.
+terms of `xc_map_foreign_batch` for other OSes.
tools/libxc/include/xenctrl.h +0 -10
index 61f68bb..201fd70 100644
@@ -1367,16 +1367,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
index da77e9d..ae133a1 100644
@@ -56,6 +56,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)
@@ -76,7 +78,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
index 488e8df..6641bd1 100644
@@ -86,8 +86,8 @@ int osdep_privcmd_close(xc_interface *xch)
     return close(fd);
 }
 
-static int xc_map_foreign_batch_single(int fd, uint32_t dom,
-                                       xen_pfn_t *mfn, unsigned long addr)
+static int map_foreign_batch_single(int fd, uint32_t dom,
+                                    xen_pfn_t *mfn, unsigned long addr)
 {
     privcmd_mmapbatch_t ioctlx;
     int rc;
@@ -108,59 +108,6 @@ static int xc_map_foreign_batch_single(int fd, uint32_t dom,
     return rc;
 }
 
-void *xc_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;
-    int rc;
-
-    addr = mmap(NULL, num << XC_PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
-    if ( addr == MAP_FAILED )
-    {
-        PERROR("xc_map_foreign_batch: mmap failed");
-        return NULL;
-    }
-
-    ioctlx.num = num;
-    ioctlx.dom = dom;
-    ioctlx.addr = (unsigned long)addr;
-    ioctlx.arr = arr;
-
-    rc = ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx);
-    if ( (rc < 0) && (errno == ENOENT) )
-    {
-        int i;
-
-        for ( i = 0; i < num; i++ )
-        {
-            if ( (arr[i] & PRIVCMD_MMAPBATCH_MFN_ERROR) ==
-                           PRIVCMD_MMAPBATCH_PAGED_ERROR )
-            {
-                unsigned long paged_addr = (unsigned long)addr + (i << XC_PAGE_SHIFT);
-                rc = xc_map_foreign_batch_single(fd, dom, &arr[i],
-                                                 paged_addr);
-                if ( rc < 0 )
-                    goto out;
-            }
-        }
-    }
-
- out:
-    if ( rc < 0 )
-    {
-        int saved_errno = errno;
-        PERROR("xc_map_foreign_batch: ioctl failed");
-        (void)munmap(addr, num << XC_PAGE_SHIFT);
-        errno = saved_errno;
-        return NULL;
-    }
-
-    return addr;
-}
-
 /*
  * Retry mmap of all paged gfns in batches
  * retuns < 0 on fatal error
@@ -300,7 +247,7 @@ void *xc_map_foreign_bulk(xc_interface *xch,
                     err[i] = rc ?: -EINVAL;
                     continue;
                 }
-                rc = xc_map_foreign_batch_single(fd, dom, pfn + i,
+                rc = map_foreign_batch_single(fd, dom, pfn + i,
                         (unsigned long)addr + ((unsigned long)i<<XC_PAGE_SHIFT));
                 if ( rc < 0 )
                 {
tools/libxc/xc_minios.c +0 -22
index 27a4c4a..ed20652 100644
@@ -74,28 +74,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
index a61e52f..f02015c 100644
@@ -68,16 +68,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;
     }
 
@@ -88,7 +88,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
index 1e1a0c4..0a0fd14 100644
@@ -68,9 +68,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 +18 -7
index a5b3277..4d7e7cc 100644
@@ -46,6 +46,7 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
     void *ring_page = NULL;
     uint64_t pfn;
     xen_pfn_t ring_pfn, mmap_pfn;
+    int err;
     unsigned int op, mode;
     int rc1, rc2, saved_errno;
 
@@ -73,9 +74,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,
-                                     &mmap_pfn, 1);
-    if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+    ring_page = xc_map_foreign_bulk(xch, domain_id, PROT_READ | PROT_WRITE,
+				    &mmap_pfn, &err, 1);
+    if ( !ring_page )
     {
         /* Map failed, populate ring page */
         rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0,
@@ -87,11 +88,11 @@ 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,
-                                         &mmap_pfn, 1);
-        if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+        ring_page = xc_map_foreign_bulk(xch, domain_id, PROT_READ | PROT_WRITE,
+					&mmap_pfn, &err, 1);
+        if ( !ring_page )
         {
-            PERROR("Could not map the ring page\n");
+            PERROR("Could not map the ring page: %d\n", err);
             goto out;
         }
     }
@@ -157,3 +158,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 +15 -4
index f092aec..9e2a49b 100644
@@ -408,14 +408,15 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
                                    + tbufs.t_info->mfn_offset[i];
         int j;
         xen_pfn_t pfn_list[tbufs.t_info->tbuf_size];
+        int err_list[tbufs.t_info->tbuf_size];
 
         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,
-                                             PROT_READ | PROT_WRITE,
-                                             pfn_list,
-                                             tbufs.t_info->tbuf_size);
+        tbufs.meta[i] = xc_map_foreign_bulk(xc_handle, DOMID_XEN,
+					    PROT_READ | PROT_WRITE,
+					    pfn_list, err_list,
+					    tbufs.t_info->tbuf_size);
         if ( tbufs.meta[i] == NULL )
         {
             PERROR("Failed to map cpu buffer!");
@@ -1176,3 +1177,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/pagein.c +3 -1
index 7cb0f33..18699ec 100644
@@ -23,6 +23,7 @@ static void *page_in(void *arg)
     void *page;
     int i, num;
     xen_pfn_t gfns[XENPAGING_PAGEIN_QUEUE_SIZE];
+    int errs[XENPAGING_PAGEIN_QUEUE_SIZE];
 
     while (1)
     {
@@ -42,7 +43,8 @@ static void *page_in(void *arg)
         pthread_mutex_unlock(&page_in_mutex);
 
         /* Ignore errors */
-        page = xc_map_foreign_pages(pia->xch, pia->dom, PROT_READ, gfns, num);
+        page = xc_map_foreign_bulk(pia->xch, pia->dom, PROT_READ,
+                                   gfns, errs, num);
         if (page)
             munmap(page, PAGE_SIZE * num);
     }
tools/xenpaging/xenpaging.c +7 -5
index 6776896..a819a5b 100644
@@ -282,6 +282,7 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
     char *p;
     int rc;
     unsigned long ring_pfn, mmap_pfn;
+    int mmap_err;
 
     /* Allocate memory */
     paging = calloc(1, sizeof(struct xenpaging));
@@ -343,8 +344,8 @@ 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);
+        xc_map_foreign_bulk(xch, paging->vm_event.domain_id,
+                            PROT_READ | PROT_WRITE, &mmap_pfn, &mmap_err, 1);
     if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
     {
         /* Map failed, populate ring page */
@@ -359,11 +360,12 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
 
         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);
+            xc_map_foreign_bulk(xch, paging->vm_event.domain_id,
+                                PROT_READ | PROT_WRITE,
+                                &mmap_pfn, &mmap_err, 1);
         if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
         {
-            PERROR("Could not map the ring page\n");
+            PERROR("Could not map the ring page: %d\n", mmap_err);
             goto err;
         }
     }
tools/xentrace/xentrace.c +6 -4
index c970d42..f66a77c 100644
@@ -504,14 +504,15 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
                                    + tbufs.t_info->mfn_offset[i];
         int j;
         xen_pfn_t pfn_list[tbufs.t_info->tbuf_size];
+        int pfn_err[tbufs.t_info->tbuf_size];
 
         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,
-                                             PROT_READ | PROT_WRITE,
-                                             pfn_list,
-                                             tbufs.t_info->tbuf_size);
+        tbufs.meta[i] = xc_map_foreign_bulk(xc_handle, DOMID_XEN,
+                                            PROT_READ | PROT_WRITE,
+                                            pfn_list, pfn_err,
+                                            tbufs.t_info->tbuf_size);
         if ( tbufs.meta[i] == NULL )
         {
             PERROR("Failed to map cpu buffer!");
@@ -1221,6 +1222,7 @@ int main(int argc, char **argv)
 
     return ret;
 }
+
 /*
  * Local variables:
  * mode: C
#22 lore raw

PATCH v2 13/15 tools: Implement xc_map_foreign_range(s) in terms of common helper

In reply to Ian Campbell

Both 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.

---
 docs/misc/toolstack-library-abis.pandoc | 35 +++++------------
 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 -------------------------------
 7 files changed, 60 insertions(+), 304 deletions(-)
docs/misc/toolstack-library-abis.pandoc +10 -25
index 4ad6c7d..35674cc 100644
@@ -876,36 +876,25 @@ functionality areas:
 
 # Foreign memory mapping functions
 
-The `xc_map_foreign_*` functions are a bit of a twisty maze.
+The `xc_map_foreign_*` functions were once a bit of a twisty maze, but
+now all are implemented in terms of a single underlying per-OS
+function.
 
 osdep level interfaces:
 
 Interface            Linux Minios Netbsd Freebsd Solaris
 -------------------- ----- ------ ------ ------- -------
 `map_foreign_bulk`   Y     Y      compat Y       compat
-`map_foreign_range`  Y     Y      Y      Y       Y
-`map_foreign_ranges` Y     Y      Y      Y       Y
 
-_compat_ means using `xc_map_foreign_bulk_compat`
-
-`xc_map_foreign_pages` is common and implemented using
-`xc_map_foreign_bulk`.
-
-Some osdep call other `xc_map_foreign_*` recursivley:
-
-Interface            Linux                        FreeBSD
--------------------- ---------------------------- -------------------------
-`map_foreign_bulk`   `IOCTL_PRIVCMD_MMAPBATCH_V2` `IOCTL_PRIVCMD_MMAPBATCH`
-`map_foreign_range`  `xc_map_foreign_pages`       `xc_map_foreign_pages`
-`map_foreign_ranges` `xc_map_foreign_pages`       `xc_map_foreign_pages`
+_compat_ means using `osdep_map_foreign_batch` layer
 
 libxenctrl level interfaces:
 
 Interface               Underlying interface
 ----------------------  ---------------------------
 `xc_map_foreign_pages`  `xc_map_foreign_bulk`
-`xc_map_foreign_range`  `osdep: map_foreign_range`
-`xc_map_foreign_ranges` `osdep: map_foreign_ranges`
+`xc_map_foreign_range`  `xc_map_foreign_pages`
+`xc_map_foreign_ranges` `xc_map_foreign_pages`
 `xc_map_foreign_bulk`   `osdep: map_foreign_bulk`
 
 `osdep: *` have been collapsed since osdep layer was removed.
@@ -915,17 +904,13 @@ which have not implemented their own version. It used to use
 `xc_map_foreign_batch` which is now an osdep for those OSes which need
 it.
 
-Interface               Internal users               External users
-----------------------  --------------               --------------
+Interface               In-tree users                External users
+----------------------  -------------                --------------
 `xc_map_foreign_pages`  xenpaging                    qemu-pv
 `xc_map_foreign_range`  xenconsole, kdd, libxl,      qemu-dm, qemu-pv
                         mfndump, memshrtool, xenmon,
                         xenstored, xentrace
-`xc_map_foreign_ranges` NONE
+`xc_map_foreign_ranges` libxc internal
 `xc_map_foreign_bulk`   used recursively             qemu-dm
 
-Only one interface should become a stable API. Something based on
-`xc_map_foreign_bulk` seems most appropriate (it is used by
-`xc_map_foreign_pages` as well as by xc_map_foreign_range` and
-`xc_map_foreign_ranges` on Linux + FreeBSD. A compat version exists in
-terms of `xc_map_foreign_batch` for other OSes.
+`xc_map_foreign_bulk` should become an underlying stable API.
tools/libxc/xc_foreign_memory.c +50 -0

56 lines not on this page · raw message

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
#23 lore raw

PATCH v2 14/15 tools: Refactor foreign memory mapping into libxenforeignmemory

In reply to Ian Campbell

libxenforeignmemory 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.

---
 .gitignore                                         |   2 +
 docs/misc/toolstack-library-abis.pandoc            |  22 +-
 stubdom/Makefile                                   |  21 +-
 tools/Makefile                                     |   3 +
 tools/Rules.mk                                     |  11 +-
 tools/console/daemon/utils.c                       |   1 -
 tools/console/daemon/utils.h                       |   1 +
 tools/libxc/Makefile                               |   8 +-
 tools/libxc/include/xenctrl.h                      |  26 --
 tools/libxc/include/xenctrl_compat.h               |  36 +++
 tools/libxc/xc_domain_restore.c                    |   4 +-
 tools/libxc/xc_domain_save.c                       |   4 +-
 tools/libxc/xc_foreign_memory.c                    |  49 +---
 tools/libxc/xc_freebsd_osdep.c                     | 137 ----------
 tools/libxc/xc_linux_osdep.c                       | 296 ---------------------
 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/xc_vm_event.c                          |  10 +-
 tools/libxc/xg_private.h                           |   3 +-
 tools/libxenforeignmemory/Makefile                 |  67 +++++
 tools/libxenforeignmemory/compat.c                 |  72 +++++
 tools/libxenforeignmemory/core.c                   |  65 +++++
 tools/libxenforeignmemory/freebsd.c                | 126 +++++++++
 .../libxenforeignmemory/include/xenforeignmemory.h |  68 +++++
 tools/libxenforeignmemory/libxenforeignmemory.map  |   7 +
 tools/libxenforeignmemory/linux.c                  | 284 ++++++++++++++++++++
 tools/libxenforeignmemory/minios.c                 |  59 ++++
 tools/libxenforeignmemory/netbsd.c                 |  92 +++++++
 tools/libxenforeignmemory/private.h                |  47 ++++
 tools/libxenforeignmemory/solaris.c                |  95 +++++++
 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/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 +
 47 files changed, 1118 insertions(+), 721 deletions(-)
 delete mode 100644 tools/libxc/xc_freebsd_osdep.c
 delete mode 100644 tools/libxc/xc_linux_osdep.c
 create mode 100644 tools/libxenforeignmemory/Makefile
 create mode 100644 tools/libxenforeignmemory/compat.c
 create mode 100644 tools/libxenforeignmemory/core.c
 create mode 100644 tools/libxenforeignmemory/freebsd.c
 create mode 100644 tools/libxenforeignmemory/include/xenforeignmemory.h
 create mode 100644 tools/libxenforeignmemory/libxenforeignmemory.map
 create mode 100644 tools/libxenforeignmemory/linux.c
 create mode 100644 tools/libxenforeignmemory/minios.c
 create mode 100644 tools/libxenforeignmemory/netbsd.c
 create mode 100644 tools/libxenforeignmemory/private.h
 create mode 100644 tools/libxenforeignmemory/solaris.c
.gitignore +2 -0
index 5841570..bb643f7 100644
@@ -63,6 +63,7 @@ stubdom/libxentoollog-*
 stubdom/libxenevtchn-*
 stubdom/libxengnttab-*
 stubdom/libxencall-*
+stubdom/libxenforeignmemory-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
@@ -93,6 +94,7 @@ tools/libxentoollog/headers.chk
 tools/libxenevtchn/headers.chk
 tools/libxengnttab/headers.chk
 tools/libxencall/headers.chk
+tools/libxenforeignmemory/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
docs/misc/toolstack-library-abis.pandoc +17 -5
index 35674cc..63b83bc 100644
@@ -166,6 +166,16 @@ Interface                         Underlying interface           Known external
 `xencall_free_buffer`             `xencall_free_buffer_pages`
 `xencall_free_buffer_pages`       `munmap(2)`, `madvise(2)`
 
+## `libxenforeignmemory`: privileged foreign mappings
+
+Mapping foreign guest memory.
+
+Interface                         Underlying interface           Known external users
+--------------------------------- ------------------------------ --------------------
+`xenforeignmemory_open`           `open(2)`
+`xenforeignmemory_close`          `close(2)`
+`xenforeignmemory_map`            `IOCTL_PRIVCMD_MMAPBATCH` etc
+
 # Unstable libraries
 
 These libraries do not provide a stable interface and are required to
@@ -269,12 +279,14 @@ The following are private:
 
 ### Mapping foreign memory
 
-Interface                         Underlying interface           Known external users
---------------------------------- ------------------------------ --------------------
-`xc_map_foreign_pages`            `IOCTL_PRIVCMD_MMAP...`        qemu-pv
-`xc_map_foreign_range`            `IOCTL_PRIVCMD_MMAP...`        qemu-dm, and qemu-pv
+All implemented in terms of `xenforeignmemory_map`.
+
+Interface                         Known external users
+--------------------------------- --------------------
+`xc_map_foreign_pages`            qemu-pv
+`xc_map_foreign_range`            qemu-dm, qemu-pv
 `xc_map_foreign_ranges`
-`xc_map_foreign_bulk`             `IOCTL_PRIVCMD_MMAPBATCH_V2`   qemu-dm
+`xc_map_foreign_bulk`             qemu-dm
 
 ### Managing guest memory map
 
stubdom/Makefile +20 -1
index ec058ca..529f5c3 100644
@@ -336,6 +336,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libxencall/include/*.h include/ && \
 	  ln -sf $(XEN_ROOT)/tools/libxencall/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libxencall/Makefile . )
+	mkdir -p libxenforeignmemory-$(XEN_TARGET_ARCH)/include
+	[ -h libxenforeignmemory-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxenforeignmemory-$(XEN_TARGET_ARCH) && \
+	  ln -sf $(XEN_ROOT)/tools/libxenforeignmemory/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libxenforeignmemory/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libxenforeignmemory/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libxenforeignmemory/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 . && \
@@ -390,6 +396,7 @@ libxengnttab-$(XEN_TARGET_ARCH)/libxengnttab.a: $(NEWLIB_STAMPFILE)
 	$(MAKE) -C $(XEN_ROOT)/tools/include
 	$(MAKE) DESTDIR= -C $(MINI_OS) links
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxengnttab-$(XEN_TARGET_ARCH)
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxencall-$(MINIOS_TARGET_ARCH) -whole-archive -lxencall -no-whole-archive
 
 #######
 # libxencall
@@ -401,6 +408,18 @@ libxencall-$(XEN_TARGET_ARCH)/libxencall.a: $(NEWLIB_STAMPFILE)
 	$(MAKE) -C $(XEN_ROOT)/tools/include
 	$(MAKE) DESTDIR= -C $(MINI_OS) links
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxencall-$(XEN_TARGET_ARCH)
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxencall-$(MINIOS_TARGET_ARCH) -whole-archive -lxencall -no-whole-archive
+
+#######
+# libxenforeignmemory
+#######
+
+.PHONY: libxenforeignmemory
+libxenforeignmemory: libxenforeignmemory-$(XEN_TARGET_ARCH)/libxenforeignmemory.a
+libxenforeignmemory-$(XEN_TARGET_ARCH)/libxenforeignmemory.a: $(NEWLIB_STAMPFILE)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
+	$(MAKE) DESTDIR= -C $(MINI_OS) links
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libxenforeignmemory-$(XEN_TARGET_ARCH)
 
 #######
 # libxc
@@ -408,7 +427,7 @@ libxencall-$(XEN_TARGET_ARCH)/libxencall.a: $(NEWLIB_STAMPFILE)
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog libxenevtchn libxengnttab libxencall cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory cross-zlib
 	$(MAKE) -C $(XEN_ROOT)/tools/include
 	$(MAKE) DESTDIR= -C $(MINI_OS) links
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
tools/Makefile +3 -0
index e5c8879..30abd57 100644
@@ -7,6 +7,7 @@ SUBDIRS-y += libxentoollog
 SUBDIRS-y += libxenevtchn
 SUBDIRS-y += libxengnttab
 SUBDIRS-y += libxencall
+SUBDIRS-y += libxenforeignmemory
 SUBDIRS-y += libxc
 SUBDIRS-$(FLASK_ENABLE) += flask
 SUBDIRS-y += xenstore
@@ -253,6 +254,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/libxentoollog/include \
 		-I$(XEN_ROOT)/tools/libxenevtchn/include \
@@ -267,6 +269,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxenevtchn \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxengnttab \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxencall \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libxenforeignmemory \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +8 -3
index 405a6a5..4a67f1f 100644
@@ -14,6 +14,7 @@ XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libxentoollog
 XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libxenevtchn
 XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libxengnttab
 XEN_LIBXENCALL     = $(XEN_ROOT)/tools/libxencall
+XEN_LIBXENFOREIGNMEMORY = $(XEN_ROOT)/tools/libxenforeignmemory
 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=L$(XEN_LIBXC)
tools/console/daemon/utils.c +0 -1
index 71dd185..edc1595 100644
@@ -34,7 +34,6 @@
 #include <string.h>
 #include <signal.h>
 
-#include "xenctrl.h"
 #include "utils.h"
 
 struct xs_handle *xs;
tools/console/daemon/utils.h +1 -0
index 8725dcd..45c7c34 100644
@@ -24,6 +24,7 @@
 #include <stdbool.h>
 #include <syslog.h>
 #include <stdio.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 
 #include <xenstore.h>
tools/libxc/Makefile +4 -4
index 42fbabe..79afb78 100644
@@ -41,8 +41,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
@@ -126,7 +126,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)
 
@@ -208,7 +208,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
index 201fd70..bfa11a7 100644
@@ -1349,32 +1349,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
index d99fa11..54c23a4 100644
@@ -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_domain_restore.c +2 -2
index 8435f6b..5d44512 100644
@@ -1284,8 +1284,8 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
         PERROR("allocation for pfn_err failed");
         return -1;
     }
-    region_base = xc_map_foreign_bulk(
-        xch, dom, PROT_WRITE, region_mfn, pfn_err, j);
+    region_base = xenforeignmemory_map(xch->fmem,
+        dom, PROT_WRITE, region_mfn, pfn_err, j);
 
     if ( region_base == NULL )
     {
tools/libxc/xc_domain_save.c +2 -2
index 3222473..412819f 100644
@@ -1265,8 +1265,8 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter
             if ( batch == 0 )
                 goto skip; /* vanishingly unlikely... */
 
-            region_base = xc_map_foreign_bulk(
-                xch, dom, PROT_READ, pfn_type, pfn_err, batch);
+            region_base = xenforeignmemory_map(xch->fmem,
+                dom, PROT_READ, pfn_type, pfn_err, batch);
             if ( region_base == NULL )
             {
                 PERROR("map batch failed");
tools/libxc/xc_foreign_memory.c +4 -45

70 lines not on this page · raw message

tools/libxc/xc_freebsd_osdep.c deleted +0 -137

137 lines not on this page · raw message

tools/libxc/xc_linux_osdep.c deleted +0 -296

296 lines not on this page · raw message

tools/libxc/xc_minios.c +0 -29
index 1616c58..7373e54 100644
@@ -40,40 +40,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
index 00f96ba..94ec444 100644
@@ -59,11 +59,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;
@@ -71,7 +72,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;
@@ -87,8 +88,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
index c8c2bdc..b230854 100644
@@ -30,8 +30,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>
 
@@ -95,11 +100,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
index bf1ee15..4bbda9d 100644
@@ -315,8 +315,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
index d63b783..2672ad3 100644
@@ -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/xc_vm_event.c +6 -4
index 4d7e7cc..940efd7 100644
@@ -74,8 +74,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_bulk(xch, domain_id, PROT_READ | PROT_WRITE,
-				    &mmap_pfn, &err, 1);
+    ring_page = xenforeignmemory_map(xch->fmem,
+				     domain_id, PROT_READ | PROT_WRITE,
+				     &mmap_pfn, &err, 1);
     if ( !ring_page )
     {
         /* Map failed, populate ring page */
@@ -88,8 +89,9 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
         }
 
         mmap_pfn = ring_pfn;
-        ring_page = xc_map_foreign_bulk(xch, domain_id, PROT_READ | PROT_WRITE,
-					&mmap_pfn, &err, 1);
+        ring_page = xenforeignmemory_map(xch->fmem,
+					 domain_id, PROT_READ | PROT_WRITE,
+					 &mmap_pfn, &err, 1);
         if ( !ring_page )
         {
             PERROR("Could not map the ring page: %d\n", err);
tools/libxc/xg_private.h +1 -2
index 1910361..0baf403 100644
@@ -27,9 +27,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/libxenforeignmemory/Makefile new file +67 -0

67 lines not on this page · raw message

tools/libxenforeignmemory/compat.c new file +72 -0

72 lines not on this page · raw message

tools/libxenforeignmemory/core.c new file +65 -0

65 lines not on this page · raw message

tools/libxenforeignmemory/freebsd.c new file +126 -0

126 lines not on this page · raw message

tools/libxenforeignmemory/include/xenforeignmemory.h new file +68 -0

68 lines not on this page · raw message

tools/libxenforeignmemory/libxenforeignmemory.map new file +7 -0
new file mode 100644
index 0000000..11f0d2b
@@ -0,0 +1,7 @@
+VERS_1.0 {
+	global:
+		xenforeignmemory_open;
+		xenforeignmemory_close;
+		xenforeignmemory_map;
+	local: *; /* Do not expose anything by default */
+};
tools/libxenforeignmemory/linux.c new file +284 -0

284 lines not on this page · raw message

tools/libxenforeignmemory/minios.c new file +59 -0

59 lines not on this page · raw message

tools/libxenforeignmemory/netbsd.c new file +92 -0

92 lines not on this page · raw message

tools/libxenforeignmemory/private.h new file +47 -0

47 lines not on this page · raw message

tools/libxenforeignmemory/solaris.c new file +95 -0

95 lines not on this page · raw message

tools/libxl/libxl_internal.h +1 -0
index 4b59cad..101acb0 100644
@@ -50,6 +50,7 @@
 
 #include <xenevtchn.h>
 #include <xenstore.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 #include <xenguest.h>
 
tools/misc/xen-mfndump.c +1 -0
index ceeeaa9..1b22ad7 100644
@@ -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
index 9a201ee..1f5aba7 100644
@@ -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 +1 -1
index ee3e1d0..6750ee1 100644
@@ -5,6 +5,7 @@
  */
 
 #include <Python.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 #include <xenguest.h>
 #include <zlib.h>
@@ -17,7 +18,6 @@
 #include <netdb.h>
 #include <arpa/inet.h>
 
-#include "xenctrl.h"
 #include <xen/elfnote.h>
 #include <xen/tmem.h>
 #include "xc_dom.h"
tools/xenmon/xenbaked.c +1 -0
index 9e2a49b..ad77286 100644
@@ -39,6 +39,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
index 18699ec..0ea8680 100644
@@ -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
index a819a5b..8a05e98 100644
@@ -28,7 +28,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
index 6c12030..3cdd1a8 100644
@@ -26,6 +26,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
index 7f1e489..120fd64 100644
@@ -51,7 +51,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
index 2b01076..e0fa843 100644
@@ -20,6 +20,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
index 4ed120a..e647179 100644
@@ -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
index f66a77c..28c2b3c 100644
@@ -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
#24 lore raw

PATCH v2 15/15 HACK: Add a .config to pull all the right bits.

In reply to Ian Campbell
---
 .config | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100644 .config
.config new file +5 -0
new file mode 100644
index 0000000..c2eac60
@@ -0,0 +1,5 @@
+MINIOS_UPSTREAM_URL := git://xenbits.xen.org/people/ianc/mini-os.git
+MINIOS_UPSTREAM_REVISION := 134bad3e7d1ab2c93019813f607cc703ccef4661
+
+QEMU_TRADITIONAL_URL := git://xenbits.xen.org/people/ianc/qemu-xen-unstable.git
+QEMU_TRADITIONAL_REVISION := cdd8d90e3f631092dc81f5dd4b68f384c9ccf1cc
Signature · 1 line
2.1.4
#25 lore raw

PATCH v2 1/5 qemu-xen-traditional: Use xentoollog as a separate library

In reply to Ian Campbell

This has been split out of libxenctrl, so the build needs to be able to find the header and the library. QEMU does not use xtl_* itself so -rpath-link is sufficient to allow linking to libxenctrl.so (which links against libxentoollog).

---
 xen-hooks.mak | 2 ++
 1 file changed, 2 insertions(+)
xen-hooks.mak +2 -0
index bc7f1f1..2e53c04 100644
@@ -1,3 +1,4 @@
+CPPFLAGS+= -I$(XEN_ROOT)/tools/libxentoollog/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxc/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/xenstore/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/include
@@ -19,6 +20,7 @@ CFLAGS += $(CMDLINE_CFLAGS)
 
 LIBS += -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
 LIBS += -L$(XEN_ROOT)/tools/xenstore -lxenstore
+LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libxentoollog
 
 LDFLAGS := $(CFLAGS) $(LDFLAGS)
 
Signature · 1 line
2.1.4
#26 lore raw

PATCH v2 1/5 mini-os: Include libxentoollog with libxc

In reply to Ian Campbell

libxentoollog has just been split out from libxc. From mini-os's point of view we don't care about the distinction, so keep things simple by just including libxentoollog if libxc is enabled.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 2cb5e51..757bd70 100644
@@ -165,6 +165,7 @@ OBJS := $(filter-out $(OBJ_DIR)/lwip%.o $(LWO), $(OBJS))
 
 ifeq ($(libc),y)
 ifeq ($(CONFIG_XC),y)
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxentoollog-$(MINIOS_TARGET_ARCH) -whole-archive -lxentoollog -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH) -whole-archive -lxenguest -lxenctrl -no-whole-archive
 endif
 APP_LDLIBS += -lpci
Signature · 1 line
2.1.4
#27 lore raw

PATCH v2 2/5 qemu-xen-traditional: Use libxenevtchn

In reply to Ian Campbell

/dev/xen/evtchn related wrappers have been moved out of libxenctrl into their own library.

Note that i386-dm/helper2.c's xc_interface * was always really an xc_evtchn *, it's just they used to be typedefs to the same thing...

---
 hw/xen_backend.c  | 26 +++++++++++++-------------
 hw/xen_backend.h  |  2 +-
 hw/xen_common.h   |  1 +
 i386-dm/helper2.c | 19 ++++++++++---------
 xen-hooks.mak     |  2 ++
 5 files changed, 27 insertions(+), 23 deletions(-)
hw/xen_backend.c +13 -13
index 92b3506..40f6887 100644
@@ -208,19 +208,19 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
     xendev->debug      = debug;
     xendev->local_port = -1;
 
-    xendev->evtchndev = xc_evtchn_open(NULL, 0);
+    xendev->evtchndev = xenevtchn_open(NULL, 0);
     if (xendev->evtchndev == NULL) {
 	xen_be_printf(NULL, 0, "can't open evtchn device\n");
 	qemu_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 = xc_gnttab_open(NULL, 0);
 	if (xendev->gnttabdev == NULL) {
 	    xen_be_printf(NULL, 0, "can't open gnttab device\n");
-	    xc_evtchn_close(xendev->evtchndev);
+	    xenevtchn_close(xendev->evtchndev);
 	    qemu_free(xendev);
 	    return NULL;
 	}
@@ -268,7 +268,7 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
 	}
 
 	if (xendev->evtchndev != NULL)
-	    xc_evtchn_close(xendev->evtchndev);
+	    xenevtchn_close(xendev->evtchndev);
 	if (xendev->gnttabdev != NULL)
 	    xc_gnttab_close(xendev->gnttabdev);
 
@@ -630,13 +630,13 @@ 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);
@@ -683,14 +683,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;
 }
@@ -699,15 +699,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);
 }
 
 /*
hw/xen_backend.h +1 -1
index e421391..60f18f8 100644
@@ -44,7 +44,7 @@ struct XenDevice {
     int                remote_port;
     int                local_port;
 
-    xc_evtchn          *evtchndev;
+    xenevtchn_handle   *evtchndev;
     xc_gnttab          *gnttabdev;
 
     struct XenDevOps   *ops;
hw/xen_common.h +1 -0
index a615052..cee908f 100644
@@ -4,6 +4,7 @@
 #include <stddef.h>
 #include <inttypes.h>
 
+#include <xenevtchn.h>
 #include <xenctrl.h>
 #include <xenstore.h>
 #include <xen/io/xenbus.h>
i386-dm/helper2.c +10 -9
index 63a938b..e4df0d7 100644
@@ -48,6 +48,7 @@
 #include <limits.h>
 #include <fcntl.h>
 
+#include <xenevtchn.h>
 #include <xenctrl.h>
 #include <xen/hvm/ioreq.h>
 #include <xen/hvm/hvm_info_table.h>
@@ -104,7 +105,7 @@ buffered_iopage_t *buffered_io_page = NULL;
 QEMUTimer *buffered_io_timer;
 
 /* the evtchn fd for polling */
-xc_interface *xce_handle = NULL;
+xenevtchn_handle *xce_handle = NULL;
 
 /* which vcpu we are serving */
 int send_vcpu = 0;
@@ -141,7 +142,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
 
         cpu_single_env = env;
 
-        xce_handle = xc_evtchn_open(NULL, 0);
+        xce_handle = xenevtchn_open(NULL, 0);
         if (xce_handle == NULL) {
             perror("open");
             return NULL;
@@ -149,7 +150,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
 
         /* FIXME: how about if we overflow the page here? */
         for (i = 0; i < vcpus; i++) {
-            rc = xc_evtchn_bind_interdomain(
+            rc = xenevtchn_bind_interdomain(
                 xce_handle, domid, shared_page->vcpu_ioreq[i].vp_eport);
             if (rc == -1) {
                 fprintf(logfile, "bind interdomain ioctl error %d\n", errno);
@@ -164,7 +165,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
                     errno);
             return NULL;
         }
-        rc = xc_evtchn_bind_interdomain(xce_handle, domid, (uint32_t)bufioreq_evtchn);
+        rc = xenevtchn_bind_interdomain(xce_handle, domid, (uint32_t)bufioreq_evtchn);
         if (rc == -1) {
             fprintf(logfile, "bind interdomain ioctl error %d\n", errno);
             return NULL;
@@ -278,7 +279,7 @@ static ioreq_t *cpu_get_ioreq(void)
     int i;
     evtchn_port_t port;
 
-    port = xc_evtchn_pending(xce_handle);
+    port = xenevtchn_pending(xce_handle);
     if (port == bufioreq_local_port) {
         qemu_mod_timer(buffered_io_timer,
                 BUFFER_IO_MAX_DELAY + qemu_get_clock(rt_clock));
@@ -296,7 +297,7 @@ static ioreq_t *cpu_get_ioreq(void)
         }
 
         // unmask the wanted port again
-        xc_evtchn_unmask(xce_handle, port);
+        xenevtchn_unmask(xce_handle, port);
 
         //get the io packet from shared memory
         send_vcpu = i;
@@ -531,7 +532,7 @@ static void handle_buffered_io(void *opaque)
                 BUFFER_IO_MAX_DELAY + qemu_get_clock(rt_clock));
     } else {
         qemu_del_timer(buffered_io_timer);
-        xc_evtchn_unmask(xce_handle, bufioreq_local_port);
+        xenevtchn_unmask(xce_handle, bufioreq_local_port);
     }
 }
 
@@ -575,7 +576,7 @@ static void cpu_handle_ioreq(void *opaque)
 	}
 
         req->state = STATE_IORESP_READY;
-        xc_evtchn_notify(xce_handle, ioreq_local_port[send_vcpu]);
+        xenevtchn_notify(xce_handle, ioreq_local_port[send_vcpu]);
     }
 }
 
@@ -584,7 +585,7 @@ int xen_pause_requested;
 int main_loop(void)
 {
     CPUState *env = cpu_single_env;
-    int evtchn_fd = xce_handle == NULL ? -1 : xc_evtchn_fd(xce_handle);
+    int evtchn_fd = xce_handle == NULL ? -1 : xenevtchn_fd(xce_handle);
     char *qemu_file;
     fd_set fds;
 
xen-hooks.mak +2 -0
index 2e53c04..ec5fbab 100644
@@ -1,4 +1,5 @@
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxentoollog/include
+CPPFLAGS+= -I$(XEN_ROOT)/tools/libxenevtchn/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxc/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/xenstore/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/include
@@ -18,6 +19,7 @@ endif
 
 CFLAGS += $(CMDLINE_CFLAGS)
 
+LIBS += -L$(XEN_ROOT)/tools/libxenevtchn -lxenevtchn
 LIBS += -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
 LIBS += -L$(XEN_ROOT)/tools/xenstore -lxenstore
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libxentoollog
Signature · 1 line
2.1.4
#28 lore raw

PATCH v2 2/5 mini-os: Include libxenevtchn with libxc

In reply to Ian Campbell

libxenevtchn has just been split out from libxc. From mini-os's point of view we don't care about the distinction, so keep things simple by just including libxenevtchn if libxc is enabled.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 757bd70..66ed510 100644
@@ -166,6 +166,7 @@ OBJS := $(filter-out $(OBJ_DIR)/lwip%.o $(LWO), $(OBJS))
 ifeq ($(libc),y)
 ifeq ($(CONFIG_XC),y)
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxentoollog-$(MINIOS_TARGET_ARCH) -whole-archive -lxentoollog -no-whole-archive
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxenevtchn-$(MINIOS_TARGET_ARCH) -whole-archive -lxenevtchn -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH) -whole-archive -lxenguest -lxenctrl -no-whole-archive
 endif
 APP_LDLIBS += -lpci
Signature · 1 line
2.1.4
#29 lore raw

PATCH v2 3/5 qemu-xen-traditional: Use libxengnttab

In reply to Ian Campbell

/dev/xen/gntdev related wrappers have been moved out of libxenctrl into their own library.

---
 hw/xen_backend.c |  4 ++--
 hw/xen_backend.h |  2 +-
 hw/xen_common.h  |  1 +
 hw/xen_console.c |  4 ++--
 hw/xen_disk.c    | 24 ++++++++++++------------
 xen-hooks.mak    |  2 ++
 6 files changed, 20 insertions(+), 17 deletions(-)
hw/xen_backend.c +2 -2
index 40f6887..97d25da 100644
@@ -217,7 +217,7 @@ 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 = xc_gnttab_open(NULL, 0);
+	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);
@@ -270,7 +270,7 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
 	if (xendev->evtchndev != NULL)
 	    xenevtchn_close(xendev->evtchndev);
 	if (xendev->gnttabdev != NULL)
-	    xc_gnttab_close(xendev->gnttabdev);
+	    xengnttab_close(xendev->gnttabdev);
 
 	TAILQ_REMOVE(&xendevs, xendev, next);
 	qemu_free(xendev);
hw/xen_backend.h +1 -1
index 60f18f8..ba1e12f 100644
@@ -45,7 +45,7 @@ struct XenDevice {
     int                local_port;
 
     xenevtchn_handle   *evtchndev;
-    xc_gnttab          *gnttabdev;
+    xengnttab_handle          *gnttabdev;
 
     struct XenDevOps   *ops;
     TAILQ_ENTRY(XenDevice) next;
hw/xen_common.h +1 -0
index cee908f..cc48892 100644
@@ -5,6 +5,7 @@
 #include <inttypes.h>
 
 #include <xenevtchn.h>
+#include <xengnttab.h>
 #include <xenctrl.h>
 #include <xenstore.h>
 #include <xen/io/xenbus.h>
hw/xen_console.c +2 -2
index 80beb31..76c4e93 100644
@@ -230,7 +230,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);
     if (!con->sring)
@@ -263,7 +263,7 @@ static void con_disconnect(struct XenDevice *xendev)
         if (!xendev->gnttabdev)
 	    munmap(con->sring, XC_PAGE_SIZE);
         else
-            xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1);
+            xengnttab_munmap(xendev->gnttabdev, con->sring, 1);
 	con->sring = NULL;
     }
 }
hw/xen_disk.c +12 -12
index 250d806..6ccf073 100644
@@ -266,7 +266,7 @@ err:
 
 static void ioreq_unmap(struct ioreq *ioreq)
 {
-    xc_gnttab *gnt = ioreq->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
     int i;
 
     if (ioreq->v.niov == 0)
@@ -274,8 +274,8 @@ static void ioreq_unmap(struct ioreq *ioreq)
     if (batch_maps) {
 	if (!ioreq->pages)
 	    return;
-	if (xc_gnttab_munmap(gnt, ioreq->pages, ioreq->v.niov) != 0)
-	    xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
+	if (xengnttab_munmap(gnt, ioreq->pages, ioreq->v.niov) != 0)
+	    xen_be_printf(&ioreq->blkdev->xendev, 0, "xengnttab_munmap failed: %s\n",
 			  strerror(errno));
 	ioreq->blkdev->cnt_map -= ioreq->v.niov;
 	ioreq->pages = NULL;
@@ -283,8 +283,8 @@ static void ioreq_unmap(struct ioreq *ioreq)
 	for (i = 0; i < ioreq->v.niov; i++) {
 	    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_munmap(gnt, ioreq->page[i], 1) != 0)
+		xen_be_printf(&ioreq->blkdev->xendev, 0, "xengnttab_munmap failed: %s\n",
 			      strerror(errno));
 	    ioreq->blkdev->cnt_map--;
 	    ioreq->page[i] = NULL;
@@ -294,13 +294,13 @@ static void ioreq_unmap(struct ioreq *ioreq)
 
 static int ioreq_map(struct ioreq *ioreq)
 {
-    xc_gnttab *gnt = ioreq->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
     int i;
 
     if (ioreq->v.niov == 0)
         return 0;
     if (batch_maps) {
-	ioreq->pages = xc_gnttab_map_grant_refs
+	ioreq->pages = xengnttab_map_grant_refs
 	    (gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot);
 	if (ioreq->pages == NULL) {
 	    xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -314,7 +314,7 @@ static int ioreq_map(struct ioreq *ioreq)
 	ioreq->blkdev->cnt_map += ioreq->v.niov;
     } else  {
 	for (i = 0; i < ioreq->v.niov; i++) {
-	    ioreq->page[i] = xc_gnttab_map_grant_ref
+	    ioreq->page[i] = xengnttab_map_grant_ref
 		(gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot);
 	    if (ioreq->page[i] == NULL) {
 		xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -611,9 +611,9 @@ static void blk_alloc(struct XenDevice *xendev)
     blkdev->bh = qemu_bh_new(blk_bh, blkdev);
     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));
     }
 }
@@ -734,7 +734,7 @@ static int blk_connect(struct XenDevice *xendev)
             blkdev->protocol = BLKIF_PROTOCOL_X86_64;
     }
 
-    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);
@@ -787,7 +787,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_munmap(blkdev->xendev.gnttabdev, blkdev->sring, 1);
 	blkdev->cnt_map--;
 	blkdev->sring = NULL;
     }
xen-hooks.mak +2 -0
index ec5fbab..67f44ba 100644
@@ -1,5 +1,6 @@
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxentoollog/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxenevtchn/include
+CPPFLAGS+= -I$(XEN_ROOT)/tools/libxengnttab/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxc/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/xenstore/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/include
@@ -20,6 +21,7 @@ endif
 CFLAGS += $(CMDLINE_CFLAGS)
 
 LIBS += -L$(XEN_ROOT)/tools/libxenevtchn -lxenevtchn
+LIBS += -L$(XEN_ROOT)/tools/libxengnttab -lxengnttab
 LIBS += -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
 LIBS += -L$(XEN_ROOT)/tools/xenstore -lxenstore
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libxentoollog
Signature · 1 line
2.1.4
#30 lore raw

PATCH v2 3/5 mini-os: Include libxengnttab with libxc

In reply to Ian Campbell

libxengnttab has just been split out from libxc. From mini-os's point of view we don't care about the distinction, so keep things simple by just including libxengnttab if libxc is enabled.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 66ed510..5e67e6c 100644
@@ -167,6 +167,7 @@ ifeq ($(libc),y)
 ifeq ($(CONFIG_XC),y)
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxentoollog-$(MINIOS_TARGET_ARCH) -whole-archive -lxentoollog -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxenevtchn-$(MINIOS_TARGET_ARCH) -whole-archive -lxenevtchn -no-whole-archive
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxengnttab-$(MINIOS_TARGET_ARCH) -whole-archive -lxengnttab -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH) -whole-archive -lxenguest -lxenctrl -no-whole-archive
 endif
 APP_LDLIBS += -lpci
Signature · 1 line
2.1.4
#31 lore raw

PATCH v2 4/5 qemu-xen-traditional: Add libxencall to rpath-link

In reply to Ian Campbell

libxenctrl links against this library

---
 xen-hooks.mak | 1 +
 1 file changed, 1 insertion(+)
xen-hooks.mak +1 -0
index 67f44ba..42a72d8 100644
@@ -25,6 +25,7 @@ LIBS += -L$(XEN_ROOT)/tools/libxengnttab -lxengnttab
 LIBS += -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
 LIBS += -L$(XEN_ROOT)/tools/xenstore -lxenstore
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libxentoollog
+LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libxencall
 
 LDFLAGS := $(CFLAGS) $(LDFLAGS)
 
Signature · 1 line
2.1.4
#32 lore raw

PATCH v2 4/5 mini-os: Include libxencall with libxc

In reply to Ian Campbell

libxencall has just been split out from libxc. From mini-os's point of view we don't care about the distinction, so keep things simple by just including libxencall if libxc is enabled.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 5e67e6c..835c47b 100644
@@ -168,6 +168,7 @@ ifeq ($(CONFIG_XC),y)
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxentoollog-$(MINIOS_TARGET_ARCH) -whole-archive -lxentoollog -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxenevtchn-$(MINIOS_TARGET_ARCH) -whole-archive -lxenevtchn -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxengnttab-$(MINIOS_TARGET_ARCH) -whole-archive -lxengnttab -no-whole-archive
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxencall-$(MINIOS_TARGET_ARCH) -whole-archive -lxencall -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH) -whole-archive -lxenguest -lxenctrl -no-whole-archive
 endif
 APP_LDLIBS += -lpci
Signature · 1 line
2.1.4
#33 lore raw

PATCH v2 5/5 qemu-xen-traditional: Add libxenforeignmemory to rpath-link

In reply to Ian Campbell

libxenctrl links against this library.

Also, request the compat xc_map_foreign API from libxc.

---
 xen-hooks.mak | 2 ++
 1 file changed, 2 insertions(+)
xen-hooks.mak +2 -0
index 42a72d8..b6dfc4a 100644
@@ -1,6 +1,7 @@
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxentoollog/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxenevtchn/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxengnttab/include
+CPPFLAGS+= -DXC_WANT_COMPAT_MAP_FOREIGN_API
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libxc/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/xenstore/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/include
@@ -26,6 +27,7 @@ LIBS += -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
 LIBS += -L$(XEN_ROOT)/tools/xenstore -lxenstore
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libxentoollog
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libxencall
+LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libxenforeignmemory
 
 LDFLAGS := $(CFLAGS) $(LDFLAGS)
 
Signature · 1 line
2.1.4
#34 lore raw

PATCH v2 5/5 mini-os: Include libxenforeignmemory with libxc

In reply to Ian Campbell

libxenforeignmemory has just been split out from libxc. From mini-os's point of view we don't care about the distinction, so keep things simple by just including libxenforeignmemory if libxc is enabled.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 835c47b..f4e10c0 100644
@@ -169,6 +169,7 @@ APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxentoollog-$(MINIOS_TARGET_ARCH) -whole-a
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxenevtchn-$(MINIOS_TARGET_ARCH) -whole-archive -lxenevtchn -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxengnttab-$(MINIOS_TARGET_ARCH) -whole-archive -lxengnttab -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxencall-$(MINIOS_TARGET_ARCH) -whole-archive -lxencall -no-whole-archive
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxenforeignmemory-$(MINIOS_TARGET_ARCH) -whole-archive -lxenforeignmemory -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc-$(MINIOS_TARGET_ARCH) -whole-archive -lxenguest -lxenctrl -no-whole-archive
 endif
 APP_LDLIBS += -lpci
Signature · 1 line
2.1.4
#35 lore raw
In reply to Ian Campbell
Quoted 39 lines · Ian Campbell

(this is clearly not 4.6 material, aiming for 4.7)

In <[email protected]> I proposed stabilising some parts of the libxenctrl API/ABI by disaggregating into separate libraries.

After the previous proof of concept I have now split out:
* xentoollog
* evtch
* gntdev and gntshr
* hypercalls
* privileged foreign memory mappings

These represent the core low level functionality which everything else needs, I think, and so are moving things down into a layer below libxc (i.e. libxc uses all of these).

There are 3 series, against xen.git (15 patches), mini-os.git (5 patches) and qemu-xen-trad.git (5 patches). The patches against xen.git point to the patches in the other two trees via instructions to update the relevant Config.mk field. The perils of changing unstable interfaces!

NB: minios-devel will only get the mini-os side.

The code in for all three can be found in:
git://xenbits.xen.org/people/ianc/xen.git libxenctrl-split-v2
git://xenbits.xen.org/people/ianc/qemu-xen-unstable.git libxenctrl-split-v2
git://xenbits.xen.org/people/ianc/mini-os.git libxenctrl-split-v2

The tip of the xen.git branch contains an extra patch adding a .config into the tree which should get the correct things for the HEAD of the branch, but not further back.

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.

Quoted 5 lines

The new libraries use linker version-scripts to hopefully make future ABI changes be possible in a compatible way.

I'm stilling mulling over putting everything into tools/libs/FOO instead of tools/libxenFOO

On balance, +1. tools/ is already quite a mixed bag of stuff.

Quoted 3 lines

, I still haven't but I could if people think
it is worthwhile. Eventually I'd like to split libxc into libxenguest and libxenctrl to cut down on the amount of strange cross talk...

Very much +1.

FWIW, also splitting xl and libxl into different directories.

~Andrew

#36 lore raw
Quoted 5 lines · Andrew Cooper
Quoted 3 lines

I'm stilling mulling over putting everything into tools/libs/FOO instead of tools/libxenFOO

On balance, +1. tools/ is already quite a mixed bag of stuff.

OK, I think I'm going to go ahead with this.

Quoted 6 lines
Quoted 4 lines

, I still haven't but I could if people think
it is worthwhile. Eventually I'd like to split libxc into libxenguest
and libxenctrl to cut down on the amount of strange cross talk...

Very much +1.

OK (eventually ;-))

Quoted 1 line

FWIW, also splitting xl and libxl into different directories.

Yes, good idea (also "eventually ;-)").

While I'm accumulating TODO items in this thread, every library which gets split out needs a careful review before it should be declared A[PBI] stable. I'm thinking at least:

* Consistent error handling (return -1 + setting errno=EFOO)
* Correct types
* Const correctness
* General interface sanity check

Anything else?

Ian.

#37 lore raw
Quoted 8 lines · Ian Campbell
Quoted 2 lines

FWIW, also splitting xl and libxl into different directories.

Yes, good idea (also "eventually ;-)").

While I'm accumulating TODO items in this thread, every library which gets split out needs a careful review before it should be declared A[PBI] stable. I'm thinking at least:

Quoted 6 lines

* Consistent error handling (return -1 + setting errno=EFOO)
* Correct types
* Const correctness
* General interface sanity check

Anything else?

If we are filling even more copious free time,

* Thoughts about documentation in the header files.

I think a suitably-configured doxygen ought to suffice for this. (I feel like I am nominating myself to try and get this sorted in a satisfactory fashon.)

~Andrew

#38 lore raw
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Ian Campbell
Quoted 2 lines

FWIW, also splitting xl and libxl into different directories.

Yes, good idea (also "eventually ;-)").

While I'm accumulating TODO items in this thread, every library which
gets split out needs a careful review before it should be declared A[PBI] stable. I'm thinking at least:

* Consistent error handling (return -1 + setting errno=EFOO)
* Correct types
* Const correctness
* General interface sanity check

Quoted 5 lines
Quoted 1 line

Anything else?

If we are filling even more copious free time,

* Thoughts about documentation in the header files.

Yes, I think that would be good. As it happens the stuff being stripped out is from among the better documented bits of libxc. Surely not perfect though.

Quoted 3 lines

I think a suitably-configured doxygen ought to suffice for this. (I feel like I am nominating myself to try and get this sorted in a satisfactory fashon.)

I think this is rather secondary to accurate comments existing in the header in some form.

Perhaps rather than doing any work up front it would be better to point us to an existing example of something produced by what you consider a suitable-configured doxygen so we can see if we agree?

Ian.

#39 lore raw
In reply to Ian Campbell
Quoted 22 lines · Ian Campbell
Quoted 5 lines · Andrew Cooper
Quoted 3 lines

I'm stilling mulling over putting everything into tools/libs/FOO instead of tools/libxenFOO

On balance, +1. tools/ is already quite a mixed bag of stuff.

OK, I think I'm going to go ahead with this.

Quoted 6 lines
Quoted 4 lines

, I still haven't but I could if people think
it is worthwhile. Eventually I'd like to split libxc into libxenguest
and libxenctrl to cut down on the amount of strange cross talk...

Very much +1.

OK (eventually ;-))

Quoted 1 line

FWIW, also splitting xl and libxl into different directories.

Yes, good idea (also "eventually ;-)").

Quoted 8 lines

While I'm accumulating TODO items in this thread, every library which gets split out needs a careful review before it should be declared A[PBI] stable. I'm thinking at least:

* Consistent error handling (return -1 + setting errno=EFOO)
* Correct types
* Const correctness
* General interface sanity check

Explicit unmap operation to match the foreign map, rather than just using munmap (to allow valgrind hooks etc).

Ian.

#40 lore raw

Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

In reply to Ian Campbell

(dropping minios-devel)

Stefano,

Quoted 6 lines · Ian Campbell

There are 3 series, against xen.git (15 patches), mini-os.git (5 patches) and qemu-xen-trad.git (5 patches). The patches against xen.git point to the patches in the other two trees via instructions to update the relevant Config.mk field. The perils of changing unstable interfaces!

I started looking into making the appropriate changes to QEMU upstream to use the new libraries directly.

QEMU (in include/hw/xen/xen_common.h) includes compat shims for libxenctrl versions back as far as 3.3.0.

The main distinction is between pre-4.1.0 and 4.1.0 and later, since various handles switching from int's to opaque pointers at that point, meaning there are some typedefs and wrappers for things.

My plan was to rework the QEMU code to use only the new library function names for everything such that this becomes the default case (which makes sense given these libraries are intended to be long term stable) and to update the code in xen_common.h to bridge the gap to 4.6 and earlier.

But I'm having to jump through some hoops in order to support the pre-4.1.0 version of things. It's not impossible to support it, I'm sure, but things would be a lot easier if we could just drop that support code.

Can we consider dropping support for Xen 4.0 and earlier from upstream QEMU at this point?

Some data: Xen 4.0.0 was released in April 2010, the last point release was 4.0.4 in August 2012 and we no longer do security support for it (for a year or two now, I think).

Thanks,
Ian.

#41 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 31 lines · Ian Campbell

(dropping minios-devel)

Stefano,

Quoted 6 lines · Ian Campbell

There are 3 series, against xen.git (15 patches), mini-os.git (5 patches) and qemu-xen-trad.git (5 patches). The patches against xen.git point to the patches in the other two trees via instructions to update the relevant Config.mk field. The perils of changing unstable interfaces!

I started looking into making the appropriate changes to QEMU upstream to use the new libraries directly.

QEMU (in include/hw/xen/xen_common.h) includes compat shims for libxenctrl versions back as far as 3.3.0.

The main distinction is between pre-4.1.0 and 4.1.0 and later, since various handles switching from int's to opaque pointers at that point, meaning there are some typedefs and wrappers for things.

My plan was to rework the QEMU code to use only the new library function names for everything such that this becomes the default case (which makes sense given these libraries are intended to be long term stable) and to update the code in xen_common.h to bridge the gap to 4.6 and earlier.

But I'm having to jump through some hoops in order to support the pre-4.1.0 version of things. It's not impossible to support it, I'm sure, but things would be a lot easier if we could just drop that support code.

Quoted 6 lines

Can we consider dropping support for Xen 4.0 and earlier from upstream QEMU at this point?

Some data: Xen 4.0.0 was released in April 2010, the last point release was 4.0.4 in August 2012 and we no longer do security support for it (for a year or two now, I think).

The oldest Xen version I build-test for every pull request is Xen 4.0.0, I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be sent ahead of time to qemu-devel to see if anybody complains.

#42 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 4 lines · Stefano Stabellini

The oldest Xen version I build-test for every pull request is Xen 4.0.0, I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping 4.0, since 4.0.0 was the last one which used a plain int as a handle, anything older than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support and earlier was to turn the "int fd" for <=4.0 into a pointer by having the open wrapper do malloc(sizeof int) and the using wrappers do xc_foo(*handle).

This way all the different variants take pointers and we have less hoops to jump through to typedef everything in the correct way for each variant.

If you would rather avoid doing that then I think dropping 4.0.0 support would be the way to go and I'll send a mail to qemu-devel.

Ian.

#43 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 14 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini

The oldest Xen version I build-test for every pull request is Xen 4.0.0, I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping 4.0, since 4.0.0 was the last one which used a plain int as a handle, anything older than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support and earlier was to turn the "int fd" for <=4.0 into a pointer by having the open wrapper do malloc(sizeof int) and the using wrappers do xc_foo(*handle).

Quoted 5 lines

This way all the different variants take pointers and we have less hoops to jump through to typedef everything in the correct way for each variant.

If you would rather avoid doing that then I think dropping 4.0.0 support would be the way to go and I'll send a mail to qemu-devel.

Perhaps to help in killing the 4.0.0 support - Linux pvops can't work with Xen 4.0.0 - sadly I don't recall the details but I think it was missing an hypercall.

Quoted 7 lines

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#44 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 18 lines · Konrad Rzeszutek Wilk
Quoted 17 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini

The oldest Xen version I build-test for every pull request is Xen 4.0.0, I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping 4.0, since 4.0.0 was the last one which used a plain int as a handle, anything older than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support and earlier was to turn the "int fd" for <=4.0 into a pointer by having the open wrapper do malloc(sizeof int) and the using wrappers do xc_foo(*handle).

This way all the different variants take pointers and we have less hoops to jump through to typedef everything in the correct way for each variant.

Quoted 6 lines
Quoted 2 lines

If you would rather avoid doing that then I think dropping 4.0.0 support would be the way to go and I'll send a mail to qemu-devel.

Perhaps to help in killing the 4.0.0 support - Linux pvops can't work with Xen 4.0.0 - sadly I don't recall the details but I think it was missing an hypercall.

Are you sure? On the Xen developer summit this year I asked a guy from Amazon whether they are testing upstream pvops kernels on all Xen versions they support, and he confirmed that. And they do support Xen 4.0 and older.

Juergen

#45 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 19 lines · Juergen Gross
Quoted 18 lines · Konrad Rzeszutek Wilk
Quoted 17 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini

The oldest Xen version I build-test for every pull request is Xen 4.0.0, I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping 4.0, since 4.0.0 was the last one which used a plain int as a handle, anything older than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support and earlier was to turn the "int fd" for <=4.0 into a pointer by having the open wrapper do malloc(sizeof int) and the using wrappers do xc_foo(*handle).

This way all the different variants take pointers and we have less hoops to jump through to typedef everything in the correct way for each variant.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

If you would rather avoid doing that then I think dropping 4.0.0 support would be the way to go and I'll send a mail to qemu-devel.

Perhaps to help in killing the 4.0.0 support - Linux pvops can't work with Xen 4.0.0 - sadly I don't recall the details but I think it was missing an hypercall.

Are you sure? On the Xen developer summit this year I asked a guy from

And I am incorrect (from http://wiki.xen.org/wiki/Dom0_Kernels_for_Xen):

"Q: I've seen mentions of 'pv_ops' and 'xenlinux' kernels. Which one should I choose?

Simple answer: pv_ops. Xen Project 4.0 switched to using Linux pv_ops based dom0 kernel as a default.."

Quoted 3 lines

Amazon whether they are testing upstream pvops kernels on all Xen versions they support, and he confirmed that. And they do support Xen 4.0 and older.

Oh gosh, older than 4.0? Ugh.

Quoted 4 lines

Juergen

#46 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 42 lines · Konrad Rzeszutek Wilk
Quoted 32 lines · Juergen Gross
Quoted 31 lines · Konrad Rzeszutek Wilk
Quoted 29 lines · Ian Campbell
Quoted 6 lines · Stefano Stabellini

The oldest Xen version I build-test for every pull request is Xen 4.0.0,
I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be
sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping 4.0, since
4.0.0 was the last one which used a plain int as a handle, anything older
than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support and earlier
was to turn the "int fd" for <=4.0 into a pointer by having the open
wrapper do malloc(sizeof int) and the using wrappers do xc_foo(*handle).

This way all the different variants take pointers and we have less hoops to
jump through to typedef everything in the correct way for each variant.

If you would rather avoid doing that then I think dropping 4.0.0 support
would be the way to go and I'll send a mail to qemu-devel.

Quoted 6 lines
Quoted 4 lines

Perhaps to help in killing the 4.0.0 support - Linux pvops can't work with Xen 4.0.0 - sadly I don't recall the details but I think it was missing
an hypercall.

Are you sure? On the Xen developer summit this year I asked a guy from

And I am incorrect (from http://wiki.xen.org/wiki/Dom0_Kernels_for_Xen):

Quoted 7 lines

"Q: I've seen mentions of 'pv_ops' and 'xenlinux' kernels. Which
one
should I choose?

Simple answer: pv_ops. Xen Project 4.0 switched to using Linux
pv_ops
based dom0 kernel as a default.."

This contracts your hypothesis, it says that Xen 4.0 is expected to work with a pvops dom0 (or else we wouldn't have switched to it by default).

I think the cut off you are thinking of was a bit older, e.g. 3.4 or so.

Quoted 4 lines
Quoted 4 lines

Amazon whether they are testing upstream pvops kernels on all Xen versions they support, and he confirmed that. And they do support Xen 4.0 and older.

NB they presumably care about domU only for this testing, whereas whatever the incompatibility is it was to do with dom0 only, since domU interface has been stable since 3.0.

Ian.

#47 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

In reply to Ian Campbell
Quoted 14 lines · Ian Campbell
Quoted 4 lines · Stefano Stabellini

The oldest Xen version I build-test for every pull request is Xen 4.0.0, I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping 4.0, since 4.0.0 was the last one which used a plain int as a handle, anything older than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support and earlier was to turn the "int fd" for <=4.0 into a pointer by having the open wrapper do malloc(sizeof int) and the using wrappers do xc_foo(*handle).

Quoted 5 lines

This way all the different variants take pointers and we have less hoops to jump through to typedef everything in the correct way for each variant.

If you would rather avoid doing that then I think dropping 4.0.0 support would be the way to go and I'll send a mail to qemu-devel.

I would rather drop 4.0 support.

#48 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 3 lines · Stefano Stabellini
Quoted 2 lines · Ian Campbell
Quoted 1 line · Stefano Stabellini

The oldest Xen version I build-test for every pull request is Xen 4.0.0,

I setup a build trees for 4.0 thru 4.6 yesterday to test this, what a pain 4.1 and 4.0 are to build with a modern gcc! (Mostly newer compiler warnings and mostly, but not all, fixes which I could just backport from newer Xen, the exceptions were a couple of things which were removed before they needed to be fixed)

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines

I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping 4.0, since 4.0.0 was the last one which used a plain int as a handle, anything older than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support and earlier was to turn the "int fd" for <=4.0 into a pointer by having the open wrapper do malloc(sizeof int) and the using wrappers do xc_foo(*handle).

Quoted 7 lines
Quoted 5 lines

This way all the different variants take pointers and we have less hoops to jump through to typedef everything in the correct way for each variant.

If you would rather avoid doing that then I think dropping 4.0.0 support would be the way to go and I'll send a mail to qemu-devel.

I would rather drop 4.0 support.

Supporting 4.0 didn't turn out quite as ugly as I had feared.

So before I send an email to qemu-devel to propose dropping 4.0 what do you think of the following which handles the evtchn case, there is a similar patch for gnttab and a (yet to be written) patch for the foreign memory mapping case.

The relevant bit for this discussion is the 4.0.0 definition of xenevtchn_open in xen_common.h, the rest is just adjusting it to use the API of the new library (for reasons explained in the commit message).

commit d97f6bb5045685d766d85b8cd004ce007fe29120

Author: Ian Campbell <[email protected]>
Date:   Wed Sep 23 17:30:15 2015 +0100

xen: Switch to libxenevtchn interface for compat shims.

In 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.

Build tested with 4.1 and 4.5.

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.

hw/xen/xen_backend.c +15 -15
index b2cb22b..1fd8e01 100644
@@ -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,13 @@ 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);
@@ -742,14 +742,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;
 }
@@ -759,15 +759,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
index 3b4125e..a90314f 100644
@@ -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 +33 -10

67 lines not on this page · raw message

xen-hvm.c +12 -12
index 3a7fd58..54cbd72 100644
@@ -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;
 
@@ -709,7 +709,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));
@@ -728,7 +728,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;
@@ -1014,7 +1014,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);
     }
 }
 
@@ -1058,7 +1058,7 @@ 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]);
     }
 }
 
@@ -1066,8 +1066,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,
@@ -1105,7 +1105,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);
 }
 
@@ -1174,8 +1174,8 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
 
     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;
     }
@@ -1255,7 +1255,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
 
     /* 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);
@@ -1264,7 +1264,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
         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);
#49 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Il 24/09/2015 09:15, Ian Campbell ha scritto:

Quoted 21 lines · Stefano Stabellini
Quoted 3 lines · Ian Campbell
Quoted 2 lines · Stefano Stabellini
Quoted 1 line

The oldest Xen version I build-test for every pull request is Xen 4.0.0,

I setup a build trees for 4.0 thru 4.6 yesterday to test this, what a pain 4.1 and 4.0 are to build with a modern gcc! (Mostly newer compiler warnings and mostly, but not all, fixes which I could just backport from newer Xen, the exceptions were a couple of things which were removed before they needed to be fixed)

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines

I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping 4.0, since 4.0.0 was the last one which used a plain int as a handle, anything older than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support and earlier was to turn the "int fd" for <=4.0 into a pointer by having the open wrapper do malloc(sizeof int) and the using wrappers do xc_foo(*handle).

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

This way all the different variants take pointers and we have less hoops to jump through to typedef everything in the correct way for each variant.

If you would rather avoid doing that then I think dropping 4.0.0 support would be the way to go and I'll send a mail to qemu-devel.

I would rather drop 4.0 support.

Supporting 4.0 didn't turn out quite as ugly as I had feared.

Even if seems that major of distro use newer qemu version instead older with xen seems that keep updated also xen to latest stable version (or at least previous) and the cases where can uses next qemu version with very old xen I think is at least very rare. Another thing is that upstream qemu on older xen not had good support (at least for hvm domUs) and when I started to use it some years ago seems that was with too very few users.
There are also some problem, for example this:
http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=2e814a017155b885e4d4b5a88dc05e7367a9722a
without hvm domUs with emulated vga don't start with qemu>=1.4, applied to xen 4.3 and backported only in stable-4.2
Therefore excluded recent unexpected that I not know for a working support of hvm domUsat least xen 4.2 is needed.
In my cases I had saw good hvm domUs support with upstream qemu for production use only starting from xen 4.3.
I think is good know if older xen is really used with newer (more exactly next for these changes) qemu instead wasting time supporting and testing also many older xen versions.
In any cases thanks to all for any xen and qemu improvements.

Sorry for my bad english.

Quoted 326 lines

So before I send an email to qemu-devel to propose dropping 4.0 what do you think of the following which handles the evtchn case, there is a similar patch for gnttab and a (yet to be written) patch for the foreign memory mapping case.

The relevant bit for this discussion is the 4.0.0 definition of xenevtchn_open in xen_common.h, the rest is just adjusting it to use the API of the new library (for reasons explained in the commit message).

commit d97f6bb5045685d766d85b8cd004ce007fe29120

Author: Ian Campbell <[email protected]>
Date:   Wed Sep 23 17:30:15 2015 +0100

xen: Switch to libxenevtchn interface for compat shims.

In 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.

Build tested with 4.1 and 4.5.

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.

hw/xen/xen_backend.c +15 -15
index b2cb22b..1fd8e01 100644
@@ -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,13 @@ 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);
@@ -742,14 +742,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;
  }
@@ -759,15 +759,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
index 3b4125e..a90314f 100644
@@ -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 +33 -10
index 5923290..5700c1b 100644
@@ -39,17 +39,37 @@ static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
  #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
 
  typedef int XenXC;
-typedef int XenEvtchn;
+typedef int xenevtchn_handle;
  typedef int XenGnttab;
 
  #  define XC_INTERFACE_FMT "%i"
  #  define XC_HANDLER_INITIAL_VALUE    -1
 
-static inline XenEvtchn xen_xc_evtchn_open(void *logger,
-                                           unsigned int open_flags)
+static inline xenevtchn_handle *xenevtchn_open(void *logger,
+					       unsigned int open_flags)
+{
+    int *h = malloc(sizeof h);
+    if (!h)
+	return NULL;
+    *h = xc_evtchn_open();
+    if (*h == -1) {
+	 free(h);
+         h = NULL;
+    }
+    return h;
+}
+static inline int xenevtchn_close(xenevtchn_handle *h)
  {
-    return xc_evtchn_open();
+    int rc = xc_evtchn_close(*h);
+    free(h);
+    return rc;
  }
+#define xenevtchn_fd(h) xc_evtchn_fd(*h)
+#define xenevtchn_pending(h) xc_evtchn_pending(*h)
+#define xenevtchn_notify(h,p) xc_evtchn_notify(*h,p)
+#define xenevtchn_bind_interdomain(h,d,p) xc_evtchn_bind_interdomain(*h,d,p)
+#define xenevtchn_unmask(h,p) xc_evtchn_unmask(*h,p)
+#define xenevtchn_unbind(h,p) xc_evtchn_unmask(*h,p)
 
  static inline XenGnttab xen_xc_gnttab_open(void *logger,
                                             unsigned int open_flags)
@@ -108,17 +128,20 @@ static inline void xs_close(struct xs_handle *xsh)
  #else
 
  typedef xc_interface *XenXC;
-typedef xc_evtchn *XenEvtchn;
+typedef xc_evtchn xenevtchn_handle;
  typedef xc_gnttab *XenGnttab;
 
  #  define XC_INTERFACE_FMT "%p"
  #  define XC_HANDLER_INITIAL_VALUE    NULL
 
-static inline XenEvtchn xen_xc_evtchn_open(void *logger,
-                                           unsigned int open_flags)
-{
-    return xc_evtchn_open(logger, open_flags);
-}
+#define xenevtchn_open(l,f) xc_evtchn_open(l,f);
+#define xenevtchn_close(h) xc_evtchn_close(h)
+#define xenevtchn_fd(h) xc_evtchn_fd(h)
+#define xenevtchn_pending(h) xc_evtchn_pending(h)
+#define xenevtchn_notify(h,p) xc_evtchn_notify(h,p)
+#define xenevtchn_bind_interdomain(h,d,p) xc_evtchn_bind_interdomain(h,d,p)
+#define xenevtchn_unmask(h,p) xc_evtchn_unmask(h,p)
+#define xenevtchn_unbind(h,p) xc_evtchn_unbind(h,p)
 
  static inline XenGnttab xen_xc_gnttab_open(void *logger,
                                             unsigned int open_flags)
xen-hvm.c +12 -12
index 3a7fd58..54cbd72 100644
@@ -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;
 
@@ -709,7 +709,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));
@@ -728,7 +728,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;
@@ -1014,7 +1014,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);
      }
  }
 
@@ -1058,7 +1058,7 @@ 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]);
      }
  }
 
@@ -1066,8 +1066,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,
@@ -1105,7 +1105,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);
  }
 
@@ -1174,8 +1174,8 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
 
      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;
      }
@@ -1255,7 +1255,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
 
      /* 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);
@@ -1264,7 +1264,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
          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);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#50 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

In reply to Ian Campbell
Quoted 38 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
Quoted 2 lines · Ian Campbell
Quoted 1 line · Stefano Stabellini

The oldest Xen version I build-test for every pull request is Xen 4.0.0,

I setup a build trees for 4.0 thru 4.6 yesterday to test this, what a pain 4.1 and 4.0 are to build with a modern gcc! (Mostly newer compiler warnings and mostly, but not all, fixes which I could just backport from newer Xen, the exceptions were a couple of things which were removed before they needed to be fixed)

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines

I think it is very reasonable to remove anything older than that. I am OK with removing Xen 4.0.0 too, but I would like a warning to be sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping 4.0, since 4.0.0 was the last one which used a plain int as a handle, anything older than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support and earlier was to turn the "int fd" for <=4.0 into a pointer by having the open wrapper do malloc(sizeof int) and the using wrappers do xc_foo(*handle).

Quoted 7 lines
Quoted 5 lines

This way all the different variants take pointers and we have less hoops to jump through to typedef everything in the correct way for each variant.

If you would rather avoid doing that then I think dropping 4.0.0 support would be the way to go and I'll send a mail to qemu-devel.

I would rather drop 4.0 support.

Supporting 4.0 didn't turn out quite as ugly as I had feared.

So before I send an email to qemu-devel to propose dropping 4.0 what do you think of the following which handles the evtchn case, there is a similar patch for gnttab and a (yet to be written) patch for the foreign memory mapping case.

Quoted 4 lines

The relevant bit for this discussion is the 4.0.0 definition of xenevtchn_open in xen_common.h, the rest is just adjusting it to use the API of the new library (for reasons explained in the commit message).

I think that it is OK in principle.

Quoted 11 lines
include/hw/xen/xen_common.h +1 -1
index 5923290..5700c1b 100644
@@ -39,17 +39,37 @@ static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
 
 typedef int XenXC;
-typedef int XenEvtchn;
+typedef int xenevtchn_handle;
 typedef int XenGnttab;

...

include/hw/xen/xen_common.h static inline void xs_close(struct xs_handle *xsh) · line 133

Quoted 8 lines
include/hw/xen/xen_common.h +1 -1
@@ -108,17 +128,20 @@ static inline void xs_close(struct xs_handle *xsh)
 #else
 
 typedef xc_interface *XenXC;
-typedef xc_evtchn *XenEvtchn;
+typedef xc_evtchn xenevtchn_handle;
 typedef xc_gnttab *XenGnttab;
 

There is no reasons why we couldn't have a small compat shim on Xen > 4.6 too, so I would change the definition of XenEvtchn for newer versions of Xen and avoid some of the renaming in this patch to reduce the changes.

For example, why not define xc_evtchn_fd as xenevtchn_fd for Xen > 4.6? So that we don't need to go and rename all the call sites?

#51 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 94 lines · Stefano Stabellini
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
Quoted 2 lines · Ian Campbell
Quoted 1 line · Stefano Stabellini

The oldest Xen version I build-test for every pull request is

Xen 4.0.0,

Quoted 2 lines

I setup a build trees for 4.0 thru 4.6 yesterday to test this, what

a

Quoted 1 line

pain 4.1 and 4.0 are to build with a modern gcc! (Mostly newer

compiler

Quoted 5 lines

warnings and mostly, but not all, fixes which I could just backport from newer Xen, the exceptions were a couple of things which were removed before they needed to be fixed)

Quoted 1 line
Quoted 1 line
Quoted 1 line

I think it is very reasonable to remove anything older than

that.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

I am OK with removing Xen 4.0.0 too, but I would like a

warning to be

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping

4.0, since

Quoted 1 line
Quoted 1 line
Quoted 1 line

4.0.0 was the last one which used a plain int as a handle,

anything older

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support

and earlier

Quoted 1 line
Quoted 1 line
Quoted 1 line

was to turn the "int fd" for <=4.0 into a pointer by having the

open

Quoted 1 line
Quoted 1 line
Quoted 1 line

wrapper do malloc(sizeof int) and the using wrappers do

xc_foo(*handle).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

This way all the different variants take pointers and we have

less hoops to

Quoted 1 line
Quoted 1 line
Quoted 1 line

jump through to typedef everything in the correct way for each

variant.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If you would rather avoid doing that then I think dropping

4.0.0 support

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

would be the way to go and I'll send a mail to qemu-devel.

I would rather drop 4.0 support.

Supporting 4.0 didn't turn out quite as ugly as I had feared.

So before I send an email to qemu-devel to propose dropping 4.0

what do

Quoted 1 line

you think of the following which handles the evtchn case, there is

a

Quoted 5 lines

similar patch for gnttab and a (yet to be written) patch for the foreign memory mapping case.

The relevant bit for this discussion is the 4.0.0 definition of xenevtchn_open in xen_common.h, the rest is just adjusting it to

use

Quoted 2 lines

the API of the new library (for reasons explained in the commit message).

I think that it is OK in principle.

Review

Quoted 1 line
(quoted diff) +0 -0

b/include/hw/xen/xen_common.h

include/hw/xen/xen_common.h static inline void *xc_map_foreign_bulk(int

Quoted 4 lines

index 5923290..5700c1b 100644

include/hw/xen/xen_common.h +0 -0
@@ -39,17 +39,37 @@ static inline void *xc_map_foreign_bulk(int

xc_handle, uint32_t dom, int prot,

Quoted 6 lines
include/hw/xen/xen_common.h +1 -1
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
 
 typedef int XenXC;
-typedef int XenEvtchn;
+typedef int xenevtchn_handle;
 typedef int XenGnttab;

...

include/hw/xen/xen_common.h static inline void xs_close(struct xs_handle

Quoted 1 line
include/hw/xen/xen_common.h +0 -0
@@ -108,17 +128,20 @@ static inline void xs_close(struct xs_handle

*xsh)

include/hw/xen/xen_common.h static inline void xs_close(struct xs_handle *xsh) · line 133

Quoted 7 lines
include/hw/xen/xen_common.h +1 -1
 #else
 
 typedef xc_interface *XenXC;
-typedef xc_evtchn *XenEvtchn;
+typedef xc_evtchn xenevtchn_handle;
 typedef xc_gnttab *XenGnttab;
 

There is no reasons why we couldn't have a small compat shim on Xen > 4.6 too, so I would change the definition of XenEvtchn for newer versions of Xen and avoid some of the renaming in this patch to reduce the changes.

Quoted 2 lines

For example, why not define xc_evtchn_fd as xenevtchn_fd for Xen > 4.6? So that we don't need to go and rename all the call sites?

The idea was that the code would use the new stable API names from the stable libraries going forward, rather than using a shim to turn the stable APIs back into the old ones.

Ian.

#52 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 95 lines · Ian Campbell
Quoted 94 lines · Stefano Stabellini
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
Quoted 2 lines · Ian Campbell
Quoted 1 line · Stefano Stabellini

The oldest Xen version I build-test for every pull request is

Xen 4.0.0,

Quoted 2 lines

I setup a build trees for 4.0 thru 4.6 yesterday to test this, what

a

Quoted 1 line

pain 4.1 and 4.0 are to build with a modern gcc! (Mostly newer

compiler

Quoted 5 lines

warnings and mostly, but not all, fixes which I could just backport from newer Xen, the exceptions were a couple of things which were removed before they needed to be fixed)

Quoted 1 line
Quoted 1 line
Quoted 1 line

I think it is very reasonable to remove anything older than

that.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

I am OK with removing Xen 4.0.0 too, but I would like a

warning to be

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping

4.0, since

Quoted 1 line
Quoted 1 line
Quoted 1 line

4.0.0 was the last one which used a plain int as a handle,

anything older

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support

and earlier

Quoted 1 line
Quoted 1 line
Quoted 1 line

was to turn the "int fd" for <=4.0 into a pointer by having the

open

Quoted 1 line
Quoted 1 line
Quoted 1 line

wrapper do malloc(sizeof int) and the using wrappers do

xc_foo(*handle).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

This way all the different variants take pointers and we have

less hoops to

Quoted 1 line
Quoted 1 line
Quoted 1 line

jump through to typedef everything in the correct way for each

variant.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If you would rather avoid doing that then I think dropping

4.0.0 support

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

would be the way to go and I'll send a mail to qemu-devel.

I would rather drop 4.0 support.

Supporting 4.0 didn't turn out quite as ugly as I had feared.

So before I send an email to qemu-devel to propose dropping 4.0

what do

Quoted 1 line

you think of the following which handles the evtchn case, there is

a

Quoted 5 lines

similar patch for gnttab and a (yet to be written) patch for the foreign memory mapping case.

The relevant bit for this discussion is the 4.0.0 definition of xenevtchn_open in xen_common.h, the rest is just adjusting it to

use

Quoted 2 lines

the API of the new library (for reasons explained in the commit message).

I think that it is OK in principle.

Review

Quoted 1 line
(quoted diff) +0 -0

b/include/hw/xen/xen_common.h

include/hw/xen/xen_common.h static inline void *xc_map_foreign_bulk(int

Quoted 4 lines

index 5923290..5700c1b 100644

include/hw/xen/xen_common.h +0 -0
@@ -39,17 +39,37 @@ static inline void *xc_map_foreign_bulk(int

xc_handle, uint32_t dom, int prot,

Quoted 6 lines
include/hw/xen/xen_common.h +1 -1
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
 
 typedef int XenXC;
-typedef int XenEvtchn;
+typedef int xenevtchn_handle;
 typedef int XenGnttab;

...

include/hw/xen/xen_common.h static inline void xs_close(struct xs_handle

Quoted 1 line
include/hw/xen/xen_common.h +0 -0
@@ -108,17 +128,20 @@ static inline void xs_close(struct xs_handle

*xsh)

include/hw/xen/xen_common.h static inline void xs_close(struct xs_handle *xsh) · line 133

Quoted 7 lines
include/hw/xen/xen_common.h +1 -1
 #else
 
 typedef xc_interface *XenXC;
-typedef xc_evtchn *XenEvtchn;
+typedef xc_evtchn xenevtchn_handle;
 typedef xc_gnttab *XenGnttab;
 

There is no reasons why we couldn't have a small compat shim on Xen > 4.6 too, so I would change the definition of XenEvtchn for newer versions of Xen and avoid some of the renaming in this patch to reduce the changes.

Quoted 6 lines
Quoted 2 lines

For example, why not define xc_evtchn_fd as xenevtchn_fd for Xen > 4.6? So that we don't need to go and rename all the call sites?

The idea was that the code would use the new stable API names from the stable libraries going forward, rather than using a shim to turn the stable APIs back into the old ones.

I don't think that is very important from QEMU's point of view, using a shim is just fine, especially if it reduces the patch size to 5 lines of code :-)

#53 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 101 lines · Stefano Stabellini
Quoted 100 lines · Ian Campbell
Quoted 98 lines · Stefano Stabellini
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
Quoted 2 lines · Ian Campbell
Quoted 1 line · Stefano Stabellini

The oldest Xen version I build-test for every pull request is

Xen 4.0.0,

Quoted 2 lines

I setup a build trees for 4.0 thru 4.6 yesterday to test this, what

a

Quoted 1 line

pain 4.1 and 4.0 are to build with a modern gcc! (Mostly newer

compiler

Quoted 5 lines

warnings and mostly, but not all, fixes which I could just backport from newer Xen, the exceptions were a couple of things which were removed before they needed to be fixed)

Quoted 1 line
Quoted 1 line
Quoted 1 line

I think it is very reasonable to remove anything older than

that.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

I am OK with removing Xen 4.0.0 too, but I would like a

warning to be

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping

4.0, since

Quoted 1 line
Quoted 1 line
Quoted 1 line

4.0.0 was the last one which used a plain int as a handle,

anything older

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support

and earlier

Quoted 1 line
Quoted 1 line
Quoted 1 line

was to turn the "int fd" for <=4.0 into a pointer by having the

open

Quoted 1 line
Quoted 1 line
Quoted 1 line

wrapper do malloc(sizeof int) and the using wrappers do

xc_foo(*handle).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

This way all the different variants take pointers and we have

less hoops to

Quoted 1 line
Quoted 1 line
Quoted 1 line

jump through to typedef everything in the correct way for each

variant.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If you would rather avoid doing that then I think dropping

4.0.0 support

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

would be the way to go and I'll send a mail to qemu-devel.

I would rather drop 4.0 support.

Supporting 4.0 didn't turn out quite as ugly as I had feared.

So before I send an email to qemu-devel to propose dropping 4.0

what do

Quoted 1 line

you think of the following which handles the evtchn case, there is

a

Quoted 5 lines

similar patch for gnttab and a (yet to be written) patch for the foreign memory mapping case.

The relevant bit for this discussion is the 4.0.0 definition of xenevtchn_open in xen_common.h, the rest is just adjusting it to

use

Quoted 2 lines

the API of the new library (for reasons explained in the commit message).

I think that it is OK in principle.

Review

Quoted 1 line
(quoted diff) +0 -0

b/include/hw/xen/xen_common.h

include/hw/xen/xen_common.h static inline void *xc_map_foreign_bulk(int

Quoted 4 lines

index 5923290..5700c1b 100644

include/hw/xen/xen_common.h +0 -0
@@ -39,17 +39,37 @@ static inline void *xc_map_foreign_bulk(int

xc_handle, uint32_t dom, int prot,

Quoted 6 lines
include/hw/xen/xen_common.h +1 -1
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
 
 typedef int XenXC;
-typedef int XenEvtchn;
+typedef int xenevtchn_handle;
 typedef int XenGnttab;

...

include/hw/xen/xen_common.h static inline void xs_close(struct xs_handle

Quoted 1 line
include/hw/xen/xen_common.h +0 -0
@@ -108,17 +128,20 @@ static inline void xs_close(struct xs_handle

*xsh)

include/hw/xen/xen_common.h static inline void xs_close(struct xs_handle *xsh) · line 133

Quoted 7 lines
include/hw/xen/xen_common.h +1 -1
 #else
 
 typedef xc_interface *XenXC;
-typedef xc_evtchn *XenEvtchn;
+typedef xc_evtchn xenevtchn_handle;
 typedef xc_gnttab *XenGnttab;
 

There is no reasons why we couldn't have a small compat shim on Xen > 4.6 too, so I would change the definition of XenEvtchn for newer versions of Xen and avoid some of the renaming in this patch to reduce
the changes.

For example, why not define xc_evtchn_fd as xenevtchn_fd for Xen > 4.6?
So that we don't need to go and rename all the call sites?

Quoted 7 lines
Quoted 3 lines

The idea was that the code would use the new stable API names from the stable libraries going forward, rather than using a shim to turn the stable APIs back into the old ones.

I don't think that is very important from QEMU's point of view, using a shim is just fine, especially if it reduces the patch size to 5 lines of code :-)

Is patch size really the major consideration here? IMHO it is simply less confusing to have no shim (since one doesn't need to translate the names when reading differing code bases) and with time the shim layers can drop away leading to less complexity.

Also, I've already written all the patches, the renamings were very mechanical and at this point it would actually take me longer to undo them.

I'll do that if you insist, but I think the justification for sticking with a shim is very flimsy.

Ian.

#54 lore raw

Re: Oldest supported Xen version in upstream QEMU (Was: Re: [Minios-devel] [PATCH v2 0/15+5+5] Begin to disentangle libxenctrl and provide some stable libraries)

Quoted 115 lines · Ian Campbell
Quoted 101 lines · Stefano Stabellini
Quoted 100 lines · Ian Campbell
Quoted 98 lines · Stefano Stabellini
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Stefano Stabellini
Quoted 2 lines · Ian Campbell
Quoted 1 line · Stefano Stabellini

The oldest Xen version I build-test for every pull request is

Xen 4.0.0,

Quoted 2 lines

I setup a build trees for 4.0 thru 4.6 yesterday to test this, what

a

Quoted 1 line

pain 4.1 and 4.0 are to build with a modern gcc! (Mostly newer

compiler

Quoted 5 lines

warnings and mostly, but not all, fixes which I could just backport from newer Xen, the exceptions were a couple of things which were removed before they needed to be fixed)

Quoted 1 line
Quoted 1 line
Quoted 1 line

I think it is very reasonable to remove anything older than

that.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

I am OK with removing Xen 4.0.0 too, but I would like a

warning to be

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

sent ahead of time to qemu-devel to see if anybody complains.

There is not much point in removing <=3.4 support and keeping

4.0, since

Quoted 1 line
Quoted 1 line
Quoted 1 line

4.0.0 was the last one which used a plain int as a handle,

anything older

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

than 4.0.0 is trivial if 4.0.0 is supported.

One approach I am considering in order to keep 4.0.0 support

and earlier

Quoted 1 line
Quoted 1 line
Quoted 1 line

was to turn the "int fd" for <=4.0 into a pointer by having the

open

Quoted 1 line
Quoted 1 line
Quoted 1 line

wrapper do malloc(sizeof int) and the using wrappers do

xc_foo(*handle).

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

This way all the different variants take pointers and we have

less hoops to

Quoted 1 line
Quoted 1 line
Quoted 1 line

jump through to typedef everything in the correct way for each

variant.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If you would rather avoid doing that then I think dropping

4.0.0 support

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

would be the way to go and I'll send a mail to qemu-devel.

I would rather drop 4.0 support.

Supporting 4.0 didn't turn out quite as ugly as I had feared.

So before I send an email to qemu-devel to propose dropping 4.0

what do

Quoted 1 line

you think of the following which handles the evtchn case, there is

a

Quoted 5 lines

similar patch for gnttab and a (yet to be written) patch for the foreign memory mapping case.

The relevant bit for this discussion is the 4.0.0 definition of xenevtchn_open in xen_common.h, the rest is just adjusting it to

use

Quoted 2 lines

the API of the new library (for reasons explained in the commit message).

I think that it is OK in principle.

Review

Quoted 1 line
(quoted diff) +0 -0

b/include/hw/xen/xen_common.h

include/hw/xen/xen_common.h static inline void *xc_map_foreign_bulk(int

Quoted 4 lines

index 5923290..5700c1b 100644

include/hw/xen/xen_common.h +0 -0
@@ -39,17 +39,37 @@ static inline void *xc_map_foreign_bulk(int

xc_handle, uint32_t dom, int prot,

Quoted 6 lines
include/hw/xen/xen_common.h +1 -1
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 410
 
 typedef int XenXC;
-typedef int XenEvtchn;
+typedef int xenevtchn_handle;
 typedef int XenGnttab;

...

include/hw/xen/xen_common.h static inline void xs_close(struct xs_handle

Quoted 1 line
include/hw/xen/xen_common.h +0 -0
@@ -108,17 +128,20 @@ static inline void xs_close(struct xs_handle

*xsh)

include/hw/xen/xen_common.h static inline void xs_close(struct xs_handle *xsh) · line 133

Quoted 7 lines
include/hw/xen/xen_common.h +1 -1
 #else
 
 typedef xc_interface *XenXC;
-typedef xc_evtchn *XenEvtchn;
+typedef xc_evtchn xenevtchn_handle;
 typedef xc_gnttab *XenGnttab;
 

There is no reasons why we couldn't have a small compat shim on Xen > 4.6 too, so I would change the definition of XenEvtchn for newer versions of Xen and avoid some of the renaming in this patch to reduce
the changes.

For example, why not define xc_evtchn_fd as xenevtchn_fd for Xen > 4.6?
So that we don't need to go and rename all the call sites?

Quoted 7 lines
Quoted 3 lines

The idea was that the code would use the new stable API names from the stable libraries going forward, rather than using a shim to turn the stable APIs back into the old ones.

I don't think that is very important from QEMU's point of view, using a shim is just fine, especially if it reduces the patch size to 5 lines of code :-)

Is patch size really the major consideration here? IMHO it is simply less confusing to have no shim (since one doesn't need to translate the names when reading differing code bases) and with time the shim layers can drop away leading to less complexity.

Quoted 5 lines

Also, I've already written all the patches, the renamings were very mechanical and at this point it would actually take me longer to undo them.

I'll do that if you insist, but I think the justification for sticking with a shim is very flimsy.

I just don't think is important to use the new names in QEMU. Of course it is important to be consistent within the QEMU code base, but I don't think is necessary or required to be consistent with external code bases. The shim has worked very well in QEMU for years and I am quite happy to keep using it.

That said, there is nothing that screams "bished!" more than discussing the naming scheme of xc calls in QEMU, so I won't draw the line on this.

#55 lore raw
In reply to Ian Campbell

(dropping mini-os-devel and some cc's, adding David)

Hi David,

Quoted 6 lines · Ian Campbell

(this is clearly not 4.6 material, aiming for 4.7)

In <[email protected]> I proposed stabilising some parts of the libxenctrl API/ABI by disaggregating into separate libraries.

[...]

Quoted 2 lines

Still to come would be libraries for specific out of tree purposes (device model, kexec),

For kexec I have ("S" column is "interface to the left is stable A(BP)I"):

Interface S Underlying Interface S Other users
---------------------------------- - ------------------------------ - ---------------

`xc__hypercall_buffer_array_alloc`   Should use libxencall
`xc_hypercall_buffer_array_create`   Should use libxencall
`xc_hypercall_buffer_array_des...`   Should use libxencall
`xc_interface_close`
`xc_interface_open`
`xc_get_max_cpus`                  N `xc_physinfo=SYSCTL_physinfo`  N many
`xc_version`                       N `XENVER_capabilities`          Y libxl,others
`xc_get_machine_memory_map`        N `XENMEM_machine_memory_map`    Y libxl
`xc_kexec_exec`                    N `KEXEC_CMD_kexec`              Y None
`xc_kexec_get_range`               N `KEXEC_CMD_kexec_get_range`    Y None
`xc_kexec_load`                    N `KEXEC_CMD_kexec_load`         Y None
`xc_kexec_unload`                  N `KEXEC_CMD_kexec_unload`       Y None

It seems to me that there is not all that much utility to providing a stable libxenkexec containing those last four, and that they might as well be moved to kexec-tools where they can be implemented using the new libxencall (which also includes the buffer allocation stuff for the first 3).

What do you think?

That would just leave xc_get_max_cpus, xc_version and xc_get_machine_memory_map, which I'm still pondering.

Ian.