From patchwork Tue Feb 5 08:53:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 2096861 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 9A2263FCA4 for ; Tue, 5 Feb 2013 08:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755639Ab3BEIyD (ORCPT ); Tue, 5 Feb 2013 03:54:03 -0500 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:50687 "EHLO e28smtp02.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755177Ab3BEIyB (ORCPT ); Tue, 5 Feb 2013 03:54:01 -0500 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Feb 2013 14:21:24 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp02.in.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 5 Feb 2013 14:21:22 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id A76C8E004C; Tue, 5 Feb 2013 14:24:38 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r158rrKl7274582; Tue, 5 Feb 2013 14:23:53 +0530 Received: from d28av04.in.ibm.com (loopback [127.0.0.1]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r158rsjx026551; Tue, 5 Feb 2013 19:53:54 +1100 Received: from localhost.localdomain ([9.123.236.141]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r158rq5F026421; Tue, 5 Feb 2013 19:53:53 +1100 Message-ID: <5110C8A0.5050405@linux.vnet.ibm.com> Date: Tue, 05 Feb 2013 16:53:52 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Xiao Guangrong CC: Marcelo Tosatti , Gleb Natapov , LKML , KVM Subject: [PATCH v3 2/5] KVM: MMU: clarify the logic in kvm_set_pte_rmapp References: <5110C853.4080705@linux.vnet.ibm.com> In-Reply-To: <5110C853.4080705@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13020508-5816-0000-0000-0000068D9952 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In kvm_set_pte_rmapp, if the new mapping is writable, we need to remove all spte pointing to that page otherwisewe we only need to adjust the sptes to let them point to the new page. This patch clarifys the logic and makes the later patch more clean [ Impact: no logic changed ] Signed-off-by: Xiao Guangrong --- arch/x86/kvm/mmu.c | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 68d4d5f..a0dc0d7 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1225,16 +1225,16 @@ static int kvm_set_pte_rmapp(struct kvm *kvm, unsigned long *rmapp, WARN_ON(pte_huge(*ptep)); new_pfn = pte_pfn(*ptep); - for (sptep = rmap_get_first(*rmapp, &iter); sptep;) { - BUG_ON(!is_shadow_present_pte(*sptep)); - rmap_printk("kvm_set_pte_rmapp: spte %p %llx\n", sptep, *sptep); + if (pte_write(*ptep)) + need_flush = kvm_unmap_rmapp(kvm, rmapp, slot, data); + else + for (sptep = rmap_get_first(*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; + need_flush = 1; - if (pte_write(*ptep)) { - drop_spte(kvm, sptep); - sptep = rmap_get_first(*rmapp, &iter); - } else { new_spte = *sptep & ~PT64_BASE_ADDR_MASK; new_spte |= (u64)new_pfn << PAGE_SHIFT; @@ -1246,7 +1246,6 @@ static int kvm_set_pte_rmapp(struct kvm *kvm, unsigned long *rmapp, mmu_spte_set(sptep, new_spte); sptep = rmap_get_next(&iter); } - } if (need_flush) kvm_flush_remote_tlbs(kvm);