From: Maksym Planeta <mplaneta@os.inf.tu-dresden.de>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Moni Shoua <monis@mellanox.com>,
Doug Ledford <dledford@redhat.com>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 04/10] Protect kref_put with the lock
Date: Mon, 22 Jul 2019 17:28:51 +0200 [thread overview]
Message-ID: <c2fdbf86-acea-aebb-48c4-8c2f85a68978@os.inf.tu-dresden.de> (raw)
In-Reply-To: <20190722152559.GD7607@ziepe.ca>
On 22/07/2019 17:25, Jason Gunthorpe wrote:
> On Mon, Jul 22, 2019 at 05:14:20PM +0200, Maksym Planeta wrote:
>> Need to ensure that kref_put does not run concurrently with the loop
>> inside rxe_pool_get_key.
>>
>> Signed-off-by: Maksym Planeta <mplaneta@os.inf.tu-dresden.de>
>> drivers/infiniband/sw/rxe/rxe_pool.c | 18 ++++++++++++++++++
>> drivers/infiniband/sw/rxe/rxe_pool.h | 4 +---
>> 2 files changed, 19 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
>> index efa9bab01e02..30a887cf9200 100644
>> +++ b/drivers/infiniband/sw/rxe/rxe_pool.c
>> @@ -536,3 +536,21 @@ void *rxe_pool_get_key(struct rxe_pool *pool, void *key)
>> read_unlock_irqrestore(&pool->pool_lock, flags);
>> return node ? elem : NULL;
>> }
>> +
>> +static void rxe_dummy_release(struct kref *kref)
>> +{
>> +}
>> +
>> +void rxe_drop_ref(struct rxe_pool_entry *pelem)
>> +{
>> + int res;
>> + struct rxe_pool *pool = pelem->pool;
>> + unsigned long flags;
>> +
>> + write_lock_irqsave(&pool->pool_lock, flags);
>> + res = kref_put(&pelem->ref_cnt, rxe_dummy_release);
>> + write_unlock_irqrestore(&pool->pool_lock, flags);
>
> This doesn't make sense..
>
> If something is making the kref go to 0 while the node is still in the
> RB tree then that is a bug.
>
> You should never need to add locking around a kref_put.
>
From https://www.kernel.org/doc/Documentation/kref.txt
| The last rule (rule 3) is the nastiest one to handle. Say, for
| instance, you have a list of items that are each kref-ed, and you wish
| to get the first one. You can't just pull the first item off the list
| and kref_get() it. That violates rule 3 because you are not already
| holding a valid pointer. You must add a mutex (or some other lock).
> Jason
>
--
Regards,
Maksym Planeta
next prev parent reply other threads:[~2019-07-22 15:28 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-22 15:14 [PATCH 00/10] Refactor rxe driver to remove multiple race conditions Maksym Planeta
2019-07-22 15:14 ` [PATCH 01/10] Simplify rxe_run_task interface Maksym Planeta
2019-07-22 15:14 ` [PATCH 02/10] Remove counter that does not have a meaning anymore Maksym Planeta
2019-07-22 15:14 ` [PATCH 03/10] Make pool interface more type safe Maksym Planeta
2019-07-22 15:14 ` [PATCH 04/10] Protect kref_put with the lock Maksym Planeta
2019-07-22 15:25 ` Jason Gunthorpe
2019-07-22 15:28 ` Maksym Planeta [this message]
2019-07-22 15:14 ` [PATCH 05/10] Fix reference counting for rxe tasklets Maksym Planeta
2019-07-22 15:27 ` Jason Gunthorpe
2019-07-22 15:14 ` [PATCH 06/10] Remove pd form rxe_ah Maksym Planeta
2019-07-22 15:14 ` [PATCH 07/10] Pass the return value of kref_put further Maksym Planeta
2019-07-22 15:29 ` Jason Gunthorpe
2019-07-22 15:31 ` Maksym Planeta
2019-07-22 15:14 ` [PATCH 08/10] Move responsibility of cleaning up pool elements Maksym Planeta
2019-07-22 15:14 ` [PATCH 09/10] Consolidate resetting of QP's tasks into one place Maksym Planeta
2019-07-22 15:14 ` [PATCH 10/10] Replace tasklets with workqueues Maksym Planeta
2019-07-22 15:32 ` Jason Gunthorpe
2019-07-25 14:36 ` Maksym Planeta
2019-07-25 18:50 ` Jason Gunthorpe
2019-07-30 19:20 ` Maksym Planeta
2019-10-11 10:41 ` Maksym Planeta
2019-10-22 19:04 ` Jason Gunthorpe
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=c2fdbf86-acea-aebb-48c4-8c2f85a68978@os.inf.tu-dresden.de \
--to=mplaneta@os.inf.tu-dresden.de \
--cc=dledford@redhat.com \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=monis@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).