KVM: arm64: Pass a 64bit function-id in the SMC handlers
PATCH 1/1 KVM: arm64: Pass a 64bit function-id in the SMC handlers
Make the SMC handlers accept a 64bit value for the function-id to keep it uniform with the rest of the code and prevent a u64 -> u32 -> u64 conversion as it currently happens when we handle PSCI.
--- arch/arm64/include/asm/kvm_hyp.h | 2 +- arch/arm64/kvm/hyp/include/nvhe/ffa.h | 2 +- arch/arm64/kvm/hyp/nvhe/ffa.c | 2 +- arch/arm64/kvm/hyp/nvhe/psci-relay.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
arch/arm64/include/asm/kvm_hyp.h +1 -1
@@ -119,7 +119,7 @@ void __sve_restore_state(void *sve_pffr, u32 *fpsr, int restore_ffr);u64 __guest_enter (struct kvm_vcpu *vcpu); -bool kvm_host_psci_handler (struct kvm_cpu_context *host_ctxt,u32 func_id); +bool kvm_host_psci_handler (struct kvm_cpu_context *host_ctxt,u64 func_id);#ifdef __KVM_NVHE_HYPERVISOR__ void __noreturn __hyp_do_panic(struct kvm_cpu_context *host_ctxt, u64 spsr,
arch/arm64/kvm/hyp/include/nvhe/ffa.h +1 -1
@@ -12,6 +12,6 @@#define FFA_MAX_FUNC_NUM 0xFFint hyp_ffa_init (void *pages); -bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u32 func_id); +bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u64 func_id);#endif /* __KVM_HYP_FFA_H */
arch/arm64/kvm/hyp/nvhe/ffa.c +1 -1
@@ -862,7 +862,7 @@ static void do_ffa_part_get(struct arm_smccc_1_2_regs *res,hyp_spin_unlock (&host_buffers.lock); } -bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u32 func_id) +bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u64 func_id) {struct arm_smccc_1_2_regs res;
arch/arm64/kvm/hyp/nvhe/psci-relay.c +1 -1
@@ -278,7 +278,7 @@ static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context *host_ } } -bool kvm_host_psci_handler (struct kvm_cpu_context *host_ctxt,u32 func_id) +bool kvm_host_psci_handler (struct kvm_cpu_context *host_ctxt,u64 func_id) {unsigned long ret;
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog
Marc Zyngier
maintainerQuoted 4 lines · Sebastian Ene
Make the SMC handlers accept a 64bit value for the function-id to keep it uniform with the rest of the code and prevent a u64 -> u32 -> u64 conversion as it currently happens when we handle PSCI.
That seems overly creative. The spec says (2.5, from ARM DEN 0028 1.6 G):
"The Function Identifier is passed on W0 on every SMC and HVC call. Its 32-bit integer value indicates which function is being requested by the caller. It is always passed as the first argument to every SMC or HVC call in R0 or W0."
which indicates that it is *always* a 32bit value.
So if you have a 64bit value somewhere, *that* should be fixed, not propagated arbitrarily.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 9 lines · Marc Zyngier
Quoted 4 lines · Sebastian Ene
Make the SMC handlers accept a 64bit value for the function-id to keep it uniform with the rest of the code and prevent a u64 -> u32 -> u64 conversion as it currently happens when we handle PSCI.
That seems overly creative. The spec says (2.5, from ARM DEN 0028 1.6 G):
I'm not plannig to be *overly creative*. Thanks for pointing out the ARM spec.
Quoted 10 lines
"The Function Identifier is passed on W0 on every SMC and HVC call. Its 32-bit integer value indicates which function is being requested by the caller. It is always passed as the first argument to every SMC or HVC call in R0 or W0."
which indicates that it is *always* a 32bit value.
So if you have a 64bit value somewhere, *that* should be fixed, not propagated arbitrarily.
If you have a non SMCCC call that happen to have the first 32-bits of the function-id matching either PSCI or FF-A you will end up handling them instead of forwarding it to Trustzone because func_id is declared as:
DECLARE_REG(u64, func_id, host_ctxt, 0);
Quoted 7 lines
Thanks,
M.Signature · 1 line
Without deviation from the norm, progress is not possible.
Thanks,
Sebastian
Marc Zyngier
maintainerQuoted 23 lines · Sebastian Ene
Quoted 9 lines · Marc Zyngier
Quoted 4 lines · Sebastian Ene
Make the SMC handlers accept a 64bit value for the function-id to keep it uniform with the rest of the code and prevent a u64 -> u32 -> u64 conversion as it currently happens when we handle PSCI.
That seems overly creative. The spec says (2.5, from ARM DEN 0028 1.6 G):
I'm not plannig to be *overly creative*. Thanks for pointing out the ARM spec.
Quoted 8 lines
"The Function Identifier is passed on W0 on every SMC and HVC call. Its 32-bit integer value indicates which function is being requested by the caller. It is always passed as the first argument to every SMC or HVC call in R0 or W0."
which indicates that it is *always* a 32bit value.
Quoted 8 lines
Quoted 2 lines
So if you have a 64bit value somewhere, *that* should be fixed, not propagated arbitrarily.
If you have a non SMCCC call that happen to have the first 32-bits of the function-id matching either PSCI or FF-A you will end up handling them instead of forwarding it to Trustzone because
func_idis declared as:
DECLARE_REG(u64, func_id, host_ctxt, 0);
Again, the correct approach to prevent the propagation of something that is known to be wrong. Something like this:
arch/arm64/kvm/hyp/nvhe/hyp-main.c +5 -0
@@ -694,6 +694,11 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt)DECLARE_REG (u64, func_id, host_ctxt,0 );bool handled; +if (upper_32_bits (func_id)) { +cpu_reg (host_ctxt,0 ) =SMCCC_RET_NOT_SUPPORTED ; +kvm_skip_host_instr (); + } + func_id &= ~ARM_SMCCC_CALL_HINTS ; handled =kvm_host_psci_handler (host_ctxt, func_id);
Because forwarding something that is blatantly illegal to the secure side is not something we should accept at all (just like we now refuse non-zero SMC immediate values).
Thanks,
M.
Signature · 1 line
Jazz isn't dead. It just smells funny.
Marc Zyngier
maintainerQuoted 43 lines · Marc Zyngier
Quoted 23 lines · Sebastian Ene
Quoted 9 lines · Marc Zyngier
Quoted 4 lines · Sebastian Ene
Make the SMC handlers accept a 64bit value for the function-id to keep it uniform with the rest of the code and prevent a u64 -> u32 -> u64 conversion as it currently happens when we handle PSCI.
That seems overly creative. The spec says (2.5, from ARM DEN 0028 1.6 G):
I'm not plannig to be *overly creative*. Thanks for pointing out the ARM spec.
Quoted 8 lines
"The Function Identifier is passed on W0 on every SMC and HVC call. Its 32-bit integer value indicates which function is being requested by the caller. It is always passed as the first argument to every SMC or HVC call in R0 or W0."
which indicates that it is *always* a 32bit value.
Quoted 8 lines
Quoted 2 lines
So if you have a 64bit value somewhere, *that* should be fixed, not propagated arbitrarily.
If you have a non SMCCC call that happen to have the first 32-bits of the function-id matching either PSCI or FF-A you will end up handling them instead of forwarding it to Trustzone because
func_idis declared as:
DECLARE_REG(u64, func_id, host_ctxt, 0);Again, the correct approach to prevent the propagation of something that is known to be wrong. Something like this:
arch/arm64/kvm/hyp/nvhe/hyp-main.c +0
-0
arch/arm64/kvm/hyp/nvhe/hyp-main.c static void handle_host_smc(struct kvm_cpu_context *host_ctxt) · line 699
Quoted 6 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +3
-0@@ -694,6 +694,11 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt)DECLARE_REG (u64, func_id, host_ctxt,0 );bool handled; +if (upper_32_bits (func_id)) { +cpu_reg (host_ctxt,0 ) =SMCCC_RET_NOT_SUPPORTED ; +kvm_skip_host_instr ();
Plus the obviously missing:
+ return;
arch/arm64/kvm/hyp/nvhe/hyp-main.c static void handle_host_smc(struct kvm_cpu_context *host_ctxt) · line 701
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +2
-0+ } +
M.
Signature · 1 line
Jazz isn't dead. It just smells funny.
Quoted 36 lines · Marc Zyngier
Quoted 33 lines · Marc Zyngier
Quoted 30 lines · Sebastian Ene
Quoted 9 lines · Marc Zyngier
Quoted 4 lines · Sebastian Ene
Make the SMC handlers accept a 64bit value for the function-id to keep it uniform with the rest of the code and prevent a u64 -> u32 -> u64 conversion as it currently happens when we handle PSCI.
That seems overly creative. The spec says (2.5, from ARM DEN 0028 1.6 G):
I'm not plannig to be *overly creative*. Thanks for pointing out the ARM spec.
Quoted 10 lines
"The Function Identifier is passed on W0 on every SMC and HVC call. Its 32-bit integer value indicates which function is being requested by the caller. It is always passed as the first argument to every SMC or HVC call in R0 or W0."
which indicates that it is *always* a 32bit value.
So if you have a 64bit value somewhere, *that* should be fixed, not propagated arbitrarily.
If you have a non SMCCC call that happen to have the first 32-bits of the function-id matching either PSCI or FF-A you will end up handling them instead of forwarding it to Trustzone because
func_idis declared as:
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
DECLARE_REG(u64, func_id, host_ctxt, 0);Again, the correct approach to prevent the propagation of something that is known to be wrong. Something like this:
Hello Marc,
Quoted 8 lines
Quoted 8 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +0
-0@@ -694,6 +694,11 @@ static void handle_host_smc(struct kvm_cpu_context *host_ctxt)DECLARE_REG (u64, func_id, host_ctxt,0 );bool handled;
Quoted 8 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c static void handle_host_smc(struct kvm_cpu_context *host_ctxt) · line 699
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +3
-0+if (upper_32_bits (func_id)) { +cpu_reg (host_ctxt,0 ) =SMCCC_RET_NOT_SUPPORTED ; +kvm_skip_host_instr ();Plus the obviously missing:
+ return;
Thanks for the suggestion, I will do this and spin a new version. Sebastian
Quoted 7 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c static void handle_host_smc(struct kvm_cpu_context *host_ctxt) · line 701
Quoted 2 lines
arch/arm64/kvm/hyp/nvhe/hyp-main.c +2
-0+ } +M.--
Jazz isn't dead. It just smells funny.