Skip to content

Commit 6c47469

Browse files
mstsirkinavikivity
authored andcommitted
KVM: convert bus to slots_lock
Use slots_lock to protect device list on the bus. slots_lock is already taken for read everywhere, so we only need to take it for write when registering devices. This is in preparation to removing in_range and kvm->lock around it. Signed-off-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Avi Kivity <[email protected]>
1 parent 108b566 commit 6c47469

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

arch/x86/kvm/i8254.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ static const struct kvm_io_device_ops speaker_dev_ops = {
583583
.in_range = speaker_in_range,
584584
};
585585

586+
/* Caller must have writers lock on slots_lock */
586587
struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
587588
{
588589
struct kvm_pit *pit;
@@ -621,11 +622,11 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags)
621622
kvm_register_irq_mask_notifier(kvm, 0, &pit->mask_notifier);
622623

623624
kvm_iodevice_init(&pit->dev, &pit_dev_ops);
624-
kvm_io_bus_register_dev(&kvm->pio_bus, &pit->dev);
625+
__kvm_io_bus_register_dev(&kvm->pio_bus, &pit->dev);
625626

626627
if (flags & KVM_PIT_SPEAKER_DUMMY) {
627628
kvm_iodevice_init(&pit->speaker_dev, &speaker_dev_ops);
628-
kvm_io_bus_register_dev(&kvm->pio_bus, &pit->speaker_dev);
629+
__kvm_io_bus_register_dev(&kvm->pio_bus, &pit->speaker_dev);
629630
}
630631

631632
return pit;

arch/x86/kvm/i8259.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,6 @@ struct kvm_pic *kvm_create_pic(struct kvm *kvm)
548548
* Initialize PIO device
549549
*/
550550
kvm_iodevice_init(&s->dev, &picdev_ops);
551-
kvm_io_bus_register_dev(&kvm->pio_bus, &s->dev);
551+
kvm_io_bus_register_dev(kvm, &kvm->pio_bus, &s->dev);
552552
return s;
553553
}

include/linux/kvm_host.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#define KVM_USERSPACE_IRQ_SOURCE_ID 0
4444

45+
struct kvm;
4546
struct kvm_vcpu;
4647
extern struct kmem_cache *kvm_vcpu_cache;
4748

@@ -61,7 +62,9 @@ void kvm_io_bus_init(struct kvm_io_bus *bus);
6162
void kvm_io_bus_destroy(struct kvm_io_bus *bus);
6263
struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus,
6364
gpa_t addr, int len, int is_write);
64-
void kvm_io_bus_register_dev(struct kvm_io_bus *bus,
65+
void __kvm_io_bus_register_dev(struct kvm_io_bus *bus,
66+
struct kvm_io_device *dev);
67+
void kvm_io_bus_register_dev(struct kvm *kvm, struct kvm_io_bus *bus,
6568
struct kvm_io_device *dev);
6669

6770
struct kvm_vcpu {

virt/kvm/coalesced_mmio.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int kvm_coalesced_mmio_init(struct kvm *kvm)
102102
kvm_iodevice_init(&dev->dev, &coalesced_mmio_ops);
103103
dev->kvm = kvm;
104104
kvm->coalesced_mmio_dev = dev;
105-
kvm_io_bus_register_dev(&kvm->mmio_bus, &dev->dev);
105+
kvm_io_bus_register_dev(kvm, &kvm->mmio_bus, &dev->dev);
106106

107107
return 0;
108108
}

virt/kvm/ioapic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ int kvm_ioapic_init(struct kvm *kvm)
343343
kvm_ioapic_reset(ioapic);
344344
kvm_iodevice_init(&ioapic->dev, &ioapic_mmio_ops);
345345
ioapic->kvm = kvm;
346-
kvm_io_bus_register_dev(&kvm->mmio_bus, &ioapic->dev);
346+
kvm_io_bus_register_dev(kvm, &kvm->mmio_bus, &ioapic->dev);
347347
return 0;
348348
}
349349

virt/kvm/kvm_main.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,17 @@ struct kvm_io_device *kvm_io_bus_find_dev(struct kvm_io_bus *bus,
25272527
return NULL;
25282528
}
25292529

2530-
void kvm_io_bus_register_dev(struct kvm_io_bus *bus, struct kvm_io_device *dev)
2530+
void kvm_io_bus_register_dev(struct kvm *kvm, struct kvm_io_bus *bus,
2531+
struct kvm_io_device *dev)
2532+
{
2533+
down_write(&kvm->slots_lock);
2534+
__kvm_io_bus_register_dev(bus, dev);
2535+
up_write(&kvm->slots_lock);
2536+
}
2537+
2538+
/* An unlocked version. Caller must have write lock on slots_lock. */
2539+
void __kvm_io_bus_register_dev(struct kvm_io_bus *bus,
2540+
struct kvm_io_device *dev)
25312541
{
25322542
BUG_ON(bus->dev_count > (NR_IOBUS_DEVS-1));
25332543

0 commit comments

Comments
 (0)