KVM: SVM: Modify intercept_exceptions to generic intercepts
authorBabu Moger <babu.moger@amd.com>
Fri, 11 Sep 2020 19:28:20 +0000 (14:28 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 28 Sep 2020 11:57:14 +0000 (07:57 -0400)
Modify intercept_exceptions to generic intercepts in vmcb_control_area. Use
the generic vmcb_set_intercept, vmcb_clr_intercept and vmcb_is_intercept to
set/clear/test the intercept_exceptions bits.

Signed-off-by: Babu Moger <babu.moger@amd.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
Message-Id: <159985250037.11252.1361972528657052410.stgit@bmoger-ubuntu>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/svm.h
arch/x86/kvm/svm/nested.c
arch/x86/kvm/svm/svm.c
arch/x86/kvm/svm/svm.h

index 80a4db25e4244bf38b9b3814d2317ddfe74a90c3..caf7a63d65aaf05e4ec8e7c09c005eae1f1c28ba 100644 (file)
@@ -3,6 +3,7 @@
 #define __SVM_H
 
 #include <uapi/asm/svm.h>
+#include <uapi/asm/kvm.h>
 
 /*
  * 32-bit intercept words in the VMCB Control Area, starting
@@ -12,6 +13,7 @@
 enum intercept_words {
        INTERCEPT_CR = 0,
        INTERCEPT_DR,
+       INTERCEPT_EXCEPTION,
        MAX_INTERCEPT,
 };
 
@@ -42,6 +44,8 @@ enum {
        INTERCEPT_DR5_WRITE,
        INTERCEPT_DR6_WRITE,
        INTERCEPT_DR7_WRITE,
+       /* Byte offset 008h (word 2) */
+       INTERCEPT_EXCEPTION_OFFSET = 64,
 };
 
 enum {
@@ -97,7 +101,6 @@ enum {
 
 struct __attribute__ ((__packed__)) vmcb_control_area {
        u32 intercepts[MAX_INTERCEPT];
-       u32 intercept_exceptions;
        u64 intercept;
        u8 reserved_1[40];
        u16 pause_filter_thresh;
index 012ab2255b3c2d9af0ee3470d35fdfcdb28c888d..e9e6ad7fdbbe0c4b525d36c179e518d98564d9b9 100644 (file)
@@ -112,7 +112,6 @@ void recalc_intercepts(struct vcpu_svm *svm)
        for (i = 0; i < MAX_INTERCEPT; i++)
                c->intercepts[i] = h->intercepts[i];
 
-       c->intercept_exceptions = h->intercept_exceptions;
        c->intercept = h->intercept;
 
        if (g->int_ctl & V_INTR_MASKING_MASK) {
@@ -134,7 +133,6 @@ void recalc_intercepts(struct vcpu_svm *svm)
        for (i = 0; i < MAX_INTERCEPT; i++)
                c->intercepts[i] |= g->intercepts[i];
 
-       c->intercept_exceptions |= g->intercept_exceptions;
        c->intercept |= g->intercept;
 }
 
@@ -146,7 +144,6 @@ static void copy_vmcb_control_area(struct vmcb_control_area *dst,
        for (i = 0; i < MAX_INTERCEPT; i++)
                dst->intercepts[i] = from->intercepts[i];
 
-       dst->intercept_exceptions = from->intercept_exceptions;
        dst->intercept            = from->intercept;
        dst->iopm_base_pa         = from->iopm_base_pa;
        dst->msrpm_base_pa        = from->msrpm_base_pa;
@@ -491,7 +488,7 @@ int nested_svm_vmrun(struct vcpu_svm *svm)
 
        trace_kvm_nested_intercepts(vmcb12->control.intercepts[INTERCEPT_CR] & 0xffff,
                                    vmcb12->control.intercepts[INTERCEPT_CR] >> 16,
-                                   vmcb12->control.intercept_exceptions,
+                                   vmcb12->control.intercepts[INTERCEPT_EXCEPTION],
                                    vmcb12->control.intercept);
 
        /* Clear internal status */
@@ -833,7 +830,7 @@ static bool nested_exit_on_exception(struct vcpu_svm *svm)
 {
        unsigned int nr = svm->vcpu.arch.exception.nr;
 
-       return (svm->nested.ctl.intercept_exceptions & (1 << nr));
+       return (svm->nested.ctl.intercepts[INTERCEPT_EXCEPTION] & BIT(nr));
 }
 
 static void nested_svm_inject_exception_vmexit(struct vcpu_svm *svm)
@@ -982,7 +979,8 @@ int nested_svm_exit_special(struct vcpu_svm *svm)
        case SVM_EXIT_EXCP_BASE ... SVM_EXIT_EXCP_BASE + 0x1f: {
                u32 excp_bits = 1 << (exit_code - SVM_EXIT_EXCP_BASE);
 
-               if (get_host_vmcb(svm)->control.intercept_exceptions & excp_bits)
+               if (get_host_vmcb(svm)->control.intercepts[INTERCEPT_EXCEPTION] &
+                               excp_bits)
                        return NESTED_EXIT_HOST;
                else if (exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR &&
                         svm->vcpu.arch.apf.host_apf_flags)
index 07a0804d4fe76a53b97eeda550b9abc1efabd4b2..c37d64fb05ff7ab671f3cf42ba70ebffe4e2a839 100644 (file)
@@ -2816,7 +2816,7 @@ static void dump_vmcb(struct kvm_vcpu *vcpu)
        pr_err("%-20s%04x\n", "cr_write:", control->intercepts[INTERCEPT_CR] >> 16);
        pr_err("%-20s%04x\n", "dr_read:", control->intercepts[INTERCEPT_DR] & 0xffff);
        pr_err("%-20s%04x\n", "dr_write:", control->intercepts[INTERCEPT_DR] >> 16);
-       pr_err("%-20s%08x\n", "exceptions:", control->intercept_exceptions);
+       pr_err("%-20s%08x\n", "exceptions:", control->intercepts[INTERCEPT_EXCEPTION]);
        pr_err("%-20s%016llx\n", "intercepts:", control->intercept);
        pr_err("%-20s%d\n", "pause filter count:", control->pause_filter_count);
        pr_err("%-20s%d\n", "pause filter threshold:",
index 2f54829c9ad64f7d2010c8beb65eee0c52d79746..65c054994776822b4985178538859a974872c014 100644 (file)
@@ -289,20 +289,22 @@ static inline void clr_dr_intercepts(struct vcpu_svm *svm)
        recalc_intercepts(svm);
 }
 
-static inline void set_exception_intercept(struct vcpu_svm *svm, int bit)
+static inline void set_exception_intercept(struct vcpu_svm *svm, u32 bit)
 {
        struct vmcb *vmcb = get_host_vmcb(svm);
 
-       vmcb->control.intercept_exceptions |= (1U << bit);
+       WARN_ON_ONCE(bit >= 32);
+       vmcb_set_intercept(&vmcb->control, INTERCEPT_EXCEPTION_OFFSET + bit);
 
        recalc_intercepts(svm);
 }
 
-static inline void clr_exception_intercept(struct vcpu_svm *svm, int bit)
+static inline void clr_exception_intercept(struct vcpu_svm *svm, u32 bit)
 {
        struct vmcb *vmcb = get_host_vmcb(svm);
 
-       vmcb->control.intercept_exceptions &= ~(1U << bit);
+       WARN_ON_ONCE(bit >= 32);
+       vmcb_clr_intercept(&vmcb->control, INTERCEPT_EXCEPTION_OFFSET + bit);
 
        recalc_intercepts(svm);
 }