Support of RO MMIO access for PVH/HVMlite dom0s
v3 cover Support of RO MMIO access for PVH/HVMlite dom0s
v3 (patch 2 changes):
* Added handling of non-MMCFG addresses
* Factored out RO MMCFG test into pci_ro_mmcfg_decode()
* Renamed and changed arguments to hvm_emulate_one_mmio()
* Style/naming changes
Boris Ostrovsky (2):
x86/mm: Add information about faulted page's presence to npfec
structure
x86/PCI: Intercept accesses to RO MMIO from dom0s in HVM containers
xen/arch/x86/hvm/emulate.c | 46 +++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 8 ++++ xen/arch/x86/hvm/svm/svm.c | 3 +- xen/arch/x86/hvm/vmx/vmx.c | 5 ++- xen/arch/x86/mm.c | 58 ++++++++++--------------------- xen/arch/x86/x86_64/mmconfig_64.c | 10 +++++ xen/arch/x86/x86_emulate/x86_emulate.c | 10 +++++ xen/arch/x86/x86_emulate/x86_emulate.h | 12 ++++++ xen/include/asm-x86/hvm/emulate.h | 1 + xen/include/asm-x86/mm.h | 17 +++++++++ xen/include/asm-x86/pci.h | 3 ++ xen/include/xen/mm.h | 1 + 12 files changed, 133 insertions(+), 41 deletions(-)
PATCH v3 1/2 x86/mm: Add information about faulted page's presence to npfec structure
This is provided explicitly in SVM and implicitly in VMX (when neither of the three EPT_EFFECTIVE_* bits is set).
--- xen/arch/x86/hvm/svm/svm.c | 3 ++- xen/arch/x86/hvm/vmx/vmx.c | 5 ++++- xen/include/xen/mm.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-)
xen/arch/x86/hvm/svm/svm.c +2 -1
@@ -1491,7 +1491,8 @@ static void svm_do_nested_pgfault(struct vcpu *v,struct npfec npfec = { .read_access = !(pfec & PFEC_insn_fetch), .write_access = !!(pfec & PFEC_write_access), - .insn_fetch = !!(pfec & PFEC_insn_fetch) + .insn_fetch = !!(pfec & PFEC_insn_fetch), + .present = !!(pfec & PFEC_page_present), };/* These bits are mutually exclusive */
xen/arch/x86/hvm/vmx/vmx.c +4 -1
@@ -2746,7 +2746,10 @@ static void ept_handle_violation(unsigned long qualification, paddr_t gpa) .read_access = !!(qualification & EPT_READ_VIOLATION) || !!(qualification & EPT_WRITE_VIOLATION), .write_access = !!(qualification & EPT_WRITE_VIOLATION), - .insn_fetch = !!(qualification & EPT_EXEC_VIOLATION) + .insn_fetch = !!(qualification & EPT_EXEC_VIOLATION), + .present = !!(qualification & (EPT_EFFECTIVE_READ | +EPT_EFFECTIVE_WRITE | + EPT_EFFECTIVE_EXEC)) };if ( tb_init_done )
xen/include/xen/mm.h +1 -0
@@ -159,6 +159,7 @@ struct npfec { unsigned int read_access:1; unsigned int write_access:1; unsigned int insn_fetch:1; + unsigned int present:1; unsigned int gla_valid:1; unsigned int kind:2; /* npfec_kind_t */ };
Signature · 1 line
1.7.1
Re: [PATCH v3 1/2] x86/mm: Add information about faulted page's presence to npfec structure
Quoted 6 lines
From: Boris Ostrovsky [mailto:[email protected]]
Sent: Saturday, December 19, 2015 3:40 AMThis is provided explicitly in SVM and implicitly in VMX (when neither of the three EPT_EFFECTIVE_* bits is set).
Quoted 6 lines
Signed-off-by Boris Ostrovsky <[email protected]>Reviewed-by Jan Beulich <[email protected]>
well, another ack here:
PATCH v3 2/2 x86/PCI: Intercept accesses to RO MMIO from dom0s in HVM containers
In reply to Boris OstrovskyCommit 9256f66c1606 ("x86/PCI: intercept all PV Dom0 MMCFG writes") added intercepts for writes to RO MMCFG space from PV dom0.
Similar functionality, including access to RO non-MMCFG addresses, is needed by dom0s in HVM containers (such as PVH and, in the future, HVMlite).
--- xen/arch/x86/hvm/emulate.c | 46 +++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 8 ++++ xen/arch/x86/mm.c | 58 ++++++++++--------------------- xen/arch/x86/x86_64/mmconfig_64.c | 10 +++++ xen/arch/x86/x86_emulate/x86_emulate.c | 10 +++++ xen/arch/x86/x86_emulate/x86_emulate.h | 12 ++++++ xen/include/asm-x86/hvm/emulate.h | 1 + xen/include/asm-x86/mm.h | 17 +++++++++ xen/include/asm-x86/pci.h | 3 ++ 9 files changed, 126 insertions(+), 39 deletions(-)
xen/arch/x86/hvm/emulate.c +46 -0
@@ -1778,6 +1778,52 @@ int hvm_emulate_one_no_write(return _hvm_emulate_one (hvmemul_ctxt, &hvm_emulate_ops_no_write); } +int hvm_emulate_one_mmio (unsigned long mfn,unsigned long gla) +{ +static const struct x86_emulate_ops hvm_intercept_ops_mmcfg = { + .read = x86emul_unhandleable_rw, + .insn_fetch = hvmemul_insn_fetch, + .write = mmcfg_intercept_write, + }; +static const struct x86_emulate_ops hvm_ro_emulate_ops_mmio = { + .read = x86emul_unhandleable_rw, + .insn_fetch = hvmemul_insn_fetch, + .write = mmio_ro_emulated_write + }; +struct mmio_ro_emulate_ctxt mmio_ro_ctxt = { .cr2 = gla }; +struct hvm_emulate_ctxt ctxt; +const struct x86_emulate_ops *ops; +unsigned int seg, bdf; +int rc; + +if (pci_ro_mmcfg_decode (mfn, &seg, &bdf) ) + { + mmio_ro_ctxt.seg = seg; + mmio_ro_ctxt.bdf = bdf; + ops = &hvm_intercept_ops_mmcfg; + } +else + ops = &hvm_ro_emulate_ops_mmio; + +hvm_emulate_prepare (&ctxt,guest_cpu_user_regs ()); + ctxt.ctxt.data = &mmio_ro_ctxt; + rc =_hvm_emulate_one (&ctxt, ops); +switch ( rc ) + { +case X86EMUL_UNHANDLEABLE : +hvm_dump_emulation_state (XENLOG_G_WARNING "MMCFG" , &ctxt); +break ; +case X86EMUL_EXCEPTION : +if ( ctxt.exn_pending ) +hvm_inject_trap (&ctxt.trap); +/* fallthrough */ +default : +hvm_emulate_writeback (&ctxt); + } + +return rc; +} +void hvm_mem_access_emulate_one (enum emul_kind kind,unsigned int trapnr,unsigned int errcode) {
xen/arch/x86/hvm/hvm.c +8 -0
@@ -3115,6 +3115,14 @@ int hvm_hap_nested_page_fault(paddr_t gpa, unsigned long gla, goto out_put_gfn; } +if ( (p2mt == p2m_mmio_direct) &&is_hardware_domain (currd) && + npfec.write_access && npfec.present && + (hvm_emulate_one_mmio (mfn_x (mfn), gla) ==X86EMUL_OKAY ) ) + { + rc =1 ; + goto out_put_gfn; + } +/* If we fell through, the vcpu will retry now that access restrictions have * been removed. It may fault again if the p2m entry type still requires so. * Otherwise, this is an error condition. */
xen/arch/x86/mm.c +19 -39
113 lines not on this page · raw message
xen/arch/x86/x86_64/mmconfig_64.c +10 -0
@@ -198,6 +198,16 @@ bool_t pci_mmcfg_decode(unsigned long mfn, unsigned int *seg,return 0 ; } +bool_t pci_ro_mmcfg_decode (unsigned long mfn,unsigned int *seg, +unsigned int *bdf) +{ +const unsigned long *ro_map; + +return pci_mmcfg_decode (mfn, seg, bdf) && + ((ro_map =pci_get_ro_map (*seg)) ==NULL || + !test_bit (*bdf, ro_map)); +} +int __init pci_mmcfg_arch_init (void ) {int i;
xen/arch/x86/x86_emulate/x86_emulate.c +10 -0
@@ -1444,6 +1444,16 @@ static int inject_swint(enum x86_swint_type type,return ops->inject_hw_exception (fault_type, error_code, ctxt); } +int x86emul_unhandleable_rw ( +enum x86_segment seg, +unsigned long offset, +void *p_data, +unsigned int bytes, +struct x86_emulate_ctxt *ctxt) +{ +return X86EMUL_UNHANDLEABLE ; +} + int x86_emulate( struct x86_emulate_ctxt *ctxt,
xen/arch/x86/x86_emulate/x86_emulate.h +12 -0
@@ -430,6 +430,9 @@ struct x86_emulate_ctxt } flags;uint8_t byte; } retire; + +/* Caller data that can be used by x86_emulate_ops' routines. */ +void *data; };struct x86_emulate_stub {
@@ -463,4 +466,13 @@ void *decode_register ( uint8_t modrm_reg, struct cpu_user_regs *regs, int highbyte_regs); +/* Unhandleable read, write or instruction fetch */ +int +x86emul_unhandleable_rw ( +enum x86_segment seg, +unsigned long offset, +void *p_data, +unsigned int bytes, +struct x86_emulate_ctxt *ctxt); +#endif /* __X86_EMULATE_H__ */
xen/include/asm-x86/hvm/emulate.h +1 -0
@@ -57,6 +57,7 @@ void hvm_emulate_writeback(struct segment_register *hvmemul_get_seg_reg (enum x86_segment seg,struct hvm_emulate_ctxt *hvmemul_ctxt); +int hvm_emulate_one_mmio (unsigned long mfn,unsigned long gla); int hvmemul_do_pio_buffer(uint16_t port, unsigned int size,
xen/include/asm-x86/mm.h +17 -0
@@ -7,6 +7,7 @@#include <xen/spinlock.h> #include <asm/io.h> #include <asm/uaccess.h> +#include <asm/x86_emulate.h> /* * Per-page-frame information.
@@ -488,6 +489,22 @@ void memguard_unguard_range(void *p, unsigned long l);void memguard_guard_stack (void *p);void memguard_unguard_stack (void *p); +struct mmio_ro_emulate_ctxt { +unsigned long cr2; +unsigned int seg, bdf; +}; + +extern int mmio_ro_emulated_write (enum x86_segment seg, +unsigned long offset, +void *p_data, +unsigned int bytes, +struct x86_emulate_ctxt *ctxt); +extern int mmcfg_intercept_write (enum x86_segment seg, +unsigned long offset, +void *p_data, +unsigned int bytes, +struct x86_emulate_ctxt *ctxt); +int ptwr_do_page_fault (struct vcpu *,unsigned long ,struct cpu_user_regs *); int mmio_ro_do_page_fault(struct vcpu *, unsigned long,
xen/include/asm-x86/pci.h +3 -0
@@ -23,4 +23,7 @@ int pci_msi_conf_write_intercept(struct pci_dev *, unsigned int reg,bool_t pci_mmcfg_decode (unsigned long mfn,unsigned int *seg,unsigned int *bdf); +bool_t pci_ro_mmcfg_decode (unsigned long mfn,unsigned int *seg, +unsigned int *bdf); +#endif /* __X86_PCI_H__ */
Signature · 1 line
1.7.1