[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: Vikram Garhwal <vikram.garhwal@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Henry Wang <Henry.Wang@xxxxxxx>
  • Date: Fri, 14 Apr 2023 02:09:30 +0000
  • Accept-language: zh-CN, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.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=7K66/NOBOzweoXpUKEC2T8xfXCJQM7bOv4DduEzKc9A=; b=aiwpKwOoUJY5nvmd+cqsD6r9woTfjRS8PZWmLubz6nm0BfYXUvPXFM0dofTzyirqD5TF6P52+vKqO1eOiOwfJGVQQ5tam6iH0wa+/yFpGPtlzdRSN0Xxb5i1929jo0RDUUM/fXJfBIKCdcVVn7DphM3ZF2ZPezajofQx9rQmTTdjTWGzeVhBxqr19VnQR8lCL6gWNDcafHnre7pekT+PLPRTYZR2SSxFn/jeXYb6C4UFilki7KlgUgtpZVIogiJ9xE1ZVY0tyW8ZVHUn4VhUvuIGSKLU61QPQEPM5LeHiNkaFBe9yZXvK7UEMJrt1iitHlYg3eZfP1SUMuW19NQkwA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fy1E6sTz9XEvrZFc/HlkUjpT0IkQ5wPFlzUlmVlPOkdPVYr/+/0w+uEFkRNF8/bNXzGRZMkzZ0bbt9VG9mk4meb1ZEUnjqLtAUM/C9+WplE3Xpy7H4Ff04hiVg4XJ4PyBjuoMQe6MfGNPPM2IPkhLaWjKHq5wdfTUiyHU0eFf1q5KiEQrrsQgCTBGNb7IEgAcgjSuBMB6WCVn4mtnxt6pY0gkJ7yodyu2e4qZHoRHUOnmLS39N9AtvQM2KF83fyQbSdAiC1TZMYTKjv38x0DjFoN7YFUOMYnQvKdUEFFOw6OkeDLDBrW3//w2lT9gZJ5VTxZSAy09rJYqkjSbov7UA==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Fri, 14 Apr 2023 02:09:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHZbKpCBmKbFexulkCLTCM8AA6Zz68qDq7Q
  • Thread-topic: [XEN][PATCH v5 12/17] common/device_tree: Add rwlock for dt_host

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?

> 
> 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.

> +
> +        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?

> +        }
> 
>          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®.