From patchwork Mon Apr 18 18:32:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takuya Yoshikawa X-Patchwork-Id: 716151 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3IIWVeg026818 for ; Mon, 18 Apr 2011 18:32:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753005Ab1DRSc2 (ORCPT ); Mon, 18 Apr 2011 14:32:28 -0400 Received: from mail-pz0-f46.google.com ([209.85.210.46]:49273 "EHLO mail-pz0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752523Ab1DRSc1 (ORCPT ); Mon, 18 Apr 2011 14:32:27 -0400 Received: by pzk9 with SMTP id 9so2194987pzk.19 for ; Mon, 18 Apr 2011 11:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:x-mailer :mime-version:content-type:content-transfer-encoding; bh=KESVV4iZUya0/o2opsCUR8e9p3zL6Qr/MKKRAOaW9sU=; b=gq8Q8T/lh18IkG8ZKJJ3mfY1F4Tww/0i+j8Q24MMmxIse5MBR4gql26rjrEHiL/X61 5GWMdolf3hVLSi/djswLDvVc1PkQnd0dmKNhi77dNzNtFGQEDk25fog5ETchHVsZBZQC I+v4G57zPe9/6Ugbjf7enchkYwYNw0PhbnPFI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; b=W2jTK87fDUvhOrBWQ7m3aNgxp04Pl6/i5FKQSqDZdMOFSPuBZD6UQ7/4L3iymdXK37 Cb+TMWiPo8gCKPm0Pxg1cr24XO7ti0J53unK2eRBopYnOWbt3ry8T68SaOyJtr57KkPf zBPqxSSZ3EfBod1Ra5eFcQco+FgtBz+qX9DjE= Received: by 10.68.27.4 with SMTP id p4mr7819609pbg.171.1303151547313; Mon, 18 Apr 2011 11:32:27 -0700 (PDT) Received: from amd (s198099.dynamic.ppp.asahi-net.or.jp [220.157.198.99]) by mx.google.com with ESMTPS id g2sm2449021pbm.61.2011.04.18.11.32.22 (version=SSLv3 cipher=OTHER); Mon, 18 Apr 2011 11:32:24 -0700 (PDT) Date: Tue, 19 Apr 2011 03:32:20 +0900 From: Takuya Yoshikawa To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp Subject: [PATCH 1/3] KVM: Introduce a helper to check if gfn is in memslot Message-Id: <20110419033220.e527bcae.takuya.yoshikawa@gmail.com> X-Mailer: Sylpheed 3.1.0beta2 (GTK+ 2.22.0; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 18 Apr 2011 18:32:31 +0000 (UTC) From: Takuya Yoshikawa This will be used later. Signed-off-by: Takuya Yoshikawa --- include/linux/kvm_host.h | 5 +++++ virt/kvm/kvm_main.c | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 0bc3d37..9101698 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -612,6 +612,11 @@ static inline unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot, return slot->userspace_addr + (gfn - slot->base_gfn) * PAGE_SIZE; } +static inline bool gfn_in_memslot(struct kvm_memory_slot *slot, gfn_t gfn) +{ + return (gfn >= slot->base_gfn) && (gfn < slot->base_gfn + slot->npages); +} + static inline gpa_t gfn_to_gpa(gfn_t gfn) { return (gpa_t)gfn << PAGE_SHIFT; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 5814645..6df199d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -940,8 +940,7 @@ static struct kvm_memory_slot *__gfn_to_memslot(struct kvm_memslots *slots, for (i = 0; i < slots->nmemslots; ++i) { struct kvm_memory_slot *memslot = &slots->memslots[i]; - if (gfn >= memslot->base_gfn - && gfn < memslot->base_gfn + memslot->npages) + if (gfn_in_memslot(memslot, gfn)) return memslot; } return NULL; @@ -964,8 +963,7 @@ int kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn) if (memslot->flags & KVM_MEMSLOT_INVALID) continue; - if (gfn >= memslot->base_gfn - && gfn < memslot->base_gfn + memslot->npages) + if (gfn_in_memslot(memslot, gfn)) return 1; } return 0;