From mboxrd@z Thu Jan 1 00:00:00 1970 From: Laurent Vivier Subject: [PATCH 5/6] Consolidate the various functions that read and write guest memory Date: Mon, 30 Jul 2007 11:38:04 +0200 Message-ID: <46ADB17C.2060409@bull.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0730774193==" 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) --===============0730774193== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig50110A0B9A1EF3C6A1030F58" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig50110A0B9A1EF3C6A1030F58 Content-Type: multipart/mixed; boundary="------------000803010102040609080804" This is a multi-part message in MIME format. --------------000803010102040609080804 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable remove kvm_write_guest() and use emulator_write_emulated() instead. Signed-off-by: Laurent Vivier --=20 ------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org -------------- "Software is hard" - Donald Knuth --------------000803010102040609080804 Content-Type: text/plain; name="remove-kvm_write" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="remove-kvm_write" 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:50:00.000000000 +0200 +++ kvm/drivers/kvm/kvm.h 2007-07-30 10:50:26.000000000 +0200 @@ -590,11 +590,10 @@ void *val, unsigned int bytes, struct kvm_vcpu *vcpu); - -int kvm_write_guest(struct kvm_vcpu *vcpu, - gva_t addr, - unsigned long size, - void *data); +int emulator_write_emulated(unsigned long addr, + const void *val, + unsigned int bytes, + struct kvm_vcpu *vcpu); =20 unsigned long segment_base(u16 selector); =20 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:50:20.000000000 +0200 +++ kvm/drivers/kvm/kvm_main.c 2007-07-30 10:50:26.000000000 +0200 @@ -144,41 +144,6 @@ return likely(n >=3D 0 && n < KVM_MAX_VCPUS); } =20 -int kvm_write_guest(struct kvm_vcpu *vcpu, gva_t addr, unsigned long siz= e, - void *data) -{ - unsigned char *host_buf =3D data; - unsigned long req_size =3D size; - - while (size) { - hpa_t paddr; - unsigned now; - unsigned offset; - hva_t guest_buf; - gfn_t gfn; - - paddr =3D gva_to_hpa(vcpu, addr); - - if (is_error_hpa(paddr)) - break; - - gfn =3D vcpu->mmu.gva_to_gpa(vcpu, addr) >> PAGE_SHIFT; - mark_page_dirty(vcpu->kvm, gfn); - 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((void*)guest_buf, host_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_write_guest); - void kvm_load_guest_fpu(struct kvm_vcpu *vcpu) { if (!vcpu->fpu_active || vcpu->guest_fpu_loaded) @@ -1092,7 +1057,7 @@ return X86EMUL_CONTINUE; } =20 -static int emulator_write_emulated(unsigned long addr, +int emulator_write_emulated(unsigned long addr, const void *val, unsigned int bytes, struct kvm_vcpu *vcpu) @@ -1111,6 +1076,7 @@ } return emulator_write_emulated_onepage(addr, val, bytes, vcpu); } +EXPORT_SYMBOL_GPL(emulator_write_emulated); =20 static int emulator_cmpxchg_emulated(unsigned long addr, const void *old, 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:50:00.000000000 +0200 +++ kvm/drivers/kvm/vmx.c 2007-07-30 10:50:26.000000000 +0200 @@ -1463,9 +1463,9 @@ ip =3D vmcs_readl(GUEST_RIP); =20 =20 - if (kvm_write_guest(vcpu, ss_base + sp - 2, 2, &flags) !=3D 2 || - kvm_write_guest(vcpu, ss_base + sp - 4, 2, &cs) !=3D 2 || - kvm_write_guest(vcpu, ss_base + sp - 6, 2, &ip) !=3D 2) { + if (emulator_write_emulated(ss_base + sp - 2, &flags, 2, vcpu) !=3D X86= EMUL_CONTINUE || + emulator_write_emulated(ss_base + sp - 4, &cs, 2, vcpu) !=3D X86EMU= L_CONTINUE || + emulator_write_emulated(ss_base + sp - 6, &ip, 2, vcpu) !=3D X86EMU= L_CONTINUE) { vcpu_printf(vcpu, "%s: write guest err\n", __FUNCTION__); return; } --------------000803010102040609080804-- --------------enig50110A0B9A1EF3C6A1030F58 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) iD8DBQFGrbF89Kffa9pFVzwRAnMaAJ94PXQnmuaQM6TlBLvcx/rRJ5TukgCeIoow PJui+J3u2dWFPIDy4GViacQ= =M9Ro -----END PGP SIGNATURE----- --------------enig50110A0B9A1EF3C6A1030F58-- --===============0730774193== 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/ --===============0730774193== 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 --===============0730774193==--