From patchwork Fri Oct 27 18:21:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13438938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1300CC25B47 for ; Fri, 27 Oct 2023 18:22:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B77A980012; Fri, 27 Oct 2023 14:22:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B003E8000C; Fri, 27 Oct 2023 14:22:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9531980012; Fri, 27 Oct 2023 14:22:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7DE918000C for ; Fri, 27 Oct 2023 14:22:50 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5A55E409B0 for ; Fri, 27 Oct 2023 18:22:50 +0000 (UTC) X-FDA: 81392062500.16.2AC5188 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf16.hostedemail.com (Postfix) with ESMTP id 72B67180003 for ; Fri, 27 Oct 2023 18:22:48 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eUkEKsba; spf=pass (imf16.hostedemail.com: domain of 39_87ZQYKCBgG2yB704CC492.0CA96BIL-AA8Jy08.CF4@flex--seanjc.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=39_87ZQYKCBgG2yB704CC492.0CA96BIL-AA8Jy08.CF4@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698430968; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fLrd3AGy66HdihfPmI58EyyG3FCGELBv0TZMEZAIG4Y=; b=CQUawqdnjxxW4TxZnJalhoVPqEC1shBouFSNDQCm6Hvd3wjQZMWzuYdu2HZXHjIp+XsyNx VsUhObrYKx69j/evqprb92+62QAbjxSP1deeA6cMuMU7U691W4PtDuGJm4jG+bd44wPGCn msjRiWqzoFRqENlrOuzsNbeeRRZXYik= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=eUkEKsba; spf=pass (imf16.hostedemail.com: domain of 39_87ZQYKCBgG2yB704CC492.0CA96BIL-AA8Jy08.CF4@flex--seanjc.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=39_87ZQYKCBgG2yB704CC492.0CA96BIL-AA8Jy08.CF4@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698430968; a=rsa-sha256; cv=none; b=u3e0px++tpw1CdFYIiXdsvEyjp5Wh/ynK7pQzlK/wV43axgiOvDNzFIdcLw4UytSjoZ3xt GbxyrHXCI8nf7YtOSS4m4tQSYxkyb+3I332iubBpH2Ue6Mk9n1+QmG3EluxdDTt2Xqkyl9 1h6Jec9UuMwQsORQkINkpedU5YDbwv4= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1cc1ddb34ccso9088505ad.1 for ; Fri, 27 Oct 2023 11:22:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698430967; x=1699035767; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=fLrd3AGy66HdihfPmI58EyyG3FCGELBv0TZMEZAIG4Y=; b=eUkEKsbasHZ/A0sQ/eE5StIAJEN0AVSIomqOWPnUcQVU2f40XQUZrCGBhvM2MFcGTW ikEAlnvz02zgPF0ICtJOWEX/SdHtVtb8dogs3sU02vlax0aXqRNeyx4xSdM2N/nOBQ6H mehrtzo7v8jl+qFZ9OfezJ0ku1npJ0WMBIBJaCXuLIhzniKHlQpJOp40iujiFk9uGZYB puQVZwX2O04UaPKqRwSbrm4HGHkRI+yA+5y8We39vxWcKC3oDfB8iaRovnzrMtLz7Kxa ja6TdE+wPJIIiiqrGnZufrm+5WzZQM22YWc/J7ETJsNUW7M2S34do88QQ34GSizP1YlO DdBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698430967; x=1699035767; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fLrd3AGy66HdihfPmI58EyyG3FCGELBv0TZMEZAIG4Y=; b=h5uFVxcmOYXXhSxg9WZp769Krxt/K0/jWTtGXV0DAr2uxBv1f7ulTTchrB9X6rnZUJ ebBhFfXju0ZV944pLE/g+X/kwYy+8/NG62k2irVf9LatsdLkaU7r0f46BSaeDvpsEVW7 NZ4XrMCUyRwzc/9E5vQyDPIxLp3JD/6cCZhMAjpTPnOX7+THkQYVNV7gFj0jGUss04uP P1MsZ/dDvsQfsZLCVNYvTzhWQmJ2GeuSV7haQITDMtl6gKhA/Ybwfugmm17F36+yToOD AXVP9ABYA1MNVpGp8UxQWzdstyurKYA2qV81pa5gY1OZ28iMOrRiGTJdRUb+6QIMVu+M rquw== X-Gm-Message-State: AOJu0Yzk3Nx85D7UHDpwULhWHw1NzUoxJP0FxJ7kugmfevmriugt4iB8 l8vzVwoH2UOjNFW2DO4f/gCkoKfsAiM= X-Google-Smtp-Source: AGHT+IFw7CMiVxkdfLmPKgztX5f1RnQlL4BTlZlVKLxMz6aRVtHUrQY578kvMdkjnRTl6BBw2VS25sQYIRo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:ee14:b0:1ca:b952:f5fa with SMTP id z20-20020a170902ee1400b001cab952f5famr63161plb.5.1698430967325; Fri, 27 Oct 2023 11:22:47 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 27 Oct 2023 11:21:53 -0700 In-Reply-To: <20231027182217.3615211-1-seanjc@google.com> Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231027182217.3615211-12-seanjc@google.com> Subject: [PATCH v13 11/35] KVM: Drop .on_unlock() mmu_notifier hook From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Sean Christopherson , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , " =?utf-8?q?Micka=C3=ABl_Sala?= =?utf-8?q?=C3=BCn?= " , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" X-Rspamd-Queue-Id: 72B67180003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UIvBNhZ0Hfj2EBBHGwd7OlHsbRpbHmMKB/1x5EWo2Gozi+CsaXDhYoUQHc/Nl84eXeh9us6whPLWNn4Db1ICn+l/98eYtaZC9LnKIni1GDMSXDgn7c4gkJIEinsEUdcmyDp6TfBSzMump6mWimUa00mYpJ4d6BwedG8Ot4QUPk3tVQFAo0W5Sbu3x0MlbOorWjVCPKUclpMKJNOw626ozBKOK80/w0mpHqu+Op45Wu0zVr5WFrsoRkzEJCIkR1FvhX1pD4i6RmKKZra2pNWR4M07PDSUGX2T8T1lJlJkr6/Fr0X0DbmMYTtiszesr3G62jNK43/u36dFKGdrpOntQ6JsClVRSPyNDhJCjUkRClsyydXcANjvzrf4whJXW2OX1Ak3rSKZq+JwP29Z+DK2/ZBNaylBUbr7yGd7YixSJDQyccBCYUM4HWt+H7PCiqIdtFGycmSj9Z8PNigWMWSWyhlOscFIspoZY/bP8FgwhrWvx5sUyTJbNg5tYYCpZ8d+R7rl2sMIac6yWc2wY5+RFIcMt7A78QgASZNbkUVDOtXVYJucw0w2naApLGvdSRK6gLdQJk3W6o5z/C3Qd0kl2g757KNx3b5UBQantRTWLAJWUl7nJsqV0zUwmAJHIQgEVUss1u/81I84EVmfyAUGiYhFXxnuJ04syRQoY99Zq6+mCXTbkUdMiRyvzHE6X1YEs7hn5ha1tof4UTJChn3cB2aga8mGm7l1pjX/JlNnCKnDd+Xz5lZDTwU8jucKi8P5JexJIBF2fXHD3W3W0VFU2iBS9E24oXIns3BUsiTHDU0tyA7xjfGQWD7G3MBKaZl1M3qGXs2JG9pcUMgPF+/VQhv3Jr8N1cUPpAe3XRTIE/s+so8H3w2gJTvYrNy7FuVFlioc36B6PlQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Drop the .on_unlock() mmu_notifer hook now that it's no longer used for notifying arch code that memory has been reclaimed. Adding .on_unlock() and invoking it *after* dropping mmu_lock was a terrible idea, as doing so resulted in .on_lock() and .on_unlock() having divergent and asymmetric behavior, and set future developers up for failure, i.e. all but asked for bugs where KVM relied on using .on_unlock() to try to run a callback while holding mmu_lock. Opportunistically add a lockdep assertion in kvm_mmu_invalidate_end() to guard against future bugs of this nature. Reported-by: Isaku Yamahata Link: https://lore.kernel.org/all/20230802203119.GB2021422@ls.amr.corp.intel.com Signed-off-by: Sean Christopherson Reviewed-by: Paolo Bonzini Reviewed-by: Fuad Tabba Tested-by: Fuad Tabba --- virt/kvm/kvm_main.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2bc04c8ae1f4..cb9376833c18 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -544,7 +544,6 @@ static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn) typedef bool (*gfn_handler_t)(struct kvm *kvm, struct kvm_gfn_range *range); typedef void (*on_lock_fn_t)(struct kvm *kvm); -typedef void (*on_unlock_fn_t)(struct kvm *kvm); struct kvm_mmu_notifier_range { /* @@ -556,7 +555,6 @@ struct kvm_mmu_notifier_range { union kvm_mmu_notifier_arg arg; gfn_handler_t handler; on_lock_fn_t on_lock; - on_unlock_fn_t on_unlock; bool flush_on_ret; bool may_block; }; @@ -663,11 +661,8 @@ static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm, if (range->flush_on_ret && r.ret) kvm_flush_remote_tlbs(kvm); - if (r.found_memslot) { + if (r.found_memslot) KVM_MMU_UNLOCK(kvm); - if (!IS_KVM_NULL_FN(range->on_unlock)) - range->on_unlock(kvm); - } srcu_read_unlock(&kvm->srcu, idx); @@ -687,7 +682,6 @@ static __always_inline int kvm_handle_hva_range(struct mmu_notifier *mn, .arg = arg, .handler = handler, .on_lock = (void *)kvm_null_fn, - .on_unlock = (void *)kvm_null_fn, .flush_on_ret = true, .may_block = false, }; @@ -706,7 +700,6 @@ static __always_inline int kvm_handle_hva_range_no_flush(struct mmu_notifier *mn .end = end, .handler = handler, .on_lock = (void *)kvm_null_fn, - .on_unlock = (void *)kvm_null_fn, .flush_on_ret = false, .may_block = false, }; @@ -813,7 +806,6 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, .end = range->end, .handler = kvm_mmu_unmap_gfn_range, .on_lock = kvm_mmu_invalidate_begin, - .on_unlock = (void *)kvm_null_fn, .flush_on_ret = true, .may_block = mmu_notifier_range_blockable(range), }; @@ -858,6 +850,8 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, void kvm_mmu_invalidate_end(struct kvm *kvm) { + lockdep_assert_held_write(&kvm->mmu_lock); + /* * This sequence increase will notify the kvm page fault that * the page that is going to be mapped in the spte could have @@ -889,7 +883,6 @@ static void kvm_mmu_notifier_invalidate_range_end(struct mmu_notifier *mn, .end = range->end, .handler = (void *)kvm_null_fn, .on_lock = kvm_mmu_invalidate_end, - .on_unlock = (void *)kvm_null_fn, .flush_on_ret = false, .may_block = mmu_notifier_range_blockable(range), };