x86/P2M: reduce time group type changes take
cover x86/P2M: reduce time group type changes take
1: EPT: don't walk entire page tables when globally changing types 2: EPT: don't walk entire page tables when changing types on a range 3: P2M: simplify write_p2m_entry()
4: NPT: don't walk entire page tables when changing types on a range 5: NPT: don't walk entire page tables when globally changing types 6: P2M: cleanup
Beyond this series it might also be worthwhile considering to make HVMOP_set_mem_type use p2m_change_type_range(), avoiding the need for explicit preemption there.
PATCH 1/6 x86/EPT: don't walk entire page tables when globally changing types
Instead leverage the EPT_MISCONFIG VM exit by marking just the top level entries as needing recalculation of their type, propagating the the recalculation state down as necessary such that the actual recalculation gets done upon access.
For this to work, we have to
- restrict the types between which conversions can be done (right now only the two types involved in log dirty tracking need to be taken care of)
- remember the ranges that log dirty tracking was requested for as well as whether global log dirty tracking is in effect
xen/arch/x86/mm/hap/hap.c +12 -0
@@ -110,11 +110,18 @@ int hap_track_dirty_vram(struct domain *if ( begin_pfn != dirty_vram->begin_pfn || begin_pfn + nr != dirty_vram->end_pfn ) { +unsigned long ostart = dirty_vram->begin_pfn; +unsigned long oend = dirty_vram->end_pfn; + dirty_vram->begin_pfn = begin_pfn; dirty_vram->end_pfn = begin_pfn + nr;paging_unlock (d); +if ( oend > ostart ) +p2m_change_type_range (d, ostart, oend, + p2m_ram_logdirty, p2m_ram_rw); +/* set l1e entries of range within P2M table to be read-only. */ p2m_change_type_range (d, begin_pfn, begin_pfn + nr, p2m_ram_rw, p2m_ram_logdirty);
@@ -150,11 +157,16 @@ int hap_track_dirty_vram(struct domain ** If zero pages specified while tracking dirty vram * then stop tracking */ + begin_pfn = dirty_vram->begin_pfn; + nr = dirty_vram->end_pfn - dirty_vram->begin_pfn;xfree (dirty_vram); d->arch.hvm_domain.dirty_vram =NULL ; }paging_unlock (d); +if ( nr ) +p2m_change_type_range (d, begin_pfn, begin_pfn + nr, + p2m_ram_logdirty, p2m_ram_rw); } out:if ( dirty_bitmap )
xen/arch/x86/mm/p2m.c +59 -7
108 lines not on this page · raw message
xen/arch/x86/mm/p2m-ept.c +88 -64
302 lines not on this page · raw message
xen/include/asm-x86/hvm/vmx/vmx.h +1 -1
@@ -38,7 +38,7 @@ typedef union { ipat : 1, /* bit 6 - Ignore PAT memory type */ sp : 1, /* bit 7 - Is this a superpage? */ rsvd1 : 2, /* bits 9:8 - Reserved for future use */ - avail1 : 1, /* bit 10 - Software available 1 */ + recalc : 1, /* bit 10 - Software available 1 */ snp : 1, /* bit 11 - VT-d snoop control in shared EPT/VT-d usage */ mfn : 40, /* bits 51:12 - Machine physical frame number */
xen/include/asm-x86/p2m.h +13 -0
@@ -139,6 +139,10 @@ typedef unsigned int p2m_query_t; | p2m_to_mask(p2m_grant_map_ro) \ | p2m_to_mask(p2m_ram_shared) ) +/* Types that can be subject to bulk transitions. */ +#define P2M_CHANGEABLE_TYPES (p2m_to_mask(p2m_ram_rw) \ + | p2m_to_mask(p2m_ram_logdirty) ) +#define P2M_POD_TYPES (p2m_to_mask(p2m_populate_on_demand))/* Pageable types */
@@ -167,6 +171,7 @@ typedef unsigned int p2m_query_t;#define p2m_is_hole (_t) (p2m_to_mask(_t) & P2M_HOLE_TYPES)#define p2m_is_mmio (_t) (p2m_to_mask(_t) & P2M_MMIO_TYPES)#define p2m_is_readonly (_t) (p2m_to_mask(_t) & P2M_RO_TYPES) +#define p2m_is_changeable (_t) (p2m_to_mask(_t) & P2M_CHANGEABLE_TYPES)#define p2m_is_pod (_t) (p2m_to_mask(_t) & P2M_POD_TYPES)#define p2m_is_grant (_t) (p2m_to_mask(_t) & P2M_GRANT_TYPES)/* Grant types are *not* considered valid, because they can be
@@ -209,6 +214,11 @@ struct p2m_domain {* threaded on in LRU order. */ struct list_head np2m_list; +/* Host p2m: Log-dirty ranges registered for the domain. */ +struct rangeset *logdirty_ranges; + +/* Host p2m: Global log-dirty mode enabled for the domain. */ +bool_t global_logdirty;/* Host p2m: when this flag is set, don't flush all the nested-p2m * tables on every host-p2m change. The setter of this flag
@@ -510,6 +520,9 @@ p2m_type_t p2m_change_type(struct domain/* Report a change affecting memory types. */ void p2m_memory_type_changed (struct domain *d); +int p2m_is_logdirty_range (struct p2m_domain *,unsigned long start, +unsigned long end); +/* Set mmio addresses in the p2m table (for pass-through) */ int set_mmio_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn);int clear_mmio_p2m_entry (struct domain *d,unsigned long gfn);
x86/EPT: don't walk entire page tables when globally changing types
Instead leverage the EPT_MISCONFIG VM exit by marking just the top level entries as needing recalculation of their type, propagating the the recalculation state down as necessary such that the actual recalculation gets done upon access.
For this to work, we have to
- restrict the types between which conversions can be done (right now only the two types involved in log dirty tracking need to be taken care of)
- remember the ranges that log dirty tracking was requested for as well as whether global log dirty tracking is in effect
xen/arch/x86/mm/hap/hap.c +12 -0
@@ -110,11 +110,18 @@ int hap_track_dirty_vram(struct domain *if ( begin_pfn != dirty_vram->begin_pfn || begin_pfn + nr != dirty_vram->end_pfn ) { +unsigned long ostart = dirty_vram->begin_pfn; +unsigned long oend = dirty_vram->end_pfn; + dirty_vram->begin_pfn = begin_pfn; dirty_vram->end_pfn = begin_pfn + nr;paging_unlock (d); +if ( oend > ostart ) +p2m_change_type_range (d, ostart, oend, + p2m_ram_logdirty, p2m_ram_rw); +/* set l1e entries of range within P2M table to be read-only. */ p2m_change_type_range (d, begin_pfn, begin_pfn + nr, p2m_ram_rw, p2m_ram_logdirty);
@@ -150,11 +157,16 @@ int hap_track_dirty_vram(struct domain ** If zero pages specified while tracking dirty vram * then stop tracking */ + begin_pfn = dirty_vram->begin_pfn; + nr = dirty_vram->end_pfn - dirty_vram->begin_pfn;xfree (dirty_vram); d->arch.hvm_domain.dirty_vram =NULL ; }paging_unlock (d); +if ( nr ) +p2m_change_type_range (d, begin_pfn, begin_pfn + nr, + p2m_ram_logdirty, p2m_ram_rw); } out:if ( dirty_bitmap )
xen/arch/x86/mm/p2m.c +59 -7
108 lines not on this page · raw message
xen/arch/x86/mm/p2m-ept.c +88 -64
302 lines not on this page · raw message
xen/include/asm-x86/hvm/vmx/vmx.h +1 -1
@@ -38,7 +38,7 @@ typedef union { ipat : 1, /* bit 6 - Ignore PAT memory type */ sp : 1, /* bit 7 - Is this a superpage? */ rsvd1 : 2, /* bits 9:8 - Reserved for future use */ - avail1 : 1, /* bit 10 - Software available 1 */ + recalc : 1, /* bit 10 - Software available 1 */ snp : 1, /* bit 11 - VT-d snoop control in shared EPT/VT-d usage */ mfn : 40, /* bits 51:12 - Machine physical frame number */
xen/include/asm-x86/p2m.h +13 -0
@@ -139,6 +139,10 @@ typedef unsigned int p2m_query_t; | p2m_to_mask(p2m_grant_map_ro) \ | p2m_to_mask(p2m_ram_shared) ) +/* Types that can be subject to bulk transitions. */ +#define P2M_CHANGEABLE_TYPES (p2m_to_mask(p2m_ram_rw) \ + | p2m_to_mask(p2m_ram_logdirty) ) +#define P2M_POD_TYPES (p2m_to_mask(p2m_populate_on_demand))/* Pageable types */
@@ -167,6 +171,7 @@ typedef unsigned int p2m_query_t;#define p2m_is_hole (_t) (p2m_to_mask(_t) & P2M_HOLE_TYPES)#define p2m_is_mmio (_t) (p2m_to_mask(_t) & P2M_MMIO_TYPES)#define p2m_is_readonly (_t) (p2m_to_mask(_t) & P2M_RO_TYPES) +#define p2m_is_changeable (_t) (p2m_to_mask(_t) & P2M_CHANGEABLE_TYPES)#define p2m_is_pod (_t) (p2m_to_mask(_t) & P2M_POD_TYPES)#define p2m_is_grant (_t) (p2m_to_mask(_t) & P2M_GRANT_TYPES)/* Grant types are *not* considered valid, because they can be
@@ -209,6 +214,11 @@ struct p2m_domain {* threaded on in LRU order. */ struct list_head np2m_list; +/* Host p2m: Log-dirty ranges registered for the domain. */ +struct rangeset *logdirty_ranges; + +/* Host p2m: Global log-dirty mode enabled for the domain. */ +bool_t global_logdirty;/* Host p2m: when this flag is set, don't flush all the nested-p2m * tables on every host-p2m change. The setter of this flag
@@ -510,6 +520,9 @@ p2m_type_t p2m_change_type(struct domain/* Report a change affecting memory types. */ void p2m_memory_type_changed (struct domain *d); +int p2m_is_logdirty_range (struct p2m_domain *,unsigned long start, +unsigned long end); +/* Set mmio addresses in the p2m table (for pass-through) */ int set_mmio_p2m_entry (struct domain *d,unsigned long gfn,mfn_t mfn);int clear_mmio_p2m_entry (struct domain *d,unsigned long gfn);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 2/6 x86/EPT: don't walk entire page tables when changing types on a range
In reply to Jan BeulichThis requires a new P2M backend hook and a little bit of extra care and accounting in the generic function.
Note that even on leaf entries we must not immediately set the new type (in an attempt to avoid the EPT_MISCONFIG VM exits), since the global accounting in p2m_change_type_range() gets intentionally done only after updating page tables (or else the update there would conflict with the function's own use of p2m_is_logdirty_range()), and the correct type can only be calculated with that in place.
xen/arch/x86/mm/p2m.c +26 -4
@@ -730,17 +730,33 @@ void p2m_change_type_range(struct domain {p2m_access_t a;p2m_type_t pt; -unsigned long gfn; +unsigned long gfn = start;mfn_t mfn;struct p2m_domain *p2m =p2m_get_hostp2m (d);int rc =0 ; -BUG_ON (p2m_is_grant (ot) ||p2m_is_grant (nt)); +ASSERT (ot != nt); +ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt));p2m_lock (p2m); p2m->defer_nested_flush =1 ; -for ( gfn = start; gfn < end; ) +if (unlikely (end > p2m->max_mapped_pfn) ) + { +if ( !gfn ) + { + p2m->change_entry_type_global (p2m, ot, nt); + gfn = end; + } + end = p2m->max_mapped_pfn +1 ; + } + +if ( gfn < end && p2m->change_entry_type_range ) + { + rc = p2m->change_entry_type_range (p2m, ot, nt, gfn, end -1 ); + gfn = end; + } +while ( !rc && gfn < end ) {unsigned int order;
@@ -769,12 +785,18 @@ void p2m_change_type_range(struct domain order =PAGE_ORDER_4K ; }if ( pt == ot ) -p2m_set_entry (p2m, gfn, mfn, order, nt, a); + rc =p2m_set_entry (p2m, gfn, mfn, order, nt, a); gfn +=1UL << order; gfn &=-1UL << order;if ( !gfn )break ; } +if ( rc ) + { +printk (XENLOG_G_ERR "Error %d changing Dom%d GFNs [%lx,%lx] from %d to %d\n" , + rc, d->domain_id, start, end -1 , ot, nt); +domain_crash (d); + }switch ( nt ) {
xen/arch/x86/mm/p2m-ept.c +112 -0
130 lines not on this page · raw message
xen/include/asm-x86/p2m.h +4 -0
@@ -243,6 +243,10 @@ struct p2m_domain {void (*change_entry_type_global)(struct p2m_domain *p2m,p2m_type_t ot,p2m_type_t nt); +int (*change_entry_type_range)(struct p2m_domain *p2m, +p2m_type_t ot,p2m_type_t nt, +unsigned long first_gfn, +unsigned long last_gfn);void (*memory_type_changed)(struct p2m_domain *p2m); void (*write_p2m_entry)(struct p2m_domain *p2m,
x86/EPT: don't walk entire page tables when changing types on a range
This requires a new P2M backend hook and a little bit of extra care and accounting in the generic function.
Note that even on leaf entries we must not immediately set the new type (in an attempt to avoid the EPT_MISCONFIG VM exits), since the global accounting in p2m_change_type_range() gets intentionally done only after updating page tables (or else the update there would conflict with the function's own use of p2m_is_logdirty_range()), and the correct type can only be calculated with that in place.
xen/arch/x86/mm/p2m.c +26 -4
@@ -730,17 +730,33 @@ void p2m_change_type_range(struct domain {p2m_access_t a;p2m_type_t pt; -unsigned long gfn; +unsigned long gfn = start;mfn_t mfn;struct p2m_domain *p2m =p2m_get_hostp2m (d);int rc =0 ; -BUG_ON (p2m_is_grant (ot) ||p2m_is_grant (nt)); +ASSERT (ot != nt); +ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt));p2m_lock (p2m); p2m->defer_nested_flush =1 ; -for ( gfn = start; gfn < end; ) +if (unlikely (end > p2m->max_mapped_pfn) ) + { +if ( !gfn ) + { + p2m->change_entry_type_global (p2m, ot, nt); + gfn = end; + } + end = p2m->max_mapped_pfn +1 ; + } + +if ( gfn < end && p2m->change_entry_type_range ) + { + rc = p2m->change_entry_type_range (p2m, ot, nt, gfn, end -1 ); + gfn = end; + } +while ( !rc && gfn < end ) {unsigned int order;
@@ -769,12 +785,18 @@ void p2m_change_type_range(struct domain order =PAGE_ORDER_4K ; }if ( pt == ot ) -p2m_set_entry (p2m, gfn, mfn, order, nt, a); + rc =p2m_set_entry (p2m, gfn, mfn, order, nt, a); gfn +=1UL << order; gfn &=-1UL << order;if ( !gfn )break ; } +if ( rc ) + { +printk (XENLOG_G_ERR "Error %d changing Dom%d GFNs [%lx,%lx] from %d to %d\n" , + rc, d->domain_id, start, end -1 , ot, nt); +domain_crash (d); + }switch ( nt ) {
xen/arch/x86/mm/p2m-ept.c +112 -0
130 lines not on this page · raw message
xen/include/asm-x86/p2m.h +4 -0
@@ -243,6 +243,10 @@ struct p2m_domain {void (*change_entry_type_global)(struct p2m_domain *p2m,p2m_type_t ot,p2m_type_t nt); +int (*change_entry_type_range)(struct p2m_domain *p2m, +p2m_type_t ot,p2m_type_t nt, +unsigned long first_gfn, +unsigned long last_gfn);void (*memory_type_changed)(struct p2m_domain *p2m); void (*write_p2m_entry)(struct p2m_domain *p2m,
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 3/6 x86/P2M: simplify write_p2m_entry()
In reply to Jan BeulichThe "table_mfn" parameter really isn't needed anywhere, so it gets dropped.
The "struct vcpu *" one was always bogus (as was being made up by paging_write_p2m_entry()), and is not commonly used. It can be easily enough made up in the one place (sh_unshadow_for_p2m_change()) it is needed, and we can otherwise pass "struct domain *" instead, properly reflecting that P2M operations are per-domain.
xen/arch/x86/mm/hap/hap.c +2 -3
@@ -697,10 +697,9 @@ static void hap_update_paging_modes(stru }static void -hap_write_p2m_entry (struct vcpu *v,unsigned long gfn,l1_pgentry_t *p, -mfn_t table_mfn,l1_pgentry_t new,unsigned int level) +hap_write_p2m_entry (struct domain *d,unsigned long gfn,l1_pgentry_t *p, +l1_pgentry_t new,unsigned int level) { -struct domain *d = v->domain;uint32_t old_flags;bool_t flush_nestedp2m =0 ;
xen/arch/x86/mm/hap/nested_hap.c +1 -1
@@ -79,7 +79,7 @@void nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn,l1_pgentry_t new,unsigned int level) +l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) {struct domain *d = p2m->domain;uint32_t old_flags;
xen/arch/x86/mm/p2m-pt.c +21 -25
149 lines not on this page · raw message
xen/arch/x86/mm/paging.c +3 -6
@@ -724,18 +724,15 @@ void paging_update_nestedmode(struct vcp }void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level) +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) {struct domain *d = p2m->domain;struct vcpu *v = current;if ( v->domain != d ) v = d->vcpu ? d->vcpu[0 ] :NULL ;if (likely (v &&paging_mode_enabled (d) &&paging_get_hostmode (v) !=NULL ) ) - { -return paging_get_hostmode (v)->write_p2m_entry (v, gfn, p, table_mfn, - new, level); - } +paging_get_hostmode (v)->write_p2m_entry (d, gfn, p, new, level);else safe_write_pte (p, new); }
xen/arch/x86/mm/shadow/common.c +11 -10
@@ -3310,11 +3310,14 @@ static int shadow_test_disable(struct do* shadow processing jobs. */ -static void sh_unshadow_for_p2m_change (struct vcpu *v,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level) +static void sh_unshadow_for_p2m_change (struct domain *d,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) { -struct domain *d = v->domain; +struct vcpu *v = current; + +if ( v->domain != d ) + v = d->vcpu ? d->vcpu[0 ] :NULL ;/* The following assertion is to make sure we don't step on 1GB host * page support of HVM guest. */
@@ -3379,18 +3382,16 @@ static void sh_unshadow_for_p2m_change(s }void -shadow_write_p2m_entry (struct vcpu *v,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level) +shadow_write_p2m_entry (struct domain *d,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) { -struct domain *d = v->domain; -paging_lock (d);/* If there are any shadows, update them. But if shadow_teardown() * has already been called then it's not safe to try. */ if (likely (d->arch.paging.shadow.total_pages !=0 ) ) -sh_unshadow_for_p2m_change (v, gfn, p, table_mfn, new, level); +sh_unshadow_for_p2m_change (d, gfn, p, new, level);/* Update the entry with new content */ safe_write_pte (p, new);
xen/arch/x86/mm/shadow/private.h +3 -3
@@ -359,9 +359,9 @@ extern int sh_remove_write_access(struct unsigned long fault_addr);/* Functions that atomically write PT/P2M entries and update state */ -void shadow_write_p2m_entry (struct vcpu *v,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level); +void shadow_write_p2m_entry (struct domain *d,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level);int shadow_write_guest_entry (struct vcpu *v,intpte_t *p,intpte_t new,mfn_t gmfn); int shadow_cmpxchg_guest_entry(struct vcpu *v, intpte_t *p,
xen/include/asm-x86/p2m.h +2 -3
@@ -251,8 +251,7 @@ struct p2m_domain {void (*write_p2m_entry)(struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p, -mfn_t table_mfn,l1_pgentry_t new, -unsigned int level); +l1_pgentry_t new,unsigned int level);long (*audit_p2m)(struct p2m_domain *p2m);/* Default P2M access type for each page in the the domain: new pages,
@@ -679,7 +678,7 @@ void p2m_flush(struct vcpu *v, struct p2void p2m_flush_nestedp2m (struct domain *d);void nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn,l1_pgentry_t new,unsigned int level); +l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);#endif /* _XEN_P2M_H */
xen/include/asm-x86/paging.h +5 -6
@@ -111,9 +111,8 @@ struct paging_mode { unsigned int *page_order);void (*update_cr3 )(struct vcpu *v,int do_locking);void (*update_paging_modes )(struct vcpu *v); -void (*write_p2m_entry )(struct vcpu *v,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new, +void (*write_p2m_entry )(struct domain *d,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);int (*write_guest_entry )(struct vcpu *v,intpte_t *p,intpte_t new,mfn_t gmfn);
@@ -335,9 +334,9 @@ static inline void safe_write_pte(l1_pge* we are writing. */ struct p2m_domain ; -void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level); +void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level);/* Called from the guest to indicate that the a process is being * torn down and its pagetables will soon be discarded */
x86/P2M: simplify write_p2m_entry()
The "table_mfn" parameter really isn't needed anywhere, so it gets dropped.
The "struct vcpu *" one was always bogus (as was being made up by paging_write_p2m_entry()), and is not commonly used. It can be easily enough made up in the one place (sh_unshadow_for_p2m_change()) it is needed, and we can otherwise pass "struct domain *" instead, properly reflecting that P2M operations are per-domain.
xen/arch/x86/mm/hap/hap.c +2 -3
@@ -697,10 +697,9 @@ static void hap_update_paging_modes(stru }static void -hap_write_p2m_entry (struct vcpu *v,unsigned long gfn,l1_pgentry_t *p, -mfn_t table_mfn,l1_pgentry_t new,unsigned int level) +hap_write_p2m_entry (struct domain *d,unsigned long gfn,l1_pgentry_t *p, +l1_pgentry_t new,unsigned int level) { -struct domain *d = v->domain;uint32_t old_flags;bool_t flush_nestedp2m =0 ;
xen/arch/x86/mm/hap/nested_hap.c +1 -1
@@ -79,7 +79,7 @@void nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn,l1_pgentry_t new,unsigned int level) +l1_pgentry_t *p,l1_pgentry_t new,unsigned int level) {struct domain *d = p2m->domain;uint32_t old_flags;
xen/arch/x86/mm/p2m-pt.c +21 -25
149 lines not on this page · raw message
xen/arch/x86/mm/paging.c +3 -6
@@ -724,18 +724,15 @@ void paging_update_nestedmode(struct vcp }void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level) +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) {struct domain *d = p2m->domain;struct vcpu *v = current;if ( v->domain != d ) v = d->vcpu ? d->vcpu[0 ] :NULL ;if (likely (v &&paging_mode_enabled (d) &&paging_get_hostmode (v) !=NULL ) ) - { -return paging_get_hostmode (v)->write_p2m_entry (v, gfn, p, table_mfn, - new, level); - } +paging_get_hostmode (v)->write_p2m_entry (d, gfn, p, new, level);else safe_write_pte (p, new); }
xen/arch/x86/mm/shadow/common.c +11 -10
@@ -3310,11 +3310,14 @@ static int shadow_test_disable(struct do* shadow processing jobs. */ -static void sh_unshadow_for_p2m_change (struct vcpu *v,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level) +static void sh_unshadow_for_p2m_change (struct domain *d,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) { -struct domain *d = v->domain; +struct vcpu *v = current; + +if ( v->domain != d ) + v = d->vcpu ? d->vcpu[0 ] :NULL ;/* The following assertion is to make sure we don't step on 1GB host * page support of HVM guest. */
@@ -3379,18 +3382,16 @@ static void sh_unshadow_for_p2m_change(s }void -shadow_write_p2m_entry (struct vcpu *v,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level) +shadow_write_p2m_entry (struct domain *d,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level) { -struct domain *d = v->domain; -paging_lock (d);/* If there are any shadows, update them. But if shadow_teardown() * has already been called then it's not safe to try. */ if (likely (d->arch.paging.shadow.total_pages !=0 ) ) -sh_unshadow_for_p2m_change (v, gfn, p, table_mfn, new, level); +sh_unshadow_for_p2m_change (d, gfn, p, new, level);/* Update the entry with new content */ safe_write_pte (p, new);
xen/arch/x86/mm/shadow/private.h +3 -3
@@ -359,9 +359,9 @@ extern int sh_remove_write_access(struct unsigned long fault_addr);/* Functions that atomically write PT/P2M entries and update state */ -void shadow_write_p2m_entry (struct vcpu *v,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level); +void shadow_write_p2m_entry (struct domain *d,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level);int shadow_write_guest_entry (struct vcpu *v,intpte_t *p,intpte_t new,mfn_t gmfn); int shadow_cmpxchg_guest_entry(struct vcpu *v, intpte_t *p,
xen/include/asm-x86/p2m.h +2 -3
@@ -251,8 +251,7 @@ struct p2m_domain {void (*write_p2m_entry)(struct p2m_domain *p2m,unsigned long gfn,l1_pgentry_t *p, -mfn_t table_mfn,l1_pgentry_t new, -unsigned int level); +l1_pgentry_t new,unsigned int level);long (*audit_p2m)(struct p2m_domain *p2m);/* Default P2M access type for each page in the the domain: new pages,
@@ -679,7 +678,7 @@ void p2m_flush(struct vcpu *v, struct p2void p2m_flush_nestedp2m (struct domain *d);void nestedp2m_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn,l1_pgentry_t new,unsigned int level); +l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);#endif /* _XEN_P2M_H */
xen/include/asm-x86/paging.h +5 -6
@@ -111,9 +111,8 @@ struct paging_mode { unsigned int *page_order);void (*update_cr3 )(struct vcpu *v,int do_locking);void (*update_paging_modes )(struct vcpu *v); -void (*write_p2m_entry )(struct vcpu *v,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new, +void (*write_p2m_entry )(struct domain *d,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new,unsigned int level);int (*write_guest_entry )(struct vcpu *v,intpte_t *p,intpte_t new,mfn_t gmfn);
@@ -335,9 +334,9 @@ static inline void safe_write_pte(l1_pge* we are writing. */ struct p2m_domain ; -void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, -l1_pgentry_t *p,mfn_t table_mfn, -l1_pgentry_t new,unsigned int level); +void paging_write_p2m_entry (struct p2m_domain *p2m,unsigned long gfn, +l1_pgentry_t *p,l1_pgentry_t new, +unsigned int level);/* Called from the guest to indicate that the a process is being * torn down and its pagetables will soon be discarded */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 4/6 x86/NPT: don't walk entire page tables when changing types on a range
In reply to Jan BeulichThis builds on the fact that in order for no NPF VM exit to occur, _PAGE_USER must always be set. I.e. by clearing the flag we can force a VM exit allowing us to do similar lazy type changes as on EPT.
That way, the generic entry-wise code can go away, and we could remove the range restriction in enforced on HVMOP_track_dirty_vram for XSA-27.
xen/arch/x86/hvm/svm/svm.c +10 -1
@@ -2557,7 +2557,16 @@ void svm_vmexit_handler(struct cpu_user_perfc_incra (svmexits,VMEXIT_NPF_PERFC );if ( cpu_has_svm_decode ) v->arch.hvm_svm.cached_insn_len = vmcb->guest_ins_len &0xf ; -svm_do_nested_pgfault (v, regs, vmcb->exitinfo1, vmcb->exitinfo2); + rc =p2m_npt_fault (vmcb->exitinfo2); +if ( rc >=0 ) +svm_do_nested_pgfault (v, regs, vmcb->exitinfo1, vmcb->exitinfo2); +else + { +printk (XENLOG_G_ERR +"%pv: Error %d handling NPF (gpa=%08lx ec=%04lx)\n" , + v, rc, vmcb->exitinfo2, vmcb->exitinfo1); +domain_crash (v->domain); + } v->arch.hvm_svm.cached_insn_len =0 ;break ;
xen/arch/x86/mm/p2m.c +1 -43
58 lines not on this page · raw message
xen/arch/x86/mm/p2m-pt.c +271 -13
389 lines not on this page · raw message
xen/include/asm-x86/p2m.h +2 -0
@@ -668,6 +668,8 @@ static inline p2m_type_t p2m_flags_to_tyreturn (flags >>12 ) &0x7f ; } +int p2m_npt_fault (uint64_t gpa); +/* * Nested p2m: shadow p2m tables used for nested HVM virtualization */
x86/NPT: don't walk entire page tables when changing types on a range
This builds on the fact that in order for no NPF VM exit to occur, _PAGE_USER must always be set. I.e. by clearing the flag we can force a VM exit allowing us to do similar lazy type changes as on EPT.
That way, the generic entry-wise code can go away, and we could remove the range restriction in enforced on HVMOP_track_dirty_vram for XSA-27.
xen/arch/x86/hvm/svm/svm.c +10 -1
@@ -2557,7 +2557,16 @@ void svm_vmexit_handler(struct cpu_user_perfc_incra (svmexits,VMEXIT_NPF_PERFC );if ( cpu_has_svm_decode ) v->arch.hvm_svm.cached_insn_len = vmcb->guest_ins_len &0xf ; -svm_do_nested_pgfault (v, regs, vmcb->exitinfo1, vmcb->exitinfo2); + rc =p2m_npt_fault (vmcb->exitinfo2); +if ( rc >=0 ) +svm_do_nested_pgfault (v, regs, vmcb->exitinfo1, vmcb->exitinfo2); +else + { +printk (XENLOG_G_ERR +"%pv: Error %d handling NPF (gpa=%08lx ec=%04lx)\n" , + v, rc, vmcb->exitinfo2, vmcb->exitinfo1); +domain_crash (v->domain); + } v->arch.hvm_svm.cached_insn_len =0 ;break ;
xen/arch/x86/mm/p2m.c +1 -43
58 lines not on this page · raw message
xen/arch/x86/mm/p2m-pt.c +271 -13
389 lines not on this page · raw message
xen/include/asm-x86/p2m.h +2 -0
@@ -668,6 +668,8 @@ static inline p2m_type_t p2m_flags_to_tyreturn (flags >>12 ) &0x7f ; } +int p2m_npt_fault (uint64_t gpa); +/* * Nested p2m: shadow p2m tables used for nested HVM virtualization */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 4/6] x86/NPT: don't walk entire page tables when changing types on a range
Quoted 8 lines · Jan Beulich
This builds on the fact that in order for no NPF VM exit to occur,
_PAGE_USERmust always be set. I.e. by clearing the flag we can force a VM exit allowing us to do similar lazy type changes as on EPT.That way, the generic entry-wise code can go away, and we could remove the range restriction in enforced on
HVMOP_track_dirty_vramfor XSA-27.Signed-off-by Jan Beulich <[email protected]>
I am not particularly familiar with p2m code which is why my only comment so far is to add comments in the code ;-) --- there is a bunch of new non-trivial (to my eye) routines and so having a little bit of text would greatly help with understanding the logic.
-boris
PATCH 5/6 x86/NPT: don't walk entire page tables when globally changing types
In reply to Jan BeulichInstead leverage the NPF VM exit enforcement by marking just the top level entries as needing recalculation of their type, building on the respective range type change modifications.
xen/arch/x86/mm/p2m.c +4 -0
@@ -214,6 +214,10 @@ void p2m_change_entry_type_global(struct p2m_type_t ot, p2m_type_t nt) {struct p2m_domain *p2m =p2m_get_hostp2m (d); + +ASSERT (ot != nt); +ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt)); +p2m_lock (p2m); p2m->change_entry_type_global (p2m, ot, nt); p2m->global_logdirty = (nt == p2m_ram_logdirty);
xen/arch/x86/mm/p2m-ept.c +1 -3
@@ -861,11 +861,9 @@ static void ept_change_entry_type_global {unsigned long mfn =ept_get_asr (&p2m->ept); -if ( !mfn || ot == nt ) +if ( !mfn )return ; -BUG_ON (!p2m_is_changeable (ot) || !p2m_is_changeable (nt)); -if (ept_invalidate_emt (_mfn (mfn),1 ) )ept_sync_domain (p2m); }
xen/arch/x86/mm/p2m-pt.c +16 -98
134 lines not on this page · raw message
x86/NPT: don't walk entire page tables when globally changing types
Instead leverage the NPF VM exit enforcement by marking just the top level entries as needing recalculation of their type, building on the respective range type change modifications.
xen/arch/x86/mm/p2m.c +4 -0
@@ -214,6 +214,10 @@ void p2m_change_entry_type_global(struct p2m_type_t ot, p2m_type_t nt) {struct p2m_domain *p2m =p2m_get_hostp2m (d); + +ASSERT (ot != nt); +ASSERT (p2m_is_changeable (ot) &&p2m_is_changeable (nt)); +p2m_lock (p2m); p2m->change_entry_type_global (p2m, ot, nt); p2m->global_logdirty = (nt == p2m_ram_logdirty);
xen/arch/x86/mm/p2m-ept.c +1 -3
@@ -861,11 +861,9 @@ static void ept_change_entry_type_global {unsigned long mfn =ept_get_asr (&p2m->ept); -if ( !mfn || ot == nt ) +if ( !mfn )return ; -BUG_ON (!p2m_is_changeable (ot) || !p2m_is_changeable (nt)); -if (ept_invalidate_emt (_mfn (mfn),1 ) )ept_sync_domain (p2m); }
xen/arch/x86/mm/p2m-pt.c +16 -98
134 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 6/6 x86/P2M: cleanup
In reply to Jan Beulich- don't abuse __PAGE_HYPERVISOR
- don't use bogus constructs like mfn_x(_mfn())
xen/arch/x86/mm/p2m-pt.c +7 -7
@@ -193,7 +193,7 @@ p2m_next_level(struct p2m_domain *p2m, vreturn -ENOMEM ; new_entry =l1e_from_pfn (mfn_x (page_to_mfn (pg)), - __PAGE_HYPERVISOR | _PAGE_USER); +P2M_BASE_FLAGS | _PAGE_RW);switch ( type ) {case PGT_l3_page_table:
@@ -229,7 +229,7 @@ p2m_next_level(struct p2m_domain *p2m, v flags =l1e_get_flags (*p2m_entry); pfn =l1e_get_pfn (*p2m_entry); - l1_entry =map_domain_page (mfn_x (page_to_mfn (pg))); + l1_entry =__map_domain_page (pg);for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) { new_entry =l1e_from_pfn (pfn + (i *L1_PAGETABLE_ENTRIES ), flags);
@@ -238,7 +238,7 @@ p2m_next_level(struct p2m_domain *p2m, v }unmap_domain_page (l1_entry); new_entry =l1e_from_pfn (mfn_x (page_to_mfn (pg)), - __PAGE_HYPERVISOR|_PAGE_USER);//disable PSE +P2M_BASE_FLAGS | _PAGE_RW);/* disable PSE */ p2m_add_iommu_flags (&new_entry,2 , IOMMUF_readable|IOMMUF_writable); p2m->write_p2m_entry (p2m, gfn, p2m_entry, new_entry,3 ); }
@@ -273,7 +273,7 @@ p2m_next_level(struct p2m_domain *p2m, vunmap_domain_page (l1_entry); new_entry =l1e_from_pfn (mfn_x (page_to_mfn (pg)), - __PAGE_HYPERVISOR|_PAGE_USER); +P2M_BASE_FLAGS | _PAGE_RW);p2m_add_iommu_flags (&new_entry,1 , IOMMUF_readable|IOMMUF_writable); p2m->write_p2m_entry (p2m, gfn, p2m_entry, new_entry,2 ); }
@@ -918,7 +918,7 @@ long p2m_pt_audit_p2m(struct p2m_domain gfn +=1 << (L4_PAGETABLE_SHIFT -PAGE_SHIFT );continue ; } - l3e =map_domain_page (mfn_x (_mfn (l4e_get_pfn (l4e[i4])))); + l3e =map_domain_page (l4e_get_pfn (l4e[i4]));for ( i3 =0 ; i3 <L3_PAGETABLE_ENTRIES ; i3++ )
@@ -953,7 +953,7 @@ long p2m_pt_audit_p2m(struct p2m_domain } } - l2e =map_domain_page (mfn_x (_mfn (l3e_get_pfn (l3e[i3])))); + l2e =map_domain_page (l3e_get_pfn (l3e[i3]));for ( i2 =0 ; i2 <L2_PAGETABLE_ENTRIES ; i2++ ) {if ( !(l2e_get_flags (l2e[i2]) & _PAGE_PRESENT) )
@@ -989,7 +989,7 @@ long p2m_pt_audit_p2m(struct p2m_domaincontinue ; } - l1e =map_domain_page (mfn_x (_mfn (l2e_get_pfn (l2e[i2])))); + l1e =map_domain_page (l2e_get_pfn (l2e[i2]));for ( i1 =0 ; i1 <L1_PAGETABLE_ENTRIES ; i1++, gfn++ ) {
x86/P2M: cleanup
- don't abuse __PAGE_HYPERVISOR
- don't use bogus constructs like mfn_x(_mfn())
xen/arch/x86/mm/p2m-pt.c +7 -7
@@ -193,7 +193,7 @@ p2m_next_level(struct p2m_domain *p2m, vreturn -ENOMEM ; new_entry =l1e_from_pfn (mfn_x (page_to_mfn (pg)), - __PAGE_HYPERVISOR | _PAGE_USER); +P2M_BASE_FLAGS | _PAGE_RW);switch ( type ) {case PGT_l3_page_table:
@@ -229,7 +229,7 @@ p2m_next_level(struct p2m_domain *p2m, v flags =l1e_get_flags (*p2m_entry); pfn =l1e_get_pfn (*p2m_entry); - l1_entry =map_domain_page (mfn_x (page_to_mfn (pg))); + l1_entry =__map_domain_page (pg);for ( i =0 ; i <L2_PAGETABLE_ENTRIES ; i++ ) { new_entry =l1e_from_pfn (pfn + (i *L1_PAGETABLE_ENTRIES ), flags);
@@ -238,7 +238,7 @@ p2m_next_level(struct p2m_domain *p2m, v }unmap_domain_page (l1_entry); new_entry =l1e_from_pfn (mfn_x (page_to_mfn (pg)), - __PAGE_HYPERVISOR|_PAGE_USER);//disable PSE +P2M_BASE_FLAGS | _PAGE_RW);/* disable PSE */ p2m_add_iommu_flags (&new_entry,2 , IOMMUF_readable|IOMMUF_writable); p2m->write_p2m_entry (p2m, gfn, p2m_entry, new_entry,3 ); }
@@ -273,7 +273,7 @@ p2m_next_level(struct p2m_domain *p2m, vunmap_domain_page (l1_entry); new_entry =l1e_from_pfn (mfn_x (page_to_mfn (pg)), - __PAGE_HYPERVISOR|_PAGE_USER); +P2M_BASE_FLAGS | _PAGE_RW);p2m_add_iommu_flags (&new_entry,1 , IOMMUF_readable|IOMMUF_writable); p2m->write_p2m_entry (p2m, gfn, p2m_entry, new_entry,2 ); }
@@ -918,7 +918,7 @@ long p2m_pt_audit_p2m(struct p2m_domain gfn +=1 << (L4_PAGETABLE_SHIFT -PAGE_SHIFT );continue ; } - l3e =map_domain_page (mfn_x (_mfn (l4e_get_pfn (l4e[i4])))); + l3e =map_domain_page (l4e_get_pfn (l4e[i4]));for ( i3 =0 ; i3 <L3_PAGETABLE_ENTRIES ; i3++ )
@@ -953,7 +953,7 @@ long p2m_pt_audit_p2m(struct p2m_domain } } - l2e =map_domain_page (mfn_x (_mfn (l3e_get_pfn (l3e[i3])))); + l2e =map_domain_page (l3e_get_pfn (l3e[i3]));for ( i2 =0 ; i2 <L2_PAGETABLE_ENTRIES ; i2++ ) {if ( !(l2e_get_flags (l2e[i2]) & _PAGE_PRESENT) )
@@ -989,7 +989,7 @@ long p2m_pt_audit_p2m(struct p2m_domaincontinue ; } - l1e =map_domain_page (mfn_x (_mfn (l2e_get_pfn (l2e[i2])))); + l1e =map_domain_page (l2e_get_pfn (l2e[i2]));for ( i1 =0 ; i1 <L1_PAGETABLE_ENTRIES ; i1++, gfn++ ) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel