Skip to content

Commit fea541b

Browse files
binbinwu1wenlingz
authored andcommitted
hv: exception: low prioirity exception inject fix
In current code, there is a logic bug when inject low priority exceptions. If guest irq enabled, low priority exception will not be injected to guest. This patch fix the logic error, if there is no eligible vector before handling low priority exceptions, then inject low priority exception if any. Tracked-On: #2405 Signed-off-by: Binbin Wu <binbin.wu@intel.com> Acked-by: Anthony Xu <anthony.xu@intel.com>
1 parent c6d2908 commit fea541b

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

hypervisor/arch/x86/virq.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ void vcpu_make_request(struct acrn_vcpu *vcpu, uint16_t eventid)
113113

114114
/*
115115
* This function is only for case that APICv/VID is not supported.
116+
*
117+
* @retval 1 when INT is injected to guest.
118+
* @retval 0 when there is no eligible pending vector.
119+
* @retval -1 when there is a error.
116120
*/
117121
static int32_t vcpu_inject_vlapic_int(struct acrn_vcpu *vcpu)
118122
{
@@ -137,18 +141,23 @@ static int32_t vcpu_inject_vlapic_int(struct acrn_vcpu *vcpu)
137141
(vector & 0xFFU));
138142

139143
vlapic_intr_accepted(vlapic, vector);
140-
ret = 0;
144+
ret = 1;
141145
}
142146
}
143147

144148
return ret;
145149
}
146150

151+
/*
152+
* @retval 1 when INT is injected to guest.
153+
* @retval 0 when otherwise
154+
*/
147155
static int32_t vcpu_do_pending_extint(const struct acrn_vcpu *vcpu)
148156
{
149157
struct acrn_vm *vm;
150158
struct acrn_vcpu *primary;
151159
uint32_t vector;
160+
int32_t ret = 0;
152161

153162
vm = vcpu->vm;
154163

@@ -165,10 +174,11 @@ static int32_t vcpu_do_pending_extint(const struct acrn_vcpu *vcpu)
165174
VMX_INT_INFO_VALID |
166175
(vector & 0xFFU));
167176
vpic_intr_accepted(vcpu->vm, vector);
177+
ret = 1;
168178
}
169179
}
170180

171-
return 0;
181+
return ret;
172182
}
173183

174184
/* SDM Vol3 -6.15, Table 6-4 - interrupt and exception classes */
@@ -483,6 +493,11 @@ int32_t acrn_handle_pending_request(struct acrn_vcpu *vcpu)
483493
return ret;
484494
}
485495

496+
/*
497+
* @retval 1 1 when INT is injected to guest.
498+
* @retval 0 when there is no eligible pending vector.
499+
* @retval -1 when there is a error.
500+
*/
486501
static inline int32_t acrn_inject_pending_vector(struct acrn_vcpu *vcpu, uint64_t *pending_req_bits)
487502
{
488503
int32_t ret = 0;
@@ -518,12 +533,12 @@ static inline int32_t acrn_inject_pending_vector(struct acrn_vcpu *vcpu, uint64_
518533
ret = vcpu_inject_vlapic_int(vcpu);
519534
}
520535
}
521-
} else {
536+
}
537+
538+
/* if there is no eligible vector before this point */
539+
if (ret == 0) {
522540
/* SDM Vol3 table 6-2, inject lowpri exception */
523541
ret = vcpu_inject_lo_exception(vcpu);
524-
if (ret != 0) {
525-
ret = 0;
526-
}
527542
}
528543
}
529544

0 commit comments

Comments
 (0)