public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: kvm@vger.kernel.org
Cc: penberg@kernel.org, marc.zyngier@arm.com,
	c.dall@virtualopensystems.com, matt@ozlabs.org,
	peter.maydell@linaro.org, michael@ellerman.id.au,
	levinsasha928@gmail.com, kvmarm@lists.cs.columbia.edu,
	Will Deacon <will.deacon@arm.com>
Subject: [PATCH v2 7/8] kvm tools: provide a mechanism for translating host to guest addresses
Date: Thu, 22 Nov 2012 15:58:16 +0000	[thread overview]
Message-ID: <1353599897-15656-8-git-send-email-will.deacon@arm.com> (raw)
In-Reply-To: <1353599897-15656-1-git-send-email-will.deacon@arm.com>

When generating a device tree for a guest, it is useful to have a helper
for converting host addresses to guest addresses in order to populate
the device nodes correctly.

This patch adds such a helper, following a similar implementation to the
reverse translation function that already exists.

Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 tools/kvm/include/kvm/kvm.h |  1 +
 tools/kvm/kvm.c             | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 5fb2fb2..b54ac03 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -106,6 +106,7 @@ bool kvm__arch_cpu_supports_vm(void);
 void kvm__arch_periodic_poll(struct kvm *kvm);
 
 void *guest_flat_to_host(struct kvm *kvm, u64 offset);
+u64 host_to_guest_flat(struct kvm *kvm, void *ptr);
 
 int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline);
 bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline, u16 vidmode);
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index a7e2628..af19e37 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -201,6 +201,22 @@ void *guest_flat_to_host(struct kvm *kvm, u64 offset)
 	return NULL;
 }
 
+u64 host_to_guest_flat(struct kvm *kvm, void *ptr)
+{
+	struct kvm_mem_bank *bank;
+
+	list_for_each_entry(bank, &kvm->mem_banks, list) {
+		void *bank_start = bank->host_addr;
+		void *bank_end = bank_start + bank->size;
+
+		if (ptr >= bank_start && ptr < bank_end)
+			return bank->guest_phys_addr + (ptr - bank_start);
+	}
+
+	pr_warning("unable to translate host address %p to guest", ptr);
+	return 0;
+}
+
 int kvm__recommended_cpus(struct kvm *kvm)
 {
 	int ret;
-- 
1.8.0


  parent reply	other threads:[~2012-11-22 18:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-22 15:58 [PATCH v2 0/8] kvm tools: add support for ARMv7 processors Will Deacon
2012-11-22 15:58 ` [PATCH v2 1/8] rbtree: include linux/compiler.h for definition of __always_inline Will Deacon
2012-11-22 18:44   ` Sasha Levin
2012-11-23 14:36     ` Will Deacon
2012-11-22 15:58 ` [PATCH v2 2/8] kvm tools: don't bother including linux/compiler.h Will Deacon
2012-11-22 15:58 ` [PATCH v2 3/8] kvm tools: balloon: add dummy set_size_vq implementation Will Deacon
2012-11-22 15:58 ` [PATCH v2 4/8] kvm tools: add generic device registration mechanism Will Deacon
2012-11-22 15:58 ` [PATCH v2 5/8] kvm tools: keep track of registered memory banks in struct kvm Will Deacon
2012-11-22 15:58 ` [PATCH v2 6/8] kvm tools: teach guest_flat_to_host about memory banks starting above 0 Will Deacon
2012-11-22 15:58 ` Will Deacon [this message]
2012-11-22 15:58 ` [PATCH v2 8/8] kvm tools: add support for ARMv7 processors Will Deacon
2012-11-22 16:13   ` Peter Maydell
2012-11-22 16:22     ` Will Deacon
2012-11-23 11:22 ` [PATCH v2 0/8] " Pekka Enberg
2012-11-23 14:38   ` 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=1353599897-15656-8-git-send-email-will.deacon@arm.com \
    --to=will.deacon@arm.com \
    --cc=c.dall@virtualopensystems.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=levinsasha928@gmail.com \
    --cc=marc.zyngier@arm.com \
    --cc=matt@ozlabs.org \
    --cc=michael@ellerman.id.au \
    --cc=penberg@kernel.org \
    --cc=peter.maydell@linaro.org \
    /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