aboutsummaryrefslogtreecommitdiffstats
path: root/virt/kvm/assigned-dev.c
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2011-05-10 12:02:39 -0400
committerJesse Barnes <jbarnes@virtuousgeek.org>2011-05-21 15:17:10 -0400
commitf8fcfd775523347afe460dc3a0f45d0479e784a2 (patch)
tree8c7c5e0ece50b8661cae34ee1a6734144fce7594 /virt/kvm/assigned-dev.c
parentffbdd3f7931fb7cb7e36d00d16303ec433be5145 (diff)
KVM: Use pci_store/load_saved_state() around VM device usage
Store the device saved state so that we can reload the device back to the original state when it's unassigned. This has the benefit that the state survives across pci_reset_function() calls via the PCI sysfs reset interface while the VM is using the device. Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Acked-by: Avi Kivity <avi@redhat.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'virt/kvm/assigned-dev.c')
-rw-r--r--virt/kvm/assigned-dev.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/virt/kvm/assigned-dev.c b/virt/kvm/assigned-dev.c
index ae72ae604c89..6cc4b97ec458 100644
--- a/virt/kvm/assigned-dev.c
+++ b/virt/kvm/assigned-dev.c
@@ -197,8 +197,13 @@ static void kvm_free_assigned_device(struct kvm *kvm,
197{ 197{
198 kvm_free_assigned_irq(kvm, assigned_dev); 198 kvm_free_assigned_irq(kvm, assigned_dev);
199 199
200 __pci_reset_function(assigned_dev->dev); 200 pci_reset_function(assigned_dev->dev);
201 pci_restore_state(assigned_dev->dev); 201 if (pci_load_and_free_saved_state(assigned_dev->dev,
202 &assigned_dev->pci_saved_state))
203 printk(KERN_INFO "%s: Couldn't reload %s saved state\n",
204 __func__, dev_name(&assigned_dev->dev->dev));
205 else
206 pci_restore_state(assigned_dev->dev);
202 207
203 pci_release_regions(assigned_dev->dev); 208 pci_release_regions(assigned_dev->dev);
204 pci_disable_device(assigned_dev->dev); 209 pci_disable_device(assigned_dev->dev);
@@ -516,7 +521,10 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
516 521
517 pci_reset_function(dev); 522 pci_reset_function(dev);
518 pci_save_state(dev); 523 pci_save_state(dev);
519 524 match->pci_saved_state = pci_store_saved_state(dev);
525 if (!match->pci_saved_state)
526 printk(KERN_DEBUG "%s: Couldn't store %s saved state\n",
527 __func__, dev_name(&dev->dev));
520 match->assigned_dev_id = assigned_dev->assigned_dev_id; 528 match->assigned_dev_id = assigned_dev->assigned_dev_id;
521 match->host_segnr = assigned_dev->segnr; 529 match->host_segnr = assigned_dev->segnr;
522 match->host_busnr = assigned_dev->busnr; 530 match->host_busnr = assigned_dev->busnr;
@@ -546,7 +554,9 @@ out:
546 mutex_unlock(&kvm->lock); 554 mutex_unlock(&kvm->lock);
547 return r; 555 return r;
548out_list_del: 556out_list_del:
549 pci_restore_state(dev); 557 if (pci_load_and_free_saved_state(dev, &match->pci_saved_state))
558 printk(KERN_INFO "%s: Couldn't reload %s saved state\n",
559 __func__, dev_name(&dev->dev));
550 list_del(&match->list); 560 list_del(&match->list);
551 pci_release_regions(dev); 561 pci_release_regions(dev);
552out_disable: 562out_disable: