@@ -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
@@ -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;
@@ -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).