KVM: split CONFIG_KVM_PRIVATE_MEMATTR_VM out of KVM_VM_MEMORY_ATTRIBUTES

With Linux 7.4 the "private" memory attribute was moved from the VM
to the individual guest_memfd file descriptor.  The old semantics are
available for backwards compatibility via CONFIG_KVM_VM_MEMORY_ATTRIBUTES.

However, this ties support for VM memory attributes entirely to
a backwards compatibility symbol, which is a problem when adding
VM memory attributes other than PRIVATE.  Thus, make
CONFIG_KVM_VM_MEMORY_ATTRIBUTES the equivalent of the old
CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES, and use a more descriptive name
for the private memory attribute.  Do this now, instead of waiting
for more attributes to come, before distros start adjusting
their build configuration.

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2026-10-19 13:54:07 -04:00
parent 3a74cf568b
commit 28d5df7b72
5 changed files with 13 additions and 7 deletions

View File

@ -3178,8 +3178,8 @@ Kernel parameters
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
CONFIG_KVM_PRIVATE_MEMATTR_VM=y. When
CONFIG_KVM_PRIVATE_MEMATTR_VM is not set, in-place
conversion is enabled (and cannot be disabled) if KVM
is built with private memory support.

View File

@ -76,9 +76,10 @@ config KVM_WERROR
If in doubt, say "N".
config KVM_VM_MEMORY_ATTRIBUTES
config KVM_PRIVATE_MEMATTR_VM
bool "Enable per-VM PRIVATE vs. SHARED attributes (for CoCo VMs)"
depends on KVM_SW_PROTECTED_VM || KVM_INTEL_TDX || KVM_AMD_SEV
select KVM_VM_MEMORY_ATTRIBUTES
help
Enable support for tracking PRIVATE vs. SHARED memory using per-VM
memory attributes. Using per-VM attributes is deprecated in favor of

View File

@ -2582,12 +2582,14 @@ bool kvm_arch_pre_set_vm_memory_attributes(struct kvm *kvm,
struct kvm_gfn_range *range);
bool kvm_arch_post_set_vm_memory_attributes(struct kvm *kvm,
struct kvm_gfn_range *range);
#endif /* CONFIG_KVM_VM_MEMORY_ATTRIBUTES */
#ifdef CONFIG_KVM_PRIVATE_MEMATTR_VM
static inline bool kvm_vm_is_private_gfn(struct kvm *kvm, gfn_t gfn)
{
return kvm_get_vm_memory_attributes(kvm, gfn) & KVM_MEMORY_ATTRIBUTE_PRIVATE;
}
#endif /* CONFIG_KVM_VM_MEMORY_ATTRIBUTES */
#endif /* CONFIG_KVM_PRIVATE_MEMATTR_VM */
#ifdef kvm_arch_has_private_mem
extern bool gmem_in_place_conversion;

View File

@ -101,3 +101,6 @@ config HAVE_KVM_ARCH_GMEM_INVALIDATE
config HAVE_KVM_ARCH_GMEM_POPULATE
bool
depends on KVM_GUEST_MEMFD
config KVM_VM_MEMORY_ATTRIBUTES
bool

View File

@ -105,8 +105,8 @@ 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 = !IS_ENABLED(CONFIG_KVM_VM_MEMORY_ATTRIBUTES);
#ifdef CONFIG_KVM_VM_MEMORY_ATTRIBUTES
bool __ro_after_init gmem_in_place_conversion = !IS_ENABLED(CONFIG_KVM_PRIVATE_MEMATTR_VM);
#ifdef CONFIG_KVM_PRIVATE_MEMATTR_VM
module_param(gmem_in_place_conversion, bool, 0444);
#endif
EXPORT_SYMBOL_FOR_KVM_INTERNAL(gmem_in_place_conversion);
@ -2713,7 +2713,7 @@ static void kvm_init_memory_attributes(void)
{
if (gmem_in_place_conversion)
static_call_update(__kvm_is_private_gfn, kvm_gmem_is_private_gfn);
#ifdef CONFIG_KVM_VM_MEMORY_ATTRIBUTES
#ifdef CONFIG_KVM_PRIVATE_MEMATTR_VM
else
static_call_update(__kvm_is_private_gfn, kvm_vm_is_private_gfn);
#endif