Repository navigation
Conversation
|
Hi @Qubitium! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
fbarchard
left a comment
There was a problem hiding this comment.
The root cause and fix look solid — aligning the Pass 1 L2 counting logic with Pass 2's sysfs override, adding bounds checks on both l2[l2_index] write sites (which #434 didn't cover), and adding a mock regression test while preserving #418's authorship all make sense.
A couple of things before merging:
- Rebase onto
main: Commit2ca65a8a(#434) addedif (l2 != NULL && l2_index < l2_count)on the shared-L2 pointer assignment insrc/arm/linux/init.c, which currently conflicts with this PR. Keeping thel2 != NULL && l2_index < l2_countguard consistently across both L2 write/assignment sites looks clean. - Test ordering fragility in
sysfs-l2-missing-arch: The new test pairs0xD87(Cortex-A725, group 0) with0xFFF(unknown, group 1) at the same frequency and expectsexpected_linux_ids = {1, 0}. That order only happens because Cortex-A725 isn't inmidr_score_core()insrc/arm/midr.hyet and falls through todefault: return 3, tying with0xFFFand falling back to thecluster_a > cluster_btie-break. Oncemidr_score_core()is updated to score Cortex-A725 (score 5), this test will flip to{0, 1}and fail. Using an already-scored core (e.g.0xD4DCortex-A715 with{0, 1}, or0xD05Cortex-A55 with{1, 0}) or a second unknown part (0xFFE) avoids that coupling.
Non-blocking follow-up note: when cpuinfo_arm_decode_cache() leaves temp_l2 zeroed and size comes solely from sysfs, temp_l2.line_size and temp_l2.partitions stay 0 so temp_l2.sets is never computed (and associativity stays 0 if ways_of_associativity isn't present). That still eliminates the OOB write here, though init-test's L2_CACHE.{valid_size, non_zero_line_size, reasonable_line_size} assertions would still fail on such a core unless sysfs coherency_line_size / fallback defaults are populated in a separate follow-up.
(cherry picked from commit a677f08)
The population pass appends an L2 entry whenever the core has an L3 or sysfs reports a per-core L2, but the array is sized by a separate counting pass that only consults sysfs when the decoder already reported a non-zero L2. If the two passes disagree, the write runs past the end of the array. Mirror the existing L3 handling: skip the write when the index is out of range, and only set the processor's cache pointer for an entry that was actually written.
Give both CPUs a per-core sysfs L2 and omit the architecture version for the unknown core. Verify that both L2 entries are present even though the cache decoder supplies no L2 for the unknown core. Pair it with an explicitly scored Cortex-A55 to keep the expected processor order stable.
9c25921 to
e6b885c
Compare
|
@fbarchard Applied the null and bounds checks at both L2 write sites, and switched the regression fixture to Cortex-A55, with both native Linux tests and all 10 ARM topology cases passing, including under AddressSanitizer for the topology cases. |
Problem
cpuinfo_arm_linux_init()sizes the L2 cache array in one pass and fills it in a second pass, and the two passes do not agree on which cores get an entry.The counting pass is gated on the decoded L2 size:
The population pass also accepts a sysfs L2, and does not bounds-check:
A core with a per-core L2 in sysfs but no decoded L2 is skipped while counting and appended while populating.
l2_indexruns pastl2_countand writes onestruct cpuinfo_cachepast thecalloc(l2_count, sizeof(struct cpuinfo_cache))block. Whenl2_countis 0 the write goes through a NULLl2.The L3 writes below are guarded (
if (l3_index < l3_count)). The L2 writes are not.Reproduction: LXD thin container on GB10
Host: NVIDIA GB10, aarch64, Ubuntu 26.04.1 LTS, kernel
7.3.1-gb10.The process ran in an LXD thin container whose cpuset was limited to 19 of the host's 20 CPUs.
lxcfsis mounted over/proc/cpuinfo,/proc/statand/sys/devices/system/cpu. It filters/proc/cpuinfoto the cpuset and renumbers the entries from 0, while/sys/devices/system/cpustill exposes all 20 host CPUs:Nothing is offline. The kernel view is consistent; only the container's
/proc/cpuinfois not.The renumbering is visible in the cluster layout. The host is four clusters of five:
0xd87)0xd85)0xd87)0xd85)The container's
/proc/cpuinforeports0xd87x4,0xd85x5,0xd87x5,0xd85x5 for processors0-3,4-8,9-13,14-18. The first block lost an entry, so processorNdescribes host CPUN+1.Host CPU 19 therefore has no
/proc/cpuinfoentry: the decoder reports no L2 for it andarchitecture_versionstays 0. The counting pass yieldsl2_count = 18; the population pass writes 19 entries.Valgrind on the process:
Visible symptom on this machine:
import torchaborts withmalloc(): corrupted top size. This happens before CUDA initializes, and reproduces with both CUDA and CPU-only wheels.The trigger is any
/proc/cpuinfothat is a strict subset of the CPUs in/sys/devices/system/cpu, which includes any container cpuset that is not all host CPUs.Note on current
main#438propagatesarchitecture_versionfrom the cluster leader, so on this host the decoder now returns a generic L2 for CPU 19 and both passes agree (19/19, valgrind clean). The pass asymmetry and the unguarded writes are unchanged, so the overflow remains reachable where a core gets a sysfs L2, no decoded L2, and no inherited architecture (e.g.arch_version < 7, or a cluster whose leader also lacks an identity).Reproduction in the mock harness
New
sysfs-l2-missing-archtopology intest/mock/arm-linux-topology.cc: every CPU advertises a per-core L2 in sysfs, and one CPU has noCPU architectureline and no cluster sibling to inherit one from.Without the fix:
With the fix: 3/3 pass, valgrind 0 errors.
Fix
fix out-of-bounds l2 cache write in cpuinfo_arm_linux_init— cherry-picked from fix out-of-bounds l2 cache write in cpuinfo_arm_linux_init #418, authorship preserved. The counting pass applies the same sysfs override the population pass already applies, sol2_countmatches the number of entries written.arm/linux: bounds-check the L2 cache writes— mirror the L3 handling: skip out-of-range writes, and only set the processor's cache pointer for an entry that was written.test/mock: cover a sysfs L2 with no decoded L2— thesysfs-l2-missing-archtopology above.Difference from #418
src/arm/linux/init.csrc/arm/linux/init.c,test/mock/arm-linux-topology.cc,CMakeLists.txtPR #418 has the right root cause and a correct counting fix, but leaves the unguarded write and ships no test, so any future divergence between the passes reintroduces the same silent heap corruption. Commits 2 and 3 here also apply cleanly on top of it if it lands on its own.
How to run the test
The topology tests are gated on
CMAKE_SYSTEM_NAME STREQUAL "Android", so on Linux/aarch64 build the harness directly:Existing modes (
pixel-8,pixel-9,pixel-10,missing-midr,frequency-groups,unknown-parts,mixed-caches) still pass.