Skip to content

test(uffd): unregister UFFD range before fd close in cross-process cleanup#2476

Merged
ValentaTomas merged 1 commit intomainfrom
feat/uffd-unregister-cleanup
Apr 22, 2026
Merged

test(uffd): unregister UFFD range before fd close in cross-process cleanup#2476
ValentaTomas merged 1 commit intomainfrom
feat/uffd-unregister-cleanup

Conversation

@ValentaTomas
Copy link
Copy Markdown
Member

Summary

Split out from the feat/free-page-reporting branch as a small, standalone preparatory PR.

  • Adds unregister() helper in fd_helpers_test.go that wraps UFFDIO_UNREGISTER.
  • Calls it from the late `cmd.Wait()` cleanup in `configureCrossProcessTest`, before the early `uffdFd.close()` cleanup runs (cleanups are LIFO).

Why now (and why it's safe to land alone)

Today this is a no-op: no test enables `UFFD_FEATURE_EVENT_REMOVE`, so the kernel never queues REMOVE events that could keep `munmap` blocked on un-acked events against a still-registered range.

Once the follow-up REMOVE-handling PR enables that feature, missing this cleanup would manifest as flaky hangs in test teardown rather than as an obvious failure. Landing the cleanup first means that follow-up PR doesn't silently bring along a behavioural test-cleanup change alongside the production logic.

Diff

`+23 / -0` across 2 files, both `_test.go`.

Test plan

  • `go build ./...`
  • `golangci-lint run ./pkg/sandbox/uffd/userfaultfd/...` — 0 issues
  • `go test ./pkg/sandbox/uffd/userfaultfd/... -count=1` — pass

…eanup

Add an unregister() helper around UFFDIO_UNREGISTER and call it from the
late cmd.Wait() cleanup in configureCrossProcessTest, before the early
uffdFd.close() cleanup runs (cleanups are LIFO).

Today this is a no-op: no test enables UFFD_FEATURE_EVENT_REMOVE, so the
kernel never queues REMOVE events that could keep munmap blocked on
un-acked events against a registered range. Pulling this out as its own
small change so the upcoming PR that does enable REMOVE events doesn't
silently bring along a behavioural test-cleanup change too.
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 21, 2026

PR Summary

Low Risk
Low risk: test-only cleanup change, but it introduces an extra UFFDIO_UNREGISTER ioctl that could fail on unsupported kernels or if the range/FD state is unexpected during teardown.

Overview
Ensures cross-process userfaultfd tests explicitly call UFFDIO_UNREGISTER to tear down the registered address range during cleanup (before the FD is closed), preventing potential teardown hangs from queued/unacked REMOVE events in future tests that enable REMOVE notifications.

Reviewed by Cursor Bugbot for commit a0522c3. Bugbot is set up for automated code reviews on this repo. Configure here.

@ValentaTomas ValentaTomas marked this pull request as ready for review April 21, 2026 22:56
@ValentaTomas ValentaTomas enabled auto-merge (squash) April 21, 2026 22:59
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — test-only, no production code changes, and the cleanup ordering logic is correct.

Extended reasoning...

Overview

Changes are confined to two _test.go files in packages/orchestrator/pkg/sandbox/uffd/userfaultfd/. Adds an unregister() helper wrapping UFFDIO_UNREGISTER (mirroring the existing register() pattern) and calls it in the LIFO cleanup chain before uffdFd.close().

Security risks

None. These are test helpers with no impact on production paths, authentication, or data handling.

Level of scrutiny

Low. The diff is +23/-0 in test files only, mechanically mirrors the existing register() implementation, and is currently a no-op (no test enables UFFD_FEATURE_EVENT_REMOVE). The LIFO ordering reasoning is sound and well-documented.

Other factors

No bugs found, no outstanding reviewer concerns to address. The preparatory-PR rationale (isolating cleanup logic from the follow-up REMOVE-handling change) is sensible engineering hygiene.

@ValentaTomas ValentaTomas merged commit 3e48cb3 into main Apr 22, 2026
49 checks passed
@ValentaTomas ValentaTomas deleted the feat/uffd-unregister-cleanup branch April 22, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants