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 EB254941AE4 for ; Wed, 2 Aug 2023 16:21:04 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=6ZTQIfDeK94Em9H9agXM5mrXobQ2CkKndfXZohg7ksU=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: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=1690993263; v=1; b=ViylD6s61AIFHfvVHvwE/tBZIVn7KAF4b9CJeSN6G570uO0Zy+9soPWIMTqV+7qKc3Dwt0Ol dcWjbcTd7o9VLgddfcLLv1HP8Ry+KyR1Nm65JoBwOnf/TxrBUkcJm855UJdHrYNBxc/lLm2JIfg wB2IVy58gmRZZJgEq7lKK8lA= X-Received: by 127.0.0.2 with SMTP id OTMZYY7687511xcO5ubFhgrd; Wed, 02 Aug 2023 09:21:03 -0700 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.657.1690993262998777369 for ; Wed, 02 Aug 2023 09:21:03 -0700 X-Received: from [10.137.194.171] (unknown [131.107.1.171]) by linux.microsoft.com (Postfix) with ESMTPSA id 63326238C42C; Wed, 2 Aug 2023 09:21:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 63326238C42C Message-ID: <787bd2e6-c50e-a2a6-735c-ff0d9146685d@linux.microsoft.com> Date: Wed, 2 Aug 2023 09:21:02 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [PATCH v1 1/1] ArmPkg: DefaultExceptionHandlerLib: Do Not Allocate Memory To: devel@edk2.groups.io, ardb@kernel.org Cc: Leif Lindholm , Ard Biesheuvel , Sami Mujawar , Gerd Hoffmann References: <20230731220428.23002-1-osde@linux.microsoft.com> From: "Oliver Smith-Denny" In-Reply-To: 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,osde@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: mmm46USLeN9zHk3xrtBrEHp7x7686176AA= 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=ViylD6s6; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linux.microsoft.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 8/2/2023 9:06 AM, Ard Biesheuvel wrote: > On Tue, 1 Aug 2023 at 00:04, Oliver Smith-Denny > wrote: >> >> If gST->ConOut is available when Arm's DefaultExceptionHandler >> is running, AsciiPrint will get called to attempt to print to >> ConOut, in addition to the serial output. >> >> AsciiPrint calls AsciiInternalPrint in UefiLibPrint.c which >> in turn calls AllocatePool to allocate a buffer to convert >> the Ascii input string to a Unicode string to pass to >> ConOut->OutputString. >> >> Per the comment on DefaultExceptionHandler, we should not be >> allocating memory in the exception handler, as this can cause >> the exception handler to fail if we had a memory exception or >> the system state is such that we cannot allocate memory. >> >> It has been observed on ArmVirtQemu that exceptions generated >> in the memory handling code will fail to output the stack dump >> and CPU state that is critical to debugging because the >> AllocatePool will fail. >> >> This patch fixes the Arm and AARCH64 DefaultExceptionHandlers to >> not allocate memory when ConOut is available and instead use >> stack memory to convert the Ascii string needed for SerialPortWrite >> to the Unicode string needed for ConOut->OutputString. Correspondingly, >> ArmVirtQemu can now output the stack dump and CPU state when hitting >> an exception in memory code. >> >> GitHub PR: https://github.com/tianocore/edk2/pull/4703 >> >> Cc: Leif Lindholm >> Cc: Ard Biesheuvel >> Cc: Sami Mujawar >> Cc: Gerd Hoffmann >> >> Signed-off-by: Oliver Smith-Denny >=20 > Thanks a lot for fixing this. >=20 > Is calling into gST->ConOut guaranteed to be safe in this regard? Or > is it still best effort? >=20 >=20 Yeah, this is something I worried about when fixing this. It is very much best effort, because there are no guarantees that OutputString will not allocate memory (or some other such unsafe operation in an exception handler). With the ability to BYO ConOut stack and the complications with graphics that can be involved here, I personally would be happy to drop the ConOut call entirely and rely on the serial output. In my testing, this did work on ArmVirtQemu and I can envision a case where having the ConOut output would be nice, but I tend towards lets keep the exception handler as simple as possible and make sure we get the useful information dumped out. Another option would be to keep this change but move the ConOut calls to after all of the serial output, so that if we do get a recursive exception in ConOut, at least we got our serial output. Let me know what you think, happy to spin up a v2. Thanks, Oliver -=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 (#107460): https://edk2.groups.io/g/devel/message/107460 Mute This Topic: https://groups.io/mt/100472023/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-