[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [PATCH v2 1/3] VT-d: consider hidden devices when unmapping


  • To: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Tian, Kevin" <kevin.tian@xxxxxxxxx>
  • Date: Sat, 18 Sep 2021 00:48:20 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=q4izqWtMOYHvwE5erlAuG4n3VcCpUQNhbN5FnLO8ILk=; b=QM2PSjgNYuw0mJ4+SVuHv4Ssk1xdQhnzZjgvCQU0CltN5x95eOmHEDa+iSktua/nO+p+gTHTymNa4clX29moAM0dm9X3cvqyjZxv3+k3tJQ37nm+ehEGAN/6oEPPhrhh56NYfzi/gYKZROsPTBD2GQbbEfzoBasd65G/p9YAKOLhikoPnAQqEwcs1jBZRsdd+sOll1vM0j6rtsSo32d6rGoho4m+vSYSsmyi3Efs0Hp8699IZBaSHKHyruO9DHJk8WTh7a35K22W9LTT3S79JDP2vsHA6HEYabVHeoEf8WUARzvVYQLqodDZM8nwrnuyFOZ0AQblRQCPy50iS1QE7A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iErusLYViDWrV5jNPUQBhEyt/eXwhaqR3SBsP9FXj9ISFsYfr5SrRJDljPDzIoHZprimXvrPwYYr/lUc4nmEBNeJs6baN1VLKbbnkTbJyr5HnFR0fA9YUiyey3G6jluJGDWRbTbeginNmwh3xXiTFskHjrUs8kzTpfepkICgOI/cdu3WCsCsUuN6QXukeIiMgoJMbjkYWXuqO0ZrTi1ZFp0qCUhJvwSvyWZEjPg7X0N3YbX1zmrKGiuLkkbvh7gCkj74piXDnml9rwYhsW4lswwBwNYKPnxoAanaGeKKjtiFdLo2JdrqIEnsH/KtxW+FfZ9kblmHz4LzFIPhwjae+g==
  • Authentication-results: suse.com; dkim=none (message not signed) header.d=none;suse.com; dmarc=none action=none header.from=intel.com;
  • Cc: Paul Durrant <paul@xxxxxxx>
  • Delivery-date: Sat, 18 Sep 2021 00:48:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHXq7NAuWJs+9yJ2ECO4xKe2sffuauo9kZw
  • Thread-topic: [PATCH v2 1/3] VT-d: consider hidden devices when unmapping

> From: Jan Beulich <jbeulich@xxxxxxxx>
> Sent: Friday, September 17, 2021 7:00 PM
> 
> Whether to clear an IOMMU's bit in the domain's bitmap should depend on
> all devices the domain can control. For the hardware domain this
> includes hidden devices, which are associated with DomXEN.
> 
> While touching related logic
> - convert the "current device" exclusion check to a simple pointer
>   comparison,
> - convert "found" to "bool",
> - adjust style and correct a typo in an existing comment.
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

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

> ---
> v2: Introduce helper function.
> 
> --- a/xen/drivers/passthrough/vtd/iommu.c
> +++ b/xen/drivers/passthrough/vtd/iommu.c
> @@ -1650,6 +1650,27 @@ int domain_context_unmap_one(
>      return rc;
>  }
> 
> +static bool any_pdev_behind_iommu(const struct domain *d,
> +                                  const struct pci_dev *exclude,
> +                                  const struct vtd_iommu *iommu)
> +{
> +    const struct pci_dev *pdev;
> +
> +    for_each_pdev ( d, pdev )
> +    {
> +        const struct acpi_drhd_unit *drhd;
> +
> +        if ( pdev == exclude )
> +            continue;
> +
> +        drhd = acpi_find_matched_drhd_unit(pdev);
> +        if ( drhd && drhd->iommu == iommu )
> +            return true;
> +    }
> +
> +    return false;
> +}
> +
>  static int domain_context_unmap(struct domain *domain, u8 devfn,
>                                  struct pci_dev *pdev)
>  {
> @@ -1657,7 +1678,7 @@ static int domain_context_unmap(struct d
>      struct vtd_iommu *iommu = drhd ? drhd->iommu : NULL;
>      int ret;
>      u8 seg = pdev->seg, bus = pdev->bus, tmp_bus, tmp_devfn, secbus;
> -    int found = 0;
> +    bool found;
> 
>      switch ( pdev->type )
>      {
> @@ -1737,23 +1758,18 @@ static int domain_context_unmap(struct d
>          return ret;
> 
>      /*
> -     * if no other devices under the same iommu owned by this domain,
> -     * clear iommu in iommu_bitmap and clear domain_id in domid_bitmp
> +     * If no other devices under the same iommu owned by this domain,
> +     * clear iommu in iommu_bitmap and clear domain_id in domid_bitmap.
>       */
> -    for_each_pdev ( domain, pdev )
> -    {
> -        if ( pdev->seg == seg && pdev->bus == bus && pdev->devfn == devfn )
> -            continue;
> -
> -        drhd = acpi_find_matched_drhd_unit(pdev);
> -        if ( drhd && drhd->iommu == iommu )
> -        {
> -            found = 1;
> -            break;
> -        }
> -    }
> +    found = any_pdev_behind_iommu(domain, pdev, iommu);
> +    /*
> +     * Hidden devices are associated with DomXEN but usable by the
> hardware
> +     * domain. Hence they need considering here as well.
> +     */
> +    if ( !found && is_hardware_domain(domain) )
> +        found = any_pdev_behind_iommu(dom_xen, pdev, iommu);
> 
> -    if ( found == 0 )
> +    if ( !found )
>      {
>          clear_bit(iommu->index, &dom_iommu(domain)-
> >arch.vtd.iommu_bitmap);
>          cleanup_domid_map(domain, iommu);


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.