aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Nikolaev <n.nikolaev@virtualopensystems.com>2015-03-26 10:39:28 -0400
committerMarc Zyngier <marc.zyngier@arm.com>2015-03-26 17:43:11 -0400
commite32edf4fd0fa4897e12ca66118ab67bf257e16e4 (patch)
tree8bd79dc3e3d03576e084ce2dbbde68c95fdd0ea8
parent1a74847885cc87857d631f91cca4d83924f75674 (diff)
KVM: Redesign kvm_io_bus_ API to pass VCPU structure to the callbacks.
This is needed in e.g. ARM vGIC emulation, where the MMIO handling depends on the VCPU that does the access. Signed-off-by: Nikolay Nikolaev <n.nikolaev@virtualopensystems.com> Signed-off-by: Andre Przywara <andre.przywara@arm.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Acked-by: Christoffer Dall <christoffer.dall@linaro.org> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
-rw-r--r--arch/powerpc/kvm/mpic.c10
-rw-r--r--arch/powerpc/kvm/powerpc.c4
-rw-r--r--arch/s390/kvm/diag.c2
-rw-r--r--arch/x86/kvm/i8254.c14
-rw-r--r--arch/x86/kvm/i8259.c12
-rw-r--r--arch/x86/kvm/ioapic.c8
-rw-r--r--arch/x86/kvm/lapic.c4
-rw-r--r--arch/x86/kvm/vmx.c2
-rw-r--r--arch/x86/kvm/x86.c13
-rw-r--r--include/linux/kvm_host.h10
-rw-r--r--virt/kvm/coalesced_mmio.c5
-rw-r--r--virt/kvm/eventfd.c4
-rw-r--r--virt/kvm/iodev.h23
-rw-r--r--virt/kvm/kvm_main.c32
14 files changed, 79 insertions, 64 deletions
diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
index 39b3a8f816f2..8542f07491d4 100644
--- a/arch/powerpc/kvm/mpic.c
+++ b/arch/powerpc/kvm/mpic.c
@@ -1374,8 +1374,9 @@ static int kvm_mpic_write_internal(struct openpic *opp, gpa_t addr, u32 val)
1374 return -ENXIO; 1374 return -ENXIO;
1375} 1375}
1376 1376
1377static int kvm_mpic_read(struct kvm_io_device *this, gpa_t addr, 1377static int kvm_mpic_read(struct kvm_vcpu *vcpu,
1378 int len, void *ptr) 1378 struct kvm_io_device *this,
1379 gpa_t addr, int len, void *ptr)
1379{ 1380{
1380 struct openpic *opp = container_of(this, struct openpic, mmio); 1381 struct openpic *opp = container_of(this, struct openpic, mmio);
1381 int ret; 1382 int ret;
@@ -1415,8 +1416,9 @@ static int kvm_mpic_read(struct kvm_io_device *this, gpa_t addr,
1415 return ret; 1416 return ret;
1416} 1417}
1417 1418
1418static int kvm_mpic_write(struct kvm_io_device *this, gpa_t addr, 1419static int kvm_mpic_write(struct kvm_vcpu *vcpu,
1419 int len, const void *ptr) 1420 struct kvm_io_device *this,
1421 gpa_t addr, int len, const void *ptr)
1420{ 1422{
1421 struct openpic *opp = container_of(this, struct openpic, mmio); 1423 struct openpic *opp = container_of(this, struct openpic, mmio);
1422 int ret; 1424 int ret;
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 27c0face86f4..24bfe401373e 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -807,7 +807,7 @@ int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
807 807
808 idx = srcu_read_lock(&vcpu->kvm->srcu); 808 idx = srcu_read_lock(&vcpu->kvm->srcu);
809 809
810 ret = kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, run->mmio.phys_addr, 810 ret = kvm_io_bus_read(vcpu, KVM_MMIO_BUS, run->mmio.phys_addr,
811 bytes, &run->mmio.data); 811 bytes, &run->mmio.data);
812 812
813 srcu_read_unlock(&vcpu->kvm->srcu, idx); 813 srcu_read_unlock(&vcpu->kvm->srcu, idx);
@@ -880,7 +880,7 @@ int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
880 880
881 idx = srcu_read_lock(&vcpu->kvm->srcu); 881 idx = srcu_read_lock(&vcpu->kvm->srcu);
882 882
883 ret = kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, run->mmio.phys_addr, 883 ret = kvm_io_bus_write(vcpu, KVM_MMIO_BUS, run->mmio.phys_addr,
884 bytes, &run->mmio.data); 884 bytes, &run->mmio.data);
885 885
886 srcu_read_unlock(&vcpu->kvm->srcu, idx); 886 srcu_read_unlock(&vcpu->kvm->srcu, idx);
diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
index 9254afff250c..329ec75e9214 100644
--- a/arch/s390/kvm/diag.c
+++ b/arch/s390/kvm/diag.c
@@ -213,7 +213,7 @@ static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu)
213 * - gpr 3 contains the virtqueue index (passed as datamatch) 213 * - gpr 3 contains the virtqueue index (passed as datamatch)
214 * - gpr 4 contains the index on the bus (optionally) 214 * - gpr 4 contains the index on the bus (optionally)
215 */ 215 */
216 ret = kvm_io_bus_write_cookie(vcpu->kvm, KVM_VIRTIO_CCW_NOTIFY_BUS, 216 ret = kvm_io_bus_write_cookie(vcpu, KVM_VIRTIO_CCW_NOTIFY_BUS,
217 vcpu->run->s.regs.gprs[2] & 0xffffffff, 217 vcpu->run->s.regs.gprs[2] & 0xffffffff,
218 8, &vcpu->run->s.regs.gprs[3], 218 8, &vcpu->run->s.regs.gprs[3],
219 vcpu->run->s.regs.gprs[4]); 219 vcpu->run->s.regs.gprs[4]);
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 298781d4cfb4..4dce6f8b6129 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -443,7 +443,8 @@ static inline int pit_in_range(gpa_t addr)
443 (addr < KVM_PIT_BASE_ADDRESS + KVM_PIT_MEM_LENGTH)); 443 (addr < KVM_PIT_BASE_ADDRESS + KVM_PIT_MEM_LENGTH));
444} 444}
445 445
446static int pit_ioport_write(struct kvm_io_device *this, 446static int pit_ioport_write(struct kvm_vcpu *vcpu,
447 struct kvm_io_device *this,
447 gpa_t addr, int len, const void *data) 448 gpa_t addr, int len, const void *data)
448{ 449{
449 struct kvm_pit *pit = dev_to_pit(this); 450 struct kvm_pit *pit = dev_to_pit(this);
@@ -519,7 +520,8 @@ static int pit_ioport_write(struct kvm_io_device *this,
519 return 0; 520 return 0;
520} 521}
521 522
522static int pit_ioport_read(struct kvm_io_device *this, 523static int pit_ioport_read(struct kvm_vcpu *vcpu,
524 struct kvm_io_device *this,
523 gpa_t addr, int len, void *data) 525 gpa_t addr, int len, void *data)
524{ 526{
525 struct kvm_pit *pit = dev_to_pit(this); 527 struct kvm_pit *pit = dev_to_pit(this);
@@ -589,7 +591,8 @@ static int pit_ioport_read(struct kvm_io_device *this,
589 return 0; 591 return 0;
590} 592}
591 593
592static int speaker_ioport_write(struct kvm_io_device *this, 594static int speaker_ioport_write(struct kvm_vcpu *vcpu,
595 struct kvm_io_device *this,
593 gpa_t addr, int len, const void *data) 596 gpa_t addr, int len, const void *data)
594{ 597{
595 struct kvm_pit *pit = speaker_to_pit(this); 598 struct kvm_pit *pit = speaker_to_pit(this);
@@ -606,8 +609,9 @@ static int speaker_ioport_write(struct kvm_io_device *this,
606 return 0; 609 return 0;
607} 610}
608 611
609static int speaker_ioport_read(struct kvm_io_device *this, 612static int speaker_ioport_read(struct kvm_vcpu *vcpu,
610 gpa_t addr, int len, void *data) 613 struct kvm_io_device *this,
614 gpa_t addr, int len, void *data)
611{ 615{
612 struct kvm_pit *pit = speaker_to_pit(this); 616 struct kvm_pit *pit = speaker_to_pit(this);
613 struct kvm_kpit_state *pit_state = &pit->pit_state; 617 struct kvm_kpit_state *pit_state = &pit->pit_state;
diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c
index cc31f7c06d3d..8ff4eaa2bf19 100644
--- a/arch/x86/kvm/i8259.c
+++ b/arch/x86/kvm/i8259.c
@@ -528,42 +528,42 @@ static int picdev_read(struct kvm_pic *s,
528 return 0; 528 return 0;
529} 529}
530 530
531static int picdev_master_write(struct kvm_io_device *dev, 531static int picdev_master_write(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,
532 gpa_t addr, int len, const void *val) 532 gpa_t addr, int len, const void *val)
533{ 533{
534 return picdev_write(container_of(dev, struct kvm_pic, dev_master), 534 return picdev_write(container_of(dev, struct kvm_pic, dev_master),
535 addr, len, val); 535 addr, len, val);
536} 536}
537 537
538static int picdev_master_read(struct kvm_io_device *dev, 538static int picdev_master_read(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,
539 gpa_t addr, int len, void *val) 539 gpa_t addr, int len, void *val)
540{ 540{
541 return picdev_read(container_of(dev, struct kvm_pic, dev_master), 541 return picdev_read(container_of(dev, struct kvm_pic, dev_master),
542 addr, len, val); 542 addr, len, val);
543} 543}
544 544
545static int picdev_slave_write(struct kvm_io_device *dev, 545static int picdev_slave_write(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,
546 gpa_t addr, int len, const void *val) 546 gpa_t addr, int len, const void *val)
547{ 547{
548 return picdev_write(container_of(dev, struct kvm_pic, dev_slave), 548 return picdev_write(container_of(dev, struct kvm_pic, dev_slave),
549 addr, len, val); 549 addr, len, val);
550} 550}
551 551
552static int picdev_slave_read(struct kvm_io_device *dev, 552static int picdev_slave_read(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,
553 gpa_t addr, int len, void *val) 553 gpa_t addr, int len, void *val)
554{ 554{
555 return picdev_read(container_of(dev, struct kvm_pic, dev_slave), 555 return picdev_read(container_of(dev, struct kvm_pic, dev_slave),
556 addr, len, val); 556 addr, len, val);
557} 557}
558 558
559static int picdev_eclr_write(struct kvm_io_device *dev, 559static int picdev_eclr_write(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,
560 gpa_t addr, int len, const void *val) 560 gpa_t addr, int len, const void *val)
561{ 561{
562 return picdev_write(container_of(dev, struct kvm_pic, dev_eclr), 562 return picdev_write(container_of(dev, struct kvm_pic, dev_eclr),
563 addr, len, val); 563 addr, len, val);
564} 564}
565 565
566static int picdev_eclr_read(struct kvm_io_device *dev, 566static int picdev_eclr_read(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,
567 gpa_t addr, int len, void *val) 567 gpa_t addr, int len, void *val)
568{ 568{
569 return picdev_read(container_of(dev, struct kvm_pic, dev_eclr), 569 return picdev_read(container_of(dev, struct kvm_pic, dev_eclr),
diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index b1947e0f3e10..8bf2e49708e3 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -498,8 +498,8 @@ static inline int ioapic_in_range(struct kvm_ioapic *ioapic, gpa_t addr)
498 (addr < ioapic->base_address + IOAPIC_MEM_LENGTH))); 498 (addr < ioapic->base_address + IOAPIC_MEM_LENGTH)));
499} 499}
500 500
501static int ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, 501static int ioapic_mmio_read(struct kvm_vcpu *vcpu, struct kvm_io_device *this,
502 void *val) 502 gpa_t addr, int len, void *val)
503{ 503{
504 struct kvm_ioapic *ioapic = to_ioapic(this); 504 struct kvm_ioapic *ioapic = to_ioapic(this);
505 u32 result; 505 u32 result;
@@ -541,8 +541,8 @@ static int ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len,
541 return 0; 541 return 0;
542} 542}
543 543
544static int ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, 544static int ioapic_mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this,
545 const void *val) 545 gpa_t addr, int len, const void *val)
546{ 546{
547 struct kvm_ioapic *ioapic = to_ioapic(this); 547 struct kvm_ioapic *ioapic = to_ioapic(this);
548 u32 data; 548 u32 data;
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index e55b5fc344eb..ba57bb79e795 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1038,7 +1038,7 @@ static int apic_mmio_in_range(struct kvm_lapic *apic, gpa_t addr)
1038 addr < apic->base_address + LAPIC_MMIO_LENGTH; 1038 addr < apic->base_address + LAPIC_MMIO_LENGTH;
1039} 1039}
1040 1040
1041static int apic_mmio_read(struct kvm_io_device *this, 1041static int apic_mmio_read(struct kvm_vcpu *vcpu, struct kvm_io_device *this,
1042 gpa_t address, int len, void *data) 1042 gpa_t address, int len, void *data)
1043{ 1043{
1044 struct kvm_lapic *apic = to_lapic(this); 1044 struct kvm_lapic *apic = to_lapic(this);
@@ -1358,7 +1358,7 @@ static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
1358 return ret; 1358 return ret;
1359} 1359}
1360 1360
1361static int apic_mmio_write(struct kvm_io_device *this, 1361static int apic_mmio_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this,
1362 gpa_t address, int len, const void *data) 1362 gpa_t address, int len, const void *data)
1363{ 1363{
1364 struct kvm_lapic *apic = to_lapic(this); 1364 struct kvm_lapic *apic = to_lapic(this);
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index f7b20b417a3a..317da9bde728 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -5822,7 +5822,7 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
5822 gpa_t gpa; 5822 gpa_t gpa;
5823 5823
5824 gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS); 5824 gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
5825 if (!kvm_io_bus_write(vcpu->kvm, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) { 5825 if (!kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) {
5826 skip_emulated_instruction(vcpu); 5826 skip_emulated_instruction(vcpu);
5827 return 1; 5827 return 1;
5828 } 5828 }
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index bd7a70be41b3..5573d633144c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4115,8 +4115,8 @@ static int vcpu_mmio_write(struct kvm_vcpu *vcpu, gpa_t addr, int len,
4115 do { 4115 do {
4116 n = min(len, 8); 4116 n = min(len, 8);
4117 if (!(vcpu->arch.apic && 4117 if (!(vcpu->arch.apic &&
4118 !kvm_iodevice_write(&vcpu->arch.apic->dev, addr, n, v)) 4118 !kvm_iodevice_write(vcpu, &vcpu->arch.apic->dev, addr, n, v))
4119 && kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, addr, n, v)) 4119 && kvm_io_bus_write(vcpu, KVM_MMIO_BUS, addr, n, v))
4120 break; 4120 break;
4121 handled += n; 4121 handled += n;
4122 addr += n; 4122 addr += n;
@@ -4135,8 +4135,9 @@ static int vcpu_mmio_read(struct kvm_vcpu *vcpu, gpa_t addr, int len, void *v)
4135 do { 4135 do {
4136 n = min(len, 8); 4136 n = min(len, 8);
4137 if (!(vcpu->arch.apic && 4137 if (!(vcpu->arch.apic &&
4138 !kvm_iodevice_read(&vcpu->arch.apic->dev, addr, n, v)) 4138 !kvm_iodevice_read(vcpu, &vcpu->arch.apic->dev,
4139 && kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, addr, n, v)) 4139 addr, n, v))
4140 && kvm_io_bus_read(vcpu, KVM_MMIO_BUS, addr, n, v))
4140 break; 4141 break;
4141 trace_kvm_mmio(KVM_TRACE_MMIO_READ, n, addr, *(u64 *)v); 4142 trace_kvm_mmio(KVM_TRACE_MMIO_READ, n, addr, *(u64 *)v);
4142 handled += n; 4143 handled += n;
@@ -4630,10 +4631,10 @@ static int kernel_pio(struct kvm_vcpu *vcpu, void *pd)
4630 int r; 4631 int r;
4631 4632
4632 if (vcpu->arch.pio.in) 4633 if (vcpu->arch.pio.in)
4633 r = kvm_io_bus_read(vcpu->kvm, KVM_PIO_BUS, vcpu->arch.pio.port, 4634 r = kvm_io_bus_read(vcpu, KVM_PIO_BUS, vcpu->arch.pio.port,
4634 vcpu->arch.pio.size, pd); 4635 vcpu->arch.pio.size, pd);
4635 else 4636 else
4636 r = kvm_io_bus_write(vcpu->kvm, KVM_PIO_BUS, 4637 r = kvm_io_bus_write(vcpu, KVM_PIO_BUS,
4637 vcpu->arch.pio.port, vcpu->arch.pio.size, 4638 vcpu->arch.pio.port, vcpu->arch.pio.size,
4638 pd); 4639 pd);
4639 return r; 4640 return r;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ae9c72012004..9605e46fce0b 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -165,12 +165,12 @@ enum kvm_bus {
165 KVM_NR_BUSES 165 KVM_NR_BUSES
166}; 166};
167 167
168int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 168int kvm_io_bus_write(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
169 int len, const void *val); 169 int len, const void *val);
170int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 170int kvm_io_bus_write_cookie(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx,
171 int len, const void *val, long cookie); 171 gpa_t addr, int len, const void *val, long cookie);
172int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len, 172int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
173 void *val); 173 int len, void *val);
174int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 174int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
175 int len, struct kvm_io_device *dev); 175 int len, struct kvm_io_device *dev);
176int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, 176int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
index 00d86427af0f..c831a40ffc1a 100644
--- a/virt/kvm/coalesced_mmio.c
+++ b/virt/kvm/coalesced_mmio.c
@@ -60,8 +60,9 @@ static int coalesced_mmio_has_room(struct kvm_coalesced_mmio_dev *dev)
60 return 1; 60 return 1;
61} 61}
62 62
63static int coalesced_mmio_write(struct kvm_io_device *this, 63static int coalesced_mmio_write(struct kvm_vcpu *vcpu,
64 gpa_t addr, int len, const void *val) 64 struct kvm_io_device *this, gpa_t addr,
65 int len, const void *val)
65{ 66{
66 struct kvm_coalesced_mmio_dev *dev = to_mmio(this); 67 struct kvm_coalesced_mmio_dev *dev = to_mmio(this);
67 struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring; 68 struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring;
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index fc5f43e54a80..26c72f3663f2 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -715,8 +715,8 @@ ioeventfd_in_range(struct _ioeventfd *p, gpa_t addr, int len, const void *val)
715 715
716/* MMIO/PIO writes trigger an event if the addr/val match */ 716/* MMIO/PIO writes trigger an event if the addr/val match */
717static int 717static int
718ioeventfd_write(struct kvm_io_device *this, gpa_t addr, int len, 718ioeventfd_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this, gpa_t addr,
719 const void *val) 719 int len, const void *val)
720{ 720{
721 struct _ioeventfd *p = to_ioeventfd(this); 721 struct _ioeventfd *p = to_ioeventfd(this);
722 722
diff --git a/virt/kvm/iodev.h b/virt/kvm/iodev.h
index 12fd3caffd2b..9ef709cc2cae 100644
--- a/virt/kvm/iodev.h
+++ b/virt/kvm/iodev.h
@@ -20,6 +20,7 @@
20#include <asm/errno.h> 20#include <asm/errno.h>
21 21
22struct kvm_io_device; 22struct kvm_io_device;
23struct kvm_vcpu;
23 24
24/** 25/**
25 * kvm_io_device_ops are called under kvm slots_lock. 26 * kvm_io_device_ops are called under kvm slots_lock.
@@ -27,11 +28,13 @@ struct kvm_io_device;
27 * or non-zero to have it passed to the next device. 28 * or non-zero to have it passed to the next device.
28 **/ 29 **/
29struct kvm_io_device_ops { 30struct kvm_io_device_ops {
30 int (*read)(struct kvm_io_device *this, 31 int (*read)(struct kvm_vcpu *vcpu,
32 struct kvm_io_device *this,
31 gpa_t addr, 33 gpa_t addr,
32 int len, 34 int len,
33 void *val); 35 void *val);
34 int (*write)(struct kvm_io_device *this, 36 int (*write)(struct kvm_vcpu *vcpu,
37 struct kvm_io_device *this,
35 gpa_t addr, 38 gpa_t addr,
36 int len, 39 int len,
37 const void *val); 40 const void *val);
@@ -49,16 +52,20 @@ static inline void kvm_iodevice_init(struct kvm_io_device *dev,
49 dev->ops = ops; 52 dev->ops = ops;
50} 53}
51 54
52static inline int kvm_iodevice_read(struct kvm_io_device *dev, 55static inline int kvm_iodevice_read(struct kvm_vcpu *vcpu,
53 gpa_t addr, int l, void *v) 56 struct kvm_io_device *dev, gpa_t addr,
57 int l, void *v)
54{ 58{
55 return dev->ops->read ? dev->ops->read(dev, addr, l, v) : -EOPNOTSUPP; 59 return dev->ops->read ? dev->ops->read(vcpu, dev, addr, l, v)
60 : -EOPNOTSUPP;
56} 61}
57 62
58static inline int kvm_iodevice_write(struct kvm_io_device *dev, 63static inline int kvm_iodevice_write(struct kvm_vcpu *vcpu,
59 gpa_t addr, int l, const void *v) 64 struct kvm_io_device *dev, gpa_t addr,
65 int l, const void *v)
60{ 66{
61 return dev->ops->write ? dev->ops->write(dev, addr, l, v) : -EOPNOTSUPP; 67 return dev->ops->write ? dev->ops->write(vcpu, dev, addr, l, v)
68 : -EOPNOTSUPP;
62} 69}
63 70
64static inline void kvm_iodevice_destructor(struct kvm_io_device *dev) 71static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index a1093700f3a4..664d67a099f6 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2997,7 +2997,7 @@ static int kvm_io_bus_get_first_dev(struct kvm_io_bus *bus,
2997 return off; 2997 return off;
2998} 2998}
2999 2999
3000static int __kvm_io_bus_write(struct kvm_io_bus *bus, 3000static int __kvm_io_bus_write(struct kvm_vcpu *vcpu, struct kvm_io_bus *bus,
3001 struct kvm_io_range *range, const void *val) 3001 struct kvm_io_range *range, const void *val)
3002{ 3002{
3003 int idx; 3003 int idx;
@@ -3008,7 +3008,7 @@ static int __kvm_io_bus_write(struct kvm_io_bus *bus,
3008 3008
3009 while (idx < bus->dev_count && 3009 while (idx < bus->dev_count &&
3010 kvm_io_bus_cmp(range, &bus->range[idx]) == 0) { 3010 kvm_io_bus_cmp(range, &bus->range[idx]) == 0) {
3011 if (!kvm_iodevice_write(bus->range[idx].dev, range->addr, 3011 if (!kvm_iodevice_write(vcpu, bus->range[idx].dev, range->addr,
3012 range->len, val)) 3012 range->len, val))
3013 return idx; 3013 return idx;
3014 idx++; 3014 idx++;
@@ -3018,7 +3018,7 @@ static int __kvm_io_bus_write(struct kvm_io_bus *bus,
3018} 3018}
3019 3019
3020/* kvm_io_bus_write - called under kvm->slots_lock */ 3020/* kvm_io_bus_write - called under kvm->slots_lock */
3021int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 3021int kvm_io_bus_write(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
3022 int len, const void *val) 3022 int len, const void *val)
3023{ 3023{
3024 struct kvm_io_bus *bus; 3024 struct kvm_io_bus *bus;
@@ -3030,14 +3030,14 @@ int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
3030 .len = len, 3030 .len = len,
3031 }; 3031 };
3032 3032
3033 bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu); 3033 bus = srcu_dereference(vcpu->kvm->buses[bus_idx], &vcpu->kvm->srcu);
3034 r = __kvm_io_bus_write(bus, &range, val); 3034 r = __kvm_io_bus_write(vcpu, bus, &range, val);
3035 return r < 0 ? r : 0; 3035 return r < 0 ? r : 0;
3036} 3036}
3037 3037
3038/* kvm_io_bus_write_cookie - called under kvm->slots_lock */ 3038/* kvm_io_bus_write_cookie - called under kvm->slots_lock */
3039int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 3039int kvm_io_bus_write_cookie(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx,
3040 int len, const void *val, long cookie) 3040 gpa_t addr, int len, const void *val, long cookie)
3041{ 3041{
3042 struct kvm_io_bus *bus; 3042 struct kvm_io_bus *bus;
3043 struct kvm_io_range range; 3043 struct kvm_io_range range;
@@ -3047,12 +3047,12 @@ int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
3047 .len = len, 3047 .len = len,
3048 }; 3048 };
3049 3049
3050 bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu); 3050 bus = srcu_dereference(vcpu->kvm->buses[bus_idx], &vcpu->kvm->srcu);
3051 3051
3052 /* First try the device referenced by cookie. */ 3052 /* First try the device referenced by cookie. */
3053 if ((cookie >= 0) && (cookie < bus->dev_count) && 3053 if ((cookie >= 0) && (cookie < bus->dev_count) &&
3054 (kvm_io_bus_cmp(&range, &bus->range[cookie]) == 0)) 3054 (kvm_io_bus_cmp(&range, &bus->range[cookie]) == 0))
3055 if (!kvm_iodevice_write(bus->range[cookie].dev, addr, len, 3055 if (!kvm_iodevice_write(vcpu, bus->range[cookie].dev, addr, len,
3056 val)) 3056 val))
3057 return cookie; 3057 return cookie;
3058 3058
@@ -3060,11 +3060,11 @@ int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
3060 * cookie contained garbage; fall back to search and return the 3060 * cookie contained garbage; fall back to search and return the
3061 * correct cookie value. 3061 * correct cookie value.
3062 */ 3062 */
3063 return __kvm_io_bus_write(bus, &range, val); 3063 return __kvm_io_bus_write(vcpu, bus, &range, val);
3064} 3064}
3065 3065
3066static int __kvm_io_bus_read(struct kvm_io_bus *bus, struct kvm_io_range *range, 3066static int __kvm_io_bus_read(struct kvm_vcpu *vcpu, struct kvm_io_bus *bus,
3067 void *val) 3067 struct kvm_io_range *range, void *val)
3068{ 3068{
3069 int idx; 3069 int idx;
3070 3070
@@ -3074,7 +3074,7 @@ static int __kvm_io_bus_read(struct kvm_io_bus *bus, struct kvm_io_range *range,
3074 3074
3075 while (idx < bus->dev_count && 3075 while (idx < bus->dev_count &&
3076 kvm_io_bus_cmp(range, &bus->range[idx]) == 0) { 3076 kvm_io_bus_cmp(range, &bus->range[idx]) == 0) {
3077 if (!kvm_iodevice_read(bus->range[idx].dev, range->addr, 3077 if (!kvm_iodevice_read(vcpu, bus->range[idx].dev, range->addr,
3078 range->len, val)) 3078 range->len, val))
3079 return idx; 3079 return idx;
3080 idx++; 3080 idx++;
@@ -3085,7 +3085,7 @@ static int __kvm_io_bus_read(struct kvm_io_bus *bus, struct kvm_io_range *range,
3085EXPORT_SYMBOL_GPL(kvm_io_bus_write); 3085EXPORT_SYMBOL_GPL(kvm_io_bus_write);
3086 3086
3087/* kvm_io_bus_read - called under kvm->slots_lock */ 3087/* kvm_io_bus_read - called under kvm->slots_lock */
3088int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, 3088int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
3089 int len, void *val) 3089 int len, void *val)
3090{ 3090{
3091 struct kvm_io_bus *bus; 3091 struct kvm_io_bus *bus;
@@ -3097,8 +3097,8 @@ int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
3097 .len = len, 3097 .len = len,
3098 }; 3098 };
3099 3099
3100 bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu); 3100 bus = srcu_dereference(vcpu->kvm->buses[bus_idx], &vcpu->kvm->srcu);
3101 r = __kvm_io_bus_read(bus, &range, val); 3101 r = __kvm_io_bus_read(vcpu, bus, &range, val);
3102 return r < 0 ? r : 0; 3102 return r < 0 ? r : 0;
3103} 3103}
3104 3104