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

RE: [PATCH 2/6] VT-d: split domid map cleanup check into a function


  • To: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: "Tian, Kevin" <kevin.tian@xxxxxxxxx>
  • Date: Mon, 15 Nov 2021 05:16:25 +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:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=euvWnA5gNksxlJu0iR5E1/h5o+xmrjl96QdNtbzx46Y=; b=E3AV/2c4EVHbnU9vAypH+p5G6QqjWIbUqaQzYcmHGAoDhkNN8HE7AM29N3wHKU992FHA22xWdf4hHdEZ4FpwUlpj5YetvV/KLncGHPTDZEwx+6htE2UudQMe5LFcZB/Mi55bpd379yBDzyffWNK/4Hh9OYpkB8lT7liXfKUCy9JeR+qZp96K8qgwPS4ohEGg0JOK7xO5DRuNTJ1DTMu1vcaa710fhE+W76Mui0c6FmQz37c/DnE5FOiK6ydqnScOYz4qkVbzYyZAuch71b7Aqb1gKsWD8QotpyyG0rzoB3PJ6l1RB1sMhQeCFUgupT85z8RaNWyKuFeQ9VUgPuOX5g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hh7uO3Y0yVtlzhIZ91/Rz21Iv2MDUR6CcUpYbAY9vQk9vD2C0i/1f9HxJm7p8eeSvCoRSNGF4az8OJ0FuVfzvzaHmgk4fQiqqLQVOhGe37oS5ECocAHcOeqyBaUIXSI5t/94MA/s2jNCyk/rMGWRrB7ZeeHDsvdrg8n29xPm07g0sUzdSr0+k2cNLpmSSH9b6rgAUy0aSqciVhffwUbDSwrC8R4y9JgI0DREsTcvZwyOo/xgfmsMMlyfLCAyrjlG72R5NJKNaTYaJPjiBPXMjqXdeLwyoN+9tC4fbncCVfnqrF4jnXTTdWLk1UGZpy+injEqEDcsQZ6zHa/Z4v8M1A==
  • Authentication-results: suse.com; dkim=none (message not signed) header.d=none;suse.com; dmarc=none action=none header.from=intel.com;
  • Delivery-date: Mon, 15 Nov 2021 05:16:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHX16p16FVi6A9hH0KPevO89n4c9qwEEHWA
  • Thread-topic: [PATCH 2/6] VT-d: split domid map cleanup check into a function

> From: Jan Beulich <jbeulich@xxxxxxxx>
> Sent: Friday, November 12, 2021 5:48 PM
> 
> This logic will want invoking from elsewhere.
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

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

> 
> --- a/xen/drivers/passthrough/vtd/iommu.c
> +++ b/xen/drivers/passthrough/vtd/iommu.c
> @@ -157,6 +157,51 @@ static void cleanup_domid_map(struct dom
>      }
>  }
> 
> +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;
> +}
> +
> +/*
> + * If no other devices under the same iommu owned by this domain,
> + * clear iommu in iommu_bitmap and clear domain_id in domid_bitmap.
> + */
> +static void check_cleanup_domid_map(struct domain *d,
> +                                    const struct pci_dev *exclude,
> +                                    struct vtd_iommu *iommu)
> +{
> +    bool found = any_pdev_behind_iommu(d, exclude, 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(d) )
> +        found = any_pdev_behind_iommu(dom_xen, exclude, iommu);
> +
> +    if ( !found )
> +    {
> +        clear_bit(iommu->index, dom_iommu(d)->arch.vtd.iommu_bitmap);
> +        cleanup_domid_map(d, iommu);
> +    }
> +}
> +
>  static void sync_cache(const void *addr, unsigned int size)
>  {
>      static unsigned long clflush_size = 0;
> @@ -1675,27 +1720,6 @@ 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)
>  {
> @@ -1704,7 +1728,6 @@ static int domain_context_unmap(struct d
>      int ret;
>      uint16_t seg = pdev->seg;
>      uint8_t bus = pdev->bus, tmp_bus, tmp_devfn, secbus;
> -    bool found;
> 
>      switch ( pdev->type )
>      {
> @@ -1780,28 +1803,10 @@ static int domain_context_unmap(struct d
>          return -EINVAL;
>      }
> 
> -    if ( ret || QUARANTINE_SKIP(domain) || pdev->devfn != devfn )
> -        return ret;
> +    if ( !ret && !QUARANTINE_SKIP(domain) && pdev->devfn == devfn )
> +        check_cleanup_domid_map(domain, pdev, iommu);
> 
> -    /*
> -     * If no other devices under the same iommu owned by this domain,
> -     * clear iommu in iommu_bitmap and clear domain_id in domid_bitmap.
> -     */
> -    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 )
> -    {
> -        clear_bit(iommu->index, dom_iommu(domain)-
> >arch.vtd.iommu_bitmap);
> -        cleanup_domid_map(domain, iommu);
> -    }
> -
> -    return 0;
> +    return ret;
>  }
> 
>  static void iommu_clear_root_pgtable(struct domain *d)


 


Rackspace

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