Skip to contentSkip to conversation

tools/libxendevicemodel

PATCH In review Paul Durrant 4 participants 18 messages Feb 22, 2017 – Apr 5, 2017

lore
Share & tools
lore
#0 lore raw

v2 cover tools/libxendevicemodel

Paul Durrant (5):
tools/libxenctrl: fix error check after opening libxenforeignmemory tools/libxendevicemodel: introduce the new library tools/libxendevicemodel: extract functions and add a compat layer tools/libxendevicemodel: introduce a Linux-specific implementation tools/libxendevicemodel: add a call to restrict the handle

 Config.mk                                       |  12 +-
 stubdom/Makefile                                |  17 +-
 tools/Makefile                                  |   2 +
 tools/Rules.mk                                  |  10 +-
 tools/include/xen-sys/Linux/privcmd.h           |  15 +
 tools/libs/Makefile                             |   1 +
 tools/libs/devicemodel/Makefile                 |  72 ++++
 tools/libs/devicemodel/compat.c                 |  54 +++
 tools/libs/devicemodel/core.c                   | 508 ++++++++++++++++++++++++
 tools/libs/devicemodel/include/xendevicemodel.h | 308 ++++++++++++++
 tools/libs/devicemodel/libxendevicemodel.map    |  23 ++
 tools/libs/devicemodel/linux.c                  | 134 +++++++
 tools/libs/devicemodel/private.h                |  48 +++
 tools/libxc/Makefile                            |   4 +-
 tools/libxc/include/xenctrl.h                   | 197 ---------
 tools/libxc/include/xenctrl_compat.h            |  47 +++
 tools/libxc/xc_devicemodel_compat.c             | 139 +++++++
 tools/libxc/xc_domain.c                         | 201 ----------
 tools/libxc/xc_misc.c                           | 154 -------
 tools/libxc/xc_private.c                        |  82 +---
 tools/libxc/xc_private.h                        |   4 +
 21 files changed, 1395 insertions(+), 637 deletions(-)
 create mode 100644 tools/libs/devicemodel/Makefile
 create mode 100644 tools/libs/devicemodel/compat.c
 create mode 100644 tools/libs/devicemodel/core.c
 create mode 100644 tools/libs/devicemodel/include/xendevicemodel.h
 create mode 100644 tools/libs/devicemodel/libxendevicemodel.map
 create mode 100644 tools/libs/devicemodel/linux.c
 create mode 100644 tools/libs/devicemodel/private.h
 create mode 100644 tools/libxc/xc_devicemodel_compat.c
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v2 1/5 tools/libxenctrl: fix error check after opening libxenforeignmemory

Checking the value of xch->xcall is clearly incorrect. The code should be checking xch->fmem (i.e. the return of the previously called function).

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/libxc/xc_private.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/libxc/xc_private.c +1 -2
index f0e089c..9df6925 100644
@@ -64,8 +64,7 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
         goto err;
 
     xch->fmem = xenforeignmemory_open(xch->error_handler, 0);
-
-    if ( xch->xcall == NULL )
+    if ( xch->fmem == NULL )
         goto err;
 
     return xch;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#16 lore raw

PATCH v2 5/5 tools/libxendevicemodel: add a call to restrict the handle

In reply to Paul Durrant

My recent patch [1] to the Linux privcmd module introduced a mechanism to restrict an open file handle to subsequently only accept operations for a specified domain.

This patch extends the libxendevicemodel API and make use of the mechanism in the Linux-specific code to restrict operations on the interface handle.

[1] https://git.kernel.org/cgit/linux/kernel/git/ostr/linux.git/commit/?id=4610d240

---
Cc: Ian Jackson <[email protected]>

---
 tools/include/xen-sys/Linux/privcmd.h           |  2 ++
 tools/libs/devicemodel/compat.c                 |  9 +++++++++
 tools/libs/devicemodel/core.c                   |  5 +++++
 tools/libs/devicemodel/include/xendevicemodel.h | 10 ++++++++++
 tools/libs/devicemodel/libxendevicemodel.map    |  1 +
 tools/libs/devicemodel/linux.c                  | 11 +++++++++++
 tools/libs/devicemodel/private.h                |  3 +++
 7 files changed, 41 insertions(+)
tools/include/xen-sys/Linux/privcmd.h +2 -0
index c80eb5e..732ff7c 100644
@@ -101,5 +101,7 @@ typedef struct privcmd_dm_op {
 	_IOC(_IOC_NONE, 'P', 4, sizeof(privcmd_mmapbatch_v2_t))
 #define IOCTL_PRIVCMD_DM_OP					\
 	_IOC(_IOC_NONE, 'P', 5, sizeof(privcmd_dm_op_t))
+#define IOCTL_PRIVCMD_RESTRICT					\
+	_IOC(_IOC_NONE, 'P', 6, sizeof(domid_t))
 
 #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
tools/libs/devicemodel/compat.c +9 -0
index 245e907..5b4fdae 100644
@@ -15,6 +15,8 @@
  * License along with this library; If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <errno.h>
+
 #include "private.h"
 
 int osdep_xendevicemodel_open(xendevicemodel_handle *dmod)
@@ -34,6 +36,13 @@ int osdep_xendevicemodel_op(xendevicemodel_handle *dmod,
     return xendevicemodel_xcall(dmod, domid, nr_bufs, bufs);
 }
 
+int osdep_xendevicemodel_restrict(xendevicemodel_handle *dmod,
+                                  domid_t domid)
+{
+    errno = EOPNOTSUPP;
+    return -1;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/devicemodel/core.c +5 -0
index 33ee157..504543c 100644
@@ -492,6 +492,11 @@ int xendevicemodel_inject_event(
     return xendevicemodel_op(dmod, domid, 1, &op, sizeof(op));
 }
 
+int xendevicemodel_restrict(xendevicemodel_handle *dmod, domid_t domid)
+{
+    return osdep_xendevicemodel_restrict(dmod, domid);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/devicemodel/include/xendevicemodel.h +10 -0
index e00f8da..b3f600e 100644
@@ -283,6 +283,16 @@ int xendevicemodel_inject_event(
     xendevicemodel_handle *dmod, domid_t domid, int vcpu, uint8_t vector,
     uint8_t type, uint32_t error_code, uint8_t insn_len, uint64_t cr2);
 
+/**
+ * This function restricts the use of this handle to the specified
+ * domain.
+ *
+ * @parm dmod handle to the open devicemodel interface
+ * @parm domid the domain id
+ * @return 0 on success, -1 on failure.
+ */
+int xendevicemodel_restrict(xendevicemodel_handle *dmod, domid_t domid);
+
 #endif /* __XEN_TOOLS__ */
 
 #endif /* XENDEVICEMODEL_H */
tools/libs/devicemodel/libxendevicemodel.map +1 -0
index abc6d06..45c773e 100644
@@ -17,6 +17,7 @@ VERS_1.0 {
 		xendevicemodel_modified_memory;
 		xendevicemodel_set_mem_type;
 		xendevicemodel_inject_event;
+		xendevicemodel_restrict;
 		xendevicemodel_close;
 	local: *; /* Do not expose anything by default */
 };
tools/libs/devicemodel/linux.c +11 -0
index 7511ee7..438c55b 100644
@@ -112,6 +112,17 @@ int osdep_xendevicemodel_op(xendevicemodel_handle *dmod,
     return 0;
 }
 
+int osdep_xendevicemodel_restrict(xendevicemodel_handle *dmod,
+                                  domid_t domid)
+{
+    if (dmod->fd < 0) {
+        errno = EOPNOTSUPP;
+        return -1;
+    }
+
+    return ioctl(dmod->fd, IOCTL_PRIVCMD_RESTRICT, &domid);
+}
+
 /*
  * Local variables:
  * mode: C
tools/libs/devicemodel/private.h +3 -0
index 5ce3b45..4ce5aac 100644
@@ -29,6 +29,9 @@ int osdep_xendevicemodel_op(xendevicemodel_handle *dmod,
                             domid_t domid, unsigned int nr_bufs,
                             struct xendevicemodel_buf bufs[]);
 
+int osdep_xendevicemodel_restrict(
+    xendevicemodel_handle *dmod, domid_t domid);
+
 #define PERROR(_f...) \
     xtl_log(dmod->logger, XTL_ERROR, errno, "xendevicemodel", _f)
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#14 lore raw

PATCH v2 4/5 tools/libxendevicemodel: introduce a Linux-specific implementation

In reply to Paul Durrant

My recent patch [1] to the Linux privcmd module introduced a dedicated mechanism for making dm_op hypercalls.

This patch adds the necessary code to libxendevicemodel to take advantage of that mechanism if it is implemented in the tools domain kernel.

[1] https://git.kernel.org/cgit/linux/kernel/git/ostr/linux.git/commit/?id=ab520be8

---
Cc: Ian Jackson <[email protected]>

---
 tools/include/xen-sys/Linux/privcmd.h |  13 ++++
 tools/libs/devicemodel/Makefile       |   2 +-
 tools/libs/devicemodel/linux.c        | 123 ++++++++++++++++++++++++++++++++++
 tools/libs/devicemodel/private.h      |   4 ++
 4 files changed, 141 insertions(+), 1 deletion(-)
 create mode 100644 tools/libs/devicemodel/linux.c
tools/include/xen-sys/Linux/privcmd.h +13 -0
index e4e666a..c80eb5e 100644
@@ -75,6 +75,17 @@ typedef struct privcmd_mmapbatch_v2 {
 	int __user *err;  /* array of error codes */
 } privcmd_mmapbatch_v2_t;
 
+typedef struct privcmd_dm_op_buf {
+	void __user *uptr;
+	size_t size;
+} privcmd_dm_op_buf_t;
+
+typedef struct privcmd_dm_op {
+	domid_t dom;
+	__u16 num;
+	const privcmd_dm_op_buf_t __user *ubufs;
+} privcmd_dm_op_t;
+
 /*
  * @cmd: IOCTL_PRIVCMD_HYPERCALL
  * @arg: &privcmd_hypercall_t
@@ -88,5 +99,7 @@ typedef struct privcmd_mmapbatch_v2 {
 	_IOC(_IOC_NONE, 'P', 3, sizeof(privcmd_mmapbatch_t))
 #define IOCTL_PRIVCMD_MMAPBATCH_V2				\
 	_IOC(_IOC_NONE, 'P', 4, sizeof(privcmd_mmapbatch_v2_t))
+#define IOCTL_PRIVCMD_DM_OP					\
+	_IOC(_IOC_NONE, 'P', 5, sizeof(privcmd_dm_op_t))
 
 #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
tools/libs/devicemodel/Makefile +1 -1
index b87bf84..1803942 100644
@@ -11,7 +11,7 @@ CFLAGS   += $(CFLAGS_libxentoollog)
 CFLAGS   += $(CFLAGS_libxencall)
 
 SRCS-y                 += core.c
-SRCS-$(CONFIG_Linux)   += compat.c
+SRCS-$(CONFIG_Linux)   += linux.c
 SRCS-$(CONFIG_FreeBSD) += compat.c
 SRCS-$(CONFIG_SunOS)   += compat.c
 SRCS-$(CONFIG_NetBSD)  += compat.c
tools/libs/devicemodel/linux.c new file +123 -0

123 lines not on this page · raw message

tools/libs/devicemodel/private.h +4 -0
index 7c7acf2..5ce3b45 100644
@@ -11,6 +11,7 @@ struct xendevicemodel_handle {
     xentoollog_logger *logger, *logger_tofree;
     unsigned int flags;
     xencall_handle *xcall;
+    int fd;
 };
 
 struct xendevicemodel_buf {
@@ -28,6 +29,9 @@ int osdep_xendevicemodel_op(xendevicemodel_handle *dmod,
                             domid_t domid, unsigned int nr_bufs,
                             struct xendevicemodel_buf bufs[]);
 
+#define PERROR(_f...) \
+    xtl_log(dmod->logger, XTL_ERROR, errno, "xendevicemodel", _f)
+
 #endif
 
 /*
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw

PATCH v2 2/5 tools/libxendevicemodel: introduce the new library

In reply to Paul Durrant

The new xendevicemodel library is intended to be used by all Xen device models such that the only hypercall that use will be the dm_op hypercall added by commit 524a98c2.

This patch adds the boilerplate for the new library, with only open() and close() entry points, and calls to those from libxenctrl in preparation for the compat layer added by a subsequent patch.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

NOTE TO COMMITTERS:

The URLs and tags for qemu-xen-traditional and mini-is in the patch to Config.mk need to be substituted with the correct URLs and tags after the appropriate (recently posted) patches have been committed into the master branches.

v2:
- Added patch to Config.mk

---
 Config.mk                                       | 12 ++---
 stubdom/Makefile                                | 17 ++++++-
 tools/Makefile                                  |  1 +
 tools/Rules.mk                                  | 10 +++-
 tools/libs/Makefile                             |  1 +
 tools/libs/devicemodel/Makefile                 | 66 ++++++++++++++++++++++++
 tools/libs/devicemodel/core.c                   | 68 +++++++++++++++++++++++++
 tools/libs/devicemodel/include/xendevicemodel.h | 40 +++++++++++++++
 tools/libs/devicemodel/libxendevicemodel.map    |  6 +++
 tools/libs/devicemodel/private.h                | 22 ++++++++
 tools/libxc/Makefile                            |  3 +-
 tools/libxc/xc_private.c                        |  8 +++
 tools/libxc/xc_private.h                        |  4 ++
 13 files changed, 247 insertions(+), 11 deletions(-)
 create mode 100644 tools/libs/devicemodel/Makefile
 create mode 100644 tools/libs/devicemodel/core.c
 create mode 100644 tools/libs/devicemodel/include/xendevicemodel.h
 create mode 100644 tools/libs/devicemodel/libxendevicemodel.map
 create mode 100644 tools/libs/devicemodel/private.h
Config.mk +6 -6
index 9a28d15..d6d40cb 100644
@@ -257,19 +257,19 @@ 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_TRADITIONAL_URL ?= http://xenbits.xen.org/git-http/people/pauldu/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/pauldu/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_TRADITIONAL_URL ?= git://xenbits.xen.org/people/pauldu/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/pauldu/mini-os.git
 endif
 OVMF_UPSTREAM_REVISION ?= 5734d486b6aa0b69a39b2c8d52b355400bcf2551
 QEMU_UPSTREAM_REVISION ?= master
-MINIOS_UPSTREAM_REVISION ?= 1e8e464febb32428c7651b0b585866e5ee5f786e
+MINIOS_UPSTREAM_REVISION ?= master
 # Tue Dec 13 15:02:02 2016 +0000
 # build: prepend OBJ_DIR to linker script
 
@@ -280,7 +280,7 @@ SEABIOS_UPSTREAM_REVISION ?= rel-1.10.0
 ETHERBOOT_NICS ?= rtl8139 8086100e
 
 
-QEMU_TRADITIONAL_REVISION ?= b669e922b37b8957248798a5eb7aa96a666cd3fe
+QEMU_TRADITIONAL_REVISION ?= master
 # Mon Nov 14 17:19:46 2016 +0000
 # qemu: ioport_read, ioport_write: be defensive about 32-bit addresses
 
stubdom/Makefile +15 -2
index f858210..39b81c9 100644
@@ -337,13 +337,16 @@ libs-$(XEN_TARGET_ARCH)/call/stamp: $(XEN_ROOT)/tools/libs/call/Makefile
 libs-$(XEN_TARGET_ARCH)/foreignmemory/stamp: $(XEN_ROOT)/tools/libs/foreignmemory/Makefile
 	$(do_links)
 
+libs-$(XEN_TARGET_ARCH)/devicemodel/stamp: $(XEN_ROOT)/tools/libs/devicemodel/Makefile
+	$(do_links)
+
 libxc-$(XEN_TARGET_ARCH)/stamp: $(XEN_ROOT)/tools/libxc/Makefile
 	$(do_links)
 
 xenstore/stamp: $(XEN_ROOT)/tools/xenstore/Makefile
 	$(do_links)
 
-LINK_LIBS_DIRS := toollog evtchn gnttab call foreignmemory
+LINK_LIBS_DIRS := toollog evtchn gnttab call foreignmemory devicemodel
 LINK_DIRS := libxc-$(XEN_TARGET_ARCH) xenstore $(foreach dir,$(LINK_LIBS_DIRS),libs-$(XEN_TARGET_ARCH)/$(dir))
 LINK_STAMPS := $(foreach dir,$(LINK_DIRS),$(dir)/stamp)
 
@@ -414,12 +417,21 @@ libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: mk-headers-$(XEN_TA
 	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory
 
 #######
+# libxendevicemodel
+#######
+
+.PHONY: libxendevicemodel
+libxendevicemodel: libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a
+libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
+	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/devicemodel
+
+#######
 # 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 libxenforeignmemory cross-zlib
+libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory libxendevicemodel 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
@@ -616,6 +628,7 @@ 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 libs-$(XEN_TARGET_ARCH)/devicemodel/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/devicemodel 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
tools/Makefile +1 -0
index 77e0723..0890cc9 100644
@@ -281,6 +281,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call \
 		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/foreignmemory \
+		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/devicemodel \
 		$(QEMU_UPSTREAM_RPATH)" \
 		--bindir=$(LIBEXEC_BIN) \
 		--datadir=$(SHAREDIR)/qemu-xen \
tools/Rules.mk +8 -2
index b35999b..e3415f0 100644
@@ -15,6 +15,7 @@ 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_LIBXENDEVICEMODEL = $(XEN_ROOT)/tools/libs/devicemodel
 XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
 XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
 XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
@@ -117,10 +118,15 @@ CFLAGS_libxenforeignmemory = -I$(XEN_LIBXENFOREIGNMEMORY)/include $(CFLAGS_xenin
 LDLIBS_libxenforeignmemory = $(XEN_LIBXENFOREIGNMEMORY)/libxenforeignmemory$(libextension)
 SHLIB_libxenforeignmemory  = -Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY)
 
+CFLAGS_libxendevicemodel = -I$(XEN_LIBXENDEVICEMODEL)/include $(CFLAGS_xeninclude)
+SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog)
+LDLIBS_libxendevicemodel = $(XEN_LIBXENDEVICEMODEL)/libxendevicemodel$(libextension)
+SHLIB_libxendevicemodel  = -Wl,-rpath-link=$(XEN_LIBXENDEVICEMODEL)
+
 # code which compiles against libxenctrl get __XEN_TOOLS__ and
 # therefore sees the unstable hypercall interfaces.
-CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude) -D__XEN_TOOLS__
-SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall) $(SHLIB_libxenforeignmemory)
+CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) $(CFLAGS_xeninclude) -D__XEN_TOOLS__
+SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxengntshr) $(SHLIB_libxencall) $(SHLIB_libxenforeignmemory) $(SHLIB_libxendevicemodel)
 LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension)
 SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
 
tools/libs/Makefile +1 -0
index dc5726d..deae4ae 100644
@@ -7,5 +7,6 @@ SUBDIRS-y += evtchn
 SUBDIRS-y += gnttab
 SUBDIRS-y += call
 SUBDIRS-y += foreignmemory
+SUBDIRS-y += devicemodel
 
 all clean install distclean: %: subdirs-%
tools/libs/devicemodel/Makefile new file +66 -0

66 lines not on this page · raw message

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

68 lines not on this page · raw message

tools/libs/devicemodel/include/xendevicemodel.h new file +40 -0
new file mode 100644
index 0000000..f977b0e
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017 Citrix Systems Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef XENDEVICEMODEL_H
+#define XENDEVICEMODEL_H
+
+/* Callers who don't care don't need to #include <xentoollog.h> */
+struct xentoollog_logger;
+
+typedef struct xendevicemodel_handle xendevicemodel_handle;
+
+xendevicemodel_handle *xendevicemodel_open(struct xentoollog_logger *logger,
+                                           unsigned int open_flags);
+
+int xendevicemodel_close(xendevicemodel_handle *dmod);
+
+#endif /* XENDEVICEMODEL_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libs/devicemodel/libxendevicemodel.map new file +6 -0
new file mode 100644
index 0000000..980c429
@@ -0,0 +1,6 @@
+VERS_1.0 {
+	global:
+		xendevicemodel_open;
+		xendevicemodel_close;
+	local: *; /* Do not expose anything by default */
+};
tools/libs/devicemodel/private.h new file +22 -0
new file mode 100644
index 0000000..cf1e4b0
@@ -0,0 +1,22 @@
+#ifndef XENDEVICEMODEL_PRIVATE_H
+#define XENDEVICEMODEL_PRIVATE_H
+
+#include <xentoollog.h>
+#include <xendevicemodel.h>
+
+struct xendevicemodel_handle {
+    xentoollog_logger *logger, *logger_tofree;
+    unsigned int flags;
+};
+
+#endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
tools/libxc/Makefile +2 -1
index 37235e3..af5e49c 100644
@@ -113,6 +113,7 @@ CFLAGS-$(CONFIG_Linux) += -D_GNU_SOURCE
 CFLAGS	+= $(PTHREAD_CFLAGS)
 CFLAGS	+= $(CFLAGS_libxentoollog)
 CFLAGS	+= $(CFLAGS_libxenevtchn)
+CFLAGS	+= $(CFLAGS_libxendevicemodel)
 
 CTRL_LIB_OBJS := $(patsubst %.c,%.o,$(CTRL_SRCS-y))
 CTRL_PIC_OBJS := $(patsubst %.c,%.opic,$(CTRL_SRCS-y))
@@ -217,7 +218,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) $(LDLIBS_libxenforeignmemory) $(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) $(LDLIBS_libxendevicemodel) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
 
 # libxenguest
 
tools/libxc/xc_private.c +8 -0
index 9df6925..bce7797 100644
@@ -67,9 +67,14 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
     if ( xch->fmem == NULL )
         goto err;
 
+    xch->dmod = xendevicemodel_open(xch->error_handler, 0);
+    if ( xch->dmod == NULL )
+        goto err;
+
     return xch;
 
  err:
+    xenforeignmemory_close(xch->fmem);
     xencall_close(xch->xcall);
     xtl_logger_destroy(xch->error_handler_tofree);
     if (xch != &xch_buf) free(xch);
@@ -89,6 +94,9 @@ int xc_interface_close(xc_interface *xch)
     rc = xenforeignmemory_close(xch->fmem);
     if (rc) PERROR("Could not close foreign memory interface");
 
+    rc = xendevicemodel_close(xch->dmod);
+    if (rc) PERROR("Could not close device model interface");
+
     xtl_logger_destroy(xch->dombuild_logger_tofree);
     xtl_logger_destroy(xch->error_handler_tofree);
 
tools/libxc/xc_private.h +4 -0
index d0ff4b5..1c27b0f 100644
@@ -36,6 +36,7 @@
 
 #include <xencall.h>
 #include <xenforeignmemory.h>
+#include <xendevicemodel.h>
 
 #include <xen/sys/privcmd.h>
 
@@ -97,6 +98,9 @@ struct xc_interface_core {
 
     /* Foreign mappings */
     xenforeignmemory_handle *fmem;
+
+    /* Device model */
+    xendevicemodel_handle *dmod;
 };
 
 int osdep_privcmd_open(xc_interface *xch);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#7 lore raw

PATCH v2 3/5 tools/libxendevicemodel: extract functions and add a compat layer

In reply to Paul Durrant

This patch extracts all functions resulting in a dm_op hypercall from libxenctrl and moves them into libxendevicemodel. It also adds a compat layer into libxenctrl, which can be selected by defining XC_WANT_COMPAT_DEVICEMODEL_API to 1 before including xenctrl.h.

With this patch the core of libxendevicemodel still uses libxencall to issue the dm_op hypercalls, but this is done by calling through code that can be modified on a per-OS basis. A subsequent patch will add a Linux- specific variant.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

v2:
- Re-based on 78da0c2a "libxc: don't pass uninitialized data to do_dm_op()" and corrected implementation of xendevicemodel_track_dirty_vram() accordingly.

---
 tools/Makefile                                  |   1 +
 tools/Rules.mk                                  |   2 +-
 tools/libs/devicemodel/Makefile                 |  10 +-
 tools/libs/devicemodel/compat.c                 |  45 +++
 tools/libs/devicemodel/core.c                   | 435 ++++++++++++++++++++++++
 tools/libs/devicemodel/include/xendevicemodel.h | 258 ++++++++++++++
 tools/libs/devicemodel/libxendevicemodel.map    |  16 +
 tools/libs/devicemodel/private.h                |  19 ++
 tools/libxc/Makefile                            |   1 +
 tools/libxc/include/xenctrl.h                   | 197 -----------
 tools/libxc/include/xenctrl_compat.h            |  47 +++
 tools/libxc/xc_devicemodel_compat.c             | 139 ++++++++
 tools/libxc/xc_domain.c                         | 201 -----------
 tools/libxc/xc_misc.c                           | 154 ---------
 tools/libxc/xc_private.c                        |  73 ----
 15 files changed, 970 insertions(+), 628 deletions(-)
 create mode 100644 tools/libs/devicemodel/compat.c
 create mode 100644 tools/libxc/xc_devicemodel_compat.c
tools/Makefile +1 -0
index 0890cc9..e6c0cc5 100644
@@ -262,6 +262,7 @@ subdir-all-qemu-xen-dir: qemu-xen-dir-find
 		--extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \
 		-DXC_WANT_COMPAT_GNTTAB_API=1 \
 		-DXC_WANT_COMPAT_MAP_FOREIGN_API=1 \
+		-DXC_WANT_COMPAT_DEVICEMODEL_API=1 \
 		-I$(XEN_ROOT)/tools/include \
 		-I$(XEN_ROOT)/tools/libs/toollog/include \
 		-I$(XEN_ROOT)/tools/libs/evtchn/include \
tools/Rules.mk +1 -1
index e3415f0..8ea3901 100644
@@ -119,7 +119,7 @@ LDLIBS_libxenforeignmemory = $(XEN_LIBXENFOREIGNMEMORY)/libxenforeignmemory$(lib
 SHLIB_libxenforeignmemory  = -Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY)
 
 CFLAGS_libxendevicemodel = -I$(XEN_LIBXENDEVICEMODEL)/include $(CFLAGS_xeninclude)
-SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog)
+SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_xencall)
 LDLIBS_libxendevicemodel = $(XEN_LIBXENDEVICEMODEL)/libxendevicemodel$(libextension)
 SHLIB_libxendevicemodel  = -Wl,-rpath-link=$(XEN_LIBXENDEVICEMODEL)
 
tools/libs/devicemodel/Makefile +8 -2
index 4f1e616..b87bf84 100644
@@ -8,8 +8,14 @@ SHLIB_LDFLAGS += -Wl,--version-script=libxendevicemodel.map
 CFLAGS   += -Werror -Wmissing-prototypes
 CFLAGS   += -I./include $(CFLAGS_xeninclude)
 CFLAGS   += $(CFLAGS_libxentoollog)
-
-SRCS-y   += core.c
+CFLAGS   += $(CFLAGS_libxencall)
+
+SRCS-y                 += core.c
+SRCS-$(CONFIG_Linux)   += compat.c
+SRCS-$(CONFIG_FreeBSD) += compat.c
+SRCS-$(CONFIG_SunOS)   += compat.c
+SRCS-$(CONFIG_NetBSD)  += compat.c
+SRCS-$(CONFIG_MiniOS)  += compat.c
 
 LIB_OBJS := $(patsubst %.c,%.o,$(SRCS-y))
 PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS-y))
tools/libs/devicemodel/compat.c new file +45 -0

45 lines not on this page · raw message

tools/libs/devicemodel/core.c +435 -0

467 lines not on this page · raw message

tools/libs/devicemodel/include/xendevicemodel.h +258 -0

270 lines not on this page · raw message

tools/libs/devicemodel/libxendevicemodel.map +16 -0
index 980c429..abc6d06 100644
@@ -1,6 +1,22 @@
 VERS_1.0 {
 	global:
 		xendevicemodel_open;
+		xendevicemodel_create_ioreq_server;
+		xendevicemodel_get_ioreq_server_info;
+		xendevicemodel_map_io_range_to_ioreq_server;
+		xendevicemodel_unmap_io_range_from_ioreq_server;
+		xendevicemodel_map_pcidev_to_ioreq_server;
+		xendevicemodel_unmap_pcidev_from_ioreq_server;
+		xendevicemodel_destroy_ioreq_server;
+		xendevicemodel_set_ioreq_server_state;
+		xendevicemodel_set_pci_intx_level;
+		xendevicemodel_set_isa_irq_level;
+		xendevicemodel_set_pci_link_route;
+		xendevicemodel_inject_msi;
+		xendevicemodel_track_dirty_vram;
+		xendevicemodel_modified_memory;
+		xendevicemodel_set_mem_type;
+		xendevicemodel_inject_event;
 		xendevicemodel_close;
 	local: *; /* Do not expose anything by default */
 };
tools/libs/devicemodel/private.h +19 -0
index cf1e4b0..7c7acf2 100644
@@ -1,14 +1,33 @@
 #ifndef XENDEVICEMODEL_PRIVATE_H
 #define XENDEVICEMODEL_PRIVATE_H
 
+#define __XEN_TOOLS__ 1
+
 #include <xentoollog.h>
 #include <xendevicemodel.h>
+#include <xencall.h>
 
 struct xendevicemodel_handle {
     xentoollog_logger *logger, *logger_tofree;
     unsigned int flags;
+    xencall_handle *xcall;
+};
+
+struct xendevicemodel_buf {
+    void *ptr;
+    size_t size;
 };
 
+int xendevicemodel_xcall(xendevicemodel_handle *dmod,
+                         domid_t domid, unsigned int nr_bufs,
+                         struct xendevicemodel_buf bufs[]);
+
+int osdep_xendevicemodel_open(xendevicemodel_handle *dmod);
+int osdep_xendevicemodel_close(xendevicemodel_handle *dmod);
+int osdep_xendevicemodel_op(xendevicemodel_handle *dmod,
+                            domid_t domid, unsigned int nr_bufs,
+                            struct xendevicemodel_buf bufs[]);
+
 #endif
 
 /*
tools/libxc/Makefile +1 -0
index af5e49c..da689c4 100644
@@ -50,6 +50,7 @@ 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
+CTRL_SRCS-y       += xc_devicemodel_compat.c
 
 GUEST_SRCS-y :=
 GUEST_SRCS-y += xg_private.c xc_suspend.c
tools/libxc/include/xenctrl.h +0 -197

209 lines not on this page · raw message

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

53 lines not on this page · raw message

tools/libxc/xc_devicemodel_compat.c new file +139 -0

139 lines not on this page · raw message

tools/libxc/xc_domain.c +0 -201

207 lines not on this page · raw message

tools/libxc/xc_misc.c +0 -154

160 lines not on this page · raw message

tools/libxc/xc_private.c +0 -73

79 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] tools/libxenctrl: fix error check after opening libxenforeignmemory

In reply to Paul Durrant
Quoted 4 lines · Paul Durrant

Checking the value of xch->xcall is clearly incorrect. The code should be checking xch->fmem (i.e. the return of the previously called function).

Ian, please backport this.

Quoted 24 lines

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>

---
 tools/libxc/xc_private.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/libxc/xc_private.c +1 -2
index f0e089c..9df6925 100644
@@ -64,8 +64,7 @@ struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
         goto err;
 
     xch->fmem = xenforeignmemory_open(xch->error_handler, 0);
-
-    if ( xch->xcall == NULL )
+    if ( xch->fmem == NULL )
         goto err;
 
     return xch;
Signature · 1 line
2.1.4

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

Acked-by on v2 1/5
#4 lore raw

Re: [PATCH v2 1/5] tools/libxenctrl: fix error check after opening libxenforeignmemory

In reply to Paul Durrant

Paul Durrant writes ("[PATCH v2 1/5] tools/libxenctrl: fix error check after opening libxenforeignmemory"):

Quoted 2 lines

Checking the value of xch->xcall is clearly incorrect. The code should be checking xch->fmem (i.e. the return of the previously called function).

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

Acked-by on v2 2/5
#6 lore raw

Re: [PATCH v2 2/5] tools/libxendevicemodel: introduce the new library

In reply to Paul Durrant

Paul Durrant writes ("[PATCH v2 2/5] tools/libxendevicemodel: introduce the new library"):

Quoted 3 lines

The new xendevicemodel library is intended to be used by all Xen device models such that the only hypercall that use will be the dm_op hypercall added by commit 524a98c2.

Quoted 6 lines

NOTE TO COMMITTERS:

The URLs and tags for qemu-xen-traditional and mini-is in the patch to Config.mk need to be substituted with the correct URLs and tags after the appropriate (recently posted) patches have been committed into the master branches.

Just quoting this to avoid it being dropped...

Ian.

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

#8 lore raw

Re: [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer

In reply to Paul Durrant

Paul Durrant writes ("[PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer"):

Quoted 9 lines

This patch extracts all functions resulting in a dm_op hypercall from libxenctrl and moves them into libxendevicemodel. It also adds a compat layer into libxenctrl, which can be selected by defining XC_WANT_COMPAT_DEVICEMODEL_API to 1 before including xenctrl.h.

With this patch the core of libxendevicemodel still uses libxencall to issue the dm_op hypercalls, but this is done by calling through code that can be modified on a per-OS basis. A subsequent patch will add a Linux- specific variant.

...

Quoted 8 lines
tools/libs/devicemodel/core.c +8 -0
+int xendevicemodel_track_dirty_vram(
+    xendevicemodel_handle *dmod, domid_t domid, uint64_t first_pfn,
+    uint32_t nr, unsigned long *dirty_bitmap)
+{
+    struct xen_dm_op op;
+    struct xen_dm_op_track_dirty_vram *data;
+
+    memset(&op, 0, sizeof(op));

tools/libs/devicemodel/core.c err: · line 434

Quoted 10 lines
tools/libs/devicemodel/core.c +10 -0
+
+    op.op = XEN_DMOP_track_dirty_vram;
+    data = &op.u.track_dirty_vram;
+
+    data->first_pfn = first_pfn;
+    data->nr = nr;
+
+    return xendevicemodel_op(dmod, domid, 2, &op, sizeof(op),
+                             dirty_bitmap, (size_t)(nr + 7) / 8);
+}

As I think we discussed some time last week (?), this function cannot be a DMOP. This is because enabling track_dirty_vram causes the hypervisor to remember the memory referred to by dirty_bitmap, but the dmop privcmd restriction mechanism only guarantees that the memory is valid and belonging to this guest _during the hypercall_.

Are there more like this ? How does ioreq server registration work ?

Can we add a note to the hypervisor side of the DMOP buffer interface, saying something like

Code in Xen MUST NOT save copies of the pointers in the dmop buffers. Only copying to and from guest memory, during the hypercall, is permitted.

?

Ian.

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

Acked-by on v2 4/5
#15 lore raw

Re: [PATCH v2 4/5] tools/libxendevicemodel: introduce a Linux-specific implementation

In reply to Paul Durrant

Paul Durrant writes ("[PATCH v2 4/5] tools/libxendevicemodel: introduce a Linux-specific implementation"):

Quoted 6 lines

My recent patch [1] to the Linux privcmd module introduced a dedicated mechanism for making dm_op hypercalls.

This patch adds the necessary code to libxendevicemodel to take advantage of that mechanism if it is implemented in the tools domain kernel.

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

Acked-by on v2 5/5
#17 lore raw

Re: [PATCH v2 5/5] tools/libxendevicemodel: add a call to restrict the handle

In reply to Paul Durrant

Paul Durrant writes ("[PATCH v2 5/5] tools/libxendevicemodel: add a call to restrict the handle"):

Quoted 3 lines

My recent patch [1] to the Linux privcmd module introduced a mechanism to restrict an open file handle to subsequently only accept operations for a specified domain.

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

#9 lore raw

Re: [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer

In reply to Ian Jackson
Quoted 26 lines · Ian Jackson

Paul Durrant writes ("[PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer"):

Quoted 9 lines

This patch extracts all functions resulting in a dm_op hypercall from libxenctrl and moves them into libxendevicemodel. It also adds a compat layer into libxenctrl, which can be selected by defining XC_WANT_COMPAT_DEVICEMODEL_API to 1 before including xenctrl.h.

With this patch the core of libxendevicemodel still uses libxencall to issue the dm_op hypercalls, but this is done by calling through code that can be modified on a per-OS basis. A subsequent patch will add a Linux- specific variant.

...

Quoted 15 lines
tools/libs/devicemodel/core.c +15 -0
+int xendevicemodel_track_dirty_vram(
+    xendevicemodel_handle *dmod, domid_t domid, uint64_t first_pfn,
+    uint32_t nr, unsigned long *dirty_bitmap)
+{
+    struct xen_dm_op op;
+    struct xen_dm_op_track_dirty_vram *data;
+
+    memset(&op, 0, sizeof(op));
+
+    op.op = XEN_DMOP_track_dirty_vram;
+    data = &op.u.track_dirty_vram;
+
+    data->first_pfn = first_pfn;
+    data->nr = nr;
+
Quoted 8 lines

tools/libs/devicemodel/core.c err: · line 434

Quoted 3 lines
tools/libs/devicemodel/core.c +3 -0
+    return xendevicemodel_op(dmod, domid, 2, &op, sizeof(op),
+                             dirty_bitmap, (size_t)(nr + 7) / 8);
+}

As I think we discussed some time last week (?), this function cannot be a DMOP. This is because enabling track_dirty_vram causes the hypervisor to remember the memory referred to by dirty_bitmap, but the dmop privcmd restriction mechanism only guarantees that the memory is valid and belonging to this guest _during the hypercall_.

Sorry to jump in here, but what? Since when?

track-dirty-vram stashes where the DM thinks the vram is in guest physical address space, so if a new range is requested, we can set appropriate bits in the dirty map.

However, the interesting pointer for the DMOP (i.e. where the DM would like Xen to write the bitmap to) is not stored across distinct calls at all. It is stored as part of a continuation, but that is still logically part of a single invocation.

~Andrew

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

#10 lore raw

Re: [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer

Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer"):

Quoted 8 lines · Ian Jackson
Quoted 5 lines

As I think we discussed some time last week (?), this function cannot be a DMOP. This is because enabling track_dirty_vram causes the hypervisor to remember the memory referred to by dirty_bitmap, but the dmop privcmd restriction mechanism only guarantees that the memory is valid and belonging to this guest _during the hypercall_.

Sorry to jump in here, but what? Since when?

Maybe I have misunderstood.

Quoted 3 lines

track-dirty-vram stashes where the DM thinks the vram is in guest physical address space, so if a new range is requested, we can set appropriate bits in the dirty map.

Does this ...

Quoted 3 lines
Quoted 3 lines

tools/libs/devicemodel/core.c err: · line 434

Quoted 3 lines
tools/libs/devicemodel/core.c +3 -0
+    return xendevicemodel_op(dmod, domid, 2, &op, sizeof(op),
+                             dirty_bitmap, (size_t)(nr + 7) / 8);
+}

... not result in the hypervisor asynchronously updating the contents of dirty_bitmap[whatever], later ?

Quoted 4 lines

However, the interesting pointer for the DMOP (i.e. where the DM would like Xen to write the bitmap to) is not stored across distinct calls at all. It is stored as part of a continuation, but that is still logically part of a single invocation.

Is the bitmap copied in each dmop call ?

Ian.

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

#11 lore raw

Re: [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer

Quoted 13 lines · Ian Jackson

Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer"):

Quoted 7 lines · Ian Jackson
Quoted 5 lines

As I think we discussed some time last week (?), this function cannot be a DMOP. This is because enabling track_dirty_vram causes the hypervisor to remember the memory referred to by dirty_bitmap, but the dmop privcmd restriction mechanism only guarantees that the memory is valid and belonging to this guest _during the hypercall_.

Sorry to jump in here, but what? Since when?

Maybe I have misunderstood.

Quoted 3 lines

track-dirty-vram stashes where the DM thinks the vram is in guest physical address space, so if a new range is requested, we can set appropriate bits in the dirty map.

Quoted 7 lines

Does this ...

Quoted 3 lines
Quoted 3 lines

tools/libs/devicemodel/core.c err: · line 434

Quoted 3 lines
tools/libs/devicemodel/core.c +3 -0
+    return xendevicemodel_op(dmod, domid, 2, &op, sizeof(op),
+                             dirty_bitmap, (size_t)(nr + 7) / 8);
+}

... not result in the hypervisor asynchronously updating the contents of dirty_bitmap[whatever], later ?

No.

Quoted 6 lines
Quoted 5 lines

However, the interesting pointer for the DMOP (i.e. where the DM would like Xen to write the bitmap to) is not stored across distinct calls at all. It is stored as part of a continuation, but that is still logically part of a single invocation.

Is the bitmap copied in each dmop call ?

Yes, and hence...

... one optimisation I want to do in the future is for the DM to be able to make a Read-only mapping of Xens logdirty bitmap, so the bitmap can be passed by shared memory rather than memcpy(), because I expect it would be rather more efficient during some of the time-sensitive bits of live migrate.

~Andrew

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

#12 lore raw

Re: [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer

Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer"):

Quoted 4 lines · Ian Jackson
Quoted 1 line

Is the bitmap copied in each dmop call ?

Yes, and hence...

Oh!

I had assumed that this wouldn't be the case because it would obviously be slow.

Quoted 5 lines

... one optimisation I want to do in the future is for the DM to be able to make a Read-only mapping of Xens logdirty bitmap, so the bitmap can be passed by shared memory rather than memcpy(), because I expect it would be rather more efficient during some of the time-sensitive bits of live migrate.

Well, err, yes.

(What about the ioreq ring?)

Ian.

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

#13 lore raw

Re: [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer

Quoted 9 lines · Ian Jackson

Andrew Cooper writes ("Re: [Xen-devel] [PATCH v2 3/5] tools/libxendevicemodel: extract functions and add a compat layer"):

Quoted 3 lines · Ian Jackson
Quoted 1 line

Is the bitmap copied in each dmop call ?

Yes, and hence...

Oh!

I had assumed that this wouldn't be the case because it would obviously be slow.

Quoted 8 lines
Quoted 5 lines

... one optimisation I want to do in the future is for the DM to be able to make a Read-only mapping of Xens logdirty bitmap, so the bitmap can be passed by shared memory rather than memcpy(), because I expect it would be rather more efficient during some of the time-sensitive bits of live migrate.

Well, err, yes.

(What about the ioreq ring?)

That is a piece of shared memory.

But shared memory is not interesting to DMOP. You already *must* defer to your kernel to create the shared memory in the first place, so the resulting pointer is definitely ok as far as the kernel is concerned.

~Andrew

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

#3 lore raw

Re: [PATCH v2 1/5] tools/libxenctrl: fix error check after opening libxenforeignmemory

In reply to Wei Liu

Wei Liu writes ("Re: [PATCH v2 1/5] tools/libxenctrl: fix error check after opening libxenforeignmemory"):

Quoted 9 lines · Paul Durrant
Quoted 4 lines

Checking the value of xch->xcall is clearly incorrect. The code should be checking xch->fmem (i.e. the return of the previously called function).

Ian, please backport this.

I hvae applied this to 4.7 and 4.8.

Ian.

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