Skip to contentSkip to conversation

iommu/vt-d: Drain PRQs when domain removed from RID

bug report Dan Carpenter 2 participants 2 messages Dec 11, 2024 – Dec 12, 2024

lore
Share & tools
lore
#0 lore raw

Hello Lu Baolu,

Commit c43e1ccdebf2 ("iommu/vt-d: Drain PRQs when domain removed from RID") from Nov 4, 2024 (linux-next), leads to the following Smatch static checker warning:

drivers/iommu/intel/prq.c:95 intel_iommu_drain_pasid_prq()
warn: sleeping in atomic context

drivers/iommu/intel/prq.c

    60 void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid)
    61 {
    62         struct device_domain_info *info;
    63         struct dmar_domain *domain;
    64         struct intel_iommu *iommu;
    65         struct qi_desc desc[3];
    66         int head, tail;
    67         u16 sid, did;
    68 
    69         info = dev_iommu_priv_get(dev);
    70         if (!info->pri_enabled)
    71                 return;
    72 
    73         iommu = info->iommu;
    74         domain = info->domain;
    75         sid = PCI_DEVID(info->bus, info->devfn);
    76         did = domain ? domain_id_iommu(domain, iommu) : FLPT_DEFAULT_DID;
    77 
    78         /*
    79          * Check and wait until all pending page requests in the queue are
    80          * handled by the prq handling thread.
    81          */
    82 prq_retry:
    83         reinit_completion(&iommu->prq_complete);
    84         tail = dmar_readq(iommu->reg + DMAR_PQT_REG) & PRQ_RING_MASK;
    85         head = dmar_readq(iommu->reg + DMAR_PQH_REG) & PRQ_RING_MASK;
    86         while (head != tail) {
    87                 struct page_req_dsc *req;
    88 
    89                 req = &iommu->prq[head / sizeof(*req)];
    90                 if (!req->pasid_present || req->pasid != pasid) {
    91                         head = (head + sizeof(*req)) & PRQ_RING_MASK;
    92                         continue;
    93                 }
    94 
--> 95                 wait_for_completion(&iommu->prq_complete);
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is a sleep.

    96                 goto prq_retry;
    97         }
    98 
    99         iopf_queue_flush_dev(dev);
               ^^^^^^^^^^^^^^^^^^^^^^^^^

flush sleeps as well.

The call tree is:

intel_mm_release() <- disables preempt with a spinlock
-> intel_pasid_tear_down_entry() <- the patch added intel_iommu_drain_pasid_prq()
-> intel_iommu_drain_pasid_prq()

regards,
dan carpenter

#1 lore raw
Quoted 8 lines · Dan Carpenter

Hello Lu Baolu,

Commit c43e1ccdebf2 ("iommu/vt-d: Drain PRQs when domain removed from RID") from Nov 4, 2024 (linux-next), leads to the following Smatch static checker warning:

drivers/iommu/intel/prq.c:95 intel_iommu_drain_pasid_prq()
warn: sleeping in atomic context

Thank you for the reporting, Dan. I will soon post a fix for this.

Thanks,
baolu