From 65ec6f3f3b8e058142712bd6c66db06b64b6e9a4 Mon Sep 17 00:00:00 2001 From: Binbin Wu Date: Tue, 21 Apr 2020 05:55:04 +0000 Subject: [PATCH] hv: vtd: fix potential dead loop if qi request timeout Fix potential dead loop if qi request timeout. Tracked-On: #4680 Signed-off-by: Binbin Wu --- hypervisor/arch/x86/vtd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index c879f512d..35ec95c5a 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -547,7 +547,7 @@ static void dmar_issue_qi_request(struct dmar_drhd_rt *dmar_unit, struct dmar_en { struct dmar_entry *invalidate_desc_ptr; uint32_t qi_status = 0U; - __unused uint64_t start; + uint64_t start; invalidate_desc_ptr = (struct dmar_entry *)(dmar_unit->qi_queue + dmar_unit->qi_tail); @@ -565,12 +565,10 @@ static void dmar_issue_qi_request(struct dmar_drhd_rt *dmar_unit, struct dmar_en iommu_write32(dmar_unit, DMAR_IQT_REG, dmar_unit->qi_tail); start = rdtsc(); - while (qi_status == DMAR_INV_STATUS_INCOMPLETE) { - if (qi_status == DMAR_INV_STATUS_COMPLETED) { - break; - } + while (qi_status != DMAR_INV_STATUS_COMPLETED) { if ((rdtsc() - start) > CYCLES_PER_MS) { pr_err("DMAR OP Timeout! @ %s", __func__); + break; } asm_pause(); }