Skip to content

Commit 2f56f9e

Browse files
bibo-maochenhuacai
authored andcommitted
LoongArch: KVM: Select huge page only if secondary mmu supports it
Currently page level selection about secondary mmu depends on memory slot and page level about host mmu. There will be problems if page level of secondary mmu is zero already. Huge page cannot be selected if there is normal page mapped in secondary mmu already, since it is not supported to merge normal pages into huge pages now. So page level selection should depend on the following three conditions. 1. Memslot is aligned for huge page and vm is not migrating. 2. Page level of host mmu is also huge page. 3. Page level of secondary mmu is suituable for huge page. Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent b5d4e23 commit 2f56f9e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

arch/loongarch/kvm/mmu.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,20 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write)
858858

859859
/* Disable dirty logging on HugePages */
860860
level = 0;
861-
if (!fault_supports_huge_mapping(memslot, hva, write)) {
862-
level = 0;
863-
} else {
861+
if (fault_supports_huge_mapping(memslot, hva, write)) {
862+
/* Check page level about host mmu*/
864863
level = host_pfn_mapping_level(kvm, gfn, memslot);
864+
if (level == 1) {
865+
/*
866+
* Check page level about secondary mmu
867+
* Disable hugepage if it is normal page on
868+
* secondary mmu already
869+
*/
870+
ptep = kvm_populate_gpa(kvm, NULL, gpa, 0);
871+
if (ptep && !kvm_pte_huge(*ptep))
872+
level = 0;
873+
}
874+
865875
if (level == 1) {
866876
gfn = gfn & ~(PTRS_PER_PTE - 1);
867877
pfn = pfn & ~(PTRS_PER_PTE - 1);

0 commit comments

Comments
 (0)