: PVH xen: some misc changes like mtrr, intr, msi.
RFC PATCH 11/16 : PVH xen: some misc changes like mtrr, intr, msi.
I could use some feedback here, not sure if I covered everything here.
xen/arch/x86/hvm/irq.c +3 -0
@@ -405,6 +405,9 @@ struct hvm_intack hvm_vcpu_has_pending_i && vcpu_info(v, evtchn_upcall_pending) )return hvm_intack_vector (plat->irq.callback_via.vector); +if (is_pvh_vcpu (v) ) +return hvm_intack_none; +if (vlapic_accept_pic_intr (v) && plat->vpic[0 ].int_output )return hvm_intack_pic (0 );
xen/arch/x86/hvm/mtrr.c +16 -1
@@ -553,6 +553,9 @@ int32_t hvm_get_mem_pinned_cacheattr( *type =0 ; +if (is_pvh_domain (d) ) +return 0 ; +if ( !is_hvm_domain (d) )return 0 ;
@@ -578,6 +581,9 @@ int32_t hvm_set_mem_pinned_cacheattr( {struct hvm_mem_pinned_cacheattr_range *range; +/* PVH note: The guest writes to MSR_IA32_CR_PAT natively */ +NO_PVH_ASSERT_DOMAIN (d); + if ( !((type == PAT_TYPE_UNCACHABLE) || (type == PAT_TYPE_WRCOMB) || (type == PAT_TYPE_WRTHROUGH) ||
@@ -606,6 +612,7 @@ static int hvm_save_mtrr_msr(struct domastruct vcpu *v;struct hvm_hw_mtrr hw_mtrr;struct mtrr_state *mtrr_state; +/* save mtrr&pat */ for_each_vcpu (d, v) {
@@ -693,7 +700,15 @@ uint8_t epte_get_entry_emt(struct domain ((d->vcpu == NULL) || ((v = d->vcpu[0]) == NULL)) )return MTRR_TYPE_WRBACK ; -if ( !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT ] ) +/* PVH:fixme: this needs to be studied more */ +if (is_pvh_domain (d) ) { +if (direct_mmio) +return MTRR_TYPE_UNCACHABLE ; +return MTRR_TYPE_WRBACK ; + } + +if ( !is_pvh_domain (d) && + !v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT ] )return MTRR_TYPE_WRBACK ;if ( (v == current) && v->domain->arch.hvm_domain.is_in_uc_mode )
xen/arch/x86/hvm/vmx/intr.c +4 -3
@@ -216,15 +216,16 @@ void vmx_intr_assist(void)return ; } -/* Crank the handle on interrupt state. */ - pt_vector =pt_update_irq (v); +if ( !is_pvh_vcpu (v) ) +/* Crank the handle on interrupt state. */ + pt_vector =pt_update_irq (v); do { intack = hvm_vcpu_has_pending_irq(v); if ( likely(intack.source == hvm_intsrc_none) ) goto out; - if ( unlikely(nvmx_intr_intercept(v, intack)) ) + if ( !is_pvh_vcpu(v) && unlikely(nvmx_intr_intercept(v, intack)) ) goto out; intblk = hvm_interrupt_blocked(v, intack);
xen/arch/x86/msi.c +4 -2
@@ -766,10 +766,12 @@ static int msix_capability_init(struct pWARN_ON (rangeset_overlaps_range (mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last)); -if (rangeset_add_range (mmio_ro_ranges, dev->msix_table.first, +/* PVH: for now we don't make the mmio range readonly. See xen-devel for thread: +* "[PVH]: Help: msi.c". When linux msi.c is fixed, pvh check can be removed */ +if ( !is_pvh_domain (dev->domain) &&rangeset_add_range (mmio_ro_ranges, dev->msix_table.first, dev->msix_table.last) )WARN (); -if (rangeset_add_range (mmio_ro_ranges, dev->msix_pba.first, +if ( !is_pvh_domain (dev->domain) &&rangeset_add_range (mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last) )WARN ();
xen/arch/x86/time.c +1 -1
@@ -1923,7 +1923,7 @@ void tsc_set_info(struct domain *d,break ; } d->arch.incarnation = incarnation +1 ; -if (is_hvm_domain (d) ) +if (is_hvm_or_pvh_domain (d) )hvm_set_rdtsc_exiting (d, d->arch.vtsc); }
xen/arch/x86/x86_emulate/x86_emulate.c +4 -0
@@ -968,6 +968,10 @@ static int ioport_access_check(struct segment_register tr;int rc =X86EMUL_OKAY ; +/* PVH should not really get here */ +/* fixme: need bunch of headers for this assert. check why no headers. */ +/* NO_PVH_ASSERT_VCPU(current); */ +if ( !(ctxt->regs->eflags &EFLG_VM ) &&mode_iopl () )return X86EMUL_OKAY ;
xen/arch/x86/hvm/mtrr.c int32_t hvm_get_mem_pinned_cacheattr( · line 560
Quoted 12 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor
xen/arch/x86/hvm/mtrr.c +3
-0@@ -553,6 +553,9 @@ int32_t hvm_get_mem_pinned_cacheattr( *type =0 ; +if (is_pvh_domain (d) ) +return 0 ; +if ( !is_hvm_domain (d) )return 0 ;
Doesn't the latter check by itself already do what you want?
xen/arch/x86/hvm/mtrr.c static int hvm_save_mtrr_msr(struct doma · line 618
Quoted 8 lines
xen/arch/x86/hvm/mtrr.c +1
-0@@ -606,6 +612,7 @@ static int hvm_save_mtrr_msr(struct domastruct vcpu *v;struct hvm_hw_mtrr hw_mtrr;struct mtrr_state *mtrr_state; +/* save mtrr&pat */ for_each_vcpu (d, v) {
Please drop benign changes like this from this already big patch series.
Quoted 6 lines
xen/arch/x86/msi.c +0
-0@@ -766,10 +766,12 @@ static int msix_capability_init(struct pWARN_ON (rangeset_overlaps_range (mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last));
xen/arch/x86/msi.c static int msix_capability_init(struct p · line 776
Quoted 10 lines
xen/arch/x86/msi.c +4
-2-if (rangeset_add_range (mmio_ro_ranges, dev->msix_table.first, +/* PVH: for now we don't make the mmio range readonly. See xen-devel for thread: +* "[PVH]: Help: msi.c". When linux msi.c is fixed, pvh check can be removed */ +if ( !is_pvh_domain (dev->domain) &&rangeset_add_range (mmio_ro_ranges, dev->msix_table.first, dev->msix_table.last) )WARN (); -if (rangeset_add_range (mmio_ro_ranges, dev->msix_pba.first, +if ( !is_pvh_domain (dev->domain) &&rangeset_add_range (mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last) )WARN ();
I hope there is no plan for this to go in in this shape.
xen/arch/x86/x86_emulate/x86_emulate.c static int ioport_access_check( · line 972
Quoted 8 lines
xen/arch/x86/x86_emulate/x86_emulate.c +2
-0@@ -968,6 +968,10 @@ static int ioport_access_check(struct segment_register tr;int rc =X86EMUL_OKAY ; +/* PVH should not really get here */ +/* fixme: need bunch of headers for this assert. check why no headers. */
Because the emulator is intended to be (almost) standalone, so building the emulator test (as user space app) is also possible.
Jan
Quoted 4 lines
xen/arch/x86/x86_emulate/x86_emulate.c +2
-0+/* NO_PVH_ASSERT_VCPU(current); */ +if ( !(ctxt->regs->eflags &EFLG_VM ) &&mode_iopl () )return X86EMUL_OKAY ;
Quoted 3 lines · On Mon, 14 Jan 2013 12:07:32 +0000 "Jan Beulich" <[email protected]> wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On 12.01.13 at 03:03, Mukesh Rathor <[email protected]> wrote:
Doesn't the latter check by itself already do what you want?
Yup. fixed.
Quoted 8 lines
xen/arch/x86/hvm/mtrr.c static int hvm_save_mtrr_msr(struct doma · line 615
Quoted 5 lines
xen/arch/x86/hvm/mtrr.c +1
-0@@ -606,6 +612,7 @@ static int hvm_save_mtrr_msr(struct doma +/* save mtrr&pat */ for_each_vcpu (d, v) {Please drop benign changes like this from this already big patch series.
Ok. Undone.
Quoted 6 lines
Quoted 6 lines
xen/arch/x86/msi.c +0
-0@@ -766,10 +766,12 @@ static int msix_capability_init(struct pWARN_ON (rangeset_overlaps_range (mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last));
Quoted 15 lines
Quoted 5 lines
xen/arch/x86/msi.c +0
-1- if ( rangeset_add_range(mmio_ro_ranges,
dev->msix_table.first, +/* PVH: for now we don't make the mmio range readonly. See xen-devel for thread:
+ * "[PVH]: Help:msi.c". When linuxmsi.cis fixed, pvh check can be removed */Quoted 8 lines
+ if ( !is_pvh_domain(dev->domain) &&
rangeset_add_range(mmio_ro_ranges, dev->msix_table.first, dev->msix_table.last))WARN();
- if ( rangeset_add_range(mmio_ro_ranges,dev->msix_pba.first,
+ if ( !is_pvh_domain(dev->domain) &&rangeset_add_range(mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last))WARN();I hope there is no plan for this to go in in this shape.
Can I ifdef it and make it go'able? Ifdef saying PVH is experimental? Not sure who's working on the issue on linux side.
Quoted 4 lines
Quoted 4 lines
---
a/xen/arch/x86/x86_emulate/x86_emulate.cFri Jan 11
16:34:17 2013 -0800 +++b/xen/arch/x86/x86_emulate/x86_emulate.cFri Jan 11 16:35:48
2013 -0800 @@ -968,6 +968,10 @@ static int
Quoted 8 lines
Quoted 5 lines
ioport_access_check( struct
segment_registertr; int rc =X86EMUL_OKAY;xen/arch/x86/msi.c +2
-0+/* PVH should not really get here */ +/* fixme: need bunch of headers for this assert. check why no headers. */
Because the emulator is intended to be (almost) standalone, so building the emulator test (as user space app) is also possible.
Got it, thanks.
Quoted 26 lines
Quoted 1 line
Quoted 1 line · Mukesh Rathor
Quoted 7 lines · On Mon, 14 Jan 2013 12:07:32 +0000 "Jan Beulich" <[email protected]> wrote:
Quoted 7 lines
Quoted 1 line
Quoted 1 line
On 12.01.13 at 03:03, Mukesh Rathor <[email protected]>
xen/arch/x86/msi.c +0
-0@@ -766,10 +766,12 @@ static int msix_capability_init(struct pWARN_ON (rangeset_overlaps_range (mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last));Quoted 15 lines
Quoted 5 lines
xen/arch/x86/msi.c +0
-1- if ( rangeset_add_range(mmio_ro_ranges,
dev->msix_table.first, +/* PVH: for now we don't make the mmio range readonly. See xen-devel for thread:
+ * "[PVH]: Help:msi.c". When linuxmsi.cis fixed, pvh check can be removed */Quoted 8 lines
+ if ( !is_pvh_domain(dev->domain) &&
rangeset_add_range(mmio_ro_ranges, dev->msix_table.first, dev->msix_table.last))WARN();
- if ( rangeset_add_range(mmio_ro_ranges,dev->msix_pba.first,
+ if ( !is_pvh_domain(dev->domain) &&rangeset_add_range(mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last))WARN();I hope there is no plan for this to go in in this shape.
Quoted 2 lines
Can I ifdef it and make it go'able? Ifdef saying PVH is experimental? Not sure who's working on the issue on linux side.
No, unless you intend the whole PVH code to become conditional, default off. You're widening a known security hole by suppressing this.
Jan
xen/arch/x86/time.c void tsc_set_info(struct domain *d, · line 1928
Quoted 11 lines · Mukesh Rathor
diff -r
0a38c610f26b-r33fc5356ad7cxen/arch/x86/time.cxen/arch/x86/time.c +1
-1@@ -1923,7 +1923,7 @@ void tsc_set_info(struct domain *d,break ; } d->arch.incarnation = incarnation +1 ; -if (is_hvm_domain (d) ) +if (is_hvm_or_pvh_domain (d) )hvm_set_rdtsc_exiting (d, d->arch.vtsc); }
The pvh vmexit handler in the last patch crashes the guest if it gets an RDTSC interception vmexit, so presumably either something should be added there or we need to make sure that d->arch.vtsc is never set on a PVH domain.
Tim.
Quoted 17 lines · On Thu, 24 Jan 2013 16:44:34 +0000 Tim Deegan <[email protected]> wrote:
xen/arch/x86/time.c void tsc_set_info(struct domain *d, · line 1928
Quoted 11 lines · Mukesh Rathor
diff -r
0a38c610f26b-r33fc5356ad7cxen/arch/x86/time.cxen/arch/x86/time.c +1
-1@@ -1923,7 +1923,7 @@ void tsc_set_info(struct domain *d,break ; } d->arch.incarnation = incarnation +1 ; -if (is_hvm_domain (d) ) +if (is_hvm_or_pvh_domain (d) )hvm_set_rdtsc_exiting (d, d->arch.vtsc); }The pvh vmexit handler in the last patch crashes the guest if it gets an RDTSC interception vmexit, so presumably either something should be added there or we need to make sure that
d->arch.vtscis never set on a PVH domain.
Fixed. For now, making sure vtsc is not set for PVH. But, I added an action item for Phase II to investigate and add support for it. At first glance, staring at tsc code for couple hours, I'm still clueless.
Thanks,
Mukesh
Quoted 28 lines · On Wed, 16 Jan 2013 10:00:33 +0000 "Jan Beulich" <[email protected]> wrote:
Quoted 28 lines
Quoted 2 lines
Quoted 2 lines
On 16.01.13 at 02:02, Mukesh Rathor <[email protected]> wrote:
Quoted 22 lines · On Mon, 14 Jan 2013 12:07:32 +0000 "Jan Beulich" <[email protected]> wrote:
Quoted 12 lines
Quoted 1 line
Quoted 1 line
On 12.01.13 at 03:03, Mukesh Rathor <[email protected]>
xen/arch/x86/msi.c +0
-1@@ -766,10 +766,12 @@ static int msix_capability_init(struct pWARN_ON (rangeset_overlaps_range (mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last)); - if ( rangeset_add_range(mmio_ro_ranges,
dev->msix_table.first, +/* PVH: for now we don't make the mmio range readonly. See xen-devel for thread:
+ * "[PVH]: Help:msi.c". When linuxmsi.cis fixed, pvh check can be removed */Quoted 8 lines
+ if ( !is_pvh_domain(dev->domain) &&
rangeset_add_range(mmio_ro_ranges, dev->msix_table.first, dev->msix_table.last))WARN();
- if ( rangeset_add_range(mmio_ro_ranges,dev->msix_pba.first,
+ if ( !is_pvh_domain(dev->domain) &&rangeset_add_range(mmio_ro_ranges, dev->msix_pba.first, dev->msix_pba.last))WARN();I hope there is no plan for this to go in in this shape.
Quoted 6 lines
Quoted 2 lines
Can I ifdef it and make it go'able? Ifdef saying PVH is experimental? Not sure who's working on the issue on linux side.
No, unless you intend the whole PVH code to become conditional, default off. You're widening a known security hole by suppressing this.
No, it's only for PVH that the rangesets are not added, and only temporary so we've something working for PVH in xen, and others can play with PVH, test, contribute fixes, etc... If it's a problem, I can look into disabling MSI for PVH too? If no one picks up the issue on the linux side, I can start looking at it too after xen patches for phase I are checked in.
thanks,
M-