kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Binbin Wu <binbin.wu@linux.intel.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, robert.hu@linux.intel.com
Subject: Re: [PATCH 2/4] KVM: x86: Replace kvm_read_{cr0,cr4}_bits() with kvm_is_{cr0,cr4}_bit_set()
Date: Wed, 22 Mar 2023 10:21:22 -0700	[thread overview]
Message-ID: <ZBs5Eh0LrN/TMErj@google.com> (raw)
In-Reply-To: <20230322045824.22970-3-binbin.wu@linux.intel.com>

On Wed, Mar 22, 2023, Binbin Wu wrote:
> Replace kvm_read_{cr0,cr4}_bits() with kvm_is_{cr0,cr4}_bit_set() when only
> one bit is checked and bool is preferred as return value type.
> Also change the return value type from int to bool of is_pae(), is_pse() and
> is_paging().

I'm going to squash the obvious/direct changes with the introduction of the helpers,
and isolate is_{pae,pse,paging}() as those are more risky due to the multiple
casts (ulong=>int=>bool), and because the end usage isn't visible in the patch.

Case in point, there is a benign but in svm_set_cr0() that would be silently
fixed by converting is_paging() to return a bool:

	bool old_paging = is_paging(vcpu);

	...

	vcpu->arch.cr0 = cr0;

	if (!npt_enabled) {
		hcr0 |= X86_CR0_PG | X86_CR0_WP;
		if (old_paging != is_paging(vcpu))

The "old_paging != is_paging(vcpu)" compares a bool (1/0) against an int that
was an unsigned long (X86_CR0_PG/0), i.e. gets a false positive when paging is
enabled.

I'll post a fix and slot it in before this patch, both so that there's no silent
fixes and so that this changelog can reference the commit.

> ---
>  arch/x86/kvm/cpuid.c      |  4 ++--
>  arch/x86/kvm/mmu.h        |  2 +-
>  arch/x86/kvm/vmx/nested.c |  2 +-
>  arch/x86/kvm/vmx/vmx.c    |  2 +-
>  arch/x86/kvm/x86.c        | 20 ++++++++++----------
>  arch/x86/kvm/x86.h        | 16 ++++++++--------

This misses a few conversions in kvm_pmu_rdpmc(), I'll fix those when applying too.

  reply	other threads:[~2023-03-22 17:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22  4:58 [PATCH 0/4] Add and use helpers to check bit set in CR0/CR4 Binbin Wu
2023-03-22  4:58 ` [PATCH 1/4] KVM: x86: Add helpers to check bit set in CR0/CR4 and return in bool Binbin Wu
2023-03-22  4:58 ` [PATCH 2/4] KVM: x86: Replace kvm_read_{cr0,cr4}_bits() with kvm_is_{cr0,cr4}_bit_set() Binbin Wu
2023-03-22 17:21   ` Sean Christopherson [this message]
2023-03-23  1:09     ` Binbin Wu
2023-03-22  4:58 ` [PATCH 3/4] KVM: SVM: Remove implicit cast from ulong to bool in svm_can_emulate_instruction() Binbin Wu
2023-03-22  4:58 ` [PATCH 4/4] KVM: x86: Change return type of is_long_mode() to bool Binbin Wu
2023-03-22 22:33   ` Huang, Kai
2023-03-23 22:47 ` [PATCH 0/4] Add and use helpers to check bit set in CR0/CR4 Sean Christopherson

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=ZBs5Eh0LrN/TMErj@google.com \
    --to=seanjc@google.com \
    --cc=binbin.wu@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=robert.hu@linux.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).