Re: [PATCH v12 23/45] KVM: Let userspace disable per-VM mem attributes, enable per-gmem attributes

From: Binbin Wu

Date: Wed Sep 02 2026 - 01:58:42 EST


On 9/2/2026 2:26 AM, Sean Christopherson wrote:
> On Tue, Sep 01, 2026, Fuad Tabba wrote:
>> Hi Sean, Ackerley,
>>
>> On Mon, 31 Aug 2026 at 01:25, Ackerley Tng via B4 Relay
>> <devnull+ackerleytng.google.com@xxxxxxxxxx> wrote:
>> ...
>>> + kvm.gmem_in_place_conversion=
>>> + [KVM] Controls whether KVM enables in-place conversion
>>> + support for guest_memfd and tracks the private/shared
>>> + state of memory per guest_memfd instead of per VM.
>>> +
>>> + If enabled, KVM enables the KVM_SET_MEMORY_ATTRIBUTES2
>>> + ioctl on guest_memfd file descriptors and disables the
>>> + legacy VM-scoped KVM_SET_MEMORY_ATTRIBUTES ioctl for
>>> + private memory state tracking. Only the
>>> + KVM_MEMORY_ATTRIBUTE_PRIVATE attribute moves to
>>> + per-guest_memfd tracking; other attributes remain
>>> + per-VM.
>>> +
>>> + This parameter toggles KVM's in-place conversion
>>> + capability support. Whether a VMM uses separate backends
>>> + or out-of-place memory management is determined by
>>> + userspace VMM design.
>>> +
>>> + Note, this parameter is only available when
>>> + CONFIG_KVM_VM_MEMORY_ATTRIBUTES=y. When
>>> + CONFIG_KVM_VM_MEMORY_ATTRIBUTES is not set, in-place
>>> + conversion is unconditionally enabled.
>>> +
>>> + Default is Y (on).
>>
>> The parameter is only settable when CONFIG_KVM_VM_MEMORY_ATTRIBUTES=y, and
>> in that config gmem_in_place_conversion initialises to
>> !IS_ENABLED(CONFIG_KVM_VM_MEMORY_ATTRIBUTES), i.e. N, not Y. Is the doc line
>> wrong, or is N-by-default not what was intended here?
>
> The doc is wrong. The intent is to maintain backwards compatibility with existing
> deployments if KVM_VM_MEMORY_ATTRIBUTES=y.
>

Will it result in the situation that kernel builds with CONFIG_KVM_VM_MEMORY_ATTRIBUTES
enabled by default for backwards compatibility, which requires users to explicitly enable
gmem_in_place_conversion by the kernel option? Then it effectively disables
gmem_in_place_conversion by default.

But I guess it's OK for CSPs since they know what they want.


>>> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
>>> index 05c518c9b8078..929fd3e1a01e6 100644
>>> --- a/virt/kvm/kvm_main.c
>>> +++ b/virt/kvm/kvm_main.c
>>> @@ -103,7 +103,10 @@ static bool __ro_after_init allow_unsafe_mappings;
>>> module_param(allow_unsafe_mappings, bool, 0444);
>>>
>>> #ifdef kvm_arch_has_private_mem
>>> -bool __ro_after_init gmem_in_place_conversion = false;
>>> +bool __ro_after_init gmem_in_place_conversion = !IS_ENABLED(CONFIG_KVM_VM_MEMORY_ATTRIBUTES);
>>> +#ifdef CONFIG_KVM_VM_MEMORY_ATTRIBUTES
>>> +module_param(gmem_in_place_conversion, bool, 0444);
>>> +#endif
>>> EXPORT_SYMBOL_FOR_KVM_INTERNAL(gmem_in_place_conversion);
>>> #endif
>