^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Code shared between 32 and 64 bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <asm/spec-ctrl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This needs to be inline to optimize for the common case where no extra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * work needs to be done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static inline void switch_to_extra(struct task_struct *prev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct task_struct *next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) unsigned long next_tif = task_thread_info(next)->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) unsigned long prev_tif = task_thread_info(prev)->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) if (IS_ENABLED(CONFIG_SMP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Avoid __switch_to_xtra() invocation when conditional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * STIBP is disabled and the only different bit is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * TIF_SPEC_IB. For CONFIG_SMP=n TIF_SPEC_IB is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * in the TIF_WORK_CTXSW masks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) if (!static_branch_likely(&switch_to_cond_stibp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) prev_tif &= ~_TIF_SPEC_IB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) next_tif &= ~_TIF_SPEC_IB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * __switch_to_xtra() handles debug registers, i/o bitmaps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * speculation mitigations etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (unlikely(next_tif & _TIF_WORK_CTXSW_NEXT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) prev_tif & _TIF_WORK_CTXSW_PREV))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) __switch_to_xtra(prev, next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }