From: Joao Martins <joao.m.martins@oracle.com>
To: Avihai Horon <avihaih@nvidia.com>
Cc: Yishai Hadas <yishaih@nvidia.com>,
Jason Gunthorpe <jgg@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
Maor Gottlieb <maorg@nvidia.com>,
Kirti Wankhede <kwankhede@nvidia.com>,
Tarun Gupta <targupta@nvidia.com>,
Cornelia Huck <cohuck@redhat.com>,
qemu-devel@nongnu.org,
Alex Williamson <alex.williamson@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Juan Quintela <quintela@redhat.com>
Subject: Re: [PATCH v2 07/11] vfio/migration: Implement VFIO migration protocol v2
Date: Tue, 14 Jun 2022 18:24:23 +0100 [thread overview]
Message-ID: <3d064847-f69a-66e5-ab3e-bcc5eb566ebe@oracle.com> (raw)
In-Reply-To: <d090f3e9-2dad-f133-cd57-db84d9e08691@nvidia.com>
On 6/14/22 17:34, Avihai Horon wrote:
>
> On 6/14/2022 2:08 PM, Joao Martins wrote:
>> External email: Use caution opening links or attachments
>>
>>
>> On 5/30/22 18:07, Avihai Horon wrote:
>>> +static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)
>>> +{
>>> + VFIODevice *vbasedev = opaque;
>>> + enum vfio_device_mig_state recover_state;
>>> + int ret;
>>> +
>>> + /* We reach here with device state STOP or STOP_COPY only */
>>> + recover_state = VFIO_DEVICE_STATE_STOP;
>>> + ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP_COPY,
>>> + recover_state);
>>> + if (ret) {
>>> + return ret;
>>> + }
>>> +
>>> + do {
>>> + ret = vfio_save_block(f, vbasedev->migration);
>>> + if (ret < 0) {
>>> + return ret;
>>> + }
>>> + } while (!ret);
>>> +
>>> + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE);
>>> + ret = qemu_file_get_error(f);
>>> + if (ret) {
>>> + return ret;
>>> + }
>>> +
>>> + ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP,
>>> + recover_state);
>> Is it expected that you are setting VFIO_DEVICE_STATE_STOP while
>> @recover_state is the same value (VFIO_DEVICE_STATE_STOP) ?
>
>
> Yes.
> Transitioning to any other state from STOP_COPY will first go through
> STOP state (this is done internally by kernel).
> So there is no better option for the recover state but STOP.
>
I was think about ERROR state given that you can transition there
from any state, but wasn't quite sure if it's appropriate to make that arc
while in stop copy migration phase.
>>> + if (ret) {
>>> + return ret;
>>> + }
>>> +
>>> + trace_vfio_save_complete_precopy(vbasedev->name);
>>> +
>>> + return 0;
just a cosmetic nit: you could probably rewrite these last couple of lines as:
if (!ret) {
trace_vfio_save_complete_precopy(vbasedev->name);
}
return ret;
Let's you avoid the double return path.
>>> +}
>>> +
>>> static int vfio_v1_save_complete_precopy(QEMUFile *f, void *opaque)
>>> {
>>> VFIODevice *vbasedev = opaque;
>>> @@ -593,6 +775,14 @@ static void vfio_save_state(QEMUFile *f, void *opaque)
>>> }
>>> }
>>>
>>> +static int vfio_load_setup(QEMUFile *f, void *opaque)
>>> +{
>>> + VFIODevice *vbasedev = opaque;
>>> +
>>> + return vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RESUMING,
>>> + vbasedev->migration->device_state);
>>> +}
>>> +
>>> static int vfio_v1_load_setup(QEMUFile *f, void *opaque)
>>> {
>>> VFIODevice *vbasedev = opaque;
>>> @@ -620,6 +810,15 @@ static int vfio_v1_load_setup(QEMUFile *f, void *opaque)
>>> return ret;
>>> }
>>>
>>> +static int vfio_load_cleanup(void *opaque)
>>> +{
>>> + VFIODevice *vbasedev = opaque;
>>> +
>>> + vfio_migration_cleanup(vbasedev);
>>> + trace_vfio_load_cleanup(vbasedev->name);
>>> + return 0;
>>> +}
>>> +
>>> static int vfio_v1_load_cleanup(void *opaque)
>>> {
>>> VFIODevice *vbasedev = opaque;
>>> @@ -662,7 +861,11 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)
>>> uint64_t data_size = qemu_get_be64(f);
>>>
>>> if (data_size) {
>>> - ret = vfio_v1_load_buffer(f, vbasedev, data_size);
>>> + if (vbasedev->migration->v2) {
>>> + ret = vfio_load_buffer(f, vbasedev, data_size);
>>> + } else {
>>> + ret = vfio_v1_load_buffer(f, vbasedev, data_size);
>>> + }
>>> if (ret < 0) {
>>> return ret;
>>> }
>>> @@ -683,6 +886,16 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)
>>> return ret;
>>> }
>>>
>>> +static SaveVMHandlers savevm_vfio_handlers = {
>>> + .save_setup = vfio_save_setup,
>>> + .save_cleanup = vfio_save_cleanup,
>>> + .save_live_complete_precopy = vfio_save_complete_precopy,
>>> + .save_state = vfio_save_state,
>>> + .load_setup = vfio_load_setup,
>>> + .load_cleanup = vfio_load_cleanup,
>>> + .load_state = vfio_load_state,
>>> +};
>>> +
>>> static SaveVMHandlers savevm_vfio_v1_handlers = {
>>> .save_setup = vfio_v1_save_setup,
>>> .save_cleanup = vfio_v1_save_cleanup,
>>> @@ -697,6 +910,34 @@ static SaveVMHandlers savevm_vfio_v1_handlers = {
>>>
>>> /* ---------------------------------------------------------------------- */
>>>
>>> +static void vfio_vmstate_change(void *opaque, bool running, RunState state)
>>> +{
>>> + VFIODevice *vbasedev = opaque;
>>> + enum vfio_device_mig_state new_state;
>>> + int ret;
>>> +
>>> + if (running) {
>>> + new_state = VFIO_DEVICE_STATE_RUNNING;
>>> + } else {
>>> + new_state = VFIO_DEVICE_STATE_STOP;
>>> + }
>>> +
>>> + ret = vfio_migration_set_state(vbasedev, new_state,
>>> + VFIO_DEVICE_STATE_ERROR);
>>> + if (ret) {
>>> + /*
>>> + * Migration should be aborted in this case, but vm_state_notify()
>>> + * currently does not support reporting failures.
>>> + */
>>> + if (migrate_get_current()->to_dst_file) {
>>> + qemu_file_set_error(migrate_get_current()->to_dst_file, ret);
>>> + }
>>> + }
>>> +
>>> + trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),
>>> + new_state);
>>> +}
>>> +
>>> static void vfio_v1_vmstate_change(void *opaque, bool running, RunState state)
>>> {
>>> VFIODevice *vbasedev = opaque;
>>> @@ -770,12 +1011,17 @@ static void vfio_migration_state_notifier(Notifier *notifier, void *data)
>>> case MIGRATION_STATUS_CANCELLED:
>>> case MIGRATION_STATUS_FAILED:
>>> bytes_transferred = 0;
>>> - ret = vfio_migration_v1_set_state(vbasedev,
>>> - ~(VFIO_DEVICE_STATE_V1_SAVING |
>>> - VFIO_DEVICE_STATE_V1_RESUMING),
>>> - VFIO_DEVICE_STATE_V1_RUNNING);
>>> - if (ret) {
>>> - error_report("%s: Failed to set state RUNNING", vbasedev->name);
>>> + if (migration->v2) {
>>> + vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RUNNING,
>>> + VFIO_DEVICE_STATE_ERROR);
>> Perhaps you are discarding the error?
>>
>> Shouldn't it be:
>>
>> err = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RUNNING,
>> VFIO_DEVICE_STATE_ERROR);
>>
>>> + } else {
>>> + ret = vfio_migration_v1_set_state(vbasedev,
>>> + ~(VFIO_DEVICE_STATE_V1_SAVING |
>>> + VFIO_DEVICE_STATE_V1_RESUMING),
>>> + VFIO_DEVICE_STATE_V1_RUNNING);
>>> + if (ret) {
>>> + error_report("%s: Failed to set state RUNNING", vbasedev->name);
>>> + }
>> Perhaps this error_report and condition is in the wrong scope?
>>
>> Shouldn't it be more like this:
>>
>> if (migration->v2) {
>> ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RUNNING,
>> VFIO_DEVICE_STATE_ERROR);
>> } else {
>> ret = vfio_migration_v1_set_state(vbasedev,
>> ~(VFIO_DEVICE_STATE_V1_SAVING |
>> VFIO_DEVICE_STATE_V1_RESUMING),
>> VFIO_DEVICE_STATE_V1_RUNNING);
>> }
>>
>>
>> if (ret) {
>> error_report("%s: Failed to set state RUNNING", vbasedev->name);
>> }
>
>
> It was intentionally discarded.
> The return value is used by v1 code to determine whether to print an
> error message or not.
> In v2 code the error message print is done inside
> vfio_migration_set_state(), so there is no
> need for the return value here.
>
Oh yes, I forgot that other print.
next prev parent reply other threads:[~2022-06-14 17:26 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-30 17:07 [PATCH v2 00/11] vfio/migration: Implement VFIO migration protocol v2 Avihai Horon
2022-05-30 17:07 ` [PATCH v2 01/11] vfio/migration: Fix NULL pointer dereference bug Avihai Horon
2022-05-30 17:07 ` [PATCH v2 02/11] vfio/migration: Skip pre-copy if dirty page tracking is not supported Avihai Horon
2022-05-30 17:12 ` Avihai Horon
2022-06-07 17:53 ` Avihai Horon
2022-05-30 17:07 ` [PATCH v2 03/11] migration/qemu-file: Add qemu_file_get_to_fd() Avihai Horon
2022-05-30 17:07 ` [PATCH v2 04/11] vfio/common: Change vfio_devices_all_running_and_saving() logic to equivalent one Avihai Horon
2022-05-30 17:07 ` [PATCH v2 05/11] vfio/migration: Move migration v1 logic to vfio_migration_init() Avihai Horon
2022-05-30 17:07 ` [PATCH v2 06/11] vfio/migration: Rename functions/structs related to v1 protocol Avihai Horon
2022-05-30 17:07 ` [PATCH v2 07/11] vfio/migration: Implement VFIO migration protocol v2 Avihai Horon
2022-06-14 11:08 ` Joao Martins
2022-06-14 16:34 ` Avihai Horon
2022-06-14 17:24 ` Joao Martins [this message]
2022-06-15 6:40 ` Avihai Horon
2022-07-18 15:12 ` Jason Gunthorpe
2022-07-27 15:45 ` Avihai Horon
2022-05-30 17:07 ` [PATCH v2 08/11] vfio/migration: Remove VFIO migration protocol v1 Avihai Horon
2022-09-19 8:35 ` liulongfang via
2022-09-19 11:50 ` Alex Williamson
2022-09-19 12:58 ` Philippe Mathieu-Daudé via
2022-09-19 9:41 ` Philippe Mathieu-Daudé via
2022-05-30 17:07 ` [PATCH v2 09/11] vfio/migration: Reset device if setting recover state fails Avihai Horon
2022-10-11 1:41 ` liulongfang via
2022-05-30 17:07 ` [PATCH v2 10/11] vfio: Alphabetize migration section of VFIO trace-events file Avihai Horon
2022-05-30 17:07 ` [PATCH v2 11/11] docs/devel: Align vfio-migration docs to VFIO migration v2 Avihai Horon
2022-06-07 17:44 ` [PATCH v2 00/11] vfio/migration: Implement VFIO migration protocol v2 Avihai Horon
2022-06-07 21:32 ` Alex Williamson
2022-06-13 11:21 ` Avihai Horon
2022-06-17 21:51 ` Alex Williamson
2022-06-23 14:56 ` Jason Gunthorpe
2022-06-27 7:36 ` Avihai Horon
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=3d064847-f69a-66e5-ab3e-bcc5eb566ebe@oracle.com \
--to=joao.m.martins@oracle.com \
--cc=alex.williamson@redhat.com \
--cc=avihaih@nvidia.com \
--cc=cohuck@redhat.com \
--cc=dgilbert@redhat.com \
--cc=jgg@nvidia.com \
--cc=kwankhede@nvidia.com \
--cc=maorg@nvidia.com \
--cc=mbloch@nvidia.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=targupta@nvidia.com \
--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;
as well as URLs for NNTP newsgroup(s).