Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2356063rdg; Sun, 13 Aug 2023 22:39:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFX1zku7WmSWAecuulYrOvcj1qKqgs95xtd74PKv22p5JcDW6GLLjQrPLM0RlAO+KjEzO8e X-Received: by 2002:a17:907:774e:b0:992:ef60:aadd with SMTP id kx14-20020a170907774e00b00992ef60aaddmr9514703ejc.13.1691991585489; Sun, 13 Aug 2023 22:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691991585; cv=none; d=google.com; s=arc-20160816; b=PsQsMNMTQ/kiCNuVi+1NW4XhnwN+MzFgx2JNvyj8ganw03dkZ38Zz+S945CvYyww6v 7WotdBYD29vyaD/WTbqvbesEjsMknWe0wtKmWsrK0yBmTCYMLITfJj/kSy5QBrkbr76Y zKBSoCwJfmToVLRfBsaLmlUqjYY41vgbL7r00kr/AaPu6ugVYBLPPMP/AXq4oipjPjMO pf0xgut/b+ehE5GwIHHFo4kyfK7z142jbgThy2XNGnfDregX+Fw6mBo5SdhAVIoAR4KM A3AwZ+1bcLJ+X4gx/PlfwBl0PrQXaFlTquqNQWiT2IbQ+PRpKbcHk+xMV3Bw/fWlwPu0 P5gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5Wsqg0CJ+ZJensLrSIYeU6hyG6UFSARJh1M0Jrin2SA=; fh=x0wTksZ0ORmfJnJfrG83hX1tKxiHhisrbrhBF2Ameo4=; b=xdPWDGkbRxniE2HlJyUWwjEbAdJ4CBVqxfm9B0NzMnt4I1ZKBAC2AkUguQvWIX9m/k jawy9/1q+VCc40x2mLqJggfuX13/Yxgwd0oM0h9w4NbX2qnSqA8ZNgTNRcDQUndqRqcm gnDr162R90Du1tZ1DDvnhIK3GbTcEzcg7fveh+inE+wgOHn5RygtAtJJxtCkM6UGE5mG 5350K/OQlkUITDQ7Sw3Im3/4f+ABDs5way7ULEHDG2zXgIShQrBa/wRIlejE0wAMEu24 CPP0Dru1hLWys6GZ01GoPASNJKxDENZrFWACLqDNSDlp0IWtIDwn4Ezn/7RvEFXJAE+R Enjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CXWDnybb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a170906049100b0099cc4b278c9si6771521eja.208.2023.08.13.22.39.20; Sun, 13 Aug 2023 22:39:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CXWDnybb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232714AbjHNDAn (ORCPT + 99 others); Sun, 13 Aug 2023 23:00:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232725AbjHNDAU (ORCPT ); Sun, 13 Aug 2023 23:00:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04D65A2 for ; Sun, 13 Aug 2023 19:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691981971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Wsqg0CJ+ZJensLrSIYeU6hyG6UFSARJh1M0Jrin2SA=; b=CXWDnybbCdJiBdWxQotSS6vaZ++0xPfAzYJyygrTVJtN+nzT/f5ZIUx7Z6u8ZP9bHq8Kpg 47N3Iw22afVIFJZDkyDJ4FHx+j3IDqbA7j29Wz51D6gqIsilV+uKR74m1LfPlSKT5NPpg5 k7i4Wehp68NiVU3lycuhks6oRdJzJgA= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-537-owVQoit2Ou6RAr9y0QG18Q-1; Sun, 13 Aug 2023 22:59:29 -0400 X-MC-Unique: owVQoit2Ou6RAr9y0QG18Q-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-4fe0fe8dfe0so2713965e87.0 for ; Sun, 13 Aug 2023 19:59:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691981968; x=1692586768; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Wsqg0CJ+ZJensLrSIYeU6hyG6UFSARJh1M0Jrin2SA=; b=kQb6W+MPD6iErY3w0uNPlo4qVh02Ek2LaqERkxGkp9sK/AegLdnlWPPgWRwt6E/uwz B+yjLfv7osMphGZO9V9uVvSTMl+hYfuxLIuyITsGYNM+jto6ZqQzNfUAzmPQbbQ+gonr yUFwyMkTANTSKWJTKKqRVAXF1nFBk2wa/XiBn9NjEw11xpe6Ur1GtWCy7YxJPYvGgcxl o3CDHi8CliGvBbffJ0CO3qjtxhdN6YnBYPsZLdrD0MrfxMfkwA58fXwIYXqTFpgxJSW/ GjcTlnKbpa48R+H8jyXpnvvXqKDeFrwa+I9+eJJsNGQyjomKCHk9sFfDTssDwtG0CoNG luRw== X-Gm-Message-State: AOJu0YwK6+8wleQVxARNKBLAUttal8LIuyLs41JI96ukGoxnRVGnCseS 57rURGw/qZAIZqjRKTNYhaP936HaBRalpp+yLx3qxFVOaWVqh2Lz1NHO9rhztBj+rGRODFjKl3X N/3Gx3fPSIc43YhtfKa7TsjIQ9xi33BZy07WK5Nlb X-Received: by 2002:a05:6512:3d06:b0:4f8:586a:d6ca with SMTP id d6-20020a0565123d0600b004f8586ad6camr4408714lfv.9.1691981967936; Sun, 13 Aug 2023 19:59:27 -0700 (PDT) X-Received: by 2002:a05:6512:3d06:b0:4f8:586a:d6ca with SMTP id d6-20020a0565123d0600b004f8586ad6camr4408707lfv.9.1691981967670; Sun, 13 Aug 2023 19:59:27 -0700 (PDT) MIME-Version: 1.0 References: <20230802171231.11001-1-dtatulea@nvidia.com> <20230802171231.11001-3-dtatulea@nvidia.com> <741645a0-c576-e504-8ebc-6b716099d730@oracle.com> <3472a482-dc1d-1994-e2d7-c2bd740bbd27@oracle.com> <325aaca0-ccdf-1843-4ab8-03bc94d3ea98@oracle.com> In-Reply-To: <325aaca0-ccdf-1843-4ab8-03bc94d3ea98@oracle.com> From: Jason Wang Date: Mon, 14 Aug 2023 10:59:16 +0800 Message-ID: Subject: Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics To: Si-Wei Liu Cc: Dragos Tatulea , Xuan Zhuo , "Michael S. Tsirkin" , Gal Pressman , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, =?UTF-8?Q?Eugenio_P=C3=A9rez?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 11, 2023 at 6:21=E2=80=AFAM Si-Wei Liu = wrote: > > > > On 8/9/2023 8:10 PM, Jason Wang wrote: > > On Thu, Aug 10, 2023 at 8:40=E2=80=AFAM Si-Wei Liu wrote: > >> > >> > >> On 8/8/2023 11:52 PM, Jason Wang wrote: > >>> On Wed, Aug 9, 2023 at 6:58=E2=80=AFAM Si-Wei Liu wrote: > >>>> > >>>> On 8/7/2023 8:00 PM, Jason Wang wrote: > >>>>> On Fri, Aug 4, 2023 at 1:58=E2=80=AFAM Si-Wei Liu wrote: > >>>>>> On 8/3/2023 1:03 AM, Jason Wang wrote: > >>>>>>> On Thu, Aug 3, 2023 at 1:13=E2=80=AFAM Dragos Tatulea wrote: > >>>>>>>> The mr->initialized flag is shared between the control vq and da= ta vq > >>>>>>>> part of the mr init/uninit. But if the control vq and data vq ge= t placed > >>>>>>>> in different ASIDs, it can happen that initializing the control = vq will > >>>>>>>> prevent the data vq mr from being initialized. > >>>>>>>> > >>>>>>>> This patch consolidates the control and data vq init parts into = their > >>>>>>>> own init functions. The mr->initialized will now be used for the= data vq > >>>>>>>> only. The control vq currently doesn't need a flag. > >>>>>>>> > >>>>>>>> The uninitializing part is also taken care of: mlx5_vdpa_destroy= _mr got > >>>>>>>> split into data and control vq functions which are now also ASID= aware. > >>>>>>>> > >>>>>>>> Fixes: 8fcd20c30704 ("vdpa/mlx5: Support different address space= s for control and data") > >>>>>>>> Signed-off-by: Dragos Tatulea > >>>>>>>> Reviewed-by: Eugenio P=C3=A9rez > >>>>>>>> Reviewed-by: Gal Pressman > >>>>>>>> --- > >>>>>>>> drivers/vdpa/mlx5/core/mlx5_vdpa.h | 1 + > >>>>>>>> drivers/vdpa/mlx5/core/mr.c | 97 +++++++++++++++++++= ++--------- > >>>>>>>> 2 files changed, 71 insertions(+), 27 deletions(-) > >>>>>>>> > >>>>>>>> diff --git a/drivers/vdpa/mlx5/core/mlx5_vdpa.h b/drivers/vdpa/m= lx5/core/mlx5_vdpa.h > >>>>>>>> index 25fc4120b618..a0420be5059f 100644 > >>>>>>>> --- a/drivers/vdpa/mlx5/core/mlx5_vdpa.h > >>>>>>>> +++ b/drivers/vdpa/mlx5/core/mlx5_vdpa.h > >>>>>>>> @@ -31,6 +31,7 @@ struct mlx5_vdpa_mr { > >>>>>>>> struct list_head head; > >>>>>>>> unsigned long num_directs; > >>>>>>>> unsigned long num_klms; > >>>>>>>> + /* state of dvq mr */ > >>>>>>>> bool initialized; > >>>>>>>> > >>>>>>>> /* serialize mkey creation and destruction */ > >>>>>>>> diff --git a/drivers/vdpa/mlx5/core/mr.c b/drivers/vdpa/mlx5/cor= e/mr.c > >>>>>>>> index 03e543229791..4ae14a248a4b 100644 > >>>>>>>> --- a/drivers/vdpa/mlx5/core/mr.c > >>>>>>>> +++ b/drivers/vdpa/mlx5/core/mr.c > >>>>>>>> @@ -489,60 +489,103 @@ static void destroy_user_mr(struct mlx5_v= dpa_dev *mvdev, struct mlx5_vdpa_mr *mr > >>>>>>>> } > >>>>>>>> } > >>>>>>>> > >>>>>>>> -void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev) > >>>>>>>> +static void _mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvd= ev, unsigned int asid) > >>>>>>>> +{ > >>>>>>>> + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] !=3D asid) > >>>>>>>> + return; > >>>>>>>> + > >>>>>>>> + prune_iotlb(mvdev); > >>>>>>>> +} > >>>>>>>> + > >>>>>>>> +static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvd= ev, unsigned int asid) > >>>>>>>> { > >>>>>>>> struct mlx5_vdpa_mr *mr =3D &mvdev->mr; > >>>>>>>> > >>>>>>>> - mutex_lock(&mr->mkey_mtx); > >>>>>>>> + if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] !=3D asid) > >>>>>>>> + return; > >>>>>>>> + > >>>>>>>> if (!mr->initialized) > >>>>>>>> - goto out; > >>>>>>>> + return; > >>>>>>>> > >>>>>>>> - prune_iotlb(mvdev); > >>>>>>>> if (mr->user_mr) > >>>>>>>> destroy_user_mr(mvdev, mr); > >>>>>>>> else > >>>>>>>> destroy_dma_mr(mvdev, mr); > >>>>>>>> > >>>>>>>> mr->initialized =3D false; > >>>>>>>> -out: > >>>>>>>> +} > >>>>>>>> + > >>>>>>>> +static void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvd= ev, unsigned int asid) > >>>>>>>> +{ > >>>>>>>> + struct mlx5_vdpa_mr *mr =3D &mvdev->mr; > >>>>>>>> + > >>>>>>>> + mutex_lock(&mr->mkey_mtx); > >>>>>>>> + > >>>>>>>> + _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); > >>>>>>>> + _mlx5_vdpa_destroy_cvq_mr(mvdev, asid); > >>>>>>>> + > >>>>>>>> mutex_unlock(&mr->mkey_mtx); > >>>>>>>> } > >>>>>>>> > >>>>>>>> -static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, > >>>>>>>> - struct vhost_iotlb *iotlb, unsig= ned int asid) > >>>>>>>> +void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev) > >>>>>>>> +{ > >>>>>>>> + mlx5_vdpa_destroy_mr_asid(mvdev, mvdev->group2asid[MLX5_= VDPA_CVQ_GROUP]); > >>>>>>>> + mlx5_vdpa_destroy_mr_asid(mvdev, mvdev->group2asid[MLX5_= VDPA_DATAVQ_GROUP]); > >>>>>>>> +} > >>>>>>>> + > >>>>>>>> +static int _mlx5_vdpa_create_cvq_mr(struct mlx5_vdpa_dev *mvdev= , > >>>>>>>> + struct vhost_iotlb *iotlb, > >>>>>>>> + unsigned int asid) > >>>>>>>> +{ > >>>>>>>> + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] !=3D asid) > >>>>>>>> + return 0; > >>>>>>>> + > >>>>>>>> + return dup_iotlb(mvdev, iotlb); > >>>>>>> This worries me as conceptually, there should be no difference be= tween > >>>>>>> dvq mr and cvq mr. The virtqueue should be loosely coupled with m= r. > >>>>>>> > >>>>>>> One example is that, if we only do dup_iotlb() but not try to cre= ate > >>>>>>> dma mr here, we will break virtio-vdpa: > >>>>>> For this case, I guess we may need another way to support virtio-v= dpa > >>>>>> 1:1 mapping rather than overloading virtio device reset semantics,= see: > >>>>>> > >>>>>> https://www.mail-archive.com/qemu-devel@nongnu.org/msg953755.html > >>>>>> > >>>>>> > Conceptually, the address mapping is not a part of the abstr= action for > >>>>>> > a virtio device now. So resetting the memory mapping during = virtio > >>>>>> > device reset seems wrong. > >>>>>> > >>>>>> where we want to keep memory mapping intact across virtio device r= eset > >>>>>> for best live migration latency/downtime. I wonder would it work t= o > >>>>>> reset the mapping in vhost-vdpa life cycle out of virtio reset, sa= y > >>>>>> introduce a .reset_map() op to restore 1:1 mapping within > >>>>>> vhost_vdpa_remove_as() right after vhost_vdpa_iotlb_unmap()? Then = we can > >>>>>> move the iotlb reset logic to there without worry breaking virtio-= vdpa. > >>>>> It looks to me we don't need a new ops. We can simply do set_map() > >>>>> twice > >>>> What does it mean, first set_map(0, -1ULL) with zero iotlb entry pas= sed > >>>> in to destroy all iotlb mappings previously added, and second set_ma= p(0, > >>>> -1ULL) to restore 1:1 DMA MR? But userspace (maybe a buggy one but > >>>> doesn't do harm) apart from vhost-vdpa itself can do unmap twice any= way, > >>>> this is supported today I think. Why there'll be such obscure > >>>> distinction, or what's the benefit to treat second .set_map() as > >>>> recreating 1:1 mapping? > >>> Ok, I think I miss some context. I agree that it's better to decouple > >>> memory mappings from the virtio reset. It helps to reduce the > >>> unnecessary memory transactions. It might require a new feature flag. > >> This I agreed. AFAICT QEMU would need to check this new feature flag t= o > >> make sure memory mappings are kept intact across reset, otherwise for > >> the sake of avoid breaking older kernels it has to recreate all the > >> mappings after reset like how it is done today. > >> > >>> Regarding the method of restoring to 1:1 DMA MR, it might be dangerou= s > >>> for (buggy) vhost-vDPA devices. Since its userspace doesn't set up an= y > >>> mapping it can explore the kernel with that via CVQ? > >> Not sure I understand this proposal. The 1:1 DMA MR is first created a= t > >> vdpa device add, and gets destroyed implicitly when the first .set_map > >> or .dma_map call is made, which is only possible after the vhost-vdpa > >> module is loaded and bound to vdpa devices. > > So what happens if there's a buggy userspace that doesn't do any IOTLB = setup? > Then parent driver doesn't do anything in .reset_map() - as the DMA MR > is still there. Parent driver should be able to tell apart if DMA MR has > been destroyed or not by checking the internal state. Would you mind posting a patch to demonstrate this? Thanks > > -Siwei > > > > > Thanks > > > >> Naturally the DMA MR should > >> be restored to how it was before when vhost-vdpa module is unloaded, o= r > >> if anything the 1:1 DMA MR creation can be deferred to until virtio-vd= pa > >> is probed and bound to devices. Today vhost_vdpa_remove_as() as part o= f > >> the vhost-vdpa unload code path already gets all mappings purged throu= gh > >> vhost_vdpa_iotlb_unmap(0, -1ULL), and it should be pretty safe to > >> restore DMA MR via .reset_map() right after. Not sure what's the conce= rn > >> here with buggy vhost-vdpa device? > >> > >> Noted when vhost-vdpa is being unloaded there's even no chance to prob= e > >> kernel through CVQ, as the virtio feature is not even negotiated at th= at > >> point. And it is even trickier to wait for CVQ response from device > >> indefinitely when trying to unload a module. > >> > >> Regards, > >> -Siwei > >>> Thanks > >>> > >>>>> or do you mean it would be faster? > >>>> I think with .reset_map() we at least can avoid indefinite latency > >>>> hiccup from destroying and recreating 1:1 mapping with the unwarrant= ed > >>>> 2rd unmap call. And .reset_map() should work with both .dma_map() an= d > >>>> .set_map() APIs with clear semantics. > >>>> > >>>> Regards, > >>>> -Siwei > >>>>> Thanks > >>>>> > >>>>>> Thanks, > >>>>>> -Siwei > >>>>>> > >>>>>>> commit 6f5312f801836e6af9bcbb0bdb44dc423e129206 > >>>>>>> Author: Eli Cohen > >>>>>>> Date: Wed Jun 2 11:58:54 2021 +0300 > >>>>>>> > >>>>>>> vdpa/mlx5: Add support for running with virtio_vdpa > >>>>>>> > >>>>>>> In order to support running vdpa using vritio_vdpa driver= , we need to > >>>>>>> create a different kind of MR, one that has 1:1 mapping, = since the > >>>>>>> addresses referring to virtqueues are dma addresses. > >>>>>>> > >>>>>>> We create the 1:1 MR in mlx5_vdpa_dev_add() only in case = firmware > >>>>>>> supports the general capability umem_uid_0. The reason fo= r that is that > >>>>>>> 1:1 MRs must be created with uid =3D=3D 0 while virtqueue= objects can be > >>>>>>> created with uid =3D=3D 0 only when the firmware capabili= ty is on. > >>>>>>> > >>>>>>> If the set_map() callback is called with new translations= provided > >>>>>>> through iotlb, the driver will destroy the 1:1 MR and cre= ate a regular > >>>>>>> one. > >>>>>>> > >>>>>>> Signed-off-by: Eli Cohen > >>>>>>> Link: https://lore.kernel.org/r/20210602085854.62690-1-el= ic@nvidia.com > >>>>>>> Signed-off-by: Michael S. Tsirkin > >>>>>>> Acked-by: Jason Wang > >>>>>>> > >>>>>>> Thanks > >>>>>>> > >>>>>>> > >>>>>>>> +} > >>>>>>>> + > >>>>>>>> +static int _mlx5_vdpa_create_dvq_mr(struct mlx5_vdpa_dev *mvdev= , > >>>>>>>> + struct vhost_iotlb *iotlb, > >>>>>>>> + unsigned int asid) > >>>>>>>> { > >>>>>>>> struct mlx5_vdpa_mr *mr =3D &mvdev->mr; > >>>>>>>> int err; > >>>>>>>> > >>>>>>>> - if (mr->initialized) > >>>>>>>> + if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] !=3D asid) > >>>>>>>> return 0; > >>>>>>>> > >>>>>>>> - if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] =3D=3D asi= d) { > >>>>>>>> - if (iotlb) > >>>>>>>> - err =3D create_user_mr(mvdev, iotlb); > >>>>>>>> - else > >>>>>>>> - err =3D create_dma_mr(mvdev, mr); > >>>>>>>> + if (mr->initialized) > >>>>>>>> + return 0; > >>>>>>>> > >>>>>>>> - if (err) > >>>>>>>> - return err; > >>>>>>>> - } > >>>>>>>> + if (iotlb) > >>>>>>>> + err =3D create_user_mr(mvdev, iotlb); > >>>>>>>> + else > >>>>>>>> + err =3D create_dma_mr(mvdev, mr); > >>>>>>>> > >>>>>>>> - if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] =3D=3D asid) = { > >>>>>>>> - err =3D dup_iotlb(mvdev, iotlb); > >>>>>>>> - if (err) > >>>>>>>> - goto out_err; > >>>>>>>> - } > >>>>>>>> + if (err) > >>>>>>>> + return err; > >>>>>>>> > >>>>>>>> mr->initialized =3D true; > >>>>>>>> + > >>>>>>>> + return 0; > >>>>>>>> +} > >>>>>>>> + > >>>>>>>> +static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, > >>>>>>>> + struct vhost_iotlb *iotlb, unsig= ned int asid) > >>>>>>>> +{ > >>>>>>>> + int err; > >>>>>>>> + > >>>>>>>> + err =3D _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); > >>>>>>>> + if (err) > >>>>>>>> + return err; > >>>>>>>> + > >>>>>>>> + err =3D _mlx5_vdpa_create_cvq_mr(mvdev, iotlb, asid); > >>>>>>>> + if (err) > >>>>>>>> + goto out_err; > >>>>>>>> + > >>>>>>>> return 0; > >>>>>>>> > >>>>>>>> out_err: > >>>>>>>> - if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] =3D=3D asi= d) { > >>>>>>>> - if (iotlb) > >>>>>>>> - destroy_user_mr(mvdev, mr); > >>>>>>>> - else > >>>>>>>> - destroy_dma_mr(mvdev, mr); > >>>>>>>> - } > >>>>>>>> + _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); > >>>>>>>> > >>>>>>>> return err; > >>>>>>>> } > >>>>>>>> -- > >>>>>>>> 2.41.0 > >>>>>>>> > >>>>>>> _______________________________________________ > >>>>>>> Virtualization mailing list > >>>>>>> Virtualization@lists.linux-foundation.org > >>>>>>> https://lists.linuxfoundation.org/mailman/listinfo/virtualization >