Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Nikita Kalyazin <kalyazin@amazon.com>
To: Vishal Annapurve <vannapurve@google.com>,
	David Hildenbrand <david@redhat.com>
Cc: James Houghton <jthoughton@google.com>,
	"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>,
	"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:01:04 +0100	[thread overview]
Message-ID: <3b56b4a0-ac52-4e1e-9f1b-7379af307292@amazon.com> (raw)
In-Reply-To: <CAGtprH8QjeuR90QJ7byxoAPfb30kmUEDhRhzqNZqSpR8y_+z9g@mail.gmail.com>



On 13/09/2025 01:18, Vishal Annapurve wrote:
> On Fri, Sep 12, 2025 at 8:39 AM David Hildenbrand <david@redhat.com> wrote:
>>
>>>>>> What's meant to happen if we do use this for CoCo VMs? I would expect
>>>>>> write() to fail, but I don't see why it would (seems like we need/want
>>>>>> a check that we aren't write()ing to private memory).
>>>>>
>>>>> I am not so sure that write() should fail even in CoCo VMs if we access
>>>>> not-yet-prepared pages.  My understanding was that the CoCoisation of
>>>>> the memory occurs during "preparation".  But I may be wrong here.
>>>>
>>>> But how do you handle that a page is actually inaccessible and should
>>>> not be touched?
>>>>
>>>> IOW, with CXL you could crash the host.
>>>>
>>>> There is likely some state check missing, or it should be restricted to
>>>> VM types.
>>>
>>> Sorry, I'm missing the link between VM types and CXL.  How are they related?
>>
>> I think what you explain below clarifies it.
>>
>>>
>>> My thinking was it is a regular (accessible) page until it is "prepared"
>>> by the CoCo hardware, which is currently tracked by the up-to-date flag,
>>> so it is safe to assume that until it is "prepared", it is accessible
>>> because it was allocated by filemap_grab_folio() ->
>>> filemap_alloc_folio() and hasn't been taken over by the CoCo hardware.
>>> What scenario can you see where it doesn't apply as of now?
>>
>> Thanks for clarifying, see below.
>>
>>>
>>> I am aware of an attempt to remove preparation tracking from
>>> guest_memfd, but it is still at an RFC stage AFAIK [1].
>>>
>>>>
>>>> Do we know how this would interact with the direct-map removal?
>>>
>>> I'm using folio_test_uptodate() to determine if the page has been
>>> removed from the direct map as kvm_gmem_mark_prepared() is what
>>> currently removes the page from the direct map and marks it as
>>> up-to-date.  [2] is a Firecracker feature branch where the two work in
>>> combination.
>>
>> Ah, okay. Yes, I recalled [1] that we wanted to change these semantics
>> to be "uptodate: was zeroed", and that preparation handling would be
>> essentially handled by the arch backend.
> 
> Yes, I think we should not be overloading uptodate flag to be an
> indicator of what is private for CoCo guests. Uptodate flag should
> just mean zeroed/fresh folio. It's possible that future allocator
> backing for huge pages already provides uptodate folios.

Good point, thanks for sharing.

> 
> If there is no current use case for read/write for CoCo VMs, I think
> it makes sense to disable it for now by checking the VM type before
> adding further overloading of uptodate flags.

Sounds fair.  I can add a check for the VM type and only allow it for 
KVM_X86_SW_PROTECTED_VM on x86.  When ARM CCA support [1] is added we 
should also check for KVM_VM_TYPE_ARM_NORMAL on ARM.

[1]: 
https://lore.kernel.org/kvm/20250820145606.180644-1-steven.price@arm.com

> 
>>
>> --
>> Cheers
>>
>> David / dhildenb
>>
>>


  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 [this message]
2025-09-12 22:34       ` James Houghton
2025-09-13  0:32         ` Vishal Annapurve
2025-09-15 11:00           ` Nikita Kalyazin
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=3b56b4a0-ac52-4e1e-9f1b-7379af307292@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