Skip to content

Commit 3a55852

Browse files
committed
kvm: decode KVM_EXIT_MMIO related fields of kvm_run struct
* src/kvm.c (kvm_run_structure_decode_mmio): New function. (kvm_run_structure_decode_main) <case KVM_EXIT_MMIO>: Decode the area of kvm_run struct. * tests/ioctl_kvm_run_common.c (__asm__): Add the instructions accessing address where no memory backing store to code. (run_kvm): Raise an error only when getting unexpected MMIO exit. * tests/ioctl_kvm_run_auxstr_vcpu_more.c (print_KVM_RUN_MORE): Print mmio members of kvm_run struct. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
1 parent db735b1 commit 3a55852

3 files changed

Lines changed: 53 additions & 11 deletions

File tree

src/kvm.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,22 @@ kvm_run_structure_decode_io(struct tcb *tcp,
465465
tprint_struct_end();
466466
}
467467

468+
static void
469+
kvm_run_structure_decode_mmio(struct tcb *tcp,
470+
struct kvm_run *state)
471+
{
472+
tprints_field_name("mmio");
473+
tprint_struct_begin();
474+
PRINT_FIELD_0X(state->mmio, phys_addr);
475+
tprint_struct_next();
476+
PRINT_FIELD_ARRAY(state->mmio, data, tcp, print_xint_array_member);
477+
tprint_struct_next();
478+
PRINT_FIELD_U(state->mmio, len);
479+
tprint_struct_next();
480+
PRINT_FIELD_U(state->mmio, is_write);
481+
tprint_struct_end();
482+
}
483+
468484
static void
469485
kvm_run_structure_decode_main(struct tcb *tcp,
470486
struct kvm_run *state_in,
@@ -522,6 +538,9 @@ kvm_run_structure_decode_main(struct tcb *tcp,
522538
case KVM_EXIT_IO:
523539
DECODE_UNION(kvm_run_structure_decode_io(tcp, state_out));
524540
break;
541+
case KVM_EXIT_MMIO:
542+
DECODE_UNION(kvm_run_structure_decode_mmio(tcp, state_out));
543+
break;
525544
}
526545

527546
tprint_struct_end();

tests/ioctl_kvm_run_auxstr_vcpu_more.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ print_KVM_RUN_MORE(const int fd, const char *const dev, const char *str,
3232
run_after->io.direction == KVM_EXIT_IO_IN? "KVM_EXIT_IO_IN": "KVM_EXIT_IO_OUT",
3333
run_after->io.port, run_after->io.count, run_after->io.data_offset);
3434
break;
35+
case KVM_EXIT_MMIO:
36+
printf(", {mmio={phys_addr=%#016llx, data=[%#0x, %#0x, %#0x, %#0x, %#0x, %#0x, %#0x, %#0x], len=%u, is_write=%u}}",
37+
run_after->mmio.phys_addr,
38+
run_after->mmio.data[0], run_after->mmio.data[1],
39+
run_after->mmio.data[2], run_after->mmio.data[3],
40+
run_after->mmio.data[4], run_after->mmio.data[5],
41+
run_after->mmio.data[6], run_after->mmio.data[7],
42+
run_after->mmio.len,
43+
run_after->mmio.is_write);
44+
break;
3545
}
3646

3747
puts("}");

tests/ioctl_kvm_run_common.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ __asm__(
8080
" mov $0x03f8, %dx \n"
8181
" movb $'\n', %al \n"
8282
" out %al, (%dx) \n"
83+
" mov $0x2000, %dx \n"
84+
" movb $0xdf, (%edx) \n"
8385
" hlt \n"
8486
# ifdef __x86_64__
8587
".code64 \n"
@@ -91,6 +93,11 @@ __asm__(
9193
"code_size: \n"
9294
" .short . - code \n"
9395
".size code_size, . - code_size \n"
96+
#ifdef __x86_64__
97+
".code64 \n"
98+
#else
99+
".code32 \n"
100+
#endif
94101
);
95102

96103
static void
@@ -237,17 +244,23 @@ run_kvm(const int vcpu_fd, struct kvm_run *const run, const size_t mmap_size,
237244
error_msg_and_fail("unhandled KVM_EXIT_IO");
238245
break;
239246
case KVM_EXIT_MMIO:
240-
error_msg_and_fail("Got an unexpected MMIO exit:"
241-
" phys_addr %#llx,"
242-
" data %02x %02x %02x %02x"
243-
" %02x %02x %02x %02x,"
244-
" len %u, is_write %hhu",
245-
(unsigned long long) run->mmio.phys_addr,
246-
run->mmio.data[0], run->mmio.data[1],
247-
run->mmio.data[2], run->mmio.data[3],
248-
run->mmio.data[4], run->mmio.data[5],
249-
run->mmio.data[6], run->mmio.data[7],
250-
run->mmio.len, run->mmio.is_write);
247+
if (!(p == NULL
248+
&& run->mmio.phys_addr == 0x2000
249+
&& run->mmio.data[0] == 0xdf
250+
&& run->mmio.len == 1
251+
&& run->mmio.is_write == 1))
252+
error_msg_and_fail("Got an unexpected MMIO exit:"
253+
" phys_addr %#llx,"
254+
" data %02x %02x %02x %02x"
255+
" %02x %02x %02x %02x,"
256+
" len %u, is_write %hhu\n",
257+
(unsigned long long) run->mmio.phys_addr,
258+
run->mmio.data[0], run->mmio.data[1],
259+
run->mmio.data[2], run->mmio.data[3],
260+
run->mmio.data[4], run->mmio.data[5],
261+
run->mmio.data[6], run->mmio.data[7],
262+
run->mmio.len, run->mmio.is_write);
263+
break;
251264
case KVM_EXIT_FAIL_ENTRY:
252265
error_msg_and_fail("Got an unexpected FAIL_ENTRY exit:"
253266
" hardware_entry_failure_reason %" PRI__x64,

0 commit comments

Comments
 (0)