public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
To: Will Deacon <will.deacon@arm.com>
Cc: <kvm@vger.kernel.org>,
	Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
Subject: [PATCH 3/5] kvmtool: Register each guest memory bank as vhost_memory_region
Date: Mon, 15 Jun 2015 13:49:44 +0200	[thread overview]
Message-ID: <1434368986-14963-4-git-send-email-andreas.herrmann@caviumnetworks.com> (raw)
In-Reply-To: <1434368986-14963-1-git-send-email-andreas.herrmann@caviumnetworks.com>

Otherwise vhost does not work if a virtio descriptor is used that was
allocated from a guest memory bank not registered as
vhost_memory_region.

Signed-off-by: Andreas Herrmann <andreas.herrmann@caviumnetworks.com>
---
 virtio/net.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/virtio/net.c b/virtio/net.c
index 122a9e2..9784520 100644
--- a/virtio/net.c
+++ b/virtio/net.c
@@ -639,23 +639,28 @@ static struct virtio_ops net_dev_virtio_ops = (struct virtio_ops) {
 
 static void virtio_net__vhost_init(struct kvm *kvm, struct net_dev *ndev)
 {
+	struct kvm_mem_bank *bank;
 	struct vhost_memory *mem;
-	int r;
+	int r, i;
 
 	ndev->vhost_fd = open("/dev/vhost-net", O_RDWR);
 	if (ndev->vhost_fd < 0)
 		die_perror("Failed openning vhost-net device");
 
-	mem = calloc(1, sizeof(*mem) + sizeof(struct vhost_memory_region));
+	mem = calloc(1, sizeof(*mem) + kvm->mem_slots * sizeof(struct vhost_memory_region));
 	if (mem == NULL)
 		die("Failed allocating memory for vhost memory map");
 
-	mem->nregions = 1;
-	mem->regions[0] = (struct vhost_memory_region) {
-		.guest_phys_addr	= 0,
-		.memory_size		= kvm->ram_size,
-		.userspace_addr		= (unsigned long)kvm->ram_start,
-	};
+	i = 0;
+	list_for_each_entry(bank, &kvm->mem_banks, list) {
+		mem->regions[i] = (struct vhost_memory_region) {
+			.guest_phys_addr = bank->guest_phys_addr,
+			.memory_size	 = bank->size,
+			.userspace_addr	 = (unsigned long)bank->host_addr,
+		};
+		i++;
+	}
+	mem->nregions = i;
 
 	r = ioctl(ndev->vhost_fd, VHOST_SET_OWNER);
 	if (r != 0)
-- 
1.7.9.5


  parent reply	other threads:[~2015-06-15 12:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-15 11:49 [PATCH 0/5] kvmtool: Misc fixes Andreas Herrmann
2015-06-15 11:49 ` [PATCH 1/5] kvmtool: Fix compile error on MIPS Andreas Herrmann
2015-06-15 11:49 ` [PATCH 2/5] kvmtool: Fix regression introduced with d2a7ddff4 Andreas Herrmann
2015-06-15 11:49 ` Andreas Herrmann [this message]
2015-06-15 11:49 ` [PATCH 4/5] kvmtool: Save datamatch as little endian in {add,del}_event Andreas Herrmann
2015-06-16 17:17   ` Will Deacon
2015-06-17  7:17     ` Andreas Herrmann
2015-06-17 10:03       ` Will Deacon
2015-06-15 11:49 ` [PATCH 5/5] kvmtool: Fix length of ioevent for VIRTIO_PCI_QUEUE_NOTIFY Andreas Herrmann
2015-06-16 17:29 ` [PATCH 0/5] kvmtool: Misc fixes Will Deacon

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=1434368986-14963-4-git-send-email-andreas.herrmann@caviumnetworks.com \
    --to=andreas.herrmann@caviumnetworks.com \
    --cc=kvm@vger.kernel.org \
    --cc=will.deacon@arm.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