View | Details | Raw Unified | Return to bug 216375 | Differences between
and this patch

Collapse All | Expand All

(-)a/drivers/firmware/efi/libstub/alignedmem.c (-1 / +2 lines)
Lines 27-33 efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr, Link Here
27
	efi_physical_addr_t alloc_addr;
27
	efi_physical_addr_t alloc_addr;
28
	efi_status_t status;
28
	efi_status_t status;
29
	int slack;
29
	int slack;
30
30
	efi_debug("Entered efi_allocate_pages_aligned(0x%lx, 0x%lx, 0x%lx, 0x%lx) EFI_ALLOC_ALIGN=0x%x\n", size, *addr, max,align, EFI_ALLOC_ALIGN);
31
	if (align < EFI_ALLOC_ALIGN)
31
	if (align < EFI_ALLOC_ALIGN)
32
		align = EFI_ALLOC_ALIGN;
32
		align = EFI_ALLOC_ALIGN;
33
33
Lines 42-47 efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr, Link Here
42
		return status;
42
		return status;
43
43
44
	*addr = ALIGN((unsigned long)alloc_addr, align);
44
	*addr = ALIGN((unsigned long)alloc_addr, align);
45
	efi_debug("  addr=0x%lx\n", *addr);
45
46
46
	if (slack > 0) {
47
	if (slack > 0) {
47
		int l = (alloc_addr & (align - 1)) / EFI_PAGE_SIZE;
48
		int l = (alloc_addr & (align - 1)) / EFI_PAGE_SIZE;
(-)a/drivers/firmware/efi/libstub/efi-stub-helper.c (-9 / +35 lines)
Lines 416-421 char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len) Link Here
416
	return (char *)cmdline_addr;
416
	return (char *)cmdline_addr;
417
}
417
}
418
418
419
void efi_boot_memmap_report(struct efi_boot_memmap *map)
420
{
421
	efi_debug("efi_boot_memmap = {map=0x%p map_size=0x%lx desc_size=0x%lx desc_ver=0x%x key_ptr=0x%p *key_ptr=0x%lx buff_size=0x%lx }\n" , *map->map, *map->map_size, *map->desc_size, *map->desc_ver, map->key_ptr, *map->key_ptr, *map->buff_size );
422
}
423
419
/**
424
/**
420
 * efi_exit_boot_services() - Exit boot services
425
 * efi_exit_boot_services() - Exit boot services
421
 * @handle:	handle of the exiting image
426
 * @handle:	handle of the exiting image
Lines 438-459 efi_status_t efi_exit_boot_services(void *handle, Link Here
438
				    efi_exit_boot_map_processing priv_func)
443
				    efi_exit_boot_map_processing priv_func)
439
{
444
{
440
	efi_status_t status;
445
	efi_status_t status;
446
	unsigned long stall_delay = 10000000;
447
	unsigned int repeat;
441
448
442
	status = efi_get_memory_map(map);
449
	efi_debug("Entered efi_exit_boot_services()\n");
443
450
	efi_debug("Memory map before calling priv_func():\n");
444
	if (status != EFI_SUCCESS)
451
	efi_boot_memmap_report(map);
445
		goto fail;
446
447
	status = priv_func(map, priv);
452
	status = priv_func(map, priv);
453
	efi_debug("Memory map after calling priv_func():\n");
454
	efi_boot_memmap_report(map);
448
	if (status != EFI_SUCCESS)
455
	if (status != EFI_SUCCESS)
449
		goto free_map;
456
		goto free_map;
450
457
451
	if (efi_disable_pci_dma)
458
	if (efi_disable_pci_dma) {
459
		efi_debug("Calling efi_pci_disable_bridge_busmaster()\n");
452
		efi_pci_disable_bridge_busmaster();
460
		efi_pci_disable_bridge_busmaster();
453
461
	}
462
	efi_debug("Calling efi_bs_call(exit_boot_services, 0x%p, 0x%lx)\n", handle, *map->key_ptr);
454
	status = efi_bs_call(exit_boot_services, handle, *map->key_ptr);
463
	status = efi_bs_call(exit_boot_services, handle, *map->key_ptr);
455
464
465
	for(repeat=0; repeat < 10; repeat++) {
466
	efi_debug("Repeat attempt: %d\n", repeat);
456
	if (status == EFI_INVALID_PARAMETER) {
467
	if (status == EFI_INVALID_PARAMETER) {
468
		efi_debug("efi_bs_call() returned 0x%x (EFI_INVALID_PARAMETER)\n", status);
469
        	efi_debug("Busy Wait so you can read the ebug messages!");
470
		efi_bs_call(stall, stall_delay);
457
		/*
471
		/*
458
		 * The memory map changed between efi_get_memory_map() and
472
		 * The memory map changed between efi_get_memory_map() and
459
		 * exit_boot_services().  Per the UEFI Spec v2.6, Section 6.4:
473
		 * exit_boot_services().  Per the UEFI Spec v2.6, Section 6.4:
Lines 468-473 efi_status_t efi_exit_boot_services(void *handle, Link Here
468
		 * to get_memory_map() is expected to succeed here.
482
		 * to get_memory_map() is expected to succeed here.
469
		 */
483
		 */
470
		*map->map_size = *map->buff_size;
484
		*map->map_size = *map->buff_size;
485
		efi_debug("Calling efi_bs_call() with get_memory_map\n");
471
		status = efi_bs_call(get_memory_map,
486
		status = efi_bs_call(get_memory_map,
472
				     map->map_size,
487
				     map->map_size,
473
				     *map->map,
488
				     *map->map,
Lines 475-501 efi_status_t efi_exit_boot_services(void *handle, Link Here
475
				     map->desc_size,
490
				     map->desc_size,
476
				     map->desc_ver);
491
				     map->desc_ver);
477
492
493
		efi_debug("Memory map after calling get_memory_map() again:\n");
494
		efi_boot_memmap_report(map);
478
		/* exit_boot_services() was called, thus cannot free */
495
		/* exit_boot_services() was called, thus cannot free */
479
		if (status != EFI_SUCCESS)
496
		if (status != EFI_SUCCESS)
480
			goto fail;
497
			goto fail;
481
498
		efi_debug("Calling priv_func() again\n");
482
		status = priv_func(map, priv);
499
		status = priv_func(map, priv);
500
		efi_debug("Memory map after calling priv_func() again:\n");
501
		efi_boot_memmap_report(map);
483
		/* exit_boot_services() was called, thus cannot free */
502
		/* exit_boot_services() was called, thus cannot free */
484
		if (status != EFI_SUCCESS)
503
		if (status != EFI_SUCCESS)
485
			goto fail;
504
			goto fail;
486
505
506
		efi_debug("Calling (again!) efi_bs_call(exit_boot_services, 0x%p, 0x%lx)\n", handle, *map->key_ptr);
487
		status = efi_bs_call(exit_boot_services, handle, *map->key_ptr);
507
		status = efi_bs_call(exit_boot_services, handle, *map->key_ptr);
488
	}
508
	}
509
	else {
510
		break;
511
	}
512
	}
489
513
490
	/* exit_boot_services() was called, thus cannot free */
514
	/* exit_boot_services() was called, thus cannot free */
491
	if (status != EFI_SUCCESS)
515
	if (status != EFI_SUCCESS)
492
		goto fail;
516
		goto fail;
493
517
	efi_debug("Returning from efi_exit_boot_services() with EFI_SUCCESS\n");
494
	return EFI_SUCCESS;
518
	return EFI_SUCCESS;
495
519
496
free_map:
520
free_map:
521
	efi_debug("free_map: Calling efi_bs_call() with free_pool\n");
497
	efi_bs_call(free_pool, *map->map);
522
	efi_bs_call(free_pool, *map->map);
498
fail:
523
fail:
524
	efi_debug("fail: efi_exit_boot_services() returns %ld\n", status);
499
	return status;
525
	return status;
500
}
526
}
501
527
(-)a/drivers/firmware/efi/libstub/efistub.h (-1 / +3 lines)
Lines 158-164 void efi_set_u64_split(u64 data, u32 *lo, u32 *hi) Link Here
158
 * the EFI memory map. Other related structures, e.g. x86 e820ext, need
158
 * the EFI memory map. Other related structures, e.g. x86 e820ext, need
159
 * to factor in this headroom requirement as well.
159
 * to factor in this headroom requirement as well.
160
 */
160
 */
161
#define EFI_MMAP_NR_SLACK_SLOTS	8
161
#define EFI_MMAP_NR_SLACK_SLOTS	32
162
162
163
struct efi_boot_memmap {
163
struct efi_boot_memmap {
164
	efi_memory_desc_t	**map;
164
	efi_memory_desc_t	**map;
Lines 966-969 efi_enable_reset_attack_mitigation(void) { } Link Here
966
966
967
void efi_retrieve_tpm2_eventlog(void);
967
void efi_retrieve_tpm2_eventlog(void);
968
968
969
void efi_boot_memmap_report(struct efi_boot_memmap *map);
970
969
#endif
971
#endif
(-)a/drivers/firmware/efi/libstub/fdt.c (-8 / +23 lines)
Lines 207-212 static efi_status_t exit_boot_func(struct efi_boot_memmap *map, Link Here
207
				   void *priv)
207
				   void *priv)
208
{
208
{
209
	struct exit_boot_struct *p = priv;
209
	struct exit_boot_struct *p = priv;
210
	efi_debug("Entered exit_boot_func() - updating map with virtual addresses\n");
210
	/*
211
	/*
211
	 * Update the memory map with virtual addresses. The function will also
212
	 * Update the memory map with virtual addresses. The function will also
212
	 * populate @runtime_map with copies of just the EFI_MEMORY_RUNTIME
213
	 * populate @runtime_map with copies of just the EFI_MEMORY_RUNTIME
Lines 214-220 static efi_status_t exit_boot_func(struct efi_boot_memmap *map, Link Here
214
	 */
215
	 */
215
	efi_get_virtmap(*map->map, *map->map_size, *map->desc_size,
216
	efi_get_virtmap(*map->map, *map->map_size, *map->desc_size,
216
			p->runtime_map, p->runtime_entry_count);
217
			p->runtime_map, p->runtime_entry_count);
217
218
	efi_boot_memmap_report(map);
219
	efi_debug("Returning after calling update_fdt_memmap()\n");
218
	return update_fdt_memmap(p->new_fdt_addr, map);
220
	return update_fdt_memmap(p->new_fdt_addr, map);
219
}
221
}
220
222
Lines 243-248 efi_status_t allocate_new_fdt_and_exit_boot(void *handle, Link Here
243
					    unsigned long fdt_addr,
245
					    unsigned long fdt_addr,
244
					    unsigned long fdt_size)
246
					    unsigned long fdt_size)
245
{
247
{
248
	unsigned long stall_delay = 10000000;
246
	unsigned long map_size, desc_size, buff_size;
249
	unsigned long map_size, desc_size, buff_size;
247
	u32 desc_ver;
250
	u32 desc_ver;
248
	unsigned long mmap_key;
251
	unsigned long mmap_key;
Lines 259-264 efi_status_t allocate_new_fdt_and_exit_boot(void *handle, Link Here
259
	map.key_ptr	= &mmap_key;
262
	map.key_ptr	= &mmap_key;
260
	map.buff_size	= &buff_size;
263
	map.buff_size	= &buff_size;
261
264
265
	efi_debug("Entering allocate_new_fdt_and_exit_boot()\n");
262
	/*
266
	/*
263
	 * Get a copy of the current memory map that we will use to prepare
267
	 * Get a copy of the current memory map that we will use to prepare
264
	 * the input for SetVirtualAddressMap(). We don't have to worry about
268
	 * the input for SetVirtualAddressMap(). We don't have to worry about
Lines 279-285 efi_status_t allocate_new_fdt_and_exit_boot(void *handle, Link Here
279
		efi_err("Unable to allocate memory for new device tree.\n");
283
		efi_err("Unable to allocate memory for new device tree.\n");
280
		goto fail;
284
		goto fail;
281
	}
285
	}
282
283
	/*
286
	/*
284
	 * Now that we have done our final memory allocation (and free)
287
	 * Now that we have done our final memory allocation (and free)
285
	 * we can get the memory map key needed for exit_boot_services().
288
	 * we can get the memory map key needed for exit_boot_services().
Lines 287-319 efi_status_t allocate_new_fdt_and_exit_boot(void *handle, Link Here
287
	status = efi_get_memory_map(&map);
290
	status = efi_get_memory_map(&map);
288
	if (status != EFI_SUCCESS)
291
	if (status != EFI_SUCCESS)
289
		goto fail_free_new_fdt;
292
		goto fail_free_new_fdt;
290
291
	status = update_fdt((void *)fdt_addr, fdt_size,
293
	status = update_fdt((void *)fdt_addr, fdt_size,
292
			    (void *)*new_fdt_addr, MAX_FDT_SIZE, cmdline_ptr,
294
			    (void *)*new_fdt_addr, MAX_FDT_SIZE, cmdline_ptr,
293
			    initrd_addr, initrd_size);
295
			    initrd_addr, initrd_size);
294
295
	if (status != EFI_SUCCESS) {
296
	if (status != EFI_SUCCESS) {
296
		efi_err("Unable to construct new device tree.\n");
297
		efi_err("Unable to construct new device tree.\n");
297
		goto fail_free_new_fdt;
298
		goto fail_free_new_fdt;
298
	}
299
	}
299
300
301
        efi_debug("Busy Wait so you can read the debug messages!");
302
	efi_bs_call(stall, stall_delay);
303
300
	runtime_entry_count		= 0;
304
	runtime_entry_count		= 0;
301
	priv.runtime_map		= runtime_map;
305
	priv.runtime_map		= runtime_map;
302
	priv.runtime_entry_count	= &runtime_entry_count;
306
	priv.runtime_entry_count	= &runtime_entry_count;
303
	priv.new_fdt_addr		= (void *)*new_fdt_addr;
307
	priv.new_fdt_addr		= (void *)*new_fdt_addr;
304
308
309
	efi_debug("Calling efi_exit_boot_services() with map:\n");
310
	efi_boot_memmap_report(&map);
305
	status = efi_exit_boot_services(handle, &map, &priv, exit_boot_func);
311
	status = efi_exit_boot_services(handle, &map, &priv, exit_boot_func);
306
312
	efi_debug("Returned from efi_exit_boot_services()\n");
307
	if (status == EFI_SUCCESS) {
313
	if (status == EFI_SUCCESS) {
308
		efi_set_virtual_address_map_t *svam;
314
		efi_set_virtual_address_map_t *svam;
309
315
		efi_debug("Preparing to do virtual address map\n");
310
		if (efi_novamap)
316
		if (efi_novamap) {
317
			efi_debug("Got 'novamap' so nothing to do\n");
311
			return EFI_SUCCESS;
318
			return EFI_SUCCESS;
319
		}
312
320
313
		/* Install the new virtual address map */
321
		/* Install the new virtual address map */
314
		svam = efi_system_table->runtime->set_virtual_address_map;
322
		svam = efi_system_table->runtime->set_virtual_address_map;
323
		efi_debug("Calling svam()\n");
315
		status = svam(runtime_entry_count * desc_size, desc_size,
324
		status = svam(runtime_entry_count * desc_size, desc_size,
316
			      desc_ver, runtime_map);
325
			      desc_ver, runtime_map);
326
		efi_debug("Returned from svam()\n");
317
327
318
		/*
328
		/*
319
		 * We are beyond the point of no return here, so if the call to
329
		 * We are beyond the point of no return here, so if the call to
Lines 322-327 efi_status_t allocate_new_fdt_and_exit_boot(void *handle, Link Here
322
		 */
332
		 */
323
		if (status != EFI_SUCCESS) {
333
		if (status != EFI_SUCCESS) {
324
			int l;
334
			int l;
335
			efi_debug("svam() failed with %ld\n", status);
325
336
326
			/*
337
			/*
327
			 * Set the virtual address field of all
338
			 * Set the virtual address field of all
Lines 336-352 efi_status_t allocate_new_fdt_and_exit_boot(void *handle, Link Here
336
					p->virt_addr = 0;
347
					p->virt_addr = 0;
337
			}
348
			}
338
		}
349
		}
350
		efi_debug("allocate_new_fdt_and_exit_boot() returning EFI_SUCCESS\n");
339
		return EFI_SUCCESS;
351
		return EFI_SUCCESS;
340
	}
352
	}
341
353
342
	efi_err("Exit boot services failed.\n");
354
	efi_err("Exit boot services failed.\n");
343
355
344
fail_free_new_fdt:
356
fail_free_new_fdt:
357
	efi_debug("fail_free_new_fdt: status=%ld\n", status);
345
	efi_free(MAX_FDT_SIZE, *new_fdt_addr);
358
	efi_free(MAX_FDT_SIZE, *new_fdt_addr);
346
359
347
fail:
360
fail:
361
	efi_debug("fail: status=%ld\n", status);
348
	efi_system_table->boottime->free_pool(runtime_map);
362
	efi_system_table->boottime->free_pool(runtime_map);
349
363
        efi_debug("Busy Wait so you can read the debug messages!");
364
	efi_bs_call(stall, stall_delay);
350
	return EFI_LOAD_ERROR;
365
	return EFI_LOAD_ERROR;
351
}
366
}
352
367
(-)a/drivers/firmware/efi/libstub/mem.c (-1 / +2 lines)
Lines 93-99 efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr, Link Here
93
{
93
{
94
	efi_physical_addr_t alloc_addr;
94
	efi_physical_addr_t alloc_addr;
95
	efi_status_t status;
95
	efi_status_t status;
96
96
	efi_debug("Entered efi_allocate_pages()\n");
97
	if (EFI_ALLOC_ALIGN > EFI_PAGE_SIZE)
97
	if (EFI_ALLOC_ALIGN > EFI_PAGE_SIZE)
98
		return efi_allocate_pages_aligned(size, addr, max,
98
		return efi_allocate_pages_aligned(size, addr, max,
99
						  EFI_ALLOC_ALIGN);
99
						  EFI_ALLOC_ALIGN);
Lines 106-111 efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr, Link Here
106
		return status;
106
		return status;
107
107
108
	*addr = alloc_addr;
108
	*addr = alloc_addr;
109
	efi_debug(" addr=0x%lx\n", *addr);
109
	return EFI_SUCCESS;
110
	return EFI_SUCCESS;
110
}
111
}
111
112

Return to bug 216375