From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 71FC2AC0C9C for ; Thu, 29 Feb 2024 19:04:15 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=6ocU7Pb1I3waGVgH7TDHJLDNi5lSM5xF9Xhm177inuk=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From:Autocrypt:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1709233454; v=1; b=Hs+6a9nOYyYBfLhfDZGWIIipIJRp1uLWtKTlHWomMreF4GYQolbzdNMZksbNpD8LOalnlVHD Nc9rQuo3DC3OCA/3hJ5eWFSSMISr7diyzRilqy2tPKiK985e5QN2MtB2XCfXtEAHGgtDVyozr3s P6qaQkWRUC5g/mtMU+jvqppk= X-Received: by 127.0.0.2 with SMTP id QF38YY7687511xb651QCldz7; Thu, 29 Feb 2024 11:04:14 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.3723.1709233453294905437 for ; Thu, 29 Feb 2024 11:04:13 -0800 X-Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-121-VtAKKz6BOxaVYKDVCamO7A-1; Thu, 29 Feb 2024 14:04:08 -0500 X-MC-Unique: VtAKKz6BOxaVYKDVCamO7A-1 X-Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-566b577cdc3so416238a12.1 for ; Thu, 29 Feb 2024 11:04:08 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVkWYwLtr9/PMHMbKq0xK12E8mqN294DKoNgsDuSdtp5xhYPbralzzcxuVCrbqk2YlNiexOmLmhrg3eTWa28E8f5p1DdA== X-Gm-Message-State: AKxV2Fuf0mc5KTAJEGdACtfUx7686176AA= X-Received: by 2002:a05:6402:2156:b0:566:ef8:a81a with SMTP id bq22-20020a056402215600b005660ef8a81amr2220327edb.7.1709233447533; Thu, 29 Feb 2024 11:04:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiFWFykbBlQf+u80ueXdO60nHEL8T4PwqYxi3PLdGX9w4OJLLlhQxD9x2+ApMzhB6LB2Bdvg== X-Received: by 2002:a05:6402:2156:b0:566:ef8:a81a with SMTP id bq22-20020a056402215600b005660ef8a81amr2220317edb.7.1709233447186; Thu, 29 Feb 2024 11:04:07 -0800 (PST) X-Received: from ?IPV6:2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e? ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.googlemail.com with ESMTPSA id b5-20020aa7df85000000b0056644c99f69sm874230edy.57.2024.02.29.11.04.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Feb 2024 11:04:06 -0800 (PST) Message-ID: <6ce2acb8-08a2-417c-9f4b-5f96befb412c@redhat.com> Date: Thu, 29 Feb 2024 20:04:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [PATCH 2/2] MdeModulePkg/DxeCore: Fix stack overflow issue due to nested interrupts To: Ray Ni , devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Laszlo Ersek , Michael Brown References: <20240229130246.3-1-ray.ni@intel.com> <20240229130246.3-3-ray.ni@intel.com> From: "Paolo Bonzini" Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF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8WJH2xgFL28XnqY4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: <20240229130246.3-3-ray.ni@intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: 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,pbonzini@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=Hs+6a9nO; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On 2/29/24 14:02, Ray Ni wrote: > In the end, it will lower the TPL to TPL_APPLICATION with interrupt enabl= ed. >=20 > However, it's possible that another timer interrupt happens just in the e= nd > of RestoreTPL() function when TPL is TPL_APPLICATION. How do non-OVMF platforms solve the issue? Do they just have the same=20 bug as in https://bugzilla.tianocore.org/show_bug.cgi?id=3D4162 ? The design of NestedInterruptTplLib is that each nested interrupt must=20 increase the TPL, but if I understand correctly there is a hole here: // // Call RestoreTPL() to allow event notifications to be // dispatched. This will implicitly re-enable interrupts. // gBS->RestoreTPL (InterruptedTPL); // // Re-disable interrupts after the call to RestoreTPL() to ensure // that we have exclusive access to the shared state. // DisableInterrupts (); because gBS->RestoreTPL will unconditionally enable interrupts if=20 InterruptedTPL < TPL_HIGH_LEVEL. If possible, the easiest solution would be to merge=20 NestedInterruptTplLib into Core DXE. This way, instead of calling=20 gBS->RestoreTPL, NestedInterruptTplLib can call a custom version of=20 CoreRestoreTpl that exits with interrupts disabled. That is, something lik= e VOID EFIAPI CoreRestoreTplInternal(IN EFI_TPL NewTpl, IN BOOLEAN InterruptState) { // // The caller can request disabled interrupts to access shared // state, but TPL_HIGH_LEVEL must *not* have them enabled. // ASSERT(!(NewTpl =3D=3D TPL_HIGH_LEVEL && InterruptState)); // ... gEfiCurrentTpl =3D NewTpl; CoreSetInterruptState (InterruptState); } Now, CoreRestoreTpl is just // // If lowering below HIGH_LEVEL, make sure // interrupts are enabled // CoreRestoreTplInternal(NewTpl, NewTpl < TPL_HIGH_LEVEL); whereas NestedInterruptRestoreTPL can do // // Call RestoreTPL() to allow event notifications to be // dispatched. This will implicitly re-enable interrupts, // but only if events have to be dispatched. // CoreRestoreTplInternal(InterruptedTPL, FALSE); // // Interrupts are now disabled, so we can access shared state. // This avoids the unlimited nesting of interrupts because each stack frame=20 will indeed have a higher TPL than the outer version. Paolo -=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 (#116181): https://edk2.groups.io/g/devel/message/116181 Mute This Topic: https://groups.io/mt/104642317/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-