From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.655.1591812461168519623 for ; Wed, 10 Jun 2020 11:07:41 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A61BC1FB; Wed, 10 Jun 2020 11:07:39 -0700 (PDT) Received: from [192.168.1.69] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E6CCE3F66F; Wed, 10 Jun 2020 11:07:38 -0700 (PDT) Subject: Re: [PATCH] ArmPkg/ArmExceptionLib: use static buffer for sp_el0 To: Heyi Guo , devel@edk2.groups.io Cc: yitian.ly@alibaba-inc.com, Leif Lindholm References: <1591665990-15342-1-git-send-email-guoheyi@linux.alibaba.com> From: "Ard Biesheuvel" Message-ID: <679afd8a-bb5a-9ae2-0266-3235ed227bfd@arm.com> Date: Wed, 10 Jun 2020 20:07:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <1591665990-15342-1-git-send-email-guoheyi@linux.alibaba.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 6/9/20 3:26 AM, Heyi Guo wrote: > The exception library is also used in DxeMain before memory services > are available, and AllocatePages() will fail in this case and cause > sp_el0 remains 0. Then if any exception occurs before CpuDxe driver is > loaded, a recursive exception will be trigged by page translation > fault for sp = 0 - 0x130. > > Use static buffer instead to fix this issue. > > Signed-off-by: Heyi Guo > Reviewed-by: Ard Biesheuvel Merged as #679 > --- > > Cc: Leif Lindholm > Cc: Ard Biesheuvel > --- > ArmPkg/Library/ArmExceptionLib/AArch64/AArch64Exception.c | 14 ++++++-------- > 1 file changed, 6 insertions(+), 8 deletions(-) > > diff --git a/ArmPkg/Library/ArmExceptionLib/AArch64/AArch64Exception.c b/ArmPkg/Library/ArmExceptionLib/AArch64/AArch64Exception.c > index be1cdcf..1e2aeaa 100644 > --- a/ArmPkg/Library/ArmExceptionLib/AArch64/AArch64Exception.c > +++ b/ArmPkg/Library/ArmExceptionLib/AArch64/AArch64Exception.c > @@ -19,7 +19,8 @@ EFI_EXCEPTION_CALLBACK gDebuggerExceptionHandlers[MAX_AARCH64_EXCEPTION + 1] = > PHYSICAL_ADDRESS gExceptionVectorAlignmentMask = ARM_VECTOR_TABLE_ALIGNMENT; > UINTN gDebuggerNoHandlerValue = 0; // todo: define for AArch64 > > -#define EL0_STACK_PAGES 2 > +#define EL0_STACK_SIZE EFI_PAGES_TO_SIZE(2) > +STATIC UINTN mNewStackBase[EL0_STACK_SIZE / sizeof (UINTN)]; > > VOID > RegisterEl0Stack ( > @@ -31,14 +32,11 @@ RETURN_STATUS ArchVectorConfig( > ) > { > UINTN HcrReg; > - UINT8 *Stack; > > - Stack = AllocatePages (EL0_STACK_PAGES); > - if (Stack == NULL) { > - return RETURN_OUT_OF_RESOURCES; > - } > - > - RegisterEl0Stack ((UINT8 *)Stack + EFI_PAGES_TO_SIZE (EL0_STACK_PAGES)); > + // Round down sp by 16 bytes alignment > + RegisterEl0Stack ( > + (VOID *) (((UINTN) mNewStackBase + EL0_STACK_SIZE) & ~0xFUL) > + ); > > if (ArmReadCurrentEL() == AARCH64_EL2) { > HcrReg = ArmReadHcr(); >