mirror of
https://github.com/ipxe/ipxe
synced 2026-01-01 17:34:42 +03:00
[efi] Avoid dropping below TPL as at entry to iPXE
iPXE will currently drop to TPL_APPLICATION whenever the current system time is obtained via currticks(), since the system time mechanism relies on a timer that can fire only when the TPL is below TPL_CALLBACK. This can cause unexpected behaviour if the system time is obtained in the middle of an API call into iPXE by external code. For example, MnpDxe sets up a 10ms periodic timer running at TPL_CALLBACK to poll the underling EFI_SIMPLE_NETWORK_PROTOCOL device for received packets. If the resulting poll within iPXE happens to hit a code path that requires obtaining the current system time (e.g. due to reception of an STP packet, which affects iPXE's blocked link timer), then iPXE will end up temporarily dropping to TPL_APPLICATION. This can potentially result in retriggering the MnpDxe periodic timer, causing code to be unexpectedly re-entered. Fix by recording the external TPL at any entry point into iPXE and dropping only as far as this external TPL, rather than dropping unconditionally to TPL_APPLICATION. The side effect of this change is that iPXE's view of the current system time will be frozen for the duration of any API calls made into iPXE by external code at TPL_CALLBACK or above. Since any such external code is already responsible for allowing execution at TPL_APPLICATION to occur, then this should not cause a problem in practice. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -47,6 +47,9 @@ EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
|
||||
*/
|
||||
EFI_SYSTEM_TABLE * _C2 ( PLATFORM, _systab );
|
||||
|
||||
/** External task priority level */
|
||||
EFI_TPL efi_external_tpl = TPL_APPLICATION;
|
||||
|
||||
/** EFI shutdown is in progress */
|
||||
int efi_shutdown_in_progress;
|
||||
|
||||
@@ -361,3 +364,34 @@ __attribute__ (( noreturn )) void __stack_chk_fail ( void ) {
|
||||
while ( 1 ) {}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Raise task priority level to TPL_CALLBACK
|
||||
*
|
||||
* @v tpl Saved TPL
|
||||
*/
|
||||
void efi_raise_tpl ( struct efi_saved_tpl *tpl ) {
|
||||
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
||||
|
||||
/* Record current external TPL */
|
||||
tpl->previous = efi_external_tpl;
|
||||
|
||||
/* Raise TPL and record previous TPL as new external TPL */
|
||||
tpl->current = bs->RaiseTPL ( TPL_CALLBACK );
|
||||
efi_external_tpl = tpl->current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore task priority level
|
||||
*
|
||||
* @v tpl Saved TPL
|
||||
*/
|
||||
void efi_restore_tpl ( struct efi_saved_tpl *tpl ) {
|
||||
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
|
||||
|
||||
/* Restore external TPL */
|
||||
efi_external_tpl = tpl->previous;
|
||||
|
||||
/* Restore TPL */
|
||||
bs->RestoreTPL ( tpl->current );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user