Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * |
| 4 | * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 5 | */ |
| 6 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 8 | #include <buffer.h> |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 9 | #include <errno.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 10 | #include <granule.h> |
| 11 | #include <measurement.h> |
| 12 | #include <realm.h> |
| 13 | #include <ripas.h> |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 14 | #include <s2tt.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 15 | #include <smc-handler.h> |
| 16 | #include <smc-rmi.h> |
| 17 | #include <smc.h> |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 18 | #include <status.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 19 | #include <stddef.h> |
| 20 | #include <string.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * Validate the map_addr value passed to RMI_RTT_* and RMI_DATA_* commands. |
| 24 | */ |
| 25 | static bool validate_map_addr(unsigned long map_addr, |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 26 | long level, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 27 | struct rd *rd) |
| 28 | { |
AlexeiFedorov | 14d47ae | 2023-07-19 15:26:50 +0100 | [diff] [blame] | 29 | return ((map_addr < realm_ipa_size(rd)) && |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 30 | s2tte_is_addr_lvl_aligned(&(rd->s2_ctx), map_addr, level)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | /* |
| 34 | * Structure commands can operate on all RTTs except for the root RTT so |
| 35 | * the minimal valid level is the stage 2 starting level + 1. |
| 36 | */ |
| 37 | static bool validate_rtt_structure_cmds(unsigned long map_addr, |
| 38 | long level, |
| 39 | struct rd *rd) |
| 40 | { |
| 41 | int min_level = realm_rtt_starting_level(rd) + 1; |
| 42 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 43 | if ((level < min_level) || (level > S2TT_PAGE_LEVEL)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 44 | return false; |
| 45 | } |
AlexeiFedorov | f85f810 | 2023-09-11 16:14:18 +0100 | [diff] [blame] | 46 | return validate_map_addr(map_addr, level - 1L, rd); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Map/Unmap commands can operate up to a level 2 block entry so min_level is |
| 51 | * the smallest block size. |
| 52 | */ |
| 53 | static bool validate_rtt_map_cmds(unsigned long map_addr, |
| 54 | long level, |
| 55 | struct rd *rd) |
| 56 | { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 57 | if ((level < S2TT_MIN_BLOCK_LEVEL) || (level > S2TT_PAGE_LEVEL)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 58 | return false; |
| 59 | } |
| 60 | return validate_map_addr(map_addr, level, rd); |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Entry commands can operate on any entry so the minimal valid level is the |
| 65 | * stage 2 starting level. |
| 66 | */ |
| 67 | static bool validate_rtt_entry_cmds(unsigned long map_addr, |
| 68 | long level, |
| 69 | struct rd *rd) |
| 70 | { |
| 71 | if ((level < realm_rtt_starting_level(rd)) || |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 72 | (level > S2TT_PAGE_LEVEL)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 73 | return false; |
| 74 | } |
| 75 | return validate_map_addr(map_addr, level, rd); |
| 76 | } |
| 77 | |
AlexeiFedorov | ac923c8 | 2023-04-06 15:12:04 +0100 | [diff] [blame] | 78 | unsigned long smc_rtt_create(unsigned long rd_addr, |
| 79 | unsigned long rtt_addr, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 80 | unsigned long map_addr, |
| 81 | unsigned long ulevel) |
| 82 | { |
| 83 | struct granule *g_rd; |
| 84 | struct granule *g_tbl; |
| 85 | struct rd *rd; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 86 | struct s2tt_walk wi; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 87 | unsigned long *s2tt, *parent_s2tt, parent_s2tte; |
| 88 | long level = (long)ulevel; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 89 | unsigned long ret; |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 90 | struct s2tt_context s2_ctx; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 91 | |
| 92 | if (!find_lock_two_granules(rtt_addr, |
| 93 | GRANULE_STATE_DELEGATED, |
| 94 | &g_tbl, |
| 95 | rd_addr, |
| 96 | GRANULE_STATE_RD, |
| 97 | &g_rd)) { |
| 98 | return RMI_ERROR_INPUT; |
| 99 | } |
| 100 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 101 | rd = buffer_granule_map(g_rd, SLOT_RD); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 102 | assert(rd != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 103 | |
| 104 | if (!validate_rtt_structure_cmds(map_addr, level, rd)) { |
| 105 | buffer_unmap(rd); |
| 106 | granule_unlock(g_rd); |
| 107 | granule_unlock(g_tbl); |
| 108 | return RMI_ERROR_INPUT; |
| 109 | } |
| 110 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 111 | s2_ctx = rd->s2_ctx; |
| 112 | buffer_unmap(rd); |
| 113 | |
| 114 | /* |
Shruti Gupta | 3530a71 | 2024-09-12 10:50:21 +0100 | [diff] [blame] | 115 | * If LPA2 is disabled for the realm, then `rtt_addr` must not be |
| 116 | * more than 48 bits wide. |
| 117 | */ |
| 118 | if (!s2_ctx.enable_lpa2) { |
| 119 | if ((rtt_addr >= (UL(1) << S2TT_MAX_PA_BITS))) { |
| 120 | granule_unlock(g_rd); |
| 121 | granule_unlock(g_tbl); |
| 122 | return RMI_ERROR_INPUT; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | /* |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 127 | * Lock the RTT root. Enforcing locking order RD->RTT is enough to |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 128 | * ensure deadlock free locking guarantee. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 129 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 130 | granule_lock(s2_ctx.g_rtt, GRANULE_STATE_RTT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 131 | |
| 132 | /* Unlock RD after locking RTT Root */ |
| 133 | granule_unlock(g_rd); |
| 134 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 135 | s2tt_walk_lock_unlock(&s2_ctx, map_addr, level - 1L, &wi); |
AlexeiFedorov | 3f5d627 | 2023-10-23 16:27:37 +0100 | [diff] [blame] | 136 | if (wi.last_level != (level - 1L)) { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 137 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 138 | (unsigned char)wi.last_level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 139 | goto out_unlock_llt; |
| 140 | } |
| 141 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 142 | parent_s2tt = buffer_granule_map(wi.g_llt, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 143 | assert(parent_s2tt != NULL); |
| 144 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 145 | parent_s2tte = s2tte_read(&parent_s2tt[wi.index]); |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 146 | s2tt = buffer_granule_map(g_tbl, SLOT_DELEGATED); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 147 | assert(s2tt != NULL); |
| 148 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 149 | if (s2tte_is_unassigned_empty(&s2_ctx, parent_s2tte)) { |
| 150 | s2tt_init_unassigned_empty(&s2_ctx, s2tt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 151 | |
| 152 | /* |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 153 | * Atomically increase the refcount of the parent, the granule |
| 154 | * was locked while table walking and hand-over-hand locking. |
| 155 | * Acquire/release semantics not required because the table is |
| 156 | * accessed always locked. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 157 | */ |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 158 | atomic_granule_get(wi.g_llt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 159 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 160 | } else if (s2tte_is_unassigned_ram(&s2_ctx, parent_s2tte)) { |
| 161 | s2tt_init_unassigned_ram(&s2_ctx, s2tt); |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 162 | atomic_granule_get(wi.g_llt); |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 163 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 164 | } else if (s2tte_is_unassigned_ns(&s2_ctx, parent_s2tte)) { |
| 165 | s2tt_init_unassigned_ns(&s2_ctx, s2tt); |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 166 | atomic_granule_get(wi.g_llt); |
AlexeiFedorov | 5ceff35 | 2023-04-12 16:17:00 +0100 | [diff] [blame] | 167 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 168 | } else if (s2tte_is_unassigned_destroyed(&s2_ctx, parent_s2tte)) { |
| 169 | s2tt_init_unassigned_destroyed(&s2_ctx, s2tt); |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 170 | atomic_granule_get(wi.g_llt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 171 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 172 | } else if (s2tte_is_assigned_destroyed(&s2_ctx, parent_s2tte, |
| 173 | level - 1L)) { |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 174 | unsigned long block_pa; |
| 175 | |
| 176 | /* |
| 177 | * We should observe parent assigned s2tte only when |
| 178 | * we create tables above this level. |
| 179 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 180 | assert(level > S2TT_MIN_BLOCK_LEVEL); |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 181 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 182 | block_pa = s2tte_pa(&s2_ctx, parent_s2tte, level - 1L); |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 183 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 184 | s2tt_init_assigned_destroyed(&s2_ctx, s2tt, block_pa, level); |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 185 | |
| 186 | /* |
| 187 | * Increase the refcount to mark the granule as in-use. refcount |
| 188 | * is incremented by S2TTES_PER_S2TT (ref RTT unfolding). |
| 189 | */ |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 190 | granule_refcount_inc(g_tbl, (unsigned short)S2TTES_PER_S2TT); |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 191 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 192 | } else if (s2tte_is_assigned_empty(&s2_ctx, parent_s2tte, level - 1L)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 193 | unsigned long block_pa; |
| 194 | |
| 195 | /* |
| 196 | * We should observe parent assigned s2tte only when |
| 197 | * we create tables above this level. |
| 198 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 199 | assert(level > S2TT_MIN_BLOCK_LEVEL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 200 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 201 | block_pa = s2tte_pa(&s2_ctx, parent_s2tte, level - 1L); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 202 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 203 | s2tt_init_assigned_empty(&s2_ctx, s2tt, block_pa, level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 204 | |
| 205 | /* |
| 206 | * Increase the refcount to mark the granule as in-use. refcount |
| 207 | * is incremented by S2TTES_PER_S2TT (ref RTT unfolding). |
| 208 | */ |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 209 | granule_refcount_inc(g_tbl, (unsigned short)S2TTES_PER_S2TT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 210 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 211 | } else if (s2tte_is_assigned_ram(&s2_ctx, parent_s2tte, level - 1L)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 212 | unsigned long block_pa; |
| 213 | |
| 214 | /* |
| 215 | * We should observe parent valid s2tte only when |
| 216 | * we create tables above this level. |
| 217 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 218 | assert(level > S2TT_MIN_BLOCK_LEVEL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * Break before make. This may cause spurious S2 aborts. |
| 222 | */ |
| 223 | s2tte_write(&parent_s2tt[wi.index], 0UL); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 224 | s2tt_invalidate_block(&s2_ctx, map_addr); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 225 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 226 | block_pa = s2tte_pa(&s2_ctx, parent_s2tte, level - 1L); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 227 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 228 | s2tt_init_assigned_ram(&s2_ctx, s2tt, block_pa, level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * Increase the refcount to mark the granule as in-use. refcount |
| 232 | * is incremented by S2TTES_PER_S2TT (ref RTT unfolding). |
| 233 | */ |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 234 | granule_refcount_inc(g_tbl, (unsigned short)S2TTES_PER_S2TT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 235 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 236 | } else if (s2tte_is_assigned_ns(&s2_ctx, parent_s2tte, level - 1L)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 237 | unsigned long block_pa; |
| 238 | |
| 239 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 240 | * We should observe parent assigned_ns s2tte only when |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 241 | * we create tables above this level. |
| 242 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 243 | assert(level > S2TT_MIN_BLOCK_LEVEL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * Break before make. This may cause spurious S2 aborts. |
| 247 | */ |
| 248 | s2tte_write(&parent_s2tt[wi.index], 0UL); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 249 | s2tt_invalidate_block(&s2_ctx, map_addr); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 250 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 251 | block_pa = s2tte_pa(&s2_ctx, parent_s2tte, level - 1L); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 252 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 253 | s2tt_init_assigned_ns(&s2_ctx, s2tt, parent_s2tte, |
| 254 | block_pa, level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 255 | |
| 256 | /* |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 257 | * Increment the refcount on the parent for the new RTT we are |
| 258 | * about to add. The NS block entry doesn't have a refcount |
| 259 | * on the parent RTT. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 260 | */ |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 261 | atomic_granule_get(wi.g_llt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 262 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 263 | } else if (s2tte_is_table(&s2_ctx, parent_s2tte, level - 1L)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 264 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 265 | (unsigned char)(level - 1L)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 266 | goto out_unmap_table; |
| 267 | |
| 268 | } else { |
| 269 | assert(false); |
| 270 | } |
| 271 | |
| 272 | ret = RMI_SUCCESS; |
| 273 | |
| 274 | granule_set_state(g_tbl, GRANULE_STATE_RTT); |
| 275 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 276 | parent_s2tte = s2tte_create_table(&s2_ctx, rtt_addr, level - 1L); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 277 | s2tte_write(&parent_s2tt[wi.index], parent_s2tte); |
| 278 | |
| 279 | out_unmap_table: |
| 280 | buffer_unmap(s2tt); |
| 281 | buffer_unmap(parent_s2tt); |
| 282 | out_unlock_llt: |
| 283 | granule_unlock(wi.g_llt); |
| 284 | granule_unlock(g_tbl); |
| 285 | return ret; |
| 286 | } |
| 287 | |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 288 | void smc_rtt_fold(unsigned long rd_addr, |
| 289 | unsigned long map_addr, |
| 290 | unsigned long ulevel, |
| 291 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 292 | { |
| 293 | struct granule *g_rd; |
| 294 | struct granule *g_tbl; |
| 295 | struct rd *rd; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 296 | struct s2tt_walk wi; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 297 | unsigned long *table, *parent_s2tt, parent_s2tte; |
| 298 | long level = (long)ulevel; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 299 | unsigned long rtt_addr; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 300 | unsigned long ret; |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 301 | struct s2tt_context s2_ctx; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 302 | |
| 303 | g_rd = find_lock_granule(rd_addr, GRANULE_STATE_RD); |
| 304 | if (g_rd == NULL) { |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 305 | res->x[0] = RMI_ERROR_INPUT; |
| 306 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 309 | rd = buffer_granule_map(g_rd, SLOT_RD); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 310 | assert(rd != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 311 | |
| 312 | if (!validate_rtt_structure_cmds(map_addr, level, rd)) { |
| 313 | buffer_unmap(rd); |
| 314 | granule_unlock(g_rd); |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 315 | res->x[0] = RMI_ERROR_INPUT; |
| 316 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 319 | s2_ctx = rd->s2_ctx; |
| 320 | buffer_unmap(rd); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 321 | granule_lock(s2_ctx.g_rtt, GRANULE_STATE_RTT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 322 | granule_unlock(g_rd); |
| 323 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 324 | s2tt_walk_lock_unlock(&s2_ctx, map_addr, level - 1L, &wi); |
AlexeiFedorov | 3f5d627 | 2023-10-23 16:27:37 +0100 | [diff] [blame] | 325 | if (wi.last_level != (level - 1L)) { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 326 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 327 | (unsigned char)wi.last_level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 328 | goto out_unlock_parent_table; |
| 329 | } |
| 330 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 331 | parent_s2tt = buffer_granule_map(wi.g_llt, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 332 | assert(parent_s2tt != NULL); |
| 333 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 334 | parent_s2tte = s2tte_read(&parent_s2tt[wi.index]); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 335 | if (!s2tte_is_table(&s2_ctx, parent_s2tte, level - 1L)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 336 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 337 | (unsigned char)(level - 1L)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 338 | goto out_unmap_parent_table; |
| 339 | } |
| 340 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 341 | rtt_addr = s2tte_pa(&s2_ctx, parent_s2tte, level - 1L); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 342 | g_tbl = find_lock_granule(rtt_addr, GRANULE_STATE_RTT); |
| 343 | |
| 344 | /* |
| 345 | * A table descriptor S2TTE always points to a TABLE granule. |
| 346 | */ |
AlexeiFedorov | 63b7169 | 2023-04-19 11:18:42 +0100 | [diff] [blame] | 347 | assert(g_tbl != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 348 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 349 | table = buffer_granule_map(g_tbl, SLOT_RTT2); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 350 | assert(table != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 351 | |
| 352 | /* |
| 353 | * The command can succeed only if all 512 S2TTEs are of the same type. |
| 354 | * We first check the table's ref. counter to speed up the case when |
| 355 | * the host makes a guess whether a memory region can be folded. |
| 356 | */ |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 357 | if (granule_refcount_read(g_tbl) == 0U) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 358 | if (s2tt_is_unassigned_destroyed_block(&s2_ctx, table)) { |
| 359 | parent_s2tte = s2tte_create_unassigned_destroyed(&s2_ctx); |
| 360 | } else if (s2tt_is_unassigned_empty_block(&s2_ctx, table)) { |
| 361 | parent_s2tte = s2tte_create_unassigned_empty(&s2_ctx); |
| 362 | } else if (s2tt_is_unassigned_ram_block(&s2_ctx, table)) { |
| 363 | parent_s2tte = s2tte_create_unassigned_ram(&s2_ctx); |
| 364 | } else if (s2tt_is_unassigned_ns_block(&s2_ctx, table)) { |
| 365 | parent_s2tte = s2tte_create_unassigned_ns(&s2_ctx); |
| 366 | } else if (s2tt_maps_assigned_ns_block(&s2_ctx, table, level)) { |
Shruti Gupta | 3105c3f | 2024-02-26 14:06:11 +0000 | [diff] [blame] | 367 | |
| 368 | /* |
| 369 | * The RMM specification does not allow creating block entries less than |
| 370 | * S2TT_MIN_BLOCK_LEVEL for ASSIGNED_NS state. |
| 371 | */ |
| 372 | if (level <= S2TT_MIN_BLOCK_LEVEL) { |
| 373 | ret = pack_return_code(RMI_ERROR_RTT, |
| 374 | (unsigned char)wi.last_level); |
| 375 | goto out_unmap_table; |
| 376 | } |
AlexeiFedorov | 49752c6 | 2023-04-24 14:31:14 +0100 | [diff] [blame] | 377 | unsigned long s2tte = s2tte_read(&table[0]); |
AlexeiFedorov | c07a638 | 2023-04-14 11:59:18 +0100 | [diff] [blame] | 378 | |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 379 | /* |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 380 | * Since s2tt_maps_assigned_ns_block() has succedded, |
Javier Almansa Sobrino | 15fc44e | 2023-09-29 13:52:04 +0100 | [diff] [blame] | 381 | * the PA in first entry of the table is aligned at |
| 382 | * parent level. Use the TTE from the first entry |
| 383 | * directly as it also has the NS attributes to be used |
| 384 | * for the parent block entry. |
| 385 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 386 | parent_s2tte = s2tte_create_assigned_ns(&s2_ctx, s2tte, level - 1L); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 387 | } else { |
| 388 | /* |
| 389 | * The table holds a mixture of destroyed and |
| 390 | * unassigned entries. |
| 391 | */ |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 392 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 393 | (unsigned char)level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 394 | goto out_unmap_table; |
| 395 | } |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 396 | atomic_granule_put(wi.g_llt); |
| 397 | } else if (granule_refcount_read(g_tbl) == |
| 398 | (unsigned short)S2TTES_PER_S2TT) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 399 | |
| 400 | unsigned long s2tte, block_pa; |
| 401 | |
| 402 | /* The RMM specification does not allow creating block |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 403 | * entries less than S2TT_MIN_BLOCK_LEVEL even though |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 404 | * permitted by the Arm Architecture. |
| 405 | * Hence ensure that the table being folded is at a level |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 406 | * higher than the S2TT_MIN_BLOCK_LEVEL. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 407 | * |
| 408 | * A fully populated table cannot be destroyed if that |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 409 | * would create a block mapping below S2TT_MIN_BLOCK_LEVEL. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 410 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 411 | if (level <= S2TT_MIN_BLOCK_LEVEL) { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 412 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 413 | (unsigned char)wi.last_level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 414 | goto out_unmap_table; |
| 415 | } |
| 416 | |
| 417 | s2tte = s2tte_read(&table[0]); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 418 | block_pa = s2tte_pa(&s2_ctx, s2tte, level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 419 | |
| 420 | /* |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 421 | * The table must also refer to a contiguous block through the |
AlexeiFedorov | 3f840a0 | 2023-07-19 10:55:05 +0100 | [diff] [blame] | 422 | * same type of s2tte, either Assigned or Valid. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 423 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 424 | if (s2tt_maps_assigned_empty_block(&s2_ctx, table, level)) { |
| 425 | parent_s2tte = s2tte_create_assigned_empty(&s2_ctx, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 426 | block_pa, level - 1L); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 427 | } else if (s2tt_maps_assigned_ram_block(&s2_ctx, |
| 428 | table, level)) { |
| 429 | parent_s2tte = s2tte_create_assigned_ram(&s2_ctx, |
| 430 | block_pa, |
AlexeiFedorov | 3a73933 | 2023-04-13 13:54:04 +0100 | [diff] [blame] | 431 | level - 1L); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 432 | } else if (s2tt_maps_assigned_destroyed_block(&s2_ctx, |
| 433 | table, level)) { |
| 434 | parent_s2tte = s2tte_create_assigned_destroyed(&s2_ctx, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 435 | block_pa, level - 1L); |
AlexeiFedorov | 80c2f04 | 2022-11-25 14:54:46 +0000 | [diff] [blame] | 436 | /* The table contains mixed entries that cannot be folded */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 437 | } else { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 438 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 439 | (unsigned char)level); |
AlexeiFedorov | 80c2f04 | 2022-11-25 14:54:46 +0000 | [diff] [blame] | 440 | goto out_unmap_table; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 441 | } |
| 442 | |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 443 | granule_refcount_dec(g_tbl, (unsigned short)S2TTES_PER_S2TT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 444 | } else { |
| 445 | /* |
| 446 | * The table holds a mixture of different types of s2ttes. |
| 447 | */ |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 448 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 449 | (unsigned char)level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 450 | goto out_unmap_table; |
| 451 | } |
| 452 | |
| 453 | ret = RMI_SUCCESS; |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 454 | res->x[1] = rtt_addr; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 455 | |
| 456 | /* |
| 457 | * Break before make. |
| 458 | */ |
| 459 | s2tte_write(&parent_s2tt[wi.index], 0UL); |
| 460 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 461 | if (s2tte_is_assigned_ram(&s2_ctx, parent_s2tte, level - 1L) || |
| 462 | s2tte_is_assigned_ns(&s2_ctx, parent_s2tte, level - 1L)) { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 463 | s2tt_invalidate_pages_in_block(&s2_ctx, map_addr); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 464 | } else { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 465 | s2tt_invalidate_block(&s2_ctx, map_addr); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | s2tte_write(&parent_s2tt[wi.index], parent_s2tte); |
| 469 | |
| 470 | granule_memzero_mapped(table); |
| 471 | granule_set_state(g_tbl, GRANULE_STATE_DELEGATED); |
| 472 | |
| 473 | out_unmap_table: |
| 474 | buffer_unmap(table); |
| 475 | granule_unlock(g_tbl); |
| 476 | out_unmap_parent_table: |
| 477 | buffer_unmap(parent_s2tt); |
| 478 | out_unlock_parent_table: |
| 479 | granule_unlock(wi.g_llt); |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 480 | res->x[0] = ret; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 481 | } |
| 482 | |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 483 | void smc_rtt_destroy(unsigned long rd_addr, |
| 484 | unsigned long map_addr, |
| 485 | unsigned long ulevel, |
| 486 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 487 | { |
| 488 | struct granule *g_rd; |
| 489 | struct granule *g_tbl; |
| 490 | struct rd *rd; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 491 | struct s2tt_walk wi; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 492 | unsigned long *table, *parent_s2tt, parent_s2tte; |
| 493 | long level = (long)ulevel; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 494 | unsigned long rtt_addr; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 495 | unsigned long ret; |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 496 | struct s2tt_context s2_ctx; |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 497 | bool in_par, skip_non_live = false; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 498 | |
| 499 | g_rd = find_lock_granule(rd_addr, GRANULE_STATE_RD); |
| 500 | if (g_rd == NULL) { |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 501 | res->x[0] = RMI_ERROR_INPUT; |
AlexeiFedorov | 3ebd462 | 2023-07-18 16:27:39 +0100 | [diff] [blame] | 502 | res->x[2] = 0UL; |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 503 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 506 | rd = buffer_granule_map(g_rd, SLOT_RD); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 507 | assert(rd != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 508 | |
| 509 | if (!validate_rtt_structure_cmds(map_addr, level, rd)) { |
| 510 | buffer_unmap(rd); |
| 511 | granule_unlock(g_rd); |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 512 | res->x[0] = RMI_ERROR_INPUT; |
AlexeiFedorov | 3ebd462 | 2023-07-18 16:27:39 +0100 | [diff] [blame] | 513 | res->x[2] = 0UL; |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 514 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 517 | s2_ctx = rd->s2_ctx; |
| 518 | in_par = addr_in_par(rd, map_addr); |
| 519 | buffer_unmap(rd); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 520 | granule_lock(s2_ctx.g_rtt, GRANULE_STATE_RTT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 521 | granule_unlock(g_rd); |
| 522 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 523 | s2tt_walk_lock_unlock(&s2_ctx, map_addr, level - 1L, &wi); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 524 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 525 | parent_s2tt = buffer_granule_map(wi.g_llt, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 526 | assert(parent_s2tt != NULL); |
| 527 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 528 | parent_s2tte = s2tte_read(&parent_s2tt[wi.index]); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 529 | |
AlexeiFedorov | 3f5d627 | 2023-10-23 16:27:37 +0100 | [diff] [blame] | 530 | if ((wi.last_level != (level - 1L)) || |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 531 | !s2tte_is_table(&s2_ctx, parent_s2tte, level - 1L)) { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 532 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 533 | (unsigned char)wi.last_level); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 534 | skip_non_live = true; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 535 | goto out_unmap_parent_table; |
| 536 | } |
| 537 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 538 | rtt_addr = s2tte_pa(&s2_ctx, parent_s2tte, level - 1L); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 539 | |
| 540 | /* |
| 541 | * Lock the RTT granule. The 'rtt_addr' is verified, thus can be treated |
| 542 | * as an internal granule. |
| 543 | */ |
| 544 | g_tbl = find_lock_granule(rtt_addr, GRANULE_STATE_RTT); |
| 545 | |
| 546 | /* |
| 547 | * A table descriptor S2TTE always points to a TABLE granule. |
| 548 | */ |
| 549 | assert(g_tbl != NULL); |
| 550 | |
| 551 | /* |
| 552 | * Read the refcount value. RTT granule is always accessed locked, thus |
| 553 | * the refcount can be accessed without atomic operations. |
| 554 | */ |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 555 | if (granule_refcount_read(g_tbl) != 0U) { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 556 | ret = pack_return_code(RMI_ERROR_RTT, (unsigned char)level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 557 | goto out_unlock_table; |
| 558 | } |
| 559 | |
| 560 | ret = RMI_SUCCESS; |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 561 | res->x[1] = rtt_addr; |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 562 | skip_non_live = true; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 563 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 564 | table = buffer_granule_map(g_tbl, SLOT_RTT2); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 565 | assert(table != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 566 | |
| 567 | if (in_par) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 568 | parent_s2tte = s2tte_create_unassigned_destroyed(&s2_ctx); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 569 | } else { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 570 | parent_s2tte = s2tte_create_unassigned_ns(&s2_ctx); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 571 | } |
| 572 | |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 573 | atomic_granule_put(wi.g_llt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 574 | |
| 575 | /* |
| 576 | * Break before make. Note that this may cause spurious S2 aborts. |
| 577 | */ |
| 578 | s2tte_write(&parent_s2tt[wi.index], 0UL); |
AlexeiFedorov | 22ba106 | 2023-11-15 16:23:37 +0000 | [diff] [blame] | 579 | |
| 580 | if (in_par) { |
| 581 | /* For protected IPA, all S2TTEs in the RTT will be invalid */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 582 | s2tt_invalidate_block(&s2_ctx, map_addr); |
AlexeiFedorov | 22ba106 | 2023-11-15 16:23:37 +0000 | [diff] [blame] | 583 | } else { |
| 584 | /* |
| 585 | * For unprotected IPA, invalidate the TLB for the entire range |
| 586 | * mapped by the RTT as it may have valid NS mappings. |
| 587 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 588 | s2tt_invalidate_pages_in_block(&s2_ctx, map_addr); |
AlexeiFedorov | 22ba106 | 2023-11-15 16:23:37 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 591 | s2tte_write(&parent_s2tt[wi.index], parent_s2tte); |
| 592 | |
| 593 | granule_memzero_mapped(table); |
| 594 | granule_set_state(g_tbl, GRANULE_STATE_DELEGATED); |
| 595 | |
| 596 | buffer_unmap(table); |
| 597 | out_unlock_table: |
| 598 | granule_unlock(g_tbl); |
| 599 | out_unmap_parent_table: |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 600 | if (skip_non_live) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 601 | res->x[2] = s2tt_skip_non_live_entries(&s2_ctx, map_addr, |
| 602 | parent_s2tt, &wi); |
AlexeiFedorov | 3ebd462 | 2023-07-18 16:27:39 +0100 | [diff] [blame] | 603 | } else { |
| 604 | res->x[2] = map_addr; |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 605 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 606 | buffer_unmap(parent_s2tt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 607 | granule_unlock(wi.g_llt); |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 608 | res->x[0] = ret; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | enum map_unmap_ns_op { |
| 612 | MAP_NS, |
| 613 | UNMAP_NS |
| 614 | }; |
| 615 | |
| 616 | /* |
| 617 | * We don't hold a reference on the NS granule when it is |
| 618 | * mapped into a realm. Instead we rely on the guarantees |
| 619 | * provided by the architecture to ensure that a NS access |
| 620 | * to a protected granule is prohibited even within the realm. |
| 621 | */ |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 622 | static void map_unmap_ns(unsigned long rd_addr, |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 623 | unsigned long map_addr, |
| 624 | long level, |
| 625 | unsigned long host_s2tte, |
| 626 | enum map_unmap_ns_op op, |
| 627 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 628 | { |
| 629 | struct granule *g_rd; |
| 630 | struct rd *rd; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 631 | unsigned long *s2tt, s2tte; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 632 | struct s2tt_walk wi; |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 633 | struct s2tt_context s2_ctx; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 634 | |
| 635 | g_rd = find_lock_granule(rd_addr, GRANULE_STATE_RD); |
| 636 | if (g_rd == NULL) { |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 637 | res->x[0] = RMI_ERROR_INPUT; |
| 638 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 641 | rd = buffer_granule_map(g_rd, SLOT_RD); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 642 | assert(rd != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 643 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 644 | s2_ctx = rd->s2_ctx; |
| 645 | |
| 646 | if (op == MAP_NS) { |
| 647 | if (!host_ns_s2tte_is_valid(&s2_ctx, host_s2tte, level)) { |
| 648 | buffer_unmap(rd); |
| 649 | granule_unlock(g_rd); |
| 650 | res->x[0] = RMI_ERROR_INPUT; |
| 651 | return; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 656 | if (!validate_rtt_map_cmds(map_addr, level, rd)) { |
| 657 | buffer_unmap(rd); |
| 658 | granule_unlock(g_rd); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 659 | res->x[0] = RMI_ERROR_INPUT; |
| 660 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 661 | } |
| 662 | |
AlexeiFedorov | c34e324 | 2023-04-12 11:30:33 +0100 | [diff] [blame] | 663 | /* Check if map_addr is outside PAR */ |
| 664 | if (addr_in_par(rd, map_addr)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 665 | buffer_unmap(rd); |
| 666 | granule_unlock(g_rd); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 667 | res->x[0] = RMI_ERROR_INPUT; |
| 668 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 671 | buffer_unmap(rd); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 672 | granule_lock(s2_ctx.g_rtt, GRANULE_STATE_RTT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 673 | granule_unlock(g_rd); |
| 674 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 675 | s2tt_walk_lock_unlock(&s2_ctx, map_addr, level, &wi); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 676 | |
| 677 | /* |
| 678 | * For UNMAP_NS, we need to map the table and look |
| 679 | * for the end of the non-live region. |
| 680 | */ |
AlexeiFedorov | 14d47ae | 2023-07-19 15:26:50 +0100 | [diff] [blame] | 681 | if ((op == MAP_NS) && (wi.last_level != level)) { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 682 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 683 | (unsigned char)wi.last_level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 684 | goto out_unlock_llt; |
| 685 | } |
| 686 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 687 | s2tt = buffer_granule_map(wi.g_llt, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 688 | assert(s2tt != NULL); |
| 689 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 690 | s2tte = s2tte_read(&s2tt[wi.index]); |
| 691 | |
| 692 | if (op == MAP_NS) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 693 | if (!s2tte_is_unassigned_ns(&s2_ctx, s2tte)) { |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 694 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 695 | (unsigned char)level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 696 | goto out_unmap_table; |
| 697 | } |
| 698 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 699 | s2tte = s2tte_create_assigned_ns(&s2_ctx, host_s2tte, level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 700 | s2tte_write(&s2tt[wi.index], s2tte); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 701 | |
| 702 | } else if (op == UNMAP_NS) { |
| 703 | /* |
| 704 | * The following check also verifies that map_addr is outside |
| 705 | * PAR, as valid_NS s2tte may only cover outside PAR IPA range. |
| 706 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 707 | bool assigned_ns = s2tte_is_assigned_ns(&s2_ctx, s2tte, |
| 708 | wi.last_level); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 709 | |
| 710 | if ((wi.last_level != level) || !assigned_ns) { |
| 711 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 712 | (unsigned char)wi.last_level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 713 | goto out_unmap_table; |
| 714 | } |
| 715 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 716 | s2tte = s2tte_create_unassigned_ns(&s2_ctx); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 717 | s2tte_write(&s2tt[wi.index], s2tte); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 718 | if (level == S2TT_PAGE_LEVEL) { |
| 719 | s2tt_invalidate_page(&s2_ctx, map_addr); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 720 | } else { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 721 | s2tt_invalidate_block(&s2_ctx, map_addr); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 722 | } |
| 723 | } |
| 724 | |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 725 | res->x[0] = RMI_SUCCESS; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 726 | |
| 727 | out_unmap_table: |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 728 | if (op == UNMAP_NS) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 729 | res->x[1] = s2tt_skip_non_live_entries(&s2_ctx, map_addr, |
| 730 | s2tt, &wi); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 731 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 732 | buffer_unmap(s2tt); |
| 733 | out_unlock_llt: |
| 734 | granule_unlock(wi.g_llt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | unsigned long smc_rtt_map_unprotected(unsigned long rd_addr, |
| 738 | unsigned long map_addr, |
| 739 | unsigned long ulevel, |
| 740 | unsigned long s2tte) |
| 741 | { |
| 742 | long level = (long)ulevel; |
Shruti Gupta | 9e966b8 | 2024-03-21 13:45:24 +0000 | [diff] [blame] | 743 | struct smc_result res; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 744 | |
Shruti Gupta | 9e966b8 | 2024-03-21 13:45:24 +0000 | [diff] [blame] | 745 | (void)memset(&res, 0, sizeof(struct smc_result)); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 746 | if ((level < S2TT_MIN_BLOCK_LEVEL) || (level > S2TT_PAGE_LEVEL)) { |
AlexeiFedorov | 7a2f588 | 2023-09-14 11:41:32 +0100 | [diff] [blame] | 747 | return RMI_ERROR_INPUT; |
| 748 | } |
| 749 | |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 750 | map_unmap_ns(rd_addr, map_addr, level, s2tte, MAP_NS, &res); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 751 | |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 752 | return res.x[0]; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 753 | } |
| 754 | |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 755 | void smc_rtt_unmap_unprotected(unsigned long rd_addr, |
| 756 | unsigned long map_addr, |
| 757 | unsigned long ulevel, |
| 758 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 759 | { |
AlexeiFedorov | 7a2f588 | 2023-09-14 11:41:32 +0100 | [diff] [blame] | 760 | long level = (long)ulevel; |
| 761 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 762 | if ((level < S2TT_MIN_BLOCK_LEVEL) || (level > S2TT_PAGE_LEVEL)) { |
AlexeiFedorov | 7a2f588 | 2023-09-14 11:41:32 +0100 | [diff] [blame] | 763 | res->x[0] = RMI_ERROR_INPUT; |
| 764 | return; |
| 765 | } |
| 766 | |
| 767 | map_unmap_ns(rd_addr, map_addr, level, 0UL, UNMAP_NS, res); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | void smc_rtt_read_entry(unsigned long rd_addr, |
| 771 | unsigned long map_addr, |
| 772 | unsigned long ulevel, |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 773 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 774 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 775 | struct granule *g_rd; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 776 | struct rd *rd; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 777 | struct s2tt_walk wi; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 778 | unsigned long *s2tt, s2tte; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 779 | long level = (long)ulevel; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 780 | struct s2tt_context s2_ctx; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 781 | |
| 782 | g_rd = find_lock_granule(rd_addr, GRANULE_STATE_RD); |
| 783 | if (g_rd == NULL) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 784 | res->x[0] = RMI_ERROR_INPUT; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 785 | return; |
| 786 | } |
| 787 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 788 | rd = buffer_granule_map(g_rd, SLOT_RD); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 789 | assert(rd != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 790 | |
| 791 | if (!validate_rtt_entry_cmds(map_addr, level, rd)) { |
| 792 | buffer_unmap(rd); |
| 793 | granule_unlock(g_rd); |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 794 | res->x[0] = RMI_ERROR_INPUT; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 795 | return; |
| 796 | } |
| 797 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 798 | s2_ctx = rd->s2_ctx; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 799 | buffer_unmap(rd); |
| 800 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 801 | granule_lock(s2_ctx.g_rtt, GRANULE_STATE_RTT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 802 | granule_unlock(g_rd); |
| 803 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 804 | s2tt_walk_lock_unlock(&s2_ctx, map_addr, level, &wi); |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 805 | s2tt = buffer_granule_map(wi.g_llt, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 806 | assert(s2tt != NULL); |
| 807 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 808 | s2tte = s2tte_read(&s2tt[wi.index]); |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 809 | res->x[1] = (unsigned long)wi.last_level; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 810 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 811 | if (s2tte_is_unassigned_empty(&s2_ctx, s2tte)) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 812 | res->x[2] = RMI_UNASSIGNED; |
| 813 | res->x[3] = 0UL; |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 814 | res->x[4] = (unsigned long)RIPAS_EMPTY; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 815 | } else if (s2tte_is_unassigned_ram(&s2_ctx, s2tte)) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 816 | res->x[2] = RMI_UNASSIGNED; |
| 817 | res->x[3] = 0UL; |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 818 | res->x[4] = (unsigned long)RIPAS_RAM; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 819 | } else if (s2tte_is_unassigned_destroyed(&s2_ctx, s2tte)) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 820 | res->x[2] = RMI_UNASSIGNED; |
| 821 | res->x[3] = 0UL; |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 822 | res->x[4] = (unsigned long)RIPAS_DESTROYED; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 823 | } else if (s2tte_is_assigned_empty(&s2_ctx, s2tte, wi.last_level)) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 824 | res->x[2] = RMI_ASSIGNED; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 825 | res->x[3] = s2tte_pa(&s2_ctx, s2tte, wi.last_level); |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 826 | res->x[4] = (unsigned long)RIPAS_EMPTY; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 827 | } else if (s2tte_is_assigned_ram(&s2_ctx, s2tte, wi.last_level)) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 828 | res->x[2] = RMI_ASSIGNED; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 829 | res->x[3] = s2tte_pa(&s2_ctx, s2tte, wi.last_level); |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 830 | res->x[4] = (unsigned long)RIPAS_RAM; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 831 | } else if (s2tte_is_assigned_destroyed(&s2_ctx, s2tte, wi.last_level)) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 832 | res->x[2] = RMI_ASSIGNED; |
Soby Mathew | f5257c6 | 2024-10-25 15:50:11 +0100 | [diff] [blame] | 833 | res->x[3] = s2tte_pa(&s2_ctx, s2tte, wi.last_level); |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 834 | res->x[4] = (unsigned long)RIPAS_DESTROYED; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 835 | } else if (s2tte_is_unassigned_ns(&s2_ctx, s2tte)) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 836 | res->x[2] = RMI_UNASSIGNED; |
| 837 | res->x[3] = 0UL; |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 838 | res->x[4] = (unsigned long)RIPAS_EMPTY; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 839 | } else if (s2tte_is_assigned_ns(&s2_ctx, s2tte, wi.last_level)) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 840 | res->x[2] = RMI_ASSIGNED; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 841 | res->x[3] = host_ns_s2tte(&s2_ctx, s2tte, wi.last_level); |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 842 | res->x[4] = (unsigned long)RIPAS_EMPTY; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 843 | } else if (s2tte_is_table(&s2_ctx, s2tte, wi.last_level)) { |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 844 | res->x[2] = RMI_TABLE; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 845 | res->x[3] = s2tte_pa(&s2_ctx, s2tte, wi.last_level); |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 846 | res->x[4] = (unsigned long)RIPAS_EMPTY; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 847 | } else { |
| 848 | assert(false); |
| 849 | } |
| 850 | |
| 851 | buffer_unmap(s2tt); |
| 852 | granule_unlock(wi.g_llt); |
| 853 | |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 854 | res->x[0] = RMI_SUCCESS; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 857 | static unsigned long validate_data_create_unknown(unsigned long map_addr, |
| 858 | struct rd *rd) |
| 859 | { |
| 860 | if (!addr_in_par(rd, map_addr)) { |
| 861 | return RMI_ERROR_INPUT; |
| 862 | } |
| 863 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 864 | if (!validate_map_addr(map_addr, S2TT_PAGE_LEVEL, rd)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 865 | return RMI_ERROR_INPUT; |
| 866 | } |
| 867 | |
| 868 | return RMI_SUCCESS; |
| 869 | } |
| 870 | |
| 871 | static unsigned long validate_data_create(unsigned long map_addr, |
| 872 | struct rd *rd) |
| 873 | { |
Mate Toth-Pal | 988dfcb | 2024-01-19 10:52:06 +0100 | [diff] [blame] | 874 | if (get_rd_state_locked(rd) != REALM_NEW) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 875 | return RMI_ERROR_REALM; |
| 876 | } |
| 877 | |
| 878 | return validate_data_create_unknown(map_addr, rd); |
| 879 | } |
| 880 | |
| 881 | /* |
AlexeiFedorov | 0f9cd1f | 2023-07-10 17:04:58 +0100 | [diff] [blame] | 882 | * Implements both RMI_DATA_CREATE and RMI_DATA_CREATE_UNKNOWN |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 883 | * |
AlexeiFedorov | 0f9cd1f | 2023-07-10 17:04:58 +0100 | [diff] [blame] | 884 | * if @g_src == NULL, implements RMI_DATA_CREATE_UNKNOWN |
| 885 | * and RMI_DATA_CREATE otherwise. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 886 | */ |
AlexeiFedorov | ac923c8 | 2023-04-06 15:12:04 +0100 | [diff] [blame] | 887 | static unsigned long data_create(unsigned long rd_addr, |
| 888 | unsigned long data_addr, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 889 | unsigned long map_addr, |
| 890 | struct granule *g_src, |
| 891 | unsigned long flags) |
| 892 | { |
| 893 | struct granule *g_data; |
| 894 | struct granule *g_rd; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 895 | struct rd *rd; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 896 | struct s2tt_walk wi; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 897 | struct s2tt_context *s2_ctx; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 898 | unsigned long s2tte, *s2tt; |
AlexeiFedorov | d6d93d8 | 2024-02-13 16:52:11 +0000 | [diff] [blame] | 899 | unsigned char new_data_state = GRANULE_STATE_DELEGATED; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 900 | unsigned long ret; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 901 | |
| 902 | if (!find_lock_two_granules(data_addr, |
| 903 | GRANULE_STATE_DELEGATED, |
| 904 | &g_data, |
| 905 | rd_addr, |
| 906 | GRANULE_STATE_RD, |
| 907 | &g_rd)) { |
| 908 | return RMI_ERROR_INPUT; |
| 909 | } |
| 910 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 911 | rd = buffer_granule_map(g_rd, SLOT_RD); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 912 | assert(rd != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 913 | |
| 914 | ret = (g_src != NULL) ? |
| 915 | validate_data_create(map_addr, rd) : |
| 916 | validate_data_create_unknown(map_addr, rd); |
| 917 | |
| 918 | if (ret != RMI_SUCCESS) { |
| 919 | goto out_unmap_rd; |
| 920 | } |
| 921 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 922 | s2_ctx = &(rd->s2_ctx); |
Shruti Gupta | 3530a71 | 2024-09-12 10:50:21 +0100 | [diff] [blame] | 923 | |
| 924 | /* |
| 925 | * If LPA2 is disabled for the realm, then `data_addr` must not be |
| 926 | * more than 48 bits wide. |
| 927 | */ |
| 928 | if (!s2_ctx->enable_lpa2) { |
| 929 | if ((data_addr >= (UL(1) << S2TT_MAX_PA_BITS))) { |
| 930 | ret = RMI_ERROR_INPUT; |
| 931 | goto out_unmap_rd; |
| 932 | } |
| 933 | } |
| 934 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 935 | granule_lock(s2_ctx->g_rtt, GRANULE_STATE_RTT); |
| 936 | |
| 937 | s2tt_walk_lock_unlock(s2_ctx, map_addr, S2TT_PAGE_LEVEL, &wi); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 938 | if (wi.last_level != S2TT_PAGE_LEVEL) { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 939 | ret = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 940 | (unsigned char)wi.last_level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 941 | goto out_unlock_ll_table; |
| 942 | } |
| 943 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 944 | s2tt = buffer_granule_map(wi.g_llt, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 945 | assert(s2tt != NULL); |
| 946 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 947 | s2tte = s2tte_read(&s2tt[wi.index]); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 948 | if (!s2tte_is_unassigned(s2_ctx, s2tte)) { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 949 | ret = pack_return_code(RMI_ERROR_RTT, |
| 950 | (unsigned char)S2TT_PAGE_LEVEL); |
AlexeiFedorov | 4e2db16 | 2023-10-10 13:57:22 +0100 | [diff] [blame] | 951 | goto out_unmap_ll_table; |
| 952 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 953 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 954 | if (g_src != NULL) { |
| 955 | bool ns_access_ok; |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 956 | void *data = buffer_granule_map(g_data, SLOT_DELEGATED); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 957 | |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 958 | assert(data != NULL); |
| 959 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 960 | ns_access_ok = ns_buffer_read(SLOT_NS, g_src, 0U, |
| 961 | GRANULE_SIZE, data); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 962 | if (!ns_access_ok) { |
| 963 | /* |
| 964 | * Some data may be copied before the failure. Zero |
| 965 | * g_data granule as it will remain in delegated state. |
| 966 | */ |
AlexeiFedorov | 862f96c | 2024-03-01 16:26:48 +0000 | [diff] [blame] | 967 | granule_memzero_mapped(data); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 968 | buffer_unmap(data); |
| 969 | ret = RMI_ERROR_INPUT; |
| 970 | goto out_unmap_ll_table; |
| 971 | } |
| 972 | |
Mate Toth-Pal | c769831 | 2023-08-09 12:49:34 +0200 | [diff] [blame] | 973 | measurement_data_granule_measure( |
| 974 | rd->measurement[RIM_MEASUREMENT_SLOT], |
| 975 | rd->algorithm, |
| 976 | data, |
| 977 | map_addr, |
| 978 | flags); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 979 | buffer_unmap(data); |
AlexeiFedorov | 0f9cd1f | 2023-07-10 17:04:58 +0100 | [diff] [blame] | 980 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 981 | s2tte = s2tte_create_assigned_ram(s2_ctx, data_addr, |
| 982 | S2TT_PAGE_LEVEL); |
AlexeiFedorov | 4e2db16 | 2023-10-10 13:57:22 +0100 | [diff] [blame] | 983 | } else { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 984 | s2tte = s2tte_create_assigned_unchanged(s2_ctx, s2tte, |
| 985 | data_addr, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 986 | S2TT_PAGE_LEVEL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | new_data_state = GRANULE_STATE_DATA; |
| 990 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 991 | s2tte_write(&s2tt[wi.index], s2tte); |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 992 | atomic_granule_get(wi.g_llt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 993 | |
| 994 | ret = RMI_SUCCESS; |
| 995 | |
| 996 | out_unmap_ll_table: |
| 997 | buffer_unmap(s2tt); |
| 998 | out_unlock_ll_table: |
| 999 | granule_unlock(wi.g_llt); |
| 1000 | out_unmap_rd: |
| 1001 | buffer_unmap(rd); |
| 1002 | granule_unlock(g_rd); |
| 1003 | granule_unlock_transition(g_data, new_data_state); |
| 1004 | return ret; |
| 1005 | } |
| 1006 | |
AlexeiFedorov | ac923c8 | 2023-04-06 15:12:04 +0100 | [diff] [blame] | 1007 | unsigned long smc_data_create(unsigned long rd_addr, |
| 1008 | unsigned long data_addr, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1009 | unsigned long map_addr, |
| 1010 | unsigned long src_addr, |
| 1011 | unsigned long flags) |
| 1012 | { |
| 1013 | struct granule *g_src; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1014 | |
AlexeiFedorov | 93f5ec5 | 2023-08-31 14:26:53 +0100 | [diff] [blame] | 1015 | if ((flags != RMI_NO_MEASURE_CONTENT) && |
| 1016 | (flags != RMI_MEASURE_CONTENT)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1017 | return RMI_ERROR_INPUT; |
| 1018 | } |
| 1019 | |
| 1020 | g_src = find_granule(src_addr); |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 1021 | if ((g_src == NULL) || |
| 1022 | (granule_unlocked_state(g_src) != GRANULE_STATE_NS)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1023 | return RMI_ERROR_INPUT; |
| 1024 | } |
| 1025 | |
AlexeiFedorov | ac923c8 | 2023-04-06 15:12:04 +0100 | [diff] [blame] | 1026 | return data_create(rd_addr, data_addr, map_addr, g_src, flags); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
AlexeiFedorov | ac923c8 | 2023-04-06 15:12:04 +0100 | [diff] [blame] | 1029 | unsigned long smc_data_create_unknown(unsigned long rd_addr, |
| 1030 | unsigned long data_addr, |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1031 | unsigned long map_addr) |
| 1032 | { |
AlexeiFedorov | ac923c8 | 2023-04-06 15:12:04 +0100 | [diff] [blame] | 1033 | return data_create(rd_addr, data_addr, map_addr, NULL, 0); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 1036 | void smc_data_destroy(unsigned long rd_addr, |
| 1037 | unsigned long map_addr, |
| 1038 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1039 | { |
| 1040 | struct granule *g_data; |
| 1041 | struct granule *g_rd; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1042 | struct s2tt_walk wi; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1043 | unsigned long data_addr, s2tte, *s2tt; |
| 1044 | struct rd *rd; |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 1045 | struct s2tt_context s2_ctx; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1046 | |
| 1047 | g_rd = find_lock_granule(rd_addr, GRANULE_STATE_RD); |
| 1048 | if (g_rd == NULL) { |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 1049 | res->x[0] = RMI_ERROR_INPUT; |
AlexeiFedorov | a1b2a1d | 2023-07-18 15:08:47 +0100 | [diff] [blame] | 1050 | res->x[2] = 0UL; |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 1051 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 1054 | rd = buffer_granule_map(g_rd, SLOT_RD); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 1055 | assert(rd != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1056 | |
AlexeiFedorov | 868a651 | 2023-09-14 13:21:11 +0100 | [diff] [blame] | 1057 | if (!addr_in_par(rd, map_addr) || |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1058 | !validate_map_addr(map_addr, S2TT_PAGE_LEVEL, rd)) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1059 | buffer_unmap(rd); |
| 1060 | granule_unlock(g_rd); |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 1061 | res->x[0] = RMI_ERROR_INPUT; |
AlexeiFedorov | a1b2a1d | 2023-07-18 15:08:47 +0100 | [diff] [blame] | 1062 | res->x[2] = 0UL; |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 1063 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1066 | s2_ctx = rd->s2_ctx; |
| 1067 | buffer_unmap(rd); |
| 1068 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1069 | granule_lock(s2_ctx.g_rtt, GRANULE_STATE_RTT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1070 | granule_unlock(g_rd); |
| 1071 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1072 | s2tt_walk_lock_unlock(&s2_ctx, map_addr, S2TT_PAGE_LEVEL, &wi); |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 1073 | s2tt = buffer_granule_map(wi.g_llt, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 1074 | assert(s2tt != NULL); |
| 1075 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1076 | if (wi.last_level != S2TT_PAGE_LEVEL) { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 1077 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1078 | (unsigned char)wi.last_level); |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1079 | goto out_unmap_ll_table; |
| 1080 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1081 | |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1082 | s2tte = s2tte_read(&s2tt[wi.index]); |
AlexeiFedorov | c53b1f7 | 2023-07-04 15:37:03 +0100 | [diff] [blame] | 1083 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1084 | if (s2tte_is_assigned_ram(&s2_ctx, s2tte, S2TT_PAGE_LEVEL)) { |
| 1085 | data_addr = s2tte_pa(&s2_ctx, s2tte, S2TT_PAGE_LEVEL); |
| 1086 | s2tte = s2tte_create_unassigned_destroyed(&s2_ctx); |
AlexeiFedorov | a43cd31 | 2023-04-17 11:42:25 +0100 | [diff] [blame] | 1087 | s2tte_write(&s2tt[wi.index], s2tte); |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1088 | s2tt_invalidate_page(&s2_ctx, map_addr); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1089 | } else if (s2tte_is_assigned_empty(&s2_ctx, s2tte, S2TT_PAGE_LEVEL)) { |
| 1090 | data_addr = s2tte_pa(&s2_ctx, s2tte, S2TT_PAGE_LEVEL); |
| 1091 | s2tte = s2tte_create_unassigned_empty(&s2_ctx); |
AlexeiFedorov | a43cd31 | 2023-04-17 11:42:25 +0100 | [diff] [blame] | 1092 | s2tte_write(&s2tt[wi.index], s2tte); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1093 | } else if (s2tte_is_assigned_destroyed(&s2_ctx, s2tte, |
| 1094 | S2TT_PAGE_LEVEL)) { |
| 1095 | data_addr = s2tte_pa(&s2_ctx, s2tte, S2TT_PAGE_LEVEL); |
| 1096 | s2tte = s2tte_create_unassigned_destroyed(&s2_ctx); |
Javier Almansa Sobrino | 84a1b16 | 2023-09-26 17:32:44 +0100 | [diff] [blame] | 1097 | s2tte_write(&s2tt[wi.index], s2tte); |
AlexeiFedorov | a43cd31 | 2023-04-17 11:42:25 +0100 | [diff] [blame] | 1098 | } else { |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1099 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
| 1100 | (unsigned char)S2TT_PAGE_LEVEL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1101 | goto out_unmap_ll_table; |
| 1102 | } |
| 1103 | |
AlexeiFedorov | 745499d | 2024-04-25 16:52:44 +0100 | [diff] [blame] | 1104 | atomic_granule_put(wi.g_llt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1105 | |
| 1106 | /* |
| 1107 | * Lock the data granule and check expected state. Correct locking order |
| 1108 | * is guaranteed because granule address is obtained from a locked |
| 1109 | * granule by table walk. This lock needs to be acquired before a state |
| 1110 | * transition to or from GRANULE_STATE_DATA for granule address can happen. |
| 1111 | */ |
| 1112 | g_data = find_lock_granule(data_addr, GRANULE_STATE_DATA); |
AlexeiFedorov | 63b7169 | 2023-04-19 11:18:42 +0100 | [diff] [blame] | 1113 | assert(g_data != NULL); |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 1114 | buffer_granule_memzero(g_data, SLOT_DELEGATED); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1115 | granule_unlock_transition(g_data, GRANULE_STATE_DELEGATED); |
| 1116 | |
AlexeiFedorov | 917eabf | 2023-04-24 12:20:41 +0100 | [diff] [blame] | 1117 | res->x[0] = RMI_SUCCESS; |
AlexeiFedorov | e2002be | 2023-04-19 17:20:12 +0100 | [diff] [blame] | 1118 | res->x[1] = data_addr; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1119 | out_unmap_ll_table: |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1120 | res->x[2] = s2tt_skip_non_live_entries(&s2_ctx, map_addr, s2tt, &wi); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1121 | buffer_unmap(s2tt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1122 | granule_unlock(wi.g_llt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 1125 | /* |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1126 | * Update the ripas value for the entry pointed by @s2ttep. |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 1127 | * |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1128 | * Returns: |
| 1129 | * < 0 - On error and the operation was aborted, |
| 1130 | * e.g., entry cannot have a ripas. |
| 1131 | * 0 - Operation was success and no TLBI is required. |
| 1132 | * > 0 - Operation was success and TLBI is required. |
| 1133 | * Sets: |
| 1134 | * @(*do_tlbi) to 'true' if the TLBs have to be invalidated. |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 1135 | */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1136 | static int update_ripas(const struct s2tt_context *s2_ctx, |
| 1137 | unsigned long *s2ttep, long level, |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1138 | enum ripas ripas_val, |
| 1139 | enum ripas_change_destroyed change_destroyed) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1140 | { |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1141 | unsigned long pa, s2tte = s2tte_read(s2ttep); |
| 1142 | int ret = 0; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 1143 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1144 | assert(s2_ctx != NULL); |
| 1145 | |
| 1146 | if (!s2tte_has_ripas(s2_ctx, s2tte, level)) { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1147 | return -EPERM; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 1150 | if (ripas_val == RIPAS_RAM) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1151 | if (s2tte_is_unassigned_empty(s2_ctx, s2tte)) { |
| 1152 | s2tte = s2tte_create_unassigned_ram(s2_ctx); |
| 1153 | } else if (s2tte_is_unassigned_destroyed(s2_ctx, s2tte)) { |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1154 | if (change_destroyed == CHANGE_DESTROYED) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1155 | s2tte = s2tte_create_unassigned_ram(s2_ctx); |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1156 | } else { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1157 | return -EINVAL; |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1158 | } |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1159 | } else if (s2tte_is_assigned_empty(s2_ctx, s2tte, level)) { |
| 1160 | pa = s2tte_pa(s2_ctx, s2tte, level); |
| 1161 | s2tte = s2tte_create_assigned_ram(s2_ctx, pa, level); |
| 1162 | } else if (s2tte_is_assigned_destroyed(s2_ctx, s2tte, level)) { |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1163 | if (change_destroyed == CHANGE_DESTROYED) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1164 | pa = s2tte_pa(s2_ctx, s2tte, level); |
| 1165 | s2tte = s2tte_create_assigned_ram(s2_ctx, pa, |
| 1166 | level); |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1167 | } else { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1168 | return -EINVAL; |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1169 | } |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1170 | } else { |
| 1171 | /* No action is required */ |
| 1172 | return 0; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1173 | } |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 1174 | } else if (ripas_val == RIPAS_EMPTY) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1175 | if (s2tte_is_unassigned_ram(s2_ctx, s2tte)) { |
| 1176 | s2tte = s2tte_create_unassigned_empty(s2_ctx); |
| 1177 | } else if (s2tte_is_unassigned_destroyed(s2_ctx, s2tte)) { |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1178 | if (change_destroyed == CHANGE_DESTROYED) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1179 | s2tte = s2tte_create_unassigned_empty(s2_ctx); |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1180 | } else { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1181 | return -EINVAL; |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1182 | } |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1183 | } else if (s2tte_is_assigned_ram(s2_ctx, s2tte, level)) { |
| 1184 | pa = s2tte_pa(s2_ctx, s2tte, level); |
| 1185 | s2tte = s2tte_create_assigned_empty(s2_ctx, pa, level); |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1186 | /* TLBI is required */ |
| 1187 | ret = 1; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1188 | } else if (s2tte_is_assigned_destroyed(s2_ctx, s2tte, level)) { |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1189 | if (change_destroyed == CHANGE_DESTROYED) { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1190 | pa = s2tte_pa(s2_ctx, s2tte, level); |
| 1191 | s2tte = s2tte_create_assigned_empty(s2_ctx, |
| 1192 | pa, level); |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1193 | /* TLBI is required */ |
| 1194 | ret = 1; |
| 1195 | } else { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1196 | return -EINVAL; |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1197 | } |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1198 | } else { |
| 1199 | /* No action is required */ |
| 1200 | return 0; |
AlexeiFedorov | 0fb4455 | 2023-04-14 15:37:58 +0100 | [diff] [blame] | 1201 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1202 | } |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1203 | s2tte_write(s2ttep, s2tte); |
| 1204 | return ret; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1207 | void smc_rtt_init_ripas(unsigned long rd_addr, |
| 1208 | unsigned long base, |
| 1209 | unsigned long top, |
| 1210 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1211 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1212 | struct granule *g_rd; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1213 | struct rd *rd; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1214 | unsigned long addr, map_size; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1215 | struct s2tt_walk wi; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1216 | struct s2tt_context *s2_ctx; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1217 | unsigned long s2tte, *s2tt; |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1218 | long level; |
AlexeiFedorov | 14d47ae | 2023-07-19 15:26:50 +0100 | [diff] [blame] | 1219 | unsigned long index; |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1220 | unsigned int s2ttes_per_s2tt; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1221 | |
AlexeiFedorov | 14d47ae | 2023-07-19 15:26:50 +0100 | [diff] [blame] | 1222 | if (top <= base) { |
| 1223 | res->x[0] = RMI_ERROR_INPUT; |
| 1224 | return; |
| 1225 | } |
| 1226 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1227 | g_rd = find_lock_granule(rd_addr, GRANULE_STATE_RD); |
| 1228 | if (g_rd == NULL) { |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1229 | res->x[0] = RMI_ERROR_INPUT; |
| 1230 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 1233 | rd = buffer_granule_map(g_rd, SLOT_RD); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 1234 | assert(rd != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1235 | |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1236 | if (!validate_map_addr(base, S2TT_PAGE_LEVEL, rd) || |
| 1237 | !validate_map_addr(top, S2TT_PAGE_LEVEL, rd) || |
AlexeiFedorov | 14d47ae | 2023-07-19 15:26:50 +0100 | [diff] [blame] | 1238 | !addr_in_par(rd, base) || !addr_in_par(rd, top - GRANULE_SIZE)) { |
| 1239 | buffer_unmap(rd); |
| 1240 | granule_unlock(g_rd); |
| 1241 | res->x[0] = RMI_ERROR_INPUT; |
| 1242 | return; |
| 1243 | } |
| 1244 | |
Mate Toth-Pal | 988dfcb | 2024-01-19 10:52:06 +0100 | [diff] [blame] | 1245 | if (get_rd_state_locked(rd) != REALM_NEW) { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1246 | buffer_unmap(rd); |
| 1247 | granule_unlock(g_rd); |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1248 | res->x[0] = RMI_ERROR_REALM; |
| 1249 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1252 | s2_ctx = &(rd->s2_ctx); |
| 1253 | granule_lock(s2_ctx->g_rtt, GRANULE_STATE_RTT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1254 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1255 | s2tt_walk_lock_unlock(s2_ctx, base, S2TT_PAGE_LEVEL, &wi); |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1256 | level = wi.last_level; |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 1257 | s2tt = buffer_granule_map(wi.g_llt, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 1258 | assert(s2tt != NULL); |
| 1259 | |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1260 | map_size = s2tte_map_size(level); |
| 1261 | addr = base & ~(map_size - 1UL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1262 | |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1263 | /* |
AlexeiFedorov | 14d47ae | 2023-07-19 15:26:50 +0100 | [diff] [blame] | 1264 | * If the RTTE covers a range below "base", we need to go deeper. |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1265 | */ |
| 1266 | if (addr != base) { |
| 1267 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1268 | (unsigned char)level); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1269 | goto out_unmap_llt; |
| 1270 | } |
| 1271 | |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1272 | s2ttes_per_s2tt = |
| 1273 | (unsigned int)((level == S2TT_MIN_STARTING_LEVEL_LPA2) ? |
| 1274 | S2TTES_PER_S2TT_LM1 : S2TTES_PER_S2TT); |
| 1275 | for (index = wi.index; index < s2ttes_per_s2tt; index++) { |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1276 | unsigned long next = addr + map_size; |
| 1277 | |
AlexeiFedorov | 14d47ae | 2023-07-19 15:26:50 +0100 | [diff] [blame] | 1278 | /* |
| 1279 | * Break on "top_align" failure condition, |
| 1280 | * or if this entry crosses the range. |
| 1281 | */ |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1282 | if (next > top) { |
| 1283 | break; |
| 1284 | } |
| 1285 | |
| 1286 | s2tte = s2tte_read(&s2tt[index]); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1287 | if (s2tte_is_unassigned_empty(s2_ctx, s2tte)) { |
| 1288 | s2tte = s2tte_create_unassigned_ram(s2_ctx); |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1289 | s2tte_write(&s2tt[index], s2tte); |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1290 | } else if (!s2tte_is_unassigned_ram(s2_ctx, s2tte)) { |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1291 | break; |
| 1292 | } |
Mate Toth-Pal | c769831 | 2023-08-09 12:49:34 +0200 | [diff] [blame] | 1293 | measurement_init_ripas_measure(rd->measurement[RIM_MEASUREMENT_SLOT], |
| 1294 | rd->algorithm, |
| 1295 | addr, |
| 1296 | next); |
AlexeiFedorov | ee2fc82 | 2023-10-31 14:54:39 +0000 | [diff] [blame] | 1297 | addr = next; |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | if (addr > base) { |
| 1301 | res->x[0] = RMI_SUCCESS; |
| 1302 | res->x[1] = addr; |
| 1303 | } else { |
| 1304 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1305 | (unsigned char)level); |
AlexeiFedorov | 960d161 | 2023-04-25 13:23:39 +0100 | [diff] [blame] | 1306 | } |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1307 | |
| 1308 | out_unmap_llt: |
| 1309 | buffer_unmap(s2tt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1310 | buffer_unmap(rd); |
| 1311 | granule_unlock(wi.g_llt); |
AlexeiFedorov | 80295e4 | 2023-07-10 13:11:14 +0100 | [diff] [blame] | 1312 | granule_unlock(g_rd); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
Javier Almansa Sobrino | 2eb98b0 | 2023-12-18 18:10:55 +0000 | [diff] [blame] | 1315 | static void rtt_set_ripas_range(struct s2tt_context *s2_ctx, |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1316 | unsigned long *s2tt, |
| 1317 | unsigned long base, |
| 1318 | unsigned long top, |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1319 | struct s2tt_walk *wi, |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 1320 | enum ripas ripas_val, |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1321 | enum ripas_change_destroyed change_destroyed, |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1322 | struct smc_result *res) |
| 1323 | { |
AlexeiFedorov | 14d47ae | 2023-07-19 15:26:50 +0100 | [diff] [blame] | 1324 | unsigned long index; |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1325 | long level = wi->last_level; |
AlexeiFedorov | 4faab85 | 2023-08-30 15:06:49 +0100 | [diff] [blame] | 1326 | unsigned long map_size = s2tte_map_size((int)level); |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1327 | |
| 1328 | /* Align to the RTT level */ |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1329 | unsigned long addr = base & ~(map_size - 1UL); |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1330 | |
| 1331 | /* Make sure we don't touch a range below the requested range */ |
| 1332 | if (addr != base) { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 1333 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1334 | (unsigned char)level); |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1335 | return; |
| 1336 | } |
| 1337 | |
AlexeiFedorov | ee2fc82 | 2023-10-31 14:54:39 +0000 | [diff] [blame] | 1338 | for (index = wi->index; index < S2TTES_PER_S2TT; index++) { |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1339 | int ret; |
| 1340 | |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 1341 | /* |
| 1342 | * Break on "top_align" failure condition, |
| 1343 | * or if this entry crosses the range. |
| 1344 | */ |
| 1345 | if ((addr + map_size) > top) { |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1346 | break; |
| 1347 | } |
| 1348 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1349 | ret = update_ripas(s2_ctx, &s2tt[index], level, |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1350 | ripas_val, change_destroyed); |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1351 | if (ret < 0) { |
| 1352 | break; |
| 1353 | } |
| 1354 | |
| 1355 | /* Handle TLBI */ |
| 1356 | if (ret != 0) { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1357 | if (level == S2TT_PAGE_LEVEL) { |
| 1358 | s2tt_invalidate_page(s2_ctx, addr); |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1359 | } else { |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1360 | s2tt_invalidate_block(s2_ctx, addr); |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1361 | } |
| 1362 | } |
AlexeiFedorov | ee2fc82 | 2023-10-31 14:54:39 +0000 | [diff] [blame] | 1363 | |
| 1364 | addr += map_size; |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | if (addr > base) { |
| 1368 | res->x[0] = RMI_SUCCESS; |
| 1369 | res->x[1] = addr; |
| 1370 | } else { |
AlexeiFedorov | be37dee | 2023-07-18 10:44:01 +0100 | [diff] [blame] | 1371 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1372 | (unsigned char)level); |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | void smc_rtt_set_ripas(unsigned long rd_addr, |
| 1377 | unsigned long rec_addr, |
| 1378 | unsigned long base, |
| 1379 | unsigned long top, |
| 1380 | struct smc_result *res) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1381 | { |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1382 | struct granule *g_rd, *g_rec; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1383 | struct rec *rec; |
| 1384 | struct rd *rd; |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1385 | struct s2tt_walk wi; |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1386 | unsigned long *s2tt; |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1387 | struct s2tt_context *s2_ctx; |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1388 | enum ripas ripas_val; |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1389 | enum ripas_change_destroyed change_destroyed; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1390 | |
Shyamanth RH | 62ece7d | 2024-12-12 01:14:43 +0530 | [diff] [blame] | 1391 | if ((top <= base) || !GRANULE_ALIGNED(top)) { |
AlexeiFedorov | 14d47ae | 2023-07-19 15:26:50 +0100 | [diff] [blame] | 1392 | res->x[0] = RMI_ERROR_INPUT; |
| 1393 | return; |
| 1394 | } |
| 1395 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1396 | if (!find_lock_two_granules(rd_addr, |
| 1397 | GRANULE_STATE_RD, |
| 1398 | &g_rd, |
| 1399 | rec_addr, |
| 1400 | GRANULE_STATE_REC, |
| 1401 | &g_rec)) { |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1402 | res->x[0] = RMI_ERROR_INPUT; |
| 1403 | return; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
AlexeiFedorov | d6d93d8 | 2024-02-13 16:52:11 +0000 | [diff] [blame] | 1406 | if (granule_refcount_read_acquire(g_rec) != 0U) { |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1407 | res->x[0] = RMI_ERROR_REC; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1408 | goto out_unlock_rec_rd; |
| 1409 | } |
| 1410 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 1411 | rec = buffer_granule_map(g_rec, SLOT_REC); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 1412 | assert(rec != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1413 | |
| 1414 | if (g_rd != rec->realm_info.g_rd) { |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1415 | res->x[0] = RMI_ERROR_REC; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1416 | goto out_unmap_rec; |
| 1417 | } |
| 1418 | |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1419 | ripas_val = rec->set_ripas.ripas_val; |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1420 | change_destroyed = rec->set_ripas.change_destroyed; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1421 | |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1422 | /* |
| 1423 | * Return error in case of target region: |
| 1424 | * - is not the next chunk of requested region |
| 1425 | * - extends beyond the end of requested region |
| 1426 | */ |
| 1427 | if ((base != rec->set_ripas.addr) || (top > rec->set_ripas.top)) { |
| 1428 | res->x[0] = RMI_ERROR_INPUT; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1429 | goto out_unmap_rec; |
| 1430 | } |
| 1431 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 1432 | rd = buffer_granule_map(g_rd, SLOT_RD); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 1433 | assert(rd != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1434 | |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1435 | /* |
| 1436 | * At this point, we know base == rec->set_ripas.addr |
| 1437 | * and thus must be aligned to GRANULE size. |
| 1438 | */ |
Javier Almansa Sobrino | 1e1781e | 2023-10-18 18:25:56 +0100 | [diff] [blame] | 1439 | assert(validate_map_addr(base, S2TT_PAGE_LEVEL, rd)); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1440 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1441 | s2_ctx = &(rd->s2_ctx); |
| 1442 | granule_lock(s2_ctx->g_rtt, GRANULE_STATE_RTT); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1443 | |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1444 | /* Walk to the deepest level possible */ |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1445 | s2tt_walk_lock_unlock(s2_ctx, base, S2TT_PAGE_LEVEL, &wi); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1446 | |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 1447 | /* |
| 1448 | * Base has to be aligned to the level at which |
| 1449 | * it is mapped in RTT. |
| 1450 | */ |
| 1451 | if (!validate_map_addr(base, wi.last_level, rd)) { |
| 1452 | res->x[0] = pack_return_code(RMI_ERROR_RTT, |
Javier Almansa Sobrino | f6fff69 | 2024-02-02 17:13:57 +0000 | [diff] [blame] | 1453 | (unsigned char)wi.last_level); |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 1454 | goto out_unlock_llt; |
| 1455 | } |
| 1456 | |
Javier Almansa Sobrino | 2f717dd | 2024-02-12 20:49:46 +0000 | [diff] [blame] | 1457 | s2tt = buffer_granule_map(wi.g_llt, SLOT_RTT); |
AlexeiFedorov | 9a9062c | 2023-08-21 15:41:48 +0100 | [diff] [blame] | 1458 | assert(s2tt != NULL); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1459 | |
Javier Almansa Sobrino | 2595cd8 | 2024-01-25 18:25:12 +0000 | [diff] [blame] | 1460 | rtt_set_ripas_range(s2_ctx, s2tt, base, top, &wi, |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame] | 1461 | ripas_val, change_destroyed, res); |
| 1462 | |
AlexeiFedorov | 5cf35ba | 2023-04-25 10:02:20 +0100 | [diff] [blame] | 1463 | if (res->x[0] == RMI_SUCCESS) { |
| 1464 | rec->set_ripas.addr = res->x[1]; |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1467 | buffer_unmap(s2tt); |
AlexeiFedorov | 64fd6c3 | 2023-07-20 12:33:00 +0100 | [diff] [blame] | 1468 | out_unlock_llt: |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1469 | granule_unlock(wi.g_llt); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1470 | buffer_unmap(rd); |
| 1471 | out_unmap_rec: |
| 1472 | buffer_unmap(rec); |
| 1473 | out_unlock_rec_rd: |
| 1474 | granule_unlock(g_rec); |
| 1475 | granule_unlock(g_rd); |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1476 | } |