From 9876138b699be2206e647ef319ca9111aa3f3fad Mon Sep 17 00:00:00 2001 From: Minggui Cao Date: Wed, 15 May 2019 18:15:48 +0800 Subject: [PATCH] HV: add spinlock to dmar_enable/disable_qi add spinlock to dmar_enable_qi & dmar_disable_qi to protect struct dmar_unit variables; keep consistent with other same level functions. Tracked-On: #3130 Signed-off-by: Minggui Cao Acked-by: Eddie Dong --- hypervisor/arch/x86/vtd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hypervisor/arch/x86/vtd.c b/hypervisor/arch/x86/vtd.c index fea3ae6d9..a0d896634 100644 --- a/hypervisor/arch/x86/vtd.c +++ b/hypervisor/arch/x86/vtd.c @@ -952,6 +952,8 @@ static void dmar_enable_qi(struct dmar_drhd_rt *dmar_unit) { uint32_t status = 0; + spinlock_obtain(&(dmar_unit->lock)); + dmar_unit->qi_queue = hva2hpa(get_qi_queue(dmar_unit->index)); iommu_write64(dmar_unit, DMAR_IQA_REG, dmar_unit->qi_queue); @@ -962,17 +964,23 @@ static void dmar_enable_qi(struct dmar_drhd_rt *dmar_unit) iommu_write32(dmar_unit, DMAR_GCMD_REG, dmar_unit->gcmd); dmar_wait_completion(dmar_unit, DMAR_GSTS_REG, DMA_GSTS_QIES, false, &status); } + + spinlock_release(&(dmar_unit->lock)); } static void dmar_disable_qi(struct dmar_drhd_rt *dmar_unit) { uint32_t status = 0; + spinlock_obtain(&(dmar_unit->lock)); + if ((dmar_unit->gcmd & DMA_GCMD_QIE) == DMA_GCMD_QIE) { dmar_unit->gcmd &= ~DMA_GCMD_QIE; iommu_write32(dmar_unit, DMAR_GCMD_REG, dmar_unit->gcmd); dmar_wait_completion(dmar_unit, DMAR_GSTS_REG, DMA_GSTS_QIES, true, &status); } + + spinlock_release(&(dmar_unit->lock)); } static void dmar_prepare(struct dmar_drhd_rt *dmar_unit)