From patchwork Tue Oct 17 03:20:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Tina" X-Patchwork-Id: 153892 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3872818vqb; Mon, 16 Oct 2023 20:23:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8ccx/jvU5ZLVVsOvdnE2WXz6Vn/ewBFTT7ZMjg0+0Ht6Vl/7ENT7zVxKKwCrFnXbTKcV0 X-Received: by 2002:a05:6a20:7d91:b0:163:57ba:2ad4 with SMTP id v17-20020a056a207d9100b0016357ba2ad4mr1156085pzj.2.1697513014419; Mon, 16 Oct 2023 20:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697513014; cv=none; d=google.com; s=arc-20160816; b=LT0qZSM6h0h+Mj/CJXf9xxVwU+3LP8pxDmlTJsPGkhtNsKEv1Y5dPrLcgRrm20TrBW E0lm3FSdSIBSDVlyPqfRxAPMXUG5Jr+RDcTie6Oj6aVJT6qS3809QDAH66ne++qJhhnB 93/Di4ki3RYAaTP6JuT/Es+Zg+bta6dqn4CxtyVbZHopq1G77x52DZoN3Dsm1Qvkn1xD UekIRQ9yYTMjZIpbbraMkIzlPH0yYGX7H3UNhYvMUrpVdT6s9zXALS0ZTwQ+BUa+ibuW RD9KKr1kcDH80+Rt5e45dfUVVLvaF7iM+pOEmOz17SKYAfHHUwahUtJSqqL4Xp6fX97H Z96Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=haCsEVuflKJ0Td8QM6lx9zWHn1VHMXWzEWrO9vs/4rg=; fh=R49q8kPD/ziIvsyYshS2LccDCxkbN9TSdzSyy3EleF0=; b=NCzoVXnHe08aAp4vIOuXIYrZBBs44AtKsAdKNwBpTiUgP0M8v5PCo5tFZvhslgiGEN ntfNbnmi/t+CIEbc5a7JPXi9UxHrNDFqNjhNQMp4i2bhQJ78v8iMP9+8HQlZKg+eQT0T VoeloX3AJOfv3Ao+UJT5DR21UkgmrObzFw28VP+yFqu2/N4urUnBSo5LGMk4F/29RSJ1 dM7GodDex/2KNJeaLqig1VPYst7UeoBAExuoxS8cp2JvpxGggsoed+rBR+KMNGoSbjV0 lrJxknvC8rfdV7dmo9kZmnxSFBbJ4jYIdDC9Khupmkv3449b1O03A3DMQqOexvFfqDKD 0XHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VTIfFmeM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id d8-20020a170902cec800b001c1f1394bf9si854308plg.357.2023.10.16.20.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 20:23:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VTIfFmeM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 56D5D8077A47; Mon, 16 Oct 2023 20:23:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234337AbjJQDWm (ORCPT + 19 others); Mon, 16 Oct 2023 23:22:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234581AbjJQDWG (ORCPT ); Mon, 16 Oct 2023 23:22:06 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48806D43; Mon, 16 Oct 2023 20:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697512896; x=1729048896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8lrMBovYHF13zqlv8fq2NGGZgFHbL3cK2VIac2TIbMY=; b=VTIfFmeMJTTOnw77lzFEU3b1fXofAy1tGCOb77oKTJim1KdF3Mdl7vFb M/dgTAxGa6z8f3vN+MfDrplG+PfXRU7qlvjK24EQM/adVbiNNEuO7OT2e VyRT69geh3E9WdtLNGKMXFqLIFBh/mId5zFy0fMP1+hVbfarkBp/X2nWx diTjdGyBin7fYq9wa4B6a12LvhLyahr1V0cDE1g/NEw8jg4O96c2uBWbo fAexO3Ps78UASBNDUG0MCKmKAKn8jGT/n2tXvT7ehI9O0sAsjHhLVXuVU NMoAmE6DXOfRwV9h47soJrvqrOOa9GZJFFWxyIhKkni3q0pwToBCmkr8L g==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="389560888" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="389560888" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 20:21:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="826270092" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="826270092" Received: from sqa-gate.sh.intel.com (HELO spr-2s5.tsp.org) ([10.239.48.212]) by fmsmga004.fm.intel.com with ESMTP; 16 Oct 2023 20:21:33 -0700 From: Tina Zhang To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Jason Gunthorpe , Kevin Tian , Tina Zhang Subject: [RFC PATCH 10/12] iommu/vt-d: Refactor intel_iommu_remove_dev_pasid() Date: Tue, 17 Oct 2023 11:20:43 +0800 Message-Id: <20231017032045.114868-12-tina.zhang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231017032045.114868-1-tina.zhang@intel.com> References: <20231017032045.114868-1-tina.zhang@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 16 Oct 2023 20:23:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779971406836007119 X-GMAIL-MSGID: 1779971406836007119 Since domain centralizes info required for sva domain in itself, the intel_iommu_remove_dev_pasid() can handle device detaching work of sva domain w/o asking help of intel_svm_remove_dev_pasid() any more. Signed-off-by: Tina Zhang --- drivers/iommu/intel/iommu.c | 16 +++++---------- drivers/iommu/intel/iommu.h | 4 ---- drivers/iommu/intel/svm.c | 39 ------------------------------------- 3 files changed, 5 insertions(+), 54 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 57f6bbf33205..2aea5201de3d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4703,19 +4703,9 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid) unsigned long flags; domain = iommu_get_domain_for_dev_pasid(dev, pasid, 0); - if (WARN_ON_ONCE(!domain)) + if (WARN_ON_ONCE(IS_ERR_OR_NULL(domain))) goto out_tear_down; - /* - * The SVA implementation needs to handle its own stuffs like the mm - * notification. Before consolidating that code into iommu core, let - * the intel sva code handle it. - */ - if (domain_type_is_sva(dmar_domain)) { - intel_svm_remove_dev_pasid(dev, pasid); - goto out_tear_down; - } - dmar_domain = to_dmar_domain(domain); spin_lock_irqsave(&dmar_domain->lock, flags); list_for_each_entry(curr, &dmar_domain->dev_pasids, link_domain) { @@ -4730,6 +4720,10 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid) domain_detach_iommu(dmar_domain, iommu); kfree_rcu(dev_pasid, rcu); + if (list_empty(&to_dmar_domain(domain)->dev_pasids)) { + if (domain->notifier.ops) + mmu_notifier_unregister(&domain->notifier, domain->mm); + } out_tear_down: intel_pasid_tear_down_entry(iommu, dev, pasid, false); intel_drain_pasid_prq(dev, pasid); diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index b6dff0da9e8e..84e942a16666 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -860,7 +860,6 @@ int intel_svm_finish_prq(struct intel_iommu *iommu); int intel_svm_page_response(struct device *dev, struct iommu_fault_event *evt, struct iommu_page_response *msg); struct iommu_domain *intel_svm_domain_alloc(void); -void intel_svm_remove_dev_pasid(struct device *dev, ioasid_t pasid); void intel_drain_pasid_prq(struct device *dev, u32 pasid); #else static inline void intel_svm_check(struct intel_iommu *iommu) {} @@ -870,9 +869,6 @@ static inline struct iommu_domain *intel_svm_domain_alloc(void) return NULL; } -static inline void intel_svm_remove_dev_pasid(struct device *dev, ioasid_t pasid) -{ -} #endif #ifdef CONFIG_INTEL_IOMMU_DEBUGFS diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index fd61fbf7593a..7f98c8acd04f 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -27,23 +27,6 @@ static irqreturn_t prq_event_thread(int irq, void *d); -static struct dev_pasid_info * -domain_lookup_dev_pasid_info_by_dev(struct dmar_domain *domain, struct device *dev) -{ - struct dev_pasid_info *dev_pasid = NULL, *t; - - rcu_read_lock(); - list_for_each_entry_rcu(t, &domain->dev_pasids, link_domain) { - if (t->dev == dev) { - dev_pasid = t; - break; - } - } - rcu_read_unlock(); - - return dev_pasid; -} - int intel_svm_enable_prq(struct intel_iommu *iommu) { struct iopf_queue *iopfq; @@ -301,28 +284,6 @@ static int intel_svm_set_dev_pasid(struct iommu_domain *domain, return ret; } -void intel_svm_remove_dev_pasid(struct device *dev, u32 pasid) -{ - struct iommu_domain *domain; - struct dev_pasid_info *dev_pasid; - - domain = iommu_get_domain_for_dev_pasid(dev, pasid, - IOMMU_DOMAIN_SVA); - if (WARN_ON_ONCE(IS_ERR_OR_NULL(domain))) - return; - - dev_pasid = domain_lookup_dev_pasid_info_by_dev(to_dmar_domain(domain), dev); - if (dev_pasid) { - list_del_rcu(&dev_pasid->link_domain); - kfree_rcu(dev_pasid, rcu); - - if (list_empty(&to_dmar_domain(domain)->dev_pasids)) { - if (domain->notifier.ops) - mmu_notifier_unregister(&domain->notifier, domain->mm); - } - } -} - /* Page request queue descriptor */ struct page_req_dsc { union {