wbinvd();
}
+static void hvm_set_uc_mode(struct vcpu *v, bool_t is_in_uc_mode)
+{
+ v->domain->arch.hvm_domain.is_in_uc_mode = is_in_uc_mode;
+ shadow_blow_tables_per_domain(v->domain);
+ if ( hvm_funcs.set_uc_mode )
+ return hvm_funcs.set_uc_mode(v);
+}
+
int hvm_set_cr0(unsigned long value)
{
struct vcpu *v = current;
{
/* Flush physical caches. */
on_each_cpu(local_flush_cache, NULL, 1, 1);
- /* Shadow pagetables must recognise UC mode. */
- v->domain->arch.hvm_domain.is_in_uc_mode = 1;
- shadow_blow_tables_per_domain(v->domain);
+ hvm_set_uc_mode(v, 1);
}
spin_unlock(&v->domain->arch.hvm_domain.uc_lock);
}
v->arch.hvm_vcpu.cache_mode = NORMAL_CACHE_MODE;
if ( domain_exit_uc_mode(v) )
- {
- /* Shadow pagetables must recognise normal caching mode. */
- v->domain->arch.hvm_domain.is_in_uc_mode = 0;
- shadow_blow_tables_per_domain(v->domain);
- }
+ hvm_set_uc_mode(v, 0);
+
spin_unlock(&v->domain->arch.hvm_domain.uc_lock);
}
}
HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr, hvm_load_mtrr_msr,
1, HVMSR_PER_VCPU);
+
+uint8_t epte_get_entry_emt(
+ struct domain *d, unsigned long gfn, unsigned long mfn)
+{
+ uint8_t gmtrr_mtype, hmtrr_mtype;
+ uint32_t type;
+ struct vcpu *v = current;
+
+ if ( (current->domain != d) && ((v = d->vcpu[0]) == NULL) )
+ return MTRR_TYPE_WRBACK;
+
+ if ( !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 )
+ return MTRR_TYPE_UNCACHABLE;
+
+ if ( !mfn_valid(mfn) )
+ return MTRR_TYPE_UNCACHABLE;
+
+ if ( hvm_get_mem_pinned_cacheattr(d, gfn, &type) )
+ return type;
+
+ gmtrr_mtype = get_mtrr_type(&v->arch.hvm_vcpu.mtrr, (gfn << PAGE_SHIFT));
+ hmtrr_mtype = get_mtrr_type(&mtrr_state, (mfn << PAGE_SHIFT));
+ return ((gmtrr_mtype <= hmtrr_mtype) ? gmtrr_mtype : hmtrr_mtype);
+}
#include <asm/p2m.h>
#include <asm/hvm/vmx/vmx.h>
#include <xen/iommu.h>
+#include <asm/mtrr.h>
+#include <asm/hvm/cacheattr.h>
static void ept_p2m_type_to_flags(ept_entry_t *entry, p2m_type_t type)
{
/* Track the highest gfn for which we have ever had a valid mapping */
if ( gfn > d->arch.p2m->max_mapped_pfn )
d->arch.p2m->max_mapped_pfn = gfn;
-
- ept_entry->emt = EPT_DEFAULT_MT;
+ ept_entry->emt = epte_get_entry_emt(d, gfn, mfn_x(mfn));
ept_entry->sp_avail = walk_level ? 1 : 0;
if ( ret == GUEST_TABLE_SUPER_PAGE )
/* split the super page before to 4k pages */
split_table = map_domain_page(ept_entry->mfn);
+ offset = gfn & ((1 << EPT_TABLE_ORDER) - 1);
for ( i = 0; i < 512; i++ )
{
split_ept_entry = split_table + i;
- split_ept_entry->emt = EPT_DEFAULT_MT;
+ split_ept_entry->emt = epte_get_entry_emt(d,
+ gfn-offset+i, split_mfn+i);
split_ept_entry->sp_avail = 0;
split_ept_entry->mfn = split_mfn+i;
}
/* Set the destinated 4k page as normal */
-
- offset = gfn & ((1 << EPT_TABLE_ORDER) - 1);
split_ept_entry = split_table + offset;
+ split_ept_entry->emt = epte_get_entry_emt(d, gfn, mfn_x(mfn));
split_ept_entry->mfn = mfn_x(mfn);
split_ept_entry->avail1 = p2mt;
ept_p2m_type_to_flags(split_ept_entry, p2mt);
unmap_domain_page(split_table);
-
}
/* Success */
{
if ( order == EPT_TABLE_ORDER )
{
- for ( i = 0; i < 512; i++ )
+ for ( i = 0; i < ( 1 << order ); i++ )
iommu_map_page(d, gfn-offset+i, mfn_x(mfn)-offset+i);
}
else if ( !order )
{
if ( order == EPT_TABLE_ORDER )
{
- for ( i = 0; i < 512; i++ )
+ for ( i = 0; i < ( 1 << order ); i++ )
iommu_unmap_page(d, gfn-offset+i);
}
else if ( !order )
return mfn;
}
+static uint64_t ept_get_entry_content(struct domain *d, unsigned long gfn)
+{
+ ept_entry_t *table =
+ map_domain_page(mfn_x(pagetable_get_mfn(d->arch.phys_table)));
+ unsigned long gfn_remainder = gfn;
+ ept_entry_t *ept_entry;
+ uint64_t content = 0;
+
+ u32 index;
+ int i, ret=0;
+
+ /* This pfn is higher than the highest the p2m map currently holds */
+ if ( gfn > d->arch.p2m->max_mapped_pfn )
+ goto out;
+
+ for ( i = EPT_DEFAULT_GAW; i > 0; i-- )
+ {
+ ret = ept_next_level(d, 1, &table, &gfn_remainder,
+ i * EPT_TABLE_ORDER, 0);
+ if ( !ret )
+ goto out;
+ else if ( ret == GUEST_TABLE_SUPER_PAGE )
+ break;
+ }
+
+ index = gfn_remainder >> ( i * EPT_TABLE_ORDER);
+ ept_entry = table + index;
+ content = ept_entry->epte;
+
+ out:
+ unmap_domain_page(table);
+ return content;
+}
+
static mfn_t ept_get_entry_current(unsigned long gfn, p2m_type_t *t)
{
return ept_get_entry(current->domain, gfn, t);
}
+void ept_change_entry_emt_with_range(struct domain *d, unsigned long start_gfn,
+ unsigned long end_gfn)
+{
+ unsigned long gfn;
+ p2m_type_t p2mt;
+ uint64_t epte;
+ int order = 0;
+ unsigned long mfn;
+
+ for ( gfn = start_gfn; gfn <= end_gfn; gfn++ )
+ {
+ epte = ept_get_entry_content(d, gfn);
+ if ( epte == 0 )
+ continue;
+ mfn = (epte & EPTE_MFN_MASK) >> PAGE_SHIFT;
+ if ( !mfn_valid(mfn) )
+ continue;
+ p2mt = (epte & EPTE_AVAIL1_MASK) >> 8;
+ order = 0;
+
+ if ( epte & EPTE_SUPER_PAGE_MASK )
+ {
+ if ( !(gfn & ( (1 << EPT_TABLE_ORDER) - 1)) &&
+ ((gfn + 0x1FF) <= end_gfn) )
+ {
+ /* gfn assigned with 2M, and the end covers more than 2m areas.
+ * Set emt for super page.
+ */
+ order = EPT_TABLE_ORDER;
+ ept_set_entry(d, gfn, _mfn(mfn), order, p2mt);
+ gfn += 0x1FF;
+ }
+ else
+ {
+ /* change emt for partial entries of the 2m area */
+ ept_set_entry(d, gfn, _mfn(mfn), order, p2mt);
+ gfn = ((gfn >> EPT_TABLE_ORDER) << EPT_TABLE_ORDER) + 0x1FF;
+ }
+ }
+ else /* gfn assigned with 4k */
+ ept_set_entry(d, gfn, _mfn(mfn), order, p2mt);
+ }
+}
+
/* Walk the whole p2m table, changing any entries of the old type
* to the new type. This is used in hardware-assisted paging to
* quickly enable or diable log-dirty tracking */