|
39 | 39 | #endif |
40 | 40 | .endm |
41 | 41 |
|
| 42 | +#if defined(CONFIG_CPU_SW_DOMAIN_PAN) |
| 43 | + |
42 | 44 | .macro uaccess_disable, tmp, isb=1 |
43 | | -#ifdef CONFIG_CPU_SW_DOMAIN_PAN |
44 | 45 | /* |
45 | 46 | * Whenever we re-enter userspace, the domains should always be |
46 | 47 | * set appropriately. |
|
50 | 51 | .if \isb |
51 | 52 | instr_sync |
52 | 53 | .endif |
53 | | -#endif |
54 | 54 | .endm |
55 | 55 |
|
56 | 56 | .macro uaccess_enable, tmp, isb=1 |
57 | | -#ifdef CONFIG_CPU_SW_DOMAIN_PAN |
58 | 57 | /* |
59 | 58 | * Whenever we re-enter userspace, the domains should always be |
60 | 59 | * set appropriately. |
|
64 | 63 | .if \isb |
65 | 64 | instr_sync |
66 | 65 | .endif |
67 | | -#endif |
68 | 66 | .endm |
69 | 67 |
|
| 68 | +#elif defined(CONFIG_CPU_TTBR0_PAN) |
| 69 | + |
| 70 | + .macro uaccess_disable, tmp, isb=1 |
| 71 | + /* |
| 72 | + * Disable TTBR0 page table walks (EDP0 = 1), use the reserved ASID |
| 73 | + * from TTBR1 (A1 = 1) and enable TTBR1 page table walks for kernel |
| 74 | + * addresses by reducing TTBR0 range to 32MB (T0SZ = 7). |
| 75 | + */ |
| 76 | + mrc p15, 0, \tmp, c2, c0, 2 @ read TTBCR |
| 77 | + orr \tmp, \tmp, #TTBCR_EPD0 | TTBCR_T0SZ_MASK |
| 78 | + orr \tmp, \tmp, #TTBCR_A1 |
| 79 | + mcr p15, 0, \tmp, c2, c0, 2 @ write TTBCR |
| 80 | + .if \isb |
| 81 | + instr_sync |
| 82 | + .endif |
| 83 | + .endm |
| 84 | + |
| 85 | + .macro uaccess_enable, tmp, isb=1 |
| 86 | + /* |
| 87 | + * Enable TTBR0 page table walks (T0SZ = 0, EDP0 = 0) and ASID from |
| 88 | + * TTBR0 (A1 = 0). |
| 89 | + */ |
| 90 | + mrc p15, 0, \tmp, c2, c0, 2 @ read TTBCR |
| 91 | + bic \tmp, \tmp, #TTBCR_EPD0 | TTBCR_T0SZ_MASK |
| 92 | + bic \tmp, \tmp, #TTBCR_A1 |
| 93 | + mcr p15, 0, \tmp, c2, c0, 2 @ write TTBCR |
| 94 | + .if \isb |
| 95 | + instr_sync |
| 96 | + .endif |
| 97 | + .endm |
| 98 | + |
| 99 | +#else |
| 100 | + |
| 101 | + .macro uaccess_disable, tmp, isb=1 |
| 102 | + .endm |
| 103 | + |
| 104 | + .macro uaccess_enable, tmp, isb=1 |
| 105 | + .endm |
| 106 | + |
| 107 | +#endif |
| 108 | + |
70 | 109 | #if defined(CONFIG_CPU_SW_DOMAIN_PAN) || defined(CONFIG_CPU_USE_DOMAINS) |
71 | 110 | #define DACR(x...) x |
72 | 111 | #else |
73 | 112 | #define DACR(x...) |
| 113 | +#endif |
| 114 | + |
| 115 | +#ifdef CONFIG_CPU_TTBR0_PAN |
| 116 | +#define PAN(x...) x |
| 117 | +#else |
| 118 | +#define PAN(x...) |
74 | 119 | #endif |
75 | 120 |
|
76 | 121 | /* |
|
86 | 131 | .macro uaccess_entry, tsk, tmp0, tmp1, tmp2, disable |
87 | 132 | DACR( mrc p15, 0, \tmp0, c3, c0, 0) |
88 | 133 | DACR( str \tmp0, [sp, #SVC_DACR]) |
| 134 | + PAN( mrc p15, 0, \tmp0, c2, c0, 2) |
| 135 | + PAN( str \tmp0, [sp, #SVC_TTBCR]) |
89 | 136 | .if \disable && IS_ENABLED(CONFIG_CPU_SW_DOMAIN_PAN) |
90 | 137 | /* kernel=client, user=no access */ |
91 | 138 | mov \tmp2, #DACR_UACCESS_DISABLE |
|
104 | 151 | .macro uaccess_exit, tsk, tmp0, tmp1 |
105 | 152 | DACR( ldr \tmp0, [sp, #SVC_DACR]) |
106 | 153 | DACR( mcr p15, 0, \tmp0, c3, c0, 0) |
| 154 | + PAN( ldr \tmp0, [sp, #SVC_TTBCR]) |
| 155 | + PAN( mcr p15, 0, \tmp0, c2, c0, 2) |
107 | 156 | .endm |
108 | 157 |
|
109 | 158 | #undef DACR |
| 159 | +#undef PAN |
110 | 160 |
|
111 | 161 | #endif /* __ASM_UACCESS_ASM_H__ */ |
0 commit comments