opengnsys_ipxe/src/include
Michael Brown 562c74e1ea [efi] Run ExitBootServices shutdown hook at TPL_NOTIFY
On some systems (observed with the Thunderbolt ports on a ThinkPad X1
Extreme Gen3 and a ThinkPad P53), if the IOMMU is enabled then the
system firmware will install an ExitBootServices notification event
that disables bus mastering on the Thunderbolt xHCI controller and all
PCI bridges, and destroys any extant IOMMU mappings.  This leaves the
xHCI controller unable to perform any DMA operations.

As described in commit 236299b ("[xhci] Avoid DMA during shutdown if
firmware has disabled bus mastering"), any subsequent DMA operation
attempted by the xHCI controller will end up completing after the
operating system kernel has reenabled bus mastering, resulting in a
DMA operation to an area of memory that the hardware is no longer
permitted to access and, on Windows with the Driver Verifier enabled,
a STOP 0xE6 (DRIVER_VERIFIER_DMA_VIOLATION).

That commit avoids triggering any DMA attempts during the shutdown of
the xHCI controller itself.  However, this is not a complete solution
since any attached and opened USB device (e.g. a USB NIC) may
asynchronously trigger DMA attempts that happen to occur after bus
mastering has been disabled but before we reset the xHCI controller.

Avoid this problem by installing our own ExitBootServices notification
event at TPL_NOTIFY, thereby causing it to be invoked before the
firmware's own ExitBootServices notification event that disables bus
mastering.

This unsurprisingly causes the shutdown hook itself to be invoked at
TPL_NOTIFY, which causes a fatal error when later code attempts to
raise the TPL to TPL_CALLBACK (which is a lower TPL).  Work around
this problem by redefining the "internal" iPXE TPL to be variable, and
set this internal TPL to TPL_NOTIFY when the shutdown hook is invoked.

Avoid calling into an underlying SNP protocol instance from within our
shutdown hook at TPL_NOTIFY, since the underlying SNP driver may
attempt to raise the TPL to TPL_CALLBACK (which would cause a fatal
error).  Failing to shut down the underlying SNP device is safe to do
since the underlying device must, in any case, have installed its own
ExitBootServices hook if any shutdown actions are required.

Reported-by: Andreas Hammarskjöld <junior@2PintSoftware.com>
Tested-by: Andreas Hammarskjöld <junior@2PintSoftware.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-11-23 15:55:01 +00:00
..
hci [linux] Use host glibc system call wrappers 2021-02-28 23:28:23 +00:00
ipxe [efi] Run ExitBootServices shutdown hook at TPL_NOTIFY 2021-11-23 15:55:01 +00:00
readline [readline] Add an optional timeout to readline_history() 2021-04-23 12:27:57 +01:00
sys [legal] Relicense files under GPL2_OR_LATER_OR_UBDL 2015-03-02 14:17:31 +00:00
usr [image] Add "imgextract" command for extracting archive images 2021-05-08 15:34:19 +01:00
valgrind [malloc] Move valgrind headers out of arch/x86 2015-03-03 14:25:51 +00:00
xen [xen] Import selected public headers 2014-07-29 15:20:49 +01:00
alloca.h
assert.h [libc] Allow assertions to be globally enabled or disabled 2016-07-05 13:28:51 +01:00
byteswap.h [libc] Rewrite byte-swapping code 2015-03-02 16:35:37 +00:00
coff.h
compiler.h [build] Avoid confusing sparse in single-argument DBG() macros 2017-03-22 08:25:04 +02:00
cpu.h
ctype.h [libc] Rewrite unrelicensable portions of ctype.h 2015-03-02 16:35:37 +00:00
curses.h [libc] Add stdbool.h standard header 2017-04-10 16:12:53 +01:00
elf.h [elf] Rewrite ELF header 2015-03-02 19:42:48 +00:00
endian.h [libc] Allow for externally-defined LITTLE_ENDIAN and BIG_ENDIAN constants 2021-07-15 14:16:17 +01:00
errno.h [build] Use .balign directive instead of .align 2021-02-12 23:22:54 +00:00
etherboot.h [console] Move putchar() and getchar() declarations to stdio.h 2012-03-26 14:43:52 +01:00
fs.h
getopt.h [legal] Relicense files under GPL2_OR_LATER_OR_UBDL 2015-03-02 14:17:31 +00:00
i82365.h [legal] Add FILE_LICENCE macro to some GPL-v2 files 2010-12-03 23:23:35 +00:00
libgen.h [legal] Relicense files under GPL2_OR_LATER_OR_UBDL 2015-03-02 14:17:31 +00:00
mii.h [realtek] Work around hardware bug on RTL8211B 2021-06-24 12:36:46 +01:00
nic.h [legacy] Fix building with GCC 6 2016-05-04 16:01:33 +01:00
old_tcp.h
pc_kbd.h
pcmcia-opts.h
pcmcia.h
stdarg.h [legal] Relicense files under GPL2_OR_LATER_OR_UBDL 2015-03-02 14:17:31 +00:00
stdbool.h [libc] Add stdbool.h standard header 2017-04-10 16:12:53 +01:00
stddef.h [libc] Allow container_of() to be used on volatile pointers 2016-03-18 08:18:31 +00:00
stdint.h [legal] Relicense files under GPL2_OR_LATER_OR_UBDL 2015-03-02 16:35:29 +00:00
stdio.h [libc] Match standard prototype for putchar() 2021-06-07 13:26:01 +01:00
stdlib.h [legal] Relicense files under GPL2_OR_LATER_OR_UBDL 2015-03-02 16:35:29 +00:00
string.h [libc] Provide an unoptimised generic_memcpy_reverse() 2020-07-07 13:13:28 +01:00
strings.h [libc] Add strncasecmp() 2021-05-18 11:45:24 +01:00
sys_info.h
syslog.h [legal] Relicense files under GPL2_OR_LATER_OR_UBDL 2015-03-02 14:17:31 +00:00
time.h [time] Allow system clock to be adjusted at runtime 2016-06-13 15:29:05 +01:00
unistd.h [time] Allow timer to be selected at runtime 2017-01-26 08:17:37 +00:00
wchar.h [legal] Relicense files under GPL2_OR_LATER_OR_UBDL 2015-03-02 16:35:29 +00:00