[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YAiJrsyC1KSTKycg@google.com>
Date: Wed, 20 Jan 2021 11:51:10 -0800
From: Sean Christopherson <seanjc@...gle.com>
To: Ben Gardon <bgardon@...gle.com>
Cc: linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
Paolo Bonzini <pbonzini@...hat.com>,
Peter Xu <peterx@...hat.com>, Peter Shier <pshier@...gle.com>,
Peter Feiner <pfeiner@...gle.com>,
Junaid Shahid <junaids@...gle.com>,
Jim Mattson <jmattson@...gle.com>,
Yulei Zhang <yulei.kernel@...il.com>,
Wanpeng Li <kernellwp@...il.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Xiao Guangrong <xiaoguangrong.eric@...il.com>
Subject: Re: [PATCH 06/24] kvm: x86/mmu: Skip no-op changes in TDP MMU
functions
On Tue, Jan 12, 2021, Ben Gardon wrote:
> Skip setting SPTEs if no change is expected.
>
> Reviewed-by: Peter Feiner <pfeiner@...gle.com>
>
Nit on all of these, can you remove the extra newline between the Reviewed-by
and SOB?
> Signed-off-by: Ben Gardon <bgardon@...gle.com>
> ---
> arch/x86/kvm/mmu/tdp_mmu.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index 1987da0da66e..2650fa9fe066 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -882,6 +882,9 @@ static bool wrprot_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
> !is_last_spte(iter.old_spte, iter.level))
> continue;
>
> + if (!(iter.old_spte & PT_WRITABLE_MASK))
Include the new check with the existing if statement? I think it makes sense to
group all the checks on old_spte.
> + continue;
> +
> new_spte = iter.old_spte & ~PT_WRITABLE_MASK;
>
> tdp_mmu_set_spte_no_dirty_log(kvm, &iter, new_spte);
> @@ -1079,6 +1082,9 @@ static bool set_dirty_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
> if (!is_shadow_present_pte(iter.old_spte))
> continue;
>
> + if (iter.old_spte & shadow_dirty_mask)
Same comment here.
> + continue;
> +
Unrelated to this patch, but it got me looking at the code: shouldn't
clear_dirty_pt_masked() clear the bit in @mask before checking whether or not
the spte needs to be modified? That way the early break kicks in after sptes
are checked, not necessarily written. E.g.
diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index 2650fa9fe066..d8eeae910cbf 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -1010,21 +1010,21 @@ static void clear_dirty_pt_masked(struct kvm *kvm, struct kvm_mmu_page *root,
!(mask & (1UL << (iter.gfn - gfn))))
continue;
- if (wrprot || spte_ad_need_write_protect(iter.old_spte)) {
- if (is_writable_pte(iter.old_spte))
- new_spte = iter.old_spte & ~PT_WRITABLE_MASK;
- else
- continue;
- } else {
- if (iter.old_spte & shadow_dirty_mask)
- new_spte = iter.old_spte & ~shadow_dirty_mask;
- else
- continue;
- }
-
- tdp_mmu_set_spte_no_dirty_log(kvm, &iter, new_spte);
-
mask &= ~(1UL << (iter.gfn - gfn));
+
+ if (wrprot || spte_ad_need_write_protect(iter.old_spte)) {
+ if (is_writable_pte(iter.old_spte))
+ new_spte = iter.old_spte & ~PT_WRITABLE_MASK;
+ else
+ continue;
+ } else {
+ if (iter.old_spte & shadow_dirty_mask)
+ new_spte = iter.old_spte & ~shadow_dirty_mask;
+ else
+ continue;
+ }
+
+ tdp_mmu_set_spte_no_dirty_log(kvm, &iter, new_spte);
}
}
> new_spte = iter.old_spte | shadow_dirty_mask;
>
> tdp_mmu_set_spte(kvm, &iter, new_spte);
> --
> 2.30.0.284.gd98b1dd5eaa7-goog
>
Powered by blists - more mailing lists