KVM: x86: Refactor I/O emulation helpers to provide vcpu-only variant
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> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
2bde08f9f5
commit
2e3bb4d886
@ -5904,11 +5904,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)
|
||||
@ -5928,15 +5926,28 @@ data_avail:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
|
||||
int size, unsigned short port, void *val,
|
||||
unsigned int count)
|
||||
{
|
||||
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)
|
||||
{
|
||||
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
|
||||
|
||||
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);
|
||||
return emulator_pio_out(emul_to_vcpu(ctxt), size, port, val, count);
|
||||
}
|
||||
|
||||
static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg)
|
||||
@ -6891,8 +6902,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;
|
||||
|
||||
@ -6928,11 +6939,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);
|
||||
@ -6947,8 +6957,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;
|
||||
|
Loading…
Reference in New Issue
Block a user