KVM: Trivial cleanups
cover KVM: Trivial cleanups
From: Lai Jiangshan <[email protected]>
A small collection of trivial cleanups.
Lai Jiangshan (6):
KVM: X86/MMU: Remove unused macros from paging_tmpl.h
KVM: X86/MMU: Remove unused PT32_DIR_BASE_ADDR_MASK from mmu.c
KVM: X86/MMU: Update comments in paging_tmpl.h for the kinds of guest
PTEs
KVM: Rename ack_flush() to ack_kick()
KVM: X86/MMU: Remove useless mmu_topup_memory_caches() in
kvm_mmu_pte_write()
KVM: X86/SVM: Use root_level in svm_load_mmu_pgd()
arch/x86/kvm/mmu/mmu.c | 9 --------- arch/x86/kvm/mmu/paging_tmpl.h | 16 ++-------------- arch/x86/kvm/svm/svm.c | 2 +- virt/kvm/kvm_main.c | 4 ++-- 4 files changed, 5 insertions(+), 26 deletions(-)
Signature · 1 line
2.19.1.6.gb485710b
PATCH 1/6 KVM: X86/MMU: Remove unused macros from paging_tmpl.h
From: Lai Jiangshan <[email protected]>
Remove unused PT_BASE_ADDR_MASK, PT_LEVEL_BITS, and CMPXCHG.
--- arch/x86/kvm/mmu/paging_tmpl.h | 12 ------------ 1 file changed, 12 deletions(-)
arch/x86/kvm/mmu/paging_tmpl.h +0 -12
@@ -24,17 +24,14 @@#define pt_element_t u64#define guest_walker guest_walker64#define FNAME (name) paging##64_##name -#define PT_BASE_ADDR_MASK GUEST_PT64_BASE_ADDR_MASK#define PT_LVL_ADDR_MASK (lvl) PT64_LVL_ADDR_MASK(lvl)#define PT_LVL_OFFSET_MASK (lvl) PT64_LVL_OFFSET_MASK(lvl)#define PT_INDEX (addr, level) PT64_INDEX(addr, level) -#define PT_LEVEL_BITS PT64_LEVEL_BITS#define PT_GUEST_DIRTY_SHIFT PT_DIRTY_SHIFT#define PT_GUEST_ACCESSED_SHIFT PT_ACCESSED_SHIFT#define PT_HAVE_ACCESSED_DIRTY (mmu) true#ifdef CONFIG_X86_64 #define PT_MAX_FULL_LEVELS PT64_ROOT_MAX_LEVEL -#define CMPXCHG "cmpxchgq"#else #define PT_MAX_FULL_LEVELS 2#endif
@@ -42,30 +39,24 @@#define pt_element_t u32#define guest_walker guest_walker32#define FNAME (name) paging##32_##name -#define PT_BASE_ADDR_MASK PT32_BASE_ADDR_MASK#define PT_LVL_ADDR_MASK (lvl) PT32_LVL_ADDR_MASK(lvl)#define PT_LVL_OFFSET_MASK (lvl) PT32_LVL_OFFSET_MASK(lvl)#define PT_INDEX (addr, level) PT32_INDEX(addr, level) -#define PT_LEVEL_BITS PT32_LEVEL_BITS#define PT_MAX_FULL_LEVELS 2#define PT_GUEST_DIRTY_SHIFT PT_DIRTY_SHIFT#define PT_GUEST_ACCESSED_SHIFT PT_ACCESSED_SHIFT#define PT_HAVE_ACCESSED_DIRTY (mmu) true -#define CMPXCHG "cmpxchgl"#elif PTTYPE ==PTTYPE_EPT #define pt_element_t u64#define guest_walker guest_walkerEPT#define FNAME (name) ept_##name -#define PT_BASE_ADDR_MASK GUEST_PT64_BASE_ADDR_MASK#define PT_LVL_ADDR_MASK (lvl) PT64_LVL_ADDR_MASK(lvl)#define PT_LVL_OFFSET_MASK (lvl) PT64_LVL_OFFSET_MASK(lvl)#define PT_INDEX (addr, level) PT64_INDEX(addr, level) -#define PT_LEVEL_BITS PT64_LEVEL_BITS#define PT_GUEST_DIRTY_SHIFT 9#define PT_GUEST_ACCESSED_SHIFT 8#define PT_HAVE_ACCESSED_DIRTY (mmu) (!(mmu)->cpu_role.base.ad_disabled)#ifdef CONFIG_X86_64 -#define CMPXCHG "cmpxchgq"#endif #define PT_MAX_FULL_LEVELS PT64_ROOT_MAX_LEVEL#else
@@ -1076,15 +1067,12 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)#undef pt_element_t#undef guest_walker#undef FNAME -#undef PT_BASE_ADDR_MASK#undef PT_INDEX#undef PT_LVL_ADDR_MASK#undef PT_LVL_OFFSET_MASK -#undef PT_LEVEL_BITS#undef PT_MAX_FULL_LEVELS#undef gpte_to_gfn#undef gpte_to_gfn_lvl -#undef CMPXCHG#undef PT_GUEST_ACCESSED_MASK#undef PT_GUEST_DIRTY_MASK#undef PT_GUEST_DIRTY_SHIFT
Signature · 1 line
2.19.1.6.gb485710b
PATCH 2/6 KVM: X86/MMU: Remove unused PT32_DIR_BASE_ADDR_MASK from mmu.c
In reply to Lai JiangshanFrom: Lai Jiangshan <[email protected]>
It is unused.
--- arch/x86/kvm/mmu/mmu.c | 2 -- 1 file changed, 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +0 -2
@@ -125,8 +125,6 @@ module_param(dbg, bool, 0644);#define PT32_BASE_ADDR_MASK PAGE_MASK -#define PT32_DIR_BASE_ADDR_MASK \ - (PAGE_MASK & ~((1ULL << (PAGE_SHIFT + PT32_LEVEL_BITS)) - 1))#define PT32_LVL_ADDR_MASK (level) \ (PAGE_MASK & ~((1ULL << (PAGE_SHIFT + (((level) - 1) \ * PT32_LEVEL_BITS))) - 1))
Signature · 1 line
2.19.1.6.gb485710b
PATCH 3/6 KVM: X86/MMU: Update comments in paging_tmpl.h for the kinds of guest PTEs
In reply to Lai JiangshanFrom: Lai Jiangshan <[email protected]>
Add EPT PTEs into the comments.
--- arch/x86/kvm/mmu/paging_tmpl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu/paging_tmpl.h +2 -2
@@ -16,8 +16,8 @@*/ /* -* We need the mmu code to access both 32-bit and 64-bit guest ptes, -* so the code in this file is compiled twice, once per pte size. +* We need the MMU code to access 32-bit, 64-bit PTEs and 64-bit EPT PTEs, +* so the code in this file is compiled three times, once per a kind of PTE. */ #if PTTYPE ==64
Signature · 1 line
2.19.1.6.gb485710b
PATCH 4/6 KVM: Rename ack_flush() to ack_kick()
In reply to Lai JiangshanFrom: Lai Jiangshan <[email protected]>
Make it use the same verb as in kvm_kick_many_cpus().
--- virt/kvm/kvm_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
virt/kvm/kvm_main.c +2 -2
@@ -235,7 +235,7 @@ static bool kvm_request_needs_ipi(struct kvm_vcpu *vcpu, unsigned req)return mode ==IN_GUEST_MODE ; } -static void ack_flush (void *_completed) +static void ack_kick (void *_completed) { }
@@ -244,7 +244,7 @@ static inline bool kvm_kick_many_cpus(struct cpumask *cpus, bool wait)if (cpumask_empty (cpus))return false; -smp_call_function_many (cpus, ack_flush,NULL , wait); +smp_call_function_many (cpus, ack_kick,NULL , wait);return true; }
Signature · 1 line
2.19.1.6.gb485710b
PATCH 5/6 KVM: X86/MMU: Remove useless mmu_topup_memory_caches() in kvm_mmu_pte_write()
In reply to Lai JiangshanFrom: Lai Jiangshan <[email protected]>
Since the commit c5e2184d1544("KVM: x86/mmu: Remove the defunct update_pte() paging hook"), kvm_mmu_pte_write() no longer uses the rmap cache.
So remove mmu_topup_memory_caches() in it.
--- arch/x86/kvm/mmu/mmu.c | 7 ------- 1 file changed, 7 deletions(-)
arch/x86/kvm/mmu/mmu.c +0 -7
@@ -5326,13 +5326,6 @@ static void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,pgprintk ("%s: gpa %llx bytes %d\n" , __func__, gpa, bytes); -/* -* No need to care whether allocation memory is successful -* or not since pte prefetch is skipped if it does not have -* enough objects in the cache. -*/ -mmu_topup_memory_caches (vcpu, true); -write_lock (&vcpu->kvm->mmu_lock); gentry =mmu_pte_write_fetch_gpte (vcpu, &gpa, &bytes);
Signature · 1 line
2.19.1.6.gb485710b
PATCH 6/6 KVM: X86/SVM: Use root_level in svm_load_mmu_pgd()
In reply to Lai JiangshanFrom: Lai Jiangshan <[email protected]>
The caller always call it with root_level = vcpu->arch.mmu->root_role.level.
--- arch/x86/kvm/svm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/svm.c +1 -1
@@ -3951,7 +3951,7 @@ static void svm_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa,hv_track_root_tdp (vcpu, root_hpa); cr3 = vcpu->arch.cr3; - }else if (vcpu->arch.mmu->root_role.level >=PT64_ROOT_4LEVEL ) { + }else if (root_level >=PT64_ROOT_4LEVEL ) { cr3 =__sme_set (root_hpa) |kvm_get_active_pcid (vcpu); }else {/* PCID in the guest should be impossible with a 32-bit MMU. */
Signature · 1 line
2.19.1.6.gb485710b
Re: [PATCH 6/6] KVM: X86/SVM: Use root_level in svm_load_mmu_pgd()
Quoted 3 lines · Lai Jiangshan
From: Lai Jiangshan <[email protected]>
The caller always call it with
root_level=vcpu->arch.mmu->root_role.level.
It'd be helpful to be more specific about the caller. e.g.
Use root_level in svm_load_mmu_pg() rather that looking up the root level in vcpu->arch.mmu->root_role.level. svm_load_mmu_pgd() has only one caller, kvm_mmu_load_pgd(), which always passes vcpu->arch.mmu->root_role.level as root_level.
No functional change intended.
Quoted 22 lines
Signed-off-by Lai Jiangshan <[email protected]>--- arch/x86/kvm/svm/svm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/svm/svm.c +1
-1@@ -3951,7 +3951,7 @@ static void svm_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa,hv_track_root_tdp (vcpu, root_hpa); cr3 = vcpu->arch.cr3; - }else if (vcpu->arch.mmu->root_role.level >=PT64_ROOT_4LEVEL ) { + }else if (root_level >=PT64_ROOT_4LEVEL ) { cr3 =__sme_set (root_hpa) |kvm_get_active_pcid (vcpu); }else {/* PCID in the guest should be impossible with a 32-bit MMU. */ Signature · 1 line
2.19.1.6.gb485710b
Quoted 3 lines · Lai Jiangshan
From: Lai Jiangshan <[email protected]>
A small collection of trivial cleanups.
Nice cleanups. My only feedback is on the commit messages, which are a bit terse. Here's what I would recommend:
- Explain what the commit does in the first sentence/paragraph of the commit message and then explain why/background info.
- Include "No functional change intended." for commits that are expected to be no-ops. It's pretty obvious for most of these changes but it's still nice that have to convey your intent.
Commit messages aside:
Quoted 20 lines
Lai Jiangshan (6):
KVM: X86/MMU: Remove unused macros frompaging_tmpl.h
KVM: X86/MMU: Remove unusedPT32_DIR_BASE_ADDR_MASKfrommmu.c
KVM: X86/MMU: Update comments inpaging_tmpl.hfor the kinds of guest
PTEs
KVM: Renameack_flush()toack_kick()
KVM: X86/MMU: Remove uselessmmu_topup_memory_caches()inkvm_mmu_pte_write()KVM: X86/SVM: Use
root_levelinsvm_load_mmu_pgd()arch/x86/kvm/mmu/mmu.c | 9 --------- arch/x86/kvm/mmu/paging_tmpl.h | 16 ++-------------- arch/x86/kvm/svm/svm.c | 2 +- virt/kvm/kvm_main.c | 4 ++-- 4 files changed, 5 insertions(+), 26 deletions(-)Signature · 1 line
2.19.1.6.gb485710b
Queued patches 2 and 4-6, thanks.
I also applied David's rewarded commit mesage for patch 6.
Paolo