From patchwork Sun Sep 19 01:00:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 192902 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8J10c3s005529 for ; Sun, 19 Sep 2010 01:00:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754808Ab0ISBAf (ORCPT ); Sat, 18 Sep 2010 21:00:35 -0400 Received: from mga11.intel.com ([192.55.52.93]:23376 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753752Ab0ISBAf (ORCPT ); Sat, 18 Sep 2010 21:00:35 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 18 Sep 2010 18:00:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.56,387,1280732400"; d="scan'208";a="838908667" Received: from yhuang-dev.sh.intel.com (HELO [10.239.13.2]) ([10.239.13.2]) by fmsmga001.fm.intel.com with ESMTP; 18 Sep 2010 18:00:33 -0700 Subject: [PATCH] Add RAM -> physical addr mapping in MCE simulation From: Huang Ying To: Avi Kivity , Marcelo Tosatti Cc: "kvm@vger.kernel.org" , Andi Kleen , Dean Nelson Date: Sun, 19 Sep 2010 09:00:33 +0800 Message-ID: <1284858033.32373.317.camel@yhuang-dev> Mime-Version: 1.0 X-Mailer: Evolution 2.30.2 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sun, 19 Sep 2010 01:00:40 +0000 (UTC) --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -1137,12 +1137,15 @@ static void sigbus_handler(int n, struct if (first_cpu->mcg_cap && siginfo->ssi_addr && siginfo->ssi_code == BUS_MCEERR_AO) { uint64_t status; + void *vaddr; + ram_addr_t ram_addr; unsigned long paddr; CPUState *cenv; /* Hope we are lucky for AO MCE */ - if (do_qemu_ram_addr_from_host((void *)(intptr_t)siginfo->ssi_addr, - &paddr)) { + vaddr = (void *)(intptr_t)siginfo->ssi_addr; + if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) || + !kvm_physical_memory_addr_from_ram(kvm_state, ram_addr, &paddr)) { fprintf(stderr, "Hardware memory error for memory used by " "QEMU itself instead of guest system!: %llx\n", (unsigned long long)siginfo->ssi_addr); @@ -1316,6 +1319,8 @@ static void kvm_on_sigbus(CPUState *env, struct kvm_x86_mce mce = { .bank = 9, }; + void *vaddr; + ram_addr_t ram_addr; unsigned long paddr; int r; @@ -1347,7 +1352,9 @@ static void kvm_on_sigbus(CPUState *env, mce.misc = (MCM_ADDR_PHYS << 6) | 0xc; mce.mcg_status = MCG_STATUS_MCIP | MCG_STATUS_RIPV; } - if (do_qemu_ram_addr_from_host((void *)siginfo->si_addr, &paddr)) { + vaddr = (void *)siginfo->si_addr; + if (do_qemu_ram_addr_from_host(vaddr, &ram_addr) || + !kvm_physical_memory_addr_from_ram(kvm_state, ram_addr, &paddr)) { fprintf(stderr, "Hardware memory error for memory used by " "QEMU itself instaed of guest system!\n"); /* Hope we are lucky for AO MCE */ --- a/kvm-all.c +++ b/kvm-all.c @@ -141,6 +141,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; --- a/kvm.h +++ b/kvm.h @@ -195,4 +195,7 @@ int kvm_set_irqfd(int gsi, int fd, bool #endif int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign); + +int kvm_physical_memory_addr_from_ram(KVMState *s, ram_addr_t ram_addr, + target_phys_addr_t *phys_addr); #endif