2023-06-27 04:38:07

by Like Xu

[permalink] [raw]
Subject: [PATCH] KVM: x86/mmu: Move the lockdep_assert of mmu_lock to inside clear_dirty_pt_masked()

From: Like Xu <[email protected]>

Move the lockdep_assert_held_write(&kvm->mmu_lock) from the only one caller
kvm_tdp_mmu_clear_dirty_pt_masked() to inside clear_dirty_pt_masked().

This change makes it more obvious why it's safe for clear_dirty_pt_masked()
to use the non-atomic (for non-volatile SPTEs) tdp_mmu_clear_spte_bits()
helper. for_each_tdp_mmu_root() does its own lockdep, so the only "loss"
in lockdep coverage is if the list is completely empty.

Suggested-by: Sean Christopherson <[email protected]>
Signed-off-by: Like Xu <[email protected]>
---
arch/x86/kvm/mmu/tdp_mmu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index 512163d52194..0b4f03bef70e 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -1600,6 +1600,8 @@ static void clear_dirty_pt_masked(struct kvm *kvm, struct kvm_mmu_page *root,
shadow_dirty_mask;
struct tdp_iter iter;

+ lockdep_assert_held_write(&kvm->mmu_lock);
+
rcu_read_lock();

tdp_root_for_each_leaf_pte(iter, root, gfn + __ffs(mask),
@@ -1646,7 +1648,6 @@ void kvm_tdp_mmu_clear_dirty_pt_masked(struct kvm *kvm,
{
struct kvm_mmu_page *root;

- lockdep_assert_held_write(&kvm->mmu_lock);
for_each_tdp_mmu_root(kvm, root, slot->as_id)
clear_dirty_pt_masked(kvm, root, gfn, mask, wrprot);
}

base-commit: 88bb466c9dec4f70d682cf38c685324e7b1b3d60
--
2.41.0



2023-08-02 20:40:23

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH] KVM: x86/mmu: Move the lockdep_assert of mmu_lock to inside clear_dirty_pt_masked()

On Tue, 27 Jun 2023 12:26:39 +0800, Like Xu wrote:
> Move the lockdep_assert_held_write(&kvm->mmu_lock) from the only one caller
> kvm_tdp_mmu_clear_dirty_pt_masked() to inside clear_dirty_pt_masked().
>
> This change makes it more obvious why it's safe for clear_dirty_pt_masked()
> to use the non-atomic (for non-volatile SPTEs) tdp_mmu_clear_spte_bits()
> helper. for_each_tdp_mmu_root() does its own lockdep, so the only "loss"
> in lockdep coverage is if the list is completely empty.
>
> [...]

Applied to kvm-x86 mmu, thanks!

[1/1] KVM: x86/mmu: Move the lockdep_assert of mmu_lock to inside clear_dirty_pt_masked()
https://github.com/kvm-x86/linux/commit/e19314998321

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes