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

Re: [PATCH] xen/scsiback: don't call scsiback_free_translation_entry() under lock


  • To: Juergen Gross <jgross@xxxxxxxx>
  • From: Oleksandr Tyshchenko <Oleksandr_Tyshchenko@xxxxxxxx>
  • Date: Tue, 28 Mar 2023 15:47:05 +0000
  • Accept-language: en-US, ru-RU
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.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=0lyl2FbygBKyUAq7wNX6N1p7kZaXAlPRDYbwEJ10+l4=; b=kSiGk9dDUrIXOH2U8dmotPQQdv+BmumbJxq4wG9HWZg0cbeMzHoxQ6l3TUJsIn5vLnqcC3AAu4xJg8GTxNKhrdYvVRWoaL3+X2FquTmBatpRijk4NIsflvtNnHtvo6Z5Xyw2yHIqhlY16/2H2HhtZqlfWpoeIAbx/cbHkria4P6mrLNA9xi+ehyJu8bSSAaMOl8eRlhoZjtzzqUJH7+lZyE5d0DL8G35bjS5ICD+D2IZJiDJbBqwGGn4+mtlZaoQn9sCH9chiKEDO1+0/v3Eqo9M20hVlnpHorB1nl4nCBwYGf1ox+tH3/4zC9CTewi0DJ+n3OTn7DQYQV2G0qkg9w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZvgsIQgVF6MtxZ4IWdtKTfYaOgm1RofK2WagQ39n+Fxh084h+sLbtZNNUSLJoZY2xYsM30mX5tN56nnx+WnhFhMprbMNvwBEMMniKD0bd8Hvw1Kaoyn32XQF27wpPCIWVYr9dX1kuKXFFCTxHQew7nXYtKBBDdF63LPZqHw4KkDZST/WHoJYWojxl4IlPbjJY0KFjDcwxVX7rAlJVV9Likc93gS3b3EDUUSFUMjNzZyyiqUD0llsCEw2FnQtbR7Euoe4ccqZO5Ddp14HtzjIhakPHDPMfrTaKdz5nnVBwIo9CNHWdlXxZ+At21rEor4L+9oEXA3sdzF7f5pQ50AItw==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Dan Carpenter <error27@xxxxxxxxx>, "linux-scsi@xxxxxxxxxxxxxxx" <linux-scsi@xxxxxxxxxxxxxxx>, "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>
  • Delivery-date: Tue, 28 Mar 2023 15:47:37 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZYVG+3GUB3O/23kquKYQ39EYPJq8QVnGA
  • Thread-topic: [PATCH] xen/scsiback: don't call scsiback_free_translation_entry() under lock


On 28.03.23 11:46, Juergen Gross wrote:

Hello Juergen

> scsiback_free_translation_entry() shouldn't be called under spinlock,
> as it can sleep.
> 
> This requires to split removing a translation entry from the v2p list
> from actually calling kref_put() for the entry.
> 
> Reported-by: Dan Carpenter <error27@xxxxxxxxx>
> Link: 
> https://urldefense.com/v3/__https://lore.kernel.org/lkml/Y*JUIl64UDmdkboh@kadam/__;Kw!!GF_29dbcQIUBPA!23IKdVhamoFq8ptUnprd_TubDMObj-0QAalsGiffBHCeEdOuwrq7z4ohg92Sj0olgl0nh73oXvSr-i1zqXhY$
>  [lore[.]kernel[.]org]
> Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
> ---
>   drivers/xen/xen-scsiback.c | 27 ++++++++++++++-------------
>   1 file changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
> index 954188b0b858..294f29cdc7aa 100644
> --- a/drivers/xen/xen-scsiback.c
> +++ b/drivers/xen/xen-scsiback.c
> @@ -1010,12 +1010,6 @@ static int scsiback_add_translation_entry(struct 
> vscsibk_info *info,
>       return err;
>   }
>   
> -static void __scsiback_del_translation_entry(struct v2p_entry *entry)
> -{
> -     list_del(&entry->l);
> -     kref_put(&entry->kref, scsiback_free_translation_entry);
> -}
> -
>   /*
>     Delete the translation entry specified
>   */
> @@ -1024,18 +1018,20 @@ static int scsiback_del_translation_entry(struct 
> vscsibk_info *info,
>   {
>       struct v2p_entry *entry;
>       unsigned long flags;
> -     int ret = 0;
>   
>       spin_lock_irqsave(&info->v2p_lock, flags);
>       /* Find out the translation entry specified */
>       entry = scsiback_chk_translation_entry(info, v);
>       if (entry)
> -             __scsiback_del_translation_entry(entry);
> -     else
> -             ret = -ENOENT;
> +             list_del(&entry->l);
>   
>       spin_unlock_irqrestore(&info->v2p_lock, flags);
> -     return ret;
> +
> +     if (!entry)
> +             return -ENOENT;
> +
> +     kref_put(&entry->kref, scsiback_free_translation_entry);
> +     return 0;
>   }
>   
>   static void scsiback_do_add_lun(struct vscsibk_info *info, const char 
> *state,
> @@ -1239,14 +1235,19 @@ static void scsiback_release_translation_entry(struct 
> vscsibk_info *info)
>   {
>       struct v2p_entry *entry, *tmp;
>       struct list_head *head = &(info->v2p_entry_lists);
> +     struct list_head tmp_list;


I would use LIST_HEAD(tmp_list);

>       unsigned long flags;
>   
>       spin_lock_irqsave(&info->v2p_lock, flags);
>   
> -     list_for_each_entry_safe(entry, tmp, head, l)
> -             __scsiback_del_translation_entry(entry);
> +     list_cut_before(&tmp_list, head, head);

so we just move all entries from head to tmp_list here to be processed...

>   
>       spin_unlock_irqrestore(&info->v2p_lock, flags);

... when the lock is not held, ok

Patch LGTM, but one (maybe stupid) question to clarify.

Why do we need to use a lock here in the first place? The 
scsiback_release_translation_entry() gets called when the driver 
instance is about to be removed and *after* the disconnection from 
otherend (so no requests are expected), so what else might cause this 
list to be accessed concurrently?


> +
> +     list_for_each_entry_safe(entry, tmp, &tmp_list, l) {
> +             list_del(&entry->l);
> +             kref_put(&entry->kref, scsiback_free_translation_entry);
> +     }
>   }
>   
>   static void scsiback_remove(struct xenbus_device *dev)

 


Rackspace

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