Provide support for multiple frame buffers in Xen
PATCH 1/1 Provide support for multiple frame buffers in Xen
Support is provided for both shadow and hardware assisted paging (HAP) modes. This code bookkeeps the set of video frame buffers (vram), detects when the guest has modified any of those buffers and, upon request, returns a bitmap of the modified pages.
This lets other software components re-paint the portions of the monitor (or monitors) that have changed.
Each monitor has a frame buffer of some size at some position in guest physical memory.
The set of frame buffers being tracked can change over time as monitors are plugged and unplugged.
--- tools/libxc/xenctrl.h | 20 +- xen/arch/x86/hvm/hvm.c | 9 +- xen/arch/x86/mm/Makefile | 1 + xen/arch/x86/mm/dirty_vram.c | 864 ++++++++++++++++++++++++++++++++++++++ xen/arch/x86/mm/hap/hap.c | 111 ----- xen/arch/x86/mm/p2m.c | 11 +- xen/arch/x86/mm/paging.c | 57 ++- xen/arch/x86/mm/shadow/common.c | 335 ++++++++------- xen/arch/x86/mm/shadow/multi.c | 174 ++++---- xen/arch/x86/mm/shadow/multi.h | 7 +- xen/arch/x86/mm/shadow/types.h | 1 + xen/include/asm-x86/dirty_vram.h | 202 +++++++++ xen/include/asm-x86/hap.h | 4 - xen/include/asm-x86/hvm/domain.h | 2 +- xen/include/asm-x86/paging.h | 15 +- xen/include/asm-x86/shadow.h | 6 - 16 files changed, 1422 insertions(+), 397 deletions(-) create mode 100644 xen/arch/x86/mm/dirty_vram.c create mode 100644 xen/include/asm-x86/dirty_vram.h
tools/libxc/xenctrl.h +14 -6
@@ -1563,15 +1563,23 @@ int xc_hvm_inject_msi( xc_interface *xch, domid_t dom, uint64_t addr, uint32_t data);/* -* Track dirty bit changes in the VRAM area +* Track dirty bit changes in a VRAM region defined by +* [ first_pfn : first_pfn + nr - 1 ] * * All of this is done atomically: -* - get the dirty bitmap since the last call -* - set up dirty tracking area for period up to the next call -* - clear the dirty tracking area. +* - gets the dirty bitmap since the last call, all zeroes for +* the first call with some new region +* - sets up a dirty tracking region for period up to the next call +* - clears the specified dirty tracking region. * -* Returns -ENODATA and does not fill bitmap if the area has changed since the -* last call. +* Creating a new region causes any existing regions that it overlaps +* to be discarded. +* +* Specifying nr == 0 causes all regions to be discarded and +* disables dirty bit tracking. +* +* If nr is not a multiple of 64, only the first nr bits of bitmap +* are well defined. */ int xc_hvm_track_dirty_vram( xc_interface *xch, domid_t dom,
xen/arch/x86/hvm/hvm.c +7 -2
@@ -57,6 +57,7 @@#include <asm/hvm/cacheattr.h> #include <asm/hvm/trace.h> #include <asm/hvm/nestedhvm.h> +#include <asm/dirty_vram.h> #include <asm/mtrr.h> #include <asm/apic.h> #include <public/sched.h>
@@ -66,6 +67,7 @@#include <asm/mem_event.h> #include <asm/mem_access.h> #include <public/mem_event.h> +#include "../mm/mm-locks.h" bool_t __read_mostly hvm_enabled;
@@ -1433,8 +1435,11 @@ int hvm_hap_nested_page_fault(paddr_t gpa,*/ if ( access_w ) { -paging_mark_dirty (v->domain,mfn_x (mfn)); -p2m_change_type (v->domain, gfn, p2m_ram_logdirty, p2m_ram_rw); +if (p2m_change_type (v->domain, gfn, p2m_ram_logdirty, + p2m_ram_rw) == p2m_ram_logdirty ) + { +paging_mark_dirty_gpfn (v->domain, gfn); + } } rc =1 ; goto out_put_gfn;
xen/arch/x86/mm/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-y += paging.o obj-y += p2m.o p2m-pt.o p2m-ept.o p2m-pod.o obj-y += guest_walk_2.o obj-y += guest_walk_3.o +obj-y += dirty_vram.o obj-$(x86_64) += guest_walk_4.o obj-$(x86_64) += mem_event.o obj-$(x86_64) += mem_paging.o
xen/arch/x86/mm/dirty_vram.c new file +864 -0
864 lines not on this page · raw message
xen/arch/x86/mm/hap/hap.c +0 -111
117 lines not on this page · raw message
xen/arch/x86/mm/p2m.c +7 -4
@@ -690,20 +690,23 @@ void p2m_change_type_range(struct domain *d,struct p2m_domain *p2m =p2m_get_hostp2m (d);BUG_ON (p2m_is_grant (ot) ||p2m_is_grant (nt)); -p2m_lock (p2m); - p2m->defer_nested_flush =1 ; + p2m->defer_nested_flush =1 ; +for ( gfn = start; gfn < end; gfn++ ) { mfn = p2m->get_entry (p2m, gfn, &pt, &a,0 ,NULL );if ( pt == ot ) -set_p2m_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, p2m->default_access); +set_p2m_entry (p2m, gfn, mfn,PAGE_ORDER_4K , nt, + p2m->default_access); } - + p2m->defer_nested_flush =0 ; +if (nestedhvm_enabled (d) )p2m_flush_nestedp2m (d); +p2m_unlock (p2m); }
xen/arch/x86/mm/paging.c +49 -8
104 lines not on this page · raw message
xen/arch/x86/mm/shadow/common.c +185 -150
381 lines not on this page · raw message
xen/arch/x86/mm/shadow/multi.c +80 -94
255 lines not on this page · raw message
xen/arch/x86/mm/shadow/multi.h +6 -1
@@ -66,7 +66,12 @@ SHADOW_INTERNAL_NAME(sh_rm_write_access_from_l1, GUEST_LEVELS)extern int SHADOW_INTERNAL_NAME (sh_rm_mappings_from_l1 ,GUEST_LEVELS ) (struct vcpu *v,mfn_t sl1mfn,mfn_t target_mfn); - +extern int +SHADOW_INTERNAL_NAME (sh_find_vram_mappings_in_l1 ,GUEST_LEVELS ) + (struct vcpu *v,mfn_t sl1mfn, +unsigned long begin_pfn, +unsigned long end_pfn, +int *removed);extern void SHADOW_INTERNAL_NAME (sh_clear_shadow_entry ,GUEST_LEVELS ) (struct vcpu *v,void *ep,mfn_t smfn);
xen/arch/x86/mm/shadow/types.h +1 -0
@@ -229,6 +229,7 @@ static inline shadow_l4e_t shadow_l4e_from_mfn(mfn_t mfn, u32 flags)#define sh_update_cr3 INTERNAL_NAME(sh_update_cr3)#define sh_rm_write_access_from_l1 INTERNAL_NAME(sh_rm_write_access_from_l1)#define sh_rm_mappings_from_l1 INTERNAL_NAME(sh_rm_mappings_from_l1) +#define sh_find_vram_mappings_in_l1 INTERNAL_NAME(sh_find_vram_mappings_in_l1)#define sh_remove_l1_shadow INTERNAL_NAME(sh_remove_l1_shadow)#define sh_remove_l2_shadow INTERNAL_NAME(sh_remove_l2_shadow)#define sh_remove_l3_shadow INTERNAL_NAME(sh_remove_l3_shadow)
xen/include/asm-x86/dirty_vram.h new file +202 -0
202 lines not on this page · raw message
xen/include/asm-x86/hap.h +0 -4
@@ -57,10 +57,6 @@ void hap_final_teardown(struct domain *d);void hap_teardown (struct domain *d);void hap_vcpu_init (struct vcpu *v);void hap_logdirty_init (struct domain *d); -int hap_track_dirty_vram (struct domain *d, -unsigned long begin_pfn, -unsigned long nr, -XEN_GUEST_HANDLE_64 (uint8) dirty_bitmap);extern const struct paging_mode *hap_paging_get_mode (struct vcpu *);
xen/include/asm-x86/hvm/domain.h +1 -1
@@ -74,7 +74,7 @@ struct hvm_domain {struct list_head pinned_cacheattr_ranges;/* VRAM dirty support. */ -struct sh_dirty_vram *dirty_vram; +struct dv_dirty_vram *dirty_vram;/* If one of vcpus of this domain is in no_fill_mode or * mtrr/pat between vcpus is not the same, set is_in_uc_mode
xen/include/asm-x86/paging.h +5 -10
@@ -154,9 +154,13 @@ void paging_log_dirty_init(struct domain *d,int (*disable_log_dirty)(struct domain *d), void (*clean_dirty_bitmap)(struct domain *d)); -/* mark a page as dirty */ +/* mark a gmfn as dirty, a wrapper around marking a gpfn as dirty */ void paging_mark_dirty (struct domain *d,unsigned long guest_mfn); +/* mark a gpfn as dirty */ +void paging_mark_dirty_gpfn (struct domain *d,unsigned long gpfn); + +/* is this guest page dirty? * This is called from inside paging code, with the paging lock held. */ int paging_mfn_is_dirty (struct domain *d,mfn_t gmfn);
@@ -183,15 +187,6 @@ int paging_mfn_is_dirty(struct domain *d, mfn_t gmfn);#define L4_LOGDIRTY_IDX (pfn) 0#endif -/* VRAM dirty tracking support */ -struct sh_dirty_vram { -unsigned long begin_pfn; -unsigned long end_pfn; -paddr_t *sl1ma; -uint8_t *dirty_bitmap; -s_time_t last_dirty; -}; -/***************************************************************************** * Entry points into the paging-assistance code */
xen/include/asm-x86/shadow.h +0 -6
@@ -62,12 +62,6 @@ void shadow_vcpu_init(struct vcpu *v);/* Enable an arbitrary shadow mode. Call once at domain creation. */ int shadow_enable (struct domain *d,u32 mode); -/* Enable VRAM dirty bit tracking. */ -int shadow_track_dirty_vram (struct domain *d, -unsigned long first_pfn, -unsigned long nr, -XEN_GUEST_HANDLE_64 (uint8) dirty_bitmap); -/* Handler for shadow control ops: operations from user-space to enable * and disable ephemeral shadow modes (test mode and log-dirty mode) and * manipulate the log-dirty bitmap. */
Signature · 1 line
1.7.9.5
Tim Deegan
AppliedQuoted 11 lines · Robert Phillips
Support is provided for both shadow and hardware assisted paging (HAP) modes. This code bookkeeps the set of video frame buffers (vram), detects when the guest has modified any of those buffers and, upon request, returns a bitmap of the modified pages.
This lets other software components re-paint the portions of the monitor (or monitors) that have changed.
Each monitor has a frame buffer of some size at some position in guest physical memory.
The set of frame buffers being tracked can change over time as monitors are plugged and unplugged.
Quoted 1 line
Signed-off-by Robert Phillips <[email protected]>
Applied, thanks.
Tim.