* [PATCH 1/6] domctl: prefer is_..._domain() over is_..._vcpu()
2015-06-11 10:15 [PATCH 0/6] prefer is_..._domain() over is_..._vcpu() Jan Beulich
@ 2015-06-11 10:20 ` Jan Beulich
2015-06-11 10:35 ` Ian Campbell
2015-06-11 10:20 ` [PATCH 2/6] x86: " Jan Beulich
` (5 subsequent siblings)
6 siblings, 1 reply; 10+ messages in thread
From: Jan Beulich @ 2015-06-11 10:20 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Campbell, Keir Fraser, Ian Jackson, Tim Deegan
[-- Attachment #1: Type: text/plain, Size: 836 bytes --]
... when the domain pointer is already available.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -495,7 +495,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
break;
#ifdef CONFIG_COMPAT
- if ( !is_pv_32on64_vcpu(v) )
+ if ( !is_pv_32on64_domain(d) )
ret = copy_from_guest(c.nat, op->u.vcpucontext.ctxt, 1);
else
ret = copy_from_guest(c.cmp,
@@ -901,7 +901,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
vcpu_unpause(v);
#ifdef CONFIG_COMPAT
- if ( !is_pv_32on64_vcpu(v) )
+ if ( !is_pv_32on64_domain(d) )
ret = copy_to_guest(op->u.vcpucontext.ctxt, c.nat, 1);
else
ret = copy_to_guest(guest_handle_cast(op->u.vcpucontext.ctxt,
[-- Attachment #2: use-is_X_domain-common.patch --]
[-- Type: text/plain, Size: 883 bytes --]
domctl: prefer is_..._domain() over is_..._vcpu()
... when the domain pointer is already available.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -495,7 +495,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
break;
#ifdef CONFIG_COMPAT
- if ( !is_pv_32on64_vcpu(v) )
+ if ( !is_pv_32on64_domain(d) )
ret = copy_from_guest(c.nat, op->u.vcpucontext.ctxt, 1);
else
ret = copy_from_guest(c.cmp,
@@ -901,7 +901,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xe
vcpu_unpause(v);
#ifdef CONFIG_COMPAT
- if ( !is_pv_32on64_vcpu(v) )
+ if ( !is_pv_32on64_domain(d) )
ret = copy_to_guest(op->u.vcpucontext.ctxt, c.nat, 1);
else
ret = copy_to_guest(guest_handle_cast(op->u.vcpucontext.ctxt,
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 2/6] x86: prefer is_..._domain() over is_..._vcpu()
2015-06-11 10:15 [PATCH 0/6] prefer is_..._domain() over is_..._vcpu() Jan Beulich
2015-06-11 10:20 ` [PATCH 1/6] domctl: " Jan Beulich
@ 2015-06-11 10:20 ` Jan Beulich
2015-06-11 10:21 ` [PATCH 3/6] x86/HVM: " Jan Beulich
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2015-06-11 10:20 UTC (permalink / raw)
To: xen-devel; +Cc: Andrew Cooper, Keir Fraser
[-- Attachment #1: Type: text/plain, Size: 7535 bytes --]
... when the domain pointer is already available or such operations
occur frequently in a function.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -481,7 +481,7 @@ int vcpu_initialise(struct vcpu *v)
v->arch.pv_vcpu.ctrlreg[4] = real_cr4_to_pv_guest_cr4(mmu_cr4_features);
- rc = is_pv_32on64_vcpu(v) ? setup_compat_l4(v) : 0;
+ rc = 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 = c(flags);
- 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 = !!(flags & VGCF_I387_VALID);
v->arch.flags &= ~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 |= TF_kernel_mode;
v->arch.vgc_flags = 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_regs));
- 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);
}
- if ( has_hvm_container_vcpu(v) )
+ if ( has_hvm_container_domain(d) )
{
for ( i = 0; i < ARRAY_SIZE(v->arch.debugreg); ++i )
v->arch.debugreg[i] = c(debugreg[i]);
hvm_set_info_guest(v);
- if ( is_hvm_vcpu(v) || v->is_initialised )
+ if ( is_hvm_domain(d) || v->is_initialised )
goto out;
/* 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 = is_pv_32on64_domain(v->domain);
+ const struct domain *d = v->domain;
+ bool_t compat = is_pv_32on64_domain(d);
#define c(fld) (!compat ? (c.nat->fld) : (c.cmp->fld))
- 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 = 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_regs));
- 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 = 0; i < ARRAY_SIZE(v->arch.debugreg); ++i )
c(debugreg[i] = v->arch.debugreg[i]);
- if ( has_hvm_container_vcpu(v) )
+ if ( has_hvm_container_domain(d) )
{
struct segment_register sreg;
@@ -1245,7 +1246,7 @@ void arch_get_info_guest(struct vcpu *v,
BUG_ON((c(user_regs.eflags) & X86_EFLAGS_IOPL) != 0);
c(user_regs.eflags |= v->arch.pv_vcpu.iopl << 12);
- if ( !is_pv_32on64_domain(v->domain) )
+ if ( !compat )
{
c.nat->ctrlreg[3] = 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 |= VGCF_in_kernel);
}
- c(vm_assist = v->domain->vm_assist);
+ c(vm_assist = d->vm_assist);
#undef c
}
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -798,7 +798,7 @@ int cpuid_hypervisor_leaves( uint32_t id
*ebx = 0x40000200;
*ecx = 0; /* Features 1 */
*edx = 0; /* Features 2 */
- if ( is_pv_vcpu(current) )
+ if ( is_pv_domain(d) )
*ecx |= XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD;
break;
@@ -822,18 +822,19 @@ void pv_cpuid(struct cpu_user_regs *regs
{
uint32_t a, b, c, d;
struct vcpu *curr = current;
+ struct domain *currd = curr->domain;
a = regs->eax;
b = regs->ebx;
c = regs->ecx;
d = regs->edx;
- if ( !is_control_domain(curr->domain) && !is_hardware_domain(curr->domain) )
+ if ( !is_control_domain(currd) && !is_hardware_domain(currd) )
{
unsigned int cpuid_leaf = a, sub_leaf = c;
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);
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 = _eax + _ebx;
@@ -869,7 +870,7 @@ void pv_cpuid(struct cpu_user_regs *regs
if ( !cpu_has_apic )
__clear_bit(X86_FEATURE_APIC, &d);
- 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);
__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
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 != X86_VENDOR_AMD )
__clear_bit(X86_FEATURE_SYSCALL % 32, &d);
__clear_bit(X86_FEATURE_PAGE1GB % 32, &d);
[-- Attachment #2: use-is_X_domain-x86.patch --]
[-- Type: text/plain, Size: 7581 bytes --]
x86: prefer is_..._domain() over is_..._vcpu()
... when the domain pointer is already available or such operations
occur frequently in a function.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -481,7 +481,7 @@ int vcpu_initialise(struct vcpu *v)
v->arch.pv_vcpu.ctrlreg[4] = real_cr4_to_pv_guest_cr4(mmu_cr4_features);
- rc = is_pv_32on64_vcpu(v) ? setup_compat_l4(v) : 0;
+ rc = 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 = c(flags);
- 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 = !!(flags & VGCF_I387_VALID);
v->arch.flags &= ~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 |= TF_kernel_mode;
v->arch.vgc_flags = 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_regs));
- 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);
}
- if ( has_hvm_container_vcpu(v) )
+ if ( has_hvm_container_domain(d) )
{
for ( i = 0; i < ARRAY_SIZE(v->arch.debugreg); ++i )
v->arch.debugreg[i] = c(debugreg[i]);
hvm_set_info_guest(v);
- if ( is_hvm_vcpu(v) || v->is_initialised )
+ if ( is_hvm_domain(d) || v->is_initialised )
goto out;
/* 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 = is_pv_32on64_domain(v->domain);
+ const struct domain *d = v->domain;
+ bool_t compat = is_pv_32on64_domain(d);
#define c(fld) (!compat ? (c.nat->fld) : (c.cmp->fld))
- 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 = 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_regs));
- 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 = 0; i < ARRAY_SIZE(v->arch.debugreg); ++i )
c(debugreg[i] = v->arch.debugreg[i]);
- if ( has_hvm_container_vcpu(v) )
+ if ( has_hvm_container_domain(d) )
{
struct segment_register sreg;
@@ -1245,7 +1246,7 @@ void arch_get_info_guest(struct vcpu *v,
BUG_ON((c(user_regs.eflags) & X86_EFLAGS_IOPL) != 0);
c(user_regs.eflags |= v->arch.pv_vcpu.iopl << 12);
- if ( !is_pv_32on64_domain(v->domain) )
+ if ( !compat )
{
c.nat->ctrlreg[3] = 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 |= VGCF_in_kernel);
}
- c(vm_assist = v->domain->vm_assist);
+ c(vm_assist = d->vm_assist);
#undef c
}
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -798,7 +798,7 @@ int cpuid_hypervisor_leaves( uint32_t id
*ebx = 0x40000200;
*ecx = 0; /* Features 1 */
*edx = 0; /* Features 2 */
- if ( is_pv_vcpu(current) )
+ if ( is_pv_domain(d) )
*ecx |= XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD;
break;
@@ -822,18 +822,19 @@ void pv_cpuid(struct cpu_user_regs *regs
{
uint32_t a, b, c, d;
struct vcpu *curr = current;
+ struct domain *currd = curr->domain;
a = regs->eax;
b = regs->ebx;
c = regs->ecx;
d = regs->edx;
- if ( !is_control_domain(curr->domain) && !is_hardware_domain(curr->domain) )
+ if ( !is_control_domain(currd) && !is_hardware_domain(currd) )
{
unsigned int cpuid_leaf = a, sub_leaf = c;
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);
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 = _eax + _ebx;
@@ -869,7 +870,7 @@ void pv_cpuid(struct cpu_user_regs *regs
if ( !cpu_has_apic )
__clear_bit(X86_FEATURE_APIC, &d);
- 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);
__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
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 != X86_VENDOR_AMD )
__clear_bit(X86_FEATURE_SYSCALL % 32, &d);
__clear_bit(X86_FEATURE_PAGE1GB % 32, &d);
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 3/6] x86/HVM: prefer is_..._domain() over is_..._vcpu()
2015-06-11 10:15 [PATCH 0/6] prefer is_..._domain() over is_..._vcpu() Jan Beulich
2015-06-11 10:20 ` [PATCH 1/6] domctl: " Jan Beulich
2015-06-11 10:20 ` [PATCH 2/6] x86: " Jan Beulich
@ 2015-06-11 10:21 ` Jan Beulich
2015-06-11 10:21 ` [PATCH 4/6] x86/mm: " Jan Beulich
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2015-06-11 10:21 UTC (permalink / raw)
To: xen-devel; +Cc: Andrew Cooper, Keir Fraser
[-- Attachment #1: Type: text/plain, Size: 3531 bytes --]
... when the domain pointer is already available or such operations
occur frequently in a function.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -445,7 +445,7 @@ void hvm_do_resume(struct vcpu *v)
check_wakeup_from_wait();
- if ( is_hvm_vcpu(v) )
+ if ( is_hvm_domain(d) )
pt_restore_timer(v);
list_for_each_entry ( s,
@@ -2312,7 +2312,7 @@ int hvm_vcpu_initialise(struct vcpu *v)
v->arch.hvm_vcpu.inject_trap.vector = -1;
- if ( is_pvh_vcpu(v) )
+ if ( is_pvh_domain(d) )
{
v->arch.hvm_vcpu.hcall_64bit = 1; /* PVH 32bitfixme. */
/* This is for hvm_long_mode_enabled(v). */
@@ -2364,9 +2364,7 @@ int hvm_vcpu_initialise(struct vcpu *v)
void hvm_vcpu_destroy(struct vcpu *v)
{
- struct domain *d = v->domain;
-
- hvm_all_ioreq_servers_remove_vcpu(d, v);
+ hvm_all_ioreq_servers_remove_vcpu(v->domain, v);
nestedhvm_vcpu_destroy(v);
@@ -4921,6 +4920,7 @@ extern const uint8_t hypercall_args_tabl
int hvm_do_hypercall(struct cpu_user_regs *regs)
{
struct vcpu *curr = current;
+ struct domain *currd = curr->domain;
struct segment_register sreg;
int mode = hvm_guest_x86_mode(curr);
uint32_t eax = regs->eax;
@@ -4941,12 +4941,12 @@ int hvm_do_hypercall(struct cpu_user_reg
break;
}
- if ( (eax & 0x80000000) && is_viridian_domain(curr->domain) )
+ if ( (eax & 0x80000000) && is_viridian_domain(currd) )
return viridian_hypercall(regs);
if ( (eax >= NR_hypercalls) ||
- (is_pvh_vcpu(curr) ? !pvh_hypercall64_table[eax]
- : !hvm_hypercall32_table[eax]) )
+ (is_pvh_domain(currd) ? !pvh_hypercall64_table[eax]
+ : !hvm_hypercall32_table[eax]) )
{
regs->eax = -ENOSYS;
return HVM_HCALL_completed;
@@ -4980,7 +4980,7 @@ int hvm_do_hypercall(struct cpu_user_reg
#endif
curr->arch.hvm_vcpu.hcall_64bit = 1;
- regs->rax = (is_pvh_vcpu(curr)
+ regs->rax = (is_pvh_domain(currd)
? pvh_hypercall64_table
: hvm_hypercall64_table)[eax](rdi, rsi, rdx, r10, r8, r9);
curr->arch.hvm_vcpu.hcall_64bit = 0;
@@ -5001,7 +5001,7 @@ int hvm_do_hypercall(struct cpu_user_reg
}
#endif
}
- else if ( unlikely(is_pvh_vcpu(curr)) )
+ else if ( unlikely(is_pvh_domain(currd)) )
regs->_eax = -ENOSYS; /* PVH 32bitfixme. */
else
{
@@ -5053,8 +5053,8 @@ int hvm_do_hypercall(struct cpu_user_reg
if ( curr->arch.hvm_vcpu.hcall_preempted )
return HVM_HCALL_preempted;
- if ( unlikely(curr->domain->arch.hvm_domain.qemu_mapcache_invalidate) &&
- test_and_clear_bool(curr->domain->arch.hvm_domain.
+ if ( unlikely(currd->arch.hvm_domain.qemu_mapcache_invalidate) &&
+ test_and_clear_bool(currd->arch.hvm_domain.
qemu_mapcache_invalidate) )
return HVM_HCALL_invalidate;
--- a/xen/arch/x86/hvm/vmx/vmcs.c
+++ b/xen/arch/x86/hvm/vmx/vmcs.c
@@ -1207,7 +1207,7 @@ static int construct_vmcs(struct vcpu *v
vmx_vmcs_exit(v);
/* PVH: paging mode is updated by arch_set_info_guest(). */
- if ( is_hvm_vcpu(v) )
+ if ( is_hvm_domain(d) )
{
/* will update HOST & GUEST_CR3 as reqd */
paging_update_paging_modes(v);
[-- Attachment #2: use-is_X_domain-x86-HVM.patch --]
[-- Type: text/plain, Size: 3579 bytes --]
x86/HVM: prefer is_..._domain() over is_..._vcpu()
... when the domain pointer is already available or such operations
occur frequently in a function.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -445,7 +445,7 @@ void hvm_do_resume(struct vcpu *v)
check_wakeup_from_wait();
- if ( is_hvm_vcpu(v) )
+ if ( is_hvm_domain(d) )
pt_restore_timer(v);
list_for_each_entry ( s,
@@ -2312,7 +2312,7 @@ int hvm_vcpu_initialise(struct vcpu *v)
v->arch.hvm_vcpu.inject_trap.vector = -1;
- if ( is_pvh_vcpu(v) )
+ if ( is_pvh_domain(d) )
{
v->arch.hvm_vcpu.hcall_64bit = 1; /* PVH 32bitfixme. */
/* This is for hvm_long_mode_enabled(v). */
@@ -2364,9 +2364,7 @@ int hvm_vcpu_initialise(struct vcpu *v)
void hvm_vcpu_destroy(struct vcpu *v)
{
- struct domain *d = v->domain;
-
- hvm_all_ioreq_servers_remove_vcpu(d, v);
+ hvm_all_ioreq_servers_remove_vcpu(v->domain, v);
nestedhvm_vcpu_destroy(v);
@@ -4921,6 +4920,7 @@ extern const uint8_t hypercall_args_tabl
int hvm_do_hypercall(struct cpu_user_regs *regs)
{
struct vcpu *curr = current;
+ struct domain *currd = curr->domain;
struct segment_register sreg;
int mode = hvm_guest_x86_mode(curr);
uint32_t eax = regs->eax;
@@ -4941,12 +4941,12 @@ int hvm_do_hypercall(struct cpu_user_reg
break;
}
- if ( (eax & 0x80000000) && is_viridian_domain(curr->domain) )
+ if ( (eax & 0x80000000) && is_viridian_domain(currd) )
return viridian_hypercall(regs);
if ( (eax >= NR_hypercalls) ||
- (is_pvh_vcpu(curr) ? !pvh_hypercall64_table[eax]
- : !hvm_hypercall32_table[eax]) )
+ (is_pvh_domain(currd) ? !pvh_hypercall64_table[eax]
+ : !hvm_hypercall32_table[eax]) )
{
regs->eax = -ENOSYS;
return HVM_HCALL_completed;
@@ -4980,7 +4980,7 @@ int hvm_do_hypercall(struct cpu_user_reg
#endif
curr->arch.hvm_vcpu.hcall_64bit = 1;
- regs->rax = (is_pvh_vcpu(curr)
+ regs->rax = (is_pvh_domain(currd)
? pvh_hypercall64_table
: hvm_hypercall64_table)[eax](rdi, rsi, rdx, r10, r8, r9);
curr->arch.hvm_vcpu.hcall_64bit = 0;
@@ -5001,7 +5001,7 @@ int hvm_do_hypercall(struct cpu_user_reg
}
#endif
}
- else if ( unlikely(is_pvh_vcpu(curr)) )
+ else if ( unlikely(is_pvh_domain(currd)) )
regs->_eax = -ENOSYS; /* PVH 32bitfixme. */
else
{
@@ -5053,8 +5053,8 @@ int hvm_do_hypercall(struct cpu_user_reg
if ( curr->arch.hvm_vcpu.hcall_preempted )
return HVM_HCALL_preempted;
- if ( unlikely(curr->domain->arch.hvm_domain.qemu_mapcache_invalidate) &&
- test_and_clear_bool(curr->domain->arch.hvm_domain.
+ if ( unlikely(currd->arch.hvm_domain.qemu_mapcache_invalidate) &&
+ test_and_clear_bool(currd->arch.hvm_domain.
qemu_mapcache_invalidate) )
return HVM_HCALL_invalidate;
--- a/xen/arch/x86/hvm/vmx/vmcs.c
+++ b/xen/arch/x86/hvm/vmx/vmcs.c
@@ -1207,7 +1207,7 @@ static int construct_vmcs(struct vcpu *v
vmx_vmcs_exit(v);
/* PVH: paging mode is updated by arch_set_info_guest(). */
- if ( is_hvm_vcpu(v) )
+ if ( is_hvm_domain(d) )
{
/* will update HOST & GUEST_CR3 as reqd */
paging_update_paging_modes(v);
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 4/6] x86/mm: prefer is_..._domain() over is_..._vcpu()
2015-06-11 10:15 [PATCH 0/6] prefer is_..._domain() over is_..._vcpu() Jan Beulich
` (2 preceding siblings ...)
2015-06-11 10:21 ` [PATCH 3/6] x86/HVM: " Jan Beulich
@ 2015-06-11 10:21 ` Jan Beulich
2015-06-11 10:22 ` [PATCH 5/6] x86/context‑switch: " Jan Beulich
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2015-06-11 10:21 UTC (permalink / raw)
To: xen-devel; +Cc: Tim Deegan
[-- Attachment #1: Type: text/plain, Size: 3070 bytes --]
... when the domain pointer is already available.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/mm/guest_walk.c
+++ b/xen/arch/x86/mm/guest_walk.c
@@ -159,7 +159,7 @@ guest_walk_tables(struct vcpu *v, struct
mflags = mandatory_flags(v, pfec);
iflags = (_PAGE_NX_BIT | _PAGE_INVALID_BITS);
- if ( is_hvm_vcpu(v) && !(pfec & PFEC_user_mode) )
+ if ( is_hvm_domain(d) && !(pfec & PFEC_user_mode) )
{
struct segment_register seg;
const struct cpu_user_regs *regs = guest_cpu_user_regs();
--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -3157,12 +3157,10 @@ void shadow_teardown(struct domain *d)
* destroyed any shadows of it or sh_destroy_shadow will get confused. */
if ( !pagetable_is_null(d->arch.paging.shadow.unpaged_pagetable) )
{
+ ASSERT(is_hvm_domain(d));
for_each_vcpu(d, v)
- {
- ASSERT(is_hvm_vcpu(v));
if ( !hvm_paging_enabled(v) )
v->arch.guest_table = pagetable_null();
- }
unpaged_pagetable =
pagetable_get_page(d->arch.paging.shadow.unpaged_pagetable);
d->arch.paging.shadow.unpaged_pagetable = pagetable_null();
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -2043,7 +2043,7 @@ void sh_destroy_monitor_table(struct vcp
sh_unmap_domain_page(l3e);
shadow_free(d, m3mfn);
- if ( is_pv_32on64_vcpu(v) )
+ if ( is_pv_32on64_domain(d) )
{
/* Need to destroy the l3 and l2 monitor pages that map the
* Xen VAs at 3GB-4GB */
@@ -3963,7 +3963,7 @@ sh_update_cr3(struct vcpu *v, int do_loc
(unsigned long)pagetable_get_pfn(v->arch.guest_table));
#if GUEST_PAGING_LEVELS == 4
- if ( !(v->arch.flags & TF_kernel_mode) && !is_pv_32on64_vcpu(v) )
+ if ( !(v->arch.flags & TF_kernel_mode) && !is_pv_32on64_domain(d) )
gmfn = pagetable_get_mfn(v->arch.guest_table_user);
else
#endif
@@ -4674,7 +4674,7 @@ static void *emulate_map_dest(struct vcp
/* Cross-page emulated writes are only supported for HVM guests;
* PV guests ought to know better */
- if ( !is_hvm_vcpu(v) )
+ if ( !is_hvm_domain(d) )
return MAPPING_UNHANDLEABLE;
/* This write crosses a page boundary. Translate the second page */
@@ -5104,7 +5104,7 @@ int sh_audit_l3_table(struct vcpu *v, mf
gmfn = get_shadow_status(d, get_gfn_query_unlocked(
d, gfn_x(gfn), &p2mt),
((GUEST_PAGING_LEVELS == 3 ||
- is_pv_32on64_vcpu(v))
+ is_pv_32on64_domain(d))
&& !shadow_mode_external(d)
&& (guest_index(gl3e) % 4) == 3)
? SH_type_l2h_shadow
[-- Attachment #2: use-is_X_domain-x86-mm.patch --]
[-- Type: text/plain, Size: 3117 bytes --]
x86/mm: prefer is_..._domain() over is_..._vcpu()
... when the domain pointer is already available.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/mm/guest_walk.c
+++ b/xen/arch/x86/mm/guest_walk.c
@@ -159,7 +159,7 @@ guest_walk_tables(struct vcpu *v, struct
mflags = mandatory_flags(v, pfec);
iflags = (_PAGE_NX_BIT | _PAGE_INVALID_BITS);
- if ( is_hvm_vcpu(v) && !(pfec & PFEC_user_mode) )
+ if ( is_hvm_domain(d) && !(pfec & PFEC_user_mode) )
{
struct segment_register seg;
const struct cpu_user_regs *regs = guest_cpu_user_regs();
--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -3157,12 +3157,10 @@ void shadow_teardown(struct domain *d)
* destroyed any shadows of it or sh_destroy_shadow will get confused. */
if ( !pagetable_is_null(d->arch.paging.shadow.unpaged_pagetable) )
{
+ ASSERT(is_hvm_domain(d));
for_each_vcpu(d, v)
- {
- ASSERT(is_hvm_vcpu(v));
if ( !hvm_paging_enabled(v) )
v->arch.guest_table = pagetable_null();
- }
unpaged_pagetable =
pagetable_get_page(d->arch.paging.shadow.unpaged_pagetable);
d->arch.paging.shadow.unpaged_pagetable = pagetable_null();
--- a/xen/arch/x86/mm/shadow/multi.c
+++ b/xen/arch/x86/mm/shadow/multi.c
@@ -2043,7 +2043,7 @@ void sh_destroy_monitor_table(struct vcp
sh_unmap_domain_page(l3e);
shadow_free(d, m3mfn);
- if ( is_pv_32on64_vcpu(v) )
+ if ( is_pv_32on64_domain(d) )
{
/* Need to destroy the l3 and l2 monitor pages that map the
* Xen VAs at 3GB-4GB */
@@ -3963,7 +3963,7 @@ sh_update_cr3(struct vcpu *v, int do_loc
(unsigned long)pagetable_get_pfn(v->arch.guest_table));
#if GUEST_PAGING_LEVELS == 4
- if ( !(v->arch.flags & TF_kernel_mode) && !is_pv_32on64_vcpu(v) )
+ if ( !(v->arch.flags & TF_kernel_mode) && !is_pv_32on64_domain(d) )
gmfn = pagetable_get_mfn(v->arch.guest_table_user);
else
#endif
@@ -4674,7 +4674,7 @@ static void *emulate_map_dest(struct vcp
/* Cross-page emulated writes are only supported for HVM guests;
* PV guests ought to know better */
- if ( !is_hvm_vcpu(v) )
+ if ( !is_hvm_domain(d) )
return MAPPING_UNHANDLEABLE;
/* This write crosses a page boundary. Translate the second page */
@@ -5104,7 +5104,7 @@ int sh_audit_l3_table(struct vcpu *v, mf
gmfn = get_shadow_status(d, get_gfn_query_unlocked(
d, gfn_x(gfn), &p2mt),
((GUEST_PAGING_LEVELS == 3 ||
- is_pv_32on64_vcpu(v))
+ is_pv_32on64_domain(d))
&& !shadow_mode_external(d)
&& (guest_index(gl3e) % 4) == 3)
? SH_type_l2h_shadow
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 5/6] x86/context‑switch: prefer is_..._domain() over is_..._vcpu()
2015-06-11 10:15 [PATCH 0/6] prefer is_..._domain() over is_..._vcpu() Jan Beulich
` (3 preceding siblings ...)
2015-06-11 10:21 ` [PATCH 4/6] x86/mm: " Jan Beulich
@ 2015-06-11 10:22 ` Jan Beulich
2015-06-11 10:24 ` [PATCH 6/6] x86/HAP: " Jan Beulich
2015-06-11 10:33 ` [PATCH 0/6] " Andrew Cooper
6 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2015-06-11 10:22 UTC (permalink / raw)
To: xen-devel; +Cc: Andrew Cooper, Keir Fraser
[-- Attachment #1: Type: text/plain, Size: 6126 bytes --]
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 <jbeulich@suse.com>
--- 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 = 1;
}
-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);
}
static void __context_switch(void)
@@ -1440,13 +1440,14 @@ static void __context_switch(void)
unsigned int cpu = smp_processor_id();
struct vcpu *p = per_cpu(curr_vcpu, cpu);
struct vcpu *n = current;
+ struct domain *pd = p->domain, *nd = n->domain;
struct desc_struct *gdt;
struct desc_ptr gdt_desc;
ASSERT(p != n);
ASSERT(cpumask_empty(n->vcpu_dirty_cpumask));
- 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 != n->domain )
- cpumask_set_cpu(cpu, n->domain->domain_dirty_cpumask);
+ if ( pd != nd )
+ cpumask_set_cpu(cpu, nd->domain_dirty_cpumask);
cpumask_set_cpu(cpu, n->vcpu_dirty_cpumask);
- 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);
}
- psr_ctxt_switch_to(n->domain);
+ psr_ctxt_switch_to(nd);
- gdt = !is_pv_32on64_vcpu(n) ? per_cpu(gdt_table, cpu) :
- per_cpu(compat_gdt_table, cpu);
- if ( need_full_gdt(n) )
+ gdt = !is_pv_32on64_domain(nd) ? per_cpu(gdt_table, cpu) :
+ per_cpu(compat_gdt_table, cpu);
+ if ( need_full_gdt(nd) )
{
unsigned long mfn = virt_to_mfn(gdt);
- l1_pgentry_t *pl1e = gdt_ldt_ptes(n->domain, n);
+ l1_pgentry_t *pl1e = gdt_ldt_ptes(nd, n);
unsigned int i;
for ( i = 0; i < NR_RESERVED_GDT_PAGES; i++ )
@@ -1491,8 +1492,8 @@ static void __context_switch(void)
l1e_from_pfn(mfn + i, __PAGE_HYPERVISOR));
}
- if ( need_full_gdt(p) &&
- ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(n)) )
+ if ( need_full_gdt(pd) &&
+ ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(nd)) )
{
gdt_desc.limit = LAST_RESERVED_GDT_BYTE;
gdt_desc.base = (unsigned long)(gdt - FIRST_RESERVED_GDT_ENTRY);
@@ -1501,16 +1502,16 @@ static void __context_switch(void)
write_ptbase(n);
- if ( need_full_gdt(n) &&
- ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(p)) )
+ if ( need_full_gdt(nd) &&
+ ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(pd)) )
{
gdt_desc.limit = LAST_RESERVED_GDT_BYTE;
gdt_desc.base = GDT_VIRT_START(n);
asm volatile ( "lgdt %0" : : "m" (gdt_desc) );
}
- if ( p->domain != n->domain )
- cpumask_clear_cpu(cpu, p->domain->domain_dirty_cpumask);
+ if ( pd != nd )
+ cpumask_clear_cpu(cpu, pd->domain_dirty_cpumask);
cpumask_clear_cpu(cpu, p->vcpu_dirty_cpumask);
per_cpu(curr_vcpu, cpu) = n;
@@ -1520,6 +1521,7 @@ static void __context_switch(void)
void context_switch(struct vcpu *prev, struct vcpu *next)
{
unsigned int cpu = smp_processor_id();
+ const struct domain *prevd = prev->domain, *nextd = next->domain;
cpumask_t dirty_mask;
ASSERT(local_irq_is_enabled());
@@ -1537,7 +1539,7 @@ void context_switch(struct vcpu *prev, s
if ( prev != next )
_update_runstate_area(prev);
- if ( is_hvm_vcpu(prev) )
+ if ( is_hvm_domain(prevd) )
{
if (prev != next)
vpmu_save(prev);
@@ -1551,7 +1553,7 @@ void context_switch(struct vcpu *prev, s
set_current(next);
if ( (per_cpu(curr_vcpu, cpu) == 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();
- if ( is_pv_vcpu(next) &&
- (is_idle_vcpu(prev) ||
- has_hvm_container_vcpu(prev) ||
- is_pv_32on64_vcpu(prev) != is_pv_32on64_vcpu(next)) )
+ if ( is_pv_domain(nextd) &&
+ (is_idle_domain(prevd) ||
+ has_hvm_container_domain(prevd) ||
+ is_pv_32on64_domain(prevd) != is_pv_32on64_domain(nextd)) )
{
uint64_t efer = 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();
- if ( is_pv_vcpu(next) )
+ if ( is_pv_domain(nextd) )
{
load_LDT(next);
load_segments(next);
}
- 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));
}
- if (is_hvm_vcpu(next) && (prev != next) )
+ if (is_hvm_domain(nextd) && (prev != next) )
/* Must be done with interrupts enabled */
vpmu_load(next);
[-- Attachment #2: x86-cswitch-latch-domain.patch --]
[-- Type: text/plain, Size: 6187 bytes --]
x86/context-switch: prefer is_..._domain() over is_..._vcpu()
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 <jbeulich@suse.com>
--- 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 = 1;
}
-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);
}
static void __context_switch(void)
@@ -1440,13 +1440,14 @@ static void __context_switch(void)
unsigned int cpu = smp_processor_id();
struct vcpu *p = per_cpu(curr_vcpu, cpu);
struct vcpu *n = current;
+ struct domain *pd = p->domain, *nd = n->domain;
struct desc_struct *gdt;
struct desc_ptr gdt_desc;
ASSERT(p != n);
ASSERT(cpumask_empty(n->vcpu_dirty_cpumask));
- 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 != n->domain )
- cpumask_set_cpu(cpu, n->domain->domain_dirty_cpumask);
+ if ( pd != nd )
+ cpumask_set_cpu(cpu, nd->domain_dirty_cpumask);
cpumask_set_cpu(cpu, n->vcpu_dirty_cpumask);
- 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);
}
- psr_ctxt_switch_to(n->domain);
+ psr_ctxt_switch_to(nd);
- gdt = !is_pv_32on64_vcpu(n) ? per_cpu(gdt_table, cpu) :
- per_cpu(compat_gdt_table, cpu);
- if ( need_full_gdt(n) )
+ gdt = !is_pv_32on64_domain(nd) ? per_cpu(gdt_table, cpu) :
+ per_cpu(compat_gdt_table, cpu);
+ if ( need_full_gdt(nd) )
{
unsigned long mfn = virt_to_mfn(gdt);
- l1_pgentry_t *pl1e = gdt_ldt_ptes(n->domain, n);
+ l1_pgentry_t *pl1e = gdt_ldt_ptes(nd, n);
unsigned int i;
for ( i = 0; i < NR_RESERVED_GDT_PAGES; i++ )
@@ -1491,8 +1492,8 @@ static void __context_switch(void)
l1e_from_pfn(mfn + i, __PAGE_HYPERVISOR));
}
- if ( need_full_gdt(p) &&
- ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(n)) )
+ if ( need_full_gdt(pd) &&
+ ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(nd)) )
{
gdt_desc.limit = LAST_RESERVED_GDT_BYTE;
gdt_desc.base = (unsigned long)(gdt - FIRST_RESERVED_GDT_ENTRY);
@@ -1501,16 +1502,16 @@ static void __context_switch(void)
write_ptbase(n);
- if ( need_full_gdt(n) &&
- ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(p)) )
+ if ( need_full_gdt(nd) &&
+ ((p->vcpu_id != n->vcpu_id) || !need_full_gdt(pd)) )
{
gdt_desc.limit = LAST_RESERVED_GDT_BYTE;
gdt_desc.base = GDT_VIRT_START(n);
asm volatile ( "lgdt %0" : : "m" (gdt_desc) );
}
- if ( p->domain != n->domain )
- cpumask_clear_cpu(cpu, p->domain->domain_dirty_cpumask);
+ if ( pd != nd )
+ cpumask_clear_cpu(cpu, pd->domain_dirty_cpumask);
cpumask_clear_cpu(cpu, p->vcpu_dirty_cpumask);
per_cpu(curr_vcpu, cpu) = n;
@@ -1520,6 +1521,7 @@ static void __context_switch(void)
void context_switch(struct vcpu *prev, struct vcpu *next)
{
unsigned int cpu = smp_processor_id();
+ const struct domain *prevd = prev->domain, *nextd = next->domain;
cpumask_t dirty_mask;
ASSERT(local_irq_is_enabled());
@@ -1537,7 +1539,7 @@ void context_switch(struct vcpu *prev, s
if ( prev != next )
_update_runstate_area(prev);
- if ( is_hvm_vcpu(prev) )
+ if ( is_hvm_domain(prevd) )
{
if (prev != next)
vpmu_save(prev);
@@ -1551,7 +1553,7 @@ void context_switch(struct vcpu *prev, s
set_current(next);
if ( (per_cpu(curr_vcpu, cpu) == 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();
- if ( is_pv_vcpu(next) &&
- (is_idle_vcpu(prev) ||
- has_hvm_container_vcpu(prev) ||
- is_pv_32on64_vcpu(prev) != is_pv_32on64_vcpu(next)) )
+ if ( is_pv_domain(nextd) &&
+ (is_idle_domain(prevd) ||
+ has_hvm_container_domain(prevd) ||
+ is_pv_32on64_domain(prevd) != is_pv_32on64_domain(nextd)) )
{
uint64_t efer = 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();
- if ( is_pv_vcpu(next) )
+ if ( is_pv_domain(nextd) )
{
load_LDT(next);
load_segments(next);
}
- 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));
}
- if (is_hvm_vcpu(next) && (prev != next) )
+ if (is_hvm_domain(nextd) && (prev != next) )
/* Must be done with interrupts enabled */
vpmu_load(next);
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 6/6] x86/HAP: prefer is_..._domain() over is_..._vcpu()
2015-06-11 10:15 [PATCH 0/6] prefer is_..._domain() over is_..._vcpu() Jan Beulich
` (4 preceding siblings ...)
2015-06-11 10:22 ` [PATCH 5/6] x86/context‑switch: " Jan Beulich
@ 2015-06-11 10:24 ` Jan Beulich
2015-06-11 10:33 ` [PATCH 0/6] " Andrew Cooper
6 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2015-06-11 10:24 UTC (permalink / raw)
To: xen-devel; +Cc: Tim Deegan
[-- Attachment #1: Type: text/plain, Size: 4790 bytes --]
In hvm_hap_nested_page_fault() latch the current domain alongside the
current vCPU into a local variable, making use of it where possible
also beyond what the title says.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2776,7 +2776,8 @@ int hvm_hap_nested_page_fault(paddr_t gp
p2m_type_t p2mt;
p2m_access_t p2ma;
mfn_t mfn;
- struct vcpu *v = current;
+ struct vcpu *curr = current;
+ struct domain *currd = curr->domain;
struct p2m_domain *p2m;
int rc, fall_through = 0, paged = 0;
int sharing_enomem = 0;
@@ -2786,9 +2787,9 @@ int hvm_hap_nested_page_fault(paddr_t gp
* If this succeeds, all is fine.
* If this fails, inject a nested page fault into the guest.
*/
- if ( nestedhvm_enabled(v->domain)
- && nestedhvm_vcpu_in_guestmode(v)
- && nestedhvm_paging_mode_hap(v) )
+ if ( nestedhvm_enabled(currd)
+ && nestedhvm_vcpu_in_guestmode(curr)
+ && nestedhvm_paging_mode_hap(curr) )
{
int rv;
@@ -2800,7 +2801,7 @@ int hvm_hap_nested_page_fault(paddr_t gp
* the same as for shadow paging.
*/
- rv = nestedhvm_hap_nested_page_fault(v, &gpa,
+ rv = nestedhvm_hap_nested_page_fault(curr, &gpa,
npfec.read_access,
npfec.write_access,
npfec.insn_fetch);
@@ -2830,8 +2831,8 @@ int hvm_hap_nested_page_fault(paddr_t gp
* - 32-bit WinXP (& older Windows) on AMD CPUs for LAPIC accesses,
* - newer Windows (like Server 2012) for HPET accesses.
*/
- if ( !nestedhvm_vcpu_in_guestmode(v)
- && is_hvm_vcpu(v)
+ if ( !nestedhvm_vcpu_in_guestmode(curr)
+ && is_hvm_domain(currd)
&& hvm_mmio_internal(gpa) )
{
if ( !handle_mmio_with_translation(gla, gpa >> PAGE_SHIFT, npfec) )
@@ -2840,7 +2841,7 @@ int hvm_hap_nested_page_fault(paddr_t gp
goto out;
}
- p2m = p2m_get_hostp2m(v->domain);
+ p2m = p2m_get_hostp2m(currd);
mfn = get_gfn_type_access(p2m, gfn, &p2mt, &p2ma,
P2M_ALLOC | (npfec.write_access ? P2M_UNSHARE : 0),
NULL);
@@ -2903,10 +2904,10 @@ int hvm_hap_nested_page_fault(paddr_t gp
(npfec.write_access &&
(p2m_is_discard_write(p2mt) || (p2mt == p2m_mmio_write_dm))) )
{
- put_gfn(p2m->domain, gfn);
+ put_gfn(currd, gfn);
rc = 0;
- if ( unlikely(is_pvh_vcpu(v)) )
+ if ( unlikely(is_pvh_domain(currd)) )
goto out;
if ( !handle_mmio_with_translation(gla, gpa >> PAGE_SHIFT, npfec) )
@@ -2924,7 +2925,7 @@ int hvm_hap_nested_page_fault(paddr_t gp
{
ASSERT(p2m_is_hostp2m(p2m));
sharing_enomem =
- (mem_sharing_unshare_page(p2m->domain, gfn, 0) < 0);
+ (mem_sharing_unshare_page(currd, gfn, 0) < 0);
rc = 1;
goto out_put_gfn;
}
@@ -2939,8 +2940,8 @@ int hvm_hap_nested_page_fault(paddr_t gp
*/
if ( npfec.write_access )
{
- paging_mark_dirty(v->domain, mfn_x(mfn));
- p2m_change_type_one(v->domain, gfn, p2m_ram_logdirty, p2m_ram_rw);
+ paging_mark_dirty(currd, mfn_x(mfn));
+ p2m_change_type_one(currd, gfn, p2m_ram_logdirty, p2m_ram_rw);
}
rc = 1;
goto out_put_gfn;
@@ -2952,28 +2953,28 @@ int hvm_hap_nested_page_fault(paddr_t gp
rc = fall_through;
out_put_gfn:
- put_gfn(p2m->domain, gfn);
+ put_gfn(currd, gfn);
out:
/* All of these are delayed until we exit, since we might
* sleep on event ring wait queues, and we must not hold
* locks in such circumstance */
if ( paged )
- p2m_mem_paging_populate(v->domain, gfn);
+ p2m_mem_paging_populate(currd, gfn);
if ( sharing_enomem )
{
int rv;
- if ( (rv = mem_sharing_notify_enomem(v->domain, gfn, 1)) < 0 )
+ if ( (rv = mem_sharing_notify_enomem(currd, gfn, 1)) < 0 )
{
gdprintk(XENLOG_ERR, "Domain %hu attempt to unshare "
"gfn %lx, ENOMEM and no helper (rc %d)\n",
- v->domain->domain_id, gfn, rv);
+ currd->domain_id, gfn, rv);
/* Crash the domain */
rc = 0;
}
}
if ( req_ptr )
{
- mem_access_send_req(v->domain, req_ptr);
+ mem_access_send_req(currd, req_ptr);
xfree(req_ptr);
}
return rc;
[-- Attachment #2: x86-HAP-nested-PF-latch-domain.patch --]
[-- Type: text/plain, Size: 4840 bytes --]
x86/HAP: prefer is_..._domain() over is_..._vcpu()
In hvm_hap_nested_page_fault() latch the current domain alongside the
current vCPU into a local variable, making use of it where possible
also beyond what the title says.
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2776,7 +2776,8 @@ int hvm_hap_nested_page_fault(paddr_t gp
p2m_type_t p2mt;
p2m_access_t p2ma;
mfn_t mfn;
- struct vcpu *v = current;
+ struct vcpu *curr = current;
+ struct domain *currd = curr->domain;
struct p2m_domain *p2m;
int rc, fall_through = 0, paged = 0;
int sharing_enomem = 0;
@@ -2786,9 +2787,9 @@ int hvm_hap_nested_page_fault(paddr_t gp
* If this succeeds, all is fine.
* If this fails, inject a nested page fault into the guest.
*/
- if ( nestedhvm_enabled(v->domain)
- && nestedhvm_vcpu_in_guestmode(v)
- && nestedhvm_paging_mode_hap(v) )
+ if ( nestedhvm_enabled(currd)
+ && nestedhvm_vcpu_in_guestmode(curr)
+ && nestedhvm_paging_mode_hap(curr) )
{
int rv;
@@ -2800,7 +2801,7 @@ int hvm_hap_nested_page_fault(paddr_t gp
* the same as for shadow paging.
*/
- rv = nestedhvm_hap_nested_page_fault(v, &gpa,
+ rv = nestedhvm_hap_nested_page_fault(curr, &gpa,
npfec.read_access,
npfec.write_access,
npfec.insn_fetch);
@@ -2830,8 +2831,8 @@ int hvm_hap_nested_page_fault(paddr_t gp
* - 32-bit WinXP (& older Windows) on AMD CPUs for LAPIC accesses,
* - newer Windows (like Server 2012) for HPET accesses.
*/
- if ( !nestedhvm_vcpu_in_guestmode(v)
- && is_hvm_vcpu(v)
+ if ( !nestedhvm_vcpu_in_guestmode(curr)
+ && is_hvm_domain(currd)
&& hvm_mmio_internal(gpa) )
{
if ( !handle_mmio_with_translation(gla, gpa >> PAGE_SHIFT, npfec) )
@@ -2840,7 +2841,7 @@ int hvm_hap_nested_page_fault(paddr_t gp
goto out;
}
- p2m = p2m_get_hostp2m(v->domain);
+ p2m = p2m_get_hostp2m(currd);
mfn = get_gfn_type_access(p2m, gfn, &p2mt, &p2ma,
P2M_ALLOC | (npfec.write_access ? P2M_UNSHARE : 0),
NULL);
@@ -2903,10 +2904,10 @@ int hvm_hap_nested_page_fault(paddr_t gp
(npfec.write_access &&
(p2m_is_discard_write(p2mt) || (p2mt == p2m_mmio_write_dm))) )
{
- put_gfn(p2m->domain, gfn);
+ put_gfn(currd, gfn);
rc = 0;
- if ( unlikely(is_pvh_vcpu(v)) )
+ if ( unlikely(is_pvh_domain(currd)) )
goto out;
if ( !handle_mmio_with_translation(gla, gpa >> PAGE_SHIFT, npfec) )
@@ -2924,7 +2925,7 @@ int hvm_hap_nested_page_fault(paddr_t gp
{
ASSERT(p2m_is_hostp2m(p2m));
sharing_enomem =
- (mem_sharing_unshare_page(p2m->domain, gfn, 0) < 0);
+ (mem_sharing_unshare_page(currd, gfn, 0) < 0);
rc = 1;
goto out_put_gfn;
}
@@ -2939,8 +2940,8 @@ int hvm_hap_nested_page_fault(paddr_t gp
*/
if ( npfec.write_access )
{
- paging_mark_dirty(v->domain, mfn_x(mfn));
- p2m_change_type_one(v->domain, gfn, p2m_ram_logdirty, p2m_ram_rw);
+ paging_mark_dirty(currd, mfn_x(mfn));
+ p2m_change_type_one(currd, gfn, p2m_ram_logdirty, p2m_ram_rw);
}
rc = 1;
goto out_put_gfn;
@@ -2952,28 +2953,28 @@ int hvm_hap_nested_page_fault(paddr_t gp
rc = fall_through;
out_put_gfn:
- put_gfn(p2m->domain, gfn);
+ put_gfn(currd, gfn);
out:
/* All of these are delayed until we exit, since we might
* sleep on event ring wait queues, and we must not hold
* locks in such circumstance */
if ( paged )
- p2m_mem_paging_populate(v->domain, gfn);
+ p2m_mem_paging_populate(currd, gfn);
if ( sharing_enomem )
{
int rv;
- if ( (rv = mem_sharing_notify_enomem(v->domain, gfn, 1)) < 0 )
+ if ( (rv = mem_sharing_notify_enomem(currd, gfn, 1)) < 0 )
{
gdprintk(XENLOG_ERR, "Domain %hu attempt to unshare "
"gfn %lx, ENOMEM and no helper (rc %d)\n",
- v->domain->domain_id, gfn, rv);
+ currd->domain_id, gfn, rv);
/* Crash the domain */
rc = 0;
}
}
if ( req_ptr )
{
- mem_access_send_req(v->domain, req_ptr);
+ mem_access_send_req(currd, req_ptr);
xfree(req_ptr);
}
return rc;
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 0/6] prefer is_..._domain() over is_..._vcpu()
2015-06-11 10:15 [PATCH 0/6] prefer is_..._domain() over is_..._vcpu() Jan Beulich
` (5 preceding siblings ...)
2015-06-11 10:24 ` [PATCH 6/6] x86/HAP: " Jan Beulich
@ 2015-06-11 10:33 ` Andrew Cooper
2015-06-11 11:32 ` Jan Beulich
6 siblings, 1 reply; 10+ messages in thread
From: Andrew Cooper @ 2015-06-11 10:33 UTC (permalink / raw)
To: Jan Beulich, xen-devel
On 11/06/15 11:15, Jan Beulich wrote:
> ... when the domain pointer is already available or such operations occur
> frequently in a function. There's no particular ordering requirement
> between the individual patches, they only all do the same thing to
> different areas of code.
>
> 1: domctl: prefer is_..._domain() over is_..._vcpu()
> 2: x86: prefer is_..._domain() over is_..._vcpu()
> 3: x86/HVM: prefer is_..._domain() over is_..._vcpu()
> 4: x86/mm: prefer is_..._domain() over is_..._vcpu()
> 5: x86/context-switch: prefer is_..._domain() over is_..._vcpu()
> 6: x86/HAP: prefer is_..._domain() over is_..._vcpu()
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
The entire series, Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
With two further suggestions:
Patch 2:
> --- a/xen/arch/x86/traps.c
> +++ b/xen/arch/x86/traps.c
> @@ -798,7 +798,7 @@ int cpuid_hypervisor_leaves( uint32_t id
> *ebx = 0x40000200;
> *ecx = 0; /* Features 1 */
> *edx = 0; /* Features 2 */
> - if ( is_pv_vcpu(current) )
> + if ( is_pv_domain(d) )
> *ecx |= XEN_CPUID_FEAT1_MMU_PT_UPDATE_PRESERVE_AD;
> break;
It would be clearer to s/d/currd/ in this functions. It won't make the
patch much larger.
Patch 5:
> --- 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 = 1;
> }
>
> -static inline int need_full_gdt(struct vcpu *v)
> +static inline int need_full_gdt(const struct domain *d)
As you area already changing this, you might as well switch int for bool_t.
~Andrew
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 0/6] prefer is_..._domain() over is_..._vcpu()
2015-06-11 10:33 ` [PATCH 0/6] " Andrew Cooper
@ 2015-06-11 11:32 ` Jan Beulich
0 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2015-06-11 11:32 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel
>>> On 11.06.15 at 12:33, <andrew.cooper3@citrix.com> wrote:
> On 11/06/15 11:15, Jan Beulich wrote:
>> ... when the domain pointer is already available or such operations occur
>> frequently in a function. There's no particular ordering requirement
>> between the individual patches, they only all do the same thing to
>> different areas of code.
>>
>> 1: domctl: prefer is_..._domain() over is_..._vcpu()
>> 2: x86: prefer is_..._domain() over is_..._vcpu()
>> 3: x86/HVM: prefer is_..._domain() over is_..._vcpu()
>> 4: x86/mm: prefer is_..._domain() over is_..._vcpu()
>> 5: x86/context-switch: prefer is_..._domain() over is_..._vcpu()
>> 6: x86/HAP: prefer is_..._domain() over is_..._vcpu()
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> The entire series, Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
>
> With two further suggestions:
Thanks, both carried out.
Jan
^ permalink raw reply [flat|nested] 10+ messages in thread