--- zzzz-none-000/linux-4.4.271/arch/arm/mm/proc-v7-3level.S 2021-06-03 06:22:09.000000000 +0000 +++ dakota-7530ac-750/linux-4.4.271/arch/arm/mm/proc-v7-3level.S 2023-01-11 09:25:41.000000000 +0000 @@ -65,6 +65,37 @@ ret lr ENDPROC(cpu_v7_switch_mm) +/* + * Qualcomm Technologies Inc. Krait processors - require bp invalidation + */ +ENTRY(cpu_krait_switch_mm) +/* Sanitize link stack + * The below instrucitons will cause lr to be loaded with a value + * which will never be used, thus nullyfying branch prediction based + * attacks + */ + push {lr} + bl 1f +1: bl 1f +1: bl 1f +1: bl 1f +1: bl 1f +1: bl 1f +1: bl 1f +1: bl 1f +1: mov lr, #0 + mcr p15, 0, lr, c7, c5, 6 @ BPIALL + isb +#ifdef CONFIG_MMU + mmid r2, r2 + asid r2, r2 + orr rpgdh, rpgdh, r2, lsl #(48 - 32) @ upper 32-bits of pgd + mcrr p15, 0, rpgdl, rpgdh, c2 @ set TTB 0 + isb +#endif + pop {pc} +ENDPROC(cpu_krait_switch_mm) + #ifdef __ARMEB__ #define rl r3 #define rh r2