nutanix / libvfio-user

framework for emulating devices in userspace
BSD 3-Clause "New" or "Revised" License
162 stars 51 forks source link

libvfio-user responds with duplicated FD in get_region_info when sparse maps is used #711

Open tmakatos opened 1 year ago

tmakatos commented 1 year ago

In dev_get_caps:

        for (i = 0; i < nr_mmap_areas; i++) {
            struct iovec *iov = &vfu_reg->mmap_areas[i];

            vfu_log(vfu_ctx, LOG_DEBUG, "%s: area %d [%p, %p)", __func__,
            i, iov->iov_base, iov_end(iov));
            (*fds)[i] = vfu_reg->fd;
            sparse->areas[i].offset = (uintptr_t)iov->iov_base;
            sparse->areas[i].size = iov->iov_len;
        } 

If we use more than one sparse mmap in a device region, libvifo-user duplicates the FD for each sparse map. However, QEMU only expectes one FD which is also what the spec mandates (there's only one FD in VFIO as well). We should either fix libvfio-user or change the spec to allow multiple FDs to be returned.

jlevon commented 1 year ago

Presumably this isn't breaking now just because we don't have > 1 sparse area?

tmakatos commented 1 year ago

Presumably this isn't breaking now just because we don't have > 1 sparse area?

Yes.