From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by mx.groups.io with SMTP id smtpd.web11.42.1686244863849074852 for ; Thu, 08 Jun 2023 10:21:03 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ceAVKOo+; spf=pass (domain: gmail.com, ip: 209.85.215.180, mailfrom: kuqin12@gmail.com) Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-51b4ef5378bso601061a12.1 for ; Thu, 08 Jun 2023 10:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686244863; x=1688836863; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=YVmVXZNyjCwfa3xwpPyf4/8aE6uHyzrfTXys7uqWLfs=; b=ceAVKOo+En1gkgFgLDLgewbzxAzhunQLMjAkvs1WiXRhP6OU45qn6HyNOac6iWWqh3 vjyywCrkXrWCDoxpplWge//0X/18dl7Q0YM3FC0ILyC6Zepq/6np2h6fCAXMilt/AbAi xMIXj6Y4j5/n5ZfxqKhWcnCwzaLIbLZ5ojaT+9U2l99nmtuYKGXSOFiFYYnDYzgyPqxJ dWA6a9+KKV0N58pTvRXOiVeRoCBotU76BYamwb72IwNQaGvfkdC36KsLVvHCochE98gy AzTa4aaQqLXXrvkk8bRrqHXdpQTNE+xJdGrNrFyp7fpspBXGhUdE4AealNV+O5hkq3Gh jOxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686244863; x=1688836863; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YVmVXZNyjCwfa3xwpPyf4/8aE6uHyzrfTXys7uqWLfs=; b=FsbBTJIWr3mZV4nouAbSQyP98v+5s69Rpq4fda80W/Qca+Q8wY6N0ujRvknCUdQits G/jQBUjo7EVy4o821eMQ6QwFDh9VsPKzszET/T7qL4TnAWPEdi+E4dQB0cQSF9oQWndo foePpIjgCmXRXohcKoY3N+gyucsYqfVqjxcxdDE99TcBCFRZ9/KpraMIIeRmErY72U7m hdkWcqZ3/PWTTk/rgZMPdN85Jr4OmwsXZDNipEbiiQ06eBCheWD1QKLW0fQv9+suEwli 3TrCsaMBzOF6mL/vE43E0ysz99u4fXOXVk7hx8uc+7SGUWCO9eQTOsWW7mDiN1jxauUb FXWw== X-Gm-Message-State: AC+VfDxoHntTtUHk0gTz1gQapS849/1Qj/QB0+XUBV39kM1dTVvZTKb/ zXTWaDwKpA9XtTECszj+TBt5HW2TS8E= X-Google-Smtp-Source: ACHHUZ6iUFCXySaDFXxHViY0bNWJ2Xvt/aeRjhfdzE1HDjr1i8zxPvnMSIRqkeDXwBe2YJ3qDE7StQ== X-Received: by 2002:a17:903:44b:b0:1a9:b0a3:f03a with SMTP id iw11-20020a170903044b00b001a9b0a3f03amr8608084plb.9.1686244862971; Thu, 08 Jun 2023 10:21:02 -0700 (PDT) Return-Path: Received: from ?IPV6:2001:4898:d8:33:7c4a:9362:be2c:efe5? ([2001:4898:80e8:37:fc35:9362:be2c:efe5]) by smtp.gmail.com with ESMTPSA id 5-20020a170902e9c500b001b1920d000bsm1673486plk.234.2023.06.08.10.21.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Jun 2023 10:21:02 -0700 (PDT) Message-ID: Date: Thu, 8 Jun 2023 10:21:01 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [edk2-devel] Using Depex for Standalone MM drivers on ARM To: devel@edk2.groups.io, Ard Biesheuvel , Sami Mujawar , 'Ray Ni' References: <17663A832C512EDF.23186@groups.io> From: "Kun Qin" In-Reply-To: <17663A832C512EDF.23186@groups.io> Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Forgot to add applicable maintainers earlier.. It would be great if StandaloneMmPkg maintainers could shed some light here. Thanks, Kun On 6/6/2023 5:57 PM, Kun Qin via groups.io wrote: > Hi all, > > We found an issue a while back on ARM systems, where the Standalone MM > drivers with Depex specified will run into a hang when TFA hands off to > Standalone MM core. (https://bugzilla.tianocore.org/show_bug.cgi?id=3883) > > After some debugging, the logic in the ticket still seems to be true > until today: > > 1. The UEFI Standalone MM partition needs to setup Standalone MM core to > be branched off that the beginning of this FV by manipulating the build > rules. Example: > https://github.com/tianocore/edk2-platforms/blob/93a71a67fd80bbc5baf0708ba75e73696b4a1c67/Platform/ARM/SgiPkg/PlatformStandaloneMm.fdf#LL88C1-L89C1 > > > 2. During build time, the MM partition was initialized to code pages > through `ARM_SP_IMAGE_MMAP` as part of `plat_arm_mmap` see here: > https://github.com/ARM-software/arm-trusted-firmware/blob/a0f3b552cfa45258099170c83f79619b2dbd7b9b/include/plat/arm/common/arm_spm_def.h#LL36C11-L36C11, > > which was later used for initial setup. > > 3. During BL31 setup step, the EL1 jump point will be updated to > `sp_image_base` from `plat_get_secure_partition_boot_info`: > https://github.com/ARM-software/arm-trusted-firmware/blob/a0f3b552cfa45258099170c83f79619b2dbd7b9b/services/std_svc/spm/spm_mm/spm_mm_setup.c#LL45C29-L45C42 > > which was initialized to `ARM_SP_IMAGE_BASE`. > > 4. After demoting to Secure EL1, the FD will first branch off to > standalone core entrypoint: > https://github.com/tianocore/edk2/blob/ded0b489af09cde5afa05d74acdb12cd4b4f8394/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c#L319. > > Standalone core entrypoint will execute in place of FV for the first few > lines. Then the core will locate itself in reported buffer SpImageBase > (which is also the FV image buffer location) and update the page > attribute accordingly > (https://github.com/tianocore/edk2/blob/ded0b489af09cde5afa05d74acdb12cd4b4f8394/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/StandaloneMmCoreEntryPoint.c#LL386C12-L386C48). > > > 5. The FV image buffer location (SpImageBase from UEFI, sp_image_base > from tf-a) is then published as an FV hob for further dispatches > (https://github.com/tianocore/edk2/blob/ded0b489af09cde5afa05d74acdb12cd4b4f8394/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c#LL84C1-L84C75), > > which was then used for Depex tracking/evaluation during driver discovery > and dispatching process in > https://github.com/tianocore/edk2/blob/ded0b489af09cde5afa05d74acdb12cd4b4f8394/StandaloneMmPkg/Core/StandaloneMmCore.c#L646. > > > 6. Depex discovered from FV during this process is cached in the > DriverEntry structure as pointers and added to the mDiscoveredList in > https://github.com/tianocore/edk2/blob/ded0b489af09cde5afa05d74acdb12cd4b4f8394/StandaloneMmPkg/Core/Dispatcher.c#L864 > > > 7. Later during Standalone MM dispatching, this Depex pointer will be > updated in place: > https://github.com/tianocore/edk2/blob/ded0b489af09cde5afa05d74acdb12cd4b4f8394/StandaloneMmPkg/Core/Dependency.c#LL256C14-L256C14, > > which causes memory violation as we are writing to the code pages. > > Could you please let me know if there is anything I missed on this path? > > To resolve this issue, I think any one of the following changes > could be considered: > > 1. Updating the incoming FV region to be Data pages, in TF-A; > 2. Copying this incoming region to a separate data buffer; > 3. Allocating designated copy pools for Depex sections during dispatching > (and free them once done). > > We could work around this by compressing the FV, but I think we should > still fix the issue, correct? > > Any thoughts or suggestions on this would be appreciated. > > Regards, > Kun > > > > > >