[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aFMh51vXbTNCf9mv@google.com>
Date: Wed, 18 Jun 2025 13:33:17 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: Oliver Upton <oliver.upton@...ux.dev>
Cc: James Houghton <jthoughton@...gle.com>, Paolo Bonzini <pbonzini@...hat.com>,
Jonathan Corbet <corbet@....net>, Marc Zyngier <maz@...nel.org>, Yan Zhao <yan.y.zhao@...el.com>,
Nikita Kalyazin <kalyazin@...zon.com>, Anish Moorthy <amoorthy@...gle.com>,
Peter Gonda <pgonda@...gle.com>, Peter Xu <peterx@...hat.com>,
David Matlack <dmatlack@...gle.com>, wei.w.wang@...el.com, kvm@...r.kernel.org,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.linux.dev
Subject: Re: [PATCH v3 04/15] KVM: Add common infrastructure for KVM Userfaults
On Wed, Jun 18, 2025, Oliver Upton wrote:
> > Signed-off-by: Sean Christopherson <seanjc@...gle.com>
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
Powered by blists - more mailing lists