From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Williamson Subject: [RFC PATCH 1/2] kvm: Allow querying free slots Date: Fri, 21 Jan 2011 16:48:25 -0700 Message-ID: <20110121234809.22262.3194.stgit@s20.home> References: <20110121233040.22262.68117.stgit@s20.home> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: alex.williamson@redhat.com, ddutile@redhat.com, mst@redhat.com, avi@redhat.com, chrisw@redhat.com, jan.kiszka@siemens.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:27059 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754462Ab1AUXs3 (ORCPT ); Fri, 21 Jan 2011 18:48:29 -0500 In-Reply-To: <20110121233040.22262.68117.stgit@s20.home> Sender: kvm-owner@vger.kernel.org List-ID: KVM memory slots are used any place we want a guest to have direct access to a chunk of memory. Unfortunately, there's only a small, fixed number of them, and accidentally going over the limit causes an abort. Add a trivial interface so that callers can at least guess if they have a chance to successfully map memory. Signed-off-by: Alex Williamson --- kvm-all.c | 16 ++++++++++++++++ kvm.h | 2 ++ 2 files changed, 18 insertions(+), 0 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 2f203dd..4fe3631 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -96,6 +96,22 @@ static KVMSlot *kvm_alloc_slot(KVMState *s) abort(); } +int kvm_free_slots(void) +{ + KVMState *s = kvm_state; + int i, j; + + for (i = 0, j = 0; i < ARRAY_SIZE(s->slots); i++) { + /* KVM private memory slots and used slots */ + if ((i >= 8 && i < 12) || s->slots[i].memory_size) { + continue; + } + j++; + } + + return j; +} + static KVMSlot *kvm_lookup_matching_slot(KVMState *s, target_phys_addr_t start_addr, target_phys_addr_t end_addr) diff --git a/kvm.h b/kvm.h index 02280a6..93da155 100644 --- a/kvm.h +++ b/kvm.h @@ -221,4 +221,6 @@ int kvm_irqchip_in_kernel(void); int kvm_set_irq(int irq, int level, int *status); +int kvm_free_slots(void); + #endif