Repository navigation
fix(pcie): restore BAR memory after PCI_IN_13 Check_1 - #664
Open
La1itchauhan wants to merge 1 commit into
Open
La1itchauhan wants to merge 1 commit into
La1itchauhan wants to merge 1 commit into
Conversation
In Check_1 of p004 (non-prefetchable) and p005 (prefetchable), the test writes KNOWN_DATA (0xABABABAB) to the endpoint BAR at base + mem_offset to verify that in-window memory access does not abort. While old_value is read before the write, it was never restored. When the endpoint BAR hosts the MSI-X table at offset 0 (with default mem_offset 0x10), this leaves 0xABABABAB in entry 1's Message Address. Subsequent compliance rules (e.g. PCI_MSI_2 / S_L3GI_02) that walk the live MSI-X tables fail to resolve the corrupted entry and report false failures. 1. Restore old_value back to mem_base + mem_offset immediately after the in-window check readback. 2. Guard the exception-recovery path with volatile restore_pending and old_value (both modified after the exception-return context is saved), clearing the flag before the restore write to prevent re-entrant fault loops. Read into a temporary buffer to preserve qualifier safety. 3. At exception_return, ensure the Root Port window configuration is restored first before writing old_value back to ori_mem_base + mem_offset. 4. In p005, initialize ori_mem_base and save exception return context before Check_1 so that any exception during Check_1 targets the valid device base. (The subsequent ori_mem_base assignment before Check_2 is retained for existing Check_2 logic). Fixes ARM-software#650 Signed-off-by: Lalit Chauhan <chauhanlalitofficial@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In
Check_1ofp004(non-prefetchable) andp005(prefetchable), the test writesKNOWN_DATA(0xABABABAB) to the start of the Root Port's memory window atbase + mem_offsetto verify that in-range memory access completes without an exception or data abort.Although
old_valuewas read prior to writing, it was never restored back to memory upon completing the check or on exception recovery. For devices where the endpoint BAR hosts the MSI-X table at offset0(wherepal_pcie_mem_get_offset()defaults to0x10), this leaves0xABABABABin entry 1's Message Lower Address.Subsequent tests in the test suite that inspect live MSI-X tables (such as
PCI_MSI_2/ test 897 andS_L3GI_02/ test 846) then fail to resolve the corrupted vector through the ITS mappings and report false test failures.Key Changes:
old_valueback tomem_base + mem_offsetimmediately after the in-window readback check in bothp004.candp005.c.volatile uint32_t restore_pendingandvolatile uint32_t old_value(read into temporarytmpto avoid discarded qualifier warnings). Inexception_return:, after Root Port window registers are restored (TYPE1_NP_MEM/TYPE1_P_MEM), restoreold_valueatori_mem_base + mem_offset.restore_pendingis cleared prior to issuing the write to prevent recursive exception loops in case of access aborts.p005.c, initializeori_mem_base = mem_base;and refreshbranch_stack_pointer = val_pe_save_exception_return_context();beforeCheck_1(aligning withp004.c) so that any exception duringCheck_1targets the correct original base on the current device. The duplicateori_mem_base = mem_base;prior toCheck_2is retained forCheck_2logic.Note on Platform Ports / PAL:
As discussed in #650, PAL implementers should also ensure that
pal_pcie_mem_get_offset()returns an offset within BAR memory that is safe to access and overwrite without corrupting device configuration or capability structures (such as MSI-X tables). Restoring original BAR contents in the ACS test ensures test hygiene and robustness regardless of table layout.Fixes #650
Test Plan
aarch64-linux-gnu-gcc -Wall -Wextra -Werror -DTARGET_BAREMETALacrosstest_pool/pcie/p004.candtest_pool/pcie/p005.cwith zero warnings and zero errors.-O0and-O2to confirmold_valueandrestore_pendingstack-slot reloads atexception_return:.git diff --checkpasses cleanly with no whitespace or style issues.