Skip to contentSkip to conversation

Add xl PCI daemon (server for libxl PCI)

PATCH New Anastasiia Lukianenko 1 participant 10 messages Aug 12, 2021

lore
Share & tools
lore
#0 lore raw

cover Add xl PCI daemon (server for libxl PCI)

From: Anastasiia Lukianenko <[email protected]>

This work introduces xl PCI daemon that acts as a server for the client in the libxl PCI. The toolstack in Dom0 accesses sysfs to get information about PCI devices and in case of Hardware Domain that sysfs lives in Hardware Domain, so Dom0 can't read that information directly anymore. For that reason we introduce a "proxy" which directs requests from Dom0 to the domain which owns PCI devices, being it Dom0 itself or any other domain, e.g. Hardware Domain. xl PCI daemon is based on vchan-node2 tool and uses the libxenvchan library for messaging transport.

It was verified that this model works both remotely (in different domains) and locally (within one domain) as requested by Xen community [1]. The server processes the requests that come from the client. For better interoperability between guest OSes, e.g. Linux vs FreeBSD, the path in the request is not a direct sysfs entry as seen in Dom0, but instead it is a key-word defined in the protocol. For now libxl PCI refers to sysfs in the following functions, therefore such a subset was implemented in xl PCI daemon commands handling:
* ‘ls’ - the server receives "dir_id" as a parameter. Xl pcid server transmits information about devices assigned to the PCI driver by sending a reply with the remote directory listing. Client cannot pass the sysfs path, as it is not the same on different operating systems. Therefore, for example, we pass parameter "pciback_driver" and on the server side we refer to "/sys/bus/pci/drivers/pciback" if Linux is used);
* ‘write’- the server receives the file name and value as parameters where and what to write;
* ‘read_hex’ - xl PCI daemon returns hex value read from the given path;
* ‘exists’ - check if path exists;
* ‘read_resources’ - returns an array of PCI device resources (start, end, flags) read from given path;
* ‘unbind’ - unbinds PCI device;
* ‘reset’ - resets PCI device.

Requests and responses are formed in the form of a json which is already used by libxenlight (xl). The commands are aimed at preventing the libxl PCI from reading / writing from / to the local sysfs directly. To do this, the libxl PCI itself was changed, vchan and pcid support was added to libxl - instead of working with the read and write functions from / to the sysfs, functionality was added to send requests to the server, then receive and process the response.

Libxl vchan is used as transport between libxl and the server side. Libxl vchan adds support for JSON messages processing. Libxl pcid functions allow to process the received message from PCI server and to generate a reply in JSON format for the client. The pcid functions in the libxl allow the use of internal libxl structures and functions, so there is no code duplications on server side.

The issue of simultaneous access of several processes to the channel is not resolved as well. For example, the commands “xl pci-assignable-list” and “xl pci-assignable-add” will be sent at the same time. Due to the fact that there is only one channel, the processing of two requests will cause undefined behavior on the server side. In the future, it is necessary to take into account cases when from different domains there can be several requests from a client at the same time or from the same but xl commands are executed concurrently.

[1] - https://www.mail-archive.com/[email protected]/msg84452.html

Regards,
Anastasiia

Anastasiia Lukianenko (9):
tools/libs/light: Add vchan support to libxl tools/libs/light: Add functions for handling PCI messages in JSON
format
tools/xl: Add pcid daemon to xl
tools/libs/light: Add "ls" command processing to xl pcid daemon and
libxl PCI
tools/libs/light: Add "write" command to xl pcid and libxl PCI tools/libs/light: Add "read" command to xl pcid and libxl PCI tools/libs/light: Make Libxl PCI get values from xl pcid instead of
libxl side
tools/libs/light: Add "unbind" and "read resources" commands to libxl
PCI and xl pcid
tools/libs/light: Add "reset" and "remove" PCI dev commands to xl pcid
daemon and libxl PCI

 tools/configure                           |   5 +-
 tools/helpers/Makefile                    |   4 +-
 tools/hotplug/FreeBSD/rc.d/xlpcid.in      |  75 +++
 tools/hotplug/Linux/init.d/xlpcid.in      |  76 +++
 tools/hotplug/NetBSD/rc.d/xlpcid.in       |  75 +++
 tools/include/pcid.h                      |  73 +++
 tools/libs/light/Makefile                 |   8 +-
 tools/libs/light/libxl_pci.c              | 566 ++++++++++++++--------
 tools/libs/light/libxl_pcid.c             | 527 ++++++++++++++++++++
 tools/libs/light/libxl_types.idl          |   1 +
 tools/libs/light/libxl_types_internal.idl |   6 +
 tools/libs/light/libxl_vchan.c            | 359 ++++++++++++++
 tools/libs/light/libxl_vchan.h            |  81 ++++
 tools/xl/Makefile                         |   5 +-
 tools/xl/xl.h                             |   1 +
 tools/xl/xl_cmdtable.c                    |   7 +
 tools/xl/xl_pcid.c                        |  79 +++
 17 files changed, 1727 insertions(+), 221 deletions(-)
 create mode 100644 tools/hotplug/FreeBSD/rc.d/xlpcid.in
 create mode 100644 tools/hotplug/Linux/init.d/xlpcid.in
 create mode 100644 tools/hotplug/NetBSD/rc.d/xlpcid.in
 create mode 100644 tools/include/pcid.h
 create mode 100644 tools/libs/light/libxl_pcid.c
 create mode 100644 tools/libs/light/libxl_vchan.c
 create mode 100644 tools/libs/light/libxl_vchan.h
 create mode 100644 tools/xl/xl_pcid.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/9 tools/libs/light: Add vchan support to libxl

From: Anastasiia Lukianenko <[email protected]>

Add possibility to send commands from libxl and execute them on server side. Libxl vchan adds support for JSON messages processing.

The using of libxl vchan is preventing the client from libxl from reading and writing from / to the local sysfs directly.To do this, the libxl vchan was added - instead of working with the read and write functions from / to the sysfs, functionality allows to send requests to the server, then receive and process the response.

---
 tools/helpers/Makefile         |   4 +-
 tools/libs/light/Makefile      |   7 +-
 tools/libs/light/libxl_vchan.c | 359 +++++++++++++++++++++++++++++++++
 tools/libs/light/libxl_vchan.h |  81 ++++++++
 tools/xl/Makefile              |   3 +-
 5 files changed, 448 insertions(+), 6 deletions(-)
 create mode 100644 tools/libs/light/libxl_vchan.c
 create mode 100644 tools/libs/light/libxl_vchan.h
tools/helpers/Makefile +2 -2
index 1bcc97ea8a..ad2cdf32ad 100644
@@ -29,12 +29,12 @@ $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenlight)
 all: $(PROGS)
 
 xen-init-dom0: $(XEN_INIT_DOM0_OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxenctrl) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxenctrl) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS)
 
 $(INIT_XENSTORE_DOMAIN_OBJS): _paths.h
 
 init-xenstore-domain: $(INIT_XENSTORE_DOMAIN_OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(INIT_XENSTORE_DOMAIN_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenlight) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $(INIT_XENSTORE_DOMAIN_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenlight) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: all
tools/libs/light/Makefile +4 -3
index 4a4de12610..f5d34b3371 100644
@@ -76,6 +76,7 @@ SRCS-y += libxl.c
 SRCS-y += libxl_create.c
 SRCS-y += libxl_dm.c
 SRCS-y += libxl_pci.c
+SRCS-y += libxl_vchan.c
 SRCS-y += libxl_dom.c
 SRCS-y += libxl_exec.c
 SRCS-y += libxl_xshelp.c
@@ -176,7 +177,7 @@ LDUSELIBS-y += $(PTHREAD_LIBS)
 LDUSELIBS-y += -lyajl
 LDUSELIBS += $(LDUSELIBS-y)
 
-$(LIB_OBJS) $(PIC_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h
+$(LIB_OBJS) $(PIC_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) $(CFLAGS_libxenevtchn) -include $(XEN_ROOT)/tools/config.h
 $(ACPI_OBJS) $(ACPI_PIC_OBJS): CFLAGS += -I. -DLIBACPI_STDUTILS=\"$(CURDIR)/libxl_x86_acpi.h\"
 $(TEST_PROG_OBJS) _libxl.api-for-check: CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxentoolcore)
 libxl_dom.o libxl_dom.opic: CFLAGS += -I$(XEN_ROOT)/tools  # include libacpi/x86.h
@@ -240,13 +241,13 @@ libxenlight_test.so: $(PIC_OBJS) $(LIBXL_TEST_OBJS)
 	$(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDUSELIBS) $(APPEND_LDFLAGS)
 
 test_%: test_%.o test_common.o libxenlight_test.so
-	$(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(LDLIBS_libxenvchan) -lyajl $(APPEND_LDFLAGS)
 
 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so
 	$(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
 
 testidl: testidl.o libxenlight.so
-	$(CC) $(LDFLAGS) -o $@ testidl.o $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ testidl.o $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(LDLIBS_libxenvchan) $(APPEND_LDFLAGS)
 
 install: installlocal $(LIBHEADERS)
 
tools/libs/light/libxl_vchan.c new file +359 -0

359 lines not on this page · raw message

tools/libs/light/libxl_vchan.h new file +81 -0

81 lines not on this page · raw message

tools/xl/Makefile +2 -1
index a5d2ee4528..d35570c343 100644
@@ -15,6 +15,7 @@ LDFLAGS += $(PTHREAD_LDFLAGS)
 CFLAGS_XL += $(CFLAGS_libxenlight)
 CFLAGS_XL += $(CFLAGS_libxenutil)
 CFLAGS_XL += -Wshadow
+CFLAGS_XL += $(CFLAGS_libxenvchan)
 
 XL_OBJS-$(CONFIG_X86) = xl_psr.o
 XL_OBJS = xl.o xl_cmdtable.o xl_sxp.o xl_utils.o $(XL_OBJS-y)
@@ -38,7 +39,7 @@ $(XL_OBJS): _paths.h
 all: xl
 
 xl: $(XL_OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenvchan) -lyajl $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: all
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/9 tools/libs/light: Add functions for handling PCI messages in JSON format

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

These functions allow to process the received message from PCI server and to generate a reply in JSON format for the client.

---
 tools/include/pcid.h                      |  49 ++++++++
 tools/libs/light/Makefile                 |   1 +
 tools/libs/light/libxl_pcid.c             | 134 ++++++++++++++++++++++
 tools/libs/light/libxl_types.idl          |   1 +
 tools/libs/light/libxl_types_internal.idl |   6 +
 5 files changed, 191 insertions(+)
 create mode 100644 tools/include/pcid.h
 create mode 100644 tools/libs/light/libxl_pcid.c
tools/include/pcid.h new file +49 -0
new file mode 100644
index 0000000000..59a7aad64a
@@ -0,0 +1,49 @@
+/*
+    Common definitions for Xen PCI client-server protocol.
+    Copyright (C) 2021 EPAM 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; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    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 PCID_H
+#define PCID_H
+
+#define PCID_XS_DIR             "/local/domain/"
+#define PCID_XS_PATH            "/data/pcid-vchan"
+
+#define PCI_RECEIVE_BUFFER_SIZE 4096
+#define PCI_MAX_SIZE_RX_BUF     MB(1)
+
+#define PCID_MSG_FIELD_ID        "id"
+#define PCID_MSG_FIELD_ARGS      "arguments"
+
+#define PCID_PCIBACK_DRIVER      "pciback_driver"
+
+#if defined(__linux__)
+#define SYSFS_PCIBACK_DRIVER   "/sys/bus/pci/drivers/pciback"
+#endif
+
+int libxl_pcid_process(libxl_ctx *ctx);
+
+#endif /* PCID_H */
+
+/*
+ * Local variables:
+ *  mode: C
+ *  c-file-style: "linux"
+ *  indent-tabs-mode: t
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */
tools/libs/light/Makefile +1 -0
index f5d34b3371..40e3a7d7ce 100644
@@ -76,6 +76,7 @@ SRCS-y += libxl.c
 SRCS-y += libxl_create.c
 SRCS-y += libxl_dm.c
 SRCS-y += libxl_pci.c
+SRCS-y += libxl_pcid.c
 SRCS-y += libxl_vchan.c
 SRCS-y += libxl_dom.c
 SRCS-y += libxl_exec.c
tools/libs/light/libxl_pcid.c new file +134 -0

134 lines not on this page · raw message

tools/libs/light/libxl_types.idl +1 -0
index 395165d801..d89c3ac1eb 100644
@@ -76,6 +76,7 @@ libxl_error = Enumeration("error", [
     (-30, "QMP_DEVICE_NOT_ACTIVE"), # a device has failed to be become active
     (-31, "QMP_DEVICE_NOT_FOUND"), # the requested device has not been found
     (-32, "QEMU_API"), # QEMU's replies don't contains expected members
+    (-33, "PROTOCOL_ERROR_PCID"),
     ], value_namespace = "")
 
 libxl_domain_type = Enumeration("domain_type", [
tools/libs/light/libxl_types_internal.idl +6 -0
index d66da13764..b9cee64d41 100644
@@ -58,3 +58,9 @@ libxl__device_action = Enumeration("device_action", [
     (1, "ADD"),
     (2, "REMOVE"),
     ])
+
+libxl__pcid_message_type = Enumeration("pcid_message_type", [
+    (1, "return"),
+    (2, "error"),
+    (3, "invalid"),
+    ])
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/9 tools/xl: Add pcid daemon to xl

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Add draft version of pcid server (based on vchan-node2), which can receive messages from the client.

---
 tools/configure                      |  5 +-
 tools/hotplug/FreeBSD/rc.d/xlpcid.in | 75 ++++++++++++++++++++++++++
 tools/hotplug/Linux/init.d/xlpcid.in | 76 ++++++++++++++++++++++++++
 tools/hotplug/NetBSD/rc.d/xlpcid.in  | 75 ++++++++++++++++++++++++++
 tools/xl/Makefile                    |  4 +-
 tools/xl/xl.h                        |  1 +
 tools/xl/xl_cmdtable.c               |  7 +++
 tools/xl/xl_pcid.c                   | 79 ++++++++++++++++++++++++++++
 8 files changed, 319 insertions(+), 3 deletions(-)
 create mode 100644 tools/hotplug/FreeBSD/rc.d/xlpcid.in
 create mode 100644 tools/hotplug/Linux/init.d/xlpcid.in
 create mode 100644 tools/hotplug/NetBSD/rc.d/xlpcid.in
 create mode 100644 tools/xl/xl_pcid.c
tools/configure +4 -1
index b21ade08c0..be9fc9b1d4 100755
@@ -2454,7 +2454,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
-ac_config_files="$ac_config_files ../config/Tools.mk hotplug/FreeBSD/rc.d/xencommons hotplug/FreeBSD/rc.d/xendriverdomain hotplug/Linux/init.d/sysconfig.xencommons hotplug/Linux/init.d/sysconfig.xendomains hotplug/Linux/init.d/xen-watchdog hotplug/Linux/init.d/xencommons hotplug/Linux/init.d/xendomains hotplug/Linux/init.d/xendriverdomain hotplug/Linux/launch-xenstore hotplug/Linux/vif-setup hotplug/Linux/xen-hotplug-common.sh hotplug/Linux/xendomains hotplug/NetBSD/rc.d/xencommons hotplug/NetBSD/rc.d/xendriverdomain ocaml/xenstored/oxenstored.conf"
+ac_config_files="$ac_config_files ../config/Tools.mk hotplug/FreeBSD/rc.d/xencommons hotplug/FreeBSD/rc.d/xendriverdomain hotplug/FreeBSD/rc.d/xlpcid hotplug/Linux/init.d/sysconfig.xencommons hotplug/Linux/init.d/sysconfig.xendomains hotplug/Linux/init.d/xlpcid hotplug/Linux/init.d/xen-watchdog hotplug/Linux/init.d/xencommons hotplug/Linux/init.d/xendomains hotplug/Linux/init.d/xendriverdomain hotplug/Linux/launch-xenstore hotplug/Linux/vif-setup hotplug/Linux/xen-hotplug-common.sh hotplug/Linux/xendomains hotplug/NetBSD/rc.d/xencommons hotplug/NetBSD/rc.d/xendriverdomain hotplug/NetBSD/rc.d/xlpcid ocaml/xenstored/oxenstored.conf"
 
 ac_config_headers="$ac_config_headers config.h"
 
@@ -10892,8 +10892,10 @@ do
     "../config/Tools.mk") CONFIG_FILES="$CONFIG_FILES ../config/Tools.mk" ;;
     "hotplug/FreeBSD/rc.d/xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/FreeBSD/rc.d/xencommons" ;;
     "hotplug/FreeBSD/rc.d/xendriverdomain") CONFIG_FILES="$CONFIG_FILES hotplug/FreeBSD/rc.d/xendriverdomain" ;;
+    "hotplug/FreeBSD/rc.d/xlpcid") CONFIG_FILES="$CONFIG_FILES hotplug/FreeBSD/rc.d/xlpcid" ;;
     "hotplug/Linux/init.d/sysconfig.xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/sysconfig.xencommons" ;;
     "hotplug/Linux/init.d/sysconfig.xendomains") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/sysconfig.xendomains" ;;
+    "hotplug/Linux/init.d/xlpcid") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xlpcid" ;;
     "hotplug/Linux/init.d/xen-watchdog") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xen-watchdog" ;;
     "hotplug/Linux/init.d/xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xencommons" ;;
     "hotplug/Linux/init.d/xendomains") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/init.d/xendomains" ;;
@@ -10904,6 +10906,7 @@ do
     "hotplug/Linux/xendomains") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/xendomains" ;;
     "hotplug/NetBSD/rc.d/xencommons") CONFIG_FILES="$CONFIG_FILES hotplug/NetBSD/rc.d/xencommons" ;;
     "hotplug/NetBSD/rc.d/xendriverdomain") CONFIG_FILES="$CONFIG_FILES hotplug/NetBSD/rc.d/xendriverdomain" ;;
+    "hotplug/NetBSD/rc.d/xlpcid") CONFIG_FILES="$CONFIG_FILES hotplug/NetBSD/rc.d/xlpcid" ;;
     "ocaml/xenstored/oxenstored.conf") CONFIG_FILES="$CONFIG_FILES ocaml/xenstored/oxenstored.conf" ;;
     "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
     "hotplug/Linux/systemd/proc-xen.mount") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/proc-xen.mount" ;;
tools/hotplug/FreeBSD/rc.d/xlpcid.in new file +75 -0

75 lines not on this page · raw message

tools/hotplug/Linux/init.d/xlpcid.in new file +76 -0

76 lines not on this page · raw message

tools/hotplug/NetBSD/rc.d/xlpcid.in new file +75 -0

75 lines not on this page · raw message

tools/xl/Makefile +2 -2
index d35570c343..d46a9ad24a 100644
@@ -22,7 +22,7 @@ XL_OBJS = xl.o xl_cmdtable.o xl_sxp.o xl_utils.o $(XL_OBJS-y)
 XL_OBJS += xl_parse.o xl_cpupool.o xl_flask.o
 XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o
 XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o xl_mem.o
-XL_OBJS += xl_info.o xl_console.o xl_misc.o
+XL_OBJS += xl_info.o xl_console.o xl_misc.o xl_pcid.o
 XL_OBJS += xl_vmcontrol.o xl_saverestore.o xl_migrate.o
 XL_OBJS += xl_vdispl.o xl_vsnd.o xl_vkb.o xl_vcamera.o
 
@@ -39,7 +39,7 @@ $(XL_OBJS): _paths.h
 all: xl
 
 xl: $(XL_OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenvchan) -lyajl $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenvchan) -lyajl $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: all
tools/xl/xl.h +1 -0
index e1d5190cc8..a88f03c624 100644
@@ -206,6 +206,7 @@ int main_loadpolicy(int argc, char **argv);
 int main_remus(int argc, char **argv);
 #endif
 int main_devd(int argc, char **argv);
+int main_pcid(int argc, char **argv);
 #if defined(__i386__) || defined(__x86_64__)
 int main_psr_hwinfo(int argc, char **argv);
 int main_psr_cmt_attach(int argc, char **argv);
tools/xl/xl_cmdtable.c +7 -0
index c3cb515348..dfc4386b35 100644
@@ -560,6 +560,13 @@ const struct cmd_spec cmd_table[] = {
       "-F                      Run in the foreground.\n"
       "-p, --pidfile [FILE]    Write PID to pidfile when daemonizing.",
     },
+    { "pcid",
+      &main_pcid, 0, 1,
+      "Daemon that acts as a server for the client in the libxl PCI",
+      "[options]",
+      "-F                      Run in the foreground.\n"
+      "-p, --pidfile [FILE]    Write PID to pidfile when daemonizing.",
+    },
 #if defined(__i386__) || defined(__x86_64__)
     { "psr-hwinfo",
       &main_psr_hwinfo, 0, 1,
tools/xl/xl_pcid.c new file +79 -0

79 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/9 tools/libs/light: Add "ls" command processing to xl pcid daemon and libxl PCI

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Messaging format is based on json style. Xl pcid receives "ls" command from client and sends a reply:
1. success case - array of directory's names
2. error case - message with "error" in return

Xl pcid server transmits information about devices assigned to the PCI driver by sending reply with directory's names. Libxl PCI processes reply message instead of opening directory in libxl side.

---
 tools/include/pcid.h          |   7 ++
 tools/libs/light/libxl_pci.c  | 136 +++++++++++++++++++++++++++++-----
 tools/libs/light/libxl_pcid.c |  59 +++++++++++++++
 3 files changed, 184 insertions(+), 18 deletions(-)
tools/include/pcid.h +7 -0
index 59a7aad64a..e9c3c497c6 100644
@@ -28,12 +28,19 @@
 #define PCID_MSG_FIELD_ID        "id"
 #define PCID_MSG_FIELD_ARGS      "arguments"
 
+#define PCID_CMD_LIST            "ls"
+#define PCID_CMD_DIR_ID          "dir_id"
+
 #define PCID_PCIBACK_DRIVER      "pciback_driver"
 
 #if defined(__linux__)
 #define SYSFS_PCIBACK_DRIVER   "/sys/bus/pci/drivers/pciback"
 #endif
 
+#define PCI_INFO_PATH "/libxl/pci"
+#define PCI_BDF_XSPATH         "%04x-%02x-%02x-%01x"
+#define PCI_BDF                "%04x:%02x:%02x.%01x"
+
 int libxl_pcid_process(libxl_ctx *ctx);
 
 #endif /* PCID_H */
tools/libs/light/libxl_pci.c +118 -18

170 lines not on this page · raw message

tools/libs/light/libxl_pcid.c +59 -0

71 lines not on this page · raw message

Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/9 tools/libs/light: Add "write" command to xl pcid and libxl PCI

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Add functions for handling "write" command on xl pcid side. Libxl PCI side receives reply:
1. success - string in "return" message
2. fail - error type of reply message

---
 tools/include/pcid.h          |  7 ++++
 tools/libs/light/libxl_pci.c  | 69 +++++++++++++++++++----------------
 tools/libs/light/libxl_pcid.c | 69 +++++++++++++++++++++++++++++++++++
 3 files changed, 113 insertions(+), 32 deletions(-)
tools/include/pcid.h +7 -0
index e9c3c497c6..935d99b186 100644
@@ -31,7 +31,14 @@
 #define PCID_CMD_LIST            "ls"
 #define PCID_CMD_DIR_ID          "dir_id"
 
+#define PCID_CMD_WRITE           "write"
+#define PCID_CMD_PCI_PATH        "pci_path"
+#define PCID_CMD_PCI_INFO        "pci_info"
+
 #define PCID_PCIBACK_DRIVER      "pciback_driver"
+#define PCID_PCI_DEV             "pci_dev"
+
+#define SYSFS_DRIVER_PATH        "driver_path"
 
 #if defined(__linux__)
 #define SYSFS_PCIBACK_DRIVER   "/sys/bus/pci/drivers/pciback"
tools/libs/light/libxl_pci.c +37 -32

125 lines not on this page · raw message

tools/libs/light/libxl_pcid.c +69 -0

81 lines not on this page · raw message

Signature · 1 line
2.17.1
#6 lore raw

PATCH 6/9 tools/libs/light: Add "read" command to xl pcid and libxl PCI

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Libxl PCI can use xl pcid server to read integer value from the given path.

---
 tools/include/pcid.h          |   1 +
 tools/libs/light/libxl_pci.c  | 125 ++++++++++++++++++----------------
 tools/libs/light/libxl_pcid.c |  50 ++++++++++++++
 3 files changed, 119 insertions(+), 57 deletions(-)
tools/include/pcid.h +1 -0
index 935d99b186..f39011ecb8 100644
@@ -32,6 +32,7 @@
 #define PCID_CMD_DIR_ID          "dir_id"
 
 #define PCID_CMD_WRITE           "write"
+#define PCID_CMD_READ_HEX        "read_hex"
 #define PCID_CMD_PCI_PATH        "pci_path"
 #define PCID_CMD_PCI_INFO        "pci_info"
 
tools/libs/light/libxl_pci.c +68 -57

151 lines not on this page · raw message

tools/libs/light/libxl_pcid.c +50 -0

62 lines not on this page · raw message

Signature · 1 line
2.17.1
#7 lore raw

PATCH 7/9 tools/libs/light: Make Libxl PCI get values from xl pcid instead of libxl side

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

pci_multifunction_check needs to use "ls" and "lstat" commands to get information from sysfs.
Add "is_exists" command processing to xl pcid daemon to make possible pci_multifunction_check read directories and check lstat by using xl pcid.

---
 tools/include/pcid.h          |  1 +
 tools/libs/light/libxl_pci.c  | 47 ++++++++++++++++++-----------------
 tools/libs/light/libxl_pcid.c | 47 +++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 23 deletions(-)
tools/include/pcid.h +1 -0
index f39011ecb8..5c8efbb435 100644
@@ -33,6 +33,7 @@
 
 #define PCID_CMD_WRITE           "write"
 #define PCID_CMD_READ_HEX        "read_hex"
+#define PCID_CMD_EXISTS          "exists"
 #define PCID_CMD_PCI_PATH        "pci_path"
 #define PCID_CMD_PCI_INFO        "pci_info"
 
tools/libs/light/libxl_pci.c +24 -23

69 lines not on this page · raw message

tools/libs/light/libxl_pcid.c +47 -0

65 lines not on this page · raw message

Signature · 1 line
2.17.1
#8 lore raw

PATCH 8/9 tools/libs/light: Add "unbind" and "read resources" commands to libxl PCI and xl pcid

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Send requests to xl pcid from libxl PCI to prevent the libxl PCI from reading / writing from / to the local sysfs directly.

"Unbind" command returns driver's path or "nolstat" result in success and NULL if writing to PCI path failed.

"Read resources" command returns an array of PCI resources - start, end and flags in success, NULL if getting resources from PCI path failed.

---
 tools/include/pcid.h          |   7 +++
 tools/libs/light/libxl_pci.c  |  99 ++++++++++++++++++--------------
 tools/libs/light/libxl_pcid.c | 105 ++++++++++++++++++++++++++++++++++
 3 files changed, 169 insertions(+), 42 deletions(-)
tools/include/pcid.h +7 -0
index 5c8efbb435..3153bafb19 100644
@@ -29,11 +29,13 @@
 #define PCID_MSG_FIELD_ARGS      "arguments"
 
 #define PCID_CMD_LIST            "ls"
+#define PCID_CMD_UNBIND          "unbind"
 #define PCID_CMD_DIR_ID          "dir_id"
 
 #define PCID_CMD_WRITE           "write"
 #define PCID_CMD_READ_HEX        "read_hex"
 #define PCID_CMD_EXISTS          "exists"
+#define PCID_CMD_READ_RESOURCES  "read_resources"
 #define PCID_CMD_PCI_PATH        "pci_path"
 #define PCID_CMD_PCI_INFO        "pci_info"
 
@@ -44,12 +46,17 @@
 
 #if defined(__linux__)
 #define SYSFS_PCIBACK_DRIVER   "/sys/bus/pci/drivers/pciback"
+#define SYSFS_PCI_DEV          "/sys/bus/pci/devices"
 #endif
 
 #define PCI_INFO_PATH "/libxl/pci"
 #define PCI_BDF_XSPATH         "%04x-%02x-%02x-%01x"
 #define PCI_BDF                "%04x:%02x:%02x.%01x"
 
+#define RESOURCE_START "start"
+#define RESOURCE_END   "end"
+#define RESOURCE_FLAGS "flags"
+
 int libxl_pcid_process(libxl_ctx *ctx);
 
 #endif /* PCID_H */
tools/libs/light/libxl_pci.c +57 -42

160 lines not on this page · raw message

tools/libs/light/libxl_pcid.c +105 -0

117 lines not on this page · raw message

Signature · 1 line
2.17.1
#9 lore raw

PATCH 9/9 tools/libs/light: Add "reset" and "remove" PCI dev commands to xl pcid daemon and libxl PCI

In reply to Anastasiia Lukianenko

From: Anastasiia Lukianenko <[email protected]>

Add "reset" command processing to xl pcid daemon.
Make possible sending "reset"/"remove" PCI device requests from libxl PCI to xl pcid daemon instead of using sysfs on libxl side.

---
 tools/include/pcid.h          |  1 +
 tools/libs/light/libxl_pci.c  | 94 +++++++++++++++++++----------------
 tools/libs/light/libxl_pcid.c | 63 +++++++++++++++++++++++
 3 files changed, 115 insertions(+), 43 deletions(-)
tools/include/pcid.h +1 -0
index 3153bafb19..38ea06c602 100644
@@ -30,6 +30,7 @@
 
 #define PCID_CMD_LIST            "ls"
 #define PCID_CMD_UNBIND          "unbind"
+#define PCID_CMD_RESET           "reset"
 #define PCID_CMD_DIR_ID          "dir_id"
 
 #define PCID_CMD_WRITE           "write"
tools/libs/light/libxl_pci.c +51 -43

131 lines not on this page · raw message

tools/libs/light/libxl_pcid.c +63 -0

75 lines not on this page · raw message

Signature · 1 line
2.17.1