All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 03/16] efi_loader: Add PE image loader
Date: Tue, 2 Feb 2016 17:49:47 +0000	[thread overview]
Message-ID: <20160202174947.GA29778@leverpostej> (raw)
In-Reply-To: <1454381114-22547-4-git-send-email-agraf@suse.de>

On Tue, Feb 02, 2016 at 03:45:01AM +0100, Alexander Graf wrote:
> EFI uses the PE binary format for its application images. Add support to EFI PE
> binaries as well as all necessary bits for the "EFI image loader" interfaces.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> 
> ---
> 
> v1 -> v2:
> 
>   - move memory allocation to separate patch
>   - limit 32/64 to hosts that support it
>   - check 32bit optional nt header magic
>   - switch to GPL2+
> 
> v2 -> v3:
> 
>   - use efi_alloc
>   - add EFIAPI to function prototypes
>   - remove unused macros
>   - reorder header inclusion
>   - split relocation code into function
>   - flush cache after loading
> ---
>  include/efi_loader.h              |  20 +++
>  include/pe.h                      | 263 ++++++++++++++++++++++++++++++++++++++
>  lib/efi_loader/efi_image_loader.c | 182 ++++++++++++++++++++++++++
>  3 files changed, 465 insertions(+)
>  create mode 100644 include/efi_loader.h
>  create mode 100644 include/pe.h
>  create mode 100644 lib/efi_loader/efi_image_loader.c

[...]

> +static void efi_loader_relocate(const IMAGE_BASE_RELOCATION *rel,
> +			unsigned long rel_size, void *efi_reloc)
> +{
> +	const IMAGE_BASE_RELOCATION *end;
> +	int i;
> +
> +	end = (const IMAGE_BASE_RELOCATION *)((const char *)rel + rel_size);
> +	while (rel < end - 1 && rel->SizeOfBlock) {
> +		const uint16_t *relocs = (const uint16_t *)(rel + 1);
> +		i = (rel->SizeOfBlock - sizeof(*rel)) / sizeof(uint16_t);
> +		while (i--) {
> +			uint16_t offset = (*relocs & 0xfff) +
> +					  rel->VirtualAddress;
> +			int type = *relocs >> 12;
> +			unsigned long delta = (unsigned long)efi_reloc;
> +			uint64_t *x64 = efi_reloc + offset;
> +			uint32_t *x32 = efi_reloc + offset;
> +			uint16_t *x16 = efi_reloc + offset;
> +
> +			switch (type) {
> +			case IMAGE_REL_BASED_ABSOLUTE:
> +				break;
> +			case IMAGE_REL_BASED_HIGH:
> +				*x16 += ((uint32_t)delta) >> 16;
> +				break;
> +			case IMAGE_REL_BASED_LOW:
> +				*x16 += (uint16_t)delta;
> +				break;
> +			case IMAGE_REL_BASED_HIGHLOW:
> +				*x32 += (uint32_t)delta;
> +				break;
> +			case IMAGE_REL_BASED_DIR64:
> +				*x64 += (uint64_t)delta;
> +				break;
> +			default:
> +				printf("Unknown Relocation off %x type %x\n",
> +				       offset, type);
> +			}
> +			relocs++;
> +		}
> +		rel = (const IMAGE_BASE_RELOCATION *)relocs;
> +	}
> +}

[...]

> +	/* Load sections into RAM */
> +	for (i = num_sections - 1; i >= 0; i--) {
> +		IMAGE_SECTION_HEADER *sec = &sections[i];
> +		memset(efi_reloc + sec->VirtualAddress, 0,
> +		       sec->Misc.VirtualSize);
> +		memcpy(efi_reloc + sec->VirtualAddress,
> +		       efi + sec->PointerToRawData,
> +		       sec->SizeOfRawData);
> +	}
> +
> +	/* Run through relocations */
> +	efi_loader_relocate(rel, rel_size, efi_reloc);
> +
> +	/* Flush cache */
> +	flush_cache((ulong)efi_reloc, virt_size);

Where's the I-cache maintenance for the image performed? I can't see it
here and I didn't spot it in later patches.

Given that speculative instruction fetches can happen at any time for
anything not marked NX, there may already be stale entries in the
I-caches.

Also, flush_cache seems to perform DC CIVAC in a loop, which is
excessively expensive. To make the instructions visible to instruction
fetches you only need DC CVAU (i.e. clean by VA to the PoU), and you
only need to do that for executable sections.

Mark.

> +
> +	/* Populate the loaded image interface bits */
> +	loaded_image_info->image_base = efi;
> +	loaded_image_info->image_size = image_size;
> +
> +	return entry;
> +}
> -- 
> 2.6.2
> 
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
> 

  parent reply	other threads:[~2016-02-02 17:49 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-02  2:44 [U-Boot] [PATCH 00/16] EFI payload / application support v3 Alexander Graf
2016-02-02  2:44 ` [U-Boot] [PATCH 01/16] disk/part.c: Expose list of available block drivers Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 02/16] include/efi_api.h: Add more detailed API definitions Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 03/16] efi_loader: Add PE image loader Alexander Graf
2016-02-02 12:54   ` Leif Lindholm
2016-02-02 17:49   ` Mark Rutland [this message]
2016-02-26  1:25     ` Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 04/16] efi_loader: Add boot time services Alexander Graf
2016-02-02 14:47   ` Leif Lindholm
2016-02-26  1:00     ` Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 05/16] efi_loader: Add console interface Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 06/16] efi_loader: Add runtime services Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 07/16] efi_loader: Add disk interfaces Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 08/16] efi_loader: Add "bootefi" command Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 09/16] efi_loader: Implement memory allocation and map Alexander Graf
2016-02-02 17:35   ` Leif Lindholm
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 10/16] arm64: Allow exceptions to return Alexander Graf
2016-02-02  2:45 ` [U-Boot] [PATCH 11/16] arm64: Allow EFI payload code to take exceptions Alexander Graf
2016-02-02  2:45 ` [U-Boot] [PATCH 12/16] efi_loader: Add DCACHE_OFF support for arm64 Alexander Graf
2016-02-02 15:55   ` Mark Rutland
2016-02-02 16:28     ` Tom Rini
2016-02-02 16:58       ` Alexander Graf
2016-02-02  2:45 ` [U-Boot] [PATCH 13/16] efi_loader: hook up in build environment Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 14/16] efi_loader: Add distro boot script for removable media Alexander Graf
2016-02-02 17:52   ` Leif Lindholm
2016-02-26  1:29     ` Alexander Graf
2016-02-03 10:36   ` Leif Lindholm
2016-02-03 15:53     ` Alexander Graf
2016-02-04  4:11       ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 15/16] efi_loader: Add README section in README.efi Alexander Graf
2016-02-03  3:31   ` Simon Glass
2016-02-02  2:45 ` [U-Boot] [PATCH 16/16] efi_loader: Add MAINTAINERS entry Alexander Graf
2016-02-03  3:31   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160202174947.GA29778@leverpostej \
    --to=mark.rutland@arm.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.