From patchwork Wed Jan 23 10:10:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 2023521 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 810C2DF280 for ; Wed, 23 Jan 2013 10:10:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754802Ab3AWKKT (ORCPT ); Wed, 23 Jan 2013 05:10:19 -0500 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:60287 "EHLO e23smtp07.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754595Ab3AWKKR (ORCPT ); Wed, 23 Jan 2013 05:10:17 -0500 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 23 Jan 2013 20:03:51 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 23 Jan 2013 20:03:50 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 7378D357804D; Wed, 23 Jan 2013 21:10:12 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0NAABF859572366; Wed, 23 Jan 2013 21:10:11 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r0NAAAMS001876; Wed, 23 Jan 2013 21:10:12 +1100 Received: from localhost.localdomain ([9.123.236.211]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r0NAA7tC001729; Wed, 23 Jan 2013 21:10:08 +1100 Message-ID: <50FFB6FF.5060607@linux.vnet.ibm.com> Date: Wed, 23 Jan 2013 18:10:07 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Xiao Guangrong CC: Marcelo Tosatti , Avi Kivity , Gleb Natapov , LKML , KVM Subject: [PATCH v2 11/12] KVM: MMU: fix spte assertion References: <50FFB5A1.5090708@linux.vnet.ibm.com> In-Reply-To: <50FFB5A1.5090708@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13012310-0260-0000-0000-00000271660B Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org PT_PRESENT_MASK bit is not enough to see the spte has already been mapped into pte-list for mmio spte also set this bit. Use is_shadow_present_pte instead to fix it Also, this patch move many assertions to the common place to clean up the code Signed-off-by: Xiao Guangrong --- arch/x86/kvm/mmu.c | 20 ++++++-------------- 1 files changed, 6 insertions(+), 14 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index b7da3fb..2c0a786 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1032,7 +1032,9 @@ static u64 *pte_list_get_next(struct pte_list_iterator *iter) #define for_each_spte_in_pte_list(pte_list, iter, spte) \ for (spte = pte_list_get_first(pte_list, &(iter)); \ - spte != NULL; spte = pte_list_get_next(&(iter))) + spte != NULL && \ + ({WARN_ON(!is_shadow_present_pte(*(spte))); 1; });\ + spte = pte_list_get_next(&iter)) #define for_each_spte_in_rmap(rmap, iter, spte) \ for_each_spte_in_pte_list(rmap, iter, spte) @@ -1151,11 +1153,8 @@ static bool __rmap_write_protect(struct kvm *kvm, unsigned long *rmapp, struct pte_list_iterator iter; bool flush = false; - for_each_spte_in_rmap(*rmapp, iter, sptep) { - BUG_ON(!(*sptep & PT_PRESENT_MASK)); - + for_each_spte_in_rmap(*rmapp, iter, sptep) spte_write_protect(kvm, sptep, &flush, pt_protect); - } return flush; } @@ -1236,7 +1235,6 @@ static int kvm_set_pte_rmapp(struct kvm *kvm, unsigned long *rmapp, restart: for_each_spte_in_rmap(*rmapp, iter, sptep) { - BUG_ON(!is_shadow_present_pte(*sptep)); rmap_printk("kvm_set_pte_rmapp: spte %p %llx\n", sptep, *sptep); need_flush = 1; @@ -1361,15 +1359,12 @@ static int kvm_age_rmapp(struct kvm *kvm, unsigned long *rmapp, goto out; } - for_each_spte_in_rmap(*rmapp, iter, sptep) { - BUG_ON(!is_shadow_present_pte(*sptep)); - + for_each_spte_in_rmap(*rmapp, iter, sptep) if (*sptep & shadow_accessed_mask) { young = 1; clear_bit((ffs(shadow_accessed_mask) - 1), (unsigned long *)sptep); } - } out: /* @data has hva passed to kvm_age_hva(). */ trace_kvm_age_page(data, slot, young); @@ -1391,14 +1386,11 @@ static int kvm_test_age_rmapp(struct kvm *kvm, unsigned long *rmapp, if (!shadow_accessed_mask) goto out; - for_each_spte_in_rmap(*rmapp, iter, sptep) { - BUG_ON(!is_shadow_present_pte(*sptep)); - + for_each_spte_in_rmap(*rmapp, iter, sptep) if (*sptep & shadow_accessed_mask) { young = 1; break; } - } out: return young; }