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 <alex.williamson@xxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html