Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2580303rwd; Fri, 2 Jun 2023 11:21:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4as6zvVW6209Pia5lHlO9sK+rm4cx6Q8pPhmAPUWl4Nfo39ZU0f21wiaE1Bfbc98Y1Mb8E X-Received: by 2002:a54:4691:0:b0:398:3152:fee1 with SMTP id k17-20020a544691000000b003983152fee1mr696414oic.20.1685730090882; Fri, 02 Jun 2023 11:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685730090; cv=none; d=google.com; s=arc-20160816; b=zP0hMatlIrvgzIrgyRjLQbzy2m4U6MK5/0bw0iSX8/7zlLup0YXJin+xGnVJ5rMVAf v6Vbv1kslC1P3+q8/X7pB6CPh+Kf21tAI8BdfL7R8mVUhFRNBCjHQCeyWH3PWwfa+2Nv Z1CW+03G75J3fAsSNvz0p1u7Vv8ahzYXuZujrDFN5SVi3yki/lIWl20+Qz5s3GOP+W7e KnWuHop8fjlFlOzkWicBT2dekPi8nhX4vviuhUVy/tn8Iz3LWwpbGJqg5L1O+iMB3wwr +dMST2XzxCWPVKmExlJeg+Cb0U+5wJxrGIefObrRl/sbbruh/PN+Px0zaqzjIePLWkhF sAzw== 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=ekCXVjSa7w+GBQ89Kf04Azf22DBYG+ctyxjlz0fuMWo=; b=sUHgH5Y+qA3M9I0UcOTITqOAn8N2DTmb/Y4B1Caf+jTXSFlotP7vqDeLotbmRglE/n rRSi7lUrPUnNJVg/b+tkTDFmADU4lH6L6UQkeiTDCJRkWlBfqrJz5CSmhj3pEm+cQWRG 8lYtgW1J0Ot+GvKr1FD31QLOfqITNGlIP1f3dtHqa8ld+QB0PGiFo/nVRpFBZZ9L9YV4 AzZW1vgevkJJo+BSg9sru89zaIbKWtVCxPJF+RcAJcBf27waW/k3qfbrJb5llGDkn56y Jey5+gC0ZzpmeoCfBv/dNgQbbOGUj6Mqu+meCqZzEVdedLImDxYFi09U5dEJOnB4XCCB Zunw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LF2RMysN; 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 h16-20020a633850000000b0053b8570baafsi1337607pgn.444.2023.06.02.11.21.16; Fri, 02 Jun 2023 11:21:30 -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=LF2RMysN; 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 S237083AbjFBSSG (ORCPT + 99 others); Fri, 2 Jun 2023 14:18:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237025AbjFBSRp (ORCPT ); Fri, 2 Jun 2023 14:17:45 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5607B197; Fri, 2 Jun 2023 11:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685729864; x=1717265864; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3e3OFmQg7r8dzQcmVaorP5GcY9XosK0gMzuLCkej4As=; b=LF2RMysN3WigRIgediM2uJHHyDIqBrx2a1kRI3rO4tfzRDOpmhEQml7S b7y3O5tah9BPnLjxj0NdqAxxY6GwnrauxMaUIAxhtZQiHancava6d9VEt NqnOkaZ6CzcRBI7LJCybXKZ0xHlV9WDMMRnbx7KDf7MvR98uiK1QB59hd 2OKckK8WiTj6FiT7dbXT4z5BKIwN8THxs5gXFPwNLkmBvmG76eUu0TUYh SWc3C5E0aPGLRn5bzJ3cE26kjrQEdC33ppT5p9+NNguOeiShzegE5is7m EW4NotsyETtk57gOBa2UDcvXaYfNRP9r58nWNpWlhA28gKM6xG43tUscs Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="442310254" X-IronPort-AV: E=Sophos;i="6.00,213,1681196400"; d="scan'208";a="442310254" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2023 11:17:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10729"; a="832060971" X-IronPort-AV: E=Sophos;i="6.00,213,1681196400"; d="scan'208";a="832060971" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.97.184]) by orsmga004.jf.intel.com with ESMTP; 02 Jun 2023 11:17:38 -0700 From: Jacob Pan To: LKML , iommu@lists.linux.dev, Jason Gunthorpe , "Lu Baolu" , Joerg Roedel , "Robin Murphy" , Jean-Philippe Brucker , dmaengine@vger.kernel.org, vkoul@kernel.org Cc: "Will Deacon" , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" , rex.zhang@intel.com, xiaochen.shen@intel.com, narayan.ranganathan@intel.com, Jacob Pan Subject: [PATCH v8 5/7] iommu/vt-d: Make prq draining code generic Date: Fri, 2 Jun 2023 11:22:10 -0700 Message-Id: <20230602182212.150825-6-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230602182212.150825-1-jacob.jun.pan@linux.intel.com> References: <20230602182212.150825-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 --- drivers/iommu/intel/iommu.c | 30 +++++++++++++++++++----------- drivers/iommu/intel/iommu.h | 2 ++ drivers/iommu/intel/svm.c | 8 ++------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 3214990b69b7..8ea656446616 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4740,21 +4740,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 (!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..588367a9e9b5 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) @@ -391,8 +389,6 @@ void intel_svm_remove_dev_pasid(struct device *dev, u32 pasid) * 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 +445,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 +459,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