From patchwork Thu Jan 13 08:34:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 475381 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 p0D8Yq8E012454 for ; Thu, 13 Jan 2011 08:34:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755954Ab1AMIet (ORCPT ); Thu, 13 Jan 2011 03:34:49 -0500 Received: from mga11.intel.com ([192.55.52.93]:40610 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755193Ab1AMIes (ORCPT ); Thu, 13 Jan 2011 03:34:48 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 13 Jan 2011 00:34:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.60,317,1291622400"; d="scan'208";a="877125913" Received: from yhuang-dev.sh.intel.com (HELO [10.239.13.101]) ([10.239.13.101]) by fmsmga001.fm.intel.com with ESMTP; 13 Jan 2011 00:34:47 -0800 Subject: [PATCH uq/master 2/2] MCE, unpoison memory address across reboot From: Huang Ying To: Avi Kivity , Marcelo Tosatti , Anthony Liguori Cc: "qemu-devel@nongnu.org" , "kvm@vger.kernel.org" , Dean Nelson , Andi Kleen Date: Thu, 13 Jan 2011 16:34:45 +0800 Message-ID: <1294907685.4596.44.camel@yhuang-dev> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 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.6 (demeter1.kernel.org [140.211.167.41]); Thu, 13 Jan 2011 08:35:22 +0000 (UTC) --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -580,6 +580,42 @@ static int kvm_get_supported_msrs(void) return ret; } +struct HWPoisonPage; +typedef struct HWPoisonPage HWPoisonPage; +struct HWPoisonPage +{ + ram_addr_t ram_addr; + QLIST_ENTRY(HWPoisonPage) list; +}; + +static QLIST_HEAD(hwpoison_page_list, HWPoisonPage) hwpoison_page_list = + QLIST_HEAD_INITIALIZER(hwpoison_page_list); + +void kvm_unpoison_all(void *param) +{ + HWPoisonPage *page, *next_page; + + QLIST_FOREACH_SAFE(page, &hwpoison_page_list, list, next_page) { + QLIST_REMOVE(page, list); + qemu_ram_remap(page->ram_addr, TARGET_PAGE_SIZE); + qemu_free(page); + } +} + +static void kvm_hwpoison_page_add(ram_addr_t ram_addr) +{ + HWPoisonPage *page; + + QLIST_FOREACH(page, &hwpoison_page_list, list) { + if (page->ram_addr == ram_addr) + return; + } + + page = qemu_malloc(sizeof(HWPoisonPage)); + page->ram_addr = ram_addr; + QLIST_INSERT_HEAD(&hwpoison_page_list, page, list); +} + int kvm_arch_init(void) { uint64_t identity_base = 0xfffbc000; @@ -632,6 +668,7 @@ int kvm_arch_init(void) fprintf(stderr, "e820_add_entry() table is full\n"); return ret; } + qemu_register_reset(kvm_unpoison_all, NULL); return 0; } @@ -1940,6 +1977,7 @@ int kvm_on_sigbus_vcpu(CPUState *env, in hardware_memory_error(); } } + kvm_hwpoison_page_add(ram_addr); if (code == BUS_MCEERR_AR) { /* Fake an Intel architectural Data Load SRAR UCR */ @@ -1984,6 +2022,7 @@ int kvm_on_sigbus(int code, void *addr) "QEMU itself instead of guest system!: %p\n", addr); return 0; } + kvm_hwpoison_page_add(ram_addr); kvm_mce_inj_srao_memscrub2(first_cpu, paddr); } else #endif --- a/kvm.h +++ b/kvm.h @@ -188,6 +188,8 @@ int kvm_physical_memory_addr_from_ram(ra target_phys_addr_t *phys_addr); #endif +void kvm_unpoison_all(void *param); + #endif int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign);