From: Nikita Kalyazin <kalyazin@amazon.com>
To: Vishal Annapurve <vannapurve@google.com>,
James Houghton <jthoughton@google.com>
Cc: "Kalyazin, Nikita" <kalyazin@amazon.co.uk>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"shuah@kernel.org" <shuah@kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"michael.day@amd.com" <michael.day@amd.com>,
"david@redhat.com" <david@redhat.com>,
"Roy, Patrick" <roypat@amazon.co.uk>,
"Thomson, Jack" <jackabt@amazon.co.uk>,
"Manwaring, Derek" <derekmn@amazon.com>,
"Cali, Marco" <xmarcalx@amazon.co.uk>
Subject: Re: [PATCH v5 1/2] KVM: guest_memfd: add generic population via write
Date: Mon, 15 Sep 2025 12:00:54 +0100 [thread overview]
Message-ID: <b325fb38-d34d-45e1-a5cb-eaf2b8c59549@amazon.com> (raw)
In-Reply-To: <CAGtprH_LF+F9q=wLGCp9bXNWhoVXH36q2o2YM-VbF1OT64Qcpg@mail.gmail.com>
On 13/09/2025 01:32, Vishal Annapurve wrote:
> On Fri, Sep 12, 2025 at 3:35 PM James Houghton <jthoughton@google.com> wrote:
>>
>>>>> +
>>>>> + if (folio_test_uptodate(folio)) {
>>>>> + folio_unlock(folio);
>>>>> + folio_put(folio);
>>>>> + return -ENOSPC;
>>>>
>>>> Does it actually matter for the folio not to be uptodate? It seems
>>>> unnecessarily restrictive not to be able to overwrite data if we're
>>>> saying that this is only usable for unencrypted memory anyway.
>>>
>>> In the context of direct map removal [1] it does actually because when
>>> we mark a folio as prepared, we remove it from the direct map making it
>>> inaccessible to the way write() performs the copy. It does not matter
>>> if direct map removal isn't enabled though. Do you think it should be
>>> conditional?
>>
>> Oh, good point. It's simpler (both to implement and to describe) to
>> disallow a second write() call in all cases (no matter if the direct
>> map for the page has been removed or if the contents have been
>> encrypted), so I'm all for leaving it unconditional like you have now.
>> Thanks!
>
> Are we deviating from the way read/write semantics work for the other
> filesystems? I don't think other filesystems carry this restriction of
> one-time-write only. Do we strictly need the differing semantics?
Yes, I believe we are deviating from other "regular" filesystems, but I
don't think what we propose is too uncommon as in "special" filesystems
such as sysfs subsequent calls to attributes like "remove" will likely
fail as well (not due to up-to-date flag though).
> Maybe it would be simpler to not overload uptodate flag and just not
> allow read/write if folio is not mapped in the direct map for non-conf
> VMs (assuming there could be other ways to deduce that information).
The only such interface I'm aware of is kernel_page_present() so the
check may look like:
for (i = 0; i < folio_nr_pages(folio); i++) {
struct page *page = folio_page(folio, i);
if (!kernel_page_present(page)) {
folio_unlock(folio);
folio_put(folio);
return -ENOSPC;
}
}
However, kernel_page_present() is not currently exported to modules.
Alternatively, the same effect can be achieved via checking for both
kvm_gmem_test_no_direct_map(inode) [1] and folio_test_uptodate(folio).
It would be the "conditional" check I mentioned earlier in the thread.
[1]: https://lore.kernel.org/kvm/20250912091708.17502-6-roypat@amazon.co.uk/
> Can there be users who want to populate the file ranges multiple times
> as it seems more performant?
Yes, you are right, there may be use cases like that. At the same time,
I think they are much less common because it's more typical for the
initial population to cover larger memory ranges and be sensitive to
performance.
>
>>
>>>
>>> [1]: https://lore.kernel.org/kvm/20250828093902.2719-1-roypat@amazon.co.uk
>>>
>>>>
next prev parent reply other threads:[~2025-09-15 11:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-02 11:19 [PATCH v5 0/2] KVM: guest_memfd: use write for population Kalyazin, Nikita
2025-09-02 11:20 ` [PATCH v5 1/2] KVM: guest_memfd: add generic population via write Kalyazin, Nikita
2025-09-10 21:23 ` James Houghton
2025-09-11 10:15 ` Nikita Kalyazin
2025-09-12 13:36 ` David Hildenbrand
2025-09-12 14:48 ` Nikita Kalyazin
2025-09-12 15:39 ` David Hildenbrand
2025-09-13 0:18 ` Vishal Annapurve
2025-09-15 11:01 ` Nikita Kalyazin
2025-09-12 22:34 ` James Houghton
2025-09-13 0:32 ` Vishal Annapurve
2025-09-15 11:00 ` Nikita Kalyazin [this message]
2025-09-16 1:08 ` Vishal Annapurve
2025-09-15 11:00 ` Nikita Kalyazin
2025-09-02 11:20 ` [PATCH v5 2/2] KVM: selftests: update guest_memfd write tests Kalyazin, Nikita
2025-09-10 21:37 ` [PATCH v5 0/2] KVM: guest_memfd: use write for population James Houghton
2025-09-11 10:15 ` Nikita Kalyazin
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=b325fb38-d34d-45e1-a5cb-eaf2b8c59549@amazon.com \
--to=kalyazin@amazon.com \
--cc=david@redhat.com \
--cc=derekmn@amazon.com \
--cc=jackabt@amazon.co.uk \
--cc=jthoughton@google.com \
--cc=kalyazin@amazon.co.uk \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=michael.day@amd.com \
--cc=pbonzini@redhat.com \
--cc=roypat@amazon.co.uk \
--cc=shuah@kernel.org \
--cc=vannapurve@google.com \
--cc=xmarcalx@amazon.co.uk \
/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