[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 07/14] xen: vmx: Update the EPT leaf entry indicated with the SPP enable bit.
From: Zhang Yi Z <yi.z.zhang@xxxxxxxxxxxxxxx> If the sub-page write permission VM-execution control is set, treatment of write accesses to guest-physical accesses depends on the state of the accumulated write-access bit (position 1) and sub-page permission bit (position 61) in the EPT leaf paging-structure. Software will update the EPT leaf entry sub-page permission bit while kvm_set_subpage. If the EPT write-access bit set to 0 and the SPP bit set to 1 in the leaf EPT paging-structure entry that maps a 4KB page, then the hardware will look up a VMM-managed Sub-Page Permission Table (SPPT), which will also be prepared by setup kvm_set_subpage. Signed-off-by: Zhang Yi Z <yi.z.zhang@xxxxxxxxxxxxxxx> --- xen/arch/x86/mm/mem_access.c | 24 ++++++++++++++++++++++ xen/arch/x86/mm/p2m-ept.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-x86/p2m.h | 2 ++ 3 files changed, 73 insertions(+) diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 5adaf6d..a471c74 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -466,6 +466,30 @@ int p2m_get_mem_access(struct domain *d, gfn_t gfn, xenmem_access_t *access) return _p2m_get_mem_access(p2m, gfn, access); } +int p2m_set_mem_spp_wp(struct domain *d, gfn_t gfn) +{ + struct p2m_domain *p2m = p2m_get_hostp2m(d); + mfn_t mfn; + p2m_access_t old_a; + int rc = -1; + p2m_type_t t; + unsigned long gfn_l = gfn_x(gfn); + + p2m_lock(p2m); + mfn = p2m->get_entry(p2m, gfn_l, &t, &old_a, 0, NULL, NULL); + if( mfn_eq(mfn, INVALID_MFN) ) + { + rc = -1; + goto unlock_exit; + } + if ( p2m->update_ept_spp_wp ) + rc = p2m->update_ept_spp_wp(p2m, gfn_l); + +unlock_exit: + p2m_unlock(p2m); + return rc; +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/mm/p2m-ept.c b/xen/arch/x86/mm/p2m-ept.c index 8d9da92..c249286 100644 --- a/xen/arch/x86/mm/p2m-ept.c +++ b/xen/arch/x86/mm/p2m-ept.c @@ -667,6 +667,48 @@ bool_t ept_handle_misconfig(uint64_t gpa) return spurious ? (rc >= 0) : (rc > 0); } +static int +ept_spp_update_wp(struct p2m_domain *p2m, unsigned long gfn) +{ + ept_entry_t *table, *ept_entry = NULL; + unsigned long gfn_remainder = gfn; + ept_entry_t new_entry = { .epte = 0 }; + struct ept_data *ept = &p2m->ept; + unsigned int i; + int ret, rc; + + table = map_domain_page(_mfn(pagetable_get_pfn(p2m_get_pagetable(p2m)))); + + ret = GUEST_TABLE_MAP_FAILED; + for ( i = ept->wl; i > 0; i-- ) + { + ret = ept_next_level(p2m, 0, &table, &gfn_remainder, i); + if ( ret != GUEST_TABLE_NORMAL_PAGE ) + { + rc = -ENOENT; + goto out; + } + } + + ept_entry = table + (gfn_remainder >> (i * EPT_TABLE_ORDER)); + if ( !is_epte_present(ept_entry) ) + { + rc = -ENOENT; + goto out; + } + + new_entry = atomic_read_ept_entry(ept_entry); + new_entry.spp = 1; + new_entry.w = 0; + write_atomic(&(ept_entry->epte), new_entry.epte); + + ept_sync_domain(p2m); + rc = 0; +out: + unmap_domain_page(table); + return rc; +} + /* * ept_set_entry() computes 'need_modify_vtd_table' for itself, * by observing whether any gfn->mfn translations are modified. @@ -1264,6 +1306,11 @@ int ept_p2m_init(struct p2m_domain *p2m) p2m->flush_hardware_cached_dirty = ept_flush_pml_buffers; } + if ( cpu_has_vmx_ept_spp ) + { + p2m->update_ept_spp_wp = ept_spp_update_wp; + } + if ( !zalloc_cpumask_var(&ept->invalidate) ) return -ENOMEM; diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 0561643..adbc1c6 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -266,6 +266,8 @@ struct p2m_domain { unsigned long gfn, l1_pgentry_t *p, l1_pgentry_t new, unsigned int level); long (*audit_p2m)(struct p2m_domain *p2m); + int (*update_ept_spp_wp)(struct p2m_domain *p2m, + unsigned long gfn); /* * P2M updates may require TLBs to be flushed (invalidated). -- 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |