Message ID | 20240801090117.3841080-5-tabba@google.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | KVM: Restricted mapping of guest_memfd at the host and pKVM/arm64 support | expand |
Hi Ackerley, On Mon, 5 Aug 2024 at 18:19, Ackerley Tng <ackerleytng@google.com> wrote: > > Fuad Tabba <tabba@google.com> writes: > > > Add the KVM capability KVM_CAP_GUEST_MEMFD_MAPPABLE, which is > > true if mapping guest memory is supported by the host. > > > > Signed-off-by: Fuad Tabba <tabba@google.com> > > --- > > include/uapi/linux/kvm.h | 3 ++- > > virt/kvm/kvm_main.c | 4 ++++ > > 2 files changed, 6 insertions(+), 1 deletion(-) > > > > <snip> > > Why do we need a cap for `KVM_CAP_GUEST_MEMFD_MAPPABLE` instead of just > making guest_memfd mmap-able? > > Is this to prevent breaking userspace, because a user might be relying > on guest_memfd being not mmap-able? To be able to check that the ability is there, since it is a new capability not available in Linux 6.9 not 6.10 (i.e., after guest_memfd()) was introduced. Cheers, /fuad
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index d03842abae57..783d0c3f4cb1 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -916,7 +916,8 @@ struct kvm_enable_cap { #define KVM_CAP_MEMORY_FAULT_INFO 232 #define KVM_CAP_MEMORY_ATTRIBUTES 233 #define KVM_CAP_GUEST_MEMFD 234 -#define KVM_CAP_VM_TYPES 235 +#define KVM_CAP_GUEST_MEMFD_MAPPABLE 235 +#define KVM_CAP_VM_TYPES 236 struct kvm_irq_routing_irqchip { __u32 irqchip; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index ec6255c7325e..485c39fc373c 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5077,6 +5077,10 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) #ifdef CONFIG_KVM_PRIVATE_MEM case KVM_CAP_GUEST_MEMFD: return !kvm || kvm_arch_has_private_mem(kvm); +#endif +#ifdef CONFIG_KVM_PRIVATE_MEM_MAPPABLE + case KVM_CAP_GUEST_MEMFD_MAPPABLE: + return !kvm || kvm_arch_has_private_mem(kvm); #endif default: break;
Add the KVM capability KVM_CAP_GUEST_MEMFD_MAPPABLE, which is true if mapping guest memory is supported by the host. Signed-off-by: Fuad Tabba <tabba@google.com> --- include/uapi/linux/kvm.h | 3 ++- virt/kvm/kvm_main.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-)