> +int vfio_device_io_remap_mapping_range(struct vfio_device *device, > + loff_t start, loff_t len) > +{ > + struct address_space *mapping = device->inode->i_mapping; > + int ret = 0; > + > + i_mmap_lock_write(mapping); > + if (mapping_mapped(mapping)) { > + struct rb_root_cached *root = &mapping->i_mmap; > + pgoff_t pgstart = start >> PAGE_SHIFT; > + pgoff_t pgend = (start + len - 1) >> PAGE_SHIFT; > + struct vm_area_struct *vma; > + > + vma_interval_tree_foreach(vma, root, pgstart, pgend) { There is no need for the mapping_mapped check here, vma_interval_tree_foreach will the right thing for an empty tree. That also allows to move a few more instructions out of the lock. > + /* > + * Force NOFS memory allocation context to avoid > + * deadlock while we hold i_mmap_rwsem. > + */ > + flags = memalloc_nofs_save(); Please move this out of the loop. > +extern int vfio_device_io_remap_mapping_range(struct vfio_device *device, > + loff_t start, loff_t len); No need for the extern.