Commit f8fcfd77 authored by Alex Williamson's avatar Alex Williamson Committed by Jesse Barnes

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: default avatarAlex Williamson <alex.williamson@redhat.com>
Acked-by: default avatarAvi Kivity <avi@redhat.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent ffbdd3f7
...@@ -513,6 +513,7 @@ struct kvm_assigned_dev_kernel { ...@@ -513,6 +513,7 @@ struct kvm_assigned_dev_kernel {
struct kvm *kvm; struct kvm *kvm;
spinlock_t intx_lock; spinlock_t intx_lock;
char irq_name[32]; char irq_name[32];
struct pci_saved_state *pci_saved_state;
}; };
struct kvm_irq_mask_notifier { struct kvm_irq_mask_notifier {
......
...@@ -197,7 +197,12 @@ static void kvm_free_assigned_device(struct kvm *kvm, ...@@ -197,7 +197,12 @@ static void kvm_free_assigned_device(struct kvm *kvm,
{ {
kvm_free_assigned_irq(kvm, assigned_dev); kvm_free_assigned_irq(kvm, assigned_dev);
__pci_reset_function(assigned_dev->dev); pci_reset_function(assigned_dev->dev);
if (pci_load_and_free_saved_state(assigned_dev->dev,
&assigned_dev->pci_saved_state))
printk(KERN_INFO "%s: Couldn't reload %s saved state\n",
__func__, dev_name(&assigned_dev->dev->dev));
else
pci_restore_state(assigned_dev->dev); pci_restore_state(assigned_dev->dev);
pci_release_regions(assigned_dev->dev); pci_release_regions(assigned_dev->dev);
...@@ -516,7 +521,10 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -516,7 +521,10 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
pci_reset_function(dev); pci_reset_function(dev);
pci_save_state(dev); pci_save_state(dev);
match->pci_saved_state = pci_store_saved_state(dev);
if (!match->pci_saved_state)
printk(KERN_DEBUG "%s: Couldn't store %s saved state\n",
__func__, dev_name(&dev->dev));
match->assigned_dev_id = assigned_dev->assigned_dev_id; match->assigned_dev_id = assigned_dev->assigned_dev_id;
match->host_segnr = assigned_dev->segnr; match->host_segnr = assigned_dev->segnr;
match->host_busnr = assigned_dev->busnr; match->host_busnr = assigned_dev->busnr;
...@@ -546,7 +554,9 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm, ...@@ -546,7 +554,9 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
mutex_unlock(&kvm->lock); mutex_unlock(&kvm->lock);
return r; return r;
out_list_del: out_list_del:
pci_restore_state(dev); if (pci_load_and_free_saved_state(dev, &match->pci_saved_state))
printk(KERN_INFO "%s: Couldn't reload %s saved state\n",
__func__, dev_name(&dev->dev));
list_del(&match->list); list_del(&match->list);
pci_release_regions(dev); pci_release_regions(dev);
out_disable: out_disable:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment