Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cee0aa0c authored by Sami Tolvanen's avatar Sami Tolvanen Committed by Bruno Martins
Browse files

ANDROID: arm64: add __va_function



With CFI, the compiler replaces function references with pointers
to the CFI jump table. This breaks passing these addresses to
code running at EL2, where the jump tables are not valid. Add a
__va_function macro similarly to the earlier __pa_function to take
address of the actual function in inline assembly and use that in
kvm_ksym_ref instead.

Bug: 163385976
Change-Id: I097b99409995512c00786300e7d18fe42c720a1b
(cherry picked from commit 2f4d6c9fd77c88ad0500aad4bf1f64aaf2654c49)
Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
parent 8e9cd82b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -40,9 +40,9 @@
/* Translate a kernel address of @sym into its equivalent linear mapping */
#define kvm_ksym_ref(sym)						\
	({								\
		void *val = &sym;					\
		void *val = __va_function(sym);				\
		if (!is_kernel_in_hyp_mode())				\
			val = lm_alias(&sym);				\
			val = lm_alias(val);				\
		val;							\
	 })

+5 −3
Original line number Diff line number Diff line
@@ -326,13 +326,15 @@ static inline void *phys_to_virt(phys_addr_t x)
 * virtual address. Therefore, use inline assembly to ensure we are
 * always taking the address of the actual function.
 */
#define __pa_function(x) ({						\
	unsigned long addr;						\
#define __va_function(x) ({						\
	void *addr;							\
	asm("adrp %0, " __stringify(x) "\n\t"				\
	    "add  %0, %0, :lo12:" __stringify(x) : "=r" (addr));	\
	__pa_symbol(addr);						\
	addr;								\
})

#define __pa_function(x) 	__pa_symbol(__va_function(x))

/*
 *  virt_to_page(k)	convert a _valid_ virtual address to struct page *
 *  virt_addr_valid(k)	indicates whether a virtual address is valid