Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp402712pxt; Thu, 5 Aug 2021 02:33:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5zP8BWLHLTZ+Lwm+VzT677fDdrJdb6jBLG3HdZ4kb9sBtEOlHfEVpIqYXocy5aJGu9rxg X-Received: by 2002:a50:bb2e:: with SMTP id y43mr5358537ede.103.1628155994644; Thu, 05 Aug 2021 02:33:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628155994; cv=none; d=google.com; s=arc-20160816; b=tcIXNdxa2haMy2fJomMy6Z2j2OGKe2GYQCymfzRl93ugpS5tm7wIvUH+bZmN2pdMNZ CRHHijUHbgSzFBFp5f/9sIckWG/fZwpKzI6iwwIjq04JZYuizzHg1JiG3an4w2GclUoI UcG32P7k9yOf1ryUTGZsfLkM1Qxy3Se6I20v7+s7hvHXk8fDOpHWe9pkxlczEszk2YPk g5TZa/LA9x/YY/i3ZRlZ7y7KHkgmdA37PjtPdudEdiTZHsCeBdQ7qATTmjy/l9R/tgFo IjYgHEx1ertWsmfbMOVe+oAD69Pghhw0JTwZ4aXCqz5sJ3icomNsYIdaQhnuYbl9jC+0 VPRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=zdsM6sYx9Uwo7+VQYCHrapZKF5T0NaZO13s164H5qrM=; b=wMW2hjIJyyOdWMLVqpf5UdwUXWWlGf8uSlG17YghOvSDbbPhw4N30wkXNv29PcxFTl ErcybR5H3vf6obr6PXmATo2Gko/VHdWVzro9wPKzU0IKDuAcUuPNgi2BYfKL0e0Jq/Ll c4a6w59IzBD/1k9anMPylEVXUFu3H8Mt7M8lrdcipKPoLqcNNtR4Upjg7cSbGoQXva1R JdnrSQjo3vO5Pv3PBJCvDWAukDHl/2rRhvVYVfXBPNsWF4IBQyevVVUpE0XXpY6pj3p8 bwNtzCa9bWvF1niJbhFDkEPSHGDzAjvNX6XnTLc5uexZL00XqL0AxWPeuuyjX/7xS2QH ltNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si5228933edc.10.2021.08.05.02.32.50; Thu, 05 Aug 2021 02:33:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237773AbhHEJ3o (ORCPT + 99 others); Thu, 5 Aug 2021 05:29:44 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:12454 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbhHEJ3n (ORCPT ); Thu, 5 Aug 2021 05:29:43 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GgNWh5By0zcl7t; Thu, 5 Aug 2021 17:25:52 +0800 (CST) Received: from dggema769-chm.china.huawei.com (10.1.198.211) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Thu, 5 Aug 2021 17:29:27 +0800 Received: from [10.174.179.215] (10.174.179.215) by dggema769-chm.china.huawei.com (10.1.198.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 5 Aug 2021 17:29:26 +0800 Subject: Re: [PATCH -next] RDMA/hns: Fix return in hns_roce_rereg_user_mr() To: Leon Romanovsky CC: , , , , , , References: <20210804125939.20516-1-yuehaibing@huawei.com> From: YueHaibing Message-ID: <974d3309-3617-6413-5a8d-c92b1b2f8dfe@huawei.com> Date: Thu, 5 Aug 2021 17:29:25 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.215] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggema769-chm.china.huawei.com (10.1.198.211) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/8/5 11:40, Leon Romanovsky wrote: > On Thu, Aug 05, 2021 at 10:36:03AM +0800, YueHaibing wrote: >> On 2021/8/4 21:53, Leon Romanovsky wrote: >>> On Wed, Aug 04, 2021 at 08:59:39PM +0800, YueHaibing wrote: >>>> If re-registering an MR in hns_roce_rereg_user_mr(), we should >>>> return NULL instead of pass 0 to ERR_PTR. >>>> >>>> Fixes: 4e9fc1dae2a9 ("RDMA/hns: Optimize the MR registration process") >>>> Signed-off-by: YueHaibing >>>> --- >>>> drivers/infiniband/hw/hns/hns_roce_mr.c | 4 +++- >>>> 1 file changed, 3 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c >>>> index 006c84bb3f9f..7089ac780291 100644 >>>> --- a/drivers/infiniband/hw/hns/hns_roce_mr.c >>>> +++ b/drivers/infiniband/hw/hns/hns_roce_mr.c >>>> @@ -352,7 +352,9 @@ struct ib_mr *hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, >>>> free_cmd_mbox: >>>> hns_roce_free_cmd_mailbox(hr_dev, mailbox); >>>> >>>> - return ERR_PTR(ret); >>>> + if (ret) >>>> + return ERR_PTR(ret); >>>> + return NULL; >>>> } >>> >>> I don't understand this function, it returns or ERR_PTR() or NULL, but >>> should return &mr->ibmr in success path. How does it work? >> >> Did you means hns_roce_reg_user_mr()? >> >> hns_roce_rereg_user_mr() returns ERR_PTR() on failure, and return NULL on success, >> >> In ib_uverbs_rereg_mr(), old mr will be used if rereg_user_mr() return NULL, see: >> >> 829 new_mr = ib_dev->ops.rereg_user_mr(mr, cmd.flags, cmd.start, cmd.length, >> 830 cmd.hca_va, cmd.access_flags, new_pd, >> 831 &attrs->driver_udata); >> 832 if (IS_ERR(new_mr)) { >> 833 ret = PTR_ERR(new_mr); >> 834 goto put_new_uobj; >> 835 } >> 836 if (new_mr) { >> ..... >> 860 mr = new_mr; >> 861 } else { >> 862 if (cmd.flags & IB_MR_REREG_PD) { >> 863 atomic_dec(&orig_pd->usecnt); >> 864 mr->pd = new_pd; >> 865 atomic_inc(&new_pd->usecnt); >> 866 } >> 867 if (cmd.flags & IB_MR_REREG_TRANS) >> 868 mr->iova = cmd.hca_va; >> 869 } > > You overwrite various fields in old_mr when executing hns_roce_rereg_user_mr(). > For example mr->access flags, which is not returned to the original > state after all failures. IMO, if ibv_rereg_mr failed, the mr is in undefined state, user needs to call ibv_dereg_mr in order to release it, so there no need to recover the original state. Also, mlx4_ib_rereg_user_mr seems to do the same thing. > > Also I'm not so sure about if it is valid to return NULL in all flows. > > Thanks > >> >> >>> >>> Thanks >>> >>>> >>>> int hns_roce_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata) >>>> -- >>>> 2.17.1 >>>> >>> . >>> > . >