diff options
author | Bibo Mao <maobibo@loongson.cn> | 2024-07-09 11:25:51 +0300 |
---|---|---|
committer | Huacai Chen <chenhuacai@loongson.cn> | 2024-07-09 11:25:51 +0300 |
commit | 2f56f9ea4dc3892c1265751a1c09038f365107ed (patch) | |
tree | 0ea020a25d72e72321dee382f6a9d4c291c7a95e /arch/loongarch/kvm/mmu.c | |
parent | b5d4e2325db29e063ff23772adb5846f1299b2e2 (diff) | |
download | linux-2f56f9ea4dc3892c1265751a1c09038f365107ed.tar.xz |
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 <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Diffstat (limited to 'arch/loongarch/kvm/mmu.c')
-rw-r--r-- | arch/loongarch/kvm/mmu.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c index 431a26eda473..576bc90292f0 100644 --- a/arch/loongarch/kvm/mmu.c +++ b/arch/loongarch/kvm/mmu.c @@ -858,11 +858,21 @@ retry: /* Disable dirty logging on HugePages */ level = 0; - if (!fault_supports_huge_mapping(memslot, hva, write)) { - level = 0; - } else { + if (fault_supports_huge_mapping(memslot, hva, write)) { + /* Check page level about host mmu*/ level = host_pfn_mapping_level(kvm, gfn, memslot); if (level == 1) { + /* + * Check page level about secondary mmu + * Disable hugepage if it is normal page on + * secondary mmu already + */ + ptep = kvm_populate_gpa(kvm, NULL, gpa, 0); + if (ptep && !kvm_pte_huge(*ptep)) + level = 0; + } + + if (level == 1) { gfn = gfn & ~(PTRS_PER_PTE - 1); pfn = pfn & ~(PTRS_PER_PTE - 1); } |