From patchwork Thu Sep 14 01:55:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13384016 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 47254EE0213 for ; Thu, 14 Sep 2023 01:56:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 704FA6B02A0; Wed, 13 Sep 2023 21:55:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B4F06B02A4; Wed, 13 Sep 2023 21:55:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B6AC6B02A3; Wed, 13 Sep 2023 21:55:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 352936B029D for ; Wed, 13 Sep 2023 21:55:57 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 11A8280EC1 for ; Thu, 14 Sep 2023 01:55:57 +0000 (UTC) X-FDA: 81233537154.29.154AB1E Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf14.hostedemail.com (Postfix) with ESMTP id 494CD100018 for ; Thu, 14 Sep 2023 01:55:55 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JG67F76E; spf=pass (imf14.hostedemail.com: domain of 3KmgCZQYKCDMhTPcYRVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--seanjc.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3KmgCZQYKCDMhTPcYRVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694656555; a=rsa-sha256; cv=none; b=v0rc+I94ff+HJ/u4MaDap0tKCdJ88a8l8iCCBxQljuaQEOh0jASa29Tm+U0zLtE6QppbXV XQxp7MejNZCbrvQv8QNdJ2+gid9dpfCkGmKn3anXqsGz8O3HfHuwbHISMlIH0+qgdxtCPC 0TLfeQHBQf3CvegQnv9lQfj/Ahh8PqI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=JG67F76E; spf=pass (imf14.hostedemail.com: domain of 3KmgCZQYKCDMhTPcYRVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--seanjc.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3KmgCZQYKCDMhTPcYRVddVaT.RdbaXcjm-bbZkPRZ.dgV@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=1694656555; 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=snuesVO7Pgb0vyCed2d5Ea1z3YHTBEL1EKVJI8LHRYQ=; b=a3v57WnLSwgtwMZ+mNfHNtnrWqAsY9Ra+A1+IVm9tP/ub5EUuPEXIvniWBW80onotYLYPF UXahFw4pzZ8vF4l525fCQ3aQP8mfhJKB4QT9Gbot9z7X/1XZDN2TTvQuizbmICI0dntezn 1rBie57HnA75jxNAuuYgkGrNFiH60Qk= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1c08a15fcf4so3864675ad.3 for ; Wed, 13 Sep 2023 18:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694656554; x=1695261354; 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=snuesVO7Pgb0vyCed2d5Ea1z3YHTBEL1EKVJI8LHRYQ=; b=JG67F76Eoc0w+9Ln2a6HnvV//GejqbLJPVtGZo5Qi/79mntK83e3PIUZEvNMAFn3H5 h0b/eWj5JXrXY6Q6LCjDX47DqQxyFmyGJUxj6bEq0By6sW1UIsua8h6dekx5fMJjzC6J 6eajylvgf/LiIj3sRTYB6BCKB7iyEEeW/O255Un3LfqjApc3AdVU5hWV5Pun35SXN/6B 3wBePewOwBh7KtN6Abf2jFQoWDeTx3vXWClYIm1nB8A0mzFFO/LvOk6Lpw0ha5FC3msx PsvLmkbLfKIy3HivPMAQdlstVy8t5xBJ3qxQ1rCijpC0Lhyix6reS4aemHzUEBKmFJvs te0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694656554; x=1695261354; 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=snuesVO7Pgb0vyCed2d5Ea1z3YHTBEL1EKVJI8LHRYQ=; b=HW32/4HTqMjwiiITdpC6C6pqSobYX4SPcOIXLdZtMdKv9Gsk8GnQIcq2bOXKrVLPWj us0WoJGFOwCQagUqpL2i7tmD4/aTSXNYGe3Xt5YE4jIPIAqhkolSZe2O1f2X63vi1Ff3 toTM+HoDH8P5DoDP8C3I20V+No01IeM2yMrSGySLL3rjH3AYnbn7S4GwSiQQxEYr/Fga lzantRi5HVuShj8Rjqy6aESxtb3xU9CveLvMZ30D5jt/5CCeZFh5RyIsgc12l3Cssgzl aWaaBEKDvx/v+s9U6iY1JkUU6jETIb7911cwQMBGeDuUVUhZYvW0zkrriomHeRotFTdn Un9w== X-Gm-Message-State: AOJu0YxYHmmf3q2jPq/Zum/h0H48Z+pJbC2k537wsbGrwearFler2o0d WRT73ItjXG9b7yNiz+HL3N+doqiGkQ4= X-Google-Smtp-Source: AGHT+IGilm0IehJXdYbDJdwfV4Q368JwTuC1tx+vxoEF5ebf3gbFa0uVyGZgeqLtkzJroDu6r4LDVxWZ5mo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:6bca:b0:1b8:80c9:a98e with SMTP id m10-20020a1709026bca00b001b880c9a98emr149790plt.13.1694656554156; Wed, 13 Sep 2023 18:55:54 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 13 Sep 2023 18:55:07 -0700 In-Reply-To: <20230914015531.1419405-1-seanjc@google.com> Mime-Version: 1.0 References: <20230914015531.1419405-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230914015531.1419405-10-seanjc@google.com> Subject: [RFC PATCH v12 09/33] 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 , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" 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-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , Yu Zhang , Isaku Yamahata , Xu Yilun , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" X-Rspamd-Server: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WZ0VVe d0mQ8AjpQ82tg2u9FrKlKa4HyJwunn0eCYYQ4twk2e+dqsFllKWn3fEwlnGs5paYtWXtf4oHkV1iGcKqg548CMEzf8ggy8Zc3uBCUWhZ6k/SfDTBlkfMiDay046ufdMTwZOklDdtDTcevEI368BDIuSkfpy+TiOz5rdJU0MKw5YnFEqQzT1nJ1u4LLr01hFDsVACS5okYugPEvOSD3XlgRC3+V+ufguOz70bY3dub9Gg+JFtsuVKyxQEBYPkQ11r1qiZdkB1G9VB01NGXYwG58bO1cyMPnBcvQ0XlA+4ZOrZqcSt1o6Rw5n0WFMVbg9q2T2xpx3VOyqqTSAouUIp76r+Ci5dFHLs4vV5PbwwMiWR07loGRQKQVebxw0TrBZiHwj7k01LpknXxU9r3icV7Mng8upqs6bwgw/+0f0CnwIXMhhmfVaLgflFwsgC8aDbldhiX5c/b2FnkdsIndf/huJlz4H6cknzwlJostItSzyQNEVOSdHn5b03TN/TwMD6dsFDFUw8EhjcSXTRRaslPcu4J7TY66cfqWGKWP5rryaUHoFzgxQUBdM2LBjyAXi38i/Lbh4imhBA0lpKBeevmWxmpBUrwyf5T1s5NM6GJxtBCU4UFqcQNZTzQnNfJZ58LoQ/R7ADJkoNQ9evAvx8AW29TWdLbAO0fbgw/w83QYbnWC0HEElI9FpUioS+D4A9wymbp7+5XmvNebaw8UyP8DO45L9GiGLvrmuqGGrhLzGrMbkIXd1ozha6EN31As7cNL/+o+8iDjET039eaZIZ1y1sBlZ1WIuGElZWDdv1sSwOwuXEuYvsCPYUb5cEp+H2Ymt/q3FvFUyFcRSNlp0smy4CugdS96FTm1hUaEcAvFSd1szh+pZDUeS+EiMKcg3+IDGHuuTbGqUbfxeEJ1v/CIyrC5w== 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: 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 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 --- 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 76d01de7838f..174de2789657 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, }; @@ -811,7 +804,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), }; @@ -856,6 +848,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 @@ -887,7 +881,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), };