Skip to content

Commit 6f6fbe9

Browse files
Xiao Guangrongavikivity
authored andcommitted
KVM: x86: cleanup port-in/port-out emulated
Remove the same code between emulator_pio_in_emulated and emulator_pio_out_emulated Signed-off-by: Xiao Guangrong <[email protected]> Signed-off-by: Avi Kivity <[email protected]>
1 parent 1cb3f3a commit 6f6fbe9

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

arch/x86/kvm/x86.c

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,32 +4349,24 @@ static int kernel_pio(struct kvm_vcpu *vcpu, void *pd)
43494349
return r;
43504350
}
43514351

4352-
4353-
static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
4354-
int size, unsigned short port, void *val,
4355-
unsigned int count)
4352+
static int emulator_pio_in_out(struct kvm_vcpu *vcpu, int size,
4353+
unsigned short port, void *val,
4354+
unsigned int count, bool in)
43564355
{
4357-
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
4358-
4359-
if (vcpu->arch.pio.count)
4360-
goto data_avail;
4361-
4362-
trace_kvm_pio(0, port, size, count);
4356+
trace_kvm_pio(!in, port, size, count);
43634357

43644358
vcpu->arch.pio.port = port;
4365-
vcpu->arch.pio.in = 1;
4359+
vcpu->arch.pio.in = in;
43664360
vcpu->arch.pio.count = count;
43674361
vcpu->arch.pio.size = size;
43684362

43694363
if (!kernel_pio(vcpu, vcpu->arch.pio_data)) {
4370-
data_avail:
4371-
memcpy(val, vcpu->arch.pio_data, size * count);
43724364
vcpu->arch.pio.count = 0;
43734365
return 1;
43744366
}
43754367

43764368
vcpu->run->exit_reason = KVM_EXIT_IO;
4377-
vcpu->run->io.direction = KVM_EXIT_IO_IN;
4369+
vcpu->run->io.direction = in ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT;
43784370
vcpu->run->io.size = size;
43794371
vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE;
43804372
vcpu->run->io.count = count;
@@ -4383,36 +4375,37 @@ static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
43834375
return 0;
43844376
}
43854377

4386-
static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt,
4387-
int size, unsigned short port,
4388-
const void *val, unsigned int count)
4378+
static int emulator_pio_in_emulated(struct x86_emulate_ctxt *ctxt,
4379+
int size, unsigned short port, void *val,
4380+
unsigned int count)
43894381
{
43904382
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
4383+
int ret;
43914384

4392-
trace_kvm_pio(1, port, size, count);
4393-
4394-
vcpu->arch.pio.port = port;
4395-
vcpu->arch.pio.in = 0;
4396-
vcpu->arch.pio.count = count;
4397-
vcpu->arch.pio.size = size;
4398-
4399-
memcpy(vcpu->arch.pio_data, val, size * count);
4385+
if (vcpu->arch.pio.count)
4386+
goto data_avail;
44004387

4401-
if (!kernel_pio(vcpu, vcpu->arch.pio_data)) {
4388+
ret = emulator_pio_in_out(vcpu, size, port, val, count, true);
4389+
if (ret) {
4390+
data_avail:
4391+
memcpy(val, vcpu->arch.pio_data, size * count);
44024392
vcpu->arch.pio.count = 0;
44034393
return 1;
44044394
}
44054395

4406-
vcpu->run->exit_reason = KVM_EXIT_IO;
4407-
vcpu->run->io.direction = KVM_EXIT_IO_OUT;
4408-
vcpu->run->io.size = size;
4409-
vcpu->run->io.data_offset = KVM_PIO_PAGE_OFFSET * PAGE_SIZE;
4410-
vcpu->run->io.count = count;
4411-
vcpu->run->io.port = port;
4412-
44134396
return 0;
44144397
}
44154398

4399+
static int emulator_pio_out_emulated(struct x86_emulate_ctxt *ctxt,
4400+
int size, unsigned short port,
4401+
const void *val, unsigned int count)
4402+
{
4403+
struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
4404+
4405+
memcpy(vcpu->arch.pio_data, val, size * count);
4406+
return emulator_pio_in_out(vcpu, size, port, (void *)val, count, false);
4407+
}
4408+
44164409
static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg)
44174410
{
44184411
return kvm_x86_ops->get_segment_base(vcpu, seg);

0 commit comments

Comments
 (0)