PCID server
v3 cover PCID server
From: Dmytro Semenets <[email protected]>
PCID server used if domain has passthrough PCI controller and we wants assign some device to other domain.
pcid server should be launched in domain owns the PCI controller and process request from other domains.
pcid server needs if domain which owns the PCI controller is not Domain-0. Changes:
patch with subject "remove xenstore entries on vchan server closure" removed from patchset because it already merged.
patch with subject "Add pcid daemon to xl" divided on several patches because it was very large.
Fixed crash in some cases
Fixed memory leak
Fixed false client detection.
Dmytro Semenets (6):
tools/libs/light: Add vchan support to libxl tools/xl: Add pcid daemon to xl
tools/libs/light: pcid: implement is_device_assigned command tools/libs/light: pcid: implement reset_device command tools/libs/light: pcid: implement resource_list command tools/libs/light: pcid: implement write_bdf command
Oleksandr Andrushchenko (2):
tools: allow vchan XenStore paths more then 64 bytes long tools/libs/light: pcid: implement list_assignable command
Volodymyr Babchuk (2):
tools/light: pci: describe [MAKE|REVERT]_ASSIGNABLE commands tools/light: pci: move assign/revert logic to pcid
tools/configure | 8 +- tools/configure.ac | 1 + tools/helpers/Makefile | 4 +- tools/hotplug/FreeBSD/rc.d/xlpcid.in | 75 ++ tools/hotplug/Linux/init.d/xlpcid.in | 76 ++ tools/hotplug/Linux/systemd/Makefile | 1 + .../hotplug/Linux/systemd/xenpcid.service.in | 10 + tools/hotplug/NetBSD/rc.d/xlpcid.in | 75 ++ tools/include/pcid.h | 228 ++++ tools/libs/light/Makefile | 8 +- tools/libs/light/libxl_pci.c | 673 +++++----- tools/libs/light/libxl_pcid.c | 1110 +++++++++++++++++ tools/libs/light/libxl_vchan.c | 496 ++++++++ tools/libs/light/libxl_vchan.h | 94 ++ tools/libs/vchan/init.c | 28 +- tools/xl/Makefile | 5 +- tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 7 + tools/xl/xl_pcid.c | 81 ++ 19 files changed, 2613 insertions(+), 368 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/Linux/systemd/xenpcid.service.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.34.1
RFC PATCH v3 1/10 tools: allow vchan XenStore paths more then 64 bytes long
From: Oleksandr Andrushchenko <[email protected]>
Current vchan implementation, while dealing with XenStore paths, allocates 64 bytes buffer on the stack which may not be enough for some use-cases. Make the buffer longer to respect maximum allowed XenStore path of XENSTORE_ABS_PATH_MAX.
--- tools/libs/vchan/init.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-)
tools/libs/vchan/init.c +21 -7
@@ -249,7 +249,7 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_baseint ret =-1 ;struct xs_handle *xs;struct xs_permissions perms[2 ]; -char buf[64 ]; +char *buf;char ref[16 ];char * domid_str =NULL ;xs_transaction_t xs_trans =XBT_NULL ;
@@ -259,6 +259,10 @@ static int init_xs_srv(struct libxenvchan *ctrl, int domain, const char* xs_baseif (!ctrl->xs_path)return -1 ; + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) +return -1 ; + xs =xs_open (0 );if (!xs) goto fail;
@@ -280,14 +284,14 @@ retry_transaction: goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ring_ref); -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 )) goto fail_xs_open;snprintf (ref,sizeof ref,"%d" , ctrl->event_port); -snprintf (buf,sizeof buf,"%s/event-channel" , xs_base); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_base);if (!xs_write (xs, xs_trans, buf, ref,strlen (ref))) goto fail_xs_open;if (!xs_set_permissions (xs, xs_trans, buf, perms,2 ))
@@ -303,6 +307,7 @@ retry_transaction:free (domid_str);xs_close (xs); fail: +free (buf);return ret; }
@@ -419,13 +424,20 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, {struct libxenvchan *ctrl =malloc (sizeof (struct libxenvchan ));struct xs_handle *xs =NULL ; -char buf[64 ]; +char *buf;char *ref;int ring_ref;unsigned int len;if (!ctrl) -return 0 ; +return NULL ; + + buf =malloc (XENSTORE_ABS_PATH_MAX ); +if (!buf) { +free (ctrl); +return NULL ; + } + ctrl->ring =NULL ; ctrl->event =NULL ; ctrl->gnttab =NULL ;
@@ -436,8 +448,9 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,if (!xs) goto fail; +// find xenstore entry -snprintf (buf,sizeof buf,"%s/ring-ref" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/ring-ref" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;
@@ -445,7 +458,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger,free (ref);if (!ring_ref) goto fail; -snprintf (buf,sizeof buf,"%s/event-channel" , xs_path); +snprintf (buf,XENSTORE_ABS_PATH_MAX ,"%s/event-channel" , xs_path); ref =xs_read (xs,0 , buf, &len);if (!ref) goto fail;
@@ -475,6 +488,7 @@ struct libxenvchan *libxenvchan_client_init(struct xentoollog_logger *logger, out:if (xs)xs_close (xs); +free (buf);return ctrl; fail:libxenvchan_close (ctrl);
Signature · 1 line
2.34.1
RFC PATCH v3 2/10 tools/libs/light: Add vchan support to libxl
In reply to Dmytro SemenetsFrom: Dmytro Semenets <[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 | 488 +++++++++++++++++++++++++++++++++ tools/libs/light/libxl_vchan.h | 92 +++++++ tools/xl/Makefile | 3 +- 5 files changed, 588 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
@@ -20,7 +20,7 @@ $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxentoollog) $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenlight) $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenctrl) -xen-init-dom0: LDLIBS += $(call xenlibs-ldlibs,ctrl toollog store light) +xen-init-dom0: LDLIBS += $(call xenlibs-ldlibs,ctrl toollog store light vchan) INIT_XENSTORE_DOMAIN_OBJS = init-xenstore-domain.o init-dom-json.o $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
@@ -29,7 +29,7 @@ $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenstore) $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenlight) $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h -init-xenstore-domain: LDLIBS += $(call xenlibs-ldlibs,toollog store ctrl guest light) +init-xenstore-domain: LDLIBS += $(call xenlibs-ldlibs,toollog store ctrl guest light vchan) INIT_DOM0LESS_OBJS = init-dom0less.o init-dom-json.o $(INIT_DOM0LESS_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
tools/libs/light/Makefile +4 -3
@@ -71,6 +71,7 @@ OBJS-y += libxl.o OBJS-y += libxl_create.o OBJS-y += libxl_dm.o OBJS-y += libxl_pci.o +OBJS-y += libxl_vchan.o OBJS-y += libxl_dom.o OBJS-y += libxl_exec.o OBJS-y += libxl_xshelp.o
@@ -170,7 +171,7 @@ LDLIBS-y += $(PTHREAD_LIBS) LDLIBS-y += -lyajl LDLIBS += $(LDLIBS-y) -$(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h +$(OBJS-y) $(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
@@ -241,13 +242,13 @@ libxenlight_test.so: $(PIC_OBJS) $(LIBXL_TEST_OBJS) $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS) $(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:: $(LIBHEADERS) libxl-save-helper $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
tools/libs/light/libxl_vchan.c new file +488 -0
488 lines not on this page · raw message
tools/libs/light/libxl_vchan.h new file +92 -0
92 lines not on this page · raw message
tools/xl/Makefile +2 -1
@@ -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)
@@ -33,7 +34,7 @@ $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs i 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.34.1
RFC PATCH v3 3/10 tools/xl: Add pcid daemon to xl
In reply to Dmytro SemenetsFrom: Dmytro Semenets <[email protected]>
Add draft version of pcid server (based on vchan-node2), which can receive messages from the client.
Add essential functionality to handle pcid protocol:
- define required constants
- prepare for handling remote requests
- prepare and send an error packet
--- tools/configure | 8 +- tools/configure.ac | 1 + tools/hotplug/FreeBSD/rc.d/xlpcid.in | 75 +++ tools/hotplug/Linux/init.d/xlpcid.in | 76 ++++ tools/hotplug/Linux/systemd/Makefile | 1 + .../hotplug/Linux/systemd/xenpcid.service.in | 10 + tools/hotplug/NetBSD/rc.d/xlpcid.in | 75 +++ tools/include/pcid.h | 94 ++++ tools/libs/light/Makefile | 1 + tools/libs/light/libxl_pci.c | 128 ++++++ tools/libs/light/libxl_pcid.c | 428 ++++++++++++++++++ tools/xl/Makefile | 4 +- tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 7 + tools/xl/xl_pcid.c | 81 ++++ 15 files changed, 986 insertions(+), 4 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/Linux/systemd/xenpcid.service.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/xl/xl_pcid.c
tools/configure +6 -2
@@ -2455,7 +2455,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -ac_config_files="$ac_config_files ../config/Tools.mk hotplug/common/hotplugpath.sh 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/libs/xs/paths.ml ocaml/xenstored/paths.ml ocaml/xenstored/oxenstored.conf" +ac_config_files="$ac_config_files ../config/Tools.mk hotplug/common/hotplugpath.sh 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/libs/xs/paths.ml ocaml/xenstored/paths.ml ocaml/xenstored/oxenstored.conf" ac_config_headers="$ac_config_headers config.h"
@@ -10081,7 +10081,7 @@ fi if test "x$systemd" = "xy"; then : - ac_config_files="$ac_config_files hotplug/Linux/systemd/proc-xen.mount hotplug/Linux/systemd/xen-init-dom0.service hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service hotplug/Linux/systemd/xen-watchdog.service hotplug/Linux/systemd/xenconsoled.service hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xenstored.service" + ac_config_files="$ac_config_files hotplug/Linux/systemd/proc-xen.mount hotplug/Linux/systemd/xen-init-dom0.service hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service hotplug/Linux/systemd/xen-watchdog.service hotplug/Linux/systemd/xenconsoled.service hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xenstored.service hotplug/Linux/systemd/xenpcid.service" fi
@@ -10946,8 +10946,10 @@ do "hotplug/common/hotplugpath.sh") CONFIG_FILES="$CONFIG_FILES hotplug/common/hotplugpath.sh" ;; "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" ;;
@@ -10958,6 +10960,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/libs/xs/paths.ml") CONFIG_FILES="$CONFIG_FILES ocaml/libs/xs/paths.ml" ;; "ocaml/xenstored/paths.ml") CONFIG_FILES="$CONFIG_FILES ocaml/xenstored/paths.ml" ;; "ocaml/xenstored/oxenstored.conf") CONFIG_FILES="$CONFIG_FILES ocaml/xenstored/oxenstored.conf" ;;
@@ -10970,6 +10973,7 @@ do "hotplug/Linux/systemd/xendomains.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xendomains.service" ;; "hotplug/Linux/systemd/xendriverdomain.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xendriverdomain.service" ;; "hotplug/Linux/systemd/xenstored.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xenstored.service" ;; + "hotplug/Linux/systemd/xenpcid.service") CONFIG_FILES="$CONFIG_FILES hotplug/Linux/systemd/xenpcid.service" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac
tools/configure.ac +1 -0
@@ -489,6 +489,7 @@ AS_IF([test "x$systemd" = "xy"], [ hotplug/Linux/systemd/xendomains.service hotplug/Linux/systemd/xendriverdomain.service hotplug/Linux/systemd/xenstored.service + hotplug/Linux/systemd/xenpcid.service ]) ])
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/Linux/systemd/Makefile +1 -0
@@ -12,6 +12,7 @@ XEN_SYSTEMD_SERVICE += xendomains.service XEN_SYSTEMD_SERVICE += xen-watchdog.service XEN_SYSTEMD_SERVICE += xen-init-dom0.service XEN_SYSTEMD_SERVICE += xendriverdomain.service +XEN_SYSTEMD_SERVICE += xenpcid.service ALL_XEN_SYSTEMD := $(XEN_SYSTEMD_MODULES) \ $(XEN_SYSTEMD_MOUNT) \
tools/hotplug/Linux/systemd/xenpcid.service.in new file +10 -0
@@ -0,0 +1,10 @@ +[Unit] +Description=Xen PCI host daemon +ConditionVirtualization=xen + +[Service] +Type=forking +ExecStart=@sbindir@/xl pcid + +[Install] +WantedBy=multi-user.target
tools/hotplug/NetBSD/rc.d/xlpcid.in new file +75 -0
75 lines not on this page · raw message
tools/include/pcid.h new file +94 -0
94 lines not on this page · raw message
tools/libs/light/Makefile +1 -0
@@ -71,6 +71,7 @@ OBJS-y += libxl.o OBJS-y += libxl_create.o OBJS-y += libxl_dm.o OBJS-y += libxl_pci.o +OBJS-y += libxl_pcid.o OBJS-y += libxl_vchan.o OBJS-y += libxl_dom.o OBJS-y += libxl_exec.o
tools/libs/light/libxl_pci.c +128 -0
140 lines not on this page · raw message
tools/libs/light/libxl_pcid.c new file +428 -0
428 lines not on this page · raw message
tools/xl/Makefile +2 -2
@@ -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
@@ -34,7 +34,7 @@ $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs i 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
@@ -201,6 +201,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
@@ -545,6 +545,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 +81 -0
81 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [RFC PATCH v3 03/10] tools/xl: Add pcid daemon to xl
tools/include/pcid.h
Quoted 5 lines · Dmytro Semenets
tools/include/pcid.h new file +0
-0
Please, rename it "xen-pcid.h". We should try to use our own namespace to avoid issue with another unrelated project using "pcid.h" as well.
Also, it would be a good idea to introduce this file and/or a protocol description in a separate patch.
Quoted 7 lines
tools/include/pcid.h new file +6
-0@@ -0,0 +1,94 @@ +/* +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
tools/include/pcid.h line 16
Quoted 10 lines
tools/include/pcid.h new file +10
-0+ 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/>.
This licence boilerplate could be replace by
/* SPDX-License-Identifier: LGPL-2.1+ */
at the top of the file.
Quoted 18 lines
tools/include/pcid.h new file +18
-0+*/ + +#ifndef PCID_H +#define PCID_H + +#define PCID_SRV_NAME "pcid" +#define PCID_XS_TOKEN "pcid-token" + +#define PCI_RECEIVE_BUFFER_SIZE 4096 +#define PCI_MAX_SIZE_RX_BUF MB(1) + +/* +******************************************************************************* +* Common request and response structures used be the pcid remote protocol are +* described below. +******************************************************************************* +* Request: +* +-------------+--------------+----------------------------------------------+
tools/include/pcid.h line 44
Quoted 10 lines
tools/include/pcid.h new file +10
-0+* | Field | Type | Comment | +* +-------------+--------------+----------------------------------------------+ +* | cmd | string | String identifying the command | +* +-------------+--------------+----------------------------------------------+ +* +* Response: +* +-------------+--------------+----------------------------------------------+ +* | Field | Type | Comment | +* +-------------+--------------+----------------------------------------------+ +* | resp | string | Command string as in the request |
Instead of sending back the command, you could use a new field "id" that would be set by the client, and send back as is by the server. A command could be sent several time, but with an "id", the client can set a different id to been able to differentiate which commands failed.
"id" field is been usable by QEMU's QMP protocol for example.
Quoted 11 lines
tools/include/pcid.h new file +11
-0+* +-------------+--------------+----------------------------------------------+ +* | error | string | "okay", "failed" | +* +-------------+--------------+----------------------------------------------+ +* | error_desc | string | Optional error description string | +* +-------------+--------------+----------------------------------------------+ +* +* Notes. +* 1. Every request and response must contain the above mandatory structures. +* 2. In case if a bad packet or an unknown command received by the server side +* a valid reply with the corresponding error code must be sent to the client. +*
tools/include/pcid.h line 65
Quoted 10 lines
tools/include/pcid.h new file +10
-0+* Requests and responses, which require SBDF as part of their payload, must +* use the following convention for encoding SBDF value: +* +* pci_device object: +* +-------------+--------------+----------------------------------------------+ +* | Field | Type | Comment | +* +-------------+--------------+----------------------------------------------+ +* | sbdf | string | SBDF string in form SSSS:BB:DD.F | +* +-------------+--------------+----------------------------------------------+ +*/
It could be nice to have a better description of the protocol, it's not even spelled out that JSON is been used.
Also what are the possible commands with there arguments?
Quoted 5 lines
tools/include/pcid.h new file +5
-0+ +#define PCID_MSG_FIELD_CMD "cmd" + +#define PCID_MSG_FIELD_RESP "resp" +#define PCID_MSG_FIELD_ERR "error"
tools/include/pcid.h line 80
Quoted 10 lines
tools/include/pcid.h new file +10
-0+#define PCID_MSG_FIELD_ERR_DESC "error_desc" + +/* pci_device object fields. */ +#define PCID_MSG_FIELD_SBDF "sbdf" + +#define PCID_MSG_ERR_OK "okay" +#define PCID_MSG_ERR_FAILED "failed" +#define PCID_MSG_ERR_NA "NA" + +#define PCID_SBDF_FMT "%04x:%02x:%02x.%01x"
Thanks,
Signature · 1 line
Anthony PERARD
RFC PATCH v3 4/10 tools/libs/light: pcid: implement list_assignable command
In reply to Dmytro SemenetsFrom: Oleksandr Andrushchenko <[email protected]>
--- tools/include/pcid.h | 19 ++++++++++++ tools/libs/light/libxl_pci.c | 54 ++++++++++++++++++++++----------- tools/libs/light/libxl_pcid.c | 56 ++++++++++++++++++++++++++++++----- 3 files changed, 103 insertions(+), 26 deletions(-)
tools/include/pcid.h +19 -0
@@ -79,6 +79,25 @@#define PCID_SBDF_FMT "%04x:%02x:%02x.%01x" +/* +******************************************************************************* +* List assignable devices +* +* This command lists PCI devices that can be passed through to a guest domain. +* +* Request (see other mandatory fields above): +* - "cmd" field of the request must be set to "list_assignable". +* +* Response (see other mandatory fields above): +* - "resp" field of the response must be set to "list_assignable". +* Command specific response data: +* +-------------+--------------+----------------------------------------------+ +* | devices | list | List of of pci_device objects | +* +-------------+--------------+----------------------------------------------+ +*/ +#define PCID_CMD_LIST_ASSIGNABLE "list_assignable" +#define PCID_MSG_FIELD_DEVICES "devices" +int libxl_pcid_process (libxl_ctx *ctx);#endif /* PCID_H */
tools/libs/light/libxl_pci.c +36 -18
97 lines not on this page · raw message
tools/libs/light/libxl_pcid.c +48 -8
68 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 5/10 tools/light: pci: describe [MAKE|REVERT]_ASSIGNABLE commands
In reply to Dmytro SemenetsFrom: Volodymyr Babchuk <[email protected]>
Add protocol for two more commands, one to make a PCI device assignable, and other - to revert its state back.
--- tools/include/pcid.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
tools/include/pcid.h +38 -0
@@ -98,6 +98,44 @@#define PCID_CMD_LIST_ASSIGNABLE "list_assignable"#define PCID_MSG_FIELD_DEVICES "devices" +/* +******************************************************************************* +* Make device assignable +* +* This command makes given device assignable by ensuring that OS +* will not try to access it. +* +* Request (see other mandatory fields above): +* - "cmd" field of the request must be set to "make_assignable". +* - "sbdf" SBDF of the device in format defined by PCID_SBDF_FMT. +* - "rebind" = true if daemon needs to save original driver name, +* so device later can be rebound back. +* +* Response (see other mandatory fields above): +* - "resp" field of the response must be set to "make_assignable". +*/ +#define PCID_CMD_MAKE_ASSIGNABLE "make_assignable" +#define PCID_MSG_FIELD_REBIND "rebind" + +/* +******************************************************************************* +* Revert device from assignable state +* +* This command reverts effect of "make_assignable" command. Basically, +* now device can be used by OS again. +* +* Request (see other mandatory fields above): +* - "cmd" field of the request must be set to "revert_assignable". +* - "sbdf" SBDF of the device in format defined by PCID_SBDF_FMT. +* - "rebind" = true if daemon needs to rebind device back to it's +* original driver, which name was saved by "make_assignable" command +* +* Response (see other mandatory fields above): +* - "resp" field of the response must be set to "revert_assignable". +*/ +#define PCID_CMD_REVERT_ASSIGNABLE "revert_assignable" + +int libxl_pcid_process (libxl_ctx *ctx);#endif /* PCID_H */
Signature · 1 line
2.34.1
RFC PATCH v3 6/10 tools/light: pci: move assign/revert logic to pcid
In reply to Dmytro SemenetsFrom: Volodymyr Babchuk <[email protected]>
Implement commands MAKE_ASSIGNABLE and REVERT_ASSIGNABLE in pcid in the same way as they were implemented in libxl_pci.c
Replace original logic in libxl_pci.c by calling appropriate functions from pcid.
This is quite huge patch, as lots of code were moved from lixbl_pci.c to libxl_pcid.c.
--- tools/libs/light/libxl_pci.c | 292 +++++-------------------- tools/libs/light/libxl_pcid.c | 396 ++++++++++++++++++++++++++++++++++ 2 files changed, 454 insertions(+), 234 deletions(-)
tools/libs/light/libxl_pci.c +58 -234
@@ -82,6 +82,10 @@ static int pci_handle_response(libxl__gc *gc,if (strcmp (command_name,PCID_CMD_LIST_ASSIGNABLE ) ==0 ) ret =process_list_assignable (gc, response, result); +else if (strcmp (command_name,PCID_CMD_MAKE_ASSIGNABLE ) ==0 ) + *result =libxl__json_object_alloc (gc,JSON_NULL ); +else if (strcmp (command_name,PCID_CMD_REVERT_ASSIGNABLE ) ==0 ) + *result =libxl__json_object_alloc (gc,JSON_NULL );return ret; }
@@ -636,44 +640,6 @@ void libxl_device_pci_assignable_list_free(libxl_device_pci *list, int num)free (list); } -/* Unbind device from its current driver, if any. If driver_path is non-NULL, -* store the path to the original driver in it. */ -static int sysfs_dev_unbind (libxl__gc *gc,libxl_device_pci *pci, -char **driver_path) -{ -char * spath, *dp =NULL ; -struct stat st; - - spath =GCSPRINTF (SYSFS_PCI_DEV "/" PCI_BDF "/driver" , - pci->domain, - pci->bus, - pci->dev, - pci->func); -if ( !lstat (spath, &st) ) { -/* Find the canonical path to the driver. */ - dp =libxl__zalloc (gc,PATH_MAX ); - dp =realpath (spath, dp); -if ( !dp ) { -LOGE (ERROR ,"realpath() failed" ); -return -1 ; - } - -LOG (DEBUG ,"Driver re-plug path: %s" , dp); - -/* Unbind from the old driver */ - spath =GCSPRINTF ("%s/unbind" , dp); -if (sysfs_write_bdf (gc, spath, pci) <0 ) { -LOGE (ERROR ,"Couldn't unbind device" ); -return -1 ; - } - } - -if ( driver_path ) - *driver_path = dp; - -return 0 ; -} -static uint16_t sysfs_dev_get_vendor (libxl__gc *gc,libxl_device_pci *pci) { char *pci_device_vendor_path =
@@ -785,49 +751,6 @@ bool libxl__is_igd_vga_passthru(libxl__gc *gc,return false; } -/* -* A brief comment about slots. I don't know what slots are for; however, -* I have by experimentation determined: -* - Before a device can be bound to pciback, its BDF must first be listed -* in pciback/slots -* - The way to get the BDF listed there is to write BDF to -* pciback/new_slot -* - Writing the same BDF to pciback/new_slot is not idempotent; it results -* in two entries of the BDF in pciback/slots -* It's not clear whether having two entries in pciback/slots is a problem -* or not. Just to be safe, this code does the conservative thing, and -* first checks to see if there is a slot, adding one only if one does not -* already exist. -*/ - -/* Scan through /sys/.../pciback/slots looking for pci's BDF */ -static int pciback_dev_has_slot (libxl__gc *gc,libxl_device_pci *pci) -{ -FILE *f; -int rc =0 ; -unsigned dom, bus, dev, func; - - f =fopen (SYSFS_PCIBACK_DRIVER "/slots" ,"r" ); - -if (f ==NULL ) { -LOGE (ERROR ,"Couldn't open %s" ,SYSFS_PCIBACK_DRIVER "/slots" ); -return ERROR_FAIL ; - } - -while (fscanf (f,"%x:%x:%x.%d\n" , &dom, &bus, &dev, &func) ==4 ) { -if (dom == pci->domain - && bus == pci->bus - && dev == pci->dev - && func == pci->func) { - rc =1 ; - goto out; - } - } -out: -fclose (f); -return rc; -} -static int pciback_dev_is_assigned (libxl__gc *gc,libxl_device_pci *pci) {char * spath;
@@ -856,133 +779,34 @@ static int pciback_dev_is_assigned(libxl__gc *gc, libxl_device_pci *pci)return -1 ; } -static int pciback_dev_assign (libxl__gc *gc,libxl_device_pci *pci) -{ -int rc; - -if ( (rc =pciback_dev_has_slot (gc, pci)) <0 ) { -LOGE (ERROR ,"Error checking for pciback slot" ); -return ERROR_FAIL ; - }else if (rc ==0 ) { -if (sysfs_write_bdf (gc,SYSFS_PCIBACK_DRIVER "/new_slot" , - pci) <0 ) { -LOGE (ERROR ,"Couldn't bind device to pciback!" ); -return ERROR_FAIL ; - } - } - -if (sysfs_write_bdf (gc,SYSFS_PCIBACK_DRIVER "/bind" , pci) <0 ) { -LOGE (ERROR ,"Couldn't bind device to pciback!" ); -return ERROR_FAIL ; - } -return 0 ; -} - -static int pciback_dev_unassign (libxl__gc *gc,libxl_device_pci *pci) -{ -/* Remove from pciback */ -if (sysfs_dev_unbind (gc, pci,NULL ) <0 ) { -LOG (ERROR ,"Couldn't unbind device!" ); -return ERROR_FAIL ; - } - -/* Remove slot if necessary */ -if (pciback_dev_has_slot (gc, pci) >0 ) { -if (sysfs_write_bdf (gc,SYSFS_PCIBACK_DRIVER "/remove_slot" , - pci) <0 ) { -LOGE (ERROR ,"Couldn't remove pciback slot" ); -return ERROR_FAIL ; - } - } -return 0 ; -} -static int libxl__device_pci_assignable_add (libxl__gc *gc,libxl_device_pci *pci,int rebind) {libxl_ctx *ctx =libxl__gc_owner (gc); -unsigned dom, bus, dev, func; -char *spath, *driver_path =NULL ; -const char *name; +struct vchan_info *vchan;int rc; -struct stat st; - -/* Local copy for convenience */ - dom = pci->domain; - bus = pci->bus; - dev = pci->dev; - func = pci->func; - name = pci->name; - -/* Sanitise any name that is set */ -if (name) { -unsigned int i, n =strlen (name); +libxl__json_object *args, *result; -if (n >64 ) {/* Reasonable upper bound on name length */ -LOG (ERROR ,"Name too long" ); -return ERROR_FAIL ; - } - -for (i =0 ; i < n; i++) { -if (!isgraph (name[i])) { -LOG (ERROR ,"Names may only include printable characters" ); -return ERROR_FAIL ; - } - } - } - -/* See if the device exists */ - spath =GCSPRINTF (SYSFS_PCI_DEV "/" PCI_BDF , dom, bus, dev, func); -if (lstat (spath, &st) ) { -LOGE (ERROR ,"Couldn't lstat %s" , spath); -return ERROR_FAIL ; - } - -/* Check to see if it's already assigned to pciback */ - rc =pciback_dev_is_assigned (gc, pci); -if ( rc <0 ) { -return ERROR_FAIL ; - } -if ( rc ) { -LOG (WARN ,PCI_BDF " already assigned to pciback" , dom, bus, dev, func); - goto name; + vchan =pci_vchan_get_client (gc); +if (!vchan) { + rc =ERROR_NOT_READY ; + goto out; } -/* Check to see if there's already a driver that we need to unbind from */ -if (sysfs_dev_unbind (gc, pci, &driver_path ) ) { -LOG (ERROR ,"Couldn't unbind " PCI_BDF " from driver" , - dom, bus, dev, func); -return ERROR_FAIL ; - } + args =libxl__vchan_start_args (gc); -/* Store driver_path for rebinding to dom0 */ -if ( rebind ) { -if ( driver_path ) { -pci_info_xs_write (gc, pci,"driver_path" , driver_path); - }else if ( (driver_path = -pci_info_xs_read (gc, pci,"driver_path" )) !=NULL ) { -LOG (INFO ,PCI_BDF " not bound to a driver, will be rebound to %s" , - dom, bus, dev, func, driver_path); - }else { -LOG (WARN ,PCI_BDF " not bound to a driver, will not be rebound." , - dom, bus, dev, func); - } - }else { -pci_info_xs_remove (gc, pci,"driver_path" ); - } +libxl__vchan_arg_add_string (gc, args,PCID_MSG_FIELD_SBDF , +GCSPRINTF (PCID_SBDF_FMT , pci->domain, + pci->bus, pci->dev, pci->func)); +libxl__vchan_arg_add_bool (gc, args,PCID_MSG_FIELD_REBIND , rebind); -if (pciback_dev_assign (gc, pci) ) { -LOG (ERROR ,"Couldn't bind device to pciback!" ); -return ERROR_FAIL ; + result =vchan_send_command (gc, vchan,PCID_CMD_MAKE_ASSIGNABLE , args); +if (!result) { + rc =ERROR_FAIL ; + goto vchan_free; } -name: -if (name) -pci_info_xs_write (gc, pci,"name" , name); -else -pci_info_xs_remove (gc, pci,"name" ); -/* * DOMID_IO is just a sentinel domain, without any actual mappings, * so always pass XEN_DOMCTL_DEV_RDM_RELAXED to avoid assignment being
@@ -990,12 +814,15 @@ name:*/ rc =xc_assign_device (ctx->xch,DOMID_IO ,pci_encode_bdf (pci),XEN_DOMCTL_DEV_RDM_RELAXED ); -if ( rc <0 ) { -LOG (ERROR ,"failed to quarantine " PCI_BDF , dom, bus, dev, func); -return ERROR_FAIL ; - } +if ( rc <0 ) +LOG (ERROR ,"failed to quarantine " PCI_BDF , pci->domain, pci->bus, + pci->dev, pci->func); -return 0 ; +vchan_free: +pci_vchan_free (gc, vchan); + +out: +return rc; }static int name2bdf (libxl__gc *gc,libxl_device_pci *pci)
@@ -1038,13 +865,8 @@ static int libxl__device_pci_assignable_remove(libxl__gc *gc, {libxl_ctx *ctx =libxl__gc_owner (gc);int rc; -char *driver_path; - -/* If the device is named then we need to look up the BDF */ -if (pci->name) { - rc =name2bdf (gc, pci); -if (rc)return rc; - } +struct vchan_info *vchan; +libxl__json_object *args, *temp_obj, *result;/* De-quarantine */ rc =xc_deassign_device (ctx->xch,DOMID_IO ,pci_encode_bdf (pci));
@@ -1054,41 +876,43 @@ static int libxl__device_pci_assignable_remove(libxl__gc *gc,return ERROR_FAIL ; } -/* Unbind from pciback */ -if ( (rc =pciback_dev_is_assigned (gc, pci)) <0 ) { -return ERROR_FAIL ; - }else if ( rc ) { -pciback_dev_unassign (gc, pci); - }else { -LOG (WARN ,"Not bound to pciback" ); + vchan =pci_vchan_get_client (gc); +if (!vchan) { + rc =ERROR_NOT_READY ; + goto out; } -/* Rebind if necessary */ - driver_path =pci_info_xs_read (gc, pci,"driver_path" ); + args =libxl__json_object_alloc (gc,JSON_MAP ); + temp_obj =libxl__json_object_alloc (gc,JSON_STRING ); +if (!temp_obj) { + rc =ERROR_NOMEM ; + goto vchan_free; + } + temp_obj->u.string =GCSPRINTF (PCID_SBDF_FMT , pci->domain, pci->bus, + pci->dev, pci->func); +flexarray_append_pair (args->u.map,PCID_MSG_FIELD_SBDF , temp_obj); -if ( driver_path ) { -if ( rebind ) { -LOG (INFO ,"Rebinding to driver at %s" , driver_path); + args =libxl__json_object_alloc (gc,JSON_MAP ); + temp_obj =libxl__json_object_alloc (gc,JSON_BOOL ); +if (!temp_obj) { + rc =ERROR_NOMEM ; + goto vchan_free; + } -if (sysfs_write_bdf (gc, -GCSPRINTF ("%s/bind" , driver_path), - pci) <0 ) { -LOGE (ERROR ,"Couldn't bind device to %s" , driver_path); -return -1 ; - } + temp_obj->u.b = rebind; +flexarray_append_pair (args->u.map,PCID_MSG_FIELD_REBIND , temp_obj); -pci_info_xs_remove (gc, pci,"driver_path" ); - } - }else { -if ( rebind ) { -LOG (WARN , -"Couldn't find path for original driver; not rebinding" ); - } + result =vchan_send_command (gc, vchan,PCID_CMD_REVERT_ASSIGNABLE , args); +if (!result) { + rc =ERROR_FAIL ; + goto vchan_free; } -pci_info_xs_remove (gc, pci,"name" ); +vchan_free: +pci_vchan_free (gc, vchan); -return 0 ; +out: +return rc; } int libxl_device_pci_assignable_add(libxl_ctx *ctx, libxl_device_pci *pci,
tools/libs/light/libxl_pcid.c +396 -0
414 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 7/10 tools/libs/light: pcid: implement is_device_assigned command
In reply to Dmytro SemenetsFrom: Dmytro Semenets <[email protected]>
--- tools/include/pcid.h | 19 ++++++++++++++++ tools/libs/light/libxl_pci.c | 43 +++++++++++++++++++---------------- tools/libs/light/libxl_pcid.c | 34 ++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 21 deletions(-)
tools/include/pcid.h +19 -0
@@ -135,6 +135,25 @@*/ #define PCID_CMD_REVERT_ASSIGNABLE "revert_assignable" +/* +******************************************************************************* +* Check is device assigned +* +* This command checks device is assigned +* +* Request (see other mandatory fields above): +* - "cmd" field of the request must be set to "is_device_assigned". +* - "sbdf" SBDF of the device in format defined by PCID_SBDF_FMT. +* +* Response (see other mandatory fields above): +* - "resp" field of the response must be set to "is_device_assigned". +* Command specific response data: +* +-------------+--------------+----------------------------------------------+ +* | result | bool | true if device assigned | +* +-------------+--------------+----------------------------------------------+ +*/ +#define PCID_CMD_IS_ASSIGNED "is_device_assigned" +#define PCID_MSG_FIELD_RESULT "result"int libxl_pcid_process (libxl_ctx *ctx);
tools/libs/light/libxl_pci.c +23 -20
60 lines not on this page · raw message
tools/libs/light/libxl_pcid.c +33 -1
@@ -147,7 +147,7 @@ static int pciback_dev_is_assigned(libxl__gc *gc, unsigned int domain,if (rc <0 && errno ==ENOENT )return 0 ;LOGE (ERROR ,"Accessing %s" , spath); -return -1 ; +return 0 ; }#define PCID_INFO_PATH "pcid"
@@ -335,6 +335,35 @@ static int pciback_dev_assign(libxl__gc *gc, unsigned int domain,return 0 ; } +static int process_pciback_dev_is_assigned (libxl__gc *gc,yajl_gen gen, +char *command_name, +const struct libxl__json_object *request, +struct libxl__json_object **response) +{ +const struct libxl__json_object *json_o; +unsigned int dom, bus, dev, func; +int rc; + +libxl__yajl_gen_asciiz (gen,PCID_MSG_FIELD_RESULT ); + *response =libxl__json_object_alloc (gc,JSON_BOOL ); + json_o =libxl__json_map_get (PCID_MSG_FIELD_SBDF , request,JSON_STRING ); +if (!json_o) { +make_error_reply (gc, gen,"No mandatory parameter 'sbdf'" , command_name); +return ERROR_FAIL ; + } + +if (sscanf (libxl__json_object_get_string (json_o),PCID_SBDF_FMT , + &dom, &bus, &dev, &func) !=4 ) { +make_error_reply (gc, gen,"Can't parse SBDF" , command_name); +return ERROR_FAIL ; + } + rc =pciback_dev_is_assigned (gc, dom, bus, dev, func); +if (rc <0 ) +return ERROR_FAIL ; + (*response)->u.b = rc; +return 0 ; +} + static int process_make_assignable(libxl__gc *gc, yajl_gen gen, char *command_name, const struct libxl__json_object *request,
@@ -538,6 +567,9 @@ static int pcid_handle_request(libxl__gc *gc, yajl_gen gen,else if (strcmp (command_name,PCID_CMD_REVERT_ASSIGNABLE ) ==0 ) ret =process_revert_assignable (gc, gen, command_name, request, &command_response); +else if (strcmp (command_name,PCID_CMD_IS_ASSIGNED ) ==0 ) + ret =process_pciback_dev_is_assigned (gc, gen, command_name, + request, &command_response);else {/* * This is an unsupported command: make a reply and proceed over
Signature · 1 line
2.34.1
RFC PATCH v3 8/10 tools/libs/light: pcid: implement reset_device command
In reply to Dmytro SemenetsFrom: Dmytro Semenets <[email protected]>
--- tools/include/pcid.h | 15 ++++++++ tools/libs/light/libxl_pci.c | 52 +++++++++++---------------- tools/libs/light/libxl_pcid.c | 66 +++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 31 deletions(-)
tools/include/pcid.h +15 -0
@@ -155,6 +155,21 @@#define PCID_CMD_IS_ASSIGNED "is_device_assigned"#define PCID_MSG_FIELD_RESULT "result" +/* +******************************************************************************* +* Reset PCI device +* +* This command resets PCI device +* +* Request (see other mandatory fields above): +* - "cmd" field of the request must be set to "reset_device". +* - "sbdf" SBDF of the device in format defined by PCID_SBDF_FMT. +* +* Response (see other mandatory fields above): +* - "resp" field of the response must be set to "reset_device". +*/ +#define PCID_CMD_RESET_DEVICE "reset_device" +int libxl_pcid_process (libxl_ctx *ctx);#endif /* PCID_H */
tools/libs/light/libxl_pci.c +21 -31
65 lines not on this page · raw message
tools/libs/light/libxl_pcid.c +66 -0
78 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v3 9/10 tools/libs/light: pcid: implement resource_list command
In reply to Dmytro SemenetsFrom: Dmytro Semenets <[email protected]>
--- tools/include/pcid.h | 26 ++++++++ tools/libs/light/libxl_pci.c | 63 ++++++++++--------- tools/libs/light/libxl_pcid.c | 110 +++++++++++++++++++++++++++++++++ tools/libs/light/libxl_vchan.c | 8 +++ tools/libs/light/libxl_vchan.h | 4 +- 5 files changed, 180 insertions(+), 31 deletions(-)
tools/include/pcid.h +26 -0
@@ -155,6 +155,32 @@#define PCID_CMD_IS_ASSIGNED "is_device_assigned"#define PCID_MSG_FIELD_RESULT "result" +/* +******************************************************************************* +* Get device resources +* +* This command returns resource list of device +* +* Request (see other mandatory fields above): +* - "cmd" field of the request must be set to "resource_list". +* - "sbdf" SBDF of the device in format defined by PCID_SBDF_FMT. +* +* Response (see other mandatory fields above): +* - "resp" field of the response must be set to "resource_list". +* Command specific response data: +* +-------------+--------------+----------------------------------------------+ +* | resources | map | key 'iomem' - list of memory regions | +* | | | key 'irqs' - list of irqs | +* +-------------+--------------+----------------------------------------------+ +*/ +#define PCID_CMD_RESOURCE_LIST "resource_list" +/* Arguments */ +#define PCID_MSG_FIELD_DOMID "domid" +/* Result */ +#define PCID_MSG_FIELD_RESOURCES "resources" +#define PCID_RESULT_KEY_IOMEM "iomem" +#define PCID_RESULT_KEY_IRQS "irqs" +/* ******************************************************************************* * Reset PCI device
tools/libs/light/libxl_pci.c +33 -30
142 lines not on this page · raw message
tools/libs/light/libxl_pcid.c +110 -0
128 lines not on this page · raw message
tools/libs/light/libxl_vchan.c +8 -0
@@ -99,6 +99,14 @@ void libxl__vchan_arg_add_bool(libxl__gc *gc, libxl__json_object *args, obj->u.b = val; } +void libxl__vchan_arg_add_integer (libxl__gc *gc,libxl__json_object *args, +char *key,int val) +{ +libxl__json_object *obj =libxl__vchan_arg_new (gc,JSON_INTEGER , args, key); + + obj->u.i = val; +} +static void reset_yajl_generator (struct vchan_state *state) {yajl_gen_clear (state->gen);
tools/libs/light/libxl_vchan.h +3 -1
@@ -58,7 +58,9 @@ static inline libxl__json_object *libxl__vchan_start_args(libxl__gc *gc)void libxl__vchan_arg_add_string (libxl__gc *gc,libxl__json_object *args,char *key,char *val);void libxl__vchan_arg_add_bool (libxl__gc *gc,libxl__json_object *args, -char *key,bool val); +char *key,bool val); +void libxl__vchan_arg_add_integer (libxl__gc *gc,libxl__json_object *args, +char *key,int val);libxl__json_object *vchan_send_command (libxl__gc *gc,struct vchan_info *vchan,char *cmd,libxl__json_object *args);
Signature · 1 line
2.34.1
RFC PATCH v3 10/10 tools/libs/light: pcid: implement write_bdf command
In reply to Dmytro SemenetsFrom: Dmytro Semenets <[email protected]>
--- tools/include/pcid.h | 17 +++++++++ tools/libs/light/libxl_pci.c | 67 ++++++++++++++++++----------------- tools/libs/light/libxl_pcid.c | 38 ++++++++++++++++++++ 3 files changed, 90 insertions(+), 32 deletions(-)
tools/include/pcid.h +17 -0
@@ -181,6 +181,23 @@#define PCID_RESULT_KEY_IOMEM "iomem"#define PCID_RESULT_KEY_IRQS "irqs" +/* +******************************************************************************* +* Write BDF values to the pciback sysfs path +* +* This command resets PCI device +* +* Request (see other mandatory fields above): +* - "cmd" field of the request must be set to "write_bdf". +* - "sbdf" SBDF of the device in format defined by PCID_SBDF_FMT. +* - "name" name of sysfs file of pciback driver +* +* Response (see other mandatory fields above): +* - "resp" field of the response must be set to "write_bdf". +*/ +#define PCID_CMD_WRITE_BDF "write_bdf" +#define PCID_MSG_FIELD_NAME "name" +/* ******************************************************************************* * Reset PCI device
tools/libs/light/libxl_pci.c +35 -32
104 lines not on this page · raw message
tools/libs/light/libxl_pcid.c +38 -0
@@ -257,6 +257,41 @@ static int pciback_dev_is_assigned(libxl__gc *gc, unsigned int domain,return 0 ; } +static int process_pciback_write_bdf (libxl__gc *gc,yajl_gen gen, +char *command_name, +const struct libxl__json_object *request, +struct libxl__json_object **response) +{ +const struct libxl__json_object *json_o; +unsigned int dom, bus, dev, func; +int rc =0 ; +const char *name; +char *spath; + + json_o =libxl__json_map_get (PCID_MSG_FIELD_SBDF , request,JSON_STRING ); +if (!json_o) { +make_error_reply (gc, gen,"No mandatory parameter 'sbdf'" , command_name); +return ERROR_FAIL ; + } + +if (sscanf (libxl__json_object_get_string (json_o),PCID_SBDF_FMT , + &dom, &bus, &dev, &func) !=4 ) { +make_error_reply (gc, gen,"Can't parse SBDF" , command_name); +return ERROR_FAIL ; + } + + json_o =libxl__json_map_get (PCID_MSG_FIELD_NAME , request,JSON_STRING ); +if (!json_o) { +make_error_reply (gc, gen,"No mandatory parameter 'rebind'" , command_name); +return ERROR_FAIL ; + } + + name =libxl__json_object_get_string (json_o); + spath =GCSPRINTF ("%s/%s" ,SYSFS_PCIBACK_DRIVER , name); +LOG (WARN ,"sysf_write_bdf(%s, %d, %d, %d, %d)" , spath, dom, bus, dev,func); +return rc; +} +#define PCID_INFO_PATH "pcid"#define PCID_BDF_XSPATH "%04x-%02x-%02x-%01x"
@@ -746,6 +781,9 @@ static int pcid_handle_request(libxl__gc *gc, yajl_gen gen,else if (strcmp (command_name,PCID_CMD_RESOURCE_LIST ) ==0 ) ret =process_list_resources (gc, gen, command_name, request, &command_response); +else if (strcmp (command_name,PCID_CMD_WRITE_BDF ) ==0 ) + ret =process_pciback_write_bdf (gc, gen, command_name, + request, &command_response);else {/* * This is an unsupported command: make a reply and proceed over
Signature · 1 line
2.34.1
Quoted 5 lines · Dmytro Semenets
PCID server used if domain has passthrough PCI controller and we wants assign some device to other domain.
pcid server should be launched in domain owns the PCI controller and process request from other domains.
pcid server needs if domain which owns the PCI controller is not Domain-0.
Hi Dmytro,
Thanks for the patch.
I did already ask in the previous version[1], but could you write a new binary for pcid? I still don't think libxl is appropriate for this kind of tool. libxl is supposed to be used to manage a VM. Or could you explain why it is implemented in xl/libxl?
[1] https://lore.kernel.org/xen-devel/[email protected]/
Thanks,
Signature · 1 line
Anthony PERARD