@@ -209,28 +209,9 @@ alternative_cb_end
209
209
add x29 , sp , #S_STACKFRAME
210
210
211
211
#ifdef CONFIG_ARM64_SW_TTBR0_PAN
212
- / *
213
- * Set the TTBR0 PAN bit in SPSR. When the exception is taken from
214
- * EL0 , there is no need to check the state of TTBR0_EL1 since
215
- * accesses are always enabled.
216
- * Note th at the meaning of this bit differs from the ARMv8. 1 PAN
217
- * feature as all TTBR0_EL1 accesses are disabled , not just those to
218
- * user mappings.
219
- * /
220
- alternative_if ARM64_HAS_PAN
221
- b 1f // skip TTBR0 PAN
212
+ alternative_if_not ARM64_HAS_PAN
213
+ bl __swpan_entry_el\el
222
214
alternative_else_nop_endif
223
-
224
- .if \el != 0
225
- mrs x21 , ttbr0_el1
226
- tst x21 , #TTBR_ASID_MASK // Check for the reserved ASID
227
- orr x23 , x23 , #PSR_PAN_BIT // Set the emulated PAN in the saved SPSR
228
- b.eq 1f // TTBR0 access already disabled
229
- and x23 , x23 , #~PSR_PAN_BIT // Clear the emulated PAN in the saved SPSR
230
- .endif
231
-
232
- __uaccess_ttbr0_disable x21
233
- 1 :
234
215
#endif
235
216
236
217
stp x22 , x23 , [ sp , #S_PC ]
@@ -284,34 +265,9 @@ alternative_else_nop_endif
284
265
.endif
285
266
286
267
#ifdef CONFIG_ARM64_SW_TTBR0_PAN
287
- / *
288
- * Restore access to TTBR0_EL1. If returning to EL0 , no need for SPSR
289
- * PAN bit checking.
290
- * /
291
- alternative_if ARM64_HAS_PAN
292
- b 2f // skip TTBR0 PAN
268
+ alternative_if_not ARM64_HAS_PAN
269
+ bl __swpan_exit_el\el
293
270
alternative_else_nop_endif
294
-
295
- .if \el != 0
296
- tbnz x22 , # 22 , 1f // Skip re - enabling TTBR0 access if the PSR_PAN_BIT is set
297
- .endif
298
-
299
- __uaccess_ttbr0_enable x0 , x1
300
-
301
- .if \el == 0
302
- / *
303
- * Enable errata workarounds only if returning to user. The only
304
- * workaround currently required for TTBR0_EL1 changes are for the
305
- * Cavium erratum 27456 (broadcast TLBI instructions may cause I - cache
306
- * corruption).
307
- * /
308
- bl post_ttbr_update_workaround
309
- .endif
310
- 1 :
311
- .if \el != 0
312
- and x22 , x22 , #~PSR_PAN_BIT // ARMv8. 0 CPUs do not understand this bit
313
- .endif
314
- 2 :
315
271
#endif
316
272
317
273
.if \el == 0
@@ -391,6 +347,49 @@ alternative_insn eret, nop, ARM64_UNMAP_KERNEL_AT_EL0
391
347
sb
392
348
.endm
393
349
350
+ #ifdef CONFIG_ARM64_SW_TTBR0_PAN
351
+ / *
352
+ * Set the TTBR0 PAN bit in SPSR. When the exception is taken from
353
+ * EL0 , there is no need to check the state of TTBR0_EL1 since
354
+ * accesses are always enabled.
355
+ * Note th at the meaning of this bit differs from the ARMv8. 1 PAN
356
+ * feature as all TTBR0_EL1 accesses are disabled , not just those to
357
+ * user mappings.
358
+ * /
359
+ SYM_CODE_START_LOCAL(__swpan_entry_el1)
360
+ mrs x21 , ttbr0_el1
361
+ tst x21 , #TTBR_ASID_MASK // Check for the reserved ASID
362
+ orr x23 , x23 , #PSR_PAN_BIT // Set the emulated PAN in the saved SPSR
363
+ b.eq 1f // TTBR0 access already disabled
364
+ and x23 , x23 , #~PSR_PAN_BIT // Clear the emulated PAN in the saved SPSR
365
+ SYM_INNER_LABEL(__swpan_entry_el0 , SYM_L_LOCAL)
366
+ __uaccess_ttbr0_disable x21
367
+ 1 : ret
368
+ SYM_CODE_END(__swpan_entry_el1)
369
+
370
+ / *
371
+ * Restore access to TTBR0_EL1. If returning to EL0 , no need for SPSR
372
+ * PAN bit checking.
373
+ * /
374
+ SYM_CODE_START_LOCAL(__swpan_exit_el1)
375
+ tbnz x22 , # 22 , 1f // Skip re - enabling TTBR0 access if the PSR_PAN_BIT is set
376
+ __uaccess_ttbr0_enable x0 , x1
377
+ 1 : and x22 , x22 , #~PSR_PAN_BIT // ARMv8. 0 CPUs do not understand this bit
378
+ ret
379
+ SYM_CODE_END(__swpan_exit_el1)
380
+
381
+ SYM_CODE_START_LOCAL(__swpan_exit_el0)
382
+ __uaccess_ttbr0_enable x0 , x1
383
+ / *
384
+ * Enable errata workarounds only if returning to user. The only
385
+ * workaround currently required for TTBR0_EL1 changes are for the
386
+ * Cavium erratum 27456 (broadcast TLBI instructions may cause I - cache
387
+ * corruption).
388
+ * /
389
+ b post_ttbr_update_workaround
390
+ SYM_CODE_END(__swpan_exit_el0)
391
+ #endif
392
+
394
393
.macro irq_stack_entry
395
394
mov x19 , sp // preserve the original sp
396
395
#ifdef CONFIG_SHADOW_CALL_STACK
0 commit comments