mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleksandr Tyshchenko <Oleksandr_Tyshchenko@epam.com>
To: Juergen Gross <jgross@suse.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	Dan Carpenter <error27@gmail.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] xen/scsiback: don't call scsiback_free_translation_entry() under lock
Date: Wed, 29 Mar 2023 06:50:02 +0000	[thread overview]
Message-ID: <9e94aeea-b56f-ef97-089c-84b669367002@epam.com> (raw)
In-Reply-To: <38d97163-5c02-9193-5c20-ab3b5274bd51@suse.com>



On 29.03.23 09:20, Juergen Gross wrote:

Hello Juergen


> On 28.03.23 17:47, Oleksandr Tyshchenko wrote:
>>
>>
>> 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@gmail.com>
>>> 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@suse.com>
>>> ---
>>>    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);
> 
> There is no need to initialize it, so I think I will keep it as is.
> 
>>
>>>        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...
> 
> Correct.
> 
>>
>>>        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?
> 
> Maybe nothing, but I think it is good practice to keep the lock in order
> to avoid future code changes to cause problems.


Thanks for the explanation, it sounds reasonable to me.

Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

> 
> 
> Juergen
> 

      reply	other threads:[~2023-03-29  6:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28  8:46 Juergen Gross
2023-03-28 15:47 ` Oleksandr Tyshchenko
2023-03-29  6:20   ` Juergen Gross
2023-03-29  6:50     ` Oleksandr Tyshchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e94aeea-b56f-ef97-089c-84b669367002@epam.com \
    --to=oleksandr_tyshchenko@epam.com \
    --cc=error27@gmail.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®