From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 01/13] KVM: x86: Refactor I/O emulation helpers to provide vcpu-only variant
Date: Wed, 26 Feb 2020 16:16:35 +0100 [thread overview]
Message-ID: <87h7zdjs4s.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <20200218232953.5724-2-sean.j.christopherson@intel.com>
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
next prev parent reply other threads:[~2020-02-26 15:16 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-18 23:29 [PATCH v2 00/13] KVM: x86: Allow userspace to disable the emulator Sean Christopherson
2020-02-18 23:29 ` [PATCH v2 01/13] KVM: x86: Refactor I/O emulation helpers to provide vcpu-only variant Sean Christopherson
2020-02-26 15:16 ` Vitaly Kuznetsov [this message]
2020-02-18 23:29 ` [PATCH v2 02/13] KVM: x86: Explicitly pass an exception struct to check_intercept Sean Christopherson
2020-02-18 23:29 ` [PATCH v2 03/13] KVM: x86: Move emulation-only helpers to emulate.c Sean Christopherson
2020-02-26 15:23 ` Vitaly Kuznetsov
2020-02-18 23:29 ` [PATCH v2 04/13] KVM: x86: Refactor R/W page helper to take the emulation context Sean Christopherson
2020-02-26 15:24 ` Vitaly Kuznetsov
2020-02-18 23:29 ` [PATCH v2 05/13] KVM: x86: Refactor emulated exception injection to take the emul context Sean Christopherson
2020-02-26 15:25 ` Vitaly Kuznetsov
2020-02-18 23:29 ` [PATCH v2 06/13] KVM: x86: Refactor emulate tracepoint to explicitly take context Sean Christopherson
2020-02-26 17:11 ` Vitaly Kuznetsov
2020-03-03 16:48 ` Sean Christopherson
2020-03-03 17:29 ` Paolo Bonzini
2020-03-03 17:42 ` Sean Christopherson
2020-03-03 17:44 ` Paolo Bonzini
2020-02-18 23:29 ` [PATCH v2 07/13] KVM: x86: Refactor init_emulate_ctxt() " Sean Christopherson
2020-02-26 17:13 ` Vitaly Kuznetsov
2020-02-18 23:29 ` [PATCH v2 08/13] KVM: x86: Dynamically allocate per-vCPU emulation context Sean Christopherson
2020-02-26 17:29 ` Vitaly Kuznetsov
2020-03-03 10:26 ` Paolo Bonzini
2020-03-03 14:57 ` Sean Christopherson
2020-03-03 16:18 ` Vitaly Kuznetsov
2020-03-03 16:52 ` Sean Christopherson
2020-02-18 23:29 ` [PATCH v2 09/13] KVM: x86: Move kvm_emulate.h into KVM's private directory Sean Christopherson
2020-02-26 17:38 ` Vitaly Kuznetsov
2020-03-03 10:27 ` Paolo Bonzini
2020-02-18 23:29 ` [PATCH v2 10/13] KVM: x86: Shrink the usercopy region of the emulation context Sean Christopherson
2020-02-26 17:51 ` Vitaly Kuznetsov
2020-03-02 18:40 ` Paolo Bonzini
2020-03-02 19:19 ` Sean Christopherson
2020-03-02 19:13 ` Sean Christopherson
2020-02-18 23:29 ` [PATCH v2 11/13] KVM: x86: Add helper to "handle" internal emulation error Sean Christopherson
2020-02-26 17:52 ` Vitaly Kuznetsov
2020-02-18 23:29 ` [PATCH v2 12/13] KVM: x86: Add variable to control existence of emulator Sean Christopherson
2020-02-26 18:01 ` Vitaly Kuznetsov
2020-02-18 23:29 ` [PATCH v2 13/13] KVM: x86: Allow userspace to disable the kernel's emulator Sean Christopherson
2020-03-02 18:42 ` [PATCH v2 00/13] KVM: x86: Allow userspace to disable the emulator Paolo Bonzini
2020-03-02 20:02 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h7zdjs4s.fsf@vitty.brq.redhat.com \
--to=vkuznets@redhat.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=wanpengli@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).