From: Avi Kivity Subject: [PATCH] kvm: allow tpr patching to write to write-protected vapic option rom Date: Tue, 5 Oct 2010 15:05:13 +0200 Message-ID: <1286283913-17399-1-git-send-email-avi@redhat.com> To: kvm@vger.kernel.org, Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:29673 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751728Ab0JENFQ (ORCPT ); Tue, 5 Oct 2010 09:05:16 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o95D5Fue030160 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 5 Oct 2010 09:05:15 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o95D5EZ6006687 for ; Tue, 5 Oct 2010 09:05:15 -0400 Sender: kvm-owner@vger.kernel.org List-ID: Now that we allow the bios to write protect option roms, we need to allow the tpr patching code to write to this write protected memory. This means using cpu_physical_memory_write_rom() instead of the usual APIs. Fixes Windows XP without flexpriority. Signed-off-by: Avi Kivity --- kvm-tpr-opt.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/kvm-tpr-opt.c b/kvm-tpr-opt.c index 46890e2..c929fc8 100644 --- a/kvm-tpr-opt.c +++ b/kvm-tpr-opt.c @@ -73,7 +73,7 @@ static uint8_t read_byte_virt(CPUState *env, target_ulong virt) static void write_byte_virt(CPUState *env, target_ulong virt, uint8_t b) { - stb_phys(map_addr(env, virt, NULL), b); + cpu_physical_memory_write_rom(map_addr(env, virt, NULL), &b, 1); } struct vapic_bios { @@ -107,7 +107,7 @@ static void update_vbios_real_tpr(void) cpu_physical_memory_rw(vbios_desc_phys, (void *)&vapic_bios, sizeof vapic_bios, 0); vapic_bios.real_tpr = real_tpr; vapic_bios.vcpu_shift = 7; - cpu_physical_memory_rw(vbios_desc_phys, (void *)&vapic_bios, sizeof vapic_bios, 1); + cpu_physical_memory_write_rom(vbios_desc_phys, (void *)&vapic_bios, sizeof vapic_bios); } static unsigned modrm_reg(uint8_t modrm) @@ -174,6 +174,7 @@ static int bios_is_mapped(CPUState *env, uint64_t rip) unsigned perms; uint32_t i; uint32_t offset, fixup, start = vapic_bios_addr ? : 0xe0000; + uint32_t patch; if (bios_enabled) return 1; @@ -198,7 +199,8 @@ static int bios_is_mapped(CPUState *env, uint64_t rip) for (i = vapic_bios.fixup_start; i < vapic_bios.fixup_end; i += 4) { offset = ldl_phys(phys + i - vapic_bios.virt_base); fixup = phys + offset; - stl_phys(fixup, ldl_phys(fixup) + bios_addr - vapic_bios.virt_base); + patch = ldl_phys(fixup) + bios_addr - vapic_bios.virt_base; + cpu_physical_memory_write_rom(fixup, (uint8_t *)&patch, 4); } vapic_phys = vapic_bios.vapic - vapic_bios.virt_base + phys; return 1; @@ -225,7 +227,7 @@ int kvm_tpr_enable_vapic(CPUState *env) return 0; kvm_enable_vapic(env, vapic_phys + (pcr_cpu << 7)); - cpu_physical_memory_rw(vapic_phys + (pcr_cpu << 7) + 4, &one, 1, 1); + cpu_physical_memory_write_rom(vapic_phys + (pcr_cpu << 7) + 4, &one, 1); env->kvm_vcpu_update_vapic = 0; bios_enabled = 1; return 1; -- 1.7.2.3