From nobody Sun Apr 28 14:47:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61329+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61329+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1592304006; cv=none; d=zohomail.com; s=zohoarc; b=DHkUP+uncSlrAHfUuuCr17aRzITGlADIARShZNQtnt8EgvU/qkesmMzqZfYsq2T3jsF1Il0+TQP8/MYvLImhqBsdmftp/4jtEcKcAn4/HorH0ISjAYM0rMQSd5YCd8Y8m0M6vCpnUuS74N1ZprLVKKdJG1w08mKZhAiv8RtyEDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592304006; h=Content-Type:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=lq6+fHScSWikKc1uj8wad2pmde5dDXrnAYznhO2UBCY=; b=e4OQlDcyLUxU/+/sY6ClwN6brLVYljMlw+R++pkoaBG9rfNf0p1wGDWu2pxmnj/BrIpazmHCV2IqjCn3ux3eCRYvnu1tA0uWHzGpcGieXy3lsluqCgmRoIywoSvaKWo6h0pm+s1bHK8PLJl6Z/iG9JivGbK7Bk2G0OfuvlRki0w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61329+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1592304006402188.14218298821072; Tue, 16 Jun 2020 03:40:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id sYooYY1788612xFajikfj2MW; Tue, 16 Jun 2020 03:40:06 -0700 X-Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by mx.groups.io with SMTP id smtpd.web12.2622.1592275802821098287 for ; Mon, 15 Jun 2020 19:50:02 -0700 IronPort-SDR: KzmC4IlJmvFM5fUok7jMyCcojCWEoAVzzm536ptJeJ/uOrzKfXn0+x8PVe9E9SdEb4JVCBRK3W PnOTlJqanb45w2BOygID5GKmFZrgUtSeH7mnlKwiMKNkqbfrLcxU7FoTXM+3gDMroxuN7/UA9m PjLnxgREMIcuhscaHIJyRlyZbmQAfb+uYUZrKUwebEJuBIm8NmP486dLtDc6p0ys1C5SwMQGTh Nc1RH2RFDSQ4Q2+l85NkymWRFk0qS2shoIsehF1oBYrB4Gi7rEq/OZlyK+7IP4Qy99tOqfmIRO wg4= X-SBRS: 2.7 X-MesageID: 20118697 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.73,517,1583211600"; d="scan'208";a="20118697" From: Igor Druzhinin To: CC: , , , , , "Igor Druzhinin" Subject: [edk2-devel] [PATCH] OvmfPkg: End timer interrupt later to avoid stack overflow under load Date: Tue, 16 Jun 2020 03:49:42 +0100 Message-ID: <1592275782-9369-1-git-send-email-igor.druzhinin@citrix.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,igor.druzhinin@citrix.com X-Gm-Message-State: 3BFg1VVubsTe6E7QPZMdtBSux1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1592304006; bh=obbexNmTpxaXzvhukxf5kYFHpplDf8OJGXFCkNzihDk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Hl97gC3zF+0OoSYfnCKP9DmDOHet2A/6ZhnwpEWpAeCo98NVn94cERNbOI7Wo8z21r9 pYKVBRLeJPivRM5SA7FNHCssCge9imcjfHZSLLc8QJAbLogwJZsputCq2He8tpbqOG6eE j10IOOrsIlq51vi8fLi8jjWfOc2Z0V3QiN0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" RestoreTPL called while at TPL_HIGH_LEVEL unconditionally enables interrupts even if called in interrupt handler. That opens a window while interrupt is not completely handled but another interrupt could be accepted. If a VM starts on a heavily loaded host hundreds of periodic timer interrup= ts might be queued while vCPU is descheduled (the behavior is typical for a Xen host). The next time vCPU is scheduled again all of them get delivered back to back causing OVMF to accept each one without finishing a previous one and cleaning up the stack. That quickly results in stack overflow and a triple fault. Fix it by postponing sending EOI until we finished processing the current tick giving interrupt handler opportunity to clean up the stack before accepting the next tick. Signed-off-by: Igor Druzhinin Acked-by: Laszlo Ersek Reviewed-by: Paolo Bonzini --- Laszlo, Anthony, Do you think it's the right way to address it? Alternatively, we might avoid calling RaiseTPL in interrupt handler at all like it's done in HpetTimer implementation for instance. Or we might try to address it in Raise/RestoreTPL calls by saving/restoring interrupt state along with TPL. --- OvmfPkg/8254TimerDxe/Timer.c | 5 +++-- OvmfPkg/XenTimerDxe/XenTimerDxe.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/8254TimerDxe/Timer.c b/OvmfPkg/8254TimerDxe/Timer.c index 67e22f5..fd1691b 100644 --- a/OvmfPkg/8254TimerDxe/Timer.c +++ b/OvmfPkg/8254TimerDxe/Timer.c @@ -79,8 +79,6 @@ TimerInterruptHandler ( =20 OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); =20 - mLegacy8259->EndOfInterrupt (mLegacy8259, Efi8259Irq0); - if (mTimerNotifyFunction !=3D NULL) { // // @bug : This does not handle missed timer interrupts @@ -89,6 +87,9 @@ TimerInterruptHandler ( } =20 gBS->RestoreTPL (OriginalTPL); + + DisableInterrupts (); + mLegacy8259->EndOfInterrupt (mLegacy8259, Efi8259Irq0); } =20 /** diff --git a/OvmfPkg/XenTimerDxe/XenTimerDxe.c b/OvmfPkg/XenTimerDxe/XenTim= erDxe.c index 9f9e047..0bec593 100644 --- a/OvmfPkg/XenTimerDxe/XenTimerDxe.c +++ b/OvmfPkg/XenTimerDxe/XenTimerDxe.c @@ -61,8 +61,6 @@ TimerInterruptHandler ( =20 OriginalTPL =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); =20 - SendApicEoi(); - if (mTimerNotifyFunction !=3D NULL) { // // @bug : This does not handle missed timer interrupts @@ -71,6 +69,9 @@ TimerInterruptHandler ( } =20 gBS->RestoreTPL (OriginalTPL); + + DisableInterrupts (); + SendApicEoi (); } =20 /** --=20 2.7.4 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#61329): https://edk2.groups.io/g/devel/message/61329 Mute This Topic: https://groups.io/mt/74913405/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-