From: Ross Lagerwall Date: Wed, 18 Oct 2017 13:42:32 +0000 (+0100) Subject: tools/libs/evtchn: Add support for restricting a handle X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~1057 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6b6500b3cbaa06e7097f84f4851275f456cdd2ca;p=xen.git tools/libs/evtchn: Add support for restricting a handle Implement support for restricting evtchn handles to a particular domain on Linux by calling the IOCTL_EVTCHN_RESTRICT_DOMID ioctl (support added in Linux v4.8). Signed-off-by: Ross Lagerwall Acked-by: Ian Jackson Release-acked-by: Julien Grall --- diff --git a/tools/include/xen-sys/Linux/evtchn.h b/tools/include/xen-sys/Linux/evtchn.h index 938d4da2bd..08ee0b7c33 100644 --- a/tools/include/xen-sys/Linux/evtchn.h +++ b/tools/include/xen-sys/Linux/evtchn.h @@ -85,4 +85,19 @@ struct ioctl_evtchn_notify { #define IOCTL_EVTCHN_RESET \ _IOC(_IOC_NONE, 'E', 5, 0) +/* + * Restrict this file descriptor so that it can only be used to bind + * new interdomain events from one domain. + * + * Once a file descriptor has been restricted it cannot be + * de-restricted, and must be closed and re-opened. Event channels + * which were bound before restricting remain bound afterwards, and + * can be notified as usual. + */ +#define IOCTL_EVTCHN_RESTRICT_DOMID \ + _IOC(_IOC_NONE, 'E', 6, sizeof(struct ioctl_evtchn_restrict_domid)) +struct ioctl_evtchn_restrict_domid { + domid_t domid; +}; + #endif /* __LINUX_PUBLIC_EVTCHN_H__ */ diff --git a/tools/libs/evtchn/Makefile b/tools/libs/evtchn/Makefile index 5444ec73e5..bc98aed429 100644 --- a/tools/libs/evtchn/Makefile +++ b/tools/libs/evtchn/Makefile @@ -2,7 +2,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 -MINOR = 0 +MINOR = 1 SHLIB_LDFLAGS += -Wl,--version-script=libxenevtchn.map CFLAGS += -Werror -Wmissing-prototypes diff --git a/tools/libs/evtchn/core.c b/tools/libs/evtchn/core.c index c31e08ce3d..41621ff64b 100644 --- a/tools/libs/evtchn/core.c +++ b/tools/libs/evtchn/core.c @@ -61,6 +61,11 @@ int xenevtchn_close(xenevtchn_handle *xce) return rc; } +int xenevtchn_restrict(xenevtchn_handle *xce, domid_t domid) +{ + return osdep_evtchn_restrict(xce, domid); +} + /* * Local variables: * mode: C diff --git a/tools/libs/evtchn/freebsd.c b/tools/libs/evtchn/freebsd.c index 30eaa705ac..ba82f06311 100644 --- a/tools/libs/evtchn/freebsd.c +++ b/tools/libs/evtchn/freebsd.c @@ -47,6 +47,12 @@ int osdep_evtchn_close(xenevtchn_handle *xce) return close(xce->fd); } +int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid) +{ + errno = -EOPNOTSUPP; + return -1; +} + int xenevtchn_fd(xenevtchn_handle *xce) { return xce->fd; diff --git a/tools/libs/evtchn/include/xenevtchn.h b/tools/libs/evtchn/include/xenevtchn.h index 93b80cb119..91821ee56d 100644 --- a/tools/libs/evtchn/include/xenevtchn.h +++ b/tools/libs/evtchn/include/xenevtchn.h @@ -151,6 +151,16 @@ xenevtchn_pending(xenevtchn_handle *xce); */ int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port_t port); +/** + * This function restricts the use of this handle to the specified + * domain. + * + * @parm xce handle to the open evtchn interface + * @parm domid the domain id + * @return 0 on success, -1 on failure with errno set appropriately. + */ +int xenevtchn_restrict(xenevtchn_handle *xce, domid_t domid); + #endif /* diff --git a/tools/libs/evtchn/libxenevtchn.map b/tools/libs/evtchn/libxenevtchn.map index 625a1e2b82..33a38f953a 100644 --- a/tools/libs/evtchn/libxenevtchn.map +++ b/tools/libs/evtchn/libxenevtchn.map @@ -17,3 +17,7 @@ VERS_1.0 { xenevtchn_pending; local: *; /* Do not expose anything by default */ }; +VERS_1.1 { + global: + xenevtchn_restrict; +} VERS_1.0; diff --git a/tools/libs/evtchn/linux.c b/tools/libs/evtchn/linux.c index a581c5d316..17e64aea32 100644 --- a/tools/libs/evtchn/linux.c +++ b/tools/libs/evtchn/linux.c @@ -21,9 +21,11 @@ #include #include #include +#include #include +#include #include #include "private.h" @@ -49,6 +51,13 @@ int osdep_evtchn_close(xenevtchn_handle *xce) return close(xce->fd); } +int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid) +{ + struct ioctl_evtchn_restrict_domid restrict_domid = { domid }; + + return ioctl(xce->fd, IOCTL_EVTCHN_RESTRICT_DOMID, &restrict_domid); +} + int xenevtchn_fd(xenevtchn_handle *xce) { return xce->fd; diff --git a/tools/libs/evtchn/minios.c b/tools/libs/evtchn/minios.c index ccf37f081a..414c21ba67 100644 --- a/tools/libs/evtchn/minios.c +++ b/tools/libs/evtchn/minios.c @@ -82,6 +82,12 @@ int osdep_evtchn_close(xenevtchn_handle *xce) return close(xce->fd); } +int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid) +{ + errno = -EOPNOTSUPP; + return -1; +} + void minios_evtchn_close_fd(int fd) { struct evtchn_port_info *port_info, *tmp; diff --git a/tools/libs/evtchn/netbsd.c b/tools/libs/evtchn/netbsd.c index 114c6e6bc4..5ce3a35f80 100644 --- a/tools/libs/evtchn/netbsd.c +++ b/tools/libs/evtchn/netbsd.c @@ -47,6 +47,12 @@ int osdep_evtchn_close(xenevtchn_handle *xce) return close(xce->fd); } +int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid) +{ + errno = -EOPNOTSUPP; + return -1; +} + int xenevtchn_fd(xenevtchn_handle *xce) { return xce->fd; diff --git a/tools/libs/evtchn/private.h b/tools/libs/evtchn/private.h index fcd0e96979..3d34862acc 100644 --- a/tools/libs/evtchn/private.h +++ b/tools/libs/evtchn/private.h @@ -4,6 +4,8 @@ #include #include +#include + struct xenevtchn_handle { xentoollog_logger *logger, *logger_tofree; int fd; @@ -11,6 +13,7 @@ struct xenevtchn_handle { int osdep_evtchn_open(xenevtchn_handle *xce); int osdep_evtchn_close(xenevtchn_handle *xce); +int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid); #endif diff --git a/tools/libs/evtchn/solaris.c b/tools/libs/evtchn/solaris.c index dc249aa013..f718989450 100644 --- a/tools/libs/evtchn/solaris.c +++ b/tools/libs/evtchn/solaris.c @@ -50,6 +50,12 @@ int osdep_evtchn_close(xenevtchn_handle *xce) return close(xce->fd); } +int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid) +{ + errno = -EOPNOTSUPP; + return -1; +} + int xenevtchn_fd(xenevtchn_handle *xce) { return xce->fd; diff --git a/tools/libvchan/init.c b/tools/libvchan/init.c index e53f3a78d2..0b3759a056 100644 --- a/tools/libvchan/init.c +++ b/tools/libvchan/init.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include diff --git a/tools/libvchan/libxenvchan.h b/tools/libvchan/libxenvchan.h index 2adbdfe29d..d6010b145d 100644 --- a/tools/libvchan/libxenvchan.h +++ b/tools/libvchan/libxenvchan.h @@ -43,6 +43,7 @@ */ #include +#include #include #include #include