nvme namespace attach and detach ioctls are not safe with concurrent access
The ioctls for attaching and detaching nvme namespaces are not thread safe.
If more than a single thread are to run through nvme_ioctl_attach() concurrently, there would certainly be race conditions exposed in the execution through nvme_init_ns() as well as the freeing of kmem. It would also be prudent, to serialise with nvme_ioctl_detach().
There is nm_mutex which is used for serialising exclusive access through nvme_opem()/close(). It makes sense to ex_tend the use of this.