From: "Jan Beulich" Subject: [PATCH 2/6] x86: prefer is_..._domain() over is_..._vcpu() Date: Thu, 11 Jun 2015 11:20:41 +0100 Message-ID: <55797D1902000078000838BD@mail.emea.novell.com> References: <55797BF702000078000838AF@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartCDF9ECE9.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 1Z2zbJ-0002n8-7L for xen-devel@lists.xenproject.org; Thu, 11 Jun 2015 10:20:45 +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. --=__PartCDF9ECE9.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... when the domain pointer is already available or such operations occur frequently in a function. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -481,7 +481,7 @@ int vcpu_initialise(struct vcpu *v) =20 v->arch.pv_vcpu.ctrlreg[4] =3D real_cr4_to_pv_guest_cr4(mmu_cr4_featur= es); =20 - rc =3D is_pv_32on64_vcpu(v) ? setup_compat_l4(v) : 0; + rc =3D is_pv_32on64_domain(d) ? setup_compat_l4(v) : 0; done: if ( rc ) { @@ -722,7 +722,7 @@ int arch_set_info_guest( #define c(fld) (compat ? (c.cmp->fld) : (c.nat->fld)) flags =3D c(flags); =20 - if ( is_pv_vcpu(v) ) + if ( is_pv_domain(d) ) { if ( !compat ) { @@ -763,7 +763,7 @@ int arch_set_info_guest( (c(ldt_ents) > 8192) ) return -EINVAL; } - else if ( is_pvh_vcpu(v) ) + else if ( is_pvh_domain(d) ) { /* PVH 32bitfixme */ ASSERT(!compat); @@ -781,7 +781,7 @@ int arch_set_info_guest( v->fpu_initialised =3D !!(flags & VGCF_I387_VALID); =20 v->arch.flags &=3D ~TF_kernel_mode; - if ( (flags & VGCF_in_kernel) || has_hvm_container_vcpu(v)/*???*/ ) + if ( (flags & VGCF_in_kernel) || has_hvm_container_domain(d)/*???*/ ) v->arch.flags |=3D TF_kernel_mode; =20 v->arch.vgc_flags =3D flags; @@ -796,7 +796,7 @@ int arch_set_info_guest( if ( !compat ) { memcpy(&v->arch.user_regs, &c.nat->user_regs, sizeof(c.nat->user_r= egs)); - if ( is_pv_vcpu(v) ) + if ( is_pv_domain(d) ) memcpy(v->arch.pv_vcpu.trap_ctxt, c.nat->trap_ctxt, sizeof(c.nat->trap_ctxt)); } @@ -808,14 +808,14 @@ int arch_set_info_guest( c.cmp->trap_ctxt + i); } =20 - if ( has_hvm_container_vcpu(v) ) + if ( has_hvm_container_domain(d) ) { for ( i =3D 0; i < ARRAY_SIZE(v->arch.debugreg); ++i ) v->arch.debugreg[i] =3D c(debugreg[i]); =20 hvm_set_info_guest(v); =20 - if ( is_hvm_vcpu(v) || v->is_initialised ) + if ( is_hvm_domain(d) || v->is_initialised ) goto out; =20 /* NB: No need to use PV cr3 un-pickling macros */ --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1150,10 +1150,11 @@ CHECK_FIELD_(struct, vcpu_guest_context, void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) { unsigned int i; - bool_t compat =3D is_pv_32on64_domain(v->domain); + const struct domain *d =3D v->domain; + bool_t compat =3D is_pv_32on64_domain(d); #define c(fld) (!compat ? (c.nat->fld) : (c.cmp->fld)) =20 - if ( !is_pv_vcpu(v) ) + if ( !is_pv_domain(d) ) memset(c.nat, 0, sizeof(*c.nat)); memcpy(&c.nat->fpu_ctxt, v->arch.fpu_ctxt, sizeof(c.nat->fpu_ctxt)); c(flags =3D v->arch.vgc_flags & ~(VGCF_i387_valid|VGCF_in_kernel)); @@ -1164,7 +1165,7 @@ void arch_get_info_guest(struct vcpu *v, if ( !compat ) { memcpy(&c.nat->user_regs, &v->arch.user_regs, sizeof(c.nat->user_r= egs)); - if ( is_pv_vcpu(v) ) + if ( is_pv_domain(d) ) memcpy(c.nat->trap_ctxt, v->arch.pv_vcpu.trap_ctxt, sizeof(c.nat->trap_ctxt)); } @@ -1179,7 +1180,7 @@ void arch_get_info_guest(struct vcpu *v, for ( i =3D 0; i < ARRAY_SIZE(v->arch.debugreg); ++i ) c(debugreg[i] =3D v->arch.debugreg[i]); =20 - if ( has_hvm_container_vcpu(v) ) + if ( has_hvm_container_domain(d) ) { struct segment_register sreg; =20 @@ -1245,7 +1246,7 @@ void arch_get_info_guest(struct vcpu *v, BUG_ON((c(user_regs.eflags) & X86_EFLAGS_IOPL) !=3D 0); c(user_regs.eflags |=3D v->arch.pv_vcpu.iopl << 12); =20 - if ( !is_pv_32on64_domain(v->domain) ) + if ( !compat ) { c.nat->ctrlreg[3] =3D xen_pfn_to_cr3( pagetable_get_pfn(v->arch.guest_table)); @@ -1274,7 +1275,7 @@ void arch_get_info_guest(struct vcpu *v, c(flags |=3D VGCF_in_kernel); } =20 - c(vm_assist =3D v->domain->vm_assist); + c(vm_assist =3D d->vm_assist); #undef c } =20 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -798,7 +798,7 @@ int cpuid_hypervisor_leaves( uint32_t id *ebx =3D 0x40000200; *ecx =3D 0; /* Features 1 */ *edx =3D 0; /* Features 2 */ - if ( is_pv_vcpu(current) ) + if ( is_pv_domain(d) ) *ecx |=3D XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD; break; =20 @@ -822,18 +822,19 @@ void pv_cpuid(struct cpu_user_regs *regs { uint32_t a, b, c, d; struct vcpu *curr =3D current; + struct domain *currd =3D curr->domain; =20 a =3D regs->eax; b =3D regs->ebx; c =3D regs->ecx; d =3D regs->edx; =20 - if ( !is_control_domain(curr->domain) && !is_hardware_domain(curr->dom= ain) ) + if ( !is_control_domain(currd) && !is_hardware_domain(currd) ) { unsigned int cpuid_leaf =3D a, sub_leaf =3D c; =20 if ( !cpuid_hypervisor_leaves(a, c, &a, &b, &c, &d) ) - domain_cpuid(curr->domain, a, c, &a, &b, &c, &d); + domain_cpuid(currd, a, c, &a, &b, &c, &d); =20 switch ( cpuid_leaf ) { @@ -849,7 +850,7 @@ void pv_cpuid(struct cpu_user_regs *regs { if ( !(curr->arch.xcr0 & (1ULL << sub_leaf)) ) continue; - domain_cpuid(curr->domain, cpuid_leaf, sub_leaf, + domain_cpuid(currd, cpuid_leaf, sub_leaf, &_eax, &_ebx, &_ecx, &_edx); if ( (_eax + _ebx) > b ) b =3D _eax + _ebx; @@ -869,7 +870,7 @@ void pv_cpuid(struct cpu_user_regs *regs if ( !cpu_has_apic ) __clear_bit(X86_FEATURE_APIC, &d); =20 - if ( !is_pvh_vcpu(curr) ) + if ( !is_pvh_domain(currd) ) { __clear_bit(X86_FEATURE_PSE, &d); __clear_bit(X86_FEATURE_PGE, &d); @@ -887,7 +888,7 @@ void pv_cpuid(struct cpu_user_regs *regs __clear_bit(X86_FEATURE_DS, &d); __clear_bit(X86_FEATURE_ACC, &d); __clear_bit(X86_FEATURE_PBE, &d); - if ( is_pvh_vcpu(curr) ) + if ( is_pvh_domain(currd) ) __clear_bit(X86_FEATURE_MTRR, &d); =20 __clear_bit(X86_FEATURE_DTES64 % 32, &c); @@ -896,7 +897,7 @@ void pv_cpuid(struct cpu_user_regs *regs __clear_bit(X86_FEATURE_VMXE % 32, &c); __clear_bit(X86_FEATURE_SMXE % 32, &c); __clear_bit(X86_FEATURE_TM2 % 32, &c); - if ( is_pv_32bit_vcpu(curr) ) + if ( is_pv_32bit_domain(currd) ) __clear_bit(X86_FEATURE_CX16 % 32, &c); __clear_bit(X86_FEATURE_XTPR % 32, &c); __clear_bit(X86_FEATURE_PDCM % 32, &c); @@ -945,12 +946,12 @@ void pv_cpuid(struct cpu_user_regs *regs =20 case 0x80000001: /* Modify Feature Information. */ - if ( is_pv_32bit_vcpu(curr) ) + if ( is_pv_32bit_domain(currd) ) { __clear_bit(X86_FEATURE_LM % 32, &d); __clear_bit(X86_FEATURE_LAHF_LM % 32, &c); } - if ( is_pv_32on64_vcpu(curr) && + if ( is_pv_32on64_domain(currd) && boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD ) __clear_bit(X86_FEATURE_SYSCALL % 32, &d); __clear_bit(X86_FEATURE_PAGE1GB % 32, &d); --=__PartCDF9ECE9.1__= Content-Type: text/plain; name="use-is_X_domain-x86.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="use-is_X_domain-x86.patch" x86: prefer is_..._domain() over is_..._vcpu()=0A=0A... when the domain = pointer is already available or such operations=0Aoccur frequently in a = function.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/domain.c=0A+++ b/xen/arch/x86/domain.c=0A@@ -481,7 +481,7 = @@ int vcpu_initialise(struct vcpu *v)=0A =0A v->arch.pv_vcpu.ctrlreg[4= ] =3D real_cr4_to_pv_guest_cr4(mmu_cr4_features);=0A =0A- rc =3D = is_pv_32on64_vcpu(v) ? setup_compat_l4(v) : 0;=0A+ rc =3D is_pv_32on64_d= omain(d) ? setup_compat_l4(v) : 0;=0A done:=0A if ( rc )=0A = {=0A@@ -722,7 +722,7 @@ int arch_set_info_guest(=0A #define c(fld) (compat = ? (c.cmp->fld) : (c.nat->fld))=0A flags =3D c(flags);=0A =0A- if ( = is_pv_vcpu(v) )=0A+ if ( is_pv_domain(d) )=0A {=0A if ( = !compat )=0A {=0A@@ -763,7 +763,7 @@ int arch_set_info_guest(=0A = (c(ldt_ents) > 8192) )=0A return -EINVAL;=0A = }=0A- else if ( is_pvh_vcpu(v) )=0A+ else if ( is_pvh_domain(d) )=0A = {=0A /* PVH 32bitfixme */=0A ASSERT(!compat);=0A@@ = -781,7 +781,7 @@ int arch_set_info_guest(=0A v->fpu_initialised =3D = !!(flags & VGCF_I387_VALID);=0A =0A v->arch.flags &=3D ~TF_kernel_mode;= =0A- if ( (flags & VGCF_in_kernel) || has_hvm_container_vcpu(v)/*???*/ = )=0A+ if ( (flags & VGCF_in_kernel) || has_hvm_container_domain(d)/*???*= / )=0A v->arch.flags |=3D TF_kernel_mode;=0A =0A v->arch.vgc_fl= ags =3D flags;=0A@@ -796,7 +796,7 @@ int arch_set_info_guest(=0A if ( = !compat )=0A {=0A memcpy(&v->arch.user_regs, &c.nat->user_regs,= sizeof(c.nat->user_regs));=0A- if ( is_pv_vcpu(v) )=0A+ if = ( is_pv_domain(d) )=0A memcpy(v->arch.pv_vcpu.trap_ctxt, = c.nat->trap_ctxt,=0A sizeof(c.nat->trap_ctxt));=0A = }=0A@@ -808,14 +808,14 @@ int arch_set_info_guest(=0A = c.cmp->trap_ctxt + i);=0A }=0A =0A- if ( has_hvm_container_vcp= u(v) )=0A+ if ( has_hvm_container_domain(d) )=0A {=0A for ( = i =3D 0; i < ARRAY_SIZE(v->arch.debugreg); ++i )=0A v->arch.deb= ugreg[i] =3D c(debugreg[i]);=0A =0A hvm_set_info_guest(v);=0A =0A- = if ( is_hvm_vcpu(v) || v->is_initialised )=0A+ if ( = is_hvm_domain(d) || v->is_initialised )=0A goto out;=0A =0A = /* NB: No need to use PV cr3 un-pickling macros */=0A--- a/xen/arch/x8= 6/domctl.c=0A+++ b/xen/arch/x86/domctl.c=0A@@ -1150,10 +1150,11 @@ = CHECK_FIELD_(struct, vcpu_guest_context,=0A void arch_get_info_guest(struct= vcpu *v, vcpu_guest_context_u c)=0A {=0A unsigned int i;=0A- = bool_t compat =3D is_pv_32on64_domain(v->domain);=0A+ const struct = domain *d =3D v->domain;=0A+ bool_t compat =3D is_pv_32on64_domain(d);= =0A #define c(fld) (!compat ? (c.nat->fld) : (c.cmp->fld))=0A =0A- if ( = !is_pv_vcpu(v) )=0A+ if ( !is_pv_domain(d) )=0A memset(c.nat, = 0, sizeof(*c.nat));=0A memcpy(&c.nat->fpu_ctxt, v->arch.fpu_ctxt, = sizeof(c.nat->fpu_ctxt));=0A c(flags =3D v->arch.vgc_flags & ~(VGCF_i38= 7_valid|VGCF_in_kernel));=0A@@ -1164,7 +1165,7 @@ void arch_get_info_guest(= struct vcpu *v,=0A if ( !compat )=0A {=0A memcpy(&c.nat->us= er_regs, &v->arch.user_regs, sizeof(c.nat->user_regs));=0A- if ( = is_pv_vcpu(v) )=0A+ if ( is_pv_domain(d) )=0A memcpy(c.n= at->trap_ctxt, v->arch.pv_vcpu.trap_ctxt,=0A sizeof(c.na= t->trap_ctxt));=0A }=0A@@ -1179,7 +1180,7 @@ void arch_get_info_guest(s= truct vcpu *v,=0A for ( i =3D 0; i < ARRAY_SIZE(v->arch.debugreg); ++i = )=0A c(debugreg[i] =3D v->arch.debugreg[i]);=0A =0A- if ( = has_hvm_container_vcpu(v) )=0A+ if ( has_hvm_container_domain(d) )=0A = {=0A struct segment_register sreg;=0A =0A@@ -1245,7 +1246,7 @@ = void arch_get_info_guest(struct vcpu *v,=0A BUG_ON((c(user_regs.efl= ags) & X86_EFLAGS_IOPL) !=3D 0);=0A c(user_regs.eflags |=3D = v->arch.pv_vcpu.iopl << 12);=0A =0A- if ( !is_pv_32on64_domain(v->do= main) )=0A+ if ( !compat )=0A {=0A c.nat->ctrlre= g[3] =3D xen_pfn_to_cr3(=0A pagetable_get_pfn(v->arch.guest= _table));=0A@@ -1274,7 +1275,7 @@ void arch_get_info_guest(struct vcpu = *v,=0A c(flags |=3D VGCF_in_kernel);=0A }=0A =0A- = c(vm_assist =3D v->domain->vm_assist);=0A+ c(vm_assist =3D d->vm_assist)= ;=0A #undef c=0A }=0A =0A--- a/xen/arch/x86/traps.c=0A+++ b/xen/arch/x86/tr= aps.c=0A@@ -798,7 +798,7 @@ int cpuid_hypervisor_leaves( uint32_t id=0A = *ebx =3D 0x40000200;=0A *ecx =3D 0; /* Features = 1 */=0A *edx =3D 0; /* Features 2 */=0A- if ( = is_pv_vcpu(current) )=0A+ if ( is_pv_domain(d) )=0A = *ecx |=3D XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD;=0A break;=0A = =0A@@ -822,18 +822,19 @@ void pv_cpuid(struct cpu_user_regs *regs=0A {=0A = uint32_t a, b, c, d;=0A struct vcpu *curr =3D current;=0A+ = struct domain *currd =3D curr->domain;=0A =0A a =3D regs->eax;=0A = b =3D regs->ebx;=0A c =3D regs->ecx;=0A d =3D regs->edx;=0A =0A- = if ( !is_control_domain(curr->domain) && !is_hardware_domain(curr->domain)= )=0A+ if ( !is_control_domain(currd) && !is_hardware_domain(currd) = )=0A {=0A unsigned int cpuid_leaf =3D a, sub_leaf =3D c;=0A = =0A if ( !cpuid_hypervisor_leaves(a, c, &a, &b, &c, &d) )=0A- = domain_cpuid(curr->domain, a, c, &a, &b, &c, &d);=0A+ = domain_cpuid(currd, a, c, &a, &b, &c, &d);=0A =0A switch ( = cpuid_leaf )=0A {=0A@@ -849,7 +850,7 @@ void pv_cpuid(struct = cpu_user_regs *regs=0A {=0A if ( = !(curr->arch.xcr0 & (1ULL << sub_leaf)) )=0A = continue;=0A- domain_cpuid(curr->domain, cpuid_leaf, = sub_leaf,=0A+ domain_cpuid(currd, cpuid_leaf, = sub_leaf,=0A &_eax, &_ebx, &_ecx, = &_edx);=0A if ( (_eax + _ebx) > b )=0A = b =3D _eax + _ebx;=0A@@ -869,7 +870,7 @@ void pv_cpuid(struct = cpu_user_regs *regs=0A if ( !cpu_has_apic )=0A = __clear_bit(X86_FEATURE_APIC, &d);=0A =0A- if ( !is_pvh_vcpu(curr) = )=0A+ if ( !is_pvh_domain(currd) )=0A {=0A = __clear_bit(X86_FEATURE_PSE, &d);=0A __clear_bit(X86_FEATURE_PG= E, &d);=0A@@ -887,7 +888,7 @@ void pv_cpuid(struct cpu_user_regs *regs=0A = __clear_bit(X86_FEATURE_DS, &d);=0A __clear_bit(X86_FEATURE_= ACC, &d);=0A __clear_bit(X86_FEATURE_PBE, &d);=0A- if ( = is_pvh_vcpu(curr) )=0A+ if ( is_pvh_domain(currd) )=0A = __clear_bit(X86_FEATURE_MTRR, &d);=0A =0A __clear_bit(X86_FEATURE_D= TES64 % 32, &c);=0A@@ -896,7 +897,7 @@ void pv_cpuid(struct cpu_user_regs = *regs=0A __clear_bit(X86_FEATURE_VMXE % 32, &c);=0A = __clear_bit(X86_FEATURE_SMXE % 32, &c);=0A __clear_bit(X86_FEATURE_= TM2 % 32, &c);=0A- if ( is_pv_32bit_vcpu(curr) )=0A+ if ( = is_pv_32bit_domain(currd) )=0A __clear_bit(X86_FEATURE_CX16 % = 32, &c);=0A __clear_bit(X86_FEATURE_XTPR % 32, &c);=0A = __clear_bit(X86_FEATURE_PDCM % 32, &c);=0A@@ -945,12 +946,12 @@ void = pv_cpuid(struct cpu_user_regs *regs=0A =0A case 0x80000001:=0A = /* Modify Feature Information. */=0A- if ( is_pv_32bit_vcpu(curr) = )=0A+ if ( is_pv_32bit_domain(currd) )=0A {=0A = __clear_bit(X86_FEATURE_LM % 32, &d);=0A __clear_bit(X86_FEATUR= E_LAHF_LM % 32, &c);=0A }=0A- if ( is_pv_32on64_vcpu(curr) = &&=0A+ if ( is_pv_32on64_domain(currd) &&=0A boot_cpu_d= ata.x86_vendor !=3D X86_VENDOR_AMD )=0A __clear_bit(X86_FEATURE= _SYSCALL % 32, &d);=0A __clear_bit(X86_FEATURE_PAGE1GB % 32, = &d);=0A --=__PartCDF9ECE9.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 --=__PartCDF9ECE9.1__=--