Page MenuHomeFreeBSD

LinuxKPI: preserve shmem backing ownership for managed PFN mappings
Needs ReviewPublic

Authored by oleglelchuk_gmail.com on Mon, Sep 7, 2:32 PM.
Tags
None
Referenced Files
F170937120: D59481.diff
Mon, Sep 7, 5:41 PM
F170929271: D59481-PUBLIC-DIFF-VERIFICATION.json
Mon, Sep 7, 4:24 PM
F170929124: D59481.diff
Mon, Sep 7, 4:23 PM
F170929006: D59481-EXPORT-VALIDATION.json
Mon, Sep 7, 4:22 PM
F170929005: D59481-EVIDENCE.md
Mon, Sep 7, 4:22 PM
F170921438: D59481.diff
Mon, Sep 7, 2:55 PM
F170920053: D59481.diff
Mon, Sep 7, 2:38 PM

Details

Reviewers
None
Group Reviewers
linuxkpi
Virtual Memory
Summary

A recorded FreeBSD/i915 buffer lifetime showed a still-live graphics buffer losing its original nonzero backing contents across page retirement and reacquisition. Replacement backing was zero-filled before a later submission. Source analysis identifies a path that transfers pages out of the original shmem object. The recorded loss is consistent with that ownership transfer; exact GPU instruction fetch and a matched single-change causal comparison have not been established.

On my Intel Meteor Lake laptop, my experience with large LAN downloads has been:

  • Non-PFN kernels with my manual ZFS ARC cap removed: I have experienced a recoverable GPU hang in every attempt, using either Sway or Plasma.
  • Non-PFN kernels with the 4 GiB ARC cap: I have not experienced this hang under that usage pattern.
  • PFN kernels with my manual ARC cap removed: I have not experienced this hang under the same general usage pattern.

These are my personal observations. I have not supplied a formal trial count or performed a matched, single-change kernel comparison. The first result describes all of my attempts, not a universal 100% failure probability. The affected desktop can be recovered by terminating the compositor; these failures are not kernel panics. Here, "uncapped ARC" means automatic ARC sizing with a finite effective maximum.

The cap comparison supports memory reclamation or its timing as a possible condition exposing the ownership defect. There is a concrete source-level route: FreeBSD low-memory notifications invoke registered LinuxKPI shrinkers; the i915 shrinker can release eligible graphics-buffer pages. FreeBSD's ARC implementation also responds to low-memory notifications. A larger resident ARC can leave less immediately available memory and change the demand for reclaim. This is a plausible route from the cache-size difference to a buffer release, not a recorded call trace identifying the caller that released the affected buffer.

The capture established that a still-live buffer's nonzero backing page was retired and the same logical buffer later acquired zero-filled replacement backing before submission. It did not require an operation that overwrote the old physical page with zeros. The source-level ownership transfer is consistent with loss of recoverable contents across that transition. The working explanation is that the 4 GiB cap avoids or changes the problematic release/reacquisition sequence in my workload, while the PFN change preserves backing ownership when that sequence occurs. The cap does not repair the ownership logic.

The caller that initiated this buffer's release remains unidentified, and the GPU's subsequent instruction fetch was not observed. The later ARC/VM sample in

, including no recorded swap I/O and free pages above the target, does not reconstruct conditions at retirement or exclude earlier reclamation. I have used "memory pressure" informally; neither the downloads nor that later sample establish its precise state at the content-loss transition.

Preserve managed OBJT_SWAP/shmem pages in their backing object and supply exclusively busy pages through an external device-pager handoff. Retain references to tracked backing owners until VMA teardown, consume each handed-off page once, and invalidate mappings without removing supported pages from their original backing object. The change also balances temporary requested-page holds, delays their publication until the required operations succeed, and rejects selecting a page already held by the same population transaction.

The pager interface makes memory-locking behavior explicit. Managed LinuxKPI IO/PFN mappings opt into a user-wiring exemption before object publication. Ordinary mappings retain their locking requirements. Kernel-origin wiring retains its separate requirements, and conservative resource-limit admission and RACCT reservations still apply. The manual changes document this policy and correct an inherited statement about per-process limits.

The patch is a candidate correction for the observed managed-shmem path. Other managed backing-owner types retain legacy transfer behavior. Invalidation covers tracked owner intervals and can revoke aliases beyond the requested VMA subrange. References to previously used owners remain until VMA teardown. Review is requested on these lifetime, invalidation, pager-interface and memory-locking decisions.

The source patch contains the PFN/VM changes, their manuals, and a kernel interface version marker. Local diagnostic instrumentation and unrelated laptop changes are excluded. Kernel/module pager interfaces change and require compatible kernel and module builds.

The __FreeBSD_version bump from 1600024 to 1600025 is provisional for this review. The accepting committer must confirm or adjust the final number against the landing tree and add the corresponding Porter's Handbook version entry with the actual commit identity. This review does not reserve an official version number. The manual pages retain their base dates until merge.

Related work

  • D32090 already discussed the risk of shared-memory contents being lost when pages move between objects. This submission makes no claim to have first identified that hazard.
  • drm-kmod issue 481 and Bugzilla 296448 report related PFN insertion failures. The proposed mapped-page handling change in issue 481 still removes pages from their original object, and subsequent feedback reports rendering corruption and GPU hangs. Whether those reports contain the exact locally recorded lifetime failure remains unverified.
  • drm-kmod PR 484 questions the existing ownership model and proposes exporter-provided VM objects for dma-buf mmap, primarily for udmabuf. That is relevant design work with which this proposal may need coordination.

The public-source comparison has not established an equivalent implementation or the absence of one. Direction toward an existing review or preferred mapping design would be welcome.

This patch and supporting analysis were developed with AI assistance. Independent maintainer review of the implementation and design is requested.

Test Plan

Completed checks of this revised 12-file export, based on pristine FreeBSD main commit 661d1135e4ed12d6017220ea654ae67a6956dc73 (pinned September 7, 2026):

  • Actual application to an independent temporary Git index initialized from that base, application and whitespace checks, and actual reverse application returning the identical pristine base tree.
  • All nine PFN kernel/header postimages are byte-identical to the previously checked local export. Both manual postimages differ only by restoration of their base document dates. The additional sys/sys/param.h change supplies the provisional interface version boundary.
  • Both revised manuals pass mandoc -Tlint without output.
  • The downloaded public diff 186141 was actually applied against the pinned pristine base after upload. All twelve resulting files and the complete result tree match the prepared export; actual reverse application returns the pristine base tree.

Existing local pfnmap11 validation, performed before this export:

  • Recorded kernel build/boot identity and source checks; offline producer, handoff, invalidation, consumer and memory-locking checks with mocked VM dependencies. These offline checks do not establish actual kernel scheduler, reclaim or pmap behavior.
  • Twenty-five distinct live API cases covering the documented locking/accounting behavior. These are not twenty-five independent reproductions of the backing-loss failure. The evidence attachment lists the coverage groups and explains an accounting test-controller correction.
  • A completed diagnostic recording with 74 preservation cycles across 30 distinct objects and no recorded comparison mismatch. Observations use page checksums and 24 sampled bytes; 46 cycles are zero-compatible. All 374 tracked lifetimes closed in that recording.
  • My observations with large LAN downloads cover three configurations: a recoverable Sway or Plasma hang in every non-PFN attempt with my manual ARC cap removed; no such hang on non-PFN kernels with the 4 GiB ARC cap; and no such hang on PFN kernels with my manual cap removed. I have not supplied a formal trial count. These are personal observations, not a matched single-change comparison. The proposed role of the source-level reclaim route described in the Summary is a hypothesis for how the ARC-cap difference exposes the defect, not a recorded call trace or a measurement of memory pressure at the content-loss transition.

The exact exported sources on the stated newer base have not received a new full kernel/module build or boot validation. Whole-buffer preservation, exact GPU instruction fetch, every internal reference lifetime and correctness under all kernel interleavings are not established. Live kernel-concurrency validation and a matched causal comparison remain unperformed.

Public supporting evidence:

  • Historical environment, artifact identities, recorded failure and later ARC/VM sample, API coverage, preservation counts, limitations, and revised-export summary:
  • Revised-export application checks and per-file hashes:
  • Post-upload public-diff and attachment verification: . The patch checksum in the evidence and export manifest identifies the submitted raw Git file. Phabricator reformats diff metadata, so this verification records the separate public-download checksum and confirms identical resulting source contents.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

oleglelchuk_gmail.com created this object with edit policy "Administrators".

Because an LLM wrote the patch, summary, and test plan, you can see things such as "The user reports", instead of "I noticed" while reading all this stuff.

oleglelchuk_gmail.com edited the summary of this revision. (Show Details)
oleglelchuk_gmail.com edited the test plan for this revision. (Show Details)

Clarification of my earlier comment: descriptions of my own desktop experience now use the first person. The patch, technical analysis, summary and test plan remain AI-assisted and are submitted for independent maintainer review.

This update adds explicit LinuxKPI and Virtual Memory review requests, a provisional kernel interface version bump, corrected manual-date handling, and a public evidence summary. It records my repeated non-PFN/PFN desktop observations without treating "memory pressure" as a measured explanation or claiming a matched causal comparison.

Historical evidence and current export summary:


Export validation and per-file hashes:

oleglelchuk_gmail.com edited the test plan for this revision. (Show Details)