From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wanpeng Li Subject: [PATCH 2/2] kvm: mmu: don't do overflow memslot check Date: Tue, 14 Apr 2015 13:51:30 +0800 Message-ID: <1428990690-20119-2-git-send-email-wanpeng.li@linux.intel.com> References: <1428990690-20119-1-git-send-email-wanpeng.li@linux.intel.com> Cc: Andres Lagar-Cavilla , Xiao Guangrong , Eric Northup , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Wanpeng Li To: Paolo Bonzini Return-path: Received: from mga09.intel.com ([134.134.136.24]:4855 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752106AbbDNGJy (ORCPT ); Tue, 14 Apr 2015 02:09:54 -0400 In-Reply-To: <1428990690-20119-1-git-send-email-wanpeng.li@linux.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: As Andre pointed out: | I don't understand the value of this check here. Are we looking for a | broken memslot? Shouldn't this be a BUG_ON? Is this the place to care | about these things? npages is capped to KVM_MEM_MAX_NR_PAGES, i.e. | 2^31. A 64 bit overflow would be caused by a gigantic gfn_start which | would be trouble in many other ways. This patch drops the memslot overflow check to make the codes more simple. Signed-off-by: Wanpeng Li --- arch/x86/kvm/mmu.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 2a0d77e..9265fda 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -4505,19 +4505,12 @@ void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm, bool flush = false; unsigned long *rmapp; unsigned long last_index, index; - gfn_t gfn_start, gfn_end; spin_lock(&kvm->mmu_lock); - gfn_start = memslot->base_gfn; - gfn_end = memslot->base_gfn + memslot->npages - 1; - - if (gfn_start >= gfn_end) - goto out; - rmapp = memslot->arch.rmap[0]; - last_index = gfn_to_index(gfn_end, memslot->base_gfn, - PT_PAGE_TABLE_LEVEL); + last_index = gfn_to_index(memslot->base_gfn + memslot->npages - 1, + memslot->base_gfn, PT_PAGE_TABLE_LEVEL); for (index = 0; index <= last_index; ++index, ++rmapp) { if (*rmapp) @@ -4535,7 +4528,6 @@ void kvm_mmu_zap_collapsible_sptes(struct kvm *kvm, if (flush) kvm_flush_remote_tlbs(kvm); -out: spin_unlock(&kvm->mmu_lock); } -- 1.9.1