Commit 9780d51d authored by Babu Moger's avatar Babu Moger Committed by Paolo Bonzini

KVM: SVM: Modify intercept_exceptions to generic intercepts

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: default avatarBabu Moger <babu.moger@amd.com>
Reviewed-by: default avatarJim Mattson <jmattson@google.com>
Message-Id: <159985250037.11252.1361972528657052410.stgit@bmoger-ubuntu>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 30abaa88
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#define __SVM_H #define __SVM_H
#include <uapi/asm/svm.h> #include <uapi/asm/svm.h>
#include <uapi/asm/kvm.h>
/* /*
* 32-bit intercept words in the VMCB Control Area, starting * 32-bit intercept words in the VMCB Control Area, starting
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
enum intercept_words { enum intercept_words {
INTERCEPT_CR = 0, INTERCEPT_CR = 0,
INTERCEPT_DR, INTERCEPT_DR,
INTERCEPT_EXCEPTION,
MAX_INTERCEPT, MAX_INTERCEPT,
}; };
...@@ -42,6 +44,8 @@ enum { ...@@ -42,6 +44,8 @@ enum {
INTERCEPT_DR5_WRITE, INTERCEPT_DR5_WRITE,
INTERCEPT_DR6_WRITE, INTERCEPT_DR6_WRITE,
INTERCEPT_DR7_WRITE, INTERCEPT_DR7_WRITE,
/* Byte offset 008h (word 2) */
INTERCEPT_EXCEPTION_OFFSET = 64,
}; };
enum { enum {
...@@ -97,7 +101,6 @@ enum { ...@@ -97,7 +101,6 @@ enum {
struct __attribute__ ((__packed__)) vmcb_control_area { struct __attribute__ ((__packed__)) vmcb_control_area {
u32 intercepts[MAX_INTERCEPT]; u32 intercepts[MAX_INTERCEPT];
u32 intercept_exceptions;
u64 intercept; u64 intercept;
u8 reserved_1[40]; u8 reserved_1[40];
u16 pause_filter_thresh; u16 pause_filter_thresh;
......
...@@ -112,7 +112,6 @@ void recalc_intercepts(struct vcpu_svm *svm) ...@@ -112,7 +112,6 @@ void recalc_intercepts(struct vcpu_svm *svm)
for (i = 0; i < MAX_INTERCEPT; i++) for (i = 0; i < MAX_INTERCEPT; i++)
c->intercepts[i] = h->intercepts[i]; c->intercepts[i] = h->intercepts[i];
c->intercept_exceptions = h->intercept_exceptions;
c->intercept = h->intercept; c->intercept = h->intercept;
if (g->int_ctl & V_INTR_MASKING_MASK) { if (g->int_ctl & V_INTR_MASKING_MASK) {
...@@ -134,7 +133,6 @@ void recalc_intercepts(struct vcpu_svm *svm) ...@@ -134,7 +133,6 @@ void recalc_intercepts(struct vcpu_svm *svm)
for (i = 0; i < MAX_INTERCEPT; i++) for (i = 0; i < MAX_INTERCEPT; i++)
c->intercepts[i] |= g->intercepts[i]; c->intercepts[i] |= g->intercepts[i];
c->intercept_exceptions |= g->intercept_exceptions;
c->intercept |= g->intercept; c->intercept |= g->intercept;
} }
...@@ -146,7 +144,6 @@ static void copy_vmcb_control_area(struct vmcb_control_area *dst, ...@@ -146,7 +144,6 @@ static void copy_vmcb_control_area(struct vmcb_control_area *dst,
for (i = 0; i < MAX_INTERCEPT; i++) for (i = 0; i < MAX_INTERCEPT; i++)
dst->intercepts[i] = from->intercepts[i]; dst->intercepts[i] = from->intercepts[i];
dst->intercept_exceptions = from->intercept_exceptions;
dst->intercept = from->intercept; dst->intercept = from->intercept;
dst->iopm_base_pa = from->iopm_base_pa; dst->iopm_base_pa = from->iopm_base_pa;
dst->msrpm_base_pa = from->msrpm_base_pa; dst->msrpm_base_pa = from->msrpm_base_pa;
...@@ -491,7 +488,7 @@ int nested_svm_vmrun(struct vcpu_svm *svm) ...@@ -491,7 +488,7 @@ int nested_svm_vmrun(struct vcpu_svm *svm)
trace_kvm_nested_intercepts(vmcb12->control.intercepts[INTERCEPT_CR] & 0xffff, trace_kvm_nested_intercepts(vmcb12->control.intercepts[INTERCEPT_CR] & 0xffff,
vmcb12->control.intercepts[INTERCEPT_CR] >> 16, vmcb12->control.intercepts[INTERCEPT_CR] >> 16,
vmcb12->control.intercept_exceptions, vmcb12->control.intercepts[INTERCEPT_EXCEPTION],
vmcb12->control.intercept); vmcb12->control.intercept);
/* Clear internal status */ /* Clear internal status */
...@@ -833,7 +830,7 @@ static bool nested_exit_on_exception(struct vcpu_svm *svm) ...@@ -833,7 +830,7 @@ static bool nested_exit_on_exception(struct vcpu_svm *svm)
{ {
unsigned int nr = svm->vcpu.arch.exception.nr; 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) static void nested_svm_inject_exception_vmexit(struct vcpu_svm *svm)
...@@ -982,7 +979,8 @@ int nested_svm_exit_special(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: { case SVM_EXIT_EXCP_BASE ... SVM_EXIT_EXCP_BASE + 0x1f: {
u32 excp_bits = 1 << (exit_code - SVM_EXIT_EXCP_BASE); 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; return NESTED_EXIT_HOST;
else if (exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR && else if (exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR &&
svm->vcpu.arch.apf.host_apf_flags) svm->vcpu.arch.apf.host_apf_flags)
......
...@@ -2816,7 +2816,7 @@ static void dump_vmcb(struct kvm_vcpu *vcpu) ...@@ -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", "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_read:", control->intercepts[INTERCEPT_DR] & 0xffff);
pr_err("%-20s%04x\n", "dr_write:", control->intercepts[INTERCEPT_DR] >> 16); 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%016llx\n", "intercepts:", control->intercept);
pr_err("%-20s%d\n", "pause filter count:", control->pause_filter_count); pr_err("%-20s%d\n", "pause filter count:", control->pause_filter_count);
pr_err("%-20s%d\n", "pause filter threshold:", pr_err("%-20s%d\n", "pause filter threshold:",
......
...@@ -289,20 +289,22 @@ static inline void clr_dr_intercepts(struct vcpu_svm *svm) ...@@ -289,20 +289,22 @@ static inline void clr_dr_intercepts(struct vcpu_svm *svm)
recalc_intercepts(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); 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); 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); 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); recalc_intercepts(svm);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment