[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [XEN][RFC PATCH v3 07/14] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller
- To: Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
- From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
- Date: Mon, 14 Mar 2022 15:58:22 +0000
- Accept-language: en-GB, 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=tZ0teu4xHkZMW5oIDulrSlOAgq2X79hUYcgZGFr32Fw=; b=c9I94y/c3UDCIGhejYIjwBP7yZ6yZ7M9OhUct4PJ6xtFKOzoC/cpupcQy4bnCvlcVd+q5FtXdbGhktUFISQy9PRJYYkYN9waWd4Cc8evIO1HeCy/XD3lWyGwxxKL797Z322cH3wH7DYfiyYVUNjnX2uMDp5zFVByvuETs51s1uyJfbNXoMIhht281/4mjhZKNg+5LWPc2jQq0nYPaBzYCo+3i1/4+93fPesbeH9HJgNsxYdEHggiIuDEC/0mApit4sQStu2i9JW7EH4LrXrmbIjbR6pEY6rxIvhckzYdh/iptIhvGtS90N3qqrjNwYXNi5+/LZ3ivmizmAK0qUYczg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iQJ0258Mm37+ENhouwf8jomwENrYouUm0yAU14Ut3v6KltPKH9coKPCcVUX/v8pO8WPaKATs3lsYRGCuZnNOlhwBpEM9vOGK/a+iL+pI7jV8Bw1u6qtk34OjBOOog2fgnQoHWJw+sqJvvudj9Z++4h5Nu8ipYQXm2IUJXc9IClHSYwQ/QwssrJRXzsJ6/turFtT0L1qSoSM+BIBE4UVhE4d2hZFSqBa9PdjnO3wdlVzVg3Vyvo2+e8gfwM08R6NFaIBGz26sRrUup8vLgz6EqgDxZ9i/fT9/jNCr7lyjuSdIBwBGk1euq6mNHGxUYD7k+Nq9fsEcgD8iWjT85sgICQ==
- Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
- Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "sstabellini@xxxxxxxxxx" <sstabellini@xxxxxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, "volodymyr_babchuk@xxxxxxxx" <volodymyr_babchuk@xxxxxxxx>
- Delivery-date: Mon, 14 Mar 2022 15:58:46 +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: AQHYMyV0/VHCKbIU/Emb5cXwtoiAAKy/El2A
- Thread-topic: [XEN][RFC PATCH v3 07/14] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller
> On 8 Mar 2022, at 19:46, Vikram Garhwal <fnu.vikram@xxxxxxxxxx> wrote:
>
> Rename iommu_dt_device_is_assigned() to iommu_dt_device_is_assigned_lock().
>
> Moving spin_lock to caller was done to prevent the concurrent access to
> iommu_dt_device_is_assigned while doing add/remove/assign/deassign.
>
> Signed-off-by: Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
> ---
> xen/drivers/passthrough/device_tree.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/xen/drivers/passthrough/device_tree.c
> b/xen/drivers/passthrough/device_tree.c
> index 98f2aa0dad..b3b04f8e03 100644
> --- a/xen/drivers/passthrough/device_tree.c
> +++ b/xen/drivers/passthrough/device_tree.c
> @@ -83,16 +83,14 @@ 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_lock(const struct dt_device_node
> *dev)
> {
> bool_t assigned = 0;
>
You can add an ASSERT(spin_is_locked(&dtdevs_lock)); to be sure, however the
name is pretty clear,
so for me with or without it:
Reviewed-by: Luca Fancellu <luca.fancellu@xxxxxxx>
> if ( !dt_device_is_protected(dev) )
> return 0;
>
> - spin_lock(&dtdevs_lock);
> assigned = !list_empty(&dev->domain_list);
> - spin_unlock(&dtdevs_lock);
>
> return assigned;
> }
> @@ -225,12 +223,17 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl,
> struct domain *d,
>
> if ( domctl->cmd == XEN_DOMCTL_test_assign_device )
> {
> - if ( iommu_dt_device_is_assigned(dev) )
> + spin_lock(&dtdevs_lock);
> +
> + if ( iommu_dt_device_is_assigned_lock(dev) )
> {
> printk(XENLOG_G_ERR "%s already assigned.\n",
> dt_node_full_name(dev));
> ret = -EINVAL;
> }
> +
> + spin_unlock(&dtdevs_lock);
> +
> break;
> }
>
>
|