Skip to content

Commit 37c8e49

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Let errors from SMCCC emulation to reach userspace
Typically a negative return from an exit handler is used to request a return to userspace with the specified error. KVM's handling of SMCCC emulation (i.e. both HVCs and SMCs) deviates from the trend and resumes the guest instead. Stop handling negative returns this way and instead let the error percolate to userspace. Suggested-by: Suzuki K Poulose <suzuki.poulose@arm.com> Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230404154050.2270077-12-oliver.upton@linux.dev
1 parent 7e484d2 commit 37c8e49

1 file changed

Lines changed: 2 additions & 16 deletions

File tree

arch/arm64/kvm/handle_exit.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ static void kvm_handle_guest_serror(struct kvm_vcpu *vcpu, u64 esr)
3636

3737
static int handle_hvc(struct kvm_vcpu *vcpu)
3838
{
39-
int ret;
40-
4139
trace_kvm_hvc_arm64(*vcpu_pc(vcpu), vcpu_get_reg(vcpu, 0),
4240
kvm_vcpu_hvc_get_imm(vcpu));
4341
vcpu->stat.hvc_exit_stat++;
@@ -52,19 +50,11 @@ static int handle_hvc(struct kvm_vcpu *vcpu)
5250
return 1;
5351
}
5452

55-
ret = kvm_smccc_call_handler(vcpu);
56-
if (ret < 0) {
57-
vcpu_set_reg(vcpu, 0, ~0UL);
58-
return 1;
59-
}
60-
61-
return ret;
53+
return kvm_smccc_call_handler(vcpu);
6254
}
6355

6456
static int handle_smc(struct kvm_vcpu *vcpu)
6557
{
66-
int ret;
67-
6858
/*
6959
* "If an SMC instruction executed at Non-secure EL1 is
7060
* trapped to EL2 because HCR_EL2.TSC is 1, the exception is a
@@ -93,11 +83,7 @@ static int handle_smc(struct kvm_vcpu *vcpu)
9383
* at Non-secure EL1 is trapped to EL2 if HCR_EL2.TSC==1, rather than
9484
* being treated as UNDEFINED.
9585
*/
96-
ret = kvm_smccc_call_handler(vcpu);
97-
if (ret < 0)
98-
vcpu_set_reg(vcpu, 0, ~0UL);
99-
100-
return ret;
86+
return kvm_smccc_call_handler(vcpu);
10187
}
10288

10389
/*

0 commit comments

Comments
 (0)