Repository navigation
honeykrisp: validate the existing Aurora capture/replay heap #18
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
Open
joshuaswarren
wants to merge
3
commits into
omacom:integration/aurora
Choose a base branch
from
joshuaswarren:aurora-va-check
base: integration/aurora
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d37ab98
honeykrisp: check a replayed buffer address against the capture range
joshuaswarren 462fa36
asahi: reserve capture replay addresses on older chips too
joshuaswarren 2e0f01a
asahi/tests: fill the ordinary VA heap and free every allocation in t…
joshuaswarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /* | ||
| * Copyright 2026 Joshua Warren | ||
| * SPDX-License-Identifier: MIT | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include "agx_bo.h" | ||
| #include "agx_device.h" | ||
| #include "agx_va_runtime_hole.h" | ||
|
|
||
| /* A user window like the one agx_open_device builds: 1 TiB of user VA. */ | ||
| #define USER_START 0x2000000000ull | ||
| #define USER_SIZE 0x10000000000ull | ||
| #define PAGE 16384ull | ||
|
|
||
| static unsigned failures; | ||
|
|
||
| #define CHECK(cond) \ | ||
| do { \ | ||
| if (!(cond)) { \ | ||
| fprintf(stderr, "%s:%d: CHECK failed: %s\n", __FILE__, __LINE__, \ | ||
| #cond); \ | ||
| failures++; \ | ||
| } \ | ||
| } while (0) | ||
|
|
||
| static struct agx_device * | ||
| open_va(void) | ||
| { | ||
| struct agx_device *dev = calloc(1, sizeof(*dev)); | ||
| simple_mtx_init(&dev->vma_lock, mtx_plain); | ||
| dev->guard_size = PAGE; | ||
| util_vma_heap_init(&dev->main_heap, USER_START, USER_SIZE); | ||
| dev->replay_heap_initialized = agx_capture_replay_heap_init( | ||
| &dev->main_heap, &dev->replay_heap, USER_SIZE, &dev->replay_start, | ||
| &dev->replay_size); | ||
| return dev; | ||
| } | ||
|
|
||
| static void | ||
| close_va(struct agx_device *dev) | ||
| { | ||
| util_vma_heap_finish(&dev->replay_heap); | ||
| util_vma_heap_finish(&dev->main_heap); | ||
| simple_mtx_destroy(&dev->vma_lock); | ||
| free(dev); | ||
| } | ||
|
|
||
| static bool | ||
| inside(const struct agx_device *dev, const struct agx_va *va) | ||
| { | ||
| return va->addr < dev->replay_start + dev->replay_size && | ||
| dev->replay_start < va->addr + va->size_B; | ||
| } | ||
|
|
||
| int | ||
| main(void) | ||
| { | ||
| struct agx_device *dev = open_va(); | ||
| CHECK(dev->replay_heap_initialized); | ||
| const uint64_t start = dev->replay_start, size = dev->replay_size; | ||
| const uint64_t end = start + size, sz = 4 * PAGE; | ||
|
|
||
| /* The range is carved out of the user window and is aligned. */ | ||
| CHECK(size == 64ull << 30); | ||
| CHECK(start >= USER_START && end <= USER_START + USER_SIZE); | ||
| CHECK(start % (1ull << 30) == 0); | ||
|
|
||
| /* Valid and invalid replay addresses. The guard counts as part of the | ||
| * allocation, and nothing may wrap. */ | ||
| CHECK(agx_va_capture_valid(dev, start, sz, PAGE)); | ||
| CHECK(agx_va_capture_valid(dev, end - sz - dev->guard_size, sz, PAGE)); | ||
| CHECK(!agx_va_capture_valid(dev, end - sz, sz, PAGE)); | ||
| CHECK(!agx_va_capture_valid(dev, end, sz, PAGE)); | ||
| CHECK(!agx_va_capture_valid(dev, start - PAGE, sz, PAGE)); | ||
| CHECK(!agx_va_capture_valid(dev, 0, sz, PAGE)); | ||
| CHECK(!agx_va_capture_valid(dev, UINT64_MAX - PAGE + 1, sz, PAGE)); | ||
| CHECK(!agx_va_capture_valid(dev, start + 4096, sz, PAGE)); | ||
| CHECK(!agx_va_capture_valid(dev, start, UINT64_MAX - 100, PAGE)); | ||
| CHECK(!agx_va_capture_valid(dev, start, size, PAGE)); | ||
| CHECK(!agx_va_capture_valid(dev, start, sz, 0)); | ||
|
|
||
| /* A fixed request inside the range works once, then the address is in use. | ||
| * One outside the range is refused without asserting. */ | ||
| struct agx_va *a = agx_va_alloc(dev, sz, PAGE, | ||
| AGX_VA_CAPTURE_REPLAY | AGX_VA_FIXED, | ||
| start + 8 * PAGE); | ||
| CHECK(a && a->addr == start + 8 * PAGE); | ||
| CHECK(!agx_va_alloc(dev, sz, PAGE, AGX_VA_CAPTURE_REPLAY | AGX_VA_FIXED, | ||
| start + 8 * PAGE)); | ||
| CHECK(!agx_va_alloc(dev, sz, PAGE, AGX_VA_CAPTURE_REPLAY | AGX_VA_FIXED, | ||
| end - PAGE)); | ||
| CHECK(!agx_va_alloc(dev, sz, PAGE, AGX_VA_CAPTURE_REPLAY | AGX_VA_FIXED, | ||
| UINT64_MAX - PAGE + 1)); | ||
| agx_va_free(dev, a, false); | ||
| a = agx_va_alloc(dev, sz, PAGE, AGX_VA_CAPTURE_REPLAY | AGX_VA_FIXED, | ||
| start + 8 * PAGE); | ||
| CHECK(a && a->addr == start + 8 * PAGE); | ||
| agx_va_free(dev, a, false); | ||
|
|
||
| /* Ordinary allocations never land in the range, even when the ordinary | ||
| * heap runs dry. The ordinary heap holds 960 GiB, so 4 GiB steps run it | ||
| * dry after about 240 successes; the cap only stops a runaway loop. */ | ||
| enum { MAX_FILL = 512 }; | ||
| struct agx_va *filled[MAX_FILL]; | ||
| unsigned n_filled = 0; | ||
| while (n_filled < MAX_FILL) { | ||
| struct agx_va *va = agx_va_alloc(dev, 4ull << 30, PAGE, 0, 0); | ||
| if (!va) | ||
| break; | ||
| CHECK(!inside(dev, va)); | ||
| filled[n_filled++] = va; | ||
| } | ||
| CHECK(n_filled >= 200 && n_filled < MAX_FILL); | ||
|
|
||
| /* With the ordinary heap dry, a small ordinary request either fails or | ||
| * lands outside the range, and an oversized one fails. */ | ||
| struct agx_va *small = agx_va_alloc(dev, sz, PAGE, 0, 0); | ||
| CHECK(!small || !inside(dev, small)); | ||
| agx_va_free(dev, small, false); | ||
| struct agx_va *big = agx_va_alloc(dev, 4 * USER_SIZE, PAGE, 0, 0); | ||
| CHECK(!big); | ||
|
|
||
| /* Replay buffers without an address come from the range, dry heap or not. */ | ||
| struct agx_va *r = agx_va_alloc(dev, sz, PAGE, AGX_VA_CAPTURE_REPLAY, 0); | ||
| CHECK(r && inside(dev, r)); | ||
| agx_va_free(dev, r, false); | ||
|
|
||
| for (unsigned i = 0; i < n_filled; ++i) | ||
| agx_va_free(dev, filled[i], false); | ||
|
|
||
| close_va(dev); | ||
|
|
||
| if (failures) { | ||
| fprintf(stderr, "%u checks failed\n", failures); | ||
| return 1; | ||
| } | ||
| puts("PASS: capture/replay address range"); | ||
| return 0; | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.