Skip to content

drm/asahi: GEM_USERPTR in processes with a smaller page size - #2226

Merged
DjDeveloperr merged 2 commits into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/asahi-userptr-subpage
Nov 19, 2026
Merged

DjDeveloperr merged 2 commits into
aurora-silicon:integration/aurorafrom
jgoyvaerts:m4pro/asahi-userptr-subpage

Conversation

@jgoyvaerts

Copy link
Copy Markdown
Contributor

GEM_USERPTR (#1609) pins its range with pin_user_pages_fast(). In a process whose user page size is smaller than the native one (CONFIG_MM_SUBPAGE: 4K processes on a 16K kernel, such as everything running under FEX), GUP cannot return pages. So every GEM_USERPTR fails with EOPNOTSUPP, and VK_EXT_external_memory_host imports fail there.

Such a process maps each of its pages to a fragment of a native page, and pin_user_fragments_remote() pins those. The GPU maps native pages, so a native page can back the object only where the process maps all of it: its fragments in order, at consecutive addresses. Then the GPU sees exactly what the CPU sees, and nothing the process does not map.

user_pages.c pins the range as fragments and checks that layout, all or nothing. It returns EFAULT where a native page is not mapped whole and in order. The fragment records hold the pins and are released with the object. pinned_vm counts native pages, as for other processes. Processes with the native page size keep pin_user_pages_fast().

The uAPI documentation of drm_asahi_gem_userptr now states the layout rule. This is a comment only; no struct, flag or value changes.

The second commit adds tools/testing/selftests/arm64/user4k/gem-userptr.c. It runs in a 4K process and submits no GPU work:

  • A 32K range whose 16K pages are each mapped whole and in order pins 32K in VmPin until the object is closed.
  • A 16K page with one 4K page moved in from elsewhere fails with EFAULT and leaves VmPin unchanged.
  • So does a 16K page with two of its own 4K pages swapped. This is the case only the order check catches.

Tested on the J616s (M4 Pro, 16K kernel)

  • dEQP and imports: dEQP-VK.*external_memory_host* gave 5 pass, 8 not supported, 0 fail. Host-pointer imports worked from a native process and from a FEX 4K process, including memory write-protected through userfaultfd (with mm: populate a subpage window's uffd-wp markers with the faulting page #2225's mm fix). The refusal path leaked no pins. 0 GPU recoveries.
  • The selftest:
    ok 1 native pages mapped whole and in order
    ok 2 a 4K page from elsewhere in a native page
    ok 3 a native page mapped out of order
    # Totals: pass:3 fail:0 xfail:0 xpass:0 skip:0 error:0
    
  • In use: this has run in our daily kernels since 11-16.

On this branch: KUnit 696 of 697 passed, one skipped (needs CONFIG_UCLAMP_TASK). tools/asahi/run-host-tests.py --only g17 passed 90/90. drivers/gpu/drm/asahi/ builds with W=1 and no new warnings.

Not done

  • The M4 Pro is the only SoC tested.
  • Layouts that fail: native pages that a 4K process maps scattered fail with EFAULT. That includes the zero page, and private copies that landed in arbitrary COW-pool slots. For memory written before import, mm: populate a subpage window's uffd-wp markers with the faulting page #2225 keeps uffd-wp-before-touch windows whole.
  • A related gap in mm/gup.c, not touched here: a read-only long-term pin through follow_subpage_fragment() takes the shared zero page. Native GUP unshares it first.

🤖 Generated with Claude Code

GEM_USERPTR pins its range with pin_user_pages_fast(). In a process
whose user page size is smaller than the native one (CONFIG_MM_SUBPAGE,
user4k: 4K processes on a 16K kernel, such as everything running under
FEX), GUP cannot return pages, and every GEM_USERPTR fails with
EOPNOTSUPP, so VK_EXT_external_memory_host imports fail there.

Such a process maps each of its pages to a fragment of a native page,
and pin_user_fragments_remote() pins those. The GPU maps native pages,
so a native page can back the object only where the process maps all
of it, its fragments in order at consecutive addresses: then the GPU
sees exactly what the CPU sees, and nothing the process does not map.
user_pages.c pins the range as fragments and checks that layout, all
or nothing (EFAULT where a native page is not mapped whole and in
order). The fragment records hold the pins and are released with the
object; pinned_vm counts native pages, as for other processes.
The GEM_USERPTR uAPI documentation states the layout requirement.

Processes with the native page size keep pin_user_pages_fast().

Tested on an M4 Pro: see the userptr probe in the cover note (native
16K and userpages 4k).

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Assisted-by: LLM
gem-userptr re-executes itself as a 4K process and imports anonymous
32K ranges with DRM_IOCTL_ASAHI_GEM_USERPTR on the GPU render node,
without submitting GPU work. A range whose 16K pages are each mapped
whole and in order pins 32K in VmPin until the object is closed. A 16K
page with one 4K page moved in from elsewhere, or with two of its own
4K pages swapped, fails with EFAULT and leaves VmPin unchanged.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Assisted-by: LLM
@DjDeveloperr
DjDeveloperr merged commit 4c297ac into aurora-silicon:integration/aurora Nov 19, 2026
1 check passed
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.

2 participants