All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Upton <oliver.upton@linux.dev>
To: Sean Christopherson <seanjc@google.com>
Cc: James Houghton <jthoughton@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Jonathan Corbet <corbet@lwn.net>, Marc Zyngier <maz@kernel.org>,
	Yan Zhao <yan.y.zhao@intel.com>,
	Nikita Kalyazin <kalyazin@amazon.com>,
	Anish Moorthy <amoorthy@google.com>,
	Peter Gonda <pgonda@google.com>, Peter Xu <peterx@redhat.com>,
	David Matlack <dmatlack@google.com>,
	wei.w.wang@intel.com, kvm@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev
Subject: Re: [PATCH v3 04/15] KVM: Add common infrastructure for KVM Userfaults
Date: Wed, 18 Jun 2025 15:43:21 -0700	[thread overview]
Message-ID: <aFNBCaLEdABfybmd@linux.dev> (raw)
In-Reply-To: <aFMh51vXbTNCf9mv@google.com>

On Wed, Jun 18, 2025 at 01:33:17PM -0700, Sean Christopherson wrote:
> On Wed, Jun 18, 2025, Oliver Upton wrote:
> > > Signed-off-by: Sean Christopherson <seanjc@google.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;

Agreed, this reads correctly. My only issue is that when I read the
function signature, "bool" is usually wired the other way around.

> > > +{
> > > +	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;

Yeah, that's gross. Although I would imagine we want to express
"failure" here, game over, out to userspace for resolution. So maybe:

	if (__get_user(chunk, user_chunk))
		return -EFAULT;

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

+1, it isn't _that_ big of a deal, just noticed it as part of review.

Thanks,
Oliver

  parent reply	other threads:[~2025-06-18 22:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18  4:24 [PATCH v3 00/15] KVM: Introduce KVM Userfault James Houghton
2025-06-18  4:24 ` [PATCH v3 01/15] KVM: x86/mmu: Move "struct kvm_page_fault" definition to asm/kvm_host.h James Houghton
2025-06-18  4:24 ` [PATCH v3 02/15] KVM: arm64: Add "struct kvm_page_fault" to gather common fault variables James Houghton
2025-06-18 19:26   ` Oliver Upton
2025-06-18 21:17     ` Sean Christopherson
2025-06-18  4:24 ` [PATCH v3 03/15] KVM: arm64: x86: Require "struct kvm_page_fault" for memory fault exits James Houghton
2025-06-18 20:00   ` Oliver Upton
2025-06-18 20:47     ` Sean Christopherson
2025-06-18 23:14       ` Oliver Upton
2025-06-19  1:22         ` Sean Christopherson
2025-06-18  4:24 ` [PATCH v3 04/15] KVM: Add common infrastructure for KVM Userfaults James Houghton
2025-06-18 19:40   ` Oliver Upton
2025-06-18 20:33     ` Sean Christopherson
2025-06-18 20:41       ` James Houghton
2025-06-18 22:43       ` Oliver Upton [this message]
2025-06-19  1:27         ` Sean Christopherson
2025-06-18 20:38     ` James Houghton
2025-06-18  4:24 ` [PATCH v3 05/15] KVM: x86: Add support for KVM userfault exits James Houghton
2025-07-30 21:11   ` James Houghton
2025-06-18  4:24 ` [PATCH v3 06/15] KVM: arm64: " James Houghton
2025-06-18  4:24 ` [PATCH v3 07/15] KVM: Enable and advertise " James Houghton
2025-06-18  4:24 ` [PATCH v3 08/15] KVM: selftests: Fix vm_mem_region_set_flags docstring James Houghton
2025-06-18  4:24 ` [PATCH v3 09/15] KVM: selftests: Fix prefault_mem logic James Houghton
2025-06-18  4:24 ` [PATCH v3 10/15] KVM: selftests: Add va_start/end into uffd_desc James Houghton
2025-06-18  4:24 ` [PATCH v3 11/15] KVM: selftests: Add KVM Userfault mode to demand_paging_test James Houghton
2025-06-18  4:24 ` [PATCH v3 12/15] KVM: selftests: Inform set_memory_region_test of KVM_MEM_USERFAULT James Houghton
2025-06-18  4:24 ` [PATCH v3 13/15] KVM: selftests: Add KVM_MEM_USERFAULT + guest_memfd toggle tests James Houghton
2025-06-18  4:24 ` [PATCH v3 14/15] KVM: Documentation: Fix section number for KVM_CAP_ARM_WRITABLE_IMP_ID_REGS James Houghton
2025-06-18  4:24 ` [PATCH v3 15/15] KVM: Documentation: Add KVM_CAP_USERFAULT and KVM_MEM_USERFAULT details James Houghton
2025-06-18 23:24 ` [PATCH v3 00/15] KVM: Introduce KVM Userfault Oliver Upton
2025-09-04 16:43 ` Nikita Kalyazin
2025-09-04 18:45   ` James Houghton
2025-09-05 12:27     ` Sean Christopherson
2025-09-23 12:13       ` Nikita Kalyazin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aFNBCaLEdABfybmd@linux.dev \
    --to=oliver.upton@linux.dev \
    --cc=amoorthy@google.com \
    --cc=corbet@lwn.net \
    --cc=dmatlack@google.com \
    --cc=jthoughton@google.com \
    --cc=kalyazin@amazon.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=pgonda@google.com \
    --cc=seanjc@google.com \
    --cc=wei.w.wang@intel.com \
    --cc=yan.y.zhao@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.