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

Re: [XEN][PATCH v5 12/17] common/device_tree: Add rwlock for dt_host


  • To: Henry Wang <Henry.Wang@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <vikram.garhwal@xxxxxxx>
  • Date: Fri, 14 Apr 2023 10:23:22 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.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=Ej5SWGuUgb6hps2pgI4GwpP608Nluv+8+jfvaBUuYXI=; b=Veyc6rjldKlPLkv2VXtAIN9+eJQHiE6BehYFTAXgBLiAaF0S6oOcC0XmviiQ/1NsvgpAyhcQw4Pu5+icodoviiX0dph4l1VIuJopfZfdvm5d80KUEKtRV0ox5xj47MVPxPeMvYheg/+Sxc/cDP0BlaGL5mp5LQFntJozgBSoSzgjvMc3ZV5hcd0HqwpgGO6brzq33eLend/aM6L0gLFuGrWT1OzERxWntvhvNt9RCrVhq9mNbjSTkdqWByAStMu3n8L3nMuD2PL9/f31E1MPRgF6vf1QATVRed3bqgiFdr3K02plwyHOJQ6FqD+SBMdTA45ie0mi3t/vIVZ78we6Rw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OobbYPp7E/tUwaL0H/DvMcsv2VP9RYcUJvVDsFl1lY5ehOXPjgTeGQ82zjy2Gr6qO34FcDutP+P0hfC/FIghfAXkUKUAelh8oK42SRMUKA8n7xxk8SGR+OlbelUlHa92B5psxhcgzl+k4cS3bODVnrRwMoEt21qvwZzsXZdZnD4vS1+7VsiSL00FSdfy1SAL3UFf3qeLPgehG4eiJv//eaMOQfC2E4f/1IKTANXsNkp3cnskgDbLSEfoK1QgOVTJK9rDIAEpbY8Khm3B+UzDcF+i0mZfzIHEt13dzv/vaoHP5MTL75+CVtE0YHuYiCTPMgrKZCh+zgFQmJbQx1nn5g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Fri, 14 Apr 2023 17:23:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Henry,

On 4/13/23 7:09 PM, Henry Wang wrote:
Hi Vikram,

-----Original Message-----
Subject: [XEN][PATCH v5 12/17] common/device_tree: Add rwlock for dt_host

  Dynamic programming ops will modify the dt_host and there might be other
  function which are browsing the dt_host at the same time. To avoid the race
  conditions, adding rwlock for browsing the dt_host during runtime.
For clarity, could you please add a little bit more details to explain why you 
chose
rwlock instead of normal spinlock?
rwlock is just to protect someone reading the dt_host while dynamic programming is modifying the dt_host.
Initial suggestion was from Julien about adding rwlock here.
For now, dynamic programming is the dt_host writer in Xen during run time. All other iommu passthrough function was just readers during run-time. So, it was better to go for r/w locks here as spinlock won't be able to difference between read and r/w access.

For next version, I will add a comment in commit message.
Signed-off-by: Vikram Garhwal <vikram.garhwal@xxxxxxx>
---
  xen/common/device_tree.c              |  3 +++
  xen/drivers/passthrough/device_tree.c | 39 +++++++++++++++++++++++++++
  xen/include/xen/device_tree.h         |  6 +++++
  3 files changed, 48 insertions(+)

          if ( ret )
+        {
              printk(XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign
\"%s\""
                     " to dom%u failed (%d)\n",
                     dt_node_full_name(dev), d->domain_id, ret);
+        }
I am not sure if it is necessary to add "{" and "}" here.
You are right. Will remove it in next version.

+
+        read_unlock(&dt_host->lock);
          break;

      case XEN_DOMCTL_deassign_device:
@@ -322,25 +345,41 @@ int iommu_do_dt_domctl(struct xen_domctl
*domctl, struct domain *d,
          if ( domctl->u.assign_device.flags )
              break;

+        read_lock(&dt_host->lock);
+
          ret = dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path,
                                      domctl->u.assign_device.u.dt.size,
                                      &dev);
          if ( ret )
+        {
+            read_unlock(&dt_host->lock);
I think instead of adding "read_unlock" in every break and return path,
you can...

              break;
+        }

          ret = xsm_deassign_dtdevice(XSM_HOOK, d, dt_node_full_name(dev));
+
          if ( ret )
+        {
+            read_unlock(&dt_host->lock);
              break;
+        }

          if ( d == dom_io )
+        {
+            read_unlock(&dt_host->lock);
              return -EINVAL;
...do something like:

ret = -EINVAL;
break;

here, and then add one single "read_unlock" before the "return ret;"
in the bottom of the function?
Will do.

+        }

          ret = iommu_deassign_dt_device(d, dev);

          if ( ret )
+        {
              printk(XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign
\"%s\""
                     " to dom%u failed (%d)\n",
                     dt_node_full_name(dev), d->domain_id, ret);
+        }
Same here. I am not sure if it is necessary to add "{" and "}".
Kind regards,
Henry




 


Rackspace

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