KVM: arm64: Stop sparse from moaning at __hyp_this_cpu_ptr
authorMarc Zyngier <maz@kernel.org>
Sun, 7 Jun 2020 09:55:28 +0000 (10:55 +0100)
committerMarc Zyngier <maz@kernel.org>
Tue, 9 Jun 2020 09:59:52 +0000 (10:59 +0100)
Sparse complains that __hyp_this_cpu_ptr() returns something
that is flagged noderef and not in the correct address space
(both being the result of the __percpu annotation).

Pretend that __hyp_this_cpu_ptr() knows what it is doing by
forcefully casting the pointer with __kernel __force.

Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_asm.h

index 0c9b5fc4ba0aedf60da4a9ec8ade5cddc30eddb8..d9b7da15dbca46dd92476f0cfcf4c5e000a9c6e8 100644 (file)
@@ -81,12 +81,19 @@ extern u32 __kvm_get_mdcr_el2(void);
 
 extern char __smccc_workaround_1_smc[__SMCCC_WORKAROUND_1_SMC_SZ];
 
-/* Home-grown __this_cpu_{ptr,read} variants that always work at HYP */
+/*
+ * Home-grown __this_cpu_{ptr,read} variants that always work at HYP,
+ * provided that sym is really a *symbol* and not a pointer obtained from
+ * a data structure. As for SHIFT_PERCPU_PTR(), the creative casting keeps
+ * sparse quiet.
+ */
 #define __hyp_this_cpu_ptr(sym)                                                \
        ({                                                              \
-               void *__ptr = hyp_symbol_addr(sym);                     \
+               void *__ptr;                                            \
+               __verify_pcpu_ptr(&sym);                                \
+               __ptr = hyp_symbol_addr(sym);                           \
                __ptr += read_sysreg(tpidr_el2);                        \
-               (typeof(&sym))__ptr;                                    \
+               (typeof(sym) __kernel __force *)__ptr;                  \
         })
 
 #define __hyp_this_cpu_read(sym)                                       \