RE: [PATCH v2 05/14] kvm/vfio: Accept vfio device file from userspace

From: Tian, Kevin
Date: Mon Feb 06 2023 - 22:36:58 EST


> From: Liu, Yi L <yi.l.liu@xxxxxxxxx>
> Sent: Monday, February 6, 2023 5:05 PM
>
> This defines KVM_DEV_VFIO_FILE* and make alias with
> KVM_DEV_VFIO_GROUP*.
> Old userspace uses KVM_DEV_VFIO_GROUP* works as well.
>
> Signed-off-by: Yi Liu <yi.l.liu@xxxxxxxxx>
> ---
> Documentation/virt/kvm/devices/vfio.rst | 40 ++++++++++++++-----------
> include/uapi/linux/kvm.h | 16 +++++++---
> virt/kvm/vfio.c | 16 +++++-----
> 3 files changed, 42 insertions(+), 30 deletions(-)
>
> diff --git a/Documentation/virt/kvm/devices/vfio.rst
> b/Documentation/virt/kvm/devices/vfio.rst
> index 2d20dc561069..7f84ec26ca4a 100644
> --- a/Documentation/virt/kvm/devices/vfio.rst
> +++ b/Documentation/virt/kvm/devices/vfio.rst
> @@ -9,23 +9,26 @@ Device types supported:
> - KVM_DEV_TYPE_VFIO
>
> Only one VFIO instance may be created per VM. The created device
> -tracks VFIO groups in use by the VM and features of those groups
> -important to the correctness and acceleration of the VM. As groups
> -are enabled and disabled for use by the VM, KVM should be updated
> -about their presence. When registered with KVM, a reference to the
> -VFIO-group is held by KVM.
> +tracks VFIO files (group or device) in use by the VM and features
> +of those groups/devices important to the correctness and acceleration
> +of the VM. As groups/devices are enabled and disabled for use by the
> +VM, KVM should be updated about their presence. When registered with
> +KVM, a reference to the VFIO file is held by KVM.
>
> Groups:

"Files"

> - KVM_DEV_VFIO_GROUP
> -
> -KVM_DEV_VFIO_GROUP attributes:
> - KVM_DEV_VFIO_GROUP_ADD: Add a VFIO group to VFIO-KVM device
> tracking
> - kvm_device_attr.addr points to an int32_t file descriptor
> - for the VFIO group.
> - KVM_DEV_VFIO_GROUP_DEL: Remove a VFIO group from VFIO-KVM
> device tracking
> - kvm_device_attr.addr points to an int32_t file descriptor
> - for the VFIO group.
> - KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE: attaches a guest visible TCE
> table
> + KVM_DEV_VFIO_FILE
> + - alias: KVM_DEV_VFIO_GROUP
> +
> +KVM_DEV_VFIO_FILE attributes:
> + KVM_DEV_VFIO_FILE_ADD: Add a VFIO file (group/device) to VFIO-KVM
> device
> + tracking kvm_device_attr.addr points to an int32_t file descriptor

"... device tracking" and "kvm_device.attr.addr points to..." are two
sentences. They are deliberately arranged to be in different lines.

> + for the VFIO file.
> + - alias: KVM_DEV_VFIO_GROUP_ADD
> + KVM_DEV_VFIO_FILE_DEL: Remove a VFIO file (group/device) from VFIO-
> KVM
> + device tracking kvm_device_attr.addr points to an int32_t file
> + descriptor for the VFIO file.

ditto

> + - alias: KVM_DEV_VFIO_GROUP_DEL
> + KVM_DEV_VFIO_FILE_SET_SPAPR_TCE: attaches a guest visible TCE table
> allocated by sPAPR KVM.

somehow here it should emphasize that the file can only be group

> kvm_device_attr.addr points to a struct::
>
> @@ -36,6 +39,7 @@ KVM_DEV_VFIO_GROUP attributes:
>
> where:
>
> - - @groupfd is a file descriptor for a VFIO group;
> - - @tablefd is a file descriptor for a TCE table allocated via
> - KVM_CREATE_SPAPR_TCE.
> + *) @groupfd is a file descriptor for a VFIO group;
> + *) @tablefd is a file descriptor for a TCE table allocated via

why changing above two lines?

> + KVM_CREATE_SPAPR_TCE.
> + - alias: KVM_DEV_VFIO_FILE_SET_SPAPR_TCE

GROUP