# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1195230120 0
# Node ID ef4b60c99735c883394270dcf4acd09633fac01c
# Parent 79d050b2b35e472c0874443ceccf31cd65103571
x86, hvm: Small code cleanups.
Based on patch from Xin Li.
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
---
xen/arch/x86/hvm/hvm.c | 10 ++---
xen/arch/x86/hvm/vmx/vmx.c | 76 +++++++++++++++++++++------------------------
2 files changed, 42 insertions(+), 44 deletions(-)
diff -r 79d050b2b35e -r ef4b60c99735 xen/arch/x86/hvm/hvm.c
--- a/xen/arch/x86/hvm/hvm.c Fri Nov 16 14:45:35 2007 +0000
+++ b/xen/arch/x86/hvm/hvm.c Fri Nov 16 16:22:00 2007 +0000
@@ -667,7 +667,7 @@ int hvm_set_cr0(unsigned long value)
struct vcpu *v = current;
p2m_type_t p2mt;
unsigned long gfn, mfn, old_value = v->arch.hvm_vcpu.guest_cr[0];
-
+
HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR0 value = %lx", value);
if ( (u32)value != value )
@@ -684,7 +684,7 @@ int hvm_set_cr0(unsigned long value)
/* ET is reserved and should be always be 1. */
value |= X86_CR0_ET;
- if ( (value & (X86_CR0_PE|X86_CR0_PG)) == X86_CR0_PG )
+ if ( (value & (X86_CR0_PE | X86_CR0_PG)) == X86_CR0_PG )
{
hvm_inject_exception(TRAP_gp_fault, 0, 0);
return 0;
@@ -710,10 +710,10 @@ int hvm_set_cr0(unsigned long value)
/* The guest CR3 must be pointing to the guest physical. */
gfn = v->arch.hvm_vcpu.guest_cr[3]>>PAGE_SHIFT;
mfn = mfn_x(gfn_to_mfn_current(gfn, &p2mt));
- if ( !p2m_is_ram(p2mt) || !mfn_valid(mfn) ||
+ if ( !p2m_is_ram(p2mt) || !mfn_valid(mfn) ||
!get_page(mfn_to_page(mfn), v->domain))
{
- gdprintk(XENLOG_ERR, "Invalid CR3 value = %lx (mfn=%lx)\n",
+ gdprintk(XENLOG_ERR, "Invalid CR3 value = %lx (mfn=%lx)\n",
v->arch.hvm_vcpu.guest_cr[3], mfn);
domain_crash(v->domain);
return 0;
@@ -742,7 +742,7 @@ int hvm_set_cr0(unsigned long value)
}
}
- if ( !list_empty(&(domain_hvm_iommu(v->domain)->pdev_list)) )
+ if ( !list_empty(&domain_hvm_iommu(v->domain)->pdev_list) )
{
if ( (value & X86_CR0_CD) && !(value & X86_CR0_NW) )
{
diff -r 79d050b2b35e -r ef4b60c99735 xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c Fri Nov 16 14:45:35 2007 +0000
+++ b/xen/arch/x86/hvm/vmx/vmx.c Fri Nov 16 16:22:00 2007 +0000
@@ -518,10 +518,36 @@ void vmx_vmcs_save(struct vcpu *v, struc
vmx_vmcs_exit(v);
}
-int vmx_vmcs_restore(struct vcpu *v, struct hvm_hw_cpu *c)
+static int vmx_restore_cr0_cr3(
+ struct vcpu *v, unsigned long cr0, unsigned long cr3)
{
unsigned long mfn = 0;
p2m_type_t p2mt;
+
+ if ( cr0 & X86_CR0_PG )
+ {
+ mfn = mfn_x(gfn_to_mfn(v->domain, cr3 >> PAGE_SHIFT, &p2mt));
+ if ( !p2m_is_ram(p2mt) || !get_page(mfn_to_page(mfn), v->domain) )
+ {
+ gdprintk(XENLOG_ERR, "Invalid CR3 value=0x%lx\n", cr3);
+ return -EINVAL;
+ }
+ }
+
+ if ( v->arch.hvm_vcpu.guest_cr[0] & X86_CR0_PG )
+ put_page(pagetable_get_page(v->arch.guest_table));
+
+ v->arch.guest_table = pagetable_from_pfn(mfn);
+
+ v->arch.hvm_vcpu.guest_cr[0] = cr0 | X86_CR0_ET;
+ v->arch.hvm_vcpu.guest_cr[3] = cr3;
+
+ return 0;
+}
+
+int vmx_vmcs_restore(struct vcpu *v, struct hvm_hw_cpu *c)
+{
+ int rc;
if ( c->pending_valid &&
((c->pending_type == 1) || (c->pending_type > 6) ||
@@ -532,26 +558,13 @@ int vmx_vmcs_restore(struct vcpu *v, str
return -EINVAL;
}
- if ( c->cr0 & X86_CR0_PG )
- {
- mfn = mfn_x(gfn_to_mfn(v->domain, c->cr3 >> PAGE_SHIFT, &p2mt));
- if ( !p2m_is_ram(p2mt) || !get_page(mfn_to_page(mfn), v->domain) )
- {
- gdprintk(XENLOG_ERR, "Invalid CR3 value=0x%"PRIx64"\n", c->cr3);
- return -EINVAL;
- }
- }
-
- if ( v->arch.hvm_vcpu.guest_cr[0] & X86_CR0_PG )
- put_page(pagetable_get_page(v->arch.guest_table));
-
- v->arch.guest_table = pagetable_from_pfn(mfn);
+ rc = vmx_restore_cr0_cr3(v, c->cr0, c->cr3);
+ if ( rc )
+ return rc;
vmx_vmcs_enter(v);
- v->arch.hvm_vcpu.guest_cr[0] = c->cr0 | X86_CR0_ET;
v->arch.hvm_vcpu.guest_cr[2] = c->cr2;
- v->arch.hvm_vcpu.guest_cr[3] = c->cr3;
v->arch.hvm_vcpu.guest_cr[4] = c->cr4;
vmx_update_guest_cr(v, 0);
vmx_update_guest_cr(v, 2);
@@ -1846,30 +1859,16 @@ static int vmx_world_restore(struct vcpu
static int vmx_world_restore(struct vcpu *v, struct vmx_assist_context *c)
{
struct cpu_user_regs *regs = guest_cpu_user_regs();
- unsigned long mfn = 0;
- p2m_type_t p2mt;
-
- if ( c->cr0 & X86_CR0_PG )
- {
- mfn = mfn_x(gfn_to_mfn(v->domain, c->cr3 >> PAGE_SHIFT, &p2mt));
- if ( !p2m_is_ram(p2mt) || !get_page(mfn_to_page(mfn), v->domain) )
- {
- gdprintk(XENLOG_ERR, "Invalid CR3 value=%x", c->cr3);
- return -EINVAL;
- }
- }
-
- if ( v->arch.hvm_vcpu.guest_cr[0] & X86_CR0_PG )
- put_page(pagetable_get_page(v->arch.guest_table));
-
- v->arch.guest_table = pagetable_from_pfn(mfn);
+ int rc;
+
+ rc = vmx_restore_cr0_cr3(v, c->cr0, c->cr3);
+ if ( rc )
+ return rc;
regs->eip = c->eip;
regs->esp = c->esp;
regs->eflags = c->eflags | 2;
- v->arch.hvm_vcpu.guest_cr[0] = c->cr0;
- v->arch.hvm_vcpu.guest_cr[3] = c->cr3;
v->arch.hvm_vcpu.guest_cr[4] = c->cr4;
vmx_update_guest_cr(v, 0);
vmx_update_guest_cr(v, 4);
@@ -2016,9 +2015,8 @@ static int vmx_set_cr0(unsigned long val
static int vmx_set_cr0(unsigned long value)
{
struct vcpu *v = current;
- int rc = hvm_set_cr0(value);
-
- if ( rc == 0 )
+
+ if ( hvm_set_cr0(value) == 0 )
return 0;
/*
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|