Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1538039rwo; Wed, 2 Aug 2023 16:14:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlF/mXD0tUthYKPOtExm0Fyh9xwWy3hSvQLRLW2eOd4UNdfT0hC1gOvXAaKeRvVqMs3qHHBW X-Received: by 2002:a5d:608a:0:b0:313:e8b6:1699 with SMTP id w10-20020a5d608a000000b00313e8b61699mr5868044wrt.55.1691018099306; Wed, 02 Aug 2023 16:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691018099; cv=none; d=google.com; s=arc-20160816; b=nJQuC0JJYksXRbZYqOJEHDfTy18HbEvLeMS23WYeme2F+Owp4/HRgKtpe+xUy5+eaA Tt/rhW3I1lwO60VNlxAh5diFcdTgFXLwLLGFkag7T+ESTGeluqudGbEw1j6u9jVmTec+ lBlgOgtyG1aWdiJPP/4iptnPbQhvWcN598nYKHbqOBshvn0amkNIjBqJm2e8yHWaqRaW y3hVwqkpTqNnTdNPzpPrVF2ygtqCH1/bPIed6KFJuYQQdWHIJpb55qY2/rvD2b2OnaeM Gzvl4KYofvqFH0Ew1QRoH+4pdQaoyTEGeyWIgzg44y4hXkS3yuoaWZlQy396LZ1dAr4j /iYg== 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=bQWuk1XZc6WYD+0mo0+1WmBalNLwTSqwa1jO0sM0lgQ=; fh=bGo/Q4ro8pFaOByjLYWhYmu9zFeFMbnTLIEA0/9l4hc=; b=0gYQOTWnXYfUmUkhXMnQxjsTxC0Ly+TvGc8RLd+ebI538AfwIVTYQL8MSW++qTrNiU oBc53s+nH3/WdEWX/+Jf71czH2DO/RJGxuNqoh+/6ByHdwzx4TUb/r5++PMhiAeWRo9G PS0hXr1J3nofMP4FK9o8i5SbFDCeSpGU//J1yd16Wfzh6/RaHRCWg0OJEsWPfUti8MiB bu529waj2Q4dc/X+91YmuwjsWFPwTFmgGTfH8B4gBWe+Vy3+FDtVXSCPrOleWxc8/vlg 5+53tyFuaZcpXiwhHJ0HcZDX66BtHmpDP05+KCiqlXfJLtjGfYhbWLVyKqnuINPHvw/G ISTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WmlzfuPa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i19-20020aa7dd13000000b00522202a23d6si613998edv.127.2023.08.02.16.14.35; Wed, 02 Aug 2023 16:14:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WmlzfuPa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232662AbjHBVTs (ORCPT + 99 others); Wed, 2 Aug 2023 17:19:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbjHBVT1 (ORCPT ); Wed, 2 Aug 2023 17:19:27 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC48C2D42 for ; Wed, 2 Aug 2023 14:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691011165; x=1722547165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kZVeq1rXuwa6GYQA59z5gU2DeM0mMtagVuisbPFVZ2I=; b=WmlzfuPaOvaPu/UN1IzBXdFhCwkObzDvUBnh4vXeq6R00QnYmjtQW9JJ o7Il8ryAciKKTeHKrtGfEllB1Trft9d0Kw5ffdjxSVBui7FZg7uNqzSZr pnjVMSzQXSkbzxq70x0/7w9O+BkUtYLR5IsuZr4coVGpD3Ul6qXwRtq8h 52GOk+nccq3B4AEwByu/waVlnIbMF0chulQGd1SsU1yCTtTtcI+73HmAZ OxjG9+Fhra9Ut8NzPID3nqwiG1QvOC2PQdyhhQMd7JSf/D+5PhfqmptxB +RnwiOZCpe46qHy1h4nYIDjhxY8rhCHkaEafcY2aiGqgUjEO90TFFgWfA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="372436163" X-IronPort-AV: E=Sophos;i="6.01,250,1684825200"; d="scan'208";a="372436163" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2023 14:19:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="729290792" X-IronPort-AV: E=Sophos;i="6.01,250,1684825200"; d="scan'208";a="729290792" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.97.184]) by orsmga002.jf.intel.com with ESMTP; 02 Aug 2023 14:19:22 -0700 From: Jacob Pan To: LKML , iommu@lists.linux.dev, "Lu Baolu" , Joerg Roedel , Jean-Philippe Brucker , "Robin Murphy" Cc: Jason Gunthorpe , "Will Deacon" , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Tony Luck , Jacob Pan Subject: [PATCH v12 5/8] iommu/vt-d: Make prq draining code generic Date: Wed, 2 Aug 2023 14:24:24 -0700 Message-Id: <20230802212427.1497170-6-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230802212427.1497170-1-jacob.jun.pan@linux.intel.com> References: <20230802212427.1497170-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lu Baolu Currently draining page requests and responses for a pasid is part of SVA implementation. This is because the driver only supports attaching an SVA domain to a device pasid. As we are about to support attaching other types of domains to a device pasid, the prq draining code becomes generic. Reviewed-by: Jacob Pan Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 30 +++++++++++++++++++----------- drivers/iommu/intel/iommu.h | 2 ++ drivers/iommu/intel/svm.c | 17 ++--------------- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index bb8316fec1aa..bdde38a5e43a 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4720,21 +4720,29 @@ static void intel_iommu_remove_dev_pasid(struct device *dev, ioasid_t pasid) struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL); struct iommu_domain *domain; - /* Domain type specific cleanup: */ domain = iommu_get_domain_for_dev_pasid(dev, pasid, 0); - if (domain) { - switch (domain->type) { - case IOMMU_DOMAIN_SVA: - intel_svm_remove_dev_pasid(dev, pasid); - break; - default: - /* should never reach here */ - WARN_ON(1); - break; - } + if (WARN_ON_ONCE(!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 == IOMMU_DOMAIN_SVA) { + intel_svm_remove_dev_pasid(dev, pasid); + goto out_tear_down; } + /* + * Should never reach here until we add support for attaching + * non-SVA domain to a pasid. + */ + WARN_ON(1); + +out_tear_down: intel_pasid_tear_down_entry(iommu, dev, pasid, false); + intel_drain_pasid_prq(dev, pasid); } const struct iommu_ops intel_iommu_ops = { diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 1c5e1d88862b..6d94a29f5d52 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -844,6 +844,7 @@ 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); struct intel_svm_dev { struct list_head list; @@ -862,6 +863,7 @@ struct intel_svm { }; #else static inline void intel_svm_check(struct intel_iommu *iommu) {} +static inline void intel_drain_pasid_prq(struct device *dev, u32 pasid) {} static inline struct iommu_domain *intel_svm_domain_alloc(void) { return NULL; diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index 2a82864e9d57..9fbae9af6615 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -26,8 +26,6 @@ #include "trace.h" static irqreturn_t prq_event_thread(int irq, void *d); -static void intel_svm_drain_prq(struct device *dev, u32 pasid); -#define to_intel_svm_dev(handle) container_of(handle, struct intel_svm_dev, sva) static DEFINE_XARRAY_ALLOC(pasid_private_array); static int pasid_private_add(ioasid_t pasid, void *priv) @@ -382,17 +380,6 @@ void intel_svm_remove_dev_pasid(struct device *dev, u32 pasid) if (sdev) { list_del_rcu(&sdev->list); - /* - * Flush the PASID cache and IOTLB for this device. - * Note that we do depend on the hardware *not* using - * the PASID any more. Just as we depend on other - * devices never using PASIDs that they have no right - * to use. We have a *shared* PASID table, because it's - * large and has to be physically contiguous. So it's - * hard to be as defensive as we might like. - */ - intel_pasid_tear_down_entry(iommu, dev, svm->pasid, false); - intel_svm_drain_prq(dev, svm->pasid); kfree_rcu(sdev, rcu); if (list_empty(&svm->devs)) { @@ -449,7 +436,7 @@ static bool is_canonical_address(u64 addr) } /** - * intel_svm_drain_prq - Drain page requests and responses for a pasid + * intel_drain_pasid_prq - Drain page requests and responses for a pasid * @dev: target device * @pasid: pasid for draining * @@ -463,7 +450,7 @@ static bool is_canonical_address(u64 addr) * described in VT-d spec CH7.10 to drain all page requests and page * responses pending in the hardware. */ -static void intel_svm_drain_prq(struct device *dev, u32 pasid) +void intel_drain_pasid_prq(struct device *dev, u32 pasid) { struct device_domain_info *info; struct dmar_domain *domain; -- 2.25.1