Skip to content

Commit b990d37

Browse files
author
Marc Zyngier
committed
KVM: arm64: Stop sparse from moaning at __hyp_this_cpu_ptr
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 <[email protected]>
1 parent 29eb5a3 commit b990d37

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

arch/arm64/include/asm/kvm_asm.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,19 @@ extern u32 __kvm_get_mdcr_el2(void);
8181

8282
extern char __smccc_workaround_1_smc[__SMCCC_WORKAROUND_1_SMC_SZ];
8383

84-
/* Home-grown __this_cpu_{ptr,read} variants that always work at HYP */
84+
/*
85+
* Home-grown __this_cpu_{ptr,read} variants that always work at HYP,
86+
* provided that sym is really a *symbol* and not a pointer obtained from
87+
* a data structure. As for SHIFT_PERCPU_PTR(), the creative casting keeps
88+
* sparse quiet.
89+
*/
8590
#define __hyp_this_cpu_ptr(sym) \
8691
({ \
87-
void *__ptr = hyp_symbol_addr(sym); \
92+
void *__ptr; \
93+
__verify_pcpu_ptr(&sym); \
94+
__ptr = hyp_symbol_addr(sym); \
8895
__ptr += read_sysreg(tpidr_el2); \
89-
(typeof(&sym))__ptr; \
96+
(typeof(sym) __kernel __force *)__ptr; \
9097
})
9198

9299
#define __hyp_this_cpu_read(sym) \

0 commit comments

Comments
 (0)