remove kvm vmap usage
cover remove kvm vmap usage
Remove the vmap usage from kvm, this is needed both for ksm and get_user_pages != write.
PATCH 1/2 KVM: introducing kvm_read_guest_virt, kvm_write_guest_virt.
This commit change the name of emulator_read_std into kvm_read_guest_virt, and add new function name kvm_write_guest_virt that allow writing into a guest virtual address.
--- arch/x86/include/asm/kvm_host.h | 4 --- arch/x86/kvm/x86.c | 56 +++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 18 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -4
@@ -608,10 +608,6 @@ void kvm_inject_nmi(struct kvm_vcpu *vcpu);void fx_init (struct kvm_vcpu *vcpu); -int emulator_read_std (unsigned long addr, -void *val, -unsigned int bytes, -struct kvm_vcpu *vcpu); int emulator_write_emulated(unsigned long addr, const void *val, unsigned int bytes,
arch/x86/kvm/x86.c +42 -14
101 lines not on this page · raw message
Signature · 1 line
1.6.1
PATCH 2/2 KVM: remove the vmap usage
--- arch/x86/kvm/x86.c | 62 +++++++++----------------------------------- include/linux/kvm_types.h | 3 +- 2 files changed, 14 insertions(+), 51 deletions(-)
arch/x86/kvm/x86.c +13 -49
@@ -2368,40 +2368,19 @@ int emulate_instruction(struct kvm_vcpu *vcpu, }EXPORT_SYMBOL_GPL (emulate_instruction); -static void free_pio_guest_pages (struct kvm_vcpu *vcpu) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (vcpu->arch.pio.guest_pages); ++i) -if (vcpu->arch.pio.guest_pages[i]) { -kvm_release_page_dirty (vcpu->arch.pio.guest_pages[i]); - vcpu->arch.pio.guest_pages[i] =NULL ; - } -} -static int pio_copy_data (struct kvm_vcpu *vcpu) {void *p = vcpu->arch.pio_data; -void *q; +gva_t q = vcpu->arch.pio.guest_gva;unsigned bytes; -int nr_pages = vcpu->arch.pio.guest_pages[1 ] ?2 :1 ; +int ret; - q =vmap (vcpu->arch.pio.guest_pages, nr_pages,VM_READ |VM_WRITE , -PAGE_KERNEL ); -if (!q) { -free_pio_guest_pages (vcpu); -return -ENOMEM ; - } - q += vcpu->arch.pio.guest_page_offset; bytes = vcpu->arch.pio.size * vcpu->arch.pio.cur_count;if (vcpu->arch.pio.in) -memcpy (q, p, bytes); + ret =kvm_write_guest_virt (q, p, bytes, vcpu);else -memcpy (p, q, bytes); - q -= vcpu->arch.pio.guest_page_offset; -vunmap (q); -free_pio_guest_pages (vcpu); -return 0 ; + ret =kvm_read_guest_virt (q, p, bytes, vcpu); +return ret; }int complete_pio (struct kvm_vcpu *vcpu)
@@ -2512,7 +2491,6 @@ int kvm_emulate_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, vcpu->arch.pio.in = in; vcpu->arch.pio.string =0 ; vcpu->arch.pio.down =0 ; - vcpu->arch.pio.guest_page_offset =0 ; vcpu->arch.pio.rep =0 ;if (vcpu->run->io.direction ==KVM_EXIT_IO_IN )
@@ -2540,9 +2518,7 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, gva_t address, int rep, unsigned port) { unsigned now, in_page; -int i, ret =0 ; -int nr_pages =1 ; -struct page *page; +int ret =0 ;struct kvm_io_device *pio_dev; vcpu->run->exit_reason =KVM_EXIT_IO ;
@@ -2554,7 +2530,6 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in, vcpu->arch.pio.in = in; vcpu->arch.pio.string =1 ; vcpu->arch.pio.down = down; - vcpu->arch.pio.guest_page_offset =offset_in_page (address); vcpu->arch.pio.rep = rep;if (vcpu->run->io.direction ==KVM_EXIT_IO_IN )
@@ -2574,15 +2549,8 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,else in_page =offset_in_page (address) + size; now =min (count, (unsigned long )in_page / size); -if (!now) { -/* -* String I/O straddles page boundary. Pin two guest pages -* so that we satisfy atomicity constraints. Do just one -* transaction to avoid complexity. -*/ - nr_pages =2 ; +if (!now) now =1 ; - }if (down) {/* * String I/O in reverse. Yuck. Kill the guest, fix later.
@@ -2597,15 +2565,7 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,if (vcpu->arch.pio.cur_count == vcpu->arch.pio.count) kvm_x86_ops->skip_emulated_instruction (vcpu); -for (i =0 ; i < nr_pages; ++i) { - page =gva_to_page (vcpu, address + i *PAGE_SIZE ); - vcpu->arch.pio.guest_pages[i] = page; -if (!page) { -kvm_inject_gp (vcpu,0 ); -free_pio_guest_pages (vcpu); -return 1 ; - } - } + vcpu->arch.pio.guest_gva = address; pio_dev = vcpu_find_pio_dev(vcpu, port, vcpu->arch.pio.cur_count,
@@ -2613,7 +2573,11 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,if (!vcpu->arch.pio.in) {/* string PIO write */ ret =pio_copy_data (vcpu); -if (ret >=0 && pio_dev) { +if (ret ==X86EMUL_PROPAGATE_FAULT ) { +kvm_inject_gp (vcpu,0 ); +return 1 ; + } +if (ret ==0 && pio_dev) {pio_string_write (pio_dev, vcpu);complete_pio (vcpu);if (vcpu->arch.pio.count ==0 )
include/linux/kvm_types.h +1 -2
@@ -43,8 +43,7 @@ typedef hfn_t pfn_t;struct kvm_pio_request {unsigned long count;int cur_count; -struct page *guest_pages[2 ]; -unsigned guest_page_offset; +gva_t guest_gva;int in;int port;int size;
Signature · 1 line
1.6.1
Quoted 7 lines · Izik Eidus
Remove the vmap usage from kvm, this is needed both for ksm and
get_user_pages!= write.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Ok so for ksm things are now all right, actully i could live without this vmap as well, beacuse ksm check the page _count and every call to gva_to_page should increase it.
anyway before i continue with the kmap removing (again ksm doesnt need it, only get_user_pages != write) does we really want to go that way?
even for the get_user_pages case we can live with the write = 0, if before each kmap_atomic we will call get_user_pages (write = 1), so the page inside apic_page and time_page and what so ever would be safe (when ksm will come to merge that page it will skip it with the page count check)
Avi Kivity
AppliedQuoted 3 lines · Izik Eidus
Remove the vmap usage from kvm, this is needed both for ksm and
get_user_pages!= write.
applied, thanks.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.