History

KVM: x86/mmu: Skip filling the gfn cache for guaranteed direct MMU topups

Don't bother filling the gfn array cache when the caller is a fully direct MMU, i.e. won't need a gfn array for shadow pages.

Sean Christopherson committed 6 years ago

Commit 378f5cd1 parent 96880882 files · +12 −10Browse files

Unified · Split

2 files
  1. arch/x86/kvm/mmu/mmu.c +10 −8
  2. arch/x86/kvm/mmu/paging_tmpl.h +2 −2
arch/x86/kvm/mmu/mmu.c+10−8
@@ -1102,7 +1102,7 @@ static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc) · 1101 unmodified lines
11021102 }
11031103 }
11041104
1105−static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu)
1105+static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu, bool maybe_indirect)
11061106 {
11071107 int r;
11081108
@@ -1115,10 +1115,12 @@ static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu) · 6 unmodified lines
11151115 PT64_ROOT_MAX_LEVEL);
11161116 if (r)
11171117 return r;
1118− r = mmu_topup_memory_cache(&vcpu->arch.mmu_gfn_array_cache,
1119− PT64_ROOT_MAX_LEVEL);
1120− if (r)
1121− return r;
1118+ if (maybe_indirect) {
1119+ r = mmu_topup_memory_cache(&vcpu->arch.mmu_gfn_array_cache,
1120+ PT64_ROOT_MAX_LEVEL);
1121+ if (r)
1122+ return r;
1123+ }
11221124 return mmu_topup_memory_cache(&vcpu->arch.mmu_page_header_cache,
11231125 PT64_ROOT_MAX_LEVEL);
11241126 }
@@ -4132,7 +4134,7 @@ static int direct_page_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, · 3007 unmodified lines
41324134 if (fast_page_fault(vcpu, gpa, error_code))
41334135 return RET_PF_RETRY;
41344136
4135− r = mmu_topup_memory_caches(vcpu);
4137+ r = mmu_topup_memory_caches(vcpu, false);
41364138 if (r)
41374139 return r;
41384140
@@ -5168,7 +5170,7 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu) · 1029 unmodified lines
51685170 {
51695171 int r;
51705172
5171− r = mmu_topup_memory_caches(vcpu);
5173+ r = mmu_topup_memory_caches(vcpu, !vcpu->arch.mmu->direct_map);
51725174 if (r)
51735175 goto out;
51745176 r = mmu_alloc_roots(vcpu);
@@ -5362,7 +5364,7 @@ static void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, · 187 unmodified lines
53625364 * or not since pte prefetch is skiped if it does not have
53635365 * enough objects in the cache.
53645366 */
5365− mmu_topup_memory_caches(vcpu);
5367+ mmu_topup_memory_caches(vcpu, true);
53665368
53675369 spin_lock(&vcpu->kvm->mmu_lock);
53685370
arch/x86/kvm/mmu/paging_tmpl.h+2−2
@@ -816,7 +816,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gpa_t addr, u32 error_code, · 815 unmodified lines
816816 return RET_PF_EMULATE;
817817 }
818818
819− r = mmu_topup_memory_caches(vcpu);
819+ r = mmu_topup_memory_caches(vcpu, true);
820820 if (r)
821821 return r;
822822
@@ -904,7 +904,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva, hpa_t root_hpa) · 81 unmodified lines
904904 * No need to check return value here, rmap_can_add() can
905905 * help us to skip pte prefetch later.
906906 */
907− mmu_topup_memory_caches(vcpu);
907+ mmu_topup_memory_caches(vcpu, true);
908908
909909 if (!VALID_PAGE(root_hpa)) {
910910 WARN_ON(1);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t