[PATCH v6 29/64] KVM: arm64: nv: Forward debug traps to the nested guest
Alexandru Elisei
alexandru.elisei at arm.com
Wed Feb 9 03:04:39 PST 2022
Hi Marc,
On Fri, Jan 28, 2022 at 12:18:37PM +0000, Marc Zyngier wrote:
> On handling a debug trap, check whether we need to forward it to the
> guest before handling it.
>
> Signed-off-by: Marc Zyngier <maz at kernel.org>
> ---
> arch/arm64/include/asm/kvm_nested.h | 2 ++
> arch/arm64/kvm/emulate-nested.c | 9 +++++++--
> arch/arm64/kvm/sys_regs.c | 3 +++
> 3 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h
> index 82fc8b6c990b..047ca700163b 100644
> --- a/arch/arm64/include/asm/kvm_nested.h
> +++ b/arch/arm64/include/asm/kvm_nested.h
> @@ -66,6 +66,8 @@ static inline u64 translate_cnthctl_el2_to_cntkctl_el1(u64 cnthctl)
> }
>
> int handle_wfx_nested(struct kvm_vcpu *vcpu, bool is_wfe);
> +extern bool __forward_traps(struct kvm_vcpu *vcpu, unsigned int reg,
> + u64 control_bit);
> extern bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit);
> extern bool forward_nv_traps(struct kvm_vcpu *vcpu);
> extern bool forward_nv1_traps(struct kvm_vcpu *vcpu);
> diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c
> index 0109dfd664dd..1f6cf8fe9fe3 100644
> --- a/arch/arm64/kvm/emulate-nested.c
> +++ b/arch/arm64/kvm/emulate-nested.c
> @@ -13,14 +13,14 @@
>
> #include "trace.h"
>
> -bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit)
> +bool __forward_traps(struct kvm_vcpu *vcpu, unsigned int reg, u64 control_bit)
> {
> bool control_bit_set;
>
> if (!vcpu_has_nv(vcpu))
> return false;
>
> - control_bit_set = __vcpu_sys_reg(vcpu, HCR_EL2) & control_bit;
> + control_bit_set = __vcpu_sys_reg(vcpu, reg) & control_bit;
> if (!vcpu_is_el2(vcpu) && control_bit_set) {
> kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
> return true;
> @@ -28,6 +28,11 @@ bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit)
> return false;
> }
>
> +bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit)
> +{
> + return __forward_traps(vcpu, HCR_EL2, control_bit);
> +}
> +
> bool forward_nv_traps(struct kvm_vcpu *vcpu)
> {
> return forward_traps(vcpu, HCR_NV);
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 697bf0bca550..3e1f37c507a8 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -566,6 +566,9 @@ static bool trap_debug_regs(struct kvm_vcpu *vcpu,
> struct sys_reg_params *p,
> const struct sys_reg_desc *r)
> {
> + if (__forward_traps(vcpu, MDCR_EL2, MDCR_EL2_TDA | MDCR_EL2_TDE))
> + return false;
The description of the MDCR_EL2.TDA field says:
"This field is treated as being 1 for all purposes other than a direct read
when one or more of the following are true:
- MDCR_EL2.TDE == 1
- HCR_EL2.TGE == 1"
Shouldn't we also check for HCR_EL2.TGE == 1 when deciding to forward the trap?
Thanks,
Alex
> +
> access_rw(vcpu, p, r);
> if (p->is_write)
> vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY;
> --
> 2.30.2
>
More information about the linux-arm-kernel
mailing list