Skip to content

Commit 64a2268

Browse files
matosattiavikivity
authored andcommitted
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 <[email protected]> Signed-off-by: Avi Kivity <[email protected]>
1 parent 9f4cc12 commit 64a2268

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

virt/kvm/coalesced_mmio.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ static int coalesced_mmio_in_range(struct kvm_io_device *this,
3131
if (!is_write)
3232
return 0;
3333

34-
/* kvm->lock is taken by the caller and must be not released before
35-
* dev.read/write
36-
*/
37-
3834
/* Are we able to batch it ? */
3935

4036
/* last is the first free entry
@@ -43,7 +39,7 @@ static int coalesced_mmio_in_range(struct kvm_io_device *this,
4339
*/
4440
ring = dev->kvm->coalesced_mmio_ring;
4541
avail = (ring->first - ring->last - 1) % KVM_COALESCED_MMIO_MAX;
46-
if (avail < 1) {
42+
if (avail < KVM_MAX_VCPUS) {
4743
/* full */
4844
return 0;
4945
}
@@ -70,7 +66,7 @@ static void coalesced_mmio_write(struct kvm_io_device *this,
7066
struct kvm_coalesced_mmio_dev *dev = to_mmio(this);
7167
struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring;
7268

73-
/* kvm->lock must be taken by caller before call to in_range()*/
69+
spin_lock(&dev->lock);
7470

7571
/* copy data in first free entry of the ring */
7672

@@ -79,6 +75,7 @@ static void coalesced_mmio_write(struct kvm_io_device *this,
7975
memcpy(ring->coalesced_mmio[ring->last].data, val, len);
8076
smp_wmb();
8177
ring->last = (ring->last + 1) % KVM_COALESCED_MMIO_MAX;
78+
spin_unlock(&dev->lock);
8279
}
8380

8481
static void coalesced_mmio_destructor(struct kvm_io_device *this)
@@ -101,6 +98,7 @@ int kvm_coalesced_mmio_init(struct kvm *kvm)
10198
dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL);
10299
if (!dev)
103100
return -ENOMEM;
101+
spin_lock_init(&dev->lock);
104102
kvm_iodevice_init(&dev->dev, &coalesced_mmio_ops);
105103
dev->kvm = kvm;
106104
kvm->coalesced_mmio_dev = dev;

virt/kvm/coalesced_mmio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
struct kvm_coalesced_mmio_dev {
1313
struct kvm_io_device dev;
1414
struct kvm *kvm;
15+
spinlock_t lock;
1516
int nb_zones;
1617
struct kvm_coalesced_mmio_zone zone[KVM_COALESCED_MMIO_ZONE_MAX];
1718
};

0 commit comments

Comments
 (0)