From: "Jan Beulich" Subject: [PATCH 2/4] x86/mm: allow for building without shadow mode support Date: Wed, 28 Jan 2015 08:11:07 +0000 Message-ID: <54C8A7AB020000780005A2D2@mail.emea.novell.com> References: <54C8A524020000780005A27E@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartE6D3778B.1__=" Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YGNiR-0003Gy-B3 for xen-devel@lists.xenproject.org; Wed, 28 Jan 2015 08:11:11 +0000 In-Reply-To: <54C8A524020000780005A27E@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Andrew Cooper , Keir Fraser , Tim Deegan List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartE6D3778B.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Considering the complexity of the code, it seems to be a reasonable thing to allow people to disable that code entirely even outside the immediate need for this by the next patch. Signed-off-by: Jan Beulich --- There is one XXX being added to the code - while it doesn't look like we need to set v->arch.paging.mode in shadow_vcpu_init(), it may be deemed more secure to set up a table with stub function pointers. --- a/xen/arch/x86/Rules.mk +++ b/xen/arch/x86/Rules.mk @@ -32,9 +32,13 @@ x86 :=3D y x86_32 :=3D n x86_64 :=3D y =20 +shadow-paging ?=3D y + CFLAGS +=3D -mno-red-zone -mno-sse -fpic CFLAGS +=3D -fno-asynchronous-unwind-tables # -fvisibility=3Dhidden reduces -fpic cost, if it's available ifneq ($(call cc-option,$(CC),-fvisibility=3Dhidden,n),n) CFLAGS +=3D -DGCC_HAS_VISIBILITY_ATTRIBUTE endif + +CFLAGS-$(shadow-paging) +=3D -DCONFIG_SHADOW_PAGING --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -635,16 +635,16 @@ int paging_domain_init(struct domain *d, * don't want to leak any active log-dirty bitmaps */ d->arch.paging.log_dirty.top =3D _mfn(INVALID_MFN); =20 - /* The order of the *_init calls below is important, as the later - * ones may rewrite some common fields. Shadow pagetables are the - * default... */ - shadow_domain_init(d, domcr_flags); - - /* ... but we will use hardware assistance if it's available. */ + /* + * Shadow pagetables are the default, but we will use + * hardware assistance if it's available and enabled. + */ if ( hap_enabled(d) ) hap_domain_init(d); + else + rc =3D shadow_domain_init(d, domcr_flags); =20 - return 0; + return rc; } =20 /* vcpu paging struct initialization goes here */ @@ -822,12 +822,16 @@ int paging_enable(struct domain *d, u32=20 * and therefore its pagetables will soon be discarded */ void pagetable_dying(struct domain *d, paddr_t gpa) { +#ifdef CONFIG_SHADOW_PAGING struct vcpu *v; =20 ASSERT(paging_mode_shadow(d)); =20 v =3D d->vcpu[0]; v->arch.paging.mode->shadow.pagetable_dying(v, gpa); +#else + BUG(); +#endif } =20 /* Print paging-assistance info to the console */ --- a/xen/arch/x86/mm/shadow/Makefile +++ b/xen/arch/x86/mm/shadow/Makefile @@ -1,4 +1,5 @@ -obj-$(x86_64) +=3D common.o guest_2.o guest_3.o guest_4.o +obj-y :=3D none.o +obj-$(shadow-paging) :=3D common.o guest_2.o guest_3.o guest_4.o =20 guest_%.o: multi.c Makefile $(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=3D$* -c $< -o $@ --- a/xen/arch/x86/mm/shadow/common.c +++ b/xen/arch/x86/mm/shadow/common.c @@ -43,7 +43,7 @@ DEFINE_PER_CPU(uint32_t,trace_shadow_pat =20 /* Set up the shadow-specific parts of a domain struct at start of day. * Called for every domain from arch_domain_create() */ -void shadow_domain_init(struct domain *d, unsigned int domcr_flags) +int shadow_domain_init(struct domain *d, unsigned int domcr_flags) { INIT_PAGE_LIST_HEAD(&d->arch.paging.shadow.freelist); INIT_PAGE_LIST_HEAD(&d->arch.paging.shadow.pinned_shadows); @@ -57,6 +57,8 @@ void shadow_domain_init(struct domain *d d->arch.paging.shadow.oos_off =3D (domcr_flags & DOMCRF_oos_off) ? 1 = : 0; #endif d->arch.paging.shadow.pagetable_dying_op =3D 0; + + return 0; } =20 /* Setup the shadow-specfic parts of a vcpu struct. Note: The most = important --- /dev/null +++ b/xen/arch/x86/mm/shadow/none.c 2015-01-26 17:23:04.000000000 = +0100 @@ -0,0 +1,70 @@ +#include +#include + +static int _enable_log_dirty(struct domain *d, bool_t log_global) +{ + BUG_ON(!is_pv_domain(d)); + return -EOPNOTSUPP; +} + +static int _disable_log_dirty(struct domain *d) +{ + BUG_ON(!is_pv_domain(d)); + return -EOPNOTSUPP; +} + +static void _clean_dirty_bitmap(struct domain *d) +{ + BUG_ON(!is_pv_domain(d)); +} + +int shadow_domain_init(struct domain *d, unsigned int domcr_flags) +{ + paging_log_dirty_init(d, _enable_log_dirty, + _disable_log_dirty, _clean_dirty_bitmap); + return is_pv_domain(d) ? 0 : -EOPNOTSUPP; +} + +void shadow_vcpu_init(struct vcpu *v) +{ + BUG_ON(!is_pv_domain(v->domain)); + /* XXX v->arch.paging.mode =3D ???; */ +} + +void shadow_teardown(struct domain *d) +{ + BUG_ON(!is_pv_domain(d)); +} + +void shadow_final_teardown(struct domain *d) +{ + BUG_ON(!is_pv_domain(d)); +} + +int shadow_enable(struct domain *d, u32 mode) +{ + BUG_ON(!is_pv_domain(d)); + return -EOPNOTSUPP; +} + +void sh_remove_shadows(struct vcpu *v, mfn_t gmfn, int fast, int all) +{ +} + +void shadow_blow_tables_per_domain(struct domain *d) +{ +} + +int shadow_track_dirty_vram(struct domain *d, + unsigned long begin_pfn, unsigned long nr, + XEN_GUEST_HANDLE_64(uint8) dirty_bitmap) +{ + BUG(); + return -EOPNOTSUPP; +} + +int shadow_domctl(struct domain *d, xen_domctl_shadow_op_t *sc, + XEN_GUEST_HANDLE_PARAM(void) u_domctl) +{ + return -EINVAL; +} --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -88,6 +88,7 @@ void hypercall_page_initialise(struct do /* shadow paging extension */ /************************************************/ struct shadow_domain { +#ifdef CONFIG_SHADOW_PAGING unsigned int opt_flags; /* runtime tunable optimizations = on/off */ struct page_list_head pinned_shadows; =20 @@ -117,9 +118,11 @@ struct shadow_domain { =20 /* Has this domain ever used HVMOP_pagetable_dying? */ bool_t pagetable_dying_op; +#endif }; =20 struct shadow_vcpu { +#ifdef CONFIG_SHADOW_PAGING /* PAE guests: per-vcpu shadow top-level table */ l3_pgentry_t l3table[4] __attribute__((__aligned__(32))); /* PAE guests: per-vcpu cache of the top-level *guest* entries */ @@ -145,6 +148,7 @@ struct shadow_vcpu { } oos_fixup[SHADOW_OOS_PAGES]; =20 bool_t pagetable_dying; +#endif }; =20 /************************************************/ --- a/xen/include/asm-x86/paging.h +++ b/xen/include/asm-x86/paging.h @@ -55,7 +55,11 @@ #define PG_external (XEN_DOMCTL_SHADOW_ENABLE_EXTERNAL << PG_mode_shift= ) =20 #define paging_mode_enabled(_d) ((_d)->arch.paging.mode) +#ifdef CONFIG_SHADOW_PAGING #define paging_mode_shadow(_d) ((_d)->arch.paging.mode & PG_SH_enable) +#else +#define paging_mode_shadow(_d) ((void)(_d), 0) +#endif #define paging_mode_hap(_d) ((_d)->arch.paging.mode & PG_HAP_enable)= =20 #define paging_mode_refcounts(_d) ((_d)->arch.paging.mode & PG_refcounts) @@ -74,6 +78,7 @@ =20 struct sh_emulate_ctxt; struct shadow_paging_mode { +#ifdef CONFIG_SHADOW_PAGING void (*detach_old_tables )(struct vcpu *v); int (*x86_emulate_write )(struct vcpu *v, unsigned long = va, void *src, u32 bytes, @@ -88,6 +93,7 @@ struct shadow_paging_mode { int (*guess_wrmap )(struct vcpu *v,=20 unsigned long vaddr, mfn_t = gmfn); void (*pagetable_dying )(struct vcpu *v, paddr_t gpa); +#endif /* For outsiders to tell what mode we're in */ unsigned int shadow_levels; }; --- a/xen/include/asm-x86/shadow.h +++ b/xen/include/asm-x86/shadow.h @@ -49,7 +49,7 @@ =20 /* Set up the shadow-specific parts of a domain struct at start of day. * Called from paging_domain_init(). */ -void shadow_domain_init(struct domain *d, unsigned int domcr_flags); +int shadow_domain_init(struct domain *d, unsigned int domcr_flags); =20 /* Setup the shadow-specific parts of a vcpu struct. It is called by * paging_vcpu_init() in paging.c */ --- a/xen/include/xen/paging.h +++ b/xen/include/xen/paging.h @@ -7,7 +7,7 @@ #include #include =20 -#elif defined CONFIG_SHADOW +#elif defined CONFIG_SHADOW_PAGING =20 #include =20 --=__PartE6D3778B.1__= Content-Type: text/plain; name="x86-no-shadow.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-no-shadow.patch" x86/mm: allow for building without shadow mode support=0A=0AConsidering = the complexity of the code, it seems to be a reasonable=0Athing to allow = people to disable that code entirely even outside the=0Aimmediate need for = this by the next patch.=0A=0ASigned-off-by: Jan Beulich = =0A---=0AThere is one XXX being added to the code - while it doesn't look = like=0Awe need to set v->arch.paging.mode in shadow_vcpu_init(), it may = be=0Adeemed more secure to set up a table with stub function pointers.=0A= =0A--- a/xen/arch/x86/Rules.mk=0A+++ b/xen/arch/x86/Rules.mk=0A@@ -32,9 = +32,13 @@ x86 :=3D y=0A x86_32 :=3D n=0A x86_64 :=3D y=0A =0A+shadow-paging= ?=3D y=0A+=0A CFLAGS +=3D -mno-red-zone -mno-sse -fpic=0A CFLAGS +=3D = -fno-asynchronous-unwind-tables=0A # -fvisibility=3Dhidden reduces -fpic = cost, if it's available=0A ifneq ($(call cc-option,$(CC),-fvisibility=3Dhid= den,n),n)=0A CFLAGS +=3D -DGCC_HAS_VISIBILITY_ATTRIBUTE=0A endif=0A+=0A+CFL= AGS-$(shadow-paging) +=3D -DCONFIG_SHADOW_PAGING=0A--- a/xen/arch/x86/mm/pa= ging.c=0A+++ b/xen/arch/x86/mm/paging.c=0A@@ -635,16 +635,16 @@ int = paging_domain_init(struct domain *d,=0A * don't want to leak any = active log-dirty bitmaps */=0A d->arch.paging.log_dirty.top =3D = _mfn(INVALID_MFN);=0A =0A- /* The order of the *_init calls below is = important, as the later=0A- * ones may rewrite some common fields. = Shadow pagetables are the=0A- * default... */=0A- shadow_domain_init= (d, domcr_flags);=0A-=0A- /* ... but we will use hardware assistance if = it's available. */=0A+ /*=0A+ * Shadow pagetables are the default, = but we will use=0A+ * hardware assistance if it's available and = enabled.=0A+ */=0A if ( hap_enabled(d) )=0A hap_domain_init= (d);=0A+ else=0A+ rc =3D shadow_domain_init(d, domcr_flags);=0A = =0A- return 0;=0A+ return rc;=0A }=0A =0A /* vcpu paging struct = initialization goes here */=0A@@ -822,12 +822,16 @@ int paging_enable(struc= t domain *d, u32 =0A * and therefore its pagetables will soon be = discarded */=0A void pagetable_dying(struct domain *d, paddr_t gpa)=0A = {=0A+#ifdef CONFIG_SHADOW_PAGING=0A struct vcpu *v;=0A =0A = ASSERT(paging_mode_shadow(d));=0A =0A v =3D d->vcpu[0];=0A = v->arch.paging.mode->shadow.pagetable_dying(v, gpa);=0A+#else=0A+ = BUG();=0A+#endif=0A }=0A =0A /* Print paging-assistance info to the = console */=0A--- a/xen/arch/x86/mm/shadow/Makefile=0A+++ b/xen/arch/x86/mm/= shadow/Makefile=0A@@ -1,4 +1,5 @@=0A-obj-$(x86_64) +=3D common.o guest_2.o = guest_3.o guest_4.o=0A+obj-y :=3D none.o=0A+obj-$(shadow-pag= ing) :=3D common.o guest_2.o guest_3.o guest_4.o=0A =0A guest_%.o: multi.c = Makefile=0A $(CC) $(CFLAGS) -DGUEST_PAGING_LEVELS=3D$* -c $< -o = $@=0A--- a/xen/arch/x86/mm/shadow/common.c=0A+++ b/xen/arch/x86/mm/shadow/c= ommon.c=0A@@ -43,7 +43,7 @@ DEFINE_PER_CPU(uint32_t,trace_shadow_pat=0A = =0A /* Set up the shadow-specific parts of a domain struct at start of = day.=0A * Called for every domain from arch_domain_create() */=0A-void = shadow_domain_init(struct domain *d, unsigned int domcr_flags)=0A+int = shadow_domain_init(struct domain *d, unsigned int domcr_flags)=0A {=0A = INIT_PAGE_LIST_HEAD(&d->arch.paging.shadow.freelist);=0A INIT_PAGE_LIST= _HEAD(&d->arch.paging.shadow.pinned_shadows);=0A@@ -57,6 +57,8 @@ void = shadow_domain_init(struct domain *d=0A d->arch.paging.shadow.oos_off = =3D (domcr_flags & DOMCRF_oos_off) ? 1 : 0;=0A #endif=0A d->arch.pagin= g.shadow.pagetable_dying_op =3D 0;=0A+=0A+ return 0;=0A }=0A =0A /* = Setup the shadow-specfic parts of a vcpu struct. Note: The most = important=0A--- /dev/null=0A+++ b/xen/arch/x86/mm/shadow/none.c 2015-01-26 = 17:23:04.000000000 +0100=0A@@ -0,0 +1,70 @@=0A+#include =0A+#incl= ude =0A+=0A+static int _enable_log_dirty(struct domain *d, = bool_t log_global)=0A+{=0A+ BUG_ON(!is_pv_domain(d));=0A+ return = -EOPNOTSUPP;=0A+}=0A+=0A+static int _disable_log_dirty(struct domain = *d)=0A+{=0A+ BUG_ON(!is_pv_domain(d));=0A+ return -EOPNOTSUPP;=0A+}= =0A+=0A+static void _clean_dirty_bitmap(struct domain *d)=0A+{=0A+ = BUG_ON(!is_pv_domain(d));=0A+}=0A+=0A+int shadow_domain_init(struct domain = *d, unsigned int domcr_flags)=0A+{=0A+ paging_log_dirty_init(d, = _enable_log_dirty,=0A+ _disable_log_dirty, = _clean_dirty_bitmap);=0A+ return is_pv_domain(d) ? 0 : -EOPNOTSUPP;=0A+}= =0A+=0A+void shadow_vcpu_init(struct vcpu *v)=0A+{=0A+ BUG_ON(!is_pv_dom= ain(v->domain));=0A+ /* XXX v->arch.paging.mode =3D ???; */=0A+}=0A+=0A+= void shadow_teardown(struct domain *d)=0A+{=0A+ BUG_ON(!is_pv_domain(d))= ;=0A+}=0A+=0A+void shadow_final_teardown(struct domain *d)=0A+{=0A+ = BUG_ON(!is_pv_domain(d));=0A+}=0A+=0A+int shadow_enable(struct domain *d, = u32 mode)=0A+{=0A+ BUG_ON(!is_pv_domain(d));=0A+ return -EOPNOTSUPP;= =0A+}=0A+=0A+void sh_remove_shadows(struct vcpu *v, mfn_t gmfn, int fast, = int all)=0A+{=0A+}=0A+=0A+void shadow_blow_tables_per_domain(struct domain = *d)=0A+{=0A+}=0A+=0A+int shadow_track_dirty_vram(struct domain *d,=0A+ = unsigned long begin_pfn, unsigned long nr,=0A+ = XEN_GUEST_HANDLE_64(uint8) dirty_bitmap)=0A+{=0A+ = BUG();=0A+ return -EOPNOTSUPP;=0A+}=0A+=0A+int shadow_domctl(struct = domain *d, xen_domctl_shadow_op_t *sc,=0A+ XEN_GUEST_HANDL= E_PARAM(void) u_domctl)=0A+{=0A+ return -EINVAL;=0A+}=0A--- a/xen/includ= e/asm-x86/domain.h=0A+++ b/xen/include/asm-x86/domain.h=0A@@ -88,6 +88,7 = @@ void hypercall_page_initialise(struct do=0A /* shadow paging = extension */=0A /**********************************************= **/=0A struct shadow_domain {=0A+#ifdef CONFIG_SHADOW_PAGING=0A = unsigned int opt_flags; /* runtime tunable optimizations on/off = */=0A struct page_list_head pinned_shadows;=0A =0A@@ -117,9 +118,11 @@ = struct shadow_domain {=0A =0A /* Has this domain ever used HVMOP_pageta= ble_dying? */=0A bool_t pagetable_dying_op;=0A+#endif=0A };=0A =0A = struct shadow_vcpu {=0A+#ifdef CONFIG_SHADOW_PAGING=0A /* PAE guests: = per-vcpu shadow top-level table */=0A l3_pgentry_t l3table[4] = __attribute__((__aligned__(32)));=0A /* PAE guests: per-vcpu cache of = the top-level *guest* entries */=0A@@ -145,6 +148,7 @@ struct shadow_vcpu = {=0A } oos_fixup[SHADOW_OOS_PAGES];=0A =0A bool_t pagetable_dying;= =0A+#endif=0A };=0A =0A /************************************************/= =0A--- a/xen/include/asm-x86/paging.h=0A+++ b/xen/include/asm-x86/paging.h= =0A@@ -55,7 +55,11 @@=0A #define PG_external (XEN_DOMCTL_SHADOW_ENABLE_E= XTERNAL << PG_mode_shift)=0A =0A #define paging_mode_enabled(_d) = ((_d)->arch.paging.mode)=0A+#ifdef CONFIG_SHADOW_PAGING=0A #define = paging_mode_shadow(_d) ((_d)->arch.paging.mode & PG_SH_enable)=0A+#else= =0A+#define paging_mode_shadow(_d) ((void)(_d), 0)=0A+#endif=0A #define = paging_mode_hap(_d) ((_d)->arch.paging.mode & PG_HAP_enable)=0A =0A = #define paging_mode_refcounts(_d) ((_d)->arch.paging.mode & PG_refcounts)= =0A@@ -74,6 +78,7 @@=0A =0A struct sh_emulate_ctxt;=0A struct shadow_paging= _mode {=0A+#ifdef CONFIG_SHADOW_PAGING=0A void (*detach_old_ta= bles )(struct vcpu *v);=0A int (*x86_emulate_write = )(struct vcpu *v, unsigned long va,=0A = void *src, u32 bytes,=0A@@ -88,6 +93,7 @@ struct shadow_paging_mode= {=0A int (*guess_wrmap )(struct vcpu *v, =0A = unsigned long vaddr, mfn_t = gmfn);=0A void (*pagetable_dying )(struct vcpu *v, = paddr_t gpa);=0A+#endif=0A /* For outsiders to tell what mode we're in = */=0A unsigned int shadow_levels;=0A };=0A--- a/xen/include/asm-x86/sha= dow.h=0A+++ b/xen/include/asm-x86/shadow.h=0A@@ -49,7 +49,7 @@=0A =0A /* = Set up the shadow-specific parts of a domain struct at start of day.=0A * = Called from paging_domain_init(). */=0A-void shadow_domain_init(struct = domain *d, unsigned int domcr_flags);=0A+int shadow_domain_init(struct = domain *d, unsigned int domcr_flags);=0A =0A /* Setup the shadow-specific = parts of a vcpu struct. It is called by=0A * paging_vcpu_init() in = paging.c */=0A--- a/xen/include/xen/paging.h=0A+++ b/xen/include/xen/paging= .h=0A@@ -7,7 +7,7 @@=0A #include =0A #include =0A = =0A-#elif defined CONFIG_SHADOW=0A+#elif defined CONFIG_SHADOW_PAGING=0A = =0A #include =0A =0A --=__PartE6D3778B.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartE6D3778B.1__=--