1 /* 2 * Get user helper pc for memory unwinding. 3 * SPDX-License-Identifier: LGPL-2.1-or-later 4 */ 5 6 #ifndef ACCEL_TCG_HELPER_RETADDR_H 7 #define ACCEL_TCG_HELPER_RETADDR_H 8 9 /* 10 * For user-only, helpers that use guest to host address translation 11 * must protect the actual host memory access by recording 'retaddr' 12 * for the signal handler. This is required for a race condition in 13 * which another thread unmaps the page between a probe and the 14 * actual access. 15 */ 16 #ifdef CONFIG_USER_ONLY 17 extern __thread uintptr_t helper_retaddr; 18 set_helper_retaddr(uintptr_t ra)19static inline void set_helper_retaddr(uintptr_t ra) 20 { 21 helper_retaddr = ra; 22 /* 23 * Ensure that this write is visible to the SIGSEGV handler that 24 * may be invoked due to a subsequent invalid memory operation. 25 */ 26 signal_barrier(); 27 } 28 clear_helper_retaddr(void)29static inline void clear_helper_retaddr(void) 30 { 31 /* 32 * Ensure that previous memory operations have succeeded before 33 * removing the data visible to the signal handler. 34 */ 35 signal_barrier(); 36 helper_retaddr = 0; 37 } 38 #else 39 #define set_helper_retaddr(ra) do { } while (0) 40 #define clear_helper_retaddr() do { } while (0) 41 #endif 42 43 #endif /* ACCEL_TCG_HELPER_RETADDR_H */ 44