Skip to content

Commit 6ea34c9

Browse files
amoskongGleb Natapov
authored andcommitted
kvm: exclude ioeventfd from counting kvm_io_range limit
We can easily reach the 1000 limit by start VM with a couple hundred I/O devices (multifunction=on). The hardcode limit already been adjusted 3 times (6 ~ 200 ~ 300 ~ 1000). In userspace, we already have maximum file descriptor to limit ioeventfd count. But kvm_io_bus devices also are used for pit, pic, ioapic, coalesced_mmio. They couldn't be limited by maximum file descriptor. Currently only ioeventfds take too much kvm_io_bus devices, so just exclude it from counting kvm_io_range limit. Also fixed one indent issue in kvm_host.h Signed-off-by: Amos Kong <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Signed-off-by: Gleb Natapov <[email protected]>
1 parent 566af94 commit 6ea34c9

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

include/linux/kvm_host.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ struct kvm_io_range {
145145
#define NR_IOBUS_DEVS 1000
146146

147147
struct kvm_io_bus {
148-
int dev_count;
148+
int dev_count;
149+
int ioeventfd_count;
149150
struct kvm_io_range range[];
150151
};
151152

virt/kvm/eventfd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ kvm_assign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
753753
if (ret < 0)
754754
goto unlock_fail;
755755

756+
kvm->buses[bus_idx]->ioeventfd_count++;
756757
list_add_tail(&p->list, &kvm->ioeventfds);
757758

758759
mutex_unlock(&kvm->slots_lock);
@@ -798,6 +799,7 @@ kvm_deassign_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
798799
continue;
799800

800801
kvm_io_bus_unregister_dev(kvm, bus_idx, &p->dev);
802+
kvm->buses[bus_idx]->ioeventfd_count--;
801803
ioeventfd_release(p);
802804
ret = 0;
803805
break;

virt/kvm/kvm_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2926,7 +2926,8 @@ int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
29262926
struct kvm_io_bus *new_bus, *bus;
29272927

29282928
bus = kvm->buses[bus_idx];
2929-
if (bus->dev_count > NR_IOBUS_DEVS - 1)
2929+
/* exclude ioeventfd which is limited by maximum fd */
2930+
if (bus->dev_count - bus->ioeventfd_count > NR_IOBUS_DEVS - 1)
29302931
return -ENOSPC;
29312932

29322933
new_bus = kzalloc(sizeof(*bus) + ((bus->dev_count + 1) *

0 commit comments

Comments
 (0)