Re: [RFC PATCH v7 00/26] userland: Userland containers
From: Jarkko Sakkinen
Date: Tue Nov 24 2026 - 13:35:52 EST
On Tue, Nov 24, 2026 at 10:58:55AM +0200, Jarkko Sakkinen wrote:
> > https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/log/?h=vault
>
> The key function to look up from here is spawn_userland_container():
>
> https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd-test.git/tree/br2-external/patches/systemd/0010-nspawn-Start-containers-in-an-experimental-userland.patch?h=main
>
> It demonstrates an initialization flow that ends up cleanly with
> clone(). userland_share_host_ns() demonstrates the ioctl I added
> previous week i.e., USERLAND_SHARE_NSFD, which is used to punch those
> host namespaces that the guest actually needs. This is the allow-list
> part, which is usually the favorable principle over deny-list.
This proves that bootstrap ends with clone3(CLONE_INTO_USERLAND), which
the most important property to prove at first.
The second part is "hotpluggability" property (hmm... is that even a
word). I have early local patches for this but they ares still unpushed.
I need to test this again with real hardware as I did in ad-hoc manner
previously. I don't think QEMU is acceptable for this alone.
However, it is not really rocket science with these tools, and it would
require effort to get these completely wrong, especially if they are
stressed even slightly with bare-metal hardware:
nspawn: Hotplug device nodes into userland containers via udev
Defer absent /dev bind sources when starting a container in a userland,
keep the userland mount namespace fd open in the supervisor, and attach
an sd_device_monitor to the supervisor event loop. When matching device
nodes or optional API devices appear, update the container scope's
DeviceAllow= property, populate the dev node and /dev/{char,block}
symlink via its root fd, and attach the device mount with
MOVE_MOUNT_T_MNTNS.
machined: Allow bind mounts on user-namespaced containers
When experimental support is enabled, bind_mount_in_namespace() attaches
mounts via MOVE_MOUNT_T_MNTNS without entering the target's namespaces
and refuses to fall back to namespace_fork() for foreign user
namespaces.
mount-util: Attach live namespace mounts with MOVE_MOUNT_T_MNTNS
When experimental support is enabled, create missing target mountpoints
through the target's root fd and attach bind mounts and dissected images
directly into the target mount namespace fd instead of forking a
setns() helper process. Fall back to namespace_fork() when the kernel
does not support MOVE_MOUNT_T_MNTNS.
They are variation of the same pattern, and pretty obvious even from the
descriptions. When they are known to work, I'll push them.
Br, Jarkko