From: Jason Wang <jasowang@redhat.com>
To: wexu@redhat.com, qemu-devel@nongnu.org
Cc: tiwei.bie@intel.com, mst@redhat.com, jfreimann@redhat.com
Subject: Re: [Qemu-devel] [RFC v2 6/8] virtio: flush/push for packed ring
Date: Wed, 6 Jun 2018 11:39:00 +0800 [thread overview]
Message-ID: <b47bd06f-f140-454d-d862-74821cedddaa@redhat.com> (raw)
In-Reply-To: <1528225683-11413-7-git-send-email-wexu@redhat.com>
On 2018年06月06日 03:08, wexu@redhat.com wrote:
> From: Wei Xu <wexu@redhat.com>
>
> Signed-off-by: Wei Xu <wexu@redhat.com>
> Signed-off-by: Wei Xu <wexu@redhat.com>
> ---
> hw/virtio/virtio.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 96 insertions(+), 13 deletions(-)
>
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 0160d03..6f2da83 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -371,6 +371,21 @@ static void vring_packed_desc_read(VirtIODevice *vdev, VRingDescPacked *desc,
> virtio_tswap16s(vdev, &desc->flags);
> }
>
> +static void vring_packed_desc_write(VirtIODevice *vdev, VRingDescPacked *desc,
> + MemoryRegionCache *cache, int i)
> +{
> + virtio_tswap64s(vdev, &desc->addr);
> + virtio_tswap32s(vdev, &desc->len);
> + virtio_tswap16s(vdev, &desc->id);
> + virtio_tswap16s(vdev, &desc->flags);
> + address_space_write_cached(cache,
> + sizeof(VRingDescPacked) * i, desc,
> + sizeof(VRingDescPacked));
> + address_space_cache_invalidate(cache,
> + sizeof(VRingDescPacked) * i,
> + sizeof(VRingDescPacked));
Is there a guarantee that flags was wrote before all other fields?
> +}
> +
> static inline bool is_desc_avail(struct VRingDescPacked *desc)
> {
> return !!(desc->flags & AVAIL_DESC_PACKED(1)) !=
> @@ -526,19 +541,11 @@ bool virtqueue_rewind(VirtQueue *vq, unsigned int num)
> }
>
> /* Called within rcu_read_lock(). */
> -void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
> +static void virtqueue_split_fill(VirtQueue *vq, const VirtQueueElement *elem,
> unsigned int len, unsigned int idx)
> {
> VRingUsedElem uelem;
>
> - trace_virtqueue_fill(vq, elem, len, idx);
> -
> - virtqueue_unmap_sg(vq, elem, len);
> -
> - if (unlikely(vq->vdev->broken)) {
> - return;
> - }
> -
> if (unlikely(!vq->vring.used)) {
> return;
> }
> @@ -550,16 +557,64 @@ void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
> vring_used_write(vq, &uelem, idx);
> }
>
> -/* Called within rcu_read_lock(). */
> -void virtqueue_flush(VirtQueue *vq, unsigned int count)
> +static void virtqueue_packed_fill(VirtQueue *vq, const VirtQueueElement *elem,
> + unsigned int len, unsigned int idx)
> {
> - uint16_t old, new;
> + uint16_t w, head;
> + VRingMemoryRegionCaches *caches;
> + VRingDescPacked desc = {
> + .addr = 0,
> + .flags = 0,
> + };
> +
> + if (unlikely(!vq->vring.desc)) {
> + return;
> + }
> +
> + caches = vring_get_region_caches(vq);
> + head = vq->used_idx + idx;
> + head = head >= vq->vring.num ? (head - vq->vring.num) : head;
> + vring_packed_desc_read(vq->vdev, &desc, &caches->desc, head);
> +
> + w = (desc.flags & AVAIL_DESC_PACKED(1)) >> 7;
> + desc.flags &= ~(AVAIL_DESC_PACKED(1) | USED_DESC_PACKED(1));
> + desc.flags |= AVAIL_DESC_PACKED(w) | USED_DESC_PACKED(w);
Why need read descriptor here? We should set the used counter by our own
(e.g we have used_wrap_counter).
> + if (!(desc.flags & VRING_DESC_F_INDIRECT)) {
> + if (!(desc.flags & VRING_DESC_F_WRITE)) {
> + desc.len = 0;
> + } else {
> + desc.len = len;
> + }
> + }
> + vring_packed_desc_write(vq->vdev, &desc, &caches->desc, head);
> +
> + /* Make sure flags has been updated */
> + smp_mb();
This looks wrong, and if you think it's correct, you need a better
comment to explain, e.g how it was paired with other.
Thanks
> +}
> +
> +void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
> + unsigned int len, unsigned int idx)
> +{
> + trace_virtqueue_fill(vq, elem, len, idx);
> +
> + virtqueue_unmap_sg(vq, elem, len);
>
> if (unlikely(vq->vdev->broken)) {
> - vq->inuse -= count;
> return;
> }
>
> + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) {
> + virtqueue_packed_fill(vq, elem, len, idx);
> + } else {
> + virtqueue_split_fill(vq, elem, len, idx);
> + }
> +}
> +
> +/* Called within rcu_read_lock(). */
> +static void virtqueue_split_flush(VirtQueue *vq, unsigned int count)
> +{
> + uint16_t old, new;
> +
> if (unlikely(!vq->vring.used)) {
> return;
> }
> @@ -575,6 +630,34 @@ void virtqueue_flush(VirtQueue *vq, unsigned int count)
> vq->signalled_used_valid = false;
> }
>
> +static void virtqueue_packed_flush(VirtQueue *vq, unsigned int count)
> +{
> + if (unlikely(!vq->vring.desc)) {
> + return;
> + }
> +
> + vq->inuse -= count;
> + vq->used_idx += count;
> + if (vq->used_idx >= vq->vring.num) {
> + vq->used_idx -= vq->vring.num;
> + vq->used_wrap_counter = !vq->used_wrap_counter;
> + }
> +}
> +
> +void virtqueue_flush(VirtQueue *vq, unsigned int count)
> +{
> + if (unlikely(vq->vdev->broken)) {
> + vq->inuse -= count;
> + return;
> + }
> +
> + if (virtio_vdev_has_feature(vq->vdev, VIRTIO_F_RING_PACKED)) {
> + virtqueue_packed_flush(vq, count);
> + } else {
> + virtqueue_split_flush(vq, count);
> + }
> +}
> +
> void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
> unsigned int len)
> {
next prev parent reply other threads:[~2018-06-06 3:39 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-05 19:07 [Qemu-devel] [RFC v2 0/8] packed ring virtio-net userspace backend support wexu
2018-06-05 19:07 ` [Qemu-devel] [RFC v2 1/8] virtio: feature bit, data structure, init for 1.1 wexu
2018-06-06 2:49 ` Jason Wang
2018-06-05 19:07 ` [Qemu-devel] [RFC v2 2/8] virtio: memory cache for packed ring wexu
2018-06-06 2:53 ` Jason Wang
2018-06-19 7:39 ` Wei Xu
2018-06-13 12:27 ` Paolo Bonzini
2018-06-05 19:07 ` [Qemu-devel] [RFC v2 3/8] virtio: empty check and desc read " wexu
2018-06-06 3:09 ` Jason Wang
2018-06-05 19:07 ` [Qemu-devel] [RFC v2 4/8] virtio: get avail bytes check " wexu
2018-06-06 3:19 ` Jason Wang
2018-06-05 19:08 ` [Qemu-devel] [RFC v2 5/8] virtio: queue pop " wexu
2018-06-06 3:29 ` Jason Wang
2018-06-06 3:38 ` Wei Xu
2018-06-06 3:41 ` Jason Wang
2018-06-19 7:58 ` Wei Xu
2018-06-05 19:08 ` [Qemu-devel] [RFC v2 6/8] virtio: flush/push " wexu
2018-06-06 3:39 ` Jason Wang [this message]
[not found] ` <7dc2af60-47ad-1250-fc6c-3fdf288654c3@redhat.com>
2018-11-28 17:33 ` Maxime Coquelin
2018-06-05 19:08 ` [Qemu-devel] [RFC v2 7/8] virtio: event suppression " wexu
2018-06-06 3:46 ` Jason Wang
2018-06-05 19:08 ` [Qemu-devel] [RFC v2 8/8] virtio: guest driver reload for vhost-net wexu
2018-06-06 3:48 ` Jason Wang
2018-06-19 7:53 ` Wei Xu
2018-06-06 2:34 ` [Qemu-devel] [RFC v2 0/8] packed ring virtio-net userspace backend support Jason Wang
2018-06-06 3:49 ` Jason Wang
2018-06-19 7:41 ` Wei Xu
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=b47bd06f-f140-454d-d862-74821cedddaa@redhat.com \
--to=jasowang@redhat.com \
--cc=jfreimann@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=tiwei.bie@intel.com \
--cc=wexu@redhat.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;
as well as URLs for NNTP newsgroup(s).