calling.h (8a09317b895f073977346779df52f67c1056d81d) calling.h (aa8c6248f8c75acfd610fe15d8cae23cf70d9d09)
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/jump_label.h>
3#include <asm/unwind_hints.h>
4#include <asm/cpufeatures.h>
5#include <asm/page_types.h>
6
7/*
8

--- 191 unchanged lines hidden (view full) ---

200.endm
201
202.macro ADJUST_USER_CR3 reg:req
203 /* Move CR3 up a page to the user page tables: */
204 orq $(PTI_SWITCH_MASK), \reg
205.endm
206
207.macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/jump_label.h>
3#include <asm/unwind_hints.h>
4#include <asm/cpufeatures.h>
5#include <asm/page_types.h>
6
7/*
8

--- 191 unchanged lines hidden (view full) ---

200.endm
201
202.macro ADJUST_USER_CR3 reg:req
203 /* Move CR3 up a page to the user page tables: */
204 orq $(PTI_SWITCH_MASK), \reg
205.endm
206
207.macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
208 ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
208 mov %cr3, \scratch_reg
209 ADJUST_KERNEL_CR3 \scratch_reg
210 mov \scratch_reg, %cr3
209 mov %cr3, \scratch_reg
210 ADJUST_KERNEL_CR3 \scratch_reg
211 mov \scratch_reg, %cr3
212.Lend_\@:
211.endm
212
213.macro SWITCH_TO_USER_CR3 scratch_reg:req
213.endm
214
215.macro SWITCH_TO_USER_CR3 scratch_reg:req
216 ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
214 mov %cr3, \scratch_reg
215 ADJUST_USER_CR3 \scratch_reg
216 mov \scratch_reg, %cr3
217 mov %cr3, \scratch_reg
218 ADJUST_USER_CR3 \scratch_reg
219 mov \scratch_reg, %cr3
220.Lend_\@:
217.endm
218
219.macro SAVE_AND_SWITCH_TO_KERNEL_CR3 scratch_reg:req save_reg:req
221.endm
222
223.macro SAVE_AND_SWITCH_TO_KERNEL_CR3 scratch_reg:req save_reg:req
224 ALTERNATIVE "jmp .Ldone_\@", "", X86_FEATURE_PTI
220 movq %cr3, \scratch_reg
221 movq \scratch_reg, \save_reg
222 /*
223 * Is the switch bit zero? This means the address is
224 * up in real PAGE_TABLE_ISOLATION patches in a moment.
225 */
226 testq $(PTI_SWITCH_MASK), \scratch_reg
227 jz .Ldone_\@
228
229 ADJUST_KERNEL_CR3 \scratch_reg
230 movq \scratch_reg, %cr3
231
232.Ldone_\@:
233.endm
234
235.macro RESTORE_CR3 save_reg:req
225 movq %cr3, \scratch_reg
226 movq \scratch_reg, \save_reg
227 /*
228 * Is the switch bit zero? This means the address is
229 * up in real PAGE_TABLE_ISOLATION patches in a moment.
230 */
231 testq $(PTI_SWITCH_MASK), \scratch_reg
232 jz .Ldone_\@
233
234 ADJUST_KERNEL_CR3 \scratch_reg
235 movq \scratch_reg, %cr3
236
237.Ldone_\@:
238.endm
239
240.macro RESTORE_CR3 save_reg:req
241 ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI
236 /*
237 * The CR3 write could be avoided when not changing its value,
238 * but would require a CR3 read *and* a scratch register.
239 */
240 movq \save_reg, %cr3
242 /*
243 * The CR3 write could be avoided when not changing its value,
244 * but would require a CR3 read *and* a scratch register.
245 */
246 movq \save_reg, %cr3
247.Lend_\@:
241.endm
242
243#else /* CONFIG_PAGE_TABLE_ISOLATION=n: */
244
245.macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
246.endm
247.macro SWITCH_TO_USER_CR3 scratch_reg:req
248.endm

--- 22 unchanged lines hidden ---
248.endm
249
250#else /* CONFIG_PAGE_TABLE_ISOLATION=n: */
251
252.macro SWITCH_TO_KERNEL_CR3 scratch_reg:req
253.endm
254.macro SWITCH_TO_USER_CR3 scratch_reg:req
255.endm

--- 22 unchanged lines hidden ---