From: Jason Wang <jasowang@redhat.com> To: mst@redhat.com, jasowang@redhat.com Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, tiwei.bie@intel.com, jfreimann@redhat.com, wexu@redhat.com Subject: [RFC V3 PATCH 4/8] vhost_net: do not explicitly manipulate vhost_used_elem Date: Mon, 23 Apr 2018 13:34:56 +0800 [thread overview] Message-ID: <1524461700-5469-5-git-send-email-jasowang@redhat.com> (raw) In-Reply-To: <1524461700-5469-1-git-send-email-jasowang@redhat.com> Two helpers of setting/getting used len were introduced to avoid explicitly manipulating vhost_used_elem in zerocopy code. This will be used to hide used_elem internals and simplify packed ring implementation. Signed-off-by: Jason Wang <jasowang@redhat.com> --- drivers/vhost/net.c | 11 +++++------ drivers/vhost/vhost.c | 12 ++++++++++-- drivers/vhost/vhost.h | 5 +++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 3826f1f..30273ad 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -341,9 +341,10 @@ static void vhost_zerocopy_signal_used(struct vhost_net *net, int j = 0; for (i = nvq->done_idx; i != nvq->upend_idx; i = (i + 1) % UIO_MAXIOV) { - if (vq->heads[i].elem.len == VHOST_DMA_FAILED_LEN) + if (vhost_get_used_len(vq, &vq->heads[i]) == + VHOST_DMA_FAILED_LEN) vhost_net_tx_err(net); - if (VHOST_DMA_IS_DONE(vq->heads[i].elem.len)) { + if (VHOST_DMA_IS_DONE(vhost_get_used_len(vq, &vq->heads[i]))) { vq->heads[i].elem.len = VHOST_DMA_CLEAR_LEN; ++j; } else @@ -542,10 +543,8 @@ static void handle_tx(struct vhost_net *net) struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].elem.id = - cpu_to_vhost32(vq, used.elem.id); - vq->heads[nvq->upend_idx].elem.len = - VHOST_DMA_IN_PROGRESS; + vhost_set_used_len(vq, &used, VHOST_DMA_IN_PROGRESS); + vq->heads[nvq->upend_idx] = used; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs; ubuf->desc = nvq->upend_idx; diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 24f3013..5cc1cdb 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2099,11 +2099,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, } EXPORT_SYMBOL_GPL(vhost_get_vq_desc); -static void vhost_set_used_len(struct vhost_virtqueue *vq, - struct vhost_used_elem *used, int len) +void vhost_set_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used, int len) { used->elem.len = cpu_to_vhost32(vq, len); } +EXPORT_SYMBOL_GPL(vhost_set_used_len); + +int vhost_get_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used) +{ + return vhost32_to_cpu(vq, used->elem.len); +} +EXPORT_SYMBOL_GPL(vhost_get_used_len); /* This is a multi-buffer version of vhost_get_desc, that works if * vq has read descriptors only. diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 8dea44b..604821b 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -198,6 +198,11 @@ int vhost_get_bufs(struct vhost_virtqueue *vq, unsigned *log_num, unsigned int quota, s16 *count); +void vhost_set_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used, + int len); +int vhost_get_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used); void vhost_discard_vq_desc(struct vhost_virtqueue *, int n); int vhost_vq_init_access(struct vhost_virtqueue *); -- 2.7.4
WARNING: multiple messages have this Message-ID (diff)
From: Jason Wang <jasowang@redhat.com> To: mst@redhat.com, jasowang@redhat.com Cc: kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, wexu@redhat.com Subject: [RFC V3 PATCH 4/8] vhost_net: do not explicitly manipulate vhost_used_elem Date: Mon, 23 Apr 2018 13:34:56 +0800 [thread overview] Message-ID: <1524461700-5469-5-git-send-email-jasowang@redhat.com> (raw) In-Reply-To: <1524461700-5469-1-git-send-email-jasowang@redhat.com> Two helpers of setting/getting used len were introduced to avoid explicitly manipulating vhost_used_elem in zerocopy code. This will be used to hide used_elem internals and simplify packed ring implementation. Signed-off-by: Jason Wang <jasowang@redhat.com> --- drivers/vhost/net.c | 11 +++++------ drivers/vhost/vhost.c | 12 ++++++++++-- drivers/vhost/vhost.h | 5 +++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 3826f1f..30273ad 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -341,9 +341,10 @@ static void vhost_zerocopy_signal_used(struct vhost_net *net, int j = 0; for (i = nvq->done_idx; i != nvq->upend_idx; i = (i + 1) % UIO_MAXIOV) { - if (vq->heads[i].elem.len == VHOST_DMA_FAILED_LEN) + if (vhost_get_used_len(vq, &vq->heads[i]) == + VHOST_DMA_FAILED_LEN) vhost_net_tx_err(net); - if (VHOST_DMA_IS_DONE(vq->heads[i].elem.len)) { + if (VHOST_DMA_IS_DONE(vhost_get_used_len(vq, &vq->heads[i]))) { vq->heads[i].elem.len = VHOST_DMA_CLEAR_LEN; ++j; } else @@ -542,10 +543,8 @@ static void handle_tx(struct vhost_net *net) struct ubuf_info *ubuf; ubuf = nvq->ubuf_info + nvq->upend_idx; - vq->heads[nvq->upend_idx].elem.id = - cpu_to_vhost32(vq, used.elem.id); - vq->heads[nvq->upend_idx].elem.len = - VHOST_DMA_IN_PROGRESS; + vhost_set_used_len(vq, &used, VHOST_DMA_IN_PROGRESS); + vq->heads[nvq->upend_idx] = used; ubuf->callback = vhost_zerocopy_callback; ubuf->ctx = nvq->ubufs; ubuf->desc = nvq->upend_idx; diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 24f3013..5cc1cdb 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2099,11 +2099,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq, } EXPORT_SYMBOL_GPL(vhost_get_vq_desc); -static void vhost_set_used_len(struct vhost_virtqueue *vq, - struct vhost_used_elem *used, int len) +void vhost_set_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used, int len) { used->elem.len = cpu_to_vhost32(vq, len); } +EXPORT_SYMBOL_GPL(vhost_set_used_len); + +int vhost_get_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used) +{ + return vhost32_to_cpu(vq, used->elem.len); +} +EXPORT_SYMBOL_GPL(vhost_get_used_len); /* This is a multi-buffer version of vhost_get_desc, that works if * vq has read descriptors only. diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 8dea44b..604821b 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -198,6 +198,11 @@ int vhost_get_bufs(struct vhost_virtqueue *vq, unsigned *log_num, unsigned int quota, s16 *count); +void vhost_set_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used, + int len); +int vhost_get_used_len(struct vhost_virtqueue *vq, + struct vhost_used_elem *used); void vhost_discard_vq_desc(struct vhost_virtqueue *, int n); int vhost_vq_init_access(struct vhost_virtqueue *); -- 2.7.4
next prev parent reply other threads:[~2018-04-23 5:37 UTC|newest] Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-04-23 5:34 [RFC V3 PATCH 0/8] Packed ring for vhost Jason Wang 2018-04-23 5:34 ` [RFC V3 PATCH 1/8] vhost: move get_rx_bufs to vhost.c Jason Wang 2018-05-02 8:05 ` Tiwei Bie 2018-05-02 8:05 ` Tiwei Bie 2018-05-03 7:19 ` Jason Wang 2018-05-03 7:19 ` Jason Wang 2018-04-23 5:34 ` Jason Wang 2018-04-23 5:34 ` [RFC V3 PATCH 2/8] vhost: hide used ring layout from device Jason Wang 2018-04-23 5:34 ` Jason Wang 2018-04-23 5:34 ` [RFC V3 PATCH 3/8] vhost: do not use vring_used_elem Jason Wang 2018-04-23 5:34 ` Jason Wang 2018-04-23 5:34 ` Jason Wang [this message] 2018-04-23 5:34 ` [RFC V3 PATCH 4/8] vhost_net: do not explicitly manipulate vhost_used_elem Jason Wang 2018-04-23 5:34 ` [RFC V3 PATCH 5/8] vhost: vhost_put_user() can accept metadata type Jason Wang 2018-04-23 5:34 ` Jason Wang 2018-04-23 5:34 ` [RFC V3 PATCH 6/8] virtio: introduce packed ring defines Jason Wang 2018-04-23 5:34 ` Jason Wang 2018-04-23 5:34 ` [RFC V3 PATCH 7/8] vhost: packed ring support Jason Wang 2018-04-23 5:34 ` Jason Wang 2018-04-23 5:35 ` [RFC V3 PATCH 8/8] vhost: event suppression for packed ring Jason Wang 2018-04-23 5:35 ` Jason Wang 2018-04-23 19:31 ` [RFC V3 PATCH 0/8] Packed ring for vhost Konrad Rzeszutek Wilk 2018-04-23 19:31 ` Konrad Rzeszutek Wilk 2018-04-23 19:59 ` Michael S. Tsirkin 2018-04-23 19:59 ` Michael S. Tsirkin 2018-04-23 20:11 ` Konrad Rzeszutek Wilk 2018-04-23 20:11 ` Konrad Rzeszutek Wilk 2018-04-24 1:04 ` Jason Wang 2018-04-24 1:04 ` Jason Wang
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=1524461700-5469-5-git-send-email-jasowang@redhat.com \ --to=jasowang@redhat.com \ --cc=jfreimann@redhat.com \ --cc=kvm@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=mst@redhat.com \ --cc=netdev@vger.kernel.org \ --cc=tiwei.bie@intel.com \ --cc=virtualization@lists.linux-foundation.org \ --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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.