hv: call vcpu_inject_exception() only when ACRN_REQUEST_EXCP is set
move the bitmap test call out of vcpu_inject_exception(), then we call
the expensive bitmap_test_and_clear_lock() only pending_req_bits is
non-zero and call vcpu_inject_exception() only if needed.
Acked-by: Eddie Dong
@@ -247,11 +247,8 @@ int32_t vcpu_queue_exception(struct acrn_vcpu *vcpu, uint32_t vector_arg, uint32
/*
* @pre vcpu->arch.exception_info.exception < 0x20U
*/
-static bool vcpu_inject_exception(struct acrn_vcpu *vcpu)
+static void vcpu_inject_exception(struct acrn_vcpu *vcpu)
{
- bool injected = false;
-
- if (bitmap_test_and_clear_lock(ACRN_REQUEST_EXCP, &vcpu->arch.pending_req)) {
uint32_t vector = vcpu->arch.exception_info.exception;
if ((exception_type[vector] & EXCEPTION_ERROR_CODE_VALID) != 0U) {
@@ -276,11 +273,6 @@ static bool vcpu_inject_exception(struct acrn_vcpu *vcpu)
if (get_exception_type(vector) == EXCEPTION_FAULT) {
vcpu_set_rflags(vcpu, vcpu_get_rflags(vcpu) | HV_ARCH_VCPU_RFLAGS_RF);
}
-
- injected = true;
- }
-
- return injected;
}
/* Inject external interrupt to guest */
@@ -415,8 +407,10 @@ int32_t acrn_handle_pending_request(struct acrn_vcpu *vcpu)
/*
* Inject pending exception prior pending interrupt to complete the previous instruction.
*/
- injected = vcpu_inject_exception(vcpu);
- if (!injected) {
+ if ((*pending_req_bits != 0UL) && bitmap_test_and_clear_lock(ACRN_REQUEST_EXCP, pending_req_bits)) {
+ vcpu_inject_exception(vcpu);
+ injected = true;
+ } else {
/* inject NMI before maskable hardware interrupt */
if ((*pending_req_bits != 0UL) &&
