linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Israel Rukshin <israelr@mellanox.com>
To: Sagi Grimberg <sagi@grimberg.me>,
	Max Gurtovoy <maxg@mellanox.com>,
	Linux-nvme <linux-nvme@lists.infradead.org>,
	Christoph Hellwig <hch@lst.de>
Cc: Shlomi Nimrodi <shlomin@mellanox.com>
Subject: Re: [PATCH] nvmet-rdma: Fix double free of rdma queue
Date: Mon, 30 Mar 2020 12:37:19 +0300	[thread overview]
Message-ID: <b5111042-d90a-0c48-6fe0-3cceca1b75a2@mellanox.com> (raw)
In-Reply-To: <f356a0d4-2e05-f629-ebab-a55e7e0c369b@grimberg.me>

On 3/30/2020 11:56 AM, Sagi Grimberg wrote:
>
>>>> diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
>>>> index 37d262a..59209e3 100644
>>>> --- a/drivers/nvme/target/rdma.c
>>>> +++ b/drivers/nvme/target/rdma.c
>>>> @@ -1380,13 +1380,14 @@ static void 
>>>> nvmet_rdma_queue_connect_fail(struct rdma_cm_id *cm_id,
>>>>   {
>>>>       WARN_ON_ONCE(queue->state != NVMET_RDMA_Q_CONNECTING);
>>>>   +    pr_err("failed to connect queue %d\n", queue->idx);
>>>> +
>>>>       mutex_lock(&nvmet_rdma_queue_mutex);
>>>> -    if (!list_empty(&queue->queue_list))
>>>> +    if (!list_empty(&queue->queue_list)) {
>>>>           list_del_init(&queue->queue_list);
>>>> +        schedule_work(&queue->release_work);
>>>
>>> This has a hidden assumption that the connect handler already
>>> scheduled the release.
>>>
>>> Why don't we simply not queue the release_work in the accept
>>> failure and return a negative status code to implicitly remove the
>>> cm_id? this way we will never see any cm events and we don't
>>> need to handle it.
>>
>> This changes the flow but I guess we can check this out.
>>
>> But still, this flow can be called from 3 different events 
>> (RDMA_CM_EVENT_REJECTED, RDMA_CM_EVENT_UNREACHABLE, 
>> RDMA_CM_EVENT_CONNECT_ERROR) so I prefer to locate the schedule_work 
>> under the "if".
>
> This if is only checked in connect error. Anyway, if you feel that
> this flow is racy, perhaps implement a proper serialization, instead
> of checking a random "if" that makes the reader think why are they
> even related.

This "if" is exactly like we are doing at nvmet_rdma_queue_disconnect().

All the other places before calling __nvmet_rdma_queue_disconnect() 
delete the queue from the list.

So I guess my change also protect us from races with 
nvmet_rdma_delete_ctrl/nvmet_rdma_remove_one.

Beside that, why do we need to check if the list is not empty before 
removing it from the list at nvmet_rdma_queue_connect_fail()?

I don't see a reason why to remove only the queue from the list without 
schedule the release work.


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  reply	other threads:[~2020-03-30  9:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-29 10:21 [PATCH] nvmet-rdma: Fix double free of rdma queue Israel Rukshin
2020-03-30  4:36 ` Sagi Grimberg
2020-03-30  8:22   ` Max Gurtovoy
2020-03-30  8:56     ` Sagi Grimberg
2020-03-30  9:37       ` Israel Rukshin [this message]
2020-03-31  6:42         ` Sagi Grimberg
2020-04-05 14:43           ` Israel Rukshin
2020-04-06  7:14             ` Sagi Grimberg

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=b5111042-d90a-0c48-6fe0-3cceca1b75a2@mellanox.com \
    --to=israelr@mellanox.com \
    --cc=hch@lst.de \
    --cc=linux-nvme@lists.infradead.org \
    --cc=maxg@mellanox.com \
    --cc=sagi@grimberg.me \
    --cc=shlomin@mellanox.com \
    /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;
as well as URLs for NNTP newsgroup(s).