Skip to contentSkip to conversation

Begin to disentangle libxenctrl and provide some stable libraries

PATCH Superseded Ian Campbell 7 participants 71 messages Dec 16, 2015 – Jan 7, 2016

Subsystems (2)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v7 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 v7 of that set of series against:
    xen
    qemu-xen
    qemu-xen-traditional
    mini-os

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

The code for all repos can be found in:

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

The tip of the xen.git branch contains an extra patch hacking Config.mk to point to all the others above, which should get the correct things for the HEAD of the branch, but not further back in time.

The new libraries here are:

 * libxentoollog: Common logging infrastructure
 * 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:

* Lots more docs updates based on feedback given and especially the discussion around the semantics of the libraries wrt forking without exec.
* s/gnttab_munmap/gnttab_unmap/ and s/gntshr_munmap/gntshr_unshare/ in the libxengnttab API.
* Use O_CLOEXEC on Linux and FreeBSD unconditionally.
* Fixed a stubdom/Makefile build race issue
* Dropped -pedantic from headers check, the headers in xen/include/public are not -pedantic clean, and the libraries can include headers from there (and then the check breaks).
* Dropped libxencall atform madvise thing, in favour of simpler solution of touching the pages to uncow them.
* The xentoollog patch went in but was reverted, that patch now refers to the revisions of qemu and mini-os with the corresponding changes.

Even with the dropped acks mini-os and qemu-xen-trad are fully acked, while qemu-xen and xen are mostly acked (but had a few dropped acks since last time).

The whole thing has been build tested on Linux (incl stubdoms), and on FreeBSD. I have runtime tested on Linux with qemu-xen, qemu-xen-trad and stubdoms.

Neither NetBSD nor Solaris have been tested at all. It's certainly not impossible that I've not got the #includes in the new files quite right.

http://xenbits.xen.org/people/ianc/libxenctrl-split/v7.html is the document I've been using to try and track what I'm doing. It may not be all that useful. The history of it is in the v6-with-doc branch of the xen.git linked to above.

A few of the initial patches went in, but in the meantime I discovered a wrinkle in the changes to the stubdom build changes, so now there are some new ones.

    tools: Refactor "xentoollog" into its own library

went in but then came out again and is now blocking on a libvirt patch, which is in libvirt.git#master waiting to get through our libvirt push gate.

Ian.

#1 lore raw

v7 cover Begin to disentangle libxenctrl and provide some stable libraries

We intend to stabilise some parts of the libxenctrl interface by splitting out some functionality into separate stable libraries.

This is the xen part of the first phase of that change.

This mail is (or is intended to be) a reply to a "0/<VARIOUS>" super-intro mail covering all of the related patch series and which contains more details.

Ian Campbell (29):
stubdom: recurse into tools/include in mk-headers-$(XEN_TARGET_ARCH)
rule
tools: Refactor "xentoollog" into its own library tools/libxc: Remove osdep indirection for xc_evtchn
tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.
tools: Arrange to check public headers for ANSI compatiblity tools/libxc: Remove osdep indirection for xc_gnt{shr,tab}
tools: Refactor /dev/xen/gnt{dev,shr} wrappers into libxengnttab. tools/libxc: Remove osdep indirection for privcmd
tools: Refactor hypercall calling wrappers into libxencall. tools/libxc: drop xc_map_foreign_bulk_compat wrappers
tools: Remove xc_map_foreign_batch
tools: Implement xc_map_foreign_range(s) in terms of common helper
tools: Refactor foreign memory mapping into libxenforeignmemory tools/libs/foreignmemory: provide xenforeignmemory_unmap. tools/libs/foreignmemory: use size_t for size arguments. tools/libs/foreignmemory: Mention restrictions on fork in docs. tools/libs/foreignmemory: Support err == NULL to map. tools/libs/foreignmemory: pull array length argument to map forward tools/libs/evtchn: Review and update doc comments. tools/libs: Clean up hard tabs.
tools/libs/gnttab: Extensive updates to API documentation. tools/libs/call: Update some log messages to not refer to xc. tools/libs/call: Describe return values and error semantics for
xencall*
tools/libs/call: Avoid xc_memalign in netbsd and solaris backends tools/libs/call: linux: touch newly allocated pages after madvise
lockdown
tools/libs/{call,evtchn}: Document requirements around forking. tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD
tools: Update CFLAGS for qemu-xen to allow it to use new libraries
HACK: Update Config.mk to pull all the right bits from my xenbits
trees

 .gitignore                                         |  10 +
 Config.mk                                          |  24 +-
 config/FreeBSD.mk                                  |   2 -
 config/NetBSD.mk                                   |   3 -
 config/NetBSDRump.mk                               |   1 -
 config/StdGNU.mk                                   |   1 -
 config/SunOS.mk                                    |   1 -
 stubdom/Makefile                                   |  87 +-
 stubdom/grub/Makefile                              |   1 +
 tools/Makefile                                     |  18 +-
 tools/Rules.mk                                     |  54 +-
 tools/console/Makefile                             |   3 +-
 tools/console/daemon/io.c                          |  64 +-
 tools/console/daemon/utils.c                       |   1 -
 tools/console/daemon/utils.h                       |   1 +
 tools/libs/Makefile                                |  11 +
 tools/libs/call/Makefile                           |  67 ++
 tools/libs/call/buffer.c                           | 192 +++++
 tools/libs/call/core.c                             | 147 ++++
 tools/libs/call/freebsd.c                          | 126 +++
 tools/libs/call/include/xencall.h                  | 127 +++
 tools/libs/call/libxencall.map                     |  19 +
 tools/libs/call/linux.c                            | 134 +++
 tools/libs/call/minios.c                           |  81 ++
 tools/libs/call/netbsd.c                           | 121 +++
 tools/libs/call/private.h                          |  68 ++
 tools/libs/call/solaris.c                          |  97 +++
 tools/libs/evtchn/Makefile                         |  67 ++
 tools/libs/evtchn/core.c                           |  72 ++
 tools/libs/evtchn/freebsd.c                        | 138 ++++
 tools/libs/evtchn/include/xenevtchn.h              | 163 ++++
 tools/libs/evtchn/libxenevtchn.map                 |  14 +
 tools/libs/evtchn/linux.c                          | 140 ++++
 tools/libs/evtchn/minios.c                         | 266 ++++++
 tools/libs/evtchn/netbsd.c                         | 147 ++++
 tools/libs/evtchn/private.h                        |  25 +
 tools/libs/evtchn/solaris.c                        | 135 +++
 tools/libs/foreignmemory/Makefile                  |  67 ++
 tools/libs/foreignmemory/compat.c                  |  72 ++
 tools/libs/foreignmemory/core.c                    | 116 +++
 tools/libs/foreignmemory/freebsd.c                 | 115 +++
 .../libs/foreignmemory/include/xenforeignmemory.h  | 128 +++
 tools/libs/foreignmemory/libxenforeignmemory.map   |   8 +
 tools/libs/foreignmemory/linux.c                   | 283 +++++++
 tools/libs/foreignmemory/minios.c                  |  69 ++
 tools/libs/foreignmemory/netbsd.c                  | 111 +++
 tools/libs/foreignmemory/private.h                 |  54 ++
 tools/libs/foreignmemory/solaris.c                 | 109 +++
 tools/libs/gnttab/Makefile                         |  69 ++
 tools/libs/gnttab/gntshr_core.c                    |  95 +++
 tools/libs/gnttab/gntshr_unimp.c                   |  62 ++
 tools/libs/gnttab/gnttab_core.c                    | 124 +++
 tools/libs/gnttab/gnttab_unimp.c                   |  89 ++
 tools/libs/gnttab/include/xengnttab.h              | 363 +++++++++
 tools/libs/gnttab/libxengnttab.map                 |  23 +
 tools/libs/gnttab/linux.c                          | 335 ++++++++
 tools/libs/gnttab/minios.c                         | 117 +++
 tools/libs/gnttab/private.h                        |  47 ++
 tools/libs/toollog/Makefile                        |  62 ++
 tools/{libxc => libs/toollog}/include/xentoollog.h |  10 +
 tools/libs/toollog/libxentoollog.map               |  12 +
 tools/{libxc => libs/toollog}/xtl_core.c           |  10 +
 tools/{libxc => libs/toollog}/xtl_logger_stdio.c   |  12 +-
 tools/libvchan/Makefile                            |   8 +-
 tools/libvchan/init.c                              |  46 +-
 tools/libvchan/io.c                                |  20 +-
 tools/libvchan/libxenvchan.h                       |   9 +-
 tools/libxc/Makefile                               |  44 +-
 tools/libxc/include/xenctrl.h                      | 312 +------
 tools/libxc/include/xenctrl_compat.h               | 132 +++
 tools/libxc/include/xenctrlosdep.h                 | 172 ----
 tools/libxc/include/xenguest.h                     |  14 +-
 tools/libxc/xc_altp2m.c                            |  64 +-
 tools/libxc/xc_domain.c                            | 105 +--
 tools/libxc/xc_evtchn.c                            |  54 +-
 tools/libxc/xc_evtchn_compat.c                     |  75 ++
 tools/libxc/xc_flask.c                             |   8 +-
 tools/libxc/xc_foreign_memory.c                    | 119 +--
 tools/libxc/xc_freebsd_osdep.c                     | 407 ----------
 tools/libxc/xc_gnttab.c                            |  93 +--
 tools/libxc/xc_gnttab_compat.c                     | 111 +++
 tools/libxc/xc_hcall_buf.c                         | 138 +---
 tools/libxc/xc_kexec.c                             |  36 +-
 tools/libxc/xc_linux_osdep.c                       | 904 ---------------------
 tools/libxc/xc_minios.c                            | 482 -----------
 tools/libxc/xc_misc.c                              |  79 +-
 tools/libxc/xc_netbsd.c                            | 345 --------
 tools/libxc/xc_private.c                           | 277 +------
 tools/libxc/xc_private.h                           | 105 +--
 tools/libxc/xc_solaris.c                           | 305 -------
 tools/libxc/xc_sr_restore.c                        |   8 +-
 tools/libxc/xc_sr_save.c                           |   6 +-
 tools/libxc/xc_suspend.c                           |  18 +-
 tools/libxc/xc_tmem.c                              |   7 +-
 tools/libxc/xc_vm_event.c                          |  20 +-
 tools/libxc/xenctrl_osdep_ENOSYS.c                 | 210 -----
 tools/libxc/xg_private.h                           |   3 +-
 tools/libxl/Makefile                               |  18 +-
 tools/libxl/libxl.c                                |   2 +-
 tools/libxl/libxl_dom_suspend.c                    |   4 +-
 tools/libxl/libxl_event.c                          |  14 +-
 tools/libxl/libxl_internal.h                       |   6 +-
 tools/misc/Makefile                                |  11 +-
 tools/misc/xen-hptool.c                            |  13 +-
 tools/misc/xen-lowmemd.c                           |  15 +-
 tools/misc/xen-mfndump.c                           |   1 +
 tools/ocaml/libs/eventchn/Makefile                 |   4 +-
 tools/ocaml/libs/eventchn/xeneventchn_stubs.c      |  20 +-
 tools/ocaml/libs/xc/xenctrl.ml                     |   2 -
 tools/ocaml/libs/xc/xenctrl.mli                    |   1 -
 tools/ocaml/libs/xc/xenctrl_stubs.c                |   8 +-
 tools/ocaml/libs/xentoollog/Makefile               |   6 +-
 tools/ocaml/libs/xentoollog/genlevels.py           |   2 +-
 tools/ocaml/xenstored/domains.ml                   |   6 +-
 tools/ocaml/xenstored/xenstored.ml                 |   5 +-
 tools/python/setup.py                              |  10 +-
 tools/python/xen/lowlevel/xc/xc.c                  |   2 +
 tools/tests/mce-test/tools/xen-mceinj.c            |   1 +
 tools/tests/mem-sharing/memshrtool.c               |   1 +
 tools/tests/xen-access/Makefile                    |   3 +-
 tools/tests/xen-access/xen-access.c                |  21 +-
 tools/xcutils/Makefile                             |   4 +-
 tools/xenmon/Makefile                              |   2 +
 tools/xenmon/xenbaked.c                            |  26 +-
 tools/xenpaging/Makefile                           |   4 +-
 tools/xenpaging/pagein.c                           |   1 -
 tools/xenpaging/xenpaging.c                        |  33 +-
 tools/xenpaging/xenpaging.h                        |   5 +-
 tools/xenstore/Makefile                            |   7 +-
 tools/xenstore/xenstored_core.c                    |   7 +-
 tools/xenstore/xenstored_core.h                    |   5 +-
 tools/xenstore/xenstored_domain.c                  |  49 +-
 tools/xenstore/xenstored_minios.c                  |   5 +-
 tools/xentrace/Makefile                            |   5 +-
 tools/xentrace/xenctx.c                            |   3 +-
 tools/xentrace/xentrace.c                          |  17 +-
 136 files changed, 5967 insertions(+), 4308 deletions(-)
 create mode 100644 tools/libs/Makefile
 create mode 100644 tools/libs/call/Makefile
 create mode 100644 tools/libs/call/buffer.c
 create mode 100644 tools/libs/call/core.c
 create mode 100644 tools/libs/call/freebsd.c
 create mode 100644 tools/libs/call/include/xencall.h
 create mode 100644 tools/libs/call/libxencall.map
 create mode 100644 tools/libs/call/linux.c
 create mode 100644 tools/libs/call/minios.c
 create mode 100644 tools/libs/call/netbsd.c
 create mode 100644 tools/libs/call/private.h
 create mode 100644 tools/libs/call/solaris.c
 create mode 100644 tools/libs/evtchn/Makefile
 create mode 100644 tools/libs/evtchn/core.c
 create mode 100644 tools/libs/evtchn/freebsd.c
 create mode 100644 tools/libs/evtchn/include/xenevtchn.h
 create mode 100644 tools/libs/evtchn/libxenevtchn.map
 create mode 100644 tools/libs/evtchn/linux.c
 create mode 100644 tools/libs/evtchn/minios.c
 create mode 100644 tools/libs/evtchn/netbsd.c
 create mode 100644 tools/libs/evtchn/private.h
 create mode 100644 tools/libs/evtchn/solaris.c
 create mode 100644 tools/libs/foreignmemory/Makefile
 create mode 100644 tools/libs/foreignmemory/compat.c
 create mode 100644 tools/libs/foreignmemory/core.c
 create mode 100644 tools/libs/foreignmemory/freebsd.c
 create mode 100644 tools/libs/foreignmemory/include/xenforeignmemory.h
 create mode 100644 tools/libs/foreignmemory/libxenforeignmemory.map
 create mode 100644 tools/libs/foreignmemory/linux.c
 create mode 100644 tools/libs/foreignmemory/minios.c
 create mode 100644 tools/libs/foreignmemory/netbsd.c
 create mode 100644 tools/libs/foreignmemory/private.h
 create mode 100644 tools/libs/foreignmemory/solaris.c
 create mode 100644 tools/libs/gnttab/Makefile
 create mode 100644 tools/libs/gnttab/gntshr_core.c
 create mode 100644 tools/libs/gnttab/gntshr_unimp.c
 create mode 100644 tools/libs/gnttab/gnttab_core.c
 create mode 100644 tools/libs/gnttab/gnttab_unimp.c
 create mode 100644 tools/libs/gnttab/include/xengnttab.h
 create mode 100644 tools/libs/gnttab/libxengnttab.map
 create mode 100644 tools/libs/gnttab/linux.c
 create mode 100644 tools/libs/gnttab/minios.c
 create mode 100644 tools/libs/gnttab/private.h
 create mode 100644 tools/libs/toollog/Makefile
 rename tools/{libxc => libs/toollog}/include/xentoollog.h (97%)
 create mode 100644 tools/libs/toollog/libxentoollog.map
 rename tools/{libxc => libs/toollog}/xtl_core.c (95%)
 rename tools/{libxc => libs/toollog}/xtl_logger_stdio.c (97%)
 create mode 100644 tools/libxc/include/xenctrl_compat.h
 delete mode 100644 tools/libxc/include/xenctrlosdep.h
 create mode 100644 tools/libxc/xc_evtchn_compat.c
 delete mode 100644 tools/libxc/xc_freebsd_osdep.c
 create mode 100644 tools/libxc/xc_gnttab_compat.c
 delete mode 100644 tools/libxc/xc_linux_osdep.c
 delete mode 100644 tools/libxc/xenctrl_osdep_ENOSYS.c
Signature · 1 line
2.1.4
#2 lore raw

PATCH v7 1/29 stubdom: recurse into tools/include in mk-headers-$(XEN_TARGET_ARCH) rule

... rather than in the libxc rule.

This puts all the header dependencies in one place and will allow us to avoid races when more libraries which need these headers are introduced. I observed issues with the xen-foreign/tmp.size file getting deleted in parallel with another process trying to use it.

The mini-os links are already created in the mk-headers-$(XEN_TARGET_ARCH) target so the other places which do so are redundant, in the case of polarssl and vtpmmgr indirectly through their eventual dependency on newlib which in turn depends on mk-headers-$(XEN_TARGET_ARCH).

---
v7: New patch.

---
 stubdom/Makefile | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
stubdom/Makefile +2 -5
index e1359cf..fd84024 100644
@@ -304,6 +304,7 @@ ioemu/linkfarm.stamp:
 endif
 
 mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
 	mkdir -p include/xen && \
           ln -sf $(wildcard $(XEN_ROOT)/xen/include/public/*.h) include/xen && \
           ln -sf $(addprefix $(XEN_ROOT)/xen/include/public/,arch-x86 hvm io xsm) include/xen && \
@@ -341,9 +342,7 @@ $(TARGETS_MINIOS): mini-os-%:
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: cross-zlib
-	$(MAKE) -C $(XEN_ROOT)/tools/include
-	$(MAKE) DESTDIR= -C $(MINI_OS) links
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) cross-zlib
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
  libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
@@ -386,7 +385,6 @@ c: $(CROSS_ROOT)
 
 .PHONY: vtpm
 vtpm: cross-polarssl cross-tpmemu
-	make -C $(MINI_OS) links
 	XEN_TARGET_ARCH="$(XEN_TARGET_ARCH)" CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
 
 ######
@@ -395,7 +393,6 @@ vtpm: cross-polarssl cross-tpmemu
 
 .PHONY: vtpmmgr
 vtpmmgr: cross-polarssl
-	make -C $(MINI_OS) links
 	XEN_TARGET_ARCH="$(XEN_TARGET_ARCH)" CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
 
 ######
Signature · 1 line
2.1.4
Acked-by on v7 1/29
#3 lore raw

Re: [PATCH XEN v7 01/29] stubdom: recurse into tools/include in mk-headers-$(XEN_TARGET_ARCH) rule

Quoted 7 lines · Ian Campbell, on Wed 16 Dec 2015 12:31:08 +0000, wrote:

... rather than in the libxc rule.

This puts all the header dependencies in one place and will allow us to avoid races when more libraries which need these headers are introduced. I observed issues with the xen-foreign/tmp.size file getting deleted in parallel with another process trying to use it.

Quoted 8 lines

The mini-os links are already created in the mk-headers-$(XEN_TARGET_ARCH) target so the other places which do so are redundant, in the case of polarssl and vtpmmgr indirectly through their eventual dependency on newlib which in turn depends on mk-headers-$(XEN_TARGET_ARCH).

Quoted 48 lines

---
v7: New patch.

---
 stubdom/Makefile | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
stubdom/Makefile +2 -5
index e1359cf..fd84024 100644
@@ -304,6 +304,7 @@ ioemu/linkfarm.stamp:
 endif
 
 mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
+	$(MAKE) -C $(XEN_ROOT)/tools/include
 	mkdir -p include/xen && \
           ln -sf $(wildcard $(XEN_ROOT)/xen/include/public/*.h) include/xen && \
           ln -sf $(addprefix $(XEN_ROOT)/xen/include/public/,arch-x86 hvm io xsm) include/xen && \
@@ -341,9 +342,7 @@ $(TARGETS_MINIOS): mini-os-%:
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: cross-zlib
-	$(MAKE) -C $(XEN_ROOT)/tools/include
-	$(MAKE) DESTDIR= -C $(MINI_OS) links
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) cross-zlib
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
  libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
@@ -386,7 +385,6 @@ c: $(CROSS_ROOT)
 
 .PHONY: vtpm
 vtpm: cross-polarssl cross-tpmemu
-	make -C $(MINI_OS) links
 	XEN_TARGET_ARCH="$(XEN_TARGET_ARCH)" CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
 
 ######
@@ -395,7 +393,6 @@ vtpm: cross-polarssl cross-tpmemu
 
 .PHONY: vtpmmgr
 vtpmmgr: cross-polarssl
-	make -C $(MINI_OS) links
 	XEN_TARGET_ARCH="$(XEN_TARGET_ARCH)" CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
 
 ######
Signature · 1 line
2.1.4
Signature · 2 lines
Samuel
<xterm> The problem with America is stupidity. I'm not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself?
author Applied
#4 lore raw

Re: [PATCH XEN v7 01/29] stubdom: recurse into tools/include in mk-headers-$(XEN_TARGET_ARCH) rule

Quoted 14 lines · Samuel Thibault
Quoted 13 lines · Ian Campbell, on Wed 16 Dec 2015 12:31:08 +0000, wrote:

... rather than in the libxc rule.

This puts all the header dependencies in one place and will allow us to avoid races when more libraries which need these headers are introduced. I observed issues with the xen-foreign/tmp.size file getting deleted in parallel with another process trying to use it.

The mini-os links are already created in the mk-headers-$(XEN_TARGET_ARCH) target so the other places which do so are redundant, in the case of polarssl and vtpmmgr indirectly through their eventual dependency on newlib which in turn depends on mk-headers-$(XEN_TARGET_ARCH).

Quoted 4 lines
Quoted 2 lines

Thanks, applied.

Acked-by on v7 1/29
#5 lore raw

Re: [PATCH XEN v7 01/29] stubdom: recurse into tools/include in mk-headers-$(XEN_TARGET_ARCH) rule

In reply to Ian Campbell
Quoted 7 lines · Ian Campbell

... rather than in the libxc rule.

This puts all the header dependencies in one place and will allow us to avoid races when more libraries which need these headers are introduced. I observed issues with the xen-foreign/tmp.size file getting deleted in parallel with another process trying to use it.

Quoted 8 lines

The mini-os links are already created in the mk-headers-$(XEN_TARGET_ARCH) target so the other places which do so are redundant, in the case of polarssl and vtpmmgr indirectly through their eventual dependency on newlib which in turn depends on mk-headers-$(XEN_TARGET_ARCH).

#6 lore raw

PATCH v7 2/29 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.

Note that this patch was applied as c7d3afbb44b4 but reverted via ec0712576198. See
http://lists.xen.org/archives/html/xen-devel/2015-12/msg01153.html

As of v7 the QEMU_TAG and MINIOS_UPSTREAM_REVISION updates corresponding to that push are included in the patch (since the master branches of those repos has not been reverted). If those patches are subsequently reverted as described in the mail then git am will gripe about this commit.

v2: Update doc at same time
v3: Move into tools/libs/toollog.
v6: Dropped spurious debugging changes to tools/ocaml/Makefile.rules
v7: Added Config.mk update
Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of open coding the recursion.

---
 .gitignore                                         |  1 +
 Config.mk                                          | 12 ++---
 stubdom/Makefile                                   | 22 +++++++-
 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/libs/xentoollog/Makefile               |  6 +--
 tools/ocaml/libs/xentoollog/genlevels.py           |  2 +-
 tools/python/setup.py                              |  5 +-
 tools/xenpaging/Makefile                           |  2 +-
 18 files changed, 139 insertions(+), 29 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 91e1430..a2c85e1 100644
@@ -58,6 +58,7 @@ stubdom/gcc-*
 stubdom/include
 stubdom/ioemu
 stubdom/xenstore
+stubdom/libxentoollog-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
Config.mk +6 -6
index 216a642..8fc7767 100644
@@ -255,9 +255,9 @@ MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/mini-os.git
 endif
 OVMF_UPSTREAM_REVISION ?= 52a99493cce88a9d4ec8a02d7f1bd1a1001ce60d
 QEMU_UPSTREAM_REVISION ?= master
-MINIOS_UPSTREAM_REVISION ?= bccd90071e863ec22216a000f1a07035e2f226ff
-# Mon Nov 23 16:34:31 2015 +0000
-# Add a .gitignore
+MINIOS_UPSTREAM_REVISION ?= d25773c8afa2f4dbbb466116daeb60159ddd22bd
+# Thu Dec 3 11:23:25 2015 +0000
+# mini-os: Include libxentoollog with libxc
 
 SEABIOS_UPSTREAM_REVISION ?= rel-1.9.0
 # Tue Nov 17 09:18:44 2015 -0500
@@ -266,9 +266,9 @@ SEABIOS_UPSTREAM_REVISION ?= rel-1.9.0
 ETHERBOOT_NICS ?= rtl8139 8086100e
 
 
-QEMU_TRADITIONAL_REVISION ?= 91c15bfaec1764ce2896a393eabee1183afe1130
-# Wed Dec 9 11:47:35 2015 +0000
-# net: pcnet: add check to validate receive data size(CVE-2015-7504)
+QEMU_TRADITIONAL_REVISION ?= 9fad9ed285835caef64bb8dab352e287ad8538c2
+# Thu Dec 3 11:23:16 2015 +0000
+# qemu-xen-traditional: Use xentoollog as a separate library
 
 # Specify which qemu-dm to use. This may be `ioemu' to use the old
 # Mercurial in-tree version, or a local directory, or a git URL.
stubdom/Makefile +21 -1
index fd84024..9c77205 100644
@@ -314,6 +314,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 . && \
@@ -337,12 +342,21 @@ $(TARGETS_MINIOS): mini-os-%:
 	done
 
 #######
+# libxentoollog
+#######
+
+.PHONY: libxentoollog
+libxentoollog: libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a
+libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
+	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: mk-headers-$(XEN_TARGET_ARCH) cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog cross-zlib
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
  libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
@@ -512,6 +526,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
@@ -522,6 +541,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 820ca40..9f74ac7 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 37b0aaf..7516ddd 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 818f2e4..940708f 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
@@ -112,6 +110,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))
@@ -165,7 +164,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)
@@ -208,7 +207,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
 	$(SYMLINK_SHLIB) $< $@
 
 libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(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 6ff5bee..2abae0c 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/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 fdba866..9771cc4 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
#7 lore raw

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

Quoted 23 lines · 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:

Quoted 8 lines

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

Note that this patch was applied as c7d3afbb44b4 but reverted via ec0712576198. See
http://lists.xen.org/archives/html/xen-devel/2015-12/msg01153.html

The corresponding libvirt support for this change was added to libvirt.git in 716be2570a38bc92581e31e3fec6b1ca92302c1e
Author: Ian Campbell <[email protected]>
Date:   Thu Dec 10 11:38:36 2015 +0000

    libxl: Use libxentoollog in preference to libxenctrl if available.

The contents of our output libvirt push gate is now d5a0cf10 which is after that change.

Therefore I have reapplied.

Quoted 5 lines

As of v7 the QEMU_TAG and MINIOS_UPSTREAM_REVISION updates corresponding to that push are included in the patch (since the master branches of those repos has not been reverted). If those patches are subsequently reverted as described in the mail then git am will gripe about this commit.

MINIOS_UPSTREAM_REVISION was unchanged in the interim.

QEMU_TRADITION_REVISION had since progressed to 569eac99e8dd which is after 9fad9ed28583, the commit needed here so I have dropped that hunk. Note that 9fad9ed28583 turned out to be harmless even without the corresponding xen.git change (this patch) since all it did was add until now non-existent
path to the include path and rpath-link.

Ian.

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

#8 lore raw

PATCH v7 3/29 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 01a6dda..881dcd5 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 6c0c0d6..cb79f22 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 f603c15..f4d155a 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
#9 lore raw

PATCH v7 4/29 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
v4: typedef the xenevtchn_handle in xenguest.h instead of #include, to
avoid leaking the libxenevtchn namespace into callers who may not want it. (And also to avoid adding lots of -I to places like stubdom builds)
v5: Handle NULL passed to _close()
v6: Properly port xen-access to new API (instead of a single function call)
v7: Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of
open coding the recursion.

---
 .gitignore                                    |   1 +
 stubdom/Makefile                              |  17 +-
 tools/Makefile                                |   5 +-
 tools/Rules.mk                                |  14 +-
 tools/console/Makefile                        |   2 +
 tools/console/daemon/io.c                     |  43 ++--
 tools/libs/Makefile                           |   1 +
 tools/libs/evtchn/Makefile                    |  65 +++++++
 tools/libs/evtchn/core.c                      |  72 +++++++
 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                |  14 +-
 tools/libxc/xc_evtchn_compat.c                |  75 +++++++
 tools/libxc/xc_freebsd_osdep.c                | 101 ----------
 tools/libxc/xc_linux_osdep.c                  |  95 ---------
 tools/libxc/xc_minios.c                       | 221 ---------------------
 tools/libxc/xc_netbsd.c                       | 109 -----------
 tools/libxc/xc_private.c                      |  40 ----
 tools/libxc/xc_private.h                      |   7 -
 tools/libxc/xc_solaris.c                      |  97 ----------
 tools/libxc/xc_suspend.c                      |  18 +-
 tools/libxl/Makefile                          |   5 +-
 tools/libxl/libxl.c                           |   2 +-
 tools/libxl/libxl_dom_suspend.c               |   4 +-
 tools/libxl/libxl_event.c                     |  14 +-
 tools/libxl/libxl_internal.h                  |   5 +-
 tools/misc/Makefile                           |   7 +-
 tools/misc/xen-hptool.c                       |  13 +-
 tools/misc/xen-lowmemd.c                      |  15 +-
 tools/ocaml/libs/eventchn/Makefile            |   4 +-
 tools/ocaml/libs/eventchn/xeneventchn_stubs.c |  20 +-
 tools/python/setup.py                         |   7 +-
 tools/tests/xen-access/Makefile               |   3 +-
 tools/tests/xen-access/xen-access.c           |  21 +-
 tools/xcutils/Makefile                        |   4 +-
 tools/xenmon/Makefile                         |   2 +
 tools/xenmon/xenbaked.c                       |  13 +-
 tools/xenpaging/Makefile                      |   4 +-
 tools/xenpaging/xenpaging.c                   |  18 +-
 tools/xenpaging/xenpaging.h                   |   3 +-
 tools/xenstore/Makefile                       |   5 +-
 tools/xenstore/xenstored_core.c               |   6 +-
 tools/xenstore/xenstored_domain.c             |  25 +--
 tools/xentrace/Makefile                       |   5 +-
 tools/xentrace/xentrace.c                     |  13 +-
 61 files changed, 1530 insertions(+), 925 deletions(-)
 create mode 100644 tools/libs/evtchn/Makefile
 create mode 100644 tools/libs/evtchn/core.c
 create mode 100644 tools/libs/evtchn/freebsd.c
 create mode 100644 tools/libs/evtchn/include/xenevtchn.h
 create mode 100644 tools/libs/evtchn/libxenevtchn.map
 create mode 100644 tools/libs/evtchn/linux.c
 create mode 100644 tools/libs/evtchn/minios.c
 create mode 100644 tools/libs/evtchn/netbsd.c
 create mode 100644 tools/libs/evtchn/private.h
 create mode 100644 tools/libs/evtchn/solaris.c
 create mode 100644 tools/libxc/include/xenctrl_compat.h
 create mode 100644 tools/libxc/xc_evtchn_compat.c
.gitignore +1 -0
index a2c85e1..bf382e5 100644
@@ -59,6 +59,7 @@ stubdom/include
 stubdom/ioemu
 stubdom/xenstore
 stubdom/libxentoollog-*
+stubdom/libxenevtchn-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
stubdom/Makefile +16 -1
index 9c77205..702d66b 100644
@@ -319,6 +319,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libs/toollog/include/*.h . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/toollog/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/toollog/Makefile . )
+	mkdir -p libs-$(XEN_TARGET_ARCH)/evtchn/include
+	[ -h libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/evtchn && \
+	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/Makefile . )
 	mkdir -p libxc-$(XEN_TARGET_ARCH)
 	[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
 	  ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -351,12 +357,21 @@ libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: mk-headers-$(XEN_TARGET_ARCH) $
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog
 
 #######
+# libxenevtchn
+#######
+
+.PHONY: libxenevtchn
+libxenevtchn: libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a
+libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn cross-zlib
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
  libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
tools/Makefile +4 -1
index 9f74ac7..99e016a 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 7516ddd..75d02c4 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=$(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 +72 -0

72 lines not on this page · raw message

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

138 lines not on this page · raw message

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

150 lines not on this page · raw message

tools/libs/evtchn/libxenevtchn.map new file +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 940708f..b8fc6a5 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
@@ -111,6 +112,7 @@ CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
 
 CFLAGS	+= $(PTHREAD_CFLAGS)
 CFLAGS	+= $(CFLAGS_libxentoollog)
+CFLAGS	+= $(CFLAGS_libxenevtchn)
 
 CTRL_LIB_OBJS := $(patsubst %.c,%.o,$(CTRL_SRCS-y))
 CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y))
@@ -164,7 +166,7 @@ install: build
 	$(INSTALL_DATA) libxenctrl.a $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR)
 	$(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenctrl.so
-	$(INSTALL_DATA) include/xenctrl.h include/xenctrlosdep.h $(DESTDIR)$(includedir)
+	$(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h include/xenctrlosdep.h $(DESTDIR)$(includedir)
 	$(INSTALL_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
 	$(INSTALL_DATA) libxenguest.a $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenguest.so.$(MAJOR)
@@ -207,7 +209,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
 	$(SYMLINK_SHLIB) $< $@
 
 libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 # libxenguest
 
@@ -230,7 +232,7 @@ xc_dom_bzimageloader.opic: CFLAGS += $(call zlib-options,D)
 
 libxenguest.so.$(MAJOR).$(MINOR): COMPRESSION_LIBS = $(call zlib-options,l)
 libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so
-	$(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz $(LDLIBS_libxenctrl) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 xenctrl_osdep_ENOSYS.so: $(OSDEP_PIC_OBJS) libxenctrl.so
 	$(CC) $(LDFLAGS) $(SHLIB_LDFLAGS) -o $@ $(OSDEP_PIC_OBJS) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
tools/libxc/include/xenctrl.h +3 -96

124 lines not on this page · raw message

tools/libxc/include/xenctrl_compat.h new file +48 -0

48 lines not on this page · raw message

tools/libxc/include/xenguest.h +10 -4
index 8f918b1..050a537 100644
@@ -34,6 +34,12 @@
 #define X86_64_B_SIZE   64 
 #define X86_32_B_SIZE   32
 
+/*
+ * User not using xc_suspend_* / xc_await_suspent may not want to
+ * include the full libxenevtchn API here.
+ */
+typedef struct xenevtchn_handle xenevtchn_handle;
+
 /* callbacks provided by xc_domain_save */
 struct save_callbacks {
     /* Called after expiration of checkpoint interval,
@@ -161,18 +167,18 @@ struct xc_hvm_firmware_module {
  * Sets *lockfd to -1.
  * Has deallocated everything even on error.
  */
-int xc_suspend_evtchn_release(xc_interface *xch, xc_evtchn *xce, int domid, int suspend_evtchn, int *lockfd);
+int xc_suspend_evtchn_release(xc_interface *xch, xenevtchn_handle *xce, int domid, int suspend_evtchn, int *lockfd);
 
 /**
  * This function eats the initial notification.
  * xce must not be used for anything else
  * See xc_suspend_evtchn_init_sane re lockfd.
  */
-int xc_suspend_evtchn_init_exclusive(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_init_exclusive(xc_interface *xch, xenevtchn_handle *xce,
                                      int domid, int port, int *lockfd);
 
 /* xce must not be used for anything else */
-int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn);
+int xc_await_suspend(xc_interface *xch, xenevtchn_handle *xce, int suspend_evtchn);
 
 /**
  * The port will be signaled immediately after this call
@@ -181,7 +187,7 @@ int xc_await_suspend(xc_interface *xch, xc_evtchn *xce, int suspend_evtchn);
  * and fed to xc_suspend_evtchn_release.  (On error *lockfd is
  * undefined and xc_suspend_evtchn_release is not allowed.)
  */
-int xc_suspend_evtchn_init_sane(xc_interface *xch, xc_evtchn *xce,
+int xc_suspend_evtchn_init_sane(xc_interface *xch, xenevtchn_handle *xce,
                                 int domid, int port, int *lockfd);
 
 int xc_mark_page_online(xc_interface *xch, unsigned long start,
tools/libxc/xc_evtchn_compat.c new file +75 -0

75 lines not on this page · raw message

tools/libxc/xc_freebsd_osdep.c +0 -101

118 lines not on this page · raw message

tools/libxc/xc_linux_osdep.c +0 -95

107 lines not on this page · raw message

tools/libxc/xc_minios.c +0 -221

247 lines not on this page · raw message

tools/libxc/xc_netbsd.c +0 -109

121 lines not on this page · raw message

tools/libxc/xc_private.c +0 -40
index cb79f22..56d54b6 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 f4d155a..a32accb 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 2abae0c..10b1741 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 bd3aac8..9f3153b 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 139e49a..8548365 100644
@@ -739,7 +739,7 @@ static void evtchn_fd_callback(libxl__egc *egc, libxl__ev_fd *ev,
         /* OK, that's that workaround done.  We can actually check for
          * work for us to do: */
 
-        port = xc_evtchn_pending(CTX->xce);
+        port = xenevtchn_pending(CTX->xce);
         if (port < 0) {
             if (errno == EAGAIN)
                 break;
@@ -765,20 +765,20 @@ static void evtchn_fd_callback(libxl__egc *egc, libxl__ev_fd *ev,
 }
 
 int libxl__ctx_evtchn_init(libxl__gc *gc) {
-    xc_evtchn *xce;
+    xenevtchn_handle *xce;
     int rc, fd;
 
     if (CTX->xce)
         return 0;
 
-    xce = xc_evtchn_open(CTX->lg, 0);
+    xce = xenevtchn_open(CTX->lg, 0);
     if (!xce) {
         LOGE(ERROR,"cannot open libxc evtchn handle");
         rc = ERROR_FAIL;
         goto out;
     }
 
-    fd = xc_evtchn_fd(xce);
+    fd = xenevtchn_fd(xce);
     assert(fd >= 0);
 
     rc = libxl_fd_set_nonblock(CTX, fd, 1);
@@ -788,7 +788,7 @@ int libxl__ctx_evtchn_init(libxl__gc *gc) {
     return 0;
 
  out:
-    xc_evtchn_close(xce);
+    xenevtchn_close(xce);
     return rc;
 }
 
@@ -810,14 +810,14 @@ int libxl__ev_evtchn_wait(libxl__gc *gc, libxl__ev_evtchn *evev)
 
     if (!libxl__ev_fd_isregistered(&CTX->evtchn_efd)) {
         rc = libxl__ev_fd_register(gc, &CTX->evtchn_efd, evtchn_fd_callback,
-                                   xc_evtchn_fd(CTX->xce), POLLIN);
+                                   xenevtchn_fd(CTX->xce), POLLIN);
         if (rc) goto out;
     }
 
     if (evev->waiting)
         return 0;
 
-    r = xc_evtchn_unmask(CTX->xce, evev->port);
+    r = xenevtchn_unmask(CTX->xce, evev->port);
     if (r) {
         LOGE(ERROR,"cannot unmask event channel %d",evev->port);
         rc = ERROR_FAIL;
tools/libxl/libxl_internal.h +3 -2
index d2bda0a..fa01dd7 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>
@@ -441,7 +442,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;
 
@@ -916,7 +917,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)
[… 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 9771cc4..ce317b4 100644

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

tools/tests/xen-access/Makefile +2 -1
index f810543..97cfae4 100644

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

tools/tests/xen-access/xen-access.c +11 -10
index a52ca6e..7993947 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 3c0307e..f62c192 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.

#10 lore raw

Re: [PATCH XEN v7 04/29] tools: Refactor /dev/xen/evtchn wrappers into libxenevtchn.

tools/libs/evtchn/Makefile line 65

Quoted 10 lines · Ian Campbell
tools/libs/evtchn/Makefile new file +4 -0
new file mode 100644
index 0000000..85ed6dc
[...]
+
+.PHONY: clean
+clean:
+	rm -rf *.rpm $(LIB) *~ $(DEPS) $(LIB_OBJS) $(PIC_OBJS)

This, and presumably all the subsequent patches adding new libraries, needs a distclean and to remote the .so file, as Juergen did for libxentoollog in
http://lists.xenproject.org/archives/html/xen-devel/2016-01/msg00611.html

Ian.

#11 lore raw

PATCH v7 5/29 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.

---
v7: Drop -pendantic: Some library headers include parts of
xen/include/public, which in turn are not -pedantic clean Retained ack, hope that's ok.

---
 .gitignore                  | 2 ++
 tools/Rules.mk              | 8 ++++++++
 tools/libs/evtchn/Makefile  | 4 +++-
 tools/libs/toollog/Makefile | 5 ++++-
 4 files changed, 17 insertions(+), 2 deletions(-)
.gitignore +2 -0
index bf382e5..b34dc3c 100644
@@ -86,6 +86,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 75d02c4..0c83e22 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 $(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
#12 lore raw

PATCH v7 6/29 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 b8fc6a5..184cbb7 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 8f31c4d..0fc2a11 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 a32accb..35c99e0 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
#13 lore raw

PATCH v7 7/29 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.

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"

v5: Allow _close(NULL).

v6: The extensive API document updates from the previous round of
review have been implemented in "tools/libs/gnttab: Extensive updates to API documentation." later in the series, so as not to add further functional changes than already required to this refactoring patch.

v7: Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of
open coding the recursion. s/gnttab_munmap/gnttab_unmap/ and s/gntshr_munmap/gntshr_unshare/ in the API and equivalents in the internals/osdeps etc.

---
 .gitignore                                         |   2 +
 stubdom/Makefile                                   |  17 +-
 tools/Makefile                                     |   3 +
 tools/Rules.mk                                     |  14 +-
 tools/console/Makefile                             |   5 +-
 tools/console/daemon/io.c                          |  21 +-
 tools/libs/Makefile                                |   1 +
 tools/libs/evtchn/minios.c                         |   5 +-
 tools/libs/gnttab/Makefile                         |  69 +++++
 tools/libs/gnttab/gntshr_core.c                    |  95 ++++++
 .../xc_nognttab.c => libs/gnttab/gntshr_unimp.c}   |  34 ++-
 tools/libs/gnttab/gnttab_core.c                    | 124 ++++++++
 tools/libs/gnttab/gnttab_unimp.c                   |  89 ++++++
 tools/libs/gnttab/include/xengnttab.h              | 216 ++++++++++++++
 tools/libs/gnttab/libxengnttab.map                 |  23 ++
 tools/libs/gnttab/linux.c                          | 329 +++++++++++++++++++++
 tools/libs/gnttab/minios.c                         | 117 ++++++++
 tools/libs/gnttab/private.h                        |  47 +++
 tools/libvchan/Makefile                            |   8 +-
 tools/libvchan/init.c                              |  26 +-
 tools/libvchan/io.c                                |   8 +-
 tools/libvchan/libxenvchan.h                       |   6 +-
 tools/libxc/Makefile                               |  15 +-
 tools/libxc/include/xenctrl.h                      | 168 -----------
 tools/libxc/include/xenctrl_compat.h               |  48 +++
 tools/libxc/xc_gnttab.c                            |  53 ----
 tools/libxc/xc_gnttab_compat.c                     | 111 +++++++
 tools/libxc/xc_linux_osdep.c                       | 280 ------------------
 tools/libxc/xc_minios.c                            |  73 -----
 tools/libxc/xc_nogntshr.c                          |  46 ---
 tools/libxc/xc_private.c                           |  80 -----
 tools/libxc/xc_private.h                           |  24 --
 tools/xenstore/Makefile                            |   4 +-
 tools/xenstore/xenstored_core.h                    |   4 +-
 tools/xenstore/xenstored_domain.c                  |  24 +-
 tools/xenstore/xenstored_minios.c                  |   5 +-
 36 files changed, 1393 insertions(+), 801 deletions(-)
 create mode 100644 tools/libs/gnttab/Makefile
 create mode 100644 tools/libs/gnttab/gntshr_core.c
 rename tools/{libxc/xc_nognttab.c => libs/gnttab/gntshr_unimp.c} (52%)
 create mode 100644 tools/libs/gnttab/gnttab_core.c
 create mode 100644 tools/libs/gnttab/gnttab_unimp.c
 create mode 100644 tools/libs/gnttab/include/xengnttab.h
 create mode 100644 tools/libs/gnttab/libxengnttab.map
 create mode 100644 tools/libs/gnttab/linux.c
 create mode 100644 tools/libs/gnttab/minios.c
 create mode 100644 tools/libs/gnttab/private.h
 create mode 100644 tools/libxc/xc_gnttab_compat.c
 delete mode 100644 tools/libxc/xc_nogntshr.c
.gitignore +2 -0
index b34dc3c..9241c54 100644
@@ -60,6 +60,7 @@ stubdom/ioemu
 stubdom/xenstore
 stubdom/libxentoollog-*
 stubdom/libxenevtchn-*
+stubdom/libxengnttab-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
@@ -88,6 +89,7 @@ config/Stubdom.mk
 config/Docs.mk
 tools/libs/toollog/headers.chk
 tools/libs/evtchn/headers.chk
+tools/libs/gnttab/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
stubdom/Makefile +16 -1
index 702d66b..2dbf4a8 100644
@@ -325,6 +325,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/include/*.h include/ && \
 	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/evtchn/Makefile . )
+	mkdir -p libs-$(XEN_TARGET_ARCH)/gnttab/include
+	[ -h libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/gnttab && \
+	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/Makefile . )
 	mkdir -p libxc-$(XEN_TARGET_ARCH)
 	[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
 	  ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -366,12 +372,21 @@ libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(N
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn
 
 #######
+# libxengnttab
+#######
+
+.PHONY: libxengnttab
+libxengnttab: libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a
+libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab cross-zlib
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
  libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
tools/Makefile +3 -0
index 99e016a..f373e71 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 0c83e22..379990f 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..e2e7a6b 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_unmap(xgt_handle, dom->interface, 1);
 	else
 		munmap(dom->interface, XC_PAGE_SIZE);
 	dom->interface = NULL;
@@ -552,9 +553,9 @@ static int domain_create_ring(struct domain *dom)
 	if (ring_ref != dom->ring_ref && dom->ring_ref != -1)
 		domain_unmap_interface(dom);
 
-	if (!dom->interface && xcg_handle) {
+	if (!dom->interface && xgt_handle) {
 		/* Prefer using grant table */
-		dom->interface = xc_gnttab_map_grant_ref(xcg_handle,
+		dom->interface = xengnttab_map_grant_ref(xgt_handle,
 			dom->domid, GNTTAB_RESERVED_CONSOLE,
 			PROT_READ|PROT_WRITE);
 		dom->ring_ref = -1;
@@ -1029,8 +1030,8 @@ void handle_io(void)
 		handle_hv_logs(xce_handle, true);
 	}
 
-	xcg_handle = xc_gnttab_open(NULL, 0);
-	if (xcg_handle == NULL) {
+	xgt_handle = xengnttab_open(NULL, 0);
+	if (xgt_handle == NULL) {
 		dolog(LOG_DEBUG, "Failed to open xcg handle: %d (%s)",
 		      errno, strerror(errno));
 	}
@@ -1206,9 +1207,9 @@ void handle_io(void)
 		xenevtchn_close(xce_handle);
 		xce_handle = NULL;
 	}
-	if (xcg_handle != NULL) {
-		xc_gnttab_close(xcg_handle);
-		xcg_handle = NULL;
+	if (xgt_handle != NULL) {
+		xengnttab_close(xgt_handle);
+		xgt_handle = NULL;
 	}
 	log_hv_evtchn = -1;
 }
tools/libs/Makefile +1 -0
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 +95 -0

95 lines not on this page · raw message

tools/libs/gnttab/gntshr_unimp.c renamed from tools/libxc/xc_nognttab.c +23 -11
similarity index 52%
rename from tools/libxc/xc_nognttab.c
rename to tools/libs/gnttab/gntshr_unimp.c
index e8a0fcb..e210484 100644
@@ -14,37 +14,49 @@
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Split out from xc_gnttab.c
  */
 
 #include <stdlib.h>
 
-#include "xc_private.h"
+#include "private.h"
 
-int osdep_gnttab_open(xc_gnttab *xgt)
+xengntshr_handle *xengntshr_open(xentoollog_logger *logger, unsigned open_flags)
 {
-    return -1;
+    return NULL;
 }
 
-int osdep_gnttab_close(xc_gnttab *xgt)
+int xengntshr_close(xengntshr_handle *xgs)
 {
     return 0;
 }
 
-int xc_gnttab_set_max_grants(xc_gnttab *xgt, uint32_t count)
+void *xengntshr_share_pages(xengntshr_handle *xcg, uint32_t domid,
+                            int count, uint32_t *refs, int writable)
 {
     abort();
 }
 
-void *osdep_gnttab_grant_map(xc_gnttab *xgt,
-                             uint32_t count, int flags, int prot,
-                             uint32_t *domids, uint32_t *refs,
-                             uint32_t notify_offset,
-                             evtchn_port_t notify_port)
+void *xengntshr_share_page_notify(xengntshr_handle *xcg, uint32_t domid,
+                                  uint32_t *ref, int writable,
+                                  uint32_t notify_offset,
+                                  evtchn_port_t notify_port)
 {
     abort();
 }
 
-int xc_gnttab_munmap(xc_gnttab *xgt, void *start_address, uint32_t count)
+int xengntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count)
 {
     abort();
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libs/gnttab/gnttab_core.c new file +124 -0

124 lines not on this page · raw message

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

89 lines not on this page · raw message

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

216 lines not on this page · raw message

tools/libs/gnttab/libxengnttab.map new file +23 -0
new file mode 100644
index 0000000..66e8c12
@@ -0,0 +1,23 @@
+VERS_1.0 {
+	global:
+		xengnttab_open;
+		xengnttab_close;
+
+		xengnttab_set_max_grants;
+
+		xengnttab_map_domain_grant_refs;
+		xengnttab_map_grant_ref;
+		xengnttab_map_grant_ref_notify;
+		xengnttab_map_grant_refs;
+
+		xengnttab_unmap;
+		
+		xengntshr_open;
+		xengntshr_close;
+		
+		xengntshr_share_page_notify;
+		xengntshr_share_pages;
+		
+		xengntshr_unshare;
+	local: *; /* Do not expose anything by default */
+};
tools/libs/gnttab/linux.c new file +329 -0

329 lines not on this page · raw message

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

117 lines not on this page · raw message

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

47 lines not on this page · raw message

tools/libvchan/Makefile +5 -3
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 +13 -13
index 66cb103..91531b9 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_unshare(ctrl->gntshr, ctrl->read.buffer, pages_left);
 out_ring:
-	xc_gntshr_munmap(ctrl->gntshr, ring, 1);
+	xengntshr_unshare(ctrl->gntshr, ring, 1);
 	ring_ref = -1;
 	ctrl->ring = NULL;
 	ctrl->write.order = ctrl->read.order = 0;
@@ -142,7 +142,7 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
 	int rv = -1;
 	uint32_t *grants;
 
-	ctrl->ring = xc_gnttab_map_grant_ref_notify(ctrl->gnttab,
+	ctrl->ring = xengnttab_map_grant_ref_notify(ctrl->gnttab,
 		domain, ring_ref, PROT_READ|PROT_WRITE,
 		offsetof(struct vchan_interface, cli_live), ctrl->event_port);
 
@@ -172,7 +172,7 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
 	default:
 		{
 			int pages_left = 1 << (ctrl->write.order - PAGE_SHIFT);
-			ctrl->write.buffer = xc_gnttab_map_domain_grant_refs(ctrl->gnttab,
+			ctrl->write.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
 				pages_left, domain, grants, PROT_READ|PROT_WRITE);
 			if (!ctrl->write.buffer)
 				goto out_unmap_ring;
@@ -190,7 +190,7 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
 	default:
 		{
 			int pages_right = 1 << (ctrl->read.order - PAGE_SHIFT);
-			ctrl->read.buffer = xc_gnttab_map_domain_grant_refs(ctrl->gnttab,
+			ctrl->read.buffer = xengnttab_map_domain_grant_refs(ctrl->gnttab,
 				pages_right, domain, grants, PROT_READ);
 			if (!ctrl->read.buffer)
 				goto out_unmap_left;
@@ -202,10 +202,10 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref)
 	return rv;
  out_unmap_left:
 	if (ctrl->write.order >= PAGE_SHIFT)
-		xc_gnttab_munmap(ctrl->gnttab, ctrl->write.buffer,
-		                 1 << (ctrl->write.order - PAGE_SHIFT));
+		xengnttab_unmap(ctrl->gnttab, ctrl->write.buffer,
+		                1 << (ctrl->write.order - PAGE_SHIFT));
  out_unmap_ring:
-	xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
+	xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
 	ctrl->ring = 0;
 	ctrl->write.order = ctrl->read.order = 0;
 	rv = -1;
@@ -325,7 +325,7 @@ struct libxenvchan *libxenvchan_server_init(xentoollog_logger *logger, int domai
 		ctrl->write.order = LARGE_RING_SHIFT;
 	}
 
-	ctrl->gntshr = xc_gntshr_open(logger, 0);
+	ctrl->gntshr = xengntshr_open(logger, 0);
 	if (!ctrl->gntshr)
 		goto out;
 
@@ -413,7 +413,7 @@ struct libxenvchan *libxenvchan_client_init(xentoollog_logger *logger, int 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..6265219 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_unshare(ctrl->gntshr, ctrl->ring, 1);
 		} else {
 			ctrl->ring->cli_live = 0;
-			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
+			xengnttab_unmap(ctrl->gnttab, ctrl->ring, 1);
 		}
 	}
 	if (ctrl->event) {
@@ -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 184cbb7..33d18db 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
@@ -126,6 +127,8 @@ OSDEP_PIC_OBJS := $(patsubst %.c,%.opic,$(OSDEP_SRCS-y))
 $(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) $(OSDEP_LIB_OBJS) \
 $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS) $(OSDEP_PIC_OBJS) : CFLAGS += -include $(XEN_ROOT)/tools/config.h
 
+$(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr)
+
 LIB := libxenctrl.a
 ifneq ($(nosharedlibs),y)
 LIB += libxenctrl.so libxenctrl.so.$(MAJOR) libxenctrl.so.$(MAJOR).$(MINOR)
@@ -209,7 +212,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
 	$(SYMLINK_SHLIB) $< $@
 
 libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 # libxenguest
 
tools/libxc/include/xenctrl.h +0 -168

192 lines not on this page · raw message

tools/libxc/include/xenctrl_compat.h +48 -0

54 lines not on this page · raw message

tools/libxc/xc_gnttab.c +0 -53

59 lines not on this page · raw message

tools/libxc/xc_gnttab_compat.c new file +111 -0

111 lines not on this page · raw message

tools/libxc/xc_linux_osdep.c +0 -280

298 lines not on this page · raw message

tools/libxc/xc_minios.c +0 -73

91 lines not on this page · raw message

tools/libxc/xc_nogntshr.c deleted +0 -46

46 lines not on this page · raw message

tools/libxc/xc_private.c +0 -80

86 lines not on this page · raw message

tools/libxc/xc_private.h +0 -24
index 35c99e0..a32accb 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..414a9fd 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_unmap(*xgt_handle, interface, 1);
 	else
 		munmap(interface, XC_PAGE_SIZE);
 }
@@ -577,9 +577,9 @@ static int close_xc_handle(void *_handle)
 	return 0;
 }
 
-static int close_xcg_handle(void *_handle)
+static int close_xgt_handle(void *_handle)
 {
-	xc_gnttab_close(*(xc_gnttab **)_handle);
+	xengnttab_close(*(xengnttab_handle **)_handle);
 	return 0;
 }
 
@@ -634,15 +634,15 @@ void domain_init(void)
 
 	talloc_set_destructor(xc_handle, close_xc_handle);
 
-	xcg_handle = talloc(talloc_autofree_context(), xc_gnttab*);
-	if (!xcg_handle)
+	xgt_handle = talloc(talloc_autofree_context(), xengnttab_handle*);
+	if (!xgt_handle)
 		barf_perror("Failed to allocate domain gnttab handle");
 
-	*xcg_handle = xc_gnttab_open(NULL, 0);
-	if (*xcg_handle == NULL)
+	*xgt_handle = xengnttab_open(NULL, 0);
+	if (*xgt_handle == NULL)
 		xprintf("WARNING: Failed to open connection to gnttab\n");
 	else
-		talloc_set_destructor(xcg_handle, close_xcg_handle);
+		talloc_set_destructor(xgt_handle, close_xgt_handle);
 
 	xce_handle = xenevtchn_open(NULL, 0);
 
tools/xenstore/xenstored_minios.c +2 -3
index b686e1c..c94493e 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_unmap(*xgt_handle, interface, 1);
 }
 
Signature · 1 line
2.1.4
#14 lore raw

Re: [PATCH XEN v7 07/29] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab.

Quoted 7 lines · 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.

Quoted 8 lines

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

GNTTABOP presumably?

~Andrew

Quoted 6 lines

libxenctrl. Specifically:

- xc_gnttab_get_version
- xc_gnttab_map_table_v1
- xc_gnttab_map_table_v2
- xc_gnttab_op

#15 lore raw

Re: [PATCH XEN v7 07/29] tools: Refactor /dev/xen/gnt{dev, shr} wrappers into libxengnttab.

Quoted 10 lines · Andrew Cooper
Quoted 9 lines · 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.

All in-tree users are updated to use the new names.

Quoted 8 lines
Quoted 6 lines

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

GNTTABOP presumably?

Uh, yes, I think I may have copied a bit to eagerly from the libxenevtchn patch description!

Quoted 9 lines

~Andrew

Quoted 6 lines

libxenctrl. Specifically:

- xc_gnttab_get_version
- xc_gnttab_map_table_v1
- xc_gnttab_map_table_v2
- xc_gnttab_op

#16 lore raw

PATCH v7 8/29 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.

---
v7: Stop CCing Dave's dead citrix address.

---
 config/FreeBSD.mk                   |   2 -
 config/NetBSD.mk                    |   3 -
 config/NetBSDRump.mk                |   1 -
 config/StdGNU.mk                    |   1 -
 config/SunOS.mk                     |   1 -
 tools/libxc/Makefile                |  27 ++----
 tools/libxc/include/xenctrl.h       |   9 --
 tools/libxc/include/xenctrlosdep.h  | 133 ---------------------------
 tools/libxc/xc_foreign_memory.c     |  31 +------
 tools/libxc/xc_freebsd_osdep.c      | 100 ++++++---------------
 tools/libxc/xc_hcall_buf.c          |   6 +-
 tools/libxc/xc_linux_osdep.c        |  88 ++++++------------
 tools/libxc/xc_minios.c             |  82 +++++------------
 tools/libxc/xc_netbsd.c             |  90 +++++++------------
 tools/libxc/xc_private.c            | 174 ++----------------------------------
 tools/libxc/xc_private.h            |  19 ++--
 tools/libxc/xc_solaris.c            |  90 +++++++------------
 tools/libxc/xenctrl_osdep_ENOSYS.c  | 123 -------------------------
 tools/ocaml/libs/xc/xenctrl.ml      |   2 -
 tools/ocaml/libs/xc/xenctrl.mli     |   1 -
 tools/ocaml/libs/xc/xenctrl_stubs.c |   7 --
 tools/ocaml/xenstored/domains.ml    |   6 +-
 tools/ocaml/xenstored/xenstored.ml  |   5 +-
 23 files changed, 178 insertions(+), 823 deletions(-)
 delete mode 100644 tools/libxc/include/xenctrlosdep.h
 delete mode 100644 tools/libxc/xenctrl_osdep_ENOSYS.c
config/FreeBSD.mk +0 -2
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 33d18db..3305fdd 100644
@@ -101,8 +101,6 @@ GUEST_SRCS-y                 += xc_dom_decompress_unsafe_lzo1x.c
 GUEST_SRCS-y                 += xc_dom_decompress_unsafe_xz.c
 endif
 
-OSDEP_SRCS-y                 += xenctrl_osdep_ENOSYS.c
-
 -include $(XEN_TARGET_ARCH)/Makefile
 
 CFLAGS   += -Werror -Wmissing-prototypes
@@ -121,11 +119,8 @@ CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y))
 GUEST_LIB_OBJS := $(patsubst %.c,%.o,$(GUEST_SRCS-y))
 GUEST_PIC_OBJS := $(patsubst %.c,%.opic,$(GUEST_SRCS-y))
 
-OSDEP_LIB_OBJS := $(patsubst %.c,%.o,$(OSDEP_SRCS-y))
-OSDEP_PIC_OBJS := $(patsubst %.c,%.opic,$(OSDEP_SRCS-y))
-
-$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) $(OSDEP_LIB_OBJS) \
-$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS) $(OSDEP_PIC_OBJS) : CFLAGS += -include $(XEN_ROOT)/tools/config.h
+$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \
+$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h
 
 $(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr)
 
@@ -139,17 +134,13 @@ ifneq ($(nosharedlibs),y)
 LIB += libxenguest.so libxenguest.so.$(MAJOR) libxenguest.so.$(MAJOR).$(MINOR)
 endif
 
-ifneq ($(nosharedlibs),y)
-LIB += xenctrl_osdep_ENOSYS.so
-endif
-
 genpath-target = $(call buildmakevars2header,_paths.h)
 $(eval $(genpath-target))
 
 xc_private.h: _paths.h
 
-$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) $(OSDEP_LIB_OBJS) \
-$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS) $(OSDEP_PIC_OBJS): xc_private.h
+$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \
+$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): xc_private.h
 
 .PHONY: all
 all: build
@@ -169,7 +160,7 @@ install: build
 	$(INSTALL_DATA) libxenctrl.a $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenctrl.so.$(MAJOR)
 	$(SYMLINK_SHLIB) libxenctrl.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenctrl.so
-	$(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h include/xenctrlosdep.h $(DESTDIR)$(includedir)
+	$(INSTALL_DATA) include/xenctrl.h include/xenctrl_compat.h $(DESTDIR)$(includedir)
 	$(INSTALL_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
 	$(INSTALL_DATA) libxenguest.a $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenguest.so.$(MAJOR)
@@ -185,8 +176,7 @@ clean:
 	rm -rf *.rpm $(LIB) *~ $(DEPS) \
             _paths.h \
             $(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS) \
-            $(GUEST_LIB_OBJS) $(GUEST_PIC_OBJS) \
-            $(OSDEP_LIB_OBJS) $(OSDEP_PIC_OBJS)
+            $(GUEST_LIB_OBJS) $(GUEST_PIC_OBJS)
 
 .PHONY: distclean
 distclean: clean
@@ -212,7 +202,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
 	$(SYMLINK_SHLIB) $< $@
 
 libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(DLOPEN_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 # libxenguest
 
@@ -237,8 +227,5 @@ libxenguest.so.$(MAJOR).$(MINOR): COMPRESSION_LIBS = $(call zlib-options,l)
 libxenguest.so.$(MAJOR).$(MINOR): $(GUEST_PIC_OBJS) libxenctrl.so
 	$(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenguest.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(GUEST_PIC_OBJS) $(COMPRESSION_LIBS) -lz $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
-xenctrl_osdep_ENOSYS.so: $(OSDEP_PIC_OBJS) libxenctrl.so
-	$(CC) $(LDFLAGS) $(SHLIB_LDFLAGS) -o $@ $(OSDEP_PIC_OBJS) $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
-
 -include $(DEPS)
 
tools/libxc/include/xenctrl.h +0 -9
index 16e2628..78400d3 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 a32accb..30157cf 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 41d228d..58a53a1 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 b4a175b..16443df 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 393156c..e2fa7e4 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
#17 lore raw

PATCH v7 9/29 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)

v5: Allow _close(NULL).

v6: Use size_t for nr_pages throughout.
Rebase over "libxc: prefer using privcmd character device"

v7: Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of
open coding the recursion.
Remove incorrect/spurious APP_LDLIBS (which anyway was removed by a later patch)

---
 .gitignore                        |   2 +
 stubdom/Makefile                  |  17 +++-
 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            | 147 +++++++++++++++++++++++++++++
 tools/libs/call/freebsd.c         | 140 +++++++++++++++++++++++++++
 tools/libs/call/include/xencall.h |  84 +++++++++++++++++
 tools/libs/call/libxencall.map    |  19 ++++
 tools/libs/call/linux.c           | 138 +++++++++++++++++++++++++++
 tools/libs/call/minios.c          |  81 ++++++++++++++++
 tools/libs/call/netbsd.c          | 121 ++++++++++++++++++++++++
 tools/libs/call/private.h         |  68 ++++++++++++++
 tools/libs/call/solaris.c         |  97 +++++++++++++++++++
 tools/libxc/Makefile              |   7 +-
 tools/libxc/xc_altp2m.c           |  64 ++++---------
 tools/libxc/xc_domain.c           | 105 +++++++--------------
 tools/libxc/xc_evtchn.c           |   9 +-
 tools/libxc/xc_flask.c            |   8 +-
 tools/libxc/xc_freebsd_osdep.c    |  47 ----------
 tools/libxc/xc_gnttab.c           |   9 +-
 tools/libxc/xc_hcall_buf.c        | 138 ++-------------------------
 tools/libxc/xc_kexec.c            |  36 +++----
 tools/libxc/xc_linux_osdep.c      |  49 ----------
 tools/libxc/xc_minios.c           |  32 -------
 tools/libxc/xc_misc.c             |  79 ++++++----------
 tools/libxc/xc_netbsd.c           |  40 --------
 tools/libxc/xc_private.c          |  64 +++++--------
 tools/libxc/xc_private.h          |  76 +++++----------
 tools/libxc/xc_solaris.c          |  16 ----
 tools/libxc/xc_tmem.c             |   7 +-
 tools/misc/Makefile               |   4 +-
 tools/xcutils/Makefile            |   2 +-
 tools/xenpaging/Makefile          |   2 +-
 36 files changed, 1344 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 9241c54..2899852 100644
@@ -61,6 +61,7 @@ stubdom/xenstore
 stubdom/libxentoollog-*
 stubdom/libxenevtchn-*
 stubdom/libxengnttab-*
+stubdom/libxencall-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
@@ -90,6 +91,7 @@ config/Docs.mk
 tools/libs/toollog/headers.chk
 tools/libs/evtchn/headers.chk
 tools/libs/gnttab/headers.chk
+tools/libs/call/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
stubdom/Makefile +16 -1
index 2dbf4a8..5bf4ed6 100644
@@ -331,6 +331,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/include/*.h include/ && \
 	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/gnttab/Makefile . )
+	mkdir -p libs-$(XEN_TARGET_ARCH)/call/include
+	[ -h libs-$(XEN_TARGET_ARCH)/call/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/call && \
+	  ln -sf $(XEN_ROOT)/tools/libs/call/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/call/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libs/call/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/call/Makefile . )
 	mkdir -p libxc-$(XEN_TARGET_ARCH)
 	[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
 	  ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -381,12 +387,21 @@ libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: mk-headers-$(XEN_TARGET_ARCH) $(N
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab
 
 #######
+# libxencall
+#######
+
+.PHONY: libxencall
+libxencall: libs-$(XEN_TARGET_ARCH)/call/libxencall.a
+libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall cross-zlib
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
  libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
tools/Makefile +1 -0
index f373e71..e5bbc98 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 379990f..18e3688 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 +147 -0

147 lines not on this page · raw message

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

140 lines not on this page · raw message

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

84 lines not on this page · raw message

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

138 lines not on this page · raw message

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

81 lines not on this page · raw message

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

121 lines not on this page · raw message

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

68 lines not on this page · raw message

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

97 lines not on this page · raw message

tools/libxc/Makefile +6 -1
index 3305fdd..a122f73 100644
@@ -122,6 +122,11 @@ GUEST_PIC_OBJS := $(patsubst %.c,%.opic,$(GUEST_SRCS-y))
 $(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \
 $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h
 
+# libxenguest includes xc_private.h, so needs this despite not using
+# this functionality directly.
+$(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \
+$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += $(CFLAGS_libxencall)
+
 $(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr)
 
 LIB := libxenctrl.a
@@ -202,7 +207,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
 	$(SYMLINK_SHLIB) $< $@
 
 libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(LDLIBS_libxencall) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 # libxenguest
 
tools/libxc/xc_altp2m.c +16 -48

203 lines not on this page · raw message

tools/libxc/xc_domain.c +36 -69

296 lines not on this page · raw message

tools/libxc/xc_evtchn.c +3 -6
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
#18 lore raw

PATCH v7 10/29 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 c93df7f..ecf2451 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
#19 lore raw

PATCH v7 11/29 tools: Remove xc_map_foreign_batch

In reply to Ian Campbell

It can trivially be replaced by xc_map_foreign_pages which is the interface I want to move to going forward (by standardising on _bulk but handling err=NULL as _pages does).

The callers of _batch are checking a mixture of a NULL return or looking to see if the top nibble of the (usually sole) mfn they pass has been modified to be non-zero to detect errors. _pages never modifies the mfn it was given (it's const) and returns NULL on failure, so adjust the error handling where necessary. Some callers use a copy of the mfn array, for reuse on failure with _batch, which is no longer necessary as _pages doesn't modify the array, however I haven't cleaned that up here.

This reduces the twist maze of xc_map_foreign_* by one, which will be useful when trying to come up with an underlying stable interface.

NetBSD and Solaris implemented xc_map_foreign_bulk in terms of xc_map_foreign_batch via a compat layer, so xc_map_foreign_batch becomes an internal osdep for them.

---
v7: Don't mention new ports implementing _bulk, which is confusing and
will be obsolete a couple of patches later.
v6: Switch to xc_map_foreign_pages not xc_map_foreign_bulk, since the
former has more similar error handling semantics to the current usage.

Dropped acks.

---
 tools/libxc/include/xenctrl.h   | 10 -------
 tools/libxc/xc_foreign_memory.c |  4 ++-
 tools/libxc/xc_linux_osdep.c    | 59 +++--------------------------------------
 tools/libxc/xc_minios.c         | 22 ---------------
 tools/libxc/xc_netbsd.c         | 10 +++----
 tools/libxc/xc_solaris.c        |  6 ++---
 tools/libxc/xc_vm_event.c       | 18 ++++++++++---
 tools/xenmon/xenbaked.c         | 12 ++++++++-
 tools/xenpaging/xenpaging.c     | 14 +++++-----
 tools/xentrace/xentrace.c       |  3 ++-
 10 files changed, 48 insertions(+), 110 deletions(-)
tools/libxc/include/xenctrl.h +0 -10
index 78400d3..cb41c07 100644
@@ -1387,16 +1387,6 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
                            const xen_pfn_t *arr, int num );
 
 /**
- * DEPRECATED - use xc_map_foreign_bulk() instead.
- *
- * Like xc_map_foreign_pages(), except it can succeeed partially.
- * When a page cannot be mapped, its PFN in @arr is or'ed with
- * 0xF0000000 to indicate the error.
- */
-void *xc_map_foreign_batch(xc_interface *xch, uint32_t dom, int prot,
-                           xen_pfn_t *arr, int num );
-
-/**
  * Like xc_map_foreign_pages(), except it can succeed partially.
  * When a page cannot be mapped, its respective field in @err is
  * set to the corresponding errno value.
tools/libxc/xc_foreign_memory.c +3 -1
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 +14 -4
index 2fef96a..d2d99e4 100644
@@ -72,9 +72,9 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
 
     ring_pfn = pfn;
     mmap_pfn = pfn;
-    ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ | PROT_WRITE,
+    ring_page = xc_map_foreign_pages(xch, domain_id, PROT_READ | PROT_WRITE,
                                      &mmap_pfn, 1);
-    if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+    if ( !ring_page )
     {
         /* Map failed, populate ring page */
         rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0,
@@ -86,9 +86,9 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
         }
 
         mmap_pfn = ring_pfn;
-        ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ | PROT_WRITE,
+        ring_page = xc_map_foreign_pages(xch, domain_id, PROT_READ | PROT_WRITE,
                                          &mmap_pfn, 1);
-        if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+        if ( !ring_page )
         {
             PERROR("Could not map the ring page\n");
             goto out;
@@ -156,3 +156,13 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
 
     return ring_page;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/xenmon/xenbaked.c +11 -1
index e4602ef..da46126 100644
@@ -411,7 +411,7 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
         for ( j=0; j<tbufs.t_info->tbuf_size; j++)
             pfn_list[j] = (xen_pfn_t)mfn_list[j];
 
-        tbufs.meta[i] = xc_map_foreign_batch(xc_handle, DOMID_XEN,
+        tbufs.meta[i] = xc_map_foreign_pages(xc_handle, DOMID_XEN,
                                              PROT_READ | PROT_WRITE,
                                              pfn_list,
                                              tbufs.t_info->tbuf_size);
@@ -1175,3 +1175,13 @@ static int process_record(int cpu, struct t_rec *r)
 
     return 4 + (r->cycles_included ? 8 : 0) + (r->extra_u32 * 4);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/xenpaging/xenpaging.c +7 -7
index df99c6a..c4bc713 100644
@@ -342,9 +342,9 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
                         HVM_PARAM_PAGING_RING_PFN, &ring_pfn);
     mmap_pfn = ring_pfn;
     paging->vm_event.ring_page = 
-        xc_map_foreign_batch(xch, paging->vm_event.domain_id, 
-                                PROT_READ | PROT_WRITE, &mmap_pfn, 1);
-    if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+        xc_map_foreign_pages(xch, paging->vm_event.domain_id,
+                             PROT_READ | PROT_WRITE, &mmap_pfn, 1);
+    if ( !paging->vm_event.ring_page )
     {
         /* Map failed, populate ring page */
         rc = xc_domain_populate_physmap_exact(paging->xc_handle, 
@@ -356,11 +356,11 @@ static struct xenpaging *xenpaging_init(int argc, char *argv[])
             goto err;
         }
 
-        mmap_pfn = ring_pfn;
         paging->vm_event.ring_page = 
-            xc_map_foreign_batch(xch, paging->vm_event.domain_id, 
-                                    PROT_READ | PROT_WRITE, &mmap_pfn, 1);
-        if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
+            xc_map_foreign_pages(xch, paging->vm_event.domain_id,
+                                 PROT_READ | PROT_WRITE,
+                                 &mmap_pfn, 1);
+        if ( !paging->vm_event.ring_page )
         {
             PERROR("Could not map the ring page\n");
             goto err;
tools/xentrace/xentrace.c +2 -1
index c970d42..6cbe0ac 100644
@@ -508,7 +508,7 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
         for ( j=0; j<tbufs.t_info->tbuf_size; j++)
             pfn_list[j] = (xen_pfn_t)mfn_list[j];
 
-        tbufs.meta[i] = xc_map_foreign_batch(xc_handle, DOMID_XEN,
+        tbufs.meta[i] = xc_map_foreign_pages(xc_handle, DOMID_XEN,
                                              PROT_READ | PROT_WRITE,
                                              pfn_list,
                                              tbufs.t_info->tbuf_size);
@@ -1221,6 +1221,7 @@ int main(int argc, char **argv)
 
     return ret;
 }
+
 /*
  * Local variables:
  * mode: C
Signature · 1 line
2.1.4
#20 lore raw

PATCH v7 12/29 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
#21 lore raw

PATCH v7 13/29 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.

v5: Allow close(NULL)

v6: Define XC_WANT_COMPAT_MAP_FOREIGN_API for xen-mceinj.c and memshrtool.c
Fix typo in type name in compat.c, and get the functions names to match.
Use an osdep layer for _map, to allow for future common code.

v7: Correct comment in compat.h #error due to switch to osdep layer
for map in v6
Added mk-headers-$(XEN_TARGET_ARCH) build dependency instead of open coding the recursion.

---
 .gitignore                                         |   2 +
 stubdom/Makefile                                   |  17 +++-
 tools/Makefile                                     |   2 +
 tools/Rules.mk                                     |  11 ++-
 tools/console/daemon/utils.c                       |   1 -
 tools/console/daemon/utils.h                       |   1 +
 tools/libs/Makefile                                |   1 +
 tools/libs/foreignmemory/Makefile                  |  67 +++++++++++++
 tools/libs/foreignmemory/compat.c                  |  72 ++++++++++++++
 tools/libs/foreignmemory/core.c                    |  84 +++++++++++++++++
 .../foreignmemory/freebsd.c}                       |  33 +++----
 .../libs/foreignmemory/include/xenforeignmemory.h  |  71 ++++++++++++++
 tools/libs/foreignmemory/libxenforeignmemory.map   |   7 ++
 .../foreignmemory/linux.c}                         |  70 ++++++--------
 tools/libs/foreignmemory/minios.c                  |  62 ++++++++++++
 tools/libs/foreignmemory/netbsd.c                  | 105 +++++++++++++++++++++
 tools/libs/foreignmemory/private.h                 |  53 +++++++++++
 tools/libs/foreignmemory/solaris.c                 |  93 ++++++++++++++++++
 tools/libxc/Makefile                               |   8 +-
 tools/libxc/include/xenctrl.h                      |  26 -----
 tools/libxc/include/xenctrl_compat.h               |  36 +++++++
 tools/libxc/xc_foreign_memory.c                    |  49 +---------
 tools/libxc/xc_minios.c                            |  29 ------
 tools/libxc/xc_netbsd.c                            |  73 --------------
 tools/libxc/xc_private.c                           |  13 +--
 tools/libxc/xc_private.h                           |  11 ++-
 tools/libxc/xc_solaris.c                           |  73 --------------
 tools/libxc/xc_sr_restore.c                        |   4 +-
 tools/libxc/xc_sr_save.c                           |   4 +-
 tools/libxc/xg_private.h                           |   3 +-
 tools/libxl/libxl_internal.h                       |   1 +
 tools/misc/xen-mfndump.c                           |   1 +
 tools/ocaml/libs/xc/xenctrl_stubs.c                |   1 +
 tools/python/xen/lowlevel/xc/xc.c                  |   2 +
 tools/tests/mce-test/tools/xen-mceinj.c            |   1 +
 tools/tests/mem-sharing/memshrtool.c               |   1 +
 tools/xenmon/xenbaked.c                            |   1 +
 tools/xenpaging/pagein.c                           |   1 -
 tools/xenpaging/xenpaging.c                        |   1 -
 tools/xenpaging/xenpaging.h                        |   2 +
 tools/xenstore/xenstored_core.c                    |   1 -
 tools/xenstore/xenstored_core.h                    |   1 +
 tools/xentrace/xenctx.c                            |   3 +-
 tools/xentrace/xentrace.c                          |   1 +
 44 files changed, 766 insertions(+), 333 deletions(-)
 create mode 100644 tools/libs/foreignmemory/Makefile
 create mode 100644 tools/libs/foreignmemory/compat.c
 create mode 100644 tools/libs/foreignmemory/core.c
 rename tools/{libxc/xc_freebsd_osdep.c => libs/foreignmemory/freebsd.c} (76%)
 create mode 100644 tools/libs/foreignmemory/include/xenforeignmemory.h
 create mode 100644 tools/libs/foreignmemory/libxenforeignmemory.map
 rename tools/{libxc/xc_linux_osdep.c => libs/foreignmemory/linux.c} (83%)
 create mode 100644 tools/libs/foreignmemory/minios.c
 create mode 100644 tools/libs/foreignmemory/netbsd.c
 create mode 100644 tools/libs/foreignmemory/private.h
 create mode 100644 tools/libs/foreignmemory/solaris.c
.gitignore +2 -0
index 2899852..2549337 100644
@@ -62,6 +62,7 @@ stubdom/libxentoollog-*
 stubdom/libxenevtchn-*
 stubdom/libxengnttab-*
 stubdom/libxencall-*
+stubdom/libxenforeignmemory-*
 stubdom/libxc-*
 stubdom/lwip-*
 stubdom/mini-os-*
@@ -92,6 +93,7 @@ tools/libs/toollog/headers.chk
 tools/libs/evtchn/headers.chk
 tools/libs/gnttab/headers.chk
 tools/libs/call/headers.chk
+tools/libs/foreignmemory/headers.chk
 tools/blktap2/daemon/blktapctrl
 tools/blktap2/drivers/img2qcow
 tools/blktap2/drivers/lock-util
stubdom/Makefile +16 -1
index 5bf4ed6..6f68e98 100644
@@ -337,6 +337,12 @@ mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET)
 	  ln -sf $(XEN_ROOT)/tools/libs/call/include/*.h include/ && \
 	  ln -sf $(XEN_ROOT)/tools/libs/call/*.c . && \
 	  ln -sf $(XEN_ROOT)/tools/libs/call/Makefile . )
+	mkdir -p libs-$(XEN_TARGET_ARCH)/foreignmemory/include
+	[ -h libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || ( cd libs-$(XEN_TARGET_ARCH)/foreignmemory && \
+	  ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.h . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/include/*.h include/ && \
+	  ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/*.c . && \
+	  ln -sf $(XEN_ROOT)/tools/libs/foreignmemory/Makefile . )
 	mkdir -p libxc-$(XEN_TARGET_ARCH)
 	[ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
 	  ln -sf $(XEN_ROOT)/tools/libxc/*.h . && \
@@ -396,12 +402,21 @@ libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLI
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call
 
 #######
+# libxenforeignmemory
+#######
+
+.PHONY: libxenforeignmemory
+libxenforeignmemory: libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
+libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory
+
+#######
 # libxc
 #######
 
 .PHONY: libxc
 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
-libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory cross-zlib
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
 
  libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
tools/Makefile +2 -0
index e5bbc98..c03f6db 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 18e3688..d47fa45 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=$(XEN_LIBXC)
tools/console/daemon/utils.c +0 -1
index 644f6af..97d7798 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 +84 -0

84 lines not on this page · raw message

tools/libs/foreignmemory/freebsd.c renamed from tools/libxc/xc_freebsd_osdep.c +13 -20
similarity index 76%
rename from tools/libxc/xc_freebsd_osdep.c
rename to tools/libs/foreignmemory/freebsd.c
index 7745d28..4b2815d 100644
@@ -3,9 +3,6 @@
  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  *
- * xc_gnttab functions:
- * Copyright (c) 2007-2008, D G Murray <[email protected]>
- *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
@@ -30,14 +27,11 @@
 #include <sys/mman.h>
 #include <sys/ioctl.h>
 
-#include <xen/memory.h>
-
-#include "xc_private.h"
+#include "private.h"
 
 #define PRIVCMD_DEV     "/dev/xen/privcmd"
 
-/*------------------------- Privcmd device interface -------------------------*/
-int osdep_privcmd_open(xc_interface *xch)
+int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
 {
     int flags, saved_errno;
     int fd = open(PRIVCMD_DEV, O_RDWR);
@@ -46,7 +40,7 @@ int osdep_privcmd_open(xc_interface *xch)
     {
         PERROR("Could not obtain handle on privileged command interface "
                PRIVCMD_DEV);
-        return -1
+        return -1;
     }
 
     /*
@@ -69,7 +63,7 @@ int osdep_privcmd_open(xc_interface *xch)
         goto error;
     }
 
-    xch->privcmdfd = fd;
+    fmem->fd = fd;
     return 0;
 
  error:
@@ -80,26 +74,25 @@ int osdep_privcmd_open(xc_interface *xch)
     return -1;
 }
 
-int osdep_privcmd_close(xc_interface *xch)
+int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
 {
-    int fd = xch->privcmdfd;
+    int fd = fmem->fd;
     if ( fd == -1 )
         return 0;
     return close(fd);
 }
 
-/*----------------------- Privcmd foreign map interface ----------------------*/
-void *xc_map_foreign_bulk(xc_interface *xch,
-                          uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err,
-                          unsigned int num)
+void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
+                                 uint32_t dom, int prot,
+                                 const xen_pfn_t *arr, int *err,
+                                 unsigned int num)
 {
-    int fd = xch->privcmdfd;
+    int fd = fmem->fd;
     privcmd_mmapbatch_t ioctlx;
     void *addr;
     int rc;
 
-    addr = mmap(NULL, num << XC_PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
+    addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED, fd, 0);
     if ( addr == MAP_FAILED )
     {
         PERROR("xc_map_foreign_bulk: mmap failed");
@@ -117,7 +110,7 @@ void *xc_map_foreign_bulk(xc_interface *xch,
     {
         int saved_errno = errno;
         PERROR("xc_map_foreign_bulk: ioctl failed");
-        (void)munmap(addr, num << XC_PAGE_SHIFT);
+        (void)munmap(addr, num << PAGE_SHIFT);
         errno = saved_errno;
         return NULL;
     }
tools/libs/foreignmemory/include/xenforeignmemory.h new file +71 -0

71 lines not on this page · raw message

tools/libs/foreignmemory/libxenforeignmemory.map new file +7 -0
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 renamed from tools/libxc/xc_linux_osdep.c +31 -39

175 lines not on this page · raw message

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

62 lines not on this page · raw message

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

105 lines not on this page · raw message

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

53 lines not on this page · raw message

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

93 lines not on this page · raw message

tools/libxc/Makefile +4 -4
index a122f73..ca8bab7 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
@@ -125,7 +125,7 @@ $(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.
 # libxenguest includes xc_private.h, so needs this despite not using
 # this functionality directly.
 $(CTRL_LIB_OBJS) $(GUEST_LIB_OBJS) \
-$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += $(CFLAGS_libxencall)
+$(CTRL_PIC_OBJS) $(GUEST_PIC_OBJS): CFLAGS += $(CFLAGS_libxencall) $(CFLAGS_libxenforeignmemory)
 
 $(CTRL_LIB_OBJS) $(CTRL_PIC_OBJS): CFLAGS += $(CFLAGS_libxengnttab) $(CFLAGS_libxengntshr)
 
@@ -207,7 +207,7 @@ libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR)
 	$(SYMLINK_SHLIB) $< $@
 
 libxenctrl.so.$(MAJOR).$(MINOR): $(CTRL_PIC_OBJS)
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(LDLIBS_libxencall) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenctrl.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxengnttab) $(LDLIBS_libxengntshr) $(LDLIBS_libxencall) $(LDLIBS_libxenforeignmemory) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 # libxenguest
 
tools/libxc/include/xenctrl.h +0 -26
index cb41c07..76beafd 100644
@@ -1369,32 +1369,6 @@ int xc_lockprof_query(xc_interface *xch,
 void *xc_memalign(xc_interface *xch, size_t alignment, size_t size);
 
 /**
- * Memory maps a range within one domain to a local address range.  Mappings
- * should be unmapped with munmap and should follow the same rules as mmap
- * regarding page alignment.  Returns NULL on failure.
- *
- * @parm xch a handle on an open hypervisor interface
- * @parm dom the domain to map memory from
- * @parm size the amount of memory to map (in multiples of page size)
- * @parm prot same flag as in mmap().
- * @parm mfn the frame address to map.
- */
-void *xc_map_foreign_range(xc_interface *xch, uint32_t dom,
-                            int size, int prot,
-                            unsigned long mfn );
-
-void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
-                           const xen_pfn_t *arr, int num );
-
-/**
- * Like xc_map_foreign_pages(), except it can succeed partially.
- * When a page cannot be mapped, its respective field in @err is
- * set to the corresponding errno value.
- */
-void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
-                          const xen_pfn_t *arr, int *err, unsigned int num);
-
-/**
  * Translates a virtual address in the context of a given domain and
  * vcpu returning the GFN containing the address (that is, an MFN for 
  * PV guests, a PFN for HVM guests).  Returns 0 for failure.
tools/libxc/include/xenctrl_compat.h +36 -0
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_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 ca4c17a..c41e433 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 ecf2451..aa8daf1 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 05159bb..8e9e9c7 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 cefcef5..628ae07 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/xg_private.h +1 -2
index a76d6b3..175c1e5 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 fa01dd7..57f3ee7 100644
@@ -50,6 +50,7 @@
 
 #include <xenevtchn.h>
 #include <xenstore.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 #include <xenguest.h>
 #include <xc_dom.h>
tools/misc/xen-mfndump.c +1 -0
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 e2fa7e4..74928e9 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 +2 -0
index 6dd79e0..c40a4e9 100644
@@ -5,6 +5,7 @@
  */
 
 #include <Python.h>
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 #include <fcntl.h>
 #include <netinet/in.h>
@@ -15,6 +16,7 @@
 #include <netdb.h>
 #include <arpa/inet.h>
 
+#include <xen/elfnote.h>
 #include <xen/tmem.h>
 #include "xc_dom.h"
 #include <xen/hvm/hvm_info_table.h>
tools/tests/mce-test/tools/xen-mceinj.c +1 -0
index d22f0ad..061ec7c 100644
@@ -30,6 +30,7 @@
 #include <signal.h>
 #include <stdarg.h>
 
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include <xenctrl.h>
 #include <xenguest.h>
 #include <inttypes.h>
tools/tests/mem-sharing/memshrtool.c +1 -0
index 6454bc3..437c7c9 100644
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <sys/mman.h>
 
+#define XC_WANT_COMPAT_MAP_FOREIGN_API
 #include "xenctrl.h"
 
 static int usage(const char* prog)
tools/xenmon/xenbaked.c +1 -0
index da46126..eacacb0 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 7cb0f33..2a298b4 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 c4bc713..0377507 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 f62c192..51fb0b3 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 6cbe0ac..f09fe6c 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
#22 lore raw

PATCH v7 14/29 tools/libs/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.

---
v4: xenforeignmemory_unmap takes pages not bytes, adjust callers.
v6: Document error behaviour
Use an osdep layer, although there is no current need for common code on _unmap there is for _map so use this indirection for consistency.

---
 tools/libs/foreignmemory/freebsd.c                  |  6 ++++++
 tools/libs/foreignmemory/include/xenforeignmemory.h | 11 +++++++++--
 tools/libs/foreignmemory/libxenforeignmemory.map    |  1 +
 tools/libs/foreignmemory/linux.c                    |  6 ++++++
 tools/libs/foreignmemory/minios.c                   |  6 ++++++
 tools/libs/foreignmemory/netbsd.c                   |  6 ++++++
 tools/libs/foreignmemory/solaris.c                  |  6 ++++++
 tools/libxc/xc_sr_restore.c                         |  2 +-
 tools/libxc/xc_sr_save.c                            |  2 +-
 tools/libxc/xc_vm_event.c                           |  2 +-
 10 files changed, 43 insertions(+), 5 deletions(-)
tools/libs/foreignmemory/freebsd.c +6 -0
index 4b2815d..3c3ad09 100644
@@ -118,6 +118,12 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return addr;
 }
 
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+	return munmap(addr, num << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/include/xenforeignmemory.h +9 -2
index 0909585..b1cae30 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).
  *
@@ -57,6 +57,13 @@ int xenforeignmemory_close(xenforeignmemory_handle *xmem);
 void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
                            int prot, const xen_pfn_t *arr, int *err,
                            unsigned int num);
+/*
+ * Unmap a mapping previous created with xenforeignmemory_map().
+ *
+ * Returns 0 on success on failure sets errno and returns -1.
+ */
+int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                           void *addr, unsigned int num);
 
 #endif
 
tools/libs/foreignmemory/libxenforeignmemory.map +1 -0
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 b403ca7..40ecd41 100644
@@ -282,6 +282,12 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return addr;
 }
 
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+    return munmap(addr, (unsigned long)num << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/minios.c +6 -0
index a542e3d..5fcb861 100644
@@ -51,6 +51,12 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
     return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
 }
 
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+	return munmap(addr, num << PAGE_SHIFT);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/netbsd.c +6 -0
index 704a096..740c26f 100644
@@ -94,6 +94,12 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
 
 }
 
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+	return munmap(addr, num*XC_PAGE_SIZE);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/foreignmemory/solaris.c +6 -0
index f4dd634..966fccb 100644
@@ -91,3 +91,9 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
     }
     return addr;
 }
+
+int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
+                                 void *addr, unsigned int num)
+{
+	return munmap(addr, num*XC_PAGE_SIZE);
+}
tools/libxc/xc_sr_restore.c +1 -1
index 8e9e9c7..a334efd 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);
 
     free(map_errs);
     free(mfns);
tools/libxc/xc_sr_save.c +1 -1
index 628ae07..3d78970 100644
@@ -263,7 +263,7 @@ static int write_batch(struct xc_sr_context *ctx)
  err:
     free(rec_pfns);
     if ( guest_mapping )
-        munmap(guest_mapping, nr_pages_mapped * PAGE_SIZE);
+        xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped);
     for ( i = 0; local_pages && i < nr_pfns; ++i )
         free(local_pages[i]);
     free(iov);
tools/libxc/xc_vm_event.c +1 -1
index d2d99e4..57abce0 100644
@@ -148,7 +148,7 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
         }
 
         if ( ring_page )
-            munmap(ring_page, XC_PAGE_SIZE);
+            xenforeignmemory_unmap(xch->fmem, ring_page, 1);
         ring_page = NULL;
 
         errno = saved_errno;
Signature · 1 line
2.1.4
#23 lore raw

PATCH v7 15/29 tools/libs/foreignmemory: use size_t for size arguments.

In reply to Ian Campbell

Surprisingly it appears no callers need updating.

---
v4: New patch

---
 tools/libs/foreignmemory/compat.c                  |  2 +-
 tools/libs/foreignmemory/freebsd.c                 |  4 ++--
 .../libs/foreignmemory/include/xenforeignmemory.h  |  5 +++--
 tools/libs/foreignmemory/linux.c                   | 23 +++++++++++-----------
 tools/libs/foreignmemory/minios.c                  |  4 ++--
 tools/libs/foreignmemory/netbsd.c                  |  2 +-
 tools/libs/foreignmemory/solaris.c                 |  2 +-
 7 files changed, 22 insertions(+), 20 deletions(-)
tools/libs/foreignmemory/compat.c +1 -1
index b8c6fc6..039297c 100644
@@ -23,7 +23,7 @@
 
 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
                                  uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, unsigned int num)
+                                 const xen_pfn_t *arr, int *err, size_t num)
 {
     xen_pfn_t *pfn;
     unsigned int i;
tools/libs/foreignmemory/freebsd.c +2 -2
index 3c3ad09..ed26ebb 100644
@@ -85,7 +85,7 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
                                  uint32_t dom, int prot,
                                  const xen_pfn_t *arr, int *err,
-                                 unsigned int num)
+                                 size_t num)
 {
     int fd = fmem->fd;
     privcmd_mmapbatch_t ioctlx;
@@ -119,7 +119,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
 }
 
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
-                                 void *addr, unsigned int num)
+                                 void *addr, size_t num)
 {
 	return munmap(addr, num << PAGE_SHIFT);
 }
tools/libs/foreignmemory/include/xenforeignmemory.h +3 -2
index b1cae30..87f72fd 100644
@@ -56,14 +56,15 @@ int xenforeignmemory_close(xenforeignmemory_handle *xmem);
  */
 void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
                            int prot, const xen_pfn_t *arr, int *err,
-                           unsigned int num);
+                           size_t pages);
+
 /*
  * Unmap a mapping previous created with xenforeignmemory_map().
  *
  * Returns 0 on success on failure sets errno and returns -1.
  */
 int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
-                           void *addr, unsigned int num);
+                           void *addr, size_t pages);
 
 #endif
 
tools/libs/foreignmemory/linux.c +12 -11
index 40ecd41..6620391 100644
@@ -115,10 +115,11 @@ static int map_foreign_batch_single(int fd, uint32_t dom,
  * This will keep the request ring full and avoids delays.
  */
 static int retry_paged(int fd, uint32_t dom, void *addr,
-                       const xen_pfn_t *arr, int *err, unsigned int num)
+                       const xen_pfn_t *arr, int *err, size_t num)
 {
     privcmd_mmapbatch_v2_t ioctlx;
-    int rc, paged = 0, i = 0;
+    int rc, paged = 0;
+    size_t i = 0;
 
     do
     {
@@ -134,7 +135,7 @@ static int retry_paged(int fd, uint32_t dom, void *addr,
         /* At least one gfn is still in paging state */
         ioctlx.num = 1;
         ioctlx.dom = dom;
-        ioctlx.addr = (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT);
+        ioctlx.addr = (unsigned long)addr + (i<<PAGE_SHIFT);
         ioctlx.arr = arr + i;
         ioctlx.err = err + i;
 
@@ -160,15 +161,15 @@ out:
 
 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
                                  uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, unsigned int num)
+                                 const xen_pfn_t *arr, int *err, size_t num)
 {
     int fd = fmem->fd;
     privcmd_mmapbatch_v2_t ioctlx;
     void *addr;
-    unsigned int i;
+    size_t i;
     int rc;
 
-    addr = mmap(NULL, (unsigned long)num << PAGE_SHIFT, prot, MAP_SHARED,
+    addr = mmap(NULL, num << PAGE_SHIFT, prot, MAP_SHARED,
                 fd, 0);
     if ( addr == MAP_FAILED )
     {
@@ -212,7 +213,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
             if ( pfn == MAP_FAILED )
             {
                 PERROR("mmap of pfn array failed");
-                (void)munmap(addr, (unsigned long)num << PAGE_SHIFT);
+                (void)munmap(addr, num << PAGE_SHIFT);
                 return NULL;
             }
         }
@@ -245,7 +246,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
                     continue;
                 }
                 rc = map_foreign_batch_single(fd, dom, pfn + i,
-                        (unsigned long)addr + ((unsigned long)i<<PAGE_SHIFT));
+                        (unsigned long)addr + (i<<PAGE_SHIFT));
                 if ( rc < 0 )
                 {
                     rc = -errno;
@@ -274,7 +275,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
         int saved_errno = errno;
 
         PERROR("ioctl failed");
-        (void)munmap(addr, (unsigned long)num << PAGE_SHIFT);
+        (void)munmap(addr, num << PAGE_SHIFT);
         errno = saved_errno;
         return NULL;
     }
@@ -283,9 +284,9 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
 }
 
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
-                                 void *addr, unsigned int num)
+                                 void *addr, size_t num)
 {
-    return munmap(addr, (unsigned long)num << PAGE_SHIFT);
+    return munmap(addr, num << PAGE_SHIFT);
 }
 
 /*
tools/libs/foreignmemory/minios.c +2 -2
index 5fcb861..bdc1239 100644
@@ -41,7 +41,7 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
 
 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
                                  uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, unsigned int num)
+                                 const xen_pfn_t *arr, int *err, size_t num)
 {
     unsigned long pt_prot = 0;
     if (prot & PROT_READ)
@@ -52,7 +52,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
 }
 
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
-                                 void *addr, unsigned int num)
+                                 void *addr, size_t num)
 {
 	return munmap(addr, num << PAGE_SHIFT);
 }
tools/libs/foreignmemory/netbsd.c +1 -1
index 740c26f..d0d233a 100644
@@ -95,7 +95,7 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
 }
 
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
-                                 void *addr, unsigned int num)
+                                 void *addr, size_t num)
 {
 	return munmap(addr, num*XC_PAGE_SIZE);
 }
tools/libs/foreignmemory/solaris.c +1 -1
index 966fccb..f1c44bc 100644
@@ -93,7 +93,7 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
 }
 
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
-                                 void *addr, unsigned int num)
+                                 void *addr, size_t num)
 {
 	return munmap(addr, num*XC_PAGE_SIZE);
 }
Signature · 1 line
2.1.4
#24 lore raw

PATCH v7 16/29 tools/libs/foreignmemory: Mention restrictions on fork in docs.

In reply to Ian Campbell

---
v6: Also discuss recovering the memory.

v7: Further clarifications regarding forking based on ML discussions.
(Dropped Wei's ack)

---
 .../libs/foreignmemory/include/xenforeignmemory.h  | 33 +++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
tools/libs/foreignmemory/include/xenforeignmemory.h +32 -1
index 87f72fd..36f3753 100644
@@ -32,13 +32,44 @@ typedef struct xentoollog_logger xentoollog_logger;
 typedef struct xenforeignmemory_handle xenforeignmemory_handle;
 
 /*
- * Return a handle onto the hypercall driver.  Logs errors.
+ * Return a handle onto the foreign memory mapping driver.  Logs errors.
+ *
+ * Note: After fork(2) a child process must not use any opened
+ * foreignmemory handle inherited from their parent, nor access any
+ * grant mapped areas associated with that handle.
+ *
+ * The child must open a new handle if they want to interact with
+ * foreignmemory.
+ *
+ * Calling exec(2) in a child will safely (and reliably) reclaim any
+ * resources which were allocated via a xenforeignmemory_handle in the
+ * parent.
+ *
+ * A child which does not call exec(2) may safely call
+ * xenforeignmemory_close() on a xenforeignmemory_handle inherited
+ * from their parent. This will attempt to reclaim any resources
+ * associated with that handle. Note that in some implementations this
+ * reclamation may not be completely effective, in this case any
+ * affected resources remain allocated.
+ *
+ * Calling xenforeignmemory_close() is the only safe operation on a
+ * xenforeignmemory_handle which has been inherited.
  */
 xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,
                                                unsigned open_flags);
 
 /*
  * Close a handle previously allocated with xenforeignmemory_open().
+ *
+ * Under normal circumstances (i.e. not in the child after a fork)
+ * xenforeignmemory_unmap() should be used on all mappings allocated
+ * by xenforeignmemory_map() prior to closing the handle in order to
+ * free up resources associated with those mappings.
+ *
+ * This is the only function which may be safely called on a
+ * xenforeignmemory_handle in a child after a
+ * fork. xenforeignmemory_unmap() must not be called under such
+ * circumstances.
  */
 int xenforeignmemory_close(xenforeignmemory_handle *xmem);
 
Signature · 1 line
2.1.4
#25 lore raw

PATCH v7 17/29 tools/libs/foreignmemory: Support err == NULL to map.

In reply to Ian Campbell

The existing xc_map_foreign_bulk-like interface encourages callers to miss error checking for partial failure (by forgetting to scan the err array).

Add support for passing err==NULL which behaves in a xc_map_foreign_pages-like manner and returns a global error for any failure.

While documenting this also clarify the overall behaviour and the behaviour with err!=NULL.

With this the compat wrapper of xc_map_foreign_pages() can be simplified.

---
v7: Check for NULL when allocating err.

v6: New

---
 tools/libs/foreignmemory/core.c                    | 33 +++++++++++++++++++++-
 .../libs/foreignmemory/include/xenforeignmemory.h  | 24 ++++++++++++++--
 tools/libxc/xc_foreign_memory.c                    | 22 +--------------
 3 files changed, 54 insertions(+), 25 deletions(-)
tools/libs/foreignmemory/core.c +32 -1
index 21dc7ee..4e0541f 100644
@@ -14,6 +14,8 @@
  */
 
 #include <stdlib.h>
+#include <assert.h>
+#include <errno.h>
 
 #include "private.h"
 
@@ -64,7 +66,36 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
                            uint32_t dom, int prot,
                            const xen_pfn_t *arr, int *err, size_t num)
 {
-    return osdep_xenforeignmemory_map(fmem, dom, prot, arr, err, num);
+    void *ret;
+    int *err_to_free = NULL;
+
+    if ( err == NULL )
+        err = err_to_free = malloc(num * sizeof(int));
+
+    if ( err == NULL )
+        return NULL;
+
+    ret = osdep_xenforeignmemory_map(fmem, dom, prot, arr, err, num);
+
+    if ( ret == 0 && err_to_free )
+    {
+        int i;
+
+        for ( i = 0 ; i < num ; i++ )
+        {
+            if ( err[i] )
+            {
+                errno = -err[i];
+                (void)osdep_xenforeignmemory_unmap(fmem, ret, num);
+                ret = NULL;
+                break;
+            }
+        }
+    }
+
+    free(err_to_free);
+
+    return ret;
 }
 
 int xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
tools/libs/foreignmemory/include/xenforeignmemory.h +21 -3
index 36f3753..b162dca 100644
@@ -80,10 +80,28 @@ int xenforeignmemory_close(xenforeignmemory_handle *xmem);
  *
  * prot is as for mmap(2).
  *
- * Can partially succeed. When a page cannot be mapped, its respective
- * field in @err is set to the corresponding errno value.
+ * @arr is an array of @pages gfns to be mapped linearly in the local
+ * address range. @err is an (optional) output array used to report
+ * per-page errors, as errno values.
  *
- * Returns NULL if no pages can be mapped.
+ * If @err is given (is non-NULL) then the mapping may partially
+ * succeed and return a valid pointer while also using @err to
+ * indicate the success (0) or failure (errno value) of the individual
+ * pages. The global errno thread local variable is not valid in this
+ * case.
+ *
+ * If @err is not given (is NULL) then on failure to map any page any
+ * successful mappings will be undone and NULL will be returned. errno
+ * will be set to correspond to the first failure (which may not be
+ * the most critical).
+ *
+ * It is also possible to return NULL due to a complete failure,
+ * i.e. failure to even attempt the mapping, in this case the global
+ * errno will have been set and the contents of @err (if given) is
+ * invalid.
+ *
+ * Note that it is also possible to return non-NULL with the contents
+ * of @err indicating failure to map every page.
  */
 void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
                            int prot, const xen_pfn_t *arr, int *err,
tools/libxc/xc_foreign_memory.c +1 -21
index 1737c10..4b24388 100644
@@ -23,32 +23,12 @@
 void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
                            const xen_pfn_t *arr, int num)
 {
-    void *res;
-    int i, *err;
-
     if (num < 0) {
         errno = EINVAL;
         return NULL;
     }
 
-    err = malloc(num * sizeof(*err));
-    if (!err)
-        return NULL;
-
-    res = xenforeignmemory_map(xch->fmem, dom, prot, arr, err, num);
-    if (res) {
-        for (i = 0; i < num; i++) {
-            if (err[i]) {
-                errno = -err[i];
-                munmap(res, num * PAGE_SIZE);
-                res = NULL;
-                break;
-            }
-        }
-    }
-
-    free(err);
-    return res;
+    return xenforeignmemory_map(xch->fmem, dom, prot, arr, NULL, num);
 }
 
 void *xc_map_foreign_range(xc_interface *xch,
Signature · 1 line
2.1.4
#26 lore raw

PATCH v7 18/29 tools/libs/foreignmemory: pull array length argument to map forward

In reply to Ian Campbell

By having the "num" argument before the page and error arrays we can potentially use a variable-length-array argument ("int pages[num]") in the function prototype.

However VLAs are a C99 feature and we are currently targetting C89 and later, so we don't actually make use of this here, merely arrange that we can switch to VLAs in the future without changing the function ABI.

---
v6: New

---
 tools/libs/foreignmemory/compat.c                   | 4 ++--
 tools/libs/foreignmemory/core.c                     | 5 +++--
 tools/libs/foreignmemory/freebsd.c                  | 4 ++--
 tools/libs/foreignmemory/include/xenforeignmemory.h | 4 ++--
 tools/libs/foreignmemory/linux.c                    | 3 ++-
 tools/libs/foreignmemory/minios.c                   | 3 ++-
 tools/libs/foreignmemory/private.h                  | 3 ++-
 tools/libxc/xc_foreign_memory.c                     | 4 ++--
 tools/libxc/xc_sr_restore.c                         | 2 +-
 tools/libxc/xc_sr_save.c                            | 2 +-
 10 files changed, 19 insertions(+), 15 deletions(-)
tools/libs/foreignmemory/compat.c +2 -2
index 039297c..b79ec1a 100644
@@ -22,8 +22,8 @@
 #include "private.h"
 
 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
-                                 uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, size_t num)
+                                 uint32_t dom, int prot, size_t num,
+                                 const xen_pfn_t arr[/*num*/], int err[/*num*/])
 {
     xen_pfn_t *pfn;
     unsigned int i;
tools/libs/foreignmemory/core.c +3 -2
index 4e0541f..cfb0a73 100644
@@ -64,7 +64,8 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem)
 
 void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
                            uint32_t dom, int prot,
-                           const xen_pfn_t *arr, int *err, size_t num)
+                           size_t num,
+                           const xen_pfn_t arr[/*num*/], int err[/*num*/])
 {
     void *ret;
     int *err_to_free = NULL;
@@ -75,7 +76,7 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
     if ( err == NULL )
         return NULL;
 
-    ret = osdep_xenforeignmemory_map(fmem, dom, prot, arr, err, num);
+    ret = osdep_xenforeignmemory_map(fmem, dom, prot, num, arr, err);
 
     if ( ret == 0 && err_to_free )
     {
tools/libs/foreignmemory/freebsd.c +2 -2
index ed26ebb..703754f 100644
@@ -84,8 +84,8 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
 
 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
                                  uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err,
-                                 size_t num)
+                                 size_t num,
+                                 const xen_pfn_t arr[/*num*/], int err[/*num*/])
 {
     int fd = fmem->fd;
     privcmd_mmapbatch_t ioctlx;
tools/libs/foreignmemory/include/xenforeignmemory.h +2 -2
index b162dca..d75f946 100644
@@ -104,8 +104,8 @@ int xenforeignmemory_close(xenforeignmemory_handle *xmem);
  * of @err indicating failure to map every page.
  */
 void *xenforeignmemory_map(xenforeignmemory_handle *fmem, uint32_t dom,
-                           int prot, const xen_pfn_t *arr, int *err,
-                           size_t pages);
+                           int prot, size_t pages,
+                           const xen_pfn_t arr[/*pages*/], int err[/*pages*/]);
 
 /*
  * Unmap a mapping previous created with xenforeignmemory_map().
tools/libs/foreignmemory/linux.c +2 -1
index 6620391..32b6def 100644
@@ -161,7 +161,8 @@ out:
 
 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
                                  uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, size_t num)
+                                 size_t num,
+                                 const xen_pfn_t arr[/*num*/], int err[/*num*/])
 {
     int fd = fmem->fd;
     privcmd_mmapbatch_v2_t ioctlx;
tools/libs/foreignmemory/minios.c +2 -1
index bdc1239..ca5ba71 100644
@@ -41,7 +41,8 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
 
 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
                                  uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, size_t num)
+                                 size_t num,
+                                 const xen_pfn_t arr[/*num*/], int err[/*num*/])
 {
     unsigned long pt_prot = 0;
     if (prot & PROT_READ)
tools/libs/foreignmemory/private.h +2 -1
index 36a71ec..cd732fd 100644
@@ -27,7 +27,8 @@ int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem);
 
 void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
                                  uint32_t dom, int prot,
-                                 const xen_pfn_t *arr, int *err, size_t num);
+                                 size_t num,
+                                 const xen_pfn_t arr[num], int err[num]);
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                                  void *addr, size_t num);
 
tools/libxc/xc_foreign_memory.c +2 -2
index 4b24388..4053d26 100644
@@ -28,7 +28,7 @@ void *xc_map_foreign_pages(xc_interface *xch, uint32_t dom, int prot,
         return NULL;
     }
 
-    return xenforeignmemory_map(xch->fmem, dom, prot, arr, NULL, num);
+    return xenforeignmemory_map(xch->fmem, dom, prot, num, arr, NULL);
 }
 
 void *xc_map_foreign_range(xc_interface *xch,
@@ -84,7 +84,7 @@ void *xc_map_foreign_ranges(xc_interface *xch,
 void *xc_map_foreign_bulk(xc_interface *xch, uint32_t dom, int prot,
                           const xen_pfn_t *arr, int *err, unsigned int num)
 {
-    return xenforeignmemory_map(xch->fmem, dom, prot, arr, err, num);
+    return xenforeignmemory_map(xch->fmem, dom, prot, num, arr, err);
 }
 
 /*
tools/libxc/xc_sr_restore.c +1 -1
index a334efd..d6d2397 100644
@@ -318,7 +318,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count,
 
     mapping = guest_page = xenforeignmemory_map(xch->fmem,
         ctx->domid, PROT_READ | PROT_WRITE,
-        mfns, map_errs, nr_pages);
+        nr_pages, mfns, map_errs);
     if ( !mapping )
     {
         rc = -1;
tools/libxc/xc_sr_save.c +1 -1
index 3d78970..4894a57 100644
@@ -154,7 +154,7 @@ static int write_batch(struct xc_sr_context *ctx)
     if ( nr_pages > 0 )
     {
         guest_mapping = xenforeignmemory_map(xch->fmem,
-            ctx->domid, PROT_READ, mfns, errors, nr_pages);
+            ctx->domid, PROT_READ, nr_pages, mfns, errors);
         if ( !guest_mapping )
         {
             PERROR("Failed to map guest pages");
Signature · 1 line
2.1.4
#27 lore raw

PATCH v7 19/29 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
#28 lore raw

PATCH v7 20/29 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/minios.c     |  6 +++---
 tools/libs/foreignmemory/netbsd.c     |  2 +-
 tools/libs/foreignmemory/private.h    |  2 +-
 tools/libs/foreignmemory/solaris.c    | 12 +++++++++++-
 tools/libs/gnttab/include/xengnttab.h |  4 ++--
 tools/libs/gnttab/linux.c             |  6 +++---
 tools/libs/toollog/xtl_logger_stdio.c |  2 +-
 13 files changed, 48 insertions(+), 38 deletions(-)
tools/libs/call/buffer.c +2 -2
index 1a1b27a..2d8fc29 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, size_t nr_pages)
     xcall->buffer_current_allocations--;
 
     if ( nr_pages == 1 &&
-	 xcall->buffer_cache_nr < BUFFER_CACHE_SIZE )
+         xcall->buffer_cache_nr < BUFFER_CACHE_SIZE )
     {
         xcall->buffer_cache[xcall->buffer_cache_nr++] = p;
         rc = 1;
tools/libs/call/core.c +1 -1
index a342871..bbf88de 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 3bee7be..f04688f 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 703754f..38138dc 100644
@@ -121,7 +121,7 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                                  void *addr, size_t num)
 {
-	return munmap(addr, num << PAGE_SHIFT);
+    return munmap(addr, num << PAGE_SHIFT);
 }
 
 /*
tools/libs/foreignmemory/minios.c +3 -3
index ca5ba71..6dc97bd 100644
@@ -46,16 +46,16 @@ void *osdep_xenforeignmemory_map(xenforeignmemory_handle *fmem,
 {
     unsigned long pt_prot = 0;
     if (prot & PROT_READ)
-	pt_prot = L1_PROT_RO;
+        pt_prot = L1_PROT_RO;
     if (prot & PROT_WRITE)
-	pt_prot = L1_PROT;
+        pt_prot = L1_PROT;
     return map_frames_ex(arr, num, 1, 0, 1, dom, err, pt_prot);
 }
 
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                                  void *addr, size_t num)
 {
-	return munmap(addr, num << PAGE_SHIFT);
+    return munmap(addr, num << PAGE_SHIFT);
 }
 
 /*
tools/libs/foreignmemory/netbsd.c +1 -1
index d0d233a..08f4964 100644
@@ -97,7 +97,7 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                                  void *addr, size_t num)
 {
-	return munmap(addr, num*XC_PAGE_SIZE);
+    return munmap(addr, num*XC_PAGE_SIZE);
 }
 
 /*
tools/libs/foreignmemory/private.h +1 -1
index cd732fd..9cc7814 100644
@@ -39,7 +39,7 @@ void *compat_mapforeign_batch(xenforeignmem_handle *fmem, uint32_t dom,
 #endif
 
 #define PERROR(_f...) \
-	xtl_log(fmem->logger, XTL_ERROR, errno, "xenforeignmemory", _f)
+    xtl_log(fmem->logger, XTL_ERROR, errno, "xenforeignmemory", _f)
 
 #endif
 
tools/libs/foreignmemory/solaris.c +11 -1
index f1c44bc..e925a29 100644
@@ -95,5 +95,15 @@ void *osdep_map_foreign_batch(xenforeignmem_handle *fmem, uint32_t dom,
 int osdep_xenforeignmemory_unmap(xenforeignmemory_handle *fmem,
                                  void *addr, size_t num)
 {
-	return munmap(addr, num*XC_PAGE_SIZE);
+    return munmap(addr, num*XC_PAGE_SIZE);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libs/gnttab/include/xengnttab.h +2 -2
index 700a5f1..1e07672 100644
@@ -142,7 +142,7 @@ int xengnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count);
  *      of grants.
  */
 int xengnttab_set_max_grants(xengnttab_handle *xgt,
-			     uint32_t count);
+                             uint32_t count);
 
 /*
  * Grant Sharing Interface (allocating and granting pages)
@@ -160,7 +160,7 @@ typedef struct xengntdev_handle xengntshr_handle;
  *
  */
 xengntshr_handle *xengntshr_open(xentoollog_logger *logger,
-			  unsigned open_flags);
+                                 unsigned open_flags);
 
 /*
  * Close a handle previously allocated with xengntshr_open().
tools/libs/gnttab/linux.c +3 -3
index 768119a..8dbdff8 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
#29 lore raw

PATCH v7 21/29 tools/libs/gnttab: Extensive updates to API documentation.

In reply to Ian Campbell

In particular around error handling, behaviour on fork and the unmap notification mechanism.

Behaviour of xengnttab_map_*grant_refs and xengntshr_share_pages on partial failure has been confirmed/inferred (by inspection) on Linux and Mini-os (the only two known implementations. Likewise the behaviour of the notification mechanism has been confirmed/inferred (by inspection) of the Linux implementation (currently the only implementation) and libvchan (primary known user).

These updates are not folded into "tools: Refactor /dev/xen/gnt{dev,shr} wrappers into libxengnttab." to try and reduce the amount of non-movement changes in that patch.

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

Also fix a typo in a code comment.

---

v7: Typo.
Updates based on Ian Jackson's review.
Even more updates to the discussion of forking based on ML discussion.
v6: Rewrapped a comment.
Incorported much review from Ian on the API, retitled (was:
"tools/libs/gnttab: Review and update doc comments.") and dropped acks

---
 tools/libs/gnttab/include/xengnttab.h | 201 +++++++++++++++++++++++++++++-----
 tools/libs/gnttab/linux.c             |  12 +-
 2 files changed, 181 insertions(+), 32 deletions(-)
tools/libs/gnttab/include/xengnttab.h +174 -27
index 1e07672..7bf8462 100644
@@ -31,28 +31,124 @@
 typedef struct xentoollog_logger xentoollog_logger;
 
 /*
+ * PRODUCING AND CONSUMING GRANT REFERENCES
+ * ========================================
+ *
+ * The xengnttab library contains two distinct interfaces, each with
+ * their own distinct handle type and entry points. The represent the
+ * two sides of the grant table interface, producer (gntshr) and
+ * consumer (gnttab).
+ *
+ * The xengnttab_* interfaces take a xengnttab_handle and provide
+ * mechanisms for consuming (i.e. mapping or copying to/from) grant
+ * references provided by a peer.
+ *
+ * The xengntshr_* interfaces take a xengntshr_handle and provide a
+ * mechanism to produce grantable memory and grant references to that
+ * memory, which can be handed to some peer.
+ *
+ * UNMAP NOTIFICATION
+ * ==================
+ *
+ * The xengnt{tab,shr}_*_notify interfaces implement a cooperative
+ * interface which is intended to allow the underlying kernel
+ * interfaces to attempt to notify the peer to perform graceful
+ * teardown upon failure (i.e. crash or exit) of the process on their
+ * end.
+ *
+ * These interfaces operate on a single page only and are intended for
+ * use on the main shared-ring page of a protocol. It is assumed that
+ * on teardown both ends would automatically teardown all grants
+ * associated with the protocol in addition to the shared ring itself.
+ *
+ * Each end is able to optionally nominate a byte offset within the
+ * shared page or an event channel or both. On exit of the process the
+ * underlying kernel driver will zero the byte at the given offset and
+ * signal the event channel.
+ *
+ * The event channel can be the same event channel used for regular
+ * ring progress notifications, or may be a dedicated event channel.
+ *
+ * Both ends may share the same notification byte offset within the
+ * shared page, or may have dedicated "client" and "server" status
+ * bytes.
+ *
+ * Since the byte is cleared on shutdown the protocol must use 0 as
+ * the "closed/dead" status, but is permitted to use any other non-0
+ * values to indicate various other "live" states (waiting for
+ * connection, connected, etc).
+ *
+ * Both ends are permitted to modify (including clear) their
+ * respective status bytes and to signal the event channel themselves
+ * from userspace.
+ *
+ * Depending on the mechanisms which have been registered an
+ * the peer may receive a shutdown notification as:
+ *
+ *   - An event channel notification on a dedicated event channel
+ *   - Observation of the other ends's status byte being cleared
+ *     (whether in response to an explicit notification or in the
+ *     course of normal operation).
+ *
+ * The mechanism should be defined as part of the specific ring
+ * protocol.
+ *
+ * Upon receiving notification of the peer is expected to teardown any
+ * resources (and in particular any grant mappings) in a timely
+ * manner.
+ *
+ * NOTE: this protocol is intended to allow for better error behaviour
+ * and recovery between two cooperating peers. It does not cover the
+ * case of a malivious peer who may continue to hold resources open.
+ */
+
+/*
  * Grant Table Interface (making use of grants from other domains)
  */
 
 typedef struct xengntdev_handle xengnttab_handle;
 
 /*
- * Note:
- * After fork a child process must not use any opened xc gnttab
- * handle inherited from their parent. They must open a new handle if
- * they want to interact with xc.
+ * Returns a handle onto the grant table driver.  Logs errors.
+ *
+ * Note: After fork(2) a child process must not use any opened gnttab
+ * handle inherited from their parent, nor access any grant mapped
+ * areas associated with that handle.
  *
- * Return an fd onto the grant table driver.  Logs errors.
+ * The child must open a new handle if they want to interact with
+ * gnttab.
+ *
+ * Calling exec(2) in a child will safely (and reliably) reclaim any
+ * resources which were allocated via a xengnttab_handle in the parent.
+ *
+ * A child which does not call exec(2) may safely call
+ * xengnttab_close() on a xengnttab_handle inherited from their
+ * parent. This will attempt to reclaim any resources associated with
+ * that handle. Note that in some implementations this reclamation may
+ * not be completely effective, in this case any affected resources
+ * remain allocated.
+ *
+ * Calling xengnttab_close() is the only safe operation on a
+ * xengnttab_handle which has been inherited. xengnttab_unmap() must
+ * not be called under such circumstances.
  */
 xengnttab_handle *xengnttab_open(xentoollog_logger *logger, unsigned open_flags);
 
 /*
- * Close a handle previously allocated with xengnttab_open().
- * Never logs errors.
+ * Close a handle previously allocated with xengnttab_open(),
+ * including unmaping any current grant maps.  Never logs errors.
+ *
+ * Under normal circumstances (i.e. not in the child after a fork)
+ * xengnttab_unmap() should be used on all mappings allocated through
+ * a xengnttab_handle prior to closing the handle in order to free up
+ * resources associated with those mappings.
+ *
+ * This is the only function which may be safely called on a
+ * xengnttab_handle in a child after a fork.
  */
 int xengnttab_close(xengnttab_handle *xgt);
 
-/*
+/**
  * Memory maps a grant reference from one domain to a local address range.
  * Mappings should be unmapped with xengnttab_unmap.  Logs errors.
  *
@@ -71,6 +167,10 @@ void *xengnttab_map_grant_ref(xengnttab_handle *xgt,
  * contiguous local address range. Mappings should be unmapped with
  * xengnttab_unmap.  Logs errors.
  *
+ * On failure (including partial failure) sets errno and returns
+ * NULL. On partial failure no mappings are established (any partial
+ * work is undone).
+ *
  * @parm xgt a handle on an open grant table interface
  * @parm count the number of grant references to be mapped
  * @parm domids an array of @count domain IDs by which the corresponding @refs
@@ -89,6 +189,9 @@ void *xengnttab_map_grant_refs(xengnttab_handle *xgt,
  * contiguous local address range. Mappings should be unmapped with
  * xengnttab_unmap.  Logs errors.
  *
+ * This call is equivalent to calling @xengnttab_map_grant_refs with a
+ * @domids array with every entry set to @domid.
+ *
  * @parm xgt a handle on an open grant table interface
  * @parm count the number of grant references to be mapped
  * @parm domid the domain to map memory from
@@ -109,6 +212,11 @@ void *xengnttab_map_domain_grant_refs(xengnttab_handle *xgt,
  * unmapped, the byte at the given offset will be zeroed and a wakeup will be
  * sent to the given event channel.  Logs errors.
  *
+ * On failure sets errno and returns NULL.
+ *
+ * If notify_offset or notify_port are requested and cannot be set up
+ * an error will be returned and no mapping will be made.
+ *
  * @parm xgt a handle on an open grant table interface
  * @parm domid the domain to map memory from
  * @parm ref the grant reference ID to map
@@ -124,15 +232,20 @@ void *xengnttab_map_grant_ref_notify(xengnttab_handle *xgt,
                                      uint32_t notify_offset,
                                      evtchn_port_t notify_port);
 
-/*
- * Unmaps the @count pages starting at @start_address, which were mapped by a
- * call to xengnttab_map_grant_ref or xengnttab_map_grant_refs. Never logs.
+/**
+ * Unmaps the @count pages starting at @start_address, which were
+ * mapped by a call to xengnttab_map_grant_ref,
+ * xengnttab_map_grant_refs or xengnttab_map_grant_ref_notify. Never
+ * logs.
+ *
+ * If the mapping was made using xengnttab_map_grant_ref_notify() with
+ * either notify_offset or notify_port then the peer will be notified.
  */
 int xengnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count);
 
-/*
- * Sets the maximum number of grants that may be mapped by the given instance
- * to @count.  Never logs.
+/**
+ * Sets the maximum number of grants that may be mapped by the given
+ * instance to @count.  Never logs.
  *
  * N.B. This function must be called after opening the handle, and before any
  *      other functions are invoked on it.
@@ -142,22 +255,37 @@ int xengnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count);
  *      of grants.
  */
 int xengnttab_set_max_grants(xengnttab_handle *xgt,
-                             uint32_t count);
+                             uint32_t nr_grants);
 
 /*
- * Grant Sharing Interface (allocating and granting pages)
+ * Grant Sharing Interface (allocating and granting pages to others)
  */
 
 typedef struct xengntdev_handle xengntshr_handle;
 
 /*
- * Return an fd onto the grant sharing driver.  Logs errors.
+ * Returns a handle onto the grant sharing driver.  Logs errors.
+ *
+ * Note: After fork(2) a child process must not use any opened gntshr
+ * handle inherited from their parent, nor access any grant mapped
+ * areas associated with that handle.
+ *
+ * The child must open a new handle if they want to interact with
+ * gntshr.
  *
- * Note:
- * After fork a child process must not use any opened xc gntshr
- * handle inherited from their parent. They must open a new handle if
- * they want to interact with xc.
+ * Calling exec(2) in a child will safely (and reliably) reclaim any
+ * resources which were allocated via a xengntshr_handle in the
+ * parent.
  *
+ * A child which does not call exec(2) may safely call
+ * xengntshr_close() on a xengntshr_handle inherited from their
+ * parent. This will attempt to reclaim any resources associated with
+ * that handle. Note that in some implementations this reclamation may
+ * not be completely effective, in this case any affected resources
+ * remain allocated.
+ *
+ * Calling xengntshr_close() is the only safe operation on a
+ * xengntshr_handle which has been inherited.
  */
 xengntshr_handle *xengntshr_open(xentoollog_logger *logger,
                                  unsigned open_flags);
@@ -165,11 +293,26 @@ xengntshr_handle *xengntshr_open(xentoollog_logger *logger,
 /*
  * Close a handle previously allocated with xengntshr_open().
  * Never logs errors.
+ *
+ * Under normal circumstances (i.e. not in the child after a fork)
+ * xengntshr_unmap() should be used on all mappings allocated through
+ * a xengnttab_handle prior to closing the handle in order to free up
+ * resources associated with those mappings.
+ *
+ * xengntshr_close() is the only function which may be safely called
+ * on a xengntshr_handle in a child after a fork. xengntshr_unshare()
+ * must not be called under such circumstances.
  */
 int xengntshr_close(xengntshr_handle *xgs);
 
-/*
- * Creates and shares pages with another domain.
+/**
+ * Allocates and shares pages with another domain.
+ *
+ * On failure sets errno and returns NULL. No allocations will be made.
+ *
+ * This library only provides functionality for sharing memory
+ * allocated via this call, memory from elsewhere (malloc, mmap etc)
+ * cannot be shared here.
  *
  * @parm xgs a handle to an open grant sharing instance
  * @parm domid the domain to share memory with
@@ -181,7 +324,7 @@ int xengntshr_close(xengntshr_handle *xgs);
 void *xengntshr_share_pages(xengntshr_handle *xgs, uint32_t domid,
                             int count, uint32_t *refs, int writable);
 
-/*
+/**
  * Creates and shares a page with another domain, with unmap notification.
  *
  * @parm xgs a handle to an open grant sharing instance
@@ -197,9 +340,13 @@ void *xengntshr_share_page_notify(xengntshr_handle *xgs, uint32_t domid,
                                   uint32_t *ref, int writable,
                                   uint32_t notify_offset,
                                   evtchn_port_t notify_port);
-/*
- * Unmaps the @count pages starting at @start_address, which were mapped by a
- * call to xengntshr_share_*. Never logs.
+
+/**
+ * Unmaps the @count pages starting at @start_address, which were
+ * mapped by a call to xengntshr_share_*. Never logs.
+ *
+ * If the mapping was made using xengntshr_share_page_notify() with
+ * either notify_offset or notify_port then the peer will be notified.
  */
 int xengntshr_unshare(xengntshr_handle *xgs, void *start_address, uint32_t count);
 
tools/libs/gnttab/linux.c +7 -5
index 8dbdff8..be04295 100644
@@ -132,12 +132,14 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt,
     if (addr == MAP_FAILED && errno == EAGAIN)
     {
         /*
-         * The grant hypercall can return EAGAIN if the granted page is
-         * swapped out. Since the paging daemon may be in the same domain, the
-         * hypercall cannot block without causing a deadlock.
+         * The grant hypercall can return EAGAIN if the granted page
+         * is swapped out. Since the paging daemon may be in the same
+         * domain, the hypercall cannot block without causing a
+         * deadlock.
          *
-         * Because there are no notificaitons when the page is swapped in, wait
-         * a bit before retrying, and hope that the page will arrive eventually.
+         * Because there are no notifications when the page is swapped
+         * in, wait a bit before retrying, and hope that the page will
+         * arrive eventually.
          */
         usleep(1000);
         goto retry;
Signature · 1 line
2.1.4
#30 lore raw

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

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

PATCH v7 23/29 tools/libs/call: Describe return values and error semantics for xencall*

In reply to Ian Campbell

This behaviour has been confirmed by inspection on:

- Linux
- NetBSD & FreeBSD (NB: hcall->retval is the hypercall return value only for values >= 0. For negative values the underlying privcmd driver translates the value from Xen to {Net,Free}BSD errno space and returns it as the result of the ioctl, which becomes ret=-1/errno=EFOO in userspace)
- MiniOS (which takes care of errno in this library)

---
v7: Noted NetBSD behaviour
v6: New patch

---
 tools/libs/call/include/xencall.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
tools/libs/call/include/xencall.h +15 -0
index 0d91aa8..3f325f0 100644
@@ -46,6 +46,21 @@ int xencall_close(xencall_handle *xcall);
 
 /*
  * Call hypercalls with varying numbers of arguments.
+ *
+ * On success the return value of the hypercall is the return value of
+ * the xencall function.  On error these functions set errno and
+ * return -1.
+ *
+ * The errno values will be either:
+ * - The Xen hypercall error return (from xen/include/public/errno.h)
+ *   translated into the corresponding local value for that POSIX error.
+ * - An errno value produced by the OS driver or the library
+ *   implementation. Such values may be defined by POSIX or by the OS.
+ *
+ * Note that under some circumstances it will not be possible to tell
+ * whether an error came from Xen or from the OS/library.
+ *
+ * These functions never log.
  */
 int xencall0(xencall_handle *xcall, unsigned int op);
 int xencall1(xencall_handle *xcall, unsigned int op,
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v7 23/29
#32 lore raw

Re: [PATCH XEN v7 23/29] tools/libs/call: Describe return values and error semantics for xencall*

El 16/12/15 a les 13.31, Ian Campbell ha escrit:

Quoted 10 lines

This behaviour has been confirmed by inspection on:

- Linux
- NetBSD & FreeBSD (NB: hcall->retval is the hypercall return value only for values >= 0. For negative values the underlying privcmd driver translates the value from Xen to {Net,Free}BSD errno space and returns it as the result of the ioctl, which becomes ret=-1/errno=EFOO in userspace)
- MiniOS (which takes care of errno in this library)

Quoted 3 lines

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

#33 lore raw

PATCH v7 24/29 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 2aa02f1..e96fbf1 100644
@@ -74,8 +74,8 @@ void *osdep_alloc_hypercall_buffer(xencall_handle *xcall, size_t npages)
     size_t size = npages * XC_PAGE_SIZE;
     void *p;
 
-    p = xc_memalign(xcall, XC_PAGE_SIZE, size);
-    if (!p)
+    ret = posix_memalign(&p, XC_PAGE_SIZE, size);
+    if ( ret != 0 || !p )
         return NULL;
 
     if ( mlock(p, size) < 0 )
tools/libs/call/solaris.c +1 -1
index 945d867..5aa330e 100644
@@ -71,7 +71,7 @@ int osdep_xencall_close(xencall_handle *xcall)
 
 void *osdep_alloc_hypercall_buffer(xencall_handle *xcall, size_t npages)
 {
-    return xc_memalign(xcall, XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
+    return memalign(XC_PAGE_SIZE, npages * XC_PAGE_SIZE);
 }
 
 void osdep_free_hypercall_buffer(xencall_handle *xcall, void *ptr,
Signature · 1 line
2.1.4
#34 lore raw

PATCH v7 25/29 tools/libs/call: linux: touch newly allocated pages after madvise lockdown

In reply to Ian Campbell

This avoids a potential issue with a fork after allocation but before madvise.

---
v7: New, replacing "tools/libs/call: linux: avoid forking between mmap
and madvise".

---
 tools/libs/call/linux.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
tools/libs/call/linux.c +13 -1
index 3641e41..651f380 100644
@@ -88,7 +88,7 @@ void *osdep_alloc_pages(xencall_handle *xcall, size_t npages)
 {
     size_t size = npages * PAGE_SIZE;
     void *p;
-    int rc, saved_errno;
+    int rc, i, saved_errno;
 
     /* Address returned by mmap is page aligned. */
     p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED, -1, 0);
@@ -107,6 +107,18 @@ void *osdep_alloc_pages(xencall_handle *xcall, size_t npages)
         goto out;
     }
 
+    /*
+     * Touch each page in turn to force them to be un-CoWed, in case a
+     * fork happened in another thread at an inopportune moment
+     * above. The madvise() will prevent any subsequent fork calls from
+     * causing the same problem.
+     */
+    for ( i = 0; i < npages ; i++ )
+    {
+        char *c = (char *)p + (i*PAGE_SIZE);
+        *c = 0;
+    }
+
     return p;
 
 out:
Signature · 1 line
2.1.4
#35 lore raw

PATCH v7 26/29 tools/libs/{call, evtchn}: Document requirements around forking.

In reply to Ian Campbell

Much like for gnttab and foreignmemory xencall hypercall buffers need care.

Evtchn is a bit simpler (no magic mappings) but may not work from parent + child simultaneously, document "parent only" since it is consistent with the others.

---
v7: New

---
 tools/libs/call/include/xencall.h     | 28 ++++++++++++++++++++++++++++
 tools/libs/evtchn/include/xenevtchn.h | 23 +++++++++++++++++++----
 2 files changed, 47 insertions(+), 4 deletions(-)
tools/libs/call/include/xencall.h +28 -0
index 3f325f0..559624a 100644
@@ -36,11 +36,39 @@ typedef struct xencall_handle xencall_handle;
 
 /*
  * Return a handle onto the hypercall driver.  Logs errors.
+ * *
+ * Note: After fork(2) a child process must not use any opened
+ * xencall handle inherited from their parent, nor access any
+ * hypercall argument buffers associated with that handle.
+ *
+ * The child must open a new handle if they want to interact with
+ * xencall.
+ *
+ * Calling exec(2) in a child will safely (and reliably) reclaim any
+ * resources which were allocated via a xencall_handle in the parent.
+ *
+ * A child which does not call exec(2) may safely call xencall_close()
+ * on a xencall_handle inherited from their parent. This will attempt
+ * to reclaim any resources associated with that handle. Note that in
+ * some implementations this reclamation may not be completely
+ * effective, in this case any affected resources remain allocated.
+ *
+ * Calling xencall_close() is the only safe operation on a
+ * xencall_handle which has been inherited.
  */
 xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags);
 
 /*
  * Close a handle previously allocated with xencall_open().
+ *
+ * Under normal circumstances (i.e. not in the child after a fork) any
+ * allocated hypercall argument buffers should be freed using the
+ * appropriate xencall_free_*() prior to closing the handle in order
+ * to free up resources associated with those mappings.
+ *
+ * This is the only function which may be safely called on a
+ * xencall_handle in a child after a fork. xencall_free_*() must not
+ * be called under such circumstances.
  */
 int xencall_close(xencall_handle *xcall);
 
tools/libs/evtchn/include/xenevtchn.h +19 -4
index 60da2a3..bb24462 100644
@@ -45,10 +45,25 @@ typedef struct xentoollog_logger xentoollog_logger;
  * Return a handle to the event channel driver, or NULL on failure, in
  * which case errno will be set appropriately.
  *
- * Note:
- * After fork a child process must not use any opened evtchn
- * handle inherited from their parent. They must open a new handle if
- * they want to interact with evtchn.
+ * Note: After fork(2) a child process must not use any opened evtchn
+ * handle inherited from their parent, nor access any grant mapped
+ * areas associated with that handle.
+ *
+ * The child must open a new handle if they want to interact with
+ * evtchn.
+ *
+ * Calling exec(2) in a child will safely (and reliably) reclaim any
+ * allocated resources via a xenevtchn_handle in the parent.
+ *
+ * A child which does not call exec(2) may safely call
+ * xenevtchn_close() on a xenevtchn_handle inherited from their
+ * parent. This will attempt to reclaim any resources associated with
+ * that handle. Note that in some implementations this reclamation may
+ * not be completely effective, in this case any affected resources
+ * remain allocated.
+ *
+ * Calling xenevtchn_close() is the only safe operation on a
+ * xenevtchn_handle which has been inherited.
  */
 /* Currently no flags are defined */
 xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags);
Signature · 1 line
2.1.4
#36 lore raw

PATCH v7 27/29 tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD

In reply to Ian Campbell

In some cases this replaces an FD_CLOEXEC dance, in others it is new.

Linux has had O_CLOEXEC since 2.6.23 (October 2007), so we can rely on it from Xen 4.7 I think. Some libc headers may still lack the definition, so we take care of that if need be.

All stable versions of FreeBSD support O_CLOEXEC (10.2, 9.3 and 8.4), and we assume the libc there does too.

Remove various comments about having to take responsibility for this (since really it is just hygiene, politeness, not a requirement) and the reasons for using O_CLOEXEC seem pretty straightforward.

Backends for other OSes are untouched.

---
v6: New

v7: New, replaces "tools/libs/call: Use O_CLOEXEC when opening
/dev/xen/privcmd on Linux"

---
 tools/libs/call/freebsd.c          | 30 ++++++++----------------------
 tools/libs/call/linux.c            | 38 +++++++++++---------------------------
 tools/libs/evtchn/freebsd.c        |  2 +-
 tools/libs/evtchn/linux.c          |  6 +++++-
 tools/libs/foreignmemory/freebsd.c | 24 ++----------------------
 tools/libs/foreignmemory/linux.c   | 36 +++++++++---------------------------
 tools/libs/gnttab/linux.c          |  6 +++++-
 7 files changed, 41 insertions(+), 101 deletions(-)
tools/libs/call/freebsd.c +8 -22
index 2413966..b3cbccd 100644
@@ -35,8 +35,14 @@
 
 int osdep_xencall_open(xencall_handle *xcall)
 {
-    int flags, saved_errno;
-    int fd = open(PRIVCMD_DEV, O_RDWR);
+    int saved_errno;
+    int fd = open(PRIVCMD_DEV, O_RDWR|O_CLOEXEC);
+
+    /*
+     * This file descriptor is opaque to the caller, thus we are
+     * polite and try and ensure it doesn't propagate (ie leak)
+     * outside the process, by using O_CLOEXEC.
+     */
 
     if ( fd == -1 )
     {
@@ -45,26 +51,6 @@ int osdep_xencall_open(xencall_handle *xcall)
         return -1;
     }
 
-    /*
-     * Although we return the file handle as the 'xc handle' the API
-     * does not specify / guarentee that this integer is in fact
-     * a file handle. Thus we must take responsiblity to ensure
-     * it doesn't propagate (ie leak) outside the process.
-     */
-    if ( (flags = fcntl(fd, F_GETFD)) < 0 )
-    {
-        PERROR("Could not get file handle flags");
-        goto error;
-    }
-
-    flags |= FD_CLOEXEC;
-
-    if ( fcntl(fd, F_SETFD, flags) < 0 )
-    {
-        PERROR("Could not set file handle flags");
-        goto error;
-    }
-
     xcall->fd = fd;
     return 0;
 
tools/libs/call/linux.c +11 -27
index 651f380..1d6c40f 100644
@@ -26,15 +26,23 @@
 
 #include "private.h"
 
+#ifndef O_CLOEXEC
+#define O_CLOEXEC      02000000
+#endif
+
 int osdep_xencall_open(xencall_handle *xcall)
 {
-    int flags, saved_errno;
-    int fd = open("/dev/xen/privcmd", O_RDWR); /* prefer this newer interface */
+    int fd;
+
+    /*
+     * Prefer the newer interface.
+     */
+    fd = open("/dev/xen/privcmd", O_RDWR|O_CLOEXEC);
 
     if ( fd == -1 && ( errno == ENOENT || errno == ENXIO || errno == ENODEV ))
     {
         /* Fallback to /proc/xen/privcmd */
-        fd = open("/proc/xen/privcmd", O_RDWR);
+        fd = open("/proc/xen/privcmd", O_RDWR|O_CLOEXEC);
     }
 
     if ( fd == -1 )
@@ -43,32 +51,8 @@ int osdep_xencall_open(xencall_handle *xcall)
         return -1;
     }
 
-    /* Although we return the file handle as the 'xc handle' the API
-       does not specify / guarentee that this integer is in fact
-       a file handle. Thus we must take responsiblity to ensure
-       it doesn't propagate (ie leak) outside the process */
-    if ( (flags = fcntl(fd, F_GETFD)) < 0 )
-    {
-        PERROR("Could not get file handle flags");
-        goto error;
-    }
-
-    flags |= FD_CLOEXEC;
-
-    if ( fcntl(fd, F_SETFD, flags) < 0 )
-    {
-        PERROR("Could not set file handle flags");
-        goto error;
-    }
-
     xcall->fd = fd;
     return 0;
-
- error:
-    saved_errno = errno;
-    close(fd);
-    errno = saved_errno;
-    return -1;
 }
 
 int osdep_xencall_close(xencall_handle *xcall)
tools/libs/evtchn/freebsd.c +1 -1
index 636f052..cc14991 100644
@@ -32,7 +32,7 @@
 
 int osdep_evtchn_open(xenevtchn_handle *xce)
 {
-    int fd = open(EVTCHN_DEV, O_RDWR);
+    int fd = open(EVTCHN_DEV, O_RDWR|O_CLOEXEC);
     if ( fd == -1 )
         return -1;
     xce->fd = fd;
tools/libs/evtchn/linux.c +5 -1
index 27fd6e9..119dbc6 100644
@@ -28,9 +28,13 @@
 
 #include "private.h"
 
+#ifndef O_CLOEXEC
+#define O_CLOEXEC      02000000
+#endif
+
 int osdep_evtchn_open(xenevtchn_handle *xce)
 {
-    int fd = open("/dev/xen/evtchn", O_RDWR);
+    int fd = open("/dev/xen/evtchn", O_RDWR|O_CLOEXEC);
     if ( fd == -1 )
         return -1;
     xce->fd = fd;
tools/libs/foreignmemory/freebsd.c +2 -22
index 38138dc..7bf3939 100644
@@ -33,8 +33,8 @@
 
 int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
 {
-    int flags, saved_errno;
-    int fd = open(PRIVCMD_DEV, O_RDWR);
+    int saved_errno;
+    int fd = open(PRIVCMD_DEV, O_RDWR|O_CLOEXEC);
 
     if ( fd == -1 )
     {
@@ -43,26 +43,6 @@ int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
         return -1;
     }
 
-    /*
-     * Although we return the file handle as the 'xc handle' the API
-     * does not specify / guarentee that this integer is in fact
-     * a file handle. Thus we must take responsiblity to ensure
-     * it doesn't propagate (ie leak) outside the process.
-     */
-    if ( (flags = fcntl(fd, F_GETFD)) < 0 )
-    {
-        PERROR("Could not get file handle flags");
-        goto error;
-    }
-
-    flags |= FD_CLOEXEC;
-
-    if ( fcntl(fd, F_SETFD, flags) < 0 )
-    {
-        PERROR("Could not set file handle flags");
-        goto error;
-    }
-
     fmem->fd = fd;
     return 0;
 
tools/libs/foreignmemory/linux.c +9 -27
index 32b6def..498efc6 100644
@@ -30,15 +30,21 @@
 
 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 
+#ifndef O_CLOEXEC
+#define O_CLOEXEC      02000000
+#endif
+
 int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
 {
-    int flags, saved_errno;
-    int fd = open("/dev/xen/privcmd", O_RDWR); /* prefer this newer interface */
+    int fd;
+
+    /* prefer this newer interface */
+    fd = open("/dev/xen/privcmd", O_RDWR|O_CLOEXEC);
 
     if ( fd == -1 && ( errno == ENOENT || errno == ENXIO || errno == ENODEV ))
     {
         /* Fallback to /proc/xen/privcmd */
-        fd = open("/proc/xen/privcmd", O_RDWR);
+        fd = open("/proc/xen/privcmd", O_RDWR|O_CLOEXEC);
     }
 
     if ( fd == -1 )
@@ -47,32 +53,8 @@ int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem)
         return -1;
     }
 
-    /* Although we return the file handle as the 'xc handle' the API
-       does not specify / guarentee that this integer is in fact
-       a file handle. Thus we must take responsiblity to ensure
-       it doesn't propagate (ie leak) outside the process */
-    if ( (flags = fcntl(fd, F_GETFD)) < 0 )
-    {
-        PERROR("Could not get file handle flags");
-        goto error;
-    }
-
-    flags |= FD_CLOEXEC;
-
-    if ( fcntl(fd, F_SETFD, flags) < 0 )
-    {
-        PERROR("Could not set file handle flags");
-        goto error;
-    }
-
     fmem->fd = fd;
     return 0;
-
- error:
-    saved_errno = errno;
-    close(fd);
-    errno = saved_errno;
-    return -1;
 }
 
 int osdep_xenforeignmemory_close(xenforeignmemory_handle *fmem)
tools/libs/gnttab/linux.c +5 -1
index be04295..1c31863 100644
@@ -43,9 +43,13 @@
 #define PAGE_SIZE            (1UL << PAGE_SHIFT)
 #define PAGE_MASK            (~(PAGE_SIZE-1))
 
+#ifndef O_CLOEXEC
+#define O_CLOEXEC      02000000
+#endif
+
 int osdep_gnttab_open(xengnttab_handle *xgt)
 {
-    int fd = open(DEVXEN "gntdev", O_RDWR);
+    int fd = open(DEVXEN "gntdev", O_RDWR|O_CLOEXEC);
     if ( fd == -1 )
         return -1;
     xgt->fd = fd;
Signature · 1 line
2.1.4
Acked-by on v7 27/29
#37 lore raw

Re: [PATCH XEN v7 27/29] tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD

El 16/12/15 a les 13.31, Ian Campbell ha escrit:

Quoted 8 lines

In some cases this replaces an FD_CLOEXEC dance, in others it is new.

Linux has had O_CLOEXEC since 2.6.23 (October 2007), so we can rely on it from Xen 4.7 I think. Some libc headers may still lack the definition, so we take care of that if need be.

All stable versions of FreeBSD support O_CLOEXEC (10.2, 9.3 and 8.4), and we assume the libc there does too.

Yes, the FreeBSD libc certainly does, since the kernel and libc are tied together in the BSD world (ie: they live in the same repository).

Quoted 8 lines

Remove various comments about having to take responsibility for this (since really it is just hygiene, politeness, not a requirement) and the reasons for using O_CLOEXEC seem pretty straightforward.

Backends for other OSes are untouched.

For the FreeBSD side:

#38 lore raw

Re: [PATCH XEN v7 27/29] tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD

In reply to Ian Campbell

tools/libs/call/freebsd.c line 39

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 16.12.15 at 13:31, <[email protected]> wrote:
tools/libs/call/freebsd.c +2 -2
@@ -35,8 +35,14 @@
 
 int osdep_xencall_open(xencall_handle *xcall)
 {
-    int flags, saved_errno;
-    int fd = open(PRIVCMD_DEV, O_RDWR);
+    int saved_errno;
+    int fd = open(PRIVCMD_DEV, O_RDWR|O_CLOEXEC);

No compatibility define needed for FreeBSD?

tools/libs/call/linux.c line 31

Quoted 9 lines
tools/libs/call/linux.c +3 -0
@@ -26,15 +26,23 @@
 
 #include "private.h"
 
+#ifndef O_CLOEXEC
+#define O_CLOEXEC      02000000
+#endif

Is that a good idea? Wouldn't you better define to zero if building on an old glibc, assuming you'd then also run on an old kernel?

Jan

#39 lore raw

Re: [PATCH XEN v7 27/29] tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD

Quoted 13 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 16.12.15 at 13:31, <[email protected]> wrote:
tools/libs/call/freebsd.c +0 -0
@@ -35,8 +35,14 @@


 int osdep_xencall_open(xencall_handle *xcall) {
-    int flags, saved_errno;
-    int fd = open(PRIVCMD_DEV, O_RDWR);
+    int saved_errno;
+    int fd = open(PRIVCMD_DEV, O_RDWR|O_CLOEXEC);

No compatibility define needed for FreeBSD?

No, the kernel and libc are more tightly integrated there.

Quoted 4 lines
Quoted 4 lines
tools/libs/call/linux.c +0 -0
@@ -26,15 +26,23 @@

Quoted 8 lines

tools/libs/call/linux.c line 31

Quoted 5 lines

 #include "private.h"

tools/libs/call/linux.c +3 -0
+#ifndef O_CLOEXEC
+#define O_CLOEXEC      02000000
+#endif

Is that a good idea? Wouldn't you better define to zero if building on an old glibc, assuming you'd then also run on an old kernel?

Good point, I was only considering the old userspace but with newer kernel case. Since O_CLOEXEC was implemented in 2.6.23 I was expecting we could just rely on its presence, but you mentioned that you sometimes used newers kernels with older glibcs.

In the end I don't think I mind either way.

Ian.

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

#40 lore raw

Re: [PATCH XEN v7 27/29] tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD

Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 16.12.15 at 15:04, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 16.12.15 at 13:31, <[email protected]> wrote:
tools/libs/call/linux.c +0 -0
@@ -26,15 +26,23 @@
 
Quoted 8 lines

tools/libs/call/linux.c line 31

Quoted 5 lines
tools/libs/call/linux.c +3 -0
 #include "private.h"
 
+#ifndef O_CLOEXEC
+#define O_CLOEXEC      02000000
+#endif

Is that a good idea? Wouldn't you better define to zero if building on an old glibc, assuming you'd then also run on an old kernel?

Quoted 4 lines

Good point, I was only considering the old userspace but with newer kernel case. Since O_CLOEXEC was implemented in 2.6.23 I was expecting we could just rely on its presence, but you mentioned that you sometimes used newers kernels with older glibcs.

I do (and specifically don't run old kernels under newer glibc), but along with the old kernel consideration it is also unclear to me whether we can rely on old glibc to not barf on bits they don't know, irrespective of whether the kernel knows. I.e. I still think that - unless you want to probe for support at runtime, or also evaluate the kernel version of the kernel headers installed - using zero here would be the most compatible approach.

Jan

#41 lore raw

Re: [PATCH XEN v7 27/29] tools/libs/*: Use O_CLOEXEC on Linux and FreeBSD

Quoted 25 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 16.12.15 at 15:04, <[email protected]> wrote:
Quoted 14 lines · Jan Beulich

tools/libs/call/linux.c line 31

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 16.12.15 at 13:31, <[email protected]> wrote:
tools/libs/call/linux.c +0 -0
@@ -26,15 +26,23 @@


 #include "private.h"

tools/libs/call/linux.c +3 -0
+#ifndef O_CLOEXEC
+#define O_CLOEXEC      02000000
+#endif

Is that a good idea? Wouldn't you better define to zero if building on
an old glibc, assuming you'd then also run on an old kernel?

Quoted 7 lines

Good point, I was only considering the old userspace but with newer kernel
case. Since O_CLOEXEC was implemented in 2.6.23 I was expecting we could
just rely on its presence, but you mentioned that you sometimes used newers
kernels with older glibcs.

Quoted 7 lines

I do (and specifically don't run old kernels under newer glibc), but along with the old kernel consideration it is also unclear to me whether we can rely on old glibc to not barf on bits they don't know, irrespective of whether the kernel knows. I.e. I still think that - unless you want to probe for support at runtime, or also evaluate the kernel version of the kernel headers installed - using zero here would be the most compatible approach.

OK, I'll make that change next time.

Ian.

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

#42 lore raw

PATCH v7 28/29 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 c03f6db..3575f16 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
#43 lore raw

PATCH v7 29/29 HACK: Update Config.mk to pull all the right bits from my xenbits trees

In reply to Ian Campbell

v4: Config.mk instead of .config

---
 Config.mk | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
Config.mk +13 -15
index 8fc7767..5472d45 100644
@@ -1,5 +1,3 @@
-# -*- mode: Makefile; -*-
-
 ifeq ($(filter /%,$(XEN_ROOT)),)
 $(error XEN_ROOT must be absolute)
 endif
@@ -242,22 +240,22 @@ endif
 
 ifeq ($(GIT_HTTP),y)
 OVMF_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/ovmf.git
-QEMU_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/qemu-xen.git
-QEMU_TRADITIONAL_URL ?= http://xenbits.xen.org/git-http/qemu-xen-traditional.git
+QEMU_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/people/ianc/libxenctrl-split/qemu-xen.git
+QEMU_TRADITIONAL_URL ?= http://xenbits.xen.org/git-http/people/ianc/libxenctrl-split/qemu-xen-traditional.git
 SEABIOS_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/seabios.git
-MINIOS_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/mini-os.git
+MINIOS_UPSTREAM_URL ?= http://xenbits.xen.org/git-http/people/ianc/libxenctrl-split/mini-os.git
 else
 OVMF_UPSTREAM_URL ?= git://xenbits.xen.org/ovmf.git
-QEMU_UPSTREAM_URL ?= git://xenbits.xen.org/qemu-xen.git
-QEMU_TRADITIONAL_URL ?= git://xenbits.xen.org/qemu-xen-traditional.git
+QEMU_UPSTREAM_URL ?= git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen.git
+QEMU_TRADITIONAL_URL ?= git://xenbits.xen.org/people/ianc/libxenctrl-split/qemu-xen-traditional.git
 SEABIOS_UPSTREAM_URL ?= git://xenbits.xen.org/seabios.git
-MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/mini-os.git
+MINIOS_UPSTREAM_URL ?= git://xenbits.xen.org/people/ianc/libxenctrl-split/mini-os.git
 endif
 OVMF_UPSTREAM_REVISION ?= 52a99493cce88a9d4ec8a02d7f1bd1a1001ce60d
-QEMU_UPSTREAM_REVISION ?= master
-MINIOS_UPSTREAM_REVISION ?= d25773c8afa2f4dbbb466116daeb60159ddd22bd
-# Thu Dec 3 11:23:25 2015 +0000
-# mini-os: Include libxentoollog with libxc
+QEMU_UPSTREAM_REVISION ?= origin/v7
+MINIOS_UPSTREAM_REVISION ?= origin/v7
+# Mon Nov 23 16:34:31 2015 +0000
+# Add a .gitignore
 
 SEABIOS_UPSTREAM_REVISION ?= rel-1.9.0
 # Tue Nov 17 09:18:44 2015 -0500
@@ -266,9 +264,9 @@ SEABIOS_UPSTREAM_REVISION ?= rel-1.9.0
 ETHERBOOT_NICS ?= rtl8139 8086100e
 
 
-QEMU_TRADITIONAL_REVISION ?= 9fad9ed285835caef64bb8dab352e287ad8538c2
-# Thu Dec 3 11:23:16 2015 +0000
-# qemu-xen-traditional: Use xentoollog as a separate library
+QEMU_TRADITIONAL_REVISION ?= origin/v7
+# Tue Mar 11 10:19:23 2014 +0000
+# block-vvfat: fix resource leaks in read_directory()
 
 # Specify which qemu-dm to use. This may be `ioemu' to use the old
 # Mercurial in-tree version, or a local directory, or a git URL.
Signature · 1 line
2.1.4
#44 lore raw

PATCH v7 1/1 tools/libs/*: Introduce APIs to restrict handles to a specific domain.

In reply to Ian Campbell

These are intended to allow user space processes (in particular QEMU) to lock down all the handles at start of day and then drop the privileges which would allow them to open any new unrestricted handles (e.g. setuid or similar). This will reduce the privileges which taking over such a process would gain an attacker wrt other domains in the system.

These are currently unimplemented on all platforms, however the API semantics are defined as the basis for discussion, and so that consumers can rely on this interface always having been present rather than requiring compile time API checks.

It is expected that these will be implemented by adding new ioctl calls on the underlying driver and that the restrictions will be enforced at the kernel interface layer (most likely by the kernel itself).

For evtchn, foreignmemory, gnttab and gntshr this is hopefully reasonably straightforward.

For call it is not so clear cut. Clearly the kernel cannot enforce these restrictions for hypercalls which are not stable (domctl et al) so they can never be on the whitelist. It may also be that potential users would like to restrict the handle further than just a given target domain, i.e. to a specific set of functionality (e.g. "things a device model might reasonably do"). I think we will also need some way to discover whether a given set of interfaces is available to a restricted handle, in order to support the addition of new functionality.

Notes:

- On many (all?) platforms libxencall and libxenforeignmemory are implemented by the same underlying privcmd driver. The platform level ioctl interface should support restricting the handle to only one or the other.
- On platforms with multiple privilege mapping ioctl variants should consider only allowing the newest/currently preferred one on a restricted handle. e.g. on Linux this would allow IOCTL_PRIVCMD_MMAPBATCH_V2 but not IOCTL_PRIVCMD_MMAPBATCH. (Of course any subsequently introduced _V3 would be subject to compatibility concerns)

---
v8: New

This applies on top of the Xen portion of "Begin to disentangle libxenctrl and provide some stable libraries", v7, plus a couple of minor fixes which will be in v8. All of this can be found in the "vwip" branch of the tree referenced by that series at
git://xenbits.xen.org/people/ianc/libxenctrl-split/xen.git.

---
 tools/libs/call/core.c                             |  7 +++
 tools/libs/call/include/xencall.h                  | 34 +++++++++++++++
 tools/libs/call/libxencall.map                     |  2 +
 tools/libs/evtchn/core.c                           |  7 +++
 tools/libs/evtchn/include/xenevtchn.h              | 35 +++++++++++++++
 tools/libs/evtchn/libxenevtchn.map                 |  2 +
 tools/libs/foreignmemory/core.c                    |  7 +++
 .../libs/foreignmemory/include/xenforeignmemory.h  | 22 ++++++++++
 tools/libs/foreignmemory/libxenforeignmemory.map   |  3 ++
 tools/libs/gnttab/gntshr_core.c                    |  8 ++++
 tools/libs/gnttab/gnttab_core.c                    |  7 +++
 tools/libs/gnttab/include/xengnttab.h              | 50 ++++++++++++++++++++++
 tools/libs/gnttab/libxengnttab.map                 |  8 +++-
 13 files changed, 190 insertions(+), 2 deletions(-)
tools/libs/call/core.c +7 -0
index bbf88de..07283da 100644
@@ -14,6 +14,7 @@
  */
 
 #include <stdlib.h>
+#include <errno.h>
 
 #include "private.h"
 
@@ -70,6 +71,12 @@ int xencall_close(xencall_handle *xcall)
     return rc;
 }
 
+int xencall_restrict_target(xencall_handle *xcall, uint32_t domid)
+{
+    errno = ENOSYS;
+    return -1;
+}
+
 int xencall0(xencall_handle *xcall, unsigned int op)
 {
     privcmd_hypercall_t call = {
tools/libs/call/include/xencall.h +34 -0
index 559624a..594e5f1 100644
@@ -73,6 +73,40 @@ xencall_handle *xencall_open(xentoollog_logger *logger, unsigned open_flags);
 int xencall_close(xencall_handle *xcall);
 
 /*
+ * Attempt to restrict the given xcall handle to only be able to
+ * target the given domain.
+ *
+ * On success returns 0, after which only hypercalls which are on a
+ * platform specific whitelist can be called and the arguments will be
+ * audited by the platform to ensure that the target domain is
+ * domid.
+ *
+ * Subsequent attempts to call any hypercall not on the platform
+ * specific whitelist will return -1 setting errno to ENOSYS.
+ *
+ * Subsequent attempts to call any hypercall on the platform specific
+ * whitelist with any other target domain return return -1 setting
+ * errno to EPERM.
+ *
+ * These restrictions will be implemented by the platform in a way
+ * which cannot be circumvented by a userspace process. Further
+ * privilege drops (such as using setuid(2) etc) may also be required
+ * to prevent a compromised process from simply opening a second
+ * handle
+ *
+ * XXX which hypercalls are restricted, per platform list, do we need
+ * a way to probe? Do we want to be able to restrict to particular
+ * subsets of whitelisted hypercalls?
+ *
+ * On failure returns -1 and sets errno:
+ *   ENOSYS: The platform is not able to support restricting the
+ *           target domain.
+ *   Other: The platform should be able to support restricting the
+ *          target domain, but was unable to do so.
+ */
+int xencall_restrict_target(xencall_handle *xcall, uint32_t domid);
+
+/*
  * Call hypercalls with varying numbers of arguments.
  *
  * On success the return value of the hypercall is the return value of
tools/libs/call/libxencall.map +2 -0
index 2f96144..d39f88e 100644
@@ -3,6 +3,8 @@ VERS_1.0 {
 		xencall_open;
 		xencall_close;
 
+		xencall_restrict_target;
+
 		xencall0;
 		xencall1;
 		xencall2;
tools/libs/evtchn/core.c +7 -0
index c31e08c..5f68f52 100644
@@ -15,6 +15,7 @@
 
 #include <unistd.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #include "private.h"
 
@@ -61,6 +62,12 @@ int xenevtchn_close(xenevtchn_handle *xce)
     return rc;
 }
 
+int xenevtchn_restrict_target(xenevtchn_handle *xce, uint32_t domid)
+{
+    errno = ENOSYS;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/evtchn/include/xenevtchn.h +35 -0
index 4d26161..e0bcd78 100644
@@ -74,6 +74,41 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags)
 int xenevtchn_close(xenevtchn_handle *xce);
 
 /*
+ * Attempt to restrict the given evtchn handle to only operate on the
+ * given domain.
+ *
+ * On success returns 0, after which:
+ *
+ * - Any operations which take a peer domain as an argument can only
+ *   be called with the specified target domain. Subsequent attempts
+ *   to call any such interface with another domain will return -1
+ *   setting errno to EPERM.
+ *
+ * - Any operations which take an evtchn_port_t are not restricted
+ *   other than by the requirement to have previously bound that
+ *   evtchn to the handle. Therefore users of the restrict interface
+ *   should take care not to bind any event channels relating to other
+ *   domains prior to enforcing the restriction. The restrictions on
+ *   xenevtchn_bind_* suffice to prevent any new such bindings.
+ *
+ * - xenevtchn_bind_virq is not permitted after and will return -1
+ *   setting errno EPERM.
+ *
+ * These restrictions will be implemented by the platform in a way
+ * which cannot be circumvented by a userspace process. Further
+ * privilege drops (such as using setuid(2) etc) may also be required
+ * to prevent a compromised process from simply opening a second
+ * handle
+ *
+ * On failure returns -1 and sets errno:
+ *   ENOSYS: The platform is not able to support restricting the
+ *           target domain.
+ *   Other: The platform should be able to support restricting the
+ *          target domain, but was unable to do so.
+ */
+int xenevtchn_restrict_target(xenevtchn_handle *xce, uint32_t domid);
+
+/*
  * Return an fd that can be select()ed on.
  *
  * Note that due to bugs, setting this fd to non blocking may not
tools/libs/evtchn/libxenevtchn.map +2 -0
index 625a1e2..08e9dd5 100644
@@ -3,6 +3,8 @@ VERS_1.0 {
 		xenevtchn_open;
 		xenevtchn_close;
 
+		xenevtchn_restrict_target;
+
 		xenevtchn_fd;
 
 		xenevtchn_bind_unbound_port;
tools/libs/foreignmemory/core.c +7 -0
index cfb0a73..73e8034 100644
@@ -62,6 +62,13 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem)
     return rc;
 }
 
+int xenforeignmemory_restrict_target(xenforeignmemory_handle *fmem,
+                                     uint32_t domid)
+{
+    errno = ENOSYS;
+    return -1;
+}
+
 void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
                            uint32_t dom, int prot,
                            size_t num,
tools/libs/foreignmemory/include/xenforeignmemory.h +22 -0
index 3724c63..350ca75 100644
@@ -74,6 +74,28 @@ xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,
 int xenforeignmemory_close(xenforeignmemory_handle *fmem);
 
 /*
+ * Attempt to restrict the given handle to only target the given
+ * domain.
+ *
+ * On success returns 0, after which calls to xenforeignmemory_map
+ * which pass a domain other than the given domain will return -1
+ * setting errno to EPERM.
+ *
+ * This restriction will be implemented by the platform in a way which
+ * cannot be circumvented by a userspace process. Further privilege
+ * drops (such as using setuid(2) etc) may also be required to prevent
+ * a compromised process from simply opening a second handle
+ *
+ * On failure returns -1 and sets errno:
+ *   ENOSYS: The platform is not able to support restricting the
+ *           target domain.
+ *   Other: The platform should be able to support restricting the
+ *          target domain, but was unable to do so.
+ */
+int xenforeignmemory_restrict_target(xenforeignmemory_handle *fmem,
+                                     uint32_t domid);
+
+/*
  * Maps a range within one domain to a local address range.  Mappings
  * must be unmapped with xenforeignmemory_unmap and should follow the
  * same rules as mmap regarding page alignment.
tools/libs/foreignmemory/libxenforeignmemory.map +3 -0
index df206b3..dc1e0a1 100644
@@ -2,6 +2,9 @@ VERS_1.0 {
 	global:
 		xenforeignmemory_open;
 		xenforeignmemory_close;
+
+		xenforeignmemory_restrict_target;
+
 		xenforeignmemory_map;
 		xenforeignmemory_unmap;
 	local: *; /* Do not expose anything by default */
tools/libs/gnttab/gntshr_core.c +8 -0
index 7f6bf9d..0347a16 100644
@@ -19,6 +19,7 @@
  */
 
 #include <stdlib.h>
+#include <errno.h>
 
 #include "private.h"
 
@@ -64,6 +65,13 @@ int xengntshr_close(xengntshr_handle *xgs)
     free(xgs);
     return rc;
 }
+
+int xengntshr_restrict_target(xengntshr_handle *xgs, uint32_t domid)
+{
+    errno = ENOSYS;
+    return -1;
+}
+
 void *xengntshr_share_pages(xengntshr_handle *xcg, uint32_t domid,
                             int count, uint32_t *refs, int writable)
 {
tools/libs/gnttab/gnttab_core.c +7 -0
index 5d0474d..77ce1670 100644
@@ -19,6 +19,7 @@
  */
 
 #include <stdlib.h>
+#include <errno.h>
 
 #include "private.h"
 
@@ -65,6 +66,12 @@ int xengnttab_close(xengnttab_handle *xgt)
     return rc;
 }
 
+int xengnttab_restrict_target(xengnttab_handle *xgt, uint32_t domid)
+{
+    errno = ENOSYS;
+    return -1;
+}
+
 int xengnttab_set_max_grants(xengnttab_handle *xgt, uint32_t count)
 {
     return osdep_gnttab_set_max_grants(xgt, count);
tools/libs/gnttab/include/xengnttab.h +50 -0

62 lines not on this page · raw message

tools/libs/gnttab/libxengnttab.map +6 -2
index 66e8c12..c3d7d49 100644
@@ -3,6 +3,8 @@ VERS_1.0 {
 		xengnttab_open;
 		xengnttab_close;
 
+		xengnttab_restrict_target;
+
 		xengnttab_set_max_grants;
 
 		xengnttab_map_domain_grant_refs;
@@ -11,10 +13,12 @@ VERS_1.0 {
 		xengnttab_map_grant_refs;
 
 		xengnttab_unmap;
-		
+
 		xengntshr_open;
 		xengntshr_close;
-		
+
+		xengntshr_restrict_target;
+
 		xengntshr_share_page_notify;
 		xengntshr_share_pages;
 		
Signature · 1 line
2.1.4
#45 lore raw

v7 cover Begin to disentangle libxenctrl and provide some stable libraries

In reply to Ian Campbell

We intend to stabilise some parts of the libxenctrl interface by splitting out some functionality into separate stable libraries.

This is the qemu-xen part of the first phase of that change.

This mail is (or is intended to be) a reply to a "0/<VARIOUS>" super-intro mail covering all of the related patch series and which contains more details.

Ian Campbell (8):
xen_console: correctly cleanup primary console on teardown.
xen: Switch to libxenevtchn interface for compat shims.
xen: Switch to libxengnttab interface for compat shims.
xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages
xen: Switch uses of xc_map_foreign_{pages,bulk} to use
libxenforeignmemory API.
xen: Use stable library interfaces when they are available.
xen: domainbuild: reopen libxenctrl interface after forking for domain
watcher.
xen: make it possible to build without the Xen PV domain builder

 configure                    |  57 ++++++++++++++++-
 hw/block/xen_disk.c          |  38 +++++------
 hw/char/xen_console.c        |  19 +++---
 hw/display/xenfb.c           |  28 +++++----
 hw/net/xen_nic.c             |  18 +++---
 hw/xen/xen_backend.c         |  44 ++++++-------
 hw/xenpv/Makefile.objs       |   4 +-
 hw/xenpv/xen_domainbuild.c   |   9 ++-
 hw/xenpv/xen_machine_pv.c    |  15 +++--
 include/hw/xen/xen_backend.h |   5 +-
 include/hw/xen/xen_common.h  | 147 ++++++++++++++++++++++++++++++++++---------
 xen-common.c                 |   6 ++
 xen-hvm.c                    |  39 ++++++------
 xen-mapcache.c               |   6 +-
 14 files changed, 299 insertions(+), 136 deletions(-)
Signature · 1 line
2.1.4
#46 lore raw

v7 cover Begin to disentangle libxenctrl and provide some stable libraries

In reply to Ian Campbell

We intend to stabilise some parts of the libxenctrl interface by splitting out some functionality into separate stable libraries.

This is the qemu-xen part of the first phase of that change.

This mail is (or is intended to be) a reply to a "0/<VARIOUS>" super-intro mail covering all of the related patch series and which contains more details.

Ian Campbell (8):
xen_console: correctly cleanup primary console on teardown.
xen: Switch to libxenevtchn interface for compat shims.
xen: Switch to libxengnttab interface for compat shims.
xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages
xen: Switch uses of xc_map_foreign_{pages,bulk} to use
libxenforeignmemory API.
xen: Use stable library interfaces when they are available.
xen: domainbuild: reopen libxenctrl interface after forking for domain
watcher.
xen: make it possible to build without the Xen PV domain builder

 configure                    |  57 ++++++++++++++++-
 hw/block/xen_disk.c          |  38 +++++------
 hw/char/xen_console.c        |  19 +++---
 hw/display/xenfb.c           |  28 +++++----
 hw/net/xen_nic.c             |  18 +++---
 hw/xen/xen_backend.c         |  44 ++++++-------
 hw/xenpv/Makefile.objs       |   4 +-
 hw/xenpv/xen_domainbuild.c   |   9 ++-
 hw/xenpv/xen_machine_pv.c    |  15 +++--
 include/hw/xen/xen_backend.h |   5 +-
 include/hw/xen/xen_common.h  | 147 ++++++++++++++++++++++++++++++++++---------
 xen-common.c                 |   6 ++
 xen-hvm.c                    |  39 ++++++------
 xen-mapcache.c               |   6 +-
 14 files changed, 299 insertions(+), 136 deletions(-)
Signature · 1 line
2.1.4
#47 lore raw

PATCH v7 1/8 xen_console: correctly cleanup primary console on teardown.

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

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

With this con_initialise and con_disconnect now mirror each other.

Fix up a hard tab in the function while editing.

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

---
 hw/char/xen_console.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
hw/char/xen_console.c +2 -5
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;
     }
 }
 
Signature · 1 line
2.1.4
#48 lore raw

PATCH v7 2/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.

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

Note that xc_evtchn_alloc_unbound functionality remains in libxenctrl, since that functionality is not exposed by /dev/xen/evtchn.

---
v4: Ran checkpatch, fixed all errors
Allocate correct size for handle (i.e. not size of the ptr)

---
 hw/xen/xen_backend.c         | 31 ++++++++++++++++---------------
 include/hw/xen/xen_backend.h |  2 +-
 include/hw/xen/xen_common.h  | 44 ++++++++++++++++++++++++++++++++++----------
 xen-hvm.c                    | 25 +++++++++++++------------
 4 files changed, 64 insertions(+), 38 deletions(-)
hw/xen/xen_backend.c +16 -15
index 2510e2e..ae2a1f0 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,14 @@ static void xen_be_evtchn_event(void *opaque)
     struct XenDevice *xendev = opaque;
     evtchn_port_t port;
 
-    port = xc_evtchn_pending(xendev->evtchndev);
+    port = xenevtchn_pending(xendev->evtchndev);
     if (port != xendev->local_port) {
-        xen_be_printf(xendev, 0, "xc_evtchn_pending returned %d (expected %d)\n",
+        xen_be_printf(xendev, 0,
+                      "xenevtchn_pending returned %d (expected %d)\n",
                       port, xendev->local_port);
         return;
     }
-    xc_evtchn_unmask(xendev->evtchndev, port);
+    xenevtchn_unmask(xendev->evtchndev, port);
 
     if (xendev->ops->event) {
         xendev->ops->event(xendev);
@@ -740,14 +741,14 @@ int xen_be_bind_evtchn(struct XenDevice *xendev)
     if (xendev->local_port != -1) {
         return 0;
     }
-    xendev->local_port = xc_evtchn_bind_interdomain
+    xendev->local_port = xenevtchn_bind_interdomain
         (xendev->evtchndev, xendev->dom, xendev->remote_port);
     if (xendev->local_port == -1) {
-        xen_be_printf(xendev, 0, "xc_evtchn_bind_interdomain failed\n");
+        xen_be_printf(xendev, 0, "xenevtchn_bind_interdomain failed\n");
         return -1;
     }
     xen_be_printf(xendev, 2, "bind evtchn port %d\n", xendev->local_port);
-    qemu_set_fd_handler(xc_evtchn_fd(xendev->evtchndev),
+    qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev),
                         xen_be_evtchn_event, NULL, xendev);
     return 0;
 }
@@ -757,15 +758,15 @@ void xen_be_unbind_evtchn(struct XenDevice *xendev)
     if (xendev->local_port == -1) {
         return;
     }
-    qemu_set_fd_handler(xc_evtchn_fd(xendev->evtchndev), NULL, NULL, NULL);
-    xc_evtchn_unbind(xendev->evtchndev, xendev->local_port);
+    qemu_set_fd_handler(xenevtchn_fd(xendev->evtchndev), NULL, NULL, NULL);
+    xenevtchn_unbind(xendev->evtchndev, xendev->local_port);
     xen_be_printf(xendev, 2, "unbind evtchn port %d\n", xendev->local_port);
     xendev->local_port = -1;
 }
 
 int xen_be_send_notify(struct XenDevice *xendev)
 {
-    return xc_evtchn_notify(xendev->evtchndev, xendev->local_port);
+    return xenevtchn_notify(xendev->evtchndev, xendev->local_port);
 }
 
 /*
include/hw/xen/xen_backend.h +1 -1
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 +34 -10

68 lines not on this page · raw message

xen-hvm.c +13 -12
index 3d78a0c..6680782 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;
 
@@ -714,7 +714,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));
@@ -733,7 +733,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;
@@ -1040,7 +1040,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);
     }
 }
 
@@ -1084,7 +1084,8 @@ static void cpu_handle_ioreq(void *opaque)
         }
 
         req->state = STATE_IORESP_READY;
-        xc_evtchn_notify(state->xce_handle, state->ioreq_local_port[state->send_vcpu]);
+        xenevtchn_notify(state->xce_handle,
+                         state->ioreq_local_port[state->send_vcpu]);
     }
 }
 
@@ -1092,8 +1093,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,
@@ -1131,7 +1132,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);
 }
 
@@ -1200,8 +1201,8 @@ int xen_hvm_init(PCMachineState *pcms,
 
     state = g_malloc0(sizeof (XenIOState));
 
-    state->xce_handle = xen_xc_evtchn_open(NULL, 0);
-    if (state->xce_handle == XC_HANDLER_INITIAL_VALUE) {
+    state->xce_handle = xenevtchn_open(NULL, 0);
+    if (state->xce_handle == NULL) {
         perror("xen: event channel open");
         return -1;
     }
@@ -1281,7 +1282,7 @@ int xen_hvm_init(PCMachineState *pcms,
 
     /* FIXME: how about if we overflow the page here? */
     for (i = 0; i < max_cpus; i++) {
-        rc = xc_evtchn_bind_interdomain(state->xce_handle, xen_domid,
+        rc = xenevtchn_bind_interdomain(state->xce_handle, xen_domid,
                                         xen_vcpu_eport(state->shared_page, i));
         if (rc == -1) {
             fprintf(stderr, "shared evtchn %d bind error %d\n", i, errno);
@@ -1290,7 +1291,7 @@ int xen_hvm_init(PCMachineState *pcms,
         state->ioreq_local_port[i] = rc;
     }
 
-    rc = xc_evtchn_bind_interdomain(state->xce_handle, xen_domid,
+    rc = xenevtchn_bind_interdomain(state->xce_handle, xen_domid,
                                     bufioreq_evtchn);
     if (rc == -1) {
         fprintf(stderr, "buffered evtchn bind error %d\n", errno);
Signature · 1 line
2.1.4
#49 lore raw

PATCH v7 3/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.

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

---
v4: Ran checkpatch, fixed all errors
Allocate correct size for handle (i.e. not size of the ptr) Rebase onto "xen_console: correctly cleanup primary console on teardown."

v5: Rebase over b4f72e31b924 "hw/net/xen_nic.c: Free 'netdev->txs' when map 'netdev->rxs' fails" which added a new gnttab_munmap.

v7: s/gnttab_munmap/gnttab_unmap/ to reflect change in the library.

---
 hw/block/xen_disk.c          | 38 ++++++++++++++++++++------------------
 hw/char/xen_console.c        |  4 ++--
 hw/net/xen_nic.c             | 18 +++++++++---------
 hw/xen/xen_backend.c         | 10 +++++-----
 include/hw/xen/xen_backend.h |  2 +-
 include/hw/xen/xen_common.h  | 42 ++++++++++++++++++++++++++++++++----------
 6 files changed, 69 insertions(+), 45 deletions(-)
hw/block/xen_disk.c +20 -18
index 8146650..e1f8dd4 100644
@@ -171,11 +171,11 @@ static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
 static void destroy_grant(gpointer pgnt)
 {
     PersistentGrant *grant = pgnt;
-    XenGnttab gnt = grant->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = grant->blkdev->xendev.gnttabdev;
 
-    if (xc_gnttab_munmap(gnt, grant->page, 1) != 0) {
+    if (xengnttab_unmap(gnt, grant->page, 1) != 0) {
         xen_be_printf(&grant->blkdev->xendev, 0,
-                      "xc_gnttab_munmap failed: %s\n",
+                      "xengnttab_unmap failed: %s\n",
                       strerror(errno));
     }
     grant->blkdev->persistent_gnt_count--;
@@ -188,11 +188,11 @@ static void remove_persistent_region(gpointer data, gpointer dev)
 {
     PersistentRegion *region = data;
     struct XenBlkDev *blkdev = dev;
-    XenGnttab gnt = blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = blkdev->xendev.gnttabdev;
 
-    if (xc_gnttab_munmap(gnt, region->addr, region->num) != 0) {
+    if (xengnttab_unmap(gnt, region->addr, region->num) != 0) {
         xen_be_printf(&blkdev->xendev, 0,
-                      "xc_gnttab_munmap region %p failed: %s\n",
+                      "xengnttab_unmap region %p failed: %s\n",
                       region->addr, strerror(errno));
     }
     xen_be_printf(&blkdev->xendev, 3,
@@ -327,7 +327,7 @@ err:
 
 static void ioreq_unmap(struct ioreq *ioreq)
 {
-    XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
     int i;
 
     if (ioreq->num_unmap == 0 || ioreq->mapped == 0) {
@@ -337,8 +337,9 @@ static void ioreq_unmap(struct ioreq *ioreq)
         if (!ioreq->pages) {
             return;
         }
-        if (xc_gnttab_munmap(gnt, ioreq->pages, ioreq->num_unmap) != 0) {
-            xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
+        if (xengnttab_unmap(gnt, ioreq->pages, ioreq->num_unmap) != 0) {
+            xen_be_printf(&ioreq->blkdev->xendev, 0,
+                          "xengnttab_unmap failed: %s\n",
                           strerror(errno));
         }
         ioreq->blkdev->cnt_map -= ioreq->num_unmap;
@@ -348,8 +349,9 @@ static void ioreq_unmap(struct ioreq *ioreq)
             if (!ioreq->page[i]) {
                 continue;
             }
-            if (xc_gnttab_munmap(gnt, ioreq->page[i], 1) != 0) {
-                xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
+            if (xengnttab_unmap(gnt, ioreq->page[i], 1) != 0) {
+                xen_be_printf(&ioreq->blkdev->xendev, 0,
+                              "xengnttab_unmap failed: %s\n",
                               strerror(errno));
             }
             ioreq->blkdev->cnt_map--;
@@ -361,7 +363,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
 
 static int ioreq_map(struct ioreq *ioreq)
 {
-    XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
     uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST];
@@ -412,7 +414,7 @@ static int ioreq_map(struct ioreq *ioreq)
     }
 
     if (batch_maps && new_maps) {
-        ioreq->pages = xc_gnttab_map_grant_refs
+        ioreq->pages = xengnttab_map_grant_refs
             (gnt, new_maps, domids, refs, ioreq->prot);
         if (ioreq->pages == NULL) {
             xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -428,7 +430,7 @@ static int ioreq_map(struct ioreq *ioreq)
         ioreq->blkdev->cnt_map += new_maps;
     } else if (new_maps)  {
         for (i = 0; i < new_maps; i++) {
-            ioreq->page[i] = xc_gnttab_map_grant_ref
+            ioreq->page[i] = xengnttab_map_grant_ref
                 (gnt, domids[i], refs[i], ioreq->prot);
             if (ioreq->page[i] == NULL) {
                 xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -778,9 +780,9 @@ static void blk_alloc(struct XenDevice *xendev)
     if (xen_mode != XEN_EMULATE) {
         batch_maps = 1;
     }
-    if (xc_gnttab_set_max_grants(xendev->gnttabdev,
+    if (xengnttab_set_max_grants(xendev->gnttabdev,
             MAX_GRANTS(max_requests, BLKIF_MAX_SEGMENTS_PER_REQUEST)) < 0) {
-        xen_be_printf(xendev, 0, "xc_gnttab_set_max_grants failed: %s\n",
+        xen_be_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n",
                       strerror(errno));
     }
 }
@@ -987,7 +989,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);
@@ -1052,7 +1054,7 @@ static void blk_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&blkdev->xendev);
 
     if (blkdev->sring) {
-        xc_gnttab_munmap(blkdev->xendev.gnttabdev, blkdev->sring, 1);
+        xengnttab_unmap(blkdev->xendev.gnttabdev, blkdev->sring, 1);
         blkdev->cnt_map--;
         blkdev->sring = NULL;
     }
hw/char/xen_console.c +2 -2
index 63ade33..ac1b324 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);
     }
@@ -275,7 +275,7 @@ static void con_disconnect(struct XenDevice *xendev)
         if (!xendev->dev) {
             munmap(con->sring, XC_PAGE_SIZE);
         } else {
-            xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1);
+            xengnttab_unmap(xendev->gnttabdev, con->sring, 1);
         }
         con->sring = NULL;
     }
hw/net/xen_nic.c +9 -9
index 0da16b4..3ffb07d 100644
@@ -168,7 +168,7 @@ static void net_tx_packets(struct XenNetDev *netdev)
                           (txreq.flags & NETTXF_more_data)      ? " more_data"      : "",
                           (txreq.flags & NETTXF_extra_info)     ? " extra_info"     : "");
 
-            page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+            page = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                            netdev->xendev.dom,
                                            txreq.gref, PROT_READ);
             if (page == NULL) {
@@ -190,7 +190,7 @@ static void net_tx_packets(struct XenNetDev *netdev)
                 qemu_send_packet(qemu_get_queue(netdev->nic),
                                  page + txreq.offset, txreq.size);
             }
-            xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
+            xengnttab_unmap(netdev->xendev.gnttabdev, page, 1);
             net_tx_response(netdev, &txreq, NETIF_RSP_OKAY);
         }
         if (!netdev->tx_work) {
@@ -260,7 +260,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t 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) {
@@ -270,7 +270,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_unmap(netdev->xendev.gnttabdev, page, 1);
     net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0);
 
     return size;
@@ -342,19 +342,19 @@ static int net_connect(struct XenDevice *xendev)
         return -1;
     }
 
-    netdev->txs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->txs = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->tx_ring_ref,
                                           PROT_READ | PROT_WRITE);
     if (!netdev->txs) {
         return -1;
     }
-    netdev->rxs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->rxs = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->rx_ring_ref,
                                           PROT_READ | PROT_WRITE);
     if (!netdev->rxs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->txs, 1);
+        xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1);
         netdev->txs = NULL;
         return -1;
     }
@@ -379,11 +379,11 @@ static void net_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&netdev->xendev);
 
     if (netdev->txs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->txs, 1);
+        xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1);
         netdev->txs = NULL;
     }
     if (netdev->rxs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
+        xengnttab_unmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
         netdev->rxs = NULL;
     }
 }
hw/xen/xen_backend.c +5 -5
index ae2a1f0..966e34f 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 +32 -10

68 lines not on this page · raw message

Signature · 1 line
2.1.4
#50 lore raw

PATCH v7 3/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.

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

---
v4: Ran checkpatch, fixed all errors
Allocate correct size for handle (i.e. not size of the ptr) Rebase onto "xen_console: correctly cleanup primary console on teardown."

v5: Rebase over b4f72e31b924 "hw/net/xen_nic.c: Free 'netdev->txs' when map 'netdev->rxs' fails" which added a new gnttab_munmap.

v7: s/gnttab_munmap/gnttab_unmap/ to reflect change in the library.

---
 hw/block/xen_disk.c          | 38 ++++++++++++++++++++------------------
 hw/char/xen_console.c        |  4 ++--
 hw/net/xen_nic.c             | 18 +++++++++---------
 hw/xen/xen_backend.c         | 10 +++++-----
 include/hw/xen/xen_backend.h |  2 +-
 include/hw/xen/xen_common.h  | 42 ++++++++++++++++++++++++++++++++----------
 6 files changed, 69 insertions(+), 45 deletions(-)
hw/block/xen_disk.c +20 -18
index 8146650..e1f8dd4 100644
@@ -171,11 +171,11 @@ static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
 static void destroy_grant(gpointer pgnt)
 {
     PersistentGrant *grant = pgnt;
-    XenGnttab gnt = grant->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = grant->blkdev->xendev.gnttabdev;
 
-    if (xc_gnttab_munmap(gnt, grant->page, 1) != 0) {
+    if (xengnttab_unmap(gnt, grant->page, 1) != 0) {
         xen_be_printf(&grant->blkdev->xendev, 0,
-                      "xc_gnttab_munmap failed: %s\n",
+                      "xengnttab_unmap failed: %s\n",
                       strerror(errno));
     }
     grant->blkdev->persistent_gnt_count--;
@@ -188,11 +188,11 @@ static void remove_persistent_region(gpointer data, gpointer dev)
 {
     PersistentRegion *region = data;
     struct XenBlkDev *blkdev = dev;
-    XenGnttab gnt = blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = blkdev->xendev.gnttabdev;
 
-    if (xc_gnttab_munmap(gnt, region->addr, region->num) != 0) {
+    if (xengnttab_unmap(gnt, region->addr, region->num) != 0) {
         xen_be_printf(&blkdev->xendev, 0,
-                      "xc_gnttab_munmap region %p failed: %s\n",
+                      "xengnttab_unmap region %p failed: %s\n",
                       region->addr, strerror(errno));
     }
     xen_be_printf(&blkdev->xendev, 3,
@@ -327,7 +327,7 @@ err:
 
 static void ioreq_unmap(struct ioreq *ioreq)
 {
-    XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
     int i;
 
     if (ioreq->num_unmap == 0 || ioreq->mapped == 0) {
@@ -337,8 +337,9 @@ static void ioreq_unmap(struct ioreq *ioreq)
         if (!ioreq->pages) {
             return;
         }
-        if (xc_gnttab_munmap(gnt, ioreq->pages, ioreq->num_unmap) != 0) {
-            xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
+        if (xengnttab_unmap(gnt, ioreq->pages, ioreq->num_unmap) != 0) {
+            xen_be_printf(&ioreq->blkdev->xendev, 0,
+                          "xengnttab_unmap failed: %s\n",
                           strerror(errno));
         }
         ioreq->blkdev->cnt_map -= ioreq->num_unmap;
@@ -348,8 +349,9 @@ static void ioreq_unmap(struct ioreq *ioreq)
             if (!ioreq->page[i]) {
                 continue;
             }
-            if (xc_gnttab_munmap(gnt, ioreq->page[i], 1) != 0) {
-                xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
+            if (xengnttab_unmap(gnt, ioreq->page[i], 1) != 0) {
+                xen_be_printf(&ioreq->blkdev->xendev, 0,
+                              "xengnttab_unmap failed: %s\n",
                               strerror(errno));
             }
             ioreq->blkdev->cnt_map--;
@@ -361,7 +363,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
 
 static int ioreq_map(struct ioreq *ioreq)
 {
-    XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
+    xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
     uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
     void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST];
@@ -412,7 +414,7 @@ static int ioreq_map(struct ioreq *ioreq)
     }
 
     if (batch_maps && new_maps) {
-        ioreq->pages = xc_gnttab_map_grant_refs
+        ioreq->pages = xengnttab_map_grant_refs
             (gnt, new_maps, domids, refs, ioreq->prot);
         if (ioreq->pages == NULL) {
             xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -428,7 +430,7 @@ static int ioreq_map(struct ioreq *ioreq)
         ioreq->blkdev->cnt_map += new_maps;
     } else if (new_maps)  {
         for (i = 0; i < new_maps; i++) {
-            ioreq->page[i] = xc_gnttab_map_grant_ref
+            ioreq->page[i] = xengnttab_map_grant_ref
                 (gnt, domids[i], refs[i], ioreq->prot);
             if (ioreq->page[i] == NULL) {
                 xen_be_printf(&ioreq->blkdev->xendev, 0,
@@ -778,9 +780,9 @@ static void blk_alloc(struct XenDevice *xendev)
     if (xen_mode != XEN_EMULATE) {
         batch_maps = 1;
     }
-    if (xc_gnttab_set_max_grants(xendev->gnttabdev,
+    if (xengnttab_set_max_grants(xendev->gnttabdev,
             MAX_GRANTS(max_requests, BLKIF_MAX_SEGMENTS_PER_REQUEST)) < 0) {
-        xen_be_printf(xendev, 0, "xc_gnttab_set_max_grants failed: %s\n",
+        xen_be_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n",
                       strerror(errno));
     }
 }
@@ -987,7 +989,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);
@@ -1052,7 +1054,7 @@ static void blk_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&blkdev->xendev);
 
     if (blkdev->sring) {
-        xc_gnttab_munmap(blkdev->xendev.gnttabdev, blkdev->sring, 1);
+        xengnttab_unmap(blkdev->xendev.gnttabdev, blkdev->sring, 1);
         blkdev->cnt_map--;
         blkdev->sring = NULL;
     }
hw/char/xen_console.c +2 -2
index 63ade33..ac1b324 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);
     }
@@ -275,7 +275,7 @@ static void con_disconnect(struct XenDevice *xendev)
         if (!xendev->dev) {
             munmap(con->sring, XC_PAGE_SIZE);
         } else {
-            xc_gnttab_munmap(xendev->gnttabdev, con->sring, 1);
+            xengnttab_unmap(xendev->gnttabdev, con->sring, 1);
         }
         con->sring = NULL;
     }
hw/net/xen_nic.c +9 -9
index 0da16b4..3ffb07d 100644
@@ -168,7 +168,7 @@ static void net_tx_packets(struct XenNetDev *netdev)
                           (txreq.flags & NETTXF_more_data)      ? " more_data"      : "",
                           (txreq.flags & NETTXF_extra_info)     ? " extra_info"     : "");
 
-            page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+            page = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                            netdev->xendev.dom,
                                            txreq.gref, PROT_READ);
             if (page == NULL) {
@@ -190,7 +190,7 @@ static void net_tx_packets(struct XenNetDev *netdev)
                 qemu_send_packet(qemu_get_queue(netdev->nic),
                                  page + txreq.offset, txreq.size);
             }
-            xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
+            xengnttab_unmap(netdev->xendev.gnttabdev, page, 1);
             net_tx_response(netdev, &txreq, NETIF_RSP_OKAY);
         }
         if (!netdev->tx_work) {
@@ -260,7 +260,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t 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) {
@@ -270,7 +270,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_unmap(netdev->xendev.gnttabdev, page, 1);
     net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0);
 
     return size;
@@ -342,19 +342,19 @@ static int net_connect(struct XenDevice *xendev)
         return -1;
     }
 
-    netdev->txs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->txs = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->tx_ring_ref,
                                           PROT_READ | PROT_WRITE);
     if (!netdev->txs) {
         return -1;
     }
-    netdev->rxs = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,
+    netdev->rxs = xengnttab_map_grant_ref(netdev->xendev.gnttabdev,
                                           netdev->xendev.dom,
                                           netdev->rx_ring_ref,
                                           PROT_READ | PROT_WRITE);
     if (!netdev->rxs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->txs, 1);
+        xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1);
         netdev->txs = NULL;
         return -1;
     }
@@ -379,11 +379,11 @@ static void net_disconnect(struct XenDevice *xendev)
     xen_be_unbind_evtchn(&netdev->xendev);
 
     if (netdev->txs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->txs, 1);
+        xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1);
         netdev->txs = NULL;
     }
     if (netdev->rxs) {
-        xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
+        xengnttab_unmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
         netdev->rxs = NULL;
     }
 }
hw/xen/xen_backend.c +5 -5
index ae2a1f0..966e34f 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 +32 -10

68 lines not on this page · raw message

Signature · 1 line
2.1.4
#51 lore raw

PATCH v7 4/8 xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages

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_{pages,bulk}.

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

* Pass &mfn (an array of length 1) instead of mfn. The function takes a pointer to const, so there is no possibily of mfn changing due to this change.
* Pass nr_pages=1 instead of size=XC_PAGE_SIZE

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

In xenfb.c:common_bind we now explicitly launder the mfn into a xen_pfn_t, so it has the correct type to be passed to xc_map_foreign_pages and doesn't provoke warnings on 32-bit x86.

---
v7: Correct type mismatch (int64 vs xen_pfn_t) on 32 bit x86 in
xenfb.c, by explicitly laundering via a xen_pfn_t variable.

v6: Switch to xc_map_foreign_pages rather than _bulk. Switching to
_bulk without checking the value of err[0] risked missing errors. The new xenforeignmemory_map coming later in this series will DTRT with err==NULL.

Dropped Stefano's Reviewed-by due to this change.

v4: Ran checkpatch, fixed all errors
Mention the const-ness of the mfn array in the commit log

fixup!xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages

---
 hw/char/xen_console.c |  8 ++++----
 hw/display/xenfb.c    | 15 ++++++++-------
 xen-hvm.c             | 14 +++++++-------
 3 files changed, 19 insertions(+), 18 deletions(-)
hw/char/xen_console.c +4 -4
index ac1b324..3e8a57b 100644
@@ -228,10 +228,10 @@ static int con_initialise(struct XenDevice *xendev)
 	con->buffer.max_capacity = limit;
 
     if (!xendev->dev) {
-        con->sring = xc_map_foreign_range(xen_xc, con->xendev.dom,
-                                          XC_PAGE_SIZE,
-                                          PROT_READ|PROT_WRITE,
-                                          con->ring_ref);
+        xen_pfn_t mfn = con->ring_ref;
+        con->sring = xc_map_foreign_pages(xen_xc, con->xendev.dom,
+                                         PROT_READ|PROT_WRITE,
+                                         &mfn, 1);
     } else {
         con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
                                              con->ring_ref,
hw/display/xenfb.c +8 -7
index 5e324ef..4a597d7 100644
@@ -95,23 +95,24 @@ struct XenFB {
 
 static int common_bind(struct common *c)
 {
-    uint64_t mfn;
+    uint64_t val;
+    xen_pfn_t mfn;
 
-    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
+    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &val) == -1)
 	return -1;
-    assert(mfn == (xen_pfn_t)mfn);
+    mfn = (xen_pfn_t)val;
+    assert(val == mfn);
 
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    c->page = xc_map_foreign_pages(xen_xc, c->xendev.dom,
+                                   PROT_READ | PROT_WRITE, &mfn, 1);
     if (c->page == NULL)
 	return -1;
 
     xen_be_bind_evtchn(&c->xendev);
-    xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d, local-port %d\n",
+    xen_be_printf(&c->xendev, 1, "ring mfn %"PRI_xen_pfn", remote-port %d, local-port %d\n",
 		  mfn, c->xendev.remote_port, c->xendev.local_port);
 
     return 0;
xen-hvm.c +7 -7
index 6680782..2f4e109 100644
@@ -1240,8 +1240,9 @@ int xen_hvm_init(PCMachineState *pcms,
     DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn);
     DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn);
 
-    state->shared_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
-                                              PROT_READ|PROT_WRITE, ioreq_pfn);
+    state->shared_page = xc_map_foreign_pages(xen_xc, xen_domid,
+                                              PROT_READ|PROT_WRITE,
+                                              &ioreq_pfn, 1);
     if (state->shared_page == NULL) {
         hw_error("map shared IO page returned error %d handle=" XC_INTERFACE_FMT,
                  errno, xen_xc);
@@ -1251,8 +1252,8 @@ int xen_hvm_init(PCMachineState *pcms,
     if (!rc) {
         DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn);
         state->shared_vmport_page =
-            xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
-                                 PROT_READ|PROT_WRITE, ioreq_pfn);
+            xc_map_foreign_pages(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
+                                 &ioreq_pfn, 1);
         if (state->shared_vmport_page == NULL) {
             hw_error("map shared vmport IO page returned error %d handle="
                      XC_INTERFACE_FMT, errno, xen_xc);
@@ -1261,10 +1262,9 @@ int xen_hvm_init(PCMachineState *pcms,
         hw_error("get vmport regs pfn returned error %d, rc=%d", errno, rc);
     }
 
-    state->buffered_io_page = xc_map_foreign_range(xen_xc, xen_domid,
-                                                   XC_PAGE_SIZE,
+    state->buffered_io_page = xc_map_foreign_pages(xen_xc, xen_domid,
                                                    PROT_READ|PROT_WRITE,
-                                                   bufioreq_pfn);
+                                                   &bufioreq_pfn, 1);
     if (state->buffered_io_page == NULL) {
         hw_error("map buffered IO page returned error %d", errno);
     }
Signature · 1 line
2.1.4
#52 lore raw

PATCH v7 4/8 xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages

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_{pages,bulk}.

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

* Pass &mfn (an array of length 1) instead of mfn. The function takes a pointer to const, so there is no possibily of mfn changing due to this change.
* Pass nr_pages=1 instead of size=XC_PAGE_SIZE

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

In xenfb.c:common_bind we now explicitly launder the mfn into a xen_pfn_t, so it has the correct type to be passed to xc_map_foreign_pages and doesn't provoke warnings on 32-bit x86.

---
v7: Correct type mismatch (int64 vs xen_pfn_t) on 32 bit x86 in
xenfb.c, by explicitly laundering via a xen_pfn_t variable.

v6: Switch to xc_map_foreign_pages rather than _bulk. Switching to
_bulk without checking the value of err[0] risked missing errors. The new xenforeignmemory_map coming later in this series will DTRT with err==NULL.

Dropped Stefano's Reviewed-by due to this change.

v4: Ran checkpatch, fixed all errors
Mention the const-ness of the mfn array in the commit log

fixup!xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages

---
 hw/char/xen_console.c |  8 ++++----
 hw/display/xenfb.c    | 15 ++++++++-------
 xen-hvm.c             | 14 +++++++-------
 3 files changed, 19 insertions(+), 18 deletions(-)
hw/char/xen_console.c +4 -4
index ac1b324..3e8a57b 100644
@@ -228,10 +228,10 @@ static int con_initialise(struct XenDevice *xendev)
 	con->buffer.max_capacity = limit;
 
     if (!xendev->dev) {
-        con->sring = xc_map_foreign_range(xen_xc, con->xendev.dom,
-                                          XC_PAGE_SIZE,
-                                          PROT_READ|PROT_WRITE,
-                                          con->ring_ref);
+        xen_pfn_t mfn = con->ring_ref;
+        con->sring = xc_map_foreign_pages(xen_xc, con->xendev.dom,
+                                         PROT_READ|PROT_WRITE,
+                                         &mfn, 1);
     } else {
         con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
                                              con->ring_ref,
hw/display/xenfb.c +8 -7
index 5e324ef..4a597d7 100644
@@ -95,23 +95,24 @@ struct XenFB {
 
 static int common_bind(struct common *c)
 {
-    uint64_t mfn;
+    uint64_t val;
+    xen_pfn_t mfn;
 
-    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
+    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &val) == -1)
 	return -1;
-    assert(mfn == (xen_pfn_t)mfn);
+    mfn = (xen_pfn_t)val;
+    assert(val == mfn);
 
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    c->page = xc_map_foreign_pages(xen_xc, c->xendev.dom,
+                                   PROT_READ | PROT_WRITE, &mfn, 1);
     if (c->page == NULL)
 	return -1;
 
     xen_be_bind_evtchn(&c->xendev);
-    xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d, local-port %d\n",
+    xen_be_printf(&c->xendev, 1, "ring mfn %"PRI_xen_pfn", remote-port %d, local-port %d\n",
 		  mfn, c->xendev.remote_port, c->xendev.local_port);
 
     return 0;
xen-hvm.c +7 -7
index 6680782..2f4e109 100644
@@ -1240,8 +1240,9 @@ int xen_hvm_init(PCMachineState *pcms,
     DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn);
     DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn);
 
-    state->shared_page = xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
-                                              PROT_READ|PROT_WRITE, ioreq_pfn);
+    state->shared_page = xc_map_foreign_pages(xen_xc, xen_domid,
+                                              PROT_READ|PROT_WRITE,
+                                              &ioreq_pfn, 1);
     if (state->shared_page == NULL) {
         hw_error("map shared IO page returned error %d handle=" XC_INTERFACE_FMT,
                  errno, xen_xc);
@@ -1251,8 +1252,8 @@ int xen_hvm_init(PCMachineState *pcms,
     if (!rc) {
         DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn);
         state->shared_vmport_page =
-            xc_map_foreign_range(xen_xc, xen_domid, XC_PAGE_SIZE,
-                                 PROT_READ|PROT_WRITE, ioreq_pfn);
+            xc_map_foreign_pages(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
+                                 &ioreq_pfn, 1);
         if (state->shared_vmport_page == NULL) {
             hw_error("map shared vmport IO page returned error %d handle="
                      XC_INTERFACE_FMT, errno, xen_xc);
@@ -1261,10 +1262,9 @@ int xen_hvm_init(PCMachineState *pcms,
         hw_error("get vmport regs pfn returned error %d, rc=%d", errno, rc);
     }
 
-    state->buffered_io_page = xc_map_foreign_range(xen_xc, xen_domid,
-                                                   XC_PAGE_SIZE,
+    state->buffered_io_page = xc_map_foreign_pages(xen_xc, xen_domid,
                                                    PROT_READ|PROT_WRITE,
-                                                   bufioreq_pfn);
+                                                   &bufioreq_pfn, 1);
     if (state->buffered_io_page == NULL) {
         hw_error("map buffered IO page returned error %d", errno);
     }
Signature · 1 line
2.1.4
#53 lore raw

PATCH v7 5/8 xen: Switch uses of xc_map_foreign_{pages, 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_{pages,bulk}.

The new xenforeignmemory_map() function behaves like xc_map_foreign_pages() when the err argument is NULL and like xc_map_foreign_bulk() when err is non-NULL, which maps into the shim here onto checking err == NULL and calling the appropriate old function.

Note that xenforeignmemory_map() takes the number of pages before the arrays themselves, in order to support potentially future use of variable-length-arrays in the prototype (in the future, when Xen's baseline toolchain requirements are new enough to ensure VLAs are supported).

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

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

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

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

---
v7: Move two copies of compat xenforeignmemory_map to a common location.
Note that the existing xen_domain_create #ifdef will be covered by a CONFIG_XEN_PV_DOMAIN_BUILD in a later patch, and so is not a suitable place to put this function.
v6: Handle _pages as well as _bulk, due to changes in the previous
patches, including the dropping of "xen: Switch uses of xc_map_foreign_pages into xc_map_foreign_bulk" which previous preceded this patch and the change of "xen: Switch uses of xc_map_foreign_range into xc_map_foreign_bulk" into "xen: Switch uses of xc_map_foreign_range into xc_map_foreign_pages".

Handle reordering of arguments to xenforeignmemory_map().

Dropped Stefano's Reviewed-by due to these changes.

v4: Rebase onto "xen_console: correctly cleanup primary console on
teardown."

xenforeignmemory_unmap takes pages not bytes

Compat wrapper for xenforeignmemory_open instead of ifdef in code.

Run check patch and fix most issues. I did not fix:

ERROR: do not initialise globals to 0 or NULL
+xenforeignmemory_handle *xen_fmem = NULL;

=> This is consistent with all of the existing declarations.

ERROR: need consistent spacing around '*' (ctx:WxV) +typedef xc_interface *xenforeignmemory_handle;

=> I think this is a false +ve since this is a pointer "*" not a multiple "*".

reorder args to xenforeignmemory_map

---
 hw/char/xen_console.c        |  8 ++++----
 hw/display/xenfb.c           | 17 +++++++++--------
 hw/xen/xen_backend.c         |  3 ++-
 include/hw/xen/xen_backend.h |  1 +
 include/hw/xen/xen_common.h  | 23 +++++++++++++++++++++++
 xen-common.c                 |  6 ++++++
 xen-hvm.c                    | 12 ++++++------
 xen-mapcache.c               |  6 +++---
 8 files changed, 54 insertions(+), 22 deletions(-)
hw/char/xen_console.c +4 -4
index 3e8a57b..b92d0c6 100644
@@ -229,9 +229,9 @@ static int con_initialise(struct XenDevice *xendev)
 
     if (!xendev->dev) {
         xen_pfn_t mfn = con->ring_ref;
-        con->sring = xc_map_foreign_pages(xen_xc, con->xendev.dom,
-                                         PROT_READ|PROT_WRITE,
-                                         &mfn, 1);
+        con->sring = xenforeignmemory_map(xen_fmem, con->xendev.dom,
+                                          PROT_READ|PROT_WRITE,
+                                          1, &mfn, NULL);
     } else {
         con->sring = xengnttab_map_grant_ref(xendev->gnttabdev, con->xendev.dom,
                                              con->ring_ref,
@@ -273,7 +273,7 @@ static void con_disconnect(struct XenDevice *xendev)
 
     if (con->sring) {
         if (!xendev->dev) {
-            munmap(con->sring, XC_PAGE_SIZE);
+            xenforeignmemory_unmap(xen_fmem, con->sring, 1);
         } else {
             xengnttab_unmap(xendev->gnttabdev, con->sring, 1);
         }
hw/display/xenfb.c +9 -8
index 4a597d7..55258b8 100644
@@ -106,8 +106,8 @@ static int common_bind(struct common *c)
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_pages(xen_xc, c->xendev.dom,
-                                   PROT_READ | PROT_WRITE, &mfn, 1);
+    c->page = xenforeignmemory_map(xen_fmem, c->xendev.dom,
+                                   PROT_READ | PROT_WRITE, 1, &mfn, NULL);
     if (c->page == NULL)
 	return -1;
 
@@ -122,7 +122,7 @@ static void common_unbind(struct common *c)
 {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        xenforeignmemory_unmap(xen_fmem, c->page, 1);
 	c->page = NULL;
     }
 }
@@ -495,15 +495,15 @@ static int xenfb_map_fb(struct XenFB *xenfb)
     fbmfns = g_malloc0(sizeof(xen_pfn_t) * xenfb->fbpages);
 
     xenfb_copy_mfns(mode, n_fbdirs, pgmfns, pd);
-    map = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
-			       PROT_READ, pgmfns, n_fbdirs);
+    map = xenforeignmemory_map(xen_fmem, xenfb->c.xendev.dom,
+                               PROT_READ, n_fbdirs, pgmfns, NULL);
     if (map == NULL)
 	goto out;
     xenfb_copy_mfns(mode, xenfb->fbpages, fbmfns, map);
-    munmap(map, n_fbdirs * XC_PAGE_SIZE);
+    xenforeignmemory_unmap(xen_fmem, map, n_fbdirs);
 
-    xenfb->pixels = xc_map_foreign_pages(xen_xc, xenfb->c.xendev.dom,
-            PROT_READ, fbmfns, xenfb->fbpages);
+    xenfb->pixels = xenforeignmemory_map(xen_fmem, xenfb->c.xendev.dom,
+            PROT_READ, xenfb->fbpages, fbmfns, NULL);
     if (xenfb->pixels == NULL)
 	goto out;
 
@@ -910,6 +910,7 @@ static void fb_disconnect(struct XenDevice *xendev)
      *   Replacing the framebuffer with anonymous shared memory
      *   instead.  This releases the guest pages and keeps qemu happy.
      */
+    xenforeignmemory_unmap(xen_fmem, fb->pixels, fb->fbpages);
     fb->pixels = mmap(fb->pixels, fb->fbpages * XC_PAGE_SIZE,
                       PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON,
                       -1, 0);
hw/xen/xen_backend.c +2 -1
index 966e34f..caa459c 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;
 
@@ -717,7 +718,7 @@ int xen_be_init(void)
 
     qemu_set_fd_handler(xs_fileno(xenstore), xenstore_update, NULL, NULL);
 
-    if (xen_xc == XC_HANDLER_INITIAL_VALUE) {
+    if (xen_xc == XC_HANDLER_INITIAL_VALUE || xen_fmem == NULL) {
         /* Check if xen_init() have been called */
         goto err;
     }
include/hw/xen/xen_backend.h +1 -0
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 +23 -0
index 8f38310..55809b4 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
@@ -104,6 +105,10 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open();
 }
 
+#define xenforeignmemory_open(l, f) &xen_xc
+/* See below for xenforeignmemory_map */
+#define xenforeignmemory_unmap(h, p, s) munmap(p, s * XC_PAGE_SIZE)
+
 static inline int xc_fd(int xen_xc)
 {
     return xen_xc;
@@ -149,6 +154,7 @@ static inline void xs_close(struct xs_handle *xsh)
 #else
 
 typedef xc_interface *XenXC;
+typedef xc_interface *xenforeignmemory_handle;
 typedef xc_evtchn xenevtchn_handle;
 typedef xc_gnttab xengnttab_handle;
 
@@ -178,6 +184,10 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open(logger, dombuild_logger, open_flags);
 }
 
+#define xenforeignmemory_open(l, f) &xen_xc
+/* See below for xenforeignmemory_map */
+#define xenforeignmemory_unmap(h, p, s) munmap(p, s * XC_PAGE_SIZE)
+
 /* FIXME There is now way to have the xen fd */
 static inline int xc_fd(xc_interface *xen_xc)
 {
@@ -501,4 +511,17 @@ static inline int xen_domain_create(XenXC xc, uint32_t ssidref,
 }
 #endif
 
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 470
+static inline void *xenforeignmemory_map(XenXC *h, uint32_t dom,
+                                         int prot, size_t pages,
+                                         const xen_pfn_t arr[/*pages*/],
+                                         int err[/*pages*/])
+{
+    if (err)
+        return xc_map_foreign_bulk(*h, dom, prot, arr, err, pages);
+    else
+        return xc_map_foreign_pages(*h, dom, prot, arr, pages);
+}
+#endif
+
 #endif /* QEMU_HW_XEN_COMMON_H */
xen-common.c +6 -0
index 0dcdbc3..6cd2959 100644
@@ -118,6 +118,12 @@ static int xen_init(MachineState *ms)
         xen_be_printf(NULL, 0, "can't open xen interface\n");
         return -1;
     }
+    xen_fmem = xenforeignmemory_open(0, 0);
+    if (xen_fmem == NULL) {
+        xen_be_printf(NULL, 0, "can't open xen fmem interface\n");
+        xc_interface_close(xen_xc);
+        return -1;
+    }
     qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
 
     global_state_set_optional();
xen-hvm.c +6 -6
index 2f4e109..c64f4b0 100644
@@ -1240,9 +1240,9 @@ int xen_hvm_init(PCMachineState *pcms,
     DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn);
     DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn);
 
-    state->shared_page = xc_map_foreign_pages(xen_xc, xen_domid,
+    state->shared_page = xenforeignmemory_map(xen_fmem, xen_domid,
                                               PROT_READ|PROT_WRITE,
-                                              &ioreq_pfn, 1);
+                                              1, &ioreq_pfn, NULL);
     if (state->shared_page == NULL) {
         hw_error("map shared IO page returned error %d handle=" XC_INTERFACE_FMT,
                  errno, xen_xc);
@@ -1252,8 +1252,8 @@ int xen_hvm_init(PCMachineState *pcms,
     if (!rc) {
         DPRINTF("shared vmport page at pfn %lx\n", ioreq_pfn);
         state->shared_vmport_page =
-            xc_map_foreign_pages(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
-                                 &ioreq_pfn, 1);
+            xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE,
+                                 1, &ioreq_pfn, NULL);
         if (state->shared_vmport_page == NULL) {
             hw_error("map shared vmport IO page returned error %d handle="
                      XC_INTERFACE_FMT, errno, xen_xc);
@@ -1262,9 +1262,9 @@ int xen_hvm_init(PCMachineState *pcms,
         hw_error("get vmport regs pfn returned error %d, rc=%d", errno, rc);
     }
 
-    state->buffered_io_page = xc_map_foreign_pages(xen_xc, xen_domid,
+    state->buffered_io_page = xenforeignmemory_map(xen_fmem, xen_domid,
                                                    PROT_READ|PROT_WRITE,
-                                                   &bufioreq_pfn, 1);
+                                                   1, &bufioreq_pfn, NULL);
     if (state->buffered_io_page == NULL) {
         hw_error("map buffered IO page returned error %d", errno);
     }
xen-mapcache.c +3 -3
index 97fece2..4a04378 100644
@@ -176,10 +176,10 @@ static void xen_remap_bucket(MapCacheEntry *entry,
         pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i;
     }
 
-    vaddr_base = xc_map_foreign_bulk(xen_xc, xen_domid, PROT_READ|PROT_WRITE,
-                                     pfns, err, nb_pfn);
+    vaddr_base = xenforeignmemory_map(xen_fmem, xen_domid, PROT_READ|PROT_WRITE,
+                                      nb_pfn, pfns, err);
     if (vaddr_base == NULL) {
-        perror("xc_map_foreign_bulk");
+        perror("xenforeignmemory_map");
         exit(-1);
     }
 
Signature · 1 line
2.1.4
#54 lore raw

Re: [PATCH QEMU-XEN v7 5/8] xen: Switch uses of xc_map_foreign_{pages, bulk} to use libxenforeignmemory API.

Quoted 83 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_{pages,bulk}.

The new xenforeignmemory_map() function behaves like xc_map_foreign_pages() when the err argument is NULL and like xc_map_foreign_bulk() when err is non-NULL, which maps into the shim here onto checking err == NULL and calling the appropriate old function.

Note that xenforeignmemory_map() takes the number of pages before the arrays themselves, in order to support potentially future use of variable-length-arrays in the prototype (in the future, when Xen's baseline toolchain requirements are new enough to ensure VLAs are supported).

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

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

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

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

include/hw/xen/xen_common.h +6 -0
index 8f38310..55809b4 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
@@ -104,6 +105,10 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open();
 }
 
+#define xenforeignmemory_open(l, f) &xen_xc
+/* See below for xenforeignmemory_map */
+#define xenforeignmemory_unmap(h, p, s) munmap(p, s * XC_PAGE_SIZE)
+
 static inline int xc_fd(int xen_xc)
 {
     return xen_xc;
@@ -149,6 +154,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;
 

include/hw/xen/xen_common.h static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger, · line 193

Quoted 10 lines
include/hw/xen/xen_common.h +4 -0
@@ -178,6 +184,10 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open(logger, dombuild_logger, open_flags);
 }
 
+#define xenforeignmemory_open(l, f) &xen_xc
+/* See below for xenforeignmemory_map */
+#define xenforeignmemory_unmap(h, p, s) munmap(p, s * XC_PAGE_SIZE)
+
 /* FIXME There is now way to have the xen fd */
 static inline int xc_fd(xc_interface *xen_xc)
 {

@@ -501,4 +511,17 @@ static inline int xen_domain_create(XenXC xc, uint32_t ssidref,

Quoted 5 lines

}
#endif

include/hw/xen/xen_common.h +2 -0
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 470
+static inline void *xenforeignmemory_map(XenXC *h, uint32_t dom,

include/hw/xen/xen_common.h static inline int xen_domain_create(XenXC xc, uint32_t ssidref, · line 525

Quoted 10 lines
include/hw/xen/xen_common.h +10 -0
+                                         int prot, size_t pages,
+                                         const xen_pfn_t arr[/*pages*/],
+                                         int err[/*pages*/])
+{
+    if (err)
+        return xc_map_foreign_bulk(*h, dom, prot, arr, err, pages);
+    else
+        return xc_map_foreign_pages(*h, dom, prot, arr, pages);
+}
+#endif

Why not move the definition of xenforeignmemory_open and xenforeignmemory_unmap here too?

#55 lore raw

Re: [Qemu-devel] [PATCH QEMU-XEN v7 5/8] xen: Switch uses of xc_map_foreign_{pages, bulk} to use libxenforeignmemory API.

In reply to Ian Campbell
Quoted 83 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_{pages,bulk}.

The new xenforeignmemory_map() function behaves like xc_map_foreign_pages() when the err argument is NULL and like xc_map_foreign_bulk() when err is non-NULL, which maps into the shim here onto checking err == NULL and calling the appropriate old function.

Note that xenforeignmemory_map() takes the number of pages before the arrays themselves, in order to support potentially future use of variable-length-arrays in the prototype (in the future, when Xen's baseline toolchain requirements are new enough to ensure VLAs are supported).

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

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

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

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

include/hw/xen/xen_common.h +6 -0
index 8f38310..55809b4 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
@@ -104,6 +105,10 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open();
 }
 
+#define xenforeignmemory_open(l, f) &xen_xc
+/* See below for xenforeignmemory_map */
+#define xenforeignmemory_unmap(h, p, s) munmap(p, s * XC_PAGE_SIZE)
+
 static inline int xc_fd(int xen_xc)
 {
     return xen_xc;
@@ -149,6 +154,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;
 

include/hw/xen/xen_common.h static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger, · line 193

Quoted 10 lines
include/hw/xen/xen_common.h +4 -0
@@ -178,6 +184,10 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
     return xc_interface_open(logger, dombuild_logger, open_flags);
 }
 
+#define xenforeignmemory_open(l, f) &xen_xc
+/* See below for xenforeignmemory_map */
+#define xenforeignmemory_unmap(h, p, s) munmap(p, s * XC_PAGE_SIZE)
+
 /* FIXME There is now way to have the xen fd */
 static inline int xc_fd(xc_interface *xen_xc)
 {

@@ -501,4 +511,17 @@ static inline int xen_domain_create(XenXC xc, uint32_t ssidref,

Quoted 5 lines

}
#endif

include/hw/xen/xen_common.h +2 -0
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 470
+static inline void *xenforeignmemory_map(XenXC *h, uint32_t dom,

include/hw/xen/xen_common.h static inline int xen_domain_create(XenXC xc, uint32_t ssidref, · line 525

Quoted 10 lines
include/hw/xen/xen_common.h +10 -0
+                                         int prot, size_t pages,
+                                         const xen_pfn_t arr[/*pages*/],
+                                         int err[/*pages*/])
+{
+    if (err)
+        return xc_map_foreign_bulk(*h, dom, prot, arr, err, pages);
+    else
+        return xc_map_foreign_pages(*h, dom, prot, arr, pages);
+}
+#endif

Why not move the definition of xenforeignmemory_open and xenforeignmemory_unmap here too?

#56 lore raw

Re: [PATCH QEMU-XEN v7 5/8] xen: Switch uses of xc_map_foreign_{pages, bulk} to use libxenforeignmemory API.

Quoted 3 lines · Stefano Stabellini


Why not move the definition of xenforeignmemory_open and xenforeignmemory_unmap here too?

I failed to spot they were also the same. Will do.

Ian.

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

#57 lore raw

Re: [Qemu-devel] [PATCH QEMU-XEN v7 5/8] xen: Switch uses of xc_map_foreign_{pages, bulk} to use libxenforeignmemory API.

In reply to Stefano Stabellini
Quoted 3 lines · Stefano Stabellini


Why not move the definition of xenforeignmemory_open and xenforeignmemory_unmap here too?

I failed to spot they were also the same. Will do.

Ian.

#58 lore raw

PATCH v7 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.6 (inclusive) and the patches targetting 4.7 which adds these libraries.

---
v6: Two minor formatting things.
Rebase onto "xen: fix usage of xc_domain_create in domain builder", required adjusting the configure script changes.

The rebase wasn't entirely trivial (semantically), so dropped Stefano's reviwed by.

v5: Remove ifdef check when undeffing the compat stuff.
s/now way/no way/

v4: xenforeignmemory_open is now a compat wrapper, so no ifdef.

Simplify configury by asserting that interface version 470 will always have the libraries (lack of them makes it 460).

Ran checkpatch and fixed everything except:

ERROR: need consistent spacing around '*' (ctx:WxV) +typedef xc_interface *XenXC;

Which I think is a false +ve.

Simpler configure stuff

---
 configure                   | 42 +++++++++++++++++++++++++++++++++++++++++-
 include/hw/xen/xen_common.h | 35 +++++++++++++++++++++++++++++++++--
 2 files changed, 74 insertions(+), 3 deletions(-)
configure +41 -1
index b9552fd..162aa16 100755
@@ -1938,6 +1938,7 @@ fi
 
 if test "$xen" != "no" ; then
   xen_libs="-lxenstore -lxenctrl -lxenguest"
+  xen_stable_libs="-lxenforeignmemory -lxengnttab -lxenevtchn"
 
   # First we test whether Xen headers and libraries are available.
   # If no, we are done and there is no Xen support.
@@ -1960,16 +1961,52 @@ EOF
   # Xen unstable
   elif
       cat > $TMPC <<EOF &&
+/*
+ * If we have stable libs the we don't want the libxc compat
+ * layers, regardless of what CFLAGS we may have been given.
+ */
+#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 <xenevtchn.h>
+#include <xengnttab.h>
+#include <xenforeignmemory.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 = NULL;
+  xenforeignmemory_handle *xfmem;
+  xenevtchn_handle *xe;
+  xengnttab_handle *xg;
   xen_domain_handle_t handle;
+
+  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);
   xc_domain_create(xc, 0, handle, 0, NULL, NULL);
+
+  xfmem = xenforeignmemory_open(0, 0);
+  xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0);
+
+  xe = xenevtchn_open(0, 0);
+  xenevtchn_fd(xe);
+
+  xg = xengnttab_open(0, 0);
+  xengnttab_map_grant_ref(xg, 0, 0, 0);
+
   return 0;
 }
 EOF
-      compile_prog "" "$xen_libs"
+      compile_prog "" "$xen_libs $xen_stable_libs"
     then
     xen_ctrl_version=470
     xen=yes
@@ -2153,6 +2190,9 @@ EOF
   fi
 
   if test "$xen" = yes; then
+    if test $xen_ctrl_version -ge 470  ; then
+      libs_softmmu="$xen_stable_libs $libs_softmmu"
+    fi
     libs_softmmu="$xen_libs $libs_softmmu"
   fi
 fi
include/hw/xen/xen_common.h +33 -2
index 55809b4..310d6ef 100644
@@ -6,6 +6,15 @@
 #include <stddef.h>
 #include <inttypes.h>
 
+/*
+ * 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
+
 #include <xenctrl.h>
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 420
 #  include <xs.h>
@@ -150,8 +159,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;
@@ -188,6 +197,28 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
 /* See below for xenforeignmemory_map */
 #define xenforeignmemory_unmap(h, p, s) munmap(p, s * XC_PAGE_SIZE)
 
+/* FIXME There is no way to have the xen fd */
+static inline int xc_fd(xc_interface *xen_xc)
+{
+    return -1;
+}
+#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 470 */
+
+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)
 {
Signature · 1 line
2.1.4
#59 lore raw

PATCH v7 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 ac0e5ac..f9be029 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 310d6ef..8c4fc42 100644
@@ -118,12 +118,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
 /* See below for xenforeignmemory_map */
 #define xenforeignmemory_unmap(h, p, s) munmap(p, s * XC_PAGE_SIZE)
 
-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)
@@ -197,11 +191,6 @@ static inline XenXC xen_xc_interface_open(void *logger, void *dombuild_logger,
 /* See below for xenforeignmemory_map */
 #define xenforeignmemory_unmap(h, p, s) munmap(p, s * XC_PAGE_SIZE)
 
-/* FIXME There is no way to have the xen fd */
-static inline int xc_fd(xc_interface *xen_xc)
-{
-    return -1;
-}
 #else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 470 */
 
 typedef xc_interface *XenXC;
@@ -218,12 +207,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
#60 lore raw

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

Given this wasn't working since Xen 4.0 I have marked this as disabled by default.

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.

---
v6: Rebase onto "xen: fix usage of xc_domain_create in domain
builder" (trivial, Reviewed-by retained)

v5: XEN_CREATE entirely wihtin CONFIG_XEN_PV_DOMAIN_BUILD ifdef.
Simplify configure'ry.

v4: Fixed all checkpatch errors.
Disabled by default.

---
 configure                   | 15 +++++++++++++++
 hw/xenpv/Makefile.objs      |  4 +++-
 hw/xenpv/xen_machine_pv.c   | 15 +++++++++++----
 include/hw/xen/xen_common.h |  2 ++
 4 files changed, 31 insertions(+), 5 deletions(-)
configure +15 -0
index 162aa16..0d157e7 100755
@@ -250,6 +250,7 @@ vnc_jpeg=""
 vnc_png=""
 xen=""
 xen_ctrl_version=""
+xen_pv_domain_build="no"
 xen_pci_passthrough=""
 linux_aio=""
 cap_ng=""
@@ -927,6 +928,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"
@@ -2214,6 +2219,12 @@ if test "$xen_pci_passthrough" != "no"; then
   fi
 fi
 
+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
+
 ##########################################
 # libtool probe
 
@@ -4821,6 +4832,7 @@ fi
 echo "xen support       $xen"
 if test "$xen" = "yes" ; then
   echo "xen ctrl version  $xen_ctrl_version"
+  echo "pv dom build      $xen_pv_domain_build"
 fi
 echo "brlapi support    $brlapi"
 echo "bluez  support    $bluez"
@@ -5189,6 +5201,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 "$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 +11 -4
index 23d6ef0..3250b94 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,17 +43,27 @@ static void xen_init_pv(MachineState *machine)
     case XEN_ATTACH:
         /* nothing to do, xend handles everything */
         break;
-    case XEN_CREATE:
+#ifdef CONFIG_XEN_PV_DOMAIN_BUILD
+    case XEN_CREATE: {
+        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);
         }
         break;
+    }
+#endif
     case XEN_EMULATE:
         fprintf(stderr, "xen emulation not implemented (yet)\n");
         exit(1);
         break;
+    default:
+        fprintf(stderr, "unhandled xen_mode %d\n", xen_mode);
+        exit(1);
+        break;
     }
 
     xen_be_register("console", &xen_console_ops);
include/hw/xen/xen_common.h +2 -0
index 8c4fc42..0d19816 100644
@@ -509,6 +509,7 @@ static inline int xen_xc_domain_add_to_physmap(XenXC xch, uint32_t domid,
 }
 #endif
 
+#ifdef CONFIG_XEN_PV_DOMAIN_BUILD
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 470
 static inline int xen_domain_create(XenXC xc, uint32_t ssidref,
                                     xen_domain_handle_t handle, uint32_t flags,
@@ -524,6 +525,7 @@ static inline int xen_domain_create(XenXC xc, uint32_t ssidref,
     return xc_domain_create(xc, ssidref, handle, flags, pdomid, NULL);
 }
 #endif
+#endif
 
 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 470
 static inline void *xenforeignmemory_map(XenXC *h, uint32_t dom,
Signature · 1 line
2.1.4
#61 lore raw

v7 cover Begin to disentangle libxenctrl and provide some stable libraries

In reply to Ian Campbell

We intend to stabilise some parts of the libxenctrl interface by splitting out some functionality into separate stable libraries.

This is the qemu-xen-traditional part of the first phase of that change.

This mail is (or is intended to be) a reply to a "0/<VARIOUS>" super-intro mail covering all of the related patch series and which contains more details.

Ian Campbell (4):
qemu-xen-traditional: Use libxenevtchn
qemu-xen-traditional: Use libxengnttab
qemu-xen-traditional: Add libxencall to rpath-link
qemu-xen-traditional: Add libxenforeignmemory to rpath-link

 hw/xen_backend.c  | 30 +++++++++++++++---------------
 hw/xen_backend.h  |  4 ++--
 hw/xen_common.h   |  2 ++
 hw/xen_console.c  |  4 ++--
 hw/xen_disk.c     | 24 ++++++++++++------------
 i386-dm/helper2.c | 19 ++++++++++---------
 xen-hooks.mak     |  7 +++++++
 7 files changed, 50 insertions(+), 40 deletions(-)
Signature · 1 line
2.1.4
#62 lore raw

PATCH v7 1/4 qemu-xen-traditional: Use libxenevtchn

/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
#63 lore raw

PATCH v7 2/4 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/

v7: s/gnttab_munmap/gnttab_unmap/ to reflect change to the library API.

---
 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..0bb4469 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_unmap(xendev->gnttabdev, con->sring, 1);
 	con->sring = NULL;
     }
 }
hw/xen_disk.c +12 -12
index 250d806..bc78748 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_unmap(gnt, ioreq->pages, ioreq->v.niov) != 0)
+	    xen_be_printf(&ioreq->blkdev->xendev, 0, "xengnttab_unmap 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_unmap(gnt, ioreq->page[i], 1) != 0)
+		xen_be_printf(&ioreq->blkdev->xendev, 0, "xengnttab_unmap failed: %s\n",
 			      strerror(errno));
 	    ioreq->blkdev->cnt_map--;
 	    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_unmap(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
#64 lore raw

PATCH v7 3/4 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
#65 lore raw

PATCH v7 4/4 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
#66 lore raw

v7 cover Begin to disentangle libxenctrl and provide some stable libraries

In reply to Ian Campbell

We intend to stabilise some parts of the libxenctrl interface by splitting out some functionality into separate stable libraries.

This is the mini-os part of the first phase of that change.

This mail is (or is intended to be) a reply to a "0/<VARIOUS>" super-intro mail covering all of the related patch series and which contains more details.

Ian Campbell (4):
mini-os: Include libxenevtchn with libxc
mini-os: Include libxengnttab with libxc
mini-os: Include libxencall with libxc
mini-os: Include libxenforeignmemory with libxc

 Makefile | 4 ++++
 1 file changed, 4 insertions(+)
Signature · 1 line
2.1.4
#67 lore raw

PATCH v7 1/4 mini-os: Include libxenevtchn with libxc

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

PATCH v7 2/4 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
#69 lore raw

PATCH v7 3/4 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
#70 lore raw

PATCH v7 4/4 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