From patchwork Mon Apr 1 09:56:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 2370071 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 C9C333FD40 for ; Mon, 1 Apr 2013 09:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759107Ab3DAJ5V (ORCPT ); Mon, 1 Apr 2013 05:57:21 -0400 Received: from e28smtp08.in.ibm.com ([122.248.162.8]:46784 "EHLO e28smtp08.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759097Ab3DAJ5S (ORCPT ); Mon, 1 Apr 2013 05:57:18 -0400 Received: from /spool/local by e28smtp08.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 1 Apr 2013 15:22:10 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp08.in.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 1 Apr 2013 15:22:01 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id 3FDE13940023; Mon, 1 Apr 2013 15:27:06 +0530 (IST) Received: from d28av04.in.ibm.com (d28av04.in.ibm.com [9.184.220.66]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r319v2M064553084; Mon, 1 Apr 2013 15:27:03 +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 r319v21Z010090; Mon, 1 Apr 2013 20:57:04 +1100 Received: from localhost (dhcp-9-111-29-28.cn.ibm.com [9.111.29.28]) by d28av04.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r319v0g8010042; Mon, 1 Apr 2013 20:57:01 +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 6/6] KVM: MMU: init kvm generation close to mmio wrap-around value Date: Mon, 1 Apr 2013 17:56:49 +0800 Message-Id: <1364810209-25954-7-git-send-email-xiaoguangrong@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1364810209-25954-1-git-send-email-xiaoguangrong@linux.vnet.ibm.com> References: <1364810209-25954-1-git-send-email-xiaoguangrong@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13040109-2000-0000-0000-00000B90A924 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Then it has chance to trigger mmio generation number wrap-around Signed-off-by: Xiao Guangrong --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/mmu.c | 8 ++++++++ virt/kvm/kvm_main.c | 6 ++++++ 3 files changed, 15 insertions(+), 0 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 6c1e642..4e1f7cb 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -767,6 +767,7 @@ void kvm_mmu_write_protect_pt_masked(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn_offset, unsigned long mask); void kvm_mmu_zap_all(struct kvm *kvm); +void kvm_arch_init_generation(struct kvm *kvm); void kvm_mmu_invalid_mmio_sptes(struct kvm *kvm); unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm); void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages); diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index d314e21..dcc059c 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -4279,6 +4279,14 @@ restart: spin_unlock(&kvm->mmu_lock); } +void kvm_arch_init_generation(struct kvm *kvm) +{ + mutex_lock(&kvm->slots_lock); + /* It is easier to trigger mmio generation-number wrap-around. */ + kvm_memslots(kvm)->generation = MMIO_MAX_GEN - 13; + mutex_unlock(&kvm->slots_lock); +} + void kvm_mmu_invalid_mmio_sptes(struct kvm *kvm) { /* diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index ff71541..d21694a 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -459,6 +459,10 @@ static void kvm_init_memslots_id(struct kvm *kvm) slots->id_to_index[i] = slots->memslots[i].id = i; } +void __attribute__((weak)) kvm_arch_init_generation(struct kvm *kvm) +{ +} + static struct kvm *kvm_create_vm(unsigned long type) { int r, i; @@ -505,6 +509,8 @@ static struct kvm *kvm_create_vm(unsigned long type) mutex_init(&kvm->slots_lock); atomic_set(&kvm->users_count, 1); + kvm_arch_init_generation(kvm); + r = kvm_init_mmu_notifier(kvm); if (r) goto out_err;