Re: [PATCH v3 02/70] RAMBlock: Add support of KVM private guest memfd

Xiaoyao Li
2023-11-16T02:45:51Z

On 11/16/2023 1:54 AM, David Hildenbrand wrote:
> On 15.11.23 08:14, Xiaoyao Li wrote:
>> Add KVM guest_memfd support to RAMBlock so both normal hva based memory
>> and kvm guest memfd based private memory can be associated in one
>> RAMBlock.
>>
>> Introduce new flag RAM_GUEST_MEMFD. When it's set, it calls KVM ioctl to
>> create private guest_memfd during RAMBlock setup.
>>
>> Note, RAM_GUEST_MEMFD is supposed to be set for memory backends of
>> confidential guests, such as TDX VM. How and when to set it for memory
>> backends will be implemented in the following patches.
>
> Can you elaborate (and add to the patch description if there is good
> reason) why we need that flag and why we cannot simply rely on the VM
> type instead to decide whether to allocate a guest_memfd or not?
>

The reason is, relying on the VM type is sort of hack that we need to
get the MachineState instance and retrieve the vm type info. I think
it's better not to couple them.

More importantly, it's not flexible and extensible for future case that
not all the memory need guest memfd.