x86/hvm: Add per-vcpu evtchn upcalls
PATCH v5 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. This is usually an IOAPIC vector and is only used if the event channel is bound to vcpu 0.
PVHVM Linux uses a pre-defined interrupt vector for the event channel upcall, set using HVM_PARAM_CALLBACK_IRQ by ORing in a special bit (bit 57) into the value (see params.h). However, it does not assert the interrupt via the emulated local APIC.
This mechanism is not suitable in the general case since Windows (and potentially other OSes) because they:
- cannot guarantee the same vector for all VCPUs
- do require the upcall to be asserted via the local APIC
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 therefore coping with the case of differing vector numbers.
---
v2:
- Addressed comments from Andrew Cooper
- Check vector >=16
- Put hypercall in x86-specific section
v3:
- Addressed comments from Jan Beulich
- More verbose check-in comment
v4:
- Amended check-in comment as suggested by David Vrabel
v5:
- Addressed comments from Jan Beulich
xen/arch/x86/hvm/hvm.c | 30 ++++++++++++++++++++++++++++++ xen/arch/x86/hvm/irq.c | 8 +++++++- xen/include/asm-x86/hvm/vcpu.h | 1 + xen/include/public/hvm/hvm_op.h | 19 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hvm.c +30 -0
@@ -5514,6 +5514,31 @@ 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 = current->domain; +struct vcpu *v; + +if (copy_from_guest (&op, uop,1 ) ) +return -EFAULT ; + +if ( !is_hvm_domain (d) ) +return -EINVAL ; + +if ( op.vector <0x10 ) +return -EINVAL ; + +if ( op.vcpu >= d->max_vcpus || (v = d->vcpu[op.vcpu]) ==NULL ) +return -ENOENT ; + +printk (XENLOG_G_INFO "%pv: upcall vector %u\n" , v, op.vector); + + v->arch.hvm_vcpu.evtchn_upcall_vector = op.vector; +return 0 ; +} +/* * Note that this value is effectively part of the ABI, even if we don't need * to make it a formal part of it: A guest suspended for migration in the
@@ -5573,6 +5598,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 +7 -1
@@ -218,7 +218,13 @@ void hvm_assert_evtchn_irq(struct vcpu *v)return ; } -if (is_hvm_pv_evtchn_vcpu (v) ) +if ( v->arch.hvm_vcpu.evtchn_upcall_vector !=0 ) + { +uint8_t vector = v->arch.hvm_vcpu.evtchn_upcall_vector; + +vlapic_set_irq (vcpu_vlapic (v), vector,0 ); + } +else if (is_hvm_pv_evtchn_vcpu (v) )vcpu_kick (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 +19 -0
@@ -370,6 +370,25 @@ 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 global callback via (see +* HVM_PARAM_CALLBACK_IRQ). +*/ +#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 139 lines · Paul Durrant
HVM guests have always been confined to using the domain callback via (see
HVM_PARAM_CALLBACK_IRQ) to receive event notifications. This is usually an IOAPIC vector and is only used if the event channel is bound to vcpu 0.PVHVM Linux uses a pre-defined interrupt vector for the event channel upcall, set using
HVM_PARAM_CALLBACK_IRQby ORing in a special bit (bit 57) into the value (seeparams.h). However, it does not assert the interrupt via the emulated local APIC.This mechanism is not suitable in the general case since Windows (and potentially other OSes) because they:
- cannot guarantee the same vector for all VCPUs
- do require the upcall to be asserted via the local APICThis 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 therefore coping with the case of differing vector numbers.
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc David Vrabel <[email protected]>---
v2:
- Addressed comments from Andrew Cooper
- Check vector >=16
- Put hypercall in x86-specific sectionv3:
- Addressed comments from Jan Beulich
- More verbose check-in commentv4:
- Amended check-in comment as suggested by David Vrabelv5:
- Addressed comments from Jan Beulichxen/arch/x86/hvm/hvm.c | 30 ++++++++++++++++++++++++++++++ xen/arch/x86/hvm/irq.c | 8 +++++++- xen/include/asm-x86/hvm/vcpu.h | 1 + xen/include/public/hvm/hvm_op.h | 19 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-)xen/arch/x86/hvm/hvm.c +30
-0@@ -5514,6 +5514,31 @@ 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 = current->domain; +struct vcpu *v; + +if (copy_from_guest (&op, uop,1 ) ) +return -EFAULT ; + +if ( !is_hvm_domain (d) ) +return -EINVAL ; + +if ( op.vector <0x10 ) +return -EINVAL ; + +if ( op.vcpu >= d->max_vcpus || (v = d->vcpu[op.vcpu]) ==NULL ) +return -ENOENT ; + +printk (XENLOG_G_INFO "%pv: upcall vector %u\n" , v, op.vector); + + v->arch.hvm_vcpu.evtchn_upcall_vector = op.vector; +return 0 ; +} +/* * Note that this value is effectively part of the ABI, even if we don't need * to make it a formal part of it: A guest suspended for migration in the @@ -5573,6 +5598,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 +7
-1@@ -218,7 +218,13 @@ void hvm_assert_evtchn_irq(struct vcpu *v)return ; } -if (is_hvm_pv_evtchn_vcpu (v) ) +if ( v->arch.hvm_vcpu.evtchn_upcall_vector !=0 ) + { +uint8_t vector = v->arch.hvm_vcpu.evtchn_upcall_vector; + +vlapic_set_irq (vcpu_vlapic (v), vector,0 ); + } +else if (is_hvm_pv_evtchn_vcpu (v) )vcpu_kick (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 +6
-0@@ -370,6 +370,25 @@ 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
xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t); · line 388
Quoted 10 lines
xen/include/public/hvm/hvm_op.h +10
-0+* domain global callback via (see +* HVM_PARAM_CALLBACK_IRQ). +*/ +#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);
I think you should remove "set" from the structure name. Who knows - someone might want to implement a get hypercall in the future.
Other than that, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 6 lines
xen/include/public/hvm/hvm_op.h +3
-0+ +#endif /* defined(__i386__) || defined(__x86_64__) */ +#endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */ /*
Quoted 164 lines
-----Original Message-----
From: Andrew Cooper
Sent: 16 January 2015 10:39
To: Paul Durrant; [email protected]
Cc: Keir (Xen.org); David Vrabel; Jan Beulich
Subject: Re: [Xen-devel] [PATCH v5] x86/hvm: Add per-vcpu evtchn upcallsQuoted 34 lines · Paul Durrant
HVM guests have always been confined to using the domain callback via (see
HVM_PARAM_CALLBACK_IRQ) to receive event notifications. This is usually an IOAPIC vector and is only used if the event channel is bound to vcpu 0.PVHVM Linux uses a pre-defined interrupt vector for the event channel upcall, set using
HVM_PARAM_CALLBACK_IRQby ORing in a special bit (bit 57) into the value (seeparams.h). However, it does not assert the interrupt via the emulated local APIC.This mechanism is not suitable in the general case since Windows (and potentially other OSes) because they:
- cannot guarantee the same vector for all VCPUs
- do require the upcall to be asserted via the local APICThis 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 therefore coping with the case of differing vector numbers.
Signed-off-by Paul Durrant <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc David Vrabel <[email protected]>---
v2:
- Addressed comments from Andrew Cooper
- Check vector >=16
- Put hypercall in x86-specific sectionv3:
- Addressed comments from Jan Beulich
- More verbose check-in commentQuoted 7 lines
v4:
- Amended check-in comment as suggested by David Vrabelv5:
- Addressed comments from Jan Beulichxen/arch/x86/hvm/hvm.c | 30++++++++++++++++++++++++++++++
Quoted 10 lines
xen/arch/x86/hvm/irq.c | 8 +++++++- xen/include/asm-x86/hvm/vcpu.h | 1 + xen/include/public/hvm/hvm_op.h | 19 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-)xen/arch/x86/hvm/hvm.c +0
-0xen/arch/x86/hvm/hvm.c static int hvmop_destroy_ioreq_server( · line 5518
Quoted 5 lines
xen/arch/x86/hvm/hvm.c +2
-0@@ -5514,6 +5514,31 @@ 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/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op,
Quoted 27 lines
xen/arch/x86/hvm/hvm.c +23
-0+{ +xen_hvm_set_evtchn_upcall_vector_t op; +struct domain *d = current->domain; +struct vcpu *v; + +if (copy_from_guest (&op, uop,1 ) ) +return -EFAULT ; + +if ( !is_hvm_domain (d) ) +return -EINVAL ; + +if ( op.vector <0x10 ) +return -EINVAL ; + +if ( op.vcpu >= d->max_vcpus || (v = d->vcpu[op.vcpu]) ==NULL ) +return -ENOENT ; + +printk (XENLOG_G_INFO "%pv: upcall vector %u\n" , v, op.vector); + + v->arch.hvm_vcpu.evtchn_upcall_vector = op.vector; +return 0 ; +} +/* * Note that this value is effectively part of the ABI, even if we don't need * to make it a formal part of it: A guest suspended for migration in the @@ -5573,6 +5598,11 @@ long do_hvm_op(unsigned long op,
XEN_GUEST_HANDLE_PARAM(void)arg)xen/include/asm-
Quoted 31 lines
xen/arch/x86/hvm/hvm.c +5
-0guest_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 +7
-1@@ -218,7 +218,13 @@ void hvm_assert_evtchn_irq(struct vcpu *v)return ; } -if (is_hvm_pv_evtchn_vcpu (v) ) +if ( v->arch.hvm_vcpu.evtchn_upcall_vector !=0 ) + { +uint8_t vector = v->arch.hvm_vcpu.evtchn_upcall_vector; + +vlapic_set_irq (vcpu_vlapic (v), vector,0 ); + } +else if (is_hvm_pv_evtchn_vcpu (v) )vcpu_kick (v);else if ( v->vcpu_id ==0 )hvm_set_callback_irq_level (v);xen/include/asm- renamed from xen/include/asm-x86/hvm/vcpu.h +0
-0
x86/hvm/vcpu.hReview
Quoted 12 lines
index 01e0665..edd4523 100644
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;(quoted diff) +0
-0
b/xen/include/public/hvm/hvm_op.hxen/include/public/hvm/hvm_op.h
Quoted 4 lines
index a4e5345..a857561 100644
xen/include/public/hvm/hvm_op.h +0
-0@@ -370,6 +370,25 @@
DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t);xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t);
Quoted 7 lines
xen/include/public/hvm/hvm_op.h +4
-0#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
xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t);
Quoted 11 lines
xen/include/public/hvm/hvm_op.h +11
-0+* channel upcalls on the specified <vcpu>. If set, +* this vector will be used in preference to the +* domain global callback via (see +* HVM_PARAM_CALLBACK_IRQ). +*/ +#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;
Quoted 5 lines
xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t); · line 388
Quoted 1 line
xen/include/public/hvm/hvm_op.h +1
-0+DEFINE_XEN_GUEST_HANDLE (xen_hvm_set_evtchn_upcall_vector_t);I think you should remove "set" from the structure name. Who knows - someone might want to implement a get hypercall in the future.
I didn't want to make any assumption about future use of the structure and followed the convention of tying the name to the hypercall. I'm happy to make the name more generic if anyone else also thinks that's a good idea.
Quoted 3 lines
Other than that, Reviewed-by: Andrew Cooper
<[email protected]>
Thanks,
Paul
Quoted 6 lines
Quoted 6 lines
xen/include/public/hvm/hvm_op.h +3
-0+ +#endif /* defined(__i386__) || defined(__x86_64__) */ +#endif /* __XEN_PUBLIC_HVM_HVM_OP_H__ */ /*
Quoted 12 lines
Quoted 12 lines
Quoted 1 line · On 16.01.15 at 12:07, <[email protected]> wrote:
From: Andrew Cooper
xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t);
Quoted 6 lines · Paul Durrant
xen/include/public/hvm/hvm_op.h +6
-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;Quoted 1 line
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_evtchn_upcall_vector_t);
Quoted 7 lines
Quoted 3 lines
I think you should remove "set" from the structure name. Who knows - someone might want to implement a get hypercall in the future.
I didn't want to make any assumption about future use of the structure and followed the convention of tying the name to the hypercall. I'm happy to make the name more generic if anyone else also thinks that's a good idea.
I think this is a good idea, and I can take care of the name change while committing (unless other reasons for another round should show up).
Jan
Quoted 24 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 16 January 2015 11:59
To: Andrew Cooper; Paul Durrant; [email protected]
Cc: David Vrabel; Keir (Xen.org)
Subject: RE: [Xen-devel] [PATCH v5] x86/hvm: Add per-vcpu evtchn upcallsQuoted 11 lines
Quoted 11 lines
Quoted 1 line · On 16.01.15 at 12:07, <[email protected]> wrote:
From: Andrew Cooper
xen/include/public/hvm/hvm_op.h DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_ioreq_server_state_t);
Quoted 6 lines · Paul Durrant
xen/include/public/hvm/hvm_op.h +6
-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;Quoted 1 line
+DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_evtchn_upcall_vector_t);
Quoted 5 lines
Quoted 4 lines
I think you should remove "set" from the structure name. Who knows - someone might want to implement a get hypercall in the future.
Quoted 9 lines
Quoted 2 lines
I didn't want to make any assumption about future use of the structure and followed the convention of tying the name to the hypercall. I'm happy to
make
Quoted 1 line
the name more generic if anyone else also thinks that's a good idea.
I think this is a good idea, and I can take care of the name change while committing (unless other reasons for another round should show up).
Thanks :-)
Paul
Quoted 1 line
Jan
xen/include/asm-x86/hvm/vcpu.h struct hvm_vcpu { · line 166
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 16.01.15 at 11:09, <[email protected]> wrote:
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;
Since where you put this is arbitrary, you should really have used a slot that's currently padding space - there are a number of places you could have picked. I'll see to change the placement when committing.
Jan
Quoted 16 lines
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 16 January 2015 16:28
To: Paul Durrant
Cc: David Vrabel; [email protected]; Keir (Xen.org)
Subject: Re: [PATCH v5] x86/hvm: Add per-vcpu evtchn upcallsQuoted 9 lines
Quoted 1 line
Quoted 1 line · On 16.01.15 at 11:09, <[email protected]> wrote:
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;
Quoted 7 lines
xen/include/asm-x86/hvm/vcpu.h struct hvm_vcpu { · line 166
Quoted 2 lines
xen/include/asm-x86/hvm/vcpu.h +0
-0struct nestedvcpu nvcpu;Since where you put this is arbitrary, you should really have used a slot that's currently padding space - there are a number of places you could have picked. I'll see to change the placement when committing.
Ok. Thanks,
Paul
Quoted 2 lines
Jan