2013-08-27 13:41:53

by Paolo Bonzini

[permalink] [raw]
Subject: [PATCH 0/3] Trivial KVM patches for 3.12

Gleb,

these are fixups for the patches I sent on July 31. It would
be nice to have them for the next merge window.

Thanks,

Paolo

Paolo Bonzini (3):
KVM: rename __kvm_io_bus_sort_cmp to kvm_io_bus_cmp
KVM: vmx: count exits to userspace during invalid guest emulation
KVM: x86: add comments where MMIO does not return to the emulator

arch/x86/kvm/vmx.c | 1 +
arch/x86/kvm/x86.c | 7 +++++--
virt/kvm/kvm_main.c | 16 ++++++++--------
3 files changed, 14 insertions(+), 10 deletions(-)

--
1.8.3.1


2013-08-27 13:41:57

by Paolo Bonzini

[permalink] [raw]
Subject: [PATCH 1/3] KVM: rename __kvm_io_bus_sort_cmp to kvm_io_bus_cmp

This is the type-safe comparison function, so the double-underscore is
not related.

Signed-off-by: Paolo Bonzini <[email protected]>
---
virt/kvm/kvm_main.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c6c8bbe..f7e4334 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2815,8 +2815,8 @@ static void kvm_io_bus_destroy(struct kvm_io_bus *bus)
kfree(bus);
}

-static inline int __kvm_io_bus_sort_cmp(const struct kvm_io_range *r1,
- const struct kvm_io_range *r2)
+static inline int kvm_io_bus_cmp(const struct kvm_io_range *r1,
+ const struct kvm_io_range *r2)
{
if (r1->addr < r2->addr)
return -1;
@@ -2827,7 +2827,7 @@ static inline int __kvm_io_bus_sort_cmp(const struct kvm_io_range *r1,

static int kvm_io_bus_sort_cmp(const void *p1, const void *p2)
{
- return __kvm_io_bus_sort_cmp(p1, p2);
+ return kvm_io_bus_cmp(p1, p2);
}

static int kvm_io_bus_insert_dev(struct kvm_io_bus *bus, struct kvm_io_device *dev,
@@ -2863,7 +2863,7 @@ static int kvm_io_bus_get_first_dev(struct kvm_io_bus *bus,

off = range - bus->range;

- while (off > 0 && __kvm_io_bus_sort_cmp(&key, &bus->range[off-1]) == 0)
+ while (off > 0 && kvm_io_bus_cmp(&key, &bus->range[off-1]) == 0)
off--;

return off;
@@ -2879,7 +2879,7 @@ static int __kvm_io_bus_write(struct kvm_io_bus *bus,
return -EOPNOTSUPP;

while (idx < bus->dev_count &&
- __kvm_io_bus_sort_cmp(range, &bus->range[idx]) == 0) {
+ kvm_io_bus_cmp(range, &bus->range[idx]) == 0) {
if (!kvm_iodevice_write(bus->range[idx].dev, range->addr,
range->len, val))
return idx;
@@ -2923,7 +2923,7 @@ int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,

/* First try the device referenced by cookie. */
if ((cookie >= 0) && (cookie < bus->dev_count) &&
- (__kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
+ (kvm_io_bus_cmp(&range, &bus->range[cookie]) == 0))
if (!kvm_iodevice_write(bus->range[cookie].dev, addr, len,
val))
return cookie;
@@ -2945,7 +2945,7 @@ static int __kvm_io_bus_read(struct kvm_io_bus *bus, struct kvm_io_range *range,
return -EOPNOTSUPP;

while (idx < bus->dev_count &&
- __kvm_io_bus_sort_cmp(range, &bus->range[idx]) == 0) {
+ kvm_io_bus_cmp(range, &bus->range[idx]) == 0) {
if (!kvm_iodevice_read(bus->range[idx].dev, range->addr,
range->len, val))
return idx;
@@ -2989,7 +2989,7 @@ int kvm_io_bus_read_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,

/* First try the device referenced by cookie. */
if ((cookie >= 0) && (cookie < bus->dev_count) &&
- (__kvm_io_bus_sort_cmp(&range, &bus->range[cookie]) == 0))
+ (kvm_io_bus_cmp(&range, &bus->range[cookie]) == 0))
if (!kvm_iodevice_read(bus->range[cookie].dev, addr, len,
val))
return cookie;
--
1.8.3.1

2013-08-27 13:42:03

by Paolo Bonzini

[permalink] [raw]
Subject: [PATCH 3/3] KVM: x86: add comments where MMIO does not return to the emulator

Support for single-step in the emulator (new in 3.12) does not work for
MMIO or PIO writes, because they are completed without returning to
the emulator. This is not worse than what we had in 3.11; still, add
comments so that the issue is not forgotten.

Signed-off-by: Paolo Bonzini <[email protected]>
---
arch/x86/kvm/x86.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 668f19a..3625798 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5122,9 +5122,10 @@ restart:
inject_emulated_exception(vcpu);
r = EMULATE_DONE;
} else if (vcpu->arch.pio.count) {
- if (!vcpu->arch.pio.in)
+ if (!vcpu->arch.pio.in) {
+ /* FIXME: return into emulator if single-stepping. */
vcpu->arch.pio.count = 0;
- else {
+ } else {
writeback = false;
vcpu->arch.complete_userspace_io = complete_emulated_pio;
}
@@ -6154,6 +6155,8 @@ static int complete_emulated_mmio(struct kvm_vcpu *vcpu)

if (vcpu->mmio_cur_fragment == vcpu->mmio_nr_fragments) {
vcpu->mmio_needed = 0;
+
+ /* FIXME: return into emulator if single-stepping. */
if (vcpu->mmio_is_write)
return 1;
vcpu->mmio_read_completed = 1;
--
1.8.3.1

2013-08-27 13:42:27

by Paolo Bonzini

[permalink] [raw]
Subject: [PATCH 2/3] KVM: vmx: count exits to userspace during invalid guest emulation

These will happen due to MMIO.

Suggested-by: Gleb Natapov @[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
---
arch/x86/kvm/vmx.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 57b4e12..1f1da43 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -5485,6 +5485,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
err = emulate_instruction(vcpu, EMULTYPE_NO_REEXECUTE);

if (err == EMULATE_USER_EXIT) {
+ ++vcpu->stat.mmio_exits;
ret = 0;
goto out;
}
--
1.8.3.1

2013-08-28 06:40:16

by Gleb Natapov

[permalink] [raw]
Subject: Re: [PATCH 0/3] Trivial KVM patches for 3.12

On Tue, Aug 27, 2013 at 03:41:40PM +0200, Paolo Bonzini wrote:
> Gleb,
>
> these are fixups for the patches I sent on July 31. It would
> be nice to have them for the next merge window.
>
> Thanks,
>
Applied, thanks.

> Paolo
>
> Paolo Bonzini (3):
> KVM: rename __kvm_io_bus_sort_cmp to kvm_io_bus_cmp
> KVM: vmx: count exits to userspace during invalid guest emulation
> KVM: x86: add comments where MMIO does not return to the emulator
>
> arch/x86/kvm/vmx.c | 1 +
> arch/x86/kvm/x86.c | 7 +++++--
> virt/kvm/kvm_main.c | 16 ++++++++--------
> 3 files changed, 14 insertions(+), 10 deletions(-)
>
> --
> 1.8.3.1

--
Gleb.