Skip to content

Commit 28a7718

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Clear PRQ overflow only when PRQ is empty
It is incorrect to always clear PRO when it's set w/o first checking whether the overflow condition has been cleared. Current code assumes that if an overflow condition occurs it must have been cleared by earlier loop. However since the code runs in a threaded context, the overflow condition could occur even after setting the head to the tail under some extreme condition. To be sane, we should read both head/tail again when seeing a pending PRO and only clear PRO after all pending PRs have been handled. Suggested-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Link: https://lore.kernel.org/linux-iommu/MWHPR11MB18862D2EA5BD432BF22D99A48CA09@MWHPR11MB1886.namprd11.prod.outlook.com/ Link: https://lore.kernel.org/r/20210126080730.2232859-2-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent a8ce9eb commit 28a7718

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

drivers/iommu/intel/svm.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,17 @@ static irqreturn_t prq_event_thread(int irq, void *d)
10421042
* Clear the page request overflow bit and wake up all threads that
10431043
* are waiting for the completion of this handling.
10441044
*/
1045-
if (readl(iommu->reg + DMAR_PRS_REG) & DMA_PRS_PRO)
1046-
writel(DMA_PRS_PRO, iommu->reg + DMAR_PRS_REG);
1045+
if (readl(iommu->reg + DMAR_PRS_REG) & DMA_PRS_PRO) {
1046+
pr_info_ratelimited("IOMMU: %s: PRQ overflow detected\n",
1047+
iommu->name);
1048+
head = dmar_readq(iommu->reg + DMAR_PQH_REG) & PRQ_RING_MASK;
1049+
tail = dmar_readq(iommu->reg + DMAR_PQT_REG) & PRQ_RING_MASK;
1050+
if (head == tail) {
1051+
writel(DMA_PRS_PRO, iommu->reg + DMAR_PRS_REG);
1052+
pr_info_ratelimited("IOMMU: %s: PRQ overflow cleared",
1053+
iommu->name);
1054+
}
1055+
}
10471056

10481057
if (!completion_done(&iommu->prq_complete))
10491058
complete(&iommu->prq_complete);

0 commit comments

Comments
 (0)