Commit 15e6a7e5 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: x86/mmu: Use boolean returns for (S)PTE accessors

Return a 'bool' instead of an 'int' for various PTE accessors that are
boolean in nature, e.g. is_shadow_present_pte().  Returning an int is
goofy and potentially dangerous, e.g. if a flag being checked is moved
into the upper 32 bits of a SPTE, then the compiler may silently squash
the entire check since casting to an int is guaranteed to yield a
return value of '0'.

Opportunistically refactor is_last_spte() so that it naturally returns
a bool value instead of letting it implicitly cast 0/1 to false/true.

No functional change intended.
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Message-Id: <20210123003003.3137525-1-seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent c910662c
...@@ -152,7 +152,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, ...@@ -152,7 +152,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
* *
* TODO: introduce APIs to split these two cases. * TODO: introduce APIs to split these two cases.
*/ */
static inline int is_writable_pte(unsigned long pte) static inline bool is_writable_pte(unsigned long pte)
{ {
return pte & PT_WRITABLE_MASK; return pte & PT_WRITABLE_MASK;
} }
......
...@@ -185,23 +185,19 @@ static inline bool is_access_track_spte(u64 spte) ...@@ -185,23 +185,19 @@ static inline bool is_access_track_spte(u64 spte)
return !spte_ad_enabled(spte) && (spte & shadow_acc_track_mask) == 0; return !spte_ad_enabled(spte) && (spte & shadow_acc_track_mask) == 0;
} }
static inline int is_shadow_present_pte(u64 pte) static inline bool is_shadow_present_pte(u64 pte)
{ {
return (pte != 0) && !is_mmio_spte(pte); return (pte != 0) && !is_mmio_spte(pte);
} }
static inline int is_large_pte(u64 pte) static inline bool is_large_pte(u64 pte)
{ {
return pte & PT_PAGE_SIZE_MASK; return pte & PT_PAGE_SIZE_MASK;
} }
static inline int is_last_spte(u64 pte, int level) static inline bool is_last_spte(u64 pte, int level)
{ {
if (level == PG_LEVEL_4K) return (level == PG_LEVEL_4K) || is_large_pte(pte);
return 1;
if (is_large_pte(pte))
return 1;
return 0;
} }
static inline bool is_executable_pte(u64 spte) static inline bool is_executable_pte(u64 spte)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment