Re: [PATCH v3 04/15] KVM: Add common infrastructure for KVM Userfaults

From: Sean Christopherson
Date: Wed Jun 18 2025 - 16:33:27 EST


On Wed, Jun 18, 2025, Oliver Upton wrote:
> > Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>

No need for my SoB.

> > +#ifdef CONFIG_KVM_GENERIC_PAGE_FAULT
> > +bool kvm_do_userfault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault)
>
> The polarity of the return here feels weird. If we want a value of 0 to
> indicate success then int is a better return type.

The boolean is my fault/suggestion. My thinking is that it would make the callers
more intuitive, e.g. so that this reads "if do userfault, then exit to userspace
with -EFAULT".

if (kvm_do_userfault(vcpu, fault))
return -EFAULT;


> > +{
> > + struct kvm_memory_slot *slot = fault->slot;
> > + unsigned long __user *user_chunk;
> > + unsigned long chunk;
> > + gfn_t offset;
> > +
> > + if (!kvm_is_userfault_memslot(slot))
> > + return false;
> > +
> > + offset = fault->gfn - slot->base_gfn;
> > + user_chunk = slot->userfault_bitmap + (offset / BITS_PER_LONG);
> > +
> > + if (__get_user(chunk, user_chunk))
> > + return true;

And this path is other motiviation for returning a boolean. To me, return "success"
when a uaccess fails looks all kinds of wrong:

if (__get_user(chunk, user_chunk))
return 0;

That said, I don't have a super strong preference; normally I'm fanatical about
not returning booleans. :-D