Skip to contentSkip to conversation

Begin to disentangle libxenctrl and provide some stable libraries

PATCH Superseded Ian Campbell 5 participants 88 messages Oct 7, 2015 – Oct 15, 2015

Subsystems (2)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

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

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

This is v3 of that set of series against:
xen
qemu-xen (new this time)
qemu-xen-traditional
mini-os

NB: minios-devel will only get the mini-os side and Stefano the qemu-xen side.

The code in for all repos can be found in:

git://xenbits.xen.org/people/ianc/libxenctrl-split/xen.git v3
git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen.git v3
git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen-traditional.git v3
git://xenbits.xen.org/people/ianc/libxenctrl-split/mini-os.git v3

(nb the repos have changed since last time, I've carried the v2 tags over as well)

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.

The new libraries here are:

* libxentoollog: Common logging infrastructure
* libxenevtchn: Userspace access to evtchns (via /dev/xen/evtchn etc)
* libxengnttab: Userspace access to grant tables (via /dev/xen/gnt??? etc)
* libxencall: Making hypercalls (i.e. the IOCTL_PRIVCMD_HYPERCALL type functionality)
* libxenforeignmemory: Privileged mappings of foreign memory (IOCTL_PRIVCMD_MMAP et al)

The first three were actually pretty distinct within libxenctrl already and have not changed in quite some time.

Although the other two are somewhat new they are based on top of long standing stable ioctls, which gives me some confidence.

Nonetheless I would appreciate extra review of at least the interface headers of all of these with a particular eye to the suitability of these interfaces being maintained in an ABI (_B_, not _P_) stable way going forward.

Still to come would be libraries for specific out of tree purposes (device model, kexec), which would be adding new library at the same level as libxc I think, rather than underneath, i.e. also using the libraries split out here, but hopefully not libxenctrl itself.

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

Since last time I have:

* Moved everything from tools/libxenfoo to tools/libs/foo
* Added patches to qemu-xen to use the new libraries instead of the compat layer. These can come any time after this transition and are not entangled (due to the compat layer being present in the meantime)
* Reviewed each of the new libraries for
* Error handling, Specifically no return -errno type stuff, but instead return -1 or NULL and setting errno if necessary
* Appropriate types (some discussion around that hasn't been folded in here yet)
* No inlines in the pubic headers (troublesome for ABI compatibility)
* Documentation, in that they all have some, not that it is necessarily comprehensive or complete (although it does look better than the average).
* Dropped
 and you
can find its history
* Fixed various issue.

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.

Ian.

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

#1 lore raw

Ian Campbell writes ("[PATCH v3 0/<VARIOUS>] Begin to disentangle libxenctrl and provide some stable libraries"):

Quoted 3 lines

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.

Wait, what ? .config is for the user's settings.

Ian.

#2 lore raw
Quoted 7 lines · Ian Jackson

Ian Campbell writes ("[PATCH v3 0/<VARIOUS>] Begin to disentangle libxenctrl and provide some stable libraries"):

Quoted 3 lines

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.

Wait, what ? .config is for the user's settings.

Right, this is a convenience for people wanting to play with this stuff, not something to be committed. Hence "extra patch" and the patch title being "HACK:...".

Ian.

#3 lore raw
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Ian Jackson

Ian Campbell writes ("[PATCH v3 0/<VARIOUS>] Begin to disentangle libxenctrl and provide some stable libraries"):

Quoted 4 lines

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.

Quoted 5 lines
Quoted 1 line

Wait, what ? .config is for the user's settings.

Right, this is a convenience for people wanting to play with this stuff, not something to be committed. Hence "extra patch" and the patch title being "HACK:...".

Or maybe your point was I should have patched Config.mk instead, which is probably true but I was lazy and just committed the file I was using.

Ian.

#4 lore raw

PATCH v3 1/22 tools/Rules.mk: Properly handle libraries with recursive dependencies.

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
Acked-by on v3 1/22
#5 lore raw

Re: [PATCH XEN v3 01/22] tools/Rules.mk: Properly handle libraries with recursive dependencies.

Ian Campbell writes ("[PATCH XEN v3 01/22] tools/Rules.mk: Properly handle libraries with recursive dependencies."):

Quoted 4 lines

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.

Quoted 8 lines

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.

...

Thanks.

tools/Rules.mk INSTALL_SHLIB = : install-shlib-unsupported-fail · line 49

Quoted 13 lines
tools/Rules.mk +13 -0
+# 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.

The first sentence seems slightly mangled.

You seem to have reinvented half of pkg-config. But it's small, so, with the docs fix,

(I have only skimread the detailed changes which seem quite formulaic. I'm content to commit this early in the 4.7 cycle and work out the bugs in-tree.)

Ian.

#6 lore raw

Re: [PATCH XEN v3 01/22] tools/Rules.mk: Properly handle libraries with recursive dependencies.

Quoted 18 lines · Ian Jackson

Ian Campbell writes ("[PATCH XEN v3 01/22] tools/Rules.mk: Properly handle libraries with recursive dependencies."):

Quoted 4 lines

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.

Quoted 8 lines

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.

...

Thanks.

Quoted 15 lines

tools/Rules.mk INSTALL_SHLIB = : install-shlib-unsupported-fail · line 49

Quoted 13 lines
tools/Rules.mk +13 -0
+# 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.

The first sentence seems slightly mangled.

Ah yes. I think I meant:

+# libbaz - whose use is entirely internal to libfoo but libfoo's

+#           public headers include one or more of libbaz's
+#           public headers. Users of libfoo are therefore transitively
+#           using libbaz's header but not linking against libbaz.

(dropping a stray "libbaz's" from the middle)

Quoted 4 lines

You seem to have reinvented half of pkg-config. But it's small, so, with the docs fix,

Thanks.

Probably we should look at shipping pkg-config files for these libraries, for the benefit of third parties. I'm not sure how well pkg-config can be made to work for in-tree users. I suppose it can be directed to examine some $PATH thing for .pc files, but I'm less sure about having it ignore system installed versions of things (i.e. older versions).

Ian.

#7 lore raw

PATCH v3 2/22 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
v3: Move into tools/libs/toollog.

---
 .gitignore                               |   1 +
 stubdom/Makefile                         |  24 +++-
 stubdom/grub/Makefile                    |   1 +
 tools/Makefile                           |   3 +
 tools/Rules.mk                           |  14 ++-
 tools/libs/Makefile                      |   7 ++
 tools/libs/toollog/Makefile              |  59 ++++++++++
 tools/libs/toollog/include/xentoollog.h  | 136 ++++++++++++++++++++++
 tools/libs/toollog/libxentoollog.map     |  12 ++
 tools/libs/toollog/xtl_core.c            |  83 +++++++++++++
 tools/libs/toollog/xtl_logger_stdio.c    | 192 +++++++++++++++++++++++++++++++
 tools/libxc/Makefile                     |   7 +-
 tools/libxc/include/xentoollog.h         | 136 ----------------------
 tools/libxc/xtl_core.c                   |  83 -------------
 tools/libxc/xtl_logger_stdio.c           | 192 -------------------------------
 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, 559 insertions(+), 447 deletions(-)
 create mode 100644 tools/libs/Makefile
 create mode 100644 tools/libs/toollog/Makefile
 create mode 100644 tools/libs/toollog/include/xentoollog.h
 create mode 100644 tools/libs/toollog/libxentoollog.map
 create mode 100644 tools/libs/toollog/xtl_core.c
 create mode 100644 tools/libs/toollog/xtl_logger_stdio.c
 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
.gitignore +1 -0
index 9ead7c4..74d0ab8 100644
@@ -59,6 +59,7 @@ stubdom/gcc-*
 stubdom/include
 stubdom/ioemu
 stubdom/xenstore
+stubdom/libxentoollog-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
stubdom/Makefile +23 -1
index e1359cf..9c923dd 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 libs-$(XEN_TARGET_ARCH)/toollog
+	[ -h libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/toollog && \
+	  ln -sf $(XEN_ROOT)/tools/libs/toollog/include/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/toollog/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/toollog/Makefile . )
 	mkdir -p 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: libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a
+libs-$(XEN_TARGET_ARCH)/toollog/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 libs-$(XEN_TARGET_ARCH)/toollog
+
+#######
 # 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)
@@ -515,6 +531,11 @@ clean:
 	$(MAKE) -C vtpmmgr clean
 	rm -fr grub-$(XEN_TARGET_ARCH)
 	rm -f $(STUBDOMPATH)
+	[ ! -e libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog clean
+	[ ! -e libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn clean
+	[ ! -e libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab clean
+	[ ! -e libs-$(XEN_TARGET_ARCH)/call/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call clean
+	[ ! -e libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory 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
@@ -525,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 libs-$(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..26dff45 100644
@@ -5,6 +5,7 @@ vpath %.c ../grub-upstream
 
 BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
 
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/toollog/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 2618559..8fcf8e9 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS-y :=
 SUBDIRS-y += include
+SUBDIRS-y += libs
 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/libs/toollog/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/libs/toollog \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +10 -4
index 28e84e6..65bf8f8 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/libs/toollog
 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/libs/Makefile new file +7 -0
new file mode 100644
index 0000000..73be500
@@ -0,0 +1,7 @@
+XEN_ROOT = $(CURDIR)/../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SUBDIRS-y :=
+SUBDIRS-y += toollog
+
+all clean install distclean: %: subdirs-%
tools/libs/toollog/Makefile new file +59 -0

59 lines not on this page · raw message

tools/libs/toollog/include/xentoollog.h new file +136 -0

136 lines not on this page · raw message

tools/libs/toollog/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/libs/toollog/xtl_core.c new file +83 -0

83 lines not on this page · raw message

tools/libs/toollog/xtl_logger_stdio.c new file +192 -0

192 lines not on this page · raw message

tools/libxc/Makefile +3 -4
index a0f899b..0e1794e 100644
@@ -39,8 +39,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 -136

136 lines not on this page · raw message

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

83 lines not on this page · raw message

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

192 lines not on this page · raw message

tools/libxl/Makefile +8 -7
index c5ecec1..7d12cdc 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)
@@ -149,7 +150,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.
 
@@ -253,19 +254,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..8ae0a78 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/libs/toollog/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..8c233c5 100755
@@ -3,7 +3,7 @@
 import sys
 
 def read_levels():
-	f = open('../../../libxc/include/xentoollog.h', 'r')
+	f = open('../../../libs/toollog/include/xentoollog.h', 'r')
 
 	levels = []
 	record = False
tools/python/setup.py +3 -2
index 5bf81be..473c56d 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/libs/toollog"
 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
#8 lore raw

Re: [PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library

Quoted 46 lines · Ian Campbell
tools/libs/toollog/Makefile new file +40 -0
new file mode 100644
index 0000000..bd12403
@@ -0,0 +1,59 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+MAJOR	= 1
+MINOR	= 0
+SHLIB_LDFLAGS += -Wl,--version-script=libxentoollog.map
+
+CFLAGS	+= -Werror -Wmissing-prototypes
+CFLAGS	+= -I./include
+
+SRCS-y	+= xtl_core.c
+SRCS-y	+= xtl_logger_stdio.c
+
+LIB_OBJS := $(patsubst %.c,%.o,$(SRCS-y))
+PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS-y))
+
+LIB := libxentoollog.a
+ifneq ($(nosharedlibs),y)
+LIB += libxentoollog.so
+endif
+
+.PHONY: all
+all: build
+
+.PHONY: build
+build:
+	$(MAKE) libs
+
+.PHONY: libs
+libs: $(LIB)
+
+libxentoollog.a: $(LIB_OBJS)
+	$(AR) rc $@ $^
+
+libxentoollog.so: libxentoollog.so.$(MAJOR)
+	$(SYMLINK_SHLIB) $< $@
+libxentoollog.so.$(MAJOR): libxentoollog.so.$(MAJOR).$(MINOR)
+	$(SYMLINK_SHLIB) $< $@
+
+libxentoollog.so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxentoollog.map

tools/libs/toollog/Makefile line 50

Quoted 10 lines
tools/libs/toollog/Makefile new file +10 -0
+	$(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxentoollog.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(APPEND_LDFLAGS)
+
+.PHONY: install
+install: build
+	$(INSTALL_DIR) $(DESTDIR)$(libdir)
+	$(INSTALL_DIR) $(DESTDIR)$(includedir)
+	$(INSTALL_SHLIB) libxentoollog.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
+	$(INSTALL_DATA) libxentoollog.a $(DESTDIR)$(libdir)
+	$(SYMLINK_SHLIB) libxentoollog.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxentoollog.so.$(MAJOR)
+	$(SYMLINK_SHLIB) libxentoollog.so.$(MAJOR) $(DESTDIR)$(libdir)/libxentoollog.so

Installation of all .so's needs to be conditional on $(nosharedlibs) to match the condition in the build rule.

~Andrew

#9 lore raw

Re: [PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library

Quoted 6 lines · Andrew Cooper
Quoted 6 lines

+.PHONY: install

tools/libs/toollog/Makefile new file +4 -0
+install: build
+	$(INSTALL_DIR) $(DESTDIR)$(libdir)
+	$(INSTALL_DIR) $(DESTDIR)$(includedir)
+	$(INSTALL_SHLIB) libxentoollog.so.$(MAJOR).$(MINOR)

$(DESTDIR)$(libdir)

Quoted 8 lines
Quoted 5 lines
(quoted diff) +2 -0
+	$(INSTALL_DATA) libxentoollog.a $(DESTDIR)$(libdir)
+	$(SYMLINK_SHLIB) libxentoollog.so.$(MAJOR).$(MINOR)

$(DESTDIR)$(libdir)/libxentoollog.so.$(MAJOR)

(quoted diff) +1 -0
+	$(SYMLINK_SHLIB) libxentoollog.so.$(MAJOR)

$(DESTDIR)$(libdir)/libxentoollog.so

Installation of all .so's needs to be conditional on $(nosharedlibs) to match the condition in the build rule.

This isn't true of any of the existing in tree things (e.g. the existing libxenctrl Makefile, the xenstore one etc).

I think because the nosharedlibs mode is specifically for stubdom (and rumpkernel?) and we do not (yet?) support install for builds of those types.

Ian.

#10 lore raw

Re: [PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library

Ian Campbell writes ("Re: [Xen-devel] [PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library"):

Quoted 1 line · Andrew Cooper

...

Quoted 9 lines
Quoted 2 lines

Installation of all .so's needs to be conditional on $(nosharedlibs) to match the condition in the build rule.

This isn't true of any of the existing in tree things (e.g. the existing libxenctrl Makefile, the xenstore one etc).

I think because the nosharedlibs mode is specifically for stubdom (and rumpkernel?) and we do not (yet?) support install for builds of those types.

Yes, I think so. Certainly when i introduced it in May 2014 it was only for libxc and libxenstore, and git log -S doesn't show commits causing other libraries to honour it.

Ian.

#11 lore raw

Re: [PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library

In reply to Ian Campbell

Ian Campbell writes ("[PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library"):

Quoted 13 lines

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.

Quoted 5 lines

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.

This patch looks plausible but it's hard to review because all of the code motion. Did you generate the series with git-format-patch -M ?

Ian.

#12 lore raw

Re: [PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library

Quoted 15 lines · Ian Jackson

Ian Campbell writes ("[PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library"):

Quoted 13 lines

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.

Quoted 8 lines
Quoted 5 lines

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.

This patch looks plausible but it's hard to review because all of the code motion. Did you generate the series with git-format-patch -M ?

Sorry I forgot when automating the sending of N series at a time.

In general this series doesn't really benefit from -M since only large chunks, but not entire files, are moving. This specific commit would benefit though and I've added -M to my script for next time.

In the meantime the -M version of this patch is below.

Ian.

Quoted 1 line

From bf4b39649d9efeaaf5436cd0c6b1a3fb658d87ef Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Mon, 8 Jun 2015 16:04:17 +0100
Subject: [PATCH] tools: Refactor "xentoollog" into its own library

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
v3: Move into tools/libs/toollog.

---
 .gitignore                                         |  1 +
 docs/misc/toolstack-library-abis.pandoc            | 36 +++++++------
 stubdom/Makefile                                   | 24 ++++++++-
 stubdom/grub/Makefile                              |  1 +
 tools/Makefile                                     |  3 ++
 tools/Rules.mk                                     | 14 +++--
 tools/libs/Makefile                                |  7 +++
 tools/libs/toollog/Makefile                        | 59 ++++++++++++++++++++++
 tools/{libxc => libs/toollog}/include/xentoollog.h |  0
 tools/libs/toollog/libxentoollog.map               | 12 +++++
 tools/{libxc => libs/toollog}/xtl_core.c           |  0
 tools/{libxc => libs/toollog}/xtl_logger_stdio.c   |  0
 tools/libxc/Makefile                               |  7 ++-
 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 +-
 19 files changed, 168 insertions(+), 52 deletions(-)
 create mode 100644 tools/libs/Makefile
 create mode 100644 tools/libs/toollog/Makefile
 rename tools/{libxc => libs/toollog}/include/xentoollog.h (100%)
 create mode 100644 tools/libs/toollog/libxentoollog.map
 rename tools/{libxc => libs/toollog}/xtl_core.c (100%)
 rename tools/{libxc => libs/toollog}/xtl_logger_stdio.c (100%)
.gitignore +1 -0
index 9ead7c4..74d0ab8 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 59e204e..659d69a 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 +23 -1
index e1359cf..9c923dd 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 libs-$(XEN_TARGET_ARCH)/toollog
+	[ -h libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/toollog && \
+	  ln -sf $(XEN_ROOT)/tools/libs/toollog/include/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/toollog/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/toollog/Makefile . )
 	mkdir -p 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: libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a
+libs-$(XEN_TARGET_ARCH)/toollog/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 libs-$(XEN_TARGET_ARCH)/toollog
+
+#######
 # 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)
@@ -515,6 +531,11 @@ clean:
 	$(MAKE) -C vtpmmgr clean
 	rm -fr grub-$(XEN_TARGET_ARCH)
 	rm -f $(STUBDOMPATH)
+	[ ! -e libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog clean
+	[ ! -e libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn clean
+	[ ! -e libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab clean
+	[ ! -e libs-$(XEN_TARGET_ARCH)/call/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call clean
+	[ ! -e libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory 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
@@ -525,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 libs-$(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..26dff45 100644
@@ -5,6 +5,7 @@ vpath %.c ../grub-upstream
 
 BOOT=$(OBJ_DIR)/boot-$(XEN_TARGET_ARCH).o
 
+DEF_CPPFLAGS += -I$(XEN_ROOT)/tools/libs/toollog/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 2618559..8fcf8e9 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS-y :=
 SUBDIRS-y += include
+SUBDIRS-y += libs
 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/libs/toollog/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/libs/toollog \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +10 -4
index 28e84e6..65bf8f8 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/libs/toollog
 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/libs/Makefile new file +7 -0
new file mode 100644
index 0000000..73be500
@@ -0,0 +1,7 @@
+XEN_ROOT = $(CURDIR)/../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SUBDIRS-y :=
+SUBDIRS-y += toollog
+
+all clean install distclean: %: subdirs-%
tools/libs/toollog/Makefile new file +59 -0

59 lines not on this page · raw message

tools/libs/toollog/include/xentoollog.h renamed from tools/libxc/include/xentoollog.h +0 -0
similarity index 100%
rename from tools/libxc/include/xentoollog.h
rename to tools/libs/toollog/include/xentoollog.h
tools/libs/toollog/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/libs/toollog/xtl_core.c renamed from tools/libxc/xtl_core.c +0 -0
similarity index 100%
rename from tools/libxc/xtl_core.c
rename to tools/libs/toollog/xtl_core.c
tools/libs/toollog/xtl_logger_stdio.c renamed from tools/libxc/xtl_logger_stdio.c +0 -0
similarity index 100%
rename from tools/libxc/xtl_logger_stdio.c
rename to tools/libs/toollog/xtl_logger_stdio.c
tools/libxc/Makefile +3 -4
index a0f899b..0e1794e 100644
@@ -39,8 +39,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/libxl/Makefile +8 -7
index c5ecec1..7d12cdc 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)
@@ -149,7 +150,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.
 
@@ -253,19 +254,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..8ae0a78 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/libs/toollog/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..8c233c5 100755
@@ -3,7 +3,7 @@
 import sys
 
 def read_levels():
-	f = open('../../../libxc/include/xentoollog.h', 'r')
+	f = open('../../../libs/toollog/include/xentoollog.h', 'r')
 
 	levels = []
 	record = False
tools/python/setup.py +3 -2
index 5bf81be..473c56d 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/libs/toollog"
 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
Acked-by
#13 lore raw

Re: [PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library

Ian Campbell writes ("Re: [PATCH XEN v3 02/22] tools: Refactor "xentoollog" into its own library"):

Quoted 5 lines

In general this series doesn't really benefit from -M since only large chunks, but not entire files, are moving. This specific commit would benefit though and I've added -M to my script for next time.

In the meantime the -M version of this patch is below.

Thanks,

#14 lore raw

PATCH v3 3/22 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 3bfa00b..4a71af3 100644
@@ -117,7 +117,7 @@
  */
 
 typedef struct xc_interface_core xc_interface;
-typedef struct xc_interface_core xc_evtchn;
+typedef struct xenevtchn_handle xc_evtchn;
 typedef struct xc_interface_core xc_gnttab;
 typedef struct xc_interface_core xc_gntshr;
 
tools/libxc/include/xenctrlosdep.h +0 -16
index 5121d9b..89564e1 100644
@@ -51,7 +51,6 @@
 
 enum xc_osdep_type {
     XC_OSDEP_PRIVCMD,
-    XC_OSDEP_EVTCHN,
     XC_OSDEP_GNTTAB,
     XC_OSDEP_GNTSHR,
 };
@@ -90,21 +89,6 @@ struct xc_osdep_ops
                                         int nentries);
         } privcmd;
         struct {
-            int (*fd)(xc_evtchn *xce, xc_osdep_handle h);
-
-            int (*notify)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port);
-
-            evtchn_port_or_error_t (*bind_unbound_port)(xc_evtchn *xce, xc_osdep_handle h, int domid);
-            evtchn_port_or_error_t (*bind_interdomain)(xc_evtchn *xce, xc_osdep_handle h, int domid,
-                                                       evtchn_port_t remote_port);
-            evtchn_port_or_error_t (*bind_virq)(xc_evtchn *xce, xc_osdep_handle h, unsigned int virq);
-
-            int (*unbind)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port);
-
-            evtchn_port_or_error_t (*pending)(xc_evtchn *xce, xc_osdep_handle h);
-            int (*unmask)(xc_evtchn *xce, xc_osdep_handle h, evtchn_port_t port);
-        } evtchn;
-        struct {
 #define XC_GRANT_MAP_SINGLE_DOMAIN 0x1
             void *(*grant_map)(xc_gnttab *xcg, xc_osdep_handle h,
                                uint32_t count, int flags, int prot,
tools/libxc/xc_evtchn.c +0 -45

51 lines not on this page · raw message

tools/libxc/xc_freebsd_osdep.c +26 -53

152 lines not on this page · raw message

tools/libxc/xc_linux_osdep.c +28 -48

155 lines not on this page · raw message

tools/libxc/xc_minios.c +24 -39

138 lines not on this page · raw message

tools/libxc/xc_netbsd.c +26 -46

141 lines not on this page · raw message

tools/libxc/xc_private.c +30 -7
index 7c39897..154e553 100644
@@ -119,7 +119,6 @@ static const char *xc_osdep_type_name(enum xc_osdep_type type)
     switch ( type )
     {
     case XC_OSDEP_PRIVCMD: return "privcmd";
-    case XC_OSDEP_EVTCHN:  return "evtchn";
     case XC_OSDEP_GNTTAB:  return "gnttab";
     case XC_OSDEP_GNTSHR:  return "gntshr";
     }
@@ -252,20 +251,44 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
     return xch->ops->u.privcmd.hypercall(xch, xch->ops_handle, hypercall);
 }
 
-xc_evtchn *xc_evtchn_open(xentoollog_logger *logger,
-                             unsigned open_flags)
+xc_evtchn *xc_evtchn_open(xentoollog_logger *logger, unsigned open_flags)
 {
-    xc_evtchn *xce;
+    xc_evtchn *xce = malloc(sizeof(*xce));
+    int rc;
+
+    if (!xce) return NULL;
+
+    xce->fd = -1;
+    xce->logger = logger;
+    xce->logger_tofree  = NULL;
 
-    xce = xc_interface_open_common(logger, NULL, open_flags,
-                                   XC_OSDEP_EVTCHN);
+    if (!xce->logger) {
+        xce->logger = xce->logger_tofree =
+            (xentoollog_logger*)
+            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
+        if (!xce->logger) goto err;
+    }
+
+    rc = osdep_evtchn_open(xce);
+    if ( rc  < 0 ) goto err;
 
     return xce;
+
+err:
+    osdep_evtchn_close(xce);
+    xtl_logger_destroy(xce->logger_tofree);
+    free(xce);
+    return NULL;
 }
 
 int xc_evtchn_close(xc_evtchn *xce)
 {
-    return xc_interface_close_common(xce);
+    int rc;
+
+    rc = osdep_evtchn_close(xce);
+    xtl_logger_destroy(xce->logger_tofree);
+    free(xce);
+    return rc;
 }
 
 xc_gnttab *xc_gnttab_open(xentoollog_logger *logger,
tools/libxc/xc_private.h +17 -0
index 2df1d59..a5bf79a 100644
@@ -123,6 +123,13 @@ struct xc_interface_core {
     xc_osdep_handle  ops_handle; /* opaque data for xc_osdep_ops */
 };
 
+struct xenevtchn_handle {
+    xentoollog_logger *logger, *logger_tofree;
+    int fd;
+};
+int osdep_evtchn_open(xc_evtchn *xce);
+int osdep_evtchn_close(xc_evtchn *xce);
+
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
@@ -446,3 +453,13 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
                          uint32_t *port);
 
 #endif /* __XC_PRIVATE_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libxc/xc_solaris.c +26 -45

145 lines not on this page · raw message

tools/libxc/xenctrl_osdep_ENOSYS.c +0 -87

99 lines not on this page · raw message

tools/ocaml/libs/eventchn/xeneventchn_stubs.c +2 -2
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
#15 lore raw

PATCH v3 4/22 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
v3: Moved to tools/libs/evtchn

---
 .gitignore                                    |   1 +
 stubdom/Makefile                              |  19 +-
 tools/Makefile                                |   5 +-
 tools/Rules.mk                                |  14 +-
 tools/console/Makefile                        |   2 +
 tools/console/daemon/io.c                     |  43 ++--
 tools/libs/Makefile                           |   1 +
 tools/libs/evtchn/Makefile                    |  65 +++++++
 tools/libs/evtchn/core.c                      |  69 +++++++
 tools/libs/evtchn/freebsd.c                   | 138 +++++++++++++
 tools/libs/evtchn/include/xenevtchn.h         | 150 ++++++++++++++
 tools/libs/evtchn/libxenevtchn.map            |  14 ++
 tools/libs/evtchn/linux.c                     | 136 +++++++++++++
 tools/libs/evtchn/minios.c                    | 269 ++++++++++++++++++++++++++
 tools/libs/evtchn/netbsd.c                    | 147 ++++++++++++++
 tools/libs/evtchn/private.h                   |  25 +++
 tools/libs/evtchn/solaris.c                   | 135 +++++++++++++
 tools/libs/toollog/include/xentoollog.h       |  10 +
 tools/libs/toollog/xtl_core.c                 |  10 +
 tools/libs/toollog/xtl_logger_stdio.c         |  10 +
 tools/libvchan/Makefile                       |   6 +-
 tools/libvchan/init.c                         |  20 +-
 tools/libvchan/io.c                           |  12 +-
 tools/libvchan/libxenvchan.h                  |   3 +-
 tools/libxc/Makefile                          |   8 +-
 tools/libxc/include/xenctrl.h                 |  99 +---------
 tools/libxc/include/xenctrl_compat.h          |  48 +++++
 tools/libxc/include/xenguest.h                |  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/libxl/Makefile                          |   5 +-
 tools/libxl/libxl.c                           |   2 +-
 tools/libxl/libxl_dom_suspend.c               |   4 +-
 tools/libxl/libxl_event.c                     |  14 +-
 tools/libxl/libxl_internal.h                  |   5 +-
 tools/misc/Makefile                           |   7 +-
 tools/misc/xen-hptool.c                       |  13 +-
 tools/misc/xen-lowmemd.c                      |  15 +-
 tools/ocaml/libs/eventchn/Makefile            |   4 +-
 tools/ocaml/libs/eventchn/xeneventchn_stubs.c |  20 +-
 tools/python/setup.py                         |   7 +-
 tools/tests/xen-access/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, 1513 insertions(+), 915 deletions(-)
 create mode 100644 tools/libs/evtchn/Makefile
 create mode 100644 tools/libs/evtchn/core.c
 create mode 100644 tools/libs/evtchn/freebsd.c
 create mode 100644 tools/libs/evtchn/include/xenevtchn.h
 create mode 100644 tools/libs/evtchn/libxenevtchn.map
 create mode 100644 tools/libs/evtchn/linux.c
 create mode 100644 tools/libs/evtchn/minios.c
 create mode 100644 tools/libs/evtchn/netbsd.c
 create mode 100644 tools/libs/evtchn/private.h
 create mode 100644 tools/libs/evtchn/solaris.c
 create mode 100644 tools/libxc/include/xenctrl_compat.h
 create mode 100644 tools/libxc/xc_evtchn_compat.c
.gitignore +1 -0
index 74d0ab8..5c76b6d 100644
@@ -60,6 +60,7 @@ stubdom/include
 stubdom/ioemu
 stubdom/xenstore
 stubdom/libxentoollog-*
+stubdom/libxenevtchn-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
stubdom/Makefile +18 -1
index 9c923dd..3b3bfc9 100644
@@ -318,6 +318,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libs/toollog/include/*.h . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/toollog/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/toollog/Makefile . )
+	mkdir -p libs-$(XEN_TARGET_ARCH)/evtchn/include
+	[ -h libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/evtchn && \
+	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/Makefile . )
 	mkdir -p libxc-$(XEN_TARGET_ARCH)
 	[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
 	  ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -352,12 +358,23 @@ libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog
 
 #######
+# libxenevtchn
+#######
+
+.PHONY: libxenevtchn
+libxenevtchn: libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a
+libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: $(NEWLIB_STAMPFILE)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
+	$(MAKE) DESTDIR= -C $(MINI_OS) links
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: 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 +4 -1
index 8fcf8e9..922f008 100644
@@ -248,8 +248,10 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		--libdir=$(LIBEXEC_LIB) \
 		--includedir=$(LIBEXEC_INC) \
 		--source-path=$$source \
-		--extra-cflags="-I$(XEN_ROOT)/tools/include \
+		--extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \
+		-I$(XEN_ROOT)/tools/include \
 		-I$(XEN_ROOT)/tools/libs/toollog/include \
+		-I$(XEN_ROOT)/tools/libs/evtchn/include \
 		-I$(XEN_ROOT)/tools/libxc/include \
 		-I$(XEN_ROOT)/tools/xenstore/include \
 		-I$(XEN_ROOT)/tools/xenstore/compat/include \
@@ -257,6 +259,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		--extra-ldflags="-L$(XEN_ROOT)/tools/libxc \
 		-L$(XEN_ROOT)/tools/xenstore \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +10 -4
index 65bf8f8..1ffe425 100644
@@ -11,6 +11,7 @@ INSTALL = $(XEN_ROOT)/tools/cross-install
 
 XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libs/toollog
+XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libs/evtchn
 XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
 XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
 XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
@@ -82,13 +83,18 @@ SHDEPS_libxentoollog =
 LDLIBS_libxentoollog = $(XEN_LIBXENTOOLLOG)/libxentoollog$(libextension)
 SHLIB_libxentoollog  = -Wl,-rpath-link=$(XEN_LIBXENTOOLLOG)
 
+CFLAGS_libxenevtchn = -I$(XEN_LIBXENEVTCHN)/include $(CFLAGS_xeninclude)
+SHDEPS_libxenevtchn =
+LDLIBS_libxenevtchn = $(XEN_LIBXENEVTCHN)/libxenevtchn$(libextension)
+SHLIB_libxenevtchn  = -Wl,-rpath-link=$(XEN_LIBXENEVTCHN)
+
 CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude)
-SHDEPS_libxenctrl = $(SHLIB_libxentoollog) 
+SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn)
 LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension)
 SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
 
-CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_xeninclude)
-SHDEPS_libxenguest =
+CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_xeninclude)
+SHDEPS_libxenguest = $(SHLIB_libxenevtchn)
 LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_LIBXC)/libxenguest$(libextension)
 SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=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 77e8f29..4b3a492 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/libs/Makefile +1 -0
index 73be500..0e3f523 100644
@@ -3,5 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS-y :=
 SUBDIRS-y += toollog
+SUBDIRS-y += evtchn
 
 all clean install distclean: %: subdirs-%
tools/libs/evtchn/Makefile new file +65 -0

65 lines not on this page · raw message

tools/libs/evtchn/core.c new file +69 -0

69 lines not on this page · raw message

tools/libs/evtchn/freebsd.c new file +138 -0

138 lines not on this page · raw message

tools/libs/evtchn/include/xenevtchn.h new file +150 -0

150 lines not on this page · raw message

tools/libs/evtchn/libxenevtchn.map new file +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/libs/evtchn/linux.c new file +136 -0

136 lines not on this page · raw message

tools/libs/evtchn/minios.c new file +269 -0

269 lines not on this page · raw message

tools/libs/evtchn/netbsd.c new file +147 -0

147 lines not on this page · raw message

tools/libs/evtchn/private.h new file +25 -0
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/libs/evtchn/solaris.c new file +135 -0

135 lines not on this page · raw message

tools/libs/toollog/include/xentoollog.h +10 -0
index 853e9c7..76f17fe 100644
@@ -134,3 +134,13 @@ const char *xtl_level_to_string(xentoollog_level); /* never fails */
 
 
 #endif /* XENTOOLLOG_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libs/toollog/xtl_core.c +10 -0
index c4724a0..099d2f3 100644
@@ -81,3 +81,13 @@ void xtl_logger_destroy(struct xentoollog_logger *logger) {
     if (!logger) return;
     logger->destroy(logger);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libs/toollog/xtl_logger_stdio.c +10 -0
index 0cd9206..f9c5bd8 100644
@@ -190,3 +190,13 @@ xentoollog_logger_stdiostream *xtl_createlogger_stdiostream
 
     return XTL_NEW_LOGGER(stdiostream, newlogger);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libvchan/Makefile +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 77be4e7..66cb103 100644
@@ -216,25 +216,25 @@ static int init_evt_srv(struct libxenvchan *ctrl, int domain, xentoollog_logger
 {
 	evtchn_port_or_error_t port;
 
-	ctrl->event = xc_evtchn_open(logger, 0);
+	ctrl->event = xenevtchn_open(logger, 0);
 	if (!ctrl->event)
 		return -1;
 
-	port = xc_evtchn_bind_unbound_port(ctrl->event, domain);
+	port = xenevtchn_bind_unbound_port(ctrl->event, domain);
 	if (port < 0)
 		goto fail;
 	ctrl->event_port = port;
 
-	if (xc_evtchn_unmask(ctrl->event, ctrl->event_port))
+	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
 		goto fail;
 
 	return 0;
 
 fail:
 	if (port >= 0)
-		xc_evtchn_unbind(ctrl->event, port);
+		xenevtchn_unbind(ctrl->event, port);
 
-	xc_evtchn_close(ctrl->event);
+	xenevtchn_close(ctrl->event);
 	ctrl->event = NULL;
 
 	return -1;
@@ -346,26 +346,26 @@ static int init_evt_cli(struct libxenvchan *ctrl, int domain, xentoollog_logger
 {
 	evtchn_port_or_error_t port;
 
-	ctrl->event = xc_evtchn_open(logger, 0);
+	ctrl->event = xenevtchn_open(logger, 0);
 	if (!ctrl->event)
 		return -1;
 
-	port = xc_evtchn_bind_interdomain(ctrl->event,
+	port = xenevtchn_bind_interdomain(ctrl->event,
 		domain, ctrl->event_port);
 	if (port < 0)
 		goto fail;
 	ctrl->event_port = port;
 
-	if (xc_evtchn_unmask(ctrl->event, ctrl->event_port))
+	if (xenevtchn_unmask(ctrl->event, ctrl->event_port))
 		goto fail;
 
 	return 0;
 
 fail:
 	if (port >= 0)
-		xc_evtchn_unbind(ctrl->event, port);
+		xenevtchn_unbind(ctrl->event, port);
 
-	xc_evtchn_close(ctrl->event);
+	xenevtchn_close(ctrl->event);
 	ctrl->event = NULL;
 
 	return -1;
tools/libvchan/io.c +6 -6
index 8a9629b..4461490 100644
@@ -105,7 +105,7 @@ static inline int send_notify(struct libxenvchan *ctrl, uint8_t bit)
 	notify = ctrl->is_server ? &ctrl->ring->srv_notify : &ctrl->ring->cli_notify;
 	prev = __sync_fetch_and_and(notify, ~bit);
 	if (prev & bit)
-		return xc_evtchn_notify(ctrl->event, ctrl->event_port);
+		return xenevtchn_notify(ctrl->event, ctrl->event_port);
 	else
 		return 0;
 }
@@ -194,10 +194,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;
 }
 
@@ -350,7 +350,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)
@@ -372,8 +372,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 0944a0e..1544378 100644
@@ -44,6 +44,7 @@
 
 #include <xen/io/libxenvchan.h>
 #include <xen/sys/evtchn.h>
+#include <xenevtchn.h>
 #include <xenctrl.h>
 
 struct libxenvchan_ring {
@@ -71,7 +72,7 @@ struct libxenvchan {
 	/* Pointer to shared ring page */
 	struct vchan_interface *ring;
 	/* event channel interface */
-	xc_evtchn *event;
+	xenevtchn_handle *event;
 	uint32_t event_port;
 	/* informative flags: are we acting as server? */
 	int is_server:1;
tools/libxc/Makefile +5 -3
index 0e1794e..b9bbd24 100644
@@ -48,6 +48,7 @@ CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
 CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
 CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
 CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
+CTRL_SRCS-y       += xc_evtchn_compat.c
 
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
@@ -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 1a1a185..5ee0d5b 100644
@@ -22,6 +22,8 @@
 #ifndef XENGUEST_H
 #define XENGUEST_H
 
+#include <xenevtchn.h>
+
 #define XC_NUMA_NO_NODE   (~0U)
 
 #define XCFLAGS_LIVE      (1 << 0)
@@ -253,18 +255,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
@@ -273,7 +275,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 154e553..c6876c3 100644
@@ -251,46 +251,6 @@ int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
     return xch->ops->u.privcmd.hypercall(xch, xch->ops_handle, hypercall);
 }
 
-xc_evtchn *xc_evtchn_open(xentoollog_logger *logger, unsigned open_flags)
-{
-    xc_evtchn *xce = malloc(sizeof(*xce));
-    int rc;
-
-    if (!xce) return NULL;
-
-    xce->fd = -1;
-    xce->logger = logger;
-    xce->logger_tofree  = NULL;
-
-    if (!xce->logger) {
-        xce->logger = xce->logger_tofree =
-            (xentoollog_logger*)
-            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
-        if (!xce->logger) goto err;
-    }
-
-    rc = osdep_evtchn_open(xce);
-    if ( rc  < 0 ) goto err;
-
-    return xce;
-
-err:
-    osdep_evtchn_close(xce);
-    xtl_logger_destroy(xce->logger_tofree);
-    free(xce);
-    return NULL;
-}
-
-int xc_evtchn_close(xc_evtchn *xce)
-{
-    int rc;
-
-    rc = osdep_evtchn_close(xce);
-    xtl_logger_destroy(xce->logger_tofree);
-    free(xce);
-    return rc;
-}
-
 xc_gnttab *xc_gnttab_open(xentoollog_logger *logger,
                              unsigned open_flags)
 {
tools/libxc/xc_private.h +0 -7
index a5bf79a..46e0e75 100644
@@ -123,13 +123,6 @@ struct xc_interface_core {
     xc_osdep_handle  ops_handle; /* opaque data for xc_osdep_ops */
 };
 
-struct xenevtchn_handle {
-    xentoollog_logger *logger, *logger_tofree;
-    int fd;
-};
-int osdep_evtchn_open(xc_evtchn *xce);
-int osdep_evtchn_close(xc_evtchn *xce);
-
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
tools/libxc/xc_solaris.c +0 -97

109 lines not on this page · raw message

tools/libxc/xc_suspend.c +10 -8
index bba36e7..8361c7b 100644
@@ -16,6 +16,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <xenevtchn.h>
+
 #include "xc_private.h"
 #include "xenguest.h"
 
@@ -124,12 +126,12 @@ static int unlock_suspend_event(xc_interface *xch, int domid, int *lockfd)
     return -1;
 }
 
-int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn)
+int xc_await_suspend(xc_interface *xch, xenevtchn_handle *xce, int suspend_evtchn)
 {
     int rc;
 
     do {
-        rc = xc_evtchn_pending(xce);
+        rc = xenevtchn_pending(xce);
         if (rc < 0) {
             ERROR("error polling suspend notification channel: %d", rc);
             return -1;
@@ -137,7 +139,7 @@ int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn)
     } while (rc != suspend_evtchn);
 
     /* harmless for one-off suspend */
-    if (xc_evtchn_unmask(xce, suspend_evtchn) < 0)
+    if (xenevtchn_unmask(xce, suspend_evtchn) < 0)
         ERROR("failed to unmask suspend notification channel: %d", rc);
 
     return 0;
@@ -145,16 +147,16 @@ int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn)
 
 /* Internal callers are allowed to call this with suspend_evtchn<0
  * but *lockfd>0. */
-int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_release(xc_interface *xch, xenevtchn_handle *xce,
                               int domid, int suspend_evtchn, int *lockfd)
 {
     if (suspend_evtchn >= 0)
-        xc_evtchn_unbind(xce, suspend_evtchn);
+        xenevtchn_unbind(xce, suspend_evtchn);
 
     return unlock_suspend_event(xch, domid, lockfd);
 }
 
-int xc_suspend_evtchn_init_sane(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_init_sane(xc_interface *xch, xenevtchn_handle *xce,
                                 int domid, int port, int *lockfd)
 {
     int rc, suspend_evtchn = -1;
@@ -164,7 +166,7 @@ int xc_suspend_evtchn_init_sane(xc_interface *xch, xc_evtchn *xce,
         goto cleanup;
     }
 
-    suspend_evtchn = xc_evtchn_bind_interdomain(xce, domid, port);
+    suspend_evtchn = xenevtchn_bind_interdomain(xce, domid, port);
     if (suspend_evtchn < 0) {
         ERROR("failed to bind suspend event channel: %d", suspend_evtchn);
         goto cleanup;
@@ -184,7 +186,7 @@ cleanup:
     return -1;
 }
 
-int xc_suspend_evtchn_init_exclusive(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_init_exclusive(xc_interface *xch, xenevtchn_handle *xce,
                                      int domid, int port, int *lockfd)
 {
     int suspend_evtchn;
tools/libxl/Makefile +3 -2
index 7d12cdc..23cfd6b 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)
@@ -159,7 +160,7 @@ $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
 $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenstore)
 
 SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o
-$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
+$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn)
 
 PKG_CONFIG = xenlight.pc xlutil.pc
 
tools/libxl/libxl.c +1 -1
index e4ea476..579d09a 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_suspend.c +2 -2
index 4cc01ad..a2e8d86 100644
@@ -107,9 +107,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 bfb6b31..2997160 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 c2413c2..6cef654 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>
@@ -440,7 +441,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;
 
@@ -914,7 +915,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);
     if (xch)
         xc_interface_close(xch);
     if (xs_handle)
@@ -94,7 +95,7 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-	xce_handle = xc_evtchn_open(NULL, 0);
+	xce_handle = xenevtchn_open(NULL, 0);
 	if (xce_handle == NULL)
     {
         perror("Failed to open evtchn device");
@@ -108,7 +109,7 @@ int main(int argc, char *argv[])
         return 3;
     }
 
-	if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_ENOMEM)) == -1)
+	if ((rc = xenevtchn_bind_virq(xce_handle, VIRQ_ENOMEM)) == -1)
     {
         perror("Failed to bind to domain exception virq port");
         return 4;
@@ -120,7 +121,7 @@ int main(int argc, char *argv[])
     {
         evtchn_port_t port;
 
-        if ((port = xc_evtchn_pending(xce_handle)) == -1)
+        if ((port = xenevtchn_pending(xce_handle)) == -1)
         {
             perror("Failed to listen for pending event channel");
             return 5;
@@ -134,7 +135,7 @@ int main(int argc, char *argv[])
             return 6;
         }
 
-        if (xc_evtchn_unmask(xce_handle, port) == -1)
+        if (xenevtchn_unmask(xce_handle, port) == -1)
         {
             perror("Failed to unmask port");
             return 7;
tools/ocaml/libs/eventchn/Makefile +2 -2
index 2d8d618..154efd4 100644
@@ -2,13 +2,13 @@ TOPLEVEL=$(CURDIR)/../..
 XEN_ROOT=$(TOPLEVEL)/../..
 include $(TOPLEVEL)/common.make
 
-CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude)
+CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_xeninclude)
 
 OBJS = xeneventchn
 INTF = $(foreach obj, $(OBJS),$(obj).cmi)
 LIBS = xeneventchn.cma xeneventchn.cmxa
 
[… more lines in the raw message]

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 473c56d..25085f0 100644

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

tools/tests/xen-access/xen-access.c +1 -1
index a52ca6e..f639860 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 20ea100..98056f2 100644

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

tools/xenmon/xenbaked.c +7 -6
index 1ddb29b..e4602ef 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 b5ffee6..df99c6a 100644

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

tools/xenpaging/xenpaging.h +2 -1
index c6ab77c..d0f8d20 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 25a548d..c8a5d52 100644

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

tools/xenstore/xenstored_domain.c +13 -12
index dcd6581..6ceec29 100644

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

tools/xentrace/Makefile +4 -1
index 6c13cd1..0157be2 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.

#16 lore raw

PATCH v3 5/22 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/libs/evtchn/Makefile  | 4 +++-
 tools/libs/toollog/Makefile | 5 ++++-
 4 files changed, 17 insertions(+), 2 deletions(-)
.gitignore +2 -0
index 5c76b6d..f1ecd29 100644
@@ -87,6 +87,8 @@ tools/config.cache
 config/Tools.mk
 config/Stubdom.mk
 config/Docs.mk
+tools/libs/toollog/headers.chk
+tools/libs/evtchn/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
tools/Rules.mk +8 -0
index 1ffe425..65a2344 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/libs/evtchn/Makefile +3 -1
index 85ed6dc..892892c 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/libs/toollog/Makefile +4 -1
index bd12403..72c70c9 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
#17 lore raw

PATCH v3 6/22 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          |  46 ++++++++++++++
 tools/libxc/xc_nognttab.c          |  50 ++++++++++++++++
 tools/libxc/xc_private.c           |  83 +++++++++++++++++++++-----
 tools/libxc/xc_private.h           |  24 ++++++++
 10 files changed, 274 insertions(+), 193 deletions(-)
 create mode 100644 tools/libxc/xc_nogntshr.c
 create mode 100644 tools/libxc/xc_nognttab.c
tools/libxc/Makefile +5 -5
index b9bbd24..4b9fe70 100644
@@ -43,11 +43,11 @@ CTRL_SRCS-y       += xc_resource.c
 CTRL_SRCS-$(CONFIG_X86) += xc_psr.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
-CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
-CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
-CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
-CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
-CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
+CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c xc_nognttab.c xc_nogntshr.c
+CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c xc_nognttab.c xc_nogntshr.c
+CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c
+CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c
+CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_nogntshr.c
 CTRL_SRCS-y       += xc_evtchn_compat.c
 
 GUEST_SRCS-y :=
tools/libxc/include/xenctrl.h +2 -2
index e4ec52d..3ea939f 100644
@@ -117,8 +117,8 @@
  */
 
 typedef struct xc_interface_core xc_interface;
-typedef struct xc_interface_core xc_gnttab;
-typedef struct xc_interface_core xc_gntshr;
+typedef struct xengntdev_handle xc_gnttab;
+typedef struct xengntdev_handle xc_gntshr;
 
 enum xc_error_code {
   XC_ERROR_NONE = 0,
tools/libxc/include/xenctrlosdep.h +0 -23
index 89564e1..423660d 100644
@@ -51,8 +51,6 @@
 
 enum xc_osdep_type {
     XC_OSDEP_PRIVCMD,
-    XC_OSDEP_GNTTAB,
-    XC_OSDEP_GNTSHR,
 };
 
 /* Opaque handle internal to the backend */
@@ -88,27 +86,6 @@ struct xc_osdep_ops
                                         size_t chunksize, privcmd_mmap_entry_t entries[],
                                         int nentries);
         } privcmd;
-        struct {
-#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1
-            void *(*grant_map)(xc_gnttab *xcg, xc_osdep_handle h,
-                               uint32_t count, int flags, int prot,
-                               uint32_t *domids, uint32_t *refs,
-                               uint32_t notify_offset,
-                               evtchn_port_t notify_port);
-            int (*munmap)(xc_gnttab *xcg, xc_osdep_handle h,
-                          void *start_address,
-                          uint32_t count);
-            int (*set_max_grants)(xc_gnttab *xcg, xc_osdep_handle h, uint32_t count);
-        } gnttab;
-        struct {
-            void *(*share_pages)(xc_gntshr *xcg, xc_osdep_handle h,
-                                 uint32_t domid, int count,
-                                 uint32_t *refs, int writable,
-                                 uint32_t notify_offset,
-                                 evtchn_port_t notify_port);
-            int (*munmap)(xc_gntshr *xcg, xc_osdep_handle h,
-                          void *start_address, uint32_t count);
-        } gntshr;
     } u;
 };
 typedef struct xc_osdep_ops xc_osdep_ops;
tools/libxc/xc_gnttab.c +13 -44

103 lines not on this page · raw message

tools/libxc/xc_linux_osdep.c +47 -72

235 lines not on this page · raw message

tools/libxc/xc_minios.c +19 -32

97 lines not on this page · raw message

tools/libxc/xc_nogntshr.c new file +46 -0

46 lines not on this page · raw message

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

50 lines not on this page · raw message

tools/libxc/xc_private.c +68 -15

106 lines not on this page · raw message

tools/libxc/xc_private.h +24 -0
index 46e0e75..1e9dc93 100644
@@ -123,6 +123,30 @@ struct xc_interface_core {
     xc_osdep_handle  ops_handle; /* opaque data for xc_osdep_ops */
 };
 
+struct xengntdev_handle {
+    xentoollog_logger *logger, *logger_tofree;
+    int fd;
+};
+
+int osdep_gnttab_open(xc_gnttab *xgt);
+int osdep_gnttab_close(xc_gnttab *xgt);
+
+#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1
+void *osdep_gnttab_grant_map(xc_gnttab *xgt,
+                             uint32_t count, int flags, int prot,
+                             uint32_t *domids, uint32_t *refs,
+                             uint32_t notify_offset,
+                             evtchn_port_t notify_port);
+
+int osdep_gntshr_open(xc_gntshr *xgs);
+int osdep_gntshr_close(xc_gntshr *xgs);
+
+void *osdep_gntshr_share_pages(xc_gntshr *xgs,
+                               uint32_t domid, int count,
+                               uint32_t *refs, int writable,
+                               uint32_t notify_offset,
+                               evtchn_port_t notify_port);
+
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
Signature · 1 line
2.1.4
#18 lore raw

PATCH v3 7/22 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.

v3:
- Remove SHLIB_libxenctrl from SHDEPS_libxenvchan, and replace with SHLIB_libxentoollog.
- Move to tools/libs/gnttab
- Adjust for rebase over 31cf2ca75181 "tools/libxc: linux: Don't use getpagesize() when unmapping the grants"

---
 .gitignore                            |   2 +
 stubdom/Makefile                      |  19 +-
 tools/Makefile                        |   3 +
 tools/Rules.mk                        |  14 +-
 tools/console/Makefile                |   5 +-
 tools/console/daemon/io.c             |  21 +--
 tools/libs/Makefile                   |   1 +
 tools/libs/evtchn/minios.c            |   5 +-
 tools/libs/gnttab/Makefile            |  69 +++++++
 tools/libs/gnttab/gntshr_core.c       |  92 ++++++++++
 tools/libs/gnttab/gntshr_unimp.c      |  62 +++++++
 tools/libs/gnttab/gnttab_core.c       | 121 +++++++++++++
 tools/libs/gnttab/gnttab_unimp.c      |  89 +++++++++
 tools/libs/gnttab/include/xengnttab.h | 218 ++++++++++++++++++++++
 tools/libs/gnttab/libxengnttab.map    |  23 +++
 tools/libs/gnttab/linux.c             | 329 ++++++++++++++++++++++++++++++++++
 tools/libs/gnttab/minios.c            | 117 ++++++++++++
 tools/libs/gnttab/private.h           |  47 +++++
 tools/libvchan/Makefile               |   8 +-
 tools/libvchan/init.c                 |  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             |  46 -----
 tools/libxc/xc_nognttab.c             |  50 ------
 tools/libxc/xc_private.c              |  80 ---------
 tools/libxc/xc_private.h              |  24 ---
 tools/xenstore/Makefile               |   4 +-
 tools/xenstore/xenstored_core.h       |   4 +-
 tools/xenstore/xenstored_domain.c     |  24 +--
 tools/xenstore/xenstored_minios.c     |   5 +-
 37 files changed, 1429 insertions(+), 839 deletions(-)
 create mode 100644 tools/libs/gnttab/Makefile
 create mode 100644 tools/libs/gnttab/gntshr_core.c
 create mode 100644 tools/libs/gnttab/gntshr_unimp.c
 create mode 100644 tools/libs/gnttab/gnttab_core.c
 create mode 100644 tools/libs/gnttab/gnttab_unimp.c
 create mode 100644 tools/libs/gnttab/include/xengnttab.h
 create mode 100644 tools/libs/gnttab/libxengnttab.map
 create mode 100644 tools/libs/gnttab/linux.c
 create mode 100644 tools/libs/gnttab/minios.c
 create mode 100644 tools/libs/gnttab/private.h
 create mode 100644 tools/libxc/xc_gnttab_compat.c
 delete mode 100644 tools/libxc/xc_nogntshr.c
 delete mode 100644 tools/libxc/xc_nognttab.c
.gitignore +2 -0
index f1ecd29..ca79cab 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/libs/toollog/headers.chk
 tools/libs/evtchn/headers.chk
+tools/libs/gnttab/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
stubdom/Makefile +18 -1
index 3b3bfc9..d4576eb 100644
@@ -324,6 +324,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/include/*.h include/ && \
 	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/Makefile . )
+	mkdir -p libs-$(XEN_TARGET_ARCH)/gnttab/include
+	[ -h libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/gnttab && \
+	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/Makefile . )
 	mkdir -p libxc-$(XEN_TARGET_ARCH)
 	[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
 	  ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -369,12 +375,23 @@ libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn
 
 #######
+# libxengnttab
+#######
+
+.PHONY: libxengnttab
+libxengnttab: libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a
+libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: $(NEWLIB_STAMPFILE)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
+	$(MAKE) DESTDIR= -C $(MINI_OS) links
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: 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 +3 -0
index 922f008..181045c 100644
@@ -249,9 +249,11 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		--includedir=$(LIBEXEC_INC) \
 		--source-path=$$source \
 		--extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \
+		-DXC_WANT_COMPAT_GNTTAB_API=1 \
 		-I$(XEN_ROOT)/tools/include \
 		-I$(XEN_ROOT)/tools/libs/toollog/include \
 		-I$(XEN_ROOT)/tools/libs/evtchn/include \
+		-I$(XEN_ROOT)/tools/libs/gnttab/include \
 		-I$(XEN_ROOT)/tools/libxc/include \
 		-I$(XEN_ROOT)/tools/xenstore/include \
 		-I$(XEN_ROOT)/tools/xenstore/compat/include \
@@ -260,6 +262,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-L$(XEN_ROOT)/tools/xenstore \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +12 -2
index 65a2344..2893c9f 100644
@@ -12,6 +12,7 @@ INSTALL = $(XEN_ROOT)/tools/cross-install
 XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libs/toollog
 XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libs/evtchn
+XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libs/gnttab
 XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
 XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
 XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
@@ -88,8 +89,17 @@ SHDEPS_libxenevtchn =
 LDLIBS_libxenevtchn = $(XEN_LIBXENEVTCHN)/libxenevtchn$(libextension)
 SHLIB_libxenevtchn  = -Wl,-rpath-link=$(XEN_LIBXENEVTCHN)
 
+CFLAGS_libxengnttab = -I$(XEN_LIBXENGNTTAB)/include $(CFLAGS_xeninclude)
+LDLIBS_libxengnttab = $(XEN_LIBXENGNTTAB)/libxengnttab$(libextension)
+SHLIB_libxengnttab  = -Wl,-rpath-link=$(XEN_LIBXENGNTTAB)
+
+# xengntshr_* interfaces are actually part of libxengnttab.so
+CFLAGS_libxengntshr = -I$(XEN_LIBXENGNTTAB)/include $(CFLAGS_xeninclude)
+LDLIBS_libxengntshr = $(XEN_LIBXENGNTTAB)/libxengnttab$(libextension)
+SHLIB_libxengntshr  = -Wl,-rpath-link=$(XEN_LIBXENGNTTAB)
+
 CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude)
-SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn)
+SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr)
 LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension)
 SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
 
@@ -109,7 +119,7 @@ LDLIBS_libxenstat  = $(SHDEPS_libxenstat) $(XEN_LIBXENSTAT)/libxenstat$(libexten
 SHLIB_libxenstat   = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_LIBXENSTAT)
 
 CFLAGS_libxenvchan = -I$(XEN_LIBVCHAN)
-SHDEPS_libxenvchan = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn)
+SHDEPS_libxenvchan = $(SHLIB_libxentoollog) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr)
 LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libextension)
 SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
 
tools/console/Makefile +2 -3
index 4b3a492..6eeac8f 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)
@@ -28,8 +26,9 @@ clean:
 .PHONY: distclean
 distclean: clean
 
+daemon/io.o: CFLAGS += $(CFLAGS_libxenevtchn) $(CFLAGS_libxengnttab)
 xenconsoled: $(patsubst %.c,%.o,$(wildcard daemon/*.c))
-	$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_xenconsoled) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_xenconsoled) $(APPEND_LDFLAGS)
 
 xenconsole: client/_paths.h $(patsubst %.c,%.o,$(wildcard client/*.c))
 	$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) $(LDLIBS_xenconsole) $(APPEND_LDFLAGS)
tools/console/daemon/io.c +11 -10
index 2f2e9c5..f265f4d 100644
@@ -22,6 +22,7 @@
 #include "utils.h"
 #include "io.h"
 #include <xenevtchn.h>
+#include <xengnttab.h>
 #include <xenstore.h>
 #include <xen/io/console.h>
 #include <xen/grant_table.h>
@@ -72,7 +73,7 @@ static int log_time_hv_needts = 1;
 static int log_time_guest_needts = 1;
 static int log_hv_fd = -1;
 
-static xc_gnttab *xcg_handle = NULL;
+static xengnttab_handle *xgt_handle = NULL;
 
 static struct pollfd  *fds;
 static unsigned int current_array_size;
@@ -520,8 +521,8 @@ static void domain_unmap_interface(struct domain *dom)
 {
 	if (dom->interface == NULL)
 		return;
-	if (xcg_handle && dom->ring_ref == -1)
-		xc_gnttab_munmap(xcg_handle, dom->interface, 1);
+	if (xgt_handle && dom->ring_ref == -1)
+		xengnttab_munmap(xgt_handle, dom->interface, 1);
 	else
 		munmap(dom->interface, XC_PAGE_SIZE);
 	dom->interface = NULL;
@@ -552,9 +553,9 @@ static int domain_create_ring(struct domain *dom)
 	if (ring_ref != dom->ring_ref && dom->ring_ref != -1)
 		domain_unmap_interface(dom);
 
-	if (!dom->interface && xcg_handle) {
+	if (!dom->interface && xgt_handle) {
 		/* Prefer using grant table */
-		dom->interface = xc_gnttab_map_grant_ref(xcg_handle,
+		dom->interface = xengnttab_map_grant_ref(xgt_handle,
 			dom->domid, GNTTAB_RESERVED_CONSOLE,
 			PROT_READ|PROT_WRITE);
 		dom->ring_ref = -1;
@@ -1029,8 +1030,8 @@ void handle_io(void)
 		handle_hv_logs(xce_handle, true);
 	}
 
-	xcg_handle = xc_gnttab_open(NULL, 0);
-	if (xcg_handle == NULL) {
+	xgt_handle = xengnttab_open(NULL, 0);
+	if (xgt_handle == NULL) {
 		dolog(LOG_DEBUG, "Failed to open xcg handle: %d (%s)",
 		      errno, strerror(errno));
 	}
@@ -1206,9 +1207,9 @@ void handle_io(void)
 		xenevtchn_close(xce_handle);
 		xce_handle = NULL;
 	}
-	if (xcg_handle != NULL) {
-		xc_gnttab_close(xcg_handle);
-		xcg_handle = NULL;
+	if (xgt_handle != NULL) {
+		xengnttab_close(xgt_handle);
+		xgt_handle = NULL;
 	}
 	log_hv_evtchn = -1;
 }
tools/libs/Makefile +1 -0
index 0e3f523..00156ae 100644
@@ -4,5 +4,6 @@ include $(XEN_ROOT)/tools/Rules.mk
 SUBDIRS-y :=
 SUBDIRS-y += toollog
 SUBDIRS-y += evtchn
+SUBDIRS-y += gnttab
 
 all clean install distclean: %: subdirs-%
tools/libs/evtchn/minios.c +1 -4
index fb913a2..b839cd0 100644
@@ -27,13 +27,12 @@
 #include <mini-os/events.h>
 #include <mini-os/wait.h>
 
-#include <sys/socket.h>
-
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <unistd.h>
 #include <inttypes.h>
 #include <malloc.h>
 
@@ -43,8 +42,6 @@ extern void minios_evtchn_close_fd(int fd);
 
 extern struct wait_queue_head event_queue;
 
-//void minios_evtchn_close_fd(int fd);
-
 /* XXX Note: This is not threadsafe */
 static struct evtchn_port_info* port_alloc(int fd) {
     struct evtchn_port_info *port_info;
tools/libs/gnttab/Makefile new file +69 -0

69 lines not on this page · raw message

tools/libs/gnttab/gntshr_core.c new file +92 -0

92 lines not on this page · raw message

tools/libs/gnttab/gntshr_unimp.c new file +62 -0

62 lines not on this page · raw message

tools/libs/gnttab/gnttab_core.c new file +121 -0

121 lines not on this page · raw message

tools/libs/gnttab/gnttab_unimp.c new file +89 -0

89 lines not on this page · raw message

tools/libs/gnttab/include/xengnttab.h new file +218 -0

218 lines not on this page · raw message

tools/libs/gnttab/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/libs/gnttab/linux.c new file +329 -0

329 lines not on this page · raw message

tools/libs/gnttab/minios.c new file +117 -0

117 lines not on this page · raw message

tools/libs/gnttab/private.h new file +47 -0

47 lines not on this page · raw message

tools/libvchan/Makefile +5 -3
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 66cb103..18cbbf4 100644
@@ -78,7 +78,7 @@ static int init_gnt_srv(struct libxenvchan *ctrl, int domain)
 	uint32_t ring_ref = -1;
 	void *ring;
 
-	ring = xc_gntshr_share_page_notify(ctrl->gntshr, domain,
+	ring = xengntshr_share_page_notify(ctrl->gntshr, domain,
 			&ring_ref, 1, offsetof(struct vchan_interface, srv_live),
 			ctrl->event_port);
 
@@ -104,7 +104,7 @@ static int init_gnt_srv(struct libxenvchan *ctrl, int domain)
 		ctrl->read.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
 		break;
 	default:
-		ctrl->read.buffer = xc_gntshr_share_pages(ctrl->gntshr, domain,
+		ctrl->read.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
 			pages_left, ctrl->ring->grants, 1);
 		if (!ctrl->read.buffer)
 			goto out_ring;
@@ -118,7 +118,7 @@ static int init_gnt_srv(struct libxenvchan *ctrl, int domain)
 		ctrl->write.buffer = ((void*)ctrl->ring) + LARGE_RING_OFFSET;
 		break;
 	default:
-		ctrl->write.buffer = xc_gntshr_share_pages(ctrl->gntshr, domain,
+		ctrl->write.buffer = xengntshr_share_pages(ctrl->gntshr, domain,
 			pages_right, ctrl->ring->grants + pages_left, 1);
 		if (!ctrl->write.buffer)
 			goto out_unmap_left;
@@ -128,9 +128,9 @@ out:
 	return ring_ref;
 out_unmap_left:
 	if (pages_left)
-		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left);
+		xengntshr_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;
@@ -142,7 +142,7 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
 	int rv = -1;
 	uint32_t *grants;
 
-	ctrl->ring = xc_gnttab_map_grant_ref_notify(ctrl->gnttab,
+	ctrl->ring = xengnttab_map_grant_ref_notify(ctrl->gnttab,
 		domain, ring_ref, PROT_READ|PROT_WRITE,
 		offsetof(struct vchan_interface, cli_live), ctrl->event_port);
 
@@ -172,7 +172,7 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
 	default:
 		{
 			int pages_left = 1 << (ctrl->write.order - PAGE_SHIFT);
-			ctrl->write.buffer = xc_gnttab_map_domain_grant_refs(ctrl->gnttab,
+			ctrl->write.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
 				pages_left, domain, grants, PROT_READ|PROT_WRITE);
 			if (!ctrl->write.buffer)
 				goto out_unmap_ring;
@@ -190,7 +190,7 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
 	default:
 		{
 			int pages_right = 1 << (ctrl->read.order - PAGE_SHIFT);
-			ctrl->read.buffer = xc_gnttab_map_domain_grant_refs(ctrl->gnttab,
+			ctrl->read.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
 				pages_right, domain, grants, PROT_READ);
 			if (!ctrl->read.buffer)
 				goto out_unmap_left;
@@ -202,10 +202,10 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
 	return rv;
  out_unmap_left:
 	if (ctrl->write.order >= PAGE_SHIFT)
-		xc_gnttab_munmap(ctrl->gnttab, ctrl->write.buffer,
+		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;
@@ -325,7 +325,7 @@ struct libxenvchan *libxenvchan_server_init(xentoollog_logger *logger, int domai
 		ctrl->write.order = LARGE_RING_SHIFT;
 	}
 
-	ctrl->gntshr = xc_gntshr_open(logger, 0);
+	ctrl->gntshr = xengntshr_open(logger, 0);
 	if (!ctrl->gntshr)
 		goto out;
 
@@ -413,7 +413,7 @@ struct libxenvchan *libxenvchan_client_init(xentoollog_logger *logger, int 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 4461490..bfffd73 100644
@@ -364,10 +364,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) {
@@ -377,10 +377,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 1544378..341c375 100644
@@ -45,7 +45,7 @@
 #include <xen/io/libxenvchan.h>
 #include <xen/sys/evtchn.h>
 #include <xenevtchn.h>
-#include <xenctrl.h>
+#include <xengnttab.h>
 
 struct libxenvchan_ring {
 	/* Pointer into the shared page. Offsets into buffer. */
@@ -66,8 +66,8 @@ struct libxenvchan_ring {
 struct libxenvchan {
 	/* Mapping handle for shared ring page */
 	union {
-		xc_gntshr *gntshr; /* for server */
-		xc_gnttab *gnttab; /* for client */
+		xengntshr_handle *gntshr; /* for server */
+		xengnttab_handle *gnttab; /* for client */
 	};
 	/* Pointer to shared ring page */
 	struct vchan_interface *ring;
tools/libxc/Makefile +9 -6
index 4b9fe70..6344629 100644
@@ -43,12 +43,13 @@ CTRL_SRCS-y       += xc_resource.c
 CTRL_SRCS-$(CONFIG_X86) += xc_psr.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
 CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
-CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c xc_nognttab.c xc_nogntshr.c
-CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c xc_nognttab.c xc_nogntshr.c
-CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c
-CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c xc_nognttab.c xc_nogntshr.c
-CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c xc_nogntshr.c
+CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
+CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
+CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
+CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
+CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
 CTRL_SRCS-y       += xc_evtchn_compat.c
+CTRL_SRCS-y       += xc_gnttab_compat.c
 
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
@@ -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 -46

46 lines not on this page · raw message

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

50 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 1e9dc93..46e0e75 100644
@@ -123,30 +123,6 @@ struct xc_interface_core {
     xc_osdep_handle  ops_handle; /* opaque data for xc_osdep_ops */
 };
 
-struct xengntdev_handle {
-    xentoollog_logger *logger, *logger_tofree;
-    int fd;
-};
-
-int osdep_gnttab_open(xc_gnttab *xgt);
-int osdep_gnttab_close(xc_gnttab *xgt);
-
-#define XC_GRANT_MAP_SINGLE_DOMAIN 0x1
-void *osdep_gnttab_grant_map(xc_gnttab *xgt,
-                             uint32_t count, int flags, int prot,
-                             uint32_t *domids, uint32_t *refs,
-                             uint32_t notify_offset,
-                             evtchn_port_t notify_port);
-
-int osdep_gntshr_open(xc_gntshr *xgs);
-int osdep_gntshr_close(xc_gntshr *xgs);
-
-void *osdep_gntshr_share_pages(xc_gntshr *xgs,
-                               uint32_t domid, int count,
-                               uint32_t *refs, int writable,
-                               uint32_t notify_offset,
-                               evtchn_port_t notify_port);
-
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
tools/xenstore/Makefile +3 -1
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 8c853c9..624737d 100644
@@ -20,12 +20,14 @@
 #define _XENSTORED_CORE_H
 
 #include <xenctrl.h>
+#include <xengnttab.h>
 
 #include <sys/types.h>
 #include <dirent.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <errno.h>
+
 #include "xenstore_lib.h"
 #include "list.h"
 #include "tdb.h"
@@ -196,7 +198,7 @@ void finish_daemonize(void);
 /* Open a pipe for signal handling */
 void init_pipe(int reopen_log_pipe[2]);
 
-xc_gnttab **xcg_handle;
+xengnttab_handle **xgt_handle;
 
 #endif /* _XENSTORED_CORE_H */
 
tools/xenstore/xenstored_domain.c +12 -12
index 6ceec29..25b8607 100644
@@ -34,7 +34,7 @@
 #include <xen/grant_table.h>
 
 static xc_interface **xc_handle;
-xc_gnttab **xcg_handle;
+xengnttab_handle **xgt_handle;
 static evtchn_port_t virq_port;
 
 xenevtchn_handle *xce_handle = NULL;
@@ -166,9 +166,9 @@ static int readchn(struct connection *conn, void *data, unsigned int len)
 
 static void *map_interface(domid_t domid, unsigned long mfn)
 {
-	if (*xcg_handle != NULL) {
+	if (*xgt_handle != NULL) {
 		/* this is the preferred method */
-		return xc_gnttab_map_grant_ref(*xcg_handle, domid,
+		return xengnttab_map_grant_ref(*xgt_handle, domid,
 			GNTTAB_RESERVED_XENSTORE, PROT_READ|PROT_WRITE);
 	} else {
 		return xc_map_foreign_range(*xc_handle, domid,
@@ -178,8 +178,8 @@ static void *map_interface(domid_t domid, unsigned long mfn)
 
 static void unmap_interface(void *interface)
 {
-	if (*xcg_handle != NULL)
-		xc_gnttab_munmap(*xcg_handle, interface, 1);
+	if (*xgt_handle != NULL)
+		xengnttab_munmap(*xgt_handle, interface, 1);
 	else
 		munmap(interface, XC_PAGE_SIZE);
 }
@@ -577,9 +577,9 @@ static int close_xc_handle(void *_handle)
 	return 0;
 }
 
-static int close_xcg_handle(void *_handle)
+static int close_xgt_handle(void *_handle)
 {
-	xc_gnttab_close(*(xc_gnttab **)_handle);
+	xengnttab_close(*(xengnttab_handle **)_handle);
 	return 0;
 }
 
@@ -634,15 +634,15 @@ void domain_init(void)
 
 	talloc_set_destructor(xc_handle, close_xc_handle);
 
-	xcg_handle = talloc(talloc_autofree_context(), xc_gnttab*);
-	if (!xcg_handle)
+	xgt_handle = talloc(talloc_autofree_context(), xengnttab_handle*);
+	if (!xgt_handle)
 		barf_perror("Failed to allocate domain gnttab handle");
 
-	*xcg_handle = xc_gnttab_open(NULL, 0);
-	if (*xcg_handle == NULL)
+	*xgt_handle = xengnttab_open(NULL, 0);
+	if (*xgt_handle == NULL)
 		xprintf("WARNING: Failed to open connection to gnttab\n");
 	else
-		talloc_set_destructor(xcg_handle, close_xcg_handle);
+		talloc_set_destructor(xgt_handle, close_xgt_handle);
 
 	xce_handle = xenevtchn_open(NULL, 0);
 
tools/xenstore/xenstored_minios.c +2 -3
index b686e1c..6ef1c46 100644
@@ -17,7 +17,6 @@
 */
 #include <sys/types.h>
 #include <sys/mman.h>
-#include <xenctrl.h>
 #include "xenstored_core.h"
 #include <xen/grant_table.h>
 
@@ -50,12 +49,12 @@ evtchn_port_t xenbus_evtchn(void)
 
 void *xenbus_map(void)
 {
-	return xc_gnttab_map_grant_ref(*xcg_handle, xenbus_master_domid(),
+	return xengnttab_map_grant_ref(*xgt_handle, xenbus_master_domid(),
 			GNTTAB_RESERVED_XENSTORE, PROT_READ|PROT_WRITE);
 }
 
 void unmap_xenbus(void *interface)
 {
-	xc_gnttab_munmap(*xcg_handle, interface, 1);
+	xengnttab_munmap(*xgt_handle, interface, 1);
 }
 
Signature · 1 line
2.1.4
#19 lore raw

PATCH v3 8/22 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 -
 tools/libxc/Makefile                |  27 ++----
 tools/libxc/include/xenctrl.h       |   9 --
 tools/libxc/include/xenctrlosdep.h  | 133 ---------------------------
 tools/libxc/xc_foreign_memory.c     |  31 +------
 tools/libxc/xc_freebsd_osdep.c      | 100 ++++++---------------
 tools/libxc/xc_hcall_buf.c          |   6 +-
 tools/libxc/xc_linux_osdep.c        |  88 ++++++------------
 tools/libxc/xc_minios.c             |  82 +++++------------
 tools/libxc/xc_netbsd.c             |  90 +++++++------------
 tools/libxc/xc_private.c            | 174 ++----------------------------------
 tools/libxc/xc_private.h            |  19 ++--
 tools/libxc/xc_solaris.c            |  90 +++++++------------
 tools/libxc/xenctrl_osdep_ENOSYS.c  | 123 -------------------------
 tools/ocaml/libs/xc/xenctrl.ml      |   2 -
 tools/ocaml/libs/xc/xenctrl.mli     |   1 -
 tools/ocaml/libs/xc/xenctrl_stubs.c |   7 --
 tools/ocaml/xenstored/domains.ml    |   6 +-
 tools/ocaml/xenstored/xenstored.ml  |   5 +-
 23 files changed, 178 insertions(+), 823 deletions(-)
 delete mode 100644 tools/libxc/include/xenctrlosdep.h
 delete mode 100644 tools/libxc/xenctrl_osdep_ENOSYS.c
config/FreeBSD.mk +0 -2
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
tools/libxc/Makefile +7 -20
index 6344629..51dc16c 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 360d677..0c6b36b 100644
@@ -181,15 +181,6 @@ enum xc_open_flags {
  */
 int xc_interface_close(xc_interface *xch);
 
-/**
- * Query the active OS interface (i.e. that which would be returned by
- * xc_interface_open) to find out if it is fake (i.e. backends onto
- * something other than an actual Xen hypervisor).
- *
- * @return 0 is "real", >0 if fake, -1 on error.
- */
-int xc_interface_is_fake(void);
-
 /*
  * HYPERCALL SAFE MEMORY BUFFER
  *
tools/libxc/include/xenctrlosdep.h deleted +0 -133

133 lines not on this page · raw message

tools/libxc/xc_foreign_memory.c +1 -30
index f42d140..9c705b6 100644
@@ -50,37 +50,8 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
     return res;
 }
 
-void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
-                           int size, int prot, unsigned long mfn)
-{
-    return xch->ops->u.privcmd.map_foreign_range(xch, xch->ops_handle,
-                                                 dom, size, prot, mfn);
-}
-
-void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
-                            size_t size, int prot, size_t chunksize,
-                            privcmd_mmap_entry_t entries[], int nentries)
-{
-    return xch->ops->u.privcmd.map_foreign_ranges(xch, xch->ops_handle,
-                                                  dom, size, prot, chunksize, entries, nentries);
-}
-
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
-{
-    return xch->ops->u.privcmd.map_foreign_batch(xch, xch->ops_handle,
-                                                 dom, prot, arr, num);
-}
-
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err, unsigned int num)
-{
-    return xch->ops->u.privcmd.map_foreign_bulk(xch, xch->ops_handle,
-                                                dom, prot, arr, err, num);
-}
-
 /* stub for all not yet converted OSes */
-void *xc_map_foreign_bulk_compat(xc_interface *xch, xc_osdep_handle h,
+void *xc_map_foreign_bulk_compat(xc_interface *xch,
                                  uint32_t dom, int prot,
                                  const xen_pfn_t *arr, int *err, unsigned int num)
 {
tools/libxc/xc_freebsd_osdep.c +27 -73

173 lines not on this page · raw message

tools/libxc/xc_hcall_buf.c +3 -3
index 6e3c958..a0e66cf 100644
@@ -122,7 +122,7 @@ void xc__hypercall_buffer_cache_release(xc_interface *xch)
     while ( xch->hypercall_buffer_cache_nr > 0 )
     {
         p = xch->hypercall_buffer_cache[--xch->hypercall_buffer_cache_nr];
-        xch->ops->u.privcmd.free_hypercall_buffer(xch, xch->ops_handle, p, 1);
+        osdep_free_hypercall_buffer(xch, p, 1);
     }
 
     hypercall_buffer_cache_unlock(xch);
@@ -133,7 +133,7 @@ void *xc__hypercall_buffer_alloc_pages(xc_interface *xch, xc_hypercall_buffer_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;
@@ -151,7 +151,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 46e0e75..9f846b8 100644
@@ -30,7 +30,6 @@
 
 #include "_paths.h"
 #include "xenctrl.h"
-#include "xenctrlosdep.h"
 
 #include <xen/sys/privcmd.h>
 
@@ -88,7 +87,6 @@ struct iovec {
 #define MAX_PAGECACHE_USAGE (4*1024)
 
 struct xc_interface_core {
-    enum xc_osdep_type type;
     int flags;
     xentoollog_logger *error_handler,   *error_handler_tofree;
     xentoollog_logger *dombuild_logger, *dombuild_logger_tofree;
@@ -117,12 +115,21 @@ struct xc_interface_core {
     int hypercall_buffer_cache_misses;
     int hypercall_buffer_cache_toobig;
 
-    /* Low lovel OS interface */
-    xc_osdep_info_t  osdep;
-    xc_osdep_ops    *ops; /* backend operations */
-    xc_osdep_handle  ops_handle; /* opaque data for xc_osdep_ops */
+    /* Privcmd interface */
+    int privcmdfd;
 };
 
+int osdep_privcmd_open(xc_interface *xch);
+int osdep_privcmd_close(xc_interface *xch);
+
+void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages);
+void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages);
+
+/* Stub for not yet converted OSes */
+void *xc_map_foreign_bulk_compat(xc_interface *xch,
+                                 uint32_t dom, int prot,
+                                 const xen_pfn_t *arr, int *err, unsigned int num);
+
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
tools/libxc/xc_solaris.c +32 -58

158 lines not on this page · raw message

tools/libxc/xenctrl_osdep_ENOSYS.c deleted +0 -123

123 lines not on this page · raw message

tools/ocaml/libs/xc/xenctrl.ml +0 -2
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 b7de615..29055cc 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 42b8183..25c126a 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
#20 lore raw

PATCH v3 9/22 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.

v3: Moved to tools/libs/call
Ported new wrappers (altp2m)

fixup! port altp2m to libxencall

---
 .gitignore                        |   2 +
 stubdom/Makefile                  |  20 +++-
 tools/Makefile                    |   1 +
 tools/Rules.mk                    |   7 +-
 tools/libs/Makefile               |   1 +
 tools/libs/call/Makefile          |  67 +++++++++++++
 tools/libs/call/buffer.c          | 192 ++++++++++++++++++++++++++++++++++++++
 tools/libs/call/core.c            | 144 ++++++++++++++++++++++++++++
 tools/libs/call/freebsd.c         | 140 +++++++++++++++++++++++++++
 tools/libs/call/include/xencall.h |  84 +++++++++++++++++
 tools/libs/call/libxencall.map    |  19 ++++
 tools/libs/call/linux.c           | 132 ++++++++++++++++++++++++++
 tools/libs/call/minios.c          |  81 ++++++++++++++++
 tools/libs/call/netbsd.c          | 121 ++++++++++++++++++++++++
 tools/libs/call/private.h         |  68 ++++++++++++++
 tools/libs/call/solaris.c         |  97 +++++++++++++++++++
 tools/libxc/Makefile              |   7 +-
 tools/libxc/xc_altp2m.c           |  64 ++++---------
 tools/libxc/xc_domain.c           | 105 +++++++--------------
 tools/libxc/xc_evtchn.c           |   9 +-
 tools/libxc/xc_flask.c            |   8 +-
 tools/libxc/xc_freebsd_osdep.c    |  47 ----------
 tools/libxc/xc_gnttab.c           |   9 +-
 tools/libxc/xc_hcall_buf.c        | 138 ++-------------------------
 tools/libxc/xc_kexec.c            |  36 +++----
 tools/libxc/xc_linux_osdep.c      |  49 ----------
 tools/libxc/xc_minios.c           |  32 -------
 tools/libxc/xc_misc.c             |  79 ++++++----------
 tools/libxc/xc_netbsd.c           |  40 --------
 tools/libxc/xc_private.c          |  64 +++++--------
 tools/libxc/xc_private.h          |  76 +++++----------
 tools/libxc/xc_solaris.c          |  16 ----
 tools/libxc/xc_tmem.c             |   7 +-
 tools/misc/Makefile               |   4 +-
 tools/xcutils/Makefile            |   2 +-
 tools/xenpaging/Makefile          |   2 +-
 36 files changed, 1338 insertions(+), 632 deletions(-)
 create mode 100644 tools/libs/call/Makefile
 create mode 100644 tools/libs/call/buffer.c
 create mode 100644 tools/libs/call/core.c
 create mode 100644 tools/libs/call/freebsd.c
 create mode 100644 tools/libs/call/include/xencall.h
 create mode 100644 tools/libs/call/libxencall.map
 create mode 100644 tools/libs/call/linux.c
 create mode 100644 tools/libs/call/minios.c
 create mode 100644 tools/libs/call/netbsd.c
 create mode 100644 tools/libs/call/private.h
 create mode 100644 tools/libs/call/solaris.c
.gitignore +2 -0
index ca79cab..319ef8f 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/libs/toollog/headers.chk
 tools/libs/evtchn/headers.chk
 tools/libs/gnttab/headers.chk
+tools/libs/call/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
stubdom/Makefile +19 -1
index d4576eb..24f0e0f 100644
@@ -330,6 +330,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/include/*.h include/ && \
 	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/Makefile . )
+	mkdir -p libs-$(XEN_TARGET_ARCH)/call/include
+	[ -h libs-$(XEN_TARGET_ARCH)/call/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/call && \
+	  ln -sf $(XEN_ROOT)/tools/libs/call/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/call/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libs/call/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/call/Makefile . )
 	mkdir -p libxc-$(XEN_TARGET_ARCH)
 	[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
 	  ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -386,12 +392,24 @@ libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: $(NEWLIB_STAMPFILE)
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab
 
 #######
+# libxencall
+#######
+
+.PHONY: libxencall
+libxencall: libs-$(XEN_TARGET_ARCH)/call/libxencall.a
+libs-$(XEN_TARGET_ARCH)/call/libxencall.a: $(NEWLIB_STAMPFILE)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
+	$(MAKE) DESTDIR= -C $(MINI_OS) links
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call -whole-archive -lxencall -no-whole-archive
+
+#######
 # 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 +1 -0
index 181045c..8679c3b 100644
@@ -263,6 +263,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +6 -1
index 2893c9f..0e451ce 100644
@@ -13,6 +13,7 @@ XEN_INCLUDE        = $(XEN_ROOT)/tools/include
 XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libs/toollog
 XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libs/evtchn
 XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libs/gnttab
+XEN_LIBXENCALL     = $(XEN_ROOT)/tools/libs/call
 XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
 XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
 XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
@@ -98,8 +99,12 @@ CFLAGS_libxengntshr = -I$(XEN_LIBXENGNTTAB)/include $(CFLAGS_xeninclude)
 LDLIBS_libxengntshr = $(XEN_LIBXENGNTTAB)/libxengnttab$(libextension)
 SHLIB_libxengntshr  = -Wl,-rpath-link=$(XEN_LIBXENGNTTAB)
 
+CFLAGS_libxencall = -I$(XEN_LIBXENCALL)/include $(CFLAGS_xeninclude)
+LDLIBS_libxencall = $(XEN_LIBXENCALL)/libxencall$(libextension)
+SHLIB_libxencall  = -Wl,-rpath-link=$(XEN_LIBXENCALL)
+
 CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude)
-SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr)
+SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall)
 LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension)
 SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
 
tools/libs/Makefile +1 -0
index 00156ae..f4f5d57 100644
@@ -5,5 +5,6 @@ SUBDIRS-y :=
 SUBDIRS-y += toollog
 SUBDIRS-y += evtchn
 SUBDIRS-y += gnttab
+SUBDIRS-y += call
 
 all clean install distclean: %: subdirs-%
tools/libs/call/Makefile new file +67 -0

67 lines not on this page · raw message

tools/libs/call/buffer.c new file +192 -0

192 lines not on this page · raw message

tools/libs/call/core.c new file +144 -0

144 lines not on this page · raw message

tools/libs/call/freebsd.c new file +140 -0

140 lines not on this page · raw message

tools/libs/call/include/xencall.h new file +84 -0

84 lines not on this page · raw message

tools/libs/call/libxencall.map new file +19 -0
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/libs/call/linux.c new file +132 -0

132 lines not on this page · raw message

tools/libs/call/minios.c new file +81 -0

81 lines not on this page · raw message

tools/libs/call/netbsd.c new file +121 -0

121 lines not on this page · raw message

tools/libs/call/private.h new file +68 -0

68 lines not on this page · raw message

tools/libs/call/solaris.c new file +97 -0

97 lines not on this page · raw message

tools/libxc/Makefile +6 -1
index 51dc16c..07cd335 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_altp2m.c +16 -48

203 lines not on this page · raw message

tools/libxc/xc_domain.c +36 -69

296 lines not on this page · raw message

tools/libxc/xc_evtchn.c +3 -6
index ae2fe1a..53f7605 100644
@@ -25,7 +25,6 @@ static int do_evtchn_op(xc_interface *xch, int cmd, void *arg,
                         size_t arg_size, int silently_fail)
 {
     int ret = -1;
-    DECLARE_HYPERCALL;
     DECLARE_HYPERCALL_BOUNCE(arg, arg_size, XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
 
     if ( xc_hypercall_bounce_pre(xch, arg) )
@@ -34,11 +33,9 @@ static int do_evtchn_op(xc_interface *xch, int cmd, void *arg,
         goto out;
     }
 
-    hypercall.op     = __HYPERVISOR_event_channel_op;
-    hypercall.arg[0] = cmd;
-    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(arg);
-
-    if ((ret = do_xen_hypercall(xch, &hypercall)) < 0 && !silently_fail)
+    ret = xencall2(xch->xcall, __HYPERVISOR_event_channel_op,
+                   cmd, HYPERCALL_BUFFER_AS_ARG(arg));
+    if ( ret < 0 && !silently_fail )
         ERROR("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d", ret);
 
     xc_hypercall_bounce_post(xch, arg);
tools/libxc/xc_flask.c +3 -5
index b533656..ec52b0f 100644
@@ -37,7 +37,6 @@
 int xc_flask_op(xc_interface *xch, xen_flask_op_t *op)
 {
     int ret = -1;
-    DECLARE_HYPERCALL;
     DECLARE_HYPERCALL_BOUNCE(op, sizeof(*op), XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
 
     op->interface_version = XEN_FLASK_INTERFACE_VERSION;
@@ -48,10 +47,9 @@ int xc_flask_op(xc_interface *xch, xen_flask_op_t *op)
         goto out;
     }
 
-    hypercall.op     = __HYPERVISOR_xsm_op;
-    hypercall.arg[0] = HYPERCALL_BUFFER_AS_ARG(op);
-
-    if ( (ret = do_xen_hypercall(xch, &hypercall)) < 0 )
+    ret = xencall1(xch->xcall, __HYPERVISOR_xsm_op,
+                   HYPERCALL_BUFFER_AS_ARG(op));
+    if ( ret < 0 )
     {
         if ( errno == EACCES )
             fprintf(stderr, "XSM operation failed!\n");
tools/libxc/xc_freebsd_osdep.c +0 -47

53 lines not on this page · raw message

tools/libxc/xc_gnttab.c +2 -7
index dd32aa2..af53fac 100644
@@ -21,7 +21,6 @@
 int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int count)
 {
     int ret = 0;
-    DECLARE_HYPERCALL;
     DECLARE_HYPERCALL_BOUNCE(op, count * op_size, XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
 
     if ( xc_hypercall_bounce_pre(xch, op) )
@@ -30,12 +29,8 @@ int xc_gnttab_op(xc_interface *xch, int cmd, void * op, int op_size, int count)
         goto out1;
     }
 
-    hypercall.op = __HYPERVISOR_grant_table_op;
-    hypercall.arg[0] = cmd;
-    hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(op);
-    hypercall.arg[2] = count;
-
-    ret = do_xen_hypercall(xch, &hypercall);
+    ret = xencall3(xch->xcall,  __HYPERVISOR_grant_table_op,
+                   cmd, HYPERCALL_BUFFER_AS_ARG(op), count);
 
     xc_hypercall_bounce_post(xch, op);
 
tools/libxc/xc_hcall_buf.c +6 -132

176 lines not on this page · raw message

tools/libxc/xc_kexec.c +12 -24
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 047e13b..e3c8241 100644
@@ -61,38 +61,6 @@ void minios_interface_close_fd(int fd)
     files[fd].type = FTYPE_NONE;
 }
 
-void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages)
-{
-    return xc_memalign(xch, PAGE_SIZE, npages * PAGE_SIZE);
-}
-
-void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages)
-{
-    free(ptr);
-}
-
-int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
-{
-    multicall_entry_t call;
-    int i, ret;
-
-    call.op = hypercall->op;
-    for (i = 0; i < ARRAY_SIZE(hypercall->arg); i++)
-	call.args[i] = hypercall->arg[i];
-
-    ret = HYPERVISOR_multicall(&call, 1);
-
-    if (ret < 0) {
-	errno = -ret;
-	return -1;
-    }
-    if ((long) call.result < 0) {
-        errno = - (long) call.result;
-        return -1;
-    }
-    return call.result;
-}
-
 void *xc_map_foreign_bulk(xc_interface *xch,
                           uint32_t dom, int prot,
                           const xen_pfn_t *arr, int *err, unsigned int num)
tools/libxc/xc_misc.c +27 -52

214 lines not on this page · raw message

tools/libxc/xc_netbsd.c +0 -40
index 9abb3b6..5e3b343 100644
@@ -67,46 +67,6 @@ int osdep_privcmd_close(xc_interface *xch)
     return close(fd);
 }
 
-void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages)
-{
-    size_t size = npages * XC_PAGE_SIZE;
-    void *p;
-
-    p = xc_memalign(xch, XC_PAGE_SIZE, size);
-    if (!p)
-        return NULL;
-
-    if ( mlock(p, size) < 0 )
-    {
-        free(p);
-        return NULL;
-    }
-    return p;
-}
-
-void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages)
-{
-    (void) munlock(ptr, npages * XC_PAGE_SIZE);
-    free(ptr);
-}
-
-int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
-{
-    int fd = xch->privcmdfd;
-    int error = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
-
-    /*
-     * Since NetBSD ioctl can only return 0 on success or < 0 on
-     * error, if we want to return a value from ioctl we should
-     * do so by setting hypercall->retval, to mimic Linux ioctl
-     * implementation.
-     */
-    if (error < 0)
-        return error;
-    else
-        return hypercall->retval;
-}
-
 void *xc_map_foreign_bulk(xc_interface *xch,
                           uint32_t dom, int prot,
                           const xen_pfn_t *arr, int *err, unsigned int num)
tools/libxc/xc_private.c +25 -39

125 lines not on this page · raw message

tools/libxc/xc_private.h +21 -55

160 lines not on this page · raw message

tools/libxc/xc_solaris.c +0 -16
index 6f84b82..18622fa 100644
@@ -67,22 +67,6 @@ int osdep_privcmd_close(xc_interface *xch)
     return close(fd);
 }
 
-void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages)
-{
-    return xc_memalign(xch, XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
-}
-
-static void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages)
-{
-    free(ptr);
-}
-
-int do_xen_hypercall(xc_interface *xch, privcmd_hypercall_t *hypercall)
-{
-    int fd = xch->privcmdfd;
-    return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
-}
-
 void *xc_map_foreign_batch(xc_interface *xch,
                           uint32_t dom, int prot,
                           xen_pfn_t *arr, int num)
tools/libxc/xc_tmem.c +3 -4
index 8f4c0cc..4e5c278 100644
@@ -23,7 +23,6 @@
 static int do_tmem_op(xc_interface *xch, tmem_op_t *op)
 {
     int ret;
-    DECLARE_HYPERCALL;
     DECLARE_HYPERCALL_BOUNCE(op, sizeof(*op), XC_HYPERCALL_BUFFER_BOUNCE_BOTH);
 
     if ( xc_hypercall_bounce_pre(xch, op) )
@@ -32,9 +31,9 @@ static int do_tmem_op(xc_interface *xch, tmem_op_t *op)
         return -EFAULT;
     }
 
-    hypercall.op = __HYPERVISOR_tmem_op;
-    hypercall.arg[0] = HYPERCALL_BUFFER_AS_ARG(op);
-    if ((ret = do_xen_hypercall(xch, &hypercall)) < 0)
+    ret = xencall1(xch->xcall, __HYPERVISOR_tmem_op,
+                   HYPERCALL_BUFFER_AS_ARG(op));
+    if ( ret < 0 )
     {
         if ( errno == EACCES )
             DPRINTF("tmem operation failed -- need to"
tools/misc/Makefile +2 -2
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
#21 lore raw

PATCH v3 10/22 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.

---
 tools/libxc/xc_foreign_memory.c | 13 +++++++++----
 tools/libxc/xc_netbsd.c         |  7 -------
 tools/libxc/xc_private.h        |  5 -----
 tools/libxc/xc_solaris.c        |  7 -------
 4 files changed, 9 insertions(+), 23 deletions(-)
tools/libxc/xc_foreign_memory.c +9 -4
index 9c705b6..b205bca 100644
@@ -50,10 +50,14 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
     return res;
 }
 
-/* stub for all not yet converted OSes */
-void *xc_map_foreign_bulk_compat(xc_interface *xch,
-                                 uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, unsigned int num)
+/*
+ * stub for all not yet converted OSes (NetBSD and Solaris). New OSes should
+ * just implement xc_map_foreign_bulk.
+ */
+#if defined(__NetBSD__) || defined(__sun__)
+void *xc_map_foreign_bulk(xc_interface *xch,
+                          uint32_t dom, int prot,
+                          const xen_pfn_t *arr, int *err, unsigned int num)
 {
     xen_pfn_t *pfn;
     unsigned int i;
@@ -90,6 +94,7 @@ void *xc_map_foreign_bulk_compat(xc_interface *xch,
 
     return ret;
 }
+#endif
 
 /*
  * Local variables:
tools/libxc/xc_netbsd.c +0 -7
index 5e3b343..d7f7f31 100644
@@ -67,13 +67,6 @@ int osdep_privcmd_close(xc_interface *xch)
     return close(fd);
 }
 
-void *xc_map_foreign_bulk(xc_interface *xch,
-                          uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err, unsigned int num)
-{
-    return xc_map_foreign_bulk_compat(xch, dom, prot, arr, err, num);
-}
-
 void *xc_map_foreign_batch(xc_interface *xch,
                            uint32_t dom, int prot,
                            xen_pfn_t *arr, int num)
tools/libxc/xc_private.h +0 -5
index 3ca9d29..0de907c 100644
@@ -107,11 +107,6 @@ int osdep_privcmd_close(xc_interface *xch);
 void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages);
 void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages);
 
-/* Stub for not yet converted OSes */
-void *xc_map_foreign_bulk_compat(xc_interface *xch,
-                                 uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, unsigned int num);
-
 void xc_report_error(xc_interface *xch, int code, const char *fmt, ...)
     __attribute__((format(printf,3,4)));
 void xc_reportv(xc_interface *xch, xentoollog_logger *lg, xentoollog_level,
tools/libxc/xc_solaris.c +0 -7
index 18622fa..5e72dee 100644
@@ -94,13 +94,6 @@ void *xc_map_foreign_batch(xc_interface *xch,
 
 }
 
-void *xc_map_foreign_bulk(xc_interface *xch,
-                          uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err, unsigned int num)
-{
-    return xc_map_foreign_bulk_compat(xch, dom, prot, arr, err, num);
-}
-
 void *xc_map_foreign_range(xc_interface *xch,
                            uint32_t dom,
                            int size, int prot,
Signature · 1 line
2.1.4
#22 lore raw

PATCH v3 11/22 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.

---
 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 ++++---
 11 files changed, 63 insertions(+), 118 deletions(-)
tools/libxc/include/xenctrl.h +0 -10
index 0c6b36b..44d0496 100644
@@ -1395,16 +1395,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 b205bca..2413e75 100644
@@ -55,6 +55,8 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
  * just implement xc_map_foreign_bulk.
  */
 #if defined(__NetBSD__) || defined(__sun__)
+void *osdep_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
+                              xen_pfn_t *arr, int num );
 void *xc_map_foreign_bulk(xc_interface *xch,
                           uint32_t dom, int prot,
                           const xen_pfn_t *arr, int *err, unsigned int num)
@@ -75,7 +77,7 @@ void *xc_map_foreign_bulk(xc_interface *xch,
     }
 
     memcpy(pfn, arr, num * sizeof(*arr));
-    ret = xc_map_foreign_batch(xch, dom, prot, pfn, num);
+    ret = osdep_map_foreign_batch(xch, dom, prot, pfn, num);
 
     if (ret) {
         for (i = 0; i < num; ++i)
tools/libxc/xc_linux_osdep.c +3 -56

77 lines not on this page · raw message

tools/libxc/xc_minios.c +0 -22
index e3c8241..3ea3124 100644
@@ -73,28 +73,6 @@ void *xc_map_foreign_bulk(xc_interface *xch,
     return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
 }
 
-void *xc_map_foreign_batch(xc_interface *xch,
-                           uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
-{
-    unsigned long pt_prot = 0;
-    int err[num];
-    int i;
-    unsigned long addr;
-
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-
-    addr = (unsigned long) map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
-    for (i = 0; i < num; i++) {
-        if (err[i])
-            arr[i] |= 0xF0000000;
-    }
-    return (void *) addr;
-}
-
 void *xc_map_foreign_range(xc_interface *xch,
                            uint32_t dom,
                            int size, int prot,
tools/libxc/xc_netbsd.c +5 -5
index d7f7f31..6a7ff9f 100644
@@ -67,16 +67,16 @@ int osdep_privcmd_close(xc_interface *xch)
     return close(fd);
 }
 
-void *xc_map_foreign_batch(xc_interface *xch,
-                           uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num)
+void *osdep_map_foreign_batch(xc_interface *xch,
+                              uint32_t dom, int prot,
+                              xen_pfn_t *arr, int num)
 {
     int fd = xch->privcmdfd;
     privcmd_mmapbatch_t ioctlx;
     void *addr;
     addr = mmap(NULL, num*XC_PAGE_SIZE, prot, MAP_ANON | MAP_SHARED, -1, 0);
     if ( addr == MAP_FAILED ) {
-        PERROR("xc_map_foreign_batch: mmap failed");
+        PERROR("osdep_map_foreign_batch: mmap failed");
         return NULL;
     }
 
@@ -87,7 +87,7 @@ void *xc_map_foreign_batch(xc_interface *xch,
     if ( ioctl(fd, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx) < 0 )
     {
         int saved_errno = errno;
-        PERROR("xc_map_foreign_batch: ioctl failed");
+        PERROR("osdep_map_foreign_batch: ioctl failed");
         (void)munmap(addr, num*XC_PAGE_SIZE);
         errno = saved_errno;
         return NULL;
tools/libxc/xc_solaris.c +3 -3
index 5e72dee..2df7a06 100644
@@ -67,9 +67,9 @@ int osdep_privcmd_close(xc_interface *xch)
     return close(fd);
 }
 
-void *xc_map_foreign_batch(xc_interface *xch,
-                          uint32_t dom, int prot,
-                          xen_pfn_t *arr, int num)
+void *osdep_map_foreign_batch(xc_interface *xch,
+                              uint32_t dom, int prot,
+                              xen_pfn_t *arr, int num)
 {
     int fd = xch->privcmdfd;
     privcmd_mmapbatch_t ioctlx;
tools/libxc/xc_vm_event.c +18 -7
index 2fef96a..d74d0f0 100644
@@ -45,6 +45,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;
 
@@ -72,9 +73,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,
@@ -86,11 +87,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;
         }
     }
@@ -156,3 +157,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 e4602ef..5cfc6af 100644
@@ -407,14 +407,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!");
@@ -1175,3 +1176,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 df99c6a..18b27a4 100644
@@ -281,6 +281,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));
@@ -342,8 +343,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 */
@@ -358,11 +359,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 v3 11/22
#23 lore raw

Re: [PATCH XEN v3 11/22] tools: Remove xc_map_foreign_batch

Quoted 36 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.

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.

---
 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 ++++---
 11 files changed, 63 insertions(+), 118 deletions(-)
tools/libxc/include/xenctrl.h +0 -0
index 0c6b36b..44d0496 100644

tools/libxc/include/xenctrl.h void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot, · line 1398

Quoted 4 lines
tools/libxc/include/xenctrl.h +0 -1
@@ -1395,16 +1395,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.

I like how there are half a dozen places in tree where we've been using a deprecated function for years. :-)

In any case:

#24 lore raw

Re: [PATCH XEN v3 11/22] tools: Remove xc_map_foreign_batch

Quoted 48 lines · George Dunlap
Quoted 38 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.

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.

---
 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 ++++---
 11 files changed, 63 insertions(+), 118 deletions(-)
tools/libxc/include/xenctrl.h +0 -0
index 0c6b36b..44d0496 100644

tools/libxc/include/xenctrl.h void *xc_map_foreign_pages(xc_interface *xch, · line 1399

Quoted 5 lines
tools/libxc/include/xenctrl.h +0 -1
@@ -1395,16 +1395,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.

I like how there are half a dozen places in tree where we've been using a deprecated function for years. :-)

Quoted 3 lines

In any case:

It took me _ages_ to untangle all of these, each OS had implemented a different subsets of the N interfaces as their base line and then there were a variety of compat shims in terms of that which ended up providing the full set on all platforms, sometimes it was A implemented in terms of B and sometimes it was vice versa.

I had to resort to drawing a graph per target platform and then chopping nodes out one by one to get anything I could even understand.

Ian.

#26 lore raw

Re: [PATCH XEN v3 11/22] tools: Remove xc_map_foreign_batch

Quoted 8 lines · Ian Campbell
Quoted 2 lines · George Dunlap
Quoted 1 line · Ian Campbell

[...]

Quoted 4 lines
Quoted 4 lines
Quoted 6 lines

[...]

Quoted 3 lines

In any case:

It must be a really good patch... ;-)

Haha -- well at least I'm consistent. :-)

-George

#27 lore raw

PATCH v3 12/22 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.

---
 tools/libxc/xc_foreign_memory.c | 50 +++++++++++++++++++++++++++++
 tools/libxc/xc_freebsd_osdep.c  | 50 -----------------------------
 tools/libxc/xc_linux_osdep.c    | 49 -----------------------------
 tools/libxc/xc_minios.c         | 43 -------------------------
 tools/libxc/xc_netbsd.c         | 70 -----------------------------------------
 tools/libxc/xc_solaris.c        | 67 ---------------------------------------
 6 files changed, 50 insertions(+), 279 deletions(-)
tools/libxc/xc_foreign_memory.c +50 -0
index 2413e75..d1130e6 100644
@@ -50,6 +50,56 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
     return res;
 }
 
+void *xc_map_foreign_range(xc_interface *xch,
+                           uint32_t dom, int size, int prot,
+                           unsigned long mfn)
+{
+    xen_pfn_t *arr;
+    int num;
+    int i;
+    void *ret;
+
+    num = (size + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT;
+    arr = calloc(num, sizeof(xen_pfn_t));
+    if ( arr == NULL )
+        return NULL;
+
+    for ( i = 0; i < num; i++ )
+        arr[i] = mfn + i;
+
+    ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
+    free(arr);
+    return ret;
+}
+
+void *xc_map_foreign_ranges(xc_interface *xch,
+                            uint32_t dom, size_t size,
+                            int prot, size_t chunksize,
+                            privcmd_mmap_entry_t entries[],
+                            int nentries)
+{
+    xen_pfn_t *arr;
+    int num_per_entry;
+    int num;
+    int i;
+    int j;
+    void *ret;
+
+    num_per_entry = chunksize >> XC_PAGE_SHIFT;
+    num = num_per_entry * nentries;
+    arr = calloc(num, sizeof(xen_pfn_t));
+    if ( arr == NULL )
+        return NULL;
+
+    for ( i = 0; i < nentries; i++ )
+        for ( j = 0; j < num_per_entry; j++ )
+            arr[i * num_per_entry + j] = entries[i].mfn + j;
+
+    ret = xc_map_foreign_pages(xch, dom, prot, arr, num);
+    free(arr);
+    return ret;
+}
+
 /*
  * stub for all not yet converted OSes (NetBSD and Solaris). New OSes should
  * just implement xc_map_foreign_bulk.
tools/libxc/xc_freebsd_osdep.c +0 -50

56 lines not on this page · raw message

tools/libxc/xc_linux_osdep.c +0 -49

55 lines not on this page · raw message

tools/libxc/xc_minios.c +0 -43

49 lines not on this page · raw message

tools/libxc/xc_netbsd.c +0 -70

76 lines not on this page · raw message

tools/libxc/xc_solaris.c +0 -67

73 lines not on this page · raw message

Signature · 1 line
2.1.4
#28 lore raw

PATCH v3 13/22 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 +
 stubdom/Makefile                                   |  20 +-
 tools/Makefile                                     |   2 +
 tools/Rules.mk                                     |  11 +-
 tools/console/daemon/utils.c                       |   1 -
 tools/console/daemon/utils.h                       |   1 +
 tools/libs/Makefile                                |   1 +
 tools/libs/foreignmemory/Makefile                  |  67 +++++
 tools/libs/foreignmemory/compat.c                  |  72 +++++
 tools/libs/foreignmemory/core.c                    |  68 +++++
 tools/libs/foreignmemory/freebsd.c                 | 129 +++++++++
 .../libs/foreignmemory/include/xenforeignmemory.h  |  71 +++++
 tools/libs/foreignmemory/libxenforeignmemory.map   |   7 +
 tools/libs/foreignmemory/linux.c                   | 287 ++++++++++++++++++++
 tools/libs/foreignmemory/minios.c                  |  62 +++++
 tools/libs/foreignmemory/netbsd.c                  |  95 +++++++
 tools/libs/foreignmemory/private.h                 |  47 ++++
 tools/libs/foreignmemory/solaris.c                 |  94 +++++++
 tools/libxc/Makefile                               |   8 +-
 tools/libxc/include/xenctrl.h                      |  26 --
 tools/libxc/include/xenctrl_compat.h               |  36 +++
 tools/libxc/xc_foreign_memory.c                    |  49 +---
 tools/libxc/xc_freebsd_osdep.c                     | 136 ----------
 tools/libxc/xc_linux_osdep.c                       | 295 ---------------------
 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/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 +
 45 files changed, 1112 insertions(+), 711 deletions(-)
 create mode 100644 tools/libs/foreignmemory/Makefile
 create mode 100644 tools/libs/foreignmemory/compat.c
 create mode 100644 tools/libs/foreignmemory/core.c
 create mode 100644 tools/libs/foreignmemory/freebsd.c
 create mode 100644 tools/libs/foreignmemory/include/xenforeignmemory.h
 create mode 100644 tools/libs/foreignmemory/libxenforeignmemory.map
 create mode 100644 tools/libs/foreignmemory/linux.c
 create mode 100644 tools/libs/foreignmemory/minios.c
 create mode 100644 tools/libs/foreignmemory/netbsd.c
 create mode 100644 tools/libs/foreignmemory/private.h
 create mode 100644 tools/libs/foreignmemory/solaris.c
 delete mode 100644 tools/libxc/xc_freebsd_osdep.c
 delete mode 100644 tools/libxc/xc_linux_osdep.c
.gitignore +2 -0
index 319ef8f..e5922d3 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/libs/toollog/headers.chk
 tools/libs/evtchn/headers.chk
 tools/libs/gnttab/headers.chk
 tools/libs/call/headers.chk
+tools/libs/foreignmemory/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
stubdom/Makefile +18 -2
index 24f0e0f..dc47586 100644
@@ -336,6 +336,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libs/call/include/*.h include/ && \
 	  ln -sf $(XEN_ROOT)/tools/libs/call/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/call/Makefile . )
+	mkdir -p libs-$(XEN_TARGET_ARCH)/foreignmemory/include
+	[ -h libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/foreignmemory && \
+	  ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/Makefile . )
 	mkdir -p libxc-$(XEN_TARGET_ARCH)
 	[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
 	  ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -401,7 +407,17 @@ libs-$(XEN_TARGET_ARCH)/call/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 libs-$(XEN_TARGET_ARCH)/call
-APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call -whole-archive -lxencall -no-whole-archive
+
+#######
+# libxenforeignmemory
+#######
+
+.PHONY: libxenforeignmemory
+libxenforeignmemory: libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
+libs-$(XEN_TARGET_ARCH)/foreignmemory/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 libs-$(XEN_TARGET_ARCH)/foreignmemory
 
 #######
 # libxc
@@ -409,7 +425,7 @@ APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call -whole-archi
 
 .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 +2 -0
index 8679c3b..269cd3e 100644
@@ -250,6 +250,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		--source-path=$$source \
 		--extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \
 		-DXC_WANT_COMPAT_GNTTAB_API=1 \
+		-DXC_WANT_COMPAT_MAP_FOREIGN_API=1 \
 		-I$(XEN_ROOT)/tools/include \
 		-I$(XEN_ROOT)/tools/libs/toollog/include \
 		-I$(XEN_ROOT)/tools/libs/evtchn/include \
@@ -264,6 +265,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/foreignmemory \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +8 -3
index 0e451ce..f814424 100644
@@ -14,6 +14,7 @@ XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libs/toollog
 XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libs/evtchn
 XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libs/gnttab
 XEN_LIBXENCALL     = $(XEN_ROOT)/tools/libs/call
+XEN_LIBXENFOREIGNMEMORY = $(XEN_ROOT)/tools/libs/foreignmemory
 XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
 XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
 XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
@@ -103,12 +104,16 @@ CFLAGS_libxencall = -I$(XEN_LIBXENCALL)/include $(CFLAGS_xeninclude)
 LDLIBS_libxencall = $(XEN_LIBXENCALL)/libxencall$(libextension)
 SHLIB_libxencall  = -Wl,-rpath-link=$(XEN_LIBXENCALL)
 
-CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_xeninclude)
-SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall)
+CFLAGS_libxenforeignmemory = -I$(XEN_LIBXENFOREIGNMEMORY)/include $(CFLAGS_xeninclude)
+LDLIBS_libxenforeignmemory = $(XEN_LIBXENFOREIGNMEMORY)/libxenforeignmemory$(libextension)
+SHLIB_libxenforeignmemory  = -Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY)
+
+CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
+SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall) $(SHLIB_libxenforeignmemory)
 LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension)
 SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
 
-CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_xeninclude)
+CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
 SHDEPS_libxenguest = $(SHLIB_libxenevtchn)
 LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_LIBXC)/libxenguest$(libextension)
 SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=L$(XEN_LIBXC)
tools/console/daemon/utils.c +0 -1
index dbb3b12..5b9a16b 100644
@@ -33,7 +33,6 @@
 #include <string.h>
 #include <signal.h>
 
-#include "xenctrl.h"
 #include "utils.h"
 
 struct xs_handle *xs;
tools/console/daemon/utils.h +1 -0
index 1295822..a010ac4 100644
@@ -23,6 +23,7 @@
 #include <stdbool.h>
 #include <syslog.h>
 #include <stdio.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 
 #include <xenstore.h>
tools/libs/Makefile +1 -0
index f4f5d57..dc5726d 100644
@@ -6,5 +6,6 @@ SUBDIRS-y += toollog
 SUBDIRS-y += evtchn
 SUBDIRS-y += gnttab
 SUBDIRS-y += call
+SUBDIRS-y += foreignmemory
 
 all clean install distclean: %: subdirs-%
tools/libs/foreignmemory/Makefile new file +67 -0

67 lines not on this page · raw message

tools/libs/foreignmemory/compat.c new file +72 -0

72 lines not on this page · raw message

tools/libs/foreignmemory/core.c new file +68 -0

68 lines not on this page · raw message

tools/libs/foreignmemory/freebsd.c new file +129 -0

129 lines not on this page · raw message

tools/libs/foreignmemory/include/xenforeignmemory.h new file +71 -0

71 lines not on this page · raw message

tools/libs/foreignmemory/libxenforeignmemory.map new file +7 -0
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/libs/foreignmemory/linux.c new file +287 -0

287 lines not on this page · raw message

tools/libs/foreignmemory/minios.c new file +62 -0

62 lines not on this page · raw message

tools/libs/foreignmemory/netbsd.c new file +95 -0

95 lines not on this page · raw message

tools/libs/foreignmemory/private.h new file +47 -0

47 lines not on this page · raw message

tools/libs/foreignmemory/solaris.c new file +94 -0

94 lines not on this page · raw message

tools/libxc/Makefile +4 -4
index 07cd335..e3b1e20 100644
@@ -42,8 +42,8 @@ CTRL_SRCS-y       += xc_kexec.c
 CTRL_SRCS-y       += xc_resource.c
 CTRL_SRCS-$(CONFIG_X86) += xc_psr.c
 CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
-CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c xc_linux_osdep.c
-CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c xc_freebsd_osdep.c
+CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
+CTRL_SRCS-$(CONFIG_FreeBSD) += xc_freebsd.c
 CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
 CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.c
 CTRL_SRCS-$(CONFIG_NetBSDRump) += xc_netbsd.c
@@ -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 44d0496..a80d942 100644
@@ -1377,32 +1377,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_foreign_memory.c +4 -45

70 lines not on this page · raw message

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

136 lines not on this page · raw message

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

295 lines not on this page · raw message

tools/libxc/xc_minios.c +0 -29
index d8ca948..1799daa 100644
@@ -39,40 +39,11 @@ void minios_interface_close_fd(int fd);
 
 extern void minios_interface_close_fd(int fd);
 
-int osdep_privcmd_open(xc_interface *xch)
-{
-    int fd = alloc_fd(FTYPE_XC);
-
-    if ( fd == -1)
-        return -1;
-
-    xch->privcmdfd = fd;
-    return 0;
-}
-
-int osdep_privcmd_close(xc_interface *xch)
-{
-    int fd = xch->privcmdfd;
-    return close(fd);
-}
-
 void minios_interface_close_fd(int fd)
 {
     files[fd].type = FTYPE_NONE;
 }
 
-void *xc_map_foreign_bulk(xc_interface *xch,
-                          uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err, unsigned int num)
-{
-    unsigned long pt_prot = 0;
-    if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
-    if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
-    return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
-}
-
 /* Optionally flush file to disk and discard page cache */
 void discard_file_cache(xc_interface *xch, int fd, int flush)
 {
tools/libxc/xc_netbsd.c +0 -73

79 lines not on this page · raw message

tools/libxc/xc_private.c +7 -6
index b3a660e..5690a89 100644
@@ -58,11 +58,12 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
     if (open_flags & XC_OPENFLAG_DUMMY)
         return xch; /* We are done */
 
-    if ( osdep_privcmd_open(xch) < 0 )
-        goto err;
-
     xch->xcall = xencall_open(xch->error_handler,
         open_flags & XC_OPENFLAG_NON_REENTRANT ? XENCALL_OPENFLAG_NON_REENTRANT : 0U);
+    if ( xch->xcall == NULL )
+        goto err;
+
+    xch->fmem = xenforeignmemory_open(xch->error_handler, 0);
 
     if ( xch->xcall == NULL )
         goto err;
@@ -70,7 +71,7 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
     return xch;
 
  err:
-    osdep_privcmd_close(xch);
+    xencall_close(xch->xcall);
     xtl_logger_destroy(xch->error_handler_tofree);
     if (xch != &xch_buf) free(xch);
     return NULL;
@@ -86,8 +87,8 @@ int xc_interface_close(xc_interface *xch)
     rc = xencall_close(xch->xcall);
     if (rc) PERROR("Could not close xencall interface");
 
-    rc = osdep_privcmd_close(xch);
-    if (rc) PERROR("Could not close hypervisor interface");
+    rc = xenforeignmemory_close(xch->fmem);
+    if (rc) PERROR("Could not close foreign memory interface");
 
     xtl_logger_destroy(xch->dombuild_logger_tofree);
     xtl_logger_destroy(xch->error_handler_tofree);
tools/libxc/xc_private.h +8 -3
index 0de907c..0b1104e 100644
@@ -29,8 +29,13 @@
 #include <sys/ioctl.h>
 
 #include "_paths.h"
+
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
+#define XC_INTERNAL_COMPAT_MAP_FOREIGN_API
 #include "xenctrl.h"
+
 #include <xencall.h>
+#include <xenforeignmemory.h>
 
 #include <xen/sys/privcmd.h>
 
@@ -94,11 +99,11 @@ struct xc_interface_core {
     FILE *dombuild_logger_file;
     const char *currently_progress_reporting;
 
-    /* Privcmd interface */
-    int privcmdfd;
-
     /* Hypercall interface */
     xencall_handle *xcall;
+
+    /* Foreign mappings */
+    xenforeignmemory_handle *fmem;
 };
 
 int osdep_privcmd_open(xc_interface *xch);
tools/libxc/xc_solaris.c +0 -73

81 lines not on this page · raw message

tools/libxc/xc_sr_restore.c +2 -2
index f48e7fc..2e41af8 100644
@@ -316,8 +316,8 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,
     if ( nr_pages == 0 )
         goto done;
 
-    mapping = guest_page = xc_map_foreign_bulk(
-        xch, ctx->domid, PROT_READ | PROT_WRITE,
+    mapping = guest_page = xenforeignmemory_map(xch->fmem,
+        ctx->domid, PROT_READ | PROT_WRITE,
         mfns, map_errs, nr_pages);
     if ( !mapping )
     {
tools/libxc/xc_sr_save.c +2 -2
index 7dc3a48..e4def8c3 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 d74d0f0..df21f9c 100644
@@ -73,8 +73,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 */
@@ -87,8 +88,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 5544897..16da428 100644
@@ -26,9 +26,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "xenctrl.h"
-#include "xenguest.h"
 #include "xc_private.h"
+#include "xenguest.h"
 
 #include <xen/memory.h>
 #include <xen/elfnote.h>
tools/libxl/libxl_internal.h +1 -0
index 6cef654..ed546e1 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 29055cc..d43ed78 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 67afed4..ffbfb4e 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 5cfc6af..bf018aa 100644
@@ -38,6 +38,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <xenevtchn.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 #include <xen/xen.h>
 #include <string.h>
tools/xenpaging/pagein.c +0 -1
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 18b27a4..e2c283d 100644
@@ -27,7 +27,6 @@
 #include <signal.h>
 #include <unistd.h>
 #include <poll.h>
-#include <xc_private.h>
 #include <xenstore.h>
 #include <getopt.h>
 
tools/xenpaging/xenpaging.h +2 -0
index d0f8d20..d6c8ee5 100644
@@ -25,6 +25,8 @@
 
 
 #include <xenevtchn.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
+#include <xenctrl.h>
 #include <xc_private.h>
 #include <xen/event_channel.h>
 #include <xen/vm_event.h>
tools/xenstore/xenstored_core.c +0 -1
index c8a5d52..d4468c6 100644
@@ -50,7 +50,6 @@
 #include "xenstored_watch.h"
 #include "xenstored_transaction.h"
 #include "xenstored_domain.h"
-#include "xenctrl.h"
 #include "tdb.h"
 
 #include "hashtable.h"
tools/xenstore/xenstored_core.h +1 -0
index 624737d..3a497f7 100644
@@ -19,6 +19,7 @@
 #ifndef _XENSTORED_CORE_H
 #define _XENSTORED_CORE_H
 
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 #include <xengnttab.h>
 
tools/xentrace/xenctx.c +2 -1
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
#29 lore raw

PATCH v3 14/22 tools: foreignmemory: provide xenforeignmemory_unmap.

In reply to Ian Campbell

And require it be used instead of direct munmap.

This will allow e.g. Valgrind hooks to help track incorrect use of foreign mappings.

Switch all uses of xenforeignmemory_map to use xenforeignmemory_unmap, not that foreign mappings via the libxc compat xc_map_foreign_* interface will not take advantage of this and will need converting.

---
 tools/libs/foreignmemory/freebsd.c                  | 6 ++++++
 tools/libs/foreignmemory/include/xenforeignmemory.h | 7 +++++--
 tools/libs/foreignmemory/libxenforeignmemory.map    | 1 +
 tools/libs/foreignmemory/linux.c                    | 6 ++++++
 tools/libs/foreignmemory/minios.c                   | 6 ++++++
 tools/libs/foreignmemory/netbsd.c                   | 6 ++++++
 tools/libs/foreignmemory/solaris.c                  | 6 ++++++
 tools/libxc/xc_sr_restore.c                         | 2 +-
 tools/libxc/xc_sr_save.c                            | 3 ++-
 tools/libxc/xc_vm_event.c                           | 2 +-
 10 files changed, 40 insertions(+), 5 deletions(-)
tools/libs/foreignmemory/freebsd.c +6 -0
index a7e0f6b..f9e74fa 100644
@@ -118,6 +118,12 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return addr;
 }
 
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num)
+{
+	return munmap(addr, num << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/include/xenforeignmemory.h +5 -2
index 0909585..1bcdf6a 100644
@@ -44,8 +44,8 @@ int xenforeignmemory_close(xenforeignmemory_handle *xmem);
 
 /*
  * Maps a range within one domain to a local address range.  Mappings
- * should be unmapped with munmap and should follow the same rules as mmap
- * regarding page alignment.
+ * must be unmapped with xenforeignmemory_unmap and should follow the
+ * same rules as mmap regarding page alignment.
  *
  * prot is as for mmap(2).
  *
@@ -58,6 +58,9 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
                            int prot, const xen_pfn_t *arr, int *err,
                            unsigned int num);
 
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num);
+
 #endif
 
 /*
tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
index 11f0d2b..df206b3 100644
@@ -3,5 +3,6 @@ VERS_1.0 {
 		xenforeignmemory_open;
 		xenforeignmemory_close;
 		xenforeignmemory_map;
+		xenforeignmemory_unmap;
 	local: *; /* Do not expose anything by default */
 };
tools/libs/foreignmemory/linux.c +6 -0
index 01cd42e..86a5a97 100644
@@ -276,6 +276,12 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return addr;
 }
 
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num)
+{
+    return munmap(addr, (unsigned long)num << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/minios.c +6 -0
index 981d801..dbb152f 100644
@@ -51,6 +51,12 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
 }
 
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num)
+{
+	return munmap(addr, num << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/netbsd.c +6 -0
index e84d5ec..4d68b52 100644
@@ -93,3 +93,9 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
     return addr;
 
 }
+
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num)
+{
+	return munmap(addr, num*XC_PAGE_SIZE);
+}
tools/libs/foreignmemory/solaris.c +6 -0
index 1d27b50..3f8e705 100644
@@ -92,3 +92,9 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
     return addr;
 
 }
+
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num)
+{
+	return munmap(addr, num*XC_PAGE_SIZE);
+}
tools/libxc/xc_sr_restore.c +1 -1
index 2e41af8..1a0d76a 100644
@@ -378,7 +378,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,
 
  err:
     if ( mapping )
-        munmap(mapping, nr_pages * PAGE_SIZE);
+        xenforeignmemory_unmap(xch->fmem, mapping, nr_pages * PAGE_SIZE);
 
     free(map_errs);
     free(mfns);
tools/libxc/xc_sr_save.c +2 -1
index e4def8c3..6db225a 100644
@@ -263,7 +263,8 @@ static int write_batch(struct xc_sr_context *ctx)
  err:
     free(rec_pfns);
     if ( guest_mapping )
-        munmap(guest_mapping, nr_pages_mapped * PAGE_SIZE);
+        xenforeignmemory_unmap(xch->fmem, guest_mapping,
+                               nr_pages_mapped * PAGE_SIZE);
     for ( i = 0; local_pages && i < nr_pfns; ++i )
         free(local_pages[i]);
     free(iov);
tools/libxc/xc_vm_event.c +1 -1
index df21f9c..6a18d59 100644
@@ -151,7 +151,7 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
         }
 
         if ( ring_page )
-            munmap(ring_page, XC_PAGE_SIZE);
+            xenforeignmemory_unmap(xch->fmem, ring_page, XC_PAGE_SIZE);
         ring_page = NULL;
 
         errno = saved_errno;
Signature · 1 line
2.1.4
#30 lore raw

Re: [PATCH XEN v3 14/22] tools: foreignmemory: provide xenforeignmemory_unmap.

On 07/10/15 15:15, Ian Campbell wrote:

What is the plan WRT fixing the existing APIs?

The two options are 1) Move to new libs then fix, or 2) Fix in tree then move to pristine new libs.

Option 1) runs the risk of digging ourself a hole in the form of a stable API. Option 2) seems like it would be clearer to review.

tools/libs/foreignmemory/linux.c void *xenforeignmemory_map(xenforeignmemory_handle *fmem, · line 282

Quoted 12 lines
tools/libs/foreignmemory/linux.c +4 -0
index 01cd42e..86a5a97 100644
@@ -276,6 +276,12 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return addr;
 }
 
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num)
+{
+    return munmap(addr, (unsigned long)num << PAGE_SHIFT);

This cast indicates that unsigned int is not appropriate in the API.

It matches the map() side, but severely risks truncating the unmap() because of the internal multiplication by 4096. Both the map and unmap side should use "size_t num" rather than unsigned int.

tools/libxc/xc_sr_restore.c static int process_page_data(struct xc_sr_context *ctx, unsigned count, · line 381

Quoted 10 lines
tools/libxc/xc_sr_restore.c +1 -1
index 2e41af8..1a0d76a 100644
@@ -378,7 +378,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,
 
  err:
     if ( mapping )
-        munmap(mapping, nr_pages * PAGE_SIZE);
+        xenforeignmemory_unmap(xch->fmem, mapping, nr_pages * PAGE_SIZE);

The semantics are different between munmap() and xenforeignmemory_unmap(), which means you need to drop the * PAGE_SIZE in each of the replacements.

~Andrew

#31 lore raw

Re: [PATCH XEN v3 14/22] tools: foreignmemory: provide xenforeignmemory_unmap.

Quoted 3 lines · Andrew Cooper

On 07/10/15 15:15, Ian Campbell wrote:

What is the plan WRT fixing the existing APIs?

Which ones do you mean? The xc_map_foreign_* which aren't moved here?

My intention is to deprecate them and switch everything over to the API provided by this library. IOW xenforeignmemory_map() will be the sole (at least ABI stable way) way to map foreign memory.

I don't want to go replicate the "there's ten ways to do it" aspect of the current interfaces in this new library.

I think the selected interface (which matches the old _bulk one) provides sufficient flexibility to be usable going forward. Evidence of this is that all the old libxc interfaces are now implemented in terms of it.

Quoted 5 lines

The two options are 1) Move to new libs then fix, or 2) Fix in tree then move to pristine new libs.

Option 1) runs the risk of digging ourself a hole in the form of a stable API. Option 2) seems like it would be clearer to review.

I suppose I'm proposing option 3) port everything to this new API when we like and eventually remove these functions.

(quoted diff) +0 -0
Quoted 16 lines

tools/libs/foreignmemory/linux.c void *xenforeignmemory_map(xenforeignmemory_handle · line 283

Quoted 13 lines

b/tools/libs/foreignmemory/linux.c
index 01cd42e..86a5a97 100644

tools/libs/foreignmemory/linux.c +4 -0
@@ -276,6 +276,12 @@ void *xenforeignmemory_map(xenforeignmemory_handle
 *fmem,
     return addr;
 }
 
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num)
+{
+    return munmap(addr, (unsigned long)num << PAGE_SHIFT);

This cast indicates that unsigned int is not appropriate in the API.

Quoted 3 lines

It matches the map() side, but severely risks truncating the unmap() because of the internal multiplication by 4096. Both the map and unmap side should use "size_t num" rather than unsigned int.

Agreed.

Quoted 7 lines
Quoted 7 lines
tools/libxc/xc_sr_restore.c +0 -0
index 2e41af8..1a0d76a 100644
@@ -378,7 +378,7 @@ static int process_page_data(struct xc_sr_context
 *ctx, unsigned count,
 
Quoted 9 lines

tools/libxc/xc_sr_restore.c static int process_page_data(struct xc_sr_context · line 383

Quoted 5 lines
tools/libxc/xc_sr_restore.c +1 -1
  err:
     if ( mapping )
-        munmap(mapping, nr_pages * PAGE_SIZE);
+        xenforeignmemory_unmap(xch->fmem, mapping, nr_pages *
 PAGE_SIZE);

The semantics are different between munmap() and xenforeignmemory_unmap(), which means you need to drop the * PAGE_SIZE in each of the replacements.

Oops, yes indeed.

Ian.

#32 lore raw

Re: [PATCH XEN v3 14/22] tools: foreignmemory: provide xenforeignmemory_unmap.

Quoted 10 lines · Ian Campbell
Quoted 3 lines · Andrew Cooper

On 07/10/15 15:15, Ian Campbell wrote:

What is the plan WRT fixing the existing APIs?

Which ones do you mean? The xc_map_foreign_* which aren't moved here?

My intention is to deprecate them and switch everything over to the API provided by this library. IOW xenforeignmemory_map() will be the sole (at least ABI stable way) way to map foreign memory.

Quoted 6 lines

I don't want to go replicate the "there's ten ways to do it" aspect of the current interfaces in this new library.

I think the selected interface (which matches the old _bulk one) provides sufficient flexibility to be usable going forward. Evidence of this is that all the old libxc interfaces are now implemented in terms of it.

Sorry about not being clear. I meant "At what point do we fix the (eventual) API in the new libraries", with reference to the suggested s/unsigned int/size_t/ change.

~Andrew

#33 lore raw

Re: [PATCH XEN v3 14/22] tools: foreignmemory: provide xenforeignmemory_unmap.

Quoted 22 lines · Andrew Cooper
Quoted 15 lines · Ian Campbell
Quoted 3 lines · Andrew Cooper

On 07/10/15 15:15, Ian Campbell wrote:

What is the plan WRT fixing the existing APIs?

Which ones do you mean? The xc_map_foreign_* which aren't moved here?

My intention is to deprecate them and switch everything over to the API provided by this library. IOW xenforeignmemory_map() will be the sole (at
least ABI stable way) way to map foreign memory.

I don't want to go replicate the "there's ten ways to do it" aspect of the
current interfaces in this new library.

Quoted 5 lines

I think the selected interface (which matches the old _bulk one) provides
sufficient flexibility to be usable going forward. Evidence of this is that
all the old libxc interfaces are now implemented in terms of it.

Quoted 3 lines

Sorry about not being clear. I meant "At what point do we fix the (eventual) API in the new libraries", with reference to the suggested s/unsigned int/size_t/ change.

Ah, I think we should aim to release 4.7 with this being declared stable.

I don't foresee the s/unsigned int/size_t/ in libxenforeignmemory being especially problematic wrt that. There are only a handful of users in tree, to update and the rest are still using the legacy xc_map_foreign wrappers, which would be the appropriate place for any impedance matching until those users get ported over.

Ian.

#34 lore raw

PATCH v3 15/22 tools/libs/evtchn: Review and update doc comments.

In reply to Ian Campbell

Remove the reference to pre-4.1, since this is now a new library.

Fixup references to xc.

---
 tools/libs/evtchn/include/xenevtchn.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/libs/evtchn/include/xenevtchn.h +2 -4
index 3380fa3..60da2a3 100644
@@ -46,11 +46,9 @@ typedef struct xentoollog_logger xentoollog_logger;
  * which case errno will be set appropriately.
  *
  * Note:
- * After fork a child process must not use any opened xc evtchn
+ * After fork a child process must not use any opened evtchn
  * handle inherited from their parent. They must open a new handle if
- * they want to interact with xc.
- *
- * Before Xen pre-4.1 this function would sometimes report errors with perror.
+ * they want to interact with evtchn.
  */
 /* Currently no flags are defined */
 xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags);
Signature · 1 line
2.1.4
#35 lore raw

PATCH v3 16/22 tools/libs: Clean up hard tabs.

In reply to Ian Campbell

These were wrong in the context of libxc before this code was extracted, clean them up.

Also add some emacs magic blocks

---
 tools/libs/call/buffer.c              |  4 ++--
 tools/libs/call/core.c                |  2 +-
 tools/libs/call/minios.c              |  4 ++--
 tools/libs/evtchn/minios.c            | 28 ++++++++++++++--------------
 tools/libs/evtchn/netbsd.c            | 12 ++++++------
 tools/libs/foreignmemory/freebsd.c    |  2 +-
 tools/libs/foreignmemory/linux.c      |  4 ++--
 tools/libs/foreignmemory/minios.c     | 10 +++++-----
 tools/libs/foreignmemory/netbsd.c     | 12 +++++++++++-
 tools/libs/foreignmemory/private.h    |  2 +-
 tools/libs/foreignmemory/solaris.c    | 13 +++++++++++--
 tools/libs/gnttab/include/xengnttab.h |  4 ++--
 tools/libs/gnttab/linux.c             |  6 +++---
 tools/libs/toollog/xtl_logger_stdio.c |  2 +-
 14 files changed, 62 insertions(+), 43 deletions(-)
tools/libs/call/buffer.c +2 -2
index fbbd7ff..da27135 100644
@@ -20,7 +20,7 @@
 #include "private.h"
 
 #define DBGPRINTF(_m...) \
-	xtl_log(xcall->logger, XTL_DEBUG, -1, "xencall:buffer", _m)
+    xtl_log(xcall->logger, XTL_DEBUG, -1, "xencall:buffer", _m)
 
 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 
@@ -86,7 +86,7 @@ static int cache_free(xencall_handle *xcall, void *p, int nr_pages)
     xcall->buffer_current_allocations--;
 
     if ( nr_pages == 1 &&
-	 xcall->buffer_cache_nr < BUFFER_CACHE_SIZE )
+         xcall->buffer_cache_nr < BUFFER_CACHE_SIZE )
     {
         xcall->buffer_cache[xcall->buffer_cache_nr++] = p;
         rc = 1;
tools/libs/call/core.c +1 -1
index 83f8ddb..c570592 100644
@@ -19,7 +19,7 @@
 
 xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags)
 {
-	xencall_handle *xcall = malloc(sizeof(*xcall));
+    xencall_handle *xcall = malloc(sizeof(*xcall));
     int rc;
 
     if (!xcall) return NULL;
tools/libs/call/minios.c +2 -2
index 1cdc073..524fa04 100644
@@ -50,8 +50,8 @@ int osdep_hypercall(xencall_handle *xcall, privcmd_hypercall_t *hypercall)
     ret = HYPERVISOR_multicall(&call, 1);
 
     if (ret < 0) {
-	errno = -ret;
-	return -1;
+        errno = -ret;
+        return -1;
     }
     if ((long) call.result < 0) {
         errno = - (long) call.result;
tools/libs/evtchn/minios.c +14 -14
index b839cd0..b4b5f14 100644
@@ -103,8 +103,8 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port)
     ret = notify_remote_via_evtchn(port);
 
     if (ret < 0) {
-	errno = -ret;
-	ret = -1;
+        errno = -ret;
+        ret = -1;
     }
     return ret;
 }
@@ -138,16 +138,16 @@ evtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xce, int do
     assert(get_current() == main_thread);
     port_info = port_alloc(fd);
     if (port_info == NULL)
-	return -1;
+        return -1;
 
     printf("xenevtchn_bind_unbound_port(%d)", domid);
     ret = evtchn_alloc_unbound(domid, evtchn_handler, (void*)(intptr_t)fd, &port);
     printf(" = %d\n", ret);
 
     if (ret < 0) {
-	port_dealloc(port_info);
-	errno = -ret;
-	return -1;
+        port_dealloc(port_info);
+        errno = -ret;
+        return -1;
     }
     port_info->bound = 1;
     port_info->port = port;
@@ -166,16 +166,16 @@ evtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, int dom
     assert(get_current() == main_thread);
     port_info = port_alloc(fd);
     if (port_info == NULL)
-	return -1;
+        return -1;
 
     printf("xenevtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port);
     ret = evtchn_bind_interdomain(domid, remote_port, evtchn_handler, (void*)(intptr_t)fd, &local_port);
     printf(" = %d\n", ret);
 
     if (ret < 0) {
-	port_dealloc(port_info);
-	errno = -ret;
-	return -1;
+        port_dealloc(port_info);
+        errno = -ret;
+        return -1;
     }
     port_info->bound = 1;
     port_info->port = local_port;
@@ -208,15 +208,15 @@ evtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsigned int v
     assert(get_current() == main_thread);
     port_info = port_alloc(fd);
     if (port_info == NULL)
-	return -1;
+        return -1;
 
     printf("xenevtchn_bind_virq(%d)", virq);
     port = bind_virq(virq, evtchn_handler, (void*)(intptr_t)fd);
 
     if (port < 0) {
-	port_dealloc(port_info);
-	errno = -port;
-	return -1;
+        port_dealloc(port_info);
+        errno = -port;
+        return -1;
     }
     port_info->bound = 1;
     port_info->port = port;
tools/libs/evtchn/netbsd.c +6 -6
index c4123fe..13b77d6 100644
@@ -72,9 +72,9 @@ evtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle * xce, int d
 
     ret = ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
     if (ret == 0)
-	return bind.port;
+        return bind.port;
     else
-	return -1;
+        return -1;
 }
 
 evtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, int domid,
@@ -89,9 +89,9 @@ evtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, int dom
 
     ret = ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
     if (ret == 0)
-	return bind.port;
+        return bind.port;
     else
-	return -1;
+        return -1;
 }
 
 int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_port_t port)
@@ -114,9 +114,9 @@ evtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsigned int v
 
     err = ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
     if (err)
-	return -1;
+        return -1;
     else
-	return bind.port;
+        return bind.port;
 }
 
 evtchn_port_or_error_t xenevtchn_pending(xenevtchn_handle *xce)
tools/libs/foreignmemory/freebsd.c +1 -1
index f9e74fa..f75f61e 100644
@@ -121,7 +121,7 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
 int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                            void *addr, unsigned int num)
 {
-	return munmap(addr, num << PAGE_SHIFT);
+    return munmap(addr, num << PAGE_SHIFT);
 }
 
 /*
tools/libs/foreignmemory/linux.c +2 -2
index 86a5a97..fae0f8e 100644
@@ -153,8 +153,8 @@ out:
 }
 
 void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
-			   uint32_t dom, int prot,
-			   const xen_pfn_t *arr, int *err, unsigned int num)
+                           uint32_t dom, int prot,
+                           const xen_pfn_t *arr, int *err, unsigned int num)
 {
     int fd = fmem->fd;
     privcmd_mmapbatch_v2_t ioctlx;
tools/libs/foreignmemory/minios.c +5 -5
index dbb152f..be8f864 100644
@@ -40,21 +40,21 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
 }
 
 void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
-			   uint32_t dom, int prot,
-			   const xen_pfn_t *arr, int *err, unsigned int num)
+                           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;
+        pt_prot = L1_PROT_RO;
     if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
+        pt_prot = L1_PROT;
     return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
 }
 
 int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                            void *addr, unsigned int num)
 {
-	return munmap(addr, num << PAGE_SHIFT);
+    return munmap(addr, num << PAGE_SHIFT);
 }
 
 /*
tools/libs/foreignmemory/netbsd.c +11 -1
index 4d68b52..5a2f740 100644
@@ -97,5 +97,15 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
 int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                            void *addr, unsigned int num)
 {
-	return munmap(addr, num*XC_PAGE_SIZE);
+    return munmap(addr, num*XC_PAGE_SIZE);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libs/foreignmemory/private.h +1 -1
index 54dd7d5..30ea892 100644
@@ -32,7 +32,7 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
 #endif
 
 #define PERROR(_f...) \
-	xtl_log(fmem->logger, XTL_ERROR, errno, "xenforeignmemory", _f)
+    xtl_log(fmem->logger, XTL_ERROR, errno, "xenforeignmemory", _f)
 
 #endif
 
tools/libs/foreignmemory/solaris.c +11 -2
index 3f8e705..5f5fd35 100644
@@ -90,11 +90,20 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
         return NULL;
     }
     return addr;
-
 }
 
 int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                            void *addr, unsigned int num)
 {
-	return munmap(addr, num*XC_PAGE_SIZE);
+    return munmap(addr, num*XC_PAGE_SIZE);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libs/gnttab/include/xengnttab.h +2 -2
index 007e6db..c810c07 100644
@@ -144,7 +144,7 @@ int xengnttab_munmap(xengnttab_handle *xgt,
  *      of grants.
  */
 int xengnttab_set_max_grants(xengnttab_handle *xgt,
-			     uint32_t count);
+                             uint32_t count);
 
 /*
  * Grant Sharing Interface (allocating and granting pages)
@@ -162,7 +162,7 @@ typedef struct xengntdev_handle xengntshr_handle;
  *
  */
 xengntshr_handle *xengntshr_open(xentoollog_logger *logger,
-			  unsigned open_flags);
+                                 unsigned open_flags);
 
 /*
  * Close a handle previously allocated with xengntshr_open().
tools/libs/gnttab/linux.c +3 -3
index 635765b..a76f17f 100644
@@ -294,9 +294,9 @@ void *osdep_gntshr_share_pages(xengntshr_handle *xgs,
         err = ioctl(fd, IOCTL_GNTALLOC_SET_UNMAP_NOTIFY, &notify);
     if (err) {
         GSERROR(xgs->logger, "ioctl SET_UNMAP_NOTIFY failed");
-		munmap(area, count * PAGE_SIZE);
-		area = NULL;
-	}
+        munmap(area, count * PAGE_SIZE);
+        area = NULL;
+    }
 
     memcpy(refs, gref_info->gref_ids, count * sizeof(uint32_t));
 
tools/libs/toollog/xtl_logger_stdio.c +1 -1
index f9c5bd8..52dfbf5 100644
@@ -135,7 +135,7 @@ static void stdiostream_progress(struct xentoollog_logger *logger_in,
     newpel = fprintf(lg->f, "%s%s" "%s: %lu/%lu  %3d%%%s",
                      context?context:"", context?": ":"",
                      doing_what, done, total, percent,
-		     done == total ? "\n" : "");
+                     done == total ? "\n" : "");
 
     extra_erase = lg->progress_erase_len - newpel;
     if (extra_erase > 0)
Signature · 1 line
2.1.4
#36 lore raw

PATCH v3 17/22 tools/libs/gnttab: Review and update doc comments.

In reply to Ian Campbell

Remove some stray xc references.

While I'm not convinced by javadoc/doxygen cause the existing comments which appear to use that syntax to have the appropriate /** marker.

Also fix a typo in a code comment.

---
 tools/libs/gnttab/include/xengnttab.h | 21 +++++++++++----------
 tools/libs/gnttab/linux.c             |  2 +-
 2 files changed, 12 insertions(+), 11 deletions(-)
tools/libs/gnttab/include/xengnttab.h +11 -10
index c810c07..e091fa6 100644
@@ -38,9 +38,9 @@ typedef struct xengntdev_handle xengnttab_handle;
 
 /*
  * Note:
- * After fork a child process must not use any opened xc gnttab
+ * After fork a child process must not use any opened gnttab
  * handle inherited from their parent. They must open a new handle if
- * they want to interact with xc.
+ * they want to interact with gnttab.
  *
  * Return an fd onto the grant table driver.  Logs errors.
  */
@@ -52,7 +52,7 @@ xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned open_flags)
  */
 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.
  *
@@ -124,7 +124,7 @@ void *xengnttab_map_grant_ref_notify(xengnttab_handle *xgt,
                                      uint32_t notify_offset,
                                      evtchn_port_t notify_port);
 
-/*
+/**
  * Unmaps the @count pages starting at @start_address, which were mapped by a
  * call to xengnttab_map_grant_ref or xengnttab_map_grant_refs. Never logs.
  */
@@ -132,7 +132,7 @@ 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.
  *
@@ -156,9 +156,9 @@ 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
+ * After fork a child process must not use any opened gntshr
  * handle inherited from their parent. They must open a new handle if
- * they want to interact with xc.
+ * they want to interact with gntshr.
  *
  */
 xengntshr_handle *xengntshr_open(xentoollog_logger *logger,
@@ -170,7 +170,7 @@ xengntshr_handle *xengntshr_open(xentoollog_logger *logger,
  */
 int xengntshr_close(xengntshr_handle *xgs);
 
-/*
+/**
  * Creates and shares pages with another domain.
  *
  * @parm xgs a handle to an open grant sharing instance
@@ -183,7 +183,7 @@ int xengntshr_close(xengntshr_handle *xgs);
 void *xengntshr_share_pages(xengntshr_handle *xgs, uint32_t domid,
                             int count, uint32_t *refs, int writable);
 
-/*
+/**
  * Creates and shares a page with another domain, with unmap notification.
  *
  * @parm xgs a handle to an open grant sharing instance
@@ -199,7 +199,8 @@ 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.
  */
tools/libs/gnttab/linux.c +1 -1
index a76f17f..bdf2a42 100644
@@ -136,7 +136,7 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt,
          * swapped out. Since the paging daemon may be in the same domain, the
          * hypercall cannot block without causing a deadlock.
          *
-         * Because there are no notificaitons when the page is swapped in, wait
+         * Because there are no notifications when the page is swapped in, wait
          * a bit before retrying, and hope that the page will arrive eventually.
          */
         usleep(1000);
Signature · 1 line
2.1.4
#37 lore raw

PATCH v3 18/22 tools/libs/call: Update some log messages to not refer to xc.

In reply to Ian Campbell
---
 tools/libs/call/linux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/libs/call/linux.c +2 -2
index 906ca7e..80b505c 100644
@@ -88,7 +88,7 @@ void *osdep_alloc_pages(xencall_handle *xcall, unsigned int npages)
     p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED, -1, 0);
     if ( p == MAP_FAILED )
     {
-        PERROR("xc_alloc_hypercall_buffer: mmap failed");
+        PERROR("alloc_pages: mmap failed");
         return NULL;
     }
 
@@ -97,7 +97,7 @@ void *osdep_alloc_pages(xencall_handle *xcall, unsigned int npages)
     rc = madvise(p, npages * PAGE_SIZE, MADV_DONTFORK);
     if ( rc < 0 )
     {
-        PERROR("xc_alloc_hypercall_buffer: madvise failed");
+        PERROR("alloc_pages: madvise failed");
         goto out;
     }
 
Signature · 1 line
2.1.4
#38 lore raw

PATCH v3 19/22 tools/libs/call: Avoid xc_memalign in netbsd and solaris backends

In reply to Ian Campbell

These are already arch specific, so just use the appropriate interfaces (as determined by looking at the xc_memalign backend).

---
 tools/libs/call/netbsd.c  | 4 ++--
 tools/libs/call/solaris.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
tools/libs/call/netbsd.c +2 -2
index 12008fb..c01d3de 100644
@@ -74,8 +74,8 @@ void *osdep_alloc_hypercall_buffer(xencall_handle *xcall, unsigned int npages)
     size_t size = npages * XC_PAGE_SIZE;
     void *p;
 
-    p = xc_memalign(xcall, XC_PAGE_SIZE, size);
-    if (!p)
+    ret = posix_memalign(&p, XC_PAGE_SIZE, size);
+    if ( ret != 0 || !p )
         return NULL;
 
     if ( mlock(p, size) < 0 )
tools/libs/call/solaris.c +1 -1
index 972989d..8d9c9da 100644
@@ -71,7 +71,7 @@ int osdep_xencall_close(xencall_handle *xcall)
 
 void *osdep_alloc_hypercall_buffer(xencall_handle *xcall, unsigned int npages)
 {
-    return xc_memalign(xcall, XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
+    return memalign(XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
 }
 
 void osdep_free_hypercall_buffer(xencall_handle *xcall, void *ptr,
Signature · 1 line
2.1.4
#39 lore raw

PATCH v3 20/22 tools/libs/foreignmemory: Mention restrictions on fork in docs.

In reply to Ian Campbell
---
 tools/libs/foreignmemory/include/xenforeignmemory.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/include/xenforeignmemory.h +6 -1
index 1bcdf6a..5897fb8 100644
@@ -32,7 +32,12 @@ typedef struct xentoollog_logger xentoollog_logger;
 typedef struct xenforeignmemory_handle xenforeignmemory_handle;
 
 /*
- * Return a handle onto the hypercall driver.  Logs errors.
+ * Return a handle onto the foreign memory mapping driver.  Logs errors.
+ *
+ * Note: After fork a child process must not use any opened handle
+ * inherited from their parent. Any existing mappings should be
+ * assumed to become invalid. Therefore children must open a new
+ * handle and make new mappings if necessary.
  */
 xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,
                                                unsigned open_flags);
Signature · 1 line
2.1.4
#40 lore raw

PATCH v3 21/22 tools: Update CFLAGS for qemu-xen to allow it to use new libraries

In reply to Ian Campbell

This means adding -L for libxen{evtchn,gnttab,foreignmemory} so that it can link them directly (rather than using the libxenctrl compat layer exposed via -rpath-link). Also add -I for libxenforeignmemory.

---
 tools/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
tools/Makefile +4 -0
index 269cd3e..ef69b69 100644
@@ -255,12 +255,16 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-I$(XEN_ROOT)/tools/libs/toollog/include \
 		-I$(XEN_ROOT)/tools/libs/evtchn/include \
 		-I$(XEN_ROOT)/tools/libs/gnttab/include \
+		-I$(XEN_ROOT)/tools/libs/foreignmemory/include \
 		-I$(XEN_ROOT)/tools/libxc/include \
 		-I$(XEN_ROOT)/tools/xenstore/include \
 		-I$(XEN_ROOT)/tools/xenstore/compat/include \
 		$(EXTRA_CFLAGS_QEMU_XEN)" \
 		--extra-ldflags="-L$(XEN_ROOT)/tools/libxc \
 		-L$(XEN_ROOT)/tools/xenstore \
+		-L$(XEN_ROOT)/tools/libs/evtchn \
+		-L$(XEN_ROOT)/tools/libs/gnttab \
+		-L$(XEN_ROOT)/tools/libs/foreignmemory \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
Signature · 1 line
2.1.4
#41 lore raw

PATCH v3 22/22 HACK: Add a .config to pull all the right bits from my xenbits trees

In reply to Ian Campbell
---
 .config | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 .config
.config new file +9 -0
new file mode 100644
index 0000000..d197a0a
@@ -0,0 +1,9 @@
+MINIOS_UPSTREAM_URL := git://xenbits.xen.org/people/ianc/libxenctrl-split/mini-os.git
+MINIOS_UPSTREAM_REVISION := origin/v3
+
+QEMU_TRADITIONAL_URL := git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen-traditional.git
+QEMU_TRADITIONAL_REVISION := origin/v3
+
+QEMU_UPSTREAM_URL := git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen.git
+QEMU_UPSTREAM_REVISION := origin/v3
+
Signature · 1 line
2.1.4
#42 lore raw

PATCH v3 1/8 xen: Switch to libxenevtchn interface for compat shims.

In reply to Ian Campbell

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.0 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         | 30 +++++++++++++++---------------
 include/hw/xen/xen_backend.h |  2 +-
 include/hw/xen/xen_common.h  | 43 +++++++++++++++++++++++++++++++++----------
 xen-hvm.c                    | 24 ++++++++++++------------
 4 files changed, 61 insertions(+), 38 deletions(-)
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);
Signature · 1 line
2.1.4
#43 lore raw

Re: [PATCH QEMU-XEN v3 1/8] xen: Switch to libxenevtchn interface for compat shims.

Quoted 18 lines · Ian Campbell

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.

<snip>

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 *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot, · line 51

Quoted 10 lines
include/hw/xen/xen_common.h +4 -2
 
 #  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);

This allocates the size of a pointer, not the size of an int, as the patch description states.

As this is compatibility code, it might be better just to use "sizeof(int)" directly, as stated in the "pre 4.1 note" in xenctrl.h

~Andrew

#44 lore raw

Re: [PATCH QEMU-XEN v3 1/8] xen: Switch to libxenevtchn interface for compat shims.

Quoted 24 lines · Andrew Cooper
Quoted 23 lines · Ian Campbell

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.

<snip>

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;
 
 #  define XC_INTERFACE_FMT "%i"
 #  define XC_HANDLER_INITIAL_VALUE    -1
 
Quoted 10 lines

include/hw/xen/xen_common.h static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot, · line 51

Quoted 7 lines
include/hw/xen/xen_common.h +4 -2
-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);

This allocates the size of a pointer, not the size of an int, as the patch description states.

Indeed, thanks.

I'll have done the exact same thing in a bunch of subsequent patches, no need to comment on them all ;-)

Quoted 2 lines

As this is compatibility code, it might be better just to use "sizeof(int)" directly, as stated in the "pre 4.1 note" in xenctrl.h

#45 lore raw

Re: [PATCH QEMU-XEN v3 1/8] xen: Switch to libxenevtchn interface for compat shims.

In reply to Ian Campbell

Please CC qemu-devel for this series

Quoted 19 lines · Ian Campbell

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.0 and 4.5.

Quoted 7 lines

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.

Please run the series through scripts/checkpatch.pl

Quoted 24 lines
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 +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 *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot, · line 51

Quoted 10 lines
include/hw/xen/xen_common.h +4 -2
 
 #  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);
                       ^
                        sizeof(*h)?

include/hw/xen/xen_common.h static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot, · line 53

Quoted 2 lines
include/hw/xen/xen_common.h +2 -0
+    if (!h)
+	return NULL;

indentation

Quoted 55 lines
include/hw/xen/xen_common.h +26 -7
+    *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 +0 -0
index 3a7fd58..54cbd72 100644

xen-hvm.c typedef struct XenIOState { · line 115

Quoted 8 lines
xen-hvm.c +1 -1
@@ -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;
 

I assume everything else is just substitutions

#46 lore raw

Re: [PATCH QEMU-XEN v3 1/8] xen: Switch to libxenevtchn interface for compat shims.

Quoted 1 line · Stefano Stabellini

Please CC qemu-devel for this series

Will do, I just didn't want to spam them with the very early discussions.

[...]

Quoted 1 line

Please run the series through scripts/checkpatch.pl

Sure.

[...]

Quoted 1 line

I assume everything else is just substitutions

Correct.

#47 lore raw

PATCH v3 2/8 xen: Switch to libxengnttab interface for compat shims.

In reply to Ian Campbell

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 libxengnttab which provides access to grant tables.

In preparation for this switch the compatibility layer in xen_common.h (which support building with older versions of Xen) to use what will be the new library API. This means that the gnttab shim will disappear for versions of Xen which include libxengnttab.

To simplify things for the <= 4.0.0 support we wrap the int fd in a malloc(sizeof int) such that the handle is always a pointer. This leads to less typedef headaches and the need for XC_HANDLER_INITIAL_VALUE etc for these interfaces.

Build tested with 4.0 and 4.5.

Note that this patch does not add any support for actually using libxengnttab, it just adjusts the existing shims.

---
 hw/block/xen_disk.c          | 36 ++++++++++++++++++------------------
 hw/char/xen_console.c        |  4 ++--
 hw/net/xen_nic.c             | 16 ++++++++--------
 hw/xen/xen_backend.c         | 10 +++++-----
 include/hw/xen/xen_backend.h |  2 +-
 include/hw/xen/xen_common.h  | 39 +++++++++++++++++++++++++++++----------
 6 files changed, 63 insertions(+), 44 deletions(-)
hw/block/xen_disk.c +18 -18
index 21842a0..d52bd88 100644
@@ -172,11 +172,11 @@ static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
 static void destroy_grant(gpointer pgnt)
 {
     PersistentGrant *grant = pgnt;
-    XenGnttab gnt = grant->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = grant->blkdev->xendev.gnttabdev;
 
-    if (xc_gnttab_munmap(gnt, grant->page, 1) != 0) {
+    if (xengnttab_munmap(gnt, grant->page, 1) != 0) {
         xen_be_printf(&grant->blkdev->xendev, 0,
-                      "xc_gnttab_munmap failed: %s\n",
+                      "xengnttab_munmap failed: %s\n",
                       strerror(errno));
     }
     grant->blkdev->persistent_gnt_count--;
@@ -189,11 +189,11 @@ static void remove_persistent_region(gpointer data, gpointer dev)
 {
     PersistentRegion *region = data;
     struct XenBlkDev *blkdev = dev;
-    XenGnttab gnt = blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = blkdev->xendev.gnttabdev;
 
-    if (xc_gnttab_munmap(gnt, region->addr, region->num) != 0) {
+    if (xengnttab_munmap(gnt, region->addr, region->num) != 0) {
         xen_be_printf(&blkdev->xendev, 0,
-                      "xc_gnttab_munmap region %p failed: %s\n",
+                      "xengnttab_munmap region %p failed: %s\n",
                       region->addr, strerror(errno));
     }
     xen_be_printf(&blkdev->xendev, 3,
@@ -328,7 +328,7 @@ err:
 
 static void ioreq_unmap(struct ioreq *ioreq)
 {
-    XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
     int i;
 
     if (ioreq->num_unmap == 0 || ioreq->mapped == 0) {
@@ -338,8 +338,8 @@ static void ioreq_unmap(struct ioreq *ioreq)
         if (!ioreq->pages) {
             return;
         }
-        if (xc_gnttab_munmap(gnt, ioreq->pages, ioreq->num_unmap) != 0) {
-            xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
+        if (xengnttab_munmap(gnt, ioreq->pages, ioreq->num_unmap) != 0) {
+            xen_be_printf(&ioreq->blkdev->xendev, 0, "xengnttab_munmap failed: %s\n",
                           strerror(errno));
         }
         ioreq->blkdev->cnt_map -= ioreq->num_unmap;
@@ -349,8 +349,8 @@ static void ioreq_unmap(struct ioreq *ioreq)
             if (!ioreq->page[i]) {
                 continue;
             }
-            if (xc_gnttab_munmap(gnt, ioreq->page[i], 1) != 0) {
-                xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
+            if (xengnttab_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--;
@@ -362,7 +362,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
 
 static int ioreq_map(struct ioreq *ioreq)
 {
-    XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
     uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST];
@@ -413,7 +413,7 @@ static int ioreq_map(struct ioreq *ioreq)
     }
 
     if (batch_maps && new_maps) {
-        ioreq->pages = xc_gnttab_map_grant_refs
+        ioreq->pages = xengnttab_map_grant_refs
             (gnt, new_maps, domids, refs, ioreq->prot);
         if (ioreq->pages == NULL) {
             xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -429,7 +429,7 @@ static int ioreq_map(struct ioreq *ioreq)
         ioreq->blkdev->cnt_map += new_maps;
     } else if (new_maps)  {
         for (i = 0; i < new_maps; i++) {
-            ioreq->page[i] = xc_gnttab_map_grant_ref
+            ioreq->page[i] = xengnttab_map_grant_ref
                 (gnt, domids[i], refs[i], ioreq->prot);
             if (ioreq->page[i] == NULL) {
                 xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -762,9 +762,9 @@ static void blk_alloc(struct XenDevice *xendev)
     if (xen_mode != XEN_EMULATE) {
         batch_maps = 1;
     }
-    if (xc_gnttab_set_max_grants(xendev->gnttabdev,
+    if (xengnttab_set_max_grants(xendev->gnttabdev,
             MAX_GRANTS(max_requests, BLKIF_MAX_SEGMENTS_PER_REQUEST)) < 0) {
-        xen_be_printf(xendev, 0, "xc_gnttab_set_max_grants failed: %s\n",
+        xen_be_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n",
                       strerror(errno));
     }
 }
@@ -976,7 +976,7 @@ static int blk_connect(struct XenDevice *xendev)
         }
     }
 
-    blkdev->sring = xc_gnttab_map_grant_ref(blkdev->xendev.gnttabdev,
+    blkdev->sring = xengnttab_map_grant_ref(blkdev->xendev.gnttabdev,
                                             blkdev->xendev.dom,
                                             blkdev->ring_ref,
                                             PROT_READ | PROT_WRITE);
@@ -1041,7 +1041,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;
     }
hw/char/xen_console.c +2 -2
index eb7f450..c5a023c 100644
@@ -233,7 +233,7 @@ static int con_initialise(struct XenDevice *xendev)
                                           PROT_READ|PROT_WRITE,
                                           con->ring_ref);
     } else {
-        con->sring = xc_gnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
+        con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
                                              con->ring_ref,
                                              PROT_READ|PROT_WRITE);
     }
@@ -278,7 +278,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/net/xen_nic.c +8 -8
index 63918ae..778de28 100644
@@ -169,7 +169,7 @@ static void net_tx_packets(struct XenNetDev *netdev)
                           (txreq.flags & NETTXF_more_data)      ? " more_data"      : "",
                           (txreq.flags & NETTXF_extra_info)     ? " extra_info"     : "");
 
-            page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+            page = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                            netdev->xendev.dom,
                                            txreq.gref, PROT_READ);
             if (page == NULL) {
@@ -191,7 +191,7 @@ static void net_tx_packets(struct XenNetDev *netdev)
                 qemu_send_packet(qemu_get_queue(netdev->nic),
                                  page + txreq.offset, txreq.size);
             }
-            xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
+            xengnttab_munmap(netdev->xendev.gnttabdev, page, 1);
             net_tx_response(netdev, &txreq, NETIF_RSP_OKAY);
         }
         if (!netdev->tx_work) {
@@ -283,7 +283,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size
     memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq));
     netdev->rx_ring.req_cons = ++rc;
 
-    page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    page = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                    netdev->xendev.dom,
                                    rxreq.gref, PROT_WRITE);
     if (page == NULL) {
@@ -293,7 +293,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size
         return -1;
     }
     memcpy(page + NET_IP_ALIGN, buf, size);
-    xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
+    xengnttab_munmap(netdev->xendev.gnttabdev, page, 1);
     net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0);
 
     return size;
@@ -366,11 +366,11 @@ static int net_connect(struct XenDevice *xendev)
         return -1;
     }
 
-    netdev->txs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->txs = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->tx_ring_ref,
                                           PROT_READ | PROT_WRITE);
-    netdev->rxs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->rxs = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->rx_ring_ref,
                                           PROT_READ | PROT_WRITE);
@@ -398,11 +398,11 @@ static void net_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&netdev->xendev);
 
     if (netdev->txs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->txs, 1);
+        xengnttab_munmap(netdev->xendev.gnttabdev, netdev->txs, 1);
         netdev->txs = NULL;
     }
     if (netdev->rxs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
+        xengnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
         netdev->rxs = NULL;
     }
     if (netdev->nic) {
hw/xen/xen_backend.c +5 -5
index 1fd8e01..9e616c6 100644
@@ -252,15 +252,15 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
     fcntl(xenevtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
 
     if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
-        xendev->gnttabdev = xen_xc_gnttab_open(NULL, 0);
-        if (xendev->gnttabdev == XC_HANDLER_INITIAL_VALUE) {
+        xendev->gnttabdev = xengnttab_open(NULL, 0);
+        if (xendev->gnttabdev == NULL) {
             xen_be_printf(NULL, 0, "can't open gnttab device\n");
             xenevtchn_close(xendev->evtchndev);
             g_free(xendev);
             return NULL;
         }
     } else {
-        xendev->gnttabdev = XC_HANDLER_INITIAL_VALUE;
+        xendev->gnttabdev = NULL;
     }
 
     QTAILQ_INSERT_TAIL(&xendevs, xendev, next);
@@ -309,8 +309,8 @@ static struct XenDevice *xen_be_del_xendev(int dom, int dev)
         if (xendev->evtchndev != NULL) {
             xenevtchn_close(xendev->evtchndev);
         }
-        if (xendev->gnttabdev != XC_HANDLER_INITIAL_VALUE) {
-            xc_gnttab_close(xendev->gnttabdev);
+        if (xendev->gnttabdev != NULL) {
+            xengnttab_close(xendev->gnttabdev);
         }
 
         QTAILQ_REMOVE(&xendevs, xendev, next);
include/hw/xen/xen_backend.h +1 -1
index a90314f..8e8857b 100644
@@ -47,7 +47,7 @@ struct XenDevice {
     int                local_port;
 
     xenevtchn_handle   *evtchndev;
-    XenGnttab          gnttabdev;
+    xengnttab_handle   *gnttabdev;
 
     struct XenDevOps   *ops;
     QTAILQ_ENTRY(XenDevice) next;
include/hw/xen/xen_common.h +29 -10
index 5700c1b..3955d86 100644
@@ -40,7 +40,7 @@ static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
 
 typedef int XenXC;
 typedef int xenevtchn_handle;
-typedef int XenGnttab;
+typedef int xengnttab_handle;
 
 #  define XC_INTERFACE_FMT "%i"
 #  define XC_HANDLER_INITIAL_VALUE    -1
@@ -71,11 +71,29 @@ static inline int xenevtchn_close(xenevtchn_handle *h)
 #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)
+static inline xengnttab_handle *xengnttab_open(void *logger,
+					       unsigned int open_flags)
 {
-    return xc_gnttab_open();
+    int *h = malloc(sizeof h);
+    if (!h)
+	return NULL;
+    *h = xc_gnttab_open();
+    if (*h == -1) {
+	 free(h);
+         h = NULL;
+    }
+    return h;
 }
+static inline int xengnttab_close(xengnttab_handle *h)
+{
+    int rc = xc_gnttab_close(*h);
+    free(h);
+    return rc;
+}
+#define xengnttab_set_max_grants(h,n) xc_gnttab_set_max_grants(*h, n)
+#define xengnttab_map_grant_ref(h,d,r,p) xc_gnttab_map_grant_ref(*h,d,r,p)
+#define xengnttab_map_grant_refs(h,c,d,r,p) xc_gnttab_map_grant_refs(*h,c,d,r,p)
+#define xengnttab_munmap(h,a,n) xc_gnttab_munmap(*h,a,n)
 
 static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
                                           unsigned int open_flags)
@@ -129,7 +147,7 @@ static inline void xs_close(struct xs_handle *xsh)
 
 typedef xc_interface *XenXC;
 typedef xc_evtchn xenevtchn_handle;
-typedef xc_gnttab *XenGnttab;
+typedef xc_gnttab xengnttab_handle;
 
 #  define XC_INTERFACE_FMT "%p"
 #  define XC_HANDLER_INITIAL_VALUE    NULL
@@ -143,11 +161,12 @@ typedef xc_gnttab *XenGnttab;
 #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)
-{
-    return xc_gnttab_open(logger, open_flags);
-}
+#define xengnttab_open(l,f) xc_gnttab_open(l,f)
+#define xengnttab_close(h) xc_gnttab_close(h)
+#define xengnttab_set_max_grants(h,n) xc_gnttab_set_max_grants(h, n)
+#define xengnttab_map_grant_ref(h,d,r,p) xc_gnttab_map_grant_ref(h,d,r,p)
+#define xengnttab_munmap(h,a,n) xc_gnttab_munmap(h,a,n)
+#define xengnttab_map_grant_refs(h,c,d,r,p) xc_gnttab_map_grant_refs(h,c,d,r,p)
 
 static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
                                           unsigned int open_flags)
Signature · 1 line
2.1.4
#48 lore raw

Re: [PATCH QEMU-XEN v3 2/8] xen: Switch to libxengnttab interface for compat shims.

Quoted 23 lines · Ian Campbell

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 libxengnttab which provides access to grant tables.

In preparation for this switch the compatibility layer in xen_common.h (which support building with older versions of Xen) to use what will be the new library API. This means that the gnttab shim will disappear for versions of Xen which include libxengnttab.

To simplify things for the <= 4.0.0 support we wrap the int fd in a malloc(sizeof int) such that the handle is always a pointer. This leads to less typedef headaches and the need for XC_HANDLER_INITIAL_VALUE etc for these interfaces.

Build tested with 4.0 and 4.5.

Note that this patch does not add any support for actually using libxengnttab, it just adjusts the existing shims.

[...]

Quoted 14 lines
include/hw/xen/xen_common.h +1 -1
index 5700c1b..3955d86 100644
@@ -40,7 +40,7 @@ static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
 
 typedef int XenXC;
 typedef int xenevtchn_handle;
-typedef int XenGnttab;
+typedef int xengnttab_handle;
 
 #  define XC_INTERFACE_FMT "%i"
 #  define XC_HANDLER_INITIAL_VALUE    -1

include/hw/xen/xen_common.h static inline int xenevtchn_close(xenevtchn_handle *h) · line 77

Quoted 10 lines
include/hw/xen/xen_common.h +3 -3
@@ -71,11 +71,29 @@ static inline int xenevtchn_close(xenevtchn_handle *h)
 #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)
+static inline xengnttab_handle *xengnttab_open(void *logger,
+					       unsigned int open_flags)
 {
-    return xc_gnttab_open();
+    int *h = malloc(sizeof h);
                       ^
                       sizeof (*h)

include/hw/xen/xen_common.h static inline int xenevtchn_close(xenevtchn_handle *h) · line 79

Quoted 2 lines
include/hw/xen/xen_common.h +2 -0
+    if (!h)
+	return NULL;

indentation

Quoted 50 lines
include/hw/xen/xen_common.h +23 -6
+    *h = xc_gnttab_open();
+    if (*h == -1) {
+	 free(h);
+         h = NULL;
+    }
+    return h;
 }
+static inline int xengnttab_close(xengnttab_handle *h)
+{
+    int rc = xc_gnttab_close(*h);
+    free(h);
+    return rc;
+}
+#define xengnttab_set_max_grants(h,n) xc_gnttab_set_max_grants(*h, n)
+#define xengnttab_map_grant_ref(h,d,r,p) xc_gnttab_map_grant_ref(*h,d,r,p)
+#define xengnttab_map_grant_refs(h,c,d,r,p) xc_gnttab_map_grant_refs(*h,c,d,r,p)
+#define xengnttab_munmap(h,a,n) xc_gnttab_munmap(*h,a,n)
 
 static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
                                           unsigned int open_flags)
@@ -129,7 +147,7 @@ static inline void xs_close(struct xs_handle *xsh)
 
 typedef xc_interface *XenXC;
 typedef xc_evtchn xenevtchn_handle;
-typedef xc_gnttab *XenGnttab;
+typedef xc_gnttab xengnttab_handle;
 
 #  define XC_INTERFACE_FMT "%p"
 #  define XC_HANDLER_INITIAL_VALUE    NULL
@@ -143,11 +161,12 @@ typedef xc_gnttab *XenGnttab;
 #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)
-{
-    return xc_gnttab_open(logger, open_flags);
-}
+#define xengnttab_open(l,f) xc_gnttab_open(l,f)
+#define xengnttab_close(h) xc_gnttab_close(h)
+#define xengnttab_set_max_grants(h,n) xc_gnttab_set_max_grants(h, n)
+#define xengnttab_map_grant_ref(h,d,r,p) xc_gnttab_map_grant_ref(h,d,r,p)
+#define xengnttab_munmap(h,a,n) xc_gnttab_munmap(h,a,n)
+#define xengnttab_map_grant_refs(h,c,d,r,p) xc_gnttab_map_grant_refs(h,c,d,r,p)
 
 static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
                                           unsigned int open_flags)
Signature · 1 line
2.1.4
#49 lore raw

Re: [PATCH QEMU-XEN v3 2/8] xen: Switch to libxengnttab interface for compat shims.

Quoted 5 lines · Stefano Stabellini
(quoted diff) +0 -0
@@ -71,11 +71,29 @@ static inline int xenevtchn_close(xenevtchn_handle
 > *h)
 >  #define xenevtchn_unmask(h,p) xc_evtchn_unmask(*h,p)
 >  #define xenevtchn_unbind(h,p) xc_evtchn_unmask(*h,p)
Quoted 1 line
Quoted 10 lines

include/hw/xen/xen_common.h static inline int xenevtchn_close(xenevtchn_handle *h) · line 77

Quoted 8 lines
include/hw/xen/xen_common.h +2 -2
-static inline XenGnttab xen_xc_gnttab_open(void *logger,
-                                           unsigned int open_flags)
+static inline xengnttab_handle *xengnttab_open(void *logger,
+					       unsigned int

open_flags)
{

include/hw/xen/xen_common.h +1 -1
-    return xc_gnttab_open();
+    int *h = malloc(sizeof h);
                       ^
                       sizeof (*h)

FYI I've done this mistake in all the patches, and will fix all in one go, so you can skip this for the remainder.

Quoted 4 lines

include/hw/xen/xen_common.h static inline int xenevtchn_close(xenevtchn_handle *h) · line 79

Quoted 2 lines
include/hw/xen/xen_common.h +2 -0
+    if (!h)
+	return NULL;

indentation

Probably this too, but I will check them all so no need to keep checking.

Ian.

#50 lore raw

PATCH v3 3/8 xen: Switch uses of xc_map_foreign_range into xc_map_foreign_bulk

In reply to Ian Campbell

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 libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for this switch all uses of xc_map_foreign_range to xc_map_foreign_bulk. This is trivial because size was always XC_PAGE_SIZE so the necessary adjustments are trivial:

* Pass &mfn (an array of length 1) instead of mfn
* Add a local err variable to receive the errors and pass &err (again, an array of length 1)
* Adjust any existing logging to include err too
* Pass nr_pages=1 instead of size=XC_PAGE_SIZE

There is one wrinkle in xen_console.c:con_initialise() where con->ring_ref is an int but can in some code paths (when !xendev->dev) be treated as an mfn. I think this is an existing latent truncation hazard on platforms where xen_pfn_t is 64-bit and int is 32-bit (e.g. amd64, both arm* variants). I'm unsure under what circumstances xendev->dev can be NULL or if anything elsewhere ensures the value fits into an int. For now I just use a temporary xen_pfn_t to in effect upcast the pointer from int* to xen_pfn_t*.

Build tested with 4.0 and 4.5.

---
 hw/char/xen_console.c |  9 +++++----
 hw/display/xenfb.c    |  6 +++---
 xen-hvm.c             | 29 +++++++++++++++--------------
 3 files changed, 23 insertions(+), 21 deletions(-)
hw/char/xen_console.c +5 -4
index c5a023c..6ef477a 100644
@@ -219,6 +219,7 @@ static int con_initialise(struct XenDevice *xendev)
 {
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
     int limit;
+    int err;
 
     if (xenstore_read_int(con->console, "ring-ref", &con->ring_ref) == -1)
 	return -1;
@@ -228,10 +229,10 @@ static int con_initialise(struct XenDevice *xendev)
 	con->buffer.max_capacity = limit;
 
     if (!xendev->dev) {
-        con->sring = xc_map_foreign_range(xen_xc, con->xendev.dom,
-                                          XC_PAGE_SIZE,
-                                          PROT_READ|PROT_WRITE,
-                                          con->ring_ref);
+	xen_pfn_t mfn = con->ring_ref;
+        con->sring = xc_map_foreign_bulk(xen_xc, con->xendev.dom,
+					 PROT_READ|PROT_WRITE,
+					 &mfn, &err, 1);
     } else {
         con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
                                              con->ring_ref,
hw/display/xenfb.c +3 -3
index 8a61e95..e3fdf33 100644
@@ -94,6 +94,7 @@ struct XenFB {
 static int common_bind(struct common *c)
 {
     uint64_t mfn;
+    int err;
 
     if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
 	return -1;
@@ -102,9 +103,8 @@ static int common_bind(struct common *c)
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    c->page = xc_map_foreign_bulk(xen_xc, c->xendev.dom,
+				  PROT_READ | PROT_WRITE, &mfn, &err, 1);
     if (c->page == NULL)
 	return -1;
 
xen-hvm.c +15 -14
index 54cbd72..3a56099 100644
@@ -1166,7 +1166,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
 int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
                  MemoryRegion **ram_memory)
 {
-    int i, rc;
+    int i, rc, map_err;
     xen_pfn_t ioreq_pfn;
     xen_pfn_t bufioreq_pfn;
     evtchn_port_t bufioreq_evtchn;
@@ -1213,33 +1213,34 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn);
     DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn);
 
-    state->shared_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
-                                              PROT_READ|PROT_WRITE, ioreq_pfn);
+    state->shared_page = xc_map_foreign_bulk(xen_xc, xen_domid,
+					     PROT_READ|PROT_WRITE,
+					     &ioreq_pfn, &map_err, 1);
     if (state->shared_page == NULL) {
-        hw_error("map shared IO page returned error %d handle=" XC_INTERFACE_FMT,
-                 errno, xen_xc);
+        hw_error("map shared IO page returned error %d (%d) handle=" XC_INTERFACE_FMT,
+                 errno, map_err, xen_xc);
     }
 
     rc = xen_get_vmport_regs_pfn(xen_xc, xen_domid, &ioreq_pfn);
     if (!rc) {
         DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn);
         state->shared_vmport_page =
-            xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
-                                 PROT_READ|PROT_WRITE, ioreq_pfn);
+		xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
+				    &ioreq_pfn, &map_err, 1);
         if (state->shared_vmport_page == NULL) {
-            hw_error("map shared vmport IO page returned error %d handle="
-                     XC_INTERFACE_FMT, errno, xen_xc);
+            hw_error("map shared vmport IO page returned error %d (%d) handle="
+                     XC_INTERFACE_FMT, errno, map_err, xen_xc);
         }
     } else if (rc != -ENOSYS) {
         hw_error("get vmport regs pfn returned error %d, rc=%d", errno, rc);
     }
 
-    state->buffered_io_page = xc_map_foreign_range(xen_xc, xen_domid,
-                                                   XC_PAGE_SIZE,
-                                                   PROT_READ|PROT_WRITE,
-                                                   bufioreq_pfn);
+    state->buffered_io_page = xc_map_foreign_bulk(xen_xc, xen_domid,
+						  PROT_READ|PROT_WRITE,
+                                                  &bufioreq_pfn,
+						  &map_err, 1);
     if (state->buffered_io_page == NULL) {
-        hw_error("map buffered IO page returned error %d", errno);
+        hw_error("map buffered IO page returned error %d (%d)", errno, map_err);
     }
 
     /* Note: cpus is empty at this point in init */
Signature · 1 line
2.1.4
#51 lore raw

Re: [PATCH QEMU-XEN v3 3/8] xen: Switch uses of xc_map_foreign_range into xc_map_foreign_bulk

Quoted 10 lines · Ian Campbell

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 libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for this switch all uses of xc_map_foreign_range to xc_map_foreign_bulk.

The sentence is incomplete.

Unfortunately xc_map_foreign_bulk is not that well documented, but I am assuming that the mfn parameter is not supposed to be changed by the function, right?

Quoted 40 lines

This is trivial because size was always XC_PAGE_SIZE so the necessary adjustments are trivial:

* Pass &mfn (an array of length 1) instead of mfn
* Add a local err variable to receive the errors and pass &err (again, an array of length 1)
* Adjust any existing logging to include err too
* Pass nr_pages=1 instead of size=XC_PAGE_SIZE

There is one wrinkle in xen_console.c:con_initialise() where con->ring_ref is an int but can in some code paths (when !xendev->dev) be treated as an mfn. I think this is an existing latent truncation hazard on platforms where xen_pfn_t is 64-bit and int is 32-bit (e.g. amd64, both arm* variants). I'm unsure under what circumstances xendev->dev can be NULL or if anything elsewhere ensures the value fits into an int. For now I just use a temporary xen_pfn_t to in effect upcast the pointer from int* to xen_pfn_t*.

Build tested with 4.0 and 4.5.

---
 hw/char/xen_console.c |  9 +++++----
 hw/display/xenfb.c    |  6 +++---
 xen-hvm.c             | 29 +++++++++++++++--------------
 3 files changed, 23 insertions(+), 21 deletions(-)
hw/char/xen_console.c +1 -0
index c5a023c..6ef477a 100644
@@ -219,6 +219,7 @@ static int con_initialise(struct XenDevice *xendev)
 {
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
     int limit;
+    int err;
 
     if (xenstore_read_int(con->console, "ring-ref", &con->ring_ref) == -1)
 	return -1;

hw/char/xen_console.c static int con_initialise(struct XenDevice *xendev) · line 232

Quoted 8 lines
hw/char/xen_console.c +1 -4
@@ -228,10 +229,10 @@ static int con_initialise(struct XenDevice *xendev)
 	con->buffer.max_capacity = limit;
 
     if (!xendev->dev) {
-        con->sring = xc_map_foreign_range(xen_xc, con->xendev.dom,
-                                          XC_PAGE_SIZE,
-                                          PROT_READ|PROT_WRITE,
-                                          con->ring_ref);
+	xen_pfn_t mfn = con->ring_ref;

indentation

Quoted 94 lines
hw/char/xen_console.c +3 -0
+        con->sring = xc_map_foreign_bulk(xen_xc, con->xendev.dom,
+					 PROT_READ|PROT_WRITE,
+					 &mfn, &err, 1);
     } else {
         con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
                                              con->ring_ref,
hw/display/xenfb.c +3 -3
index 8a61e95..e3fdf33 100644
@@ -94,6 +94,7 @@ struct XenFB {
 static int common_bind(struct common *c)
 {
     uint64_t mfn;
+    int err;
 
     if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
 	return -1;
@@ -102,9 +103,8 @@ static int common_bind(struct common *c)
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    c->page = xc_map_foreign_bulk(xen_xc, c->xendev.dom,
+				  PROT_READ | PROT_WRITE, &mfn, &err, 1);
     if (c->page == NULL)
 	return -1;
 
xen-hvm.c +15 -14
index 54cbd72..3a56099 100644
@@ -1166,7 +1166,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)
 int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
                  MemoryRegion **ram_memory)
 {
-    int i, rc;
+    int i, rc, map_err;
     xen_pfn_t ioreq_pfn;
     xen_pfn_t bufioreq_pfn;
     evtchn_port_t bufioreq_evtchn;
@@ -1213,33 +1213,34 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn);
     DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn);
 
-    state->shared_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
-                                              PROT_READ|PROT_WRITE, ioreq_pfn);
+    state->shared_page = xc_map_foreign_bulk(xen_xc, xen_domid,
+					     PROT_READ|PROT_WRITE,
+					     &ioreq_pfn, &map_err, 1);
     if (state->shared_page == NULL) {
-        hw_error("map shared IO page returned error %d handle=" XC_INTERFACE_FMT,
-                 errno, xen_xc);
+        hw_error("map shared IO page returned error %d (%d) handle=" XC_INTERFACE_FMT,
+                 errno, map_err, xen_xc);
     }
 
     rc = xen_get_vmport_regs_pfn(xen_xc, xen_domid, &ioreq_pfn);
     if (!rc) {
         DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn);
         state->shared_vmport_page =
-            xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
-                                 PROT_READ|PROT_WRITE, ioreq_pfn);
+		xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
+				    &ioreq_pfn, &map_err, 1);
         if (state->shared_vmport_page == NULL) {
-            hw_error("map shared vmport IO page returned error %d handle="
-                     XC_INTERFACE_FMT, errno, xen_xc);
+            hw_error("map shared vmport IO page returned error %d (%d) handle="
+                     XC_INTERFACE_FMT, errno, map_err, xen_xc);
         }
     } else if (rc != -ENOSYS) {
         hw_error("get vmport regs pfn returned error %d, rc=%d", errno, rc);
     }
 
-    state->buffered_io_page = xc_map_foreign_range(xen_xc, xen_domid,
-                                                   XC_PAGE_SIZE,
-                                                   PROT_READ|PROT_WRITE,
-                                                   bufioreq_pfn);
+    state->buffered_io_page = xc_map_foreign_bulk(xen_xc, xen_domid,
+						  PROT_READ|PROT_WRITE,
+                                                  &bufioreq_pfn,
+						  &map_err, 1);
     if (state->buffered_io_page == NULL) {
-        hw_error("map buffered IO page returned error %d", errno);
+        hw_error("map buffered IO page returned error %d (%d)", errno, map_err);
     }
 
     /* Note: cpus is empty at this point in init */
Signature · 1 line
2.1.4
#52 lore raw

Re: [PATCH QEMU-XEN v3 3/8] xen: Switch uses of xc_map_foreign_range into xc_map_foreign_bulk

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

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.

Quoted 8 lines
Quoted 6 lines

One such library will be libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for this switch all uses of xc_map_foreign_range to xc_map_foreign_bulk.

The sentence is incomplete.

If you mean "grammatically incorrect" then I don't think it is. Did you mean it was missing some information which you hoped to to see? If so then which?

Quoted 3 lines

Unfortunately xc_map_foreign_bulk is not that well documented, but I am assuming that the mfn parameter is not supposed to be changed by the function, right?

Given:

/**
* 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);

by "the mfn parameter" I suppose you mean arr[0] (for cases where arr is passed as &mfn as below)?

That's a pointer to an array of const xen_pfn_t so no need to worry about it changing, unlike some other interfaces per-page errors are reported via the separate err array.

Ian.

#53 lore raw

Re: [PATCH QEMU-XEN v3 3/8] xen: Switch uses of xc_map_foreign_range into xc_map_foreign_bulk

Quoted 10 lines · Ian Campbell
Quoted 9 lines · Stefano Stabellini
Quoted 8 lines · Ian Campbell

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 libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

In preparation for this switch all uses of xc_map_foreign_range to xc_map_foreign_bulk.

The sentence is incomplete.

If you mean "grammatically incorrect" then I don't think it is. Did you mean it was missing some information which you hoped to to see? If so then which?

Sorry, I read it as:

In preparation for this switch,
all uses of xc_map_foreign_range <missing something> to xc_map_foreign_bulk.

:-)

Quoted 12 lines
Quoted 3 lines

Unfortunately xc_map_foreign_bulk is not that well documented, but I am assuming that the mfn parameter is not supposed to be changed by the function, right?

Given:

/**
* 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,

Quoted 4 lines
                          const xen_pfn_t *arr, int *err, unsigned int num);

by "the mfn parameter" I suppose you mean arr[0] (for cases where arr is passed as &mfn as below)?

that's right

Quoted 3 lines

That's a pointer to an array of const xen_pfn_t so no need to worry about it changing, unlike some other interfaces per-page errors are reported via the separate err array.

That's what I gathered from the code too, I just wanted to be sure

#54 lore raw

PATCH v3 4/8 xen: Switch uses of xc_map_foreign_pages into xc_map_foreign_bulk

In reply to Ian Campbell

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 libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for this switch both uses of xc_map_foreign_pages (which both happen to be in xenfb_map_fb) to xc_map_foreign_bulk. This simply requires allocating and passing a new err array (the same one for both calls).

Build tested with 4.0 and 4.5.

---
 hw/display/xenfb.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
hw/display/xenfb.c +7 -4
index e3fdf33..f9442b7 100644
@@ -428,6 +428,7 @@ static int xenfb_map_fb(struct XenFB *xenfb)
     int n_fbdirs;
     xen_pfn_t *pgmfns = NULL;
     xen_pfn_t *fbmfns = NULL;
+    int *errs = NULL;
     void *map, *pd;
     int mode, ret = -1;
 
@@ -487,17 +488,18 @@ static int xenfb_map_fb(struct XenFB *xenfb)
 
     pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);
     fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
+    errs = g_malloc0(sizeof(int) * n_fbdirs);
 
     xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
-    map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
-			       PROT_READ, pgmfns, n_fbdirs);
+    map = xc_map_foreign_bulk(xen_xc, xenfb->c.xendev.dom,
+			      PROT_READ, pgmfns, errs, n_fbdirs);
     if (map == NULL)
 	goto out;
     xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);
     munmap(map, n_fbdirs * XC_PAGE_SIZE);
 
-    xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
-            PROT_READ, fbmfns, xenfb->fbpages);
+    xenfb->pixels = xc_map_foreign_bulk(xen_xc, xenfb->c.xendev.dom,
+            PROT_READ, fbmfns, errs, xenfb->fbpages);
     if (xenfb->pixels == NULL)
 	goto out;
 
@@ -506,6 +508,7 @@ static int xenfb_map_fb(struct XenFB *xenfb)
 out:
     g_free(pgmfns);
     g_free(fbmfns);
+    g_free(errs);
     return ret;
 }
 
Signature · 1 line
2.1.4
Acked-by on v3 4/8
#55 lore raw

Re: [PATCH QEMU-XEN v3 4/8] xen: Switch uses of xc_map_foreign_pages into xc_map_foreign_bulk

Quoted 33 lines · Ian Campbell

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 libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for this switch both uses of xc_map_foreign_pages (which both happen to be in xenfb_map_fb) to xc_map_foreign_bulk. This simply requires allocating and passing a new err array (the same one for both calls).

Build tested with 4.0 and 4.5.

---
 hw/display/xenfb.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
hw/display/xenfb.c +1 -0
index e3fdf33..f9442b7 100644
@@ -428,6 +428,7 @@ static int xenfb_map_fb(struct XenFB *xenfb)
     int n_fbdirs;
     xen_pfn_t *pgmfns = NULL;
     xen_pfn_t *fbmfns = NULL;
+    int *errs = NULL;
     void *map, *pd;
     int mode, ret = -1;
 

hw/display/xenfb.c static int xenfb_map_fb(struct XenFB *xenfb) · line 495

Quoted 10 lines
hw/display/xenfb.c +3 -2
@@ -487,17 +488,18 @@ static int xenfb_map_fb(struct XenFB *xenfb)
 
     pgmfns = g_malloc0(sizeof(xen_pfn_t) * n_fbdirs);
     fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
+    errs = g_malloc0(sizeof(int) * n_fbdirs);
 
     xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
-    map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
-			       PROT_READ, pgmfns, n_fbdirs);
+    map = xc_map_foreign_bulk(xen_xc, xenfb->c.xendev.dom,
+			      PROT_READ, pgmfns, errs, n_fbdirs);

Please take this opportunity to fix the indentation. Aside from this

Quoted 23 lines
hw/display/xenfb.c +3 -2
     if (map == NULL)
 	goto out;
     xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);
     munmap(map, n_fbdirs * XC_PAGE_SIZE);
 
-    xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
-            PROT_READ, fbmfns, xenfb->fbpages);
+    xenfb->pixels = xc_map_foreign_bulk(xen_xc, xenfb->c.xendev.dom,
+            PROT_READ, fbmfns, errs, xenfb->fbpages);
     if (xenfb->pixels == NULL)
 	goto out;
 
@@ -506,6 +508,7 @@ static int xenfb_map_fb(struct XenFB *xenfb)
 out:
     g_free(pgmfns);
     g_free(fbmfns);
+    g_free(errs);
     return ret;
 }
 
Signature · 1 line
2.1.4
#56 lore raw

PATCH v3 5/8 xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

In reply to Ian Campbell

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 libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for adding support for libxenforeignmemory add support to the <=4.0 and <=4.6 compat code in xen_common.h to allow us to switch to using the new API. These shims will disappear for versions of Xen which include libxenforeignmemory.

Since libxenforeignmemory will have its own handle type but for <= 4.6 the functionality is provided by using a libxenctrl handle we introduce a new global xen_fmem alongside the existing xen_xc. In fact we make xen_fmem a pointer to the existing xen_xc, which then works correctly with both <=4.0 (xc handle is an int) and <=4.6 (xc handle is a pointer). In the latter case xen_fmem is actually a double indirect pointer, but it all falls out in the wash.

Unlike libxenctrl libxenforeignmemory has an explicit unmap function, rather than just specifying that munmap should be used, so the unmap paths are updated to use xenforeignmemory_unmap, which is a shim for munmap on these versions of xen. The mappings in xen-hvm.c do not appear to be unmapped (which makes sense for a qemu-dm process)

In fb_disconnect this results in a change from simply mmap over the existing mapping (with an implciit munmap) to expliclty unmapping with xenforeignmemory_unmap and then mapping the required anonymous memory in the same hole. I don't think this is a problem since any other thread which was racily touching this region would already be running the risk of hitting the mapping halfway through the call. If this is thought to be a problem then we could consider adding an extra API to the libxenforeignmemory interface to replace a foreign mapping with anonymous shared memory, but I'd prefer not to.

Build tested with 4.0 and 4.5.

---
I noticed in xen_console.c that the decision to use a foreign privileged memory mapping vs a grant dev is made using different variables in con_initialise vs con_disconnect. The former uses xendev->dev while the latter uses xendev->gnttabdev. Is this a latent bug?

---
 hw/char/xen_console.c        |  8 ++++----
 hw/display/xenfb.c           | 15 ++++++++-------
 hw/xen/xen_backend.c         |  3 ++-
 include/hw/xen/xen_backend.h |  1 +
 include/hw/xen/xen_common.h  |  8 ++++++++
 xen-common.c                 |  1 +
 xen-hvm.c                    | 18 +++++++++---------
 xen-mapcache.c               |  6 +++---
 8 files changed, 36 insertions(+), 24 deletions(-)
hw/char/xen_console.c +4 -4
index 6ef477a..d28a5da 100644
@@ -230,9 +230,9 @@ static int con_initialise(struct XenDevice *xendev)
 
     if (!xendev->dev) {
 	xen_pfn_t mfn = con->ring_ref;
-        con->sring = xc_map_foreign_bulk(xen_xc, con->xendev.dom,
-					 PROT_READ|PROT_WRITE,
-					 &mfn, &err, 1);
+        con->sring = xenforeignmemory_map(xen_fmem, con->xendev.dom,
+					  PROT_READ|PROT_WRITE,
+					  &mfn, &err, 1);
     } else {
         con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
                                              con->ring_ref,
@@ -277,7 +277,7 @@ static void con_disconnect(struct XenDevice *xendev)
 
     if (con->sring) {
         if (!xendev->gnttabdev) {
-            munmap(con->sring, XC_PAGE_SIZE);
+            xenforeignmemory_unmap(xen_fmem, con->sring, XC_PAGE_SIZE);
         } else {
             xengnttab_munmap(xendev->gnttabdev, con->sring, 1);
         }
hw/display/xenfb.c +8 -7
index f9442b7..ac4ace4 100644
@@ -103,8 +103,8 @@ static int common_bind(struct common *c)
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_bulk(xen_xc, c->xendev.dom,
-				  PROT_READ | PROT_WRITE, &mfn, &err, 1);
+    c->page = xenforeignmemory_map(xen_fmem, c->xendev.dom,
+				   PROT_READ | PROT_WRITE, &mfn, &err, 1);
     if (c->page == NULL)
 	return -1;
 
@@ -119,7 +119,7 @@ static void common_unbind(struct common *c)
 {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        xenforeignmemory_unmap(xen_fmem, c->page, XC_PAGE_SIZE);
 	c->page = NULL;
     }
 }
@@ -491,14 +491,14 @@ static int xenfb_map_fb(struct XenFB *xenfb)
     errs = g_malloc0(sizeof(int) * n_fbdirs);
 
     xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
-    map = xc_map_foreign_bulk(xen_xc, xenfb->c.xendev.dom,
-			      PROT_READ, pgmfns, errs, n_fbdirs);
+    map = xenforeignmemory_map(xen_fmem, xenfb->c.xendev.dom,
+			       PROT_READ, pgmfns, errs, n_fbdirs);
     if (map == NULL)
 	goto out;
     xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);
-    munmap(map, n_fbdirs * XC_PAGE_SIZE);
+    xenforeignmemory_unmap(xen_fmem, map, n_fbdirs * XC_PAGE_SIZE);
 
-    xenfb->pixels = xc_map_foreign_bulk(xen_xc, xenfb->c.xendev.dom,
+    xenfb->pixels = xenforeignmemory_map(xen_fmem, xenfb->c.xendev.dom,
             PROT_READ, fbmfns, errs, xenfb->fbpages);
     if (xenfb->pixels == NULL)
 	goto out;
@@ -907,6 +907,7 @@ static void fb_disconnect(struct XenDevice *xendev)
      *   Replacing the framebuffer with anonymous shared memory
      *   instead.  This releases the guest pages and keeps qemu happy.
      */
+    xenforeignmemory_unmap(xen_fmem, fb->pixels, fb->fbpages * XC_PAGE_SIZE);
     fb->pixels = mmap(fb->pixels, fb->fbpages * XC_PAGE_SIZE,
                       PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON,
                       -1, 0);
hw/xen/xen_backend.c +2 -1
index 9e616c6..8b16617 100644
@@ -45,6 +45,7 @@
 
 /* public */
 XenXC xen_xc = XC_HANDLER_INITIAL_VALUE;
+xenforeignmemory_handle *xen_fmem = NULL;
 struct xs_handle *xenstore = NULL;
 const char *xen_protocol;
 
@@ -718,7 +719,7 @@ int xen_be_init(void)
         goto err;
     }
 
-    if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
+    if (xen_xc == XC_HANDLER_INITIAL_VALUE || xen_fmem == NULL) {
         /* Check if xen_init() have been called */
         goto err;
     }
include/hw/xen/xen_backend.h +1 -0
index 8e8857b..e0d52ee 100644
@@ -57,6 +57,7 @@ struct XenDevice {
 
 /* variables */
 extern XenXC xen_xc;
+extern xenforeignmemory_handle *xen_fmem;
 extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
 
include/hw/xen/xen_common.h +8 -0
index 3955d86..28f3fb1 100644
@@ -41,6 +41,7 @@ static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
 typedef int XenXC;
 typedef int xenevtchn_handle;
 typedef int xengnttab_handle;
+typedef int xenforeignmemory_handle;
 
 #  define XC_INTERFACE_FMT "%i"
 #  define XC_HANDLER_INITIAL_VALUE    -1
@@ -101,6 +102,9 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open();
 }
 
+#define xenforeignmemory_map(h,d,p,a,e,n) xc_map_foreign_bulk(*h,d,p,a,e,n)
+#define xenforeignmemory_unmap(h,p,s) munmap(p, s)
+
 static inline int xc_fd(int xen_xc)
 {
     return xen_xc;
@@ -146,6 +150,7 @@ static inline void xs_close(struct xs_handle *xsh)
 #else
 
 typedef xc_interface *XenXC;
+typedef xc_interface *xenforeignmemory_handle;
 typedef xc_evtchn xenevtchn_handle;
 typedef xc_gnttab xengnttab_handle;
 
@@ -174,6 +179,9 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open(logger, dombuild_logger, open_flags);
 }
 
+#define xenforeignmemory_map(h,d,p,a,e,n) xc_map_foreign_bulk(*h,d,p,a,e,n)
+#define xenforeignmemory_unmap(h,p,s) munmap(p, s)
+
 /* FIXME There is now way to have the xen fd */
 static inline int xc_fd(xc_interface *xen_xc)
 {
xen-common.c +1 -0
index 56359ca..d319dcb 100644
@@ -117,6 +117,7 @@ static int xen_init(MachineState *ms)
         xen_be_printf(NULL, 0, "can't open xen interface\n");
         return -1;
     }
+    xen_fmem = &xen_xc;
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
     return 0;
xen-hvm.c +9 -9
index 3a56099..9603047 100644
@@ -1213,9 +1213,9 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn);
     DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn);
 
-    state->shared_page = xc_map_foreign_bulk(xen_xc, xen_domid,
-					     PROT_READ|PROT_WRITE,
-					     &ioreq_pfn, &map_err, 1);
+    state->shared_page = xenforeignmemory_map(xen_fmem, xen_domid,
+					      PROT_READ|PROT_WRITE,
+					      &ioreq_pfn, &map_err, 1);
     if (state->shared_page == NULL) {
         hw_error("map shared IO page returned error %d (%d) handle=" XC_INTERFACE_FMT,
                  errno, map_err, xen_xc);
@@ -1225,8 +1225,8 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     if (!rc) {
         DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn);
         state->shared_vmport_page =
-		xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
-				    &ioreq_pfn, &map_err, 1);
+		xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE,
+				     &ioreq_pfn, &map_err, 1);
         if (state->shared_vmport_page == NULL) {
             hw_error("map shared vmport IO page returned error %d (%d) handle="
                      XC_INTERFACE_FMT, errno, map_err, xen_xc);
@@ -1235,10 +1235,10 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
         hw_error("get vmport regs pfn returned error %d, rc=%d", errno, rc);
     }
 
-    state->buffered_io_page = xc_map_foreign_bulk(xen_xc, xen_domid,
-						  PROT_READ|PROT_WRITE,
-                                                  &bufioreq_pfn,
-						  &map_err, 1);
+    state->buffered_io_page = xenforeignmemory_map(xen_fmem, xen_domid,
+						   PROT_READ|PROT_WRITE,
+						   &bufioreq_pfn,
+						   &map_err, 1);
     if (state->buffered_io_page == NULL) {
         hw_error("map buffered IO page returned error %d (%d)", errno, map_err);
     }
xen-mapcache.c +3 -3
index 66da1a6..223fe4d 100644
@@ -169,10 +169,10 @@ static void xen_remap_bucket(MapCacheEntry *entry,
         pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i;
     }
 
-    vaddr_base = xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
-                                     pfns, err, nb_pfn);
+    vaddr_base = xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE,
+				      pfns, err, nb_pfn);
     if (vaddr_base == NULL) {
-        perror("xc_map_foreign_bulk");
+        perror("xenforeignmemory_map");
         exit(-1);
     }
 
Signature · 1 line
2.1.4
#57 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

Quoted 39 lines · Ian Campbell

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 libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for adding support for libxenforeignmemory add support to the <=4.0 and <=4.6 compat code in xen_common.h to allow us to switch to using the new API. These shims will disappear for versions of Xen which include libxenforeignmemory.

Since libxenforeignmemory will have its own handle type but for <= 4.6 the functionality is provided by using a libxenctrl handle we introduce a new global xen_fmem alongside the existing xen_xc. In fact we make xen_fmem a pointer to the existing xen_xc, which then works correctly with both <=4.0 (xc handle is an int) and <=4.6 (xc handle is a pointer). In the latter case xen_fmem is actually a double indirect pointer, but it all falls out in the wash.

Unlike libxenctrl libxenforeignmemory has an explicit unmap function, rather than just specifying that munmap should be used, so the unmap paths are updated to use xenforeignmemory_unmap, which is a shim for munmap on these versions of xen. The mappings in xen-hvm.c do not appear to be unmapped (which makes sense for a qemu-dm process)

In fb_disconnect this results in a change from simply mmap over the existing mapping (with an implciit munmap) to expliclty unmapping with xenforeignmemory_unmap and then mapping the required anonymous memory in the same hole. I don't think this is a problem since any other thread which was racily touching this region would already be running the risk of hitting the mapping halfway through the call. If this is thought to be a problem then we could consider adding an extra API to the libxenforeignmemory interface to replace a foreign mapping with anonymous shared memory, but I'd prefer not to.

Build tested with 4.0 and 4.5.

Quoted 7 lines

---
I noticed in xen_console.c that the decision to use a foreign privileged memory mapping vs a grant dev is made using different variables in con_initialise vs con_disconnect. The former uses xendev->dev while the latter uses xendev->gnttabdev. Is this a latent bug?

The code in con_disconnect is superfluous: the initial check

    if (!xendev->dev) {
        return;
    }

makes sure the rest of the function only deals with dev != 0. I guess it should be

    if (!xendev->dev) {
        munmap(con->sring, XC_PAGE_SIZE);
        return;
    }
Quoted 237 lines
---
 hw/char/xen_console.c        |  8 ++++----
 hw/display/xenfb.c           | 15 ++++++++-------
 hw/xen/xen_backend.c         |  3 ++-
 include/hw/xen/xen_backend.h |  1 +
 include/hw/xen/xen_common.h  |  8 ++++++++
 xen-common.c                 |  1 +
 xen-hvm.c                    | 18 +++++++++---------
 xen-mapcache.c               |  6 +++---
 8 files changed, 36 insertions(+), 24 deletions(-)
hw/char/xen_console.c +4 -4
index 6ef477a..d28a5da 100644
@@ -230,9 +230,9 @@ static int con_initialise(struct XenDevice *xendev)
 
     if (!xendev->dev) {
 	xen_pfn_t mfn = con->ring_ref;
-        con->sring = xc_map_foreign_bulk(xen_xc, con->xendev.dom,
-					 PROT_READ|PROT_WRITE,
-					 &mfn, &err, 1);
+        con->sring = xenforeignmemory_map(xen_fmem, con->xendev.dom,
+					  PROT_READ|PROT_WRITE,
+					  &mfn, &err, 1);
     } else {
         con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
                                              con->ring_ref,
@@ -277,7 +277,7 @@ static void con_disconnect(struct XenDevice *xendev)
 
     if (con->sring) {
         if (!xendev->gnttabdev) {
-            munmap(con->sring, XC_PAGE_SIZE);
+            xenforeignmemory_unmap(xen_fmem, con->sring, XC_PAGE_SIZE);
         } else {
             xengnttab_munmap(xendev->gnttabdev, con->sring, 1);
         }
hw/display/xenfb.c +8 -7
index f9442b7..ac4ace4 100644
@@ -103,8 +103,8 @@ static int common_bind(struct common *c)
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_bulk(xen_xc, c->xendev.dom,
-				  PROT_READ | PROT_WRITE, &mfn, &err, 1);
+    c->page = xenforeignmemory_map(xen_fmem, c->xendev.dom,
+				   PROT_READ | PROT_WRITE, &mfn, &err, 1);
     if (c->page == NULL)
 	return -1;
 
@@ -119,7 +119,7 @@ static void common_unbind(struct common *c)
 {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        xenforeignmemory_unmap(xen_fmem, c->page, XC_PAGE_SIZE);
 	c->page = NULL;
     }
 }
@@ -491,14 +491,14 @@ static int xenfb_map_fb(struct XenFB *xenfb)
     errs = g_malloc0(sizeof(int) * n_fbdirs);
 
     xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
-    map = xc_map_foreign_bulk(xen_xc, xenfb->c.xendev.dom,
-			      PROT_READ, pgmfns, errs, n_fbdirs);
+    map = xenforeignmemory_map(xen_fmem, xenfb->c.xendev.dom,
+			       PROT_READ, pgmfns, errs, n_fbdirs);
     if (map == NULL)
 	goto out;
     xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);
-    munmap(map, n_fbdirs * XC_PAGE_SIZE);
+    xenforeignmemory_unmap(xen_fmem, map, n_fbdirs * XC_PAGE_SIZE);
 
-    xenfb->pixels = xc_map_foreign_bulk(xen_xc, xenfb->c.xendev.dom,
+    xenfb->pixels = xenforeignmemory_map(xen_fmem, xenfb->c.xendev.dom,
             PROT_READ, fbmfns, errs, xenfb->fbpages);
     if (xenfb->pixels == NULL)
 	goto out;
@@ -907,6 +907,7 @@ static void fb_disconnect(struct XenDevice *xendev)
      *   Replacing the framebuffer with anonymous shared memory
      *   instead.  This releases the guest pages and keeps qemu happy.
      */
+    xenforeignmemory_unmap(xen_fmem, fb->pixels, fb->fbpages * XC_PAGE_SIZE);
     fb->pixels = mmap(fb->pixels, fb->fbpages * XC_PAGE_SIZE,
                       PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON,
                       -1, 0);
hw/xen/xen_backend.c +2 -1
index 9e616c6..8b16617 100644
@@ -45,6 +45,7 @@
 
 /* public */
 XenXC xen_xc = XC_HANDLER_INITIAL_VALUE;
+xenforeignmemory_handle *xen_fmem = NULL;
 struct xs_handle *xenstore = NULL;
 const char *xen_protocol;
 
@@ -718,7 +719,7 @@ int xen_be_init(void)
         goto err;
     }
 
-    if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
+    if (xen_xc == XC_HANDLER_INITIAL_VALUE || xen_fmem == NULL) {
         /* Check if xen_init() have been called */
         goto err;
     }
include/hw/xen/xen_backend.h +1 -0
index 8e8857b..e0d52ee 100644
@@ -57,6 +57,7 @@ struct XenDevice {
 
 /* variables */
 extern XenXC xen_xc;
+extern xenforeignmemory_handle *xen_fmem;
 extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
 
include/hw/xen/xen_common.h +8 -0
index 3955d86..28f3fb1 100644
@@ -41,6 +41,7 @@ static inline void *xc_map_foreign_bulk(int xc_handle, uint32_t dom, int prot,
 typedef int XenXC;
 typedef int xenevtchn_handle;
 typedef int xengnttab_handle;
+typedef int xenforeignmemory_handle;
 
 #  define XC_INTERFACE_FMT "%i"
 #  define XC_HANDLER_INITIAL_VALUE    -1
@@ -101,6 +102,9 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open();
 }
 
+#define xenforeignmemory_map(h,d,p,a,e,n) xc_map_foreign_bulk(*h,d,p,a,e,n)
+#define xenforeignmemory_unmap(h,p,s) munmap(p, s)
+
 static inline int xc_fd(int xen_xc)
 {
     return xen_xc;
@@ -146,6 +150,7 @@ static inline void xs_close(struct xs_handle *xsh)
 #else
 
 typedef xc_interface *XenXC;
+typedef xc_interface *xenforeignmemory_handle;
 typedef xc_evtchn xenevtchn_handle;
 typedef xc_gnttab xengnttab_handle;
 
@@ -174,6 +179,9 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open(logger, dombuild_logger, open_flags);
 }
 
+#define xenforeignmemory_map(h,d,p,a,e,n) xc_map_foreign_bulk(*h,d,p,a,e,n)
+#define xenforeignmemory_unmap(h,p,s) munmap(p, s)
+
 /* FIXME There is now way to have the xen fd */
 static inline int xc_fd(xc_interface *xen_xc)
 {
xen-common.c +1 -0
index 56359ca..d319dcb 100644
@@ -117,6 +117,7 @@ static int xen_init(MachineState *ms)
         xen_be_printf(NULL, 0, "can't open xen interface\n");
         return -1;
     }
+    xen_fmem = &xen_xc;
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
     return 0;
xen-hvm.c +9 -9
index 3a56099..9603047 100644
@@ -1213,9 +1213,9 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn);
     DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn);
 
-    state->shared_page = xc_map_foreign_bulk(xen_xc, xen_domid,
-					     PROT_READ|PROT_WRITE,
-					     &ioreq_pfn, &map_err, 1);
+    state->shared_page = xenforeignmemory_map(xen_fmem, xen_domid,
+					      PROT_READ|PROT_WRITE,
+					      &ioreq_pfn, &map_err, 1);
     if (state->shared_page == NULL) {
         hw_error("map shared IO page returned error %d (%d) handle=" XC_INTERFACE_FMT,
                  errno, map_err, xen_xc);
@@ -1225,8 +1225,8 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
     if (!rc) {
         DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn);
         state->shared_vmport_page =
-		xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
-				    &ioreq_pfn, &map_err, 1);
+		xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE,
+				     &ioreq_pfn, &map_err, 1);
         if (state->shared_vmport_page == NULL) {
             hw_error("map shared vmport IO page returned error %d (%d) handle="
                      XC_INTERFACE_FMT, errno, map_err, xen_xc);
@@ -1235,10 +1235,10 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,
         hw_error("get vmport regs pfn returned error %d, rc=%d", errno, rc);
     }
 
-    state->buffered_io_page = xc_map_foreign_bulk(xen_xc, xen_domid,
-						  PROT_READ|PROT_WRITE,
-                                                  &bufioreq_pfn,
-						  &map_err, 1);
+    state->buffered_io_page = xenforeignmemory_map(xen_fmem, xen_domid,
+						   PROT_READ|PROT_WRITE,
+						   &bufioreq_pfn,
+						   &map_err, 1);
     if (state->buffered_io_page == NULL) {
         hw_error("map buffered IO page returned error %d (%d)", errno, map_err);
     }
xen-mapcache.c +3 -3
index 66da1a6..223fe4d 100644
@@ -169,10 +169,10 @@ static void xen_remap_bucket(MapCacheEntry *entry,
         pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i;
     }
 
-    vaddr_base = xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
-                                     pfns, err, nb_pfn);
+    vaddr_base = xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE,
+				      pfns, err, nb_pfn);
     if (vaddr_base == NULL) {
-        perror("xc_map_foreign_bulk");
+        perror("xenforeignmemory_map");
         exit(-1);
     }
 
Signature · 1 line
2.1.4
#58 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

Quoted 50 lines · Stefano Stabellini
Quoted 39 lines · Ian Campbell

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 libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for adding support for libxenforeignmemory add support to the <=4.0 and <=4.6 compat code in xen_common.h to allow us to switch to using the new API. These shims will disappear for versions of Xen which include libxenforeignmemory.

Since libxenforeignmemory will have its own handle type but for <= 4.6 the functionality is provided by using a libxenctrl handle we introduce a new global xen_fmem alongside the existing xen_xc. In fact we make xen_fmem a pointer to the existing xen_xc, which then works correctly with both <=4.0 (xc handle is an int) and <=4.6 (xc handle is a pointer). In the latter case xen_fmem is actually a double indirect pointer, but it all falls out in the wash.

Unlike libxenctrl libxenforeignmemory has an explicit unmap function, rather than just specifying that munmap should be used, so the unmap paths are updated to use xenforeignmemory_unmap, which is a shim for munmap on these versions of xen. The mappings in xen-hvm.c do not appear to be unmapped (which makes sense for a qemu-dm process)

In fb_disconnect this results in a change from simply mmap over the existing mapping (with an implciit munmap) to expliclty unmapping with xenforeignmemory_unmap and then mapping the required anonymous memory in the same hole. I don't think this is a problem since any other thread which was racily touching this region would already be running the risk of hitting the mapping halfway through the call. If this is thought to be a problem then we could consider adding an extra API to the libxenforeignmemory interface to replace a foreign mapping with anonymous shared memory, but I'd prefer not to.

Build tested with 4.0 and 4.5.

Quoted 7 lines

---
I noticed in xen_console.c that the decision to use a foreign privileged memory mapping vs a grant dev is made using different variables in con_initialise vs con_disconnect. The former uses xendev->dev while the latter uses xendev->gnttabdev. Is this a latent bug?

The code in con_disconnect is superfluous: the initial check

Quoted 8 lines
    if (!xendev->dev) {
        return;
    }

makes sure the rest of the function only deals with dev != 0. I guess it should be

    if (!xendev->dev) {

Did you mean xendev->gnttabdev here? Since this is what the code is touching.

Should ->dev and ->gnttabdev be either both set or neither then?

Since con_connect uses the former to decide it would seem logical for teardown to use the same condition, but I don't know if I'm missing something. In particular given the initial check you point to how is the foreign mapping not already leaked today if the lifecycle of ->dev and ->gnttabdev are strictly aligned?

Quoted 1 line
        munmap(con->sring, XC_PAGE_SIZE);

And this is how the code should be _now_, i.e. with this patch it should become xenforeignmemory_unmap?

Ian.

#59 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

Quoted 58 lines · Ian Campbell
Quoted 57 lines · Stefano Stabellini
Quoted 39 lines · Ian Campbell

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 libxenforeignmemory which provides access to privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for adding support for libxenforeignmemory add support to the <=4.0 and <=4.6 compat code in xen_common.h to allow us to switch to using the new API. These shims will disappear for versions of Xen which include libxenforeignmemory.

Since libxenforeignmemory will have its own handle type but for <= 4.6 the functionality is provided by using a libxenctrl handle we introduce a new global xen_fmem alongside the existing xen_xc. In fact we make xen_fmem a pointer to the existing xen_xc, which then works correctly with both <=4.0 (xc handle is an int) and <=4.6 (xc handle is a pointer). In the latter case xen_fmem is actually a double indirect pointer, but it all falls out in the wash.

Unlike libxenctrl libxenforeignmemory has an explicit unmap function, rather than just specifying that munmap should be used, so the unmap paths are updated to use xenforeignmemory_unmap, which is a shim for munmap on these versions of xen. The mappings in xen-hvm.c do not appear to be unmapped (which makes sense for a qemu-dm process)

In fb_disconnect this results in a change from simply mmap over the existing mapping (with an implciit munmap) to expliclty unmapping with xenforeignmemory_unmap and then mapping the required anonymous memory in the same hole. I don't think this is a problem since any other thread which was racily touching this region would already be running the risk of hitting the mapping halfway through the call. If this is thought to be a problem then we could consider adding an extra API to the libxenforeignmemory interface to replace a foreign mapping with anonymous shared memory, but I'd prefer not to.

Build tested with 4.0 and 4.5.

Quoted 7 lines

---
I noticed in xen_console.c that the decision to use a foreign privileged memory mapping vs a grant dev is made using different variables in con_initialise vs con_disconnect. The former uses xendev->dev while the latter uses xendev->gnttabdev. Is this a latent bug?

The code in con_disconnect is superfluous: the initial check

    if (!xendev->dev) {
        return;
    }

makes sure the rest of the function only deals with dev != 0. I guess it should be

Quoted 6 lines
Quoted 1 line
    if (!xendev->dev) {

Did you mean xendev->gnttabdev here? Since this is what the code is touching.

Should ->dev and ->gnttabdev be either both set or neither then?

That's right

Quoted 10 lines

Since con_connect uses the former to decide it would seem logical for teardown to use the same condition, but I don't know if I'm missing something. In particular given the initial check you point to how is the foreign mapping not already leaked today if the lifecycle of ->dev and ->gnttabdev are strictly aligned?

Quoted 1 line
        munmap(con->sring, XC_PAGE_SIZE);

And this is how the code should be _now_, i.e. with this patch it should become xenforeignmemory_unmap?

Yes, I think that today it is leaked, but in practice there is one QEMU process per VM and the VM never disconnect/reconnect the primary console (I don't think there is a way to do that). In other words, after con_disconnect, QEMU is killed.

#60 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

Quoted 94 lines · Stefano Stabellini
Quoted 74 lines · Ian Campbell
Quoted 73 lines · Stefano Stabellini
Quoted 54 lines · Ian Campbell

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 libxenforeignmemory which provides access to
privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for adding support for libxenforeignmemory add support
to the <=4.0 and <=4.6 compat code in xen_common.h to allow us to switch to using the new API. These shims will disappear for versions
of Xen which include libxenforeignmemory.

Since libxenforeignmemory will have its own handle type but for <= 4.6
the functionality is provided by using a libxenctrl handle we introduce a new global xen_fmem alongside the existing xen_xc. In fact
we make xen_fmem a pointer to the existing xen_xc, which then works correctly with both <=4.0 (xc handle is an int) and <=4.6 (xc handle
is a pointer). In the latter case xen_fmem is actually a double indirect pointer, but it all falls out in the wash.

Unlike libxenctrl libxenforeignmemory has an explicit unmap function,
rather than just specifying that munmap should be used, so the unmap
paths are updated to use xenforeignmemory_unmap, which is a shim for
munmap on these versions of xen. The mappings in xen-hvm.c do not appear to be unmapped (which makes sense for a qemu-dm process)

In fb_disconnect this results in a change from simply mmap over the existing mapping (with an implciit munmap) to expliclty unmapping with
xenforeignmemory_unmap and then mapping the required anonymous memory
in the same hole. I don't think this is a problem since any other thread which was racily touching this region would already be running
the risk of hitting the mapping halfway through the call. If this is
thought to be a problem then we could consider adding an extra API to
the libxenforeignmemory interface to replace a foreign mapping with anonymous shared memory, but I'd prefer not to.

Build tested with 4.0 and 4.5.

Quoted 8 lines

---
I noticed in xen_console.c that the decision to use a foreign privileged memory mapping vs a grant dev is made using different variables in con_initialise vs con_disconnect. The former uses xendev->dev while the latter uses xendev->gnttabdev. Is this a latent
bug?

The code in con_disconnect is superfluous: the initial check

    if (!xendev->dev) {
        return;
    }

makes sure the rest of the function only deals with dev != 0. I guess it should be

Quoted 6 lines
Quoted 1 line
    if (!xendev->dev) {

Did you mean xendev->gnttabdev here? Since this is what the code is touching.

Should ->dev and ->gnttabdev be either both set or neither then?

That's right

Quoted 9 lines

Since con_connect uses the former to decide it would seem logical for teardown to use the same condition, but I don't know if I'm missing something. In particular given the initial check you point to how is the
foreign mapping not already leaked today if the lifecycle of ->dev and ->gnttabdev are strictly aligned?

Quoted 1 line
        munmap(con->sring, XC_PAGE_SIZE);
Quoted 8 lines
Quoted 3 lines

And this is how the code should be _now_, i.e. with this patch it should
become xenforeignmemory_unmap?

Yes, I think that today it is leaked, but in practice there is one QEMU process per VM and the VM never disconnect/reconnect the primary console (I don't think there is a way to do that). In other words, after con_disconnect, QEMU is killed.

Part of the reason for xenforeignmemory_unmap is so that we can make things like valgrind more aware of what is going on, so having this happen even if things are about to exit is still useful.

I came up with the following patch which I will insert at the front of v4, but I have one doubt, namely are the calls to qemu_chr_add_handler and qemu_chr_fe_release not useful here too?

Obviously the call to xen_be_unbind_evtchn is not useful as is, but I do wonder where the evtchn which the primary console must have somewhere actually is then...

Maybe the reasoning here is the same "we are going to exit anyway", and maybe this cleanup isn't the sort of thing valgrind will complain about (i.e. neither of them free any memory), in which case they may as well be left as is.

Ian.

commit 8d706e73b799efe0dd8268e085e572f31a6245d3

Author: Ian Campbell <[email protected]>
Date:   Wed Oct 14 16:49:25 2015 +0100

xen_console: correctly unmap primary console on teardown.

The ->dev and ->gnttabdev handles are either both set or neither. This means that we never reach the existing unmap.

---
v4: New patch based on feedback to "xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API."

hw/char/xen_console.c +5 -5
index eb7f450..b6f0029 100644
@@ -266,6 +266,10 @@ static void con_disconnect(struct XenDevice *xendev)
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
 
     if (!xendev->dev) {
+        if (con->string) {
+            munmap(con->sring, XC_PAGE_SIZE);
+            con->sring = NULL;
+        }
         return;
     }
     if (con->chr) {
@@ -275,11 +279,7 @@ static void con_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&con->xendev);
 
     if (con->sring) {
-        if (!xendev->gnttabdev) {
-            munmap(con->sring, XC_PAGE_SIZE);
-        } else {
-            xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1);
-        }
+        xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1);
 	con->sring = NULL;
     }
 }
#61 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

Quoted 4 lines · Ian Campbell

I came up with the following patch[...]

     if (!xendev->dev) {

+ if (con->string) {

I've fixed the obvious typo in my actual tree...

Quoted 4 lines
hw/char/xen_console.c +3 -0
+            munmap(con->sring, XC_PAGE_SIZE);
+            con->sring = NULL;
+        }
         return;
#62 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

In reply to Ian Campbell
Quoted 104 lines · Ian Campbell
Quoted 94 lines · Stefano Stabellini
Quoted 74 lines · Ian Campbell
Quoted 73 lines · Stefano Stabellini
Quoted 54 lines · Ian Campbell

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 libxenforeignmemory which provides access to
privileged foreign mappings and which will provide an interface equivalent to xc_map_foreign_bulk.

In preparation for adding support for libxenforeignmemory add support
to the <=4.0 and <=4.6 compat code in xen_common.h to allow us to switch to using the new API. These shims will disappear for versions
of Xen which include libxenforeignmemory.

Since libxenforeignmemory will have its own handle type but for <= 4.6
the functionality is provided by using a libxenctrl handle we introduce a new global xen_fmem alongside the existing xen_xc. In fact
we make xen_fmem a pointer to the existing xen_xc, which then works correctly with both <=4.0 (xc handle is an int) and <=4.6 (xc handle
is a pointer). In the latter case xen_fmem is actually a double indirect pointer, but it all falls out in the wash.

Unlike libxenctrl libxenforeignmemory has an explicit unmap function,
rather than just specifying that munmap should be used, so the unmap
paths are updated to use xenforeignmemory_unmap, which is a shim for
munmap on these versions of xen. The mappings in xen-hvm.c do not appear to be unmapped (which makes sense for a qemu-dm process)

In fb_disconnect this results in a change from simply mmap over the existing mapping (with an implciit munmap) to expliclty unmapping with
xenforeignmemory_unmap and then mapping the required anonymous memory
in the same hole. I don't think this is a problem since any other thread which was racily touching this region would already be running
the risk of hitting the mapping halfway through the call. If this is
thought to be a problem then we could consider adding an extra API to
the libxenforeignmemory interface to replace a foreign mapping with anonymous shared memory, but I'd prefer not to.

Build tested with 4.0 and 4.5.

Quoted 8 lines

---
I noticed in xen_console.c that the decision to use a foreign privileged memory mapping vs a grant dev is made using different variables in con_initialise vs con_disconnect. The former uses xendev->dev while the latter uses xendev->gnttabdev. Is this a latent
bug?

The code in con_disconnect is superfluous: the initial check

    if (!xendev->dev) {
        return;
    }

makes sure the rest of the function only deals with dev != 0. I guess it should be

Quoted 6 lines
Quoted 1 line
    if (!xendev->dev) {

Did you mean xendev->gnttabdev here? Since this is what the code is touching.

Should ->dev and ->gnttabdev be either both set or neither then?

That's right

Quoted 9 lines

Since con_connect uses the former to decide it would seem logical for teardown to use the same condition, but I don't know if I'm missing something. In particular given the initial check you point to how is the
foreign mapping not already leaked today if the lifecycle of ->dev and ->gnttabdev are strictly aligned?

Quoted 1 line
        munmap(con->sring, XC_PAGE_SIZE);
Quoted 8 lines
Quoted 3 lines

And this is how the code should be _now_, i.e. with this patch it should
become xenforeignmemory_unmap?

Yes, I think that today it is leaked, but in practice there is one QEMU process per VM and the VM never disconnect/reconnect the primary console (I don't think there is a way to do that). In other words, after con_disconnect, QEMU is killed.

Quoted 7 lines

Part of the reason for xenforeignmemory_unmap is so that we can make things like valgrind more aware of what is going on, so having this happen even if things are about to exit is still useful.

I came up with the following patch which I will insert at the front of v4, but I have one doubt, namely are the calls to qemu_chr_add_handler and qemu_chr_fe_release not useful here too?

Yes, it looks like they might be useful.

Quoted 3 lines

Obviously the call to xen_be_unbind_evtchn is not useful as is, but I do wonder where the evtchn which the primary console must have somewhere actually is then...

Actually I think that xen_be_unbind_evtchn might be useful too, I think that is the primary console evtchn. I wonder what specific bug I was trying to fix when I introduced that if (!xendev->dev) check.

Quoted 4 lines

Maybe the reasoning here is the same "we are going to exit anyway", and maybe this cleanup isn't the sort of thing valgrind will complain about (i.e. neither of them free any memory), in which case they may as well be left as is.

I don't know, but you have a valid point valgrid.

Quoted 6 lines

commit 8d706e73b799efe0dd8268e085e572f31a6245d3

Author: Ian Campbell <[email protected]>
Date:   Wed Oct 14 16:49:25 2015 +0100

xen_console: correctly unmap primary console on teardown.

Quoted 7 lines

The ->dev and ->gnttabdev handles are either both set or neither. This means that we never reach the existing unmap.

---
v4: New patch based on feedback to "xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API."

Makes sense

Quoted 29 lines
hw/char/xen_console.c +5 -5
index eb7f450..b6f0029 100644
@@ -266,6 +266,10 @@ static void con_disconnect(struct XenDevice *xendev)
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
 
     if (!xendev->dev) {
+        if (con->string) {
+            munmap(con->sring, XC_PAGE_SIZE);
+            con->sring = NULL;
+        }
         return;
     }
     if (con->chr) {
@@ -275,11 +279,7 @@ static void con_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&con->xendev);
 
     if (con->sring) {
-        if (!xendev->gnttabdev) {
-            munmap(con->sring, XC_PAGE_SIZE);
-        } else {
-            xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1);
-        }
+        xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1);
 	con->sring = NULL;
     }
 }
#63 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

Quoted 7 lines · Stefano Stabellini
Quoted 3 lines

Obviously the call to xen_be_unbind_evtchn is not useful as is, but I do wonder where the evtchn which the primary console must have somewhere actually is then...

Actually I think that xen_be_unbind_evtchn might be useful too, I think that is the primary console evtchn. I wonder what specific bug I was trying to fix when I introduced that if (!xendev->dev) check.

I misread xen_be_unbind_evtchn(&con->xendev) as taking xendev->dev instead, which would be NULL and hence pointless... But given that it isn't then yes it seems like it would be worth calling.

Is it not the case that &con->xendev == xendev here, leading to another potential cleanup?

Ian.

#64 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

Quoted 10 lines · Ian Campbell
Quoted 7 lines · Stefano Stabellini
Quoted 3 lines

Obviously the call to xen_be_unbind_evtchn is not useful as is, but I do wonder where the evtchn which the primary console must have somewhere actually is then...

Actually I think that xen_be_unbind_evtchn might be useful too, I think that is the primary console evtchn. I wonder what specific bug I was trying to fix when I introduced that if (!xendev->dev) check.

Quoted 6 lines

I misread xen_be_unbind_evtchn(&con->xendev) as taking xendev->dev instead, which would be NULL and hence pointless... But given that it isn't then yes it seems like it would be worth calling.

Is it not the case that &con->xendev == xendev here, leading to another potential cleanup?

Yes, it is the same

#65 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

Quoted 20 lines · Stefano Stabellini
Quoted 19 lines · Ian Campbell
Quoted 10 lines · Stefano Stabellini
Quoted 5 lines

Obviously the call to xen_be_unbind_evtchn is not useful as is, but I do
wonder where the evtchn which the primary console must have somewhere
actually is then...

Actually I think that xen_be_unbind_evtchn might be useful too, I think
that is the primary console evtchn. I wonder what specific bug I was trying to fix when I introduced that if (!xendev->dev) check.

I misread xen_be_unbind_evtchn(&con->xendev) as taking xendev->dev instead,
which would be NULL and hence pointless... But given that it isn't then yes
it seems like it would be worth calling.

Quoted 4 lines
Quoted 2 lines

Is it not the case that &con->xendev == xendev here, leading to another potential cleanup?

Yes, it is the same

I ended up with this at the head of the queue. I've not tested yet, how would I, AFAIK this code is mainly to do with the PV guest console, which would normally be handled by xenconsoled and not qemu at all. Can I force this to run for HVM guests or can I force a PV guest not to use xenconsoled (hacky ways are fine)?

Ian.

commit cbb9efe66938e44cc9ecca5a4c15cecced7f1385

Author: Ian Campbell <[email protected]>
Date:   Wed Oct 14 16:49:25 2015 +0100

xen_console: correctly cleanup primary console on teardown.

All of the work in con_disconnect applies to the primary console case (when xendev->dev is NULL). Therefore remove the early check and bail and allow it to fall through. All of the existing code is correctly conditional already.

The ->dev and ->gnttabdev handles are either both set or neither. For consistency with con_initialise() with to the former here too.

With this con_initialise and con_disconnect now mirror each other.

Fix up a hard tab in the function while editing.

---
v4: New patch based on feedback to "xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API."

hw/char/xen_console.c +2 -5
index eb7f450..63ade33 100644
@@ -265,9 +265,6 @@ static void con_disconnect(struct XenDevice *xendev)
 {
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
 
-    if (!xendev->dev) {
-        return;
-    }
     if (con->chr) {
         qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL);
         qemu_chr_fe_release(con->chr);
@@ -275,12 +272,12 @@ static void con_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&con->xendev);
 
     if (con->sring) {
-        if (!xendev->gnttabdev) {
+        if (!xendev->dev) {
             munmap(con->sring, XC_PAGE_SIZE);
         } else {
             xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1);
         }
-	con->sring = NULL;
+        con->sring = NULL;
     }
 }
#66 lore raw

Re: [PATCH QEMU-XEN v3 5/8] xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API.

Quoted 24 lines · Ian Campbell
Quoted 23 lines · Stefano Stabellini
Quoted 21 lines · Ian Campbell
Quoted 10 lines · Stefano Stabellini
Quoted 5 lines

Obviously the call to xen_be_unbind_evtchn is not useful as is, but I do
wonder where the evtchn which the primary console must have somewhere
actually is then...

Actually I think that xen_be_unbind_evtchn might be useful too, I think
that is the primary console evtchn. I wonder what specific bug I was trying to fix when I introduced that if (!xendev->dev) check.

I misread xen_be_unbind_evtchn(&con->xendev) as taking xendev->dev instead,
which would be NULL and hence pointless... But given that it isn't then yes
it seems like it would be worth calling.

Is it not the case that &con->xendev == xendev here, leading to another potential cleanup?

Quoted 7 lines
Quoted 1 line

Yes, it is the same

I ended up with this at the head of the queue. I've not tested yet, how would I, AFAIK this code is mainly to do with the PV guest console, which would normally be handled by xenconsoled and not qemu at all. Can I force this to run for HVM guests or can I force a PV guest not to use xenconsoled (hacky ways are fine)?

Yes, you just need to set consback to LIBXL__CONSOLE_BACKEND_IOEMU. Replacing LIBXL__CONSOLE_BACKEND_XENCONSOLED with LIBXL__CONSOLE_BACKEND_IOEMU in init_console_info is probably enough.

Quoted 11 lines

commit cbb9efe66938e44cc9ecca5a4c15cecced7f1385

Author: Ian Campbell <[email protected]>
Date:   Wed Oct 14 16:49:25 2015 +0100

xen_console: correctly cleanup primary console on teardown.

All of the work in con_disconnect applies to the primary console case (when xendev->dev is NULL). Therefore remove the early check and bail and allow it to fall through. All of the existing code is correctly conditional already.

Quoted 8 lines

The ->dev and ->gnttabdev handles are either both set or neither. For consistency with con_initialise() with to the former here too.

With this con_initialise and con_disconnect now mirror each other.

Fix up a hard tab in the function while editing.

I think it's good.

Quoted 34 lines

---
v4: New patch based on feedback to "xen: Switch uses of xc_map_foreign_bulk to use libxenforeignmemory API."

hw/char/xen_console.c +2 -5
index eb7f450..63ade33 100644
@@ -265,9 +265,6 @@ static void con_disconnect(struct XenDevice *xendev)
 {
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
 
-    if (!xendev->dev) {
-        return;
-    }
     if (con->chr) {
         qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL);
         qemu_chr_fe_release(con->chr);
@@ -275,12 +272,12 @@ static void con_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&con->xendev);
 
     if (con->sring) {
-        if (!xendev->gnttabdev) {
+        if (!xendev->dev) {
             munmap(con->sring, XC_PAGE_SIZE);
         } else {
             xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1);
         }
-	con->sring = NULL;
+        con->sring = NULL;
     }
 }
 
#67 lore raw

PATCH v3 6/8 xen: Use stable library interfaces when they are available.

In reply to Ian Campbell

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.

Specifically libxenevtchn, libxengnttab and libxenforeignmemory.

Previous patches have already laid the groundwork for using these by switching the existing compatibility shims to reflect the intefaces to these libraries.

So all which remains is to update configure to detect the libraries and enable their use. Although they are notionally independent we take an all or nothing approach to the three libraries since they were added at the same time.

The only non-obvious bit is that we now open a proper xenforeignmemory handle for xen_fmem instead of reusing the xen_xc handle.

Build tested with 4.0, 4.5 and the patches targetting 4.7 which adds these libraries.

---
 configure                   | 98 ++++++++++++++++++++++++++++++++++++++++++++-
 include/hw/xen/xen_common.h | 42 ++++++++++++++++++-
 xen-common.c                |  9 +++++
 3 files changed, 145 insertions(+), 4 deletions(-)
configure +96 -2
index 779623a..508b157 100755
@@ -1839,6 +1839,52 @@ fi
 # xen probe
 
 if test "$xen" != "no" ; then
+  xenevtchn_libs="-lxenevtchn"
+
+  cat > $TMPC <<EOF
+#include <xenevtchn.h>
+int main(void) { return 0; }
+EOF
+  if compile_prog "" "$xenevtchn_libs" ; then
+      xenevtchn=yes
+  else
+      xenevtchn=no
+  fi
+
+  xengnttab_libs="-lxengnttab"
+
+  cat > $TMPC <<EOF
+#include <xengnttab.h>
+int main(void) { return 0; }
+EOF
+  if compile_prog "" "$xengnttab_libs" ; then
+      xengnttab=yes
+  else
+      xengnttab=no
+  fi
+
+  xenforeignmemory_libs="-lxenforeignmemory"
+
+  cat > $TMPC <<EOF
+#include <xenforeignmemory.h>
+int main(void) { return 0; }
+EOF
+  if compile_prog "" "$xenforeignmemory_libs" ; then
+      xenforeignmemory=yes
+  else
+      xenforeignmemory=no
+  fi
+
+  # These libraries were all introduced in the same release, to
+  # simplify things we therefore assume its either all or nothing and
+  # treat any other mix as an error
+  case $xenevtchn$xengnttab$xenforeignmemory in
+      yesyesyes) xenstablelibs=yes;;
+      nonono)    xenstablelibs=no;;
+      *)         error_exit "Inconsistent set of xen libraries found"
+	  ;;
+  esac
+
   xen_libs="-lxenstore -lxenctrl -lxenguest"
 
   # First we test whether Xen headers and libraries are available.
@@ -1859,7 +1905,46 @@ EOF
     fi
     xen=no
 
-  # Xen unstable
+  # Xen unstable (with stable libs)
+  elif
+      # If we have stable libs the we don't want the libxc compat
+      # layers, regardless of what CFLAGS we may have been given.
+      test "$xenstablelibs" = "yes" &&
+      cat > $TMPC <<EOF &&
+#undef XC_WANT_COMPAT_EVTCHN_API
+#undef XC_WANT_COMPAT_GNTTAB_API
+#undef XC_WANT_COMPAT_MAP_FOREIGN_API
+#include <xenctrl.h>
+#include <xenstore.h>
+#include <stdint.h>
+#include <xen/hvm/hvm_info_table.h>
+#if !defined(HVM_MAX_VCPUS)
+# error HVM_MAX_VCPUS not defined
+#endif
+int main(void) {
+  xc_interface *xc;
+  xs_daemon_open();
+  xc = xc_interface_open(0, 0, 0);
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
+  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
+  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);
+  return 0;
+}
+EOF
+      compile_prog "" "$xen_libs"
+  then
+    xen_ctrl_version=470
+    xen=yes
+
+  # Xen unstable (without stable libs)
+  elif
+      test "$xenstablelibs" = "yes"
+  then
+      # Inconsistent result, split libs but an older libxenctrl interface?
+      xen=no
+
+  # Xen 4.6
   elif
       cat > $TMPC <<EOF &&
 #include <xenctrl.h>
@@ -2037,6 +2122,11 @@ EOF
   fi
 
   if test "$xen" = yes; then
+    if test "$xenstablelibs" = yes; then
+      libs_softmmu="$xenevtchn_libs $libs_softmmu"
+      libs_softmmu="$xengnttab_libs $libs_softmmu"
+      libs_softmmu="$xenforeignmemory_libs $libs_softmmu"
+    fi
     libs_softmmu="$xen_libs $libs_softmmu"
   fi
 fi
@@ -4337,7 +4427,8 @@ if test -n "$sparc_cpu"; then
 fi
 echo "xen support       $xen"
 if test "$xen" = "yes" ; then
-  echo "xen ctrl version  $xen_ctrl_version"
+  echo "  stable libs     $xenstablelibs"
+  echo "  ctrl version    $xen_ctrl_version"
 fi
 echo "brlapi support    $brlapi"
 echo "bluez  support    $bluez"
@@ -4670,6 +4761,9 @@ fi
 if test "$xen" = "yes" ; then
   echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
   echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
+  if test "$xenstablelibs" = "yes" ; then
+    echo "CONFIG_XEN_STABLE_LIBS=y" >> $config_host_mak
+  fi
 fi
 if test "$linux_aio" = "yes" ; then
   echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
include/hw/xen/xen_common.h +40 -2

60 lines not on this page · raw message

xen-common.c +9 -0
index d319dcb..f689758 100644
@@ -117,7 +117,16 @@ static int xen_init(MachineState *ms)
         xen_be_printf(NULL, 0, "can't open xen interface\n");
         return -1;
     }
+#ifdef CONFIG_XEN_STABLE_LIBS /* We have libxenforeignmemory */
+    xen_fmem = xenforeignmemory_open(0, 0);
+    if (xen_fmem == NULL) {
+        xen_be_printf(NULL, 0, "can't open xen fmem interface\n");
+	xc_interface_close(xen_xc);
+	return -1;
+    }
+#else
     xen_fmem = &xen_xc;
+#endif
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
     return 0;
Signature · 1 line
2.1.4
#68 lore raw

Re: [PATCH QEMU-XEN v3 6/8] xen: Use stable library interfaces when they are available.

Quoted 71 lines · Ian Campbell

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.

Specifically libxenevtchn, libxengnttab and libxenforeignmemory.

Previous patches have already laid the groundwork for using these by switching the existing compatibility shims to reflect the intefaces to these libraries.

So all which remains is to update configure to detect the libraries and enable their use. Although they are notionally independent we take an all or nothing approach to the three libraries since they were added at the same time.

The only non-obvious bit is that we now open a proper xenforeignmemory handle for xen_fmem instead of reusing the xen_xc handle.

Build tested with 4.0, 4.5 and the patches targetting 4.7 which adds these libraries.

---
 configure                   | 98 ++++++++++++++++++++++++++++++++++++++++++++-
 include/hw/xen/xen_common.h | 42 ++++++++++++++++++-
 xen-common.c                |  9 +++++
 3 files changed, 145 insertions(+), 4 deletions(-)
configure +35 -0
index 779623a..508b157 100755
@@ -1839,6 +1839,52 @@ fi
 # xen probe
 
 if test "$xen" != "no" ; then
+  xenevtchn_libs="-lxenevtchn"
+
+  cat > $TMPC <<EOF
+#include <xenevtchn.h>
+int main(void) { return 0; }
+EOF
+  if compile_prog "" "$xenevtchn_libs" ; then
+      xenevtchn=yes
+  else
+      xenevtchn=no
+  fi
+
+  xengnttab_libs="-lxengnttab"
+
+  cat > $TMPC <<EOF
+#include <xengnttab.h>
+int main(void) { return 0; }
+EOF
+  if compile_prog "" "$xengnttab_libs" ; then
+      xengnttab=yes
+  else
+      xengnttab=no
+  fi
+
+  xenforeignmemory_libs="-lxenforeignmemory"
+
+  cat > $TMPC <<EOF
+#include <xenforeignmemory.h>
+int main(void) { return 0; }
+EOF
+  if compile_prog "" "$xenforeignmemory_libs" ; then
+      xenforeignmemory=yes
+  else
+      xenforeignmemory=no
+  fi

configure fi · line 1886

Quoted 10 lines
configure +10 -0
+
+  # These libraries were all introduced in the same release, to
+  # simplify things we therefore assume its either all or nothing and
+  # treat any other mix as an error
+  case $xenevtchn$xengnttab$xenforeignmemory in
+      yesyesyes) xenstablelibs=yes;;
+      nonono)    xenstablelibs=no;;
+      *)         error_exit "Inconsistent set of xen libraries found"
+	  ;;
+  esac

I would remove all this and introduce a xen_stable_libs for the Xen 4.7 and beyond case:

xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"

Quoted 22 lines
configure +14 -1
   xen_libs="-lxenstore -lxenctrl -lxenguest"
 
   # First we test whether Xen headers and libraries are available.
@@ -1859,7 +1905,46 @@ EOF
     fi
     xen=no
 
-  # Xen unstable
+  # Xen unstable (with stable libs)
+  elif
+      # If we have stable libs the we don't want the libxc compat
+      # layers, regardless of what CFLAGS we may have been given.
+      test "$xenstablelibs" = "yes" &&
+      cat > $TMPC <<EOF &&
+#undef XC_WANT_COMPAT_EVTCHN_API
+#undef XC_WANT_COMPAT_GNTTAB_API
+#undef XC_WANT_COMPAT_MAP_FOREIGN_API
+#include <xenctrl.h>
+#include <xenstore.h>
+#include <stdint.h>
+#include <xen/hvm/hvm_info_table.h>
+#if !defined(HVM_MAX_VCPUS)

configure EOF · line 1931

Quoted 10 lines
configure +10 -0
+# error HVM_MAX_VCPUS not defined
+#endif
+int main(void) {
+  xc_interface *xc;
+  xs_daemon_open();
+  xc = xc_interface_open(0, 0, 0);
+  xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0);
+  xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0);
+  xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000);
+  xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL);

I would add some of the new function calls here.

configure EOF · line 1935

Quoted 4 lines
configure +4 -0
+  return 0;
+}
+EOF
+      compile_prog "" "$xen_libs"

^ xen_stable_libs

configure EOF · line 1940

Quoted 5 lines
configure +5 -0
+  then
+    xen_ctrl_version=470
+    xen=yes
+
+  # Xen unstable (without stable libs)

I would ignore this case completely.

Quoted 23 lines
configure +12 -0
+  elif
+      test "$xenstablelibs" = "yes"
+  then
+      # Inconsistent result, split libs but an older libxenctrl interface?
+      xen=no
+
+  # Xen 4.6
   elif
       cat > $TMPC <<EOF &&
 #include <xenctrl.h>
@@ -2037,6 +2122,11 @@ EOF
   fi
 
   if test "$xen" = yes; then
+    if test "$xenstablelibs" = yes; then
+      libs_softmmu="$xenevtchn_libs $libs_softmmu"
+      libs_softmmu="$xengnttab_libs $libs_softmmu"
+      libs_softmmu="$xenforeignmemory_libs $libs_softmmu"
+    fi
     libs_softmmu="$xen_libs $libs_softmmu"
   fi
 fi

configure if test -n "$sparc_cpu"; then · line 4431

Quoted 6 lines
configure +2 -1
@@ -4337,7 +4427,8 @@ if test -n "$sparc_cpu"; then
 fi
 echo "xen support       $xen"
 if test "$xen" = "yes" ; then
-  echo "xen ctrl version  $xen_ctrl_version"
+  echo "  stable libs     $xenstablelibs"
+  echo "  ctrl version    $xen_ctrl_version"

I don't think is necessary to print something here

configure fi · line 4766

Quoted 10 lines
configure +3 -0
 fi
 echo "brlapi support    $brlapi"
 echo "bluez  support    $bluez"
@@ -4670,6 +4761,9 @@ fi
 if test "$xen" = "yes" ; then
   echo "CONFIG_XEN_BACKEND=y" >> $config_host_mak
   echo "CONFIG_XEN_CTRL_INTERFACE_VERSION=$xen_ctrl_version" >> $config_host_mak
+  if test "$xenstablelibs" = "yes" ; then
+    echo "CONFIG_XEN_STABLE_LIBS=y" >> $config_host_mak
+  fi

I would avoid this and just use a simple Xen version check in the code

include/hw/xen/xen_common.h line 9

Quoted 12 lines
configure +0 -0
 fi
 if test "$linux_aio" = "yes" ; then
   echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
include/hw/xen/xen_common.h +1 -0
index 28f3fb1..1b824aa 100644
@@ -6,6 +6,17 @@
 #include <stddef.h>
 #include <inttypes.h>
 
+#ifdef CONFIG_XEN_STABLE_LIBS

I would just do

#if CONFIG_XEN_CTRL_INTERFACE_VERSION >= 470

Quoted 25 lines
include/hw/xen/xen_common.h +12 -2
+/*
+ * If we have new enough libxenctrl then we do not want/need these compat
+ * interfaces, despite what the user supplied cflags might say. They
+ * must be undefined before including xenctrl.h
+ */
+#undef XC_WANT_COMPAT_EVTCHN_API
+#undef XC_WANT_COMPAT_GNTTAB_API
+#undef XC_WANT_COMPAT_MAP_FOREIGN_API
+#endif
+
 #include <xenctrl.h>
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 420
 #  include <xs.h>
@@ -146,8 +157,8 @@ static inline void xs_close(struct xs_handle *xsh)
 }
 
 
-/* Xen 4.1 */
-#else
+/* Xen 4.1 thru 4.6 */
+#elif CONFIG_XEN_CTRL_INTERFACE_VERSION < 470
 
 typedef xc_interface *XenXC;
 typedef xc_interface *xenforeignmemory_handle;

include/hw/xen/xen_common.h static inline int xc_fd(xc_interface *xen_xc) · line 205

Quoted 8 lines
include/hw/xen/xen_common.h +5 -0
@@ -187,6 +198,33 @@ static inline int xc_fd(xc_interface *xen_xc)
 {
     return -1;
 }
+#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 470 */
+
+#ifndef CONFIG_XEN_STABLE_LIBS
+#error XEN_CTRL_INTERFACE_VERSION >= 470, but no stable libs?
+#endif

let's ignore this case

Quoted 32 lines
include/hw/xen/xen_common.h +21 -0
+typedef xc_interface *XenXC;
+
+#  define XC_INTERFACE_FMT "%p"
+#  define XC_HANDLER_INITIAL_VALUE    NULL
+
+#include <xenevtchn.h>
+#include <xengnttab.h>
+#include <xenforeignmemory.h>
+
+static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
+                                          unsigned int open_flags)
+{
+    return xc_interface_open(logger, dombuild_logger, open_flags);
+}
+
+/* FIXME There is now way to have the xen fd */
+static inline int xc_fd(xc_interface *xen_xc)
+{
+    return -1;
+}
+
 #endif
 
 /* Xen before 4.2 */
xen-common.c +0 -0
index d319dcb..f689758 100644
@@ -117,7 +117,16 @@ static int xen_init(MachineState *ms)
         xen_be_printf(NULL, 0, "can't open xen interface\n");
         return -1;
     }

xen-common.c static int xen_init(MachineState *ms) · line 129

Quoted 10 lines
xen-common.c +9 -0
+#ifdef CONFIG_XEN_STABLE_LIBS /* We have libxenforeignmemory */
+    xen_fmem = xenforeignmemory_open(0, 0);
+    if (xen_fmem == NULL) {
+        xen_be_printf(NULL, 0, "can't open xen fmem interface\n");
+	xc_interface_close(xen_xc);
+	return -1;
+    }
+#else
     xen_fmem = &xen_xc;
+#endif

Please introduce a wrapper for this in xen_common.h, avoid the ifdef here.

Quoted 6 lines
xen-common.c +0 -0
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
     return 0;
Signature · 1 line
2.1.4
#69 lore raw

Re: [PATCH QEMU-XEN v3 6/8] xen: Use stable library interfaces when they are available.

Quoted 13 lines · Stefano Stabellini

configure fi · line 1886

Quoted 9 lines
configure +9 -0
+  # These libraries were all introduced in the same release, to
+  # simplify things we therefore assume its either all or nothing and
+  # treat any other mix as an error
+  case $xenevtchn$xengnttab$xenforeignmemory in
+      yesyesyes) xenstablelibs=yes;;
+      nonono)    xenstablelibs=no;;
+      *)         error_exit "Inconsistent set of xen libraries found"
+	  ;;
+  esac

I would remove all this and introduce a xen_stable_libs for the Xen 4.7 and beyond case:

Quoted 1 line

xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"

This and all the consequences which followed make sense and should simplify a bunch of stuff, so will do.

Ian.

#70 lore raw

PATCH v3 7/8 xen: domainbuild: reopen libxenctrl interface after forking for domain watcher.

In reply to Ian Campbell

Using an existing libxenctrl handle after a fork was never particularly safe (especially if foreign mappings existed at the time of the fork) and the xc fd has been unavailable for many releases.

Reopen the handle after fork and therefore do away with xc_fd().

---
The fact that xc_fd hasn't been useful since at least Xen 4.1 makes me question the utility of this domainbuild in QEMU. Perhaps we should just nuke it?

---
 hw/xenpv/xen_domainbuild.c  |  9 ++++++---
 include/hw/xen/xen_common.h | 17 -----------------
 2 files changed, 6 insertions(+), 20 deletions(-)
hw/xenpv/xen_domainbuild.c +6 -3
index c0ab753..3e8422f 100644
@@ -174,12 +174,15 @@ static int xen_domain_watcher(void)
     for (i = 3; i < n; i++) {
         if (i == fd[0])
             continue;
-        if (i == xc_fd(xen_xc)) {
-            continue;
-        }
         close(i);
     }
 
+    /*
+     * Reopen xc interface, since the original is unsafe after fork
+     * and was closed above.
+     */
+    xen_xc = xc_interface_open(0, 0, 0);
+
     /* ignore term signals */
     signal(SIGINT,  SIG_IGN);
     signal(SIGTERM, SIG_IGN);
include/hw/xen/xen_common.h +0 -17
index 1b824aa..a7c1ca0 100644
@@ -116,12 +116,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
 #define xenforeignmemory_map(h,d,p,a,e,n) xc_map_foreign_bulk(*h,d,p,a,e,n)
 #define xenforeignmemory_unmap(h,p,s) munmap(p, s)
 
-static inline int xc_fd(int xen_xc)
-{
-    return xen_xc;
-}
-
-
 static inline int xc_domain_populate_physmap_exact
     (XenXC xc_handle, uint32_t domid, unsigned long nr_extents,
      unsigned int extent_order, unsigned int mem_flags, xen_pfn_t *extent_start)
@@ -193,11 +187,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
 #define xenforeignmemory_map(h,d,p,a,e,n) xc_map_foreign_bulk(*h,d,p,a,e,n)
 #define xenforeignmemory_unmap(h,p,s) munmap(p, s)
 
-/* FIXME There is now way to have the xen fd */
-static inline int xc_fd(xc_interface *xen_xc)
-{
-    return -1;
-}
 #else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 470 */
 
 #ifndef CONFIG_XEN_STABLE_LIBS
@@ -219,12 +208,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open(logger, dombuild_logger, open_flags);
 }
 
-/* FIXME There is now way to have the xen fd */
-static inline int xc_fd(xc_interface *xen_xc)
-{
-    return -1;
-}
-
 #endif
 
 /* Xen before 4.2 */
Signature · 1 line
2.1.4
Acked-by on v3 7/8
#71 lore raw

Re: [PATCH QEMU-XEN v3 7/8] xen: domainbuild: reopen libxenctrl interface after forking for domain watcher.

Quoted 11 lines · Ian Campbell

Using an existing libxenctrl handle after a fork was never particularly safe (especially if foreign mappings existed at the time of the fork) and the xc fd has been unavailable for many releases.

Reopen the handle after fork and therefore do away with xc_fd().

The fact that xc_fd hasn't been useful since at least Xen 4.1 makes me question the utility of this domainbuild in QEMU. Perhaps we should just nuke it?

Indeed

Quoted 72 lines
 hw/xenpv/xen_domainbuild.c  |  9 ++++++---
 include/hw/xen/xen_common.h | 17 -----------------
 2 files changed, 6 insertions(+), 20 deletions(-)
hw/xenpv/xen_domainbuild.c +6 -3
index c0ab753..3e8422f 100644
@@ -174,12 +174,15 @@ static int xen_domain_watcher(void)
     for (i = 3; i < n; i++) {
         if (i == fd[0])
             continue;
-        if (i == xc_fd(xen_xc)) {
-            continue;
-        }
         close(i);
     }
 
+    /*
+     * Reopen xc interface, since the original is unsafe after fork
+     * and was closed above.
+     */
+    xen_xc = xc_interface_open(0, 0, 0);
+
     /* ignore term signals */
     signal(SIGINT,  SIG_IGN);
     signal(SIGTERM, SIG_IGN);
include/hw/xen/xen_common.h +0 -17
index 1b824aa..a7c1ca0 100644
@@ -116,12 +116,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
 #define xenforeignmemory_map(h,d,p,a,e,n) xc_map_foreign_bulk(*h,d,p,a,e,n)
 #define xenforeignmemory_unmap(h,p,s) munmap(p, s)
 
-static inline int xc_fd(int xen_xc)
-{
-    return xen_xc;
-}
-
-
 static inline int xc_domain_populate_physmap_exact
     (XenXC xc_handle, uint32_t domid, unsigned long nr_extents,
      unsigned int extent_order, unsigned int mem_flags, xen_pfn_t *extent_start)
@@ -193,11 +187,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
 #define xenforeignmemory_map(h,d,p,a,e,n) xc_map_foreign_bulk(*h,d,p,a,e,n)
 #define xenforeignmemory_unmap(h,p,s) munmap(p, s)
 
-/* FIXME There is now way to have the xen fd */
-static inline int xc_fd(xc_interface *xen_xc)
-{
-    return -1;
-}
 #else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 470 */
 
 #ifndef CONFIG_XEN_STABLE_LIBS
@@ -219,12 +208,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open(logger, dombuild_logger, open_flags);
 }
 
-/* FIXME There is now way to have the xen fd */
-static inline int xc_fd(xc_interface *xen_xc)
-{
-    return -1;
-}
-
 #endif
 
 /* Xen before 4.2 */
Signature · 1 line
2.1.4
#72 lore raw

PATCH v3 8/8 xen: make it possible to build without the Xen PV domain builder

In reply to Ian Campbell

Until the previous patch this relied on xc_fd(), which was only implemented for Xen 4.0 and earlier.

I stopped short of disabling this by default, although I think there's a pretty strong argument for doing so.

Removing this support drops the use of a bunch of symbols from libxenctrl, specifically:

- xc_domain_create
- xc_domain_destroy
- xc_domain_getinfo
- xc_domain_max_vcpus
- xc_domain_setmaxmem
- xc_domain_unpause
- xc_evtchn_alloc_unbound
- xc_linux_build

This is another step towards only using Xen libraries which provide a stable inteface.

---
 configure                 | 17 +++++++++++++++++
 hw/xenpv/Makefile.objs    |  4 +++-
 hw/xenpv/xen_machine_pv.c | 14 ++++++++++----
 3 files changed, 30 insertions(+), 5 deletions(-)
configure +17 -0
index 508b157..534d280 100755
@@ -910,6 +910,10 @@ for opt do
   ;;
   --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
   ;;
+  --disable-xen-pv-domain-build) xen_pv_domain_build="no"
+  ;;
+  --enable-xen-pv-domain-build) xen_pv_domain_build="yes"
+  ;;
   --disable-brlapi) brlapi="no"
   ;;
   --enable-brlapi) brlapi="yes"
@@ -2148,6 +2152,15 @@ if test "$xen_pci_passthrough" != "no"; then
   fi
 fi
 
+if test "$xen_pv_domain_build" != "no"; then
+  if test "$xen_pv_domain_build" = "yes" &&
+     test "$xen" != "yes"; then
+      error_exit "User requested Xen PV domain builder support" \
+		 "which requires Xen support."
+  fi
+  xen_pv_domain_build=$xen
+fi
+
 ##########################################
 # libtool probe
 
@@ -4429,6 +4442,7 @@ echo "xen support       $xen"
 if test "$xen" = "yes" ; then
   echo "  stable libs     $xenstablelibs"
   echo "  ctrl version    $xen_ctrl_version"
+  echo "  PV dom build    $xen_pv_domain_build"
 fi
 echo "brlapi support    $brlapi"
 echo "bluez  support    $bluez"
@@ -4764,6 +4778,9 @@ if test "$xen" = "yes" ; then
   if test "$xenstablelibs" = "yes" ; then
     echo "CONFIG_XEN_STABLE_LIBS=y" >> $config_host_mak
   fi
+  if test "$xen_pv_domain_build" = "yes" ; then
+    echo "CONFIG_XEN_PV_DOMAIN_BUILD=y" >> $config_host_mak
+  fi
 fi
 if test "$linux_aio" = "yes" ; then
   echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
hw/xenpv/Makefile.objs +3 -1
index 49f6e9e..bbf5873 100644
@@ -1,2 +1,4 @@
 # Xen PV machine support
-obj-$(CONFIG_XEN) += xen_domainbuild.o xen_machine_pv.o
+obj-$(CONFIG_XEN) += xen_machine_pv.o
+# Xen PV machine builder support
+obj-$(CONFIG_XEN_PV_DOMAIN_BUILD) += xen_domainbuild.o
hw/xenpv/xen_machine_pv.c +10 -4
index 2e545d2..d19d29f 100644
@@ -30,9 +30,6 @@
 
 static void xen_init_pv(MachineState *machine)
 {
-    const char *kernel_filename = machine->kernel_filename;
-    const char *kernel_cmdline = machine->kernel_cmdline;
-    const char *initrd_filename = machine->initrd_filename;
     DriveInfo *dinfo;
     int i;
 
@@ -46,13 +43,22 @@ static void xen_init_pv(MachineState *machine)
     case XEN_ATTACH:
         /* nothing to do, xend handles everything */
         break;
-    case XEN_CREATE:
+    case XEN_CREATE: {
+#ifdef CONFIG_XEN_PV_DOMAIN_BUILD
+	const char *kernel_filename = machine->kernel_filename;
+	const char *kernel_cmdline = machine->kernel_cmdline;
+	const char *initrd_filename = machine->initrd_filename;
         if (xen_domain_build_pv(kernel_filename, initrd_filename,
                                 kernel_cmdline) < 0) {
             fprintf(stderr, "xen pv domain creation failed\n");
             exit(1);
         }
+#else
+	fprintf(stderr, "xen pv domain creation not supported\n");
+	exit (1);
+#endif
         break;
+    }
     case XEN_EMULATE:
         fprintf(stderr, "xen emulation not implemented (yet)\n");
         exit(1);
Signature · 1 line
2.1.4
#73 lore raw

Re: [PATCH QEMU-XEN v3 8/8] xen: make it possible to build without the Xen PV domain builder

Quoted 18 lines · Ian Campbell

Until the previous patch this relied on xc_fd(), which was only implemented for Xen 4.0 and earlier.

I stopped short of disabling this by default, although I think there's a pretty strong argument for doing so.

Removing this support drops the use of a bunch of symbols from libxenctrl, specifically:

- xc_domain_create
- xc_domain_destroy
- xc_domain_getinfo
- xc_domain_max_vcpus
- xc_domain_setmaxmem
- xc_domain_unpause
- xc_evtchn_alloc_unbound
- xc_linux_build

Quoted 2 lines

This is another step towards only using Xen libraries which provide a stable inteface.

I would prefer to remove it, but the discussion needs to happen on qemu-devel.

Quoted 107 lines
---
 configure                 | 17 +++++++++++++++++
 hw/xenpv/Makefile.objs    |  4 +++-
 hw/xenpv/xen_machine_pv.c | 14 ++++++++++----
 3 files changed, 30 insertions(+), 5 deletions(-)
configure +17 -0
index 508b157..534d280 100755
@@ -910,6 +910,10 @@ for opt do
   ;;
   --enable-xen-pci-passthrough) xen_pci_passthrough="yes"
   ;;
+  --disable-xen-pv-domain-build) xen_pv_domain_build="no"
+  ;;
+  --enable-xen-pv-domain-build) xen_pv_domain_build="yes"
+  ;;
   --disable-brlapi) brlapi="no"
   ;;
   --enable-brlapi) brlapi="yes"
@@ -2148,6 +2152,15 @@ if test "$xen_pci_passthrough" != "no"; then
   fi
 fi
 
+if test "$xen_pv_domain_build" != "no"; then
+  if test "$xen_pv_domain_build" = "yes" &&
+     test "$xen" != "yes"; then
+      error_exit "User requested Xen PV domain builder support" \
+		 "which requires Xen support."
+  fi
+  xen_pv_domain_build=$xen
+fi
+
 ##########################################
 # libtool probe
 
@@ -4429,6 +4442,7 @@ echo "xen support       $xen"
 if test "$xen" = "yes" ; then
   echo "  stable libs     $xenstablelibs"
   echo "  ctrl version    $xen_ctrl_version"
+  echo "  PV dom build    $xen_pv_domain_build"
 fi
 echo "brlapi support    $brlapi"
 echo "bluez  support    $bluez"
@@ -4764,6 +4778,9 @@ if test "$xen" = "yes" ; then
   if test "$xenstablelibs" = "yes" ; then
     echo "CONFIG_XEN_STABLE_LIBS=y" >> $config_host_mak
   fi
+  if test "$xen_pv_domain_build" = "yes" ; then
+    echo "CONFIG_XEN_PV_DOMAIN_BUILD=y" >> $config_host_mak
+  fi
 fi
 if test "$linux_aio" = "yes" ; then
   echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
hw/xenpv/Makefile.objs +3 -1
index 49f6e9e..bbf5873 100644
@@ -1,2 +1,4 @@
 # Xen PV machine support
-obj-$(CONFIG_XEN) += xen_domainbuild.o xen_machine_pv.o
+obj-$(CONFIG_XEN) += xen_machine_pv.o
+# Xen PV machine builder support
+obj-$(CONFIG_XEN_PV_DOMAIN_BUILD) += xen_domainbuild.o
hw/xenpv/xen_machine_pv.c +10 -4
index 2e545d2..d19d29f 100644
@@ -30,9 +30,6 @@
 
 static void xen_init_pv(MachineState *machine)
 {
-    const char *kernel_filename = machine->kernel_filename;
-    const char *kernel_cmdline = machine->kernel_cmdline;
-    const char *initrd_filename = machine->initrd_filename;
     DriveInfo *dinfo;
     int i;
 
@@ -46,13 +43,22 @@ static void xen_init_pv(MachineState *machine)
     case XEN_ATTACH:
         /* nothing to do, xend handles everything */
         break;
-    case XEN_CREATE:
+    case XEN_CREATE: {
+#ifdef CONFIG_XEN_PV_DOMAIN_BUILD
+	const char *kernel_filename = machine->kernel_filename;
+	const char *kernel_cmdline = machine->kernel_cmdline;
+	const char *initrd_filename = machine->initrd_filename;
         if (xen_domain_build_pv(kernel_filename, initrd_filename,
                                 kernel_cmdline) < 0) {
             fprintf(stderr, "xen pv domain creation failed\n");
             exit(1);
         }
+#else
+	fprintf(stderr, "xen pv domain creation not supported\n");
+	exit (1);
+#endif
         break;
+    }
     case XEN_EMULATE:
         fprintf(stderr, "xen emulation not implemented (yet)\n");
         exit(1);
Signature · 1 line
2.1.4
#74 lore raw

PATCH v3 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).

---
v3: Library moved to tools/libs/

---
 xen-hooks.mak | 2 ++
 1 file changed, 2 insertions(+)
xen-hooks.mak +2 -0
index bc7f1f1..bf7f027 100644
@@ -1,3 +1,4 @@
+CPPFLAGS+= -I$(XEN_ROOT)/tools/libs/toollog/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/libs/toollog
 
 LDFLAGS := $(CFLAGS) $(LDFLAGS)
 
Signature · 1 line
2.1.4
Acked-by on v3 1/5
#75 lore raw

Re: [PATCH QEMU-XEN-TRADITIONAL v3 1/5] qemu-xen-traditional: Use xentoollog as a separate library

Ian Campbell writes ("[PATCH QEMU-XEN-TRADITIONAL v3 1/5] qemu-xen-traditional: Use xentoollog as a separate library"):

Quoted 4 lines

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

(Should be committed when the corresponding xen.git patch is ready.)

Ian.

#76 lore raw

Re: [PATCH QEMU-XEN-TRADITIONAL v3 1/5] qemu-xen-traditional: Use xentoollog as a separate library

Quoted 10 lines · Ian Jackson

Ian Campbell writes ("[PATCH QEMU-XEN-TRADITIONAL v3 1/5] qemu-xen -traditional: Use xentoollog as a separate library"):

Quoted 4 lines

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

(Should be committed when the corresponding xen.git patch is ready.)

Right. Committing all of this is going to be super annoying, since essentially xen.git, qemu-trad.git and mini-os.git need to move in lock step for some portion of the commits.

I think when things are getting closer I will start preparing trees which could be pulled simultaneously into all three and DTRT. We aren't close enough yet though.

Ian.

#77 lore raw

Re: [PATCH QEMU-XEN-TRADITIONAL v3 1/5] qemu-xen-traditional: Use xentoollog as a separate library

Ian Campbell writes ("Re: [PATCH QEMU-XEN-TRADITIONAL v3 1/5] qemu-xen-traditional: Use xentoollog as a separate library"):

Quoted 3 lines

I think when things are getting closer I will start preparing trees which could be pulled simultaneously into all three and DTRT. We aren't close enough yet though.

Another good tactic would be to snip bits off the front of the various series and apply them. For example, I think the xentoollog breakout is now ready, subject to you perhaps wanting to do something with pkg-config.

Ian.

#78 lore raw

Re: [PATCH QEMU-XEN-TRADITIONAL v3 1/5] qemu-xen-traditional: Use xentoollog as a separate library

Quoted 10 lines · Ian Jackson

Ian Campbell writes ("Re: [PATCH QEMU-XEN-TRADITIONAL v3 1/5] qemu-xen -traditional: Use xentoollog as a separate library"):

Quoted 4 lines

I think when things are getting closer I will start preparing trees which
could be pulled simultaneously into all three and DTRT. We aren't close enough yet though.

Another good tactic would be to snip bits off the front of the various series and apply them. For example, I think the xentoollog breakout is now ready,

Yes, that would be a (small in the grand scheme of things) help.

Quoted 2 lines

subject to you perhaps wanting to do something with
pkg-config.

That's for another day I think...

#79 lore raw

PATCH v3 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.

---
v2: Adjust for libs/$lib layout.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 2cb5e51..daee46c 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/libs-$(MINIOS_TARGET_ARCH)/toollog -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
#80 lore raw

PATCH v3 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...

---
v3: Library moved to tools/libs/

---
 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 ede3105..2706f2e 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;
@@ -539,7 +540,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);
     }
 }
 
@@ -583,7 +584,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]);
     }
 }
 
@@ -592,7 +593,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 bf7f027..18259d4 100644
@@ -1,4 +1,5 @@
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libs/toollog/include
+CPPFLAGS+= -I$(XEN_ROOT)/tools/libs/evtchn/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/libs/evtchn -lxenevtchn
 LIBS += -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
 LIBS += -L$(XEN_ROOT)/tools/xenstore -lxenstore
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog
Signature · 1 line
2.1.4
#81 lore raw

PATCH v3 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.

---
v2: Adjust for libs/$lib layout.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index daee46c..d1d8dc4 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/libs-$(MINIOS_TARGET_ARCH)/toollog -whole-archive -lxentoollog -no-whole-archive
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn -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
#82 lore raw

PATCH v3 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.

---
v3: Library moved to tools/libs/

---
 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 18259d4..179a6b7 100644
@@ -1,5 +1,6 @@
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libs/toollog/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libs/evtchn/include
+CPPFLAGS+= -I$(XEN_ROOT)/tools/libs/gnttab/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/libs/evtchn -lxenevtchn
+LIBS += -L$(XEN_ROOT)/tools/libs/gnttab -lxengnttab
 LIBS += -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
 LIBS += -L$(XEN_ROOT)/tools/xenstore -lxenstore
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog
Signature · 1 line
2.1.4
#83 lore raw

PATCH v3 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.

---
v2: Adjust for libs/$lib layout.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index d1d8dc4..521f647 100644
@@ -167,6 +167,7 @@ ifeq ($(libc),y)
 ifeq ($(CONFIG_XC),y)
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog -whole-archive -lxentoollog -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn -whole-archive -lxenevtchn -no-whole-archive
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab -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
#84 lore raw

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

In reply to Ian Campbell

libxenctrl links against this library

---
v3: Library moved to tools/libs

---
 xen-hooks.mak | 1 +
 1 file changed, 1 insertion(+)
xen-hooks.mak +1 -0
index 179a6b7..229d642 100644
@@ -25,6 +25,7 @@ LIBS += -L$(XEN_ROOT)/tools/libs/gnttab -lxengnttab
 LIBS += -L$(XEN_ROOT)/tools/libxc -lxenctrl -lxenguest
 LIBS += -L$(XEN_ROOT)/tools/xenstore -lxenstore
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog
+LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call
 
 LDFLAGS := $(CFLAGS) $(LDFLAGS)
 
Signature · 1 line
2.1.4
#85 lore raw

PATCH v3 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.

---
v2: Adjust for libs/$lib layout.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index 521f647..c900540 100644
@@ -168,6 +168,7 @@ ifeq ($(CONFIG_XC),y)
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog -whole-archive -lxentoollog -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn -whole-archive -lxenevtchn -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab -whole-archive -lxengnttab -no-whole-archive
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call -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
#86 lore raw

PATCH v3 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.

---
v3: Library moved to tools/libs/

---
 xen-hooks.mak | 2 ++
 1 file changed, 2 insertions(+)
xen-hooks.mak +2 -0
index 229d642..c1ea4be 100644
@@ -1,6 +1,7 @@
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libs/toollog/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libs/evtchn/include
 CPPFLAGS+= -I$(XEN_ROOT)/tools/libs/gnttab/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/libs/toollog
 LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call
+LIBS += -Wl,-rpath-link=$(XEN_ROOT)/tools/libs/foreignmemory
 
 LDFLAGS := $(CFLAGS) $(LDFLAGS)
 
Signature · 1 line
2.1.4
#87 lore raw

PATCH v3 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.

---
v2: Adjust for libs/$lib layout.

---
 Makefile | 1 +
 1 file changed, 1 insertion(+)
Makefile +1 -0
index c900540..cfe015a 100644
@@ -169,6 +169,7 @@ APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/toollog -whole-ar
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/evtchn -whole-archive -lxenevtchn -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/gnttab -whole-archive -lxengnttab -no-whole-archive
 APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/call -whole-archive -lxencall -no-whole-archive
+APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libs-$(MINIOS_TARGET_ARCH)/foreignmemory -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