Repository navigation
Conversation
getPgoInstrumentationResultsInstance re-laid out the schema starting at offset 0, while the writer (allocPgoInstrumentationBySchemaInstance) and all other readers lay it out starting at countsOffset. countsOffset is only size_t aligned, so on 32-bit platforms 8-byte aligned entries (for example ValueHistogram) were placed differently. The copy then read past the end of the allocation, causing an AV when it ended on a page boundary, and the JIT saw counts at the wrong offsets. Fixes #134695 Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @agocke |
Revert the reader-side rebasing and instead make countsOffset a multiple of the largest entry alignment (8). Entry layout is relative to the data region, so with countsOffset only size_t aligned, 32-bit layouts depended on where the schema prefix ended. That broke getPgoInstrumentationResults- Instance (lays out from 0) and the text-format loader (lays out from 0, then shifts by countsOffset). No change on 64-bit, where countsOffset was already a multiple of 8. Co-authored-by: Copilot App <[email protected]>
|
@EgorBo, on #135515 you mentioned fixing this at the cause rather than the symptom. This PR now does that in the allocator: Note This comment was drafted with GitHub Copilot. |
|
I think this is basically the same band-aid rather than a complete fix. The root cause is that value probing requested 8-byte alignment on 32-bit even though it never actually needed it. As a fix, I think we can make ValueHistogram always 32-bit (and hence 4-byte aligned). It's currently only used for small integers anyway (e.g. memmove's length), so we can just truncate the value to 32 bits. It's not a correctness issue if the length is ever bigger, and that's unlikely to happen in practice anyway. As a bonus, the histograms take up less space. This might require a MIBC format version bump. I'm OOF until 11/16, so cc @dotnet/jit-contrib |
|
Closing in favor of @EgorBo's approach (making Note This comment was drafted with GitHub Copilot. |
This PR uses @EgorBo's fix from #136890 ([comment](#136890 (comment))); his commit is cherry-picked as-is. `ValueHistogram` asked for 8-byte entries and alignment it never needed. On 32-bit it was the only 8-byte-aligned kind the JIT emits. The VM lays out the schema from `countsOffset` (only 4-byte aligned) but reads it back from offset 0, so the two layouts disagreed and the copy read 4 bytes past the end of the buffer. Value histograms are now 32-bit on all targets. Replaces #135515 and #136890. A second commit fixes MIBC merging. An old (0x242) and a new (0x241) value histogram at the same IL offset were treated as the same entry, so depending on order the merge threw or kept the stale one. It now keeps the new entry. **Follow-ups / impact** - Value-histogram records in existing MIBC and R2R data are ignored until retrained. They don't crash. - `MibcConfig.FormatVersion` is now 1.1. Only `dotnet-pgo merge` checks it, with a warning. - The JIT-EE GUID bump means SuperPMI collections need refreshing. - Truncating values to 32 bits is safe: the importer only uses a profiled value after a full-width range check. - release/9.0 and release/10.0 have the same bug; servicing is up to the maintainers. **Validation (osx-arm64):** the checked CLR build passed, and all 5 `src/tests/JIT/PGO` tests passed. A TieredPGO app recorded correct 32-bit samples, and Tier1 used them for the profiled memmove/SequenceEqual guard. Not run: x86 and SuperPMI. Resolves #134695 > [!NOTE] > This PR description was generated with GitHub Copilot. --------- Co-authored-by: Egor Bogatov <[email protected]> Co-authored-by: Copilot <[email protected]> Copilot-Session: fe9884cc-3de1-4d09-82cd-e2e2869df043
PGO entry offsets are laid out relative to the start of the data region, but
countsOffset(the end of the compressed schema prefix) was only aligned tosize_t. On 32-bit targets, 8-byte-aligned entries such asValueHistogramtherefore landed at positions that depended on the schema size, and code that lays out the schema from 0 disagreed with the writer:getPgoInstrumentationResultsInstancere-laid out the schema from 0 and copied fromcountsOffset. It read counts at shifted offsets and up to 4 bytes past the allocation, causing an AV when the allocation ended on a page boundary. Two Windows x86 Helix dumps show this:countsOffset12,ValueHistogramIntCount+ 32 ×ValueHistogram, and a 260-byte block read as 264.countsOffset, while its reader re-lays out fromcountsOffset.Aligning
countsOffsetto the largest entry alignment (8) makes the layout independent of the schema size, so all of these agree. There's no change on 64-bit, wherecountsOffsetwas already a multiple of 8. The bug is present in release/9.0 and release/10.0.This replaces the reader-side rebasing in the first commit (also the approach of #135515).
Resolves #134695
Note
This PR was drafted with GitHub Copilot.