Skip to content

Commit

Permalink
KVM: arm64: Move skip_host_instruction to adjust_pc.h
Browse files Browse the repository at this point in the history
Move function for skipping host instruction in the host trap handler to
a header file containing analogical helpers for guests.

Signed-off-by: David Brazdil <dbrazdil@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20201208142452.87237-7-dbrazdil@google.com
  • Loading branch information
David Brazdil authored and Marc Zyngier committed Dec 22, 2020
1 parent e6829e0 commit 860a4c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 9 additions & 0 deletions arch/arm64/kvm/hyp/include/hyp/adjust_pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,13 @@ static inline void __adjust_pc(struct kvm_vcpu *vcpu)
}
}

/*
* Skip an instruction while host sysregs are live.
* Assumes host is always 64-bit.
*/
static inline void kvm_skip_host_instr(void)
{
write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR);
}

#endif
12 changes: 2 additions & 10 deletions arch/arm64/kvm/hyp/nvhe/hyp-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ static void default_host_smc_handler(struct kvm_cpu_context *host_ctxt)
__kvm_hyp_host_forward_smc(host_ctxt);
}

static void skip_host_instruction(void)
{
write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR);
}

static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
{
bool handled;
Expand All @@ -170,11 +165,8 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
if (!handled)
default_host_smc_handler(host_ctxt);

/*
* Unlike HVC, the return address of an SMC is the instruction's PC.
* Move the return address past the instruction.
*/
skip_host_instruction();
/* SMC was trapped, move ELR past the current PC. */
kvm_skip_host_instr();
}

void handle_trap(struct kvm_cpu_context *host_ctxt)
Expand Down

0 comments on commit 860a4c3

Please sign in to comment.