Without this patch, host_memory_map() can only handle a region that
exists on head of a guest physical memory. The patch fixes the
host_memory_map() to handle regions exist on middle of the physical memory.

Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp>
---
 lib/librte_vhost/virtio-net.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 8015dd8..9155a68 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -83,6 +83,7 @@ const uint32_t BUFSIZE = PATH_MAX;
 /* Structure containing information gathered from maps file. */
 struct procmap {
        uint64_t        va_start;       /* Start virtual address in file. */
+       uint64_t        va_end;         /* End virtual address in file. */
        uint64_t        len;            /* Size of file. */
        uint64_t        pgoff;          /* Not used. */
        uint32_t        maj;            /* Not used. */
@@ -176,7 +177,7 @@ host_memory_map(struct virtio_net *dev, struct 
virtio_memory *mem,
                        return -1;
                }

-               procmap.len = strtoull(in[1], &end, 16);
+               procmap.va_end = strtoull(in[1], &end, 16);
                if ((in[1] == '\0') || (end == NULL) || (*end != '\0') || 
(errno != 0)) {
                        fclose(fmap);
                        return -1;
@@ -209,8 +210,8 @@ host_memory_map(struct virtio_net *dev, struct 
virtio_memory *mem,
                memcpy(&procmap.prot, in[2], PROT_SZ);
                memcpy(&procmap.fname, in[7], PATH_MAX);

-               if (procmap.va_start == addr) {
-                       procmap.len = procmap.len - procmap.va_start;
+               if ((procmap.va_start <= addr) && (procmap.va_end >= addr)) {
+                       procmap.len = procmap.va_end - procmap.va_start;
                        found = 1;
                        break;
                }
-- 
1.9.1

Reply via email to