From mboxrd@z Thu Jan 1 00:00:00 1970 From: Laurent Vivier Subject: [PATCH 3/6] Consolidate the various functions that read and write guest memory Date: Mon, 30 Jul 2007 11:37:51 +0200 Message-ID: <46ADB16F.6080506@bull.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0757335230==" To: kvm-devel Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --===============0757335230== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig2DA26F281E34EB2445D2741C" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig2DA26F281E34EB2445D2741C Content-Type: multipart/mixed; boundary="------------070308030606020807020707" This is a multi-part message in MIME format. --------------070308030606020807020707 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable remove kvm_read_guest() and use emulator_read_std() instead. Signed-off-by: Laurent Vivier --=20 ------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org -------------- "Software is hard" - Donald Knuth --------------070308030606020807020707 Content-Type: text/plain; name="remove-kvm_read_guest" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="remove-kvm_read_guest" Index: kvm/drivers/kvm/kvm.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- kvm.orig/drivers/kvm/kvm.h 2007-07-30 10:11:56.000000000 +0200 +++ kvm/drivers/kvm/kvm.h 2007-07-30 10:12:45.000000000 +0200 @@ -586,10 +586,10 @@ void kvm_put_guest_fpu(struct kvm_vcpu *vcpu); void kvm_flush_remote_tlbs(struct kvm *kvm); =20 -int kvm_read_guest(struct kvm_vcpu *vcpu, - gva_t addr, - unsigned long size, - void *dest); +int emulator_read_std(unsigned long addr, + void *val, + unsigned int bytes, + struct kvm_vcpu *vcpu); =20 int kvm_write_guest(struct kvm_vcpu *vcpu, gva_t addr, Index: kvm/drivers/kvm/kvm_main.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- kvm.orig/drivers/kvm/kvm_main.c 2007-07-30 10:11:56.000000000 +0200 +++ kvm/drivers/kvm/kvm_main.c 2007-07-30 10:12:45.000000000 +0200 @@ -144,39 +144,6 @@ return likely(n >=3D 0 && n < KVM_MAX_VCPUS); } =20 -int kvm_read_guest(struct kvm_vcpu *vcpu, gva_t addr, unsigned long size= , - void *dest) -{ - unsigned char *host_buf =3D dest; - unsigned long req_size =3D size; - - while (size) { - hpa_t paddr; - unsigned now; - unsigned offset; - hva_t guest_buf; - - paddr =3D gva_to_hpa(vcpu, addr); - - if (is_error_hpa(paddr)) - break; - - guest_buf =3D (hva_t)kmap_atomic( - pfn_to_page(paddr >> PAGE_SHIFT), - KM_USER0); - offset =3D addr & ~PAGE_MASK; - guest_buf |=3D offset; - now =3D min(size, PAGE_SIZE - offset); - memcpy(host_buf, (void*)guest_buf, now); - host_buf +=3D now; - addr +=3D now; - size -=3D now; - kunmap_atomic((void *)(guest_buf & PAGE_MASK), KM_USER0); - } - return req_size - size; -} -EXPORT_SYMBOL_GPL(kvm_read_guest); - int kvm_write_guest(struct kvm_vcpu *vcpu, gva_t addr, unsigned long siz= e, void *data) { @@ -972,7 +939,7 @@ } } =20 -static int emulator_read_std(unsigned long addr, +int emulator_read_std(unsigned long addr, void *val, unsigned int bytes, struct kvm_vcpu *vcpu) @@ -1006,6 +973,7 @@ =20 return X86EMUL_CONTINUE; } +EXPORT_SYMBOL_GPL(emulator_read_std); =20 static int emulator_write_std(unsigned long addr, const void *val, Index: kvm/drivers/kvm/svm.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- kvm.orig/drivers/kvm/svm.c 2007-07-30 10:11:56.000000000 +0200 +++ kvm/drivers/kvm/svm.c 2007-07-30 10:12:45.000000000 +0200 @@ -986,7 +986,7 @@ vcpu->svm->vmcb->control.exit_info_2, ins_length); =20 - if (kvm_read_guest(vcpu, rip, ins_length, inst) !=3D ins_length) + if (emulator_read_std(rip, inst, ins_length, vcpu) !=3D X86EMUL_CONTINU= E) /* #PF */ return 0; =20 Index: kvm/drivers/kvm/vmx.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- kvm.orig/drivers/kvm/vmx.c 2007-07-30 10:11:56.000000000 +0200 +++ kvm/drivers/kvm/vmx.c 2007-07-30 10:12:45.000000000 +0200 @@ -16,6 +16,7 @@ */ =20 #include "kvm.h" +#include "x86_emulate.h" #include "vmx.h" #include "segment_descriptor.h" =20 @@ -1451,8 +1452,8 @@ return; } =20 - if (kvm_read_guest(vcpu, irq * sizeof(ent), sizeof(ent), &ent) !=3D - sizeof(ent)) { + if (emulator_read_std(irq * sizeof(ent), &ent, sizeof(ent), vcpu) !=3D + X86EMUL_CONTINUE) { vcpu_printf(vcpu, "%s: read guest err\n", __FUNCTION__); return; } @@ -1665,7 +1666,7 @@ u64 inst; gva_t rip; int countr_size; - int i, n; + int i; =20 if ((vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_VM)) { countr_size =3D 2; @@ -1680,9 +1681,11 @@ if (countr_size !=3D 8) rip +=3D vmcs_readl(GUEST_CS_BASE); =20 - n =3D kvm_read_guest(vcpu, rip, sizeof(inst), &inst); + if (emulator_read_std(rip, &inst, sizeof(inst), vcpu) !=3D + X86EMUL_CONTINUE) + return 0; =20 - for (i =3D 0; i < n; i++) { + for (i =3D 0; i < sizeof(inst); i++) { switch (((u8*)&inst)[i]) { case 0xf0: case 0xf2: --------------070308030606020807020707-- --------------enig2DA26F281E34EB2445D2741C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.7 (GNU/Linux) iD8DBQFGrbFv9Kffa9pFVzwRAuYFAJoDuQv9KF1BAcsjd/rj7rmHHAJ5GgCeN+mE +/PoCCrTOJtizFwbY2jUZXo= =BhTW -----END PGP SIGNATURE----- --------------enig2DA26F281E34EB2445D2741C-- --===============0757335230== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ --===============0757335230== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --===============0757335230==--