From patchwork Wed Mar 13 04:57:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 2261391 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 15354DFE86 for ; Wed, 13 Mar 2013 04:58:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932603Ab3CME6E (ORCPT ); Wed, 13 Mar 2013 00:58:04 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:59382 "EHLO e23smtp09.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932513Ab3CME6B (ORCPT ); Wed, 13 Mar 2013 00:58:01 -0400 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 13 Mar 2013 14:50:09 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 13 Mar 2013 14:50:07 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 3F7782CE8059; Wed, 13 Mar 2013 15:57:57 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2D4jC6n65536118; Wed, 13 Mar 2013 15:45:12 +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 r2D4vudi025031; Wed, 13 Mar 2013 15:57:56 +1100 Received: from localhost.localdomain ([9.123.236.246]) by d23av04.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2D4vrvY024966; Wed, 13 Mar 2013 15:57:54 +1100 Message-ID: <51400751.3070006@linux.vnet.ibm.com> Date: Wed, 13 Mar 2013 12:57:53 +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 4/6] KVM: x86: introduce kvm_clear_all_gfn_page_info References: <514006AC.2020904@linux.vnet.ibm.com> In-Reply-To: <514006AC.2020904@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031304-3568-0000-0000-00000347E292 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 2cf3722..3cb7685 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6881,6 +6881,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 9fa13eb..449126f 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -490,6 +490,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,