From: Binbin Wu <binbin.wu@linux.intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Chao Gao <chao.gao@intel.com>,
Robert Hoo <robert.hu@linux.intel.com>,
pbonzini@redhat.com, kvm@vger.kernel.org
Subject: Re: [PATCH v5 2/5] [Trivial]KVM: x86: Explicitly cast ulong to bool in kvm_set_cr3()
Date: Mon, 20 Mar 2023 21:56:15 +0800 [thread overview]
Message-ID: <4ff37ff4-b89e-8683-f6ea-865211ae01d2@linux.intel.com> (raw)
In-Reply-To: <75f628e3-9621-ac9e-a258-33efc7ce56af@linux.intel.com>
On 3/20/2023 8:05 PM, Binbin Wu wrote:
>
> On 3/11/2023 4:22 AM, Sean Christopherson wrote:
>> As Chao pointed out, this does not belong in the LAM series. And
>> FWIW, I highly
>> recommend NOT tagging things as Trivial. If you're wrong and the
>> patch _isn't_
>> trivial, it only slows things down. And if you're right, then
>> expediting the
>> patch can't possibly be necessary.
>>
>> On Fri, Mar 03, 2023, Robert Hoo wrote:
>>> On Thu, 2023-03-02 at 15:24 +0800, Chao Gao wrote:
>>>>> - bool pcid_enabled = kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE);
>>>>> + bool pcid_enabled = !!kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE);
>>>>>
>>>>> if (pcid_enabled) {
>>>>> skip_tlb_flush = cr3 & X86_CR3_PCID_NOFLUSH;
>>>> pcid_enabled is used only once. You can drop it, i.e.,
>>>>
>>>> if (kvm_read_cr4_bits(vcpu, X86_CR4_PCIDE)) {
>>>>
>>> Emm, that's actually another point.
>>> Though I won't object so, wouldn't this be compiler optimized?
>>>
>>> And my point was: honor bool type, though in C implemention it's 0 and
>>> !0, it has its own type value: true, false.
>>> Implicit type casting always isn't good habit.
>> I don't disagree, but I also don't particularly want to "fix" one
>> case while
>> ignoring the many others, e.g. kvm_handle_invpcid() has the exact
>> same "buggy"
>> pattern.
>>
>> I would be supportive of a patch that adds helpers and then converts
>> all of the
>> relevant CR0/CR4 checks though...
>
> Hi Sean, I can cook a patch by your suggesion and sent out the patch
> seperately.
Sean, besides the call of kvm_read_cr0_bits() and kvm_read_cr4_bits(),
there are also a lot checks in if statement like
if ( cr4 & X86_CR4_XXX )
or
if ( cr0 & X86_CR0_XXX )
I suppose these usages are OK, right?
>
>
>>
>> diff --git a/arch/x86/kvm/kvm_cache_regs.h
>> b/arch/x86/kvm/kvm_cache_regs.h
>> index 4c91f626c058..6e3cb958afdd 100644
>> --- a/arch/x86/kvm/kvm_cache_regs.h
>> +++ b/arch/x86/kvm/kvm_cache_regs.h
>> @@ -157,6 +157,14 @@ static inline ulong kvm_read_cr0_bits(struct
>> kvm_vcpu *vcpu, ulong mask)
>> return vcpu->arch.cr0 & mask;
>> }
>> +static __always_inline bool kvm_is_cr0_bit_set(struct kvm_vcpu *vcpu,
>> + unsigned long cr0_bit)
>> +{
>> + BUILD_BUG_ON(!is_power_of_2(cr0_bit));
>> +
>> + return !!kvm_read_cr0_bits(vcpu, cr0_bit);
>> +}
>> +
>> static inline ulong kvm_read_cr0(struct kvm_vcpu *vcpu)
>> {
>> return kvm_read_cr0_bits(vcpu, ~0UL);
>> @@ -178,6 +186,14 @@ static inline ulong kvm_read_cr3(struct kvm_vcpu
>> *vcpu)
>> return vcpu->arch.cr3;
>> }
>> +static __always_inline bool kvm_is_cr4_bit_set(struct kvm_vcpu *vcpu,
>> + unsigned long cr4_bit)
>> +{
>> + BUILD_BUG_ON(!is_power_of_2(cr4_bit));
>> +
>> + return !!kvm_read_cr4_bits(vcpu, cr4_bit);
>> +}
>> +
next prev parent reply other threads:[~2023-03-20 13:56 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-27 8:45 [PATCH v5 0/5] Linear Address Masking (LAM) KVM Enabling Robert Hoo
2023-02-27 8:45 ` [PATCH v5 1/5] KVM: x86: Virtualize CR4.LAM_SUP Robert Hoo
2023-03-02 7:17 ` Chao Gao
2023-03-02 12:03 ` Binbin Wu
2023-03-02 13:00 ` Robert Hoo
2023-02-27 8:45 ` [PATCH v5 2/5] [Trivial]KVM: x86: Explicitly cast ulong to bool in kvm_set_cr3() Robert Hoo
2023-03-02 7:24 ` Chao Gao
2023-03-03 3:23 ` Robert Hoo
2023-03-10 20:22 ` Sean Christopherson
2023-03-20 12:05 ` Binbin Wu
2023-03-20 13:56 ` Binbin Wu [this message]
2023-03-21 16:03 ` Sean Christopherson
2023-02-27 8:45 ` [PATCH v5 3/5] KVM: x86: Virtualize CR3.LAM_{U48,U57} Robert Hoo
2023-03-03 6:21 ` Chao Gao
2023-03-03 14:23 ` Robert Hoo
2023-03-03 15:53 ` Chao Gao
2023-03-05 1:31 ` Robert Hoo
2023-03-10 20:12 ` Sean Christopherson
2023-03-20 6:57 ` Binbin Wu
2023-02-27 8:45 ` [PATCH v5 4/5] KVM: x86: emulation: Apply LAM mask when emulating data access in 64-bit mode Robert Hoo
2023-03-02 6:41 ` Binbin Wu
2023-03-02 13:16 ` Robert Hoo
2023-03-03 1:08 ` Binbin Wu
2023-03-03 3:16 ` Robert Hoo
2023-03-03 3:35 ` Binbin Wu
2023-03-03 9:00 ` Robert Hoo
2023-03-03 10:18 ` Binbin Wu
2023-03-10 20:26 ` Sean Christopherson
2023-03-02 8:55 ` Chao Gao
2023-03-02 11:31 ` Binbin Wu
2023-03-10 20:23 ` Sean Christopherson
2023-02-27 8:45 ` [PATCH v5 5/5] KVM: x86: LAM: Expose LAM CPUID to user space VMM Robert Hoo
2023-03-03 6:46 ` Chao Gao
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=4ff37ff4-b89e-8683-f6ea-865211ae01d2@linux.intel.com \
--to=binbin.wu@linux.intel.com \
--cc=chao.gao@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=robert.hu@linux.intel.com \
--cc=seanjc@google.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).