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

Re: [XEN][PATCH v11 11/20] xen/iommu: Introduce iommu_remove_dt_device()


  • To: Vikram Garhwal <vikram.garhwal@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Mon, 4 Sep 2023 12:31:43 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=RTdBjjlskRyXVFnQ3rkx2reo+2sZu6EORZam6WJQLzQ=; b=MdgzzKFPVCaAn71tJ0eS50U3Ts5FocG8lXFaIlMlRTlFt0HozHzhYRzoWEJICZvf1TEW24GvY5jL0ftR5LE4Y1kAMYUXDrOFmOF3EHgGXoHwRBW6HnefWhhG60kz8PKoxAvqtUNTTAiBYBEzYD5ZByfwZeYeimEKSbfOaELziD6lkeo0xgnyEVKzTuTTrjxQkSUbIqRj02v2ZuuXcNrF29gpLScwStf3S01YxFuTY9u00o5DeOeLaIKOUu4O1haWogrGPUxIGM6Waa//rcKs0dKTrLPCdI9YFG6bDooJ4gse2HiH97g2OGvIgBTbkvEREq2n5ToMUdS2CisI5JfpsQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FJ4qDnzwrRvKKSpxD4kBdGM9BzzYIt8rnMQ7LJOJMKatgHj/jFtzQMlqoqYDtpYSy3y6rxkuv55/8Ub5xz4ofjr+XXMNgsu0vqi1ROQsgcalgaiFvntpQqcb3Io0IfsY94o/zRRW+dyUFt0Ss6K34eV2eFrMcpK53NsXP7E/c0hlW9WyX4TYCICMevbAf2ucgCemtAVun2rSS6n7y3LupnPbeAb5NCsGN3Cgp1X1KktLf8fAEAb2GJQ22g0kFwDj0JnMkEbdT1/VactqZ/CbgVQIeFom2rhjmB3uwF/hIstyUdUj3+vqcsEzVw2lIH370lhQ3xJd+UdY5BinNiyu7g==
  • Cc: <julien@xxxxxxx>, <sstabellini@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 04 Sep 2023 10:32:56 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 01/09/2023 06:59, Vikram Garhwal wrote:
> Remove master device from the IOMMU. This will be helpful when removing the
> overlay nodes using dynamic programming during run time.
> 
> Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>
> 
> ---
> Changes from v10:
>     Add comment regarding return values of iommu_remove_dt_device().
>     Add ASSERT to check if is_protected is removed or not.
> Changes from v7:
>     Add check if IOMMU is enabled.
>     Fix indentation of fail.
> ---
> ---
>  xen/drivers/passthrough/device_tree.c | 43 +++++++++++++++++++++++++++
>  xen/include/xen/iommu.h               | 10 +++++++
>  2 files changed, 53 insertions(+)
> 
> diff --git a/xen/drivers/passthrough/device_tree.c 
> b/xen/drivers/passthrough/device_tree.c
> index 687c61e7da..80f6efc606 100644
> --- a/xen/drivers/passthrough/device_tree.c
> +++ b/xen/drivers/passthrough/device_tree.c
> @@ -127,6 +127,49 @@ int iommu_release_dt_devices(struct domain *d)
>      return 0;
>  }
>  
> +int iommu_remove_dt_device(struct dt_device_node *np)
> +{
> +    const struct iommu_ops *ops = iommu_get_ops();
> +    struct device *dev = dt_to_dev(np);
> +    int rc;
> +
> +    if ( !iommu_enabled )
> +        return 1;
> +
> +    if ( !ops )
> +        return -EOPNOTSUPP;
> +
> +    spin_lock(&dtdevs_lock);
> +
> +    if ( iommu_dt_device_is_assigned_locked(np) )
> +    {
> +        rc = -EBUSY;
> +        goto fail;
> +    }
> +
> +    if ( !ops->remove_device )
> +    {
> +        rc = -EOPNOTSUPP;
> +        goto fail;
> +    }
> +
> +    /*
> +     * De-register the device from the IOMMU driver.
> +     * The driver is responsible for removing is_protected flag.
> +     */
> +    rc = ops->remove_device(0, dev);
> +
> +    if ( !rc )
> +    {
> +        ASSERT(!dt_device_is_protected(np));
> +        iommu_fwspec_free(dev);
> +    }
> +
> + fail:
> +    spin_unlock(&dtdevs_lock);
> +    return rc;
> +}
> +
>  int iommu_add_dt_device(struct dt_device_node *np)
>  {
>      const struct iommu_ops *ops = iommu_get_ops();
> diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
> index a18b68e247..84bd77395e 100644
> --- a/xen/include/xen/iommu.h
> +++ b/xen/include/xen/iommu.h
> @@ -235,6 +235,16 @@ int iommu_add_dt_device(struct dt_device_node *np);
>  int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d,
>                         XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
>  
> +/*
> + * Helper to remove master device from the IOMMU.
> + *
> + * Return values:
> + *  0 : device is de-registerd from IOMMU.
s/registerd/registered/

> + * <0 : error while removing the device from IOMMU.
> + * >0 : IOMMU is not enabled/present or device is not connected to it.
The first part refers to "iommu_enabled" but I cannot see how you check for the 
second part
(and return >0).

Apart from that:
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>

~Michal



 


Rackspace

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