From: Alex Williamson <alex@shazbot.org>
To: "Michał Winiarski" <michal.winiarski@intel.com>
Cc: "Lucas De Marchi" <lucas.demarchi@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Yishai Hadas" <yishaih@nvidia.com>,
"Kevin Tian" <kevin.tian@intel.com>,
"Shameer Kolothum" <skolothumtho@nvidia.com>,
intel-xe@lists.freedesktop.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, "Matthew Brost" <matthew.brost@intel.com>,
"Michal Wajdeczko" <michal.wajdeczko@intel.com>,
dri-devel@lists.freedesktop.org,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Lukasz Laguna" <lukasz.laguna@intel.com>,
"Christoph Hellwig" <hch@infradead.org>
Subject: Re: [PATCH v6 3/4] drm/xe/pf: Export helpers for VFIO
Date: Tue, 25 Nov 2025 11:34:03 -0700 [thread overview]
Message-ID: <20251125113403.6156f03a.alex@shazbot.org> (raw)
In-Reply-To: <20251124230841.613894-4-michal.winiarski@intel.com>
On Tue, 25 Nov 2025 00:08:40 +0100
Michał Winiarski <michal.winiarski@intel.com> wrote:
> +/**
> + * xe_sriov_vfio_wait_flr_done() - Wait for VF FLR completion.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + *
> + * This function will wait until VF FLR is processed by PF on all tiles (or
> + * until timeout occurs).
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_sriov_vfio_wait_flr_done(struct xe_device *xe, unsigned int vfid)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_control_wait_flr(xe, vfid);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_wait_flr_done, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_suspend_device() - Suspend VF.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + *
> + * This function will pause VF on all tiles/GTs.
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_sriov_vfio_suspend_device(struct xe_device *xe, unsigned int vfid)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_control_pause_vf(xe, vfid);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_suspend_device, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_resume_device() - Resume VF.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + *
> + * This function will resume VF on all tiles.
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_sriov_vfio_resume_device(struct xe_device *xe, unsigned int vfid)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_control_resume_vf(xe, vfid);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_resume_device, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_stop_copy_enter() - Initiate a VF device migration data save.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_sriov_vfio_stop_copy_enter(struct xe_device *xe, unsigned int vfid)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_control_trigger_save_vf(xe, vfid);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_stop_copy_enter, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_stop_copy_exit() - Finish a VF device migration data save.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_sriov_vfio_stop_copy_exit(struct xe_device *xe, unsigned int vfid)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_control_finish_save_vf(xe, vfid);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_stop_copy_exit, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_resume_data_enter() - Initiate a VF device migration data restore.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_sriov_vfio_resume_data_enter(struct xe_device *xe, unsigned int vfid)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_control_trigger_restore_vf(xe, vfid);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_resume_data_enter, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_resume_data_exit() - Finish a VF device migration data restore.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_sriov_vfio_resume_data_exit(struct xe_device *xe, unsigned int vfid)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_control_finish_restore_vf(xe, vfid);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_resume_data_exit, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_error() - Move VF device to error state.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + *
> + * Reset is needed to move it out of error state.
> + *
> + * Return: 0 on success or a negative error code on failure.
> + */
> +int xe_sriov_vfio_error(struct xe_device *xe, unsigned int vfid)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_control_stop_vf(xe, vfid);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_error, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_data_read() - Read migration data from the VF device.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + * @buf: start address of userspace buffer
> + * @len: requested read size from userspace
> + *
> + * Return: number of bytes that has been successfully read,
> + * 0 if no more migration data is available, -errno on failure.
> + */
> +ssize_t xe_sriov_vfio_data_read(struct xe_device *xe, unsigned int vfid,
> + char __user *buf, size_t len)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_migration_read(xe, vfid, buf, len);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_data_read, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_data_write() - Write migration data to the VF device.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + * @buf: start address of userspace buffer
> + * @len: requested write size from userspace
> + *
> + * Return: number of bytes that has been successfully written, -errno on failure.
> + */
> +ssize_t xe_sriov_vfio_data_write(struct xe_device *xe, unsigned int vfid,
> + const char __user *buf, size_t len)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_migration_write(xe, vfid, buf, len);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_data_write, "xe-vfio-pci");
> +
> +/**
> + * xe_sriov_vfio_stop_copy_size() - Get a size estimate of VF device migration data.
> + * @xe: the PF &xe_device obtained by calling xe_sriov_vfio_get_pf()
> + * @vfid: the VF identifier (can't be 0)
> + *
> + * Return: migration data size in bytes or a negative error code on failure.
> + */
> +ssize_t xe_sriov_vfio_stop_copy_size(struct xe_device *xe, unsigned int vfid)
> +{
> + if (!IS_SRIOV_PF(xe))
> + return -EPERM;
> + if (vfid == PFID || vfid > xe_sriov_pf_num_vfs(xe))
> + return -EINVAL;
> +
> + guard(xe_pm_runtime_noresume)(xe);
> +
> + return xe_sriov_pf_migration_size(xe, vfid);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(xe_sriov_vfio_stop_copy_size, "xe-vfio-pci");
The duplicated testing and identical structure of most of the above
functions suggests a helper, if not full on definition by macro.
Thanks,
Alex
next prev parent reply other threads:[~2025-11-25 18:34 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-24 23:08 [PATCH v6 0/4] vfio/xe: Add driver variant for Xe VF migration Michał Winiarski
2025-11-24 23:08 ` [PATCH v6 1/4] drm/xe/pf: Enable SR-IOV " Michał Winiarski
2025-11-25 14:26 ` Michal Wajdeczko
2025-11-26 22:07 ` Michał Winiarski
2025-11-24 23:08 ` [PATCH v6 2/4] drm/xe/pci: Introduce a helper to allow VF access to PF xe_device Michał Winiarski
2025-11-24 23:08 ` [PATCH v6 3/4] drm/xe/pf: Export helpers for VFIO Michał Winiarski
2025-11-25 14:38 ` Michal Wajdeczko
2025-11-26 22:07 ` Michał Winiarski
2025-11-25 18:34 ` Alex Williamson [this message]
2025-11-26 18:21 ` Michał Winiarski
2025-11-24 23:08 ` [PATCH v6 4/4] vfio/xe: Add device specific vfio_pci driver variant for Intel graphics Michał Winiarski
2025-11-25 20:08 ` Alex Williamson
2025-11-26 11:59 ` Michał Winiarski
2025-11-25 20:13 ` [PATCH v6 0/4] vfio/xe: Add driver variant for Xe VF migration Alex Williamson
2025-11-26 1:20 ` Matthew Brost
2025-11-26 11:38 ` Thomas Hellström
2025-11-26 11:39 ` Thomas Hellström
2025-11-26 14:46 ` Michał Winiarski
2025-11-26 15:40 ` Alex Williamson
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=20251125113403.6156f03a.alex@shazbot.org \
--to=alex@shazbot.org \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=hch@infradead.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=jgg@ziepe.ca \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lucas.demarchi@intel.com \
--cc=lukasz.laguna@intel.com \
--cc=matthew.brost@intel.com \
--cc=michal.wajdeczko@intel.com \
--cc=michal.winiarski@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=simona@ffwll.ch \
--cc=skolothumtho@nvidia.com \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tursulin@ursulin.net \
--cc=yishaih@nvidia.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