When SVE is enabled, the host may set bit 16 in SMCCC function IDs, a
hint that indicates an unused SVE state. At the moment NVHE doesn't
account for this bit when inspecting the function ID, and rejects most
calls. Clear the hint bit before comparing function IDs.
About version compatibility: the host's PSCI driver initially probes the
firmware for a SMCCC version number. If the firmware implements a
protocol recent enough (1.3), subsequent SMCCC calls have the hint bit
set. Since the hint bit was reserved in earlier versions of the
protocol, clearing it is fine regardless of the version in use.
When a new hint is added to the protocol in the future, it will be added
to ARM_SMCCC_CALL_HINTS and NVHE will handle it straight away. This
patch only clears known hints and leaves reserved bits as is, because
future SMCCC versions could use reserved bits as modifiers for the
function ID, rather than hints.
Fixes: cfa7ff959a78 ("arm64: smccc: Support SMCCC v1.3 SVE register saving hint")
Reported-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230911145254.934414-4-jean-philippe@linaro.org
 
 
 u64 __guest_enter(struct kvm_vcpu *vcpu);
 
-bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt);
+bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt, u32 func_id);
 
 #ifdef __KVM_NVHE_HYPERVISOR__
 void __noreturn __hyp_do_panic(struct kvm_cpu_context *host_ctxt, u64 spsr,
 
 #define FFA_MAX_FUNC_NUM 0x7F
 
 int hyp_ffa_init(void *pages);
-bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt);
+bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id);
 
 #endif /* __KVM_HYP_FFA_H */
 
        return true;
 }
 
-bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt)
+bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)
 {
-       DECLARE_REG(u64, func_id, host_ctxt, 0);
        struct arm_smccc_res res;
 
        /*
 
        cmp     x0, #HVC_STUB_HCALL_NR
        b.lo    __kvm_handle_stub_hvc
 
+       bic     x0, x0, #ARM_SMCCC_CALL_HINTS
        mov     x3, #KVM_HOST_SMCCC_FUNC(__kvm_hyp_init)
        cmp     x0, x3
        b.eq    1f
 
        if (static_branch_unlikely(&kvm_protected_mode_initialized))
                hcall_min = __KVM_HOST_SMCCC_FUNC___pkvm_prot_finalize;
 
+       id &= ~ARM_SMCCC_CALL_HINTS;
        id -= KVM_HOST_SMCCC_ID(0);
 
        if (unlikely(id < hcall_min || id >= ARRAY_SIZE(host_hcall)))
 
 static void handle_host_smc(struct kvm_cpu_context *host_ctxt)
 {
+       DECLARE_REG(u64, func_id, host_ctxt, 0);
        bool handled;
 
-       handled = kvm_host_psci_handler(host_ctxt);
+       func_id &= ~ARM_SMCCC_CALL_HINTS;
+
+       handled = kvm_host_psci_handler(host_ctxt, func_id);
        if (!handled)
-               handled = kvm_host_ffa_handler(host_ctxt);
+               handled = kvm_host_ffa_handler(host_ctxt, func_id);
        if (!handled)
                default_host_smc_handler(host_ctxt);
 
 
        }
 }
 
-bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt)
+bool kvm_host_psci_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)
 {
-       DECLARE_REG(u64, func_id, host_ctxt, 0);
        unsigned long ret;
 
        switch (kvm_host_psci_config.version) {
 
 #define ARM_SMCCC_VERSION_1_3          0x10003
 
 #define ARM_SMCCC_1_3_SVE_HINT         0x10000
+#define ARM_SMCCC_CALL_HINTS           ARM_SMCCC_1_3_SVE_HINT
+
 
 #define ARM_SMCCC_VERSION_FUNC_ID                                      \
        ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \