diff mbox series

[v2,0.9/2] VT-d: don't needlessly look up DID

Message ID 7671478f-e7c0-c43e-6395-1adc70333e04@suse.com (mailing list archive)
State New, archived
Headers show
Series VT-d: address fallout from XSA-400 | expand

Commit Message

Jan Beulich April 7, 2022, 9:27 a.m. UTC
If get_iommu_domid() in domain_context_unmap_one() fails, we better
wouldn't clear the context entry in the first place, as we're then unable
to issue the corresponding flush. However, we have no need to look up the
DID in the first place: What needs flushing is very specifically the DID
that was in the context entry before our clearing of it.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
This (an intended follow-up to XSA-399) is actually a prereq to what was
called patch 1 so far in this series.

Comments

Roger Pau Monné April 7, 2022, 9:40 a.m. UTC | #1
On Thu, Apr 07, 2022 at 11:27:53AM +0200, Jan Beulich wrote:
> If get_iommu_domid() in domain_context_unmap_one() fails, we better
> wouldn't clear the context entry in the first place, as we're then unable
> to issue the corresponding flush. However, we have no need to look up the
> DID in the first place: What needs flushing is very specifically the DID
> that was in the context entry before our clearing of it.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, Roger.
Tian, Kevin April 8, 2022, 4:08 a.m. UTC | #2
> From: Jan Beulich <jbeulich@suse.com>
> Sent: Thursday, April 7, 2022 5:28 PM
> 
> If get_iommu_domid() in domain_context_unmap_one() fails, we better
> wouldn't clear the context entry in the first place, as we're then unable
> to issue the corresponding flush. However, we have no need to look up the
> DID in the first place: What needs flushing is very specifically the DID
> that was in the context entry before our clearing of it.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

> ---
> This (an intended follow-up to XSA-399) is actually a prereq to what was
> called patch 1 so far in this series.
> 
> --- a/xen/drivers/passthrough/vtd/iommu.c
> +++ b/xen/drivers/passthrough/vtd/iommu.c
> @@ -1830,18 +1830,12 @@ int domain_context_unmap_one(
>          return 0;
>      }
> 
> +    iommu_domid = context_domain_id(*context);
> +
>      context_clear_present(*context);
>      context_clear_entry(*context);
>      iommu_sync_cache(context, sizeof(struct context_entry));
> 
> -    iommu_domid = get_iommu_did(domid, iommu, !domain->is_dying);
> -    if ( iommu_domid == -1 )
> -    {
> -        spin_unlock(&iommu->lock);
> -        unmap_vtd_domain_page(context_entries);
> -        return -EINVAL;
> -    }
> -
>      rc = iommu_flush_context_device(iommu, iommu_domid,
>                                      PCI_BDF2(bus, devfn),
>                                      DMA_CCMD_MASK_NOBIT, 0);
diff mbox series

Patch

--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -1830,18 +1830,12 @@  int domain_context_unmap_one(
         return 0;
     }
 
+    iommu_domid = context_domain_id(*context);
+
     context_clear_present(*context);
     context_clear_entry(*context);
     iommu_sync_cache(context, sizeof(struct context_entry));
 
-    iommu_domid = get_iommu_did(domid, iommu, !domain->is_dying);
-    if ( iommu_domid == -1 )
-    {
-        spin_unlock(&iommu->lock);
-        unmap_vtd_domain_page(context_entries);
-        return -EINVAL;
-    }
-
     rc = iommu_flush_context_device(iommu, iommu_domid,
                                     PCI_BDF2(bus, devfn),
                                     DMA_CCMD_MASK_NOBIT, 0);