From: Paolo Bonzini <pbonzini@redhat.com>
To: Ben Gardon <bgardon@google.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Peter Xu <peterx@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Peter Shier <pshier@google.com>,
Peter Feiner <pfeiner@google.com>,
Junaid Shahid <junaids@google.com>,
Jim Mattson <jmattson@google.com>,
Yulei Zhang <yulei.kernel@gmail.com>,
Wanpeng Li <kernellwp@gmail.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Xiao Guangrong <xiaoguangrong.eric@gmail.com>
Subject: Re: [PATCH 16/24] kvm: mmu: Wrap mmu_lock assertions
Date: Tue, 26 Jan 2021 15:29:48 +0100 [thread overview]
Message-ID: <feb59127-60cd-d0c9-1520-84232c01c6c9@redhat.com> (raw)
In-Reply-To: <20210112181041.356734-17-bgardon@google.com>
On 12/01/21 19:10, Ben Gardon wrote:
> Wrap assertions and warnings checking the MMU lock state in a function
> which uses lockdep_assert_held. While the existing checks use a few
> different functions to check the lock state, they are all better off
> using lockdep_assert_held. This will support a refactoring to move the
> mmu_lock to struct kvm_arch so that it can be replaced with an rwlock for
> x86.
>
> Reviewed-by: Peter Feiner <pfeiner@google.com>
>
> Signed-off-by: Ben Gardon <bgardon@google.com>
> ---
> arch/arm64/kvm/mmu.c | 2 +-
> arch/powerpc/include/asm/kvm_book3s_64.h | 7 +++----
> arch/powerpc/kvm/book3s_hv_nested.c | 3 +--
> arch/x86/kvm/mmu/mmu_internal.h | 4 ++--
> arch/x86/kvm/mmu/tdp_mmu.c | 8 ++++----
> include/linux/kvm_host.h | 1 +
> virt/kvm/kvm_main.c | 5 +++++
> 7 files changed, 17 insertions(+), 13 deletions(-)
>
> diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> index 57ef1ec23b56..8b54eb58bf47 100644
> --- a/arch/arm64/kvm/mmu.c
> +++ b/arch/arm64/kvm/mmu.c
> @@ -130,7 +130,7 @@ static void __unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64
> struct kvm *kvm = mmu->kvm;
> phys_addr_t end = start + size;
>
> - assert_spin_locked(&kvm->mmu_lock);
> + kvm_mmu_lock_assert_held(kvm);
> WARN_ON(size & ~PAGE_MASK);
> WARN_ON(stage2_apply_range(kvm, start, end, kvm_pgtable_stage2_unmap,
> may_block));
> diff --git a/arch/powerpc/include/asm/kvm_book3s_64.h b/arch/powerpc/include/asm/kvm_book3s_64.h
> index 9bb9bb370b53..db2e437cd97c 100644
> --- a/arch/powerpc/include/asm/kvm_book3s_64.h
> +++ b/arch/powerpc/include/asm/kvm_book3s_64.h
> @@ -650,8 +650,8 @@ static inline pte_t *find_kvm_secondary_pte(struct kvm *kvm, unsigned long ea,
> {
> pte_t *pte;
>
> - VM_WARN(!spin_is_locked(&kvm->mmu_lock),
> - "%s called with kvm mmu_lock not held \n", __func__);
> + kvm_mmu_lock_assert_held(kvm);
> +
> pte = __find_linux_pte(kvm->arch.pgtable, ea, NULL, hshift);
>
> return pte;
> @@ -662,8 +662,7 @@ static inline pte_t *find_kvm_host_pte(struct kvm *kvm, unsigned long mmu_seq,
> {
> pte_t *pte;
>
> - VM_WARN(!spin_is_locked(&kvm->mmu_lock),
> - "%s called with kvm mmu_lock not held \n", __func__);
> + kvm_mmu_lock_assert_held(kvm);
>
> if (mmu_notifier_retry(kvm, mmu_seq))
> return NULL;
> diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3s_hv_nested.c
> index 18890dca9476..6d5987d1eee7 100644
> --- a/arch/powerpc/kvm/book3s_hv_nested.c
> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
> @@ -767,8 +767,7 @@ pte_t *find_kvm_nested_guest_pte(struct kvm *kvm, unsigned long lpid,
> if (!gp)
> return NULL;
>
> - VM_WARN(!spin_is_locked(&kvm->mmu_lock),
> - "%s called with kvm mmu_lock not held \n", __func__);
> + kvm_mmu_lock_assert_held(kvm);
> pte = __find_linux_pte(gp->shadow_pgtable, ea, NULL, hshift);
>
> return pte;
> diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
> index 7f599cc64178..cc8268cf28d2 100644
> --- a/arch/x86/kvm/mmu/mmu_internal.h
> +++ b/arch/x86/kvm/mmu/mmu_internal.h
> @@ -101,14 +101,14 @@ void kvm_flush_remote_tlbs_with_address(struct kvm *kvm,
> static inline void kvm_mmu_get_root(struct kvm *kvm, struct kvm_mmu_page *sp)
> {
> BUG_ON(!sp->root_count);
> - lockdep_assert_held(&kvm->mmu_lock);
> + kvm_mmu_lock_assert_held(kvm);
>
> ++sp->root_count;
> }
>
> static inline bool kvm_mmu_put_root(struct kvm *kvm, struct kvm_mmu_page *sp)
> {
> - lockdep_assert_held(&kvm->mmu_lock);
> + kvm_mmu_lock_assert_held(kvm);
> --sp->root_count;
>
> return !sp->root_count;
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
> index fb911ca428b2..1d7c01300495 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.c
> +++ b/arch/x86/kvm/mmu/tdp_mmu.c
> @@ -117,7 +117,7 @@ void kvm_tdp_mmu_free_root(struct kvm *kvm, struct kvm_mmu_page *root)
> {
> gfn_t max_gfn = 1ULL << (shadow_phys_bits - PAGE_SHIFT);
>
> - lockdep_assert_held(&kvm->mmu_lock);
> + kvm_mmu_lock_assert_held(kvm);
>
> WARN_ON(root->root_count);
> WARN_ON(!root->tdp_mmu_page);
> @@ -425,7 +425,7 @@ static inline void __tdp_mmu_set_spte(struct kvm *kvm, struct tdp_iter *iter,
> struct kvm_mmu_page *root = sptep_to_sp(root_pt);
> int as_id = kvm_mmu_page_as_id(root);
>
> - lockdep_assert_held(&kvm->mmu_lock);
> + kvm_mmu_lock_assert_held(kvm);
>
> WRITE_ONCE(*iter->sptep, new_spte);
>
> @@ -1139,7 +1139,7 @@ void kvm_tdp_mmu_clear_dirty_pt_masked(struct kvm *kvm,
> struct kvm_mmu_page *root;
> int root_as_id;
>
> - lockdep_assert_held(&kvm->mmu_lock);
> + kvm_mmu_lock_assert_held(kvm);
> for_each_tdp_mmu_root(kvm, root) {
> root_as_id = kvm_mmu_page_as_id(root);
> if (root_as_id != slot->as_id)
> @@ -1324,7 +1324,7 @@ bool kvm_tdp_mmu_write_protect_gfn(struct kvm *kvm,
> int root_as_id;
> bool spte_set = false;
>
> - lockdep_assert_held(&kvm->mmu_lock);
> + kvm_mmu_lock_assert_held(kvm);
> for_each_tdp_mmu_root(kvm, root) {
> root_as_id = kvm_mmu_page_as_id(root);
> if (root_as_id != slot->as_id)
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 6e2773fc406c..022e3522788f 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -1499,5 +1499,6 @@ void kvm_mmu_lock(struct kvm *kvm);
> void kvm_mmu_unlock(struct kvm *kvm);
> int kvm_mmu_lock_needbreak(struct kvm *kvm);
> int kvm_mmu_lock_cond_resched(struct kvm *kvm);
> +void kvm_mmu_lock_assert_held(struct kvm *kvm);
Probably better to make this an empty inline if !defined(CONFIG_LOCKDEP).
Paolo
> #endif
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index b4c49a7e0556..c504f876176b 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -452,6 +452,11 @@ int kvm_mmu_lock_cond_resched(struct kvm *kvm)
> return cond_resched_lock(&kvm->mmu_lock);
> }
>
> +void kvm_mmu_lock_assert_held(struct kvm *kvm)
> +{
> + lockdep_assert_held(&kvm->mmu_lock);
> +}
> +
> #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
> static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn)
> {
>
next prev parent reply other threads:[~2021-01-26 14:34 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 18:10 [PATCH 00/24] Allow parallel page faults with TDP MMU Ben Gardon
2021-01-12 18:10 ` [PATCH 01/24] locking/rwlocks: Add contention detection for rwlocks Ben Gardon
2021-01-12 18:10 ` [PATCH 02/24] sched: Add needbreak " Ben Gardon
2021-01-12 18:10 ` [PATCH 03/24] sched: Add cond_resched_rwlock Ben Gardon
2021-01-12 18:10 ` [PATCH 04/24] kvm: x86/mmu: change TDP MMU yield function returns to match cond_resched Ben Gardon
2021-01-20 18:38 ` Sean Christopherson
2021-01-21 20:22 ` Paolo Bonzini
2021-01-26 14:11 ` Paolo Bonzini
2021-01-12 18:10 ` [PATCH 05/24] kvm: x86/mmu: Fix yielding in TDP MMU Ben Gardon
2021-01-20 19:28 ` Sean Christopherson
2021-01-22 1:06 ` Ben Gardon
2021-01-12 18:10 ` [PATCH 06/24] kvm: x86/mmu: Skip no-op changes in TDP MMU functions Ben Gardon
2021-01-20 19:51 ` Sean Christopherson
2021-01-25 23:51 ` Ben Gardon
2021-01-12 18:10 ` [PATCH 07/24] kvm: x86/mmu: Add comment on __tdp_mmu_set_spte Ben Gardon
2021-01-26 14:13 ` Paolo Bonzini
2021-01-12 18:10 ` [PATCH 08/24] kvm: x86/mmu: Add lockdep when setting a TDP MMU SPTE Ben Gardon
2021-01-20 19:58 ` Sean Christopherson
2021-01-26 14:13 ` Paolo Bonzini
2021-01-12 18:10 ` [PATCH 09/24] kvm: x86/mmu: Don't redundantly clear TDP MMU pt memory Ben Gardon
2021-01-20 20:06 ` Sean Christopherson
2021-01-26 14:14 ` Paolo Bonzini
2021-01-12 18:10 ` [PATCH 10/24] kvm: x86/mmu: Factor out handle disconnected pt Ben Gardon
2021-01-20 20:30 ` Sean Christopherson
2021-01-26 14:14 ` Paolo Bonzini
2021-01-12 18:10 ` [PATCH 11/24] kvm: x86/mmu: Put TDP MMU PT walks in RCU read-critical section Ben Gardon
2021-01-20 22:19 ` Sean Christopherson
2021-01-12 18:10 ` [PATCH 12/24] kvm: x86/kvm: RCU dereference tdp mmu page table links Ben Gardon
2021-01-22 18:32 ` Sean Christopherson
2021-01-26 18:17 ` Ben Gardon
2021-01-12 18:10 ` [PATCH 13/24] kvm: x86/mmu: Only free tdp_mmu pages after a grace period Ben Gardon
2021-01-12 18:10 ` [PATCH 14/24] kvm: mmu: Wrap mmu_lock lock / unlock in a function Ben Gardon
2021-01-12 18:10 ` [PATCH 15/24] kvm: mmu: Wrap mmu_lock cond_resched and needbreak Ben Gardon
2021-01-21 0:19 ` Sean Christopherson
2021-01-21 20:17 ` Paolo Bonzini
2021-01-26 14:38 ` Paolo Bonzini
2021-01-26 17:47 ` Ben Gardon
2021-01-26 17:55 ` Paolo Bonzini
2021-01-26 18:11 ` Ben Gardon
2021-01-26 20:47 ` Paolo Bonzini
2021-01-27 20:08 ` Ben Gardon
2021-01-27 20:55 ` Paolo Bonzini
2021-01-27 21:20 ` Ben Gardon
2021-01-28 8:18 ` Paolo Bonzini
2021-01-12 18:10 ` [PATCH 16/24] kvm: mmu: Wrap mmu_lock assertions Ben Gardon
2021-01-26 14:29 ` Paolo Bonzini [this message]
2021-01-12 18:10 ` [PATCH 17/24] kvm: mmu: Move mmu_lock to struct kvm_arch Ben Gardon
2021-01-12 18:10 ` [PATCH 18/24] kvm: x86/mmu: Use an rwlock for the x86 TDP MMU Ben Gardon
2021-01-21 0:45 ` Sean Christopherson
2021-01-12 18:10 ` [PATCH 19/24] kvm: x86/mmu: Protect tdp_mmu_pages with a lock Ben Gardon
2021-01-21 19:22 ` Sean Christopherson
2021-01-21 21:32 ` Sean Christopherson
2021-01-26 14:27 ` Paolo Bonzini
2021-01-26 21:47 ` Ben Gardon
2021-01-26 22:02 ` Sean Christopherson
2021-01-26 22:09 ` Sean Christopherson
2021-01-27 12:40 ` Paolo Bonzini
2021-01-26 13:37 ` Paolo Bonzini
2021-01-26 21:07 ` Ben Gardon
2021-01-12 18:10 ` [PATCH 20/24] kvm: x86/mmu: Add atomic option for setting SPTEs Ben Gardon
2021-01-26 14:21 ` Paolo Bonzini
2021-01-12 18:10 ` [PATCH 21/24] kvm: x86/mmu: Use atomic ops to set SPTEs in TDP MMU map Ben Gardon
2021-01-12 18:10 ` [PATCH 22/24] kvm: x86/mmu: Flush TLBs after zap in TDP MMU PF handler Ben Gardon
2021-01-21 0:05 ` Sean Christopherson
2021-01-12 18:10 ` [PATCH 23/24] kvm: x86/mmu: Freeze SPTEs in disconnected pages Ben Gardon
2021-01-12 18:10 ` [PATCH 24/24] kvm: x86/mmu: Allow parallel page faults for the TDP MMU Ben Gardon
2021-01-21 0:55 ` Sean Christopherson
2021-01-26 21:57 ` Ben Gardon
2021-01-27 17:14 ` Sean Christopherson
2021-01-26 13:37 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=feb59127-60cd-d0c9-1520-84232c01c6c9@redhat.com \
--to=pbonzini@redhat.com \
--cc=bgardon@google.com \
--cc=jmattson@google.com \
--cc=junaids@google.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=pfeiner@google.com \
--cc=pshier@google.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=xiaoguangrong.eric@gmail.com \
--cc=yulei.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).