From patchwork Wed Mar 13 04:57:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 2261371 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 E8E11DF215 for ; Wed, 13 Mar 2013 04:58:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751796Ab3CME5t (ORCPT ); Wed, 13 Mar 2013 00:57:49 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:59347 "EHLO e23smtp09.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751257Ab3CME5s (ORCPT ); Wed, 13 Mar 2013 00:57:48 -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:49:55 +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:49:31 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id D351B2CE804C; Wed, 13 Mar 2013 15:57:21 +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 r2D4ibFR5439864; Wed, 13 Mar 2013 15:44:37 +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 r2D4vLHr024228; Wed, 13 Mar 2013 15:57:21 +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 r2D4vIg8024205; Wed, 13 Mar 2013 15:57:19 +1100 Message-ID: <5140072E.30008@linux.vnet.ibm.com> Date: Wed, 13 Mar 2013 12:57:18 +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 3/6] KVM: x86: introduce memslot_set_lpage_disallowed 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-00000347E263 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org It is used to set disallowed lage page on the specified level, can be used in later patch Signed-off-by: Xiao Guangrong --- arch/x86/kvm/x86.c | 53 ++++++++++++++++++++++++++++++++++----------------- 1 files changed, 35 insertions(+), 18 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7083568..2cf3722 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6847,12 +6847,45 @@ void kvm_arch_free_memslot(struct kvm_memory_slot *free, } } +static void +memslot_set_lpage_disallowed(struct kvm_memory_slot *slot, + unsigned long npages, int lpage_size, + int lpages) +{ + struct kvm_lpage_info *lpage_info; + unsigned long ugfn; + int level = lpage_size + 1; + + WARN_ON(!lpage_size); + + lpage_info = slot->arch.lpage_info[lpage_size - 1]; + + if (slot->base_gfn & (KVM_PAGES_PER_HPAGE(level) - 1)) + lpage_info[0].write_count = 1; + + if ((slot->base_gfn + npages) & (KVM_PAGES_PER_HPAGE(level) - 1)) + lpage_info[lpages - 1].write_count = 1; + + ugfn = slot->userspace_addr >> PAGE_SHIFT; + /* + * If the gfn and userspace address are not aligned wrt each + * other, or if explicitly asked to, disable large page + * support for this slot + */ + if ((slot->base_gfn ^ ugfn) & (KVM_PAGES_PER_HPAGE(level) - 1) || + !kvm_largepages_enabled()) { + unsigned long j; + + for (j = 0; j < lpages; ++j) + lpage_info[j].write_count = 1; + } +} + int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) { int i; for (i = 0; i < KVM_NR_PAGE_SIZES; ++i) { - unsigned long ugfn; int lpages; int level = i + 1; @@ -6871,23 +6904,7 @@ int kvm_arch_create_memslot(struct kvm_memory_slot *slot, unsigned long npages) if (!slot->arch.lpage_info[i - 1]) goto out_free; - if (slot->base_gfn & (KVM_PAGES_PER_HPAGE(level) - 1)) - slot->arch.lpage_info[i - 1][0].write_count = 1; - if ((slot->base_gfn + npages) & (KVM_PAGES_PER_HPAGE(level) - 1)) - slot->arch.lpage_info[i - 1][lpages - 1].write_count = 1; - ugfn = slot->userspace_addr >> PAGE_SHIFT; - /* - * If the gfn and userspace address are not aligned wrt each - * other, or if explicitly asked to, disable large page - * support for this slot - */ - if ((slot->base_gfn ^ ugfn) & (KVM_PAGES_PER_HPAGE(level) - 1) || - !kvm_largepages_enabled()) { - unsigned long j; - - for (j = 0; j < lpages; ++j) - slot->arch.lpage_info[i - 1][j].write_count = 1; - } + memslot_set_lpage_disallowed(slot, npages, i, lpages); } return 0;