From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=54059 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P2qGe-0005v9-NI for qemu-devel@nongnu.org; Mon, 04 Oct 2010 15:00:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P2qGc-00087Q-6K for qemu-devel@nongnu.org; Mon, 04 Oct 2010 15:00:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49029) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P2qGb-000870-UW for qemu-devel@nongnu.org; Mon, 04 Oct 2010 15:00:06 -0400 Message-Id: <20101004185715.106392604@redhat.com> Date: Mon, 04 Oct 2010 15:54:53 -0300 From: Marcelo Tosatti References: <20101004185447.891324545@redhat.com> Content-Disposition: inline; filename=kvm_physical_memory_addr_from_ram Subject: [Qemu-devel] [patch uq/master 6/8] Add RAM -> physical addr mapping in MCE simulation List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: Dean Nelson , Marcelo Tosatti , Huang Ying From: Huang Ying In QEMU-KVM, physical address != RAM address. While MCE simulation needs physical address instead of RAM address. So kvm_physical_memory_addr_from_ram() is implemented to do the conversion, and it is invoked before being filled in the IA32_MCi_ADDR MSR. Reported-by: Dean Nelson Signed-off-by: Huang Ying Signed-off-by: Marcelo Tosatti Index: qemu/kvm-all.c =================================================================== --- qemu.orig/kvm-all.c +++ qemu/kvm-all.c @@ -137,6 +137,24 @@ static KVMSlot *kvm_lookup_overlapping_s return found; } +int kvm_physical_memory_addr_from_ram(KVMState *s, ram_addr_t ram_addr, + target_phys_addr_t *phys_addr) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(s->slots); i++) { + KVMSlot *mem = &s->slots[i]; + + if (ram_addr >= mem->phys_offset && + ram_addr < mem->phys_offset + mem->memory_size) { + *phys_addr = mem->start_addr + (ram_addr - mem->phys_offset); + return 1; + } + } + + return 0; +} + static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot) { struct kvm_userspace_memory_region mem; Index: qemu/kvm.h =================================================================== --- qemu.orig/kvm.h +++ qemu/kvm.h @@ -174,6 +174,9 @@ static inline void cpu_synchronize_post_ } } +int kvm_physical_memory_addr_from_ram(KVMState *s, ram_addr_t ram_addr, + target_phys_addr_t *phys_addr); + #endif int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign);