Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9964906rwd; Wed, 21 Jun 2023 14:23:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ75NMeOFqc6w2Ryf9xQ3SpnLScfxAvl0B19N9240Qmy/Umlurqm2cFFA47BXeQoGIU15ok7 X-Received: by 2002:a05:6a20:6a28:b0:10c:c5df:8bb7 with SMTP id p40-20020a056a206a2800b0010cc5df8bb7mr13740952pzk.30.1687382613533; Wed, 21 Jun 2023 14:23:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687382613; cv=none; d=google.com; s=arc-20160816; b=BhpA5jV9bOusieyboov5X8ESaraGJRMtVkWZbN5T8MelZ846CF6xGC+vhkKtadZR40 wYRLHDhZGDcRc0XrFGNMZIE0pe+2WJAPewI7Wv96cHi0798VEt7SX9jBur/KZtP7UZJa SsU5hxt7Qi+TYHZ7+nlDJkuG0v9dAP8lTmshEA3k7wdCDx6z2zSTMozXolmzltTwmB1t cy7pmbn16k9jUYQO0AJf+coMzkMl59NE8SUe1dXffiCJRvmLriUGLEsoKixR5cCg1lP7 M85nP9hxsypsnryRmyZzVxIB1rNf1VZCfgQ5U3K1qvy+nlfk+p88oapU03LQKtDq4r1y W6BA== 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=UOo5wa5sZgbEAi6OOvDHjtqns0dwaM38QKdlndMg1Agldd8qPywkqoP2ovtC0hJ8Fu rXrxcAN5ea8zOYhs2FlaJKQBmSMyTa+yNUJ9VmA0yKT1EXJbRP+FxQnHkbXj+an43/mV TcUjRXIZGahibzfE0rKZ6eQqFPkwYYmOR/7XSl3Jrc58IwJardAsklszMCUCKjvDsiaa bOA+DsBa/ZPITyFzcr6dtGRBrWS63M8WsdJ6Ov4hykXpAEsQ2GIiwCE8R62eBaQ/DxOh m3D7oIXu/VTFJIDiM48QHK+kRdF/tkyKzaf1Jl6PlFXfII2KSgU66+yifeS2jzX7habb 6uAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=guUnuieO; 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 f17-20020a170902f39100b001a9b4bda723si4523457ple.421.2023.06.21.14.23.20; Wed, 21 Jun 2023 14:23:33 -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=guUnuieO; 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 S230340AbjFUUzZ (ORCPT + 99 others); Wed, 21 Jun 2023 16:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbjFUUzL (ORCPT ); Wed, 21 Jun 2023 16:55:11 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8761719A3; Wed, 21 Jun 2023 13:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1687380910; x=1718916910; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3e3OFmQg7r8dzQcmVaorP5GcY9XosK0gMzuLCkej4As=; b=guUnuieO9Z4dsU+08NfPwAo9ToLbWGIJ1QhXIu7bAEypscnDxL/JBoTj UPcsfDIHNkV4gPAB1/hg867KEAoJPR4X3SD5J9enFKsu63ChbsGg35+++ L78oPJy/gAMoviCueeNpdCLnpKwKjWbDIFXlw+ANcwMZO9ncNnDmkzke/ qfR+BgJUqlmZoVW6gUoD7UkSZlAnOqoObie2UASAKW/k1it+0bdM7RimF yYp1GEfetBxQI7djYjIV6hsnM0pJv8mmSBPFkSXO3Hz8dapfHxkz4MtD+ Z0KZ7hWs+rjsKs+y7V4Qo6ZBKUc6fDvZaGq+VkXWrus694PyOoYpOE/bF A==; X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="359168947" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="359168947" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2023 13:55:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10748"; a="827597924" X-IronPort-AV: E=Sophos;i="6.00,261,1681196400"; d="scan'208";a="827597924" Received: from srinivas-otcpl-7600.jf.intel.com (HELO jacob-builder.jf.intel.com) ([10.54.97.184]) by fmsmga002.fm.intel.com with ESMTP; 21 Jun 2023 13:55:08 -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 v9 5/7] iommu/vt-d: Make prq draining code generic Date: Wed, 21 Jun 2023 13:59:45 -0700 Message-Id: <20230621205947.1327094-6-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230621205947.1327094-1-jacob.jun.pan@linux.intel.com> References: <20230621205947.1327094-1-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 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