@@ -800,23 +800,20 @@ static void kvm_queue_exception_vmexit(struct kvm_vcpu *vcpu, unsigned int vecto
800800 ex -> payload = payload ;
801801}
802802
803- static void kvm_multiple_exception (struct kvm_vcpu * vcpu ,
804- unsigned nr , bool has_error , u32 error_code ,
805- bool has_payload , unsigned long payload , bool reinject )
803+ static void kvm_multiple_exception (struct kvm_vcpu * vcpu , unsigned int nr ,
804+ bool has_error , u32 error_code ,
805+ bool has_payload , unsigned long payload )
806806{
807807 u32 prev_nr ;
808808 int class1 , class2 ;
809809
810810 kvm_make_request (KVM_REQ_EVENT , vcpu );
811811
812812 /*
813- * If the exception is destined for L2 and isn't being reinjected,
814- * morph it to a VM-Exit if L1 wants to intercept the exception. A
815- * previously injected exception is not checked because it was checked
816- * when it was original queued, and re-checking is incorrect if _L1_
817- * injected the exception, in which case it's exempt from interception.
813+ * If the exception is destined for L2, morph it to a VM-Exit if L1
814+ * wants to intercept the exception.
818815 */
819- if (! reinject && is_guest_mode (vcpu ) &&
816+ if (is_guest_mode (vcpu ) &&
820817 kvm_x86_ops .nested_ops -> is_exception_vmexit (vcpu , nr , error_code )) {
821818 kvm_queue_exception_vmexit (vcpu , nr , has_error , error_code ,
822819 has_payload , payload );
@@ -825,28 +822,9 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu,
825822
826823 if (!vcpu -> arch .exception .pending && !vcpu -> arch .exception .injected ) {
827824 queue :
828- if (reinject ) {
829- /*
830- * On VM-Entry, an exception can be pending if and only
831- * if event injection was blocked by nested_run_pending.
832- * In that case, however, vcpu_enter_guest() requests an
833- * immediate exit, and the guest shouldn't proceed far
834- * enough to need reinjection.
835- */
836- WARN_ON_ONCE (kvm_is_exception_pending (vcpu ));
837- vcpu -> arch .exception .injected = true;
838- if (WARN_ON_ONCE (has_payload )) {
839- /*
840- * A reinjected event has already
841- * delivered its payload.
842- */
843- has_payload = false;
844- payload = 0 ;
845- }
846- } else {
847- vcpu -> arch .exception .pending = true;
848- vcpu -> arch .exception .injected = false;
849- }
825+ vcpu -> arch .exception .pending = true;
826+ vcpu -> arch .exception .injected = false;
827+
850828 vcpu -> arch .exception .has_error_code = has_error ;
851829 vcpu -> arch .exception .vector = nr ;
852830 vcpu -> arch .exception .error_code = error_code ;
@@ -887,29 +865,52 @@ static void kvm_multiple_exception(struct kvm_vcpu *vcpu,
887865
888866void kvm_queue_exception (struct kvm_vcpu * vcpu , unsigned nr )
889867{
890- kvm_multiple_exception (vcpu , nr , false, 0 , false, 0 , false );
868+ kvm_multiple_exception (vcpu , nr , false, 0 , false, 0 );
891869}
892870EXPORT_SYMBOL_GPL (kvm_queue_exception );
893871
894- void kvm_requeue_exception (struct kvm_vcpu * vcpu , unsigned nr )
895- {
896- kvm_multiple_exception (vcpu , nr , false, 0 , false, 0 , true);
897- }
898- EXPORT_SYMBOL_GPL (kvm_requeue_exception );
899872
900873void kvm_queue_exception_p (struct kvm_vcpu * vcpu , unsigned nr ,
901874 unsigned long payload )
902875{
903- kvm_multiple_exception (vcpu , nr , false, 0 , true, payload , false );
876+ kvm_multiple_exception (vcpu , nr , false, 0 , true, payload );
904877}
905878EXPORT_SYMBOL_GPL (kvm_queue_exception_p );
906879
907880static void kvm_queue_exception_e_p (struct kvm_vcpu * vcpu , unsigned nr ,
908881 u32 error_code , unsigned long payload )
909882{
910- kvm_multiple_exception (vcpu , nr , true, error_code ,
911- true, payload , false);
883+ kvm_multiple_exception (vcpu , nr , true, error_code , true, payload );
884+ }
885+
886+ void kvm_requeue_exception (struct kvm_vcpu * vcpu , unsigned int nr ,
887+ bool has_error_code , u32 error_code )
888+ {
889+
890+ /*
891+ * On VM-Entry, an exception can be pending if and only if event
892+ * injection was blocked by nested_run_pending. In that case, however,
893+ * vcpu_enter_guest() requests an immediate exit, and the guest
894+ * shouldn't proceed far enough to need reinjection.
895+ */
896+ WARN_ON_ONCE (kvm_is_exception_pending (vcpu ));
897+
898+ /*
899+ * Do not check for interception when injecting an event for L2, as the
900+ * exception was checked for intercept when it was original queued, and
901+ * re-checking is incorrect if _L1_ injected the exception, in which
902+ * case it's exempt from interception.
903+ */
904+ kvm_make_request (KVM_REQ_EVENT , vcpu );
905+
906+ vcpu -> arch .exception .injected = true;
907+ vcpu -> arch .exception .has_error_code = has_error_code ;
908+ vcpu -> arch .exception .vector = nr ;
909+ vcpu -> arch .exception .error_code = error_code ;
910+ vcpu -> arch .exception .has_payload = false;
911+ vcpu -> arch .exception .payload = 0 ;
912912}
913+ EXPORT_SYMBOL_GPL (kvm_requeue_exception );
913914
914915int kvm_complete_insn_gp (struct kvm_vcpu * vcpu , int err )
915916{
@@ -980,16 +981,10 @@ void kvm_inject_nmi(struct kvm_vcpu *vcpu)
980981
981982void kvm_queue_exception_e (struct kvm_vcpu * vcpu , unsigned nr , u32 error_code )
982983{
983- kvm_multiple_exception (vcpu , nr , true, error_code , false, 0 , false );
984+ kvm_multiple_exception (vcpu , nr , true, error_code , false, 0 );
984985}
985986EXPORT_SYMBOL_GPL (kvm_queue_exception_e );
986987
987- void kvm_requeue_exception_e (struct kvm_vcpu * vcpu , unsigned nr , u32 error_code )
988- {
989- kvm_multiple_exception (vcpu , nr , true, error_code , false, 0 , true);
990- }
991- EXPORT_SYMBOL_GPL (kvm_requeue_exception_e );
992-
993988/*
994989 * Checks if cpl <= required_cpl; if true, return true. Otherwise queue
995990 * a #GP and return false.
0 commit comments