]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: x86/mmu: Invert @can_unsync and renamed to @synchronizing
authorSean Christopherson <seanjc@google.com>
Thu, 10 Oct 2024 18:23:08 +0000 (11:23 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 25 Oct 2024 16:54:42 +0000 (12:54 -0400)
Invert the polarity of "can_unsync" and rename the parameter to
"synchronizing" to allow a future change to set the Accessed bit if KVM
is synchronizing an existing SPTE.  Querying "can_unsync" in that case is
nonsensical, as the fact that KVM can't unsync SPTEs doesn't provide any
justification for setting the Accessed bit.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Tested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20241010182427.1434605-7-seanjc@google.com>

arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/mmu/mmu_internal.h
arch/x86/kvm/mmu/paging_tmpl.h
arch/x86/kvm/mmu/spte.c
arch/x86/kvm/mmu/spte.h
arch/x86/kvm/mmu/tdp_mmu.c

index f66a0e59cb6a9766875277df826b9e2630d34647..8d781e25e4d3ecc99f2c3bff6926b16cb44da8b7 100644 (file)
@@ -2802,7 +2802,7 @@ static void kvm_unsync_page(struct kvm *kvm, struct kvm_mmu_page *sp)
  * be write-protected.
  */
 int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
-                           gfn_t gfn, bool can_unsync, bool prefetch)
+                           gfn_t gfn, bool synchronizing, bool prefetch)
 {
        struct kvm_mmu_page *sp;
        bool locked = false;
@@ -2817,12 +2817,12 @@ int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
 
        /*
         * The page is not write-tracked, mark existing shadow pages unsync
-        * unless KVM is synchronizing an unsync SP (can_unsync = false).  In
-        * that case, KVM must complete emulation of the guest TLB flush before
-        * allowing shadow pages to become unsync (writable by the guest).
+        * unless KVM is synchronizing an unsync SP.  In that case, KVM must
+        * complete emulation of the guest TLB flush before allowing shadow
+        * pages to become unsync (writable by the guest).
         */
        for_each_gfn_valid_sp_with_gptes(kvm, sp, gfn) {
-               if (!can_unsync)
+               if (synchronizing)
                        return -EPERM;
 
                if (sp->unsync)
@@ -2948,7 +2948,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot,
        }
 
        wrprot = make_spte(vcpu, sp, slot, pte_access, gfn, pfn, *sptep, prefetch,
-                          true, host_writable, &spte);
+                          false, host_writable, &spte);
 
        if (*sptep == spte) {
                ret = RET_PF_SPURIOUS;
index c98827840e07abf988098b2fa608aefd09e24e93..4da83544c4e1b89cd796f37b30daa803b1f79e90 100644 (file)
@@ -164,7 +164,7 @@ static inline gfn_t gfn_round_for_level(gfn_t gfn, int level)
 }
 
 int mmu_try_to_unsync_pages(struct kvm *kvm, const struct kvm_memory_slot *slot,
-                           gfn_t gfn, bool can_unsync, bool prefetch);
+                           gfn_t gfn, bool synchronizing, bool prefetch);
 
 void kvm_mmu_gfn_disallow_lpage(const struct kvm_memory_slot *slot, gfn_t gfn);
 void kvm_mmu_gfn_allow_lpage(const struct kvm_memory_slot *slot, gfn_t gfn);
index ae7d39ff2d07f048e66fd5e53cbcae2237359533..6e7bd8921c6f3625feecb81310d9b8d0d33f6d5e 100644 (file)
@@ -963,7 +963,7 @@ static int FNAME(sync_spte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, int
        host_writable = spte & shadow_host_writable_mask;
        slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn);
        make_spte(vcpu, sp, slot, pte_access, gfn,
-                 spte_to_pfn(spte), spte, true, false,
+                 spte_to_pfn(spte), spte, true, true,
                  host_writable, &spte);
 
        return mmu_spte_update(sptep, spte);
index 5521608077ec093d29da442407dd12745430ec08..0e47fea1a2d91c064de835960ec265919f22b9f1 100644 (file)
@@ -157,7 +157,7 @@ bool spte_has_volatile_bits(u64 spte)
 bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
               const struct kvm_memory_slot *slot,
               unsigned int pte_access, gfn_t gfn, kvm_pfn_t pfn,
-              u64 old_spte, bool prefetch, bool can_unsync,
+              u64 old_spte, bool prefetch, bool synchronizing,
               bool host_writable, u64 *new_spte)
 {
        int level = sp->role.level;
@@ -248,7 +248,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
                 * e.g. it's write-tracked (upper-level SPs) or has one or more
                 * shadow pages and unsync'ing pages is not allowed.
                 */
-               if (mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, can_unsync, prefetch)) {
+               if (mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, synchronizing, prefetch)) {
                        wrprot = true;
                        pte_access &= ~ACC_WRITE_MASK;
                        spte &= ~(PT_WRITABLE_MASK | shadow_mmu_writable_mask);
index 2cb816ea24307aa38e46ee0b6e838c6eb99e805a..c81cac9358e02dc5ba2dbf8ff7af380e1467f665 100644 (file)
@@ -499,7 +499,7 @@ bool spte_has_volatile_bits(u64 spte);
 bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
               const struct kvm_memory_slot *slot,
               unsigned int pte_access, gfn_t gfn, kvm_pfn_t pfn,
-              u64 old_spte, bool prefetch, bool can_unsync,
+              u64 old_spte, bool prefetch, bool synchronizing,
               bool host_writable, u64 *new_spte);
 u64 make_huge_page_split_spte(struct kvm *kvm, u64 huge_spte,
                              union kvm_mmu_page_role role, int index);
index 3c65834687421a5ddd5350f1251c283be6b4a9dd..76bca7a726c1829cbb6da4afaf5ad36001df60ab 100644 (file)
@@ -1033,8 +1033,8 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu,
                new_spte = make_mmio_spte(vcpu, iter->gfn, ACC_ALL);
        else
                wrprot = make_spte(vcpu, sp, fault->slot, ACC_ALL, iter->gfn,
-                                        fault->pfn, iter->old_spte, fault->prefetch, true,
-                                        fault->map_writable, &new_spte);
+                                  fault->pfn, iter->old_spte, fault->prefetch,
+                                  false, fault->map_writable, &new_spte);
 
        if (new_spte == iter->old_spte)
                ret = RET_PF_SPURIOUS;