• Sean Christopherson's avatar
    KVM: selftests: Add support for creating private memslots · bb2968ad
    Sean Christopherson authored
    Add support for creating "private" memslots via KVM_CREATE_GUEST_MEMFD and
    KVM_SET_USER_MEMORY_REGION2.  Make vm_userspace_mem_region_add() a wrapper
    to its effective replacement, vm_mem_add(), so that private memslots are
    fully opt-in, i.e. don't require update all tests that add memory regions.
    
    Pivot on the KVM_MEM_PRIVATE flag instead of the validity of the "gmem"
    file descriptor so that simple tests can let vm_mem_add() do the heavy
    lifting of creating the guest memfd, but also allow the caller to pass in
    an explicit fd+offset so that fancier tests can do things like back
    multiple memslots with a single file.  If the caller passes in a fd, dup()
    the fd so that (a) __vm_mem_region_delete() can close the fd associated
    with the memory region without needing yet another flag, and (b) so that
    the caller can safely close its copy of the fd without having to first
    destroy memslots.
    Co-developed-by: default avatarAckerley Tng <ackerleytng@google.com>
    Signed-off-by: default avatarAckerley Tng <ackerleytng@google.com>
    Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
    Message-Id: <20231027182217.3615211-27-seanjc@google.com>
    Reviewed-by: default avatarFuad Tabba <tabba@google.com>
    Tested-by: default avatarFuad Tabba <tabba@google.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    bb2968ad
kvm_util.c 57.8 KB