Commit 82ffa13f authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: x86/mmu: constify uses of struct kvm_mmu_role_regs

struct kvm_mmu_role_regs is computed just once and then accessed.  Use
const to make this clearer, even though the const fields of struct
kvm_mmu_role_regs already prevent (or make it harder...) to modify
the contents of the struct.
Reviewed-by: default avatarDavid Matlack <dmatlack@google.com>
Reviewed-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent daed87b8
...@@ -197,7 +197,8 @@ struct kvm_mmu_role_regs { ...@@ -197,7 +197,8 @@ struct kvm_mmu_role_regs {
* the single source of truth for the MMU's state. * the single source of truth for the MMU's state.
*/ */
#define BUILD_MMU_ROLE_REGS_ACCESSOR(reg, name, flag) \ #define BUILD_MMU_ROLE_REGS_ACCESSOR(reg, name, flag) \
static inline bool __maybe_unused ____is_##reg##_##name(struct kvm_mmu_role_regs *regs)\ static inline bool __maybe_unused \
____is_##reg##_##name(const struct kvm_mmu_role_regs *regs) \
{ \ { \
return !!(regs->reg & flag); \ return !!(regs->reg & flag); \
} }
...@@ -244,7 +245,7 @@ static struct kvm_mmu_role_regs vcpu_to_role_regs(struct kvm_vcpu *vcpu) ...@@ -244,7 +245,7 @@ static struct kvm_mmu_role_regs vcpu_to_role_regs(struct kvm_vcpu *vcpu)
return regs; return regs;
} }
static int role_regs_to_root_level(struct kvm_mmu_role_regs *regs) static int role_regs_to_root_level(const struct kvm_mmu_role_regs *regs)
{ {
if (!____is_cr0_pg(regs)) if (!____is_cr0_pg(regs))
return 0; return 0;
...@@ -4748,7 +4749,7 @@ static void paging32_init_context(struct kvm_mmu *context) ...@@ -4748,7 +4749,7 @@ static void paging32_init_context(struct kvm_mmu *context)
} }
static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu, static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu,
struct kvm_mmu_role_regs *regs) const struct kvm_mmu_role_regs *regs)
{ {
union kvm_mmu_extended_role ext = {0}; union kvm_mmu_extended_role ext = {0};
...@@ -4771,7 +4772,7 @@ static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu, ...@@ -4771,7 +4772,7 @@ static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu,
} }
static union kvm_mmu_role kvm_calc_mmu_role_common(struct kvm_vcpu *vcpu, static union kvm_mmu_role kvm_calc_mmu_role_common(struct kvm_vcpu *vcpu,
struct kvm_mmu_role_regs *regs, const struct kvm_mmu_role_regs *regs,
bool base_only) bool base_only)
{ {
union kvm_mmu_role role = {0}; union kvm_mmu_role role = {0};
...@@ -4807,7 +4808,8 @@ static inline int kvm_mmu_get_tdp_level(struct kvm_vcpu *vcpu) ...@@ -4807,7 +4808,8 @@ static inline int kvm_mmu_get_tdp_level(struct kvm_vcpu *vcpu)
static union kvm_mmu_role static union kvm_mmu_role
kvm_calc_tdp_mmu_root_page_role(struct kvm_vcpu *vcpu, kvm_calc_tdp_mmu_root_page_role(struct kvm_vcpu *vcpu,
struct kvm_mmu_role_regs *regs, bool base_only) const struct kvm_mmu_role_regs *regs,
bool base_only)
{ {
union kvm_mmu_role role = kvm_calc_mmu_role_common(vcpu, regs, base_only); union kvm_mmu_role role = kvm_calc_mmu_role_common(vcpu, regs, base_only);
...@@ -4853,7 +4855,8 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu) ...@@ -4853,7 +4855,8 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
static union kvm_mmu_role static union kvm_mmu_role
kvm_calc_shadow_root_page_role_common(struct kvm_vcpu *vcpu, kvm_calc_shadow_root_page_role_common(struct kvm_vcpu *vcpu,
struct kvm_mmu_role_regs *regs, bool base_only) const struct kvm_mmu_role_regs *regs,
bool base_only)
{ {
union kvm_mmu_role role = kvm_calc_mmu_role_common(vcpu, regs, base_only); union kvm_mmu_role role = kvm_calc_mmu_role_common(vcpu, regs, base_only);
...@@ -4866,7 +4869,8 @@ kvm_calc_shadow_root_page_role_common(struct kvm_vcpu *vcpu, ...@@ -4866,7 +4869,8 @@ kvm_calc_shadow_root_page_role_common(struct kvm_vcpu *vcpu,
static union kvm_mmu_role static union kvm_mmu_role
kvm_calc_shadow_mmu_root_page_role(struct kvm_vcpu *vcpu, kvm_calc_shadow_mmu_root_page_role(struct kvm_vcpu *vcpu,
struct kvm_mmu_role_regs *regs, bool base_only) const struct kvm_mmu_role_regs *regs,
bool base_only)
{ {
union kvm_mmu_role role = union kvm_mmu_role role =
kvm_calc_shadow_root_page_role_common(vcpu, regs, base_only); kvm_calc_shadow_root_page_role_common(vcpu, regs, base_only);
...@@ -4884,7 +4888,7 @@ kvm_calc_shadow_mmu_root_page_role(struct kvm_vcpu *vcpu, ...@@ -4884,7 +4888,7 @@ kvm_calc_shadow_mmu_root_page_role(struct kvm_vcpu *vcpu,
} }
static void shadow_mmu_init_context(struct kvm_vcpu *vcpu, struct kvm_mmu *context, static void shadow_mmu_init_context(struct kvm_vcpu *vcpu, struct kvm_mmu *context,
struct kvm_mmu_role_regs *regs, const struct kvm_mmu_role_regs *regs,
union kvm_mmu_role new_role) union kvm_mmu_role new_role)
{ {
if (new_role.as_u64 == context->mmu_role.as_u64) if (new_role.as_u64 == context->mmu_role.as_u64)
...@@ -4907,7 +4911,7 @@ static void shadow_mmu_init_context(struct kvm_vcpu *vcpu, struct kvm_mmu *conte ...@@ -4907,7 +4911,7 @@ static void shadow_mmu_init_context(struct kvm_vcpu *vcpu, struct kvm_mmu *conte
} }
static void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, static void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu,
struct kvm_mmu_role_regs *regs) const struct kvm_mmu_role_regs *regs)
{ {
struct kvm_mmu *context = &vcpu->arch.root_mmu; struct kvm_mmu *context = &vcpu->arch.root_mmu;
union kvm_mmu_role new_role = union kvm_mmu_role new_role =
...@@ -4918,7 +4922,7 @@ static void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu, ...@@ -4918,7 +4922,7 @@ static void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu,
static union kvm_mmu_role static union kvm_mmu_role
kvm_calc_shadow_npt_root_page_role(struct kvm_vcpu *vcpu, kvm_calc_shadow_npt_root_page_role(struct kvm_vcpu *vcpu,
struct kvm_mmu_role_regs *regs) const struct kvm_mmu_role_regs *regs)
{ {
union kvm_mmu_role role = union kvm_mmu_role role =
kvm_calc_shadow_root_page_role_common(vcpu, regs, false); kvm_calc_shadow_root_page_role_common(vcpu, regs, false);
...@@ -5018,7 +5022,7 @@ static void init_kvm_softmmu(struct kvm_vcpu *vcpu) ...@@ -5018,7 +5022,7 @@ static void init_kvm_softmmu(struct kvm_vcpu *vcpu)
} }
static union kvm_mmu_role static union kvm_mmu_role
kvm_calc_nested_mmu_role(struct kvm_vcpu *vcpu, struct kvm_mmu_role_regs *regs) kvm_calc_nested_mmu_role(struct kvm_vcpu *vcpu, const struct kvm_mmu_role_regs *regs)
{ {
union kvm_mmu_role role; union kvm_mmu_role role;
......
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