From patchwork Tue Apr 16 06:32:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 2447821 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 54C463FD8C for ; Tue, 16 Apr 2013 06:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754803Ab3DPGfQ (ORCPT ); Tue, 16 Apr 2013 02:35:16 -0400 Received: from e28smtp06.in.ibm.com ([122.248.162.6]:41834 "EHLO e28smtp06.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754787Ab3DPGfP (ORCPT ); Tue, 16 Apr 2013 02:35:15 -0400 Received: from /spool/local by e28smtp06.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 16 Apr 2013 12:00:15 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp06.in.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 16 Apr 2013 12:00:14 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 4AF3B3940053; Tue, 16 Apr 2013 12:05:10 +0530 (IST) Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r3G6Z6J810617206; Tue, 16 Apr 2013 12:05:06 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r3G6Z8Hl008006; Tue, 16 Apr 2013 16:35:09 +1000 Received: from localhost (dhcp-9-111-29-110.cn.ibm.com [9.111.29.110]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r3G6Z7bg007951; Tue, 16 Apr 2013 16:35:07 +1000 From: Xiao Guangrong To: mtosatti@redhat.com Cc: gleb@redhat.com, avi.kivity@gmail.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Xiao Guangrong Subject: [PATCH v3 10/15] KVM: x86: introduce memslot_set_lpage_disallowed Date: Tue, 16 Apr 2013 14:32:48 +0800 Message-Id: <1366093973-2617-11-git-send-email-xiaoguangrong@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1366093973-2617-1-git-send-email-xiaoguangrong@linux.vnet.ibm.com> References: <1366093973-2617-1-git-send-email-xiaoguangrong@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13041606-9574-0000-0000-0000077A8B77 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 bec83cd..0c5bb2c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6875,13 +6875,46 @@ 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; + } +} + static int kvm_arch_create_memslot(struct kvm_memory_slot *slot) { unsigned long npages = slot->npages; int i; for (i = 0; i < KVM_NR_PAGE_SIZES; ++i) { - unsigned long ugfn; int lpages; int level = i + 1; @@ -6900,23 +6933,7 @@ static int kvm_arch_create_memslot(struct kvm_memory_slot *slot) 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); } init_memslot_rmap_ops(slot);