Skip to content

Commit 4d66623

Browse files
RichardWeiYangbonzini
authored andcommitted
KVM: x86: remove check on nr_mmu_pages in kvm_arch_commit_memory_region()
* nr_mmu_pages would be non-zero only if kvm->arch.n_requested_mmu_pages is non-zero. * nr_mmu_pages is always non-zero, since kvm_mmu_calculate_mmu_pages() never return zero. Based on these two reasons, we can merge the two *if* clause and use the return value from kvm_mmu_calculate_mmu_pages() directly. This simplify the code and also eliminate the possibility for reader to believe nr_mmu_pages would be zero. Signed-off-by: Wei Yang <richard.weiyang@gmail.com> Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 711eff3 commit 4d66623

3 files changed

Lines changed: 4 additions & 8 deletions

File tree

‎arch/x86/include/asm/kvm_host.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ void kvm_mmu_clear_dirty_pt_masked(struct kvm *kvm,
12541254
gfn_t gfn_offset, unsigned long mask);
12551255
void kvm_mmu_zap_all(struct kvm *kvm);
12561256
void kvm_mmu_invalidate_mmio_sptes(struct kvm *kvm, u64 gen);
1257-
unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm);
1257+
unsigned int kvm_mmu_calculate_default_mmu_pages(struct kvm *kvm);
12581258
void kvm_mmu_change_mmu_pages(struct kvm *kvm, unsigned int kvm_nr_mmu_pages);
12591259

12601260
int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3);

‎arch/x86/kvm/mmu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6028,7 +6028,7 @@ int kvm_mmu_module_init(void)
60286028
/*
60296029
* Calculate mmu pages needed for kvm.
60306030
*/
6031-
unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm)
6031+
unsigned int kvm_mmu_calculate_default_mmu_pages(struct kvm *kvm)
60326032
{
60336033
unsigned int nr_mmu_pages;
60346034
unsigned int nr_pages = 0;

‎arch/x86/kvm/x86.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9429,13 +9429,9 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
94299429
const struct kvm_memory_slot *new,
94309430
enum kvm_mr_change change)
94319431
{
9432-
int nr_mmu_pages = 0;
9433-
94349432
if (!kvm->arch.n_requested_mmu_pages)
9435-
nr_mmu_pages = kvm_mmu_calculate_mmu_pages(kvm);
9436-
9437-
if (nr_mmu_pages)
9438-
kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
9433+
kvm_mmu_change_mmu_pages(kvm,
9434+
kvm_mmu_calculate_default_mmu_pages(kvm));
94399435

94409436
/*
94419437
* Dirty logging tracks sptes in 4k granularity, meaning that large

0 commit comments

Comments
 (0)