diff options
author | Marcelo Tosatti <mtosatti@redhat.com> | 2009-06-04 14:08:22 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2009-09-10 01:32:49 -0400 |
commit | 64a2268dcfc9c3626aa7f70902690e2fc10c1630 (patch) | |
tree | 51e37e86dc9a75f10708ff4df7614c63dfa7c079 /virt/kvm/coalesced_mmio.c | |
parent | 9f4cc12765ea48a40347449d6802a3322ced8709 (diff) |
KVM: move coalesced_mmio locking to its own device
Move coalesced_mmio locking to its own device, instead of relying on
kvm->lock.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'virt/kvm/coalesced_mmio.c')
-rw-r--r-- | virt/kvm/coalesced_mmio.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c index 754906800999..397f41936698 100644 --- a/virt/kvm/coalesced_mmio.c +++ b/virt/kvm/coalesced_mmio.c | |||
@@ -31,10 +31,6 @@ static int coalesced_mmio_in_range(struct kvm_io_device *this, | |||
31 | if (!is_write) | 31 | if (!is_write) |
32 | return 0; | 32 | return 0; |
33 | 33 | ||
34 | /* kvm->lock is taken by the caller and must be not released before | ||
35 | * dev.read/write | ||
36 | */ | ||
37 | |||
38 | /* Are we able to batch it ? */ | 34 | /* Are we able to batch it ? */ |
39 | 35 | ||
40 | /* last is the first free entry | 36 | /* last is the first free entry |
@@ -43,7 +39,7 @@ static int coalesced_mmio_in_range(struct kvm_io_device *this, | |||
43 | */ | 39 | */ |
44 | ring = dev->kvm->coalesced_mmio_ring; | 40 | ring = dev->kvm->coalesced_mmio_ring; |
45 | avail = (ring->first - ring->last - 1) % KVM_COALESCED_MMIO_MAX; | 41 | avail = (ring->first - ring->last - 1) % KVM_COALESCED_MMIO_MAX; |
46 | if (avail < 1) { | 42 | if (avail < KVM_MAX_VCPUS) { |
47 | /* full */ | 43 | /* full */ |
48 | return 0; | 44 | return 0; |
49 | } | 45 | } |
@@ -70,7 +66,7 @@ static void coalesced_mmio_write(struct kvm_io_device *this, | |||
70 | struct kvm_coalesced_mmio_dev *dev = to_mmio(this); | 66 | struct kvm_coalesced_mmio_dev *dev = to_mmio(this); |
71 | struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring; | 67 | struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring; |
72 | 68 | ||
73 | /* kvm->lock must be taken by caller before call to in_range()*/ | 69 | spin_lock(&dev->lock); |
74 | 70 | ||
75 | /* copy data in first free entry of the ring */ | 71 | /* copy data in first free entry of the ring */ |
76 | 72 | ||
@@ -79,6 +75,7 @@ static void coalesced_mmio_write(struct kvm_io_device *this, | |||
79 | memcpy(ring->coalesced_mmio[ring->last].data, val, len); | 75 | memcpy(ring->coalesced_mmio[ring->last].data, val, len); |
80 | smp_wmb(); | 76 | smp_wmb(); |
81 | ring->last = (ring->last + 1) % KVM_COALESCED_MMIO_MAX; | 77 | ring->last = (ring->last + 1) % KVM_COALESCED_MMIO_MAX; |
78 | spin_unlock(&dev->lock); | ||
82 | } | 79 | } |
83 | 80 | ||
84 | static void coalesced_mmio_destructor(struct kvm_io_device *this) | 81 | static void coalesced_mmio_destructor(struct kvm_io_device *this) |
@@ -101,6 +98,7 @@ int kvm_coalesced_mmio_init(struct kvm *kvm) | |||
101 | dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL); | 98 | dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL); |
102 | if (!dev) | 99 | if (!dev) |
103 | return -ENOMEM; | 100 | return -ENOMEM; |
101 | spin_lock_init(&dev->lock); | ||
104 | kvm_iodevice_init(&dev->dev, &coalesced_mmio_ops); | 102 | kvm_iodevice_init(&dev->dev, &coalesced_mmio_ops); |
105 | dev->kvm = kvm; | 103 | dev->kvm = kvm; |
106 | kvm->coalesced_mmio_dev = dev; | 104 | kvm->coalesced_mmio_dev = dev; |