From: Christoffer Dall <cdall@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: kvm@vger.kernel.org, julien.thierry@arm.com,
marc.zyngier@arm.com, Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
open list <linux-kernel@vger.kernel.org>,
Dave Martin <Dave.Martin@arm.com>,
linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v1 2/2] kvm: arm64: handle single-step of hyp emulated mmio instructions
Date: Thu, 23 Nov 2017 13:39:01 +0100 [thread overview]
Message-ID: <20171123123901.GZ28855@cbox> (raw)
In-Reply-To: <20171123121134.11050-3-alex.bennee@linaro.org>
On Thu, Nov 23, 2017 at 12:11:34PM +0000, Alex Bennée wrote:
> There is a fast-path of MMIO emulation inside hyp mode. The handling
> of single-step is broadly the same as kvm_arm_handle_step_debug()
> except we just setup ESR/HSR so handle_exit() does the correct thing
> as we exit.
>
> For the case of an emulated illegal access causing an SError we will
> exit via the ARM_EXCEPTION_EL1_SERROR path in handle_exit(). We behave
> as we would during a real SError and clear the DBG_SPSR_SS bit for the
> emulated instruction.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> arch/arm64/kvm/hyp/switch.c | 37 ++++++++++++++++++++++++++++++-------
> 1 file changed, 30 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
> index 525c01f48867..f7c651f3a8c0 100644
> --- a/arch/arm64/kvm/hyp/switch.c
> +++ b/arch/arm64/kvm/hyp/switch.c
> @@ -22,6 +22,7 @@
> #include <asm/kvm_emulate.h>
> #include <asm/kvm_hyp.h>
> #include <asm/fpsimd.h>
> +#include <asm/debug-monitors.h>
>
> static bool __hyp_text __fpsimd_enabled_nvhe(void)
> {
> @@ -269,7 +270,11 @@ static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu)
> return true;
> }
>
> -static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu)
> +/* Skip an instruction which has been emulated. Returns true if
> + * execution can continue or false if we need to exit hyp mode because
> + * single-step was in effect.
> + */
> +static bool __hyp_text __skip_instr(struct kvm_vcpu *vcpu)
> {
> *vcpu_pc(vcpu) = read_sysreg_el2(elr);
>
> @@ -282,6 +287,14 @@ static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu)
> }
>
> write_sysreg_el2(*vcpu_pc(vcpu), elr);
> +
> + if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
> + vcpu->arch.fault.esr_el2 =
> + (ESR_ELx_EC_SOFTSTP_LOW << ESR_ELx_EC_SHIFT) | 0x22;
> + return false;
> + } else {
> + return true;
> + }
> }
>
> int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> @@ -342,13 +355,21 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> int ret = __vgic_v2_perform_cpuif_access(vcpu);
>
> if (ret == 1) {
> - __skip_instr(vcpu);
> - goto again;
> + if (__skip_instr(vcpu))
> + goto again;
> + else
> + exit_code = ARM_EXCEPTION_TRAP;
> }
>
> if (ret == -1) {
> - /* Promote an illegal access to an SError */
> - __skip_instr(vcpu);
> + /* Promote an illegal access to an
> + * SError. If we would be returning
> + * due to single-step clear the SS
> + * bit so handle_exit knows what to
> + * do after dealing with the error.
> + */
> + if (!__skip_instr(vcpu))
> + *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS;
> exit_code = ARM_EXCEPTION_EL1_SERROR;
> }
>
> @@ -363,8 +384,10 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> int ret = __vgic_v3_perform_cpuif_access(vcpu);
>
> if (ret == 1) {
> - __skip_instr(vcpu);
> - goto again;
> + if (__skip_instr(vcpu))
> + goto again;
> + else
> + exit_code = ARM_EXCEPTION_TRAP;
> }
>
> /* 0 falls through to be handled out of EL2 */
> --
> 2.15.0
>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
WARNING: multiple messages have this Message-ID (diff)
From: cdall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v1 2/2] kvm: arm64: handle single-step of hyp emulated mmio instructions
Date: Thu, 23 Nov 2017 13:39:01 +0100 [thread overview]
Message-ID: <20171123123901.GZ28855@cbox> (raw)
In-Reply-To: <20171123121134.11050-3-alex.bennee@linaro.org>
On Thu, Nov 23, 2017 at 12:11:34PM +0000, Alex Benn?e wrote:
> There is a fast-path of MMIO emulation inside hyp mode. The handling
> of single-step is broadly the same as kvm_arm_handle_step_debug()
> except we just setup ESR/HSR so handle_exit() does the correct thing
> as we exit.
>
> For the case of an emulated illegal access causing an SError we will
> exit via the ARM_EXCEPTION_EL1_SERROR path in handle_exit(). We behave
> as we would during a real SError and clear the DBG_SPSR_SS bit for the
> emulated instruction.
>
> Signed-off-by: Alex Benn?e <alex.bennee@linaro.org>
> ---
> arch/arm64/kvm/hyp/switch.c | 37 ++++++++++++++++++++++++++++++-------
> 1 file changed, 30 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
> index 525c01f48867..f7c651f3a8c0 100644
> --- a/arch/arm64/kvm/hyp/switch.c
> +++ b/arch/arm64/kvm/hyp/switch.c
> @@ -22,6 +22,7 @@
> #include <asm/kvm_emulate.h>
> #include <asm/kvm_hyp.h>
> #include <asm/fpsimd.h>
> +#include <asm/debug-monitors.h>
>
> static bool __hyp_text __fpsimd_enabled_nvhe(void)
> {
> @@ -269,7 +270,11 @@ static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu)
> return true;
> }
>
> -static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu)
> +/* Skip an instruction which has been emulated. Returns true if
> + * execution can continue or false if we need to exit hyp mode because
> + * single-step was in effect.
> + */
> +static bool __hyp_text __skip_instr(struct kvm_vcpu *vcpu)
> {
> *vcpu_pc(vcpu) = read_sysreg_el2(elr);
>
> @@ -282,6 +287,14 @@ static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu)
> }
>
> write_sysreg_el2(*vcpu_pc(vcpu), elr);
> +
> + if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
> + vcpu->arch.fault.esr_el2 =
> + (ESR_ELx_EC_SOFTSTP_LOW << ESR_ELx_EC_SHIFT) | 0x22;
> + return false;
> + } else {
> + return true;
> + }
> }
>
> int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> @@ -342,13 +355,21 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> int ret = __vgic_v2_perform_cpuif_access(vcpu);
>
> if (ret == 1) {
> - __skip_instr(vcpu);
> - goto again;
> + if (__skip_instr(vcpu))
> + goto again;
> + else
> + exit_code = ARM_EXCEPTION_TRAP;
> }
>
> if (ret == -1) {
> - /* Promote an illegal access to an SError */
> - __skip_instr(vcpu);
> + /* Promote an illegal access to an
> + * SError. If we would be returning
> + * due to single-step clear the SS
> + * bit so handle_exit knows what to
> + * do after dealing with the error.
> + */
> + if (!__skip_instr(vcpu))
> + *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS;
> exit_code = ARM_EXCEPTION_EL1_SERROR;
> }
>
> @@ -363,8 +384,10 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> int ret = __vgic_v3_perform_cpuif_access(vcpu);
>
> if (ret == 1) {
> - __skip_instr(vcpu);
> - goto again;
> + if (__skip_instr(vcpu))
> + goto again;
> + else
> + exit_code = ARM_EXCEPTION_TRAP;
> }
>
> /* 0 falls through to be handled out of EL2 */
> --
> 2.15.0
>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
WARNING: multiple messages have this Message-ID (diff)
From: Christoffer Dall <cdall@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: julien.thierry@arm.com, kvm@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org,
marc.zyngier@arm.com, Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
Dave Martin <Dave.Martin@arm.com>,
James Morse <james.morse@arm.com>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1 2/2] kvm: arm64: handle single-step of hyp emulated mmio instructions
Date: Thu, 23 Nov 2017 13:39:01 +0100 [thread overview]
Message-ID: <20171123123901.GZ28855@cbox> (raw)
In-Reply-To: <20171123121134.11050-3-alex.bennee@linaro.org>
On Thu, Nov 23, 2017 at 12:11:34PM +0000, Alex Bennée wrote:
> There is a fast-path of MMIO emulation inside hyp mode. The handling
> of single-step is broadly the same as kvm_arm_handle_step_debug()
> except we just setup ESR/HSR so handle_exit() does the correct thing
> as we exit.
>
> For the case of an emulated illegal access causing an SError we will
> exit via the ARM_EXCEPTION_EL1_SERROR path in handle_exit(). We behave
> as we would during a real SError and clear the DBG_SPSR_SS bit for the
> emulated instruction.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> arch/arm64/kvm/hyp/switch.c | 37 ++++++++++++++++++++++++++++++-------
> 1 file changed, 30 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
> index 525c01f48867..f7c651f3a8c0 100644
> --- a/arch/arm64/kvm/hyp/switch.c
> +++ b/arch/arm64/kvm/hyp/switch.c
> @@ -22,6 +22,7 @@
> #include <asm/kvm_emulate.h>
> #include <asm/kvm_hyp.h>
> #include <asm/fpsimd.h>
> +#include <asm/debug-monitors.h>
>
> static bool __hyp_text __fpsimd_enabled_nvhe(void)
> {
> @@ -269,7 +270,11 @@ static bool __hyp_text __populate_fault_info(struct kvm_vcpu *vcpu)
> return true;
> }
>
> -static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu)
> +/* Skip an instruction which has been emulated. Returns true if
> + * execution can continue or false if we need to exit hyp mode because
> + * single-step was in effect.
> + */
> +static bool __hyp_text __skip_instr(struct kvm_vcpu *vcpu)
> {
> *vcpu_pc(vcpu) = read_sysreg_el2(elr);
>
> @@ -282,6 +287,14 @@ static void __hyp_text __skip_instr(struct kvm_vcpu *vcpu)
> }
>
> write_sysreg_el2(*vcpu_pc(vcpu), elr);
> +
> + if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) {
> + vcpu->arch.fault.esr_el2 =
> + (ESR_ELx_EC_SOFTSTP_LOW << ESR_ELx_EC_SHIFT) | 0x22;
> + return false;
> + } else {
> + return true;
> + }
> }
>
> int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> @@ -342,13 +355,21 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> int ret = __vgic_v2_perform_cpuif_access(vcpu);
>
> if (ret == 1) {
> - __skip_instr(vcpu);
> - goto again;
> + if (__skip_instr(vcpu))
> + goto again;
> + else
> + exit_code = ARM_EXCEPTION_TRAP;
> }
>
> if (ret == -1) {
> - /* Promote an illegal access to an SError */
> - __skip_instr(vcpu);
> + /* Promote an illegal access to an
> + * SError. If we would be returning
> + * due to single-step clear the SS
> + * bit so handle_exit knows what to
> + * do after dealing with the error.
> + */
> + if (!__skip_instr(vcpu))
> + *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS;
> exit_code = ARM_EXCEPTION_EL1_SERROR;
> }
>
> @@ -363,8 +384,10 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
> int ret = __vgic_v3_perform_cpuif_access(vcpu);
>
> if (ret == 1) {
> - __skip_instr(vcpu);
> - goto again;
> + if (__skip_instr(vcpu))
> + goto again;
> + else
> + exit_code = ARM_EXCEPTION_TRAP;
> }
>
> /* 0 falls through to be handled out of EL2 */
> --
> 2.15.0
>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
next prev parent reply other threads:[~2017-11-23 12:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-23 12:11 [PATCH v1 0/2] Additional single-step-cases Alex Bennée
2017-11-23 12:11 ` Alex Bennée
2017-11-23 12:11 ` [PATCH v1 1/2] kvm: arm64: handle single-step during SError exceptions Alex Bennée
2017-11-23 12:11 ` Alex Bennée
2017-11-23 12:11 ` Alex Bennée
2017-11-23 12:33 ` Christoffer Dall
2017-11-23 12:33 ` Christoffer Dall
2017-11-23 12:11 ` [PATCH v1 2/2] kvm: arm64: handle single-step of hyp emulated mmio instructions Alex Bennée
2017-11-23 12:11 ` Alex Bennée
2017-11-23 12:11 ` Alex Bennée
2017-11-23 12:39 ` Christoffer Dall [this message]
2017-11-23 12:39 ` Christoffer Dall
2017-11-23 12:39 ` Christoffer Dall
2017-11-29 16:18 ` [PATCH v1 0/2] Additional single-step-cases Marc Zyngier
2017-11-29 16:18 ` Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171123123901.GZ28855@cbox \
--to=cdall@linaro.org \
--cc=Dave.Martin@arm.com \
--cc=alex.bennee@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=julien.thierry@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.