public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Jiewen Yao <jiewen.yao@intel.com>
Subject: [edk2-devel] [PATCH 13/37] OvmfPkg/IncompatiblePciDeviceSupportDxe: ignore CSM presence
Date: Sat, 11 Nov 2023 00:57:56 +0100	[thread overview]
Message-ID: <20231110235820.644381-14-lersek@redhat.com> (raw)
In-Reply-To: <20231110235820.644381-1-lersek@redhat.com>

The UEFI protocol database cannot contain gEfiLegacyBiosProtocolGuid any
longer, after excluding LegacyBiosDxe from the OVMF platforms. Therefore,
instruct PciBusDxe from IncompatiblePciDeviceSupportDxe to allocate 64-bit
BARs above 4 GB regardless of a CSM.

Regression test: in commit 855743f71774 ("OvmfPkg: prevent 64-bit MMIO BAR
degradation if there is no CSM", 2016-05-25), where we introduced
IncompatiblePciDeviceSupportDxe, we said, "By default, the PCI Bus driver
considers an option ROM reason enough for allocating the 64-bit MMIO BARs
in 32-bit address space". Therefore it suffices to verify the 64-bit BARs
of a device for which QEMU provides an option ROM. The simplest case is
the virtio-net-pci device. And indeed, with this patch applied, the log
contains:

> PciBus: Discovered PCI @ [04|00|00]  [VID = 0x1AF4, DID = 0x1041]
>    BAR[1]: Type =  Mem32; Alignment = 0xFFF;    Length = 0x1000;        Offset = 0x14
>    BAR[4]: Type = PMem64; Alignment = 0x3FFF;   Length = 0x4000;        Offset = 0x20

This portion shows that Bus|Device|Function 04|00|00 is a (modern)
virito-net-pci device [VID = 0x1AF4, DID = 0x1041].

> PciBus: Resource Map for Bridge [00|01|03]
> Type =  Mem32; Base = 0x81200000;       Length = 0x200000;      Alignment = 0x1FFFFF
>    Base = Padding;      Length = 0x200000;      Alignment = 0x1FFFFF
>    Base = 0x81200000;   Length = 0x1000;        Alignment = 0xFFF;      Owner = PCI [04|00|00:14]
> Type =  Mem32; Base = 0x81A43000;       Length = 0x1000;        Alignment = 0xFFF
> Type = PMem64; Base = 0x800200000;      Length = 0x100000;      Alignment = 0xFFFFF
>    Base = 0x800200000;  Length = 0x4000;        Alignment = 0x3FFF;     Owner = PCI [04|00|00:20]

This quote shows that 04|00|00 has a BAR at 0x8_0020_0000.

(It also shows that the device is behind a bridge (PCIe root port) whose
own BDF is 00|01|03.)

> [Security] 3rd party image[7CEEB418] can be loaded after EndOfDxe: PciRoot(0x0)/Pci(0x1,0x3)/Pci(0x0,0x0)/Offset(0x10E00,0x273FF).
> None of Tcg2Protocol/CcMeasurementProtocol is installed.
> InstallProtocolInterface: [EfiLoadedImageProtocol] 7D2E5140
> Loading driver at 0x0007CA9F000 EntryPoint=0x0007CAA5447 1af41000.efi
> InstallProtocolInterface: [EfiLoadedImageDevicePathProtocol] 7D5B2198

And this part finally shows that the iPXE option ROM for the device
(1af41000.efi) was detected and is loaded. (Same PCIe root port, and PCIe
root ports can only host a single device.)

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4588
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf |   5 +-
 OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c   | 141 +-------------------
 2 files changed, 6 insertions(+), 140 deletions(-)

diff --git a/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf b/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
index ad38128fcbf9..b92662d0bb36 100644
--- a/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
+++ b/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.inf
@@ -1,7 +1,7 @@
 ## @file
 # A simple DXE_DRIVER that causes the PCI Bus UEFI_DRIVER to allocate 64-bit
-# MMIO BARs above 4 GB, regardless of option ROM availability (as long as a CSM
-# is not present), conserving 32-bit MMIO aperture for 32-bit BARs.
+# MMIO BARs above 4 GB, regardless of option ROM availability, conserving 32-bit
+# MMIO aperture for 32-bit BARs.
 #
 # Copyright (C) 2016, Red Hat, Inc.
 #
@@ -33,7 +33,6 @@ [LibraryClasses]
 
 [Protocols]
   gEfiIncompatiblePciDeviceSupportProtocolGuid ## SOMETIMES_PRODUCES
-  gEfiLegacyBiosProtocolGuid                   ## NOTIFY
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size                ## CONSUMES
diff --git a/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c b/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c
index 3092a174bc51..434cdca84b23 100644
--- a/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c
+++ b/OvmfPkg/IncompatiblePciDeviceSupportDxe/IncompatiblePciDeviceSupport.c
@@ -1,7 +1,7 @@
 /** @file
   A simple DXE_DRIVER that causes the PCI Bus UEFI_DRIVER to allocate 64-bit
-  MMIO BARs above 4 GB, regardless of option ROM availability (as long as a CSM
-  is not present), conserving 32-bit MMIO aperture for 32-bit BARs.
+  MMIO BARs above 4 GB, regardless of option ROM availability, conserving 32-bit
+  MMIO aperture for 32-bit BARs.
 
   Copyright (C) 2016, Red Hat, Inc.
   Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
@@ -21,12 +21,6 @@
 #include <Library/CcProbeLib.h>
 
 #include <Protocol/IncompatiblePciDeviceSupport.h>
-#include <Protocol/LegacyBios.h>
-
-//
-// The Legacy BIOS protocol has been located.
-//
-STATIC BOOLEAN  mLegacyBiosInstalled;
 
 //
 // The protocol interface this driver produces.
@@ -111,50 +105,6 @@ STATIC CONST EFI_ACPI_END_TAG_DESCRIPTOR  mEndDesc = {
   0                                                // Checksum: to be ignored
 };
 
-//
-// The CheckDevice() member function has been called.
-//
-STATIC BOOLEAN  mCheckDeviceCalled;
-
-/**
-  Notification callback for Legacy BIOS protocol installation.
-
-  @param[in] Event    Event whose notification function is being invoked.
-
-  @param[in] Context  The pointer to the notification function's context, which
-                      is implementation-dependent.
-**/
-STATIC
-VOID
-EFIAPI
-LegacyBiosInstalled (
-  IN EFI_EVENT  Event,
-  IN VOID       *Context
-  )
-{
-  EFI_STATUS                Status;
-  EFI_LEGACY_BIOS_PROTOCOL  *LegacyBios;
-
-  ASSERT (!mCheckDeviceCalled);
-
-  Status = gBS->LocateProtocol (
-                  &gEfiLegacyBiosProtocolGuid,
-                  NULL /* Registration */,
-                  (VOID **)&LegacyBios
-                  );
-  if (EFI_ERROR (Status)) {
-    return;
-  }
-
-  mLegacyBiosInstalled = TRUE;
-
-  //
-  // Close the event and deregister this callback.
-  //
-  Status = gBS->CloseEvent (Event);
-  ASSERT_EFI_ERROR (Status);
-}
-
 /**
   Returns a list of ACPI resource descriptors that detail the special resource
   configuration requirements for an incompatible PCI device.
@@ -228,7 +178,6 @@ CheckDevice (
   OUT VOID                                          **Configuration
   )
 {
-  mCheckDeviceCalled = TRUE;
   UINTN  Length;
   UINT8  *Ptr;
 
@@ -243,17 +192,8 @@ CheckDevice (
   // The concern captured in the PCI Bus UEFI_DRIVER is that a legacy BIOS boot
   // (via a CSM) could dispatch a legacy option ROM on the device, which might
   // have trouble with MMIO BARs that have been allocated outside of the 32-bit
-  // address space. But, if we don't support legacy option ROMs at all, then
-  // this problem cannot arise.
-  //
-  if (mLegacyBiosInstalled) {
-    //
-    // Don't interfere with resource degradation.
-    //
-    *Configuration = NULL;
-    return EFI_SUCCESS;
-  }
-
+  // address space. But, we don't support legacy option ROMs at all, thus this
+  // problem cannot arise.
   //
   // This member function is mis-specified actually: it is supposed to allocate
   // memory, but as specified, it could not return an error status. Thankfully,
@@ -317,8 +257,6 @@ DriverInitialize (
   )
 {
   EFI_STATUS  Status;
-  EFI_EVENT   Event;
-  VOID        *Registration;
 
   //
   // If there is no 64-bit PCI MMIO aperture, then 64-bit MMIO BARs have to be
@@ -328,63 +266,6 @@ DriverInitialize (
     return EFI_UNSUPPORTED;
   }
 
-  //
-  // Otherwise, create a protocol notify to see if a CSM is present. (With the
-  // CSM absent, the PCI Bus driver won't have to worry about allocating 64-bit
-  // MMIO BARs in the 32-bit MMIO aperture, for the sake of a legacy BIOS.)
-  //
-  // If the Legacy BIOS Protocol is present at the time of this driver starting
-  // up, we can mark immediately that the PCI Bus driver should perform the
-  // usual 64-bit MMIO BAR degradation.
-  //
-  // Otherwise, if the Legacy BIOS Protocol is absent at startup, it may be
-  // installed later. However, if it doesn't show up until the first
-  // EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL.CheckDevice() call from the
-  // PCI Bus driver, then it never will:
-  //
-  // 1. The following drivers are dispatched in some unspecified order:
-  //    - PCI Host Bridge DXE_DRIVER,
-  //    - PCI Bus UEFI_DRIVER,
-  //    - this DXE_DRIVER,
-  //    - Legacy BIOS DXE_DRIVER.
-  //
-  // 2. The DXE_CORE enters BDS.
-  //
-  // 3. The platform BDS connects the PCI Root Bridge IO instances (produced by
-  //    the PCI Host Bridge DXE_DRIVER).
-  //
-  // 4. The PCI Bus UEFI_DRIVER enumerates resources and calls into this
-  //    DXE_DRIVER (CheckDevice()).
-  //
-  // 5. This driver remembers if EFI_LEGACY_BIOS_PROTOCOL has been installed
-  //    sometime during step 1 (produced by the Legacy BIOS DXE_DRIVER).
-  //
-  // For breaking this order, the Legacy BIOS DXE_DRIVER would have to install
-  // its protocol after the firmware enters BDS, which cannot happen.
-  //
-  Status = gBS->CreateEvent (
-                  EVT_NOTIFY_SIGNAL,
-                  TPL_CALLBACK,
-                  LegacyBiosInstalled,
-                  NULL /* Context */,
-                  &Event
-                  );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
-  Status = gBS->RegisterProtocolNotify (
-                  &gEfiLegacyBiosProtocolGuid,
-                  Event,
-                  &Registration
-                  );
-  if (EFI_ERROR (Status)) {
-    goto CloseEvent;
-  }
-
-  Status = gBS->SignalEvent (Event);
-  ASSERT_EFI_ERROR (Status);
-
   mIncompatiblePciDeviceSupport.CheckDevice = CheckDevice;
   Status                                    = gBS->InstallMultipleProtocolInterfaces (
                                                      &ImageHandle,
@@ -392,19 +273,5 @@ DriverInitialize (
                                                      &mIncompatiblePciDeviceSupport,
                                                      NULL
                                                      );
-  if (EFI_ERROR (Status)) {
-    goto CloseEvent;
-  }
-
-  return EFI_SUCCESS;
-
-CloseEvent:
-  if (!mLegacyBiosInstalled) {
-    EFI_STATUS  CloseStatus;
-
-    CloseStatus = gBS->CloseEvent (Event);
-    ASSERT_EFI_ERROR (CloseStatus);
-  }
-
   return Status;
 }



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111084): https://edk2.groups.io/g/devel/message/111084
Mute This Topic: https://groups.io/mt/102518651/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2023-11-10 23:59 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 23:57 [edk2-devel] [PATCH 00/37] OvmfPkg: remove the CSM (after edk2-stable202311) Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 01/37] OvmfPkg: cripple CSM_ENABLE macro Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 02/37] OvmfPkg: remove PcdCsmEnable Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 03/37] OvmfPkg: unplug LegacyBootManagerLib from BdsDxe and UiApp Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 04/37] OvmfPkg: remove LegacyBootManagerLib Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 05/37] OvmfPkg: unplug LegacyBootMaintUiLib from UiApp Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 06/37] OvmfPkg: remove LegacyBootMaintUiLib Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 07/37] OvmfPkg: remove gEfiLegacyDevOrderVariableGuid Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 08/37] OvmfPkg: exclude the CSM-based VideoDxe driver Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 09/37] OvmfPkg: remove Csm/BiosThunk/VideoDxe Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 10/37] OvmfPkg: remove gEfiVgaMiniPortProtocolGuid Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 11/37] OvmfPkg: remove Bios Video PCDs Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 12/37] OvmfPkg: exclude LegacyBiosDxe Laszlo Ersek
2023-11-10 23:57 ` Laszlo Ersek [this message]
2023-11-10 23:57 ` [edk2-devel] [PATCH 14/37] Revert "OvmfPkg: don't assign PCI BARs above 4GiB when CSM enabled" Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 15/37] OvmfPkg: remove LegacyBiosDxe Laszlo Ersek
2023-11-10 23:57 ` [edk2-devel] [PATCH 16/37] OvmfPkg: exclude NullMemoryTestDxe driver Laszlo Ersek
2024-04-24 11:02   ` Corvin Köhne
2023-11-10 23:58 ` [edk2-devel] [PATCH 17/37] OvmfPkg: remove gEfiIsaIoProtocolGuid Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 18/37] OvmfPkg: remove gEfiIsaAcpiProtocolGuid Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 19/37] OvmfPkg: remove gEfiLegacyBiosGuid Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 20/37] OvmfPkg: remove LegacyBiosDxe PCDs Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 21/37] OvmfPkg: unplug CsmSupportLib from BdsDxe Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 22/37] OvmfPkg: remove CsmSupportLib Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 23/37] OvmfPkg: remove gEfiFirmwareVolumeProtocolGuid Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 24/37] OvmfPkg: remove gEfiLegacyBiosPlatformProtocolGuid Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 25/37] OvmfPkg: remove gEfiLegacyBiosProtocolGuid Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 26/37] OvmfPkg: remove gEfiLegacyInterruptProtocolGuid Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 27/37] OvmfPkg: remove <FrameworkDxe.h> Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 28/37] OvmfPkg: exclude Csm16.inf / Csm16.bin Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 29/37] OvmfPkg: remove Rule.Common.USER_DEFINED.CSM from all FDF files Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 30/37] OvmfPkg: remove Csm16 Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 31/37] OvmfPkg: exclude 8254TimerDxe Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 32/37] OvmfPkg: remove 8254TimerDxe Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 33/37] OvmfPkg: exclude 8259InterruptControllerDxe Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 34/37] OvmfPkg: remove 8259InterruptControllerDxe Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 35/37] OvmfPkg: remove gEfiLegacy8259ProtocolGuid Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 36/37] OvmfPkg: remove Pcd8259LegacyModeEdgeLevel and Pcd8259LegacyModeMask Laszlo Ersek
2023-11-10 23:58 ` [edk2-devel] [PATCH 37/37] OvmfPkg: remove CSM_ENABLE build macro Laszlo Ersek
2023-11-11  2:12 ` [edk2-devel] [PATCH 00/37] OvmfPkg: remove the CSM (after edk2-stable202311) Yao, Jiewen
2023-11-11 10:54   ` Ard Biesheuvel
2023-11-13  7:52     ` Corvin Köhne
2023-11-13 10:44 ` Gerd Hoffmann
2023-12-07 18:10 ` Laszlo Ersek

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-list 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=20231110235820.644381-14-lersek@redhat.com \
    --to=devel@edk2.groups.io \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox