diff options
author | Joerg Roedel <joerg.roedel@amd.com> | 2010-11-30 12:03:59 -0500 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-01-12 04:30:13 -0500 |
commit | 18c918c5f59bc35f9c567689daef8c255b575fdc (patch) | |
tree | f4b24acd45fa8c92b4579feeaf98461c4bcc9660 /arch/x86/kvm/svm.c | |
parent | 3aed041a4c1b78cac87db76cf264b081df64dd37 (diff) |
KVM: SVM: Add manipulation functions for exception intercepts
This patch wraps changes to the exception intercepts of SVM
into seperate functions to abstract nested-svm better and
prepare the implementation of the vmcb-clean-bits feature.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch/x86/kvm/svm.c')
-rw-r--r-- | arch/x86/kvm/svm.c | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index a7c38eb9d2e3..d69ec44143c0 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c | |||
@@ -259,6 +259,24 @@ static inline void clr_dr_intercept(struct vcpu_svm *svm, int bit) | |||
259 | recalc_intercepts(svm); | 259 | recalc_intercepts(svm); |
260 | } | 260 | } |
261 | 261 | ||
262 | static inline void set_exception_intercept(struct vcpu_svm *svm, int bit) | ||
263 | { | ||
264 | struct vmcb *vmcb = get_host_vmcb(svm); | ||
265 | |||
266 | vmcb->control.intercept_exceptions |= (1U << bit); | ||
267 | |||
268 | recalc_intercepts(svm); | ||
269 | } | ||
270 | |||
271 | static inline void clr_exception_intercept(struct vcpu_svm *svm, int bit) | ||
272 | { | ||
273 | struct vmcb *vmcb = get_host_vmcb(svm); | ||
274 | |||
275 | vmcb->control.intercept_exceptions &= ~(1U << bit); | ||
276 | |||
277 | recalc_intercepts(svm); | ||
278 | } | ||
279 | |||
262 | static inline void enable_gif(struct vcpu_svm *svm) | 280 | static inline void enable_gif(struct vcpu_svm *svm) |
263 | { | 281 | { |
264 | svm->vcpu.arch.hflags |= HF_GIF_MASK; | 282 | svm->vcpu.arch.hflags |= HF_GIF_MASK; |
@@ -841,10 +859,9 @@ static void init_vmcb(struct vcpu_svm *svm) | |||
841 | set_dr_intercept(svm, INTERCEPT_DR6_WRITE); | 859 | set_dr_intercept(svm, INTERCEPT_DR6_WRITE); |
842 | set_dr_intercept(svm, INTERCEPT_DR7_WRITE); | 860 | set_dr_intercept(svm, INTERCEPT_DR7_WRITE); |
843 | 861 | ||
844 | control->intercept_exceptions = (1 << PF_VECTOR) | | 862 | set_exception_intercept(svm, PF_VECTOR); |
845 | (1 << UD_VECTOR) | | 863 | set_exception_intercept(svm, UD_VECTOR); |
846 | (1 << MC_VECTOR); | 864 | set_exception_intercept(svm, MC_VECTOR); |
847 | |||
848 | 865 | ||
849 | control->intercept = (1ULL << INTERCEPT_INTR) | | 866 | control->intercept = (1ULL << INTERCEPT_INTR) | |
850 | (1ULL << INTERCEPT_NMI) | | 867 | (1ULL << INTERCEPT_NMI) | |
@@ -921,7 +938,7 @@ static void init_vmcb(struct vcpu_svm *svm) | |||
921 | control->nested_ctl = 1; | 938 | control->nested_ctl = 1; |
922 | control->intercept &= ~((1ULL << INTERCEPT_TASK_SWITCH) | | 939 | control->intercept &= ~((1ULL << INTERCEPT_TASK_SWITCH) | |
923 | (1ULL << INTERCEPT_INVLPG)); | 940 | (1ULL << INTERCEPT_INVLPG)); |
924 | control->intercept_exceptions &= ~(1 << PF_VECTOR); | 941 | clr_exception_intercept(svm, PF_VECTOR); |
925 | clr_cr_intercept(svm, INTERCEPT_CR3_READ); | 942 | clr_cr_intercept(svm, INTERCEPT_CR3_READ); |
926 | clr_cr_intercept(svm, INTERCEPT_CR3_WRITE); | 943 | clr_cr_intercept(svm, INTERCEPT_CR3_WRITE); |
927 | save->g_pat = 0x0007040600070406ULL; | 944 | save->g_pat = 0x0007040600070406ULL; |
@@ -1382,20 +1399,18 @@ static void update_db_intercept(struct kvm_vcpu *vcpu) | |||
1382 | { | 1399 | { |
1383 | struct vcpu_svm *svm = to_svm(vcpu); | 1400 | struct vcpu_svm *svm = to_svm(vcpu); |
1384 | 1401 | ||
1385 | svm->vmcb->control.intercept_exceptions &= | 1402 | clr_exception_intercept(svm, DB_VECTOR); |
1386 | ~((1 << DB_VECTOR) | (1 << BP_VECTOR)); | 1403 | clr_exception_intercept(svm, BP_VECTOR); |
1387 | 1404 | ||
1388 | if (svm->nmi_singlestep) | 1405 | if (svm->nmi_singlestep) |
1389 | svm->vmcb->control.intercept_exceptions |= (1 << DB_VECTOR); | 1406 | set_exception_intercept(svm, DB_VECTOR); |
1390 | 1407 | ||
1391 | if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) { | 1408 | if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) { |
1392 | if (vcpu->guest_debug & | 1409 | if (vcpu->guest_debug & |
1393 | (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP)) | 1410 | (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP)) |
1394 | svm->vmcb->control.intercept_exceptions |= | 1411 | set_exception_intercept(svm, DB_VECTOR); |
1395 | 1 << DB_VECTOR; | ||
1396 | if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) | 1412 | if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) |
1397 | svm->vmcb->control.intercept_exceptions |= | 1413 | set_exception_intercept(svm, BP_VECTOR); |
1398 | 1 << BP_VECTOR; | ||
1399 | } else | 1414 | } else |
1400 | vcpu->guest_debug = 0; | 1415 | vcpu->guest_debug = 0; |
1401 | } | 1416 | } |
@@ -1516,21 +1531,8 @@ static int ud_interception(struct vcpu_svm *svm) | |||
1516 | static void svm_fpu_activate(struct kvm_vcpu *vcpu) | 1531 | static void svm_fpu_activate(struct kvm_vcpu *vcpu) |
1517 | { | 1532 | { |
1518 | struct vcpu_svm *svm = to_svm(vcpu); | 1533 | struct vcpu_svm *svm = to_svm(vcpu); |
1519 | u32 excp; | ||
1520 | |||
1521 | if (is_guest_mode(vcpu)) { | ||
1522 | u32 h_excp, n_excp; | ||
1523 | 1534 | ||
1524 | h_excp = svm->nested.hsave->control.intercept_exceptions; | 1535 | clr_exception_intercept(svm, NM_VECTOR); |
1525 | n_excp = svm->nested.intercept_exceptions; | ||
1526 | h_excp &= ~(1 << NM_VECTOR); | ||
1527 | excp = h_excp | n_excp; | ||
1528 | } else { | ||
1529 | excp = svm->vmcb->control.intercept_exceptions; | ||
1530 | excp &= ~(1 << NM_VECTOR); | ||
1531 | } | ||
1532 | |||
1533 | svm->vmcb->control.intercept_exceptions = excp; | ||
1534 | 1536 | ||
1535 | svm->vcpu.fpu_active = 1; | 1537 | svm->vcpu.fpu_active = 1; |
1536 | update_cr0_intercept(svm); | 1538 | update_cr0_intercept(svm); |
@@ -3643,9 +3645,7 @@ static void svm_fpu_deactivate(struct kvm_vcpu *vcpu) | |||
3643 | { | 3645 | { |
3644 | struct vcpu_svm *svm = to_svm(vcpu); | 3646 | struct vcpu_svm *svm = to_svm(vcpu); |
3645 | 3647 | ||
3646 | svm->vmcb->control.intercept_exceptions |= 1 << NM_VECTOR; | 3648 | set_exception_intercept(svm, NM_VECTOR); |
3647 | if (is_guest_mode(vcpu)) | ||
3648 | svm->nested.hsave->control.intercept_exceptions |= 1 << NM_VECTOR; | ||
3649 | update_cr0_intercept(svm); | 3649 | update_cr0_intercept(svm); |
3650 | } | 3650 | } |
3651 | 3651 | ||