bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: Jason Wang <jasowang@redhat.com>
Cc: virtualization <virtualization@lists.linux-foundation.org>,
	netdev <netdev@vger.kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	bpf@vger.kernel.org
Subject: Re: [PATCH v5 19/22] virtio: add helper virtio_set_max_ring_num()
Date: Wed, 16 Feb 2022 15:54:23 +0800	[thread overview]
Message-ID: <1644998063.772229-2-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <CACGkMEsdySbtHN4SNSmX8sD6Y7S=dj3oxq5a3EBhRG1qUeT24A@mail.gmail.com>

On Wed, 16 Feb 2022 12:14:04 +0800, Jason Wang <jasowang@redhat.com> wrote:
> On Mon, Feb 14, 2022 at 4:15 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> >
> > Added helper virtio_set_max_ring_num() to set the upper limit of ring
> > num when creating a virtqueue.
> >
> > Can be used to limit ring num before find_vqs() call. Or change ring num
> > when re-enable reset queue.
>
> Do we have a chance that RX and TX may want different ring size? If
> yes, it might be even better to have per vq limit via find_vqs()?
>
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > ---
> >  drivers/virtio/virtio_ring.c  |  6 ++++++
> >  include/linux/virtio.h        |  1 +
> >  include/linux/virtio_config.h | 30 ++++++++++++++++++++++++++++++
> >  3 files changed, 37 insertions(+)
> >
> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > index 1a123b5e5371..a77a82883e44 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -943,6 +943,9 @@ static struct virtqueue *vring_create_virtqueue_split(
> >         size_t queue_size_in_bytes;
> >         struct vring vring;
> >
> > +       if (vdev->max_ring_num && num > vdev->max_ring_num)
> > +               num = vdev->max_ring_num;
> > +
> >         /* We assume num is a power of 2. */
> >         if (num & (num - 1)) {
> >                 dev_warn(&vdev->dev, "Bad virtqueue length %u\n", num);
> > @@ -1692,6 +1695,9 @@ static struct virtqueue *vring_create_virtqueue_packed(
> >         dma_addr_t ring_dma_addr, driver_event_dma_addr, device_event_dma_addr;
> >         size_t ring_size_in_bytes, event_size_in_bytes;
> >
> > +       if (vdev->max_ring_num && num > vdev->max_ring_num)
> > +               num = vdev->max_ring_num;
> > +
> >         ring_size_in_bytes = num * sizeof(struct vring_packed_desc);
> >
> >         ring = vring_alloc_queue(vdev, ring_size_in_bytes,
> > diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> > index 1153b093c53d..45525beb2ec4 100644
> > --- a/include/linux/virtio.h
> > +++ b/include/linux/virtio.h
> > @@ -127,6 +127,7 @@ struct virtio_device {
> >         struct list_head vqs;
> >         u64 features;
> >         void *priv;
> > +       u16 max_ring_num;
> >  };
> >
> >  static inline struct virtio_device *dev_to_virtio(struct device *_dev)
> > diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> > index cd7f7f44ce38..d7cb2d0341ee 100644
> > --- a/include/linux/virtio_config.h
> > +++ b/include/linux/virtio_config.h
> > @@ -200,6 +200,36 @@ static inline bool virtio_has_dma_quirk(const struct virtio_device *vdev)
> >         return !virtio_has_feature(vdev, VIRTIO_F_ACCESS_PLATFORM);
> >  }
> >
> > +/**
> > + * virtio_set_max_ring_num - set max ring num
> > + * @vdev: the device
> > + * @num: max ring num. Zero clear the limit.
> > + *
> > + * When creating a virtqueue, use this value as the upper limit of ring num.
> > + *
> > + * Returns 0 on success or error status
> > + */
> > +static inline
> > +int virtio_set_max_ring_num(struct virtio_device *vdev, u16 num)
> > +{
>
> Having a dedicated helper for a per device parameter usually means the
> use cases are greatly limited. For example, this seems can only be
> used when DRIVER_OK is not set?
>
> And in patch 17 this function is called even if we only modify the RX
> size, this is probably another call for a more flexible API as I
> suggest like exporting vring allocation/deallocation helper and extend
> find_vqs()?
>

I understand.

Thanks.

> Thanks
>
>
> > +       if (!num) {
> > +               vdev->max_ring_num = num;
> > +               return 0;
> > +       }
> > +
> > +       if (!virtio_has_feature(vdev, VIRTIO_F_RING_PACKED)) {
> > +               if (!is_power_of_2(num)) {
> > +                       num = __rounddown_pow_of_two(num);
> > +
> > +                       if (!num)
> > +                               return -EINVAL;
> > +               }
> > +       }
> > +
> > +       vdev->max_ring_num = num;
> > +       return 0;
> > +}
> > +
> >  static inline
> >  struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,
> >                                         vq_callback_t *c, const char *n)
> > --
> > 2.31.0
> >
>

  reply	other threads:[~2022-02-16  7:55 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-14  8:13 [PATCH v5 00/22] virtio pci support VIRTIO_F_RING_RESET Xuan Zhuo
2022-02-14  8:13 ` [PATCH v5 01/22] virtio_pci: struct virtio_pci_common_cfg add queue_notify_data Xuan Zhuo
2022-02-14  8:13 ` [PATCH v5 02/22] virtio: queue_reset: add VIRTIO_F_RING_RESET Xuan Zhuo
2022-02-14  8:13 ` [PATCH v5 03/22] virtio_ring: queue_reset: add function vring_setup_virtqueue() Xuan Zhuo
2022-02-14  8:13 ` [PATCH v5 04/22] virtio_ring: queue_reset: split: add __vring_init_virtqueue() Xuan Zhuo
2022-02-14  8:13 ` [PATCH v5 05/22] virtio_ring: queue_reset: split: support enable reset queue Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 06/22] virtio_ring: queue_reset: packed: " Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-14  8:14 ` [PATCH v5 07/22] virtio_ring: queue_reset: extract the release function of the vq ring Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 08/22] virtio_ring: queue_reset: add vring_release_virtqueue() Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-14  8:14 ` [PATCH v5 09/22] virtio: queue_reset: struct virtio_config_ops add callbacks for queue_reset Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 10/22] virtio_pci: queue_reset: update struct virtio_pci_common_cfg and option functions Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 11/22] virtio_pci: queue_reset: release vq by vp_dev->vqs Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 12/22] virtio_pci: queue_reset: setup_vq() support vring_setup_virtqueue() Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 13/22] virtio_pci: queue_reset: reserve vq->priv for re-enable queue Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 14/22] virtio_pci: queue_reset: support VIRTIO_F_RING_RESET Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  8:03     ` Xuan Zhuo
2022-02-17  7:25       ` Jason Wang
2022-02-14  8:14 ` [PATCH v5 15/22] virtio: queue_reset: add helper Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 16/22] virtio_net: split free_unused_bufs() Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 17/22] virtio_net: support rx/tx queue reset Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  7:56     ` Xuan Zhuo
2022-02-16  8:35       ` Michael S. Tsirkin
2022-02-16  8:42         ` Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 18/22] virtio: add helper virtqueue_get_vring_max_size() Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 19/22] virtio: add helper virtio_set_max_ring_num() Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  7:54     ` Xuan Zhuo [this message]
2022-02-14  8:14 ` [PATCH v5 20/22] virtio_net: set the default max ring num Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  7:46     ` Xuan Zhuo
2022-02-17  7:21       ` Jason Wang
2022-02-17  9:30         ` Xuan Zhuo
2022-02-21  3:40           ` Jason Wang
2022-02-21  7:00             ` Jason Wang
2022-02-14  8:14 ` [PATCH v5 21/22] virtio_net: get max ring size by virtqueue_get_vring_max_size() Xuan Zhuo
2022-02-14  8:14 ` [PATCH v5 22/22] virtio_net: support set_ringparam Xuan Zhuo
2022-02-16  4:14   ` Jason Wang
2022-02-16  7:21     ` 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=1644998063.772229-2-xuanzhuo@linux.alibaba.com \
    --to=xuanzhuo@linux.alibaba.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=jasowang@redhat.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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;
as well as URLs for NNTP newsgroup(s).