@@ -466,7 +466,7 @@ 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)
+int p2m_set_mem_spp_wp(struct domain *d, gfn_t gfn, bool spp, bool w)
{
struct p2m_domain *p2m = p2m_get_hostp2m(d);
mfn_t mfn;
@@ -482,8 +482,9 @@ int p2m_set_mem_spp_wp(struct domain *d, gfn_t gfn)
rc = -1;
goto unlock_exit;
}
+
if ( p2m->update_ept_spp_wp )
- rc = p2m->update_ept_spp_wp(p2m, gfn_l);
+ rc = p2m->update_ept_spp_wp(p2m, gfn_l, spp, w);
unlock_exit:
p2m_unlock(p2m);
@@ -528,7 +529,12 @@ int p2m_set_spp_page_st(struct domain *d, gfn_t gfn, uint32_t access_map)
int p2m_set_subpage(struct domain *d, gfn_t gfn, uint32_t access_map)
{
int ret;
- ret = p2m_set_mem_spp_wp(d, gfn);
+ bool w, spp = 0;
+
+ w = !~access_map;
+ spp = !w;
+ printk("SPP: Set subpage spp=%d, is write:%d\n", spp, w);
+ ret = p2m_set_mem_spp_wp(d, gfn, spp, w);
if ( ret < 0 )
{
printk("SPP: Set subpage ept wp failed!! %x\n", ret);
@@ -46,6 +46,11 @@ static inline bool_t is_epte_valid(ept_entry_t *e)
return ((e->epte & ~(1ul << 63)) != 0 && e->sa_p2mt != p2m_invalid);
}
+static inline bool_t is_epte_spp_wp(ept_entry_t *e)
+{
+ return ( e->spp && !(e->w) && (e->access == p2m_access_spp) );
+}
+
/* returns : 0 for success, -errno otherwise */
static int atomic_write_ept_entry(ept_entry_t *entryptr, ept_entry_t new,
int level)
@@ -725,7 +730,7 @@ bool_t ept_handle_misconfig(uint64_t gpa)
}
static int
-ept_spp_update_wp(struct p2m_domain *p2m, unsigned long gfn)
+ept_spp_update_wp(struct p2m_domain *p2m, unsigned long gfn, bool spp, bool w)
{
ept_entry_t *table, *ept_entry = NULL;
unsigned long gfn_remainder = gfn;
@@ -754,12 +759,16 @@ ept_spp_update_wp(struct p2m_domain *p2m, unsigned long gfn)
goto out;
}
+ if ( is_epte_spp_wp(ept_entry) && spp )
+ goto sync_out;
+
new_entry = atomic_read_ept_entry(ept_entry);
- new_entry.spp = 1;
- new_entry.w = 0;
- new_entry.access = p2m_access_spp;
+ new_entry.spp = spp;
+ new_entry.w = w;
+ new_entry.access = spp? p2m_access_spp:p2m_access_n;
write_atomic(&(ept_entry->epte), new_entry.epte);
+sync_out:
ept_sync_domain(p2m);
rc = 0;
out:
@@ -267,7 +267,7 @@ struct p2m_domain {
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);
+ unsigned long gfn, bool spp, bool w);
int (*spp_set_entry)(struct p2m_domain *p2m,
unsigned long gfn,
u64 access);