On Fri, May 08, 2026, Bibo Mao wrote:
> The type of guest_memfd in structure kvm_userspace_memory_region2
> is __u32, it is not correct to assign it with -1 and check whether
> it is smaller than 0. Here check flags with KVM_MEM_GUEST_MEMFD
> set.
> 
> Signed-off-by: Bibo Mao <[email protected]>
> ---
>  tools/testing/selftests/kvm/lib/kvm_util.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c 
> b/tools/testing/selftests/kvm/lib/kvm_util.c
> index 2a76eca7029d..9d3553f7e6a5 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -817,7 +817,7 @@ static void __vm_mem_region_delete(struct kvm_vm *vm,
>               kvm_munmap(region->mmap_alias, region->mmap_size);
>               close(region->fd);
>       }
> -     if (region->region.guest_memfd >= 0)
> +     if (region->region.flags & KVM_MEM_GUEST_MEMFD)

Hmm, it's a bit gross, but this is probably more robust?

        if ((int)region->region.guest_memfd < 0)

E.g. if we somehow end up in a state where KVM_MEM_GUEST_MEMFD is either stale
or the guest_memfd file was already closed.  I highly doubt either of those 
things
will happen, but logically it's the correct fix (the only reason guest_memfd is
a u32 is being it's part of the kernel's uAPI). 

Reply via email to