Xen: enhanced PV on HVM
PATCH 1/1 Xen: enhanced PV on HVM
Hi all,
this patch is for Xen and it is derived from an earlier patch by Shen. The changes introduced by this patch include:
- add support to some vcpuops and physdevops for HVM domains;
- introduce a new interrupt callback method for HVM domains;
- allow HVM guests to map emulated interrupts to pirqs;
in particular the last point is new and it isn't present in the corresponding patch from Shen.
This patch doesn't introduce an "enable_pv" hypercall and resets the tsc offset when the guest binds the VIRQ_TIMER.
---
xen/arch/x86/domain.c +10 -0
@@ -495,6 +495,16 @@for ( i =1 ;platform_legacy_irq (i); ++i )if ( !IO_APIC_IRQ (i) ) d->arch.irq_pirq[i] = d->arch.pirq_irq[i] = i; + + d->arch.pirq_emuirq =xmalloc_array (int, d->nr_pirqs); + d->arch.emuirq_pirq =xmalloc_array (int, d->nr_pirqs); +if ( !d->arch.pirq_emuirq || !d->arch.emuirq_pirq ) + goto fail; +memset (d->arch.pirq_emuirq,-1 , + d->nr_pirqs *sizeof (*d->arch.pirq_emuirq)); +memset (d->arch.emuirq_pirq,-1 , + d->nr_pirqs *sizeof (*d->arch.emuirq_pirq)); +if ( (rc =iommu_domain_init (d)) !=0 ) goto fail;
xen/arch/x86/hvm/hvm.c +55 -0
104 lines not on this page · raw message
xen/arch/x86/hvm/irq.c +43 -15
132 lines not on this page · raw message
xen/arch/x86/hvm/vmx/intr.c +2 -1
@@ -164,7 +164,8 @@ {HVMTRACE_2D (INJ_VIRQ , intack.vector,/*fake=*/ 0 );vmx_inject_extint (intack.vector); -pt_intr_post (v, intack); +if (intack.source != hvm_intsrc_vector) +pt_intr_post (v, intack); }/* Is there another IRQ to queue up behind this one? */
xen/arch/x86/irq.c +68 -0
71 lines not on this page · raw message
xen/arch/x86/physdev.c +40 -1
71 lines not on this page · raw message
xen/common/event_channel.c +26 -9
@@ -305,7 +305,7 @@if ( (pirq <0 ) || (pirq >= d->nr_pirqs) )return -EINVAL ; -if ( !irq_access_permitted (d, pirq) ) +if ( !is_hvm_domain (d) && !irq_access_permitted (d, pirq) )return -EPERM ;spin_lock (&d->event_lock);
@@ -319,12 +319,14 @@ chn =evtchn_from_port (d, port); d->pirq_to_evtchn[pirq] = port; - rc =pirq_guest_bind (d->vcpu[0 ], pirq, - !!(bind->flags &BIND_PIRQ__WILL_SHARE )); -if ( rc !=0 ) - { - d->pirq_to_evtchn[pirq] =0 ; - goto out; +if ( !is_hvm_domain (d) ) { + rc =pirq_guest_bind (d->vcpu[0 ], pirq, + !!(bind->flags &BIND_PIRQ__WILL_SHARE )); +if ( rc !=0 ) + { + d->pirq_to_evtchn[pirq] =0 ; + goto out; + } } chn->state =ECS_PIRQ ;
@@ -376,7 +378,8 @@break ;case ECS_PIRQ : -pirq_guest_unbind (d1, chn1->u.pirq); +if ( !is_hvm_domain (d1) ) +pirq_guest_unbind (d1, chn1->u.pirq); d1->pirq_to_evtchn[chn1->u.pirq] =0 ;break ;
@@ -636,8 +639,17 @@/* * It should not be possible to race with __evtchn_close(): * The caller of this function must synchronise with pirq_guest_unbind(). +* +* In the HVM case port is 0 when the guest disable the +* emulated interrupt\evtchn. */ -ASSERT (port !=0 ); +if (!port) + { +if (is_hvm_domain (d) &&domain_pirq_to_emuirq (d, pirq) >=0 ) +return 0 ; +else +return -EINVAL ; + } chn =evtchn_from_port (d, port);return evtchn_set_pending (d->vcpu[chn->notify_vcpu_id], port);
@@ -824,6 +836,7 @@long do_event_channel_op (int cmd,XEN_GUEST_HANDLE (void ) arg) {long rc; +struct domain *d = current->domain;switch ( cmd ) {
@@ -852,6 +865,10 @@if (copy_from_guest (&bind_virq, arg,1 ) !=0 )return -EFAULT ; rc =evtchn_bind_virq (&bind_virq); +if (is_hvm_domain (d) && bind_virq.virq ==VIRQ_TIMER ) { +update_domain_wallclock_time (d); + hvm_funcs.set_tsc_offset (d->vcpu[0 ],0 ); + }if ( (rc ==0 ) && (copy_to_guest (arg, &bind_virq,1 ) !=0 ) ) rc = -EFAULT ;/* Cleaning up here would be a mess! */ break ;
xen/include/asm-x86/domain.h +3 -0
@@ -278,6 +278,9 @@/* NB. protected by d->event_lock and by irq_desc[irq].lock */ int *irq_pirq;int *pirq_irq; +/* pirq to emulated irq and vice versa */ +int *emuirq_pirq; +int *pirq_emuirq;/* Shared page for notifying that explicit PIRQ EOI is required. */ unsigned long *pirq_eoi_map;
xen/include/asm-x86/hvm/hvm.h +3 -1
@@ -33,7 +33,8 @@ hvm_intsrc_pic, hvm_intsrc_lapic, hvm_intsrc_nmi, - hvm_intsrc_mce + hvm_intsrc_mce, + hvm_intsrc_vector };struct hvm_intack {uint8_t source;/* enum hvm_intsrc */
@@ -44,6 +45,7 @@#define hvm_intack_lapic (vec) ( (struct hvm_intack) { hvm_intsrc_lapic, vec } )#define hvm_intack_nmi ( (struct hvm_intack) { hvm_intsrc_nmi, 2 } )#define hvm_intack_mce ( (struct hvm_intack) { hvm_intsrc_mce, 18 } ) +#define hvm_intack_vector (vec)( (struct hvm_intack) { hvm_intsrc_vector, vec } )enum hvm_intblk { hvm_intblk_none,/* not blocked (deliverable) */ hvm_intblk_shadow,/* MOV-SS or STI shadow */
xen/include/asm-x86/hvm/irq.h +3 -1
@@ -54,12 +54,14 @@enum { HVMIRQ_callback_none, HVMIRQ_callback_gsi, - HVMIRQ_callback_pci_intx + HVMIRQ_callback_pci_intx, + HVMIRQ_callback_vector } callback_via_type; };union {uint32_t gsi;struct {uint8_t dev, intx; } pci; +uint32_t vector; } callback_via;/* Number of INTx wires asserting each PCI-ISA link. */
xen/include/asm-x86/irq.h +5 -0
@@ -112,6 +112,9 @@int map_domain_pirq (struct domain *d,int pirq,int irq,int type,void *data);int unmap_domain_pirq (struct domain *d,int pirq); +int map_domain_emuirq_pirq (struct domain *d,int pirq,int irq,int type, +void *data); +int unmap_domain_pirq_emuirq (struct domain *d,int pirq);int get_free_pirq (struct domain *d,int type,int index);void free_domain_pirqs (struct domain *d);
@@ -147,5 +150,7 @@#define domain_pirq_to_irq (d, pirq) ((d)->arch.pirq_irq[pirq])#define domain_irq_to_pirq (d, irq) ((d)->arch.irq_pirq[irq]) +#define domain_pirq_to_emuirq (d, pirq) ((d)->arch.pirq_emuirq[pirq]) +#define domain_emuirq_to_pirq (d, emuirq) ((d)->arch.emuirq_pirq[emuirq])#endif /* _ASM_HW_IRQ_H */
xen/include/xen/sched.h +3 -0
@@ -592,6 +592,9 @@#define VM_ASSIST (_d,_t) (test_bit((_t), &(_d)->vm_assist))#define is_hvm_domain (d) ((d)->is_hvm) +#define is_hvm_pv_evtchn_domain (d) (is_hvm_domain(d) && \ + d->arch.hvm_domain.irq.callback_via_type == HVMIRQ_callback_vector) +#define is_hvm_pv_evtchn_vcpu (v) (is_hvm_pv_evtchn_domain(v->domain))#define is_hvm_vcpu (v) (is_hvm_domain(v->domain))#define need_iommu (d) ((d)->need_iommu)
Quoted 6 lines · Stefano Stabellini
Hi all,
this patch is for Xen and it is derived from an earlier patch by Shen. The changes introduced by this patch include:- add support to some vcpuops and physdevops for HVM domains;
Quoted 9 lines
- introduce a new interrupt callback method for HVM domains;
- allow HVM guests to map emulated interrupts to pirqs;
in particular the last point is new and it isn't present in the corresponding patch from Shen.
This patch doesn't introduce an "enable_pv" hypercall and resets the tsc offset when the guest binds theVIRQ_TIMER.
What branch/version is this based on?
J
Quoted 11 lines · Jeremy Fitzhardinge
Quoted 10 lines · Stefano Stabellini
Hi all,
this patch is for Xen and it is derived from an earlier patch by Shen. The changes introduced by this patch include:- add support to some vcpuops and physdevops for HVM domains;
- introduce a new interrupt callback method for HVM domains;
- allow HVM guests to map emulated interrupts to pirqs;
Quoted 8 lines
Quoted 5 lines
in particular the last point is new and it isn't present in the corresponding patch from Shen.
This patch doesn't introduce an "enable_pv" hypercall and resets the tsc offset when the guest binds theVIRQ_TIMER.What branch/version is this based on?
xen/dom0/apic-xiantao
BTW I have passthrought working now, I'll send a new version of the series soon.