|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v1 1/2] x86/nestedsvm: Handle CR8 accesses with V_INTR_MASKING=0 correctly
When V_INTR_MASKING=0, reads return the value in the APIC TPR and writes
update the value in the APIC TPR and the V_TPR.
To implement this for Nested SVM, intercept reads and writes of CR8 when
V_INTR_MASKING=0. For reads, simply return the value in Xen's emulated
APIC. For writes, update the value in the emulated APIC as well as
VMCB(0-2)'s V_TPR.
Signed-off-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
---
xen/arch/x86/hvm/emulate.c | 1 +
xen/arch/x86/hvm/hvm.c | 1 +
xen/arch/x86/hvm/svm/nestedsvm.c | 3 +++
xen/arch/x86/hvm/svm/svm.c | 30 ++++++++++++++++++------------
xen/arch/x86/hvm/vmx/vmx.c | 4 ++++
5 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c
index cd2831d34b44..57e1fa7e5a2a 100644
--- a/xen/arch/x86/hvm/emulate.c
+++ b/xen/arch/x86/hvm/emulate.c
@@ -2376,6 +2376,7 @@ static int cf_check hvmemul_write_cr(
}
vlapic_set_reg(vcpu_vlapic(curr), APIC_TASKPRI, val << 4);
+ hvm_update_guest_cr(curr, 8);
rc = X86EMUL_OKAY;
break;
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 4334ff678d34..6a2a76339be1 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -2205,6 +2205,7 @@ int hvm_mov_to_cr(unsigned int cr, unsigned int gpr)
case 8:
vlapic_set_reg(vcpu_vlapic(curr), APIC_TASKPRI, ((val & 0x0f) << 4));
+ hvm_update_guest_cr(curr, cr);
rc = X86EMUL_OKAY;
break;
diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 366178ff54a7..eeb9363dc061 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -394,6 +394,9 @@ static int nsvm_vmcb_prepare4vmrun(struct vcpu *v, struct
cpu_user_regs *regs)
n2vmcb->_cr_intercepts =
n1vmcb->_cr_intercepts | ns_vmcb->_cr_intercepts;
+ if ( !svm->ns_hostflags.vintrmask )
+ n2vmcb->_cr_intercepts |=
+ CR_INTERCEPT_CR8_READ | CR_INTERCEPT_CR8_WRITE;
n2vmcb->_dr_intercepts =
n1vmcb->_dr_intercepts | ns_vmcb->_dr_intercepts;
n2vmcb->_exception_intercepts =
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index bfca1eda4af5..1043f4a988a8 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -104,6 +104,15 @@ static void cf_check svm_cpu_down(void)
write_efer(read_efer() & ~EFER_SVME);
}
+static void svm_update_tpr(struct vmcb *vmcb, struct vlapic *vlapic)
+{
+ /* Reflect the vlapic's TPR in the hardware vtpr */
+ vintr_t intr = vmcb_get_vintr(vmcb);
+
+ intr.tpr = (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
+ vmcb_set_vintr(vmcb, intr);
+}
+
static void cf_check svm_update_guest_cr(
struct vcpu *v, unsigned int cr, unsigned int flags)
{
@@ -170,6 +179,13 @@ static void cf_check svm_update_guest_cr(
vmcb_set_cr4(vmcb, value);
break;
+
+ case 8:
+ if ( nestedhvm_vcpu_in_guestmode(v) &&
+ !vcpu_nestedsvm(v).ns_hostflags.vintrmask )
+ svm_update_tpr(vmcb, vcpu_vlapic(v));
+ break;
+
default:
BUG();
}
@@ -959,14 +975,7 @@ static void noreturn cf_check svm_do_resume(void)
}
if ( !vcpu_guestmode && !vlapic_hw_disabled(vlapic) )
- {
- vintr_t intr;
-
- /* Reflect the vlapic's TPR in the hardware vtpr */
- intr = vmcb_get_vintr(vmcb);
- intr.tpr = (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
- vmcb_set_vintr(vmcb, intr);
- }
+ svm_update_tpr(vmcb, vlapic);
hvm_do_resume(v);
@@ -3069,10 +3078,7 @@ void asmlinkage svm_vmexit_handler(void)
if ( vcpu_guestmode || vlapic_hw_disabled(vlapic) )
return;
- /* The exit may have updated the TPR: reflect this in the hardware vtpr */
- intr = vmcb_get_vintr(vmcb);
- intr.tpr = (vlapic_get_reg(vlapic, APIC_TASKPRI) & 0xFF) >> 4;
- vmcb_set_vintr(vmcb, intr);
+ svm_update_tpr(vmcb, vlapic);
}
/*
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 3c7374a9ff42..53d50a1bb329 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1874,6 +1874,10 @@ static void cf_check vmx_update_guest_cr(
hvm_asid_flush_vcpu(v);
break;
+ case 8:
+ /* Nothing to do */
+ break;
+
default:
BUG();
}
--
2.56.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |