xen/arm64: io: Emulate instructions (with invalid ISS) on MMIO region
authorAyan Kumar Halder <ayan.kumar.halder@xilinx.com>
Thu, 17 Mar 2022 14:00:44 +0000 (14:00 +0000)
committerStefano Stabellini <stefano.stabellini@xilinx.com>
Sat, 19 Mar 2022 04:17:13 +0000 (21:17 -0700)
commit5e9c429ad41f03740817ed370119f9f9f2a3a68f
treef6604bfd333920948e47c85c7103091cbd7cc5dd
parent6974c75180f1aad44e5428eabf2396b2b50fb0e4
xen/arm64: io: Emulate instructions (with invalid ISS) on MMIO region

When an instruction is trapped in Xen due to translation fault, Xen
checks if the ISS is invalid (for data abort) or it is an instruction
abort. If so, Xen tries to resolve the translation fault using p2m page
tables. In case of data abort, Xen will try to map the mmio region to
the guest (ie tries to emulate the mmio region).

If the ISS is not valid and it is a data abort, then Xen tries to
decode the instruction. In case of ioreq, Xen  saves the decoding state,
rn and imm9 to vcpu_io. Whenever the vcpu handles the ioreq successfully,
it will read the decoding state to determine if the instruction decoded
was a ldr/str post indexing (ie INSTR_LDR_STR_POSTINDEXING). If so, it
uses these details to post increment rn.

In case of mmio handler, if the mmio operation was successful, then Xen
retrives the decoding state, rn and imm9. For state ==
INSTR_LDR_STR_POSTINDEXING, Xen will update rn.

If there is an error encountered while decoding/executing the instruction,
Xen will forward the abort to the guest.

Also, the logic to infer the type of instruction has been moved from
try_handle_mmio() to try_decode_instruction() which is called before.
try_handle_mmio() is solely responsible for handling the mmio operation.

Signed-off-by: Ayan Kumar Halder <ayankuma@xilinx.com>
Tested-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Julien Grall <jgrall@amazon.com>
xen/arch/arm/arm32/traps.c
xen/arch/arm/arm64/traps.c
xen/arch/arm/decode.c
xen/arch/arm/include/asm/domain.h
xen/arch/arm/include/asm/mmio.h
xen/arch/arm/include/asm/traps.h
xen/arch/arm/io.c
xen/arch/arm/ioreq.c
xen/arch/arm/traps.c
xen/arch/x86/include/asm/domain.h
xen/include/xen/sched.h