From: "Jan Beulich" Subject: =?utf-8?q?=5BPATCH_5/6=5D_x86/context=E2=80=91switch?= =?utf-8?b?OiBwcmVmZXIgaXNfLi4uX2RvbWFpbigpIG92ZXIgaXNfLi4uX3ZjcHUoKQ==?= Date: Thu, 11 Jun 2015 11:22:54 +0100 Message-ID: <55797D9E02000078000838C9@mail.emea.novell.com> References: <55797BF702000078000838AF@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part4B7F6A6E.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z2zdR-0003HU-S9 for xen-devel@lists.xenproject.org; Thu, 11 Jun 2015 10:22:58 +0000 In-Reply-To: <55797BF702000078000838AF@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 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. --=__Part4B7F6A6E.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Latch both domains alongside both vCPU-s into local variables, making use of them where possible also beyond what the title says. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1429,9 +1429,9 @@ static void _update_runstate_area(struct v->arch.pv_vcpu.need_update_runstate_area =3D 1; } =20 -static inline int need_full_gdt(struct vcpu *v) +static inline int need_full_gdt(const struct domain *d) { - return (is_pv_vcpu(v) && !is_idle_vcpu(v)); + return is_pv_domain(d) && !is_idle_domain(d); } =20 static void __context_switch(void) @@ -1440,13 +1440,14 @@ static void __context_switch(void) unsigned int cpu =3D smp_processor_id(); struct vcpu *p =3D per_cpu(curr_vcpu, cpu); struct vcpu *n =3D current; + struct domain *pd =3D p->domain, *nd =3D n->domain; struct desc_struct *gdt; struct desc_ptr gdt_desc; =20 ASSERT(p !=3D n); ASSERT(cpumask_empty(n->vcpu_dirty_cpumask)); =20 - if ( !is_idle_vcpu(p) ) + if ( !is_idle_domain(pd) ) { memcpy(&p->arch.user_regs, stack_regs, CTXT_SWITCH_STACK_BYTES); vcpu_save_fpu(p); @@ -1458,11 +1459,11 @@ static void __context_switch(void) * ctxt_switch_to(). This avoids a race on things like EPT flushing, * which is synchronised on that function. */ - if ( p->domain !=3D n->domain ) - cpumask_set_cpu(cpu, n->domain->domain_dirty_cpumask); + if ( pd !=3D nd ) + cpumask_set_cpu(cpu, nd->domain_dirty_cpumask); cpumask_set_cpu(cpu, n->vcpu_dirty_cpumask); =20 - if ( !is_idle_vcpu(n) ) + if ( !is_idle_domain(nd) ) { memcpy(stack_regs, &n->arch.user_regs, CTXT_SWITCH_STACK_BYTES); if ( cpu_has_xsave ) @@ -1476,14 +1477,14 @@ static void __context_switch(void) n->arch.ctxt_switch_to(n); } =20 - psr_ctxt_switch_to(n->domain); + psr_ctxt_switch_to(nd); =20 - gdt =3D !is_pv_32on64_vcpu(n) ? per_cpu(gdt_table, cpu) : - per_cpu(compat_gdt_table, cpu); - if ( need_full_gdt(n) ) + gdt =3D !is_pv_32on64_domain(nd) ? per_cpu(gdt_table, cpu) : + per_cpu(compat_gdt_table, cpu); + if ( need_full_gdt(nd) ) { unsigned long mfn =3D virt_to_mfn(gdt); - l1_pgentry_t *pl1e =3D gdt_ldt_ptes(n->domain, n); + l1_pgentry_t *pl1e =3D gdt_ldt_ptes(nd, n); unsigned int i; =20 for ( i =3D 0; i < NR_RESERVED_GDT_PAGES; i++ ) @@ -1491,8 +1492,8 @@ static void __context_switch(void) l1e_from_pfn(mfn + i, __PAGE_HYPERVISOR)); } =20 - if ( need_full_gdt(p) && - ((p->vcpu_id !=3D n->vcpu_id) || !need_full_gdt(n)) ) + if ( need_full_gdt(pd) && + ((p->vcpu_id !=3D n->vcpu_id) || !need_full_gdt(nd)) ) { gdt_desc.limit =3D LAST_RESERVED_GDT_BYTE; gdt_desc.base =3D (unsigned long)(gdt - FIRST_RESERVED_GDT_ENTRY)= ; @@ -1501,16 +1502,16 @@ static void __context_switch(void) =20 write_ptbase(n); =20 - if ( need_full_gdt(n) && - ((p->vcpu_id !=3D n->vcpu_id) || !need_full_gdt(p)) ) + if ( need_full_gdt(nd) && + ((p->vcpu_id !=3D n->vcpu_id) || !need_full_gdt(pd)) ) { gdt_desc.limit =3D LAST_RESERVED_GDT_BYTE; gdt_desc.base =3D GDT_VIRT_START(n); asm volatile ( "lgdt %0" : : "m" (gdt_desc) ); } =20 - if ( p->domain !=3D n->domain ) - cpumask_clear_cpu(cpu, p->domain->domain_dirty_cpumask); + if ( pd !=3D nd ) + cpumask_clear_cpu(cpu, pd->domain_dirty_cpumask); cpumask_clear_cpu(cpu, p->vcpu_dirty_cpumask); =20 per_cpu(curr_vcpu, cpu) =3D n; @@ -1520,6 +1521,7 @@ static void __context_switch(void) void context_switch(struct vcpu *prev, struct vcpu *next) { unsigned int cpu =3D smp_processor_id(); + const struct domain *prevd =3D prev->domain, *nextd =3D next->domain; cpumask_t dirty_mask; =20 ASSERT(local_irq_is_enabled()); @@ -1537,7 +1539,7 @@ void context_switch(struct vcpu *prev, s if ( prev !=3D next ) _update_runstate_area(prev); =20 - if ( is_hvm_vcpu(prev) ) + if ( is_hvm_domain(prevd) ) { if (prev !=3D next) vpmu_save(prev); @@ -1551,7 +1553,7 @@ void context_switch(struct vcpu *prev, s set_current(next); =20 if ( (per_cpu(curr_vcpu, cpu) =3D=3D next) || - (is_idle_vcpu(next) && cpu_online(cpu)) ) + (is_idle_domain(nextd) && cpu_online(cpu)) ) { local_irq_enable(); } @@ -1559,10 +1561,10 @@ void context_switch(struct vcpu *prev, s { __context_switch(); =20 - if ( is_pv_vcpu(next) && - (is_idle_vcpu(prev) || - has_hvm_container_vcpu(prev) || - is_pv_32on64_vcpu(prev) !=3D is_pv_32on64_vcpu(next)) ) + if ( is_pv_domain(nextd) && + (is_idle_domain(prevd) || + has_hvm_container_domain(prevd) || + is_pv_32on64_domain(prevd) !=3D is_pv_32on64_domain(nextd)) = ) { uint64_t efer =3D read_efer(); if ( !(efer & EFER_SCE) ) @@ -1572,18 +1574,18 @@ void context_switch(struct vcpu *prev, s /* Re-enable interrupts before restoring state which may fault. = */ local_irq_enable(); =20 - if ( is_pv_vcpu(next) ) + if ( is_pv_domain(nextd) ) { load_LDT(next); load_segments(next); } =20 - set_cpuid_faulting(is_pv_vcpu(next) && - !is_control_domain(next->domain) && - !is_hardware_domain(next->domain)); + set_cpuid_faulting(is_pv_domain(nextd) && + !is_control_domain(nextd) && + !is_hardware_domain(nextd)); } =20 - if (is_hvm_vcpu(next) && (prev !=3D next) ) + if (is_hvm_domain(nextd) && (prev !=3D next) ) /* Must be done with interrupts enabled */ vpmu_load(next); =20 --=__Part4B7F6A6E.1__= Content-Type: text/plain; name="x86-cswitch-latch-domain.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-cswitch-latch-domain.patch" x86/context-switch: prefer is_..._domain() over is_..._vcpu()=0A=0ALatch = both domains alongside both vCPU-s into local variables, making=0Ause of = them where possible also beyond what the title says.=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- a/xen/arch/x86/domain.c=0A+++ = b/xen/arch/x86/domain.c=0A@@ -1429,9 +1429,9 @@ static void _update_runstat= e_area(struct=0A v->arch.pv_vcpu.need_update_runstate_area =3D = 1;=0A }=0A =0A-static inline int need_full_gdt(struct vcpu *v)=0A+static = inline int need_full_gdt(const struct domain *d)=0A {=0A- return = (is_pv_vcpu(v) && !is_idle_vcpu(v));=0A+ return is_pv_domain(d) && = !is_idle_domain(d);=0A }=0A =0A static void __context_switch(void)=0A@@ = -1440,13 +1440,14 @@ static void __context_switch(void)=0A unsigned = int cpu =3D smp_processor_id();=0A struct vcpu *p = =3D per_cpu(curr_vcpu, cpu);=0A struct vcpu *n =3D current;=0A= + struct domain *pd =3D p->domain, *nd =3D n->domain;=0A = struct desc_struct *gdt;=0A struct desc_ptr gdt_desc;=0A =0A = ASSERT(p !=3D n);=0A ASSERT(cpumask_empty(n->vcpu_dirty_cpumask));=0A= =0A- if ( !is_idle_vcpu(p) )=0A+ if ( !is_idle_domain(pd) )=0A = {=0A memcpy(&p->arch.user_regs, stack_regs, CTXT_SWITCH_STACK_BYTES= );=0A vcpu_save_fpu(p);=0A@@ -1458,11 +1459,11 @@ static void = __context_switch(void)=0A * ctxt_switch_to(). This avoids a race on = things like EPT flushing,=0A * which is synchronised on that = function.=0A */=0A- if ( p->domain !=3D n->domain )=0A- = cpumask_set_cpu(cpu, n->domain->domain_dirty_cpumask);=0A+ if ( pd !=3D = nd )=0A+ cpumask_set_cpu(cpu, nd->domain_dirty_cpumask);=0A = cpumask_set_cpu(cpu, n->vcpu_dirty_cpumask);=0A =0A- if ( !is_idle_vcpu(= n) )=0A+ if ( !is_idle_domain(nd) )=0A {=0A memcpy(stack_reg= s, &n->arch.user_regs, CTXT_SWITCH_STACK_BYTES);=0A if ( cpu_has_xs= ave )=0A@@ -1476,14 +1477,14 @@ static void __context_switch(void)=0A = n->arch.ctxt_switch_to(n);=0A }=0A =0A- psr_ctxt_switch_to(n->dom= ain);=0A+ psr_ctxt_switch_to(nd);=0A =0A- gdt =3D !is_pv_32on64_vcpu(= n) ? per_cpu(gdt_table, cpu) :=0A- = per_cpu(compat_gdt_table, cpu);=0A- if ( need_full_gdt(n) )=0A+ gdt = =3D !is_pv_32on64_domain(nd) ? per_cpu(gdt_table, cpu) :=0A+ = per_cpu(compat_gdt_table, cpu);=0A+ if ( = need_full_gdt(nd) )=0A {=0A unsigned long mfn =3D virt_to_mfn(g= dt);=0A- l1_pgentry_t *pl1e =3D gdt_ldt_ptes(n->domain, n);=0A+ = l1_pgentry_t *pl1e =3D gdt_ldt_ptes(nd, n);=0A unsigned int = i;=0A =0A for ( i =3D 0; i < NR_RESERVED_GDT_PAGES; i++ )=0A@@ = -1491,8 +1492,8 @@ static void __context_switch(void)=0A = l1e_from_pfn(mfn + i, __PAGE_HYPERVISOR));=0A }=0A =0A- if ( = need_full_gdt(p) &&=0A- ((p->vcpu_id !=3D n->vcpu_id) || !need_full= _gdt(n)) )=0A+ if ( need_full_gdt(pd) &&=0A+ ((p->vcpu_id !=3D = n->vcpu_id) || !need_full_gdt(nd)) )=0A {=0A gdt_desc.limit = =3D LAST_RESERVED_GDT_BYTE;=0A gdt_desc.base =3D (unsigned = long)(gdt - FIRST_RESERVED_GDT_ENTRY);=0A@@ -1501,16 +1502,16 @@ static = void __context_switch(void)=0A =0A write_ptbase(n);=0A =0A- if ( = need_full_gdt(n) &&=0A- ((p->vcpu_id !=3D n->vcpu_id) || !need_full= _gdt(p)) )=0A+ if ( need_full_gdt(nd) &&=0A+ ((p->vcpu_id !=3D = n->vcpu_id) || !need_full_gdt(pd)) )=0A {=0A gdt_desc.limit = =3D LAST_RESERVED_GDT_BYTE;=0A gdt_desc.base =3D GDT_VIRT_START(n);= =0A asm volatile ( "lgdt %0" : : "m" (gdt_desc) );=0A }=0A = =0A- if ( p->domain !=3D n->domain )=0A- cpumask_clear_cpu(cpu, = p->domain->domain_dirty_cpumask);=0A+ if ( pd !=3D nd )=0A+ = cpumask_clear_cpu(cpu, pd->domain_dirty_cpumask);=0A cpumask_clear_cpu(= cpu, p->vcpu_dirty_cpumask);=0A =0A per_cpu(curr_vcpu, cpu) =3D = n;=0A@@ -1520,6 +1521,7 @@ static void __context_switch(void)=0A void = context_switch(struct vcpu *prev, struct vcpu *next)=0A {=0A unsigned = int cpu =3D smp_processor_id();=0A+ const struct domain *prevd =3D = prev->domain, *nextd =3D next->domain;=0A cpumask_t dirty_mask;=0A =0A = ASSERT(local_irq_is_enabled());=0A@@ -1537,7 +1539,7 @@ void context_sw= itch(struct vcpu *prev, s=0A if ( prev !=3D next )=0A = _update_runstate_area(prev);=0A =0A- if ( is_hvm_vcpu(prev) )=0A+ if = ( is_hvm_domain(prevd) )=0A {=0A if (prev !=3D next)=0A = vpmu_save(prev);=0A@@ -1551,7 +1553,7 @@ void context_switch(struct = vcpu *prev, s=0A set_current(next);=0A =0A if ( (per_cpu(curr_vcpu,= cpu) =3D=3D next) ||=0A- (is_idle_vcpu(next) && cpu_online(cpu)) = )=0A+ (is_idle_domain(nextd) && cpu_online(cpu)) )=0A {=0A = local_irq_enable();=0A }=0A@@ -1559,10 +1561,10 @@ void context_swi= tch(struct vcpu *prev, s=0A {=0A __context_switch();=0A =0A- = if ( is_pv_vcpu(next) &&=0A- (is_idle_vcpu(prev) ||=0A- = has_hvm_container_vcpu(prev) ||=0A- is_pv_32on64_vc= pu(prev) !=3D is_pv_32on64_vcpu(next)) )=0A+ if ( is_pv_domain(nextd= ) &&=0A+ (is_idle_domain(prevd) ||=0A+ has_hvm_con= tainer_domain(prevd) ||=0A+ is_pv_32on64_domain(prevd) !=3D = is_pv_32on64_domain(nextd)) )=0A {=0A uint64_t efer = =3D read_efer();=0A if ( !(efer & EFER_SCE) )=0A@@ -1572,18 = +1574,18 @@ void context_switch(struct vcpu *prev, s=0A /* = Re-enable interrupts before restoring state which may fault. */=0A = local_irq_enable();=0A =0A- if ( is_pv_vcpu(next) )=0A+ if ( = is_pv_domain(nextd) )=0A {=0A load_LDT(next);=0A = load_segments(next);=0A }=0A =0A- set_cpuid_faulting(i= s_pv_vcpu(next) &&=0A- !is_control_domain(next->d= omain) &&=0A- !is_hardware_domain(next->domain));= =0A+ set_cpuid_faulting(is_pv_domain(nextd) &&=0A+ = !is_control_domain(nextd) &&=0A+ = !is_hardware_domain(nextd));=0A }=0A =0A- if (is_hvm_vcpu(next) && = (prev !=3D next) )=0A+ if (is_hvm_domain(nextd) && (prev !=3D next) = )=0A /* Must be done with interrupts enabled */=0A = vpmu_load(next);=0A =0A --=__Part4B7F6A6E.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 --=__Part4B7F6A6E.1__=--