From patchwork Wed Mar 20 08:30:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 2305771 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 786CD40213 for ; Wed, 20 Mar 2013 08:32:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934393Ab3CTIbA (ORCPT ); Wed, 20 Mar 2013 04:31:00 -0400 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:49589 "EHLO e28smtp04.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934385Ab3CTIa5 (ORCPT ); Wed, 20 Mar 2013 04:30:57 -0400 Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Mar 2013 13:57:35 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp04.in.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 20 Mar 2013 13:57:32 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 05A4A3940064; Wed, 20 Mar 2013 14:00:51 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2K8UlWa6291486; Wed, 20 Mar 2013 14:00:47 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2K8UlNu030027; Wed, 20 Mar 2013 19:30:48 +1100 Received: from localhost ([9.125.26.89]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2K8UioO029703; Wed, 20 Mar 2013 19:30:45 +1100 From: Xiao Guangrong To: mtosatti@redhat.com Cc: gleb@redhat.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiao Guangrong Subject: [PATCH v2 3/7] KVM: x86: introduce kvm_clear_all_gfn_page_info Date: Wed, 20 Mar 2013 16:30:23 +0800 Message-Id: <1363768227-4782-4-git-send-email-xiaoguangrong@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1363768227-4782-1-git-send-email-xiaoguangrong@linux.vnet.ibm.com> References: <1363768227-4782-1-git-send-email-xiaoguangrong@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13032008-5564-0000-0000-00000725859F Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This function is used to reset the rmaps and page info of all guest page which will be used in later patch Signed-off-by: Xiao Guangrong --- arch/x86/kvm/x86.c | 31 +++++++++++++++++++++++++++++++ include/linux/kvm_host.h | 1 + 2 files changed, 32 insertions(+), 0 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e0a7f67..87d27a8 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6902,6 +6902,37 @@ memslot_set_lpage_disallowed(struct kvm_memory_slot *slot, } } +static void clear_memslot_page_info(struct kvm_memory_slot *slot) +{ + int i; + + for (i = 0; i < KVM_NR_PAGE_SIZES; ++i) { + int lpages; + int level = i + 1; + + lpages = gfn_to_index(slot->base_gfn + slot->npages - 1, + slot->base_gfn, level) + 1; + + memset(slot->arch.rmap[i], 0, + lpages * sizeof(*slot->arch.rmap[i])); + + if (i) { + memset(slot->arch.lpage_info[i - 1], 0, + sizeof(*slot->arch.lpage_info[i - 1])); + memslot_set_lpage_disallowed(slot, slot->npages, i, + lpages); + } + } +} + +void kvm_clear_all_gfn_page_info(struct kvm *kvm) +{ + struct kvm_memory_slot *slot; + + kvm_for_each_memslot(slot, kvm->memslots) + clear_memslot_page_info(slot); +} + int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) { int i; diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 0f4941a..1de9b79 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -491,6 +491,7 @@ int __kvm_set_memory_region(struct kvm *kvm, struct kvm_userspace_memory_region *mem); void kvm_arch_free_memslot(struct kvm_memory_slot *free, struct kvm_memory_slot *dont); +void kvm_clear_all_gfn_page_info(struct kvm *kvm); int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages); int kvm_arch_prepare_memory_region(struct kvm *kvm, struct kvm_memory_slot *memslot,