Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __ASM_ASM_UACCESS_H
0003 #define __ASM_ASM_UACCESS_H
0004 
0005 #include <asm/alternative-macros.h>
0006 #include <asm/asm-extable.h>
0007 #include <asm/assembler.h>
0008 #include <asm/kernel-pgtable.h>
0009 #include <asm/mmu.h>
0010 #include <asm/sysreg.h>
0011 
0012 /*
0013  * User access enabling/disabling macros.
0014  */
0015 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
0016     .macro  __uaccess_ttbr0_disable, tmp1
0017     mrs \tmp1, ttbr1_el1            // swapper_pg_dir
0018     bic \tmp1, \tmp1, #TTBR_ASID_MASK
0019     sub \tmp1, \tmp1, #RESERVED_SWAPPER_OFFSET  // reserved_pg_dir
0020     msr ttbr0_el1, \tmp1            // set reserved TTBR0_EL1
0021     isb
0022     add \tmp1, \tmp1, #RESERVED_SWAPPER_OFFSET
0023     msr ttbr1_el1, \tmp1        // set reserved ASID
0024     isb
0025     .endm
0026 
0027     .macro  __uaccess_ttbr0_enable, tmp1, tmp2
0028     get_current_task \tmp1
0029     ldr \tmp1, [\tmp1, #TSK_TI_TTBR0]   // load saved TTBR0_EL1
0030     mrs \tmp2, ttbr1_el1
0031     extr    \tmp2, \tmp2, \tmp1, #48
0032     ror     \tmp2, \tmp2, #16
0033     msr ttbr1_el1, \tmp2        // set the active ASID
0034     isb
0035     msr ttbr0_el1, \tmp1        // set the non-PAN TTBR0_EL1
0036     isb
0037     .endm
0038 
0039     .macro  uaccess_ttbr0_disable, tmp1, tmp2
0040 alternative_if_not ARM64_HAS_PAN
0041     save_and_disable_irq \tmp2      // avoid preemption
0042     __uaccess_ttbr0_disable \tmp1
0043     restore_irq \tmp2
0044 alternative_else_nop_endif
0045     .endm
0046 
0047     .macro  uaccess_ttbr0_enable, tmp1, tmp2, tmp3
0048 alternative_if_not ARM64_HAS_PAN
0049     save_and_disable_irq \tmp3      // avoid preemption
0050     __uaccess_ttbr0_enable \tmp1, \tmp2
0051     restore_irq \tmp3
0052 alternative_else_nop_endif
0053     .endm
0054 #else
0055     .macro  uaccess_ttbr0_disable, tmp1, tmp2
0056     .endm
0057 
0058     .macro  uaccess_ttbr0_enable, tmp1, tmp2, tmp3
0059     .endm
0060 #endif
0061 
0062 #define USER(l, x...)               \
0063 9999:   x;                  \
0064     _asm_extable_uaccess    9999b, l
0065 
0066 /*
0067  * Generate the assembly for LDTR/STTR with exception table entries.
0068  * This is complicated as there is no post-increment or pair versions of the
0069  * unprivileged instructions, and USER() only works for single instructions.
0070  */
0071     .macro user_ldp l, reg1, reg2, addr, post_inc
0072 8888:       ldtr    \reg1, [\addr];
0073 8889:       ldtr    \reg2, [\addr, #8];
0074         add \addr, \addr, \post_inc;
0075 
0076         _asm_extable_uaccess    8888b, \l;
0077         _asm_extable_uaccess    8889b, \l;
0078     .endm
0079 
0080     .macro user_stp l, reg1, reg2, addr, post_inc
0081 8888:       sttr    \reg1, [\addr];
0082 8889:       sttr    \reg2, [\addr, #8];
0083         add \addr, \addr, \post_inc;
0084 
0085         _asm_extable_uaccess    8888b,\l;
0086         _asm_extable_uaccess    8889b,\l;
0087     .endm
0088 
0089     .macro user_ldst l, inst, reg, addr, post_inc
0090 8888:       \inst       \reg, [\addr];
0091         add     \addr, \addr, \post_inc;
0092 
0093         _asm_extable_uaccess    8888b, \l;
0094     .endm
0095 #endif