Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp546324pxt; Thu, 5 Aug 2021 06:07:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3DU+vm/UcNPHC5rXGZxj/WU8/uhK0qKUU4s18D8TwrAkDKHqvB5CoyNIDMn63SMaKQxry X-Received: by 2002:a5d:80d1:: with SMTP id h17mr239588ior.71.1628168870124; Thu, 05 Aug 2021 06:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628168870; cv=none; d=google.com; s=arc-20160816; b=Ky3TLF035T6AQ5TqWdS59s6nOum6m+2frUCVoqaWfzQ+cP5eSQUKa2gSbWAXNnlL5b QzqnEQA/tH9gXtfTMAOP1d6uyjrevrKwOdSV3hn3zERJKfp6sb8GWyLdV3Zw+4PHaWW8 njkRyP8j8asK+R6qKwYmSf+vJPPKXWJvCqSwaOUCHl70quovlLrbWTq3A+lJc47cNKJ+ koxkIBq3BVs7CB1Ok7Mcw9giaSUfOCwjcTSUVpQmYhBufAg3mADkn/DCDE1cO++F6z4p 7OiyBFmmNPjTXgpLHdsl4zWWK1lzoXZtfaCGCGApr8Wt/jQvWwSy24nFYUIs4KA7yaWw rw4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=l0mgzCxwG7dAr+4Mc0rz8GfSId+SC7xbluIBCS+DE2s=; b=begUMUKiGV6/xIicwZpcCK0RLTyuNp4dydhh+vZfoF9VPxausJXXoBqMSbXc/VxY3p wg1CrtviJPF4I5XReIxmLFkndh/nqlcnza5wqa/Vcci0NN1FYoq9hhBvGbWSplS4A7Qn LhzQ3w5qDuWyJUnXmD9KFSgiKeQJnjrlfbS/OPEzK2Sj6Eyy2hlV5NqObyU0vASEA0uq imA4ifA3/AB6XTOu05+TLiaq+lHet0en2k/+/bQgFaiznW3kjOqUsBi1ciYtbsfBzjb6 1fc08Pk+Fs9A49SWyvlF/qbN3HbG5FdWMBG4AezD55HKBeiihGoKPFyyvzrXHCIpcGUT fGsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pE9xZA0Y; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x10si7068027ilu.80.2021.08.05.06.07.37; Thu, 05 Aug 2021 06:07:50 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pE9xZA0Y; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240618AbhHEK7M (ORCPT + 99 others); Thu, 5 Aug 2021 06:59:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:51512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240080AbhHEK7L (ORCPT ); Thu, 5 Aug 2021 06:59:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F181961102; Thu, 5 Aug 2021 10:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628161137; bh=jpkqtKgVH0TlomV9uVXBdAe4Wn7c/wCtXDz5usqUrOU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pE9xZA0Y5HxP2T+20HNxQvo8BInmCpOlCJMcB+2rRpDaFpCTZ9ei39sZeCcVo3nUd zor/Ftyl+UcpK0KNqTHj3su1Veaf7rjT8wMETFKUJGFcg2pg9r2A+Ly2clPNgvwPux G+gwhBu+jsK+veuLE8sfoxJ0xVtEfszZHNbtvuFeHpCwH/QsjOoarmEP703AJg9M9A Ev/NniToNtQWNu35ykqTkUzTWPKtisS5XhG0Wrzl+rcd0z7CGVMSYGcIwb0FhE3Yy7 kp3tGuVfOW2v5LC8pd9Tgf4D534td0dU36H8cd437vE8PltSvSykBCUijWvKHWGNao pbBAo/3JaKHAg== Date: Thu, 5 Aug 2021 13:58:53 +0300 From: Leon Romanovsky To: YueHaibing Cc: liangwenpeng@huawei.com, liweihang@huawei.com, dledford@redhat.com, jgg@ziepe.ca, chenglang@huawei.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH -next] RDMA/hns: Fix return in hns_roce_rereg_user_mr() Message-ID: References: <20210804125939.20516-1-yuehaibing@huawei.com> <974d3309-3617-6413-5a8d-c92b1b2f8dfe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <974d3309-3617-6413-5a8d-c92b1b2f8dfe@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 05, 2021 at 05:29:25PM +0800, YueHaibing wrote: > 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. The thing is that it undefined state in the kernel. What will be if user will change access_flags and try to use that "broken" MR anyway? Will you catch it? > > Also, mlx4_ib_rereg_user_mr seems to do the same thing. mlx4 does many crazy things. > > > > > 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 > >>>> > >>> . > >>> > > . > >