From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=axdBaxTW; spf=pass (domain: linaro.org, ip: 209.85.210.193, mailfrom: ard.biesheuvel@linaro.org) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by groups.io with SMTP; Thu, 11 Apr 2019 11:58:21 -0700 Received: by mail-pf1-f193.google.com with SMTP id t21so3899693pfh.2 for ; Thu, 11 Apr 2019 11:58:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=pYksf8Dpe89sQsCBjBQOokwB03kG0hmOr+WiggbY5XM=; b=axdBaxTWWTFG8sQU5iJSDz1V1vNloqw7A7vqkJ0wkSM791kHUv0dVHdw29RWQJFKH9 iUjRJFMzegZq3+so6wHtgb6VBpdN8fWpjagX92HNuZUJmu8+5Ej1422SmhrQ9NFomNF8 YtInw56uEJvMzIX/QQ41ZVRVqelJgNKYykyT39fKuu2vKikjkY3s8sybw4pB/omBdyUE RekjVQlGE8tKqcxgQQcqfidg+WKjdOye8xiPqqMGAQ12CZwx8nfkFoYkAOOMM3sQPfKi dOMD9bpgJEeALz+FQAzQeX2e+ZGjS2U7XKQYrJEuYew1WjASS82WKaFDWhtarTsUonpk hEFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pYksf8Dpe89sQsCBjBQOokwB03kG0hmOr+WiggbY5XM=; b=mbR5QAC/zh55Scv5nihLCP1sxgQyiI7Vj+cRtqpQfU7VhNs1Fu5BGvPK8/r/VNdwCE HNM3hQWh8bJ8Vfhh3hRQfNrr/KUZUVZ6qyl/1PnSJndoTWKeEF8OAeNtK98t/Yxe8nZ7 t4pnYVx+LEq+5x0vO8/qdACuSNYBeMIWbU6C03c4URSKfWoMov1EFHfWwTWZkyrVF5H4 MS/hIghdTaz026MZCxmBN97D14lZ2JksLldV/1AmmwQyqOllyTADAF0mQeAmh2RBBMKU XhCtrgX1switYyhA9NwMFVSTHbrn8BvqyR6H6aFOhCHTFM4icG8m5Ia9Qpp28ksUGbD3 NeaQ== X-Gm-Message-State: APjAAAXnbXIEdans+5s9QL6DRYrbHUF8sOisp273U9DEd8sxL9MMjaS2 mtBRwI7jU7g/kfX+DVQ3zfDIIG9Jiboh3exe X-Google-Smtp-Source: APXvYqxZEaV5a/mR2iP6ESrUeAFn8XHbmu53kADqSDb6XnLqi+70qx4/3gDlmeu81BM6e79Gxu5gAg== X-Received: by 2002:a63:4620:: with SMTP id t32mr48118118pga.363.1555009100672; Thu, 11 Apr 2019 11:58:20 -0700 (PDT) Return-Path: Received: from localhost.localdomain (50-205-23-12-static.hfc.comcastbusiness.net. [50.205.23.12]) by smtp.gmail.com with ESMTPSA id w3sm82712861pfn.179.2019.04.11.11.58.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:58:19 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Vincent Zimmer , Brian Richardson , Michael D Kinney , Andrew Fish , Leif Lindholm , Star Zeng , Eric Dong , Ruiyu Ni , Liming Gao , Jaben Carsey , Steven Shi Subject: [PATCH v5 0/7] MdeModulePkg: add support for dispatching foreign arch PE/COFF images Date: Thu, 11 Apr 2019 11:58:06 -0700 Message-Id: <20190411185813.2084-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 Add the basic plumbing to DXE core, the PCI bus driver and the boot manager to allow PE/COFF images to be dispatched that target an architecture that is not native for the platform, but which is supported by one of potentially several available emulators. One implementation of such an emulator can be found here: https://github.com/ardbiesheuvel/X86EmulatorPkg/tree/upstream-v4 This also allows us to get rid of the special treatment of EBC images in core code. Instead, the EbcDxe driver is augmented with an implementation of the EDK2 PE/COFF image emulator protocol so that internal knowledge of how EBC is implemented (I-cache flushing, thunks) is removed from the DXE core. Changes since v4: - Fix an issue in the protocol notify handler pointed out by Mike Kinney (#2) Changes since v3: - Simplify the handling of option ROMs and Driver#### images, by simply deferring to the LoadImage() boot service to decide whether an image can be supported or not - this removes some redundant checks from the BDS layer and the PCI bus driver. - Move the machine type supported by the emulator into the protocol struct, so we can optimize away calls into the emulator for each image loaded. Instead, the LoadImage() code will only invoke the IsSupported() method for images that are known to have a matching machine type. Note that I have considered, but ultimately dismissed the suggestion to register and unregister emulators via a new protocol. The main issue is that registering and unregistering structs containing sets of function pointers is awfully similar to managing a protocol database, and we already have the code to do that in EDK2. So instead, I have removed all the code that iterates over a handle buffer of emu protocols and invokes each one to see if it will support the image. Instead, this is all done by CoreLoadImage(). Changes since v2: - incorporate feedback from Andrew Fish (delivered in person): * pass a device path into the IsImageSupported() protocol method so that an implementation can blacklist or whitelist certain devices, or implement other policies that depend on the device where the driver originated * allow the emulator to supersede the native loading of the image - this permits things like X86 on X86 emulators for security sandboxing or debug Changes since v1: - subsume the EBC handling into the EDK2 emulator protocol and abstract away from EBC specifics in core code. - allow multiple emulator implementations to co-exist - incorporate Star's review feedback Cc: Vincent Zimmer Cc: Brian Richardson Cc: Michael D Kinney Cc: Andrew Fish Cc: Leif Lindholm Cc: Star Zeng Cc: Eric Dong Cc: Ruiyu Ni Cc: Liming Gao Cc: Jaben Carsey Cc: Steven Shi Ard Biesheuvel (7): MdeModulePkg: introduce PE/COFF image emulator protocol MdeModulePkg/DxeCore: invoke the emulator protocol for foreign images MdeModulePkg/PciBusDxe: dispatch option ROMs for foreign architectures MdeModulePkg/UefiBootManagerLib: allow foreign Driver#### images MdeModulePkg/EbcDxe: implement the PE/COFF emulator protocol MdePkg/UefiBaseType.h: treat EBC as a non-native machine type MdeModulePkg/DxeCore: remove explicit EBC handling .../Bus/Pci/PciBusDxe/PciOptionRomSupport.c | 7 - MdeModulePkg/Core/Dxe/DxeMain.h | 6 +- MdeModulePkg/Core/Dxe/DxeMain.inf | 2 +- MdeModulePkg/Core/Dxe/Image/Image.c | 209 +++++++++++++----- .../Include/Protocol/PeCoffImageEmulator.h | 107 +++++++++ .../Library/UefiBootManagerLib/BmLoadOption.c | 6 +- MdeModulePkg/MdeModulePkg.dec | 4 + MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf | 3 + MdeModulePkg/Universal/EbcDxe/EbcDxe.inf | 3 + MdeModulePkg/Universal/EbcDxe/EbcInt.c | 123 +++++++++++ MdeModulePkg/Universal/EbcDxe/EbcInt.h | 3 + MdePkg/Include/Uefi/UefiBaseType.h | 6 +- 12 files changed, 407 insertions(+), 72 deletions(-) create mode 100644 MdeModulePkg/Include/Protocol/PeCoffImageEmulator.h -- 2.17.1