xen/events: fix global virq handling
PATCH v2 1/1 xen/events: fix global virq handling
VIRQs are split into "global" and "per vcpu" ones. Unfortunately in reality there are "per domain" ones, too.
send_global_virq() and set_global_virq_handler() make only sense for the real "global" ones, so replace virq_is_global() with a new function get_virq_type() returning one of the 3 possible types (global, domain, vcpu VIRQ).
To make its intended purpose more clear, also rename send_guest_global_virq() to send_guest_domain_virq().
---
As I don't have much time today (I'm having a day off), only compile tested. Please try a CI run with this patch before applying!
Whether the "domain" infix in send_guest_domain_virq() is really useful I don't know. Maybe we should go even father with renaming, to have {vcpu,domain}_send_virq()?
---
v2: Also rename send_guest_global_virq().
xen/arch/arm/include/asm/event.h +2 -2
@@ -47,9 +47,9 @@ static inline void local_event_delivery_ }/* No arch specific virq definition now. Default to global. */ -static inline bool arch_virq_is_global (unsigned int virq) +static inline enum virq_type arch_get_virq_type (unsigned int virq) { -return true; +return VIRQ_GLOBAL ; }#endif
xen/arch/ppc/include/asm/event.h +2 -2
@@ -17,9 +17,9 @@ static inline int vcpu_event_delivery_is }/* No arch specific virq definition now. Default to global. */ -static inline bool arch_virq_is_global (unsigned int virq) +static inline enum virq_type arch_get_virq_type (unsigned int virq) { -return true; +return VIRQ_GLOBAL ; }static inline int local_events_need_delivery (void )
xen/arch/riscv/include/asm/event.h +2 -2
@@ -24,9 +24,9 @@ static inline void local_event_delivery_ }/* No arch specific virq definition now. Default to global. */ -static inline bool arch_virq_is_global (unsigned int virq) +static inline enum virq_type arch_get_virq_type (unsigned int virq) { -return true; +return VIRQ_GLOBAL ; }#endif /* ASM__RISCV__EVENT_H */
xen/arch/x86/include/asm/event.h +3 -3
@@ -41,10 +41,10 @@ static inline void local_event_delivery_vcpu_info (current, evtchn_upcall_mask) =0 ; } -/* No arch specific virq definition now. Default to global. */ -static inline bool arch_virq_is_global (unsigned int virq) +/* Only global arch specific virq definitions. */ +static inline enum virq_type arch_get_virq_type (unsigned int virq) { -return true; +return VIRQ_GLOBAL ; }#ifdef CONFIG_PV_SHIM
xen/common/argo.c +1 -1
@@ -440,7 +440,7 @@ signal_domain(struct domain *d) {argo_dprintk ("signalling domid:%u\n" , d->domain_id); -send_guest_global_virq (d,VIRQ_ARGO ); +send_guest_domain_virq (d,VIRQ_ARGO ); } static void
xen/common/event_channel.c +21 -17
@@ -127,7 +127,7 @@ static struct domain *get_global_virq_hareturn global_virq_handlers[virq] ?: hardware_domain; } -static bool virq_is_global (unsigned int virq) +static enum virq_type get_virq_type (unsigned int virq) {switch ( virq ) {
@@ -135,14 +135,17 @@ static bool virq_is_global(unsigned intcase VIRQ_DEBUG :case VIRQ_XENOPROF :case VIRQ_XENPMU : -return false; +return VIRQ_VCPU ; + +case VIRQ_ARGO : +return VIRQ_DOMAIN ; case VIRQ_ARCH_0 ... VIRQ_ARCH_7: -return arch_virq_is_global (virq); +return arch_get_virq_type (virq); }ASSERT (virq <NR_VIRQS ); -return true; +return VIRQ_GLOBAL ; } static struct evtchn *_evtchn_from_port(const struct domain *d,
@@ -476,7 +479,7 @@ int evtchn_bind_virq(evtchn_bind_virq_tstruct domain *d = current->domain;int virq = bind->virq, vcpu = bind->vcpu;int rc =0 ; -bool is_global; +enum virq_type type;if ( (virq <0 ) || (virq >=ARRAY_SIZE (v->virq_to_evtchn)) )return -EINVAL ;
@@ -486,9 +489,9 @@ int evtchn_bind_virq(evtchn_bind_virq_t* speculative execution. */ virq =array_index_nospec (virq,ARRAY_SIZE (v->virq_to_evtchn)); - is_global =virq_is_global (virq); + type =get_virq_type (virq); -if ( is_global && vcpu !=0 ) +if ( type !=VIRQ_VCPU && vcpu !=0 )return -EINVAL ;if ( (v =domain_vcpu (d, vcpu)) ==NULL )
@@ -496,7 +499,7 @@ int evtchn_bind_virq(evtchn_bind_virq_twrite_lock (&d->event_lock); -if ( is_global &&get_global_virq_handler (virq) != d ) +if ( type ==VIRQ_GLOBAL &&get_global_virq_handler (virq) != d ) { rc = -EBUSY ; goto out;
@@ -756,7 +759,8 @@ int evtchn_close(struct domain *d1, intif ( chn1->u.virq ==VIRQ_DOM_EXC )domain_deinit_states (d1); - v = d1->vcpu[virq_is_global (chn1->u.virq) ?0 : chn1->notify_vcpu_id]; + v = d1->vcpu[get_virq_type (chn1->u.virq) !=VIRQ_VCPU + ?0 : chn1->notify_vcpu_id];write_lock_irqsave (&v->virq_lock, flags);ASSERT (read_atomic (&v->virq_to_evtchn[chn1->u.virq]) == port1);
@@ -900,7 +904,7 @@ bool evtchn_virq_enabled(const struct vcif ( !v )return false; -if (virq_is_global (virq) && v->vcpu_id ) +if (get_virq_type (virq) !=VIRQ_VCPU && v->vcpu_id ) v =domain_vcpu (v->domain,0 );return read_atomic (&v->virq_to_evtchn[virq]);
@@ -913,7 +917,7 @@ void send_guest_vcpu_virq(struct vcpu *vstruct domain *d;struct evtchn *chn; -ASSERT (!virq_is_global (virq)); +ASSERT (get_virq_type (virq) ==VIRQ_VCPU );read_lock_irqsave (&v->virq_lock, flags);
@@ -933,14 +937,14 @@ void send_guest_vcpu_virq(struct vcpu *vread_unlock_irqrestore (&v->virq_lock, flags); } -void send_guest_global_virq (struct domain *d,uint32_t virq) +void send_guest_domain_virq (struct domain *d,uint32_t virq) {unsigned long flags;int port;struct vcpu *v;struct evtchn *chn; -ASSERT (virq_is_global (virq)); +ASSERT (get_virq_type (virq) !=VIRQ_VCPU );if (unlikely (d ==NULL ) ||unlikely (d->vcpu ==NULL ) )return ;
@@ -995,9 +999,9 @@ static DEFINE_SPINLOCK(global_virq_handlvoid send_global_virq (uint32_t virq) { -ASSERT (virq_is_global (virq)); +ASSERT (get_virq_type (virq) ==VIRQ_GLOBAL ); -send_guest_global_virq (get_global_virq_handler (virq), virq); +send_guest_domain_virq (get_global_virq_handler (virq), virq); }int set_global_virq_handler (struct domain *d,uint32_t virq)
@@ -1008,7 +1012,7 @@ int set_global_virq_handler(struct domaiif (virq >=NR_VIRQS )return -EINVAL ; -if (!virq_is_global (virq)) +if (get_virq_type (virq) !=VIRQ_GLOBAL )return -EINVAL ;if (global_virq_handlers[virq] == d)
@@ -1204,7 +1208,7 @@ int evtchn_bind_vcpu(evtchn_port_t port,switch ( chn->state ) {case ECS_VIRQ : -if (virq_is_global (chn->u.virq) ) +if (get_virq_type (chn->u.virq) !=VIRQ_VCPU ) chn->notify_vcpu_id = v->vcpu_id;else rc = -EINVAL ;
xen/include/xen/event.h +7 -7
@@ -24,17 +24,17 @@void send_guest_vcpu_virq (struct vcpu *v,uint32_t virq);/* -* send_global_virq: Notify the domain handling a global VIRQ. -* @virq: Virtual IRQ number (VIRQ_*) +* send_guest_domain_virq: +* @d: Domain to which VIRQ should be sent +* @virq: Virtual IRQ number (VIRQ_*), may not be per-vCPU */ -void send_global_virq (uint32_t virq); +void send_guest_domain_virq (struct domain *d,uint32_t virq);/* -* send_guest_global_virq: -* @d: Domain to which VIRQ should be sent -* @virq: Virtual IRQ number (VIRQ_*), must be global +* send_global_virq: Notify the domain handling a global VIRQ. +* @virq: Virtual IRQ number (VIRQ_*) */ -void send_guest_global_virq (struct domain *d,uint32_t virq); +void send_global_virq (uint32_t virq);/* * sent_global_virq_handler: Set a global VIRQ handler.
xen/include/xen/sched.h +6 -0
@@ -84,6 +84,12 @@ extern domid_t hardware_domid;#define XEN_CONSUMER_BITS 3#define NR_XEN_CONSUMERS ((1 << XEN_CONSUMER_BITS) - 1) +enum virq_type { +VIRQ_GLOBAL , +VIRQ_DOMAIN , +VIRQ_VCPU +}; +struct evtchn {rwlock_t lock;
On 07.03.2025 11:11, Jan Beulich wrote:
Sorry, missed
From: Juergen Gross <[email protected]>
Jan
Quoted 272 lines
VIRQs are split into "global" and "per vcpu" ones. Unfortunately in reality there are "per domain" ones, too.
send_global_virq()andset_global_virq_handler()make only sense for the real "global" ones, so replacevirq_is_global()with a new functionget_virq_type()returning one of the 3 possible types (global, domain, vcpu VIRQ).To make its intended purpose more clear, also rename
send_guest_global_virq()tosend_guest_domain_virq().Fixes 980822c5edd1 ("xen/events: allow setting of global virq handler only for unbound virqs")Signed-off-by Juergen Gross <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
As I don't have much time today (I'm having a day off), only compile tested. Please try a CI run with this patch before applying!Whether the "domain" infix in
send_guest_domain_virq()is really useful I don't know. Maybe we should go even father with renaming, to have {vcpu,domain}_send_virq()?
---
v2: Also renamesend_guest_global_virq().xen/arch/arm/include/asm/event.h +2
-2@@ -47,9 +47,9 @@ static inline void local_event_delivery_ }/* No arch specific virq definition now. Default to global. */ -static inline bool arch_virq_is_global (unsigned int virq) +static inline enum virq_type arch_get_virq_type (unsigned int virq) { -return true; +return VIRQ_GLOBAL ; }#endif xen/arch/ppc/include/asm/event.h +2
-2@@ -17,9 +17,9 @@ static inline int vcpu_event_delivery_is }/* No arch specific virq definition now. Default to global. */ -static inline bool arch_virq_is_global (unsigned int virq) +static inline enum virq_type arch_get_virq_type (unsigned int virq) { -return true; +return VIRQ_GLOBAL ; }static inline int local_events_need_delivery (void )xen/arch/riscv/include/asm/event.h +2
-2@@ -24,9 +24,9 @@ static inline void local_event_delivery_ }/* No arch specific virq definition now. Default to global. */ -static inline bool arch_virq_is_global (unsigned int virq) +static inline enum virq_type arch_get_virq_type (unsigned int virq) { -return true; +return VIRQ_GLOBAL ; }#endif /* ASM__RISCV__EVENT_H */ xen/arch/x86/include/asm/event.h +3
-3@@ -41,10 +41,10 @@ static inline void local_event_delivery_vcpu_info (current, evtchn_upcall_mask) =0 ; } -/* No arch specific virq definition now. Default to global. */ -static inline bool arch_virq_is_global (unsigned int virq) +/* Only global arch specific virq definitions. */ +static inline enum virq_type arch_get_virq_type (unsigned int virq) { -return true; +return VIRQ_GLOBAL ; }#ifdef CONFIG_PV_SHIM xen/common/argo.c +1
-1@@ -440,7 +440,7 @@ signal_domain(struct domain *d) {argo_dprintk ("signalling domid:%u\n" , d->domain_id); -send_guest_global_virq (d,VIRQ_ARGO ); +send_guest_domain_virq (d,VIRQ_ARGO ); } static voidxen/common/event_channel.c +21
-17@@ -127,7 +127,7 @@ static struct domain *get_global_virq_hareturn global_virq_handlers[virq] ?: hardware_domain; } -static bool virq_is_global (unsigned int virq) +static enum virq_type get_virq_type (unsigned int virq) {switch ( virq ) {@@ -135,14 +135,17 @@ static bool virq_is_global(unsigned intcase VIRQ_DEBUG :case VIRQ_XENOPROF :case VIRQ_XENPMU : -return false; +return VIRQ_VCPU ; + +case VIRQ_ARGO : +return VIRQ_DOMAIN ; case VIRQ_ARCH_0 ... VIRQ_ARCH_7: -return arch_virq_is_global (virq); +return arch_get_virq_type (virq); }ASSERT (virq <NR_VIRQS ); -return true; +return VIRQ_GLOBAL ; } static struct evtchn *_evtchn_from_port(const struct domain *d,@@ -476,7 +479,7 @@ int evtchn_bind_virq(evtchn_bind_virq_tstruct domain *d = current->domain;int virq = bind->virq, vcpu = bind->vcpu;int rc =0 ; -bool is_global; +enum virq_type type;if ( (virq <0 ) || (virq >=ARRAY_SIZE (v->virq_to_evtchn)) )return -EINVAL ;@@ -486,9 +489,9 @@ int evtchn_bind_virq(evtchn_bind_virq_t* speculative execution. */ virq =array_index_nospec (virq,ARRAY_SIZE (v->virq_to_evtchn)); - is_global =virq_is_global (virq); + type =get_virq_type (virq); -if ( is_global && vcpu !=0 ) +if ( type !=VIRQ_VCPU && vcpu !=0 )return -EINVAL ;if ( (v =domain_vcpu (d, vcpu)) ==NULL )@@ -496,7 +499,7 @@ int evtchn_bind_virq(evtchn_bind_virq_twrite_lock (&d->event_lock); -if ( is_global &&get_global_virq_handler (virq) != d ) +if ( type ==VIRQ_GLOBAL &&get_global_virq_handler (virq) != d ) { rc = -EBUSY ; goto out;@@ -756,7 +759,8 @@ int evtchn_close(struct domain *d1, intif ( chn1->u.virq ==VIRQ_DOM_EXC )domain_deinit_states (d1); - v = d1->vcpu[virq_is_global (chn1->u.virq) ?0 : chn1->notify_vcpu_id]; + v = d1->vcpu[get_virq_type (chn1->u.virq) !=VIRQ_VCPU + ?0 : chn1->notify_vcpu_id];write_lock_irqsave (&v->virq_lock, flags);ASSERT (read_atomic (&v->virq_to_evtchn[chn1->u.virq]) == port1);@@ -900,7 +904,7 @@ bool evtchn_virq_enabled(const struct vcif ( !v )return false; -if (virq_is_global (virq) && v->vcpu_id ) +if (get_virq_type (virq) !=VIRQ_VCPU && v->vcpu_id ) v =domain_vcpu (v->domain,0 );return read_atomic (&v->virq_to_evtchn[virq]);@@ -913,7 +917,7 @@ void send_guest_vcpu_virq(struct vcpu *vstruct domain *d;struct evtchn *chn; -ASSERT (!virq_is_global (virq)); +ASSERT (get_virq_type (virq) ==VIRQ_VCPU );read_lock_irqsave (&v->virq_lock, flags);@@ -933,14 +937,14 @@ void send_guest_vcpu_virq(struct vcpu *vread_unlock_irqrestore (&v->virq_lock, flags); } -void send_guest_global_virq (struct domain *d,uint32_t virq) +void send_guest_domain_virq (struct domain *d,uint32_t virq) {unsigned long flags;int port;struct vcpu *v;struct evtchn *chn; -ASSERT (virq_is_global (virq)); +ASSERT (get_virq_type (virq) !=VIRQ_VCPU );if (unlikely (d ==NULL ) ||unlikely (d->vcpu ==NULL ) )return ;@@ -995,9 +999,9 @@ static DEFINE_SPINLOCK(global_virq_handlvoid send_global_virq (uint32_t virq) { -ASSERT (virq_is_global (virq)); +ASSERT (get_virq_type (virq) ==VIRQ_GLOBAL ); -send_guest_global_virq (get_global_virq_handler (virq), virq); +send_guest_domain_virq (get_global_virq_handler (virq), virq); }int set_global_virq_handler (struct domain *d,uint32_t virq)@@ -1008,7 +1012,7 @@ int set_global_virq_handler(struct domaiif (virq >=NR_VIRQS )return -EINVAL ; -if (!virq_is_global (virq)) +if (get_virq_type (virq) !=VIRQ_GLOBAL )return -EINVAL ;if (global_virq_handlers[virq] == d)@@ -1204,7 +1208,7 @@ int evtchn_bind_vcpu(evtchn_port_t port,switch ( chn->state ) {case ECS_VIRQ : -if (virq_is_global (chn->u.virq) ) +if (get_virq_type (chn->u.virq) !=VIRQ_VCPU ) chn->notify_vcpu_id = v->vcpu_id;else rc = -EINVAL ;xen/include/xen/event.h +7
-7@@ -24,17 +24,17 @@void send_guest_vcpu_virq (struct vcpu *v,uint32_t virq);/* -* send_global_virq: Notify the domain handling a global VIRQ. -* @virq: Virtual IRQ number (VIRQ_*) +* send_guest_domain_virq: +* @d: Domain to which VIRQ should be sent +* @virq: Virtual IRQ number (VIRQ_*), may not be per-vCPU */ -void send_global_virq (uint32_t virq); +void send_guest_domain_virq (struct domain *d,uint32_t virq);/* -* send_guest_global_virq: -* @d: Domain to which VIRQ should be sent -* @virq: Virtual IRQ number (VIRQ_*), must be global +* send_global_virq: Notify the domain handling a global VIRQ. +* @virq: Virtual IRQ number (VIRQ_*) */ -void send_guest_global_virq (struct domain *d,uint32_t virq); +void send_global_virq (uint32_t virq);/* * sent_global_virq_handler: Set a global VIRQ handler. xen/include/xen/sched.h +6
-0@@ -84,6 +84,12 @@ extern domid_t hardware_domid;#define XEN_CONSUMER_BITS 3#define NR_XEN_CONSUMERS ((1 << XEN_CONSUMER_BITS) - 1) +enum virq_type { +VIRQ_GLOBAL , +VIRQ_DOMAIN , +VIRQ_VCPU +}; +struct evtchn {rwlock_t lock;
PATCH 1/1 xen/public: Fix documentation of VIRQs
In reply to Jan BeulichIt has been discovered that VIRQ_ARGO is a 3rd type of VIRQ. Also, recent work has prevented global VIRQs from being stolen from the owning domain.
Rewrite the description of VIRQ classifications. Drop the (DOM0) comment from the global VIRQs; it's not been true for a long time.
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Juergen Gross <[email protected]>
--- xen/include/public/event_channel.h | 8 +++---- xen/include/public/xen.h | 37 +++++++++++++++++++----------- 2 files changed, 27 insertions(+), 18 deletions(-)
xen/include/public/event_channel.h +4 -4
@@ -114,10 +114,10 @@ typedef struct evtchn_bind_interdomain evtchn_bind_interdomain_t;* EVTCHNOP_bind_virq: Bind a local event channel to VIRQ <irq> on specified * vcpu. * NOTES: -* 1. Virtual IRQs are classified as per-vcpu or global. See the VIRQ list -* in xen.h for the classification of each VIRQ. -* 2. Global VIRQs must be allocated on VCPU0 but can subsequently be -* re-bound via EVTCHNOP_bind_vcpu. +* 1. Virtual IRQs are classified as per-vcpu, per-domain or global. See the +* VIRQ list in xen.h for the classification of each VIRQ. +* 2. Per-domain and global VIRQs must be allocated on vCPU0 but can +* subsequently be re-bound via EVTCHNOP_bind_vcpu. * 3. Per-vcpu VIRQs may be bound to at most one event channel per vcpu. * The allocated event channel is bound to the specified vcpu and the * binding cannot be changed.
xen/include/public/xen.h +23 -14
@@ -159,25 +159,34 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);* * Virtual interrupts that a guest OS may receive from Xen. * -* In the side comments, 'V.' denotes a per-VCPU VIRQ while 'G.' denotes a -* global VIRQ. The former can be bound once per VCPU and cannot be re-bound. -* The latter can be allocated only once per guest: they must initially be -* allocated to VCPU0 but can subsequently be re-bound. +* There are three types: +* +* 1. (V) Per-vcpu: +* These can be bound once per vCPU, each using a different evtchn port. +* An evtchn for one vCPU cannot be rebound to a different vCPU. +* +* 2. (D) Per-domain: +* These can be bound once per domain. They must be bound on vCPU 0 first, +* but can be rebound to other vCPUs afterwards. +* +* 3. (G) Global: +* Like per-domain, but can only be bound to a single domain at a time. +* The owning domain must unbind before a new domain can bind. */ /* ` enum virq { */ #define VIRQ_TIMER 0/* V. Timebase update, and/or requested timeout. */ #define VIRQ_DEBUG 1/* V. Request guest to dump debug info. */ -#define VIRQ_CONSOLE 2/* G. (DOM0) Bytes received on emergency console. */ -#define VIRQ_DOM_EXC 3/* G. (DOM0) Exceptional event for some domain. */ -#define VIRQ_TBUF 4/* G. (DOM0) Trace buffer has records available. */ -#define VIRQ_DEBUGGER 6/* G. (DOM0) A domain has paused for debugging. */ +#define VIRQ_CONSOLE 2/* G. Bytes received on emergency console. */ +#define VIRQ_DOM_EXC 3/* G. Exceptional event for some domain. */ +#define VIRQ_TBUF 4/* G. Trace buffer has records available. */ +#define VIRQ_DEBUGGER 6/* G. A domain has paused for debugging. */ #define VIRQ_XENOPROF 7/* V. XenOprofile interrupt: new sample available */ -#define VIRQ_CON_RING 8/* G. (DOM0) Bytes received on console */ -#define VIRQ_PCPU_STATE 9/* G. (DOM0) PCPU state changed */ -#define VIRQ_MEM_EVENT 10/* G. (DOM0) A memory event has occurred */ -#define VIRQ_ARGO 11/* G. Argo interdomain message notification */ -#define VIRQ_ENOMEM 12/* G. (DOM0) Low on heap memory */ -#define VIRQ_XENPMU 13/* V. PMC interrupt */ +#define VIRQ_CON_RING 8/* G. Bytes received on console */ +#define VIRQ_PCPU_STATE 9/* G. PCPU state changed */ +#define VIRQ_MEM_EVENT 10/* G. A memory event has occurred */ +#define VIRQ_ARGO 11/* D. Argo interdomain message notification */ +#define VIRQ_ENOMEM 12/* G. Low on heap memory */ +#define VIRQ_XENPMU 13/* V. PMC interrupt */ /* Architecture-specific VIRQ definitions. */ #define VIRQ_ARCH_0 16
Signature · 1 line
2.39.5
Re: [PATCH] xen/public: Fix documentation of VIRQs
Quoted 7 lines · Andrew Cooper
It has been discovered that
VIRQ_ARGOis a 3rd type of VIRQ. Also, recent work has prevented global VIRQs from being stolen from the owning domain.Rewrite the description of VIRQ classifications. Drop the (DOM0) comment from the global VIRQs; it's not been true for a long time.
Signed-off-by Andrew Cooper <[email protected]>