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

Re: [XEN][PATCH v10 09/20] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller


  • To: Vikram Garhwal <vikram.garhwal@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Tue, 29 Aug 2023 10:05:55 +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=xjlMyVt3p2CWSMNmgQxsm5mIpeTRot1yu7yCKswk6No=; b=QoFgLHDrEn48S7cMIliuMTE07NjM36qd+WmrE9dg4mgqHZ49HU707lvclSjNVOQixyFPJPaOXg03r1qvms2MzseU/N4ydD/ZiOth1SU7skyYhHbUDPEHcSqp7EpTpe8lDT1a9MIXbNZheS91i7nBhRjk9RBivJmPcH3lmS+b73i9iK4sWxwa27UqDabxVxyvUGwotl+SvKhDox5YbtpyOS5r9ObTovsmv7ZdRxTx5peUCjIhzH1yvR7l67bcQZTITVD5b+9Un6HQGTwHYUjTLlTva8yEX4c9aAwIOcZXa3fKl0bXkM4JXUp6jcxfR11seAJR1qo24Lw4cpz+lMk5Ew==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M9DLE78xIl+acbLtx6RHcPBpBInNI0c08sbAFwRaurYSq0ud2Kkba+uySh6JJUnlC+YFUka4x2N5nlU7KAPLG77ONFqVU3zBqaGOV0Qpv81/NxmW6ykZpS4mySNurpktaqm8D2HNyeCaqRBQhXyhD2j6gRFYfJ0J9oNHBNNre4TWEkHoxCo31bUR9GJ29ILMEp+HaJ9lM0uYjJncsbnrcJ0K4T5EVol8JwDREYtgyQyqeKrPOgSBmR1Xhj8JotjSNWbGnKV9SNTdthN5efpGTZnNCL846tlE49fFOBb9/VIwVyJl7tvwVyY847mx4MKM33ZL+vCuDL1vXRyqSpXT4w==
  • Cc: <sstabellini@xxxxxxxxxx>, <julien@xxxxxxx>
  • Delivery-date: Tue, 29 Aug 2023 08:06:18 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 25/08/2023 10:02, Vikram Garhwal wrote:
> Rename iommu_dt_device_is_assigned() to iommu_dt_device_is_assigned_locked().
> 
> Moving spin_lock to caller was done to prevent the concurrent access to
> iommu_dt_device_is_assigned while doing add/remove/assign/deassign. Follow-up
> patches in this series introduces node add/remove feature.
> 
> Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>
> 
> ---
> Changes from v9:
>     Make iommu_dt_device_is_assigned_locked() static and delete header.
>     Move dtdevs_lock before iommu_dt_device_is_assigned_locked().
> Changes from v7:
>     Update commit message.
>     Add ASSERT().
> ---
> ---
>  xen/drivers/passthrough/device_tree.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/drivers/passthrough/device_tree.c 
> b/xen/drivers/passthrough/device_tree.c
> index 1c32d7b50c..5d84c07b50 100644
> --- a/xen/drivers/passthrough/device_tree.c
> +++ b/xen/drivers/passthrough/device_tree.c
> @@ -83,16 +83,17 @@ fail:
>      return rc;
>  }
>  
> -static bool_t iommu_dt_device_is_assigned(const struct dt_device_node *dev)
> +static bool_t
> +iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev)
This does not apply cleanly due to recent change from bool_t to bool. Please 
rebase for v11 (the function
should then fit in a single line I think).

>  {
>      bool_t assigned = 0;
>  
> +    ASSERT(spin_is_locked(&dtdevs_lock));
> +
>      if ( !dt_device_is_protected(dev) )
>          return 0;
>  
> -    spin_lock(&dtdevs_lock);
>      assigned = !list_empty(&dev->domain_list);
> -    spin_unlock(&dtdevs_lock);
>  
>      return assigned;
>  }
> @@ -223,17 +224,24 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, 
> struct domain *d,
>          if ( ret )
>              break;
>  
> +        spin_lock(&dtdevs_lock);
Why is this lock placed here instead of ...
> +
>          if ( domctl->cmd == XEN_DOMCTL_test_assign_device )
>          {
> -            if ( iommu_dt_device_is_assigned(dev) )
> +
... here, right before iommu_dt_device_is_assigned_locked()?
> +            if ( iommu_dt_device_is_assigned_locked(dev) )
>              {
>                  printk(XENLOG_G_ERR "%s already assigned.\n",
>                         dt_node_full_name(dev));
>                  ret = -EINVAL;
>              }
> +
> +            spin_unlock(&dtdevs_lock);
>              break;
>          }
>  
> +        spin_unlock(&dtdevs_lock);
You could then remove this one.

With the remarks addressed:
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®.