Skip to content

Commit bede6eb

Browse files
Binbin Wusean-jc
authored andcommitted
KVM: x86: Use boolean return value for is_{pae,pse,paging}()
Convert is_{pae,pse,paging}() to use kvm_is_cr{0,4}_bit_set() and return bools. Returning an "int" requires not one, but two implicit casts, first from "unsigned long" to "int", and then again to a "bool". Both casts are more than a bit dangerous; the ulong=>int casts would drop a bit on 64-bit kernels _if_ the bits in question weren't in the lower 32 bits, and the int=>bool cast can result in false negatives/positives, e.g. see commit 0c928ff ("KVM: SVM: Fix benign "bool vs. int" comparison in svm_set_cr0()"). Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Link: https://lore.kernel.org/r/20230322045824.22970-3-binbin.wu@linux.intel.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 607475c commit bede6eb

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
18021802

18031803
if (!npt_enabled) {
18041804
hcr0 |= X86_CR0_PG | X86_CR0_WP;
1805-
if (old_paging != !!is_paging(vcpu))
1805+
if (old_paging != is_paging(vcpu))
18061806
svm_set_cr4(vcpu, kvm_read_cr4(vcpu));
18071807
}
18081808

arch/x86/kvm/x86.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,19 @@ static inline bool mmu_is_nested(struct kvm_vcpu *vcpu)
171171
return vcpu->arch.walk_mmu == &vcpu->arch.nested_mmu;
172172
}
173173

174-
static inline int is_pae(struct kvm_vcpu *vcpu)
174+
static inline bool is_pae(struct kvm_vcpu *vcpu)
175175
{
176-
return kvm_read_cr4_bits(vcpu, X86_CR4_PAE);
176+
return kvm_is_cr4_bit_set(vcpu, X86_CR4_PAE);
177177
}
178178

179-
static inline int is_pse(struct kvm_vcpu *vcpu)
179+
static inline bool is_pse(struct kvm_vcpu *vcpu)
180180
{
181-
return kvm_read_cr4_bits(vcpu, X86_CR4_PSE);
181+
return kvm_is_cr4_bit_set(vcpu, X86_CR4_PSE);
182182
}
183183

184-
static inline int is_paging(struct kvm_vcpu *vcpu)
184+
static inline bool is_paging(struct kvm_vcpu *vcpu)
185185
{
186-
return likely(kvm_read_cr0_bits(vcpu, X86_CR0_PG));
186+
return likely(kvm_is_cr0_bit_set(vcpu, X86_CR0_PG));
187187
}
188188

189189
static inline bool is_pae_paging(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)