From: "Cédric Le Goater" <clegoate@redhat.com>
To: Yi Liu <yi.l.liu@intel.com>,
alex.williamson@redhat.com, jgg@nvidia.com, kevin.tian@intel.com
Cc: joro@8bytes.org, robin.murphy@arm.com, cohuck@redhat.com,
eric.auger@redhat.com, nicolinc@nvidia.com, kvm@vger.kernel.org,
mjrosato@linux.ibm.com, chao.p.peng@linux.intel.com,
yi.y.sun@linux.intel.com, peterx@redhat.com, jasowang@redhat.com,
shameerali.kolothum.thodi@huawei.com, lulu@redhat.com,
suravee.suthikulpanit@amd.com,
intel-gvt-dev@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org, linux-s390@vger.kernel.org,
xudong.hao@intel.com, yan.y.zhao@intel.com,
terrence.xu@intel.com, yanting.jiang@intel.com,
zhenzhong.duan@intel.com
Subject: Re: [PATCH v10 05/22] kvm/vfio: Accept vfio device file from userspace
Date: Thu, 11 May 2023 09:11:11 +0200 [thread overview]
Message-ID: <0805efa4-9376-7485-e52b-d53216f74482@redhat.com> (raw)
In-Reply-To: <20230426150321.454465-6-yi.l.liu@intel.com>
On 4/26/23 17:03, Yi Liu wrote:
> This defines KVM_DEV_VFIO_FILE* and make alias with KVM_DEV_VFIO_GROUP*.
> Old userspace uses KVM_DEV_VFIO_GROUP* works as well.
>
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
> Reviewed-by: Kevin Tian <kevin.tian@intel.com>
> Tested-by: Terrence Xu <terrence.xu@intel.com>
> Tested-by: Nicolin Chen <nicolinc@nvidia.com>
> Tested-by: Matthew Rosato <mjrosato@linux.ibm.com>
> Tested-by: Yanting Jiang <yanting.jiang@intel.com>
> Signed-off-by: Yi Liu <yi.l.liu@intel.com>
> ---
> Documentation/virt/kvm/devices/vfio.rst | 47 ++++++++++++++++---------
> include/uapi/linux/kvm.h | 13 +++++--
> virt/kvm/vfio.c | 16 ++++-----
> 3 files changed, 49 insertions(+), 27 deletions(-)
>
> diff --git a/Documentation/virt/kvm/devices/vfio.rst b/Documentation/virt/kvm/devices/vfio.rst
> index 08b544212638..c549143bb891 100644
> --- a/Documentation/virt/kvm/devices/vfio.rst
> +++ b/Documentation/virt/kvm/devices/vfio.rst
> @@ -9,22 +9,34 @@ 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:
> - 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_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 for the
> + VFIO file.
> +
> + 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.
> +
> +KVM_DEV_VFIO_GROUP (legacy kvm device group restricted to the handling of VFIO group fd):
> + KVM_DEV_VFIO_GROUP_ADD: same as KVM_DEV_VFIO_FILE_ADD for group fd only
> +
> + KVM_DEV_VFIO_GROUP_DEL: same as KVM_DEV_VFIO_FILE_DEL for group fd only
> +
> KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE: attaches a guest visible TCE table
> allocated by sPAPR KVM.
> kvm_device_attr.addr points to a struct::
> @@ -40,7 +52,10 @@ KVM_DEV_VFIO_GROUP attributes:
> - @tablefd is a file descriptor for a TCE table allocated via
> KVM_CREATE_SPAPR_TCE.
>
> -The GROUP_ADD operation above should be invoked prior to accessing the
> +The FILE/GROUP_ADD operation above should be invoked prior to accessing the
> device file descriptor via VFIO_GROUP_GET_DEVICE_FD in order to support
> drivers which require a kvm pointer to be set in their .open_device()
> -callback.
> +callback. It is the same for device file descriptor via character device
> +open which gets device access via VFIO_DEVICE_BIND_IOMMUFD. For such file
> +descriptors, FILE_ADD should be invoked before VFIO_DEVICE_BIND_IOMMUFD
> +to support the drivers mentioned in prior sentence as well.
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index d77aef872a0a..7980c7533136 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -1410,9 +1410,16 @@ struct kvm_device_attr {
> __u64 addr; /* userspace address of attr data */
> };
>
> -#define KVM_DEV_VFIO_GROUP 1
> -#define KVM_DEV_VFIO_GROUP_ADD 1
> -#define KVM_DEV_VFIO_GROUP_DEL 2
> +#define KVM_DEV_VFIO_FILE 1
> +
> +#define KVM_DEV_VFIO_FILE_ADD 1
> +#define KVM_DEV_VFIO_FILE_DEL 2
> +
> +/* KVM_DEV_VFIO_GROUP aliases are for compile time uapi compatibility */
> +#define KVM_DEV_VFIO_GROUP KVM_DEV_VFIO_FILE
> +
> +#define KVM_DEV_VFIO_GROUP_ADD KVM_DEV_VFIO_FILE_ADD
> +#define KVM_DEV_VFIO_GROUP_DEL KVM_DEV_VFIO_FILE_DEL
> #define KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE 3
>
> enum kvm_device_type {
> diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
> index 8f7fa07e8170..10a3c7ccadf1 100644
> --- a/virt/kvm/vfio.c
> +++ b/virt/kvm/vfio.c
> @@ -286,18 +286,18 @@ static int kvm_vfio_set_file(struct kvm_device *dev, long attr,
> int32_t fd;
>
> switch (attr) {
> - case KVM_DEV_VFIO_GROUP_ADD:
> + case KVM_DEV_VFIO_FILE_ADD:
> if (get_user(fd, argp))
> return -EFAULT;
> return kvm_vfio_file_add(dev, fd);
>
> - case KVM_DEV_VFIO_GROUP_DEL:
> + case KVM_DEV_VFIO_FILE_DEL:
> if (get_user(fd, argp))
> return -EFAULT;
> return kvm_vfio_file_del(dev, fd);
>
> #ifdef CONFIG_SPAPR_TCE_IOMMU
> - case KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE:
> + case KVM_DEV_VFIO_FILE_SET_SPAPR_TCE:
This should still be DEV_VFIO_GROUP_SET_SPAPR_TCE. Same below.
> return kvm_vfio_file_set_spapr_tce(dev, arg);
> #endif
> }
> @@ -309,7 +309,7 @@ static int kvm_vfio_set_attr(struct kvm_device *dev,
> struct kvm_device_attr *attr)
> {
> switch (attr->group) {
> - case KVM_DEV_VFIO_GROUP:
> + case KVM_DEV_VFIO_FILE:
> return kvm_vfio_set_file(dev, attr->attr,
> u64_to_user_ptr(attr->addr));
> }
> @@ -321,12 +321,12 @@ static int kvm_vfio_has_attr(struct kvm_device *dev,
> struct kvm_device_attr *attr)
> {
> switch (attr->group) {
> - case KVM_DEV_VFIO_GROUP:
> + case KVM_DEV_VFIO_FILE:
> switch (attr->attr) {
> - case KVM_DEV_VFIO_GROUP_ADD:
> - case KVM_DEV_VFIO_GROUP_DEL:
> + case KVM_DEV_VFIO_FILE_ADD:
> + case KVM_DEV_VFIO_FILE_DEL:
> #ifdef CONFIG_SPAPR_TCE_IOMMU
> - case KVM_DEV_VFIO_GROUP_SET_SPAPR_TCE:
> + case KVM_DEV_VFIO_FILE_SET_SPAPR_TCE:
Probably an error due to a global rename change.
Thanks,
C.
> #endif
> return 0;
> }
next prev parent reply other threads:[~2023-05-11 7:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 15:02 [PATCH v10 00/22] Add vfio_device cdev for iommufd support Yi Liu
2023-04-26 15:03 ` [PATCH v10 01/22] vfio: Allocate per device file structure Yi Liu
2023-04-26 15:03 ` [PATCH v10 02/22] vfio: Refine vfio file kAPIs for KVM Yi Liu
2023-04-26 15:03 ` [PATCH v10 03/22] vfio: Accept vfio device file in the KVM facing kAPI Yi Liu
2023-04-26 15:03 ` [PATCH v10 04/22] kvm/vfio: Rename kvm_vfio_group to prepare for accepting vfio device fd Yi Liu
2023-04-26 15:03 ` [PATCH v10 05/22] kvm/vfio: Accept vfio device file from userspace Yi Liu
2023-05-11 7:11 ` Cédric Le Goater [this message]
2023-05-12 7:57 ` Liu, Yi L
2023-04-26 15:03 ` [PATCH v10 06/22] vfio: Pass struct vfio_device_file * to vfio_device_open/close() Yi Liu
2023-04-26 15:03 ` [PATCH v10 07/22] vfio: Block device access via device fd until device is opened Yi Liu
2023-04-26 15:03 ` [PATCH v10 08/22] vfio: Add cdev_device_open_cnt to vfio_group Yi Liu
2023-04-26 15:03 ` [PATCH v10 09/22] vfio: Make vfio_device_open() single open for device cdev path Yi Liu
2023-04-26 15:03 ` [PATCH v10 10/22] vfio-iommufd: Move noiommu compat probe out of vfio_iommufd_bind() Yi Liu
2023-04-26 15:03 ` [PATCH v10 11/22] vfio-iommufd: Split bind/attach into two steps Yi Liu
2023-04-26 15:03 ` [PATCH v10 12/22] vfio: Record devid in vfio_device_file Yi Liu
2023-04-26 15:03 ` [PATCH v10 13/22] vfio-iommufd: Add detach_ioas support for physical VFIO devices Yi Liu
2023-04-26 15:03 ` [PATCH v10 14/22] iommufd/device: Add iommufd_access_detach() API Yi Liu
2023-04-26 15:03 ` [PATCH v10 15/22] vfio-iommufd: Add detach_ioas support for emulated VFIO devices Yi Liu
2023-04-26 15:03 ` [PATCH v10 16/22] vfio: Name noiommu vfio_device with "noiommu-" prefix Yi Liu
2023-04-26 15:03 ` [PATCH v10 17/22] vfio: Move vfio_device_group_unregister() to be the first operation in unregister Yi Liu
2023-04-26 15:03 ` [PATCH v10 18/22] vfio: Add cdev for vfio_device Yi Liu
2023-04-26 15:03 ` [PATCH v10 19/22] vfio: Add VFIO_DEVICE_BIND_IOMMUFD Yi Liu
2023-04-26 15:03 ` [PATCH v10 20/22] vfio: Add VFIO_DEVICE_[AT|DE]TACH_IOMMUFD_PT Yi Liu
2023-04-26 15:03 ` [PATCH v10 21/22] vfio: Compile group optionally Yi Liu
2023-04-26 15:03 ` [PATCH v10 22/22] docs: vfio: Add vfio device cdev description Yi Liu
2023-04-28 9:29 ` [PATCH v10 00/22] Add vfio_device cdev for iommufd support Jiang, Yanting
2023-04-28 15:11 ` Shameerali Kolothum Thodi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0805efa4-9376-7485-e52b-d53216f74482@redhat.com \
--to=clegoate@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=chao.p.peng@linux.intel.com \
--cc=cohuck@redhat.com \
--cc=eric.auger@redhat.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-gvt-dev@lists.freedesktop.org \
--cc=jasowang@redhat.com \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=lulu@redhat.com \
--cc=mjrosato@linux.ibm.com \
--cc=nicolinc@nvidia.com \
--cc=peterx@redhat.com \
--cc=robin.murphy@arm.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=terrence.xu@intel.com \
--cc=xudong.hao@intel.com \
--cc=yan.y.zhao@intel.com \
--cc=yanting.jiang@intel.com \
--cc=yi.l.liu@intel.com \
--cc=yi.y.sun@linux.intel.com \
--cc=zhenzhong.duan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox