KVM: x86/mmu: Fold all of make_spte()'s writable handling into one if-else
authorSean Christopherson <seanjc@google.com>
Fri, 11 Oct 2024 02:10:35 +0000 (19:10 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 30 Oct 2024 21:46:45 +0000 (14:46 -0700)
Now that make_spte() no longer uses a funky goto to bail out for a special
case of its unsync handling, combine all of the unsync vs. writable logic
into a single if-else statement.

No functional change intended.

Link: https://lore.kernel.org/r/20241011021051.1557902-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/mmu/spte.c

index 09ce93c4916ae82129074dfe82ee0677cdaed14b..030813781a63c7b4200db5f43c7192064b1d8210 100644 (file)
@@ -217,8 +217,6 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
        spte |= (u64)pfn << PAGE_SHIFT;
 
        if (pte_access & ACC_WRITE_MASK) {
-               spte |= PT_WRITABLE_MASK | shadow_mmu_writable_mask;
-
                /*
                 * Unsync shadow pages that are reachable by the new, writable
                 * SPTE.  Write-protect the SPTE if the page can't be unsync'd,
@@ -233,16 +231,13 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
                 * guaranteed by both the shadow MMU and the TDP MMU.
                 */
                if ((!is_last_spte(old_spte, level) || !is_writable_pte(old_spte)) &&
-                   mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, synchronizing, prefetch)) {
+                   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);
-               }
+               else
+                       spte |= PT_WRITABLE_MASK | shadow_mmu_writable_mask |
+                               spte_shadow_dirty_mask(spte);
        }
 
-       if (pte_access & ACC_WRITE_MASK)
-               spte |= spte_shadow_dirty_mask(spte);
-
        if (prefetch && !synchronizing)
                spte = mark_spte_for_access_track(spte);