]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
KVM: x86: set rflags.rf during fault injection
authorNadav Amit <namit@cs.technion.ac.il>
Thu, 24 Jul 2014 11:51:24 +0000 (14:51 +0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 24 Jul 2014 12:04:01 +0000 (14:04 +0200)
x86 does not automatically set rflags.rf during event injection. This patch
does partial job, setting rflags.rf upon fault injection.  It does not handle
the setting of RF upon interrupt injection on rep-string instruction.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index 08c48a3c7c3ac713904e36573e86f7c82e54b500..439f96bf424df5018d252a65bece9a8e0f07d7f7 100644 (file)
@@ -311,6 +311,31 @@ static int exception_class(int vector)
        return EXCPT_BENIGN;
 }
 
+#define EXCPT_FAULT            0
+#define EXCPT_TRAP             1
+#define EXCPT_ABORT            2
+#define EXCPT_INTERRUPT                3
+
+static int exception_type(int vector)
+{
+       unsigned int mask;
+
+       if (WARN_ON(vector > 31 || vector == NMI_VECTOR))
+               return EXCPT_INTERRUPT;
+
+       mask = 1 << vector;
+
+       /* #DB is trap, as instruction watchpoints are handled elsewhere */
+       if (mask & ((1 << DB_VECTOR) | (1 << BP_VECTOR) | (1 << OF_VECTOR)))
+               return EXCPT_TRAP;
+
+       if (mask & ((1 << DF_VECTOR) | (1 << MC_VECTOR)))
+               return EXCPT_ABORT;
+
+       /* Reserved exceptions will result in fault */
+       return EXCPT_FAULT;
+}
+
 static void kvm_multiple_exception(struct kvm_vcpu *vcpu,
                unsigned nr, bool has_error, u32 error_code,
                bool reinject)
@@ -5893,6 +5918,11 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool req_int_win)
                trace_kvm_inj_exception(vcpu->arch.exception.nr,
                                        vcpu->arch.exception.has_error_code,
                                        vcpu->arch.exception.error_code);
+
+               if (exception_type(vcpu->arch.exception.nr) == EXCPT_FAULT)
+                       __kvm_set_rflags(vcpu, kvm_get_rflags(vcpu) |
+                                            X86_EFLAGS_RF);
+
                kvm_x86_ops->queue_exception(vcpu, vcpu->arch.exception.nr,
                                          vcpu->arch.exception.has_error_code,
                                          vcpu->arch.exception.error_code,