From: Jason Wang <jasowang@redhat.com>
To: "Eugenio Pérez" <eperezma@redhat.com>, qemu-devel@nongnu.org
Cc: Harpreet Singh Anand <hanand@xilinx.com>,
Cindy Lu <lulu@redhat.com>, Cornelia Huck <cohuck@redhat.com>,
kvm@vger.kernel.org, Parav Pandit <parav@mellanox.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
"Gonglei (Arei)" <arei.gonglei@huawei.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Zhu Lingshan <lingshan.zhu@intel.com>,
Liuxiangdong <liuxiangdong5@huawei.com>,
Gautam Dawar <gdawar@xilinx.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Eli Cohen <eli@mellanox.com>, Laurent Vivier <lvivier@redhat.com>
Subject: Re: [PATCH v2 4/7] vdpa: Add asid parameter to vhost_vdpa_dma_map/unmap
Date: Mon, 25 Jul 2022 17:36:28 +0800 [thread overview]
Message-ID: <22b35cff-bcd5-78b8-cab4-43d2e65dccbe@redhat.com> (raw)
In-Reply-To: <20220722134318.3430667-5-eperezma@redhat.com>
在 2022/7/22 21:43, Eugenio Pérez 写道:
> So the caller can choose which ASID is destined.
>
> No need to update the batch functions as they will always be called from
> memory listener updates at the moment. Memory listener updates will
> always update ASID 0, as it's the passthrough ASID.
>
> All vhost devices's ASID are 0 at this moment.
>
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
> include/hw/virtio/vhost-vdpa.h | 8 +++++---
> hw/virtio/vhost-vdpa.c | 26 ++++++++++++++++----------
> net/vhost-vdpa.c | 6 +++---
> hw/virtio/trace-events | 4 ++--
> 4 files changed, 26 insertions(+), 18 deletions(-)
>
> diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
> index 1111d85643..6560bb9d78 100644
> --- a/include/hw/virtio/vhost-vdpa.h
> +++ b/include/hw/virtio/vhost-vdpa.h
> @@ -29,6 +29,7 @@ typedef struct vhost_vdpa {
> int index;
> uint32_t msg_type;
> bool iotlb_batch_begin_sent;
> + uint32_t address_space_id;
> MemoryListener listener;
> struct vhost_vdpa_iova_range iova_range;
> uint64_t acked_features;
> @@ -42,8 +43,9 @@ typedef struct vhost_vdpa {
> VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
> } VhostVDPA;
>
> -int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
> - void *vaddr, bool readonly);
> -int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size);
> +int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
> + hwaddr size, void *vaddr, bool readonly);
> +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
> + hwaddr size);
>
> #endif
> diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
> index e1ed56b26d..79623badf2 100644
> --- a/hw/virtio/vhost-vdpa.c
> +++ b/hw/virtio/vhost-vdpa.c
> @@ -72,22 +72,24 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section,
> return false;
> }
>
> -int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
> - void *vaddr, bool readonly)
> +int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
> + hwaddr size, void *vaddr, bool readonly)
> {
> struct vhost_msg_v2 msg = {};
> int fd = v->device_fd;
> int ret = 0;
>
> msg.type = v->msg_type;
> + msg.asid = asid;
> msg.iotlb.iova = iova;
> msg.iotlb.size = size;
> msg.iotlb.uaddr = (uint64_t)(uintptr_t)vaddr;
> msg.iotlb.perm = readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW;
> msg.iotlb.type = VHOST_IOTLB_UPDATE;
>
> - trace_vhost_vdpa_dma_map(v, fd, msg.type, msg.iotlb.iova, msg.iotlb.size,
> - msg.iotlb.uaddr, msg.iotlb.perm, msg.iotlb.type);
> + trace_vhost_vdpa_dma_map(v, fd, msg.type, msg.asid, msg.iotlb.iova,
> + msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.perm,
> + msg.iotlb.type);
>
> if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) {
> error_report("failed to write, fd=%d, errno=%d (%s)",
> @@ -98,18 +100,20 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
> return ret;
> }
>
> -int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, hwaddr iova, hwaddr size)
> +int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova,
> + hwaddr size)
> {
> struct vhost_msg_v2 msg = {};
> int fd = v->device_fd;
> int ret = 0;
>
> msg.type = v->msg_type;
> + msg.asid = asid;
> msg.iotlb.iova = iova;
> msg.iotlb.size = size;
> msg.iotlb.type = VHOST_IOTLB_INVALIDATE;
>
> - trace_vhost_vdpa_dma_unmap(v, fd, msg.type, msg.iotlb.iova,
> + trace_vhost_vdpa_dma_unmap(v, fd, msg.type, msg.asid, msg.iotlb.iova,
> msg.iotlb.size, msg.iotlb.type);
>
> if (write(fd, &msg, sizeof(msg)) != sizeof(msg)) {
> @@ -228,7 +232,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener,
> }
>
> vhost_vdpa_iotlb_batch_begin_once(v);
> - ret = vhost_vdpa_dma_map(v, iova, int128_get64(llsize),
> + ret = vhost_vdpa_dma_map(v, 0, iova, int128_get64(llsize),
> vaddr, section->readonly);
> if (ret) {
> error_report("vhost vdpa map fail!");
> @@ -293,7 +297,7 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,
> vhost_iova_tree_remove(v->iova_tree, result);
> }
> vhost_vdpa_iotlb_batch_begin_once(v);
> - ret = vhost_vdpa_dma_unmap(v, iova, int128_get64(llsize));
> + ret = vhost_vdpa_dma_unmap(v, 0, iova, int128_get64(llsize));
> if (ret) {
> error_report("vhost_vdpa dma unmap error!");
> }
> @@ -884,7 +888,7 @@ static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v,
> }
>
> size = ROUND_UP(result->size, qemu_real_host_page_size());
> - r = vhost_vdpa_dma_unmap(v, result->iova, size);
> + r = vhost_vdpa_dma_unmap(v, v->address_space_id, result->iova, size);
> return r == 0;
> }
>
> @@ -926,7 +930,8 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *v, DMAMap *needle,
> return false;
> }
>
> - r = vhost_vdpa_dma_map(v, needle->iova, needle->size + 1,
> + r = vhost_vdpa_dma_map(v, v->address_space_id, needle->iova,
> + needle->size + 1,
> (void *)(uintptr_t)needle->translated_addr,
> needle->perm == IOMMU_RO);
> if (unlikely(r != 0)) {
> @@ -1092,6 +1097,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
>
> if (started) {
> vhost_vdpa_host_notifiers_init(dev);
> +
Unnecessary changes.
Other looks good.
Thanks
> ok = vhost_vdpa_svqs_start(dev);
> if (unlikely(!ok)) {
> return -1;
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 75143ded8b..8203200c2a 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -229,7 +229,7 @@ static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr)
> return;
> }
>
> - r = vhost_vdpa_dma_unmap(v, map->iova, map->size + 1);
> + r = vhost_vdpa_dma_unmap(v, v->address_space_id, map->iova, map->size + 1);
> if (unlikely(r != 0)) {
> error_report("Device cannot unmap: %s(%d)", g_strerror(r), r);
> }
> @@ -278,8 +278,8 @@ static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v,
> return false;
> }
>
> - r = vhost_vdpa_dma_map(v, map.iova, vhost_vdpa_net_cvq_cmd_page_len(), buf,
> - !write);
> + r = vhost_vdpa_dma_map(v, v->address_space_id, map.iova,
> + vhost_vdpa_net_cvq_cmd_page_len(), buf, !write);
> if (unlikely(r < 0)) {
> goto dma_map_err;
> }
> diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
> index 20af2e7ebd..36e5ae75f6 100644
> --- a/hw/virtio/trace-events
> +++ b/hw/virtio/trace-events
> @@ -26,8 +26,8 @@ vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32""
> vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p"
>
> # vhost-vdpa.c
> -vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8
> -vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8
> +vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8
> +vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8
> vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8
> vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8
> vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d"
next prev parent reply other threads:[~2022-07-25 9:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-22 13:43 [PATCH v2 0/7] ASID support in vhost-vdpa net Eugenio Pérez
2022-07-22 13:43 ` [PATCH v2 1/7] linux-headers: Update kernel headers to v5.19-rc1 Eugenio Pérez
2022-07-22 13:43 ` [PATCH v2 2/7] vdpa: Use v->shadow_vqs_enabled in vhost_vdpa_svqs_start & stop Eugenio Pérez
2022-07-22 13:43 ` [PATCH v2 3/7] vdpa: Allocate SVQ unconditionally Eugenio Pérez
2022-07-22 13:43 ` [PATCH v2 4/7] vdpa: Add asid parameter to vhost_vdpa_dma_map/unmap Eugenio Pérez
2022-07-25 9:36 ` Jason Wang [this message]
2022-08-01 7:12 ` Eugenio Perez Martin
2022-07-22 13:43 ` [PATCH v2 5/7] vdpa: Store x-svq parameter in VhostVDPAState Eugenio Pérez
2022-07-22 13:43 ` [PATCH v2 6/7] vhost_net: Add NetClientInfo prepare callback Eugenio Pérez
2022-07-22 13:43 ` [PATCH v2 7/7] vdpa: Always start CVQ in SVQ mode Eugenio Pérez
2022-07-26 3:04 ` Jason Wang
2022-08-01 7:50 ` Eugenio Perez Martin
2022-08-03 17:18 ` Eugenio Perez Martin
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=22b35cff-bcd5-78b8-cab4-43d2e65dccbe@redhat.com \
--to=jasowang@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=cohuck@redhat.com \
--cc=eli@mellanox.com \
--cc=eperezma@redhat.com \
--cc=gdawar@xilinx.com \
--cc=hanand@xilinx.com \
--cc=kvm@vger.kernel.org \
--cc=lingshan.zhu@intel.com \
--cc=liuxiangdong5@huawei.com \
--cc=lulu@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=parav@mellanox.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=stefanha@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).