[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v26 05/17] vfio: Add VM state change handler to know state of
From: |
Cornelia Huck |
Subject: |
Re: [PATCH v26 05/17] vfio: Add VM state change handler to know state of VM |
Date: |
Thu, 24 Sep 2020 17:02:19 +0200 |
On Wed, 23 Sep 2020 04:54:07 +0530
Kirti Wankhede <kwankhede@nvidia.com> wrote:
> VM state change handler gets called on change in VM's state. This is used to
> set
> VFIO device state to _RUNNING.
>
> Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
> Reviewed-by: Neo Jia <cjia@nvidia.com>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> hw/vfio/migration.c | 136
> ++++++++++++++++++++++++++++++++++++++++++
> hw/vfio/trace-events | 3 +-
> include/hw/vfio/vfio-common.h | 4 ++
> 3 files changed, 142 insertions(+), 1 deletion(-)
>
(...)
> +static int vfio_migration_set_state(VFIODevice *vbasedev, uint32_t mask,
> + uint32_t value)
I think I've mentioned that before, but this function could really
benefit from a comment what mask and value mean.
> +{
> + VFIOMigration *migration = vbasedev->migration;
> + VFIORegion *region = &migration->region;
> + off_t dev_state_off = region->fd_offset +
> + offsetof(struct vfio_device_migration_info,
> device_state);
> + uint32_t device_state;
> + int ret;
> +
> + ret = vfio_mig_read(vbasedev, &device_state, sizeof(device_state),
> + dev_state_off);
> + if (ret < 0) {
> + return ret;
> + }
> +
> + device_state = (device_state & mask) | value;
> +
> + if (!VFIO_DEVICE_STATE_VALID(device_state)) {
> + return -EINVAL;
> + }
> +
> + ret = vfio_mig_write(vbasedev, &device_state, sizeof(device_state),
> + dev_state_off);
> + if (ret < 0) {
> + ret = vfio_mig_read(vbasedev, &device_state, sizeof(device_state),
> + dev_state_off);
> + if (ret < 0) {
> + return ret;
> + }
> +
> + if (VFIO_DEVICE_STATE_IS_ERROR(device_state)) {
> + hw_error("%s: Device is in error state 0x%x",
> + vbasedev->name, device_state);
> + return -EFAULT;
Is -EFAULT a good return value here? Maybe -EIO?
> + }
> + }
> +
> + vbasedev->device_state = device_state;
> + trace_vfio_migration_set_state(vbasedev->name, device_state);
> + return 0;
> +}
> +
> +static void vfio_vmstate_change(void *opaque, int running, RunState state)
> +{
> + VFIODevice *vbasedev = opaque;
> +
> + if ((vbasedev->vm_running != running)) {
> + int ret;
> + uint32_t value = 0, mask = 0;
> +
> + if (running) {
> + value = VFIO_DEVICE_STATE_RUNNING;
> + if (vbasedev->device_state & VFIO_DEVICE_STATE_RESUMING) {
> + mask = ~VFIO_DEVICE_STATE_RESUMING;
I've been staring at this for some time and I think that the desired
result is
- set _RUNNING
- if _RESUMING was set, clear it, but leave the other bits intact
- if _RESUMING was not set, clear everything previously set
This would really benefit from a comment (or am I the only one
struggling here?)
> + }
> + } else {
> + mask = ~VFIO_DEVICE_STATE_RUNNING;
> + }
> +
> + ret = vfio_migration_set_state(vbasedev, mask, value);
> + if (ret) {
> + /*
> + * vm_state_notify() doesn't support reporting failure. If such
> + * error reporting support added in furure, migration should be
> + * aborted.
"We should abort the migration in this case, but vm_state_notify()
currently does not support reporting failures."
?
Can/should we mark the failing device in some way?
> + */
> + error_report("%s: Failed to set device state 0x%x",
> + vbasedev->name, value & mask);
> + }
> + vbasedev->vm_running = running;
> + trace_vfio_vmstate_change(vbasedev->name, running,
> RunState_str(state),
> + value & mask);
> + }
> +}
> +
> static int vfio_migration_init(VFIODevice *vbasedev,
> struct vfio_region_info *info)
> {
(...)
- [PATCH v26 01/17] vfio: Add function to unmap VFIO region, (continued)
- [PATCH v26 01/17] vfio: Add function to unmap VFIO region, Kirti Wankhede, 2020/09/22
- [PATCH v26 02/17] vfio: Add vfio_get_object callback to VFIODeviceOps, Kirti Wankhede, 2020/09/22
- [PATCH v26 03/17] vfio: Add save and load functions for VFIO PCI devices, Kirti Wankhede, 2020/09/22
- [PATCH v26 04/17] vfio: Add migration region initialization and finalize function, Kirti Wankhede, 2020/09/22
- [PATCH v26 05/17] vfio: Add VM state change handler to know state of VM, Kirti Wankhede, 2020/09/22
- [PATCH v26 06/17] vfio: Add migration state change notifier, Kirti Wankhede, 2020/09/22
- [PATCH v26 07/17] vfio: Register SaveVMHandlers for VFIO device, Kirti Wankhede, 2020/09/22
- [PATCH v26 08/17] vfio: Add save state functions to SaveVMHandlers, Kirti Wankhede, 2020/09/22