x86/hvm: Add per-vcpu evtchn upcalls
PATCH v2 1/1 x86/hvm: Add per-vcpu evtchn upcalls
HVM guests have always been confined to using the domain callback via (see HVM_PARAM_CALLBACK_IRQ) to receive event notifications which is an IOAPIC vector and is only used if the event channel is bound to vcpu 0.
This patch adds a new HVM op allowing a guest to specify a local APIC vector to use as an upcall notification for a specific vcpu. This therefore allows a guest which sets a vector for a vcpu other than 0 to then bind event channels to that vcpu.
--- xen/arch/x86/hvm/hvm.c | 39 +++++++++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/irq.c | 9 +++++++++ xen/include/asm-x86/hvm/vcpu.h | 1 + xen/include/public/hvm/hvm_op.h | 20 ++++++++++++++++++++ 4 files changed, 69 insertions(+)
xen/arch/x86/hvm/hvm.c +39 -0
@@ -5458,6 +5458,40 @@ static int hvmop_destroy_ioreq_server(return rc; } +static int hvmop_set_evtchn_upcall_vector ( +XEN_GUEST_HANDLE_PARAM (xen_hvm_set_evtchn_upcall_vector_t) uop) +{ +xen_hvm_set_evtchn_upcall_vector_t op; +struct domain *d; +struct vcpu *v; +int rc; + +if (copy_from_guest (&op, uop,1 ) ) +return -EFAULT ; + + d =rcu_lock_current_domain (); + + rc = -EINVAL ; +if ( !is_hvm_domain (d) ) + goto out; + +if ( op.vector <0x10 ) + goto out; + + rc = -ENOENT ; +if ( op.vcpu >= d->max_vcpus || (v = d->vcpu[op.vcpu]) ==NULL ) + goto out; + +printk (XENLOG_G_INFO "%pv: %s %u\n" , v, __func__, op.vector); + + v->arch.hvm_vcpu.evtchn_upcall_vector = op.vector; + rc =0 ; + + out: +rcu_unlock_domain (d); +return rc; +} +#define HVMOP_op_mask 0xfflong do_hvm_op (unsigned long op,XEN_GUEST_HANDLE_PARAM (void ) arg)
@@ -5499,6 +5533,11 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) guest_handle_cast(arg, xen_hvm_destroy_ioreq_server_t));break ; +case HVMOP_set_evtchn_upcall_vector: + rc =hvmop_set_evtchn_upcall_vector ( +guest_handle_cast (arg, xen_hvm_set_evtchn_upcall_vector_t)); +break ; +case HVMOP_set_param:case HVMOP_get_param: {
xen/arch/x86/hvm/irq.c +9 -0
@@ -152,6 +152,13 @@ void hvm_isa_irq_deassert(spin_unlock (&d->arch.hvm_domain.irq_lock); } +static void hvm_set_upcall_irq (struct vcpu *v) +{ +uint8_t vector = v->arch.hvm_vcpu.evtchn_upcall_vector; + +vlapic_set_irq (vcpu_vlapic (v), vector,0 ); +} +static void hvm_set_callback_irq_level (struct vcpu *v) {struct domain *d = v->domain;
@@ -220,6 +227,8 @@ void hvm_assert_evtchn_irq(struct vcpu *v)if (is_hvm_pv_evtchn_vcpu (v) )vcpu_kick (v); +else if ( v->arch.hvm_vcpu.evtchn_upcall_vector !=0 ) +hvm_set_upcall_irq (v);else if ( v->vcpu_id ==0 )hvm_set_callback_irq_level (v); }
xen/include/asm-x86/hvm/vcpu.h +1 -0
@@ -160,6 +160,7 @@ struct hvm_vcpu { } u;struct tasklet assert_evtchn_irq_tasklet; +u8 evtchn_upcall_vector;struct nestedvcpu nvcpu;
xen/include/public/hvm/hvm_op.h +20 -0
@@ -369,6 +369,26 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t);#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ +#if defined(__i386__) || defined(__x86_64__) + +/* +* HVMOP_set_evtchn_upcall_vector: Set a <vector> that should be used for event +* channel upcalls on the specified <vcpu>. If set, +* this vector will be used in preference to the +* domain callback via (see HVM_PARAM_CALLBACK_IRQ) +* and hence allows HVM guests to bind event +* event channels to a vcpu other than 0. +*/ +#define HVMOP_set_evtchn_upcall_vector 23 +struct xen_hvm_set_evtchn_upcall_vector { +uint32_t vcpu; +uint8_t vector; +}; +typedef struct xen_hvm_set_evtchn_upcall_vector xen_hvm_set_evtchn_upcall_vector_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_evtchn_upcall_vector_t); + +#endif /* defined(__i386__) || defined(__x86_64__) */ +#endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */ /*
Signature · 1 line
1.7.10.4
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.11.14 at 16:33, <[email protected]> wrote:
HVM guests have always been confined to using the domain callback via (see
HVM_PARAM_CALLBACK_IRQ) to receive event notifications which is an IOAPIC vector and is only used if the event channel is bound to vcpu 0.
Iirc the callback-via-vector method was specifically added to have a way to spread the IRQ handling load. And even if this didn't work out as intended, wouldn't simply setting a flag to avoid the restriction in
Quoted 4 lines
This patch adds a new HVM op allowing a guest to specify a local APIC vector to use as an upcall notification for a specific vcpu. This therefore allows a guest which sets a vector for a vcpu other than 0 to then bind event channels to that vcpu.
So is there really a need for a per-vCPU vector value (rather than a single domain wide one)?
xen/arch/x86/hvm/irq.c void hvm_assert_evtchn_irq(struct vcpu *v) · line 231
Quoted 6 lines
xen/arch/x86/hvm/irq.c +2
-0@@ -220,6 +227,8 @@ void hvm_assert_evtchn_irq(struct vcpu *v)if (is_hvm_pv_evtchn_vcpu (v) )vcpu_kick (v); +else if ( v->arch.hvm_vcpu.evtchn_upcall_vector !=0 ) +hvm_set_upcall_irq (v);
The context code above your insertion is clearly not enforcing vCPU 0 only; the code below this change is.
Jan
Quoted 18 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 07 November 2014 11:48
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: Re: [PATCH v2] x86/hvm: Add per-vcpu evtchn upcallsQuoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.11.14 at 16:33, <[email protected]> wrote:
HVM guests have always been confined to using the domain callback via (see
HVM_PARAM_CALLBACK_IRQ) to receive event notifications which is an IOAPIC vector and is only used if the event channel is bound to vcpu 0.Iirc the callback-via-vector method was specifically added to have a way to spread the IRQ handling load. And even if this didn't work out as intended, wouldn't simply setting a flag to avoid the restriction in
Quoted 8 lines
Quoted 4 lines
This patch adds a new HVM op allowing a guest to specify a local APIC vector to use as an upcall notification for a specific vcpu. This therefore allows a guest which sets a vector for a vcpu other than 0 to then bind event channels to that vcpu.
So is there really a need for a per-vCPU vector value (rather than a single domain wide one)?
I can't stipulate that Windows gives me the same vector on every CPU, so yes.
Quoted 10 lines
xen/arch/x86/hvm/irq.c void hvm_assert_evtchn_irq(struct vcpu *v) · line 231
Quoted 6 lines
xen/arch/x86/hvm/irq.c +2
-0@@ -220,6 +227,8 @@ void hvm_assert_evtchn_irq(struct vcpu *v)if (is_hvm_pv_evtchn_vcpu (v) )vcpu_kick (v); +else if ( v->arch.hvm_vcpu.evtchn_upcall_vector !=0 ) +hvm_set_upcall_irq (v);The context code above your insertion is clearly not enforcing vCPU 0 only; the code below this change is.
Yes, the callback via is only allowed to be issued for events bound to vcpu 0, although nothing ensures that it only gets delivered to vcpu0. I don't know what the historical reason behind that is. The whole point of the new vectors though is that there is one per vcpu, not just one on vcpu 0, so why would I want to enforce vcpu 0 only? It would defeat the entire point of the patch.
Paul
Quoted 1 line
Jan
Quoted 9 lines
Quoted 6 lines
Quoted 1 line · On 07.11.14 at 13:33, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 06.11.14 at 16:33, <[email protected]> wrote:
So is there really a need for a per-vCPU vector value (rather than a single domain wide one)?
I can't stipulate that Windows gives me the same vector on every CPU, so yes.
So Windows has no concept of per-CPU vectors/IRQs? I'm somewhat surprised, since for their Hyper-V drivers in Linux they were specifically looking for how to do this under Linux, making me assume that they try to keep their driver behavior as similar as possible to their native equivalents.
Quoted 11 lines
Quoted 10 lines
xen/arch/x86/hvm/irq.c void hvm_assert_evtchn_irq(struct vcpu *v) · line 231
Quoted 6 lines
xen/arch/x86/hvm/irq.c +2
-0@@ -220,6 +227,8 @@ void hvm_assert_evtchn_irq(struct vcpu *v)if (is_hvm_pv_evtchn_vcpu (v) )vcpu_kick (v); +else if ( v->arch.hvm_vcpu.evtchn_upcall_vector !=0 ) +hvm_set_upcall_irq (v);The context code above your insertion is clearly not enforcing vCPU 0 only; the code below this change is.
Quoted 6 lines
Yes, the callback via is only allowed to be issued for events bound to vcpu 0, although nothing ensures that it only gets delivered to vcpu0. I don't know what the historical reason behind that is. The whole point of the new vectors though is that there is one per vcpu, not just one on vcpu 0, so why would I want to enforce vcpu 0 only? It would defeat the entire point of the patch.
I think you misunderstood what I tried to say; I wasn't suggesting that you should limit yourself to vCPU 0. Instead I was asking why the non-vCPU-0-bound mechanism visible in the patch context doesn't suit your needs (in fact I think the answer to this should be part of the commit message).
Jan
Quoted 10 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 07 November 2014 13:02
To: Paul Durrant
Cc: [email protected]; Keir (Xen.org)
Subject: RE: [PATCH v2] x86/hvm: Add per-vcpu evtchn upcallsQuoted 3 lines
Quoted 3 lines
Quoted 1 line · On 07.11.14 at 13:33, <[email protected]> wrote:
From: Jan Beulich [mailto:[email protected]]
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 06.11.14 at 16:33, <[email protected]> wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
So is there really a need for a per-vCPU vector value (rather than a single domain wide one)?
I can't stipulate that Windows gives me the same vector on every CPU, so yes.
So Windows has no concept of per-CPU vectors/IRQs?
All I can do is ask for an interrupt with a specific affinity to 1 or more CPUs. If I ask for one interrupt bound to all CPUs then I will get the same vector on as many CPUs an Windows can allocate it on, but that's not guaranteed to be all the CPUs in the affinity mask I asked for. Also, there will be a single lock protecting that interrupt so it's really not useful. Hence I need to ask for as many interrupts as there are CPUs, each with an affinity mask specifying the individual CPU. That way I avoid the big lock, but I cannot guarantee that I will get the same vector for each interrupt I allocate. Thus I need to be able to set each vcpu to upcall on a potentially differing vector.
Quoted 22 lines
I'm somewhat
surprised, since for their Hyper-V drivers in Linux they were specifically looking for how to do this under Linux, making me assume that they try to keep their driver behavior as similar as possible to their native equivalents.Quoted 11 lines
Quoted 10 lines
xen/arch/x86/hvm/irq.c void hvm_assert_evtchn_irq(struct vcpu *v) · line 231
Quoted 6 lines
xen/arch/x86/hvm/irq.c +2
-0@@ -220,6 +227,8 @@ void hvm_assert_evtchn_irq(struct vcpu *v)if (is_hvm_pv_evtchn_vcpu (v) )vcpu_kick (v); +else if ( v->arch.hvm_vcpu.evtchn_upcall_vector !=0 ) +hvm_set_upcall_irq (v);The context code above your insertion is clearly not enforcing vCPU 0 only; the code below this change is.
Quoted 5 lines
Yes, the callback via is only allowed to be issued for events bound to vcpu 0, although nothing ensures that it only gets delivered to vcpu0. I don't know what the historical reason behind that is. The whole point of the new vectors though is that there is one per vcpu, not just one on vcpu 0, so why would I want to enforce vcpu 0 only? It would defeat the entire point of
Quoted 9 lines
the
Quoted 1 line
patch.
I think you misunderstood what I tried to say; I wasn't suggesting that you should limit yourself to vCPU 0. Instead I was asking why the non-vCPU-0-bound mechanism visible in the patch context doesn't suit your needs (in fact I think the answer to this should be part of the commit message).
Oh, I see. Yes, I can add a comment as to why the 'vector' callback via is not suitable.
Paul
Quoted 1 line
Jan