blob: 1e6031ba0c16a62f2d1749b129be7b7f0e6f8d58 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01003 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * 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 Scull18834872018-10-12 11:48:09 +01007 */
8
Andrew Scull18c78fc2018-08-20 12:57:41 +01009#include "hf/load.h"
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010010
11#include <stdbool.h>
12
Olivier Deprez112d2b52020-09-30 07:39:23 +020013#include "hf/arch/other_world.h"
Fuad Tabba77a4b012019-11-15 12:13:08 +000014#include "hf/arch/vm.h"
15
Andrew Scull18c78fc2018-08-20 12:57:41 +010016#include "hf/api.h"
Andrew Walbran34ce72e2018-09-13 16:47:44 +010017#include "hf/boot_params.h"
Andrew Scull72b43c02019-09-18 13:53:45 +010018#include "hf/check.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010019#include "hf/dlog.h"
Fuad Tabba50469e02020-06-30 15:14:28 +010020#include "hf/fdt_patch.h"
Andrew Scull5991ec92018-10-08 14:55:02 +010021#include "hf/layout.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010022#include "hf/memiter.h"
23#include "hf/mm.h"
Andrew Walbran48699362019-05-20 14:38:00 +010024#include "hf/plat/console.h"
Andrew Scullb1a6d0d2020-01-29 11:25:12 +000025#include "hf/plat/iommu.h"
Andrew Scull877ae4b2019-07-02 12:52:33 +010026#include "hf/static_assert.h"
Andrew Scull8d9e1212019-04-05 13:52:55 +010027#include "hf/std.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010028#include "hf/vm.h"
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010029
Andrew Scull19503262018-09-20 14:48:39 +010030#include "vmapi/hf/call.h"
Manish Pandeyd34f8892020-06-19 17:41:07 +010031#include "vmapi/hf/ffa.h"
Andrew Scull19503262018-09-20 14:48:39 +010032
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010033/**
34 * Copies data to an unmapped location by mapping it for write, copying the
35 * data, then unmapping it.
Andrew Sculld9225b32018-11-19 16:12:41 +000036 *
37 * The data is written so that it is available to all cores with the cache
38 * disabled. When switching to the partitions, the caching is initially disabled
39 * so the data must be available without the cache.
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010040 */
Andrew Scull3c0a90a2019-07-01 11:55:53 +010041static bool copy_to_unmapped(struct mm_stage1_locked stage1_locked, paddr_t to,
David Brazdil7a462ec2019-08-15 12:27:47 +010042 struct memiter *from_it, struct mpool *ppool)
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010043{
David Brazdil7a462ec2019-08-15 12:27:47 +010044 const void *from = memiter_base(from_it);
45 size_t size = memiter_size(from_it);
Andrew Scull80871322018-08-06 12:04:09 +010046 paddr_t to_end = pa_add(to, size);
47 void *ptr;
Andrew Scull265ada92018-07-30 15:19:01 +010048
Andrew Scull3c0a90a2019-07-01 11:55:53 +010049 ptr = mm_identity_map(stage1_locked, to, to_end, MM_MODE_W, ppool);
Andrew Scull80871322018-08-06 12:04:09 +010050 if (!ptr) {
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010051 return false;
52 }
53
Andrew Sculla1aa2ba2019-04-05 11:49:02 +010054 memcpy_s(ptr, size, from, size);
Andrew Scullc059fbe2019-09-12 12:58:40 +010055 arch_mm_flush_dcache(ptr, size);
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010056
Andrew Scull72b43c02019-09-18 13:53:45 +010057 CHECK(mm_unmap(stage1_locked, to, to_end, ppool));
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +010058
59 return true;
60}
61
Fuad Tabba50469e02020-06-30 15:14:28 +010062/**
63 * Loads the secondary VM's kernel.
64 * Stores the kernel size in kernel_size (if kernel_size is not NULL).
65 * Returns false if it cannot load the kernel.
66 */
Andrew Scull72b43c02019-09-18 13:53:45 +010067static bool load_kernel(struct mm_stage1_locked stage1_locked, paddr_t begin,
68 paddr_t end, const struct manifest_vm *manifest_vm,
Fuad Tabba50469e02020-06-30 15:14:28 +010069 const struct memiter *cpio, struct mpool *ppool,
70 size_t *kernel_size)
Andrew Scull72b43c02019-09-18 13:53:45 +010071{
Andrew Scull72b43c02019-09-18 13:53:45 +010072 struct memiter kernel;
Fuad Tabba50469e02020-06-30 15:14:28 +010073 size_t size;
Andrew Scull72b43c02019-09-18 13:53:45 +010074
David Brazdil136f2942019-09-23 14:11:03 +010075 if (!cpio_get_file(cpio, &manifest_vm->kernel_filename, &kernel)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +000076 dlog_error("Could not find kernel file \"%s\".\n",
77 string_data(&manifest_vm->kernel_filename));
Andrew Scull72b43c02019-09-18 13:53:45 +010078 return false;
79 }
80
Fuad Tabba50469e02020-06-30 15:14:28 +010081 size = memiter_size(&kernel);
82 if (pa_difference(begin, end) < size) {
Andrew Walbran17eebf92020-02-05 16:35:49 +000083 dlog_error("Kernel is larger than available memory.\n");
Andrew Scull72b43c02019-09-18 13:53:45 +010084 return false;
85 }
86
87 if (!copy_to_unmapped(stage1_locked, begin, &kernel, ppool)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +000088 dlog_error("Unable to copy kernel.\n");
Andrew Scull72b43c02019-09-18 13:53:45 +010089 return false;
90 }
91
Fuad Tabba50469e02020-06-30 15:14:28 +010092 if (kernel_size) {
93 *kernel_size = size;
94 }
95
Andrew Scull72b43c02019-09-18 13:53:45 +010096 return true;
97}
98
Manish Pandeyd34f8892020-06-19 17:41:07 +010099/*
100 * Link RX/TX buffers provided in partition manifest to mailbox
101 */
102static bool link_rxtx_to_mailbox(struct mm_stage1_locked stage1_locked,
103 struct vm_locked vm_locked, struct rx_tx rxtx,
104 struct mpool *ppool)
105{
106 struct ffa_value ret;
107 ipaddr_t send;
108 ipaddr_t recv;
109 uint32_t page_count;
110
111 send = ipa_init(rxtx.tx_buffer->base_address);
112 recv = ipa_init(rxtx.rx_buffer->base_address);
113 page_count = rxtx.tx_buffer->page_count;
114
115 ret = api_vm_configure_pages(stage1_locked, vm_locked, send, recv,
116 page_count, ppool);
117 if (ret.func != FFA_SUCCESS_32) {
118 return false;
119 }
120
121 dlog_verbose(" mailbox: send = %#x, recv = %#x\n",
122 vm_locked.vm->mailbox.send, vm_locked.vm->mailbox.recv);
123
124 return true;
125}
126
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100127/**
Andrew Scullae9962e2019-10-03 16:51:16 +0100128 * Performs VM loading activities that are common between the primary and
129 * secondaries.
130 */
Manish Pandeyd34f8892020-06-19 17:41:07 +0100131static bool load_common(struct mm_stage1_locked stage1_locked,
132 struct vm_locked vm_locked,
133 const struct manifest_vm *manifest_vm,
134 struct mpool *ppool)
Andrew Scullae9962e2019-10-03 16:51:16 +0100135{
Manish Pandeyd34f8892020-06-19 17:41:07 +0100136 vm_locked.vm->smc_whitelist = manifest_vm->smc_whitelist;
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700137 vm_locked.vm->uuid = manifest_vm->partition.uuid;
Andrew Scullae9962e2019-10-03 16:51:16 +0100138
Manish Pandeyd34f8892020-06-19 17:41:07 +0100139 if (manifest_vm->is_ffa_partition) {
140 /* Link rxtx buffers to mailbox */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700141 if (manifest_vm->partition.rxtx.available) {
Manish Pandeyd34f8892020-06-19 17:41:07 +0100142 if (!link_rxtx_to_mailbox(stage1_locked, vm_locked,
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700143 manifest_vm->partition.rxtx,
Manish Pandeyd34f8892020-06-19 17:41:07 +0100144 ppool)) {
145 dlog_error(
146 "Unable to Link RX/TX buffer with "
147 "mailbox.\n");
148 return false;
149 }
150 }
J-Alvesb37fd082020-10-22 12:29:21 +0100151
Maksims Svecovsb596eab2021-04-27 00:52:27 +0100152 vm_locked.vm->messaging_method =
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700153 manifest_vm->partition.messaging_method;
Manish Pandeyf3be6392020-09-24 17:26:09 +0100154
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700155 vm_locked.vm->managed_exit =
156 manifest_vm->partition.managed_exit;
Maksims Svecovs9ddf86a2021-05-06 17:17:21 +0100157
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700158 vm_locked.vm->boot_order = manifest_vm->partition.boot_order;
159
J-Alvesb37fd082020-10-22 12:29:21 +0100160 /* Updating boot list according to boot_order */
161 vm_update_boot(vm_locked.vm);
J-Alvesa0f317d2021-06-09 13:31:59 +0100162
163 /* TODO: Enable in accordance to VM's manifest. */
164 vm_locked.vm->notifications.enabled = true;
Manish Pandeyd34f8892020-06-19 17:41:07 +0100165 }
J-Alvesb37fd082020-10-22 12:29:21 +0100166
Fuad Tabba56970712020-01-10 11:20:09 +0000167 /* Initialize architecture-specific features. */
Manish Pandeyd34f8892020-06-19 17:41:07 +0100168 arch_vm_features_set(vm_locked.vm);
Fuad Tabba77a4b012019-11-15 12:13:08 +0000169
Madhukar Pappireddy54680c72020-10-23 15:02:38 -0500170 if (!plat_iommu_attach_peripheral(stage1_locked, vm_locked, manifest_vm,
171 ppool)) {
172 dlog_error("Unable to attach upstream peripheral device\n");
173 return false;
174 }
175
Andrew Scullae9962e2019-10-03 16:51:16 +0100176 return true;
177}
178
179/**
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100180 * Loads the primary VM.
181 */
Andrew Scull72b43c02019-09-18 13:53:45 +0100182static bool load_primary(struct mm_stage1_locked stage1_locked,
Andrew Scullae9962e2019-10-03 16:51:16 +0100183 const struct manifest_vm *manifest_vm,
Andrew Scullb5f49e02019-10-02 13:20:47 +0100184 const struct memiter *cpio,
185 const struct boot_params *params, struct mpool *ppool)
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100186{
Olivier Deprez62d99e32020-01-09 15:58:07 +0100187 paddr_t primary_begin;
188 ipaddr_t primary_entry;
David Brazdile6f83222019-09-23 14:47:37 +0100189 struct vm *vm;
Andrew Scull3c257452019-11-26 13:32:50 +0000190 struct vm_locked vm_locked;
David Brazdile6f83222019-09-23 14:47:37 +0100191 struct vcpu_locked vcpu_locked;
Andrew Scullb5f49e02019-10-02 13:20:47 +0100192 size_t i;
Andrew Scull3c257452019-11-26 13:32:50 +0000193 bool ret;
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100194
Olivier Deprez62d99e32020-01-09 15:58:07 +0100195 if (manifest_vm->is_ffa_partition) {
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700196 primary_begin = pa_init(manifest_vm->partition.load_addr);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100197 primary_entry = ipa_add(ipa_from_pa(primary_begin),
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700198 manifest_vm->partition.ep_offset);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100199 } else {
200 primary_begin =
201 (manifest_vm->primary.boot_address ==
202 MANIFEST_INVALID_ADDRESS)
203 ? layout_primary_begin()
204 : pa_init(manifest_vm->primary.boot_address);
205 primary_entry = ipa_from_pa(primary_begin);
206 }
207
David Brazdil080ee312020-02-25 15:30:30 -0800208 paddr_t primary_end = pa_add(primary_begin, RSIZE_MAX);
Andrew Scull72b43c02019-09-18 13:53:45 +0100209
Raghu Krishnamurthycd1eceb2021-01-04 12:20:48 -0800210 /* Primary VM must be a VM */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700211 CHECK(manifest_vm->partition.run_time_el == EL1);
Raghu Krishnamurthycd1eceb2021-01-04 12:20:48 -0800212
Olivier Deprez62d99e32020-01-09 15:58:07 +0100213 /*
214 * Load the kernel if a filename is specified in the VM manifest.
215 * For an FF-A partition, kernel_filename is undefined indicating
216 * the partition package has already been loaded prior to Hafnium
217 * booting.
218 */
219 if (!string_is_empty(&manifest_vm->kernel_filename)) {
220 if (!load_kernel(stage1_locked, primary_begin, primary_end,
Fuad Tabba50469e02020-06-30 15:14:28 +0100221 manifest_vm, cpio, ppool, NULL)) {
Olivier Deprez62d99e32020-01-09 15:58:07 +0100222 dlog_error("Unable to load primary kernel.\n");
223 return false;
224 }
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100225 }
226
Raghu Krishnamurthycd1eceb2021-01-04 12:20:48 -0800227 if (!vm_init_next(MAX_CPUS, ppool, &vm, false)) {
Andrew Walbran7586e042020-02-18 18:19:26 +0000228 dlog_error("Unable to initialise primary VM.\n");
David Brazdile6f83222019-09-23 14:47:37 +0100229 return false;
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100230 }
231
David Brazdile6f83222019-09-23 14:47:37 +0100232 if (vm->id != HF_PRIMARY_VM_ID) {
Andrew Walbran7586e042020-02-18 18:19:26 +0000233 dlog_error("Primary VM was not given correct ID.\n");
David Brazdile6f83222019-09-23 14:47:37 +0100234 return false;
235 }
236
Andrew Scull3c257452019-11-26 13:32:50 +0000237 vm_locked = vm_lock(vm);
238
Andrew Scull48929fd2020-01-28 10:39:10 +0000239 if (params->device_mem_ranges_count == 0) {
240 /*
241 * Map 1TB of address space as device memory to, most likely,
242 * make all devices available to the primary VM.
243 *
244 * TODO: remove this once all targets provide valid ranges.
245 */
Andrew Scullf6ab9bc2020-02-26 12:56:37 -0800246 dlog_warning(
247 "Device memory not provided, defaulting to 1 TB.\n");
Andrew Scull48929fd2020-01-28 10:39:10 +0000248
249 if (!vm_identity_map(
250 vm_locked, pa_init(0),
251 pa_init(UINT64_C(1024) * 1024 * 1024 * 1024),
252 MM_MODE_R | MM_MODE_W | MM_MODE_D, ppool, NULL)) {
253 dlog_error(
254 "Unable to initialise address space for "
Andrew Scullf6ab9bc2020-02-26 12:56:37 -0800255 "primary VM.\n");
Andrew Scull48929fd2020-01-28 10:39:10 +0000256 ret = false;
257 goto out;
258 }
David Brazdile6f83222019-09-23 14:47:37 +0100259 }
260
Andrew Scullb5f49e02019-10-02 13:20:47 +0100261 /* Map normal memory as such to permit caching, execution, etc. */
262 for (i = 0; i < params->mem_ranges_count; ++i) {
Andrew Scull3c257452019-11-26 13:32:50 +0000263 if (!vm_identity_map(vm_locked, params->mem_ranges[i].begin,
264 params->mem_ranges[i].end,
265 MM_MODE_R | MM_MODE_W | MM_MODE_X, ppool,
266 NULL)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +0000267 dlog_error(
Andrew Scullf6ab9bc2020-02-26 12:56:37 -0800268 "Unable to initialise memory for primary "
269 "VM.\n");
Andrew Scull3c257452019-11-26 13:32:50 +0000270 ret = false;
271 goto out;
Andrew Scullb5f49e02019-10-02 13:20:47 +0100272 }
273 }
274
Andrew Scull48929fd2020-01-28 10:39:10 +0000275 /* Map device memory as such to prevent execution, speculation etc. */
276 for (i = 0; i < params->device_mem_ranges_count; ++i) {
277 if (!vm_identity_map(
278 vm_locked, params->device_mem_ranges[i].begin,
279 params->device_mem_ranges[i].end,
280 MM_MODE_R | MM_MODE_W | MM_MODE_D, ppool, NULL)) {
281 dlog("Unable to initialise device memory for primary "
Andrew Scullf6ab9bc2020-02-26 12:56:37 -0800282 "VM.\n");
Andrew Scull48929fd2020-01-28 10:39:10 +0000283 ret = false;
284 goto out;
285 }
286 }
287
Manish Pandeyd34f8892020-06-19 17:41:07 +0100288 if (!load_common(stage1_locked, vm_locked, manifest_vm, ppool)) {
289 ret = false;
290 goto out;
291 }
292
Andrew Scull3c257452019-11-26 13:32:50 +0000293 if (!vm_unmap_hypervisor(vm_locked, ppool)) {
Andrew Scullf6ab9bc2020-02-26 12:56:37 -0800294 dlog_error("Unable to unmap hypervisor from primary VM.\n");
Andrew Scull3c257452019-11-26 13:32:50 +0000295 ret = false;
296 goto out;
David Brazdile6f83222019-09-23 14:47:37 +0100297 }
298
Andrew Scullb1a6d0d2020-01-29 11:25:12 +0000299 if (!plat_iommu_unmap_iommus(vm_locked, ppool)) {
Andrew Scullf6ab9bc2020-02-26 12:56:37 -0800300 dlog_error("Unable to unmap IOMMUs from primary VM.\n");
Andrew Scullb1a6d0d2020-01-29 11:25:12 +0000301 ret = false;
302 goto out;
303 }
304
Andrew Walbran7586e042020-02-18 18:19:26 +0000305 dlog_info("Loaded primary VM with %u vCPUs, entry at %#x.\n",
306 vm->vcpu_count, pa_addr(primary_begin));
307
Olivier Deprezb9adff42021-02-01 12:14:05 +0100308 /* Mark the primary to be the first booted VM */
309 vm_update_boot(vm);
310
David Brazdile6f83222019-09-23 14:47:37 +0100311 vcpu_locked = vcpu_lock(vm_get_vcpu(vm, 0));
Olivier Deprez62d99e32020-01-09 15:58:07 +0100312 vcpu_on(vcpu_locked, primary_entry, params->kernel_arg);
David Brazdile6f83222019-09-23 14:47:37 +0100313 vcpu_unlock(&vcpu_locked);
Andrew Scull3c257452019-11-26 13:32:50 +0000314 ret = true;
David Brazdile6f83222019-09-23 14:47:37 +0100315
Andrew Scull3c257452019-11-26 13:32:50 +0000316out:
317 vm_unlock(&vm_locked);
318
319 return ret;
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100320}
321
Fuad Tabba50469e02020-06-30 15:14:28 +0100322/**
323 * Loads the secondary VM's FDT.
324 * Stores the total allocated size for the FDT in fdt_allocated_size (if
325 * fdt_allocated_size is not NULL). The allocated size includes additional space
326 * for potential patching.
327 */
328static bool load_secondary_fdt(struct mm_stage1_locked stage1_locked,
329 paddr_t end, size_t fdt_max_size,
330 const struct manifest_vm *manifest_vm,
331 const struct memiter *cpio, struct mpool *ppool,
332 paddr_t *fdt_addr, size_t *fdt_allocated_size)
333{
334 struct memiter fdt;
335 size_t allocated_size;
336
337 CHECK(!string_is_empty(&manifest_vm->secondary.fdt_filename));
338
339 if (!cpio_get_file(cpio, &manifest_vm->secondary.fdt_filename, &fdt)) {
340 dlog_error("Cannot open the secondary VM's FDT.\n");
341 return false;
342 }
343
344 /*
345 * Ensure the FDT has one additional page at the end for patching, and
346 * and align it to the page boundary.
347 */
348 allocated_size = align_up(memiter_size(&fdt), PAGE_SIZE) + PAGE_SIZE;
349
350 if (allocated_size > fdt_max_size) {
351 dlog_error(
352 "FDT allocated space (%u) is more than the specified "
353 "maximum to use (%u).\n",
354 allocated_size, fdt_max_size);
355 return false;
356 }
357
358 /* Load the FDT to the end of the VM's allocated memory space. */
359 *fdt_addr = pa_init(pa_addr(pa_sub(end, allocated_size)));
360
361 dlog_info("Loading secondary FDT of allocated size %u at 0x%x.\n",
362 allocated_size, pa_addr(*fdt_addr));
363
364 if (!copy_to_unmapped(stage1_locked, *fdt_addr, &fdt, ppool)) {
365 dlog_error("Unable to copy FDT.\n");
366 return false;
367 }
368
369 if (fdt_allocated_size) {
370 *fdt_allocated_size = allocated_size;
371 }
372
373 return true;
374}
375
Andrew Scull72b43c02019-09-18 13:53:45 +0100376/*
377 * Loads a secondary VM.
378 */
379static bool load_secondary(struct mm_stage1_locked stage1_locked,
Manish Pandey2145c212020-05-01 16:04:22 +0100380 struct vm_locked primary_vm_locked,
Andrew Scull72b43c02019-09-18 13:53:45 +0100381 paddr_t mem_begin, paddr_t mem_end,
382 const struct manifest_vm *manifest_vm,
383 const struct memiter *cpio, struct mpool *ppool)
384{
385 struct vm *vm;
Andrew Scull3c257452019-11-26 13:32:50 +0000386 struct vm_locked vm_locked;
Max Shvetsov40108e72020-08-27 12:39:50 +0100387 struct vcpu_locked vcpu_locked;
Andrew Scull72b43c02019-09-18 13:53:45 +0100388 struct vcpu *vcpu;
389 ipaddr_t secondary_entry;
Andrew Scull3c257452019-11-26 13:32:50 +0000390 bool ret;
Fuad Tabba50469e02020-06-30 15:14:28 +0100391 paddr_t fdt_addr;
392 bool has_fdt;
393 size_t kernel_size = 0;
394 const size_t mem_size = pa_difference(mem_begin, mem_end);
Raghu Krishnamurthyd3ab8c32021-02-10 19:11:30 -0800395 uint32_t map_mode;
Andrew Scull72b43c02019-09-18 13:53:45 +0100396
Olivier Deprez62d99e32020-01-09 15:58:07 +0100397 /*
398 * Load the kernel if a filename is specified in the VM manifest.
399 * For an FF-A partition, kernel_filename is undefined indicating
400 * the partition package has already been loaded prior to Hafnium
401 * booting.
402 */
403 if (!string_is_empty(&manifest_vm->kernel_filename)) {
404 if (!load_kernel(stage1_locked, mem_begin, mem_end, manifest_vm,
Fuad Tabba50469e02020-06-30 15:14:28 +0100405 cpio, ppool, &kernel_size)) {
Olivier Deprez62d99e32020-01-09 15:58:07 +0100406 dlog_error("Unable to load kernel.\n");
407 return false;
408 }
Andrew Scull72b43c02019-09-18 13:53:45 +0100409 }
410
Fuad Tabba50469e02020-06-30 15:14:28 +0100411 has_fdt = !string_is_empty(&manifest_vm->secondary.fdt_filename);
412 if (has_fdt) {
413 /*
414 * Ensure that the FDT does not overwrite the kernel or overlap
415 * its page, for the FDT to start at a page boundary.
416 */
417 const size_t fdt_max_size =
418 mem_size - align_up(kernel_size, PAGE_SIZE);
419
420 size_t fdt_allocated_size;
421
422 if (!load_secondary_fdt(stage1_locked, mem_end, fdt_max_size,
423 manifest_vm, cpio, ppool, &fdt_addr,
424 &fdt_allocated_size)) {
425 dlog_error("Unable to load FDT.\n");
426 return false;
427 }
428
429 if (!fdt_patch_mem(stage1_locked, fdt_addr, fdt_allocated_size,
430 mem_begin, mem_end, ppool)) {
431 dlog_error("Unable to patch FDT.\n");
432 return false;
433 }
434 }
Raghu Krishnamurthycd1eceb2021-01-04 12:20:48 -0800435 /*
436 * An S-EL0 partition must contain only 1 vCPU (UP migratable) per the
437 * FF-A 1.0 spec.
438 */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700439 CHECK(manifest_vm->partition.run_time_el != S_EL0 ||
Raghu Krishnamurthycd1eceb2021-01-04 12:20:48 -0800440 manifest_vm->secondary.vcpu_count == 1);
Fuad Tabba50469e02020-06-30 15:14:28 +0100441
Raghu Krishnamurthycd1eceb2021-01-04 12:20:48 -0800442 if (!vm_init_next(manifest_vm->secondary.vcpu_count, ppool, &vm,
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700443 (manifest_vm->partition.run_time_el == S_EL0))) {
Andrew Walbran17eebf92020-02-05 16:35:49 +0000444 dlog_error("Unable to initialise VM.\n");
Andrew Scull72b43c02019-09-18 13:53:45 +0100445 return false;
446 }
447
Andrew Scull3c257452019-11-26 13:32:50 +0000448 vm_locked = vm_lock(vm);
449
Raghu Krishnamurthyd3ab8c32021-02-10 19:11:30 -0800450 /*
451 * Grant the VM access to the memory. TODO: For S-EL0 partitions,
452 * mapping all of its memory as RWX is bad from a security standpoint.
453 * Should just skip this and expect this to be present in the memory
454 * regions?
455 */
456 map_mode = MM_MODE_R | MM_MODE_W | MM_MODE_X;
457 if (vm->el0_partition) {
458 map_mode |= MM_MODE_USER | MM_MODE_NG;
459 }
460 if (!vm_identity_map(vm_locked, mem_begin, mem_end, map_mode, ppool,
Andrew Scull3c257452019-11-26 13:32:50 +0000461 &secondary_entry)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +0000462 dlog_error("Unable to initialise memory.\n");
Andrew Scull3c257452019-11-26 13:32:50 +0000463 ret = false;
464 goto out;
Andrew Scull72b43c02019-09-18 13:53:45 +0100465 }
466
Olivier Deprez62d99e32020-01-09 15:58:07 +0100467 if (manifest_vm->is_ffa_partition) {
Manish Pandey2145c212020-05-01 16:04:22 +0100468 int j = 0;
469 paddr_t region_begin;
470 paddr_t region_end;
471 paddr_t alloc_base = mem_end;
472 size_t size;
473 size_t total_alloc = 0;
474
475 /* Map memory-regions */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700476 while (j < manifest_vm->partition.mem_region_count) {
477 size = manifest_vm->partition.mem_regions[j]
478 .page_count *
Manish Pandey2145c212020-05-01 16:04:22 +0100479 PAGE_SIZE;
480 /*
481 * For memory-regions without base-address, memory
482 * should be allocated inside partition's page table.
483 * Start allocating memory regions in partition's
484 * page table, starting from the end.
485 * TODO: Add mechanism to let partition know of these
486 * memory regions
487 */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700488 if (manifest_vm->partition.mem_regions[j]
489 .base_address == MANIFEST_INVALID_ADDRESS) {
Manish Pandey2145c212020-05-01 16:04:22 +0100490 total_alloc += size;
491 /* Don't go beyond half the VM's memory space */
492 if (total_alloc >
493 (manifest_vm->secondary.mem_size / 2)) {
494 dlog_error(
495 "Not enough space for memory-"
496 "region allocation");
497 ret = false;
498 goto out;
499 }
500
501 region_end = alloc_base;
502 region_begin = pa_subtract(alloc_base, size);
503 alloc_base = region_begin;
504
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700505 map_mode = manifest_vm->partition.mem_regions[j]
Raghu Krishnamurthyd3ab8c32021-02-10 19:11:30 -0800506 .attributes;
507 if (vm->el0_partition) {
508 map_mode |= MM_MODE_USER | MM_MODE_NG;
509 }
510
511 if (!vm_identity_map(vm_locked, region_begin,
512 region_end, map_mode,
513 ppool, NULL)) {
Manish Pandey2145c212020-05-01 16:04:22 +0100514 dlog_error(
515 "Unable to map secondary VM "
516 "memory-region.\n");
517 ret = false;
518 goto out;
519 }
520
Olivier Deprez86d87ae2021-08-19 14:27:46 +0200521 dlog_verbose(
Manish Pandey2145c212020-05-01 16:04:22 +0100522 " Memory region %#x - %#x allocated\n",
523 region_begin, region_end);
524 } else {
525 /*
526 * Identity map memory region for both case,
527 * VA(S-EL0) or IPA(S-EL1).
528 */
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700529 region_begin = pa_init(
530 manifest_vm->partition.mem_regions[j]
531 .base_address);
Manish Pandey2145c212020-05-01 16:04:22 +0100532 region_end = pa_add(region_begin, size);
533
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700534 map_mode = manifest_vm->partition.mem_regions[j]
Raghu Krishnamurthyd3ab8c32021-02-10 19:11:30 -0800535 .attributes;
536 if (vm->el0_partition) {
537 map_mode |= MM_MODE_USER | MM_MODE_NG;
538 }
539
540 if (!vm_identity_map(vm_locked, region_begin,
541 region_end, map_mode,
542 ppool, NULL)) {
Manish Pandey2145c212020-05-01 16:04:22 +0100543 dlog_error(
544 "Unable to map secondary VM "
545 "memory-region.\n");
546 ret = false;
547 goto out;
548 }
549 }
550
551 /* Deny the primary VM access to this memory */
552 if (!vm_unmap(primary_vm_locked, region_begin,
553 region_end, ppool)) {
554 dlog_error(
555 "Unable to unmap secondary VM memory-"
556 "region from primary VM.\n");
557 ret = false;
558 goto out;
559 }
560
561 j++;
562 }
563
564 /* Map device-regions */
565 j = 0;
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700566 while (j < manifest_vm->partition.dev_region_count) {
567 region_begin =
568 pa_init(manifest_vm->partition.dev_regions[j]
569 .base_address);
570 size = manifest_vm->partition.dev_regions[j]
571 .page_count *
Manish Pandey2145c212020-05-01 16:04:22 +0100572 PAGE_SIZE;
573 region_end = pa_add(region_begin, size);
574
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700575 map_mode = manifest_vm->partition.dev_regions[j]
576 .attributes;
Raghu Krishnamurthyd3ab8c32021-02-10 19:11:30 -0800577 if (vm->el0_partition) {
578 map_mode |= MM_MODE_USER | MM_MODE_NG;
579 }
580
581 if (!vm_identity_map(vm_locked, region_begin,
582 region_end, map_mode, ppool,
583 NULL)) {
Manish Pandey2145c212020-05-01 16:04:22 +0100584 dlog_error(
585 "Unable to map secondary VM "
586 "device-region.\n");
587 ret = false;
588 goto out;
589 }
590 /* Deny primary VM access to this region */
591 if (!vm_unmap(primary_vm_locked, region_begin,
592 region_end, ppool)) {
593 dlog_error(
594 "Unable to unmap secondary VM device-"
595 "region from primary VM.\n");
596 ret = false;
597 goto out;
598 }
599 j++;
600 }
601
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700602 secondary_entry = ipa_add(secondary_entry,
603 manifest_vm->partition.ep_offset);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100604 }
605
Raghu Krishnamurthyd3ab8c32021-02-10 19:11:30 -0800606 /*
607 * Map hypervisor into the VM's page table. The hypervisor pages will
608 * not be accessible from EL0 since it will not be marked for user
609 * access.
610 * TODO: Map only the exception vectors and data that exception vectors
611 * require and not the entire hypervisor. This helps with speculative
612 * side-channel attacks.
613 */
614 if (vm->el0_partition) {
615 CHECK(vm_identity_map(vm_locked, layout_text_begin(),
616 layout_text_end(), MM_MODE_X, ppool,
617 NULL));
618
619 CHECK(vm_identity_map(vm_locked, layout_rodata_begin(),
620 layout_rodata_end(), MM_MODE_R, ppool,
621 NULL));
622
623 CHECK(vm_identity_map(vm_locked, layout_data_begin(),
624 layout_data_end(), MM_MODE_R | MM_MODE_W,
625 ppool, NULL));
626 plat_console_mm_init(mm_lock_ptable_unsafe(&vm->ptable), ppool);
627 }
628
Manish Pandeyd34f8892020-06-19 17:41:07 +0100629 if (!load_common(stage1_locked, vm_locked, manifest_vm, ppool)) {
630 ret = false;
631 goto out;
632 }
633
Manish Pandey2145c212020-05-01 16:04:22 +0100634 dlog_info("Loaded with %u vCPUs, entry at %#x.\n",
635 manifest_vm->secondary.vcpu_count, pa_addr(mem_begin));
636
Andrew Scull72b43c02019-09-18 13:53:45 +0100637 vcpu = vm_get_vcpu(vm, 0);
Fuad Tabba50469e02020-06-30 15:14:28 +0100638
Max Shvetsov40108e72020-08-27 12:39:50 +0100639 vcpu_locked = vcpu_lock(vcpu);
Fuad Tabba50469e02020-06-30 15:14:28 +0100640 if (has_fdt) {
Max Shvetsov40108e72020-08-27 12:39:50 +0100641 vcpu_secondary_reset_and_start(vcpu_locked, secondary_entry,
Fuad Tabba50469e02020-06-30 15:14:28 +0100642 pa_addr(fdt_addr));
643 } else {
644 /*
645 * Without an FDT, secondary VMs expect the memory size to be
646 * passed in register x0, which is what
647 * vcpu_secondary_reset_and_start does in this case.
648 */
Max Shvetsov40108e72020-08-27 12:39:50 +0100649 vcpu_secondary_reset_and_start(vcpu_locked, secondary_entry,
650 mem_size);
Fuad Tabba50469e02020-06-30 15:14:28 +0100651 }
652
Max Shvetsov40108e72020-08-27 12:39:50 +0100653 vcpu_unlock(&vcpu_locked);
654
Andrew Scull3c257452019-11-26 13:32:50 +0000655 ret = true;
Andrew Scull72b43c02019-09-18 13:53:45 +0100656
Andrew Scull3c257452019-11-26 13:32:50 +0000657out:
658 vm_unlock(&vm_locked);
659
660 return ret;
Andrew Scull72b43c02019-09-18 13:53:45 +0100661}
662
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100663/**
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100664 * Try to find a memory range of the given size within the given ranges, and
665 * remove it from them. Return true on success, or false if no large enough
666 * contiguous range is found.
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100667 */
Hong-Seok Kim09648362019-05-23 15:47:11 +0900668static bool carve_out_mem_range(struct mem_range *mem_ranges,
669 size_t mem_ranges_count, uint64_t size_to_find,
670 paddr_t *found_begin, paddr_t *found_end)
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100671{
672 size_t i;
673
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000674 /*
675 * TODO(b/116191358): Consider being cleverer about how we pack VMs
676 * together, with a non-greedy algorithm.
677 */
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100678 for (i = 0; i < mem_ranges_count; ++i) {
679 if (size_to_find <=
Andrew Walbran2cb43392019-04-17 12:52:45 +0100680 pa_difference(mem_ranges[i].begin, mem_ranges[i].end)) {
Wedson Almeida Filhob2c159e2018-10-25 13:27:47 +0100681 /*
682 * This range is big enough, take some of it from the
683 * end and reduce its size accordingly.
684 */
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100685 *found_end = mem_ranges[i].end;
686 *found_begin = pa_init(pa_addr(mem_ranges[i].end) -
687 size_to_find);
688 mem_ranges[i].end = *found_begin;
689 return true;
690 }
691 }
692 return false;
693}
694
695/**
696 * Given arrays of memory ranges before and after memory was removed for
697 * secondary VMs, add the difference to the reserved ranges of the given update.
698 * Return true on success, or false if there would be more than MAX_MEM_RANGES
699 * reserved ranges after adding the new ones.
700 * `before` and `after` must be arrays of exactly `mem_ranges_count` elements.
701 */
Hong-Seok Kim09648362019-05-23 15:47:11 +0900702static bool update_reserved_ranges(struct boot_params_update *update,
703 const struct mem_range *before,
704 const struct mem_range *after,
705 size_t mem_ranges_count)
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100706{
707 size_t i;
708
709 for (i = 0; i < mem_ranges_count; ++i) {
710 if (pa_addr(after[i].begin) > pa_addr(before[i].begin)) {
711 if (update->reserved_ranges_count >= MAX_MEM_RANGES) {
Andrew Walbran17eebf92020-02-05 16:35:49 +0000712 dlog_error(
713 "Too many reserved ranges after "
714 "loading secondary VMs.\n");
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100715 return false;
716 }
717 update->reserved_ranges[update->reserved_ranges_count]
718 .begin = before[i].begin;
719 update->reserved_ranges[update->reserved_ranges_count]
720 .end = after[i].begin;
721 update->reserved_ranges_count++;
722 }
723 if (pa_addr(after[i].end) < pa_addr(before[i].end)) {
724 if (update->reserved_ranges_count >= MAX_MEM_RANGES) {
Andrew Walbran17eebf92020-02-05 16:35:49 +0000725 dlog_error(
726 "Too many reserved ranges after "
727 "loading secondary VMs.\n");
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100728 return false;
729 }
730 update->reserved_ranges[update->reserved_ranges_count]
731 .begin = after[i].end;
732 update->reserved_ranges[update->reserved_ranges_count]
733 .end = before[i].end;
734 update->reserved_ranges_count++;
735 }
736 }
737
738 return true;
739}
740
Olivier Deprez112d2b52020-09-30 07:39:23 +0200741static bool init_other_world_vm(struct mpool *ppool)
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100742{
Olivier Deprez96a2a262020-06-11 17:21:38 +0200743 struct vm *other_world_vm;
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100744 size_t i;
Andrew Scull72b43c02019-09-18 13:53:45 +0100745
Andrew Walbran9daa57e2019-09-27 13:33:20 +0100746 /*
Olivier Deprez96a2a262020-06-11 17:21:38 +0200747 * Initialise the dummy VM which represents the opposite world:
748 * -TrustZone (or the SPMC) when running the Hypervisor
749 * -the Hypervisor when running TZ/SPMC
Andrew Walbran9daa57e2019-09-27 13:33:20 +0100750 */
Raghu Krishnamurthycd1eceb2021-01-04 12:20:48 -0800751 other_world_vm = vm_init(HF_OTHER_WORLD_ID, MAX_CPUS, ppool, false);
Olivier Deprez96a2a262020-06-11 17:21:38 +0200752 CHECK(other_world_vm != NULL);
753
754 for (i = 0; i < MAX_CPUS; i++) {
755 struct vcpu *vcpu = vm_get_vcpu(other_world_vm, i);
756 struct cpu *cpu = cpu_find_index(i);
757
758 vcpu->cpu = cpu;
759 }
Andrew Walbran9daa57e2019-09-27 13:33:20 +0100760
Olivier Deprez112d2b52020-09-30 07:39:23 +0200761 return arch_other_world_vm_init(other_world_vm, ppool);
762}
763
764/*
765 * Loads alls VMs from the manifest.
766 */
767bool load_vms(struct mm_stage1_locked stage1_locked,
768 const struct manifest *manifest, const struct memiter *cpio,
769 const struct boot_params *params,
770 struct boot_params_update *update, struct mpool *ppool)
771{
772 struct vm *primary;
773 struct mem_range mem_ranges_available[MAX_MEM_RANGES];
774 struct vm_locked primary_vm_locked;
775 size_t i;
776 bool success = true;
777
Andrew Walbranf8716782020-10-29 17:07:07 +0000778 /**
779 * Only try to load the primary VM if it is supposed to be in this
780 * world.
781 */
782 if (vm_id_is_current_world(HF_PRIMARY_VM_ID)) {
783 if (!load_primary(stage1_locked,
784 &manifest->vm[HF_PRIMARY_VM_INDEX], cpio,
785 params, ppool)) {
786 dlog_error("Unable to load primary VM.\n");
787 return false;
788 }
Olivier Deprez112d2b52020-09-30 07:39:23 +0200789 }
790
791 if (!init_other_world_vm(ppool)) {
792 return false;
793 }
794
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100795 static_assert(
796 sizeof(mem_ranges_available) == sizeof(params->mem_ranges),
797 "mem_range arrays must be the same size for memcpy.");
798 static_assert(sizeof(mem_ranges_available) < 500,
799 "This will use too much stack, either make "
800 "MAX_MEM_RANGES smaller or change this.");
Andrew Sculla1aa2ba2019-04-05 11:49:02 +0100801 memcpy_s(mem_ranges_available, sizeof(mem_ranges_available),
802 params->mem_ranges, sizeof(params->mem_ranges));
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100803
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100804 /* Round the last addresses down to the page size. */
805 for (i = 0; i < params->mem_ranges_count; ++i) {
Alfredo Mazzinghieb1997c2019-02-07 18:00:01 +0000806 mem_ranges_available[i].end = pa_init(align_down(
807 pa_addr(mem_ranges_available[i].end), PAGE_SIZE));
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100808 }
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +0100809
Andrew Scull3c257452019-11-26 13:32:50 +0000810 primary = vm_find(HF_PRIMARY_VM_ID);
811 primary_vm_locked = vm_lock(primary);
812
David Brazdil0251b942019-09-10 15:59:50 +0100813 for (i = 0; i < manifest->vm_count; ++i) {
David Brazdil0dbb41f2019-09-09 18:03:35 +0100814 const struct manifest_vm *manifest_vm = &manifest->vm[i];
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100815 ffa_vm_id_t vm_id = HF_VM_ID_OFFSET + i;
David Brazdil7a462ec2019-08-15 12:27:47 +0100816 uint64_t mem_size;
Andrew Scull80871322018-08-06 12:04:09 +0100817 paddr_t secondary_mem_begin;
818 paddr_t secondary_mem_end;
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100819
David Brazdil7a462ec2019-08-15 12:27:47 +0100820 if (vm_id == HF_PRIMARY_VM_ID) {
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100821 continue;
822 }
823
Olivier Deprez2a8ee342020-08-03 15:10:44 +0200824 dlog_info("Loading VM id %#x: %s.\n", vm_id,
Andrew Walbran17eebf92020-02-05 16:35:49 +0000825 manifest_vm->debug_name);
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100826
David Brazdil7a462ec2019-08-15 12:27:47 +0100827 mem_size = align_up(manifest_vm->secondary.mem_size, PAGE_SIZE);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100828
829 if (manifest_vm->is_ffa_partition) {
830 secondary_mem_begin =
Raghu Krishnamurthy8c250a92021-07-02 12:16:42 -0700831 pa_init(manifest_vm->partition.load_addr);
832 secondary_mem_end = pa_init(
833 manifest_vm->partition.load_addr + mem_size);
Olivier Deprez62d99e32020-01-09 15:58:07 +0100834 } else if (!carve_out_mem_range(mem_ranges_available,
835 params->mem_ranges_count,
836 mem_size, &secondary_mem_begin,
837 &secondary_mem_end)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +0000838 dlog_error("Not enough memory (%u bytes).\n", mem_size);
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100839 continue;
840 }
Andrew Scull80871322018-08-06 12:04:09 +0100841
Manish Pandey2145c212020-05-01 16:04:22 +0100842 if (!load_secondary(stage1_locked, primary_vm_locked,
843 secondary_mem_begin, secondary_mem_end,
844 manifest_vm, cpio, ppool)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +0000845 dlog_error("Unable to load VM.\n");
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +0100846 continue;
847 }
848
849 /* Deny the primary VM access to this memory. */
Andrew Scull3c257452019-11-26 13:32:50 +0000850 if (!vm_unmap(primary_vm_locked, secondary_mem_begin,
851 secondary_mem_end, ppool)) {
Andrew Walbran17eebf92020-02-05 16:35:49 +0000852 dlog_error(
853 "Unable to unmap secondary VM from primary "
854 "VM.\n");
Andrew Scull3c257452019-11-26 13:32:50 +0000855 success = false;
856 break;
Wedson Almeida Filho84a30a02018-07-23 20:05:05 +0100857 }
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100858 }
859
Andrew Scull3c257452019-11-26 13:32:50 +0000860 vm_unlock(&primary_vm_locked);
861
862 if (!success) {
863 return false;
864 }
865
Wedson Almeida Filhob2c159e2018-10-25 13:27:47 +0100866 /*
867 * Add newly reserved areas to update params by looking at the
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100868 * difference between the available ranges from the original params and
869 * the updated mem_ranges_available. We assume that the number and order
870 * of available ranges is the same, i.e. we don't remove any ranges
Wedson Almeida Filhob2c159e2018-10-25 13:27:47 +0100871 * above only make them smaller.
872 */
Andrew Walbran34ce72e2018-09-13 16:47:44 +0100873 return update_reserved_ranges(update, params->mem_ranges,
874 mem_ranges_available,
875 params->mem_ranges_count);
Wedson Almeida Filhofdf4afc2018-07-19 15:45:21 +0100876}