linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Sagi Grimberg <sagi@grimberg.me>
To: Israel Rukshin <israelr@mellanox.com>,
	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 23:42:25 -0700	[thread overview]
Message-ID: <edbcdf17-ef8c-f937-bea6-b5bdffb7b202@grimberg.me> (raw)
In-Reply-To: <b5111042-d90a-0c48-6fe0-3cceca1b75a2@mellanox.com>



On 3/30/20 2:37 AM, Israel Rukshin wrote:
> 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().

You're right.

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

That is fine with me, assuming we have a proper comment.

But if we take a step back, nvmet_rdma_create_queue_ib does not create
the cm_id, so why should destroy_queue_ib destroy it?

What if we made destroying the cm_id in release_work (out of 
nvmet_rdma_free_queue) and have the accept error path return a normal
negative ret to implicitly destroy the cm_id?

In a sense, that would make the behavior symmetric. Thoughts?

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

  reply	other threads:[~2020-03-31  6:42 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
2020-03-31  6:42         ` Sagi Grimberg [this message]
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=edbcdf17-ef8c-f937-bea6-b5bdffb7b202@grimberg.me \
    --to=sagi@grimberg.me \
    --cc=hch@lst.de \
    --cc=israelr@mellanox.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=maxg@mellanox.com \
    --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).