mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@us.ibm.com>
To: kvm-devel@lists.sourceforge.net
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Avi Kivity <avi@qumranet.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] Implement emulator_write_phys()
Date: Mon, 27 Aug 2007 10:16:44 -0500	[thread overview]
Message-ID: <1188227808405-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <11882278064002-git-send-email-aliguori@us.ibm.com>

Since a hypercall may span two pages and is a gva, we need a function to write
to a gva that may span multiple pages.  emulator_write_phys() seems like the
logical choice for this.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index d154487..ebcc5c9 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -962,8 +962,35 @@ static int emulator_write_std(unsigned long addr,
 			      unsigned int bytes,
 			      struct kvm_vcpu *vcpu)
 {
-	pr_unimpl(vcpu, "emulator_write_std: addr %lx n %d\n", addr, bytes);
-	return X86EMUL_UNHANDLEABLE;
+	const void *data = val;
+
+	while (bytes) {
+		gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, addr);
+		unsigned offset = addr & (PAGE_SIZE-1);
+		unsigned tocopy = min(bytes, (unsigned)PAGE_SIZE - offset);
+		unsigned long pfn;
+		struct page *page;
+		void *page_virt;
+
+		if (gpa == UNMAPPED_GVA)
+			return X86EMUL_PROPAGATE_FAULT;
+		pfn = gpa >> PAGE_SHIFT;
+		page = gfn_to_page(vcpu->kvm, pfn);
+		if (!page)
+			return X86EMUL_UNHANDLEABLE;
+		page_virt = kmap_atomic(page, KM_USER0);
+
+		memcpy(page_virt + offset, data, tocopy);
+
+		kunmap_atomic(page_virt, KM_USER0);
+		mark_page_dirty(vcpu->kvm, addr >> PAGE_SHIFT);
+
+		bytes -= tocopy;
+		data += tocopy;
+		addr += tocopy;
+	}
+
+	return X86EMUL_CONTINUE;
 }
 
 static struct kvm_io_device *vcpu_find_mmio_dev(struct kvm_vcpu *vcpu,

  reply	other threads:[~2007-08-27 15:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-27 15:16 [PATCH 0/3] KVM paravirtualization framework Anthony Liguori
2007-08-27 15:16 ` Anthony Liguori [this message]
2007-08-27 15:16   ` [PATCH 2/3] Refactor hypercall infrastructure Anthony Liguori
2007-08-27 15:16     ` [PATCH 3/3] KVM paravirt-ops implementation Anthony Liguori
2007-08-28 18:31       ` Rusty Russell
2007-08-29  5:53         ` [kvm-devel] " Anthony Liguori
2007-08-27 16:06     ` [PATCH 2/3] Refactor hypercall infrastructure Avi Kivity
2007-08-27 17:29       ` Anthony Liguori
2007-08-28 18:12     ` Rusty Russell
2007-08-29  5:51       ` [kvm-devel] " Anthony Liguori
2007-08-27 15:45   ` [PATCH 1/3] Implement emulator_write_phys() Avi Kivity
2007-08-27 17:23     ` Anthony Liguori
2007-08-27 17:26       ` Avi Kivity
2007-08-27 17:39         ` Anthony Liguori
2007-08-27 17:47           ` Avi Kivity
2007-08-27 18:09     ` Anthony Liguori

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=1188227808405-git-send-email-aliguori@us.ibm.com \
    --to=aliguori@us.ibm.com \
    --cc=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®