Skip to content

Commit f8fcfd7

Browse files
Alex Williamsonjbarnes993
authored andcommitted
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>
1 parent ffbdd3f commit f8fcfd7

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎include/linux/kvm_host.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ struct kvm_assigned_dev_kernel {
513513
struct kvm *kvm;
514514
spinlock_t intx_lock;
515515
char irq_name[32];
516+
struct pci_saved_state *pci_saved_state;
516517
};
517518

518519
struct kvm_irq_mask_notifier {

‎virt/kvm/assigned-dev.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,13 @@ static void kvm_free_assigned_device(struct kvm *kvm,
197197
{
198198
kvm_free_assigned_irq(kvm, assigned_dev);
199199

200-
__pci_reset_function(assigned_dev->dev);
201-
pci_restore_state(assigned_dev->dev);
200+
pci_reset_function(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);
202207

203208
pci_release_regions(assigned_dev->dev);
204209
pci_disable_device(assigned_dev->dev);
@@ -516,7 +521,10 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
516521

517522
pci_reset_function(dev);
518523
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));
520528
match->assigned_dev_id = assigned_dev->assigned_dev_id;
521529
match->host_segnr = assigned_dev->segnr;
522530
match->host_busnr = assigned_dev->busnr;
@@ -546,7 +554,9 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
546554
mutex_unlock(&kvm->lock);
547555
return r;
548556
out_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));
550560
list_del(&match->list);
551561
pci_release_regions(dev);
552562
out_disable:

0 commit comments

Comments
 (0)