public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>,
	Vivek Goyal <vgoyal@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] KVM: async_pf: Cleanup kvm_setup_async_pf()
Date: Thu, 11 Jun 2020 08:35:57 -0700	[thread overview]
Message-ID: <20200611153557.GE29918@linux.intel.com> (raw)
In-Reply-To: <87sgf29f77.fsf@vitty.brq.redhat.com>

On Thu, Jun 11, 2020 at 10:31:08AM +0200, Vitaly Kuznetsov wrote:
> Sean Christopherson <sean.j.christopherson@intel.com> writes:
> 
> >
> > I'd also be in favor of changing the return type to a boolean.  I think
> > you alluded to it earlier, the current semantics are quite confusing as they
> > invert the normal "return 0 on success".
> 
> Yes, will do a follow-up.
> 
> KVM/x86 code has an intertwined mix of:
> - normal 'int' functions ('0 on success')
> - bool functions ('true'/'1' on success)
> - 'int' exit handlers ('1'/'0' on success depending if exit to userspace
>   was required)
> - ...
> 
> I think we can try to standardize this to:
> - 'int' when error is propagated outside of KVM (userspace, other kernel
>   subsystem,...)
> - 'bool' when the function is internal to KVM and the result is binary
>  ('is_exit_required()', 'was_pf_injected()', 'will_have_another_beer()',
>  ...)
> - 'enum' for the rest.
> And, if there's a good reason for making an exception, require a
> comment. (leaving aside everything returning a pointer, of course as
> these are self-explanatory -- unless it's 'void *' :-))

Agreed for 'bool' case, but 'int' versus 'enum' is less straightforward as
there are a huge number of functions that _may_ propagate an error outside
of KVM, including all of the exit handlers.  As Paolo point out[*], it'd
be quite easy to end up with a mixture of enum/#define and 0/1 code, which
would be an even bigger mess than what we have today.  There are
undoubtedly cases that could be converted to an enum, but they're probably
few and far between as it requires total encapsulation, e.g. the emulator.

[*] https://lkml.kernel.org/r/3d827e8b-a04e-0a93-4bb4-e0e9d59036da@redhat.com

      reply	other threads:[~2020-06-11 15:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10 17:55 [PATCH 1/2] KVM: async_pf: Cleanup kvm_setup_async_pf() Vitaly Kuznetsov
2020-06-10 17:55 ` [PATCH 2/2] KVM: async_pf: Inject 'page ready' event only if 'page not present' was previously injected Vitaly Kuznetsov
2020-06-10 19:32   ` Vivek Goyal
2020-06-10 19:47     ` Sean Christopherson
2020-06-10 19:57       ` Vivek Goyal
2020-06-10 23:53         ` Paolo Bonzini
2020-06-11  8:14     ` Vitaly Kuznetsov
2020-06-10 18:14 ` [PATCH 1/2] KVM: async_pf: Cleanup kvm_setup_async_pf() Sean Christopherson
2020-06-11  0:07   ` Paolo Bonzini
2020-06-11  8:31   ` Vitaly Kuznetsov
2020-06-11 15:35     ` Sean Christopherson [this message]

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=20200611153557.GE29918@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=vgoyal@redhat.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox