public inbox for linux-s390@vger.kernel.org
 help / color / mirror / Atom feed
From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: Jason Wang <jasowang@redhat.com>
Cc: virtualization@lists.linux.dev,
	"Richard Weinberger" <richard@nod.at>,
	"Anton Ivanov" <anton.ivanov@cambridgegreys.com>,
	"Johannes Berg" <johannes@sipsolutions.net>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Vadim Pasternak" <vadimp@nvidia.com>,
	"Bjorn Andersson" <andersson@kernel.org>,
	"Mathieu Poirier" <mathieu.poirier@linaro.org>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Eric Farman" <farman@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Sven Schnelle" <svens@linux.ibm.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Benjamin Berg" <benjamin.berg@intel.com>,
	"Yang Li" <yang.lee@linux.alibaba.com>,
	linux-um@lists.infradead.org, netdev@vger.kernel.org,
	platform-driver-x86@vger.kernel.org,
	linux-remoteproc@vger.kernel.org, linux-s390@vger.kernel.org,
	kvm@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH vhost 06/17] virtio_ring: no store dma info when unmap is not needed
Date: Thu, 1 Feb 2024 14:04:57 +0800	[thread overview]
Message-ID: <1706767497.2529867-3-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <CACGkMEtNCjvtDWySzeAqETGZtBSL0MR6=JySBBtm3=s19wB=1w@mail.gmail.com>

On Wed, 31 Jan 2024 17:12:29 +0800, Jason Wang <jasowang@redhat.com> wrote:
> On Tue, Jan 30, 2024 at 7:42 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> >
> > As discussed:
> > http://lore.kernel.org/all/CACGkMEug-=C+VQhkMYSgUKMC==04m7-uem_yC21bgGkKZh845w@mail.gmail.com
> >
> > When the vq is premapped mode, the driver manages the dma
> > info is a good way.
> >
> > So this commit make the virtio core not to store the dma
> > info and release the memory which is used to store the dma
> > info.
> >
> > If the use_dma_api is false, the memory is also not allocated.
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > ---
> >  drivers/virtio/virtio_ring.c | 89 ++++++++++++++++++++++++++++--------
> >  1 file changed, 70 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > index 831667a57429..5bea25167259 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -94,12 +94,15 @@ struct vring_desc_state_packed {
> >  };
> >
> >  struct vring_desc_extra {
> > -       dma_addr_t addr;                /* Descriptor DMA addr. */
> > -       u32 len;                        /* Descriptor length. */
> >         u16 flags;                      /* Descriptor flags. */
> >         u16 next;                       /* The next desc state in a list. */
> >  };
> >
> > +struct vring_desc_dma {
> > +       dma_addr_t addr;                /* Descriptor DMA addr. */
> > +       u32 len;                        /* Descriptor length. */
> > +};
> > +
> >  struct vring_virtqueue_split {
> >         /* Actual memory layout for this queue. */
> >         struct vring vring;
> > @@ -116,6 +119,7 @@ struct vring_virtqueue_split {
> >         /* Per-descriptor state. */
> >         struct vring_desc_state_split *desc_state;
> >         struct vring_desc_extra *desc_extra;
> > +       struct vring_desc_dma *desc_dma;
> >
> >         /* DMA address and size information */
> >         dma_addr_t queue_dma_addr;
> > @@ -156,6 +160,7 @@ struct vring_virtqueue_packed {
> >         /* Per-descriptor state. */
> >         struct vring_desc_state_packed *desc_state;
> >         struct vring_desc_extra *desc_extra;
> > +       struct vring_desc_dma *desc_dma;
> >
> >         /* DMA address and size information */
> >         dma_addr_t ring_dma_addr;
> > @@ -472,13 +477,14 @@ static unsigned int vring_unmap_one_split(const struct vring_virtqueue *vq,
> >                                           unsigned int i)
> >  {
> >         struct vring_desc_extra *extra = vq->split.desc_extra;
> > +       struct vring_desc_dma *dma = vq->split.desc_dma;
> >         u16 flags;
> >
> >         flags = extra[i].flags;
> >
> >         dma_unmap_page(vring_dma_dev(vq),
> > -                      extra[i].addr,
> > -                      extra[i].len,
> > +                      dma[i].addr,
> > +                      dma[i].len,
> >                        (flags & VRING_DESC_F_WRITE) ?
> >                        DMA_FROM_DEVICE : DMA_TO_DEVICE);
> >
> > @@ -535,8 +541,11 @@ static inline unsigned int virtqueue_add_desc_split(struct virtqueue *vq,
> >                 next = extra[i].next;
> >                 desc[i].next = cpu_to_virtio16(vq->vdev, next);
> >
> > -               extra[i].addr = addr;
> > -               extra[i].len = len;
> > +               if (vring->split.desc_dma) {
> > +                       vring->split.desc_dma[i].addr = addr;
> > +                       vring->split.desc_dma[i].len = len;
> > +               }
> > +
> >                 extra[i].flags = flags;
> >         } else
> >                 next = virtio16_to_cpu(vq->vdev, desc[i].next);
> > @@ -1072,16 +1081,26 @@ static void virtqueue_vring_attach_split(struct vring_virtqueue *vq,
> >         vq->free_head = 0;
> >  }
> >
> > -static int vring_alloc_state_extra_split(struct vring_virtqueue_split *vring_split)
> > +static int vring_alloc_state_extra_split(struct vring_virtqueue_split *vring_split,
> > +                                        bool need_unmap)
> >  {
> >         struct vring_desc_state_split *state;
> >         struct vring_desc_extra *extra;
> > +       struct vring_desc_dma *dma;
> >         u32 num = vring_split->vring.num;
> >
> >         state = kmalloc_array(num, sizeof(struct vring_desc_state_split), GFP_KERNEL);
> >         if (!state)
> >                 goto err_state;
> >
> > +       if (need_unmap) {
> > +               dma = kmalloc_array(num, sizeof(struct vring_desc_dma), GFP_KERNEL);
> > +               if (!dma)
> > +                       goto err_dma;
> > +       } else {
> > +               dma = NULL;
> > +       }
> > +
> >         extra = vring_alloc_desc_extra(num);
> >         if (!extra)
> >                 goto err_extra;
> > @@ -1090,9 +1109,12 @@ static int vring_alloc_state_extra_split(struct vring_virtqueue_split *vring_spl
> >
> >         vring_split->desc_state = state;
> >         vring_split->desc_extra = extra;
> > +       vring_split->desc_dma = dma;
> >         return 0;
> >
> >  err_extra:
> > +       kfree(dma);
> > +err_dma:
> >         kfree(state);
> >  err_state:
> >         return -ENOMEM;
> > @@ -1108,6 +1130,7 @@ static void vring_free_split(struct vring_virtqueue_split *vring_split,
> >
> >         kfree(vring_split->desc_state);
> >         kfree(vring_split->desc_extra);
> > +       kfree(vring_split->desc_dma);
> >  }
> >
> >  static int vring_alloc_queue_split(struct vring_virtqueue_split *vring_split,
> > @@ -1209,7 +1232,8 @@ static int virtqueue_resize_split(struct virtqueue *_vq, u32 num)
> >         if (err)
> >                 goto err;
> >
> > -       err = vring_alloc_state_extra_split(&vring_split);
> > +       err = vring_alloc_state_extra_split(&vring_split,
> > +                                           vring_need_unmap_buffer(vq));
> >         if (err)
> >                 goto err_state_extra;
> >
> > @@ -1245,14 +1269,16 @@ static u16 packed_last_used(u16 last_used_idx)
> >
> >  /* caller must check vring_need_unmap_buffer() */
> >  static void vring_unmap_extra_packed(const struct vring_virtqueue *vq,
> > -                                    const struct vring_desc_extra *extra)
> > +                                    unsigned int i)
> >  {
> > +       const struct vring_desc_extra *extra = &vq->packed.desc_extra[i];
> > +       const struct vring_desc_dma *dma = &vq->packed.desc_dma[i];
> >         u16 flags;
> >
> >         flags = extra->flags;
>
> I don't think this can be compiled.

I do not find any error.
Could you say more?

Thanks.


>
> Thanks
>

  reply	other threads:[~2024-02-01  6:05 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30 11:42 [PATCH vhost 00/17] virtio: drivers maintain dma info for premapped vq Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 01/17] virtio_ring: introduce vring_need_unmap_buffer Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-01-30 11:42 ` [PATCH vhost 02/17] virtio_ring: packed: remove double check of the unmap ops Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-01-31  9:58     ` Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 03/17] virtio_ring: packed: structure the indirect desc table Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-01-31 10:00     ` Xuan Zhuo
2024-02-01  0:41       ` Jason Wang
2024-01-30 11:42 ` [PATCH vhost 04/17] virtio_ring: split: remove double check of the unmap ops Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-01-31  9:43     ` Michael S. Tsirkin
2024-02-01  5:47       ` Jason Wang
2024-02-01  6:43     ` Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 05/17] virtio_ring: split: structure the indirect desc table Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-01-30 11:42 ` [PATCH vhost 06/17] virtio_ring: no store dma info when unmap is not needed Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-02-01  6:04     ` Xuan Zhuo [this message]
2024-02-02  3:04       ` Jason Wang
2024-01-30 11:42 ` [PATCH vhost 07/17] virtio: find_vqs: pass struct instead of multi parameters Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-02-01  3:00     ` Xuan Zhuo
2024-02-20 14:18       ` Halil Pasic
2024-02-21  2:03         ` Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 08/17] virtio: vring_new_virtqueue(): " Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-01-31 11:03   ` Ilpo Järvinen
2024-02-01  2:24     ` Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 09/17] virtio_ring: reuse the parameter struct of find_vqs() Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 10/17] virtio: find_vqs: add new parameter premapped Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 11/17] virtio_ring: export premapped to driver by struct virtqueue Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-02-01  3:17     ` Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 12/17] virtio_net: set premapped mode by find_vqs() Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 13/17] virtio_ring: remove api of setting vq premapped Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 14/17] virtio_ring: introduce dma map api for page Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 15/17] virtio_net: unify the code for recycling the xmit ptr Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 16/17] virtio_net: rename free_old_xmit_skbs to free_old_xmit Xuan Zhuo
2024-01-30 11:42 ` [PATCH vhost 17/17] virtio_net: sq support premapped mode Xuan Zhuo
2024-01-31  9:12   ` Jason Wang
2024-02-01  3:21     ` Xuan Zhuo
2024-02-01  5:36       ` Jason Wang
2024-02-01  5:56         ` Xuan Zhuo
2024-02-02  3:06           ` Jason Wang
2024-02-01  7:43 ` [PATCH vhost 00/17] virtio: drivers maintain dma info for premapped vq Zhu Yanjun
2024-02-01  9:57   ` Xuan Zhuo

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=1706767497.2529867-3-xuanzhuo@linux.alibaba.com \
    --to=xuanzhuo@linux.alibaba.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andersson@kernel.org \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=ast@kernel.org \
    --cc=benjamin.berg@intel.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=cohuck@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=farman@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hawk@kernel.org \
    --cc=hca@linux.ibm.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jasowang@redhat.com \
    --cc=johannes@sipsolutions.net \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=svens@linux.ibm.com \
    --cc=vadimp@nvidia.com \
    --cc=virtualization@lists.linux.dev \
    --cc=yang.lee@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