public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: liweihang <liweihang@huawei.com>
To: Jason Gunthorpe <jgg@nvidia.com>,
	"Marciniszyn, Mike" <mike.marciniszyn@cornelisnetworks.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: "dledford@redhat.com" <dledford@redhat.com>,
	"leon@kernel.org" <leon@kernel.org>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	Linuxarm <linuxarm@huawei.com>,
	"Dalessandro, Dennis" <dennis.dalessandro@cornelisnetworks.com>
Subject: Re: [PATCH v3 for-next 13/13] RDMA/rdmavt: Use refcount_t instead of atomic_t on refcount of rvt_mcast
Date: Fri, 28 May 2021 03:58:42 +0000	[thread overview]
Message-ID: <8de36c1f7a0a4e839c6151b0963a894b@huawei.com> (raw)
In-Reply-To: 20210527131558.GB1002214@nvidia.com

On 2021/5/27 21:16, Jason Gunthorpe wrote:
> On Thu, May 27, 2021 at 01:08:37PM +0000, Marciniszyn, Mike wrote:
>>> +++ b/drivers/infiniband/hw/hfi1/verbs.c
>>> @@ -534,7 +534,8 @@ static inline void hfi1_handle_packet(struct
>>> hfi1_packet *packet,
>>>  		 * Notify rvt_multicast_detach() if it is waiting for us
>>>  		 * to finish.
>>>  		 */
>>> -		if (atomic_dec_return(&mcast->refcount) <= 1)
>>> +		refcount_dec(&mcast->refcount);
>>> +		if (refcount_read(&mcast->refcount) <= 1)
>>>  			wake_up(&mcast->wait);
>>
>> Is there refcount_ that preserves the atomic characteristics of the single call?
> 
> You are supposed to us refcount_dec_and_test() for patterns like this,
> this hunk looks wrong to me
> 
> Jason
> 

I made a mistake, thank you.

refcount_dec_and_test() test only if the refcount is 0, so I couldn't find a
good way to replace the atomic_t with refcount_t here.

And there is no refcount_dec/inc_return() for a refcount_t, I found some
previous disscussdion:

https://www.openwall.com/lists/kernel-hardening/2016/11/28/8
https://www.openwall.com/lists/kernel-hardening/2016/12/01/1
https://lkml.org/lkml/2017/9/1/389
https://yhbt.net/lore/all/20200921112218.GB2139@willie-the-truck/t/#md37f8b6084bccbc0ebf76ba249c069372b4d8497

I think such functions undermines the design of refcount. But to be honest, I
didn't find a clear reason.

Peter, could you please explain why you said "add_return and sub_return are
horrible interface for refcount"?

You can review the whole patch at:

https://patchwork.kernel.org/project/linux-rdma/patch/1621925504-33019-14-git-send-email-liweihang@huawei.com/

Thanks
Weihang

  reply	other threads:[~2021-05-28  3:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-25  6:51 [PATCH v3 for-next 00/13] RDMA: Use refcount_t for reference counting Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 01/13] RDMA/core: Use refcount_t instead of atomic_t on refcount of iwcm_id_private Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 02/13] RDMA/core: Use refcount_t instead of atomic_t on refcount of iwpm_admin_data Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 03/13] RDMA/core: Use refcount_t instead of atomic_t on refcount of ib_mad_snoop_private Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 04/13] RDMA/core: Use refcount_t instead of atomic_t on refcount of mcast_member Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 05/13] RDMA/core: Use refcount_t instead of atomic_t on refcount of mcast_port Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 06/13] RDMA/core: Use refcount_t instead of atomic_t on refcount of mcast_group Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 07/13] RDMA/core: Use refcount_t instead of atomic_t on refcount of ib_uverbs_device Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 08/13] RDMA/hns: Use refcount_t instead of atomic_t for CQ reference counting Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 09/13] RDMA/hns: Use refcount_t instead of atomic_t for SRQ " Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 10/13] RDMA/hns: Use refcount_t instead of atomic_t for QP " Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 11/13] RDMA/cxgb4: Use refcount_t instead of atomic_t for " Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 12/13] RDMA/ipoib: " Weihang Li
2021-05-25  6:51 ` [PATCH v3 for-next 13/13] RDMA/rdmavt: Use refcount_t instead of atomic_t on refcount of rvt_mcast Weihang Li
2021-05-27 13:08   ` Marciniszyn, Mike
2021-05-27 13:15     ` Jason Gunthorpe
2021-05-28  3:58       ` liweihang [this message]
2021-05-28  7:01         ` Peter Zijlstra
2021-05-28  8:22           ` liweihang

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=8de36c1f7a0a4e839c6151b0963a894b@huawei.com \
    --to=liweihang@huawei.com \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=dledford@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mike.marciniszyn@cornelisnetworks.com \
    --cc=peterz@infradead.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