From cbff453fd00835fd3735fca28990a83630d66f70 Mon Sep 17 00:00:00 2001 From: He He4 Huang Date: Thu, 28 May 2020 06:53:26 +0800 Subject: [PATCH 1/3] [efi] Restore the TPL to the original one iPXE added a workaround to raise TPL to TPL_CALLBACK always, but it would cause UEFI firmware exit boot service callback with the same TPL level cannot be executed. Worse, some UEFI modules set a pointer at exit boot service callback and use later, then will encounter exception / hang for invalid pointer which is not set to a correct one since the exit boot service callback is not executed. The solution is to restore the TPL to the original one but not always set it to TPL_CALLBACK. --- src/interface/efi/efi_timer.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/interface/efi/efi_timer.c b/src/interface/efi/efi_timer.c index 8f40cb81a8..e5a6503353 100644 --- a/src/interface/efi/efi_timer.c +++ b/src/interface/efi/efi_timer.c @@ -124,11 +124,18 @@ static unsigned long efi_currticks ( void ) { * EFI's violation of this assumption by falling back to a * simple free-running monotonic counter during shutdown. */ + EFI_TPL Efi_OldTPL; + Efi_OldTPL=0; if ( efi_shutdown_in_progress ) { efi_jiffies++; } else { - bs->RestoreTPL ( TPL_APPLICATION ); - bs->RaiseTPL ( TPL_CALLBACK ); + Efi_OldTPL = bs->RaiseTPL( TPL_CALLBACK); + bs->RestoreTPL ( TPL_APPLICATION ); + bs->RaiseTPL ( TPL_CALLBACK ); + if ( Efi_OldTPL != 0 ) { + bs->RestoreTPL(Efi_OldTPL); + } + } return ( efi_jiffies * ( TICKS_PER_SEC / EFI_JIFFIES_PER_SEC ) ); From ddc0d6049bf44860fe18c14db5ea61d1dd0fb131 Mon Sep 17 00:00:00 2001 From: He He4 Huang Date: Thu, 28 May 2020 14:44:06 +0800 Subject: [PATCH 2/3] [efi] Adjust the Indentation --- src/interface/efi/efi_timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interface/efi/efi_timer.c b/src/interface/efi/efi_timer.c index e5a6503353..be7c378793 100644 --- a/src/interface/efi/efi_timer.c +++ b/src/interface/efi/efi_timer.c @@ -131,8 +131,8 @@ static unsigned long efi_currticks ( void ) { } else { Efi_OldTPL = bs->RaiseTPL( TPL_CALLBACK); bs->RestoreTPL ( TPL_APPLICATION ); - bs->RaiseTPL ( TPL_CALLBACK ); - if ( Efi_OldTPL != 0 ) { + bs->RaiseTPL ( TPL_CALLBACK ); + if ( Efi_OldTPL != 0 ) { bs->RestoreTPL(Efi_OldTPL); } From 1ac1a5067860842fe96f803f6c2e1038971b294c Mon Sep 17 00:00:00 2001 From: He He4 Huang Date: Thu, 28 May 2020 14:59:27 +0800 Subject: [PATCH 3/3] [efi] Adjust Indentation again --- src/interface/efi/efi_timer.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/interface/efi/efi_timer.c b/src/interface/efi/efi_timer.c index be7c378793..a7635682d6 100644 --- a/src/interface/efi/efi_timer.c +++ b/src/interface/efi/efi_timer.c @@ -129,13 +129,12 @@ static unsigned long efi_currticks ( void ) { if ( efi_shutdown_in_progress ) { efi_jiffies++; } else { - Efi_OldTPL = bs->RaiseTPL( TPL_CALLBACK); - bs->RestoreTPL ( TPL_APPLICATION ); - bs->RaiseTPL ( TPL_CALLBACK ); - if ( Efi_OldTPL != 0 ) { - bs->RestoreTPL(Efi_OldTPL); - } - + Efi_OldTPL = bs->RaiseTPL( TPL_CALLBACK); + bs->RestoreTPL ( TPL_APPLICATION ); + bs->RaiseTPL ( TPL_CALLBACK ); + if ( Efi_OldTPL != 0 ) { + bs->RestoreTPL(Efi_OldTPL); + } } return ( efi_jiffies * ( TICKS_PER_SEC / EFI_JIFFIES_PER_SEC ) );