From patchwork Thu Feb 24 09:51:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 586891 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1O9mj4Q027832 for ; Thu, 24 Feb 2011 09:48:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754642Ab1BXJsn (ORCPT ); Thu, 24 Feb 2011 04:48:43 -0500 Received: from mga03.intel.com ([143.182.124.21]:29995 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751632Ab1BXJsl (ORCPT ); Thu, 24 Feb 2011 04:48:41 -0500 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga101.ch.intel.com with ESMTP; 24 Feb 2011 01:48:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.62,215,1297065600"; d="scan'208";a="393395871" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.13.17]) by azsmga001.ch.intel.com with ESMTP; 24 Feb 2011 01:48:38 -0800 Received: from yasker by syang10-desktop with local (Exim 4.72) (envelope-from ) id 1PsXqk-0005Ym-UE; Thu, 24 Feb 2011 17:51:06 +0800 From: Sheng Yang To: Avi Kivity , Marcelo Tosatti Cc: Alex Williamson , "Michael S. Tsirkin" , kvm@vger.kernel.org, Sheng Yang Subject: [PATCH 2/4] KVM: Add kvm_io_ext_data to IO handler Date: Thu, 24 Feb 2011 17:51:03 +0800 Message-Id: <1298541065-21343-3-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1298541065-21343-1-git-send-email-sheng@linux.intel.com> References: <1298541065-21343-1-git-send-email-sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 24 Feb 2011 09:48:50 +0000 (UTC) diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index efad723..bd8f0c5 100644 --- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c @@ -439,7 +439,8 @@ static inline int pit_in_range(gpa_t addr) } static int pit_ioport_write(struct kvm_io_device *this, - gpa_t addr, int len, const void *data) + gpa_t addr, int len, const void *data, + struct kvm_io_ext_data *ext_data) { struct kvm_pit *pit = dev_to_pit(this); struct kvm_kpit_state *pit_state = &pit->pit_state; @@ -585,7 +586,8 @@ static int pit_ioport_read(struct kvm_io_device *this, } static int speaker_ioport_write(struct kvm_io_device *this, - gpa_t addr, int len, const void *data) + gpa_t addr, int len, const void *data, + struct kvm_io_ext_data *ext_data) { struct kvm_pit *pit = speaker_to_pit(this); struct kvm_kpit_state *pit_state = &pit->pit_state; diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c index 3cece05..96b1070 100644 --- a/arch/x86/kvm/i8259.c +++ b/arch/x86/kvm/i8259.c @@ -480,7 +480,8 @@ static inline struct kvm_pic *to_pic(struct kvm_io_device *dev) } static int picdev_write(struct kvm_io_device *this, - gpa_t addr, int len, const void *val) + gpa_t addr, int len, const void *val, + struct kvm_io_ext_data *ext_data) { struct kvm_pic *s = to_pic(this); unsigned char data = *(unsigned char *)val; diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 93cf9d0..f413e9c 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -836,7 +836,8 @@ static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val) } static int apic_mmio_write(struct kvm_io_device *this, - gpa_t address, int len, const void *data) + gpa_t address, int len, const void *data, + struct kvm_io_ext_data *ext_data) { struct kvm_lapic *apic = to_lapic(this); unsigned int offset = address - apic->base_address; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index fa708c9..21b84e2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3571,13 +3571,14 @@ static void kvm_init_msr_list(void) } static int vcpu_mmio_write(struct kvm_vcpu *vcpu, gpa_t addr, int len, - const void *v) + const void *v, struct kvm_io_ext_data *ext_data) { if (vcpu->arch.apic && - !kvm_iodevice_write(&vcpu->arch.apic->dev, addr, len, v)) + !kvm_iodevice_write(&vcpu->arch.apic->dev, addr, len, v, ext_data)) return 0; - return kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, addr, len, v); + return kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, + addr, len, v, ext_data); } static int vcpu_mmio_read(struct kvm_vcpu *vcpu, gpa_t addr, int len, void *v) @@ -3807,6 +3808,7 @@ static int emulator_write_emulated_onepage(unsigned long addr, struct kvm_vcpu *vcpu) { gpa_t gpa; + struct kvm_io_ext_data ext_data; gpa = kvm_mmu_gva_to_gpa_write(vcpu, addr, exception); @@ -3825,7 +3827,7 @@ mmio: /* * Is this MMIO handled locally? */ - if (!vcpu_mmio_write(vcpu, gpa, bytes, val)) + if (!vcpu_mmio_write(vcpu, gpa, bytes, val, &ext_data)) return X86EMUL_CONTINUE; vcpu->mmio_needed = 1; @@ -3940,6 +3942,7 @@ static int kernel_pio(struct kvm_vcpu *vcpu, void *pd) { /* TODO: String I/O for in kernel device */ int r; + struct kvm_io_ext_data ext_data; if (vcpu->arch.pio.in) r = kvm_io_bus_read(vcpu->kvm, KVM_PIO_BUS, vcpu->arch.pio.port, @@ -3947,7 +3950,7 @@ static int kernel_pio(struct kvm_vcpu *vcpu, void *pd) else r = kvm_io_bus_write(vcpu->kvm, KVM_PIO_BUS, vcpu->arch.pio.port, vcpu->arch.pio.size, - pd); + pd, &ext_data); return r; } diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 7d313e0..6bb211d 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -68,8 +68,15 @@ enum kvm_bus { KVM_NR_BUSES }; +struct kvm_io_ext_data { + int type; + union { + char padding[256]; + }; +}; + int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, - int len, const void *val); + int len, const void *val, struct kvm_io_ext_data *data); int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len, void *val); int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, @@ -113,7 +120,8 @@ struct kvm_io_device_ops { int (*write)(struct kvm_io_device *this, gpa_t addr, int len, - const void *val); + const void *val, + struct kvm_io_ext_data *data); void (*destructor)(struct kvm_io_device *this); }; diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c index fc84875..37b254c 100644 --- a/virt/kvm/coalesced_mmio.c +++ b/virt/kvm/coalesced_mmio.c @@ -59,7 +59,8 @@ static int coalesced_mmio_in_range(struct kvm_coalesced_mmio_dev *dev, } static int coalesced_mmio_write(struct kvm_io_device *this, - gpa_t addr, int len, const void *val) + gpa_t addr, int len, const void *val, + struct kvm_io_ext_data *ext_data) { struct kvm_coalesced_mmio_dev *dev = to_mmio(this); struct kvm_coalesced_mmio_ring *ring = dev->kvm->coalesced_mmio_ring; diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 2ca4535..8edd757 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -483,7 +483,7 @@ ioeventfd_in_range(struct _ioeventfd *p, gpa_t addr, int len, const void *val) /* MMIO/PIO writes trigger an event if the addr/val match */ static int ioeventfd_write(struct kvm_io_device *this, gpa_t addr, int len, - const void *val) + const void *val, struct kvm_io_ext_data *ext_data) { struct _ioeventfd *p = to_ioeventfd(this); diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c index 0b9df83..6a027ef 100644 --- a/virt/kvm/ioapic.c +++ b/virt/kvm/ioapic.c @@ -321,7 +321,7 @@ static int ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, } static int ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, - const void *val) + const void *val, struct kvm_io_ext_data *ext_data) { struct kvm_ioapic *ioapic = to_ioapic(this); u32 data; diff --git a/virt/kvm/iodev.h b/virt/kvm/iodev.h index d1f5651..340ab79 100644 --- a/virt/kvm/iodev.h +++ b/virt/kvm/iodev.h @@ -33,9 +33,11 @@ static inline int kvm_iodevice_read(struct kvm_io_device *dev, } static inline int kvm_iodevice_write(struct kvm_io_device *dev, - gpa_t addr, int l, const void *v) + gpa_t addr, int l, const void *v, + struct kvm_io_ext_data *data) { - return dev->ops->write ? dev->ops->write(dev, addr, l, v) : -EOPNOTSUPP; + return dev->ops->write ? + dev->ops->write(dev, addr, l, v, data) : -EOPNOTSUPP; } static 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 b1b6cbb..a61f90e 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2221,14 +2221,14 @@ static void kvm_io_bus_destroy(struct kvm_io_bus *bus) /* kvm_io_bus_write - called under kvm->slots_lock */ int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, - int len, const void *val) + int len, const void *val, struct kvm_io_ext_data *ext_data) { int i; struct kvm_io_bus *bus; bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu); for (i = 0; i < bus->dev_count; i++) - if (!kvm_iodevice_write(bus->devs[i], addr, len, val)) + if (!kvm_iodevice_write(bus->devs[i], addr, len, val, ext_data)) return 0; return -EOPNOTSUPP; }