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 5/8] vhost: vhost_put_user() can accept metadata type Date: Mon, 23 Apr 2018 13:34:57 +0800 [thread overview] Message-ID: <1524461700-5469-6-git-send-email-jasowang@redhat.com> (raw) In-Reply-To: <1524461700-5469-1-git-send-email-jasowang@redhat.com> We assumes used ring update is the only user for vhost_put_user() in the past. This may not be the case for the incoming packed ring which may update the descriptor ring for used. So introduce a new type parameter. Signed-off-by: Jason Wang <jasowang@redhat.com> --- drivers/vhost/vhost.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 5cc1cdb..82a7b73 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -846,7 +846,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, return __vhost_get_user_slow(vq, addr, size, type); } -#define vhost_put_user(vq, x, ptr) \ +#define vhost_put_user(vq, x, ptr, type) \ ({ \ int ret = -EFAULT; \ if (!vq->iotlb) { \ @@ -854,7 +854,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, } else { \ __typeof__(ptr) to = \ (__typeof__(ptr)) __vhost_get_user(vq, ptr, \ - sizeof(*ptr), VHOST_ADDR_USED); \ + sizeof(*ptr), type); \ if (to != NULL) \ ret = __put_user(x, to); \ else \ @@ -1715,7 +1715,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) { void __user *used; if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->used_flags), - &vq->used->flags) < 0) + &vq->used->flags, VHOST_ADDR_USED) < 0) return -EFAULT; if (unlikely(vq->log_used)) { /* Make sure the flag is seen before log. */ @@ -1734,7 +1734,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) static int vhost_update_avail_event(struct vhost_virtqueue *vq, u16 avail_event) { if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->avail_idx), - vhost_avail_event(vq))) + vhost_avail_event(vq), VHOST_ADDR_USED)) return -EFAULT; if (unlikely(vq->log_used)) { void __user *used; @@ -2217,12 +2217,12 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq, used = vq->used->ring + start; for (i = 0; i < count; i++) { if (unlikely(vhost_put_user(vq, heads[i].elem.id, - &used[i].id))) { + &used[i].id, VHOST_ADDR_USED))) { vq_err(vq, "Failed to write used id"); return -EFAULT; } if (unlikely(vhost_put_user(vq, heads[i].elem.len, - &used[i].len))) { + &used[i].len, VHOST_ADDR_USED))) { vq_err(vq, "Failed to write used len"); return -EFAULT; } @@ -2268,7 +2268,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vhost_used_elem *heads, /* Make sure buffer is written before we update index. */ smp_wmb(); if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->last_used_idx), - &vq->used->idx)) { + &vq->used->idx, VHOST_ADDR_USED)) { vq_err(vq, "Failed to increment used idx"); return -EFAULT; } -- 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 5/8] vhost: vhost_put_user() can accept metadata type Date: Mon, 23 Apr 2018 13:34:57 +0800 [thread overview] Message-ID: <1524461700-5469-6-git-send-email-jasowang@redhat.com> (raw) In-Reply-To: <1524461700-5469-1-git-send-email-jasowang@redhat.com> We assumes used ring update is the only user for vhost_put_user() in the past. This may not be the case for the incoming packed ring which may update the descriptor ring for used. So introduce a new type parameter. Signed-off-by: Jason Wang <jasowang@redhat.com> --- drivers/vhost/vhost.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 5cc1cdb..82a7b73 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -846,7 +846,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, return __vhost_get_user_slow(vq, addr, size, type); } -#define vhost_put_user(vq, x, ptr) \ +#define vhost_put_user(vq, x, ptr, type) \ ({ \ int ret = -EFAULT; \ if (!vq->iotlb) { \ @@ -854,7 +854,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, } else { \ __typeof__(ptr) to = \ (__typeof__(ptr)) __vhost_get_user(vq, ptr, \ - sizeof(*ptr), VHOST_ADDR_USED); \ + sizeof(*ptr), type); \ if (to != NULL) \ ret = __put_user(x, to); \ else \ @@ -1715,7 +1715,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) { void __user *used; if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->used_flags), - &vq->used->flags) < 0) + &vq->used->flags, VHOST_ADDR_USED) < 0) return -EFAULT; if (unlikely(vq->log_used)) { /* Make sure the flag is seen before log. */ @@ -1734,7 +1734,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) static int vhost_update_avail_event(struct vhost_virtqueue *vq, u16 avail_event) { if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->avail_idx), - vhost_avail_event(vq))) + vhost_avail_event(vq), VHOST_ADDR_USED)) return -EFAULT; if (unlikely(vq->log_used)) { void __user *used; @@ -2217,12 +2217,12 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq, used = vq->used->ring + start; for (i = 0; i < count; i++) { if (unlikely(vhost_put_user(vq, heads[i].elem.id, - &used[i].id))) { + &used[i].id, VHOST_ADDR_USED))) { vq_err(vq, "Failed to write used id"); return -EFAULT; } if (unlikely(vhost_put_user(vq, heads[i].elem.len, - &used[i].len))) { + &used[i].len, VHOST_ADDR_USED))) { vq_err(vq, "Failed to write used len"); return -EFAULT; } @@ -2268,7 +2268,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vhost_used_elem *heads, /* Make sure buffer is written before we update index. */ smp_wmb(); if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->last_used_idx), - &vq->used->idx)) { + &vq->used->idx, VHOST_ADDR_USED)) { vq_err(vq, "Failed to increment used idx"); return -EFAULT; } -- 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 ` [RFC V3 PATCH 4/8] vhost_net: do not explicitly manipulate vhost_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 5/8] vhost: vhost_put_user() can accept metadata type 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-6-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.