From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A74C91DDA15 for ; Fri, 14 Feb 2025 06:11:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513465; cv=none; b=FT7gftKX/GaL59emLbptQP6rutIn71eNXZze7DwQhpq53gwu43KTVwi+ecd8jS6MUKpUBiKFoA3zujgD1Tq7Ak4uTHi3Cn/FhAUNYI/mrmri+l7VnMFY69O+nutMmBdHMQTI9pr6B3kvux8kpRBQ+0CGhYBfhPhhHFyi9HpKZDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513465; c=relaxed/simple; bh=R/fv1PbpOE+1k1PHs3HPMG2SWgw7UF9nULy02rnvUTk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WiC/fK/r4zUTfQVInQNFtKTVbO6UcmNLFPYS5/nz3DFVNcwZ7LzplzQe1lapFX98v7S54uFm9p2KMbeYbc3g6SaW/bTq5sjHBh6gCTihAXbylw36BbxdCP4NjfLOcnSbsl7ubw3ny0pfAabMSrbTaoOBTDc6pCGGyQ4fKf19RRg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BBJDFL/C; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BBJDFL/C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513464; x=1771049464; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R/fv1PbpOE+1k1PHs3HPMG2SWgw7UF9nULy02rnvUTk=; b=BBJDFL/CehE/w4T6pHRIiLqVtjViPjBEtW1U2/4I7iYwy3Sz1L26Up/a nT+q3JEjREBD5ow8yieeIe9naUFlpHYaBaxgt2T5KXJZm8vmMjTTeIwVZ AqiCQol7ve7vcC1BnwuU5hL3n+oE0WCkGoZrxs8IVGqKDwoDVymAj3awx +KldLhP/As7aY1UWbKtHD7Gixwv+nSGfJePS9+gNMbkjm0hDQQK+XVDvF 0qHCaKEAQUjxy62tjhGonyU+JsKUGARBslI+GTrMFEjA2HXLzgku1cHh/ 0oMAykvc93TzpMce0mMmyK9GABQEeT8KoPnQb9s+pOReK8ePvS8uYsSh8 g==; X-CSE-ConnectionGUID: fNyu5XOAQeSwpvrZRsp3kQ== X-CSE-MsgGUID: ynVB8y/RS4uSyalI5yxScQ== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124467" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124467" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:03 -0800 X-CSE-ConnectionGUID: vgptYlMGTYCO8mhg48vDcg== X-CSE-MsgGUID: 9i/HYfvNTvG+Endq88yirw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268061" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:00 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Jason Gunthorpe , Lu Baolu Subject: [PATCH 01/12] iommu/arm-smmu-v3: Put iopf enablement in the domain attach path Date: Fri, 14 Feb 2025 14:10:53 +0800 Message-ID: <20250214061104.1959525-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jason Gunthorpe SMMUv3 co-mingles FEAT_IOPF and FEAT_SVA behaviors so that fault reporting doesn't work unless both are enabled. This is not correct and causes problems for iommufd which does not enable FEAT_SVA for it's fault capable domains. These APIs are both obsolete, update SMMUv3 to use the new method like AMD implements. A driver should enable iopf support when a domain with an iopf_handler is attached, and disable iopf support when the domain is removed. Move the fault support logic to sva domain allocation and to domain attach, refusing to create or attach fault capable domains if the HW doesn't support it. Move all the logic for controlling the iopf queue under arm_smmu_attach_prepare(). Keep track of the number of domains on the master (over all the SSIDs) that require iopf. When the first domain requiring iopf is attached create the iopf queue, when the last domain is detached destroy it. Turn FEAT_IOPF and FEAT_SVA into no ops. Remove the sva_lock, this is all protected by the group mutex. Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 86 ++-------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 98 ++++++++++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 34 +------ 3 files changed, 81 insertions(+), 137 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iomm= u/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 9ba596430e7c..605d1dd0e1cc 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -13,8 +13,6 @@ #include "arm-smmu-v3.h" #include "../../io-pgtable-arm.h" =20 -static DEFINE_MUTEX(sva_lock); - static void __maybe_unused arm_smmu_update_s1_domain_cd_entry(struct arm_smmu_domain *smmu_domain) { @@ -257,84 +255,6 @@ bool arm_smmu_sva_supported(struct arm_smmu_device *sm= mu) return true; } =20 -bool arm_smmu_master_iopf_supported(struct arm_smmu_master *master) -{ - /* We're not keeping track of SIDs in fault events */ - if (master->num_streams !=3D 1) - return false; - - return master->stall_enabled; -} - -bool arm_smmu_master_sva_supported(struct arm_smmu_master *master) -{ - if (!(master->smmu->features & ARM_SMMU_FEAT_SVA)) - return false; - - /* SSID support is mandatory for the moment */ - return master->ssid_bits; -} - -bool arm_smmu_master_sva_enabled(struct arm_smmu_master *master) -{ - bool enabled; - - mutex_lock(&sva_lock); - enabled =3D master->sva_enabled; - mutex_unlock(&sva_lock); - return enabled; -} - -static int arm_smmu_master_sva_enable_iopf(struct arm_smmu_master *master) -{ - struct device *dev =3D master->dev; - - /* - * Drivers for devices supporting PRI or stall should enable IOPF first. - * Others have device-specific fault handlers and don't need IOPF. - */ - if (!arm_smmu_master_iopf_supported(master)) - return 0; - - if (!master->iopf_enabled) - return -EINVAL; - - return iopf_queue_add_device(master->smmu->evtq.iopf, dev); -} - -static void arm_smmu_master_sva_disable_iopf(struct arm_smmu_master *maste= r) -{ - struct device *dev =3D master->dev; - - if (!master->iopf_enabled) - return; - - iopf_queue_remove_device(master->smmu->evtq.iopf, dev); -} - -int arm_smmu_master_enable_sva(struct arm_smmu_master *master) -{ - int ret; - - mutex_lock(&sva_lock); - ret =3D arm_smmu_master_sva_enable_iopf(master); - if (!ret) - master->sva_enabled =3D true; - mutex_unlock(&sva_lock); - - return ret; -} - -int arm_smmu_master_disable_sva(struct arm_smmu_master *master) -{ - mutex_lock(&sva_lock); - arm_smmu_master_sva_disable_iopf(master); - master->sva_enabled =3D false; - mutex_unlock(&sva_lock); - - return 0; -} - void arm_smmu_sva_notifier_synchronize(void) { /* @@ -353,6 +273,9 @@ static int arm_smmu_sva_set_dev_pasid(struct iommu_doma= in *domain, struct arm_smmu_cd target; int ret; =20 + if (!(master->smmu->features & ARM_SMMU_FEAT_SVA)) + return -EOPNOTSUPP; + /* Prevent arm_smmu_mm_release from being called while we are attaching */ if (!mmget_not_zero(domain->mm)) return -EINVAL; @@ -406,6 +329,9 @@ struct iommu_domain *arm_smmu_sva_domain_alloc(struct d= evice *dev, u32 asid; int ret; =20 + if (!(master->smmu->features & ARM_SMMU_FEAT_SVA)) + return ERR_PTR(-EOPNOTSUPP); + smmu_domain =3D arm_smmu_domain_alloc(); if (IS_ERR(smmu_domain)) return ERR_CAST(smmu_domain); diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 358072b4e293..75b2f7c609ca 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2748,6 +2748,54 @@ to_smmu_domain_devices(struct iommu_domain *domain) return NULL; } =20 +static int arm_smmu_enable_iopf(struct arm_smmu_master *master, + struct arm_smmu_master_domain *master_domain) +{ + int ret; + + iommu_group_mutex_assert(master->dev); + + if (!IS_ENABLED(CONFIG_ARM_SMMU_V3_SVA)) + return -EOPNOTSUPP; + + /* + * Drivers for devices supporting PRI or stall require iopf others have + * device-specific fault handlers and don't need IOPF, so this is not a + * failure. + */ + if (!master->stall_enabled) + return 0; + + /* We're not keeping track of SIDs in fault events */ + if (master->num_streams !=3D 1) + return -EOPNOTSUPP; + + if (master->iopf_refcount) { + master->iopf_refcount++; + master_domain->using_iopf =3D true; + return 0; + } + + ret =3D iopf_queue_add_device(master->smmu->evtq.iopf, master->dev); + if (ret) + return ret; + master->iopf_refcount =3D 1; + master_domain->using_iopf =3D true; + return 0; +} + +static void arm_smmu_disable_iopf(struct arm_smmu_master *master) +{ + iommu_group_mutex_assert(master->dev); + + if (!IS_ENABLED(CONFIG_ARM_SMMU_V3_SVA)) + return; + + master->iopf_refcount--; + if (master->iopf_refcount =3D=3D 0) + iopf_queue_remove_device(master->smmu->evtq.iopf, master->dev); +} + static void arm_smmu_remove_master_domain(struct arm_smmu_master *master, struct iommu_domain *domain, ioasid_t ssid) @@ -2768,11 +2816,16 @@ static void arm_smmu_remove_master_domain(struct ar= m_smmu_master *master, nested_ats_flush); if (master_domain) { list_del(&master_domain->devices_elm); - kfree(master_domain); if (master->ats_enabled) atomic_dec(&smmu_domain->nr_ats_masters); } spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + + if (master_domain) { + if (master_domain->using_iopf) + arm_smmu_disable_iopf(master); + kfree(master_domain); + } } =20 /* @@ -2803,6 +2856,7 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_st= ate *state, struct arm_smmu_domain *smmu_domain =3D to_smmu_domain_devices(new_domain); unsigned long flags; + int ret; =20 /* * arm_smmu_share_asid() must not see two domains pointing to the same @@ -2841,6 +2895,12 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_s= tate *state, master_domain->nested_ats_flush =3D to_smmu_nested_domain(new_domain)->enable_ats; =20 + if (new_domain->iopf_handler) { + ret =3D arm_smmu_enable_iopf(master, master_domain); + if (ret) + goto err_free_master_domain; + } + /* * During prepare we want the current smmu_domain and new * smmu_domain to be in the devices list before we change any @@ -2860,8 +2920,8 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_st= ate *state, !arm_smmu_master_canwbs(master)) { spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); - kfree(master_domain); - return -EINVAL; + ret =3D -EINVAL; + goto err_iopf; } =20 if (state->ats_enabled) @@ -2880,6 +2940,13 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_s= tate *state, wmb(); } return 0; + +err_iopf: + if (master_domain && master_domain->using_iopf) + arm_smmu_disable_iopf(master); +err_free_master_domain: + kfree(master_domain); + return ret; } =20 /* @@ -3475,8 +3542,7 @@ static void arm_smmu_release_device(struct device *de= v) { struct arm_smmu_master *master =3D dev_iommu_priv_get(dev); =20 - if (WARN_ON(arm_smmu_master_sva_enabled(master))) - iopf_queue_remove_device(master->smmu->evtq.iopf, dev); + WARN_ON(master->iopf_refcount); =20 /* Put the STE back to what arm_smmu_init_strtab() sets */ if (dev->iommu->require_direct) @@ -3561,18 +3627,8 @@ static int arm_smmu_dev_enable_feature(struct device= *dev, =20 switch (feat) { case IOMMU_DEV_FEAT_IOPF: - if (!arm_smmu_master_iopf_supported(master)) - return -EINVAL; - if (master->iopf_enabled) - return -EBUSY; - master->iopf_enabled =3D true; - return 0; case IOMMU_DEV_FEAT_SVA: - if (!arm_smmu_master_sva_supported(master)) - return -EINVAL; - if (arm_smmu_master_sva_enabled(master)) - return -EBUSY; - return arm_smmu_master_enable_sva(master); + return 0; default: return -EINVAL; } @@ -3588,16 +3644,8 @@ static int arm_smmu_dev_disable_feature(struct devic= e *dev, =20 switch (feat) { case IOMMU_DEV_FEAT_IOPF: - if (!master->iopf_enabled) - return -EINVAL; - if (master->sva_enabled) - return -EBUSY; - master->iopf_enabled =3D false; - return 0; case IOMMU_DEV_FEAT_SVA: - if (!arm_smmu_master_sva_enabled(master)) - return -EINVAL; - return arm_smmu_master_disable_sva(master); + return 0; default: return -EINVAL; } diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.h index bd9d7c85576a..5653d7417db7 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -830,9 +830,8 @@ struct arm_smmu_master { bool ats_enabled : 1; bool ste_ats_enabled : 1; bool stall_enabled; - bool sva_enabled; - bool iopf_enabled; unsigned int ssid_bits; + unsigned int iopf_refcount; }; =20 /* SMMU private data for an IOMMU domain */ @@ -910,6 +909,7 @@ struct arm_smmu_master_domain { struct arm_smmu_master *master; ioasid_t ssid; bool nested_ats_flush : 1; + bool using_iopf : 1; }; =20 static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *= dom) @@ -987,11 +987,6 @@ int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_device= *smmu, =20 #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); -bool arm_smmu_master_sva_supported(struct arm_smmu_master *master); -bool arm_smmu_master_sva_enabled(struct arm_smmu_master *master); -int arm_smmu_master_enable_sva(struct arm_smmu_master *master); -int arm_smmu_master_disable_sva(struct arm_smmu_master *master); -bool arm_smmu_master_iopf_supported(struct arm_smmu_master *master); void arm_smmu_sva_notifier_synchronize(void); struct iommu_domain *arm_smmu_sva_domain_alloc(struct device *dev, struct mm_struct *mm); @@ -1001,31 +996,6 @@ static inline bool arm_smmu_sva_supported(struct arm_= smmu_device *smmu) return false; } =20 -static inline bool arm_smmu_master_sva_supported(struct arm_smmu_master *m= aster) -{ - return false; -} - -static inline bool arm_smmu_master_sva_enabled(struct arm_smmu_master *mas= ter) -{ - return false; -} - -static inline int arm_smmu_master_enable_sva(struct arm_smmu_master *maste= r) -{ - return -ENODEV; -} - -static inline int arm_smmu_master_disable_sva(struct arm_smmu_master *mast= er) -{ - return -ENODEV; -} - -static inline bool arm_smmu_master_iopf_supported(struct arm_smmu_master *= master) -{ - return false; -} - static inline void arm_smmu_sva_notifier_synchronize(void) {} =20 #define arm_smmu_sva_domain_alloc NULL --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 458781DE8AF for ; Fri, 14 Feb 2025 06:11:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513468; cv=none; b=pth9JC8kuMMW3H8oujhcTFI/gnGJJerHszYseKZYWGLC6Ru3iI2XWOqOk5yq9IbYfuak0AsB/rCjS2YlsV0+o2419z25CYlnWPA6OfVbtUzwresDXDXouc9LSvz367h2SUwG3/KgyBkHoYh6SfpxBp0s+bjRpeAWV5qadbvp7ZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513468; c=relaxed/simple; bh=IUNYGyLwNXt2mshtCg4MZHI5Zet/iC0sXDLsWw3WF8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rLAmiRh/hwpkg1M/+23omhx5+MPZ/MT34rIKCxhFgqnM9WLijRx4fpQezoV/+VnzztLTFNC2rvRrUr6KvfgDUD/uxT2BK+ksRkC7aRn/UshhaIkWb2gO+fi1rbgN2YokK6cPukEcnzbmmry1d/Jv3pYG+rmEyC0OSVv5yaUE+Rg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=g+eOrLCJ; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="g+eOrLCJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513467; x=1771049467; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IUNYGyLwNXt2mshtCg4MZHI5Zet/iC0sXDLsWw3WF8U=; b=g+eOrLCJQbDtd8XWODdUR+lqJFdwd7qYM9a2pmWSA/IZtieycTuSaqHh lsflIV2Odb2lWgwKfMqCjIgxxFC0QGstX2KWPc15K9cTu7xvB2syltdTS hq+3xbG9v77HRQ1vVZHisTaAfigGjM6AdbQY5W+1CgL0KdXQXYjdJSmH2 M2h+P0uXY5IZSw7VRcQP/j5Pf5S2np9GnESc1QYO0AVvcAPxMu1K12+0B AakgD/cDbmV3fmpyD7T3s6mOK2Nm+/EPCqZ/QlWClHVm+LT9FqzfHb/gl Wub/Pe/JIKLf1rJsQFSzM1FzEHU8gcELm+7WSerJzbiTT+2hTn8wYWr6r w==; X-CSE-ConnectionGUID: QXMQbm0BRraX3sV7XWCIzg== X-CSE-MsgGUID: yQzfmq/pQQ6zh+u0Qkn4lQ== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124487" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124487" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:07 -0800 X-CSE-ConnectionGUID: 6dy07sscTG6imgpwvhdohg== X-CSE-MsgGUID: +qCDbXopTjWjZcPnpExf4A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268076" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:03 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Jason Gunthorpe , Lu Baolu Subject: [PATCH 02/12] iommu/vt-d: Check if SVA is supported when attaching the SVA domain Date: Fri, 14 Feb 2025 14:10:54 +0800 Message-ID: <20250214061104.1959525-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jason Gunthorpe Attach of a SVA domain should fail if SVA is not supported, move the check for SVA support out of IOMMU_DEV_FEAT_SVA and into attach. Also check when allocating a SVA domain to match other drivers. Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 37 +------------------------------ drivers/iommu/intel/svm.c | 43 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index cc46098f875b..a4048de66378 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3851,41 +3851,6 @@ static struct iommu_group *intel_iommu_device_group(= struct device *dev) return generic_device_group(dev); } =20 -static int intel_iommu_enable_sva(struct device *dev) -{ - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - struct intel_iommu *iommu; - - if (!info || dmar_disabled) - return -EINVAL; - - iommu =3D info->iommu; - if (!iommu) - return -EINVAL; - - if (!(iommu->flags & VTD_FLAG_SVM_CAPABLE)) - return -ENODEV; - - if (!info->pasid_enabled || !info->ats_enabled) - return -EINVAL; - - /* - * Devices having device-specific I/O fault handling should not - * support PCI/PRI. The IOMMU side has no means to check the - * capability of device-specific IOPF. Therefore, IOMMU can only - * default that if the device driver enables SVA on a non-PRI - * device, it will handle IOPF in its own way. - */ - if (!info->pri_supported) - return 0; - - /* Devices supporting PRI should have it enabled. */ - if (!info->pri_enabled) - return -EINVAL; - - return 0; -} - static int context_flip_pri(struct device_domain_info *info, bool enable) { struct intel_iommu *iommu =3D info->iommu; @@ -4006,7 +3971,7 @@ intel_iommu_dev_enable_feat(struct device *dev, enum = iommu_dev_features feat) return intel_iommu_enable_iopf(dev); =20 case IOMMU_DEV_FEAT_SVA: - return intel_iommu_enable_sva(dev); + return 0; =20 default: return -ENODEV; diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index f5569347591f..ba93123cb4eb 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -110,6 +110,41 @@ static const struct mmu_notifier_ops intel_mmuops =3D { .free_notifier =3D intel_mm_free_notifier, }; =20 +static int intel_iommu_sva_supported(struct device *dev) +{ + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct intel_iommu *iommu; + + if (!info || dmar_disabled) + return -EINVAL; + + iommu =3D info->iommu; + if (!iommu) + return -EINVAL; + + if (!(iommu->flags & VTD_FLAG_SVM_CAPABLE)) + return -ENODEV; + + if (!info->pasid_enabled || !info->ats_enabled) + return -EINVAL; + + /* + * Devices having device-specific I/O fault handling should not + * support PCI/PRI. The IOMMU side has no means to check the + * capability of device-specific IOPF. Therefore, IOMMU can only + * default that if the device driver enables SVA on a non-PRI + * device, it will handle IOPF in its own way. + */ + if (!info->pri_supported) + return 0; + + /* Devices supporting PRI should have it enabled. */ + if (!info->pri_enabled) + return -EINVAL; + + return 0; +} + static int intel_svm_set_dev_pasid(struct iommu_domain *domain, struct device *dev, ioasid_t pasid, struct iommu_domain *old) @@ -121,6 +156,10 @@ static int intel_svm_set_dev_pasid(struct iommu_domain= *domain, unsigned long sflags; int ret =3D 0; =20 + ret =3D intel_iommu_sva_supported(dev); + if (ret) + return ret; + dev_pasid =3D domain_add_dev_pasid(domain, dev, pasid); if (IS_ERR(dev_pasid)) return PTR_ERR(dev_pasid); @@ -161,6 +200,10 @@ struct iommu_domain *intel_svm_domain_alloc(struct dev= ice *dev, struct dmar_domain *domain; int ret; =20 + ret =3D intel_iommu_sva_supported(dev); + if (ret) + return ERR_PTR(ret); + domain =3D kzalloc(sizeof(*domain), GFP_KERNEL); if (!domain) return ERR_PTR(-ENOMEM); --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D76A81DDA32 for ; Fri, 14 Feb 2025 06:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513472; cv=none; b=c5pZFglG9Z2vURh2X6jvjICSMGCC4W6ohUlVYolQUbuMtYheXq6LYzIbL/s9ZEoIL34QpHllJqEsUy1AYLcwG5aMdJIl6xk94u53O6eXYaZpNAILPYgn7s+0LqPRMlaWD01aMZc43Oh5aLCLXCydNOdp/sxDDz4X0goskWzi09g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513472; c=relaxed/simple; bh=Ae7CCwklY2u5LEf02DzBnSRtB2PBYlj9DOJ8QQ3Rb2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uLQpLmH2i9uoBIc+oN05rJ5txh5xDBp5s1Uj9uF8jbugcsAFj+Lbo5bIofB+xSLq3kAK/8OvaWEqD3gL13ceLD4On0yy+UsuOL4exKISMpNKuqihlTyNT7MpZKmHzx8LN7Ylue2UmkjY170YZM/gZmdcl43hA9e3ES4NQMLruv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=E2kNuEqO; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="E2kNuEqO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513471; x=1771049471; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ae7CCwklY2u5LEf02DzBnSRtB2PBYlj9DOJ8QQ3Rb2A=; b=E2kNuEqORzLe/F9IG9wdDyTPaJI0OjklU3s2BlRJFks/7SaWdDs8bwGK Lk8Vf1JWZB2Xtkb9U2nZky9gRK6lIFzbg1rYIAYg0gWLUFX0W4bNH4A87 hXkRBka9nvo986hHDWIouQ8abkVVvuiRp5FuOekAUMqHZUQnq73weAELj W0O6E/ifYbKjq1QVoVb3PbByK9/+nFAEFANtQOXXi+cqPiagWX3N8C7Dc aOi8uKo7cbGCU9tC66i5IhR6pOJLEXP4MueDHyZW7v9vq0tLxL3wyI+zt wFrlgh35cV7z49cGQKiisIyhnIz11Nhj5oRKtMl7U4MhfabGwRo8mCigs w==; X-CSE-ConnectionGUID: 3RBovnRyTlaeoqcvC+DsJg== X-CSE-MsgGUID: STJqhHcNQ+qG6Bf3BK3MgA== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124496" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124496" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:11 -0800 X-CSE-ConnectionGUID: EKoubrT0R5OJcCKse+6KVA== X-CSE-MsgGUID: ATOI6KNXSyKTaAUUlsf+6A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268092" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:07 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Jason Gunthorpe , Lu Baolu Subject: [PATCH 03/12] iommu: Remove IOMMU_DEV_FEAT_SVA Date: Fri, 14 Feb 2025 14:10:55 +0800 Message-ID: <20250214061104.1959525-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jason Gunthorpe None of the drivers implement anything here anymore, remove the dead code. Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- drivers/accel/amdxdna/aie2_pci.c | 13 ++----------- drivers/dma/idxd/init.c | 8 +------- drivers/iommu/amd/iommu.c | 2 -- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 -- drivers/iommu/intel/iommu.c | 6 ------ drivers/iommu/iommu-sva.c | 3 --- drivers/misc/uacce/uacce.c | 9 --------- include/linux/iommu.h | 9 +-------- 8 files changed, 4 insertions(+), 48 deletions(-) diff --git a/drivers/accel/amdxdna/aie2_pci.c b/drivers/accel/amdxdna/aie2_= pci.c index 5a058e565b01..c6cf7068d23c 100644 --- a/drivers/accel/amdxdna/aie2_pci.c +++ b/drivers/accel/amdxdna/aie2_pci.c @@ -512,12 +512,6 @@ static int aie2_init(struct amdxdna_dev *xdna) goto release_fw; } =20 - ret =3D iommu_dev_enable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); - if (ret) { - XDNA_ERR(xdna, "Enable PASID failed, ret %d", ret); - goto free_irq; - } - psp_conf.fw_size =3D fw->size; psp_conf.fw_buf =3D fw->data; for (i =3D 0; i < PSP_MAX_REGS; i++) @@ -526,14 +520,14 @@ static int aie2_init(struct amdxdna_dev *xdna) if (!ndev->psp_hdl) { XDNA_ERR(xdna, "failed to create psp"); ret =3D -ENOMEM; - goto disable_sva; + goto free_irq; } xdna->dev_handle =3D ndev; =20 ret =3D aie2_hw_start(xdna); if (ret) { XDNA_ERR(xdna, "start npu failed, ret %d", ret); - goto disable_sva; + goto free_irq; } =20 ret =3D aie2_mgmt_fw_query(ndev); @@ -584,8 +578,6 @@ static int aie2_init(struct amdxdna_dev *xdna) aie2_error_async_events_free(ndev); stop_hw: aie2_hw_stop(xdna); -disable_sva: - iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); free_irq: pci_free_irq_vectors(pdev); release_fw: @@ -601,7 +593,6 @@ static void aie2_fini(struct amdxdna_dev *xdna) =20 aie2_hw_stop(xdna); aie2_error_async_events_free(ndev); - iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); pci_free_irq_vectors(pdev); } =20 diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index b946f78f85e1..1e5038cca22c 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -633,17 +633,11 @@ static int idxd_enable_sva(struct pci_dev *pdev) ret =3D iommu_dev_enable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF); if (ret) return ret; - - ret =3D iommu_dev_enable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); - if (ret) - iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF); - - return ret; + return 0; } =20 static void idxd_disable_sva(struct pci_dev *pdev) { - iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_SVA); iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF); } =20 diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index b48a72bd7b23..e3653bdfcd7d 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2990,7 +2990,6 @@ static int amd_iommu_dev_enable_feature(struct device= *dev, =20 switch (feat) { case IOMMU_DEV_FEAT_IOPF: - case IOMMU_DEV_FEAT_SVA: break; default: ret =3D -EINVAL; @@ -3006,7 +3005,6 @@ static int amd_iommu_dev_disable_feature(struct devic= e *dev, =20 switch (feat) { case IOMMU_DEV_FEAT_IOPF: - case IOMMU_DEV_FEAT_SVA: break; default: ret =3D -EINVAL; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index 75b2f7c609ca..ee945a9db641 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3627,7 +3627,6 @@ static int arm_smmu_dev_enable_feature(struct device = *dev, =20 switch (feat) { case IOMMU_DEV_FEAT_IOPF: - case IOMMU_DEV_FEAT_SVA: return 0; default: return -EINVAL; @@ -3644,7 +3643,6 @@ static int arm_smmu_dev_disable_feature(struct device= *dev, =20 switch (feat) { case IOMMU_DEV_FEAT_IOPF: - case IOMMU_DEV_FEAT_SVA: return 0; default: return -EINVAL; diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index a4048de66378..16dd8f0de76d 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3970,9 +3970,6 @@ intel_iommu_dev_enable_feat(struct device *dev, enum = iommu_dev_features feat) case IOMMU_DEV_FEAT_IOPF: return intel_iommu_enable_iopf(dev); =20 - case IOMMU_DEV_FEAT_SVA: - return 0; - default: return -ENODEV; } @@ -3985,9 +3982,6 @@ intel_iommu_dev_disable_feat(struct device *dev, enum= iommu_dev_features feat) case IOMMU_DEV_FEAT_IOPF: return intel_iommu_disable_iopf(dev); =20 - case IOMMU_DEV_FEAT_SVA: - return 0; - default: return -ENODEV; } diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 503c5d23c1ea..331be2761a75 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -63,9 +63,6 @@ static struct iommu_mm_data *iommu_alloc_mm_data(struct m= m_struct *mm, struct de * reference is taken. Caller must call iommu_sva_unbind_device() * to release each reference. * - * iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_SVA) must be called first,= to - * initialize the required SVA features. - * * On error, returns an ERR_PTR value. */ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_stru= ct *mm) diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index bdc2e6fda782..2a1db2abeeca 100644 --- a/drivers/misc/uacce/uacce.c +++ b/drivers/misc/uacce/uacce.c @@ -479,14 +479,6 @@ static unsigned int uacce_enable_sva(struct device *pa= rent, unsigned int flags) dev_err(parent, "failed to enable IOPF feature! ret =3D %pe\n", ERR_PTR(= ret)); return flags; } - - ret =3D iommu_dev_enable_feature(parent, IOMMU_DEV_FEAT_SVA); - if (ret) { - dev_err(parent, "failed to enable SVA feature! ret =3D %pe\n", ERR_PTR(r= et)); - iommu_dev_disable_feature(parent, IOMMU_DEV_FEAT_IOPF); - return flags; - } - return flags | UACCE_DEV_SVA; } =20 @@ -495,7 +487,6 @@ static void uacce_disable_sva(struct uacce_device *uacc= e) if (!(uacce->flags & UACCE_DEV_SVA)) return; =20 - iommu_dev_disable_feature(uacce->parent, IOMMU_DEV_FEAT_SVA); iommu_dev_disable_feature(uacce->parent, IOMMU_DEV_FEAT_IOPF); } =20 diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 38c65e92ecd0..1d0dde49168d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -303,18 +303,11 @@ struct iommu_iort_rmr_data { =20 /** * enum iommu_dev_features - Per device IOMMU features - * @IOMMU_DEV_FEAT_SVA: Shared Virtual Addresses - * @IOMMU_DEV_FEAT_IOPF: I/O Page Faults such as PRI or Stall. Generally - * enabling %IOMMU_DEV_FEAT_SVA requires - * %IOMMU_DEV_FEAT_IOPF, but some devices manage I/O Page - * Faults themselves instead of relying on the IOMMU. When - * supported, this feature must be enabled before and - * disabled after %IOMMU_DEV_FEAT_SVA. + * @IOMMU_DEV_FEAT_IOPF: I/O Page Faults such as PRI or Stall. * * Device drivers enable a feature using iommu_dev_enable_feature(). */ enum iommu_dev_features { - IOMMU_DEV_FEAT_SVA, IOMMU_DEV_FEAT_IOPF, }; =20 --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 356A31FC7C1 for ; Fri, 14 Feb 2025 06:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513475; cv=none; b=ZhmmovzsqQ687SyPYt9/r5/VI7VZ0bYtq91Xa78evA6X6edmyz8Z6dejhlyeRydWUOlBS3XsLggV5KbdwqQvqAOEsplaMvam0DcGhAQVQeZ0qsS5m/iT6wHTCrT5i2dSpf89gNkP8igPqZngcC5YbHs1dYY0fIL7bUx2uVu8Ubg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513475; c=relaxed/simple; bh=+tLnVPAC1yQLSjyQ6Ddtkoj6n74XKHutEDN5LFTmZpc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iutc1wnMh4D54kST+N5SVhVIJw1aFx/W3biGF3N2Np9T+ifxCg7KWbLc0jXeWZUiXxIIZxCK6tdlHAEF9qAhDjGvrczP39JQ6iEzmgV7uOWs5IIDl2/iM93Ejv2Ok8PkvjnIoeKeRw3LAc75gtFlRu19cHTnnRVCe6DHRb6K9d4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=cwqrVgIG; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="cwqrVgIG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513474; x=1771049474; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+tLnVPAC1yQLSjyQ6Ddtkoj6n74XKHutEDN5LFTmZpc=; b=cwqrVgIGXrkHT0kTLgWh+boOl4MJipXY+ef1Jl4LwZsGDpTBwxfmICIF OTvCahCUg8zS7uCChT0ILVP/ZwYIJRa7ztXJdm3ohFZEHoT1glz+PXSJ0 WclK+ekDag5BFe3gfc9YcGCComWnmAvy/Xg+petgvuBeKwqxJQHxtvFQg xiGKU7RLQq7tcSKR0MiWWEiFOo/tGJ/tpByvCBDb0bDRT8Sf6c0jnoX8J ToNYG0D9kKIyIZQ3QHZOITw5nAvaEo8S6q3J/IZ6a6iyl+hUamt01jdLf D7Y40nIUZ4pfjhCEY4FqyVLD3RXs6xGQfFL3b217zFIsQ63pvou+WpnqP w==; X-CSE-ConnectionGUID: qGbZZ8qxSkS2jymHIpYB8w== X-CSE-MsgGUID: WFImuNOESvKItFqD2MVLQQ== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124506" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124506" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:14 -0800 X-CSE-ConnectionGUID: vKsfK4teSHK2nqsV3KpT1g== X-CSE-MsgGUID: tj9/Y4ZdSa+0alSzzxWEXQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268103" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:11 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 04/12] iommu/vt-d: Move scalable mode ATS enablement to probe path Date: Fri, 14 Feb 2025 14:10:56 +0800 Message-ID: <20250214061104.1959525-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Device ATS is currently enabled when a domain is attached to the device and disabled when the domain is detached. This creates a limitation: when the IOMMU is operating in scalable mode and IOPF is enabled, the device's domain cannot be changed. Remove this limitation by moving ATS enablement to the device probe path. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 78 ++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 16dd8f0de76d..f52602bde742 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1172,34 +1172,6 @@ static bool dev_needs_extra_dtlb_flush(struct pci_de= v *pdev) return true; } =20 -static void iommu_enable_pci_caps(struct device_domain_info *info) -{ - struct pci_dev *pdev; - - if (!dev_is_pci(info->dev)) - return; - - pdev =3D to_pci_dev(info->dev); - if (info->ats_supported && pci_ats_page_aligned(pdev) && - !pci_enable_ats(pdev, VTD_PAGE_SHIFT)) - info->ats_enabled =3D 1; -} - -static void iommu_disable_pci_caps(struct device_domain_info *info) -{ - struct pci_dev *pdev; - - if (!dev_is_pci(info->dev)) - return; - - pdev =3D to_pci_dev(info->dev); - - if (info->ats_enabled) { - pci_disable_ats(pdev); - info->ats_enabled =3D 0; - } -} - static void intel_flush_iotlb_all(struct iommu_domain *domain) { cache_tag_flush_all(to_dmar_domain(domain)); @@ -1556,12 +1528,22 @@ domain_context_mapping(struct dmar_domain *domain, = struct device *dev) struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu =3D info->iommu; u8 bus =3D info->bus, devfn =3D info->devfn; + struct pci_dev *pdev; + int ret; =20 if (!dev_is_pci(dev)) return domain_context_mapping_one(domain, iommu, bus, devfn); =20 - return pci_for_each_dma_alias(to_pci_dev(dev), - domain_context_mapping_cb, domain); + pdev =3D to_pci_dev(dev); + ret =3D pci_for_each_dma_alias(pdev, domain_context_mapping_cb, domain); + if (ret) + return ret; + + if (info->ats_supported && pci_ats_page_aligned(pdev) && + !pci_enable_ats(pdev, VTD_PAGE_SHIFT)) + info->ats_enabled =3D 1; + + return 0; } =20 /* Return largest possible superpage level for a given mapping */ @@ -1843,8 +1825,6 @@ static int dmar_domain_attach_device(struct dmar_doma= in *domain, if (ret) goto out_block_translation; =20 - iommu_enable_pci_caps(info); - ret =3D cache_tag_assign_domain(domain, dev, IOMMU_NO_PASID); if (ret) goto out_block_translation; @@ -3191,13 +3171,20 @@ static int domain_context_clear_one_cb(struct pci_d= ev *pdev, u16 alias, void *op */ static void domain_context_clear(struct device_domain_info *info) { + struct pci_dev *pdev; + if (!dev_is_pci(info->dev)) { domain_context_clear_one(info, info->bus, info->devfn); return; } =20 - pci_for_each_dma_alias(to_pci_dev(info->dev), - &domain_context_clear_one_cb, info); + pdev =3D to_pci_dev(info->dev); + pci_for_each_dma_alias(pdev, &domain_context_clear_one_cb, info); + + if (info->ats_enabled) { + pci_disable_ats(pdev); + info->ats_enabled =3D 0; + } } =20 /* @@ -3214,7 +3201,6 @@ void device_block_translation(struct device *dev) if (info->domain) cache_tag_unassign_domain(info->domain, dev, IOMMU_NO_PASID); =20 - iommu_disable_pci_caps(info); if (!dev_is_real_dma_subdevice(dev)) { if (sm_supported(iommu)) intel_pasid_tear_down_entry(iommu, dev, @@ -3749,6 +3735,16 @@ static struct iommu_device *intel_iommu_probe_device= (struct device *dev) !pci_enable_pasid(pdev, info->pasid_supported & ~1)) info->pasid_enabled =3D 1; =20 + if (sm_supported(iommu)) { + if (info->ats_supported && pci_ats_page_aligned(pdev)) { + ret =3D pci_enable_ats(pdev, VTD_PAGE_SHIFT); + if (ret) + pci_info(pdev, "Failed to enable ATS on device\n"); + else + info->ats_enabled =3D 1; + } + } + return &iommu->iommu; free_table: intel_pasid_free_table(dev); @@ -3765,6 +3761,11 @@ static void intel_iommu_release_device(struct device= *dev) struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu =3D info->iommu; =20 + if (info->ats_enabled) { + pci_disable_ats(to_pci_dev(dev)); + info->ats_enabled =3D 0; + } + if (info->pasid_enabled) { pci_disable_pasid(to_pci_dev(dev)); info->pasid_enabled =3D 0; @@ -4365,13 +4366,10 @@ static int identity_domain_attach_dev(struct iommu_= domain *domain, struct device if (dev_is_real_dma_subdevice(dev)) return 0; =20 - if (sm_supported(iommu)) { + if (sm_supported(iommu)) ret =3D intel_pasid_setup_pass_through(iommu, dev, IOMMU_NO_PASID); - if (!ret) - iommu_enable_pci_caps(info); - } else { + else ret =3D device_setup_pass_through(dev); - } =20 return ret; } --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B09391FC7EE for ; Fri, 14 Feb 2025 06:11:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513479; cv=none; b=X5Knp/p4w0TjnD827jvgyfpiaHFbIjiYqvHHJqgc+DACFocKK2G+PWYVZzsO19cYcI9KlG/g6iycr7CrLLRtIvH/jDYXuYfHjYjo4hwW/qls7t1QCOx7D7UseIS4VJH7qfV1AZLQ2pIe+6LjhnrAYKTOVXi/sfdRrqbTUy2R6X8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513479; c=relaxed/simple; bh=GOZqyliaqlfKT5b1FsGeKsIwtb6yo0npf3cr3VU+cTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fmk/U/1E7QxAlyz3xequFG6OWGW/LFChCoibaMIK2MEGJfFCbFCfw5r3ZeDJ1rMzSdArtrLIRXwZi5x8WN8zVMMEHpDfeVeL6raK7P/Q1Aa27ZqobR42vz2GO0FHP1kA5uVpInCGt/J2dXILrJsV77cmKrsEo4pEKQqXqfexF6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=X8PMvOFL; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="X8PMvOFL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513478; x=1771049478; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GOZqyliaqlfKT5b1FsGeKsIwtb6yo0npf3cr3VU+cTU=; b=X8PMvOFLK+21zFzG6LV76w/ibk6ImAwkkfwULwv6DO4ErH2kEkomx6q1 ywyYbgupV2q1tW4q/ZEaNDC1b0rILGBoGTet1ihag6Pg+OWPlkZoN4VXJ K5i7eSXS/Kyyn8eKZfs+nVHeyAWqknJVpx2honrKYGhM+mJQ/8wbVoE8n 7aKPNJ48NCxeOaXJS/ep05wtRqgPEcs+rplyEUSUY6n7eTXnmLgK88Sqs gYOCYy2XKqSlUcxDcgm1hpSWG0/X38DMAWE71l4iluEDzZXyWkargAhWB tvjcnjl4OfNxOPWY9awxw/kvjBHZ9qyE9yqDgRgd/kP9x9IhCiLUzVPQB Q==; X-CSE-ConnectionGUID: enBisy1BTkus3AYRXnwWjA== X-CSE-MsgGUID: 3iFhbR2qSASx16ssSmPXxg== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124522" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124522" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:17 -0800 X-CSE-ConnectionGUID: X7qgak+ST9eYdT8PIWkv4w== X-CSE-MsgGUID: hJ/YtUldQgq7m4PHJQH2eQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268110" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:14 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 05/12] iommu/vt-d: Move PRI enablement in probe path Date: Fri, 14 Feb 2025 14:10:57 +0800 Message-ID: <20250214061104.1959525-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update PRI enablement to use the new method, similar to the amd iommu driver. Enable PRI in the device probe path and disable it when the device is released. PRI is enabled throughout the device's iommu lifecycle. The infrastructure for the iommu subsystem to handle iopf requests is created during iopf enablement and released during iopf disablement. All invalid page requests from the device are automatically handled by the iommu subsystem if iopf is not enabled. Add iopf_refcount to track the iopf enablement. Convert the return type of intel_iommu_disable_iopf() to void, as there is no way to handle a failure when disabling this feature. Make intel_iommu_enable/disable_iopf() helpers global, as they will be used beyond the current file in the subsequent patch. The iopf_refcount is not protected by any lock. This is acceptable, as there is no concurrent access to it in the current code. The following patch will address this by moving it to the domain attach/detach paths, which are protected by the iommu group mutex. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 145 +++++++++++------------------------- drivers/iommu/intel/iommu.h | 4 + drivers/iommu/intel/pasid.c | 2 + drivers/iommu/intel/prq.c | 2 +- 4 files changed, 51 insertions(+), 102 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f52602bde742..91d49e2cea34 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3743,6 +3743,16 @@ static struct iommu_device *intel_iommu_probe_device= (struct device *dev) else info->ats_enabled =3D 1; } + + if (info->ats_enabled && info->pri_supported) { + /* PASID is required in PRG Response Message. */ + if (info->pasid_enabled || !pci_prg_resp_pasid_required(pdev)) { + if (!pci_reset_pri(pdev) && !pci_enable_pri(pdev, PRQ_DEPTH)) + info->pri_enabled =3D 1; + else + pci_info(pdev, "Failed to enable PRI on device\n"); + } + } } =20 return &iommu->iommu; @@ -3761,6 +3771,13 @@ static void intel_iommu_release_device(struct device= *dev) struct device_domain_info *info =3D dev_iommu_priv_get(dev); struct intel_iommu *iommu =3D info->iommu; =20 + WARN_ON(info->iopf_refcount); + + if (info->pri_enabled) { + pci_disable_pri(to_pci_dev(dev)); + info->pri_enabled =3D 0; + } + if (info->ats_enabled) { pci_disable_ats(to_pci_dev(dev)); info->ats_enabled =3D 0; @@ -3852,118 +3869,43 @@ static struct iommu_group *intel_iommu_device_grou= p(struct device *dev) return generic_device_group(dev); } =20 -static int context_flip_pri(struct device_domain_info *info, bool enable) +int intel_iommu_enable_iopf(struct device *dev) { - struct intel_iommu *iommu =3D info->iommu; - u8 bus =3D info->bus, devfn =3D info->devfn; - struct context_entry *context; - u16 did; - - spin_lock(&iommu->lock); - if (context_copied(iommu, bus, devfn)) { - spin_unlock(&iommu->lock); - return -EINVAL; - } - - context =3D iommu_context_addr(iommu, bus, devfn, false); - if (!context || !context_present(context)) { - spin_unlock(&iommu->lock); - return -ENODEV; - } - did =3D context_domain_id(context); - - if (enable) - context_set_sm_pre(context); - else - context_clear_sm_pre(context); - - if (!ecap_coherent(iommu->ecap)) - clflush_cache_range(context, sizeof(*context)); - intel_context_flush_present(info, context, did, true); - spin_unlock(&iommu->lock); - - return 0; -} - -static int intel_iommu_enable_iopf(struct device *dev) -{ - struct pci_dev *pdev =3D dev_is_pci(dev) ? to_pci_dev(dev) : NULL; struct device_domain_info *info =3D dev_iommu_priv_get(dev); - struct intel_iommu *iommu; + struct intel_iommu *iommu =3D info->iommu; int ret; =20 - if (!pdev || !info || !info->ats_enabled || !info->pri_supported) - return -ENODEV; - - if (info->pri_enabled) - return -EBUSY; - - iommu =3D info->iommu; - if (!iommu) - return -EINVAL; - - /* PASID is required in PRG Response Message. */ - if (info->pasid_enabled && !pci_prg_resp_pasid_required(pdev)) - return -EINVAL; - - ret =3D pci_reset_pri(pdev); - if (ret) - return ret; - - ret =3D iopf_queue_add_device(iommu->iopf_queue, dev); - if (ret) - return ret; - - ret =3D context_flip_pri(info, true); - if (ret) - goto err_remove_device; - - ret =3D pci_enable_pri(pdev, PRQ_DEPTH); - if (ret) - goto err_clear_pri; - - info->pri_enabled =3D 1; - - return 0; -err_clear_pri: - context_flip_pri(info, false); -err_remove_device: - iopf_queue_remove_device(iommu->iopf_queue, dev); - - return ret; -} - -static int intel_iommu_disable_iopf(struct device *dev) -{ - struct device_domain_info *info =3D dev_iommu_priv_get(dev); - struct intel_iommu *iommu =3D info->iommu; - if (!info->pri_enabled) - return -EINVAL; + return -ENODEV; =20 - /* Disable new PRI reception: */ - context_flip_pri(info, false); + if (info->iopf_refcount) { + info->iopf_refcount++; + return 0; + } =20 - /* - * Remove device from fault queue and acknowledge all outstanding - * PRQs to the device: - */ - iopf_queue_remove_device(iommu->iopf_queue, dev); + ret =3D iopf_queue_add_device(iommu->iopf_queue, dev); + if (ret) + return ret; =20 - /* - * PCIe spec states that by clearing PRI enable bit, the Page - * Request Interface will not issue new page requests, but has - * outstanding page requests that have been transmitted or are - * queued for transmission. This is supposed to be called after - * the device driver has stopped DMA, all PASIDs have been - * unbound and the outstanding PRQs have been drained. - */ - pci_disable_pri(to_pci_dev(dev)); - info->pri_enabled =3D 0; + info->iopf_refcount =3D 1; =20 return 0; } =20 +void intel_iommu_disable_iopf(struct device *dev) +{ + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + struct intel_iommu *iommu =3D info->iommu; + + if (WARN_ON(!info->pri_enabled)) + return; + + if (--info->iopf_refcount) + return; + + iopf_queue_remove_device(iommu->iopf_queue, dev); +} + static int intel_iommu_dev_enable_feat(struct device *dev, enum iommu_dev_features fe= at) { @@ -3981,7 +3923,8 @@ intel_iommu_dev_disable_feat(struct device *dev, enum= iommu_dev_features feat) { switch (feat) { case IOMMU_DEV_FEAT_IOPF: - return intel_iommu_disable_iopf(dev); + intel_iommu_disable_iopf(dev); + return 0; =20 default: return -ENODEV; diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 6ea7bbe26b19..f7d78cf0778c 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -774,6 +774,7 @@ struct device_domain_info { u8 ats_enabled:1; u8 dtlb_extra_inval:1; /* Quirk for devices need extra flush */ u8 ats_qdep; + unsigned int iopf_refcount; struct device *dev; /* it's NULL for PCIe-to-PCI bridge */ struct intel_iommu *iommu; /* IOMMU used by this device */ struct dmar_domain *domain; /* pointer to domain */ @@ -1314,6 +1315,9 @@ void intel_iommu_page_response(struct device *dev, st= ruct iopf_fault *evt, struct iommu_page_response *msg); void intel_iommu_drain_pasid_prq(struct device *dev, u32 pasid); =20 +int intel_iommu_enable_iopf(struct device *dev); +void intel_iommu_disable_iopf(struct device *dev); + #ifdef CONFIG_INTEL_IOMMU_SVM void intel_svm_check(struct intel_iommu *iommu); struct iommu_domain *intel_svm_domain_alloc(struct device *dev, diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index fb59a7d35958..c2742e256552 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -992,6 +992,8 @@ static int context_entry_set_pasid_table(struct context= _entry *context, context_set_sm_dte(context); if (info->pasid_supported) context_set_pasid(context); + if (info->pri_supported) + context_set_sm_pre(context); =20 context_set_fault_enable(context); context_set_present(context); diff --git a/drivers/iommu/intel/prq.c b/drivers/iommu/intel/prq.c index c2d792db52c3..2bdaf9293ab4 100644 --- a/drivers/iommu/intel/prq.c +++ b/drivers/iommu/intel/prq.c @@ -67,7 +67,7 @@ void intel_iommu_drain_pasid_prq(struct device *dev, u32 = pasid) u16 sid, did; =20 info =3D dev_iommu_priv_get(dev); - if (!info->pri_enabled) + if (!info->iopf_refcount) return; =20 iommu =3D info->iommu; --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 203FE1FCCF1 for ; Fri, 14 Feb 2025 06:11:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513482; cv=none; b=OGYBZMBPrqtHfMdJZH1AZjKw8s+Gdla2c51FMYrTf0IfJxzYVI3NuVrjbhIby/XM3hMnKlPTF7mBKysORMF/johkwEXJ0ZjHEWtPvhvXd+wgTChRVyYQyqV/vh0qY4YWKefHGuvw7Y58o/WIjmHEsgTXsJ0eBBJiK7n8LLBMjRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513482; c=relaxed/simple; bh=7BqROg7flfKZSHF40dyhcy1MLUmAqDfo6NpaN5vQ7/A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q6k/D2T/0uOFD9MU6emyKQo8f+nn/CydrT08ph91VT5SJpx5oRquaI7eNJoDOXht368o6S2gjdjHACfnIjgUhhIa+TC8R2lt6JU5632n5cJByfbROKNdrN5hQveOhr4lNYK4YxYkyMxJxomhbvmh8l+nvMctl+lIsfkk6M+J4Gc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HVmc11d0; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HVmc11d0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513481; x=1771049481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7BqROg7flfKZSHF40dyhcy1MLUmAqDfo6NpaN5vQ7/A=; b=HVmc11d02GO7JrNcSJcR6a+lgPjDmyZBjTnPdwWNyQofpD7gLZrN1Ku1 z26gujQ1zU4cUBgNoye8NaQkzxKSEas/4bax81R7f/TdTKhcVo8wR0UCR tRknT8VeITDeHIThf7YAKnjIu4SNxuFckJ0KE1wtYboREhQrZb9E8Ei4c Ev1yI8l8hBdHxtmkcTfs/msBZwKVkHM9cErPdrBPWTDYbci7aGaUVbP05 a8ZEBts/xDAhP6NthujP8TvrB+3El3GiogtYB0C1fzyE/j2slTk6UrGrr 5YJV9MKldq74GkBBiLV/uUE3CHJkwxlNJ6LAAnYLYwyWUhnrrCXQ+bZNP A==; X-CSE-ConnectionGUID: fXU1LsNJRk+BXRud3DJyug== X-CSE-MsgGUID: iwUlI9xPQtO7J4djDKONCg== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124540" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124540" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:21 -0800 X-CSE-ConnectionGUID: hSuWg8klTF+8fEuDyydc0Q== X-CSE-MsgGUID: 4Z/ib09KQYCj29HP7sNq+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268126" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:18 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 06/12] iommu/vt-d: Cleanup intel_context_flush_present() Date: Fri, 14 Feb 2025 14:10:58 +0800 Message-ID: <20250214061104.1959525-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The intel_context_flush_present() is called in places where either the scalable mode is disabled, or scalable mode is enabled but all PASID entries are known to be non-present. In these cases, the flush_domains path within intel_context_flush_present() will never execute. This dead code is therefore removed. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 2 +- drivers/iommu/intel/iommu.h | 3 +-- drivers/iommu/intel/pasid.c | 39 ++++++------------------------------- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 91d49e2cea34..1d564240c977 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -1730,7 +1730,7 @@ static void domain_context_clear_one(struct device_do= main_info *info, u8 bus, u8 context_clear_entry(context); __iommu_flush_cache(iommu, context, sizeof(*context)); spin_unlock(&iommu->lock); - intel_context_flush_present(info, context, did, true); + intel_context_flush_present(info, context, did); } =20 int __domain_setup_first_level(struct intel_iommu *iommu, diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index f7d78cf0778c..754f6d7ade26 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1306,8 +1306,7 @@ void cache_tag_flush_range_np(struct dmar_domain *dom= ain, unsigned long start, unsigned long end); =20 void intel_context_flush_present(struct device_domain_info *info, - struct context_entry *context, - u16 did, bool affect_domains); + struct context_entry *context, u16 did); =20 int intel_iommu_enable_prq(struct intel_iommu *iommu); int intel_iommu_finish_prq(struct intel_iommu *iommu); diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index c2742e256552..a2c6be624dbf 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -932,7 +932,7 @@ static void device_pasid_table_teardown(struct device *= dev, u8 bus, u8 devfn) context_clear_entry(context); __iommu_flush_cache(iommu, context, sizeof(*context)); spin_unlock(&iommu->lock); - intel_context_flush_present(info, context, did, false); + intel_context_flush_present(info, context, did); } =20 static int pci_pasid_table_teardown(struct pci_dev *pdev, u16 alias, void = *data) @@ -1119,17 +1119,15 @@ static void __context_flush_dev_iotlb(struct device= _domain_info *info) =20 /* * Cache invalidations after change in a context table entry that was pres= ent - * according to the Spec 6.5.3.3 (Guidance to Software for Invalidations).= If - * IOMMU is in scalable mode and all PASID table entries of the device were - * non-present, set flush_domains to false. Otherwise, true. + * according to the Spec 6.5.3.3 (Guidance to Software for Invalidations). + * This helper can only be used when IOMMU is working in the legacy mode or + * IOMMU is in scalable mode but all PASID table entries of the device are + * non-present. */ void intel_context_flush_present(struct device_domain_info *info, - struct context_entry *context, - u16 did, bool flush_domains) + struct context_entry *context, u16 did) { struct intel_iommu *iommu =3D info->iommu; - struct pasid_entry *pte; - int i; =20 /* * Device-selective context-cache invalidation. The Domain-ID field @@ -1152,30 +1150,5 @@ void intel_context_flush_present(struct device_domai= n_info *info, return; } =20 - /* - * For scalable mode: - * - Domain-selective PASID-cache invalidation to affected domains - * - Domain-selective IOTLB invalidation to affected domains - * - Global Device-TLB invalidation to affected functions - */ - if (flush_domains) { - /* - * If the IOMMU is running in scalable mode and there might - * be potential PASID translations, the caller should hold - * the lock to ensure that context changes and cache flushes - * are atomic. - */ - assert_spin_locked(&iommu->lock); - for (i =3D 0; i < info->pasid_table->max_pasid; i++) { - pte =3D intel_pasid_get_entry(info->dev, i); - if (!pte || !pasid_pte_is_present(pte)) - continue; - - did =3D pasid_get_domain_id(pte); - qi_flush_pasid_cache(iommu, did, QI_PC_ALL_PASIDS, 0); - iommu->flush.flush_iotlb(iommu, did, 0, 0, DMA_TLB_DSI_FLUSH); - } - } - __context_flush_dev_iotlb(info); } --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AD2B1FCF57 for ; Fri, 14 Feb 2025 06:11:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513486; cv=none; b=JiXKO4RMgQ+PGhwrVZRfby0ELkMFNvTEKfb29v4+i3Bf78Po2YKH8+DqIcVoblIYL3X/s0xwOQebC6drk8L+pkXeF58UC8iHUj8PyA3dt12K3caczI0HVuJH65lDWAz9GmfVO61YzhQklaAsTEH+TLjVfDkmxYI+1Yy20Ecjbf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513486; c=relaxed/simple; bh=WH8Sh6k+wR2mFocNNDMzXcNLMpGaPtVWIrSa7fLjAfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jJFtb5ws85davV82fX/+DraiNdxpjtJktEGBqUNwNgJyQUvMEeyuBuWJ0gx8ijGGZdETAsPB1R1XPDhxF1RNjIbufpMMgYeIyx69pXUP4XhDV6MR8vvHsi2sBMgQN0GCtBBtht/Q47rdSJPAaIe4VAGnVubVhxLYfN3i7UgeMQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dFeMWhn0; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dFeMWhn0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513485; x=1771049485; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WH8Sh6k+wR2mFocNNDMzXcNLMpGaPtVWIrSa7fLjAfM=; b=dFeMWhn01idOIj1WtqGtj3yJicRRuGMycLtvQiC6pOkzmiwNY9AAW8nU P6pleMENgdSmC1x/QBvxnVaVkz+t24If8PLHAjobJLZWApiosPQx/+Vuz D+vTclHQobdU2/0IdNlg0dfPd3dbywN8L6vPqShbEmDlFblU+/3amQsiB kcxZkI0pUg3gSzMxSxAe0OVoj2Ots7m5qqpOEcQ1LRuMTdCpMMpsImyNj FX8Wyezkq0LfJzpgbolw4jG0LkmUFCSWTUCohF5UJ5PhTlWpWoTZSP6p+ CyHJ+jYOfGI4TMc2FAxpGWAdqZSIl82UQgQyZMA5Es2lBjrnM32hFF7gK g==; X-CSE-ConnectionGUID: kcUfn6hRShSZ/ojIko7ZMQ== X-CSE-MsgGUID: yFq0Pw3JTiSMfbCcXXmo3A== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124557" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124557" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:24 -0800 X-CSE-ConnectionGUID: NlaYAP5MQpKSsOEjJmhnQQ== X-CSE-MsgGUID: YHAeWMmNRYOsCLlsCAxhhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268136" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:21 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 07/12] iommu/vt-d: Put iopf enablement in domain attach path Date: Fri, 14 Feb 2025 14:10:59 +0800 Message-ID: <20250214061104.1959525-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update iopf enablement in the driver to use the new method, similar to the arm-smmu-v3 driver. Enable iopf support when any domain with an iopf_handler is attached, and disable it when the domain is removed. Place all the logic for controlling the PRI and iopf queue in the domain set/remove/replace paths. Keep track of the number of domains set to the device and PASIDs that require iopf. When the first domain requiring iopf is attached, add the device to the iopf queue and enable PRI. When the last domain is removed, remove it from the iopf queue and disable PRI. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 42 ++++++++++++++++++++++++++++++----- drivers/iommu/intel/iommu.h | 43 ++++++++++++++++++++++++++++++++++++ drivers/iommu/intel/nested.c | 16 ++++++++++++-- drivers/iommu/intel/svm.c | 9 ++++++-- 4 files changed, 100 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 1d564240c977..20d07f5fea85 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3223,6 +3223,9 @@ void device_block_translation(struct device *dev) static int blocking_domain_attach_dev(struct iommu_domain *domain, struct device *dev) { + struct device_domain_info *info =3D dev_iommu_priv_get(dev); + + iopf_for_domain_remove(info->domain ? &info->domain->domain : NULL, dev); device_block_translation(dev); return 0; } @@ -3432,7 +3435,15 @@ static int intel_iommu_attach_device(struct iommu_do= main *domain, if (ret) return ret; =20 - return dmar_domain_attach_device(to_dmar_domain(domain), dev); + ret =3D iopf_for_domain_set(domain, dev); + if (ret) + return ret; + + ret =3D dmar_domain_attach_device(to_dmar_domain(domain), dev); + if (ret) + iopf_for_domain_remove(domain, dev); + + return ret; } =20 static int intel_iommu_map(struct iommu_domain *domain, @@ -3878,6 +3889,8 @@ int intel_iommu_enable_iopf(struct device *dev) if (!info->pri_enabled) return -ENODEV; =20 + /* pri_enabled is protected by the group mutex. */ + iommu_group_mutex_assert(dev); if (info->iopf_refcount) { info->iopf_refcount++; return 0; @@ -3900,6 +3913,7 @@ void intel_iommu_disable_iopf(struct device *dev) if (WARN_ON(!info->pri_enabled)) return; =20 + iommu_group_mutex_assert(dev); if (--info->iopf_refcount) return; =20 @@ -3911,8 +3925,7 @@ intel_iommu_dev_enable_feat(struct device *dev, enum = iommu_dev_features feat) { switch (feat) { case IOMMU_DEV_FEAT_IOPF: - return intel_iommu_enable_iopf(dev); - + return 0; default: return -ENODEV; } @@ -3923,7 +3936,6 @@ intel_iommu_dev_disable_feat(struct device *dev, enum= iommu_dev_features feat) { switch (feat) { case IOMMU_DEV_FEAT_IOPF: - intel_iommu_disable_iopf(dev); return 0; =20 default: @@ -4004,6 +4016,7 @@ static int blocking_domain_set_dev_pasid(struct iommu= _domain *domain, { struct device_domain_info *info =3D dev_iommu_priv_get(dev); =20 + iopf_for_domain_remove(old, dev); intel_pasid_tear_down_entry(info->iommu, dev, pasid, false); domain_remove_dev_pasid(old, dev, pasid); =20 @@ -4077,6 +4090,10 @@ static int intel_iommu_set_dev_pasid(struct iommu_do= main *domain, if (IS_ERR(dev_pasid)) return PTR_ERR(dev_pasid); =20 + ret =3D iopf_for_domain_replace(domain, old, dev); + if (ret) + goto out_remove_dev_pasid; + if (dmar_domain->use_first_level) ret =3D domain_setup_first_level(iommu, dmar_domain, dev, pasid, old); @@ -4084,7 +4101,7 @@ static int intel_iommu_set_dev_pasid(struct iommu_dom= ain *domain, ret =3D domain_setup_second_level(iommu, dmar_domain, dev, pasid, old); if (ret) - goto out_remove_dev_pasid; + goto out_unwind_iopf; =20 domain_remove_dev_pasid(old, dev, pasid); =20 @@ -4092,6 +4109,8 @@ static int intel_iommu_set_dev_pasid(struct iommu_dom= ain *domain, =20 return 0; =20 +out_unwind_iopf: + iopf_for_domain_replace(old, domain, dev); out_remove_dev_pasid: domain_remove_dev_pasid(domain, dev, pasid); return ret; @@ -4309,6 +4328,11 @@ static int identity_domain_attach_dev(struct iommu_d= omain *domain, struct device if (dev_is_real_dma_subdevice(dev)) return 0; =20 + /* + * No PRI support with the global identity domain. No need to enable or + * disable PRI in this path as the iommu has been put in the blocking + * state. + */ if (sm_supported(iommu)) ret =3D intel_pasid_setup_pass_through(iommu, dev, IOMMU_NO_PASID); else @@ -4328,9 +4352,15 @@ static int identity_domain_set_dev_pasid(struct iomm= u_domain *domain, if (!pasid_supported(iommu) || dev_is_real_dma_subdevice(dev)) return -EOPNOTSUPP; =20 + ret =3D iopf_for_domain_replace(domain, old, dev); + if (ret) + return ret; + ret =3D domain_setup_passthrough(iommu, dev, pasid, old); - if (ret) + if (ret) { + iopf_for_domain_replace(old, domain, dev); return ret; + } =20 domain_remove_dev_pasid(old, dev, pasid); return 0; diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 754f6d7ade26..dfb0628fabf8 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1317,6 +1317,49 @@ void intel_iommu_drain_pasid_prq(struct device *dev,= u32 pasid); int intel_iommu_enable_iopf(struct device *dev); void intel_iommu_disable_iopf(struct device *dev); =20 +static inline int iopf_for_domain_set(struct iommu_domain *domain, + struct device *dev) +{ + if (!domain || !domain->iopf_handler) + return 0; + + return intel_iommu_enable_iopf(dev); +} + +static inline void iopf_for_domain_remove(struct iommu_domain *domain, + struct device *dev) +{ + if (!domain || !domain->iopf_handler) + return; + + intel_iommu_disable_iopf(dev); +} + +static inline int iopf_for_domain_replace(struct iommu_domain *new, + struct iommu_domain *old, + struct device *dev) +{ + if (!old) + return iopf_for_domain_set(new, dev); + + if (!new) { + iopf_for_domain_remove(old, dev); + return 0; + } + + /* + * Replace a non-iopf-capable domain with an iopf-capable one requires + * to enable PRI on the device. On the contrary, disable it. + */ + if (new->iopf_handler && !old->iopf_handler) + return intel_iommu_enable_iopf(dev); + + if (!new->iopf_handler && old->iopf_handler) + intel_iommu_disable_iopf(dev); + + return 0; +} + #ifdef CONFIG_INTEL_IOMMU_SVM void intel_svm_check(struct intel_iommu *iommu); struct iommu_domain *intel_svm_domain_alloc(struct device *dev, diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c index aba92c00b427..ad307248bcae 100644 --- a/drivers/iommu/intel/nested.c +++ b/drivers/iommu/intel/nested.c @@ -56,10 +56,14 @@ static int intel_nested_attach_dev(struct iommu_domain = *domain, if (ret) goto detach_iommu; =20 + ret =3D iopf_for_domain_set(domain, dev); + if (ret) + goto unassign_tag; + ret =3D intel_pasid_setup_nested(iommu, dev, IOMMU_NO_PASID, dmar_domain); if (ret) - goto unassign_tag; + goto disable_iopf; =20 info->domain =3D dmar_domain; spin_lock_irqsave(&dmar_domain->lock, flags); @@ -67,6 +71,8 @@ static int intel_nested_attach_dev(struct iommu_domain *d= omain, spin_unlock_irqrestore(&dmar_domain->lock, flags); =20 return 0; +disable_iopf: + iopf_for_domain_remove(domain, dev); unassign_tag: cache_tag_unassign_domain(dmar_domain, dev, IOMMU_NO_PASID); detach_iommu: @@ -166,14 +172,20 @@ static int intel_nested_set_dev_pasid(struct iommu_do= main *domain, if (IS_ERR(dev_pasid)) return PTR_ERR(dev_pasid); =20 - ret =3D domain_setup_nested(iommu, dmar_domain, dev, pasid, old); + ret =3D iopf_for_domain_replace(domain, old, dev); if (ret) goto out_remove_dev_pasid; =20 + ret =3D domain_setup_nested(iommu, dmar_domain, dev, pasid, old); + if (ret) + goto out_unwind_iopf; + domain_remove_dev_pasid(old, dev, pasid); =20 return 0; =20 +out_unwind_iopf: + iopf_for_domain_replace(old, domain, dev); out_remove_dev_pasid: domain_remove_dev_pasid(domain, dev, pasid); return ret; diff --git a/drivers/iommu/intel/svm.c b/drivers/iommu/intel/svm.c index ba93123cb4eb..f3da596410b5 100644 --- a/drivers/iommu/intel/svm.c +++ b/drivers/iommu/intel/svm.c @@ -164,18 +164,23 @@ static int intel_svm_set_dev_pasid(struct iommu_domai= n *domain, if (IS_ERR(dev_pasid)) return PTR_ERR(dev_pasid); =20 + ret =3D iopf_for_domain_replace(domain, old, dev); + if (ret) + goto out_remove_dev_pasid; + /* Setup the pasid table: */ sflags =3D cpu_feature_enabled(X86_FEATURE_LA57) ? PASID_FLAG_FL5LP : 0; ret =3D __domain_setup_first_level(iommu, dev, pasid, FLPT_DEFAULT_DID, mm->pgd, sflags, old); if (ret) - goto out_remove_dev_pasid; + goto out_unwind_iopf; =20 domain_remove_dev_pasid(old, dev, pasid); =20 return 0; - +out_unwind_iopf: + iopf_for_domain_replace(old, domain, dev); out_remove_dev_pasid: domain_remove_dev_pasid(domain, dev, pasid); return ret; --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFBF61FCFD3 for ; Fri, 14 Feb 2025 06:11:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513489; cv=none; b=kiw1nWVJoR5AxgSi98NVQeeY1rMYWOMWk1fEKu2rjlGYpdx/a7Mt40AByPnq9c13egJPqTIRmh6gwsriHU/tSnn1cYVYq/FydO2fy/zsgf1HKHbuN2lX4Z619CN9ZqAweNFLpdJaKP11CCa9CVVyNCUlIMk4sMdJ5J6MD2wR/is= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513489; c=relaxed/simple; bh=fgHuJ9roGkGcY1DwYyoCbSL2BPlcZHJT3W616Z69MAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d3YRvN7ncrwWxGEwZj5TE3YkDUR+uiPBN7NmJbwJt0LN2m8sBfr78sDj8EnwAQgmUoh4yeuKEEgDDzgp5UAx/nq3bO2+dCz6to9CGrF9RcOMGaJ9dl03//a/ADhpP1CvlwvsVkEP3jbOMeaExd3nn+E37SaRsxeaDvHi7RwhmvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JT9bNJ1p; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JT9bNJ1p" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513488; x=1771049488; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fgHuJ9roGkGcY1DwYyoCbSL2BPlcZHJT3W616Z69MAg=; b=JT9bNJ1pPJrEqCCN657nBJXjzqCGgJhK5xPva38P3aN+abRLMtXcP5mC G7nL5+T2V+JOKrAlRFHbrO81Zup/en/0S+BMB7mZGcEYcHglqpXmdkkU/ EXNuWr0jhwnWck/SnD55+aHp/W7ODy/268TKPPhKZMfKFpcX85bTX2AZ+ U8PoleoJ0eDyiGP2UvkC2zIJS6iTHinczHV31TKTjooRPMs3GZMYRlNAC irVFCkpGofvNJFqykTtK24jSZIL7eMW60vmSlrpescmv1nYPNkmdIwOwE BxeeVgVpkdcPHC6G7i2WY+BFo6n+cfN9x60rUH7XfZV735wrolbO9tR+l Q==; X-CSE-ConnectionGUID: V9uiymXqScSu0xfdPLPCYw== X-CSE-MsgGUID: wtb8Eu2+QfuXee86BagHRA== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124571" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124571" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:28 -0800 X-CSE-ConnectionGUID: d0j8rxAwTn22ylVVX/unXQ== X-CSE-MsgGUID: SJrsJydUR/yAre0ggqPyCw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268149" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:24 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 08/12] iommufd/selftest: Put iopf enablement in domain attach path Date: Fri, 14 Feb 2025 14:11:00 +0800 Message-ID: <20250214061104.1959525-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update iopf enablement in the iommufd mock device driver to use the new method, similar to the arm-smmu-v3 driver. Enable iopf support when any domain with an iopf_handler is attached, and disable it when the domain is removed. Add a refcount in the mock device state structure to keep track of the number of domains set to the device and PASIDs that require iopf. Signed-off-by: Lu Baolu --- drivers/iommu/iommufd/selftest.c | 52 +++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selft= est.c index d40deb0a4f06..a6b12cee7b00 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -58,6 +58,9 @@ enum { MOCK_PFN_HUGE_IOVA =3D _MOCK_PFN_START << 2, }; =20 +static int mock_dev_enable_iopf(struct device *dev, struct iommu_domain *d= omain); +static void mock_dev_disable_iopf(struct device *dev, struct iommu_domain = *domain); + /* * Syzkaller has trouble randomizing the correct iova to use since it is l= inked * to the map ioctl's output, and it has no ide about that. So, simplify t= hings. @@ -164,6 +167,7 @@ struct mock_dev { unsigned long flags; int id; u32 cache[MOCK_DEV_CACHE_NUM]; + unsigned int iopf_refcount; }; =20 static inline struct mock_dev *to_mock_dev(struct device *dev) @@ -197,11 +201,19 @@ static int mock_domain_nop_attach(struct iommu_domain= *domain, if (domain->dirty_ops && (mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY)) return -EINVAL; =20 + return mock_dev_enable_iopf(dev, domain); +} + +static int mock_domain_blocking_attach(struct iommu_domain *domain, + struct device *dev) +{ + mock_dev_disable_iopf(dev, domain); + return 0; } =20 static const struct iommu_domain_ops mock_blocking_ops =3D { - .attach_dev =3D mock_domain_nop_attach, + .attach_dev =3D mock_domain_blocking_attach, }; =20 static struct iommu_domain mock_blocking_domain =3D { @@ -549,22 +561,42 @@ static void mock_domain_page_response(struct device *= dev, struct iopf_fault *evt { } =20 -static int mock_dev_enable_feat(struct device *dev, enum iommu_dev_feature= s feat) +static int mock_dev_enable_iopf(struct device *dev, struct iommu_domain *d= omain) { - if (feat !=3D IOMMU_DEV_FEAT_IOPF || !mock_iommu_iopf_queue) + struct mock_dev *mdev =3D to_mock_dev(dev); + int ret; + + if (!domain->iopf_handler) + return 0; + + if (!mock_iommu_iopf_queue) return -ENODEV; =20 - return iopf_queue_add_device(mock_iommu_iopf_queue, dev); + if (mdev->iopf_refcount) { + mdev->iopf_refcount++; + return 0; + } + + ret =3D iopf_queue_add_device(mock_iommu_iopf_queue, dev); + if (ret) + return ret; + + mdev->iopf_refcount =3D 1; + + return 0; } =20 -static int mock_dev_disable_feat(struct device *dev, enum iommu_dev_featur= es feat) +static void mock_dev_disable_iopf(struct device *dev, struct iommu_domain = *domain) { - if (feat !=3D IOMMU_DEV_FEAT_IOPF || !mock_iommu_iopf_queue) - return -ENODEV; + struct mock_dev *mdev =3D to_mock_dev(dev); + + if (!domain->iopf_handler) + return; + + if (--mdev->iopf_refcount) + return; =20 iopf_queue_remove_device(mock_iommu_iopf_queue, dev); - - return 0; } =20 static void mock_viommu_destroy(struct iommufd_viommu *viommu) @@ -709,8 +741,6 @@ static const struct iommu_ops mock_ops =3D { .device_group =3D generic_device_group, .probe_device =3D mock_probe_device, .page_response =3D mock_domain_page_response, - .dev_enable_feat =3D mock_dev_enable_feat, - .dev_disable_feat =3D mock_dev_disable_feat, .user_pasid_table =3D true, .viommu_alloc =3D mock_viommu_alloc, .default_domain_ops =3D --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C0FE1FCF57 for ; Fri, 14 Feb 2025 06:11:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513492; cv=none; b=moYd75ZK/J7yNdzQRXp/Tt15hyu+Y6J3E6WCde7X8pxRwHoAElJZCZOpO1+ue5sN6XSrp5ZYB1MNZp2Oo8pnbTLH7qVc1iK/tMXG9LuPJbcE1dN+t5GAIFAjZGrJKEWAEsZZ3iTNfSbbXd8VKNh4J5IbaW/K/lvaWXmTrdG7neI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513492; c=relaxed/simple; bh=P/XSQ+RylB0GJpNm9N0XVJmh1MmFI4aZgfpnMDOBpzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U6bsQRX2lcEkcCy4Rx0D5wWS/TNZsdKDxz2FRBaSmxQw58ryI4DRyQYQN+RcfTKV8wuqk/QqBqpN9PuImCkf+8qLkwNucp+vqxtmuhZEnqEijOf3Qg55JUCGMIMbWOCA7HLmYxmhO29UWzjkigVPxhHmRpmwR1Z7F79calb3LVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AN5sDtjL; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AN5sDtjL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513491; x=1771049491; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P/XSQ+RylB0GJpNm9N0XVJmh1MmFI4aZgfpnMDOBpzE=; b=AN5sDtjL7NttuWHOCX68aKTzi1S+QsB67rRdPUIvTKko/JKRftOI7y2U /DITwL7UD04WRzSjmOxSguByKub+bnO7j0yBtdXq5EUvd20oGn+sNcg88 tQqM0bWj12rkoFFDrzDYBrhWyCT3wXwYkvH+YQh4ND2Kynhw++dvTUn+c 7evnGQSoc7ASPZqSWEfKZ3W+48uNCp9/60bc+mwBdKYT7nzwvx9yNs+Hm ksy4Y+9d5NRbKp3Jg21YbCBUEvV0iNTl4ZkkVVncwdJ/vl7bDGO8MVXrH TmTU5aQRo3g6P3eyE5uxUXsbZPJD2sWIXDaPPZLhJRetOnSk9kz9TxHyK Q==; X-CSE-ConnectionGUID: a2rL+PyASlWN2n6QOPgpEg== X-CSE-MsgGUID: LCJUwDVTQ2KFnUgaUC50SQ== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124582" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124582" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:31 -0800 X-CSE-ConnectionGUID: QYD1vStwT/y8rh9/95omaA== X-CSE-MsgGUID: y/8M73bQRjCyFm0342wm4w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268155" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:28 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 09/12] dmaengine: idxd: Remove unnecessary IOMMU_DEV_FEAT_IOPF Date: Fri, 14 Feb 2025 14:11:01 +0800 Message-ID: <20250214061104.1959525-10-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The IOMMU_DEV_FEAT_IOPF implementation in the iommu driver is just a no-op. It will also be removed from the iommu driver in the subsequent patch. Remove it to avoid dead code. Signed-off-by: Lu Baolu Acked-by: Vinod Koul Reviewed-by: Dave Jiang Reviewed-by: Fenghua Yu Reviewed-by: Jason Gunthorpe --- drivers/dma/idxd/init.c | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/drivers/dma/idxd/init.c b/drivers/dma/idxd/init.c index 1e5038cca22c..d44944195807 100644 --- a/drivers/dma/idxd/init.c +++ b/drivers/dma/idxd/init.c @@ -626,21 +626,6 @@ static void idxd_disable_system_pasid(struct idxd_devi= ce *idxd) idxd->pasid =3D IOMMU_PASID_INVALID; } =20 -static int idxd_enable_sva(struct pci_dev *pdev) -{ - int ret; - - ret =3D iommu_dev_enable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF); - if (ret) - return ret; - return 0; -} - -static void idxd_disable_sva(struct pci_dev *pdev) -{ - iommu_dev_disable_feature(&pdev->dev, IOMMU_DEV_FEAT_IOPF); -} - static int idxd_probe(struct idxd_device *idxd) { struct pci_dev *pdev =3D idxd->pdev; @@ -655,17 +640,13 @@ static int idxd_probe(struct idxd_device *idxd) dev_dbg(dev, "IDXD reset complete\n"); =20 if (IS_ENABLED(CONFIG_INTEL_IDXD_SVM) && sva) { - if (idxd_enable_sva(pdev)) { - dev_warn(dev, "Unable to turn on user SVA feature.\n"); - } else { - set_bit(IDXD_FLAG_USER_PASID_ENABLED, &idxd->flags); + set_bit(IDXD_FLAG_USER_PASID_ENABLED, &idxd->flags); =20 - rc =3D idxd_enable_system_pasid(idxd); - if (rc) - dev_warn(dev, "No in-kernel DMA with PASID. %d\n", rc); - else - set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags); - } + rc =3D idxd_enable_system_pasid(idxd); + if (rc) + dev_warn(dev, "No in-kernel DMA with PASID. %d\n", rc); + else + set_bit(IDXD_FLAG_PASID_ENABLED, &idxd->flags); } else if (!sva) { dev_warn(dev, "User forced SVA off via module param.\n"); } @@ -703,8 +684,6 @@ static int idxd_probe(struct idxd_device *idxd) err: if (device_pasid_enabled(idxd)) idxd_disable_system_pasid(idxd); - if (device_user_pasid_enabled(idxd)) - idxd_disable_sva(pdev); return rc; } =20 @@ -715,8 +694,6 @@ static void idxd_cleanup(struct idxd_device *idxd) idxd_cleanup_internals(idxd); if (device_pasid_enabled(idxd)) idxd_disable_system_pasid(idxd); - if (device_user_pasid_enabled(idxd)) - idxd_disable_sva(idxd->pdev); } =20 /* @@ -1248,8 +1225,6 @@ static void idxd_remove(struct pci_dev *pdev) free_irq(irq_entry->vector, irq_entry); pci_free_irq_vectors(pdev); pci_iounmap(pdev, idxd->reg_base); - if (device_user_pasid_enabled(idxd)) - idxd_disable_sva(pdev); pci_disable_device(pdev); destroy_workqueue(idxd->wq); perfmon_pmu_remove(idxd); --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68FC01FDE05 for ; Fri, 14 Feb 2025 06:11:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513495; cv=none; b=IUHpLolloe4+nwzAbW2xCvIOPkpD94XVy9bpLtrg7JYSITlrRdceJbJ1ILtlX0oHM+Behua4WJ6dCMbY6D593VP+9eDyquxRUtDclo3+sWLMd/ktsRrgYVWLV0HzcmrM5M/S4wCtCYHQY5hCkPt8NSFW0vbXAAkPkFvpEuPGzvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513495; c=relaxed/simple; bh=eHTPZGlc4bucKd77w2+UvVId/z3fbuGWY7W1qJYKM9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RjniEi62+oUComllOpVVW71yOHCoHMYxsZ1cfjeFqI5HxQh1XKCUSgFUTsuAJuhbVTHC9h3Dj1oho8d2pnUPPAXGH6raC4fKKdZaVyR7agZD4si38IU+SMuDamCHEt3Wce//dlnJZ5NFejh1kDJuVK9agABV/GNCY46mJlya/Es= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=mFVKv5CB; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="mFVKv5CB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513494; x=1771049494; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eHTPZGlc4bucKd77w2+UvVId/z3fbuGWY7W1qJYKM9M=; b=mFVKv5CBuM9rh/HBKG+rjW+K75PGMxhBPtPeK3B3lp45Orzm7RSQnK9e yPuZYEst148oQqExdlD64tWcvrUmDDHVQvlFExADajstIsHFWP6rbal3S FWHx5eFOzSFOoN/+2Ke39BXsZOis8blHkVCD0FvdLkpVsYPmLCXRTgmvM rCMv9KEnD3VdXy9LtSejh5B6q73kIuaOPlJljThHH7fsn7skHY4VGjPe4 nulEzxp8tLRnseUtZC48u6G0LZoImgfTZ1S/ZFBXcjdrU8xPCkh42pI4B OCOickK9ZcLXtMPVGLKIioMw1BhhU20tj/QLlBlMTiuChOfsPk8miN3j0 Q==; X-CSE-ConnectionGUID: APyfOKpYT/S4ImcZfQ20SQ== X-CSE-MsgGUID: 3zEOwciAQ+u1TTL0NAfZFw== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124593" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124593" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:34 -0800 X-CSE-ConnectionGUID: mbkI+N/yRf2nnMMeAp/srQ== X-CSE-MsgGUID: y7DjvvTWQR2qLM3tm4arEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268166" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:31 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 10/12] uacce: Remove unnecessary IOMMU_DEV_FEAT_IOPF Date: Fri, 14 Feb 2025 14:11:02 +0800 Message-ID: <20250214061104.1959525-11-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" None of the drivers implement anything for IOMMU_DEV_FEAT_IOPF anymore, remove it to avoid dead code. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/misc/uacce/uacce.c | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/drivers/misc/uacce/uacce.c b/drivers/misc/uacce/uacce.c index 2a1db2abeeca..42e7d2a2a90c 100644 --- a/drivers/misc/uacce/uacce.c +++ b/drivers/misc/uacce/uacce.c @@ -465,31 +465,6 @@ static void uacce_release(struct device *dev) kfree(uacce); } =20 -static unsigned int uacce_enable_sva(struct device *parent, unsigned int f= lags) -{ - int ret; - - if (!(flags & UACCE_DEV_SVA)) - return flags; - - flags &=3D ~UACCE_DEV_SVA; - - ret =3D iommu_dev_enable_feature(parent, IOMMU_DEV_FEAT_IOPF); - if (ret) { - dev_err(parent, "failed to enable IOPF feature! ret =3D %pe\n", ERR_PTR(= ret)); - return flags; - } - return flags | UACCE_DEV_SVA; -} - -static void uacce_disable_sva(struct uacce_device *uacce) -{ - if (!(uacce->flags & UACCE_DEV_SVA)) - return; - - iommu_dev_disable_feature(uacce->parent, IOMMU_DEV_FEAT_IOPF); -} - /** * uacce_alloc() - alloc an accelerator * @parent: pointer of uacce parent device @@ -509,8 +484,6 @@ struct uacce_device *uacce_alloc(struct device *parent, if (!uacce) return ERR_PTR(-ENOMEM); =20 - flags =3D uacce_enable_sva(parent, flags); - uacce->parent =3D parent; uacce->flags =3D flags; uacce->ops =3D interface->ops; @@ -533,7 +506,6 @@ struct uacce_device *uacce_alloc(struct device *parent, return uacce; =20 err_with_uacce: - uacce_disable_sva(uacce); kfree(uacce); return ERR_PTR(ret); } @@ -596,9 +568,6 @@ void uacce_remove(struct uacce_device *uacce) unmap_mapping_range(q->mapping, 0, 0, 1); } =20 - /* disable sva now since no opened queues */ - uacce_disable_sva(uacce); - if (uacce->cdev) cdev_device_del(uacce->cdev, &uacce->dev); xa_erase(&uacce_xa, uacce->dev_id); --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E70071FDE3A for ; Fri, 14 Feb 2025 06:11:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513499; cv=none; b=V1Z0DpoHBDjGgNZPtI+yOTSoHpuPXLnZDMuPuGRB/Ysh/F1WtilRdmptp5FLCW+zN8fEFn30TprrrS/I/PRUgzjyODhO6z3Tp/RD7Zjx9SI4Zu0f5FzYlaUhE7UZv0237QMLnio1u216LrNT2cBfImSGyGTv18lMcSFTpXQa8Yc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513499; c=relaxed/simple; bh=5KY+D+qugIhYyewDD64S60rdrMft/EnzrStFEsxfFMY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YXXC0cpzYx4al1OwPIXBVMLNQdKy6QBctMb1MQj+qNJX7D0gqIWl8lFvE8WuHsyraDed8c0O4IXLAfydbz5d4rJgALrcFZgHD2b1vY78oZHN9jbtQ2lNCG2n2ot7oqK9u+3STRU7nP+ZTOC4kjJAQiJtt8hglbZcnL5pnl4hZ4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=c7H7Yh4h; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="c7H7Yh4h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513498; x=1771049498; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5KY+D+qugIhYyewDD64S60rdrMft/EnzrStFEsxfFMY=; b=c7H7Yh4hlXaI8f3WNfPKscy7PaZlXayTvv0YbRFjkewnPP+TDEsg3mIl iySApL+0nYMMUP+1GXxMCzP5apcQbVhCp1YChuqeus6dTQk7UgHyYanrR BsTazzs7oMaEq54fU+CGJuplKzrXPMPyiysoEWZvnQTHYmyOuRAP6RaFE LPeC/FU+HOHv/7FfEe/zl/iHUk74ZA/CmKIlgJqrmI9YNH14sef7LtHYZ XwDS6vh7Fe/qNyhn1bAcR7rYnP8mLGbf03Y8qoBwZiAVlHr7sMT2A0mYP J/0W51iZ+1FtMgxX9+F/k8kYF8x/c8BkaVLHI8BH1GkP3999UlI2ylsny Q==; X-CSE-ConnectionGUID: dG/wSycbQWSksEfyd0SO+A== X-CSE-MsgGUID: v5bSzfvATBK3FMecLDLQpw== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124606" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124606" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:38 -0800 X-CSE-ConnectionGUID: YLjE5nByQ0q63x/kYkUOmg== X-CSE-MsgGUID: T8MGUitLToaTKIc55papNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268175" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:34 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 11/12] iommufd: Remove unnecessary IOMMU_DEV_FEAT_IOPF Date: Fri, 14 Feb 2025 14:11:03 +0800 Message-ID: <20250214061104.1959525-12-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The iopf enablement has been moved to the iommu drivers. It is unnecessary for iommufd to handle iopf enablement. Remove the iopf enablement logic to avoid duplication. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/iommufd/device.c | 1 - drivers/iommu/iommufd/fault.c | 111 ++++++------------------ drivers/iommu/iommufd/iommufd_private.h | 3 - 3 files changed, 28 insertions(+), 87 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index dfd0898fb6c1..47e36456b438 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -215,7 +215,6 @@ struct iommufd_device *iommufd_device_bind(struct iommu= fd_ctx *ictx, refcount_inc(&idev->obj.users); /* igroup refcount moves into iommufd_device */ idev->igroup =3D igroup; - mutex_init(&idev->iopf_lock); =20 /* * If the caller fails after this success it must call diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index d9a937450e55..4776c632cff2 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -17,49 +17,6 @@ #include "../iommu-priv.h" #include "iommufd_private.h" =20 -static int iommufd_fault_iopf_enable(struct iommufd_device *idev) -{ - struct device *dev =3D idev->dev; - int ret; - - /* - * Once we turn on PCI/PRI support for VF, the response failure code - * should not be forwarded to the hardware due to PRI being a shared - * resource between PF and VFs. There is no coordination for this - * shared capability. This waits for a vPRI reset to recover. - */ - if (dev_is_pci(dev)) { - struct pci_dev *pdev =3D to_pci_dev(dev); - - if (pdev->is_virtfn && pci_pri_supported(pdev)) - return -EINVAL; - } - - mutex_lock(&idev->iopf_lock); - /* Device iopf has already been on. */ - if (++idev->iopf_enabled > 1) { - mutex_unlock(&idev->iopf_lock); - return 0; - } - - ret =3D iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_IOPF); - if (ret) - --idev->iopf_enabled; - mutex_unlock(&idev->iopf_lock); - - return ret; -} - -static void iommufd_fault_iopf_disable(struct iommufd_device *idev) -{ - mutex_lock(&idev->iopf_lock); - if (!WARN_ON(idev->iopf_enabled =3D=3D 0)) { - if (--idev->iopf_enabled =3D=3D 0) - iommu_dev_disable_feature(idev->dev, IOMMU_DEV_FEAT_IOPF); - } - mutex_unlock(&idev->iopf_lock); -} - static int __fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev) { @@ -82,20 +39,23 @@ static int __fault_domain_attach_dev(struct iommufd_hw_= pagetable *hwpt, int iommufd_fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev) { - int ret; - if (!hwpt->fault) return -EINVAL; =20 - ret =3D iommufd_fault_iopf_enable(idev); - if (ret) - return ret; + /* + * Once we turn on PCI/PRI support for VF, the response failure code + * should not be forwarded to the hardware due to PRI being a shared + * resource between PF and VFs. There is no coordination for this + * shared capability. This waits for a vPRI reset to recover. + */ + if (dev_is_pci(idev->dev)) { + struct pci_dev *pdev =3D to_pci_dev(idev->dev); =20 - ret =3D __fault_domain_attach_dev(hwpt, idev); - if (ret) - iommufd_fault_iopf_disable(idev); + if (pdev->is_virtfn && pci_pri_supported(pdev)) + return -EINVAL; + } =20 - return ret; + return __fault_domain_attach_dev(hwpt, idev); } =20 static void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt, @@ -155,13 +115,12 @@ void iommufd_fault_domain_detach_dev(struct iommufd_h= w_pagetable *hwpt, handle =3D iommufd_device_get_attach_handle(idev); iommu_detach_group_handle(hwpt->domain, idev->igroup->group); iommufd_auto_response_faults(hwpt, handle); - iommufd_fault_iopf_disable(idev); kfree(handle); } =20 -static int __fault_domain_replace_dev(struct iommufd_device *idev, - struct iommufd_hw_pagetable *hwpt, - struct iommufd_hw_pagetable *old) +int iommufd_fault_domain_replace_dev(struct iommufd_device *idev, + struct iommufd_hw_pagetable *hwpt, + struct iommufd_hw_pagetable *old) { struct iommufd_attach_handle *handle, *curr =3D NULL; int ret; @@ -170,6 +129,19 @@ static int __fault_domain_replace_dev(struct iommufd_d= evice *idev, curr =3D iommufd_device_get_attach_handle(idev); =20 if (hwpt->fault) { + /* + * Once we turn on PCI/PRI support for VF, the response failure code + * should not be forwarded to the hardware due to PRI being a shared + * resource between PF and VFs. There is no coordination for this + * shared capability. This waits for a vPRI reset to recover. + */ + if (dev_is_pci(idev->dev)) { + struct pci_dev *pdev =3D to_pci_dev(idev->dev); + + if (pdev->is_virtfn && pci_pri_supported(pdev)) + return -EINVAL; + } + handle =3D kzalloc(sizeof(*handle), GFP_KERNEL); if (!handle) return -ENOMEM; @@ -190,33 +162,6 @@ static int __fault_domain_replace_dev(struct iommufd_d= evice *idev, return ret; } =20 -int iommufd_fault_domain_replace_dev(struct iommufd_device *idev, - struct iommufd_hw_pagetable *hwpt, - struct iommufd_hw_pagetable *old) -{ - bool iopf_off =3D !hwpt->fault && old->fault; - bool iopf_on =3D hwpt->fault && !old->fault; - int ret; - - if (iopf_on) { - ret =3D iommufd_fault_iopf_enable(idev); - if (ret) - return ret; - } - - ret =3D __fault_domain_replace_dev(idev, hwpt, old); - if (ret) { - if (iopf_on) - iommufd_fault_iopf_disable(idev); - return ret; - } - - if (iopf_off) - iommufd_fault_iopf_disable(idev); - - return 0; -} - void iommufd_fault_destroy(struct iommufd_object *obj) { struct iommufd_fault *fault =3D container_of(obj, struct iommufd_fault, o= bj); diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommuf= d/iommufd_private.h index 0b1bafc7fd99..0eb3779db156 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -399,9 +399,6 @@ struct iommufd_device { /* always the physical device */ struct device *dev; bool enforce_cache_coherency; - /* protect iopf_enabled counter */ - struct mutex iopf_lock; - unsigned int iopf_enabled; }; =20 static inline struct iommufd_device * --=20 2.43.0 From nobody Fri Dec 19 18:29:52 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D38C1FC0E0 for ; Fri, 14 Feb 2025 06:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513503; cv=none; b=gG3+LPgmwcl3Ifl49hA9A3ZMBSRf5VMvpz2QFYW27TEZYW+GDroSJzmZJ2GgDj6++SptZaMw5xE5/srbec0B2ElCzHNdSE78Fkr8/Xot0BBD8jtu94tIjAX5p1kIGpNsIETjgNdzA1A/tyssFrsypTMKnuZcW7vY4YZLJKHZmSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739513503; c=relaxed/simple; bh=z5CHmSpsIFmOesfR9bqyE2APGqdUsxwoh53fDjhiLjs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I1y6+P+kTQ6MFaGOOnXfnPRhhl5ZJB4efe8Rkno63iQfgz2H6GQHIhkxbM18kPQYS2ZoNVtjEp5ZoHfiqDdrBINnn3zG0RhxAjtjj9VXiZYo7gONT0xjDv8rYUo72rUy9rwhjtOFeAe8vX88/EKaZ1jWtdCMkpGx/DSUyA7ljjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WXIetwel; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WXIetwel" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739513501; x=1771049501; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z5CHmSpsIFmOesfR9bqyE2APGqdUsxwoh53fDjhiLjs=; b=WXIetwelyrFk9lFIr4UwJrHlKyWX2bAVRT+KnNAqQ/52NSHbqOg0uvLq j1mwCZvtj5xgxcmAAFORXQp+oajgsYUAf8zHLAYUtEuIdPorLVNN5drpJ AIPMMiNa1v+pLujathUnaX/AGmkIlXhBOX9q9jF/O7gMqnizKtHRE3oFL ZmuT5377HqlE3qjs3J4isbER4mO3+TXJEVl6UdYlaax33SrPDJHbvg2Gk ljEJa50zSS1JlHuF7SLG6wBrOAmPO0+n7aUEYRKvELFurg4yhj0/mwKDF YW9ULkQK1vD7gVKzHLcWEeyMZQfyIPHHOHWSPpXoUBGz1rBVZgSrrZS0o A==; X-CSE-ConnectionGUID: nVUtAoulSv2HIy3N20/F6Q== X-CSE-MsgGUID: SzyB39OaRk2ixDR+K5tRpw== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40124622" X-IronPort-AV: E=Sophos;i="6.13,284,1732608000"; d="scan'208";a="40124622" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 22:11:41 -0800 X-CSE-ConnectionGUID: p1fHdXFMQdGfjFTo4KvYzQ== X-CSE-MsgGUID: 4acGqe8YQPKMgQcIdt32IA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="114268187" Received: from allen-box.sh.intel.com ([10.239.159.52]) by orviesa008.jf.intel.com with ESMTP; 13 Feb 2025 22:11:38 -0800 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Fenghua Yu , Dave Jiang , Vinod Koul , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 12/12] iommu: Remove iommu_dev_enable/disable_feature() Date: Fri, 14 Feb 2025 14:11:04 +0800 Message-ID: <20250214061104.1959525-13-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250214061104.1959525-1-baolu.lu@linux.intel.com> References: <20250214061104.1959525-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" No external drivers use these interfaces anymore. Furthermore, no existing iommu drivers implement anything in the callbacks. Remove them to avoid dead code. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/amd/iommu.c | 32 ------------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 34 --------------------- drivers/iommu/intel/iommu.c | 25 --------------- drivers/iommu/iommu.c | 32 ------------------- include/linux/iommu.h | 28 ----------------- 5 files changed, 151 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index e3653bdfcd7d..8d74afa552fb 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2983,36 +2983,6 @@ static const struct iommu_dirty_ops amd_dirty_ops = =3D { .read_and_clear_dirty =3D amd_iommu_read_and_clear_dirty, }; =20 -static int amd_iommu_dev_enable_feature(struct device *dev, - enum iommu_dev_features feat) -{ - int ret =3D 0; - - switch (feat) { - case IOMMU_DEV_FEAT_IOPF: - break; - default: - ret =3D -EINVAL; - break; - } - return ret; -} - -static int amd_iommu_dev_disable_feature(struct device *dev, - enum iommu_dev_features feat) -{ - int ret =3D 0; - - switch (feat) { - case IOMMU_DEV_FEAT_IOPF: - break; - default: - ret =3D -EINVAL; - break; - } - return ret; -} - const struct iommu_ops amd_iommu_ops =3D { .capable =3D amd_iommu_capable, .blocked_domain =3D &blocked_domain, @@ -3026,8 +2996,6 @@ const struct iommu_ops amd_iommu_ops =3D { .get_resv_regions =3D amd_iommu_get_resv_regions, .is_attach_deferred =3D amd_iommu_is_attach_deferred, .def_domain_type =3D amd_iommu_def_domain_type, - .dev_enable_feat =3D amd_iommu_dev_enable_feature, - .dev_disable_feat =3D amd_iommu_dev_disable_feature, .page_response =3D amd_iommu_page_response, .default_domain_ops =3D &(const struct iommu_domain_ops) { .attach_dev =3D amd_iommu_attach_device, diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/ar= m/arm-smmu-v3/arm-smmu-v3.c index ee945a9db641..28e67a9e3861 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3617,38 +3617,6 @@ static void arm_smmu_get_resv_regions(struct device = *dev, iommu_dma_get_resv_regions(dev, head); } =20 -static int arm_smmu_dev_enable_feature(struct device *dev, - enum iommu_dev_features feat) -{ - struct arm_smmu_master *master =3D dev_iommu_priv_get(dev); - - if (!master) - return -ENODEV; - - switch (feat) { - case IOMMU_DEV_FEAT_IOPF: - return 0; - default: - return -EINVAL; - } -} - -static int arm_smmu_dev_disable_feature(struct device *dev, - enum iommu_dev_features feat) -{ - struct arm_smmu_master *master =3D dev_iommu_priv_get(dev); - - if (!master) - return -EINVAL; - - switch (feat) { - case IOMMU_DEV_FEAT_IOPF: - return 0; - default: - return -EINVAL; - } -} - /* * HiSilicon PCIe tune and trace device can be used to trace TLP headers o= n the * PCIe link and save the data to memory by DMA. The hardware is restricte= d to @@ -3681,8 +3649,6 @@ static struct iommu_ops arm_smmu_ops =3D { .device_group =3D arm_smmu_device_group, .of_xlate =3D arm_smmu_of_xlate, .get_resv_regions =3D arm_smmu_get_resv_regions, - .dev_enable_feat =3D arm_smmu_dev_enable_feature, - .dev_disable_feat =3D arm_smmu_dev_disable_feature, .page_response =3D arm_smmu_page_response, .def_domain_type =3D arm_smmu_def_domain_type, .viommu_alloc =3D arm_vsmmu_alloc, diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 20d07f5fea85..aad11e76ac40 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3920,29 +3920,6 @@ void intel_iommu_disable_iopf(struct device *dev) iopf_queue_remove_device(iommu->iopf_queue, dev); } =20 -static int -intel_iommu_dev_enable_feat(struct device *dev, enum iommu_dev_features fe= at) -{ - switch (feat) { - case IOMMU_DEV_FEAT_IOPF: - return 0; - default: - return -ENODEV; - } -} - -static int -intel_iommu_dev_disable_feat(struct device *dev, enum iommu_dev_features f= eat) -{ - switch (feat) { - case IOMMU_DEV_FEAT_IOPF: - return 0; - - default: - return -ENODEV; - } -} - static bool intel_iommu_is_attach_deferred(struct device *dev) { struct device_domain_info *info =3D dev_iommu_priv_get(dev); @@ -4387,8 +4364,6 @@ const struct iommu_ops intel_iommu_ops =3D { .release_device =3D intel_iommu_release_device, .get_resv_regions =3D intel_iommu_get_resv_regions, .device_group =3D intel_iommu_device_group, - .dev_enable_feat =3D intel_iommu_dev_enable_feat, - .dev_disable_feat =3D intel_iommu_dev_disable_feat, .is_attach_deferred =3D intel_iommu_is_attach_deferred, .def_domain_type =3D device_def_domain_type, .pgsize_bitmap =3D SZ_4K, diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 870c3cdbd0f6..c86ab80dce4d 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2877,38 +2877,6 @@ int iommu_fwspec_add_ids(struct device *dev, const u= 32 *ids, int num_ids) } EXPORT_SYMBOL_GPL(iommu_fwspec_add_ids); =20 -/* - * Per device IOMMU features. - */ -int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f= eat) -{ - if (dev_has_iommu(dev)) { - const struct iommu_ops *ops =3D dev_iommu_ops(dev); - - if (ops->dev_enable_feat) - return ops->dev_enable_feat(dev, feat); - } - - return -ENODEV; -} -EXPORT_SYMBOL_GPL(iommu_dev_enable_feature); - -/* - * The device drivers should do the necessary cleanups before calling this. - */ -int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features = feat) -{ - if (dev_has_iommu(dev)) { - const struct iommu_ops *ops =3D dev_iommu_ops(dev); - - if (ops->dev_disable_feat) - return ops->dev_disable_feat(dev, feat); - } - - return -EBUSY; -} -EXPORT_SYMBOL_GPL(iommu_dev_disable_feature); - /** * iommu_setup_default_domain - Set the default_domain for the group * @group: Group to change diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 1d0dde49168d..127f99acab5f 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -301,16 +301,6 @@ struct iommu_iort_rmr_data { u32 num_sids; }; =20 -/** - * enum iommu_dev_features - Per device IOMMU features - * @IOMMU_DEV_FEAT_IOPF: I/O Page Faults such as PRI or Stall. - * - * Device drivers enable a feature using iommu_dev_enable_feature(). - */ -enum iommu_dev_features { - IOMMU_DEV_FEAT_IOPF, -}; - #define IOMMU_NO_PASID (0U) /* Reserved for DMA w/o PASID */ #define IOMMU_FIRST_GLOBAL_PASID (1U) /*starting range for allocation */ #define IOMMU_PASID_INVALID (-1U) @@ -630,9 +620,6 @@ struct iommu_ops { bool (*is_attach_deferred)(struct device *dev); =20 /* Per device IOMMU features */ - int (*dev_enable_feat)(struct device *dev, enum iommu_dev_features f); - int (*dev_disable_feat)(struct device *dev, enum iommu_dev_features f); - void (*page_response)(struct device *dev, struct iopf_fault *evt, struct iommu_page_response *msg); =20 @@ -1102,9 +1089,6 @@ void dev_iommu_priv_set(struct device *dev, void *pri= v); extern struct mutex iommu_probe_device_lock; int iommu_probe_device(struct device *dev); =20 -int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f= ); -int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features = f); - int iommu_device_use_default_domain(struct device *dev); void iommu_device_unuse_default_domain(struct device *dev); =20 @@ -1393,18 +1377,6 @@ static inline int iommu_fwspec_add_ids(struct device= *dev, u32 *ids, return -ENODEV; } =20 -static inline int -iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features feat) -{ - return -ENODEV; -} - -static inline int -iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features feat) -{ - return -ENODEV; -} - static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev) { return NULL; --=20 2.43.0