lkml.org 
[lkml]   [2020]   [Feb]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2 01/13] KVM: x86: Refactor I/O emulation helpers to provide vcpu-only variant
Date
Sean Christopherson <sean.j.christopherson@intel.com> writes:

> Add variants of the I/O helpers that take a vCPU instead of an emulation
> context. This will eventually allow KVM to limit use of the emulation
> context to the full emulation path.
>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
> arch/x86/kvm/x86.c | 39 ++++++++++++++++++++++++---------------
> 1 file changed, 24 insertions(+), 15 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index fbabb2f06273..6554abef631f 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -5959,11 +5959,9 @@ static int emulator_pio_in_out(struct kvm_vcpu *vcpu, int size,
> return 0;
> }
>
> -static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
> - int size, unsigned short port, void *val,
> - unsigned int count)
> +static int emulator_pio_in(struct kvm_vcpu *vcpu, int size,
> + unsigned short port, void *val, unsigned int count)
> {
> - struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
> int ret;
>
> if (vcpu->arch.pio.count)
> @@ -5983,17 +5981,30 @@ static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
> return 0;
> }
>
> -static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt,
> - int size, unsigned short port,
> - const void *val, unsigned int count)
> +static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
> + int size, unsigned short port, void *val,
> + unsigned int count)
> {
> - struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
> + return emulator_pio_in(emul_to_vcpu(ctxt), size, port, val, count);
>
> +}
> +
> +static int emulator_pio_out(struct kvm_vcpu *vcpu, int size,
> + unsigned short port, const void *val,
> + unsigned int count)
> +{
> memcpy(vcpu->arch.pio_data, val, size * count);
> trace_kvm_pio(KVM_PIO_OUT, port, size, count, vcpu->arch.pio_data);
> return emulator_pio_in_out(vcpu, size, port, (void *)val, count, false);
> }
>
> +static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt,
> + int size, unsigned short port,
> + const void *val, unsigned int count)
> +{
> + return emulator_pio_out(emul_to_vcpu(ctxt), size, port, val, count);
> +}
> +
> static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg)
> {
> return kvm_x86_ops->get_segment_base(vcpu, seg);
> @@ -6930,8 +6941,8 @@ static int kvm_fast_pio_out(struct kvm_vcpu *vcpu, int size,
> unsigned short port)
> {
> unsigned long val = kvm_rax_read(vcpu);
> - int ret = emulator_pio_out_emulated(&vcpu->arch.emulate_ctxt,
> - size, port, &val, 1);
> + int ret = emulator_pio_out(vcpu, size, port, &val, 1);
> +
> if (ret)
> return ret;
>
> @@ -6967,11 +6978,10 @@ static int complete_fast_pio_in(struct kvm_vcpu *vcpu)
> val = (vcpu->arch.pio.size < 4) ? kvm_rax_read(vcpu) : 0;
>
> /*
> - * Since vcpu->arch.pio.count == 1 let emulator_pio_in_emulated perform
> + * Since vcpu->arch.pio.count == 1 let emulator_pio_in perform
> * the copy and tracing
> */
> - emulator_pio_in_emulated(&vcpu->arch.emulate_ctxt, vcpu->arch.pio.size,
> - vcpu->arch.pio.port, &val, 1);
> + emulator_pio_in(vcpu, vcpu->arch.pio.size, vcpu->arch.pio.port, &val, 1);
> kvm_rax_write(vcpu, val);
>
> return kvm_skip_emulated_instruction(vcpu);
> @@ -6986,8 +6996,7 @@ static int kvm_fast_pio_in(struct kvm_vcpu *vcpu, int size,
> /* For size less than 4 we merge, else we zero extend */
> val = (size < 4) ? kvm_rax_read(vcpu) : 0;
>
> - ret = emulator_pio_in_emulated(&vcpu->arch.emulate_ctxt, size, port,
> - &val, 1);
> + ret = emulator_pio_in(vcpu, size, port, &val, 1);
> if (ret) {
> kvm_rax_write(vcpu, val);
> return ret;

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

--
Vitaly

\
 
 \ /
  Last update: 2020-02-26 16:17    [W:0.326 / U:0.360 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site