linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Weihang Li <liweihang@hisilicon.com>
To: Jason Gunthorpe <jgg@ziepe.ca>, "Zengtao (B)" <prime.zeng@hisilicon.com>
Cc: "leon@kernel.org" <leon@kernel.org>,
	"dledford@redhat.com" <dledford@redhat.com>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	Linuxarm <linuxarm@huawei.com>
Subject: Re: [PATCH rdma-core 1/7] libhns: Fix calculation errors with ilog32()
Date: Sat, 23 Nov 2019 10:43:02 +0800	[thread overview]
Message-ID: <35086d20-0f48-c5a8-dae7-afaa9b4ed3e4@hisilicon.com> (raw)
In-Reply-To: <20191122180933.GE7448@ziepe.ca>



On 2019/11/23 2:09, Jason Gunthorpe wrote:
> On Fri, Nov 22, 2019 at 02:58:44AM +0000, Zengtao (B) wrote:
>>> From: linux-rdma-owner@vger.kernel.org
>>> [mailto:linux-rdma-owner@vger.kernel.org] On Behalf Of Weihang Li
>>> Sent: Thursday, November 21, 2019 9:19 AM
>>> To: jgg@ziepe.ca; leon@kernel.org
>>> Cc: dledford@redhat.com; linux-rdma@vger.kernel.org; Linuxarm
>>> Subject: [PATCH rdma-core 1/7] libhns: Fix calculation errors with ilog32()
>>>
>>> Current calculation results using ilog32() is larger than expected, which
>>> will lead to driver broken. The following is the log when QP creations
>>> fails:
>>>
>>> [   81.294844] hns3 0000:7d:00.0 hns_0: check SQ size error!
>>> [   81.294848] hns3 0000:7d:00.0 hns_0: check SQ size error!
>>> [   81.300225] hns3 0000:7d:00.0 hns_0: Sanity check sq size failed
>>> [   81.300227] hns3 0000:7d:00.0: hns_roce_set_user_sq_size error for
>>> create qp
>>> [   81.305602] hns3 0000:7d:00.0 hns_0: Sanity check sq size failed
>>> [   81.305603] hns3 0000:7d:00.0: hns_roce_set_user_sq_size error for
>>> create qp
>>> [   81.311589] hns3 0000:7d:00.0 hns_0: Create RC QP 0x000000
>>> failed(-22)
>>> [   81.318603] hns3 0000:7d:00.0 hns_0: Create RC QP 0x000000
>>> failed(-22)
>>>
>>> Fixes: b6cd213b276f ("libhns: Refactor for creating qp")
>>> Signed-off-by: Weihang Li <liweihang@hisilicon.com>
>>>  providers/hns/hns_roce_u_verbs.c | 11 ++++++-----
>>>  1 file changed, 6 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/providers/hns/hns_roce_u_verbs.c
>>> b/providers/hns/hns_roce_u_verbs.c
>>> index 9d222c0..bd5060d 100644
>>> +++ b/providers/hns/hns_roce_u_verbs.c
>>> @@ -645,7 +645,8 @@ static int hns_roce_calc_qp_buff_size(struct
>>> ibv_pd *pd, struct ibv_qp_cap *cap,
>>>  	int page_size = to_hr_dev(pd->context->device)->page_size;
>>>
>>>  	if (to_hr_dev(pd->context->device)->hw_version ==
>>> HNS_ROCE_HW_VER1) {
>>> -		qp->rq.wqe_shift = ilog32(sizeof(struct hns_roce_rc_rq_wqe));
>>> +		qp->rq.wqe_shift =
>>> +				ilog32(sizeof(struct hns_roce_rc_rq_wqe)) - 1;
>>>
>>>  		qp->buf_size = align((qp->sq.wqe_cnt << qp->sq.wqe_shift),
>>>  				     page_size) +
>>> @@ -662,7 +663,7 @@ static int hns_roce_calc_qp_buff_size(struct
>>> ibv_pd *pd, struct ibv_qp_cap *cap,
>>>  	} else {
>>>  		unsigned int rqwqe_size = HNS_ROCE_SGE_SIZE *
>>> cap->max_recv_sge;
>>>
>>> -		qp->rq.wqe_shift = ilog32(rqwqe_size);
>>> +		qp->rq.wqe_shift = ilog32(rqwqe_size) - 1;
>>>
>>>  		if (qp->sq.max_gs > HNS_ROCE_SGE_IN_WQE || type ==
>>> IBV_QPT_UD)
>>>  			qp->sge.sge_shift = HNS_ROCE_SGE_SHIFT;
>>> @@ -747,8 +748,8 @@ static void hns_roce_set_qp_params(struct
>>> ibv_pd *pd,
>>>  		qp->rq.wqe_cnt =
>>> roundup_pow_of_two(attr->cap.max_recv_wr);
>>>  	}
>>>
>>> -	qp->sq.wqe_shift = ilog32(sizeof(struct hns_roce_rc_send_wqe));
>>> -	qp->sq.shift = ilog32(qp->sq.wqe_cnt);
>>> +	qp->sq.wqe_shift = ilog32(sizeof(struct hns_roce_rc_send_wqe)) - 1;
>>> +	qp->sq.shift = ilog32(qp->sq.wqe_cnt) - 1;
>>
>> One suggestion, it's better to introduce a new micro instead of ilog32(x) -1.
> 
> Is the -1 even correct?
> 
> I would have guessed something called shift wants to be:
> 
>    shift = ilog32(qp->sq.wqe_cnt - 1)
> 
> Such that 
>    1 << shift == wqe_cnt
>        When wqe_cnt is a power of two.
>    1 << shift > wqe_cnt
>        When wqe_cnt is not a power of two.
> 
> Jason
> 

That's right, shift = ilog32(n - 1) is always right, but result of
ilog32(n) - 1 is only correct when n is a power of two.

Will modify to ilog32(n - 1).

Thank you
Weihang


> .
> 


  reply	other threads:[~2019-11-23  2:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-21  1:19 [PATCH rdma-core 0/7] libhns: Bugfix for hip08 Weihang Li
2019-11-21  1:19 ` [PATCH rdma-core 1/7] libhns: Fix calculation errors with ilog32() Weihang Li
2019-11-22  2:58   ` Zengtao (B)
2019-11-22  6:16     ` Weihang Li
2019-11-22 18:09     ` Jason Gunthorpe
2019-11-23  2:43       ` Weihang Li [this message]
2019-11-21  1:19 ` [PATCH rdma-core 2/7] libhns: Optimize bind_mw for fixing null pointer access Weihang Li
2019-11-22  3:02   ` Zengtao (B)
2019-11-22  6:40     ` Weihang Li
2019-11-21  1:19 ` [PATCH rdma-core 3/7] libhns: Bugfix for assigning sl Weihang Li
2019-11-21  1:19 ` [PATCH rdma-core 4/7] libhns: Bugfix for cleaning cq Weihang Li
2019-11-21  1:19 ` [PATCH rdma-core 5/7] libhns: Bugfix for updating qp params Weihang Li
2019-11-21  1:19 ` [PATCH rdma-core 6/7] libhns: Avoid null pointer operation Weihang Li
2019-11-21  1:19 ` [PATCH rdma-core 7/7] libhns: Return correct value of cqe num when flushing cqe failed Weihang Li

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=35086d20-0f48-c5a8-dae7-afaa9b4ed3e4@hisilicon.com \
    --to=liweihang@hisilicon.com \
    --cc=dledford@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=prime.zeng@hisilicon.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).