Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 325BAC54EBD for ; Fri, 13 Jan 2023 17:40:50 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGNc5-00068X-CQ; Fri, 13 Jan 2023 12:13:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGNc4-00067y-4x for qemu-devel@nongnu.org; Fri, 13 Jan 2023 12:13:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGNc1-0008Am-P8 for qemu-devel@nongnu.org; Fri, 13 Jan 2023 12:13:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673629984; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cJ4oIsZsFSP9tMOcvK1jsBj0z5nBGppUoEQ5ZQnO2h0=; b=fyDXaFmr82BwdlyoOk9j5hx4S3ocIWywicbsFrTtQQLMl03h4okE4Tsjodu1IlEZKM1rtt 0cTHTdR6/z5gVO0H/GClFEDebImANAmSvXrjzr/Z9dB66y+yaYy5ulpQ4spSaa1CJw1CXu mM/G9IC/vII4Btf8hyrZiSgWqcbdqQc= Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-312-5UbKyIXhOS-ivZYsyMEZ9w-1; Fri, 13 Jan 2023 12:13:03 -0500 X-MC-Unique: 5UbKyIXhOS-ivZYsyMEZ9w-1 Received: by mail-yb1-f198.google.com with SMTP id h66-20020a252145000000b0071a7340eea9so23209975ybh.6 for ; Fri, 13 Jan 2023 09:13:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cJ4oIsZsFSP9tMOcvK1jsBj0z5nBGppUoEQ5ZQnO2h0=; b=yWqLSaQAK6mivpJfNFOAUTrqcc2o8ftA65b3/TB7zzR6SldUwWwa66ItkvZeUMx6LA uk7H4koWrdZJ2HmT5OA6EHgQtJmTlo9ADG7QcqDGHJUlo+MKQ+HaI0I1NL05ed5aLK7H EP7UFhv9r8YCnBMuFkfL8VPtDe/Rrjv7qYwenInwqJKQuWS6Lrr5IW9TVhBNq5NkQQVX /x6v7qe9WT2rnTrgJGfk1zbHGoJ9HHC3IHGp2u3NPs/1peBLglLWTKfpY1EduxV+TBQX bM6iD2j4MU873HuWphNab6PceDKFr+N8sE3eSYJnSzt1Qku7aRoo7WGVGimb8G82+XrK TGAw== X-Gm-Message-State: AFqh2kpX53O7NQf8ustTVjVMigaCS0X4DIElAy7cEW8Hst31/A7IpqYV D//JhVGUCVGoSL5jotHIbr1+cUriE7WhevtLTTGg3D1KoPZ8RmjymVSpWzCNM0yUcOYi+FNKh/Y izW7ENaOLpJoHC8c= X-Received: by 2002:a05:7500:3e82:b0:f0:2a85:d291 with SMTP id li2-20020a0575003e8200b000f02a85d291mr943449gab.45.1673629982588; Fri, 13 Jan 2023 09:13:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXsti17hvPeLI+G4kQQ9P6aPwTZY9XRfDGGXQyokydwCyl7lrX0u5s/QALqXWFZfCI/rED1n1w== X-Received: by 2002:a05:7500:3e82:b0:f0:2a85:d291 with SMTP id li2-20020a0575003e8200b000f02a85d291mr943407gab.45.1673629982166; Fri, 13 Jan 2023 09:13:02 -0800 (PST) Received: from [192.168.124.101] (149.37.22.93.rev.sfr.net. [93.22.37.149]) by smtp.gmail.com with ESMTPSA id bp37-20020a05620a45a500b006e99290e83fsm12911485qkb.107.2023.01.13.09.12.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Jan 2023 09:13:01 -0800 (PST) Message-ID: <522243a6-e312-c3b6-7d50-d3a2609e729d@redhat.com> Date: Fri, 13 Jan 2023 18:12:53 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v6 13/13] docs/devel: Align VFIO migration docs to v2 protocol Content-Language: en-US To: Avihai Horon , qemu-devel@nongnu.org Cc: Alex Williamson , Halil Pasic , Christian Borntraeger , Eric Farman , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Thomas Huth , Juan Quintela , "Dr. David Alan Gilbert" , "Michael S. Tsirkin" , Cornelia Huck , Paolo Bonzini , Stefan Hajnoczi , Fam Zheng , Eric Blake , Vladimir Sementsov-Ogievskiy , John Snow , qemu-s390x@nongnu.org, qemu-block@nongnu.org, Yishai Hadas , Jason Gunthorpe , Maor Gottlieb , Kirti Wankhede , Tarun Gupta , Joao Martins References: <20230112085020.15866-1-avihaih@nvidia.com> <20230112085020.15866-14-avihaih@nvidia.com> From: =?UTF-8?Q?C=c3=a9dric_Le_Goater?= In-Reply-To: <20230112085020.15866-14-avihaih@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 1/12/23 09:50, Avihai Horon wrote: > Now that VFIO migration protocol v2 has been implemented and v1 protocol > has been removed, update the documentation according to v2 protocol. > > Signed-off-by: Avihai Horon Reviewed-by: Cédric Le Goater Thanks, C. > --- > docs/devel/vfio-migration.rst | 68 ++++++++++++++++------------------- > 1 file changed, 30 insertions(+), 38 deletions(-) > > diff --git a/docs/devel/vfio-migration.rst b/docs/devel/vfio-migration.rst > index 9ff6163c88..1d50c2fe5f 100644 > --- a/docs/devel/vfio-migration.rst > +++ b/docs/devel/vfio-migration.rst > @@ -7,46 +7,39 @@ the guest is running on source host and restoring this saved state on the > destination host. This document details how saving and restoring of VFIO > devices is done in QEMU. > > -Migration of VFIO devices consists of two phases: the optional pre-copy phase, > -and the stop-and-copy phase. The pre-copy phase is iterative and allows to > -accommodate VFIO devices that have a large amount of data that needs to be > -transferred. The iterative pre-copy phase of migration allows for the guest to > -continue whilst the VFIO device state is transferred to the destination, this > -helps to reduce the total downtime of the VM. VFIO devices can choose to skip > -the pre-copy phase of migration by returning pending_bytes as zero during the > -pre-copy phase. > +Migration of VFIO devices currently consists of a single stop-and-copy phase. > +During the stop-and-copy phase the guest is stopped and the entire VFIO device > +data is transferred to the destination. > + > +The pre-copy phase of migration is currently not supported for VFIO devices. > +Support for VFIO pre-copy will be added later on. > > A detailed description of the UAPI for VFIO device migration can be found in > -the comment for the ``vfio_device_migration_info`` structure in the header > -file linux-headers/linux/vfio.h. > +the comment for the ``vfio_device_mig_state`` structure in the header file > +linux-headers/linux/vfio.h. > > VFIO implements the device hooks for the iterative approach as follows: > > -* A ``save_setup`` function that sets up the migration region and sets _SAVING > - flag in the VFIO device state. > +* A ``save_setup`` function that sets up migration on the source. > > -* A ``load_setup`` function that sets up the migration region on the > - destination and sets _RESUMING flag in the VFIO device state. > +* A ``load_setup`` function that sets the VFIO device on the destination in > + _RESUMING state. > > * A ``save_live_pending`` function that reads pending_bytes from the vendor > driver, which indicates the amount of data that the vendor driver has yet to > save for the VFIO device. > > -* A ``save_live_iterate`` function that reads the VFIO device's data from the > - vendor driver through the migration region during iterative phase. > - > * A ``save_state`` function to save the device config space if it is present. > > -* A ``save_live_complete_precopy`` function that resets _RUNNING flag from the > - VFIO device state and iteratively copies the remaining data for the VFIO > - device until the vendor driver indicates that no data remains (pending bytes > - is zero). > +* A ``save_live_complete_precopy`` function that sets the VFIO device in > + _STOP_COPY state and iteratively copies the data for the VFIO device until > + the vendor driver indicates that no data remains. > > * A ``load_state`` function that loads the config section and the data > - sections that are generated by the save functions above > + sections that are generated by the save functions above. > > * ``cleanup`` functions for both save and load that perform any migration > - related cleanup, including unmapping the migration region > + related cleanup. > > > The VFIO migration code uses a VM state change handler to change the VFIO > @@ -71,13 +64,13 @@ tracking can identify dirtied pages, but any page pinned by the vendor driver > can also be written by the device. There is currently no device or IOMMU > support for dirty page tracking in hardware. > > -By default, dirty pages are tracked when the device is in pre-copy as well as > -stop-and-copy phase. So, a page pinned by the vendor driver will be copied to > -the destination in both phases. Copying dirty pages in pre-copy phase helps > -QEMU to predict if it can achieve its downtime tolerances. If QEMU during > -pre-copy phase keeps finding dirty pages continuously, then it understands > -that even in stop-and-copy phase, it is likely to find dirty pages and can > -predict the downtime accordingly. > +By default, dirty pages are tracked during pre-copy as well as stop-and-copy > +phase. So, a page pinned by the vendor driver will be copied to the destination > +in both phases. Copying dirty pages in pre-copy phase helps QEMU to predict if > +it can achieve its downtime tolerances. If QEMU during pre-copy phase keeps > +finding dirty pages continuously, then it understands that even in stop-and-copy > +phase, it is likely to find dirty pages and can predict the downtime > +accordingly. > > QEMU also provides a per device opt-out option ``pre-copy-dirty-page-tracking`` > which disables querying the dirty bitmap during pre-copy phase. If it is set to > @@ -111,23 +104,22 @@ Live migration save path > | > migrate_init spawns migration_thread > Migration thread then calls each device's .save_setup() > - (RUNNING, _SETUP, _RUNNING|_SAVING) > + (RUNNING, _SETUP, _RUNNING) > | > - (RUNNING, _ACTIVE, _RUNNING|_SAVING) > + (RUNNING, _ACTIVE, _RUNNING) > If device is active, get pending_bytes by .save_live_pending() > If total pending_bytes >= threshold_size, call .save_live_iterate() > - Data of VFIO device for pre-copy phase is copied > Iterate till total pending bytes converge and are less than threshold > | > On migration completion, vCPU stops and calls .save_live_complete_precopy for > - each active device. The VFIO device is then transitioned into _SAVING state > - (FINISH_MIGRATE, _DEVICE, _SAVING) > + each active device. The VFIO device is then transitioned into _STOP_COPY state > + (FINISH_MIGRATE, _DEVICE, _STOP_COPY) > | > For the VFIO device, iterate in .save_live_complete_precopy until > pending data is 0 > - (FINISH_MIGRATE, _DEVICE, _STOPPED) > + (FINISH_MIGRATE, _DEVICE, _STOP) > | > - (FINISH_MIGRATE, _COMPLETED, _STOPPED) > + (FINISH_MIGRATE, _COMPLETED, _STOP) > Migraton thread schedules cleanup bottom half and exits > > Live migration resume path > @@ -136,7 +128,7 @@ Live migration resume path > :: > > Incoming migration calls .load_setup for each device > - (RESTORE_VM, _ACTIVE, _STOPPED) > + (RESTORE_VM, _ACTIVE, _STOP) > | > For each device, .load_state is called for that device section data > (RESTORE_VM, _ACTIVE, _RESUMING)