Xen: FIFO-based event channel ABI
v3 cover Xen: FIFO-based event channel ABI
This is a complete implementation of the hypervisor parts of the FIFO-based event channel ABI described in this design document:
http://xenbits.xen.org/people/dvrabel/event-channels-E.pdf
Changes in draft E are:
- Control blocks are no longer required to be in the same page as the vcpu_info.
- Added padding to struct evtchn_init_control.
Remaining work:
* Extend libxl and xl to allow the event channel limit to be set. Without this DomUs are limited the default number of event channels (4096). I use a trivial C program to set the limit.
* Decide whether EVTCHNOP_set_limit should be a DOMCTL instead.
* Allocation of struct event channels to use less memory when fewer event channels are in use. I plan to have d->evtchns point to a page contains N struct evtchns and M group pointers with the remainder event channels being indexed by group/bucket in patch 6.
Patch 1-4 do some preparatory work for supporting alternate ABIs.
Patch 5-6 expand the number of evtchn objects a domain may have to changing how they are allocated.
Patch 7 adds the ABI.
Patch 8 adds the EVTCHNOP_set_priority implementation. This will return -ENOSYS for ABIs that do not support priority.
Patch 9-10 adds the EVTCHNOP_set_limit implementation and adds a function to libxc. This will also work with the 2-level ABI.
Patch 11 adds the FIFO-based ABI implementation.
Changes in v3:
- Updates for Draft E of the design.
- Store priority in struct evtchn.
- Implement set_priority with generic code + hook.
- Implement set_limit and add libxc function.
- Add ABI specific output to 'e' debug key.
Changes in v2:
- Updates for Draft D of the design.
- 130,000+ event channels are now supported.
- event_port.c -> event_2l.c and only contains 2l functions.
- Addresses various review comments
- int -> unsigned in lots of places
- use write_atomic() to set HEAD
- removed MAX_EVTCHNS
- evtchn_ops are const.
- Pack struct evtchns better to reduce memory needed.
PATCH v3 1/11 debug: remove some event channel info from the 'i' and 'q' debug keys
From: David Vrabel <[email protected]>
The 'i' key would always use VCPU0's selector word when printing the event channel state. Remove the incorrect output as a subsequent change will add the (correct) information to the 'e' key instead.
When dumping domain information, printing the state of the VIRQ_DEBUG port is redundant -- this information is available via the 'e' key.
--- xen/arch/x86/irq.c | 5 +---- xen/common/keyhandler.c | 11 ++--------- 2 files changed, 3 insertions(+), 13 deletions(-)
xen/arch/x86/irq.c +1 -4
@@ -2262,14 +2262,11 @@ static void dump_irqs(unsigned char key) d = action->guest[i]; pirq =domain_irq_to_pirq (d, irq); info =pirq_info (d, pirq); -printk ("%u:%3d(%c%c%c%c)" , +printk ("%u:%3d(%c%c%c)" , d->domain_id, pirq, (test_bit (info->evtchn, &shared_info (d, evtchn_pending)) ?'P' :'-' ), - (test_bit (info->evtchn /BITS_PER_EVTCHN_WORD (d), - &vcpu_info (d->vcpu[0 ], evtchn_pending_sel)) ? -'S' :'-' ), (test_bit (info->evtchn, &shared_info (d, evtchn_mask)) ?'M' :'-' ), (info->masked ?'M' :'-' ));
xen/common/keyhandler.c +2 -9
@@ -310,16 +310,9 @@ static void dump_domains(unsigned char key) { for_each_vcpu ( d, v ) { -printk ("Notifying guest %d:%d (virq %d, port %d, stat %d/%d/%d)\n" , +printk ("Notifying guest %d:%d (virq %d, port %d)\n" , d->domain_id, v->vcpu_id, -VIRQ_DEBUG , v->virq_to_evtchn[VIRQ_DEBUG ], -test_bit (v->virq_to_evtchn[VIRQ_DEBUG ], - &shared_info (d, evtchn_pending)), -test_bit (v->virq_to_evtchn[VIRQ_DEBUG ], - &shared_info (d, evtchn_mask)), -test_bit (v->virq_to_evtchn[VIRQ_DEBUG ] / -BITS_PER_EVTCHN_WORD (d), - &vcpu_info (v, evtchn_pending_sel))); +VIRQ_DEBUG , v->virq_to_evtchn[VIRQ_DEBUG ]);send_guest_vcpu_virq (v,VIRQ_DEBUG ); } }
Signature · 1 line
1.7.2.5
PATCH v3 2/11 evtchn: refactor low-level event channel port ops
In reply to David VrabelFrom: David Vrabel <[email protected]>
Use functions for the low-level event channel port operations (set/clear pending, unmask, is_pending and is_masked).
Group these functions into a struct evtchn_port_op so they can be replaced by alternate implementations (for different ABIs) on a per-domain basis.
--- xen/arch/x86/irq.c | 11 ++--- xen/common/Makefile | 1 + xen/common/event_2l.c | 99 ++++++++++++++++++++++++++++++++++++++++++++ xen/common/event_channel.c | 88 +++++++++++++++------------------------ xen/common/schedule.c | 3 +- xen/include/xen/event.h | 45 ++++++++++++++++++++ xen/include/xen/sched.h | 4 ++ 7 files changed, 190 insertions(+), 61 deletions(-) create mode 100644 xen/common/event_2l.c
xen/arch/x86/irq.c +5 -6
@@ -1474,7 +1474,7 @@ int pirq_guest_unmask(struct domain *d) { pirq = pirqs[i]->pirq;if ( pirqs[i]->masked && - !test_bit (pirqs[i]->evtchn, &shared_info (d, evtchn_mask)) ) + !evtchn_port_is_masked (d,evtchn_from_port (d, pirqs[i]->evtchn)) )pirq_guest_eoi (pirqs[i]); } }while ( ++pirq < d->nr_pirqs && n ==ARRAY_SIZE (pirqs) );
@@ -2222,6 +2222,7 @@ static void dump_irqs(unsigned char key)int i, irq, pirq;struct irq_desc *desc;irq_guest_action_t *action; +struct evtchn *evtchn;struct domain *d;const struct pirq *info;unsigned long flags;
@@ -2262,13 +2263,11 @@ static void dump_irqs(unsigned char key) d = action->guest[i]; pirq =domain_irq_to_pirq (d, irq); info =pirq_info (d, pirq); + evtchn =evtchn_from_port (d, info->evtchn);printk ("%u:%3d(%c%c%c)" , d->domain_id, pirq, - (test_bit (info->evtchn, - &shared_info (d, evtchn_pending)) ? -'P' :'-' ), - (test_bit (info->evtchn, &shared_info (d, evtchn_mask)) ? -'M' :'-' ), + (evtchn_port_is_pending (d, evtchn) ?'P' :'-' ), + (evtchn_port_is_masked (d, evtchn) ?'M' :'-' ), (info->masked ?'M' :'-' ));if ( i != action->nr_guests )printk ("," );
xen/common/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-y += cpupool.o obj-$(HAS_DEVICE_TREE) += device_tree.o obj-y += domctl.o obj-y += domain.o +obj-y += event_2l.o obj-y += event_channel.o obj-y += grant_table.o obj-y += irq.o
xen/common/event_2l.c new file +99 -0
99 lines not on this page · raw message
xen/common/event_channel.c +34 -54
133 lines not on this page · raw message
xen/common/schedule.c +2 -1
@@ -34,6 +34,7 @@#include <xen/multicall.h> #include <xen/cpu.h> #include <xen/preempt.h> +#include <xen/event.h> #include <public/sched.h> #include <xsm/xsm.h>
@@ -751,7 +752,7 @@ static long do_poll(struct sched_poll *sched_poll) goto out; rc =0 ; -if (test_bit (port, &shared_info (d, evtchn_pending)) ) +if (evtchn_port_is_pending (d,evtchn_from_port (d, port)) ) goto out; }
xen/include/xen/event.h +45 -0
49 lines not on this page · raw message
xen/include/xen/sched.h +4 -0
@@ -66,6 +66,7 @@ struct evtchnu8 state;/* ECS_* */ u8 xen_consumer;/* Consumer in Xen, if any? (0 = send to guest) */ u16 notify_vcpu_id;/* VCPU for local delivery notification */ +u32 port; union { struct { domid_t remote_domid;
@@ -238,6 +239,8 @@ struct mem_event_per_domainstruct mem_event_domain access; }; +struct evtchn_port_ops ; +struct domain {domid_t domain_id;
@@ -271,6 +274,7 @@ struct domain/* Event channel information. */ struct evtchn *evtchn[NR_EVTCHN_BUCKETS ];spinlock_t event_lock; +const struct evtchn_port_ops *evtchn_port_ops;struct grant_table *grant_table;
Signature · 1 line
1.7.2.5
Re: [PATCH 02/11] evtchn: refactor low-level event channel port ops
Quoted 6 lines · David Vrabel
xen/common/event_2l.c new file +0
-0
xen/common/event_2l.c line 8
Quoted 8 lines
xen/common/event_2l.c new file +8
-0@@ -0,0 +1,99 @@ +/* +* Event channel port operations. +* +* Copyright (c) 2003-2006, K A Fraser. +* +* This source code is licensed under the GNU General Public License, +* Version 2 or later. See the file COPYING for more details. +*/
Does it have to be GPLv2 only? Can it be dual-licensed BSD to make it easier for other operating systems to support the new interface?
Re: [PATCH 02/11] evtchn: refactor low-level event channel port ops
Quoted 10 lines · Stefano Stabellini
Quoted 9 lines · David Vrabel
xen/common/event_2l.c new file +3
-0@@ -0,0 +1,99 @@ +/* +* Event channel port operations. +*
Quoted 9 lines
xen/common/event_2l.c line 8
Quoted 5 lines
xen/common/event_2l.c new file +5
-0+* Copyright (c) 2003-2006, K A Fraser. +* +* This source code is licensed under the GNU General Public License, +* Version 2 or later. See the file COPYING for more details. +*/ Does it have to be GPLv2 only? Can it be dual-licensed BSD to make it easier for other operating systems to support the new interface?
I meant to quote the new Linux files:
drivers/xen/events/events_internal.hdrivers/xen/events/n-level.cdrivers/xen/events/fifo.c
Re: [PATCH 02/11] evtchn: refactor low-level event channel port ops
Quoted 21 lines · Stefano Stabellini
Quoted 10 lines · Stefano Stabellini
Quoted 9 lines · David Vrabel
xen/common/event_2l.c new file +3
-0@@ -0,0 +1,99 @@ +/* +* Event channel port operations. +* Quoted 9 lines
xen/common/event_2l.c line 8
Quoted 5 lines
xen/common/event_2l.c new file +5
-0+* Copyright (c) 2003-2006, K A Fraser. +* +* This source code is licensed under the GNU General Public License, +* Version 2 or later. See the file COPYING for more details. +*/ Does it have to be GPLv2 only? Can it be dual-licensed BSD to make it easier for other operating systems to support the new interface?
Quoted 4 lines
I meant to quote the new Linux files:
drivers/xen/events/events_internal.hdrivers/xen/events/n-level.c
These will have to stay as GPLv2 as the are derived from the original events.c which does not have any license stated (so we must assume GPLv2).
Quoted 1 line
drivers/xen/events/fifo.c
I will make this one dual GPLv2 or later and 2-clause BSD. Although, I do think that any implementer would be better off basing their work off the documentation rather a Linux-centric implementation.
David
Re: [PATCH 02/11] evtchn: refactor low-level event channel port ops
In reply to Stefano StabelliniQuoted 10 lines · Stefano Stabellini
Quoted 9 lines · David Vrabel
xen/common/event_2l.c new file +3
-0@@ -0,0 +1,99 @@ +/* +* Event channel port operations. +*
Quoted 8 lines
xen/common/event_2l.c line 8
Quoted 5 lines
xen/common/event_2l.c new file +5
-0+* Copyright (c) 2003-2006, K A Fraser. +* +* This source code is licensed under the GNU General Public License, +* Version 2 or later. See the file COPYING for more details. +*/ Does it have to be GPLv2 only? Can it be dual-licensed BSD to make it easier for other operating systems to support the new interface?
This is the Xen side not the guest side so I'm not sure how helpful that would be in practice.
More useful would be BSD licenses mini-os support for this stuff, or just doing it in one of the BSDs, but I don't think either of those should be a requirement for this series.
Ian
PATCH v3 3/11 evtchn: print ABI specific state with the 'e' debug key
In reply to David VrabelFrom: David Vrabel <[email protected]>
In the output of the 'e' debug key, print some ABI specific state in addition to the (p)ending and (m)asked bits.
For the 2-level ABI, print the state of that event's selector bit. e.g.,
(XEN) port [p/m/s]
(XEN) 1 [0/0/1]: s=3 n=0 x=0 d=0 p=74
(XEN) 2 [0/0/1]: s=3 n=0 x=0 d=0 p=75
--- xen/common/event_2l.c | 10 ++++++++++ xen/common/event_channel.c | 8 +++++--- xen/include/xen/event.h | 7 +++++++ 3 files changed, 22 insertions(+), 3 deletions(-)
xen/common/event_2l.c +10 -0
@@ -74,6 +74,15 @@ static bool_t evtchn_2l_is_masked(struct domain *d,return test_bit (evtchn->port, &shared_info (d, evtchn_mask)); } +static void evtchn_2l_print_state (struct domain *d, +const struct evtchn *evtchn) +{ +struct vcpu *v = d->vcpu[evtchn->notify_vcpu_id]; + +printk ("%d" , !!test_bit (evtchn->port /BITS_PER_EVTCHN_WORD (d), + &vcpu_info (v, evtchn_pending_sel))); +} +static const struct evtchn_port_ops evtchn_port_ops_2l = { .set_pending = evtchn_2l_set_pending,
@@ -81,6 +90,7 @@ static const struct evtchn_port_ops evtchn_port_ops_2l = .unmask = evtchn_2l_unmask, .is_pending = evtchn_2l_is_pending, .is_masked = evtchn_2l_is_masked, + .print_state = evtchn_2l_print_state, };void evtchn_2l_init (struct domain *d)
xen/common/event_channel.c +5 -3
@@ -1233,7 +1233,7 @@ static void domain_dump_evtchn_info(struct domain *d) d->poll_mask, d->max_vcpus);printk ("Event channel information for domain %d:\n" "Polling vCPUs: {%s}\n" -" port [p/m]\n" , d->domain_id, keyhandler_scratch); +" port [p/m/s]\n" , d->domain_id, keyhandler_scratch);spin_lock (&d->event_lock);
@@ -1248,10 +1248,12 @@ static void domain_dump_evtchn_info(struct domain *d)if ( chn->state ==ECS_FREE )continue ; -printk (" %4u [%d/%d]: s=%d n=%d x=%d" , +printk (" %4u [%d/%d/" , port, !!evtchn_port_is_pending (d, chn), - !!evtchn_port_is_masked (d, chn), + !!evtchn_port_is_masked (d, chn)); +evtchn_port_print_state (d, chn); +printk ("]: s=%d n=%d x=%d" , chn->state, chn->notify_vcpu_id, chn->xen_consumer); switch ( chn->state )
xen/include/xen/event.h +7 -0
@@ -115,6 +115,7 @@ struct evtchn_port_ops {void (*unmask)(struct domain *d,struct evtchn *evtchn);bool_t (*is_pending)(struct domain *d,const struct evtchn *evtchn);bool_t (*is_masked)(struct domain *d,const struct evtchn *evtchn); +void (*print_state)(struct domain *d,const struct evtchn *evtchn); }; static inline void evtchn_port_set_pending(struct vcpu *v,
@@ -147,4 +148,10 @@ static inline bool_t evtchn_port_is_masked(struct domain *d, return d->evtchn_port_ops->is_masked(d, evtchn); } +static inline void evtchn_port_print_state (struct domain *d, +const struct evtchn *evtchn) +{ + d->evtchn_port_ops->print_state (d, evtchn); +} +#endif /* __XEN_EVENT_H__ */
Signature · 1 line
1.7.2.5
PATCH v3 4/11 evtchn: use a per-domain variable for the max number of event channels
In reply to David VrabelFrom: David Vrabel <[email protected]>
Instead of the MAX_EVTCHNS(d) macro, use d->max_evtchns instead. This avoids having to repeatedly check the ABI type.
--- xen/common/event_2l.c | 1 + xen/common/event_channel.c | 4 ++-- xen/common/schedule.c | 2 +- xen/include/xen/event.h | 2 +- xen/include/xen/sched.h | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-)
xen/common/event_2l.c +1 -0
@@ -96,6 +96,7 @@ static const struct evtchn_port_ops evtchn_port_ops_2l =void evtchn_2l_init (struct domain *d) { d->evtchn_port_ops = &evtchn_port_ops_2l; + d->max_evtchns =BITS_PER_EVTCHN_WORD (d) *BITS_PER_EVTCHN_WORD (d); }/*
xen/common/event_channel.c +2 -2
@@ -134,7 +134,7 @@ static int get_free_port(struct domain *d)if (evtchn_from_port (d, port)->state ==ECS_FREE )return port; -if ( port ==MAX_EVTCHNS (d) ) +if ( port == d->max_evtchns )return -ENOSPC ; chn = xzalloc_array(struct evtchn, EVTCHNS_PER_BUCKET);
@@ -1237,7 +1237,7 @@ static void domain_dump_evtchn_info(struct domain *d)spin_lock (&d->event_lock); -for ( port =1 ; port <MAX_EVTCHNS (d); ++port ) +for ( port =1 ; port < d->max_evtchns; ++port ) {const struct evtchn *chn;char *ssid;
xen/common/schedule.c +1 -1
@@ -748,7 +748,7 @@ static long do_poll(struct sched_poll *sched_poll) goto out; rc = -EINVAL ; -if ( port >=MAX_EVTCHNS (d) ) +if ( port >= d->max_evtchns ) goto out; rc =0 ;
xen/include/xen/event.h +1 -1
@@ -73,7 +73,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);#define bucket_from_port (d,p) \ ((d)->evtchn[(p)/EVTCHNS_PER_BUCKET])#define port_is_valid (d,p) \ - (((p) >= 0) && ((p) < MAX_EVTCHNS(d)) && \ + (((p) >= 0) && ((p) < (d)->max_evtchns) && \ (bucket_from_port(d,p) != NULL))#define evtchn_from_port (d,p) \ (&(bucket_from_port(d,p))[(p)&(EVTCHNS_PER_BUCKET-1)])
xen/include/xen/sched.h +1 -1
@@ -50,7 +50,6 @@ extern struct domain *dom0;#else #define BITS_PER_EVTCHN_WORD (d) (has_32bit_shinfo(d) ? 32 : BITS_PER_XEN_ULONG)#endif -#define MAX_EVTCHNS (d) (BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d))#define EVTCHNS_PER_BUCKET 128#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS / EVTCHNS_PER_BUCKET)
@@ -273,6 +272,7 @@ struct domain/* Event channel information. */ struct evtchn *evtchn[NR_EVTCHN_BUCKETS ]; +unsigned max_evtchns;spinlock_t event_lock;const struct evtchn_port_ops *evtchn_port_ops;
Signature · 1 line
1.7.2.5
PATCH v3 5/11 evtchn: dynamically allocate d->evtchn
In reply to David VrabelFrom: Wei Liu <[email protected]>
As we move to extended evtchn ABI we need bigger d->evtchn, as a result this will bloat struct domain. So move this array out of struct domain and allocate a dedicated array for it.
--- xen/common/event_channel.c | 13 +++++++++++++ xen/include/xen/sched.h | 2 +- 2 files changed, 14 insertions(+), 1 deletions(-)
xen/common/event_channel.c +13 -0
@@ -1153,15 +1153,26 @@ int evtchn_init(struct domain *d)/* Default to N-level ABI. */ evtchn_2l_init (d); +BUILD_BUG_ON (sizeof (struct evtchn *) *NR_EVTCHN_BUCKETS >PAGE_SIZE ); + d->evtchn = xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS); +if ( d->evtchn ==NULL ) +return -ENOMEM ; +spin_lock_init (&d->event_lock);if (get_free_port (d) !=0 ) + { +xfree (d->evtchn);return -EINVAL ; + }evtchn_from_port (d,0 )->state =ECS_RESERVED ;#if MAX_VIRT_CPUS >BITS_PER_LONG d->poll_mask = xmalloc_array(unsigned long, BITS_TO_LONGS(MAX_VIRT_CPUS));if ( !d->poll_mask ) + { +xfree (d->evtchn);return -ENOMEM ; + }bitmap_zero (d->poll_mask,MAX_VIRT_CPUS );#endif
@@ -1195,6 +1206,8 @@ void evtchn_destroy(struct domain *d)spin_unlock (&d->event_lock);clear_global_virq_handlers (d); + +xfree (d->evtchn); }
xen/include/xen/sched.h +1 -1
@@ -271,7 +271,7 @@ struct domainspinlock_t rangesets_lock;/* Event channel information. */ -struct evtchn *evtchn[NR_EVTCHN_BUCKETS ]; +struct evtchn **evtchn;unsigned max_evtchns;spinlock_t event_lock;const struct evtchn_port_ops *evtchn_port_ops;
Signature · 1 line
1.7.2.5
PATCH v3 6/11 evtchn: alter internal object handling scheme
In reply to David VrabelFrom: Wei Liu <[email protected]>
Originally, evtchn objects are stored in buckets. Now we add another layer called group. struct domain holds an array to evtchn groups, then each group holds pointers to a bucket.
With this change, each domain can have more struct evtchn in a space-efficient way.
Allocate the array of group pointers, shrinking the size of struct domain.
Compile time calculate grouping and bucket parameters to achive optimum packing into PAGE_SIZE memory allocations.
--- xen/common/event_channel.c | 29 ++++++++++++++++++++++++----- xen/include/xen/event.h | 24 ++++++++++++++++-------- xen/include/xen/sched.h | 20 +++++++++++++++++--- 3 files changed, 57 insertions(+), 16 deletions(-)
xen/common/event_channel.c +24 -5
@@ -124,6 +124,7 @@ static int virq_is_global(uint32_t virq)static int get_free_port (struct domain *d) {struct evtchn *chn; +struct evtchn **grp;int port;int i, j;
@@ -137,6 +138,15 @@ static int get_free_port(struct domain *d)if ( port == d->max_evtchns )return -ENOSPC ; +if (unlikely (group_from_port (d, port) ==NULL ) ) + { + grp = xzalloc_array(struct evtchn *, BUCKETS_PER_GROUP); +if (unlikely (grp ==NULL ) ) +return -ENOMEM ; +else +group_from_port (d, port) = grp; + } + chn = xzalloc_array(struct evtchn, EVTCHNS_PER_BUCKET);if (unlikely (chn ==NULL ) )return -ENOMEM ;
@@ -1153,8 +1163,7 @@ int evtchn_init(struct domain *d)/* Default to N-level ABI. */ evtchn_2l_init (d); -BUILD_BUG_ON (sizeof (struct evtchn *) *NR_EVTCHN_BUCKETS >PAGE_SIZE ); - d->evtchn = xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS); + d->evtchn = xzalloc_array(struct evtchn **, NR_EVTCHN_GROUPS);if ( d->evtchn ==NULL )return -ENOMEM ;
@@ -1182,7 +1191,7 @@ int evtchn_init(struct domain *d)void evtchn_destroy (struct domain *d) { -int i; +unsigned i, j;/* After this barrier no new event-channel allocations can occur. */ BUG_ON (!d->is_dying);
@@ -1197,9 +1206,19 @@ void evtchn_destroy(struct domain *d)/* Free all event-channel buckets. */ spin_lock (&d->event_lock); -for ( i =0 ; i <NR_EVTCHN_BUCKETS ; i++ ) +for ( i =0 ; i <NR_EVTCHN_GROUPS ; i++ ) { -xsm_free_security_evtchn (d->evtchn[i]); +if ( d->evtchn[i] ==NULL ) +continue ; + +for ( j =0 ; j <BUCKETS_PER_GROUP ; j++ ) + { +if ( d->evtchn[i][j] ==NULL ) +continue ; +xsm_free_security_evtchn (d->evtchn[i][j]); +xfree (d->evtchn[i][j]); + d->evtchn[i][j] =NULL ; + }xfree (d->evtchn[i]); d->evtchn[i] =NULL ; }
xen/include/xen/event.h +16 -8
@@ -69,14 +69,22 @@ int guest_enabled_event(struct vcpu *v, uint32_t virq);/* Notify remote end of a Xen-attached event channel.*/ void notify_via_xen_event_channel (struct domain *ld,int lport); -/* Internal event channel object accessors */ -#define bucket_from_port (d,p) \ - ((d)->evtchn[(p)/EVTCHNS_PER_BUCKET]) -#define port_is_valid (d,p) \ - (((p) >= 0) && ((p) < (d)->max_evtchns) && \ - (bucket_from_port(d,p) != NULL)) -#define evtchn_from_port (d,p) \ - (&(bucket_from_port(d,p))[(p)&(EVTCHNS_PER_BUCKET-1)]) +/* +* Internal event channel object storage: +* Objects are organized in two level scheme: group and bucket +* A group consists of several buckets, a bucket is an array of struct evtchn +*/ +#define group_from_port (d, p) \ + ((d)->evtchn[(p) / EVTCHNS_PER_GROUP]) +/* User should make sure group is not NULL */ +#define bucket_from_port (d, p) \ + ((group_from_port(d, p))[((p) % EVTCHNS_PER_GROUP) / EVTCHNS_PER_BUCKET]) +#define port_is_valid (d, p) \ + (((p) >= 0) && ((p) < (d)->max_evtchns) && \ + (group_from_port(d, p) != NULL) && \ + (bucket_from_port(d, p) != NULL)) +#define evtchn_from_port (d, p) \ + (&(bucket_from_port(d, p))[(p) & (EVTCHNS_PER_BUCKET-1)])/* Wait on a Xen-attached event channel. */
xen/include/xen/sched.h +17 -3
@@ -50,8 +50,22 @@ extern struct domain *dom0;#else #define BITS_PER_EVTCHN_WORD (d) (has_32bit_shinfo(d) ? 32 : BITS_PER_XEN_ULONG)#endif -#define EVTCHNS_PER_BUCKET 128 -#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS / EVTCHNS_PER_BUCKET) + +#define BUCKETS_PER_GROUP (PAGE_SIZE/sizeof(struct evtchn *)) +/* Round size of struct evtchn up to power of 2 size */ +#define __RDU2 (x) ( (x) | ( (x) >> 1)) +#define __RDU4 (x) ( __RDU2(x) | ( __RDU2(x) >> 2)) +#define __RDU8 (x) ( __RDU4(x) | ( __RDU4(x) >> 4)) +#define __RDU16 (x) ( __RDU8(x) | ( __RDU8(x) >> 8)) +#define __RDU32 (x) (__RDU16(x) | (__RDU16(x) >>16)) +#define next_power_of_2 (x) (__RDU32((x)-1) + 1) + +/* Maximum number of event channels for any ABI. */ +#define MAX_NR_EVTCHNS NR_EVENT_CHANNELS + +#define EVTCHNS_PER_BUCKET (PAGE_SIZE / next_power_of_2(sizeof(struct evtchn))) +#define EVTCHNS_PER_GROUP (BUCKETS_PER_GROUP * EVTCHNS_PER_BUCKET) +#define NR_EVTCHN_GROUPS DIV_ROUND_UP(MAX_NR_EVTCHNS, EVTCHNS_PER_GROUP)struct evtchn {
@@ -271,7 +285,7 @@ struct domainspinlock_t rangesets_lock;/* Event channel information. */ -struct evtchn **evtchn; +struct evtchn ***evtchn;unsigned max_evtchns;spinlock_t event_lock;const struct evtchn_port_ops *evtchn_port_ops;
Signature · 1 line
1.7.2.5
PATCH v3 7/11 evtchn: add FIFO-based event channel ABI
In reply to David VrabelFrom: David Vrabel <[email protected]>
Add the event channel hypercall sub-ops and the definitions for the shared data structures for the FIFO-based event channel ABI.
The design document for this new ABI is available here:
http://xenbits.xen.org/people/dvrabel/event-channels-E.pdf
In summary, events are reported using a per-domain shared event array of event words. Each event word has PENDING, LINKED and MASKED bits and a LINK field for pointing to the next event in the event queue.
There are 16 event queues (with different priorities) per-VCPU.
Key advantages of this new ABI include:
- Support for over 100,000 events (2^17).
- 16 different event priorities.
- Improved fairness in event latency through the use of FIFOs.
--- xen/include/public/event_channel.h | 77 ++++++++++++++++++++++++++++++++++++ xen/include/public/xen.h | 2 +- 2 files changed, 78 insertions(+), 1 deletions(-)
xen/include/public/event_channel.h +77 -0
@@ -71,6 +71,10 @@#define EVTCHNOP_bind_vcpu 8#define EVTCHNOP_unmask 9#define EVTCHNOP_reset 10 +#define EVTCHNOP_init_control 11 +#define EVTCHNOP_expand_array 12 +#define EVTCHNOP_set_priority 13 +#define EVTCHNOP_set_limit 14/* ` } */ typedef uint32_t evtchn_port_t ;
@@ -258,6 +262,53 @@ struct evtchn_reset {typedef struct evtchn_reset evtchn_reset_t ;/* +* EVTCHNOP_init_control: initialize the control block for the FIFO ABI. +* +* Note: any events that are currently pending will not be resent and +* will be lost. Guests should call this before binding any event to +* avoid losing any events. +*/ +struct evtchn_init_control { +/* IN parameters. */ +uint64_t control_mfn; +uint32_t offset; +uint32_t vcpu; +/* OUT parameters. */ +uint8_t link_bits; +uint8_t __pad[7 ]; +}; +typedef struct evtchn_init_control evtchn_init_control_t ; + +/* +* EVTCHNOP_expand_array: add an additional page to the event array. +*/ +struct evtchn_expand_array { +/* IN parameters. */ +uint64_t array_mfn; +}; +typedef struct evtchn_expand_array evtchn_expand_array_t ; + +/* +* EVTCHNOP_set_priority: set the priority for an event channel. +*/ +struct evtchn_set_priority { +/* IN parameters. */ +uint32_t port; +uint32_t priority; +}; +typedef struct evtchn_set_priority evtchn_set_priority_t ; + +/* +* EVTCHNOP_set_limit: set the maximum event channel port that may be bound. +*/ +struct evtchn_set_limit { +/* IN parameters. */ +uint32_t domid; +uint32_t max_port; +}; +typedef struct evtchn_set_limit evtchn_set_limit_t ; + +/* * ` enum neg_errnoval * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op) * `
@@ -281,6 +332,32 @@ struct evtchn_op {typedef struct evtchn_op evtchn_op_t ;DEFINE_XEN_GUEST_HANDLE (evtchn_op_t); +/* +* FIFO ABI +*/ + +/* Events may have priorities from 0 (highest) to 15 (lowest). */ +#define EVTCHN_FIFO_PRIORITY_MIN 15 +#define EVTCHN_FIFO_PRIORITY_DEFAULT 7 + +#define EVTCHN_FIFO_MAX_QUEUES (EVTCHN_FIFO_PRIORITY_MIN + 1) + +typedef uint32_t event_word_t ; + +#define EVTCHN_FIFO_PENDING 31 +#define EVTCHN_FIFO_MASKED 30 +#define EVTCHN_FIFO_LINKED 29 + +#define EVTCHN_FIFO_LINK_BITS 17 +#define EVTCHN_FIFO_LINK_MASK ((1 << EVTCHN_FIFO_LINK_BITS) - 1) + +struct evtchn_fifo_control_block { +uint32_t ready; +uint32_t _rsvd1; +uint32_t head[EVTCHN_FIFO_MAX_QUEUES ]; +}; +typedef struct evtchn_fifo_control_block evtchn_fifo_control_block_t ; +#endif /* __XEN_PUBLIC_EVENT_CHANNEL_H__ */ /*
xen/include/public/xen.h +1 -1
@@ -553,7 +553,7 @@ typedef struct multicall_entry multicall_entry_t;DEFINE_XEN_GUEST_HANDLE (multicall_entry_t);/* -* Event channel endpoints per domain: +* Event channel endpoints per domain (when using the 2-level ABI): * 1024 if a long is 32 bits; 4096 if a long is 64 bits. */ #define NR_EVENT_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
Signature · 1 line
1.7.2.5
Re: [PATCH 07/11] evtchn: add FIFO-based event channel ABI
xen/include/public/xen.h typedef struct multicall_entry multicall_entry_t; · line 559
Quoted 12 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/include/public/xen.h +1
-1@@ -553,7 +553,7 @@ typedef struct multicall_entry multicall_entry_t;DEFINE_XEN_GUEST_HANDLE (multicall_entry_t);/* -* Event channel endpoints per domain: +* Event channel endpoints per domain (when using the 2-level ABI): * 1024 if a long is 32 bits; 4096 if a long is 64 bits. */ #define NR_EVENT_CHANNELS (sizeof(xen_ulong_t) * sizeof(xen_ulong_t) * 64)
This should probably become NR_L2_EVENT_CHANNELS, with the original symbol aliased to the new one only for pre-4.4 interface consumers.
Jan
PATCH v3 8/11 evtchn: implement EVTCHNOP_set_priority and add the set_priority hook
In reply to David VrabelFrom: David Vrabel <[email protected]>
Implement EVTCHNOP_set_priority. A new set_priority hook added to struct evtchn_port_ops will do the ABI specific validation and setup.
If an ABI does not provide a set_priority hook (as is the case of the 2-level ABI), the sub-op will return -ENOSYS.
--- xen/common/event_channel.c | 29 +++++++++++++++++++++++++++++ xen/include/xen/event.h | 11 +++++++++++ 2 files changed, 40 insertions(+), 0 deletions(-)
xen/common/event_channel.c +29 -0
@@ -934,6 +934,27 @@ out:return rc; } +static long evtchn_set_priority (const struct evtchn_set_priority *set_priority) +{ +struct domain *d = current->domain; +unsigned port = set_priority->port; +long ret; + +spin_lock (&d->event_lock); + +if ( !port_is_valid (d, port) ) + { +spin_unlock (&d->event_lock); +return -EINVAL ; + } + + ret =evtchn_port_set_priority (d,evtchn_from_port (d, port), + set_priority->priority); + +spin_unlock (&d->event_lock); + +return ret; +}long do_event_channel_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {
@@ -1043,6 +1064,14 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } +case EVTCHNOP_set_priority: { +struct evtchn_set_priority set_priority; +if (copy_from_guest (&set_priority, arg,1 ) !=0 ) +return -EFAULT ; + rc =evtchn_set_priority (&set_priority); +break ; + } +default : rc = -ENOSYS ;break ;
xen/include/xen/event.h +11 -0
@@ -123,6 +123,8 @@ struct evtchn_port_ops {void (*unmask)(struct domain *d,struct evtchn *evtchn);bool_t (*is_pending)(struct domain *d,const struct evtchn *evtchn);bool_t (*is_masked)(struct domain *d,const struct evtchn *evtchn); +int (*set_priority)(struct domain *d,struct evtchn *evtchn, +unsigned priority);void (*print_state)(struct domain *d,const struct evtchn *evtchn); };
@@ -156,6 +158,15 @@ static inline bool_t evtchn_port_is_masked(struct domain *d,return d->evtchn_port_ops->is_masked (d, evtchn); } +static inline int evtchn_port_set_priority (struct domain *d, +struct evtchn *evtchn, +unsigned priority) +{ +if ( !d->evtchn_port_ops->set_priority ) +return -ENOSYS ; +return d->evtchn_port_ops->set_priority (d, evtchn, priority); +} +static inline void evtchn_port_print_state (struct domain *d,const struct evtchn *evtchn) {
Signature · 1 line
1.7.2.5
PATCH v3 9/11 evtchn: implement EVTCHNOP_set_limit
In reply to David VrabelFrom: David Vrabel <[email protected]>
Add max_evtchn_port to struct domain as the maximum port number that a domain may bind. Allow a suitably privileged domain to set this limit so it may restrict the other domain's usage of Xen resources for event channels (primarily global mapping entries for the shared data structures).
The default values for this limit is unlimited for control domains or NR_EVENT_CHANNELS - 1 for other domains. These defaults ensure that no domain will regress in the number of event channels they may use.
If a domain is expected to use the FIFO-based event channel ABI, a toolstack may wish to set the limit to 1023 or lower to ensure a minimum number of global mapping entries is used.
--- xen/common/event_channel.c | 47 +++++++++++++++++++++++++++++++++++- xen/include/public/event_channel.h | 3 ++ xen/include/xen/sched.h | 1 + xen/include/xsm/dummy.h | 6 ++++ xen/include/xsm/xsm.h | 6 ++++ 5 files changed, 62 insertions(+), 1 deletions(-)
xen/common/event_channel.c +46 -1
@@ -132,10 +132,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 (unlikely (group_from_port (d, port) ==NULL ) )
@@ -956,6 +960,34 @@ static long evtchn_set_priority(const struct evtchn_set_priority *set_priority)return ret; } +static long evtchn_set_limit (const struct evtchn_set_limit *set_limit) +{ +struct domain *d; +unsigned max_port = set_limit->max_port; +long ret; + +if ( max_port >EVTCHN_MAX_PORT_UNLIMITED ) +return -EINVAL ; + + d =rcu_lock_domain_by_id (set_limit->domid); +if ( !d ) +return -ESRCH ; + + ret =xsm_evtchn_set_limit (XSM_DM_PRIV , d); +if ( ret ) + goto out; + +spin_lock (&d->event_lock); + + d->max_evtchn_port = max_port; + +spin_unlock (&d->event_lock); + +out: +rcu_unlock_domain (d); +return ret; +} +long do_event_channel_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {long rc;
@@ -1072,6 +1104,14 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } +case EVTCHNOP_set_limit: { +struct evtchn_set_limit set_limit; +if (copy_from_guest (&set_limit, arg,1 ) !=0 ) +return -EFAULT ; + rc =evtchn_set_limit (&set_limit); +break ; + } +default : rc = -ENOSYS ;break ;
@@ -1189,6 +1229,11 @@ void evtchn_check_pollers(struct domain *d, unsigned port)int evtchn_init (struct domain *d) { +if (is_control_domain (d) ) + d->max_evtchn_port =EVTCHN_MAX_PORT_UNLIMITED ; +else + d->max_evtchn_port =EVTCHN_MAX_PORT_DEFAULT ; +/* Default to N-level ABI. */ evtchn_2l_init (d);
xen/include/public/event_channel.h +3 -0
@@ -308,6 +308,9 @@ struct evtchn_set_limit { };typedef struct evtchn_set_limit evtchn_set_limit_t ; +#define EVTCHN_MAX_PORT_UNLIMITED ((1u << 31) - 1) +#define EVTCHN_MAX_PORT_DEFAULT (NR_EVENT_CHANNELS - 1) +/* * ` enum neg_errnoval * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op)
xen/include/xen/sched.h +1 -0
@@ -287,6 +287,7 @@ struct domain/* Event channel information. */ struct evtchn ***evtchn;unsigned max_evtchns; +unsigned max_evtchn_port;spinlock_t event_lock;const struct evtchn_port_ops *evtchn_port_ops;
xen/include/xsm/dummy.h +6 -0
@@ -296,6 +296,12 @@ static XSM_INLINE int xsm_evtchn_reset(XSM_DEFAULT_ARG struct domain *d1, structreturn xsm_default_action (action, d1, d2); } +static XSM_INLINE int xsm_evtchn_set_limit(XSM_DEFAULT_ARG struct domain *d) +{ +XSM_ASSERT_ACTION (XSM_DM_PRIV ); +return xsm_default_action (action, current->domain, d); +} + static XSM_INLINE int xsm_alloc_security_evtchn(struct evtchn *chn) {return 0 ;
xen/include/xsm/xsm.h +6 -0
@@ -70,6 +70,7 @@ struct xsm_operations {int (*evtchn_send) (struct domain *d,struct evtchn *chn);int (*evtchn_status) (struct domain *d,struct evtchn *chn);int (*evtchn_reset) (struct domain *d1,struct domain *d2); +int (*evtchn_set_limit) (struct domain *d);int (*grant_mapref) (struct domain *d1,struct domain *d2,uint32_t flags);int (*grant_unmapref) (struct domain *d1,struct domain *d2);
@@ -255,6 +256,11 @@ static inline int xsm_evtchn_reset (xsm_default_t def, struct domain *d1, structreturn xsm_ops->evtchn_reset (d1, d2); } +static inline int xsm_evtchn_set_limit (xsm_default_t def,struct domain *d) +{ +return xsm_ops->evtchn_set_limit (d); +} +static inline int xsm_grant_mapref (xsm_default_t def,struct domain *d1,struct domain *d2,uint32_t flags) {
Signature · 1 line
1.7.2.5
Re: [PATCH 09/11] evtchn: implement EVTCHNOP_set_limit
Quoted 12 lines · David Vrabel
From: David Vrabel <[email protected]>
Add
max_evtchn_portto struct domain as the maximum port number that a domain may bind. Allow a suitably privileged domain to set this limit so it may restrict the other domain's usage of Xen resources for event channels (primarily global mapping entries for the shared data structures).The default values for this limit is unlimited for control domains or
NR_EVENT_CHANNELS- 1 for other domains. These defaults ensure that no domain will regress in the number of event channels they may use.
Quoted 6 lines
If a domain is expected to use the FIFO-based event channel ABI, a toolstack may wish to set the limit to 1023 or lower to ensure a minimum number of global mapping entries is used.
Signed-off-by David Vrabel <[email protected]>Cc Daniel De Graaf <[email protected]>
This allows device model domains to adjust the limit of their target domain arbitrarily; I think it makes more sense for this to be XSM_PRIV so that only dom0 can adjust it, similar to max_mem. Control domains will already need an explicit XSM policy that can address this as a fine-grained permission.
The new XSM hook also needs to be added to xsm/dummy.c. Adding a FLASK hook and permission similar to the one for evtchn_reset would also be nice, but that may fit better in a later patch that adds this operation to the example security policy.
With the check changed to XSM_PRIV and a set_to_dummy_if_null line added to xsm/dummy.c, Acked-by: Daniel De Graaf <[email protected]>
Signature · 2 lines
Daniel De Graaf National Security Agency
Re: [PATCH 09/11] evtchn: implement EVTCHNOP_set_limit
In reply to David VrabelQuoted 11 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/common/event_channel.c +10
-0+static long evtchn_set_limit (const struct evtchn_set_limit *set_limit) +{ +struct domain *d; +unsigned max_port = set_limit->max_port; +long ret; + +if ( max_port >EVTCHN_MAX_PORT_UNLIMITED ) +return -EINVAL ; + + d =rcu_lock_domain_by_id (set_limit->domid);
xen/common/event_channel.c static long evtchn_set_priority(const struct evtchn_set_priority *set_priority) · line 982
Quoted 10 lines
xen/common/event_channel.c +10
-0+if ( !d ) +return -ESRCH ; + + ret =xsm_evtchn_set_limit (XSM_DM_PRIV , d); +if ( ret ) + goto out; + +spin_lock (&d->event_lock); + + d->max_evtchn_port = max_port;
So you allow this to be set even if the L2 ABI is in use. Does this make sense? Is this consistent?
xen/common/event_channel.c void evtchn_check_pollers(struct domain *d, unsigned port) · line 1238
Quoted 11 lines
xen/common/event_channel.c +5
-0@@ -1189,6 +1229,11 @@ void evtchn_check_pollers(struct domain *d, unsigned port)int evtchn_init (struct domain *d) { +if (is_control_domain (d) ) + d->max_evtchn_port =EVTCHN_MAX_PORT_UNLIMITED ; +else + d->max_evtchn_port =EVTCHN_MAX_PORT_DEFAULT ; +/* Default to N-level ABI. */ evtchn_2l_init (d);
Similarly here - you set limits that are not consistent with the default L2 ABI.
xen/include/public/event_channel.h struct evtchn_set_limit { · line 312
Quoted 8 lines
xen/include/public/event_channel.h +2
-0@@ -308,6 +308,9 @@ struct evtchn_set_limit { };typedef struct evtchn_set_limit evtchn_set_limit_t ; +#define EVTCHN_MAX_PORT_UNLIMITED ((1u << 31) - 1) +#define EVTCHN_MAX_PORT_DEFAULT (NR_EVENT_CHANNELS - 1)
Does the former really need to be part of the ABI? And does it really need to be 2^31-1 (rather than 2^32-1)?
Independent of that I think that - as hinted at in the overview mail - this ought to be a domctl.
Jan
Re: [PATCH 09/11] evtchn: implement EVTCHNOP_set_limit
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/common/event_channel.c +15
-0+static long evtchn_set_limit (const struct evtchn_set_limit *set_limit) +{ +struct domain *d; +unsigned max_port = set_limit->max_port; +long ret; + +if ( max_port >EVTCHN_MAX_PORT_UNLIMITED ) +return -EINVAL ; + + d =rcu_lock_domain_by_id (set_limit->domid); +if ( !d ) +return -ESRCH ; + + ret =xsm_evtchn_set_limit (XSM_DM_PRIV , d); +if ( ret )
Quoted 8 lines
xen/common/event_channel.c static long evtchn_set_priority(const struct evtchn_set_priority *set_priority) · line 982
Quoted 5 lines
xen/common/event_channel.c +5
-0+ goto out; + +spin_lock (&d->event_lock); + + d->max_evtchn_port = max_port;So you allow this to be set even if the L2 ABI is in use. Does this make sense? Is this consistent?
I think it would be confusing if guests could subvert the limit by using a different ABI, even if it doesn't really make much difference from a resource usage point of view.
Quoted 14 lines
xen/common/event_channel.c void evtchn_check_pollers(struct domain *d, unsigned port) · line 1238
Quoted 11 lines
xen/common/event_channel.c +5
-0@@ -1189,6 +1229,11 @@ void evtchn_check_pollers(struct domain *d, unsigned port)int evtchn_init (struct domain *d) { +if (is_control_domain (d) ) + d->max_evtchn_port =EVTCHN_MAX_PORT_UNLIMITED ; +else + d->max_evtchn_port =EVTCHN_MAX_PORT_DEFAULT ; +/* Default to N-level ABI. */ evtchn_2l_init (d);Similarly here - you set limits that are not consistent with the default L2 ABI.
I'm not sure why you think they are inconsistent, the limits set here are such that there is no regression in the number of usable event channels. A guest is still limited by the maximum supported by any ABI. i.e., the limit is min(d->max_evtchn_port, d->max_evtchns-1).
However, I'm going to change it so the hypervisor always sets the limit to unlimited. The toolstack should be responsible for setting any limits (and picking a sensible default).
Quoted 11 lines
xen/include/public/event_channel.h struct evtchn_set_limit { · line 312
Quoted 8 lines
xen/include/public/event_channel.h +2
-0@@ -308,6 +308,9 @@ struct evtchn_set_limit { };typedef struct evtchn_set_limit evtchn_set_limit_t ; +#define EVTCHN_MAX_PORT_UNLIMITED ((1u << 31) - 1) +#define EVTCHN_MAX_PORT_DEFAULT (NR_EVENT_CHANNELS - 1)Does the former really need to be part of the ABI? And does it really need to be 2^31-1 (rather than 2^32-1)?
The hypervisor uses int for port in places (e.g., get_free_port() where it returns a port number or a negative error code).
I will remove UNLIMITED from the ABI and set_limit will map any limit > UNLIMITED to UNLIMITED.
At some point some one should go a change all the uses for port number to unsigned but I think this is work independent of this series.
David
Re: [PATCH 09/11] evtchn: implement EVTCHNOP_set_limit
Quoted 27 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/common/event_channel.c +15
-0+static long evtchn_set_limit (const struct evtchn_set_limit *set_limit) +{ +struct domain *d; +unsigned max_port = set_limit->max_port; +long ret; + +if ( max_port >EVTCHN_MAX_PORT_UNLIMITED ) +return -EINVAL ; + + d =rcu_lock_domain_by_id (set_limit->domid); +if ( !d ) +return -ESRCH ; + + ret =xsm_evtchn_set_limit (XSM_DM_PRIV , d); +if ( ret )Quoted 8 lines
xen/common/event_channel.c static long evtchn_set_priority(const struct evtchn_set_priority *set_priority) · line 982
Quoted 5 lines
xen/common/event_channel.c +5
-0+ goto out; + +spin_lock (&d->event_lock); + + d->max_evtchn_port = max_port;So you allow this to be set even if the L2 ABI is in use. Does this make sense? Is this consistent?
Quoted 3 lines
I think it would be confusing if guests could subvert the limit by using a different ABI, even if it doesn't really make much difference from a resource usage point of view.
Somehow I'm getting the impression we're no understanding one another. My questions were:
- What's the point of permitting use of this function for a guest using the 2-level ABI?
- If you consider it valid to be used by a 2-level guest, will the result be consistent (will the guest see the limit enforced, and is there no implicit assumption somewhere that 2-level guests can always use the so far statically limited number of event channels)?
Quoted 15 lines
Quoted 14 lines
xen/common/event_channel.c void evtchn_check_pollers(struct domain *d, unsigned port) · line 1238
Quoted 11 lines
xen/common/event_channel.c +5
-0@@ -1189,6 +1229,11 @@ void evtchn_check_pollers(struct domain *d, unsigned port)int evtchn_init (struct domain *d) { +if (is_control_domain (d) ) + d->max_evtchn_port =EVTCHN_MAX_PORT_UNLIMITED ; +else + d->max_evtchn_port =EVTCHN_MAX_PORT_DEFAULT ; +/* Default to N-level ABI. */ evtchn_2l_init (d);Similarly here - you set limits that are not consistent with the default L2 ABI.
Quoted 4 lines
I'm not sure why you think they are inconsistent, the limits set here are such that there is no regression in the number of usable event channels. A guest is still limited by the maximum supported by any ABI. i.e., the limit is
min(d->max_evtchn_port, d->max_evtchns-1).
I asked because the limit for a 2-level Dom0 is now wrong. But you ought to read this in the context of the questions above, i.e. if all's consistent (and the max() you point out is indeed consistently enforced), then there is no issue.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
xen/include/public/event_channel.h +0
-0@@ -308,6 +308,9 @@ struct evtchn_set_limit { };typedef struct evtchn_set_limit evtchn_set_limit_t ;
Quoted 8 lines
Quoted 5 lines
xen/include/public/event_channel.h struct evtchn_set_limit { · line 312
Quoted 2 lines
xen/include/public/event_channel.h +2
-0+#define EVTCHN_MAX_PORT_UNLIMITED ((1u << 31) - 1) +#define EVTCHN_MAX_PORT_DEFAULT (NR_EVENT_CHANNELS - 1)Does the former really need to be part of the ABI? And does it really need to be 2^31-1 (rather than 2^32-1)?
The hypervisor uses int for port in places (e.g.,
get_free_port()where it returns a port number or a negative error code).
Ah, right, yes.
Quoted 5 lines
I will remove UNLIMITED from the ABI and
set_limitwill map any limit > UNLIMITED to UNLIMITED.At some point some one should go a change all the uses for port number to unsigned but I think this is work independent of this series.
Indeed.
Jan
Re: [PATCH 09/11] evtchn: implement EVTCHNOP_set_limit
Quoted 27 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · David Vrabel
Quoted 24 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · David Vrabel
xen/common/event_channel.c +10
-0+static long evtchn_set_limit (const struct evtchn_set_limit *set_limit) +{ +struct domain *d; +unsigned max_port = set_limit->max_port; +long ret; + +if ( max_port >EVTCHN_MAX_PORT_UNLIMITED ) +return -EINVAL ; + + d =rcu_lock_domain_by_id (set_limit->domid);xen/common/event_channel.c static long evtchn_set_priority(const struct evtchn_set_priority *set_priority) · line 982
Quoted 10 lines
xen/common/event_channel.c +10
-0+if ( !d ) +return -ESRCH ; + + ret =xsm_evtchn_set_limit (XSM_DM_PRIV , d); +if ( ret ) + goto out; + +spin_lock (&d->event_lock); + + d->max_evtchn_port = max_port;So you allow this to be set even if the L2 ABI is in use. Does this make sense? Is this consistent?
Quoted 8 lines
Quoted 3 lines
I think it would be confusing if guests could subvert the limit by using a different ABI, even if it doesn't really make much difference from a resource usage point of view.
Somehow I'm getting the impression we're no understanding one another. My questions were:
- What's the point of permitting use of this function for a guest using the 2-level ABI?
So any administrator set limit is consistently applied regardless of which ABI a guest uses.
Quoted 4 lines
- If you consider it valid to be used by a 2-level guest, will the result be consistent (will the guest see the limit enforced, and is there no implicit assumption somewhere that 2-level guests can always use the so far statically limited number of event channels)?
The limit is enforced (see the checks in get_free_port()) for all ABIs:
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 || port > d->max_evtchn_port )
return -ENOSPC;Quoted 20 lines
Quoted 15 lines
Quoted 14 lines
xen/common/event_channel.c void evtchn_check_pollers(struct domain *d, unsigned port) · line 1238
Quoted 11 lines
xen/common/event_channel.c +5
-0@@ -1189,6 +1229,11 @@ void evtchn_check_pollers(struct domain *d, unsigned port)int evtchn_init (struct domain *d) { +if (is_control_domain (d) ) + d->max_evtchn_port =EVTCHN_MAX_PORT_UNLIMITED ; +else + d->max_evtchn_port =EVTCHN_MAX_PORT_DEFAULT ; +/* Default to N-level ABI. */ evtchn_2l_init (d);Similarly here - you set limits that are not consistent with the default L2 ABI.
Quoted 4 lines
I'm not sure why you think they are inconsistent, the limits set here are such that there is no regression in the number of usable event channels. A guest is still limited by the maximum supported by any ABI. i.e., the limit is
min(d->max_evtchn_port, d->max_evtchns-1).
Quoted 4 lines
I asked because the limit for a 2-level Dom0 is now wrong. But you ought to read this in the context of the questions above, i.e. if all's consistent (and the
max()you point out is indeed consistently enforced), then there is no issue.
The maximum supported by the ABI and the administratively set limit are independent constraints. get_free_port() makes sure neither constraint is exceeded.
David
PATCH v3 10/11 libxc: add xc_evtchn_set_limit()
In reply to David VrabelFrom: David Vrabel <[email protected]>
Add xc_evtchn_set_limit(), a wrapper around the EVTCHNOP_set_limit hypercall.
--- tools/libxc/xc_evtchn.c | 6 ++++++ tools/libxc/xenctrl.h | 13 +++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
tools/libxc/xc_evtchn.c +6 -0
@@ -78,6 +78,12 @@ int xc_evtchn_status(xc_interface *xch, xc_evtchn_status_t *status) sizeof(*status), 1); } +int xc_evtchn_set_limit (xc_interface *xch,domid_t domid,uint32_t max_port) +{ +struct evtchn_set_limit arg = { .domid = domid, max_port = max_port }; +return do_evtchn_op (xch, EVTCHNOP_set_limit, &arg,sizeof (arg),0 ); +} +int xc_evtchn_fd (xc_evtchn *xce) {return xce->ops->u.evtchn.fd (xce, xce->ops_handle);
tools/libxc/xenctrl.h +13 -0
@@ -964,6 +964,19 @@ int xc_evtchn_reset(xc_interface *xch,typedef struct evtchn_status xc_evtchn_status_t ;int xc_evtchn_status (xc_interface *xch,xc_evtchn_status_t *status); +/** +* Set the maximum port number that a domain may use. +* +* The toolstack may use this to limit the amount of Xen resources +* (xenheap, global mapping pages, etc.) the domain may use for event +* channels. +* +* @parm xch a handle to an open hypervisor interface +* @parm domid the ID of the domain +* @parm max_port the new maximum port number +*/ +int xc_evtchn_set_limit (xc_interface *xch,domid_t domid,uint32_t max_port); +/* * Return a handle to the event channel driver, or NULL on failure, in * which case errno will be set appropriately.
Signature · 1 line
1.7.2.5
PATCH v3 11/11 evtchn: add FIFO-based event channel hypercalls and port ops
In reply to David VrabelFrom: David Vrabel <[email protected]>
Add the implementation for the FIFO-based event channel ABI. The new hypercall sub-ops (EVTCHNOP_init_control, EVTCHNOP_expand_array) and the required evtchn_ops (set_pending, unmask, etc.).
--- xen/common/Makefile | 1 + xen/common/event_channel.c | 20 ++ xen/common/event_fifo.c | 455 ++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/event_fifo.h | 54 +++++ xen/include/xen/sched.h | 7 +- 5 files changed, 536 insertions(+), 1 deletions(-) create mode 100644 xen/common/event_fifo.c create mode 100644 xen/include/xen/event_fifo.h
xen/common/Makefile +1 -0
@@ -7,6 +7,7 @@ obj-y += domctl.o obj-y += domain.o obj-y += event_2l.o obj-y += event_channel.o +obj-y += event_fifo.o obj-y += grant_table.o obj-y += irq.o obj-y += kernel.o
xen/common/event_channel.c +20 -0
@@ -26,6 +26,7 @@#include <xen/compat.h> #include <xen/guest_access.h> #include <xen/keyhandler.h> +#include <xen/event_fifo.h> #include <asm/current.h> #include <public/xen.h>
@@ -1096,6 +1097,24 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)break ; } +case EVTCHNOP_init_control: { +struct evtchn_init_control init_control; +if (copy_from_guest (&init_control, arg,1 ) !=0 ) +return -EFAULT ; + rc =evtchn_fifo_init_control (&init_control); +if ( !rc &&__copy_to_guest (arg, &init_control,1 ) ) + rc = -EFAULT ; +break ; + } + +case EVTCHNOP_expand_array: { +struct evtchn_expand_array expand_array; +if (copy_from_guest (&expand_array, arg,1 ) !=0 ) +return -EFAULT ; + rc =evtchn_fifo_expand_array (&expand_array); +break ; + } +case EVTCHNOP_set_priority: {struct evtchn_set_priority set_priority;if (copy_from_guest (&set_priority, arg,1 ) !=0 )
@@ -1300,6 +1319,7 @@ void evtchn_destroy(struct domain *d)clear_global_virq_handlers (d); +evtchn_fifo_destroy (d);xfree (d->evtchn); }
xen/common/event_fifo.c new file +455 -0
455 lines not on this page · raw message
xen/include/xen/event_fifo.h new file +54 -0
54 lines not on this page · raw message
xen/include/xen/sched.h +6 -1
@@ -61,7 +61,8 @@ extern struct domain *dom0;#define next_power_of_2 (x) (__RDU32((x)-1) + 1)/* Maximum number of event channels for any ABI. */ -#define MAX_NR_EVTCHNS NR_EVENT_CHANNELS +#define MAX_NR_EVTCHNS (max_t(unsigned, NR_EVENT_CHANNELS, \ + 1 << EVTCHN_FIFO_LINK_BITS))#define EVTCHNS_PER_BUCKET (PAGE_SIZE / next_power_of_2(sizeof(struct evtchn)))#define EVTCHNS_PER_GROUP (BUCKETS_PER_GROUP * EVTCHNS_PER_BUCKET)
@@ -95,6 +96,7 @@ struct evtchn } pirq;/* state == ECS_PIRQ */ u16 virq;/* state == ECS_VIRQ */ } u; +u8 priority;#ifdef FLASK_ENABLE void *ssid;#endif
@@ -209,6 +211,8 @@ struct vcpu/* Guest-specified relocation of vcpu_info. */ unsigned long vcpu_info_mfn; +struct evtchn_fifo_vcpu *evtchn_fifo; +struct arch_vcpu arch; };
@@ -290,6 +294,7 @@ struct domainunsigned max_evtchn_port;spinlock_t event_lock;const struct evtchn_port_ops *evtchn_port_ops; +struct evtchn_fifo_domain *evtchn_fifo;struct grant_table *grant_table;
Signature · 1 line
1.7.2.5