aboutsummaryrefslogtreecommitdiffstats
path: root/virt/kvm
diff options
context:
space:
mode:
Diffstat (limited to 'virt/kvm')
-rw-r--r--virt/kvm/assigned-dev.c19
-rw-r--r--virt/kvm/eventfd.c23
-rw-r--r--virt/kvm/kvm_main.c3
3 files changed, 29 insertions, 16 deletions
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index 01f572c10c71..23a41a9f8db9 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -334,6 +334,11 @@ static int assigned_device_enable_host_intx(struct kvm *kvm,
334} 334}
335 335
336#ifdef __KVM_HAVE_MSI 336#ifdef __KVM_HAVE_MSI
337static irqreturn_t kvm_assigned_dev_msi(int irq, void *dev_id)
338{
339 return IRQ_WAKE_THREAD;
340}
341
337static int assigned_device_enable_host_msi(struct kvm *kvm, 342static int assigned_device_enable_host_msi(struct kvm *kvm,
338 struct kvm_assigned_dev_kernel *dev) 343 struct kvm_assigned_dev_kernel *dev)
339{ 344{
@@ -346,7 +351,7 @@ static int assigned_device_enable_host_msi(struct kvm *kvm,
346 } 351 }
347 352
348 dev->host_irq = dev->dev->irq; 353 dev->host_irq = dev->dev->irq;
349 if (request_threaded_irq(dev->host_irq, NULL, 354 if (request_threaded_irq(dev->host_irq, kvm_assigned_dev_msi,
350 kvm_assigned_dev_thread_msi, 0, 355 kvm_assigned_dev_thread_msi, 0,
351 dev->irq_name, dev)) { 356 dev->irq_name, dev)) {
352 pci_disable_msi(dev->dev); 357 pci_disable_msi(dev->dev);
@@ -358,6 +363,11 @@ static int assigned_device_enable_host_msi(struct kvm *kvm,
358#endif 363#endif
359 364
360#ifdef __KVM_HAVE_MSIX 365#ifdef __KVM_HAVE_MSIX
366static irqreturn_t kvm_assigned_dev_msix(int irq, void *dev_id)
367{
368 return IRQ_WAKE_THREAD;
369}
370
361static int assigned_device_enable_host_msix(struct kvm *kvm, 371static int assigned_device_enable_host_msix(struct kvm *kvm,
362 struct kvm_assigned_dev_kernel *dev) 372 struct kvm_assigned_dev_kernel *dev)
363{ 373{
@@ -374,7 +384,8 @@ static int assigned_device_enable_host_msix(struct kvm *kvm,
374 384
375 for (i = 0; i < dev->entries_nr; i++) { 385 for (i = 0; i < dev->entries_nr; i++) {
376 r = request_threaded_irq(dev->host_msix_entries[i].vector, 386 r = request_threaded_irq(dev->host_msix_entries[i].vector,
377 NULL, kvm_assigned_dev_thread_msix, 387 kvm_assigned_dev_msix,
388 kvm_assigned_dev_thread_msix,
378 0, dev->irq_name, dev); 389 0, dev->irq_name, dev);
379 if (r) 390 if (r)
380 goto err; 391 goto err;
@@ -635,7 +646,6 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
635 int r = 0, idx; 646 int r = 0, idx;
636 struct kvm_assigned_dev_kernel *match; 647 struct kvm_assigned_dev_kernel *match;
637 struct pci_dev *dev; 648 struct pci_dev *dev;
638 u8 header_type;
639 649
640 if (!(assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU)) 650 if (!(assigned_dev->flags & KVM_DEV_ASSIGN_ENABLE_IOMMU))
641 return -EINVAL; 651 return -EINVAL;
@@ -668,8 +678,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
668 } 678 }
669 679
670 /* Don't allow bridges to be assigned */ 680 /* Don't allow bridges to be assigned */
671 pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type); 681 if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL) {
672 if ((header_type & PCI_HEADER_TYPE) != PCI_HEADER_TYPE_NORMAL) {
673 r = -EPERM; 682 r = -EPERM;
674 goto out_put; 683 goto out_put;
675 } 684 }
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index f59c1e8de7a2..7d7e2aaffece 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -198,7 +198,7 @@ static void irqfd_update(struct kvm *kvm, struct _irqfd *irqfd,
198} 198}
199 199
200static int 200static int
201kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi) 201kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
202{ 202{
203 struct kvm_irq_routing_table *irq_rt; 203 struct kvm_irq_routing_table *irq_rt;
204 struct _irqfd *irqfd, *tmp; 204 struct _irqfd *irqfd, *tmp;
@@ -212,12 +212,12 @@ kvm_irqfd_assign(struct kvm *kvm, int fd, int gsi)
212 return -ENOMEM; 212 return -ENOMEM;
213 213
214 irqfd->kvm = kvm; 214 irqfd->kvm = kvm;
215 irqfd->gsi = gsi; 215 irqfd->gsi = args->gsi;
216 INIT_LIST_HEAD(&irqfd->list); 216 INIT_LIST_HEAD(&irqfd->list);
217 INIT_WORK(&irqfd->inject, irqfd_inject); 217 INIT_WORK(&irqfd->inject, irqfd_inject);
218 INIT_WORK(&irqfd->shutdown, irqfd_shutdown); 218 INIT_WORK(&irqfd->shutdown, irqfd_shutdown);
219 219
220 file = eventfd_fget(fd); 220 file = eventfd_fget(args->fd);
221 if (IS_ERR(file)) { 221 if (IS_ERR(file)) {
222 ret = PTR_ERR(file); 222 ret = PTR_ERR(file);
223 goto fail; 223 goto fail;
@@ -298,19 +298,19 @@ kvm_eventfd_init(struct kvm *kvm)
298 * shutdown any irqfd's that match fd+gsi 298 * shutdown any irqfd's that match fd+gsi
299 */ 299 */
300static int 300static int
301kvm_irqfd_deassign(struct kvm *kvm, int fd, int gsi) 301kvm_irqfd_deassign(struct kvm *kvm, struct kvm_irqfd *args)
302{ 302{
303 struct _irqfd *irqfd, *tmp; 303 struct _irqfd *irqfd, *tmp;
304 struct eventfd_ctx *eventfd; 304 struct eventfd_ctx *eventfd;
305 305
306 eventfd = eventfd_ctx_fdget(fd); 306 eventfd = eventfd_ctx_fdget(args->fd);
307 if (IS_ERR(eventfd)) 307 if (IS_ERR(eventfd))
308 return PTR_ERR(eventfd); 308 return PTR_ERR(eventfd);
309 309
310 spin_lock_irq(&kvm->irqfds.lock); 310 spin_lock_irq(&kvm->irqfds.lock);
311 311
312 list_for_each_entry_safe(irqfd, tmp, &kvm->irqfds.items, list) { 312 list_for_each_entry_safe(irqfd, tmp, &kvm->irqfds.items, list) {
313 if (irqfd->eventfd == eventfd && irqfd->gsi == gsi) { 313 if (irqfd->eventfd == eventfd && irqfd->gsi == args->gsi) {
314 /* 314 /*
315 * This rcu_assign_pointer is needed for when 315 * This rcu_assign_pointer is needed for when
316 * another thread calls kvm_irq_routing_update before 316 * another thread calls kvm_irq_routing_update before
@@ -338,12 +338,15 @@ kvm_irqfd_deassign(struct kvm *kvm, int fd, int gsi)
338} 338}
339 339
340int 340int
341kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags) 341kvm_irqfd(struct kvm *kvm, struct kvm_irqfd *args)
342{ 342{
343 if (flags & KVM_IRQFD_FLAG_DEASSIGN) 343 if (args->flags & ~KVM_IRQFD_FLAG_DEASSIGN)
344 return kvm_irqfd_deassign(kvm, fd, gsi); 344 return -EINVAL;
345
346 if (args->flags & KVM_IRQFD_FLAG_DEASSIGN)
347 return kvm_irqfd_deassign(kvm, args);
345 348
346 return kvm_irqfd_assign(kvm, fd, gsi); 349 return kvm_irqfd_assign(kvm, args);
347} 350}
348 351
349/* 352/*
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 7e140683ff14..44ee7124b16d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2047,7 +2047,7 @@ static long kvm_vm_ioctl(struct file *filp,
2047 r = -EFAULT; 2047 r = -EFAULT;
2048 if (copy_from_user(&data, argp, sizeof data)) 2048 if (copy_from_user(&data, argp, sizeof data))
2049 goto out; 2049 goto out;
2050 r = kvm_irqfd(kvm, data.fd, data.gsi, data.flags); 2050 r = kvm_irqfd(kvm, &data);
2051 break; 2051 break;
2052 } 2052 }
2053 case KVM_IOEVENTFD: { 2053 case KVM_IOEVENTFD: {
@@ -2845,6 +2845,7 @@ void kvm_exit(void)
2845 kvm_arch_hardware_unsetup(); 2845 kvm_arch_hardware_unsetup();
2846 kvm_arch_exit(); 2846 kvm_arch_exit();
2847 free_cpumask_var(cpus_hardware_enabled); 2847 free_cpumask_var(cpus_hardware_enabled);
2848 __free_page(fault_page);
2848 __free_page(hwpoison_page); 2849 __free_page(hwpoison_page);
2849 __free_page(bad_page); 2850 __free_page(bad_page);
2850} 2851}