From 4ec18f1f504556545e497ff1338bc23be4ced00b Mon Sep 17 00:00:00 2001 Message-Id: <4ec18f1f504556545e497ff1338bc23be4ced00b.1341315334.git.minovotn@redhat.com> From: Don Dutile <ddutile@redhat.com> Date: Thu, 21 Jun 2012 20:32:53 +0200 Subject: [PATCH 1/2] kvm: dev-assignment: tag pci dev when assigned to guest RH-Author: Don Dutile <ddutile@redhat.com> Message-id: <1340310773-62228-1-git-send-email-ddutile@redhat.com> Patchwork-id: 40061 O-Subject: [RHEL5 PATCH] kvm: dev-assignment: tag pci dev when assigned to guest Bugzilla: 784899 RH-Acked-by: Alex Williamson <alex.williamson@redhat.com> RH-Acked-by: Stefan Assmann <sassmann@redhat.com> RH-Acked-by: Michael S. Tsirkin <mst@redhat.com> Backport of kvm portion of upstream commit 6777829cfe1c4ed78319ad40aaee60254222da76 Upstream description: Author: Greg Rose <gregory.v.rose@intel.com> Date: Fri Jul 22 05:46:07 2011 +0000 pci: Add flag indicating device has been assigned by KVM Device drivers that create and destroy SR-IOV virtual functions via calls to pci_enable_sriov() and pci_disable_sriov can cause catastrophic failures if they attempt to destroy VFs while they are assigned to guest virtual machines. By adding a flag for use by the KVM module to indicate that a device is assigned a device driver can check that flag and avoid destroying VFs while they are assigned and avoid system failures. Backport of kvm portion of RHEL6 commit cc8bde656a9ecdb97aaa8e3723a5140f9bd01af7 RH Bugzilla 784899. Brew-build: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=4504589 (brew build results gone now; I saved the rpms if interested to try) Note: the kvm.spec file requires the kernel version to be changed to 2.6.18-317, minimum; the brew build is against -318. -- Not sure if I submit a spec file patch to make that happen, or is this note sufficient to start another process to change the package's spec file. -- I had to get dist-5E-test updated to -318 to enable the brew build to work with an updated kvm.spec file. Testing: The rhel5 igb[vf] and ixgbe[vf] drivers need to be updated to test that this patch enables the resolution of the (upstream) described problem. Stefan Assmann & Andy Gospodarek are working those backports, resp., and I am awaiting their testing results. Posting now to get initial ack's, even if they are contingent on test results. Please review and ack. --- virt/kvm/iommu.c | 4 ++++ virt/kvm/kvm_main.c | 2 ++ 2 files changed, 6 insertions(+) Signed-off-by: Michal Novotny <minovotn@redhat.com> --- virt/kvm/iommu.c | 4 ++++ virt/kvm/kvm_main.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c index 17aed9b..3e70943 100644 --- a/virt/kvm/iommu.c +++ b/virt/kvm/iommu.c @@ -107,6 +107,8 @@ int kvm_assign_device(struct kvm *kvm, return r; } + pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED; + printk(KERN_DEBUG "assign device: host bdf = %x:%x:%x\n", assigned_dev->host_busnr, PCI_SLOT(assigned_dev->host_devfn), @@ -131,6 +133,8 @@ int kvm_deassign_device(struct kvm *kvm, iommu_detach_device(domain, &pdev->dev); + pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED; + printk(KERN_DEBUG "deassign device: host bdf = %x:%x:%x\n", assigned_dev->host_busnr, PCI_SLOT(assigned_dev->host_devfn), diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 40b9328..469be3d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -313,6 +313,8 @@ static void kvm_free_assigned_device(struct kvm *kvm, pci_reset_function(assigned_dev->dev); + assigned_dev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED; + pci_release_regions(assigned_dev->dev); pci_disable_device(assigned_dev->dev); pci_dev_put(assigned_dev->dev); -- 1.7.10.4