From nobody Mon Feb 9 11:29:38 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1640100404320713.3954868768691; Tue, 21 Dec 2021 07:26:44 -0800 (PST) Received: from localhost ([::1]:40726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzh2G-0001wP-Ti for importer@patchew.org; Tue, 21 Dec 2021 10:26:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzgpI-0008B3-Oi for qemu-devel@nongnu.org; Tue, 21 Dec 2021 10:13:16 -0500 Received: from mga01.intel.com ([192.55.52.88]:50987) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzgpG-0008HR-L7 for qemu-devel@nongnu.org; Tue, 21 Dec 2021 10:13:16 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2021 07:13:10 -0800 Received: from chaop.bj.intel.com ([10.240.192.101]) by orsmga005.jf.intel.com with ESMTP; 21 Dec 2021 07:13:03 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1640099594; x=1671635594; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=mFDIpY3/LyMlA/FBo77jj+CP6HruamtUy42MpTsU/84=; b=Oq7/Z6ObVc5ksWtXk98iEoDoMMOMLLNAS5KlyVBd88/MlIb0q95P1MwL t+wdmvdvdgGpwkeAn+x4lG62fwpSLcjNS7ZYwu5W+lyOyWPIMTFsymTRQ yqXRg13sPzNvkOg84x0RMULcw701DNevFVnaFD3Yq/zvf9TtAinpRSNHt p5y7jLyNVxKJ4QuFiPVeAdbAiratRUZnFuIzgNEVtIuIynovgI1pc2vP4 MgVtYk8u7H3h8GWNOyzedHR7NL5rhMTYgOIUrKad5ksSmaEX9Zx6j+Y+w 3xpOKnbFKHbv14rxRNvh/XSYYr1VlkwjYDW8pE8Dfp+hNVPAEedOTwFrr A==; X-IronPort-AV: E=McAfee;i="6200,9189,10204"; a="264601415" X-IronPort-AV: E=Sophos;i="5.88,223,1635231600"; d="scan'208";a="264601415" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,223,1635231600"; d="scan'208";a="684688504" From: Chao Peng To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, qemu-devel@nongnu.org Subject: [PATCH v3 08/15] KVM: Split out common memory invalidation code Date: Tue, 21 Dec 2021 23:11:18 +0800 Message-Id: <20211221151125.19446-9-chao.p.peng@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211221151125.19446-1-chao.p.peng@linux.intel.com> References: <20211221151125.19446-1-chao.p.peng@linux.intel.com> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=192.55.52.88; envelope-from=chao.p.peng@linux.intel.com; helo=mga01.intel.com X-Spam_score_int: -71 X-Spam_score: -7.2 X-Spam_bar: ------- X-Spam_report: (-7.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.203, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wanpeng Li , jun.nakajima@intel.com, david@redhat.com, "J . Bruce Fields" , dave.hansen@intel.com, "H . Peter Anvin" , Chao Peng , ak@linux.intel.com, Jonathan Corbet , Joerg Roedel , x86@kernel.org, Hugh Dickins , Ingo Molnar , Borislav Petkov , luto@kernel.org, Thomas Gleixner , Vitaly Kuznetsov , Jim Mattson , Sean Christopherson , susie.li@intel.com, Jeff Layton , john.ji@intel.com, Yu Zhang , Paolo Bonzini , Andrew Morton , "Kirill A . Shutemov" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1640100406239100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When fd-based memory is enabled, there will be two types of memory invalidation: - memory invalidation from native MMU through mmu_notifier callback for hva-based memory, and, - memory invalidation from memfd through memfd_notifier callback for fd-based memory. Some code can be shared between these two types of memory invalidation. This patch moves these shared code into one place so that it can be used for CONFIG_MMU_NOTIFIER as well as CONFIG_MEMFD_NOTIFIER. Signed-off-by: Yu Zhang Signed-off-by: Chao Peng --- virt/kvm/kvm_main.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 0f2d1002f6a7..59f01e68337b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -454,22 +454,6 @@ void kvm_vcpu_destroy(struct kvm_vcpu *vcpu) EXPORT_SYMBOL_GPL(kvm_vcpu_destroy); =20 #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) -static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn) -{ - return container_of(mn, struct kvm, mmu_notifier); -} - -static void kvm_mmu_notifier_invalidate_range(struct mmu_notifier *mn, - struct mm_struct *mm, - unsigned long start, unsigned long end) -{ - struct kvm *kvm =3D mmu_notifier_to_kvm(mn); - int idx; - - idx =3D srcu_read_lock(&kvm->srcu); - kvm_arch_mmu_notifier_invalidate_range(kvm, start, end); - srcu_read_unlock(&kvm->srcu, idx); -} =20 typedef bool (*gfn_handler_t)(struct kvm *kvm, struct kvm_gfn_range *range= ); =20 @@ -580,6 +564,25 @@ static __always_inline int __kvm_handle_useraddr_range= (struct kvm *kvm, /* The notifiers are averse to booleans. :-( */ return (int)ret; } +#endif + +#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) +static inline struct kvm *mmu_notifier_to_kvm(struct mmu_notifier *mn) +{ + return container_of(mn, struct kvm, mmu_notifier); +} + +static void kvm_mmu_notifier_invalidate_range(struct mmu_notifier *mn, + struct mm_struct *mm, + unsigned long start, unsigned long end) +{ + struct kvm *kvm =3D mmu_notifier_to_kvm(mn); + int idx; + + idx =3D srcu_read_lock(&kvm->srcu); + kvm_arch_mmu_notifier_invalidate_range(kvm, start, end); + srcu_read_unlock(&kvm->srcu, idx); +} =20 static __always_inline int kvm_handle_hva_range(struct mmu_notifier *mn, unsigned long start, --=20 2.17.1