Implement 3-level event channels in Xen.
This patch series implements 3-level event channel routines in Xen.
The implementation is as followed:
* Add a field evtchn_level in struct domain.
* Add pointers in struct domain to point to 3-level shared array.
* Add 2nd level selector in struct vcpu.
* Add a new op in do_event_channel_op to register n-level evtchn.
The exposed interface for registering is extendable, however only 3-level is supported at the moment.
The routines for 3-level evtchns are more or less the same as 2-level ones.
RFC PATCH 1/3 Add a field in struct domain to indicate evtchn level.
From: Wei Liu <[email protected]>
--- xen/common/event_channel.c | 1 + xen/include/xen/sched.h | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
xen/common/event_channel.c +1 -0
@@ -1173,6 +1173,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)int evtchn_init (struct domain *d) {spin_lock_init (&d->event_lock); + d->evtchn_level =2 ;if (get_free_port (d) !=0 )return -EINVAL ;evtchn_from_port (d,0 )->state =ECS_RESERVED ;
xen/include/xen/sched.h +14 -1
@@ -50,7 +50,19 @@ extern struct domain *dom0;#else #define BITS_PER_EVTCHN_WORD (d) (has_32bit_shinfo(d) ? 32 : BITS_PER_LONG)#endif -#define MAX_EVTCHNS (d) (BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d)) +#define MAX_EVTCHNS_L2 (d) (BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d)) +#define MAX_EVTCHNS_L3 (d) (MAX_EVTCHNS_L2(d) * BITS_PER_EVTCHN_WORD(d)) +#define MAX_EVTCHNS (d) ({ int __v = 0; \ + switch ( d->evtchn_level ) { \ + case 2: \ + __v = MAX_EVTCHNS_L2(d); break; \ + case 3: \ + __v = MAX_EVTCHNS_L3(d); break; \ + default: \ + BUG(); \ + }; \ + __v;}) +#define EVTCHNS_PER_BUCKET 128#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS / EVTCHNS_PER_BUCKET)
@@ -262,6 +274,7 @@ struct domain/* Event channel information. */ struct evtchn *evtchn[NR_EVTCHN_BUCKETS ];spinlock_t event_lock; +unsigned int evtchn_level;struct grant_table *grant_table;
Signature · 1 line
1.7.10.4
RFC PATCH 2/3 Dynamically allocate domain->evtchn, also bump EVTCHNS_PER_BUCKET to 512.
In reply to Wei LiuFrom: Wei Liu <[email protected]>
--- xen/common/event_channel.c | 8 ++++++++ xen/include/xen/sched.h | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)
xen/common/event_channel.c +8 -0
@@ -1172,6 +1172,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)int evtchn_init (struct domain *d) { + d->evtchn = (struct evtchn **) + xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS); + +if ( !d->evtchn ) +return -ENOMEM ; +spin_lock_init (&d->event_lock); d->evtchn_level =2 ;if (get_free_port (d) !=0 )
@@ -1215,6 +1221,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 +2 -2
@@ -63,7 +63,7 @@ extern struct domain *dom0; }; \ __v;}) -#define EVTCHNS_PER_BUCKET 128 +#define EVTCHNS_PER_BUCKET 512#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS / EVTCHNS_PER_BUCKET)struct evtchn
@@ -272,7 +272,7 @@ struct domainspinlock_t rangesets_lock;/* Event channel information. */ -struct evtchn *evtchn[NR_EVTCHN_BUCKETS ]; +struct evtchn **evtchn;spinlock_t event_lock;unsigned int evtchn_level;
Signature · 1 line
1.7.10.4
RFC PATCH 3/3 Implement 3-level event channel routines.
In reply to Wei LiuFrom: Wei Liu <[email protected]>
Add some fields in struct domain to hold pointer to 3-level shared arrays. Also add per-cpu second level selector in struct vcpu.
These structures are mapped by a new evtchn op. Guest should fall back to use 2-level event channel if mapping fails.
The routines are more or less as the 2-level ones.
--- xen/arch/x86/domain.c | 2 + xen/arch/x86/irq.c | 2 +- xen/common/event_channel.c | 520 ++++++++++++++++++++++++++++++++++-- xen/common/keyhandler.c | 12 +- xen/common/schedule.c | 2 +- xen/include/public/event_channel.h | 24 ++ xen/include/public/xen.h | 17 +- xen/include/xen/event.h | 4 + xen/include/xen/sched.h | 12 +- 9 files changed, 565 insertions(+), 30 deletions(-)
xen/arch/x86/domain.c +2 -0
@@ -2058,6 +2058,8 @@ int domain_relinquish_resources(struct domain *d) } } +event_channel_unmap_nlevel (d); + d->arch.relmem = RELMEM_shared;/* fallthrough */
xen/arch/x86/irq.c +1 -1
@@ -1452,7 +1452,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_is_masked (d, pirqs[i]->evtchn) )pirq_guest_eoi (pirqs[i]); } }while ( ++pirq < d->nr_pirqs && n ==ARRAY_SIZE (pirqs) );
xen/common/event_channel.c +501 -19
620 lines not on this page · raw message
xen/common/keyhandler.c +6 -6
@@ -298,15 +298,15 @@ static void dump_domains(unsigned char key) { for_each_vcpu ( d, v ) { +unsigned int bits =BITS_PER_EVTCHN_WORD (d); +for (int i =2 ; i < d->evtchn_level; i++) + bits *=BITS_PER_EVTCHN_WORD (d);printk ("Notifying guest %d:%d (virq %d, port %d, stat %d/%d/%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), +evtchn_is_pending (d, v->virq_to_evtchn[VIRQ_DEBUG ]), +evtchn_is_masked (d, v->virq_to_evtchn[VIRQ_DEBUG ]), +test_bit (v->virq_to_evtchn[VIRQ_DEBUG ] / bits, &vcpu_info (v, evtchn_pending_sel)));send_guest_vcpu_virq (v,VIRQ_DEBUG ); }
xen/common/schedule.c +1 -1
@@ -693,7 +693,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_is_pending (d, port) ) goto out; }
xen/include/public/event_channel.h +24 -0
@@ -71,6 +71,7 @@#define EVTCHNOP_bind_vcpu 8#define EVTCHNOP_unmask 9#define EVTCHNOP_reset 10 +#define EVTCHNOP_register_nlevel 11/* ` } */ typedef uint32_t evtchn_port_t ;
@@ -258,6 +259,29 @@ struct evtchn_reset {typedef struct evtchn_reset evtchn_reset_t ;/* +* EVTCHNOP_register_nlevel: Register N level event channels. +* NOTES: +* 1. currently only 3-level is supported. +* 2. should fall back to basic 2-level if this call fails. +*/ +#define MAX_L3_PAGES 8 +struct evtchn_register_3level { +unsigned long evtchn_pending[MAX_L3_PAGES ]; +unsigned long evtchn_mask[MAX_L3_PAGES ]; +unsigned long *l2sel_mfn; +unsigned long *l2sel_offset; +uint32_t nr_vcpus; +}; + +struct evtchn_register_nlevel { +uint32_t level; +union { +struct evtchn_register_3level l3; + } u; +}; +typedef struct evtchn_register_nlevel evtchn_register_nlevel_t ; + +/* * ` enum neg_errnoval * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op) * `
xen/include/public/xen.h +16 -1
@@ -554,9 +554,24 @@ DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);/* * Event channel endpoints per domain: +* 2-level: * 1024 if a long is 32 bits; 4096 if a long is 64 bits. +* 3-level: +* 32k if a long is 32 bits; 256k if a long is 64 bits; */ -#define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L2 (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L3 (NR_EVENT_CHANNELS_L2 * 64) +#define NR_EVENT_CHANNELS (x) ({ unsigned int __v = 0; \ + switch (x) { \ + case 2: \ + __v = NR_EVENT_CHANNELS_L2; break; \ + case 3: \ + __v = NR_EVENT_CHANNELS_L3; break; \ + default: \ + BUG(); \ + } \ + __v;}) +struct vcpu_time_info {/*
xen/include/xen/event.h +4 -0
@@ -102,4 +102,8 @@ void notify_via_xen_event_channel(struct domain *ld, int lport);mb ();/* set blocked status /then/ caller does his work */ \ } while ( 0 ) +extern void event_channel_unmap_nlevel(struct domain *d); +int evtchn_is_masked (struct domain *d,int port); +int evtchn_is_pending (struct domain *d,int port); +#endif /* __XEN_EVENT_H__ */
xen/include/xen/sched.h +10 -2
@@ -64,7 +64,8 @@ extern struct domain *dom0; __v;})#define EVTCHNS_PER_BUCKET 512 -#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS / EVTCHNS_PER_BUCKET) +#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS_L3 / EVTCHNS_PER_BUCKET) +#define EVTCHNS_PER_PAGE (PAGE_SIZE * 8)struct evtchn {
@@ -104,7 +105,7 @@ void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */struct waitqueue_vcpu ; -struct vcpu +struct vcpu {int vcpu_id;
@@ -112,6 +113,9 @@ struct vcpuvcpu_info_t *vcpu_info; +/* For 3-level event channel */ +unsigned long *evtchn_pending_sel_l2; +struct domain *domain;struct vcpu *next_in_list;
@@ -275,6 +279,10 @@ struct domainstruct evtchn **evtchn;spinlock_t event_lock;unsigned int evtchn_level; +#define L3_PAGES (NR_EVENT_CHANNELS_L3/BITS_PER_LONG*sizeof(unsigned long)/PAGE_SIZE) +unsigned long *evtchn_pending[L3_PAGES ]; +unsigned long *evtchn_mask[L3_PAGES ]; +#undef L3_PAGESstruct grant_table *grant_table;
Signature · 1 line
1.7.10.4
Re: [RFC PATCH 1/3] Add a field in struct domain to indicate evtchn level.
In reply to Wei LiuQuoted 1 line · Wei Liu
From: Wei Liu <[email protected]>
The first patch needs to add the ABI documentation.
It's not clear what this is all for from just the changeset descriptions.
Quoted 11 lines
Signed-off-by Wei Liu <[email protected]>--- xen/common/event_channel.c | 1 + xen/include/xen/sched.h | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)xen/common/event_channel.c +0
-0
xen/common/event_channel.c void notify_via_xen_event_channel(struct domain *ld, int lport) · line 1176
Quoted 4 lines
xen/common/event_channel.c +1
-0@@ -1173,6 +1173,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)int evtchn_init (struct domain *d) {spin_lock_init (&d->event_lock); + d->evtchn_level =2 ;
I'd be inclined to have something like:
/* Original ABI: 2 level event channels */
#define EVTCHN_LEVEL_DEFAULT 2
...
d->evtchn_level = EVTCHN_LEVEL_DEFAULT;
Quoted 14 lines
xen/common/event_channel.c +0
-0if (get_free_port (d) !=0 )return -EINVAL ;evtchn_from_port (d,0 )->state =ECS_RESERVED ;xen/include/xen/sched.h +2
-1@@ -50,7 +50,19 @@ extern struct domain *dom0;#else #define BITS_PER_EVTCHN_WORD (d) (has_32bit_shinfo(d) ? 32 : BITS_PER_LONG)#endif -#define MAX_EVTCHNS (d) (BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d)) +#define MAX_EVTCHNS_L2 (d) (BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d)) +#define MAX_EVTCHNS_L3 (d) (MAX_EVTCHNS_L2(d) * BITS_PER_EVTCHN_WORD(d))
xen/include/xen/sched.h extern struct domain *dom0; · line 64
Quoted 10 lines
xen/include/xen/sched.h +10
-0+#define MAX_EVTCHNS (d) ({ int __v = 0; \ + switch ( d->evtchn_level ) { \ + case 2: \ + __v = MAX_EVTCHNS_L2(d); break; \ + case 3: \ + __v = MAX_EVTCHNS_L3(d); break; \ + default: \ + BUG(); \ + }; \ + __v;})
Here you BUG if d->evtchn_level is bad, but in other places in later patches with similar you have a printk. Need to be more consistent here.
On the Linux side you use a set of event channel ops instead of repeatedly testing d->evtchn_level. Would this also be a better approach for the Xen side?
David
Quoted 11 lines
xen/include/xen/sched.h +1
-0#define EVTCHNS_PER_BUCKET 128#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS / EVTCHNS_PER_BUCKET)@@ -262,6 +274,7 @@ struct domain/* Event channel information. */ struct evtchn *evtchn[NR_EVTCHN_BUCKETS ];spinlock_t event_lock; +unsigned int evtchn_level;struct grant_table *grant_table;
Re: [RFC PATCH 2/3] Dynamically allocate domain->evtchn, also bump EVTCHNS_PER_BUCKET to 512.
In reply to Wei LiuQuoted 1 line · Wei Liu
From: Wei Liu <[email protected]>
The changeset description needs to say why you're increasing EVTCHNS_PER_BUCKET. I can't tell why.
Quoted 11 lines
Signed-off-by Wei Liu <[email protected]>--- xen/common/event_channel.c | 8 ++++++++ xen/include/xen/sched.h | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)xen/common/event_channel.c +0
-0
xen/common/event_channel.c void notify_via_xen_event_channel(struct domain *ld, int lport) · line 1176
Quoted 5 lines
xen/common/event_channel.c +2
-0@@ -1172,6 +1172,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)int evtchn_init (struct domain *d) { + d->evtchn = (struct evtchn **) + xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS);
Don't need the cast here?
David
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
In reply to Wei LiuQuoted 11 lines · Wei Liu
From: Wei Liu <[email protected]>
Add some fields in struct domain to hold pointer to 3-level shared arrays. Also add per-cpu second level selector in struct vcpu.
These structures are mapped by a new evtchn op. Guest should fall back to use 2-level event channel if mapping fails.
The routines are more or less as the 2-level ones.
Signed-off-by Wei Liu <[email protected]>
[...]
Quoted 28 lines
xen/common/event_channel.c +15
-0@@ -27,6 +27,7 @@#include <xen/guest_access.h> #include <xen/keyhandler.h> #include <asm/current.h> +#include <xen/paging.h> #include <public/xen.h> #include <public/event_channel.h> @@ -413,6 +414,85 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)return rc; } +static inline int __evtchn_is_masked_l2 (struct domain *d,int port) +{ +return test_bit (port, &shared_info (d, evtchn_mask)); +} + +static inline int __evtchn_is_masked_l3 (struct domain *d,int port) +{ +return test_bit (port %EVTCHNS_PER_PAGE , + d->evtchn_mask[port /EVTCHNS_PER_PAGE ]); +} + +int evtchn_is_masked (struct domain *d,int port) +{ + switch ( d->evtchn_level )
xen/common/event_channel.c static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind) · line 440
Quoted 10 lines
xen/common/event_channel.c +10
-0+ { +case 2 : +return __evtchn_is_masked_l2 (d, port); +case 3 : +return __evtchn_is_masked_l3 (d, port); +default : +printk (" %s: unknown event channel level %d for domain %d \n" , + __FUNCTION__, d->evtchn_level, d->domain_id); +return 1 ; + }
Drop the printk? If d->evtchn_level is wrong this will spam the console and it BUGs elsewhere anyway.
There are a bunch of other similar places.
Quoted 30 lines
xen/common/event_channel.c +30
-0+static long __evtchn_register_3level (struct evtchn_register_3level *r) +{ +struct domain *d = current->domain; +unsigned long mfns[r->nr_vcpus]; +unsigned long offsets[r->nr_vcpus]; +unsigned char was_up[r->nr_vcpus]; +int rc, i; +struct vcpu *v; + +if ( d->evtchn_level ==3 ) +return -EINVAL ; + +if ( r->nr_vcpus > d->max_vcpus ) +return -EINVAL ; + +for ( i =0 ; i <MAX_L3_PAGES ; i++ ) +if ( d->evtchn_pending[i] || d->evtchn_mask[i] ) +return -EINVAL ; + + for_each_vcpu ( d, v ) +if ( v->evtchn_pending_sel_l2 ) +return -EINVAL ; + +if (copy_from_user (mfns, r->l2sel_mfn, +sizeof (unsigned long )*r->nr_vcpus) ) +return -EFAULT ; + +if (copy_from_user (offsets, r->l2sel_offset, +sizeof (unsigned long )*r->nr_vcpus) ) +return -EFAULT ;
xen/common/event_channel.c out: · line 1369
Quoted 10 lines
xen/common/event_channel.c +10
-0+ +/* put cpu offline */ + for_each_vcpu ( d, v ) + { +if ( v == current ) + was_up[v->vcpu_id] =1 ; +else + was_up[v->vcpu_id] = !test_and_set_bit (_VPF_down, + &v->pause_flags); + }
Why offline the VCPUs? I think there needs to be comment explaining why.
Quoted 9 lines
xen/common/event_channel.c +9
-0+/* map evtchn pending array and evtchn mask array */ + rc =__map_l3_arrays (d, r->evtchn_pending, r->evtchn_mask); +if ( rc ) + goto out; + + for_each_vcpu ( d, v ) + { +if ( (rc =__map_l2_sel (v, mfns[v->vcpu_id], offsets[v->vcpu_id])) ) + {
xen/common/event_channel.c out: · line 1389
Quoted 10 lines
xen/common/event_channel.c +10
-0+struct vcpu *v1; + for_each_vcpu ( d, v1 ) +__unmap_l2_sel (v1); +__unmap_l3_arrays (d); + goto out; + } + } + +/* Scan current bitmap and migrate all outstanding events to new bitmap */ +__evtchn_migrate_bitmap_l3 (d);
This migrate seems racy. Won't events after the migrate but before we set the level below be lost?
Alternatively, if it's not racy because it's all protected with d->event_lock, then the wmb() isn't required as the spin locks are implicit barriers.
Quoted 38 lines
xen/common/event_channel.c +35
-0+ +/* make sure all writes take effect before switching to new routines */ +wmb (); + d->evtchn_level =3 ; + + out: +/* bring cpus back online */ + for_each_vcpu ( d, v ) +if ( was_up[v->vcpu_id] && +test_and_clear_bit (_VPF_down, &v->pause_flags) ) +vcpu_wake (v); + +return rc; +} + +static long evtchn_register_nlevel (evtchn_register_nlevel_t *r) +{ +struct domain *d = current->domain; +int rc; + +spin_lock (&d->event_lock); + +switch ( r->level ) + { +case 3 : + rc =__evtchn_register_3level (&r->u.l3); +break ; +default : + rc = -EINVAL ; + } + +spin_unlock (&d->event_lock); + +return rc; +}long do_event_channel_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg) {
[...]
Quoted 11 lines
xen/include/public/event_channel.h +1
-0@@ -71,6 +71,7 @@#define EVTCHNOP_bind_vcpu 8#define EVTCHNOP_unmask 9#define EVTCHNOP_reset 10 +#define EVTCHNOP_register_nlevel 11/* ` } */ typedef uint32_t evtchn_port_t ;
xen/include/public/event_channel.h struct evtchn_reset { · line 267
Quoted 9 lines
xen/include/public/event_channel.h +6
-0@@ -258,6 +259,29 @@ struct evtchn_reset {typedef struct evtchn_reset evtchn_reset_t ;/* +* EVTCHNOP_register_nlevel: Register N level event channels. +* NOTES: +* 1. currently only 3-level is supported. +* 2. should fall back to basic 2-level if this call fails. +*/ +#define MAX_L3_PAGES 8
This is a public header so this needs to be prefixed. e.g.
#define EVTCHN_MAX_L3_PAGES 8
xen/include/public/event_channel.h struct evtchn_reset { · line 272
Quoted 5 lines
xen/include/public/event_channel.h +5
-0+struct evtchn_register_3level { +unsigned long evtchn_pending[MAX_L3_PAGES ]; +unsigned long evtchn_mask[MAX_L3_PAGES ]; +unsigned long *l2sel_mfn; +unsigned long *l2sel_offset;
Should these unsigned longs be xen_pfn_t's?
xen/include/public/event_channel.h struct evtchn_reset { · line 282
Quoted 10 lines
xen/include/public/event_channel.h +10
-0+uint32_t nr_vcpus; +}; + +struct evtchn_register_nlevel { +uint32_t level; +union { +struct evtchn_register_3level l3; + } u; +}; +typedef struct evtchn_register_nlevel evtchn_register_nlevel_t ;
Does there need to be compat handling for these structures? As-is the structures look like they do.
Quoted 22 lines
xen/include/public/event_channel.h +2
-0+ +/* * ` enum neg_errnoval * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op) * ` xen/include/public/xen.h +6
-1@@ -554,9 +554,24 @@ DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);/* * Event channel endpoints per domain: +* 2-level: * 1024 if a long is 32 bits; 4096 if a long is 64 bits. +* 3-level: +* 32k if a long is 32 bits; 256k if a long is 64 bits; */ -#define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L2 (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L3 (NR_EVENT_CHANNELS_L2 * 64) +#define NR_EVENT_CHANNELS (x) ({ unsigned int __v = 0; \
xen/include/public/xen.h DEFINE_XEN_GUEST_HANDLE(multicall_entry_t); · line 574
Quoted 10 lines
xen/include/public/xen.h +10
-0+switch (x) { \ +case 2 : \ + __v =NR_EVENT_CHANNELS_L2 ;break ; \ +case 3 : \ + __v =NR_EVENT_CHANNELS_L3 ;break ; \ +default : \ +BUG (); \ + } \ + __v;}) +
You've not documented what 'x' is in this macro. Also name it 'level'.
David
Re: [RFC PATCH 2/3] Dynamically allocate domain->evtchn, also bump EVTCHNS_PER_BUCKET to 512.
In reply to David VrabelQuoted 6 lines · David Vrabel
Quoted 1 line · Wei Liu
From: Wei Liu <[email protected]>
The changeset description needs to say why you're increasing
EVTCHNS_PER_BUCKET. I can't tell why.
Here is the tedious maths. My thought was that it is not very interesting to see this in a change log, so I dropped it. But I will add this in my later re-post of this series...
#define EVTCHNS_PER_BUCKET ???
#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNEL_L3/EVTCHNS_PER_BUCKET) d->evtchn = xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS);
We need to allow for 3-level evtchn, so use NR_EVENT_CHANNELS_L3 to calculate NR_EVTCHN_BUCKETS.
For 64 bit build, NR_EVENT_CHANNELS_L3 is 256k. The original value of EVTCHNS_PER_BUCKET is 128, which means NR_EVTCHN_BUCKETS=2048, thus d->evtchn has size of 2048*8 = 16KB = 4 pages. Given that only Dom0 or driver domain will need 3-level event channel, this is really overkill for most guests.
If we bump EVTCHNS_PER_BUCKET to 512, d->evtchn becomes 512 * 8 = 4KB = 1 page, which I think is more space efficient for most guests.
Of course, bumping EVTCHNS_PER_BUCKETS will cause overhead in other place. Xen allocates a buckets-size of struct evtchn at a time. So the overhead is:
sizeof(struct evtchn) * (512-128) ~= 18 bytes * 384
So the conclusion is:
1 page + sizeof(struct evtchn) * 384 < 4 pages
IMHO this is a good reason to bump EVTCHNS_PER_BUCKETS to 512.
Wei.
Quoted 20 lines
Quoted 11 lines
Signed-off-by Wei Liu <[email protected]>--- xen/common/event_channel.c | 8 ++++++++ xen/include/xen/sched.h | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)xen/common/event_channel.c +0
-0xen/common/event_channel.c void notify_via_xen_event_channel(struct domain *ld, int lport) · line 1176
Quoted 5 lines
xen/common/event_channel.c +2
-0@@ -1172,6 +1172,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)int evtchn_init (struct domain *d) { + d->evtchn = (struct evtchn **) + xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS);Don't need the cast here?
David
Re: [RFC PATCH 1/3] Add a field in struct domain to indicate evtchn level.
In reply to David VrabelQuoted 50 lines · David Vrabel
Quoted 1 line · Wei Liu
From: Wei Liu <[email protected]>
The first patch needs to add the ABI documentation.
It's not clear what this is all for from just the changeset descriptions.
Quoted 11 lines
Signed-off-by Wei Liu <[email protected]>--- xen/common/event_channel.c | 1 + xen/include/xen/sched.h | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)xen/common/event_channel.c +0
-0xen/common/event_channel.c void notify_via_xen_event_channel(struct domain *ld, int lport) · line 1176
Quoted 4 lines
xen/common/event_channel.c +1
-0@@ -1173,6 +1173,7 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)int evtchn_init (struct domain *d) {spin_lock_init (&d->event_lock); + d->evtchn_level =2 ;I'd be inclined to have something like:
/* Original ABI: 2 level event channels */
#defineEVTCHN_LEVEL_DEFAULT2
...d->evtchn_level = EVTCHN_LEVEL_DEFAULT;Quoted 19 lines
xen/common/event_channel.c +0
-0if (get_free_port (d) !=0 )return -EINVAL ;evtchn_from_port (d,0 )->state =ECS_RESERVED ;xen/include/xen/sched.h +7
-1@@ -50,7 +50,19 @@ extern struct domain *dom0;#else #define BITS_PER_EVTCHN_WORD (d) (has_32bit_shinfo(d) ? 32 : BITS_PER_LONG)#endif -#define MAX_EVTCHNS (d) (BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d)) +#define MAX_EVTCHNS_L2 (d) (BITS_PER_EVTCHN_WORD(d) * BITS_PER_EVTCHN_WORD(d)) +#define MAX_EVTCHNS_L3 (d) (MAX_EVTCHNS_L2(d) * BITS_PER_EVTCHN_WORD(d)) +#define MAX_EVTCHNS (d) ({ int __v = 0; \ + switch ( d->evtchn_level ) { \ + case 2: \ + __v = MAX_EVTCHNS_L2(d); break; \ + case 3: \
Quoted 9 lines
xen/include/xen/sched.h extern struct domain *dom0; · line 64
Quoted 5 lines
xen/include/xen/sched.h +5
-0+ __v =MAX_EVTCHNS_L3 (d);break ; \ +default : \ +BUG (); \ + }; \ + __v;})Here you BUG if
d->evtchn_levelis bad, but in other places in later patches with similar you have a printk. Need to be more consistent here.
Given that d->evtchn_level is only manipulated by the hypervisor, I think a BUG() here is correct. I will add a BUG() after printk's in other places if necessary. If I switch from 'switch' to ops pointers, this problem will automatically go away.
Quoted 3 lines
On the Linux side you use a set of event channel ops instead of repeatedly testing
d->evtchn_level. Would this also be a better approach for the Xen side?
I will have a look at this.
Wei.
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
In reply to Wei LiuQuoted 31 lines · Wei Liu
xen/common/event_channel.c +16
-0@@ -27,6 +27,7 @@#include <xen/guest_access.h> #include <xen/keyhandler.h> #include <asm/current.h> +#include <xen/paging.h> #include <public/xen.h> #include <public/event_channel.h> @@ -413,6 +414,85 @@ static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind)return rc; } +static inline int __evtchn_is_masked_l2 (struct domain *d,int port) +{ +return test_bit (port, &shared_info (d, evtchn_mask)); +} + +static inline int __evtchn_is_masked_l3 (struct domain *d,int port) +{ +return test_bit (port %EVTCHNS_PER_PAGE , + d->evtchn_mask[port /EVTCHNS_PER_PAGE ]); +} + +int evtchn_is_masked (struct domain *d,int port) +{ +switch ( d->evtchn_level ) + {
xen/common/event_channel.c static long evtchn_bind_pirq(evtchn_bind_pirq_t *bind) · line 441
Quoted 10 lines
xen/common/event_channel.c +10
-0+case 2 : +return __evtchn_is_masked_l2 (d, port); +case 3 : +return __evtchn_is_masked_l3 (d, port); +default : +printk (" %s: unknown event channel level %d for domain %d \n" , + __FUNCTION__, d->evtchn_level, d->domain_id); +return 1 ; + } +}
How much of this soft of thing goes away if we arrange for d->evtchn_mask to point to &shared_info(d, evtchn_mask) when evtchn_level == 2? (Likewise for pending etc)
Quoted 5 lines
xen/common/event_channel.c +0
-1@@ -633,7 +712,50 @@ static void evtchn_set_pending(struct vcpu *v, int port) {vcpu_mark_events_pending (v); } -
xen/common/event_channel.c static void evtchn_set_pending(struct vcpu *v, int port) · line 724
Quoted 10 lines
xen/common/event_channel.c +10
-0+} + +static void __evtchn_set_pending_l3 (struct vcpu *v,int port) +{ +struct domain *d = v->domain; + +int page_no = port /EVTCHNS_PER_PAGE ; +int offset = port %EVTCHNS_PER_PAGE ; +int l1cb =BITS_PER_EVTCHN_WORD (d)*BITS_PER_EVTCHN_WORD (d); +int l2cb =BITS_PER_EVTCHN_WORD (d);
What does "cb" in these variable stand for?
xen/common/event_channel.c static void evtchn_set_pending(struct vcpu *v, int port) · line 737
Quoted 13 lines
xen/common/event_channel.c +13
-0+ +if (test_and_set_bit (offset, d->evtchn_pending[page_no]) ) +return ; + +if ( !test_bit (offset, d->evtchn_mask[page_no]) && + !test_and_set_bit (port / l2cb, + v->evtchn_pending_sel_l2) && + !test_and_set_bit (port / l1cb, + &vcpu_info (v, evtchn_pending_sel)) ) + { +vcpu_mark_events_pending (v); + } +}
It doesn't seem like it would be too hard to merge this with the l2 version. Perhaps using a scheme similar to Linux's page table where a per-level macro collapses into a nop (with the appropriate return).
If you do end up duplicating the function then you should duplicate the command about the importance of the ordering and the barriers etc too.
You should write down the datastructure somewhere. In particular I'm not sure if l1 is at the top or the bottom. I think it's the top. I think it would also be useful to be explicit about what the l3 things corresponding to the fields in the shared info and vcpu info are and which is the new level.
Quoted 11 lines
xen/common/event_channel.c +11
-0+static int __map_l2_sel (struct vcpu *v,unsigned long gfn,unsigned long off) +{ +void *mapping; +int rc = -EINVAL ; +struct page_info *page; +struct domain *d = v->domain; + +if ( off >=PAGE_SIZE ) +return rc; + + page =get_page_from_gfn (d, gfn,NULL ,P2M_ALLOC );
xen/common/event_channel.c out: · line 1175
Quoted 10 lines
xen/common/event_channel.c +10
-0+if ( !page ) + goto out; + +if ( !get_page_type (page, PGT_writable_page) ) + { +put_page (page); + goto out; + } + + mapping =__map_domain_page_global (page);
I don't think you can validly use map_domain_page for a long lived mapping. domain_page.h says "Allow temporary mapping of domain page frames into Xen space.".
Are these array per-vcpu or shared? Because if they are per-vcpu you don't need the global variant.
Quoted 8 lines
xen/common/event_channel.c +8
-0+static int __map_l3_arrays (struct domain *d,unsigned long *pending, +unsigned long *mask) +{ +int i; +void *pending_mapping, *mask_mapping; +struct page_info *pending_page, *mask_page; +unsigned long pending_gfn, mask_gfn; +int rc = -EINVAL ;
xen/common/event_channel.c out: · line 1232
Quoted 10 lines
xen/common/event_channel.c +10
-0+ +for ( i =0 ; + i <MAX_L3_PAGES && pending[i] !=0 && mask[i] !=0 ; + i++ ) + { + pending_gfn = pending[i]; + mask_gfn = mask[i]; + + pending_page =get_page_from_gfn (d, pending_gfn,NULL ,P2M_ALLOC ); +if ( !pending_page )
I think you need to initialise rc here and for each subsequent goto err. The initial EINVAL is overwritten to ENOMEM below on the first iteration and isn't reset back to EINVAL at the top of the loop.
Quoted 69 lines
xen/common/event_channel.c +51
-0+ goto err; + + mask_page =get_page_from_gfn (d, mask_gfn,NULL ,P2M_ALLOC ); +if ( !mask_page ) + { +put_page (pending_page); + goto err; + } + +if ( !get_page_type (pending_page, PGT_writable_page) ) + { +put_page (pending_page); +put_page (mask_page); + goto err; + } + +if ( !get_page_type (mask_page, PGT_writable_page) ) + { +put_page_and_type (pending_page); +put_page (mask_page); + goto err; + } + + pending_mapping =__map_domain_page_global (pending_page); +if ( !pending_mapping ) + { +put_page_and_type (pending_page); +put_page_and_type (mask_page); + rc = -ENOMEM ; + goto err; + } + + mask_mapping =__map_domain_page_global (mask_page); +if ( !mask_mapping ) + { +unmap_domain_page_global (pending_mapping); +put_page_and_type (pending_page); +put_page_and_type (mask_page); + rc = -ENOMEM ; + goto err; + } + + d->evtchn_pending[i] = pending_mapping; + d->evtchn_mask[i] = mask_mapping; + } + + rc =0 ; + +err: +return rc; +}xen/include/public/event_channel.h +2
-0@@ -71,6 +71,7 @@#define EVTCHNOP_bind_vcpu 8#define EVTCHNOP_unmask 9#define EVTCHNOP_reset 10 +#define EVTCHNOP_register_nlevel 11/* ` } */ typedef uint32_t evtchn_port_t ;@@ -258,6 +259,29 @@ struct evtchn_reset {typedef struct evtchn_reset evtchn_reset_t ;/* +* EVTCHNOP_register_nlevel: Register N level event channels.
xen/include/public/event_channel.h struct evtchn_reset { · line 272
Quoted 10 lines
xen/include/public/event_channel.h +10
-0+* NOTES: +* 1. currently only 3-level is supported. +* 2. should fall back to basic 2-level if this call fails. +*/ +#define MAX_L3_PAGES 8 +struct evtchn_register_3level { +unsigned long evtchn_pending[MAX_L3_PAGES ]; +unsigned long evtchn_mask[MAX_L3_PAGES ]; +unsigned long *l2sel_mfn; +unsigned long *l2sel_offset;
You can't use bare pointers in a hypercall argument like this, you have to use the GUEST_HANDLE stuff.
Please also document which are IN and OUT parameters (look at other struct definitions for examples).
The evtchn_{pending,mask} can't be the actual pages, are they mfns?
xen/include/public/event_channel.h struct evtchn_reset { · line 279
Quoted 7 lines
xen/include/public/event_channel.h +7
-0+uint32_t nr_vcpus; +}; + +struct evtchn_register_nlevel { +uint32_t level; +union { +struct evtchn_register_3level l3;
Might be more extensible to N>3 if evtchn_{pending,mask} were also guest handles rather than fixed size arrays?
Quoted 24 lines
xen/include/public/event_channel.h +5
-0+ } u; +}; +typedef struct evtchn_register_nlevel evtchn_register_nlevel_t ; + +/* * ` enum neg_errnoval * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op) * ` xen/include/public/xen.h +5
-1@@ -554,9 +554,24 @@ DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);/* * Event channel endpoints per domain: +* 2-level: * 1024 if a long is 32 bits; 4096 if a long is 64 bits. +* 3-level: +* 32k if a long is 32 bits; 256k if a long is 64 bits; */ -#define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L2 (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L3 (NR_EVENT_CHANNELS_L2 * 64)
xen/include/public/xen.h DEFINE_XEN_GUEST_HANDLE(multicall_entry_t); · line 573
Quoted 10 lines
xen/include/public/xen.h +10
-0+#define NR_EVENT_CHANNELS (x) ({ unsigned int __v = 0; \ + switch (x) { \ + case 2: \ + __v = NR_EVENT_CHANNELS_L2; break; \ + case 3: \ + __v = NR_EVENT_CHANNELS_L3; break; \ + default: \ + BUG(); \ + } \ + __v;})
xen/include/public is supposed to be ANSI-C and I think the #define ({...}) syntax is a gcc-ism.
I think the ..._L{N} defines are sufficient.
Quoted 52 lines
xen/include/xen/sched.h +10
-3@@ -64,7 +64,8 @@ extern struct domain *dom0; __v;})#define EVTCHNS_PER_BUCKET 512 -#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS / EVTCHNS_PER_BUCKET) +#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS_L3 / EVTCHNS_PER_BUCKET) +#define EVTCHNS_PER_PAGE (PAGE_SIZE * 8)struct evtchn {@@ -104,7 +105,7 @@ void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */struct waitqueue_vcpu ; -struct vcpu +struct vcpu {int vcpu_id;@@ -112,6 +113,9 @@ struct vcpuvcpu_info_t *vcpu_info; +/* For 3-level event channel */ +unsigned long *evtchn_pending_sel_l2; +struct domain *domain;struct vcpu *next_in_list;@@ -275,6 +279,10 @@ struct domainstruct evtchn **evtchn;spinlock_t event_lock;unsigned int evtchn_level; +#define L3_PAGES (NR_EVENT_CHANNELS_L3/BITS_PER_LONG*sizeof(unsigned long)/PAGE_SIZE) +unsigned long *evtchn_pending[L3_PAGES ]; +unsigned long *evtchn_mask[L3_PAGES ]; +#undef L3_PAGESstruct grant_table *grant_table; --1.7.10.4
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [RFC PATCH 2/3] Dynamically allocate domain->evtchn, also bump EVTCHNS_PER_BUCKET to 512.
In reply to Wei LiuQuoted 20 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 6 lines · David Vrabel
Quoted 1 line · Wei Liu
From: Wei Liu <[email protected]>
The changeset description needs to say why you're increasing
EVTCHNS_PER_BUCKET. I can't tell why.Here is the tedious maths. My thought was that it is not very interesting to see this in a change log, so I dropped it. But I will add this in my later re-post of this series...
#define
EVTCHNS_PER_BUCKET???
#defineNR_EVTCHN_BUCKETS(NR_EVENT_CHANNEL_L3/EVTCHNS_PER_BUCKET)d->evtchn=xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS);We need to allow for 3-level evtchn, so use
NR_EVENT_CHANNELS_L3to calculateNR_EVTCHN_BUCKETS.
Quoted 8 lines
For 64 bit build,
NR_EVENT_CHANNELS_L3is 256k. The original value ofEVTCHNS_PER_BUCKETis 128, which means NR_EVTCHN_BUCKETS=2048, thusd->evtchnhas size of 2048*8 = 16KB = 4 pages. Given that only Dom0 or driver domain will need 3-level event channel, this is really overkill for most guests.If we bump
EVTCHNS_PER_BUCKETto 512,d->evtchnbecomes 512 * 8 = 4KB = 1 page, which I think is more space efficient for most guests.
But not suitable for allocation through xmalloc() (as it'll end up doing an order-1 page allocation). Either special case it here, or BUILD_BUG_ON() the effective size being exactly a page, or we may look into finally making xmalloc() return a page with no other tracking data when asked for exactly a page's worth of bytes.
Jan
Quoted 43 lines
Of course, bumping
EVTCHNS_PER_BUCKETSwill cause overhead in other place. Xen allocates a buckets-size of struct evtchn at a time. So the overhead is:sizeof(struct evtchn) * (512-128) ~= 18 bytes * 384
So the conclusion is:
1 page + sizeof(struct evtchn) * 384 < 4 pages
IMHO this is a good reason to bump
EVTCHNS_PER_BUCKETSto 512.Wei.
Quoted 11 lines
xen/common/event_channel.c void notify_via_xen_event_channel(struct domain *ld,
Quoted 11 lines
Signed-off-by Wei Liu <[email protected]>--- xen/common/event_channel.c | 8 ++++++++ xen/include/xen/sched.h | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)xen/common/event_channel.c +0
-0@@ -1172,6 +1172,12 @@ void notify_via_xen_event_channel(struct domain *ld,int lport)
Quoted 9 lines
xen/common/event_channel.c void notify_via_xen_event_channel(struct domain *ld, int lport) · line 1176
Quoted 5 lines
xen/common/event_channel.c +2
-0int evtchn_init (struct domain *d) { + d->evtchn = (struct evtchn **) + xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS);Don't need the cast here?
David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
In reply to Ian CampbellQuoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 1 line · Wei Liu
+ mapping =
__map_domain_page_global(page);I don't think you can validly use
map_domain_pagefor a long lived mapping.domain_page.hsays "Allow temporary mapping of domain page frames into Xen space.".
That's what distinguishes map_domain_page_global() from map_domain_page().
Quoted 2 lines
Are these array per-vcpu or shared? Because if they are per-vcpu you don't need the global variant.
You still would, as the non-global set of mappings that can be active at a time is limited. But the leaf pages ought to be shared anyway.
Jan
Re: [RFC PATCH 2/3] Dynamically allocate domain->evtchn, also bump EVTCHNS_PER_BUCKET to 512.
In reply to Jan BeulichQuoted 29 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 6 lines · David Vrabel
Quoted 1 line · Wei Liu
From: Wei Liu <[email protected]>
The changeset description needs to say why you're increasing
EVTCHNS_PER_BUCKET. I can't tell why.Here is the tedious maths. My thought was that it is not very interesting to see this in a change log, so I dropped it. But I will add this in my later re-post of this series...
#define
EVTCHNS_PER_BUCKET???
#defineNR_EVTCHN_BUCKETS(NR_EVENT_CHANNEL_L3/EVTCHNS_PER_BUCKET)d->evtchn=xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS);We need to allow for 3-level evtchn, so use
NR_EVENT_CHANNELS_L3to calculateNR_EVTCHN_BUCKETS.Quoted 8 lines
For 64 bit build,
NR_EVENT_CHANNELS_L3is 256k. The original value ofEVTCHNS_PER_BUCKETis 128, which means NR_EVTCHN_BUCKETS=2048, thusd->evtchnhas size of 2048*8 = 16KB = 4 pages. Given that only Dom0 or driver domain will need 3-level event channel, this is really overkill for most guests.If we bump
EVTCHNS_PER_BUCKETto 512,d->evtchnbecomes 512 * 8 = 4KB = 1 page, which I think is more space efficient for most guests.
Quoted 7 lines
But not suitable for allocation through
xmalloc()(as it'll end up doing an order-1 page allocation). Either special case it here, orBUILD_BUG_ON()the effective size being exactly a page, or we may look into finally makingxmalloc()return a page with no other tracking data when asked for exactly a page's worth of bytes.
Is alloc_xen_heap_page suitable? But I presume there is always some tracking structure somewhere, so I didn't even take that into account when I did calculation.
Can you give me some pointers, thanks.
Wei.
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
In reply to Wei Liuxen/common/event_channel.c static void evtchn_set_pending(struct vcpu *v, int port) · line 721
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Wei Liu
xen/common/event_channel.c +7
-1@@ -633,7 +712,50 @@ static void evtchn_set_pending(struct vcpu *v, int port) {vcpu_mark_events_pending (v); } - +} + +static void __evtchn_set_pending_l3 (struct vcpu *v,int port) +{ +struct domain *d = v->domain; + +int page_no = port /EVTCHNS_PER_PAGE ;
Anything used as array index should be unsigned int.
xen/common/event_channel.c static void evtchn_set_pending(struct vcpu *v, int port) · line 724
Quoted 3 lines
xen/common/event_channel.c +3
-0+int offset = port %EVTCHNS_PER_PAGE ; +int l1cb =BITS_PER_EVTCHN_WORD (d)*BITS_PER_EVTCHN_WORD (d); +int l2cb =BITS_PER_EVTCHN_WORD (d);
These always being powers of 2 (afaict), using divides rather than shifts is pretty inefficient (and I don't think the compiler has reasonable chances to recognize this and do the replacement for you).
xen/common/event_channel.c static void evtchn_set_pending(struct vcpu *v, int port) · line 733
Quoted 9 lines
xen/common/event_channel.c +9
-0+ +if (test_and_set_bit (offset, d->evtchn_pending[page_no]) ) +return ; + +if ( !test_bit (offset, d->evtchn_mask[page_no]) && + !test_and_set_bit (port / l2cb, + v->evtchn_pending_sel_l2) && + !test_and_set_bit (port / l1cb, + &vcpu_info (v, evtchn_pending_sel)) )
Indentation.
xen/common/event_channel.c out: · line 1148
Quoted 12 lines
xen/common/event_channel.c +8
-0@@ -969,6 +1138,290 @@ out:return rc; } +static void __unmap_l2_sel (struct vcpu *v) +{ +unsigned long mfn; + +if ( v->evtchn_pending_sel_l2 !=0 ) + { +unmap_domain_page_global (v->evtchn_pending_sel_l2); + mfn =virt_to_mfn (v->evtchn_pending_sel_l2);
virt_to_mfn() is not valid on the output of map_domain_page{,_global}() (same further down). Yes, there is at least one example of this in the existing code, but that's wrong too, and is getting eliminated by the 16Tb patch series I'm in the process of putting together.
Quoted 4 lines
xen/common/event_channel.c +4
-0+put_page_and_type (mfn_to_page (mfn)); + + v->evtchn_pending_sel_l2 =0 ; + }
xen/common/event_channel.c out: · line 1162
Quoted 10 lines
xen/common/event_channel.c +10
-0+} + +static int __map_l2_sel (struct vcpu *v,unsigned long gfn,unsigned long off) +{ +void *mapping; +int rc = -EINVAL ; +struct page_info *page; +struct domain *d = v->domain; + +if ( off >=PAGE_SIZE )
Is e.g. off == PAGE_SIZE-1 really valid here? As you're mapping guest memory here, _anything_ that is invalid must be rejected, or else you're creating a security hole.
xen/common/event_channel.c out: · line 1167
Quoted 5 lines
xen/common/event_channel.c +5
-0+return rc; + + page =get_page_from_gfn (d, gfn,NULL ,P2M_ALLOC ); +if ( !page ) + goto out;
Please be consistent here - always use return (as above) or (less preferred by me personally) always use goto.
Quoted 6 lines
xen/common/event_channel.c +6
-0+ +if ( !get_page_type (page, PGT_writable_page) ) + { +put_page (page); + goto out; + }
xen/common/event_channel.c out: · line 1183
Quoted 10 lines
xen/common/event_channel.c +10
-0+ + mapping =__map_domain_page_global (page); +if ( mapping ==NULL ) + { +put_page_and_type (page); + rc = -ENOMEM ; + goto out; + } + + v->evtchn_pending_sel_l2 = (unsigned long *)(mapping + off);
Pointless cast?
Quoted 48 lines
xen/common/event_channel.c +48
-0+static int __map_l3_arrays (struct domain *d,unsigned long *pending, +unsigned long *mask) +{ +int i; +void *pending_mapping, *mask_mapping; +struct page_info *pending_page, *mask_page; +unsigned long pending_gfn, mask_gfn; +int rc = -EINVAL ; + +for ( i =0 ; + i <MAX_L3_PAGES && pending[i] !=0 && mask[i] !=0 ; + i++ ) + { + pending_gfn = pending[i]; + mask_gfn = mask[i]; + + pending_page =get_page_from_gfn (d, pending_gfn,NULL ,P2M_ALLOC ); +if ( !pending_page ) + goto err; + + mask_page =get_page_from_gfn (d, mask_gfn,NULL ,P2M_ALLOC ); +if ( !mask_page ) + { +put_page (pending_page); + goto err; + } + +if ( !get_page_type (pending_page, PGT_writable_page) ) + { +put_page (pending_page); +put_page (mask_page); + goto err; + } + +if ( !get_page_type (mask_page, PGT_writable_page) ) + { +put_page_and_type (pending_page); +put_page (mask_page); + goto err; + } + + pending_mapping =__map_domain_page_global (pending_page); +if ( !pending_mapping ) + { +put_page_and_type (pending_page); +put_page_and_type (mask_page); + rc = -ENOMEM ; + goto err;
xen/common/event_channel.c out: · line 1272
Quoted 10 lines
xen/common/event_channel.c +10
-0+ } + + mask_mapping =__map_domain_page_global (mask_page); +if ( !mask_mapping ) + { +unmap_domain_page_global (pending_mapping); +put_page_and_type (pending_page); +put_page_and_type (mask_page); + rc = -ENOMEM ; + goto err;
The error paths in this function constitute well over half of it - can this not be consolidated in some way?
Quoted 20 lines
xen/common/event_channel.c +20
-0+static void __evtchn_migrate_bitmap_l3 (struct domain *d) +{ +struct vcpu *v; + +/* Easy way to migrate, just move existing selector down one level +* then copy the pending array and mask array */ + for_each_vcpu ( d, v ) + { +memcpy (&v->evtchn_pending_sel_l2[0 ], + &vcpu_info (v, evtchn_pending_sel), +sizeof (vcpu_info (v, evtchn_pending_sel))); + +memset (&vcpu_info (v, evtchn_pending_sel),0 , +sizeof (vcpu_info (v, evtchn_pending_sel))); + +set_bit (0 , &vcpu_info (v, evtchn_pending_sel)); + } + +memcpy (d->evtchn_pending[0 ], &shared_info (d, evtchn_pending), +sizeof (shared_info (d, evtchn_pending)));
xen/common/event_channel.c out: · line 1335
Quoted 10 lines
xen/common/event_channel.c +10
-0+memcpy (d->evtchn_mask[0 ], &shared_info (d, evtchn_mask), +sizeof (shared_info (d, evtchn_mask))); +} + +static long __evtchn_register_3level (struct evtchn_register_3level *r) +{ +struct domain *d = current->domain; +unsigned long mfns[r->nr_vcpus]; +unsigned long offsets[r->nr_vcpus]; +unsigned char was_up[r->nr_vcpus];
This is an absolute no-go in the hypervisor: Did you consider what happens when a guest has a few hundred vCPU-s?
xen/common/event_channel.c out: · line 1347
Quoted 12 lines
xen/common/event_channel.c +12
-0+int rc, i; +struct vcpu *v; + +if ( d->evtchn_level ==3 ) +return -EINVAL ; + +if ( r->nr_vcpus > d->max_vcpus ) +return -EINVAL ; + +for ( i =0 ; i <MAX_L3_PAGES ; i++ ) +if ( d->evtchn_pending[i] || d->evtchn_mask[i] ) +return -EINVAL ;
This and the check immediately below should be redundant with the level == 3 check earlier on (or if they aren't redundant, then you need to fix the code elsewhere).
xen/common/event_channel.c out: · line 1354
Quoted 7 lines
xen/common/event_channel.c +7
-0+ + for_each_vcpu ( d, v ) +if ( v->evtchn_pending_sel_l2 ) +return -EINVAL ; + +if (copy_from_user (mfns, r->l2sel_mfn, +sizeof (unsigned long )*r->nr_vcpus) )
copy_from_guest()!
Quoted 4 lines
xen/common/event_channel.c +4
-0+return -EFAULT ; + +if (copy_from_user (offsets, r->l2sel_offset, +sizeof (unsigned long )*r->nr_vcpus) )
xen/common/event_channel.c out: · line 1368
Quoted 10 lines
xen/common/event_channel.c +10
-0+return -EFAULT ; + +/* put cpu offline */ + for_each_vcpu ( d, v ) + { +if ( v == current ) + was_up[v->vcpu_id] =1 ; +else + was_up[v->vcpu_id] = !test_and_set_bit (_VPF_down, + &v->pause_flags);
This does not in any way halt that remote vCPU.
But anyway - is it really that useful to allow establishing the 3rd level with all vCPU-s already up and event processing already happening for the subject domain? I.e. wouldn't it suffice to require the guest to do the setup _before_ setting up the first event channel (which would imply on vCPU 0 to be active)?
xen/common/event_channel.c void evtchn_move_pirqs(struct vcpu *v) · line 1254
Quoted 5 lines
xen/common/event_channel.c +0
-1@@ -1251,7 +1712,6 @@ void evtchn_move_pirqs(struct vcpu *v)spin_unlock (&d->event_lock); } -
???
Quoted 15 lines
xen/common/event_channel.c +3
-5static void domain_dump_evtchn_info (struct domain *d) {unsigned int port;@@ -1276,11 +1740,28 @@ 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" , - port, - !!test_bit (port, &shared_info (d, evtchn_pending)), - !!test_bit (port, &shared_info (d, evtchn_mask)), - chn->state, chn->notify_vcpu_id, chn->xen_consumer); +printk (" %4u" , port); + + switch ( d->evtchn_level )
xen/common/event_channel.c static void domain_dump_evtchn_info(struct domain *d) · line 1755
Quoted 10 lines
xen/common/event_channel.c +10
-0+ { +case 2 : +printk (" [%d/%d]:" , + !!test_bit (port, &shared_info (d, evtchn_pending)), + !!test_bit (port, &shared_info (d, evtchn_mask))); +break ; +case 3 : +printk (" [%d/%d]:" , + !!test_bit (offset, d->evtchn_pending[page_no]), + !!test_bit (offset, d->evtchn_mask[page_no]));
Can't you, btw, set [0] of these two to the &shared_info() values, and thus fold code here and perhaps elsewhere?
xen/common/event_channel.c static void domain_dump_evtchn_info(struct domain *d) · line 1764
Quoted 9 lines
xen/common/event_channel.c +9
-0+break ; +default : +printk (" %s: unknown event channel level %d for domain %d \n" , + __FUNCTION__, d->evtchn_level, d->domain_id); + goto out; + } + +printk (" s=%d n=%d x=%d" , chn->state, chn->notify_vcpu_id, + chn->xen_consumer);
So still all event channels in one go?
xen/common/keyhandler.c static void dump_domains(unsigned char key) · line 302
Quoted 8 lines
xen/common/keyhandler.c +2
-0@@ -298,15 +298,15 @@ static void dump_domains(unsigned char key) { for_each_vcpu ( d, v ) { +unsigned int bits =BITS_PER_EVTCHN_WORD (d); +for (int i =2 ; i < d->evtchn_level; i++)
Did you check that gcc 4.1.x deals with this non-C89 code fine, with no warning?
xen/common/schedule.c static long do_poll(struct sched_poll *sched_poll) · line 696
Quoted 8 lines
xen/common/schedule.c +1
-1@@ -693,7 +693,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_is_pending (d, port) )
It would likely make the patch better readable if mechanical adjustments like this got split out into a prerequisite patch, even if used only in very few places.
Quoted 11 lines
xen/include/public/event_channel.h +1
-0@@ -71,6 +71,7 @@#define EVTCHNOP_bind_vcpu 8#define EVTCHNOP_unmask 9#define EVTCHNOP_reset 10 +#define EVTCHNOP_register_nlevel 11/* ` } */ typedef uint32_t evtchn_port_t ;
xen/include/public/event_channel.h struct evtchn_reset { · line 267
Quoted 9 lines
xen/include/public/event_channel.h +6
-0@@ -258,6 +259,29 @@ struct evtchn_reset {typedef struct evtchn_reset evtchn_reset_t ;/* +* EVTCHNOP_register_nlevel: Register N level event channels. +* NOTES: +* 1. currently only 3-level is supported. +* 2. should fall back to basic 2-level if this call fails. +*/ +#define MAX_L3_PAGES 8
Without explanation, no-one will easily understand whether this number is made up or the result of some calculation. Also, with it having "MAX" in its name, I'd conclude there can be fewer than 8 pages passed by the guest, yet the interface lacks any indication of how many pages there are being passed.
Quoted 25 lines
xen/include/public/event_channel.h +17
-0+struct evtchn_register_3level { +unsigned long evtchn_pending[MAX_L3_PAGES ]; +unsigned long evtchn_mask[MAX_L3_PAGES ]; +unsigned long *l2sel_mfn; +unsigned long *l2sel_offset; +uint32_t nr_vcpus; +}; + +struct evtchn_register_nlevel { +uint32_t level; +union { +struct evtchn_register_3level l3; + } u; +}; +typedef struct evtchn_register_nlevel evtchn_register_nlevel_t ; + +/* * ` enum neg_errnoval * ` HYPERVISOR_event_channel_op_compat(struct evtchn_op *op) * ` xen/include/public/xen.h +0
-0@@ -554,9 +554,24 @@ DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);/*
xen/include/public/xen.h DEFINE_XEN_GUEST_HANDLE(multicall_entry_t); · line 564
Quoted 10 lines
xen/include/public/xen.h +6
-1* Event channel endpoints per domain: +* 2-level: * 1024 if a long is 32 bits; 4096 if a long is 64 bits. +* 3-level: +* 32k if a long is 32 bits; 256k if a long is 64 bits; */ -#define NR_EVENT_CHANNELS (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L2 (sizeof(unsigned long) * sizeof(unsigned long) * 64) +#define NR_EVENT_CHANNELS_L3 (NR_EVENT_CHANNELS_L2 * 64) +#define NR_EVENT_CHANNELS (x) ({ unsigned int __v = 0; \
This is not a valid thing to do in a public header: You can't replace the object like NR_EVENT_CHANNELS with a function like alternative, you need to retain the old definition for consumers unaware of the new extension.
xen/include/xen/sched.h extern struct domain *dom0; · line 68
Quoted 9 lines
xen/include/xen/sched.h +2
-1@@ -64,7 +64,8 @@ extern struct domain *dom0; __v;})#define EVTCHNS_PER_BUCKET 512 -#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS / EVTCHNS_PER_BUCKET) +#define NR_EVTCHN_BUCKETS (NR_EVENT_CHANNELS_L3 / EVTCHNS_PER_BUCKET) +#define EVTCHNS_PER_PAGE (PAGE_SIZE * 8)
So is this 8 the same as the one above? If so, why don't you use the #define? If not, where does this 8 come from?
xen/include/xen/sched.h void evtchn_destroy_final(struct domain *d); /* from complete_domain_destroy */ · line 108
Quoted 7 lines
xen/include/xen/sched.h +0
-0@@ -104,7 +105,7 @@ void evtchn_destroy_final(struct domain *d); /* from
complete_domain_destroy*/struct
waitqueue_vcpu;xen/include/xen/sched.h +1
-1-struct vcpu +struct vcpu
???
xen/include/xen/sched.h struct domain · line 282
Quoted 5 lines
xen/include/xen/sched.h +1
-0@@ -275,6 +279,10 @@ struct domainstruct evtchn **evtchn;spinlock_t event_lock;unsigned int evtchn_level; +#define L3_PAGES (NR_EVENT_CHANNELS_L3/BITS_PER_LONG*sizeof(unsigned long)/PAGE_SIZE)
Without the use of BITS_TO_LONGS() and PFN_UP() it is not clear that you don't cut off any non-zero bits here. Hence you ought to either use those macros, or put a validating BUILD_BUG_ON() somewhere.
Jan
Re: [RFC PATCH 2/3] Dynamically allocate domain->evtchn, also bump EVTCHNS_PER_BUCKET to 512.
In reply to Wei LiuQuoted 39 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 29 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 6 lines · David Vrabel
Quoted 1 line · Wei Liu
From: Wei Liu <[email protected]>
The changeset description needs to say why you're increasing
EVTCHNS_PER_BUCKET. I can't tell why.Here is the tedious maths. My thought was that it is not very interesting to see this in a change log, so I dropped it. But I will add this in my later re-post of this series...
#define
EVTCHNS_PER_BUCKET???
#defineNR_EVTCHN_BUCKETS(NR_EVENT_CHANNEL_L3/EVTCHNS_PER_BUCKET)d->evtchn=xzalloc_array(struct evtchn *, NR_EVTCHN_BUCKETS);We need to allow for 3-level evtchn, so use
NR_EVENT_CHANNELS_L3to calculateNR_EVTCHN_BUCKETS.Quoted 8 lines
For 64 bit build,
NR_EVENT_CHANNELS_L3is 256k. The original value ofEVTCHNS_PER_BUCKETis 128, which means NR_EVTCHN_BUCKETS=2048, thusd->evtchnhas size of 2048*8 = 16KB = 4 pages. Given that only Dom0 or driver domain will need 3-level event channel, this is really overkill for most guests.If we bump
EVTCHNS_PER_BUCKETto 512,d->evtchnbecomes 512 * 8 = 4KB = 1 page, which I think is more space efficient for most guests.Quoted 7 lines
But not suitable for allocation through
xmalloc()(as it'll end up doing an order-1 page allocation). Either special case it here, orBUILD_BUG_ON()the effective size being exactly a page, or we may look into finally makingxmalloc()return a page with no other tracking data when asked for exactly a page's worth of bytes.
Quoted 3 lines
Is
alloc_xen_heap_pagesuitable? But I presume there is always some tracking structure somewhere, so I didn't even take that into account when I did calculation.
Yes, alloc_xenheap_page() is the right thing to use for exact page size allocations. There's no tracking structure associated with that (other than struct page_info, which exists regardless of that allocation).
Jan
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
In reply to Jan BeulichQuoted 17 lines · Jan Beulich
xen/common/event_channel.c out: · line 1148
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Wei Liu
xen/common/event_channel.c +8
-0+static void __unmap_l2_sel (struct vcpu *v) +{ +unsigned long mfn; + +if ( v->evtchn_pending_sel_l2 !=0 ) + { +unmap_domain_page_global (v->evtchn_pending_sel_l2); + mfn =virt_to_mfn (v->evtchn_pending_sel_l2);
virt_to_mfn()is not valid on the output of map_domain_page{,_global}() (same further down). Yes, there is at least one example of this in the existing code, but that's wrong too, and is getting eliminated by the 16Tb patch series I'm in the process of putting together.
So what's the correct way to do this? Do I need to wait for your patch series?
Wei.
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 17 lines · Jan Beulich
xen/common/event_channel.c out: · line 1148
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Wei Liu
xen/common/event_channel.c +8
-0+static void __unmap_l2_sel (struct vcpu *v) +{ +unsigned long mfn; + +if ( v->evtchn_pending_sel_l2 !=0 ) + { +unmap_domain_page_global (v->evtchn_pending_sel_l2); + mfn =virt_to_mfn (v->evtchn_pending_sel_l2);
virt_to_mfn()is not valid on the output of map_domain_page{,_global}() (same further down). Yes, there is at least one example of this in the existing code, but that's wrong too, and is getting eliminated by the 16Tb patch series I'm in the process of putting together.
Quoted 2 lines
So what's the correct way to do this? Do I need to wait for your patch series?
Considering that the old 32-bit case of map_domain_page() doesn't matter anymore, using domain_page_map_to_mfn() here would be the way to go (while the 32-bit version of it didn't allow map_domain_page_global() to be handled through it, my 64-bit implementation of it will).
And of course there's the obvious alternative of storing the MFN rather than re-obtaining it in the teardown path.
Jan
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 17 lines · Jan Beulich
xen/common/event_channel.c out: · line 1148
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Wei Liu
xen/common/event_channel.c +8
-0+static void __unmap_l2_sel (struct vcpu *v) +{ +unsigned long mfn; + +if ( v->evtchn_pending_sel_l2 !=0 ) + { +unmap_domain_page_global (v->evtchn_pending_sel_l2); + mfn =virt_to_mfn (v->evtchn_pending_sel_l2);
virt_to_mfn()is not valid on the output of map_domain_page{,_global}() (same further down). Yes, there is at least one example of this in the existing code, but that's wrong too, and is getting eliminated by the 16Tb patch series I'm in the process of putting together.
Quoted 5 lines
Quoted 2 lines
So what's the correct way to do this? Do I need to wait for your patch series?
Considering that the old 32-bit case of
map_domain_page()doesn't matter anymore,
We still care about it on 32-bit ARM FWIW. (I@m not sure if that invalidates your advice below though)
Quoted 15 lines
using
domain_page_map_to_mfn()
here would be the way to go (while the 32-bit version of it didn't allowmap_domain_page_global()to be handled through it, my 64-bit implementation of it will).And of course there's the obvious alternative of storing the MFN rather than re-obtaining it in the teardown path.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 17 lines · Jan Beulich
xen/common/event_channel.c out: · line 1148
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Wei Liu
xen/common/event_channel.c +8
-0+static void __unmap_l2_sel (struct vcpu *v) +{ +unsigned long mfn; + +if ( v->evtchn_pending_sel_l2 !=0 ) + { +unmap_domain_page_global (v->evtchn_pending_sel_l2); + mfn =virt_to_mfn (v->evtchn_pending_sel_l2);
virt_to_mfn()is not valid on the output of map_domain_page{,_global}() (same further down). Yes, there is at least one example of this in the existing code, but that's wrong too, and is getting eliminated by the 16Tb patch series I'm in the process of putting together.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
So what's the correct way to do this? Do I need to wait for your patch series?
Considering that the old 32-bit case of
map_domain_page()doesn't matter anymore,We still care about it on 32-bit ARM FWIW. (I@m not sure if that invalidates your advice below though)
Right - which would require ARM to implement domain_page_map_to_mfn() (so far used only in x86 and tmem code).
Quoted 7 lines
Quoted 7 lines
using
domain_page_map_to_mfn()
here would be the way to go (while the 32-bit version of it didn't allowmap_domain_page_global()to be handled through it, my 64-bit implementation of it will).And of course there's the obvious alternative of storing the MFN rather than re-obtaining it in the teardown path.
This second option of course would alway be valid, without architecture specific changes.
Jan
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
Quoted 28 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 25 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 17 lines · Jan Beulich
xen/common/event_channel.c out: · line 1148
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Wei Liu
xen/common/event_channel.c +8
-0+static void __unmap_l2_sel (struct vcpu *v) +{ +unsigned long mfn; + +if ( v->evtchn_pending_sel_l2 !=0 ) + { +unmap_domain_page_global (v->evtchn_pending_sel_l2); + mfn =virt_to_mfn (v->evtchn_pending_sel_l2);
virt_to_mfn()is not valid on the output of map_domain_page{,_global}() (same further down). Yes, there is at least one example of this in the existing code, but that's wrong too, and is getting eliminated by the 16Tb patch series I'm in the process of putting together.Quoted 2 lines
So what's the correct way to do this? Do I need to wait for your patch series?
Considering that the old 32-bit case of
map_domain_page()doesn't matter anymore,
Quoted 6 lines
Quoted 2 lines
We still care about it on 32-bit ARM FWIW. (I@m not sure if that invalidates your advice below though)
Right - which would require ARM to implement
domain_page_map_to_mfn()(so far used only in x86 and tmem code).
I only see it in x86 (specifically hvm_unmap_guest_frame) but I guess this is a useful interface for ARM to implement in any case and it doesn't look to be terribly hard.
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
using
domain_page_map_to_mfn()
here would be the way to go (while the 32-bit version of it didn't allowmap_domain_page_global()to be handled through it, my 64-bit implementation of it will).And of course there's the obvious alternative of storing the MFN rather than re-obtaining it in the teardown path.
This second option of course would alway be valid, without architecture specific changes.
Right.
Ian.
Re: [RFC PATCH 3/3] Implement 3-level event channel routines.
Quoted 33 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 31 lines · Jan Beulich
Quoted 30 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Wei Liu
Quoted 17 lines · Jan Beulich
Review
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Wei Liu
(quoted diff) +8
-0+static void __unmap_l2_sel(struct vcpu *v) +{ + unsigned long mfn; + + if ( v->evtchn_pending_sel_l2 != 0 ) + { + unmap_domain_page_global(v->evtchn_pending_sel_l2); + mfn = virt_to_mfn(v->evtchn_pending_sel_l2);
virt_to_mfn()is not valid on the output of map_domain_page{,_global}() (same further down). Yes, there is at least one example of this in the existing code, but that's wrong too, and is getting eliminated by the 16Tb patch series I'm in the process of putting together.Quoted 5 lines
Quoted 2 lines
So what's the correct way to do this? Do I need to wait for your patch series?
Considering that the old 32-bit case of
map_domain_page()doesn't matter anymore,We still care about it on 32-bit ARM FWIW. (I@m not sure if that invalidates your advice below though)
Quoted 7 lines
Quoted 3 lines
Right - which would require ARM to implement
domain_page_map_to_mfn()(so far used only in x86 and tmem code).I only see it in x86 (specifically
hvm_unmap_guest_frame) but I guess this is a useful interface for ARM to implement in any case and it doesn't look to be terribly hard.
Oh, the tmem one is from my 16Tb series that I'm hoping to post soon.
Jan