From: Jason Gunthorpe <jgg@ziepe.ca>
To: Lingyu Liu <lingyu.liu@intel.com>
Cc: kevin.tian@intel.com, yi.l.liu@intel.com,
intel-wired-lan@lists.osuosl.org, phani.r.burra@intel.com
Subject: Re: [Intel-wired-lan] [PATCH iwl-next V2 15/15] vfio/ice: support iommufd vfio compat mode
Date: Wed, 21 Jun 2023 11:40:01 -0300 [thread overview]
Message-ID: <ZJMLwXt88vWmI4XX@ziepe.ca> (raw)
In-Reply-To: <20230621091112.44945-16-lingyu.liu@intel.com>
On Wed, Jun 21, 2023 at 09:11:12AM +0000, Lingyu Liu wrote:
> From: Yahui Cao <yahui.cao@intel.com>
>
> In iommufd vfio compat mode, vfio_dma_rw() will return failure, since
> vfio_device_has_container() returns false and device->iommufd_access is
> NULL.
>
> Currently device->iommufd_access will not be created if vfio device is
> backed by pci device. To support IOVA access, manually create
> iommufd_access context by iommufd_access_create/attach() and access IOVA
> by iommufd_access_rw(). And in order to minimize the iommufd_access's
> impact, store the iommufd_access context in driver data, create it only
> before loading the device state and destroy it once finishing loading
> the device state.
>
> To be compatible with legacy vfio, use vfio_device_has_container() to
> check the vfio uAPI. If in legacy vfio mode, call vfio_dma_rw()
> directly, otherwise call iommufd_access_rw().
This is not the right approach, you should create your access by
overloading the iommufd ops. Nak on exposing vfio_device_has_container
> +/**
> + * ice_vfio_pci_emulated_unmap - callback to unmap IOVA
> + * @data: function handler data
> + * @iova: I/O virtuall address
> + * @len: IOVA length
> + *
> + * This function is called when application are doing DMA unmap and in some
> + * cases driver needs to explicitly do some unmap ops if this device does not
> + * have backed iommu. Nothing is required here since this is pci baseed vfio
> + * device, which has backed iommu.
> + */
> +static void
> +ice_vfio_pci_emulated_unmap(void *data, unsigned long iova, unsigned long len)
> +{
> +}
> +
> +static const struct iommufd_access_ops ice_vfio_user_ops = {
> + .needs_pin_pages = 1,
> + .unmap = ice_vfio_pci_emulated_unmap,
> +};
If you don't call pin pages then you shouldn't set needs_pin_pages?
An empty unmap op is unconditionally wrong.
> + * ice_vfio_dma_rw - read/write function for device IOVA address space
> + * @data: function handler data
> + * @iova: I/O virtuall address
> + * @buf: buffer for read/write access
> + * @len: buffer length
> + * @write: true for write, false for read
> + *
> + * Read/write function for device IOVA access. Since vfio_dma_rw() may fail
> + * at iommufd vfio compatiable mode, we need runtime check what uAPI it is
> + * using and use corresponding access method for IOVA access.
> + *
> + * Return 0 for success, negative value for failure.
> + */
> +static int ice_vfio_dma_rw(void *data, dma_addr_t iova,
> + void *buf, size_t len, bool write)
> +{
> + struct ice_vfio_pci_core_device *ice_vdev =
> + (struct ice_vfio_pci_core_device *)data;
> + struct vfio_device *vdev = &ice_vdev->core_device.vdev;
> + unsigned int flags = 0;
> +
> + if (vfio_device_has_container(vdev))
> + return vfio_dma_rw(vdev, iova, buf, len, write);
> +
> + if (!current->mm)
> + flags |= IOMMUFD_ACCESS_RW_KTHREAD;
No, you need to know your own calling context, you can't guess like this.
I suppose this is always called from an ioctl?
> @@ -19,7 +21,7 @@ void ice_migration_uninit_vf(void *opaque);
> int ice_migration_suspend_vf(void *opaque, bool mig_dst);
> int ice_migration_save_devstate(void *opaque, u8 *buf, u64 buf_sz);
> int ice_migration_restore_devstate(void *opaque, const u8 *buf, u64 buf_sz,
> - struct vfio_device *vdev);
> + dma_rw_handler_t handler, void *data);
Please remove all the wild function pointers and void * opaques I see
in this driver. Use proper types and get your layering right so you
dont't have to fake up improper cross-layer calls like this.
Jason
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
next prev parent reply other threads:[~2023-06-21 14:40 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-21 9:10 [Intel-wired-lan] [PATCH iwl-next V2 00/15] Add E800 live migration driver Lingyu Liu
2023-06-21 9:10 ` [Intel-wired-lan] [PATCH iwl-next V2 01/15] ice: Fix missing legacy 32byte RXDID in the supported bitmap Lingyu Liu
2023-06-21 9:10 ` [Intel-wired-lan] [PATCH iwl-next V2 02/15] ice: add function to get rxq context Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 03/15] ice: check VF migration status before sending messages to VF Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 04/15] ice: add migration init field and helper functions Lingyu Liu
2023-06-21 13:35 ` Jason Gunthorpe
2023-06-27 7:50 ` Cao, Yahui
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 05/15] ice: save VF messages as device state Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 06/15] ice: save and restore " Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 07/15] ice: do not notify VF link state during migration Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 08/15] ice: change VSI id in virtual channel message after migration Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 09/15] ice: save and restore RX queue head Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 10/15] ice: save and restore TX " Lingyu Liu
2023-06-21 14:37 ` Jason Gunthorpe
2023-06-27 6:55 ` Tian, Kevin
2023-07-03 5:27 ` Cao, Yahui
2023-07-03 21:03 ` Jason Gunthorpe
2023-07-04 7:35 ` Tian, Kevin
2023-06-28 8:11 ` Liu, Yi L
2023-06-28 12:39 ` Jason Gunthorpe
2023-07-03 12:54 ` Liu, Yi L
2023-07-04 7:38 ` Tian, Kevin
2023-07-04 17:59 ` Peter Xu
2023-07-10 15:54 ` Jason Gunthorpe
2023-07-17 21:43 ` Peter Xu
2023-07-18 15:38 ` Jason Gunthorpe
2023-07-18 17:36 ` Peter Xu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 11/15] ice: stop device before saving device states Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 12/15] ice: mask VF advanced capabilities if live migration is activated Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 13/15] vfio/ice: implement vfio_pci driver for E800 devices Lingyu Liu
2023-06-21 14:23 ` Jason Gunthorpe
2023-06-27 9:00 ` Liu, Lingyu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 14/15] vfio: Expose vfio_device_has_container() Lingyu Liu
2023-06-21 9:11 ` [Intel-wired-lan] [PATCH iwl-next V2 15/15] vfio/ice: support iommufd vfio compat mode Lingyu Liu
2023-06-21 14:40 ` Jason Gunthorpe [this message]
2023-06-27 8:09 ` Cao, Yahui
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=ZJMLwXt88vWmI4XX@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=kevin.tian@intel.com \
--cc=lingyu.liu@intel.com \
--cc=phani.r.burra@intel.com \
--cc=yi.l.liu@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