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 <ross.lagerwall@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Release-acked-by: Julien Grall <julien.grall@linaro.org>
This commit is contained in:
Ross Lagerwall authored and Wei Liu committed 2017-10-27 15:06:39 +01:00
1 parent d525519bed
commit 6b6500b3cb
13 files changed
+73 -1

No files matched your search

+15
View File
@@ -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__ */
+1 -1
View File
@@ -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
+5
View File
@@ -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
+6
View File
@@ -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;
+10
View File
@@ -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
/*
+4
View File
@@ -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;
+9
View File
@@ -21,9 +21,11 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <xen/xen.h>
#include <xen/sys/evtchn.h>
#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;
+6
View File
@@ -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;
+6
View File
@@ -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;
+3
View File
@@ -4,6 +4,8 @@
#include <xentoollog.h>
#include <xenevtchn.h>
#include <xen/xen.h>
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
+6
View File
@@ -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;
+1
View File
@@ -40,6 +40,7 @@
#include <fcntl.h>
#include <xenstore.h>
#include <xen/xen.h>
#include <xen/sys/evtchn.h>
#include <xen/sys/gntalloc.h>
#include <xen/sys/gntdev.h>
+1
View File
@@ -43,6 +43,7 @@
*/
#include <xen/io/libxenvchan.h>
#include <xen/xen.h>
#include <xen/sys/evtchn.h>
#include <xenevtchn.h>
#include <xengnttab.h>
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.