~ubuntu-branches/debian/sid/linux-2.6/sid

« back to all changes in this revision

Viewing changes to debian/patches/bugfix/all/kvm-lock-slots_lock-around-device-assignment.patch

  • Committer: Package Import Robot
  • Author(s): Ben Hutchings, Ben Hutchings
  • Date: 2012-06-01 13:15:48 UTC
  • mfrom: (1.3.23)
  • Revision ID: package-import@ubuntu.com-20120601131548-36wdtra41obedftv
Tags: 3.2.19-1
* New upstream stable update:
  http://www.kernel.org/pub/linux/kernel/v3.x/ChangeLog-3.2.19
  - hpsa: Fix problem with MSA2xxx devices (Closes: #661057)
  - IB/core: Fix mismatch between locked and pinned pages
  - iommu: Fix off by one in dmar_get_fault_reason()
  - vfs: make AIO use the proper rw_verify_area() area helpers
  - HID: logitech: read all 32 bits of report type bitfield (Closes: #671292)
  - USB: Remove races in devio.c
  - ext{3,4}: Fix error handling on inode bitmap corruption
  - uvcvideo: Fix ENUMINPUT handling
  - dl2k: Clean up rio_ioctl (CVE-2012-2313)
  - [x86] MCE: Fix vm86 handling for 32bit mce handler
  - [x86] mce: Fix check for processor context when machine check was taken.
  - ethtool: Null-terminate filename passed to ethtool_ops::flash_device
  - NFSv4: Fix buffer overflows in ACL support (CVE-2012-2375)
    + Avoid reading past buffer when calling GETACL
    + Avoid beyond bounds copy while caching ACL

[ Ben Hutchings ]
* be2net: Backport most changes up to Linux 3.5-rc1, thanks to
  Sarveshwar Bandi (Closes: #673391)
  - Add support for Skyhawk cards
* net/sched: Add codel and fq_codel from Linux 3.5-rc1
* [x86] udeb: Add hyperv-modules containing Hyper-V paravirtualised drivers
* [x86] ata_piix: defer disks to the Hyper-V drivers by default
* [x86] drm/i915:: Disable FBC on SandyBridge (Closes: #675022)
* AppArmor: compatibility patch for v5 interface (Closes: #661151)
* hugepages: fix use after free bug in "quota" handling (CVE-2012-2133)
* [x86] mm: pmd_read_atomic: fix 32bit PAE pmd walk vs pmd_populate SMP race
  condition (CVE-2012-2373)
* hugetlb: fix resv_map leak in error path (CVE-2012-2390)
* [SCSI] fix scsi_wait_scan (Closes: #647436)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From: Alex Williamson <alex.williamson@redhat.com>
2
 
Date: Tue, 17 Apr 2012 21:46:44 -0600
3
 
Subject: [PATCH] KVM: lock slots_lock around device assignment
4
 
 
5
 
commit 21a1416a1c945c5aeaeaf791b63c64926018eb77 upstream.
6
 
 
7
 
As pointed out by Jason Baron, when assigning a device to a guest
8
 
we first set the iommu domain pointer, which enables mapping
9
 
and unmapping of memory slots to the iommu.  This leaves a window
10
 
where this path is enabled, but we haven't synchronized the iommu
11
 
mappings to the existing memory slots.  Thus a slot being removed
12
 
at that point could send us down unexpected code paths removing
13
 
non-existent pinnings and iommu mappings.  Take the slots_lock
14
 
around creating the iommu domain and initial mappings as well as
15
 
around iommu teardown to avoid this race.
16
 
 
17
 
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
18
 
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
19
 
---
20
 
 virt/kvm/iommu.c |   23 +++++++++++++++--------
21
 
 1 file changed, 15 insertions(+), 8 deletions(-)
22
 
 
23
 
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
24
 
index fec1723..e9fff98 100644
25
 
--- a/virt/kvm/iommu.c
26
 
+++ b/virt/kvm/iommu.c
27
 
@@ -240,9 +240,13 @@ int kvm_iommu_map_guest(struct kvm *kvm)
28
 
                return -ENODEV;
29
 
        }
30
 
 
31
 
+       mutex_lock(&kvm->slots_lock);
32
 
+
33
 
        kvm->arch.iommu_domain = iommu_domain_alloc(&pci_bus_type);
34
 
-       if (!kvm->arch.iommu_domain)
35
 
-               return -ENOMEM;
36
 
+       if (!kvm->arch.iommu_domain) {
37
 
+               r = -ENOMEM;
38
 
+               goto out_unlock;
39
 
+       }
40
 
 
41
 
        if (!allow_unsafe_assigned_interrupts &&
42
 
            !iommu_domain_has_cap(kvm->arch.iommu_domain,
43
 
@@ -253,17 +257,16 @@ int kvm_iommu_map_guest(struct kvm *kvm)
44
 
                       " module option.\n", __func__);
45
 
                iommu_domain_free(kvm->arch.iommu_domain);
46
 
                kvm->arch.iommu_domain = NULL;
47
 
-               return -EPERM;
48
 
+               r = -EPERM;
49
 
+               goto out_unlock;
50
 
        }
51
 
 
52
 
        r = kvm_iommu_map_memslots(kvm);
53
 
        if (r)
54
 
-               goto out_unmap;
55
 
-
56
 
-       return 0;
57
 
+               kvm_iommu_unmap_memslots(kvm);
58
 
 
59
 
-out_unmap:
60
 
-       kvm_iommu_unmap_memslots(kvm);
61
 
+out_unlock:
62
 
+       mutex_unlock(&kvm->slots_lock);
63
 
        return r;
64
 
 }
65
 
 
66
 
@@ -340,7 +343,11 @@ int kvm_iommu_unmap_guest(struct kvm *kvm)
67
 
        if (!domain)
68
 
                return 0;
69
 
 
70
 
+       mutex_lock(&kvm->slots_lock);
71
 
        kvm_iommu_unmap_memslots(kvm);
72
 
+       kvm->arch.iommu_domain = NULL;
73
 
+       mutex_unlock(&kvm->slots_lock);
74
 
+
75
 
        iommu_domain_free(domain);
76
 
        return 0;
77
 
 }
78
 
1.7.10
79