RE: [RFC PATCH v6 02/11] vfio: cdev: Reject duplicate bind before updating KVM file

From: Aneesh Kumar K . V

Date: Fri Sep 25 2026 - 01:50:11 EST


"Tian, Kevin" <kevin.tian@xxxxxxxxx> writes:

>> From: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>
>> Sent: Thursday, September 17, 2026 10:02 PM
>>
>> The cdev path only supports one bound/open device fd, but
>> VFIO_DEVICE_BIND_IOMMUFD only checked the per-file access_granted flag
>> before capturing the KVM file reference. A second fd for the same device
>> could therefore replace device->kvm_file, fail later in vfio_df_open()
>> because open_count is already nonzero, and then clear the active KVM
>> association during error cleanup.
>>
>> Reject the bind while holding dev_set->lock if the device is already
>> open, matching the existing cdev single-open rule before touching the
>> device-wide KVM state.
>>
>> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>
>
> could you send it out as a separate fix?
>

Sure, I'll send it as a separate fix.

-aneesh