Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 1 | /* |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 9 | #include "hf/load.h" |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 10 | |
| 11 | #include <stdbool.h> |
| 12 | |
Olivier Deprez | 112d2b5 | 2020-09-30 07:39:23 +0200 | [diff] [blame] | 13 | #include "hf/arch/other_world.h" |
J-Alves | a9c7cba | 2021-08-25 16:26:11 +0100 | [diff] [blame] | 14 | #include "hf/arch/plat/ffa.h" |
Fuad Tabba | 77a4b01 | 2019-11-15 12:13:08 +0000 | [diff] [blame] | 15 | #include "hf/arch/vm.h" |
| 16 | |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 17 | #include "hf/api.h" |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 18 | #include "hf/boot_params.h" |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 19 | #include "hf/check.h" |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 20 | #include "hf/dlog.h" |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 21 | #include "hf/fdt_patch.h" |
Andrew Scull | 5991ec9 | 2018-10-08 14:55:02 +0100 | [diff] [blame] | 22 | #include "hf/layout.h" |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 23 | #include "hf/memiter.h" |
| 24 | #include "hf/mm.h" |
Andrew Walbran | 4869936 | 2019-05-20 14:38:00 +0100 | [diff] [blame] | 25 | #include "hf/plat/console.h" |
Madhukar Pappireddy | 5fc8be1 | 2021-08-03 11:42:53 -0500 | [diff] [blame] | 26 | #include "hf/plat/interrupts.h" |
Andrew Scull | b1a6d0d | 2020-01-29 11:25:12 +0000 | [diff] [blame] | 27 | #include "hf/plat/iommu.h" |
Andrew Scull | 877ae4b | 2019-07-02 12:52:33 +0100 | [diff] [blame] | 28 | #include "hf/static_assert.h" |
Andrew Scull | 8d9e121 | 2019-04-05 13:52:55 +0100 | [diff] [blame] | 29 | #include "hf/std.h" |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 30 | #include "hf/vm.h" |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 31 | |
Andrew Scull | 1950326 | 2018-09-20 14:48:39 +0100 | [diff] [blame] | 32 | #include "vmapi/hf/call.h" |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 33 | #include "vmapi/hf/ffa.h" |
Andrew Scull | 1950326 | 2018-09-20 14:48:39 +0100 | [diff] [blame] | 34 | |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 35 | /** |
| 36 | * Copies data to an unmapped location by mapping it for write, copying the |
| 37 | * data, then unmapping it. |
Andrew Scull | d9225b3 | 2018-11-19 16:12:41 +0000 | [diff] [blame] | 38 | * |
| 39 | * The data is written so that it is available to all cores with the cache |
| 40 | * disabled. When switching to the partitions, the caching is initially disabled |
| 41 | * so the data must be available without the cache. |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 42 | */ |
Andrew Scull | 3c0a90a | 2019-07-01 11:55:53 +0100 | [diff] [blame] | 43 | static bool copy_to_unmapped(struct mm_stage1_locked stage1_locked, paddr_t to, |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 44 | struct memiter *from_it, struct mpool *ppool) |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 45 | { |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 46 | const void *from = memiter_base(from_it); |
| 47 | size_t size = memiter_size(from_it); |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 48 | paddr_t to_end = pa_add(to, size); |
| 49 | void *ptr; |
Andrew Scull | 265ada9 | 2018-07-30 15:19:01 +0100 | [diff] [blame] | 50 | |
Andrew Scull | 3c0a90a | 2019-07-01 11:55:53 +0100 | [diff] [blame] | 51 | ptr = mm_identity_map(stage1_locked, to, to_end, MM_MODE_W, ppool); |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 52 | if (!ptr) { |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 53 | return false; |
| 54 | } |
| 55 | |
Andrew Scull | a1aa2ba | 2019-04-05 11:49:02 +0100 | [diff] [blame] | 56 | memcpy_s(ptr, size, from, size); |
Andrew Scull | c059fbe | 2019-09-12 12:58:40 +0100 | [diff] [blame] | 57 | arch_mm_flush_dcache(ptr, size); |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 58 | |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 59 | CHECK(mm_unmap(stage1_locked, to, to_end, ppool)); |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 60 | |
| 61 | return true; |
| 62 | } |
| 63 | |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 64 | /** |
| 65 | * Loads the secondary VM's kernel. |
| 66 | * Stores the kernel size in kernel_size (if kernel_size is not NULL). |
| 67 | * Returns false if it cannot load the kernel. |
| 68 | */ |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 69 | static bool load_kernel(struct mm_stage1_locked stage1_locked, paddr_t begin, |
| 70 | paddr_t end, const struct manifest_vm *manifest_vm, |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 71 | const struct memiter *cpio, struct mpool *ppool, |
| 72 | size_t *kernel_size) |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 73 | { |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 74 | struct memiter kernel; |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 75 | size_t size; |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 76 | |
David Brazdil | 136f294 | 2019-09-23 14:11:03 +0100 | [diff] [blame] | 77 | if (!cpio_get_file(cpio, &manifest_vm->kernel_filename, &kernel)) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 78 | dlog_error("Could not find kernel file \"%s\".\n", |
| 79 | string_data(&manifest_vm->kernel_filename)); |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 80 | return false; |
| 81 | } |
| 82 | |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 83 | size = memiter_size(&kernel); |
| 84 | if (pa_difference(begin, end) < size) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 85 | dlog_error("Kernel is larger than available memory.\n"); |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 86 | return false; |
| 87 | } |
| 88 | |
| 89 | if (!copy_to_unmapped(stage1_locked, begin, &kernel, ppool)) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 90 | dlog_error("Unable to copy kernel.\n"); |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 91 | return false; |
| 92 | } |
| 93 | |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 94 | if (kernel_size) { |
| 95 | *kernel_size = size; |
| 96 | } |
| 97 | |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 98 | return true; |
| 99 | } |
| 100 | |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 101 | /* |
| 102 | * Link RX/TX buffers provided in partition manifest to mailbox |
| 103 | */ |
| 104 | static bool link_rxtx_to_mailbox(struct mm_stage1_locked stage1_locked, |
| 105 | struct vm_locked vm_locked, struct rx_tx rxtx, |
| 106 | struct mpool *ppool) |
| 107 | { |
| 108 | struct ffa_value ret; |
| 109 | ipaddr_t send; |
| 110 | ipaddr_t recv; |
| 111 | uint32_t page_count; |
| 112 | |
| 113 | send = ipa_init(rxtx.tx_buffer->base_address); |
| 114 | recv = ipa_init(rxtx.rx_buffer->base_address); |
| 115 | page_count = rxtx.tx_buffer->page_count; |
| 116 | |
| 117 | ret = api_vm_configure_pages(stage1_locked, vm_locked, send, recv, |
| 118 | page_count, ppool); |
| 119 | if (ret.func != FFA_SUCCESS_32) { |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | dlog_verbose(" mailbox: send = %#x, recv = %#x\n", |
| 124 | vm_locked.vm->mailbox.send, vm_locked.vm->mailbox.recv); |
| 125 | |
| 126 | return true; |
| 127 | } |
| 128 | |
Madhukar Pappireddy | 5fc8be1 | 2021-08-03 11:42:53 -0500 | [diff] [blame] | 129 | static void infer_interrupt(struct interrupt interrupt, |
| 130 | struct interrupt_descriptor *int_desc) |
| 131 | { |
| 132 | uint32_t attr = interrupt.attributes; |
| 133 | |
| 134 | interrupt_desc_set_id(int_desc, interrupt.id); |
| 135 | interrupt_desc_set_priority(int_desc, |
| 136 | (attr >> INT_DESC_PRIORITY_SHIFT) & 0xff); |
| 137 | |
| 138 | /* Refer to the comments in interrupt_descriptor struct definition. */ |
| 139 | interrupt_desc_set_type_config_sec_state( |
| 140 | int_desc, |
| 141 | (((attr >> INT_DESC_TYPE_SHIFT) & 0x3) << 2) | |
| 142 | (((attr >> INT_DESC_CONFIG_SHIFT) & 0x1) << 1) | |
| 143 | ((attr >> INT_DESC_SEC_STATE_SHIFT) & 0x1)); |
| 144 | |
| 145 | interrupt_desc_set_valid(int_desc, true); |
| 146 | } |
| 147 | |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 148 | /** |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 149 | * Performs VM loading activities that are common between the primary and |
| 150 | * secondaries. |
| 151 | */ |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 152 | static bool load_common(struct mm_stage1_locked stage1_locked, |
| 153 | struct vm_locked vm_locked, |
| 154 | const struct manifest_vm *manifest_vm, |
| 155 | struct mpool *ppool) |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 156 | { |
Madhukar Pappireddy | 5fc8be1 | 2021-08-03 11:42:53 -0500 | [diff] [blame] | 157 | struct device_region dev_region; |
| 158 | struct interrupt interrupt; |
| 159 | uint32_t k = 0; |
| 160 | |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 161 | vm_locked.vm->smc_whitelist = manifest_vm->smc_whitelist; |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 162 | vm_locked.vm->uuid = manifest_vm->partition.uuid; |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 163 | |
Madhukar Pappireddy | 5fc8be1 | 2021-08-03 11:42:53 -0500 | [diff] [blame] | 164 | /* Populate the interrupt descriptor for current VM. */ |
| 165 | for (uint8_t i = 0; i < SP_MAX_DEVICE_REGIONS; i++) { |
| 166 | dev_region = manifest_vm->partition.dev_regions[i]; |
| 167 | |
| 168 | CHECK(dev_region.interrupt_count <= |
| 169 | SP_MAX_INTERRUPTS_PER_DEVICE); |
| 170 | |
| 171 | for (uint8_t j = 0; j < dev_region.interrupt_count; j++) { |
| 172 | struct interrupt_descriptor int_desc; |
| 173 | |
| 174 | interrupt = dev_region.interrupts[j]; |
| 175 | infer_interrupt(interrupt, &int_desc); |
| 176 | vm_locked.vm->interrupt_desc[k] = int_desc; |
| 177 | |
Madhukar Pappireddy | 72454a1 | 2021-08-03 12:21:46 -0500 | [diff] [blame] | 178 | /* |
| 179 | * Configure the physical interrupts allocated for this |
| 180 | * VM in its partition manifest. |
| 181 | */ |
| 182 | plat_interrupts_configure_interrupt(int_desc); |
Madhukar Pappireddy | 5fc8be1 | 2021-08-03 11:42:53 -0500 | [diff] [blame] | 183 | k++; |
| 184 | CHECK(k <= VM_MANIFEST_MAX_INTERRUPTS); |
| 185 | } |
| 186 | } |
| 187 | dlog_verbose("VM has %d physical interrupts defined in manifest.\n", k); |
| 188 | |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 189 | if (manifest_vm->is_ffa_partition) { |
Daniel Boulby | baeaf2e | 2021-12-09 11:42:36 +0000 | [diff] [blame] | 190 | vm_locked.vm->ffa_version = manifest_vm->partition.ffa_version; |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 191 | /* Link rxtx buffers to mailbox */ |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 192 | if (manifest_vm->partition.rxtx.available) { |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 193 | if (!link_rxtx_to_mailbox(stage1_locked, vm_locked, |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 194 | manifest_vm->partition.rxtx, |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 195 | ppool)) { |
| 196 | dlog_error( |
| 197 | "Unable to Link RX/TX buffer with " |
| 198 | "mailbox.\n"); |
| 199 | return false; |
| 200 | } |
| 201 | } |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 202 | |
Maksims Svecovs | b596eab | 2021-04-27 00:52:27 +0100 | [diff] [blame] | 203 | vm_locked.vm->messaging_method = |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 204 | manifest_vm->partition.messaging_method; |
Manish Pandey | f3be639 | 2020-09-24 17:26:09 +0100 | [diff] [blame] | 205 | |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 206 | vm_locked.vm->managed_exit = |
| 207 | manifest_vm->partition.managed_exit; |
Maksims Svecovs | 9ddf86a | 2021-05-06 17:17:21 +0100 | [diff] [blame] | 208 | |
J-Alves | a4730db | 2021-11-02 10:31:01 +0000 | [diff] [blame] | 209 | vm_locked.vm->notifications.enabled = |
| 210 | manifest_vm->partition.notification_support; |
| 211 | |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 212 | vm_locked.vm->boot_order = manifest_vm->partition.boot_order; |
| 213 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 214 | /* Updating boot list according to boot_order */ |
| 215 | vm_update_boot(vm_locked.vm); |
J-Alves | a0f317d | 2021-06-09 13:31:59 +0100 | [diff] [blame] | 216 | |
J-Alves | 09ff9d8 | 2021-11-02 11:55:20 +0000 | [diff] [blame] | 217 | if (vm_locked_are_notifications_enabled(vm_locked) && |
J-Alves | a4730db | 2021-11-02 10:31:01 +0000 | [diff] [blame] | 218 | !plat_ffa_notifications_bitmap_create_call( |
| 219 | vm_locked.vm->id, vm_locked.vm->vcpu_count)) { |
| 220 | return false; |
J-Alves | a9c7cba | 2021-08-25 16:26:11 +0100 | [diff] [blame] | 221 | } |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 222 | } |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 223 | |
Fuad Tabba | 5697071 | 2020-01-10 11:20:09 +0000 | [diff] [blame] | 224 | /* Initialize architecture-specific features. */ |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 225 | arch_vm_features_set(vm_locked.vm); |
Fuad Tabba | 77a4b01 | 2019-11-15 12:13:08 +0000 | [diff] [blame] | 226 | |
Madhukar Pappireddy | 54680c7 | 2020-10-23 15:02:38 -0500 | [diff] [blame] | 227 | if (!plat_iommu_attach_peripheral(stage1_locked, vm_locked, manifest_vm, |
| 228 | ppool)) { |
| 229 | dlog_error("Unable to attach upstream peripheral device\n"); |
| 230 | return false; |
| 231 | } |
| 232 | |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 233 | return true; |
| 234 | } |
| 235 | |
| 236 | /** |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 237 | * Loads the primary VM. |
| 238 | */ |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 239 | static bool load_primary(struct mm_stage1_locked stage1_locked, |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 240 | const struct manifest_vm *manifest_vm, |
Andrew Scull | b5f49e0 | 2019-10-02 13:20:47 +0100 | [diff] [blame] | 241 | const struct memiter *cpio, |
| 242 | const struct boot_params *params, struct mpool *ppool) |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 243 | { |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 244 | paddr_t primary_begin; |
| 245 | ipaddr_t primary_entry; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 246 | struct vm *vm; |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 247 | struct vm_locked vm_locked; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 248 | struct vcpu_locked vcpu_locked; |
Andrew Scull | b5f49e0 | 2019-10-02 13:20:47 +0100 | [diff] [blame] | 249 | size_t i; |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 250 | bool ret; |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 251 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 252 | if (manifest_vm->is_ffa_partition) { |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 253 | primary_begin = pa_init(manifest_vm->partition.load_addr); |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 254 | primary_entry = ipa_add(ipa_from_pa(primary_begin), |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 255 | manifest_vm->partition.ep_offset); |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 256 | } else { |
| 257 | primary_begin = |
| 258 | (manifest_vm->primary.boot_address == |
| 259 | MANIFEST_INVALID_ADDRESS) |
| 260 | ? layout_primary_begin() |
| 261 | : pa_init(manifest_vm->primary.boot_address); |
| 262 | primary_entry = ipa_from_pa(primary_begin); |
| 263 | } |
| 264 | |
David Brazdil | 080ee31 | 2020-02-25 15:30:30 -0800 | [diff] [blame] | 265 | paddr_t primary_end = pa_add(primary_begin, RSIZE_MAX); |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 266 | |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 267 | /* Primary VM must be a VM */ |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 268 | CHECK(manifest_vm->partition.run_time_el == EL1); |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 269 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 270 | /* |
| 271 | * Load the kernel if a filename is specified in the VM manifest. |
| 272 | * For an FF-A partition, kernel_filename is undefined indicating |
| 273 | * the partition package has already been loaded prior to Hafnium |
| 274 | * booting. |
| 275 | */ |
| 276 | if (!string_is_empty(&manifest_vm->kernel_filename)) { |
| 277 | if (!load_kernel(stage1_locked, primary_begin, primary_end, |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 278 | manifest_vm, cpio, ppool, NULL)) { |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 279 | dlog_error("Unable to load primary kernel.\n"); |
| 280 | return false; |
| 281 | } |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 284 | if (!vm_init_next(MAX_CPUS, ppool, &vm, false)) { |
Andrew Walbran | 7586e04 | 2020-02-18 18:19:26 +0000 | [diff] [blame] | 285 | dlog_error("Unable to initialise primary VM.\n"); |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 286 | return false; |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 287 | } |
| 288 | |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 289 | if (vm->id != HF_PRIMARY_VM_ID) { |
Andrew Walbran | 7586e04 | 2020-02-18 18:19:26 +0000 | [diff] [blame] | 290 | dlog_error("Primary VM was not given correct ID.\n"); |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 291 | return false; |
| 292 | } |
| 293 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 294 | vm_locked = vm_lock(vm); |
| 295 | |
Andrew Scull | 48929fd | 2020-01-28 10:39:10 +0000 | [diff] [blame] | 296 | if (params->device_mem_ranges_count == 0) { |
| 297 | /* |
| 298 | * Map 1TB of address space as device memory to, most likely, |
| 299 | * make all devices available to the primary VM. |
| 300 | * |
| 301 | * TODO: remove this once all targets provide valid ranges. |
| 302 | */ |
Andrew Scull | f6ab9bc | 2020-02-26 12:56:37 -0800 | [diff] [blame] | 303 | dlog_warning( |
| 304 | "Device memory not provided, defaulting to 1 TB.\n"); |
Andrew Scull | 48929fd | 2020-01-28 10:39:10 +0000 | [diff] [blame] | 305 | |
| 306 | if (!vm_identity_map( |
| 307 | vm_locked, pa_init(0), |
| 308 | pa_init(UINT64_C(1024) * 1024 * 1024 * 1024), |
| 309 | MM_MODE_R | MM_MODE_W | MM_MODE_D, ppool, NULL)) { |
| 310 | dlog_error( |
| 311 | "Unable to initialise address space for " |
Andrew Scull | f6ab9bc | 2020-02-26 12:56:37 -0800 | [diff] [blame] | 312 | "primary VM.\n"); |
Andrew Scull | 48929fd | 2020-01-28 10:39:10 +0000 | [diff] [blame] | 313 | ret = false; |
| 314 | goto out; |
| 315 | } |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 316 | } |
| 317 | |
Andrew Scull | b5f49e0 | 2019-10-02 13:20:47 +0100 | [diff] [blame] | 318 | /* Map normal memory as such to permit caching, execution, etc. */ |
| 319 | for (i = 0; i < params->mem_ranges_count; ++i) { |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 320 | if (!vm_identity_map(vm_locked, params->mem_ranges[i].begin, |
| 321 | params->mem_ranges[i].end, |
| 322 | MM_MODE_R | MM_MODE_W | MM_MODE_X, ppool, |
| 323 | NULL)) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 324 | dlog_error( |
Andrew Scull | f6ab9bc | 2020-02-26 12:56:37 -0800 | [diff] [blame] | 325 | "Unable to initialise memory for primary " |
| 326 | "VM.\n"); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 327 | ret = false; |
| 328 | goto out; |
Andrew Scull | b5f49e0 | 2019-10-02 13:20:47 +0100 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
Andrew Scull | 48929fd | 2020-01-28 10:39:10 +0000 | [diff] [blame] | 332 | /* Map device memory as such to prevent execution, speculation etc. */ |
| 333 | for (i = 0; i < params->device_mem_ranges_count; ++i) { |
| 334 | if (!vm_identity_map( |
| 335 | vm_locked, params->device_mem_ranges[i].begin, |
| 336 | params->device_mem_ranges[i].end, |
| 337 | MM_MODE_R | MM_MODE_W | MM_MODE_D, ppool, NULL)) { |
| 338 | dlog("Unable to initialise device memory for primary " |
Andrew Scull | f6ab9bc | 2020-02-26 12:56:37 -0800 | [diff] [blame] | 339 | "VM.\n"); |
Andrew Scull | 48929fd | 2020-01-28 10:39:10 +0000 | [diff] [blame] | 340 | ret = false; |
| 341 | goto out; |
| 342 | } |
| 343 | } |
| 344 | |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 345 | if (!load_common(stage1_locked, vm_locked, manifest_vm, ppool)) { |
| 346 | ret = false; |
| 347 | goto out; |
| 348 | } |
| 349 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 350 | if (!vm_unmap_hypervisor(vm_locked, ppool)) { |
Andrew Scull | f6ab9bc | 2020-02-26 12:56:37 -0800 | [diff] [blame] | 351 | dlog_error("Unable to unmap hypervisor from primary VM.\n"); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 352 | ret = false; |
| 353 | goto out; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Andrew Scull | b1a6d0d | 2020-01-29 11:25:12 +0000 | [diff] [blame] | 356 | if (!plat_iommu_unmap_iommus(vm_locked, ppool)) { |
Andrew Scull | f6ab9bc | 2020-02-26 12:56:37 -0800 | [diff] [blame] | 357 | dlog_error("Unable to unmap IOMMUs from primary VM.\n"); |
Andrew Scull | b1a6d0d | 2020-01-29 11:25:12 +0000 | [diff] [blame] | 358 | ret = false; |
| 359 | goto out; |
| 360 | } |
| 361 | |
Andrew Walbran | 7586e04 | 2020-02-18 18:19:26 +0000 | [diff] [blame] | 362 | dlog_info("Loaded primary VM with %u vCPUs, entry at %#x.\n", |
| 363 | vm->vcpu_count, pa_addr(primary_begin)); |
| 364 | |
Olivier Deprez | b9adff4 | 2021-02-01 12:14:05 +0100 | [diff] [blame] | 365 | /* Mark the primary to be the first booted VM */ |
| 366 | vm_update_boot(vm); |
| 367 | |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 368 | vcpu_locked = vcpu_lock(vm_get_vcpu(vm, 0)); |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 369 | vcpu_on(vcpu_locked, primary_entry, params->kernel_arg); |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 370 | vcpu_unlock(&vcpu_locked); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 371 | ret = true; |
David Brazdil | e6f8322 | 2019-09-23 14:47:37 +0100 | [diff] [blame] | 372 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 373 | out: |
| 374 | vm_unlock(&vm_locked); |
| 375 | |
| 376 | return ret; |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 379 | /** |
| 380 | * Loads the secondary VM's FDT. |
| 381 | * Stores the total allocated size for the FDT in fdt_allocated_size (if |
| 382 | * fdt_allocated_size is not NULL). The allocated size includes additional space |
| 383 | * for potential patching. |
| 384 | */ |
| 385 | static bool load_secondary_fdt(struct mm_stage1_locked stage1_locked, |
| 386 | paddr_t end, size_t fdt_max_size, |
| 387 | const struct manifest_vm *manifest_vm, |
| 388 | const struct memiter *cpio, struct mpool *ppool, |
| 389 | paddr_t *fdt_addr, size_t *fdt_allocated_size) |
| 390 | { |
| 391 | struct memiter fdt; |
| 392 | size_t allocated_size; |
| 393 | |
| 394 | CHECK(!string_is_empty(&manifest_vm->secondary.fdt_filename)); |
| 395 | |
| 396 | if (!cpio_get_file(cpio, &manifest_vm->secondary.fdt_filename, &fdt)) { |
| 397 | dlog_error("Cannot open the secondary VM's FDT.\n"); |
| 398 | return false; |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * Ensure the FDT has one additional page at the end for patching, and |
| 403 | * and align it to the page boundary. |
| 404 | */ |
| 405 | allocated_size = align_up(memiter_size(&fdt), PAGE_SIZE) + PAGE_SIZE; |
| 406 | |
| 407 | if (allocated_size > fdt_max_size) { |
| 408 | dlog_error( |
| 409 | "FDT allocated space (%u) is more than the specified " |
| 410 | "maximum to use (%u).\n", |
| 411 | allocated_size, fdt_max_size); |
| 412 | return false; |
| 413 | } |
| 414 | |
| 415 | /* Load the FDT to the end of the VM's allocated memory space. */ |
| 416 | *fdt_addr = pa_init(pa_addr(pa_sub(end, allocated_size))); |
| 417 | |
| 418 | dlog_info("Loading secondary FDT of allocated size %u at 0x%x.\n", |
| 419 | allocated_size, pa_addr(*fdt_addr)); |
| 420 | |
| 421 | if (!copy_to_unmapped(stage1_locked, *fdt_addr, &fdt, ppool)) { |
| 422 | dlog_error("Unable to copy FDT.\n"); |
| 423 | return false; |
| 424 | } |
| 425 | |
| 426 | if (fdt_allocated_size) { |
| 427 | *fdt_allocated_size = allocated_size; |
| 428 | } |
| 429 | |
| 430 | return true; |
| 431 | } |
| 432 | |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 433 | /* |
| 434 | * Loads a secondary VM. |
| 435 | */ |
| 436 | static bool load_secondary(struct mm_stage1_locked stage1_locked, |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 437 | struct vm_locked primary_vm_locked, |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 438 | paddr_t mem_begin, paddr_t mem_end, |
| 439 | const struct manifest_vm *manifest_vm, |
| 440 | const struct memiter *cpio, struct mpool *ppool) |
| 441 | { |
| 442 | struct vm *vm; |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 443 | struct vm_locked vm_locked; |
Max Shvetsov | 40108e7 | 2020-08-27 12:39:50 +0100 | [diff] [blame] | 444 | struct vcpu_locked vcpu_locked; |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 445 | struct vcpu *vcpu; |
| 446 | ipaddr_t secondary_entry; |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 447 | bool ret; |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 448 | paddr_t fdt_addr; |
| 449 | bool has_fdt; |
| 450 | size_t kernel_size = 0; |
| 451 | const size_t mem_size = pa_difference(mem_begin, mem_end); |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 452 | uint32_t map_mode; |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 453 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 454 | /* |
| 455 | * Load the kernel if a filename is specified in the VM manifest. |
| 456 | * For an FF-A partition, kernel_filename is undefined indicating |
| 457 | * the partition package has already been loaded prior to Hafnium |
| 458 | * booting. |
| 459 | */ |
| 460 | if (!string_is_empty(&manifest_vm->kernel_filename)) { |
| 461 | if (!load_kernel(stage1_locked, mem_begin, mem_end, manifest_vm, |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 462 | cpio, ppool, &kernel_size)) { |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 463 | dlog_error("Unable to load kernel.\n"); |
| 464 | return false; |
| 465 | } |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 466 | } |
| 467 | |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 468 | has_fdt = !string_is_empty(&manifest_vm->secondary.fdt_filename); |
| 469 | if (has_fdt) { |
| 470 | /* |
| 471 | * Ensure that the FDT does not overwrite the kernel or overlap |
| 472 | * its page, for the FDT to start at a page boundary. |
| 473 | */ |
| 474 | const size_t fdt_max_size = |
| 475 | mem_size - align_up(kernel_size, PAGE_SIZE); |
| 476 | |
| 477 | size_t fdt_allocated_size; |
| 478 | |
| 479 | if (!load_secondary_fdt(stage1_locked, mem_end, fdt_max_size, |
| 480 | manifest_vm, cpio, ppool, &fdt_addr, |
| 481 | &fdt_allocated_size)) { |
| 482 | dlog_error("Unable to load FDT.\n"); |
| 483 | return false; |
| 484 | } |
| 485 | |
| 486 | if (!fdt_patch_mem(stage1_locked, fdt_addr, fdt_allocated_size, |
| 487 | mem_begin, mem_end, ppool)) { |
| 488 | dlog_error("Unable to patch FDT.\n"); |
| 489 | return false; |
| 490 | } |
| 491 | } |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 492 | /* |
| 493 | * An S-EL0 partition must contain only 1 vCPU (UP migratable) per the |
| 494 | * FF-A 1.0 spec. |
| 495 | */ |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 496 | CHECK(manifest_vm->partition.run_time_el != S_EL0 || |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 497 | manifest_vm->secondary.vcpu_count == 1); |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 498 | |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 499 | if (!vm_init_next(manifest_vm->secondary.vcpu_count, ppool, &vm, |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 500 | (manifest_vm->partition.run_time_el == S_EL0))) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 501 | dlog_error("Unable to initialise VM.\n"); |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 502 | return false; |
| 503 | } |
| 504 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 505 | vm_locked = vm_lock(vm); |
| 506 | |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 507 | /* |
Raghu Krishnamurthy | 2b80169 | 2021-07-18 17:46:43 -0700 | [diff] [blame] | 508 | * Grant the VM access to the memory. For VM's we mark all memory in |
| 509 | * stage-2 tables as RWX and the VM can control permissions using |
| 510 | * stage-1 translations. For S-EL0 partitions, hafnium maps the entire |
| 511 | * region of memory for the partition as RX. The partition is then |
| 512 | * expected to perform its owns relocations and call the FFA_MEM_PERM_* |
| 513 | * API's to change permissions on its image layout. |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 514 | */ |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 515 | if (vm->el0_partition) { |
Raghu Krishnamurthy | 2b80169 | 2021-07-18 17:46:43 -0700 | [diff] [blame] | 516 | map_mode = MM_MODE_R | MM_MODE_X | MM_MODE_USER | MM_MODE_NG; |
| 517 | } else { |
| 518 | map_mode = MM_MODE_R | MM_MODE_W | MM_MODE_X; |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 519 | } |
Raghu Krishnamurthy | 2b80169 | 2021-07-18 17:46:43 -0700 | [diff] [blame] | 520 | |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 521 | if (!vm_identity_map(vm_locked, mem_begin, mem_end, map_mode, ppool, |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 522 | &secondary_entry)) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 523 | dlog_error("Unable to initialise memory.\n"); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 524 | ret = false; |
| 525 | goto out; |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 528 | if (manifest_vm->is_ffa_partition) { |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 529 | int j = 0; |
| 530 | paddr_t region_begin; |
| 531 | paddr_t region_end; |
| 532 | paddr_t alloc_base = mem_end; |
| 533 | size_t size; |
| 534 | size_t total_alloc = 0; |
| 535 | |
| 536 | /* Map memory-regions */ |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 537 | while (j < manifest_vm->partition.mem_region_count) { |
| 538 | size = manifest_vm->partition.mem_regions[j] |
| 539 | .page_count * |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 540 | PAGE_SIZE; |
| 541 | /* |
| 542 | * For memory-regions without base-address, memory |
| 543 | * should be allocated inside partition's page table. |
| 544 | * Start allocating memory regions in partition's |
| 545 | * page table, starting from the end. |
| 546 | * TODO: Add mechanism to let partition know of these |
| 547 | * memory regions |
| 548 | */ |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 549 | if (manifest_vm->partition.mem_regions[j] |
| 550 | .base_address == MANIFEST_INVALID_ADDRESS) { |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 551 | total_alloc += size; |
| 552 | /* Don't go beyond half the VM's memory space */ |
| 553 | if (total_alloc > |
| 554 | (manifest_vm->secondary.mem_size / 2)) { |
| 555 | dlog_error( |
| 556 | "Not enough space for memory-" |
| 557 | "region allocation"); |
| 558 | ret = false; |
| 559 | goto out; |
| 560 | } |
| 561 | |
| 562 | region_end = alloc_base; |
| 563 | region_begin = pa_subtract(alloc_base, size); |
| 564 | alloc_base = region_begin; |
| 565 | |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 566 | map_mode = manifest_vm->partition.mem_regions[j] |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 567 | .attributes; |
| 568 | if (vm->el0_partition) { |
| 569 | map_mode |= MM_MODE_USER | MM_MODE_NG; |
| 570 | } |
| 571 | |
| 572 | if (!vm_identity_map(vm_locked, region_begin, |
| 573 | region_end, map_mode, |
| 574 | ppool, NULL)) { |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 575 | dlog_error( |
| 576 | "Unable to map secondary VM " |
| 577 | "memory-region.\n"); |
| 578 | ret = false; |
| 579 | goto out; |
| 580 | } |
| 581 | |
Olivier Deprez | 86d87ae | 2021-08-19 14:27:46 +0200 | [diff] [blame] | 582 | dlog_verbose( |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 583 | " Memory region %#x - %#x allocated\n", |
| 584 | region_begin, region_end); |
| 585 | } else { |
| 586 | /* |
| 587 | * Identity map memory region for both case, |
| 588 | * VA(S-EL0) or IPA(S-EL1). |
| 589 | */ |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 590 | region_begin = pa_init( |
| 591 | manifest_vm->partition.mem_regions[j] |
| 592 | .base_address); |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 593 | region_end = pa_add(region_begin, size); |
| 594 | |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 595 | map_mode = manifest_vm->partition.mem_regions[j] |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 596 | .attributes; |
| 597 | if (vm->el0_partition) { |
| 598 | map_mode |= MM_MODE_USER | MM_MODE_NG; |
| 599 | } |
| 600 | |
| 601 | if (!vm_identity_map(vm_locked, region_begin, |
| 602 | region_end, map_mode, |
| 603 | ppool, NULL)) { |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 604 | dlog_error( |
| 605 | "Unable to map secondary VM " |
| 606 | "memory-region.\n"); |
| 607 | ret = false; |
| 608 | goto out; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | /* Deny the primary VM access to this memory */ |
| 613 | if (!vm_unmap(primary_vm_locked, region_begin, |
| 614 | region_end, ppool)) { |
| 615 | dlog_error( |
| 616 | "Unable to unmap secondary VM memory-" |
| 617 | "region from primary VM.\n"); |
| 618 | ret = false; |
| 619 | goto out; |
| 620 | } |
| 621 | |
| 622 | j++; |
| 623 | } |
| 624 | |
| 625 | /* Map device-regions */ |
| 626 | j = 0; |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 627 | while (j < manifest_vm->partition.dev_region_count) { |
| 628 | region_begin = |
| 629 | pa_init(manifest_vm->partition.dev_regions[j] |
| 630 | .base_address); |
| 631 | size = manifest_vm->partition.dev_regions[j] |
| 632 | .page_count * |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 633 | PAGE_SIZE; |
| 634 | region_end = pa_add(region_begin, size); |
| 635 | |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 636 | map_mode = manifest_vm->partition.dev_regions[j] |
| 637 | .attributes; |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 638 | if (vm->el0_partition) { |
| 639 | map_mode |= MM_MODE_USER | MM_MODE_NG; |
| 640 | } |
| 641 | |
| 642 | if (!vm_identity_map(vm_locked, region_begin, |
| 643 | region_end, map_mode, ppool, |
| 644 | NULL)) { |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 645 | dlog_error( |
| 646 | "Unable to map secondary VM " |
| 647 | "device-region.\n"); |
| 648 | ret = false; |
| 649 | goto out; |
| 650 | } |
| 651 | /* Deny primary VM access to this region */ |
| 652 | if (!vm_unmap(primary_vm_locked, region_begin, |
| 653 | region_end, ppool)) { |
| 654 | dlog_error( |
| 655 | "Unable to unmap secondary VM device-" |
| 656 | "region from primary VM.\n"); |
| 657 | ret = false; |
| 658 | goto out; |
| 659 | } |
| 660 | j++; |
| 661 | } |
| 662 | |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 663 | secondary_entry = ipa_add(secondary_entry, |
| 664 | manifest_vm->partition.ep_offset); |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 665 | } |
| 666 | |
Raghu Krishnamurthy | d3ab8c3 | 2021-02-10 19:11:30 -0800 | [diff] [blame] | 667 | /* |
| 668 | * Map hypervisor into the VM's page table. The hypervisor pages will |
| 669 | * not be accessible from EL0 since it will not be marked for user |
| 670 | * access. |
| 671 | * TODO: Map only the exception vectors and data that exception vectors |
| 672 | * require and not the entire hypervisor. This helps with speculative |
| 673 | * side-channel attacks. |
| 674 | */ |
| 675 | if (vm->el0_partition) { |
| 676 | CHECK(vm_identity_map(vm_locked, layout_text_begin(), |
| 677 | layout_text_end(), MM_MODE_X, ppool, |
| 678 | NULL)); |
| 679 | |
| 680 | CHECK(vm_identity_map(vm_locked, layout_rodata_begin(), |
| 681 | layout_rodata_end(), MM_MODE_R, ppool, |
| 682 | NULL)); |
| 683 | |
| 684 | CHECK(vm_identity_map(vm_locked, layout_data_begin(), |
| 685 | layout_data_end(), MM_MODE_R | MM_MODE_W, |
| 686 | ppool, NULL)); |
| 687 | plat_console_mm_init(mm_lock_ptable_unsafe(&vm->ptable), ppool); |
| 688 | } |
| 689 | |
Manish Pandey | d34f889 | 2020-06-19 17:41:07 +0100 | [diff] [blame] | 690 | if (!load_common(stage1_locked, vm_locked, manifest_vm, ppool)) { |
| 691 | ret = false; |
| 692 | goto out; |
| 693 | } |
| 694 | |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 695 | dlog_info("Loaded with %u vCPUs, entry at %#x.\n", |
| 696 | manifest_vm->secondary.vcpu_count, pa_addr(mem_begin)); |
| 697 | |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 698 | vcpu = vm_get_vcpu(vm, 0); |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 699 | |
Max Shvetsov | 40108e7 | 2020-08-27 12:39:50 +0100 | [diff] [blame] | 700 | vcpu_locked = vcpu_lock(vcpu); |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 701 | if (has_fdt) { |
Max Shvetsov | 40108e7 | 2020-08-27 12:39:50 +0100 | [diff] [blame] | 702 | vcpu_secondary_reset_and_start(vcpu_locked, secondary_entry, |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 703 | pa_addr(fdt_addr)); |
| 704 | } else { |
| 705 | /* |
| 706 | * Without an FDT, secondary VMs expect the memory size to be |
| 707 | * passed in register x0, which is what |
| 708 | * vcpu_secondary_reset_and_start does in this case. |
| 709 | */ |
Max Shvetsov | 40108e7 | 2020-08-27 12:39:50 +0100 | [diff] [blame] | 710 | vcpu_secondary_reset_and_start(vcpu_locked, secondary_entry, |
| 711 | mem_size); |
Fuad Tabba | 50469e0 | 2020-06-30 15:14:28 +0100 | [diff] [blame] | 712 | } |
| 713 | |
Max Shvetsov | 40108e7 | 2020-08-27 12:39:50 +0100 | [diff] [blame] | 714 | vcpu_unlock(&vcpu_locked); |
| 715 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 716 | ret = true; |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 717 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 718 | out: |
| 719 | vm_unlock(&vm_locked); |
| 720 | |
| 721 | return ret; |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 722 | } |
| 723 | |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 724 | /** |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 725 | * Try to find a memory range of the given size within the given ranges, and |
| 726 | * remove it from them. Return true on success, or false if no large enough |
| 727 | * contiguous range is found. |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 728 | */ |
Hong-Seok Kim | 0964836 | 2019-05-23 15:47:11 +0900 | [diff] [blame] | 729 | static bool carve_out_mem_range(struct mem_range *mem_ranges, |
| 730 | size_t mem_ranges_count, uint64_t size_to_find, |
| 731 | paddr_t *found_begin, paddr_t *found_end) |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 732 | { |
| 733 | size_t i; |
| 734 | |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 735 | /* |
| 736 | * TODO(b/116191358): Consider being cleverer about how we pack VMs |
| 737 | * together, with a non-greedy algorithm. |
| 738 | */ |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 739 | for (i = 0; i < mem_ranges_count; ++i) { |
| 740 | if (size_to_find <= |
Andrew Walbran | 2cb4339 | 2019-04-17 12:52:45 +0100 | [diff] [blame] | 741 | pa_difference(mem_ranges[i].begin, mem_ranges[i].end)) { |
Wedson Almeida Filho | b2c159e | 2018-10-25 13:27:47 +0100 | [diff] [blame] | 742 | /* |
| 743 | * This range is big enough, take some of it from the |
| 744 | * end and reduce its size accordingly. |
| 745 | */ |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 746 | *found_end = mem_ranges[i].end; |
| 747 | *found_begin = pa_init(pa_addr(mem_ranges[i].end) - |
| 748 | size_to_find); |
| 749 | mem_ranges[i].end = *found_begin; |
| 750 | return true; |
| 751 | } |
| 752 | } |
| 753 | return false; |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Given arrays of memory ranges before and after memory was removed for |
| 758 | * secondary VMs, add the difference to the reserved ranges of the given update. |
| 759 | * Return true on success, or false if there would be more than MAX_MEM_RANGES |
| 760 | * reserved ranges after adding the new ones. |
| 761 | * `before` and `after` must be arrays of exactly `mem_ranges_count` elements. |
| 762 | */ |
Hong-Seok Kim | 0964836 | 2019-05-23 15:47:11 +0900 | [diff] [blame] | 763 | static bool update_reserved_ranges(struct boot_params_update *update, |
| 764 | const struct mem_range *before, |
| 765 | const struct mem_range *after, |
| 766 | size_t mem_ranges_count) |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 767 | { |
| 768 | size_t i; |
| 769 | |
| 770 | for (i = 0; i < mem_ranges_count; ++i) { |
| 771 | if (pa_addr(after[i].begin) > pa_addr(before[i].begin)) { |
| 772 | if (update->reserved_ranges_count >= MAX_MEM_RANGES) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 773 | dlog_error( |
| 774 | "Too many reserved ranges after " |
| 775 | "loading secondary VMs.\n"); |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 776 | return false; |
| 777 | } |
| 778 | update->reserved_ranges[update->reserved_ranges_count] |
| 779 | .begin = before[i].begin; |
| 780 | update->reserved_ranges[update->reserved_ranges_count] |
| 781 | .end = after[i].begin; |
| 782 | update->reserved_ranges_count++; |
| 783 | } |
| 784 | if (pa_addr(after[i].end) < pa_addr(before[i].end)) { |
| 785 | if (update->reserved_ranges_count >= MAX_MEM_RANGES) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 786 | dlog_error( |
| 787 | "Too many reserved ranges after " |
| 788 | "loading secondary VMs.\n"); |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 789 | return false; |
| 790 | } |
| 791 | update->reserved_ranges[update->reserved_ranges_count] |
| 792 | .begin = after[i].end; |
| 793 | update->reserved_ranges[update->reserved_ranges_count] |
| 794 | .end = before[i].end; |
| 795 | update->reserved_ranges_count++; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | return true; |
| 800 | } |
| 801 | |
Olivier Deprez | 112d2b5 | 2020-09-30 07:39:23 +0200 | [diff] [blame] | 802 | static bool init_other_world_vm(struct mpool *ppool) |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 803 | { |
Olivier Deprez | 96a2a26 | 2020-06-11 17:21:38 +0200 | [diff] [blame] | 804 | struct vm *other_world_vm; |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 805 | size_t i; |
Andrew Scull | 72b43c0 | 2019-09-18 13:53:45 +0100 | [diff] [blame] | 806 | |
Andrew Walbran | 9daa57e | 2019-09-27 13:33:20 +0100 | [diff] [blame] | 807 | /* |
Olivier Deprez | 96a2a26 | 2020-06-11 17:21:38 +0200 | [diff] [blame] | 808 | * Initialise the dummy VM which represents the opposite world: |
| 809 | * -TrustZone (or the SPMC) when running the Hypervisor |
| 810 | * -the Hypervisor when running TZ/SPMC |
Andrew Walbran | 9daa57e | 2019-09-27 13:33:20 +0100 | [diff] [blame] | 811 | */ |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 812 | other_world_vm = vm_init(HF_OTHER_WORLD_ID, MAX_CPUS, ppool, false); |
Olivier Deprez | 96a2a26 | 2020-06-11 17:21:38 +0200 | [diff] [blame] | 813 | CHECK(other_world_vm != NULL); |
| 814 | |
| 815 | for (i = 0; i < MAX_CPUS; i++) { |
| 816 | struct vcpu *vcpu = vm_get_vcpu(other_world_vm, i); |
| 817 | struct cpu *cpu = cpu_find_index(i); |
| 818 | |
| 819 | vcpu->cpu = cpu; |
| 820 | } |
Andrew Walbran | 9daa57e | 2019-09-27 13:33:20 +0100 | [diff] [blame] | 821 | |
Olivier Deprez | 112d2b5 | 2020-09-30 07:39:23 +0200 | [diff] [blame] | 822 | return arch_other_world_vm_init(other_world_vm, ppool); |
| 823 | } |
| 824 | |
| 825 | /* |
| 826 | * Loads alls VMs from the manifest. |
| 827 | */ |
| 828 | bool load_vms(struct mm_stage1_locked stage1_locked, |
| 829 | const struct manifest *manifest, const struct memiter *cpio, |
| 830 | const struct boot_params *params, |
| 831 | struct boot_params_update *update, struct mpool *ppool) |
| 832 | { |
| 833 | struct vm *primary; |
| 834 | struct mem_range mem_ranges_available[MAX_MEM_RANGES]; |
| 835 | struct vm_locked primary_vm_locked; |
| 836 | size_t i; |
| 837 | bool success = true; |
| 838 | |
Andrew Walbran | f871678 | 2020-10-29 17:07:07 +0000 | [diff] [blame] | 839 | /** |
| 840 | * Only try to load the primary VM if it is supposed to be in this |
| 841 | * world. |
| 842 | */ |
| 843 | if (vm_id_is_current_world(HF_PRIMARY_VM_ID)) { |
| 844 | if (!load_primary(stage1_locked, |
| 845 | &manifest->vm[HF_PRIMARY_VM_INDEX], cpio, |
| 846 | params, ppool)) { |
| 847 | dlog_error("Unable to load primary VM.\n"); |
| 848 | return false; |
| 849 | } |
Olivier Deprez | 112d2b5 | 2020-09-30 07:39:23 +0200 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | if (!init_other_world_vm(ppool)) { |
| 853 | return false; |
| 854 | } |
| 855 | |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 856 | static_assert( |
| 857 | sizeof(mem_ranges_available) == sizeof(params->mem_ranges), |
| 858 | "mem_range arrays must be the same size for memcpy."); |
| 859 | static_assert(sizeof(mem_ranges_available) < 500, |
| 860 | "This will use too much stack, either make " |
| 861 | "MAX_MEM_RANGES smaller or change this."); |
Andrew Scull | a1aa2ba | 2019-04-05 11:49:02 +0100 | [diff] [blame] | 862 | memcpy_s(mem_ranges_available, sizeof(mem_ranges_available), |
| 863 | params->mem_ranges, sizeof(params->mem_ranges)); |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 864 | |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 865 | /* Round the last addresses down to the page size. */ |
| 866 | for (i = 0; i < params->mem_ranges_count; ++i) { |
Alfredo Mazzinghi | eb1997c | 2019-02-07 18:00:01 +0000 | [diff] [blame] | 867 | mem_ranges_available[i].end = pa_init(align_down( |
| 868 | pa_addr(mem_ranges_available[i].end), PAGE_SIZE)); |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 869 | } |
Wedson Almeida Filho | 84a30a0 | 2018-07-23 20:05:05 +0100 | [diff] [blame] | 870 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 871 | primary = vm_find(HF_PRIMARY_VM_ID); |
| 872 | primary_vm_locked = vm_lock(primary); |
| 873 | |
David Brazdil | 0251b94 | 2019-09-10 15:59:50 +0100 | [diff] [blame] | 874 | for (i = 0; i < manifest->vm_count; ++i) { |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 875 | const struct manifest_vm *manifest_vm = &manifest->vm[i]; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 876 | ffa_vm_id_t vm_id = HF_VM_ID_OFFSET + i; |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 877 | uint64_t mem_size; |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 878 | paddr_t secondary_mem_begin; |
| 879 | paddr_t secondary_mem_end; |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 880 | |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 881 | if (vm_id == HF_PRIMARY_VM_ID) { |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 882 | continue; |
| 883 | } |
| 884 | |
Olivier Deprez | 2a8ee34 | 2020-08-03 15:10:44 +0200 | [diff] [blame] | 885 | dlog_info("Loading VM id %#x: %s.\n", vm_id, |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 886 | manifest_vm->debug_name); |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 887 | |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 888 | mem_size = align_up(manifest_vm->secondary.mem_size, PAGE_SIZE); |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 889 | |
| 890 | if (manifest_vm->is_ffa_partition) { |
| 891 | secondary_mem_begin = |
Raghu Krishnamurthy | 8c250a9 | 2021-07-02 12:16:42 -0700 | [diff] [blame] | 892 | pa_init(manifest_vm->partition.load_addr); |
| 893 | secondary_mem_end = pa_init( |
| 894 | manifest_vm->partition.load_addr + mem_size); |
Olivier Deprez | 62d99e3 | 2020-01-09 15:58:07 +0100 | [diff] [blame] | 895 | } else if (!carve_out_mem_range(mem_ranges_available, |
| 896 | params->mem_ranges_count, |
| 897 | mem_size, &secondary_mem_begin, |
| 898 | &secondary_mem_end)) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 899 | dlog_error("Not enough memory (%u bytes).\n", mem_size); |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 900 | continue; |
| 901 | } |
Andrew Scull | 8087132 | 2018-08-06 12:04:09 +0100 | [diff] [blame] | 902 | |
Manish Pandey | 2145c21 | 2020-05-01 16:04:22 +0100 | [diff] [blame] | 903 | if (!load_secondary(stage1_locked, primary_vm_locked, |
| 904 | secondary_mem_begin, secondary_mem_end, |
| 905 | manifest_vm, cpio, ppool)) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 906 | dlog_error("Unable to load VM.\n"); |
Wedson Almeida Filho | 84a30a0 | 2018-07-23 20:05:05 +0100 | [diff] [blame] | 907 | continue; |
| 908 | } |
| 909 | |
| 910 | /* Deny the primary VM access to this memory. */ |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 911 | if (!vm_unmap(primary_vm_locked, secondary_mem_begin, |
| 912 | secondary_mem_end, ppool)) { |
Andrew Walbran | 17eebf9 | 2020-02-05 16:35:49 +0000 | [diff] [blame] | 913 | dlog_error( |
| 914 | "Unable to unmap secondary VM from primary " |
| 915 | "VM.\n"); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 916 | success = false; |
| 917 | break; |
Wedson Almeida Filho | 84a30a0 | 2018-07-23 20:05:05 +0100 | [diff] [blame] | 918 | } |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 919 | } |
| 920 | |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 921 | vm_unlock(&primary_vm_locked); |
| 922 | |
| 923 | if (!success) { |
| 924 | return false; |
| 925 | } |
| 926 | |
Wedson Almeida Filho | b2c159e | 2018-10-25 13:27:47 +0100 | [diff] [blame] | 927 | /* |
| 928 | * Add newly reserved areas to update params by looking at the |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 929 | * difference between the available ranges from the original params and |
| 930 | * the updated mem_ranges_available. We assume that the number and order |
| 931 | * of available ranges is the same, i.e. we don't remove any ranges |
Wedson Almeida Filho | b2c159e | 2018-10-25 13:27:47 +0100 | [diff] [blame] | 932 | * above only make them smaller. |
| 933 | */ |
Andrew Walbran | 34ce72e | 2018-09-13 16:47:44 +0100 | [diff] [blame] | 934 | return update_reserved_ranges(update, params->mem_ranges, |
| 935 | mem_ranges_available, |
| 936 | params->mem_ranges_count); |
Wedson Almeida Filho | fdf4afc | 2018-07-19 15:45:21 +0100 | [diff] [blame] | 937 | } |