Re: [PATCH 06/23] KVM: MMU: load new PGD once nested two-dimensional paging is initialized

From: Paolo Bonzini
Date: Mon Feb 07 2022 - 09:46:07 EST


On 2/7/22 14:50, Paolo Bonzini wrote:

Those checks are just for performance correct (to skip iterating through
the list of roots)?

Either way, it's probably worth including a Fixes tag below.

There's no bug because __kvm_mmu_new_pgd is passed a correct new_role. But it's unnecessarily complex as shown by patches 7 and 9.

root_level is not part of the role, but we're still safe because changing it requires to flip CR0.PG to 0 and back to 1. This calls kvm_mmu_reset_context and unloads all roots, so it's not possible to have a cached PGD with the wrong root level. On the first call the root_level might be incorrect, but then again there's no cached PGD.

(Also, shadow_root_level is either always or never >= PT64_ROOT_4LEVEL, so it's okay unless the guest_mmu was never set up and therefore no cached PGD exists).

Paolo