mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dragos Tatulea <dtatulea@nvidia.com>
To: "jasowang@redhat.com" <jasowang@redhat.com>
Cc: "virtualization@lists.linux-foundation.org" 
	<virtualization@lists.linux-foundation.org>,
	"mst@redhat.com" <mst@redhat.com>,
	"eperezma@redhat.com" <eperezma@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Gal Pressman <gal@nvidia.com>,
	"xuanzhuo@linux.alibaba.com" <xuanzhuo@linux.alibaba.com>
Subject: Re: [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics
Date: Tue, 8 Aug 2023 07:24:00 +0000	[thread overview]
Message-ID: <83ca86a42041248f8db717cdc858b7f973cbd85b.camel@nvidia.com> (raw)
In-Reply-To: <CACGkMEvoE=1ac1EGxPd14AwCfuOTiZYzYgDQC_qZjSubt891sA@mail.gmail.com>

On Tue, 2023-08-08 at 10:57 +0800, Jason Wang wrote:
> On Thu, Aug 3, 2023 at 7:40 PM Dragos Tatulea <dtatulea@nvidia.com> wrote:
> > 
> > On Thu, 2023-08-03 at 16:03 +0800, Jason Wang wrote:
> > > On Thu, Aug 3, 2023 at 1:13 AM Dragos Tatulea <dtatulea@nvidia.com> wrote:
> > > > 
> > > > The mr->initialized flag is shared between the control vq and data vq
> > > > part of the mr init/uninit. But if the control vq and data vq get 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 spaces for
> > > > control and data")
> > > > Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
> > > > Reviewed-by: Eugenio Pérez <eperezma@redhat.com>
> > > > Reviewed-by: Gal Pressman <gal@nvidia.com>
> > > > ---
> > > >  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/mlx5/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/core/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_vdpa_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 *mvdev,
> > > > unsigned
> > > > int asid)
> > > > +{
> > > > +       if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid)
> > > > +               return;
> > > > +
> > > > +       prune_iotlb(mvdev);
> > > > +}
> > > > +
> > > > +static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev,
> > > > unsigned
> > > > int asid)
> > > >  {
> > > >         struct mlx5_vdpa_mr *mr = &mvdev->mr;
> > > > 
> > > > -       mutex_lock(&mr->mkey_mtx);
> > > > +       if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != 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 = false;
> > > > -out:
> > > > +}
> > > > +
> > > > +static void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev,
> > > > unsigned
> > > > int asid)
> > > > +{
> > > > +       struct mlx5_vdpa_mr *mr = &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, unsigned 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] != asid)
> > > > +               return 0;
> > > > +
> > > > +       return dup_iotlb(mvdev, iotlb);
> > > 
> > > This worries me as conceptually, there should be no difference between
> > > dvq mr and cvq mr. The virtqueue should be loosely coupled with mr.
> > > 
> > Are you worried by the changes in this patch or about the possibility of
> > having
> > 
> > The reason for this change is that I noticed if you create one mr in one
> > asid
> > you could be blocked out from creating another one in a different asid due
> > to
> > mr->initialized being true. To me that seemed problematic. Is it not?
> 
> My feeling is that mr.c should be device agnostic. It needs to know
> nothing about the device details to work. But this patch seems to
> break the layer.
> 
But the same logic was there before (with the exception of cvq not having an
init flag anymore). So what am I missing here?

> > 
> > > One example is that, if we only do dup_iotlb() but not try to create
> > > dma mr here, we will break virtio-vdpa:
> > > 
> > How will that be possible? _mlx5_vdpa_create_mr calls
> > _mlx5_vdpa_create_dvq_mr
> > and _mlx5_vdpa_create_cvq_mr. The only thing that is different in this patch
> > is
> > that the cvq is not protected by an init flag. My understanding was that it
> > would be ok to dup_iotlb again. Is it not? If not I could add an additional
> > initialized flag for the cvq mr.
> 
> You are right here.
> 
> Thanks
> 
> 
> > 
> > Thanks,
> > Dragos
> > 
> > > commit 6f5312f801836e6af9bcbb0bdb44dc423e129206
> > > Author: Eli Cohen <elic@nvidia.com>
> > > 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 for that is
> > > that
> > >     1:1 MRs must be created with uid == 0 while virtqueue objects can be
> > >     created with uid == 0 only when the firmware capability is on.
> > > 
> > >     If the set_map() callback is called with new translations provided
> > >     through iotlb, the driver will destroy the 1:1 MR and create a regular
> > >     one.
> > > 
> > >     Signed-off-by: Eli Cohen <elic@nvidia.com>
> > >     Link: https://lore.kernel.org/r/20210602085854.62690-1-elic@nvidia.com
> > >     Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > >     Acked-by: Jason Wang <jasowang@redhat.com>
> > > 
> > > 
> > 
> > > 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 = &mvdev->mr;
> > > >         int err;
> > > > 
> > > > -       if (mr->initialized)
> > > > +       if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid)
> > > >                 return 0;
> > > > 
> > > > -       if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) {
> > > > -               if (iotlb)
> > > > -                       err = create_user_mr(mvdev, iotlb);
> > > > -               else
> > > > -                       err = create_dma_mr(mvdev, mr);
> > > > +       if (mr->initialized)
> > > > +               return 0;
> > > > 
> > > > -               if (err)
> > > > -                       return err;
> > > > -       }
> > > > +       if (iotlb)
> > > > +               err = create_user_mr(mvdev, iotlb);
> > > > +       else
> > > > +               err = create_dma_mr(mvdev, mr);
> > > > 
> > > > -       if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid) {
> > > > -               err = dup_iotlb(mvdev, iotlb);
> > > > -               if (err)
> > > > -                       goto out_err;
> > > > -       }
> > > > +       if (err)
> > > > +               return err;
> > > > 
> > > >         mr->initialized = true;
> > > > +
> > > > +       return 0;
> > > > +}
> > > > +
> > > > +static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
> > > > +                               struct vhost_iotlb *iotlb, unsigned int
> > > > asid)
> > > > +{
> > > > +       int err;
> > > > +
> > > > +       err = _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid);
> > > > +       if (err)
> > > > +               return err;
> > > > +
> > > > +       err = _mlx5_vdpa_create_cvq_mr(mvdev, iotlb, asid);
> > > > +       if (err)
> > > > +               goto out_err;
> > > > +
> > > >         return 0;
> > > > 
> > > >  out_err:
> > > > -       if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) {
> > > > -               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
> > > > 
> > > 
> > 
> 


  reply	other threads:[~2023-08-08 15:53 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-02 17:12 [PATCH 0/2] vdpa/mlx5: Fixes for ASID handling Dragos Tatulea
2023-08-02 17:12 ` [PATCH 1/2] vdpa/mlx5: Fix mr->initialized semantics Dragos Tatulea
2023-08-03  8:03   ` Jason Wang
2023-08-03 11:40     ` Dragos Tatulea
2023-08-08  2:57       ` Jason Wang
2023-08-08  7:24         ` Dragos Tatulea [this message]
2023-08-09  1:42           ` Jason Wang
2023-08-14 14:15             ` Dragos Tatulea
2023-08-15  1:28               ` Jason Wang
2023-08-03 17:57     ` Si-Wei Liu
2023-08-08  3:00       ` Jason Wang
2023-08-08 22:58         ` Si-Wei Liu
2023-08-09  6:52           ` Jason Wang
2023-08-10  0:40             ` Si-Wei Liu
2023-08-10  3:10               ` Jason Wang
2023-08-10 22:20                 ` Si-Wei Liu
2023-08-14  2:59                   ` Jason Wang
2023-08-15  1:43                     ` [PATCH RFC 0/4] vdpa: decouple reset of iotlb mapping from device reset Si-Wei Liu
2023-08-15  1:43                       ` [PATCH RFC 1/4] vdpa: introduce .reset_map operation callback Si-Wei Liu
2023-08-15  2:21                         ` Jason Wang
2023-08-15 19:49                           ` Si-Wei Liu
2023-08-16  1:55                             ` Jason Wang
2023-08-17  0:05                               ` Si-Wei Liu
2023-08-17 15:28                                 ` Eugenio Perez Martin
2023-08-21 22:31                                   ` Si-Wei Liu
2023-08-15  1:43                       ` [PATCH RFC 2/4] vdpa/mlx5: implement .reset_map driver op Si-Wei Liu
2023-08-15  8:26                         ` Dragos Tatulea
2023-08-15 23:11                           ` Si-Wei Liu
2023-08-15  1:43                       ` [PATCH RFC 3/4] vhost-vdpa: should restore 1:1 dma mapping before detaching driver Si-Wei Liu
2023-08-15  2:32                         ` Jason Wang
2023-08-15 23:09                           ` Si-Wei Liu
2023-08-15  1:43                       ` [PATCH RFC 4/4] vhost-vdpa: introduce IOTLB_PERSIST backend feature bit Si-Wei Liu
2023-08-15  2:25                         ` Jason Wang
2023-08-15 22:30                           ` Si-Wei Liu
2023-08-16  1:48                             ` Jason Wang
2023-08-16 23:43                               ` Si-Wei Liu
2023-08-22  8:54                                 ` Jason Wang
2023-08-28 23:46                                   ` Si-Wei Liu
2023-08-02 17:12 ` [PATCH 2/2] vdpa/mlx5: Delete control vq iotlb in destroy_mr only when necessary Dragos Tatulea
2023-08-10  8:54 ` [PATCH 0/2] vdpa/mlx5: Fixes for ASID handling Michael S. Tsirkin
2023-08-10  8:59   ` Jason Wang
2023-08-10  9:04   ` Dragos Tatulea

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=83ca86a42041248f8db717cdc858b7f973cbd85b.camel@nvidia.com \
    --to=dtatulea@nvidia.com \
    --cc=eperezma@redhat.com \
    --cc=gal@nvidia.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xuanzhuo@linux.alibaba.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

Powered by JetHome