From patchwork Tue Oct 19 10:40:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 68321 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C53ABB70D0 for ; Tue, 19 Oct 2010 22:02:40 +1100 (EST) Received: from localhost ([127.0.0.1]:40641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P89xl-0005Sx-I2 for incoming@patchwork.ozlabs.org; Tue, 19 Oct 2010 07:02:37 -0400 Received: from [140.186.70.92] (port=46281 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P89dE-0001uM-6s for qemu-devel@nongnu.org; Tue, 19 Oct 2010 06:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P89dB-00066l-7Q for qemu-devel@nongnu.org; Tue, 19 Oct 2010 06:41:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44153) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P89dB-00066M-0Z for qemu-devel@nongnu.org; Tue, 19 Oct 2010 06:41:21 -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 o9JAfJ49032224 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 19 Oct 2010 06:41:20 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9JAfJfE022453; Tue, 19 Oct 2010 06:41:19 -0400 Received: from amt.cnet (vpn-9-223.rdu.redhat.com [10.11.9.223]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o9JAfI5B001461; Tue, 19 Oct 2010 06:41:18 -0400 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id A28606520A6; Tue, 19 Oct 2010 08:41:01 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id o9JAexaf027483; Tue, 19 Oct 2010 08:40:59 -0200 From: Marcelo Tosatti To: Anthony Liguori Date: Tue, 19 Oct 2010 08:40:34 -0200 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Avi Kivity , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org, Huang Ying Subject: [Qemu-devel] [PATCH 08/10] Add RAM -> physical addr mapping in MCE simulation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Avi Kivity --- kvm-all.c | 18 ++++++++++++++++++ kvm.h | 3 +++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 1cc696f..37b99c7 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -137,6 +137,24 @@ static KVMSlot *kvm_lookup_overlapping_slot(KVMState *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; diff --git a/kvm.h b/kvm.h index 50b6c01..8f5a754 100644 --- a/kvm.h +++ b/kvm.h @@ -174,6 +174,9 @@ static inline void cpu_synchronize_post_init(CPUState *env) } } +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);