From: Andrey Gruzdev <andrey.gruzdev@virtuozzo.com>
To: David Hildenbrand <david@redhat.com>, qemu-devel@nongnu.org
Cc: Den Lunev <den@openvz.org>, Eric Blake <eblake@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Juan Quintela <quintela@redhat.com>,
"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Peter Xu <peterx@redhat.com>
Subject: Re: [PATCH for-6.0 3/3] migration: Pre-fault memory before starting background snasphot
Date: Wed, 31 Mar 2021 21:36:53 +0300 [thread overview]
Message-ID: <0555b956-2431-f3c7-cfbe-9a57acfb3cde@virtuozzo.com> (raw)
In-Reply-To: <79c7a862-58d8-2fa4-da75-f299f1728d52@redhat.com>
On 31.03.2021 20:37, David Hildenbrand wrote:
> On 31.03.21 19:33, David Hildenbrand wrote:
>> On 31.03.21 19:28, Andrey Gruzdev wrote:
>>> This commit solves the issue with userfault_fd WP feature that
>>> background snapshot is based on. For any never poluated or discarded
>>> memory page, the UFFDIO_WRITEPROTECT ioctl() would skip updating
>>> PTE for that page, thereby loosing WP setting for it.
>>>
>>> So we need to pre-fault pages for each RAM block to be protected
>>> before making a userfault_fd wr-protect ioctl().
>>>
>>> Signed-off-by: Andrey Gruzdev <andrey.gruzdev@virtuozzo.com>
>>> ---
>>> migration/migration.c | 6 ++++++
>>> migration/ram.c | 48
>>> +++++++++++++++++++++++++++++++++++++++++++
>>> migration/ram.h | 1 +
>>> 3 files changed, 55 insertions(+)
>>>
>>> diff --git a/migration/migration.c b/migration/migration.c
>>> index be4729e7c8..71bce15a1b 100644
>>> --- a/migration/migration.c
>>> +++ b/migration/migration.c
>>> @@ -3827,6 +3827,12 @@ static void *bg_migration_thread(void *opaque)
>>> update_iteration_initial_status(s);
>>> + /*
>>> + * Prepare for tracking memory writes with UFFD-WP - populate
>>> + * RAM pages before protecting.
>>> + */
>>> + ram_write_tracking_prepare();
>>> +
>>> qemu_savevm_state_header(s->to_dst_file);
>>> qemu_savevm_state_setup(s->to_dst_file);
>>> diff --git a/migration/ram.c b/migration/ram.c
>>> index 40e78952ad..24c8627214 100644
>>> --- a/migration/ram.c
>>> +++ b/migration/ram.c
>>> @@ -1560,6 +1560,54 @@ out:
>>> return ret;
>>> }
>>> +/*
>>> + * ram_block_populate_pages: populate memory in the RAM block by
>>> reading
>>> + * an integer from the beginning of each page.
>>> + *
>>> + * Since it's solely used for userfault_fd WP feature, here we just
>>> + * hardcode page size to qemu_real_host_page_size.
>>> + *
>>> + * @bs: RAM block to populate
>>> + */
>>> +static void ram_block_populate_pages(RAMBlock *bs)
>>
>> Usually we use "rb" or "block"; however migration/ram.c seems to do
>> things differently.
>>
>>> +{
>>> + char *ptr = (char *) bs->host;
>>> +
>>> + for (ram_addr_t offset = 0; offset < bs->used_length;
>>> + offset += qemu_real_host_page_size) {
>>> + char tmp = *(ptr + offset);
>>
>> ^ missing empty line.
>>
>>> + /* Don't optimize the read out */
>>> + asm volatile("" : "+r" (tmp));
>>> + }
>>
>>
>> Reviewed-by: David Hildenbrand <david@redhat.com>
>>
>>
>> and might want to add
>>
>> Reported-by: David Hildenbrand <david@redhat.com>
>>
>> (also to patch #2)
>>
>
> Also, proper "Fixes:" tags would be handy as well.
>
Ok, thanks.
--
Andrey Gruzdev, Principal Engineer
Virtuozzo GmbH +7-903-247-6397
virtuzzo.com
next prev parent reply other threads:[~2021-03-31 18:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-31 17:28 [PATCH for-6.0 0/3] migration: Fixes to the 'background-snapshot' code Andrey Gruzdev
2021-03-31 17:28 ` [PATCH for-6.0 1/3] migration: Fix missing qemu_fflush() on buffer file in bg_migration_thread Andrey Gruzdev
2021-03-31 17:28 ` [PATCH for-6.0 2/3] migration: Inhibit virtio-balloon for the duration of background snapshot Andrey Gruzdev
2021-03-31 17:28 ` [PATCH for-6.0 3/3] migration: Pre-fault memory before starting background snasphot Andrey Gruzdev
2021-03-31 17:33 ` David Hildenbrand
2021-03-31 17:37 ` David Hildenbrand
2021-03-31 18:36 ` Andrey Gruzdev [this message]
2021-03-31 18:35 ` Andrey Gruzdev
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=0555b956-2431-f3c7-cfbe-9a57acfb3cde@virtuozzo.com \
--to=andrey.gruzdev@virtuozzo.com \
--cc=armbru@redhat.com \
--cc=david@redhat.com \
--cc=den@openvz.org \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.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).