Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Run redroid on kernels without dma_heap, PSI or CONFIG_COMPAT (OrbStack, Alpine, ...) - #940

Open
gauravsuman007 wants to merge 2 commits into
remote-android:masterfrom
gauravsuman007:feature/no-kernel-deps
Open

gauravsuman007 wants to merge 2 commits into
remote-android:masterfrom
gauravsuman007:feature/no-kernel-deps

Conversation

@gauravsuman007

@gauravsuman007 gauravsuman007 commented Oct 27, 2026 •

Copy link
Copy Markdown

Problem

On some Docker hosts redroid fails even though binder is available. OrbStack on macOS is the most common one:

  • 12 / 13 exit within a second (exit code 129). Init aborts with Unable to set adequate mmap entropy value! because the kernel has no CONFIG_COMPAT, so /proc/sys/vm/mmap_rnd_compat_bits doesn't exist.
  • 14 shows a black screen, stuck on FallbackHome. There's no PSI (/proc/pressure), so lmkd exits ("Kernel does not support memory pressure events or in-kernel low memory killer"), init restarts it forever, and sys.boot_completed is never set.
  • All versions have no Codec2 encoders without DMA-BUF heaps, so scrcpy can't stream (same as [server] INFO: List of video encoders: (none) #407).
  • On Alpine, 14 also exits right after start: Alpine locks kernel.unprivileged_bpf_disabled = 1, so bpfloader's write of 0 fails, and the service is reboot_on_failure.

Changes

A new nokernel/ directory works around these from userspace, using only docker run flags and no image rebuild:

  • entry.sh runs before /init (static busybox). When PSI is missing it fakes /sys/module/lowmemorykiller/parameters/{minfree,adj}, so lmkd runs in legacy in-kernel mode. Each fix applies only if the kernel needs it.
  • patch-binaries.py makes copies of init (12/13) and bpfloader (14) use files under /dev instead of mmap_rnd_compat_bits / unprivileged_bpf_disabled in /proc. A fake under /proc doesn't survive, because init mounts a fresh procfs. run.sh mounts each patched binary only when the host needs it, so on Alpine the host keeps unprivileged BPF disabled.
  • dmaheap-shim/ is a small freestanding LD_PRELOAD library. It answers DMA_HEAP_IOCTL_ALLOC when the kernel can't, using a memfd turned into a real dma-buf via /dev/udmabuf when possible, and a plain memfd otherwise. It's preloaded into media.swcodec and adbd (so scrcpy's server gets it). It builds with stock clang, no NDK.
  • prepare.sh / run.sh wrap it all up. The README gets a troubleshooting pointer.

Binder is still required. nokernel/README.md documents which hosts have it (Docker Desktop's LinuxKit kernel and Debian's cloud kernels don't).

Testing

redroid/redroid:{12,13,14}.0.0_64only-latest, arm64:

Host Stock image With nokernel/run.sh
OrbStack (kernel 7.0) 12/13 exit, 14 never boots boot in 6–10 s, scrcpy H.264 + Opus recorded
Debian 13 (linux-image-arm64, binder_linux) boots, no encoders boot in 6–8 s, scrcpy H.264 + Opus recorded; buffers are real dma-bufs via udmabuf
Alpine 3.23 (linux-lts 6.18, binderfs built in) 14 exits (BPF sysctl) 12 and 14 boot in 6–10 s, scrcpy H.264 + Opus recorded. 13 crash-loops in system_server on this kernel, with the stock image too (noted in the README)

Possible follow-ups in the images

  • Set up the lowmemorykiller fallback in init.redroid.rc.
  • Backport the 14 init check for mmap_rnd_compat_bits to 12/13.
  • Don't make bpfloader fatal when the unprivileged_bpf_disabled write fails.
  • Support HAL_PIXEL_FORMAT_BLOB in gralloc.redroid. With debug.stagefright.c2-poolmask=0xB0000, Codec2 would then need no dma-buf at all.

These would make most of nokernel/ unnecessary.

On kernels like OrbStack's, redroid 12/13 exit right away (init aborts
without /proc/sys/vm/mmap_rnd_compat_bits), 14 never finishes booting
(lmkd exits without PSI, boot sticks on FallbackHome) and every version
lacks Codec2 encoders without DMA-BUF heaps.

Add userspace workarounds that need only docker run flags:
- entry.sh runs before /init and fakes the in-kernel lowmemorykiller
  sysfs files when PSI is missing
- patch-init.py makes 12/13 init read mmap_rnd_compat_bits from /dev
- dmaheap-shim is an LD_PRELOAD library that serves DMA_HEAP_IOCTL_ALLOC
  from memfds, as real dma-bufs via udmabuf when available, preloaded
  into media.swcodec and adbd

Tested with 12/13/14 64only images on OrbStack and Debian 13: boot and
scrcpy H.264 + Opus work. Binder is still required.
Alpine sets kernel.unprivileged_bpf_disabled = 1, which the kernel won't
change until reboot. Android 14's bpfloader writes 0 there, fails, and
init reboots because the service is reboot_on_failure, so the container
exits right after start.

Replace patch-init.py with patch-binaries.py, which also points a copy of
bpfloader at /dev/.nk-vm/. entry.sh provides the file and run.sh mounts
the patched binary only when the host value is locked to 1, so the host
keeps unprivileged BPF disabled. 12/13 bpfloader doesn't touch the sysctl
and is left alone.

Tested on Alpine 3.23 linux-lts 6.18 (12 and 14 boot, scrcpy H.264 + Opus)
and re-checked on Debian 13 (13 and 14). redroid 13 crash-loops in
system_server on that Alpine kernel even with the stock image; noted in
the README.
@gauravsuman007 gauravsuman007 changed the title Run redroid on kernels without dma_heap, PSI or CONFIG_COMPAT (e.g. OrbStack) Run redroid on kernels without dma_heap, PSI or CONFIG_COMPAT (OrbStack, Alpine, ...) Oct 27, 2026
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.

1 participant