]> git.proxmox.com Git - mirror_ubuntu-impish-kernel.git/commit
KVM: x86/mmu: Fix TDP MMU page table level
authorKai Huang <kai.huang@intel.com>
Tue, 15 Jun 2021 00:57:11 +0000 (12:57 +1200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Fri, 18 Feb 2022 11:29:12 +0000 (12:29 +0100)
commitbdda14e55dd68080543f3522c22304b4b7dcc7d5
tree4896f4780c33fa2981e2e49f17454528c47ee21e
parentbc0b9ca61432cfe31ba117a0d4988ad2d06d77f4
KVM: x86/mmu: Fix TDP MMU page table level

BugLink: https://bugs.launchpad.net/bugs/1956791
TDP MMU iterator's level is identical to page table's actual level.  For
instance, for the last level page table (whose entry points to one 4K
page), iter->level is 1 (PG_LEVEL_4K), and in case of 5 level paging,
the iter->level is mmu->shadow_root_level, which is 5.  However, struct
kvm_mmu_page's level currently is not set correctly when it is allocated
in kvm_tdp_mmu_map().  When iterator hits non-present SPTE and needs to
allocate a new child page table, currently iter->level, which is the
level of the page table where the non-present SPTE belongs to, is used.
This results in struct kvm_mmu_page's level always having its parent's
level (excpet root table's level, which is initialized explicitly using
mmu->shadow_root_level).

This is kinda wrong, and not consistent with existing non TDP MMU code.
Fortuantely sp->role.level is only used in handle_removed_tdp_mmu_page()
and kvm_tdp_mmu_zap_sp(), and they are already aware of this and behave
correctly.  However to make it consistent with legacy MMU code (and fix
the issue that both root page table and its child page table have
shadow_root_level), use iter->level - 1 in kvm_tdp_mmu_map(), and change
handle_removed_tdp_mmu_page() and kvm_tdp_mmu_zap_sp() accordingly.

Reviewed-by: Ben Gardon <bgardon@google.com>
Signed-off-by: Kai Huang <kai.huang@intel.com>
Message-Id: <bcb6569b6e96cb78aaa7b50640e6e6b53291a74e.1623717884.git.kai.huang@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit f1b8325508327a302f1d5cd8a4bf51e2c9c72fa9)
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
arch/x86/kvm/mmu/tdp_mmu.c
arch/x86/kvm/mmu/tdp_mmu.h