From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id CC7462C35 for ; Tue, 14 Mar 2017 12:00:14 +0100 (CET) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37CC680F7B; Tue, 14 Mar 2017 11:00:15 +0000 (UTC) Received: from [10.36.116.175] (ovpn-116-175.ams2.redhat.com [10.36.116.175]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2EB0AgR029099 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 14 Mar 2017 07:00:13 -0400 To: Yuanhan Liu , dev@dpdk.org References: <1488534682-3494-1-git-send-email-yuanhan.liu@linux.intel.com> <1488534682-3494-6-git-send-email-yuanhan.liu@linux.intel.com> Cc: Harris James R , Liu Changpeng From: Maxime Coquelin Message-ID: <7e3f93f6-74a2-9a9f-7054-c7bafbc06f0f@redhat.com> Date: Tue, 14 Mar 2017 12:00:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <1488534682-3494-6-git-send-email-yuanhan.liu@linux.intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 14 Mar 2017 11:00:15 +0000 (UTC) Subject: Re: [dpdk-dev] [PATCH 05/17] vhost: export guest memory regions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2017 11:00:15 -0000 On 03/03/2017 10:51 AM, Yuanhan Liu wrote: > Some vhost-user driver may need this info to setup its own page tables > for GPA (guest physical addr) to HPA (host physical addr) translation. > SPDK (Storage Performance Development Kit) is one example. > > Besides, by exporting this memory info, we could also export the > gpa_to_vva() as an inline function, which helps for performance. > Otherwise, it has to be referenced indirectly by a "vid". > > Signed-off-by: Yuanhan Liu > --- > lib/librte_vhost/rte_vhost_version.map | 1 + > lib/librte_vhost/rte_virtio_net.h | 24 ++++++++++++++++++++++++ > lib/librte_vhost/vhost.c | 23 +++++++++++++++++++++++ > lib/librte_vhost/vhost.h | 28 ++-------------------------- > lib/librte_vhost/vhost_user.c | 12 ++++++------ > 5 files changed, 56 insertions(+), 32 deletions(-) > > diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map > index ee72d5f..b890da6 100644 > --- a/lib/librte_vhost/rte_vhost_version.map > +++ b/lib/librte_vhost/rte_vhost_version.map > @@ -35,5 +35,6 @@ DPDK_17.05 { > rte_vhost_driver_enable_features; > rte_vhost_driver_get_features; > rte_vhost_driver_set_features; > + rte_vhost_get_vhost_memory; > > } DPDK_16.07; > diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h > index 3bfd0b7..eddf0f4 100644 > --- a/lib/librte_vhost/rte_virtio_net.h > +++ b/lib/librte_vhost/rte_virtio_net.h > @@ -59,6 +59,28 @@ > enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM}; > > /** > + * Information relating to memory regions including offsets to > + * addresses in QEMUs memory file. > + */ > +struct rte_vhost_mem_region { > + uint64_t guest_phys_addr; > + uint64_t guest_user_addr; > + uint64_t host_user_addr; > + uint64_t size; > + void *mmap_addr; > + uint64_t mmap_size; > + int fd; > +}; > + > +/** > + * Memory structure includes region and mapping information. > + */ > +struct rte_vhost_memory { > + uint32_t nregions; > + struct rte_vhost_mem_region regions[0]; > +}; > + > +/** > * Device and vring operations. > */ > struct virtio_net_device_ops { > @@ -187,4 +209,6 @@ uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id, > uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id, > struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count); > > +int rte_vhost_get_vhost_memory(int vid, struct rte_vhost_memory **mem); > + > #endif /* _VIRTIO_NET_H_ */ > diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c > index 0088f87..eee229a 100644 > --- a/lib/librte_vhost/vhost.c > +++ b/lib/librte_vhost/vhost.c > @@ -340,6 +340,29 @@ struct virtio_net * > return 0; > } > > +int > +rte_vhost_get_vhost_memory(int vid, struct rte_vhost_memory **mem) > +{ > + struct virtio_net *dev; > + struct rte_vhost_memory *m; > + size_t size; > + > + dev = get_device(vid); > + if (!dev) > + return -1; > + > + size = dev->mem->nregions * sizeof(struct rte_vhost_mem_region); > + m = malloc(size); > + if (!m) > + return -1; > + > + m->nregions = dev->mem->nregions; > + memcpy(m->regions, dev->mem->regions, size); > + *mem = m; > + > + return 0; > +} > + Might worth to be documented, as API. Other than that: Reviewed-by: Maxime Coquelin Thanks, Maxime