[RFC PATCH v2 5/6] KVM: arm64: Add support for KVM_EXIT_HYPERCALL
James Morse
james.morse at arm.com
Fri Feb 24 07:12:33 PST 2023
Hi Oliver,
On 11/02/2023 01:37, Oliver Upton wrote:
> In anticipation of user hypercall filters, add the necessary plumbing to
> get SMCCC calls out to userspace. Even though the exit structure has
> space for KVM to pass register arguments, let's just avoid it altogether
> and let userspace poke at the registers via KVM_GET_ONE_REG.
>
> This deliberately stretches the definition of a 'hypercall' to cover
> SMCs from EL1 in addition to the HVCs we know and love. KVM doesn't
> support EL1 calls into secure services, but now we can paint that as a
> userspace problem and be done with it.
>
> Finally, we need a flag to let userspace know what conduit instruction
> was used (i.e. SMC vs. HVC). Redefine the remaining padding in
> kvm_run::hypercall to accomplish this. Let's all take a moment
> to admire the flowers and see how 'longmode' tied up a full u32 in the
> UAPI. Weep.
> diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c
> index 45b8371816fd..f095c048730a 100644
> --- a/arch/arm64/kvm/hypercalls.c
> +++ b/arch/arm64/kvm/hypercalls.c
> @@ -161,6 +161,17 @@ static u8 kvm_hvc_get_action(struct kvm_vcpu *vcpu, u32 func_id)
> return KVM_SMCCC_FILTER_DENY;
> }
>
> +static void kvm_prepare_hypercall_exit(struct kvm_vcpu *vcpu, u32 func_id, bool smc)
> +{
> + struct kvm_run *run = vcpu->run;
> +
> + run->exit_reason = KVM_EXIT_HYPERCALL;
> + run->hypercall.nr = func_id;
This is a bit weird. The func_id is the x0 value, so it would more naturally live in
run->hypercall.args[0].
User-space also needs the SMC/HVC immediate value, as that is only available in the ESR.
It makes more sense to put the immediate value here.
> + if (smc)
> + run->hypercall.flags = KVM_HYPERCALL_EXIT_SMC;
> +}
> +
> int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
> {
> struct kvm_smccc_features *smccc_feat = &vcpu->kvm->arch.smccc_feat;
Thanks,
James
More information about the linux-arm-kernel
mailing list