From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from a7-11.smtp-out.eu-west-1.amazonses.com (a7-11.smtp-out.eu-west-1.amazonses.com [54.240.7.11]) by mx.groups.io with SMTP id smtpd.web10.9973.1670581228899934968 for ; Fri, 09 Dec 2022 02:20:29 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@ipxe.org header.s=cphpx6z2rfcgehlykjjh3gknqe3hsoe2 header.b=V6Qh+fT2; spf=pass (domain: eu-west-1.amazonses.com, ip: 54.240.7.11, mailfrom: 01020184f6668e77-e04c6ec0-66ec-4118-85a1-2da9c260bf95-000000@eu-west-1.amazonses.com) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=cphpx6z2rfcgehlykjjh3gknqe3hsoe2; d=ipxe.org; t=1670581227; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ygJX8p3cGyHjRkYyZ04adZzLyAcoZ9CLS1OgQ/4KDPA=; b=V6Qh+fT2AmNBMotp1g4/ajVgBdpetGdIfAIaWL0CjIxeBg6qP34PAclHDRd7uSYU PUKUd8b5HdcLpEqQvsFAKKBdkTIsBbN5qmayxXYcXfpWGLQXbIA/BNIsmO9t+txc484 UI20bDDccUnOnuNVIjDb8YCBAZJaYCd6c9MeOrDmF9lEswVU0cYhyYAXQi3hn9u2UmV GiY1gbBNQ4/kwGjN+AIi5pD2Jn2bLZsb3TXuwW1+qGVAL01CHF8WnJdXCtwiUz8MhJv AtHY4BiDbC4PsftZy1omBMwRLRqb3l9pMuoRE4PAr2YqHKaCtI6gN6fnxeKjQPlJLom E+XS8xKD6A== DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ihchhvubuqgjsxyuhssfvqohv7z3u4hn; d=amazonses.com; t=1670581227; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Feedback-ID; bh=ygJX8p3cGyHjRkYyZ04adZzLyAcoZ9CLS1OgQ/4KDPA=; b=pWJ81Wr1rnMdBxLPUqFUmQYE2m2ZG8m+ohg42m/QBc5hKQUFYgPzl4EN4mRyqSe7 jW+Bo1VZXrnpKH6antSayZGtJIFbwSuT0ZUXvYIbju5XcmMUX3E1QBzdLKJyaYNkzH4 GogEHhD8K0qMdNiB1q+E4NJar0u/ZvgkvP4IxJ3A= From: "Michael Brown" To: devel@edk2.groups.io Cc: Michael Brown , Laszlo Ersek , Paolo Bonzini Subject: [PATCH 3/3] OvmfPkg: Use NestedInterruptTplLib in nested interrupt handlers Date: Fri, 9 Dec 2022 10:20:27 +0000 Message-ID: <01020184f6668e77-e04c6ec0-66ec-4118-85a1-2da9c260bf95-000000@eu-west-1.amazonses.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, URIBL_DBL_BLOCKED_OPENDNS,URIBL_ZEN_BLOCKED_OPENDNS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on blyat.fensystems.co.uk Feedback-ID: 1.eu-west-1.fspj4M/5bzJ9NLRzJP0PaxRwxrpZqiDQJ1IF94CF2TA=:AmazonSES X-SES-Outgoing: 2022.12.09-54.240.7.11 Content-Transfer-Encoding: 8bit Prevent stack underrun in the event of a timer interrupt storm in LocalApicTimerDxe and 8254TimerDxe interrupt handlers by using the helper functions provided by NestedInterruptTplLib. This fixes the same problem as addressed in commit 239b50a86 ("OvmfPkg: End timer interrupt later to avoid stack overflow under load"), but does so without breaking nested timer interrupts. Cc: Laszlo Ersek Cc: Paolo Bonzini Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2815 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4162 Signed-off-by: Michael Brown --- OvmfPkg/8254TimerDxe/8254Timer.inf | 1 + OvmfPkg/8254TimerDxe/Timer.c | 9 ++++++--- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 + OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.c | 9 ++++++--- OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf | 1 + OvmfPkg/Microvm/MicrovmX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + 12 files changed, 22 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/8254TimerDxe/8254Timer.inf b/OvmfPkg/8254TimerDxe/8254Timer.inf index 8a07c8247e..8fbab896f0 100644 --- a/OvmfPkg/8254TimerDxe/8254Timer.inf +++ b/OvmfPkg/8254TimerDxe/8254Timer.inf @@ -24,6 +24,7 @@ UefiBootServicesTableLib BaseLib DebugLib + NestedInterruptTplLib UefiDriverEntryPoint IoLib diff --git a/OvmfPkg/8254TimerDxe/Timer.c b/OvmfPkg/8254TimerDxe/Timer.c index 7feaaaba2b..5382b01615 100644 --- a/OvmfPkg/8254TimerDxe/Timer.c +++ b/OvmfPkg/8254TimerDxe/Timer.c @@ -6,6 +6,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include + #include "Timer.h" // @@ -76,9 +78,10 @@ TimerInterruptHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ) { - EFI_TPL OriginalTPL; + STATIC NESTED_INTERRUPT_STATE NestedInterruptState; + EFI_TPL OriginalTPL; - OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL); + OriginalTPL = NestedInterruptRaiseTPL (); mLegacy8259->EndOfInterrupt (mLegacy8259, Efi8259Irq0); @@ -89,7 +92,7 @@ TimerInterruptHandler ( mTimerNotifyFunction (mTimerPeriod); } - gBS->RestoreTPL (OriginalTPL); + NestedInterruptRestoreTPL (OriginalTPL, SystemContext, &NestedInterruptState); } /** diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 8f7cae787e..3433725697 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -353,6 +353,7 @@ !endif PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + NestedInterruptTplLib|OvmfPkg/Library/NestedInterruptTplLib/NestedInterruptTplLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index ce277cb239..6d5a702b05 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -404,6 +404,7 @@ !endif PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + NestedInterruptTplLib|OvmfPkg/Library/NestedInterruptTplLib/NestedInterruptTplLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc index 3458926515..994d09c751 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -314,6 +314,7 @@ LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + NestedInterruptTplLib|OvmfPkg/Library/NestedInterruptTplLib/NestedInterruptTplLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf diff --git a/OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.c b/OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.c index 3e04b49d6b..67f4dcde37 100644 --- a/OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.c +++ b/OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.c @@ -8,6 +8,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include + #include "LocalApicTimerDxe.h" // @@ -58,9 +60,10 @@ TimerInterruptHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ) { - EFI_TPL OriginalTPL; + STATIC NESTED_INTERRUPT_STATE NestedInterruptState; + EFI_TPL OriginalTPL; - OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL); + OriginalTPL = NestedInterruptRaiseTPL (); SendApicEoi (); @@ -71,7 +74,7 @@ TimerInterruptHandler ( mTimerNotifyFunction (mTimerPeriod); } - gBS->RestoreTPL (OriginalTPL); + NestedInterruptRestoreTPL (OriginalTPL, SystemContext, &NestedInterruptState); } /** diff --git a/OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf b/OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf index 3ad28a148c..b85965c75e 100644 --- a/OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf +++ b/OvmfPkg/LocalApicTimerDxe/LocalApicTimerDxe.inf @@ -27,6 +27,7 @@ UefiBootServicesTableLib BaseLib DebugLib + NestedInterruptTplLib UefiDriverEntryPoint LocalApicLib diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 994a02d301..db449384c9 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -403,6 +403,7 @@ PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf PciExpressLib|OvmfPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + NestedInterruptTplLib|OvmfPkg/Library/NestedInterruptTplLib/NestedInterruptTplLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 6f774baf90..15ce1261ec 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -409,6 +409,7 @@ !endif PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + NestedInterruptTplLib|OvmfPkg/Library/NestedInterruptTplLib/NestedInterruptTplLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index c851764dec..da8d182b54 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -415,6 +415,7 @@ !endif PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + NestedInterruptTplLib|OvmfPkg/Library/NestedInterruptTplLib/NestedInterruptTplLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 63c3a47aea..b2d24a798b 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -435,6 +435,7 @@ !endif PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + NestedInterruptTplLib|OvmfPkg/Library/NestedInterruptTplLib/NestedInterruptTplLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 8bb497088b..c328987e84 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -340,6 +340,7 @@ !endif PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + NestedInterruptTplLib|OvmfPkg/Library/NestedInterruptTplLib/NestedInterruptTplLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf [LibraryClasses.common.UEFI_APPLICATION] -- 2.38.1