nmount(2) returns undocumented EDEADLK

From: Gleb Popov <arrowd_at_freebsd.org>
Date: Mon, 06 Dec 2021 07:13:59 UTC
Hey hackers.

I have a little program that calls the nmount(2) function in the following
way:

- First it mounts nullfs with fstype="nullfs", from="/src" and
fspath="/dst". This works fine.
- Next it tries to remount it as readonly by adding MNT_UPDATE and
MNT_RDONLY to the nmount(2) call. This call fails with errno=11 (EDEADLK)
for some reason.

The relevant part of kdump:

 19909 coolmount CALL  nmount(0x801610380,0x6,0<><invalid>0)
 19909 coolmount NAMI
 "/var/db/collaboraonline/child-roots/hQN4KQVIpWNA7Pic"
 19909 coolmount NAMI
 "/var/db/collaboraonline/child-roots/hQN4KQVIpWNA7Pic"
 19909 coolmount NAMI  "/var/db/collaboraonline/systemplate"
 19909 coolmount RET   nmount -1 errno 11 Resource deadlock avoided

Does anyone have an idea what's wrong with this? I can try coming up with
minimal repro if needed.

Thanks in advance.