]> xenbits.xensource.com Git - ovmf.git/commitdiff
OvmfPkg: Relax assertion that interrupts do not occur at TPL_HIGH_LEVEL
authorMichael Brown <mcb30@ipxe.org>
Tue, 9 May 2023 12:09:33 +0000 (12:09 +0000)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 9 May 2023 22:09:50 +0000 (22:09 +0000)
At TPL_HIGH_LEVEL, CPU interrupts are disabled (as per the UEFI
specification) and so we should never encounter a situation in which
an interrupt occurs at TPL_HIGH_LEVEL.  The specification also
restricts usage of TPL_HIGH_LEVEL to the firmware itself.

However, nothing actually prevents a UEFI application from calling
gBS->RaiseTPL(TPL_HIGH_LEVEL) and then violating the invariant by
enabling interrupts via the STI or equivalent instruction.  Some
versions of the Microsoft Windows bootloader are known to do this.

NestedInterruptTplLib maintains the invariant that interrupts are
disabled at TPL_HIGH_LEVEL (even when performing the dark art of
deliberately manipulating the stack so that IRET will return with
interrupts still disabled), but does not itself rely on external code
maintaining this invariant.

Relax the assertion that the interrupted TPL is below TPL_HIGH_LEVEL
to an error message, to allow UEFI applications such as these versions
of the Microsoft Windows bootloader to continue to function.

Debugged-by: Gerd Hoffmann <kraxel@redhat.com>
Debugged-by: Laszlo Ersek <lersek@redhat.com>
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=2189136
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
OvmfPkg/Library/NestedInterruptTplLib/Tpl.c

index e921a09c559948bccd285f4115389bf93c45e38c..d56c12a44529055bcc97f970e48a7f169270c866 100644 (file)
@@ -34,12 +34,27 @@ NestedInterruptRaiseTPL (
 \r
   //\r
   // Raise TPL and assert that we were called from within an interrupt\r
-  // handler (i.e. with TPL below TPL_HIGH_LEVEL but with interrupts\r
-  // disabled).\r
+  // handler (i.e. with interrupts already disabled before raising the\r
+  // TPL).\r
   //\r
   ASSERT (GetInterruptState () == FALSE);\r
   InterruptedTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
-  ASSERT (InterruptedTPL < TPL_HIGH_LEVEL);\r
+\r
+  //\r
+  // At TPL_HIGH_LEVEL, CPU interrupts are disabled (as per the UEFI\r
+  // specification) and so we should never encounter a situation in\r
+  // which InterruptedTPL==TPL_HIGH_LEVEL.  The specification also\r
+  // restricts usage of TPL_HIGH_LEVEL to the firmware itself.\r
+  //\r
+  // However, nothing actually prevents a UEFI application from\r
+  // invalidly calling gBS->RaiseTPL(TPL_HIGH_LEVEL) and then\r
+  // violating the invariant by enabling interrupts via the STI or\r
+  // equivalent instruction.  Some versions of the Microsoft Windows\r
+  // bootloader are known to do this.\r
+  //\r
+  if (InterruptedTPL >= TPL_HIGH_LEVEL) {\r
+    DEBUG ((DEBUG_ERROR, "ERROR: Interrupts enabled at TPL_HIGH_LEVEL!\n"));\r
+  }\r
 \r
   return InterruptedTPL;\r
 }\r