From patchwork Tue Jun 22 06:23:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 107344 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5M6NX4Y030138 for ; Tue, 22 Jun 2010 06:23:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754294Ab0FVGXO (ORCPT ); Tue, 22 Jun 2010 02:23:14 -0400 Received: from mga09.intel.com ([134.134.136.24]:20687 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754098Ab0FVGXN (ORCPT ); Tue, 22 Jun 2010 02:23:13 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 21 Jun 2010 23:22:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.53,458,1272870000"; d="scan'208";a="632434083" Received: from yhuang-dev.sh.intel.com (HELO [10.239.13.161]) ([10.239.13.161]) by orsmga001.jf.intel.com with ESMTP; 21 Jun 2010 23:23:09 -0700 Subject: [BUGFIX] kvm, Fix a race condition for usage of is_hwpoison_address From: Huang Ying To: Avi Kivity Cc: Andi Kleen , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" Date: Tue, 22 Jun 2010 14:23:11 +0800 Message-ID: <1277187791.3004.149.camel@yhuang-dev.sh.intel.com> Mime-Version: 1.0 X-Mailer: Evolution 2.28.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.3 (demeter.kernel.org [140.211.167.41]); Tue, 22 Jun 2010 06:23:34 +0000 (UTC) --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1298,6 +1298,9 @@ done: return ret; } +/* + * The caller must hold current->mm->mmap_sem in read mode. + */ int is_hwpoison_address(unsigned long addr) { pgd_t *pgdp; --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -955,12 +955,13 @@ static pfn_t hva_to_pfn(struct kvm *kvm, if (unlikely(npages != 1)) { struct vm_area_struct *vma; + down_read(¤t->mm->mmap_sem); if (is_hwpoison_address(addr)) { + up_read(¤t->mm->mmap_sem); get_page(hwpoison_page); return page_to_pfn(hwpoison_page); } - down_read(¤t->mm->mmap_sem); vma = find_vma(current->mm, addr); if (vma == NULL || addr < vma->vm_start ||