public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Jim Mattson <jmattson@google.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com
Subject: Re: [PATCH] kvm: x86: Convert return type of *is_valid_rdpmc_ecx() to bool
Date: Fri, 5 Nov 2021 00:18:39 +0000	[thread overview]
Message-ID: <YYR4X7oDXVClT7dx@google.com> (raw)
In-Reply-To: <20211104223246.443738-1-jmattson@google.com>

KVM: x86:

On Thu, Nov 04, 2021, Jim Mattson wrote:
> These function names sound like predicates, and they have siblings,
> *is_valid_msr(), which _are_ predicates. Moreover, there are comments
> that essentially warn that these functions behave unexpectedly.
> 
> Flip the polarity of the return values, so that they become
> predicates, and convert the boolean result to a success/failure code
> at the outer call site.
> 
> Signed-off-by: Jim Mattson <jmattson@google.com>
> ---

Reviewed-by: Sean Christopherson <seanjc@google.com> 

> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index c1c4e2b05a63..d7def720227d 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -7328,7 +7328,9 @@ static void emulator_set_smbase(struct x86_emulate_ctxt *ctxt, u64 smbase)
>  static int emulator_check_pmc(struct x86_emulate_ctxt *ctxt,
>  			      u32 pmc)
>  {
> -	return kvm_pmu_is_valid_rdpmc_ecx(emul_to_vcpu(ctxt), pmc);
> +	if (kvm_pmu_is_valid_rdpmc_ecx(emul_to_vcpu(ctxt), pmc))
> +		return 0;
> +	return -EINVAL;


Heh, after seeing my off-the-cuff suggestion in a patch, I'd probably prefer the
more usual "return 0 at the end".  Either way is a-ok though, and waaaay better
than kvm_pmu_is_valid_rdpmc_ecx() returning '0' on success :-)

	if (!kvm_pmu_is_valid_rdpmc_ecx(emul_to_vcpu(ctxt), pmc))
		return -EINVAL;

	return 0;

>  }
>  
>  static int emulator_read_pmc(struct x86_emulate_ctxt *ctxt,
> -- 
> 2.34.0.rc0.344.g81b53c2807-goog
> 

      reply	other threads:[~2021-11-05  0:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 22:32 [PATCH] kvm: x86: Convert return type of *is_valid_rdpmc_ecx() to bool Jim Mattson
2021-11-05  0:18 ` 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=YYR4X7oDXVClT7dx@google.com \
    --to=seanjc@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.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