-
Notifications
You must be signed in to change notification settings - Fork 2.9k
MdeModulePkg/Library: Fix memory leak for ArmFfaLib's Rx/Tx buffer and add ArmFfaLib for PeilessSec #11166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3b1a672 to
8141648
Compare
|
@kuqin12, @samimujawar Thanks! |
8141648 to
aa2db3f
Compare
|
@kuqin12 @samimujawar |
|
@LeviYeoReum I was thinking about this change in general. Would it make sense to let SEC phase to handle the memory movement? So that DXE phase does not need to know about this? I think leaving the movement to DXE phase and perform operations based on a flag in data is like logic leakage. Or is there any reason that it cannot be done in SEC phase? In our use case, by the time SEC hands off to DXE, the permanent memory is already available. |
|
Hi Kun, Thanks for reviewing this patch :)
Actually for PeilessSec as you said, this is true. it don't need to do memory movement. Thanks. |
I see. Please correct me if I misunderstood, we mainly have 2 scenarios:
The concern is mainly around when no PEIM uses FFA, correct? Wondering if you have considered using a separate PEIM to handle the movement? We are currently imposing all FFA consuming PEIMs to register a callback, is that necessary? A less-than-optimal, but simpler solution is to remap the buffer regardless in DXE phase. This is trading the complicated logic of carrying on the information with a little overhead of remapping the buffer, unless you can think of any reason why DXE has to use the same Rx/Tx buffer as PEI. |
|
Hi Kun,
This case is PeilessSec. So Yes.
Here is tow case.
Yes.
Yes. if PEIM use ArmFfaPeiLib. it's done by ArmFfaLib.
Hmm.. This seems not good for me. Thanks ;) |
Is a PEIM really considered too much? I think it might be better than sprinkle the callbacks around all PEIMs that do use FFA?
Sorry, maybe I missed your point of "LEAK". But even if we stick to the same buffer throughout the boot phase, OS/hypervisor will remap their Rx/Tx buffer anyway. Would that not be a leakage? |
|
Hi Kun,
Hmm, the "Remap" is done only once. I don't think the callback is sprinkled by all PEIM?
No. When you see the before this patch, we skip the "FreeMemory()" in case of PEIM allocate Rx/Tx buffer So, this unused Rx/Tx buffer memory area still reserved in OS/Hypervisor, It's a leak. Thanks :) |
We are imposing all FFA aware PEI modules to carry the check of permanent memory availability. Additionally, the callbacks are registered for each of the PEIMs that will use FFA lib in early PEI phase, correct? I think this will increase the footprint on flash for each involved module. And early PEIMs normally do not have compression.
Are you confirming that, if OS/Hypervisor will not use the same Rx/Tx buffer region, they will "leak" the memory region because it is marked as reserved in UEFI, even after this change? |
|
Hi Kun,
No, callback is registered by the first PEIM who allocates the Rx/Tx buffer if Rx/Tx buffer are allocated in Temporary memory.
Before this patch, Yes.
After this Patch, No. Thanks! |
Great. The migration part makes sense. We have been all over the places during the conversation. My overall point was that I hope the PEI being the only one that needs to handle the logic. A separate PEIM will cover the edge case if no PEIM uses FFA. The single module probably will save the footprint more scalablely. But you can decide how to proceed on that point. |
Thanks ;)
I understood what is your point. But, IMHO, I'm not sure the add PEIM really saves the footprint taking the duty to add the PEIM on every platform which want to use ArmFfaPeiLib and a risk -- not add the the PEIM for handling this. Also, I'm not sure about the feature "edge case" like this problem -- handling something over the Phases. If you agree, I want to remain as it is right now. Thanks. |
aa2db3f to
79ba890
Compare
|
⚠ WARNING: Cannot add some reviewers: A user specified as a reviewer for this PR is not a collaborator of the repository. Please add them as a collaborator to the repository so they can be requested in the future. Non-collaborators requested: Attn Admins: Admin Instructions:
|
09d7d31 to
8757143
Compare
8757143 to
12e3b09
Compare
12e3b09 to
041ba8c
Compare
dd0c9f1 to
43388aa
Compare
|
Hi @samimujawar and @lgao4 Could you merge this patch series please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like one minor comment change was lost. Otherwise this PR looks good to me.
The commit e15fe06 ("MdeModulePkg/Library: make ArmFfaPeiLib available early PEIM stage") uses ArmFfaPeiLib in the early PEIM stage. However, the Rx/Tx buffer allocated in the early PEIM stage uses temporary memory. This results in a memory leak when the temporary memory's heap is relocated to permanent memory. For example, if the Rx/Tx buffer memory is allocated at 0x20006000 in temporary memory, and if offset between temporary memory and permanent is 0x40000000, then: - Once permanent memory installed the temporary memory at 0x20006000 is migrated to 0x60006000. - However, ArmFfaPeiLib allocates new Rx/Tx buffer without freeing the migrated Rx/Tx buffers, i.e. the buffers at 0x60006000. This results in a memory leak as the migrated Rx/Tx buffer area is lost. To address this memory leak, use the MemoryAllocationHob's name, so that the migrated memory area will be reused as Rx/Tx buffer. This patch also includes rename ArmFfaRxTxStmm.c to ArmFfaStandaloneMmRxTxMap.c to keep the file name convention in ArmFfaLib with ArmFfa{Phase}{...}.c Fixes: e15fe06 ("MdeModulePkg/Library: ...") Signed-off-by: Yeoreum Yun <[email protected]> Continuous-integration-options: PatchCheck.ignore-multi-package
The PcdFfaTxRxPageCount can never be changed dynamically and is configured at build time to specify the size of the Rx/Tx buffers. Therefore, make PcdFfaTxRxPageCount a PcdsFixedAtBuild PCD. Signed-off-by: Yeoreum Yun <[email protected]>
To use Arm-FFA intereface in PeilessSec, implments ArmFfaSecLib used by PeilessSec. For example, communicate with TPM service using CRB over ARM-FFA (via Tpm2DeviceLibFfa), PeilessSec need to use Arm-FFA interface. Signed-off-by: Yeoreum Yun <[email protected]>
Some of code for handling Rx/Tx buffer is duplicate. This patch commonize some of duplication routine used in Rx/Tx buffer related functions. Signed-off-by: Yeoreum Yun <[email protected]>
…erInfo Change type of buffer address type in ArmFfaRxTxBufferInfo so that reduce the type casting. Signed-off-by: Yeoreum Yun <[email protected]>
43388aa to
73bdc5b
Compare
Thanks. I've updated it ! |
Description
This patchset adds:
- Fix memory leak on Rx/Tx buffer in ArmFfaPeiLib.
- Add ArmFfaSecLib for PeilessSec.
Patch 1 fixes the memory leak on RxTx buffer when ArmFfaPeiLib used.
Patch 2 makes PcdFixedAtBuildPcd as PcdsFixedAtBuildPCD.
Patch 3 adds ArmFfaSecLib used in PeilessSec
Patch 4 cleanup duplication code on ArmFfaLib.
Patch 5 change type of buffer address in ArmFFaRxTxBufferInfo structure.
Signed-off-by: Yeoreum Yun [email protected]