From 8ec7763c807f252e930c9647a0631253db2844a7 Mon Sep 17 00:00:00 2001 From: David Vrabel Date: Mon, 14 Oct 2013 10:23:10 +0200 Subject: Add DOMCTL to limit the number of event channels a domain may use Add XEN_DOMCTL_set_max_evtchn which may be used during domain creation to set the maximum event channel port a domain may use. This may be used to limit the amount of Xen resources (global mapping space and xenheap) that a domain may use for event channels. A domain that does not have a limit set may use all the event channels supported by the event channel ABI in use. Signed-off-by: David Vrabel Reviewed-by: Jan Beulich Acked-by: Daniel De Graaf Acked-by: Keir Fraser --- xen/common/domctl.c | 8 ++++++++ xen/common/event_channel.c | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'xen/common') diff --git a/xen/common/domctl.c b/xen/common/domctl.c index 9760d50955..870eef13b5 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -863,6 +863,14 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) } break; + case XEN_DOMCTL_set_max_evtchn: + { + d->max_evtchn_port = min_t(unsigned int, + op->u.set_max_evtchn.max_port, + INT_MAX); + } + break; + default: ret = arch_do_domctl(op, d, u_domctl); break; diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c index 0c0bbe494f..34efd24bb9 100644 --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -168,10 +168,14 @@ static int get_free_port(struct domain *d) return -EINVAL; for ( port = 0; port_is_valid(d, port); port++ ) + { + if ( port > d->max_evtchn_port ) + return -ENOSPC; if ( evtchn_from_port(d, port)->state == ECS_FREE ) return port; + } - if ( port == d->max_evtchns ) + if ( port == d->max_evtchns || port > d->max_evtchn_port ) return -ENOSPC; if ( !group_from_port(d, port) ) @@ -1230,6 +1234,7 @@ void evtchn_check_pollers(struct domain *d, unsigned int port) int evtchn_init(struct domain *d) { evtchn_2l_init(d); + d->max_evtchn_port = INT_MAX; d->evtchn = alloc_evtchn_bucket(d, 0); if ( !d->evtchn ) -- cgit v1.2.3