* [PATCH v3 0/2] KVM: ioeventfd cookies
@ 2013-07-03 13:50 Cornelia Huck
2013-07-03 13:50 ` [PATCH v3 1/2] KVM: kvm-io: support cookies Cornelia Huck
2013-07-03 13:50 ` [PATCH v3 2/2] KVM: s390: use cookies for ioeventfd Cornelia Huck
0 siblings, 2 replies; 6+ messages in thread
From: Cornelia Huck @ 2013-07-03 13:50 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390
Hi,
here's version 3 of the ioevent cookies patches.
Changes:
- x86 style fix
- fix returning index for reads
- refactored read/write functions to avoid double srcu_deference()
Cornelia Huck (2):
KVM: kvm-io: support cookies
KVM: s390: use cookies for ioeventfd
arch/ia64/kvm/kvm-ia64.c | 2 +-
arch/powerpc/kvm/powerpc.c | 4 +-
arch/s390/kvm/diag.c | 15 +++++--
arch/x86/kvm/x86.c | 6 +--
include/linux/kvm_host.h | 4 ++
virt/kvm/kvm_main.c | 102 ++++++++++++++++++++++++++++++++++++++-------
6 files changed, 109 insertions(+), 24 deletions(-)
--
1.8.2.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/2] KVM: kvm-io: support cookies
2013-07-03 13:50 [PATCH v3 0/2] KVM: ioeventfd cookies Cornelia Huck
@ 2013-07-03 13:50 ` Cornelia Huck
2013-07-03 13:56 ` Gleb Natapov
2013-07-03 13:50 ` [PATCH v3 2/2] KVM: s390: use cookies for ioeventfd Cornelia Huck
1 sibling, 1 reply; 6+ messages in thread
From: Cornelia Huck @ 2013-07-03 13:50 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390
Add new functions kvm_io_bus_{read,write}_cookie() that allows users of
the kvm io infrastructure to use a cookie value to speed up lookup of a
device on an io bus.
kvm_io_bus_{read,write} now returns the index on the bus; existing callers
have been fixed up to accept return codes > 0.
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
arch/ia64/kvm/kvm-ia64.c | 2 +-
arch/powerpc/kvm/powerpc.c | 4 +-
arch/x86/kvm/x86.c | 6 +--
include/linux/kvm_host.h | 4 ++
virt/kvm/kvm_main.c | 102 ++++++++++++++++++++++++++++++++++++++-------
5 files changed, 97 insertions(+), 21 deletions(-)
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
index 5b2dc0d..465ab54 100644
--- a/arch/ia64/kvm/kvm-ia64.c
+++ b/arch/ia64/kvm/kvm-ia64.c
@@ -250,7 +250,7 @@ mmio:
else
r = kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, p->addr,
p->size, &p->data);
- if (r)
+ if (r < 0)
printk(KERN_ERR"kvm: No iodevice found! addr:%lx\n", p->addr);
p->state = STATE_IORESP_READY;
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 6316ee3..26c44d0 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -649,7 +649,7 @@ int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
srcu_read_unlock(&vcpu->kvm->srcu, idx);
- if (!ret) {
+ if (ret >= 0) {
kvmppc_complete_mmio_load(vcpu, run);
vcpu->mmio_needed = 0;
return EMULATE_DONE;
@@ -711,7 +711,7 @@ int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
srcu_read_unlock(&vcpu->kvm->srcu, idx);
- if (!ret) {
+ if (ret >= 0) {
vcpu->mmio_needed = 0;
return EMULATE_DONE;
}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 7d71c0f..d58744b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3860,7 +3860,7 @@ static int vcpu_mmio_write(struct kvm_vcpu *vcpu, gpa_t addr, int len,
n = min(len, 8);
if (!(vcpu->arch.apic &&
!kvm_iodevice_write(&vcpu->arch.apic->dev, addr, n, v))
- && kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, addr, n, v))
+ && (kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, addr, n, v) < 0))
break;
handled += n;
addr += n;
@@ -3880,7 +3880,7 @@ static int vcpu_mmio_read(struct kvm_vcpu *vcpu, gpa_t addr, int len, void *v)
n = min(len, 8);
if (!(vcpu->arch.apic &&
!kvm_iodevice_read(&vcpu->arch.apic->dev, addr, n, v))
- && kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, addr, n, v))
+ && (kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, addr, n, v) < 0))
break;
trace_kvm_mmio(KVM_TRACE_MMIO_READ, n, addr, *(u64 *)v);
handled += n;
@@ -4361,7 +4361,7 @@ static int kernel_pio(struct kvm_vcpu *vcpu, void *pd)
r = kvm_io_bus_write(vcpu->kvm, KVM_PIO_BUS,
vcpu->arch.pio.port, vcpu->arch.pio.size,
pd);
- return r;
+ return (r >= 0) ? 0 : r;
}
static int emulator_pio_in_out(struct kvm_vcpu *vcpu, int size,
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index e3aae6d..60e261c9 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -159,8 +159,12 @@ enum kvm_bus {
int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
int len, const void *val);
+int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
+ int len, const void *val, long cookie);
int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len,
void *val);
+int kvm_io_bus_read_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
+ int len, void *val, long cookie);
int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
int len, struct kvm_io_device *dev);
int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 1580dd4..eca3e00 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2863,11 +2863,30 @@ static int kvm_io_bus_get_first_dev(struct kvm_io_bus *bus,
return off;
}
+static int __kvm_io_bus_write(struct kvm_io_bus *bus,
+ struct kvm_io_range *range, const void *val)
+{
+ int idx;
+
+ idx = kvm_io_bus_get_first_dev(bus, range->addr, range->len);
+ if (idx < 0)
+ return -EOPNOTSUPP;
+
+ while (idx < bus->dev_count &&
+ kvm_io_bus_sort_cmp(range, &bus->range[idx]) == 0) {
+ if (!kvm_iodevice_write(bus->range[idx].dev, range->addr,
+ range->len, val))
+ return idx;
+ idx++;
+ }
+
+ return -EOPNOTSUPP;
+}
+
/* 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 idx;
struct kvm_io_bus *bus;
struct kvm_io_range range;
@@ -2877,14 +2896,51 @@ int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
};
bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
- idx = kvm_io_bus_get_first_dev(bus, addr, len);
+ return __kvm_io_bus_write(bus, &range, val);
+}
+
+/* kvm_io_bus_write_cookie - called under kvm->slots_lock */
+int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
+ int len, const void *val, long cookie)
+{
+ struct kvm_io_bus *bus;
+ struct kvm_io_range range;
+
+ range = (struct kvm_io_range) {
+ .addr = addr,
+ .len = len,
+ };
+
+ bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
+
+ /* First try the device referenced by cookie. */
+ if ((cookie >= 0) && (cookie < bus->dev_count) &&
+ (kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
+ if (!kvm_iodevice_write(bus->range[cookie].dev, addr, len,
+ val))
+ return cookie;
+
+ /*
+ * cookie contained garbage; fall back to search and return the
+ * correct cookie value.
+ */
+ return __kvm_io_bus_write(bus, &range, val);
+}
+
+static int __kvm_io_bus_read(struct kvm_io_bus *bus, struct kvm_io_range *range,
+ void *val)
+{
+ int idx;
+
+ idx = kvm_io_bus_get_first_dev(bus, range->addr, range->len);
if (idx < 0)
return -EOPNOTSUPP;
while (idx < bus->dev_count &&
kvm_io_bus_sort_cmp(&range, &bus->range[idx]) == 0) {
- if (!kvm_iodevice_write(bus->range[idx].dev, addr, len, val))
- return 0;
+ if (!kvm_iodevice_read(bus->range[idx].dev, range->addr,
+ range->len, val))
+ return idx;
idx++;
}
@@ -2895,7 +2951,6 @@ int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
int len, void *val)
{
- int idx;
struct kvm_io_bus *bus;
struct kvm_io_range range;
@@ -2905,18 +2960,35 @@ int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
};
bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
- idx = kvm_io_bus_get_first_dev(bus, addr, len);
- if (idx < 0)
- return -EOPNOTSUPP;
+ return __kvm_io_bus_read(bus, &range, val);
+}
- while (idx < bus->dev_count &&
- kvm_io_bus_sort_cmp(&range, &bus->range[idx]) == 0) {
- if (!kvm_iodevice_read(bus->range[idx].dev, addr, len, val))
- return 0;
- idx++;
- }
+/* kvm_io_bus_read_cookie - called under kvm->slots_lock */
+int kvm_io_bus_read_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
+ int len, void *val, long cookie)
+{
+ struct kvm_io_bus *bus;
+ struct kvm_io_range range;
- return -EOPNOTSUPP;
+ range = (struct kvm_io_range) {
+ .addr = addr,
+ .len = len,
+ };
+
+ bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
+
+ /* First try the device referenced by cookie. */
+ if ((cookie >= 0) && (cookie < bus->dev_count) &&
+ (kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
+ if (!kvm_iodevice_read(bus->range[cookie].dev, addr, len,
+ val))
+ return cookie;
+
+ /*
+ * cookie contained garbage; fall back to search and return the
+ * correct cookie value.
+ */
+ return __kvm_io_bus_read(bus, &range, val);
}
/* Caller must hold slots_lock. */
--
1.8.2.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] KVM: s390: use cookies for ioeventfd
2013-07-03 13:50 [PATCH v3 0/2] KVM: ioeventfd cookies Cornelia Huck
2013-07-03 13:50 ` [PATCH v3 1/2] KVM: kvm-io: support cookies Cornelia Huck
@ 2013-07-03 13:50 ` Cornelia Huck
1 sibling, 0 replies; 6+ messages in thread
From: Cornelia Huck @ 2013-07-03 13:50 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390
Make use of cookies for the virtio ccw notification hypercall to speed up
lookup of devices on the io bus.
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
arch/s390/kvm/diag.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
index 3074475..e88c76e 100644
--- a/arch/s390/kvm/diag.c
+++ b/arch/s390/kvm/diag.c
@@ -119,11 +119,20 @@ static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu)
* The layout is as follows:
* - gpr 2 contains the subchannel id (passed as addr)
* - gpr 3 contains the virtqueue index (passed as datamatch)
+ * - gpr 4 contains the index on the bus (optionally)
*/
- ret = kvm_io_bus_write(vcpu->kvm, KVM_VIRTIO_CCW_NOTIFY_BUS,
- vcpu->run->s.regs.gprs[2],
- 8, &vcpu->run->s.regs.gprs[3]);
+ ret = kvm_io_bus_write_cookie(vcpu->kvm, KVM_VIRTIO_CCW_NOTIFY_BUS,
+ vcpu->run->s.regs.gprs[2],
+ 8, &vcpu->run->s.regs.gprs[3],
+ vcpu->run->s.regs.gprs[4]);
srcu_read_unlock(&vcpu->kvm->srcu, idx);
+
+ /*
+ * Return cookie in gpr 2, but don't overwrite the register if the
+ * diagnose will be handled by userspace.
+ */
+ if (ret != -EOPNOTSUPP)
+ vcpu->run->s.regs.gprs[2] = ret;
/* kvm_io_bus_write returns -EOPNOTSUPP if it found no match. */
return ret < 0 ? ret : 0;
}
--
1.8.2.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] KVM: kvm-io: support cookies
2013-07-03 13:50 ` [PATCH v3 1/2] KVM: kvm-io: support cookies Cornelia Huck
@ 2013-07-03 13:56 ` Gleb Natapov
2013-07-03 14:14 ` Cornelia Huck
0 siblings, 1 reply; 6+ messages in thread
From: Gleb Natapov @ 2013-07-03 13:56 UTC (permalink / raw)
To: Cornelia Huck
Cc: Paolo Bonzini, Christian Borntraeger, Heiko Carstens,
Martin Schwidefsky, KVM, linux-s390
On Wed, Jul 03, 2013 at 03:50:38PM +0200, Cornelia Huck wrote:
> Add new functions kvm_io_bus_{read,write}_cookie() that allows users of
> the kvm io infrastructure to use a cookie value to speed up lookup of a
> device on an io bus.
>
> kvm_io_bus_{read,write} now returns the index on the bus; existing callers
> have been fixed up to accept return codes > 0.
>
> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> ---
> arch/ia64/kvm/kvm-ia64.c | 2 +-
> arch/powerpc/kvm/powerpc.c | 4 +-
> arch/x86/kvm/x86.c | 6 +--
> include/linux/kvm_host.h | 4 ++
> virt/kvm/kvm_main.c | 102 ++++++++++++++++++++++++++++++++++++++-------
> 5 files changed, 97 insertions(+), 21 deletions(-)
>
> diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
> index 5b2dc0d..465ab54 100644
> --- a/arch/ia64/kvm/kvm-ia64.c
> +++ b/arch/ia64/kvm/kvm-ia64.c
> @@ -250,7 +250,7 @@ mmio:
> else
> r = kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, p->addr,
> p->size, &p->data);
> - if (r)
> + if (r < 0)
No need to change kvm_io_bus_(read|write) return value now. Just do
there:
r = __kvm_io_bus_write(bus, &range, val);
return r >=0 ? 0 : r;
> printk(KERN_ERR"kvm: No iodevice found! addr:%lx\n", p->addr);
> p->state = STATE_IORESP_READY;
>
> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
> index 6316ee3..26c44d0 100644
> --- a/arch/powerpc/kvm/powerpc.c
> +++ b/arch/powerpc/kvm/powerpc.c
> @@ -649,7 +649,7 @@ int kvmppc_handle_load(struct kvm_run *run, struct kvm_vcpu *vcpu,
>
> srcu_read_unlock(&vcpu->kvm->srcu, idx);
>
> - if (!ret) {
> + if (ret >= 0) {
> kvmppc_complete_mmio_load(vcpu, run);
> vcpu->mmio_needed = 0;
> return EMULATE_DONE;
> @@ -711,7 +711,7 @@ int kvmppc_handle_store(struct kvm_run *run, struct kvm_vcpu *vcpu,
>
> srcu_read_unlock(&vcpu->kvm->srcu, idx);
>
> - if (!ret) {
> + if (ret >= 0) {
> vcpu->mmio_needed = 0;
> return EMULATE_DONE;
> }
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 7d71c0f..d58744b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3860,7 +3860,7 @@ static int vcpu_mmio_write(struct kvm_vcpu *vcpu, gpa_t addr, int len,
> n = min(len, 8);
> if (!(vcpu->arch.apic &&
> !kvm_iodevice_write(&vcpu->arch.apic->dev, addr, n, v))
> - && kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, addr, n, v))
> + && (kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, addr, n, v) < 0))
> break;
> handled += n;
> addr += n;
> @@ -3880,7 +3880,7 @@ static int vcpu_mmio_read(struct kvm_vcpu *vcpu, gpa_t addr, int len, void *v)
> n = min(len, 8);
> if (!(vcpu->arch.apic &&
> !kvm_iodevice_read(&vcpu->arch.apic->dev, addr, n, v))
> - && kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, addr, n, v))
> + && (kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, addr, n, v) < 0))
> break;
> trace_kvm_mmio(KVM_TRACE_MMIO_READ, n, addr, *(u64 *)v);
> handled += n;
> @@ -4361,7 +4361,7 @@ static int kernel_pio(struct kvm_vcpu *vcpu, void *pd)
> r = kvm_io_bus_write(vcpu->kvm, KVM_PIO_BUS,
> vcpu->arch.pio.port, vcpu->arch.pio.size,
> pd);
> - return r;
> + return (r >= 0) ? 0 : r;
> }
>
> static int emulator_pio_in_out(struct kvm_vcpu *vcpu, int size,
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index e3aae6d..60e261c9 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -159,8 +159,12 @@ enum kvm_bus {
>
> int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> int len, const void *val);
> +int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> + int len, const void *val, long cookie);
> int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len,
> void *val);
> +int kvm_io_bus_read_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> + int len, void *val, long cookie);
> int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> int len, struct kvm_io_device *dev);
> int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx,
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 1580dd4..eca3e00 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -2863,11 +2863,30 @@ static int kvm_io_bus_get_first_dev(struct kvm_io_bus *bus,
> return off;
> }
>
> +static int __kvm_io_bus_write(struct kvm_io_bus *bus,
> + struct kvm_io_range *range, const void *val)
> +{
> + int idx;
> +
> + idx = kvm_io_bus_get_first_dev(bus, range->addr, range->len);
> + if (idx < 0)
> + return -EOPNOTSUPP;
> +
> + while (idx < bus->dev_count &&
> + kvm_io_bus_sort_cmp(range, &bus->range[idx]) == 0) {
> + if (!kvm_iodevice_write(bus->range[idx].dev, range->addr,
> + range->len, val))
> + return idx;
> + idx++;
> + }
> +
> + return -EOPNOTSUPP;
> +}
> +
> /* 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 idx;
> struct kvm_io_bus *bus;
> struct kvm_io_range range;
>
> @@ -2877,14 +2896,51 @@ int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> };
>
> bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
> - idx = kvm_io_bus_get_first_dev(bus, addr, len);
> + return __kvm_io_bus_write(bus, &range, val);
> +}
> +
> +/* kvm_io_bus_write_cookie - called under kvm->slots_lock */
> +int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> + int len, const void *val, long cookie)
> +{
> + struct kvm_io_bus *bus;
> + struct kvm_io_range range;
> +
> + range = (struct kvm_io_range) {
> + .addr = addr,
> + .len = len,
> + };
> +
> + bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
> +
> + /* First try the device referenced by cookie. */
> + if ((cookie >= 0) && (cookie < bus->dev_count) &&
> + (kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
> + if (!kvm_iodevice_write(bus->range[cookie].dev, addr, len,
> + val))
> + return cookie;
> +
> + /*
> + * cookie contained garbage; fall back to search and return the
> + * correct cookie value.
> + */
> + return __kvm_io_bus_write(bus, &range, val);
> +}
> +
> +static int __kvm_io_bus_read(struct kvm_io_bus *bus, struct kvm_io_range *range,
> + void *val)
> +{
> + int idx;
> +
> + idx = kvm_io_bus_get_first_dev(bus, range->addr, range->len);
> if (idx < 0)
> return -EOPNOTSUPP;
>
> while (idx < bus->dev_count &&
> kvm_io_bus_sort_cmp(&range, &bus->range[idx]) == 0) {
> - if (!kvm_iodevice_write(bus->range[idx].dev, addr, len, val))
> - return 0;
> + if (!kvm_iodevice_read(bus->range[idx].dev, range->addr,
> + range->len, val))
> + return idx;
> idx++;
> }
>
> @@ -2895,7 +2951,6 @@ int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> int len, void *val)
> {
> - int idx;
> struct kvm_io_bus *bus;
> struct kvm_io_range range;
>
> @@ -2905,18 +2960,35 @@ int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> };
>
> bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
> - idx = kvm_io_bus_get_first_dev(bus, addr, len);
> - if (idx < 0)
> - return -EOPNOTSUPP;
> + return __kvm_io_bus_read(bus, &range, val);
> +}
>
> - while (idx < bus->dev_count &&
> - kvm_io_bus_sort_cmp(&range, &bus->range[idx]) == 0) {
> - if (!kvm_iodevice_read(bus->range[idx].dev, addr, len, val))
> - return 0;
> - idx++;
> - }
> +/* kvm_io_bus_read_cookie - called under kvm->slots_lock */
> +int kvm_io_bus_read_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
> + int len, void *val, long cookie)
> +{
> + struct kvm_io_bus *bus;
> + struct kvm_io_range range;
>
> - return -EOPNOTSUPP;
> + range = (struct kvm_io_range) {
> + .addr = addr,
> + .len = len,
> + };
> +
> + bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
> +
> + /* First try the device referenced by cookie. */
> + if ((cookie >= 0) && (cookie < bus->dev_count) &&
> + (kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
> + if (!kvm_iodevice_read(bus->range[cookie].dev, addr, len,
> + val))
> + return cookie;
> +
> + /*
> + * cookie contained garbage; fall back to search and return the
> + * correct cookie value.
> + */
> + return __kvm_io_bus_read(bus, &range, val);
> }
>
> /* Caller must hold slots_lock. */
> --
> 1.8.2.2
--
Gleb.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] KVM: kvm-io: support cookies
2013-07-03 13:56 ` Gleb Natapov
@ 2013-07-03 14:14 ` Cornelia Huck
2013-07-03 14:26 ` Gleb Natapov
0 siblings, 1 reply; 6+ messages in thread
From: Cornelia Huck @ 2013-07-03 14:14 UTC (permalink / raw)
To: Gleb Natapov
Cc: Paolo Bonzini, Christian Borntraeger, Heiko Carstens,
Martin Schwidefsky, KVM, linux-s390
On Wed, 3 Jul 2013 16:56:42 +0300
Gleb Natapov <gleb@redhat.com> wrote:
> On Wed, Jul 03, 2013 at 03:50:38PM +0200, Cornelia Huck wrote:
> > Add new functions kvm_io_bus_{read,write}_cookie() that allows users of
> > the kvm io infrastructure to use a cookie value to speed up lookup of a
> > device on an io bus.
> >
> > kvm_io_bus_{read,write} now returns the index on the bus; existing callers
> > have been fixed up to accept return codes > 0.
> >
> > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> > ---
> > arch/ia64/kvm/kvm-ia64.c | 2 +-
> > arch/powerpc/kvm/powerpc.c | 4 +-
> > arch/x86/kvm/x86.c | 6 +--
> > include/linux/kvm_host.h | 4 ++
> > virt/kvm/kvm_main.c | 102 ++++++++++++++++++++++++++++++++++++++-------
> > 5 files changed, 97 insertions(+), 21 deletions(-)
> >
> > diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
> > index 5b2dc0d..465ab54 100644
> > --- a/arch/ia64/kvm/kvm-ia64.c
> > +++ b/arch/ia64/kvm/kvm-ia64.c
> > @@ -250,7 +250,7 @@ mmio:
> > else
> > r = kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, p->addr,
> > p->size, &p->data);
> > - if (r)
> > + if (r < 0)
> No need to change kvm_io_bus_(read|write) return value now. Just do
> there:
>
> r = __kvm_io_bus_write(bus, &range, val);
> return r >=0 ? 0 : r;
>
Well, if the index is not interesting for anything but the cookie code,
I can certainly drop it.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3 1/2] KVM: kvm-io: support cookies
2013-07-03 14:14 ` Cornelia Huck
@ 2013-07-03 14:26 ` Gleb Natapov
0 siblings, 0 replies; 6+ messages in thread
From: Gleb Natapov @ 2013-07-03 14:26 UTC (permalink / raw)
To: Cornelia Huck
Cc: Paolo Bonzini, Christian Borntraeger, Heiko Carstens,
Martin Schwidefsky, KVM, linux-s390
On Wed, Jul 03, 2013 at 04:14:39PM +0200, Cornelia Huck wrote:
> On Wed, 3 Jul 2013 16:56:42 +0300
> Gleb Natapov <gleb@redhat.com> wrote:
>
> > On Wed, Jul 03, 2013 at 03:50:38PM +0200, Cornelia Huck wrote:
> > > Add new functions kvm_io_bus_{read,write}_cookie() that allows users of
> > > the kvm io infrastructure to use a cookie value to speed up lookup of a
> > > device on an io bus.
> > >
> > > kvm_io_bus_{read,write} now returns the index on the bus; existing callers
> > > have been fixed up to accept return codes > 0.
> > >
> > > Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> > > ---
> > > arch/ia64/kvm/kvm-ia64.c | 2 +-
> > > arch/powerpc/kvm/powerpc.c | 4 +-
> > > arch/x86/kvm/x86.c | 6 +--
> > > include/linux/kvm_host.h | 4 ++
> > > virt/kvm/kvm_main.c | 102 ++++++++++++++++++++++++++++++++++++++-------
> > > 5 files changed, 97 insertions(+), 21 deletions(-)
> > >
> > > diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
> > > index 5b2dc0d..465ab54 100644
> > > --- a/arch/ia64/kvm/kvm-ia64.c
> > > +++ b/arch/ia64/kvm/kvm-ia64.c
> > > @@ -250,7 +250,7 @@ mmio:
> > > else
> > > r = kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, p->addr,
> > > p->size, &p->data);
> > > - if (r)
> > > + if (r < 0)
> > No need to change kvm_io_bus_(read|write) return value now. Just do
> > there:
> >
> > r = __kvm_io_bus_write(bus, &range, val);
> > return r >=0 ? 0 : r;
> >
>
> Well, if the index is not interesting for anything but the cookie code,
> I can certainly drop it.
It is certainly not right now.
--
Gleb.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-07-03 14:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-03 13:50 [PATCH v3 0/2] KVM: ioeventfd cookies Cornelia Huck
2013-07-03 13:50 ` [PATCH v3 1/2] KVM: kvm-io: support cookies Cornelia Huck
2013-07-03 13:56 ` Gleb Natapov
2013-07-03 14:14 ` Cornelia Huck
2013-07-03 14:26 ` Gleb Natapov
2013-07-03 13:50 ` [PATCH v3 2/2] KVM: s390: use cookies for ioeventfd Cornelia Huck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox