[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87h7zdjs4s.fsf@vitty.brq.redhat.com>
Date: Wed, 26 Feb 2020 16:16:35 +0100
From: Vitaly Kuznetsov <vkuznets@...hat.com>
To: Sean Christopherson <sean.j.christopherson@...el.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 01/13] KVM: x86: Refactor I/O emulation helpers to provide vcpu-only variant
Sean Christopherson <sean.j.christopherson@...el.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@...el.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@...hat.com>
--
Vitaly
Powered by blists - more mailing lists