From patchwork Fri Oct 13 11:04:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 10004189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 32BD2602B3 for ; Fri, 13 Oct 2017 11:07:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2541A29021 for ; Fri, 13 Oct 2017 11:07:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 196952902B; Fri, 13 Oct 2017 11:07:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7038929021 for ; Fri, 13 Oct 2017 11:07:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2xmV-0003Uv-F0; Fri, 13 Oct 2017 11:05:31 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2xmU-0003Uk-CM for xen-devel@lists.xenproject.org; Fri, 13 Oct 2017 11:05:30 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id 72/D0-26326-9FD90E95; Fri, 13 Oct 2017 11:05:29 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOLMWRWlGSWpSXmKPExsXitHSDve7buQ8 iDT68YLT4vmUykwOjx+EPV1gCGKNYM/OS8isSWDNmzFnHXPDRsmLyvO2sDYwLDbsYOTkkBPwl 5lz5xgJiswkYSNy69J25i5GDQ0RAReL2XgOQMLNAucSJ7YfZQGxhoPJPcy+zg9gsAqoS18/8Y AaxeQXsJLrerGWDGCknsefiDLAaIQE1ibfLz7BA1AhKnJz5hAVipoTEwRcvmCcwcs9CkpqFJL WAkWkVo3pxalFZapGuhV5SUWZ6RkluYmaOrqGBsV5uanFxYnpqTmJSsV5yfu4mRmAgMADBDsY L7c6HGCU5mJREedUiH0QK8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuAVAAaWkGBRanpqRVpmDjAk YdISHDxKIrxCIGne4oLE3OLMdIjUKUZdjo6bd/8wCbHk5eelSonzKoAUCYAUZZTmwY2AxcclR lkpYV5GoKOEeApSi3IzS1DlXzGKczAqCfMqgkzhycwrgdv0CugIJqAj3kWAHVGSiJCSamDs9d lbk2Z860ng7dCJ0tcnFrz52Dc1iqG4RO/zxIB1LtwuDya8NFz0eoXY/YmhEzJXzpTY+Pzf30K 7pUo80y53mRpq9nyvVT523VZulaW125/ya++5tKdln9mr8XgZU99Wpeodt5YYGR22Wvrg18vs 1kszvxnsuhKV2ayvYrfEauU8jtzi/v17lViKMxINtZiLihMBO7fapooCAAA= X-Env-Sender: prvs=452428aa2=ross.lagerwall@citrix.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1507892715!110192605!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34121 invoked from network); 13 Oct 2017 11:05:16 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-8.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 13 Oct 2017 11:05:16 -0000 X-IronPort-AV: E=Sophos;i="5.43,370,1503360000"; d="scan'208";a="453844431" From: Ross Lagerwall To: Date: Fri, 13 Oct 2017 12:04:49 +0100 Message-ID: <20171013110450.19176-1-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.9.5 MIME-Version: 1.0 Cc: Ross Lagerwall , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v1 1/2] tools/libs/evtchn: Add support for restricting a handle X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- tools/include/xen-sys/Linux/evtchn.h | 15 +++++++++++++++ tools/libs/evtchn/Makefile | 2 +- tools/libs/evtchn/core.c | 5 +++++ tools/libs/evtchn/freebsd.c | 6 ++++++ tools/libs/evtchn/include/xenevtchn.h | 10 ++++++++++ tools/libs/evtchn/libxenevtchn.map | 4 ++++ tools/libs/evtchn/linux.c | 9 +++++++++ tools/libs/evtchn/minios.c | 6 ++++++ tools/libs/evtchn/netbsd.c | 6 ++++++ tools/libs/evtchn/private.h | 3 +++ tools/libs/evtchn/solaris.c | 6 ++++++ tools/libvchan/init.c | 1 + tools/libvchan/libxenvchan.h | 1 + 13 files changed, 73 insertions(+), 1 deletion(-) diff --git a/tools/include/xen-sys/Linux/evtchn.h b/tools/include/xen-sys/Linux/evtchn.h index 938d4da..08ee0b7 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 5444ec7..bc98aed 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 c31e08c..41621ff 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 30eaa70..ba82f06 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 93b80cb..91821ee 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 625a1e2..33a38f9 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 a581c5d..17e64ae 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 ccf37f0..414c21b 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 114c6e6..5ce3a35 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 fcd0e96..3d34862 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 dc249aa..f718989 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 e53f3a7..0b3759a 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 2adbdfe..d6010b1 100644 --- a/tools/libvchan/libxenvchan.h +++ b/tools/libvchan/libxenvchan.h @@ -43,6 +43,7 @@ */ #include +#include #include #include #include