All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Resize kvm_io_bus_range array dynamically
@ 2012-02-29  5:24 Amos Kong
  2012-02-29  5:50 ` [PATCH v2] KVM: Resize kvm_io_range " Amos Kong
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Amos Kong @ 2012-02-29  5:24 UTC (permalink / raw)
  To: jasowang, alex.williamson, mtosatti, avi, kvm

kvm_io_bus devices are used for ioevent, pit, pic, ioapic,
coalesced_mmio.

Currently Qemu only emulates one PCI bus, it contains 32 slots,
one slot contains 8 functions, maximum of supported PCI devices:
 1 * 32 * 8 = 256. The maximum of coalesced mmio zone is 100,
each zone has an iobus devices.

This patch makes the kvm_io_bus_range array can be resized dynamically.

Signed-off-by: Amos Kong <akong@redhat.com>
CC: Alex Williamson <alex.williamson@redhat.com>
---
 include/linux/kvm_host.h |    3 +--
 virt/kvm/kvm_main.c      |   24 +++++++++++++++---------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 355e445..0e6d9d2 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -69,8 +69,7 @@ struct kvm_io_range {
 
 struct kvm_io_bus {
 	int                   dev_count;
-#define NR_IOBUS_DEVS 300
-	struct kvm_io_range range[NR_IOBUS_DEVS];
+	struct kvm_io_range range[];
 };
 
 enum kvm_bus {
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index e4431ad..a6b9445 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2389,9 +2389,6 @@ int kvm_io_bus_sort_cmp(const void *p1, const void *p2)
 int kvm_io_bus_insert_dev(struct kvm_io_bus *bus, struct kvm_io_device *dev,
 			  gpa_t addr, int len)
 {
-	if (bus->dev_count == NR_IOBUS_DEVS)
-		return -ENOSPC;
-
 	bus->range[bus->dev_count++] = (struct kvm_io_range) {
 		.addr = addr,
 		.len = len,
@@ -2491,10 +2488,12 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
 	struct kvm_io_bus *new_bus, *bus;
 
 	bus = kvm->buses[bus_idx];
-	if (bus->dev_count > NR_IOBUS_DEVS-1)
-		return -ENOSPC;
 
-	new_bus = kmemdup(bus, sizeof(struct kvm_io_bus), GFP_KERNEL);
+	new_bus = kzalloc(sizeof(*bus) + ((bus->dev_count + 1) *
+			  sizeof(struct kvm_io_range)), GFP_KERNEL);
+	if (new_bus)
+		memcpy(new_bus, bus, sizeof(struct kvm_io_bus) +
+		       (bus->dev_count * sizeof(struct kvm_io_range)));
 	if (!new_bus)
 		return -ENOMEM;
 	kvm_io_bus_insert_dev(new_bus, dev, addr, len);
@@ -2514,16 +2513,23 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
 
 	bus = kvm->buses[bus_idx];
 
-	new_bus = kmemdup(bus, sizeof(*bus), GFP_KERNEL);
+	new_bus = kmemdup(bus, sizeof(*bus) + ((bus->dev_count - 1) *
+			  sizeof(struct kvm_io_range)), GFP_KERNEL);
 	if (!new_bus)
 		return -ENOMEM;
 
 	r = -ENOENT;
 	for (i = 0; i < new_bus->dev_count; i++)
-		if (new_bus->range[i].dev == dev) {
+		if (i == bus->dev_count - 1) {
+			/* dev is the last item of bus->range array,
+			   and new_bus->range doesn't have this item. */
+			r = 0;
+			new_bus->dev_count--;
+			break;
+		} else if (new_bus->range[i].dev == dev) {
 			r = 0;
 			new_bus->dev_count--;
-			new_bus->range[i] = new_bus->range[new_bus->dev_count];
+			new_bus->range[i] = bus->range[new_bus->dev_count];
 			sort(new_bus->range, new_bus->dev_count,
 			     sizeof(struct kvm_io_range),
 			     kvm_io_bus_sort_cmp, NULL);


^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2012-03-09 21:09 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-29  5:24 [PATCH] KVM: Resize kvm_io_bus_range array dynamically Amos Kong
2012-02-29  5:50 ` [PATCH v2] KVM: Resize kvm_io_range " Amos Kong
2012-02-29 13:30 ` [PATCH v3] " Amos Kong
2012-02-29 14:19   ` Jan Kiszka
2012-02-29 15:22     ` Amos Kong
2012-02-29 15:29       ` Jan Kiszka
2012-02-29 16:34         ` Amos Kong
2012-03-01  5:19           ` Amos Kong
2012-03-01  7:01 ` [PATCH v4] " Amos Kong
2012-03-01 10:14   ` Sasha Levin
2012-03-01 15:33     ` Alex Williamson
2012-03-07 10:57   ` Avi Kivity
2012-03-07 12:51     ` Amos Kong
2012-03-07 14:12       ` Avi Kivity
2012-03-07 13:16   ` [PATCH v5 1/2] KVM: resize " Amos Kong
2012-03-07 13:16   ` [PATCH v5 2/2] KVM: set upper bounds for iobus dev to limit userspace Amos Kong
2012-03-07 13:20   ` [RESEND PATCH v5 0/2] fix ENOSPC issue of iobus dev Amos Kong
2012-03-07 13:20     ` [RESEND PATCH v5 1/2] KVM: resize kvm_io_range array dynamically Amos Kong
2012-03-07 13:20     ` [RESEND PATCH v5 2/2] KVM: set upper bounds for iobus dev to limit userspace Amos Kong
2012-03-08  2:03   ` [PATCH v6 0/2] fix ENOSPC issue of iobus dev Amos Kong
2012-03-08  2:03     ` [PATCH v6 1/2] KVM: resize kvm_io_range array dynamically Amos Kong
2012-03-08 23:20       ` Marcelo Tosatti
2012-03-09  4:05         ` Amos Kong
2012-03-08  2:04     ` [PATCH v6 2/2] KVM: set upper bounds for iobus dev to limit userspace Amos Kong
2012-03-09  4:17   ` [PATCH v7 0/2] fix ENOSPC issue of iobus dev Amos Kong
2012-03-09  4:17     ` [PATCH v7 1/2] KVM: resize kvm_io_range array dynamically Amos Kong
2012-03-09  4:17     ` [PATCH v7 2/2] KVM: set upper bounds for iobus dev to limit userspace Amos Kong
2012-03-09 21:07     ` [PATCH v7 0/2] fix ENOSPC issue of iobus dev Marcelo Tosatti

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.