From nobody Sun Dec 14 12:17:06 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 7CB2E26AA8A for ; Fri, 18 Apr 2025 08:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963267; cv=none; b=dxkrXK+Xj/ZsDtZ+g9GADA+b+dWBAnFOkPo6z2FdSRW1tGtvUnNTyvzbWYfDV6VDLxh+3oJ91/UqXm/IgNbgPL5x6wUFu8XuOsLydvrpSucqLsxlUWudhzV74KcQQ8SgGlbX6214eNkHDt2Wth95mYzrMFsyCNKtD1FhCs8U2Qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963267; c=relaxed/simple; bh=NXyGilvlCSGNm4oXjjk/GmSnNnA0XjgRmH0GWjlpku4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VaG6gqkBVSdZIawzrWPPokn2991zniM9VFxVwQPTS8lrpTNBUM3e10MBVO0SunmJcVNzCfDiq5y/IbQeaAgBLrt7Z6CIMWlG0HBG5hLBtqQ5odlQpslNhMxpJDRwst0TZurewykb3epe15vRKhZc03dg6oJKfs7uW7EjRyLDaI0= 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=GYUCu2Ju; arc=none smtp.client-ip=192.198.163.15 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="GYUCu2Ju" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744963265; x=1776499265; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NXyGilvlCSGNm4oXjjk/GmSnNnA0XjgRmH0GWjlpku4=; b=GYUCu2Ju9+mGSikU/EuQEvA7sih5vP9qc0zwDZyOPna8gqzf5H3xZNv5 QuljT/bJXZug33Rfu3/OkqmIt/4j2Esbf2+PXmgNL9LJWgf7p3Y1ZmSOW QkwklXFyF9tzgMsZWuOnRzRgNlS/+SB6C40LVkq9qiwn7uMPp0L8UlSh2 38YzpaMVH/Ccav8GjhOyg/VYWa6HdM5KA2HrG0+VfU+wcFwXW+WVzNjLs JAqXXvTHhObgbsG6znkb575MZfjFs+J2Ir5QvAbsxjS+Tevk+pg6PRRNM eZQ/UtXCMwOB6NoueBFX5Rv2RO9jzTvbHJeVMkeQt5mg1Wr1muRfZuclL g==; X-CSE-ConnectionGUID: 5YpeL+kBQ5u+bpg5tsKX2g== X-CSE-MsgGUID: VAKi/sKRTVSf/w1ptASoqw== X-IronPort-AV: E=McAfee;i="6700,10204,11406"; a="46708437" X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="46708437" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2025 01:01:05 -0700 X-CSE-ConnectionGUID: 36nM6vjxR2uL/Tz+0W5RQw== X-CSE-MsgGUID: kEUPXbI/SQW9WSyARnGWJg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="131358560" Received: from allen-box.sh.intel.com ([10.239.159.52]) by fmviesa008.fm.intel.com with ESMTP; 18 Apr 2025 01:01:02 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Dave Jiang , Vinod Koul , Fenghua Yu , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Jason Gunthorpe , Lu Baolu Subject: [PATCH v5 1/8] iommu/arm-smmu-v3: Put iopf enablement in the domain attach path Date: Fri, 18 Apr 2025 16:01:23 +0800 Message-ID: <20250418080130.1844424-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418080130.1844424-1-baolu.lu@linux.intel.com> References: <20250418080130.1844424-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 Tested-by: Zhangfei Gao Acked-by: Will Deacon --- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 86 +-------------- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 104 +++++++++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 39 ++----- 3 files changed, 90 insertions(+), 139 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 980cc6b33c43..0601dece0a0d 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 48d910399a1b..6cb875f98905 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2720,6 +2720,7 @@ static void arm_smmu_disable_pasid(struct arm_smmu_ma= ster *master) =20 static struct arm_smmu_master_domain * arm_smmu_find_master_domain(struct arm_smmu_domain *smmu_domain, + struct iommu_domain *domain, struct arm_smmu_master *master, ioasid_t ssid, bool nested_ats_flush) { @@ -2730,6 +2731,7 @@ arm_smmu_find_master_domain(struct arm_smmu_domain *s= mmu_domain, list_for_each_entry(master_domain, &smmu_domain->devices, devices_elm) { if (master_domain->master =3D=3D master && + master_domain->domain =3D=3D domain && master_domain->ssid =3D=3D ssid && master_domain->nested_ats_flush =3D=3D nested_ats_flush) return master_domain; @@ -2756,6 +2758,58 @@ 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, + struct arm_smmu_master_domain *master_domain) +{ + iommu_group_mutex_assert(master->dev); + + if (!IS_ENABLED(CONFIG_ARM_SMMU_V3_SVA)) + return; + + if (!master_domain || !master_domain->using_iopf) + 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) @@ -2772,15 +2826,17 @@ static void arm_smmu_remove_master_domain(struct ar= m_smmu_master *master, nested_ats_flush =3D to_smmu_nested_domain(domain)->enable_ats; =20 spin_lock_irqsave(&smmu_domain->devices_lock, flags); - master_domain =3D arm_smmu_find_master_domain(smmu_domain, master, ssid, - nested_ats_flush); + master_domain =3D arm_smmu_find_master_domain(smmu_domain, domain, master, + ssid, 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); + + arm_smmu_disable_iopf(master, master_domain); + kfree(master_domain); } =20 /* @@ -2853,12 +2909,19 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_= state *state, kfree(state->vmaster); return -ENOMEM; } + master_domain->domain =3D new_domain; master_domain->master =3D master; master_domain->ssid =3D state->ssid; if (new_domain->type =3D=3D IOMMU_DOMAIN_NESTED) 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 @@ -2878,9 +2941,9 @@ 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); kfree(state->vmaster); - return -EINVAL; + ret =3D -EINVAL; + goto err_iopf; } =20 if (state->ats_enabled) @@ -2899,6 +2962,12 @@ int arm_smmu_attach_prepare(struct arm_smmu_attach_s= tate *state, wmb(); } return 0; + +err_iopf: + arm_smmu_disable_iopf(master, master_domain); +err_free_master_domain: + kfree(master_domain); + return ret; } =20 /* @@ -3510,8 +3579,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) @@ -3596,18 +3664,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; } @@ -3623,16 +3681,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 dd1ad56ce863..ea41d790463e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -837,9 +837,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 */ @@ -915,8 +914,14 @@ void arm_smmu_make_sva_cd(struct arm_smmu_cd *target, struct arm_smmu_master_domain { struct list_head devices_elm; struct arm_smmu_master *master; + /* + * For nested domains the master_domain is threaded onto the S2 parent, + * this points to the IOMMU_DOMAIN_NESTED to disambiguate the masters. + */ + struct iommu_domain *domain; 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) @@ -995,11 +1000,6 @@ int arm_smmu_cmdq_issue_cmdlist(struct arm_smmu_devic= e *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); @@ -1009,31 +1009,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 Sun Dec 14 12:17:06 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 224F126B2B1 for ; Fri, 18 Apr 2025 08:01:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963270; cv=none; b=NqPWtDUzB/hnDnOXqt/uxCWpKMUENsgSQ0o5QuBph1ONYBT6UDYO0/G+PhwwrzIzAwBanneFHCJMFc4S3hkpZudLOzBswv9SBrYyC1PyP87TQQQKWXn3FN6Z60rZ3rMzy08sfM3F1AnkkgXsnno9GTTmc3IvUmzCOwR7GlnsOZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963270; c=relaxed/simple; bh=BOm3DIf88NOf46tYqguBLQX+n5JC5pFLUDkJxKKkypQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jvCftL90WMJdeiCxKE9AXjReSvcCIUdmH+N9LfTYgTxo6Zxf6vxPU4ujMW0njdBXiLWN6f1xH2vxS54GhKI+F3HEgmQvzmwgWTf48O2IMMccWYd3pZw6/gIJ18NNOGfBjQDnmyHTBO7Cg7vS9n0jpUPzTru0tPmWTWOfTDLqHZ0= 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=ARCRAcGg; arc=none smtp.client-ip=192.198.163.15 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="ARCRAcGg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744963269; x=1776499269; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BOm3DIf88NOf46tYqguBLQX+n5JC5pFLUDkJxKKkypQ=; b=ARCRAcGgzbQzIrRqRxKB2HpPVnLElhcYSjUkARoumN0ADyfAJXiCyhIL bSdALQGUQnoeaMzoQ7t3hSi2RuorYVpuqJFDwCfUMjnpvPlxiCnUEA/pa F0zrnPFIyHXL8wg9DmTU0/dr1e21ApSD2cN2SZKPWFpBsNSwT8swttrBA AoDL0ZYa8ETukk/HjrLUCum8RIXQ63EjiGuPqFQuwFNjjvAe5PvN1W4BW QPy2nI78OQONdSq1VWD0S5uhs8NXXaSHa4XB/YSVvEflMk+rX3zx4g7pq h5/49XF0kupaygycNaPuOynDHDV8VhYFEF0NPJMS/+d1G4T++w1/59Xjp g==; X-CSE-ConnectionGUID: HCGr6YBZSkeT2CrhHwm0Fg== X-CSE-MsgGUID: s5KDbiuETJa01j4NO7bWYw== X-IronPort-AV: E=McAfee;i="6700,10204,11406"; a="46708452" X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="46708452" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2025 01:01:09 -0700 X-CSE-ConnectionGUID: xMDROQwPQMeEK4mWg1r4zQ== X-CSE-MsgGUID: MJ5YZzceRy+P4a2ih5Nrmw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="131358570" Received: from allen-box.sh.intel.com ([10.239.159.52]) by fmviesa008.fm.intel.com with ESMTP; 18 Apr 2025 01:01:05 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Dave Jiang , Vinod Koul , Fenghua Yu , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Jason Gunthorpe , Lu Baolu , Yi Liu Subject: [PATCH v5 2/8] iommu: Remove IOMMU_DEV_FEAT_SVA Date: Fri, 18 Apr 2025 16:01:24 +0800 Message-ID: <20250418080130.1844424-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418080130.1844424-1-baolu.lu@linux.intel.com> References: <20250418080130.1844424-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 Reviewed-by: Kevin Tian Reviewed-by: Yi Liu Tested-by: Zhangfei Gao --- 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 fca1d2924999..2d3d580b9987 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 dea0fed7abb0..17aab6d04a13 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2991,7 +2991,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; @@ -3007,7 +3006,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 6cb875f98905..73f9885d20f1 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3664,7 +3664,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; @@ -3681,7 +3680,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 857c431d8ec5..4c3be92804e2 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3956,9 +3956,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; } @@ -3972,9 +3969,6 @@ intel_iommu_dev_disable_feat(struct device *dev, enum= iommu_dev_features feat) intel_iommu_disable_iopf(dev); return 0; =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 ab18bc494eef..944daa0dabd6 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 7e8c2af89799..bfdd2e71e124 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -318,18 +318,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 Sun Dec 14 12:17:06 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 63DBA26B94E for ; Fri, 18 Apr 2025 08:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963274; cv=none; b=GhOTk/NiU+pdSZhtnCsQY5K84o3ZVRA5IAvgGpMY0/CBO+xg8+ufuiIPwW0lCqBgOHdGndFoFhVuQFeEM8rHjdOkuVX/d2bspjC6wIEs2wOeW9HJDVh8BOEDDhrIyyyQTCFOGoNESNOtbNEHE1lW+AJcEHdTVzauypB+1jW3+UU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963274; c=relaxed/simple; bh=lVKb2Ow+iC1sIAH6K7AYwMND/hrpD+cM6y844vnRWGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JWrPdm56oU7vDdzDRZGIvEze+fN3b/c6gKn7BHN5jrlicgnGQ9KmMBUiIG3AfRKIXFEKBm2+u7mcICkyzrnm1AdrxTCnPu6tKEGirbLtpSdCC+Jear2PMc9Sy7HHUW+GV2/IpzTV+snbgoLOwCiKFmzlB5vI9EddUEX5RubU0mg= 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=flOog56r; arc=none smtp.client-ip=192.198.163.15 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="flOog56r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744963272; x=1776499272; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lVKb2Ow+iC1sIAH6K7AYwMND/hrpD+cM6y844vnRWGA=; b=flOog56rj9Yfa+k4A0JiyXhf51tPkNTSgCZA8ZE9Z49shP6DLxg4GLeQ nVJKyyepmdmlt90KbQOq6ols3GJlKArrNwikWc+HeEi65mShTkNhkWKOM mEWqHv7hzVYPfCiKiIWmukNzgd/ABVyWgNomMb/wiLdzwau6mD0urOLL8 zFTLITtx6jCK7/hYzWmtbHXOG7jvbO0hFj5vipVjOESfWJV/TD9v4J6Gj 9m3ozdSyJBePmlZ7vg3oZ1aXT2dq9QOZ+L6ejmMwCvK3ENR731wZ/r5V0 X6E1GravwuQnMvWi6H5tKpkoAiRFuDx51avPXjR7HaiIOipKbMA0pXKaD Q==; X-CSE-ConnectionGUID: 0mMDRdLBRIG58ZMeqFbkkQ== X-CSE-MsgGUID: vGyiEtCrTnK8TU9xjoEAlQ== X-IronPort-AV: E=McAfee;i="6700,10204,11406"; a="46708470" X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="46708470" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2025 01:01:12 -0700 X-CSE-ConnectionGUID: VCT4eEGuTkSUoU36JGFNNw== X-CSE-MsgGUID: jOYINdLOS8SbXu9HwBmimA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="131358593" Received: from allen-box.sh.intel.com ([10.239.159.52]) by fmviesa008.fm.intel.com with ESMTP; 18 Apr 2025 01:01:09 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Dave Jiang , Vinod Koul , Fenghua Yu , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , Yi Liu Subject: [PATCH v5 3/8] iommu/vt-d: Put iopf enablement in domain attach path Date: Fri, 18 Apr 2025 16:01:25 +0800 Message-ID: <20250418080130.1844424-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418080130.1844424-1-baolu.lu@linux.intel.com> References: <20250418080130.1844424-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 Reviewed-by: Kevin Tian Reviewed-by: Yi Liu Tested-by: Zhangfei Gao --- drivers/iommu/intel/iommu.c | 42 ++++++++++++++++++++++++++++++------ drivers/iommu/intel/iommu.h | 33 ++++++++++++++++++++++++++++ drivers/iommu/intel/nested.c | 16 ++++++++++++-- drivers/iommu/intel/svm.c | 9 ++++++-- 4 files changed, 90 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 4c3be92804e2..9af558390d42 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3284,6 +3284,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; } @@ -3494,7 +3497,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, @@ -3921,6 +3932,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; @@ -3943,6 +3956,7 @@ void intel_iommu_disable_iopf(struct device *dev) if (WARN_ON(!info->pri_enabled || !info->iopf_refcount)) return; =20 + iommu_group_mutex_assert(dev); if (--info->iopf_refcount) return; =20 @@ -3954,8 +3968,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; } @@ -3966,7 +3979,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: @@ -4047,6 +4059,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 @@ -4120,6 +4133,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); @@ -4127,7 +4144,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 @@ -4135,6 +4152,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; @@ -4349,6 +4368,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 @@ -4368,9 +4392,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 8d5d85bf0080..f9dcf0ab93d1 100644 --- a/drivers/iommu/intel/iommu.h +++ b/drivers/iommu/intel/iommu.h @@ -1297,6 +1297,39 @@ 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) +{ + int ret; + + ret =3D iopf_for_domain_set(new, dev); + if (ret) + return ret; + + iopf_for_domain_remove(old, 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 6ac5c534bef4..d2a94025d0a0 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 Sun Dec 14 12:17:06 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 DED3626E15F for ; Fri, 18 Apr 2025 08:01:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963277; cv=none; b=QbTMl+0zKBd/TxUJ0+oC1wM9mVQ93DDWbR/t80woqjdrbMOkGTUni/pE9N1kmdDZHyJeD3fuvgTAIsIRrVWbOluOB+noYPmKSJxDX0lCaUNP5CPfW151oCLMQtJWQXZmhxsHhqr3ur1gl4ceGlJRacRJzaZYzBDUD1HI8FgENTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963277; c=relaxed/simple; bh=BqVpy9UIaVKi4dFOxQ1AX2S2m4ehraAJ5mnL/a/Lylg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aB7P2OZ4drAbFsAIpqBKgKzXUGTLgxsEVJ6syfxA/RcGgxAXIZvI7T1VHYSn08m8nbNiaCRcWKNEMc8S9LqFry2BnvkJVHNkKI95wuO0vMuGbiDQdomnftpvOWtmAO5z+AFk4iqZs7jx7i5X/8BBnpgh+ed7LDFdyapJqt+JSMQ= 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=ZgG2Fpha; arc=none smtp.client-ip=192.198.163.15 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="ZgG2Fpha" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744963276; x=1776499276; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BqVpy9UIaVKi4dFOxQ1AX2S2m4ehraAJ5mnL/a/Lylg=; b=ZgG2FphaIDIfUNvZf3FbBYBWEmnPALlK998VtxAYAoUwRXEj46PhRBt6 u0ldoqWVNMv5Tr5lzbVVfk8eEXbbbc5p0dZ0syliz3IGTDguFVSOtDJRc bZ2i5sm6+SUU3bmZuMKwrl9ZMPc7nx5M1OrNqyZ7Lgyes330zveco9qfv EaagQVuun/T7C2AcGr2PuppA2aUTl5SAqWcHbNGwQ6tXpX9sHqIDR72pe bt9UEsQm1YNvER2tcGGwwMssT33+KZR6YJnhsa45uIJbZZFPwCPaixURQ q7wJfw5HVSR60G4KYhjaWNTaPvixC+UKz2lZe4AayBpvOV/y7hkKCzx8J g==; X-CSE-ConnectionGUID: C1wDWh9DTFaY4lhhIT3Clg== X-CSE-MsgGUID: /vsKRmmFTziDEnkn7zhW+Q== X-IronPort-AV: E=McAfee;i="6700,10204,11406"; a="46708490" X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="46708490" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2025 01:01:16 -0700 X-CSE-ConnectionGUID: aaibKIoRTgWTF1ECUN3q0g== X-CSE-MsgGUID: S/ckOaCKTbeYA0gwNqaOqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="131358607" Received: from allen-box.sh.intel.com ([10.239.159.52]) by fmviesa008.fm.intel.com with ESMTP; 18 Apr 2025 01:01:12 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Dave Jiang , Vinod Koul , Fenghua Yu , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , Yi Liu , Nicolin Chen Subject: [PATCH v5 4/8] iommufd/selftest: Put iopf enablement in domain attach path Date: Fri, 18 Apr 2025 16:01:26 +0800 Message-ID: <20250418080130.1844424-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418080130.1844424-1-baolu.lu@linux.intel.com> References: <20250418080130.1844424-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 Reviewed-by: Kevin Tian Reviewed-by: Yi Liu Reviewed-by: Nicolin Chen Tested-by: Zhangfei Gao --- drivers/iommu/iommufd/selftest.c | 57 ++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selft= est.c index 18d9a216eb30..6bd0abf9a641 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. @@ -168,6 +171,8 @@ struct mock_dev { int id; u32 cache[MOCK_DEV_CACHE_NUM]; atomic_t pasid_1024_fake_error; + unsigned int iopf_refcount; + struct iommu_domain *domain; }; =20 static inline struct mock_dev *to_mock_dev(struct device *dev) @@ -221,6 +226,13 @@ static int mock_domain_nop_attach(struct iommu_domain = *domain, up_write(&mdev->viommu_rwsem); } =20 + rc =3D mock_dev_enable_iopf(dev, domain); + if (rc) + return rc; + + mock_dev_disable_iopf(dev, mdev->domain); + mdev->domain =3D domain; + return 0; } =20 @@ -229,6 +241,7 @@ static int mock_domain_set_dev_pasid_nop(struct iommu_d= omain *domain, struct iommu_domain *old) { struct mock_dev *mdev =3D to_mock_dev(dev); + int rc; =20 /* * Per the first attach with pasid 1024, set the @@ -256,6 +269,12 @@ static int mock_domain_set_dev_pasid_nop(struct iommu_= domain *domain, } } =20 + rc =3D mock_dev_enable_iopf(dev, domain); + if (rc) + return rc; + + mock_dev_disable_iopf(dev, old); + return 0; } =20 @@ -610,22 +629,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 || !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 || !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) @@ -770,8 +809,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 Sun Dec 14 12:17:06 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 74C1126F471 for ; Fri, 18 Apr 2025 08:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963281; cv=none; b=RcfubqUADouh5fQmJ8o8qCPxSw06bj29PDeXQwpJqxmd7jl4XaPkbQz1wjZNz/GxPTe2Kbu2YP12IGRud4wj8h8IP0CdgLruOPg67HBuCII0jujTUoiIma8GD0+fWB4HXODWCIcS0b1gLsfWECfpU6j3pyA9JWrqZtYypPCeC3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963281; c=relaxed/simple; bh=ZeubqJaRkuiDA0ErRuZaIfkl9p/7c0alatni61LxmiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RzOboIovEKnpJIUbOdma4FtDyAZNncDF0xFLeRthKVqwnzIg9grEgTeFp8cKyko2iKkCbvAaT9bsTs4H5o28wk/2nSGmeT9EpFmsIxqT78yTT/h7g/bVSUnsvllpwCRZ0xSFHv0R8JTXRDkhe3liPDI/D0/08zmfTX6DD+WFpjA= 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=h6C9wkw4; arc=none smtp.client-ip=192.198.163.15 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="h6C9wkw4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744963279; x=1776499279; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZeubqJaRkuiDA0ErRuZaIfkl9p/7c0alatni61LxmiE=; b=h6C9wkw4J+tkS58AkDoYkqWTqamjh8b0CI5bE0Xu0R0pnjmOZuKAna+k A2nFtdwM/hfIlfltI7cc9gZkJA01mwcSnZcgfrKslaSXwR1e5VWvATGEQ 47v59c6iPAQ6I/jKbQDIRaHJCQZFLEMSK48+fnFpCzp+66EaQnIOmqH7Y 7GZPe3miybGtnQN/M974EoiM+7ilTn125LA2QjcEpwZ7MOSCZYwyNZIlp rlMUQsoRLyrCGBpqU+ob3sBi7Yu1AwTQSlm3tmgz03XkHsPB/Ov1V5J9f yN+Q5eEQfo8YJgqagdkIGoV7URDvO05o4u0go/5w/SC/mMmh6uZQSQ8+i g==; X-CSE-ConnectionGUID: cRYxwnBERgiEFeS7bolqeQ== X-CSE-MsgGUID: h+eX6X6wQM22z4IFq27TFA== X-IronPort-AV: E=McAfee;i="6700,10204,11406"; a="46708507" X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="46708507" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2025 01:01:19 -0700 X-CSE-ConnectionGUID: AIW8Xdo4SK6knBdPHXYprQ== X-CSE-MsgGUID: aIfgws75R2qI5HgcIC8Vww== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="131358625" Received: from allen-box.sh.intel.com ([10.239.159.52]) by fmviesa008.fm.intel.com with ESMTP; 18 Apr 2025 01:01:16 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Dave Jiang , Vinod Koul , Fenghua Yu , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe , Yi Liu Subject: [PATCH v5 5/8] dmaengine: idxd: Remove unnecessary IOMMU_DEV_FEAT_IOPF Date: Fri, 18 Apr 2025 16:01:27 +0800 Message-ID: <20250418080130.1844424-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418080130.1844424-1-baolu.lu@linux.intel.com> References: <20250418080130.1844424-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 Reviewed-by: Kevin Tian Reviewed-by: Yi Liu Tested-by: Zhangfei Gao --- 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 2d3d580b9987..9e739a4d1ecd 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 /* @@ -1247,8 +1224,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 Sun Dec 14 12:17:06 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 9649326FD85 for ; Fri, 18 Apr 2025 08:01:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963284; cv=none; b=mJD10d7gQO9hTLJblEDUAXkcjQX9sRZ6PEnZxiMr/bOsUNL/z5jnvhWlwL6kpR0XZ3r0j5PIZ/iTPrOt9eqdx20E7Vs1ynIEBU7qc5jK/6xl82ySysF6VuzS7s+fAESbG6NWvp1mF1vTKquHzUaCchIfyz/+ehMJDn27pQhKonw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963284; c=relaxed/simple; bh=QnZI5g5/imwILnMF97Mve/8kvZvqDgLUw+ieihDhkwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k7Cvd+Qjt0ct7DECcPrvstTH+oHiOVRdQBK7raGL55RND3e2AGelFfUsS0qaF6St07aVxHwDxzy8B+rXnlVkTulhQdX8eoynRRiwiyzanI2ieeUcVzOECbPjZ9drYcm96Eo2otdsTNkHOfrCtetpIbBTpVHsaxWZrMDEFJ/BlRU= 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=JBCBqsGs; arc=none smtp.client-ip=192.198.163.15 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="JBCBqsGs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744963283; x=1776499283; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QnZI5g5/imwILnMF97Mve/8kvZvqDgLUw+ieihDhkwQ=; b=JBCBqsGsdysJTlcogWzoZoxi3BSktgD51ctQIWnlaTtDjgYmwzmjORZC SD3SeYhA1oaBicMaWux+yDMfHMdUWqrRNXYEz9q8aUhFkPDq4zVkpdciF sv3jiQPNL9MaBBVBQKWVMfTjIiMI37LNek0naNGnmv1/RnoD092Sqqgji nqkUndvPbzJ+ZTcyAEUfrTmJlfaZ0YAMYSrtfiekGIc8sPLfKSvrd9mJ7 QXvqDgqes7LAFyiPgPxx2xHGjaURsGu4vhghgUo6JJ5t/ens6Rz5gztBS qrIi/ZtKnaxPKH3btfpdZdaePwQHgpFZRiczIcwT0OFqzxWR30tfezSIS g==; X-CSE-ConnectionGUID: Od1Ph7sURBK6YDd1wqnKCw== X-CSE-MsgGUID: 1W+DZTe+T9+QYp7SGN9uqw== X-IronPort-AV: E=McAfee;i="6700,10204,11406"; a="46708520" X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="46708520" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2025 01:01:22 -0700 X-CSE-ConnectionGUID: SHU+f8poSBCK5dv5GR5zHw== X-CSE-MsgGUID: EUkloXf1RsCe5AXiyyCIPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="131358642" Received: from allen-box.sh.intel.com ([10.239.159.52]) by fmviesa008.fm.intel.com with ESMTP; 18 Apr 2025 01:01:19 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Dave Jiang , Vinod Koul , Fenghua Yu , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v5 6/8] uacce: Remove unnecessary IOMMU_DEV_FEAT_IOPF Date: Fri, 18 Apr 2025 16:01:28 +0800 Message-ID: <20250418080130.1844424-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418080130.1844424-1-baolu.lu@linux.intel.com> References: <20250418080130.1844424-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 Reviewed-by: Kevin Tian Acked-by: Zhangfei Gao Tested-by: Zhangfei Gao --- 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 Sun Dec 14 12:17:06 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 0BAC626B2C4 for ; Fri, 18 Apr 2025 08:01:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963287; cv=none; b=pNBTBfcSooBuAQGOjaol1lkgUa2Oa29DHEfV5EQvNW5jPyoEPxTTzvJlHSImH4BsrnkNxc/LR+svT1bmFhIrtBOa/wng4I2N2IPSg+2W0LSPSPxGTGLs6XDJEDGC09NMOKDGineXj3F6mO6EQLt4hPCfhy69TH/WKnQ+OjCFpYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963287; c=relaxed/simple; bh=2ivYTc1Aw/K7/4eZ2gxR9fOzWvHJ5qgw1szy/sntLAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fZsrrRZEUCzyJN7MxUslxKkOZmHQBDxrFMt7GcNoLTWB5zdvPBzgkFi/eGDIjnowBI6K1JVlJfVOkcIUquCnJLWOAZxHslK9qPdmz4tDp+EeoLClSyc5BMJ7h1RNXlK2vgIlTtAQt3zDvMyGTKoaNfnBOK7GlTHhf/hZTn3XyGc= 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=HL/pzvpU; arc=none smtp.client-ip=192.198.163.15 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="HL/pzvpU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744963286; x=1776499286; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2ivYTc1Aw/K7/4eZ2gxR9fOzWvHJ5qgw1szy/sntLAU=; b=HL/pzvpUX370dwi+s+rSawCydz8RoUreg89K95GYImbnW4993nGYlqqH LNIyWUMz04GoGq7Lgwu1RaCTPYjggmeLz57Hyht7Uewtf9cM+0htm6OS2 aZz61JTIv2/z8zlKysMBDUTjK9zad3TgXogOwV/CbfnFzLF2/3gLi82eJ a+Gxc47T67H+/V3gZL32wRtf8qq4rEhNtn5vXK/7B7Ji3CYjMm48jzCCt fVoHmi7+Yu630KUs0QXS5iYEAi3eWDgEQT9ySTH48M/+IXSP1EunuVNAu cpn84NMxXN+F0+CKWZ4/59UAfYx1Fa0pMgycsRXTEWmn8ZZVuAF1v61ne Q==; X-CSE-ConnectionGUID: vwV3VAr3T9mJLZsYmMl/4Q== X-CSE-MsgGUID: G3EIbc7BR5qfZFu1DQD6Tw== X-IronPort-AV: E=McAfee;i="6700,10204,11406"; a="46708539" X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="46708539" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2025 01:01:26 -0700 X-CSE-ConnectionGUID: Q8sUrZy6Q0KxwUpx6k1Y+g== X-CSE-MsgGUID: rikO5Jo4Req/26nNS6CRVQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="131358674" Received: from allen-box.sh.intel.com ([10.239.159.52]) by fmviesa008.fm.intel.com with ESMTP; 18 Apr 2025 01:01:22 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Dave Jiang , Vinod Koul , Fenghua Yu , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v5 7/8] iommufd: Remove unnecessary IOMMU_DEV_FEAT_IOPF Date: Fri, 18 Apr 2025 16:01:29 +0800 Message-ID: <20250418080130.1844424-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418080130.1844424-1-baolu.lu@linux.intel.com> References: <20250418080130.1844424-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 Reviewed-by: Kevin Tian Tested-by: Zhangfei Gao --- drivers/iommu/iommufd/device.c | 59 ++++++++++++------------- drivers/iommu/iommufd/eventq.c | 48 +------------------- drivers/iommu/iommufd/iommufd_private.h | 6 --- 3 files changed, 30 insertions(+), 83 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 2111bad72c72..86244403b532 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -221,7 +221,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 @@ -425,6 +424,25 @@ static int iommufd_hwpt_pasid_compat(struct iommufd_hw= _pagetable *hwpt, return 0; } =20 +static bool iommufd_hwpt_compatible_device(struct iommufd_hw_pagetable *hw= pt, + struct iommufd_device *idev) +{ + struct pci_dev *pdev; + + if (!hwpt->fault || !dev_is_pci(idev->dev)) + return true; + + /* + * 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. + */ + pdev =3D to_pci_dev(idev->dev); + + return (!pdev->is_virtfn || !pci_pri_supported(pdev)); +} + static int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev, ioasid_t pasid) @@ -432,6 +450,9 @@ static int iommufd_hwpt_attach_device(struct iommufd_hw= _pagetable *hwpt, struct iommufd_attach_handle *handle; int rc; =20 + if (!iommufd_hwpt_compatible_device(hwpt, idev)) + return -EINVAL; + rc =3D iommufd_hwpt_pasid_compat(hwpt, idev, pasid); if (rc) return rc; @@ -440,12 +461,6 @@ static int iommufd_hwpt_attach_device(struct iommufd_h= w_pagetable *hwpt, if (!handle) return -ENOMEM; =20 - if (hwpt->fault) { - rc =3D iommufd_fault_iopf_enable(idev); - if (rc) - goto out_free_handle; - } - handle->idev =3D idev; if (pasid =3D=3D IOMMU_NO_PASID) rc =3D iommu_attach_group_handle(hwpt->domain, idev->igroup->group, @@ -454,13 +469,10 @@ static int iommufd_hwpt_attach_device(struct iommufd_= hw_pagetable *hwpt, rc =3D iommu_attach_device_pasid(hwpt->domain, idev->dev, pasid, &handle->handle); if (rc) - goto out_disable_iopf; + goto out_free_handle; =20 return 0; =20 -out_disable_iopf: - if (hwpt->fault) - iommufd_fault_iopf_disable(idev); out_free_handle: kfree(handle); return rc; @@ -492,10 +504,7 @@ static void iommufd_hwpt_detach_device(struct iommufd_= hw_pagetable *hwpt, else iommu_detach_device_pasid(hwpt->domain, idev->dev, pasid); =20 - if (hwpt->fault) { - iommufd_auto_response_faults(hwpt, handle); - iommufd_fault_iopf_disable(idev); - } + iommufd_auto_response_faults(hwpt, handle); kfree(handle); } =20 @@ -507,6 +516,9 @@ static int iommufd_hwpt_replace_device(struct iommufd_d= evice *idev, struct iommufd_attach_handle *handle, *old_handle; int rc; =20 + if (!iommufd_hwpt_compatible_device(hwpt, idev)) + return -EINVAL; + rc =3D iommufd_hwpt_pasid_compat(hwpt, idev, pasid); if (rc) return rc; @@ -517,12 +529,6 @@ static int iommufd_hwpt_replace_device(struct iommufd_= device *idev, if (!handle) return -ENOMEM; =20 - if (hwpt->fault && !old->fault) { - rc =3D iommufd_fault_iopf_enable(idev); - if (rc) - goto out_free_handle; - } - handle->idev =3D idev; if (pasid =3D=3D IOMMU_NO_PASID) rc =3D iommu_replace_group_handle(idev->igroup->group, @@ -531,20 +537,13 @@ static int iommufd_hwpt_replace_device(struct iommufd= _device *idev, rc =3D iommu_replace_device_pasid(hwpt->domain, idev->dev, pasid, &handle->handle); if (rc) - goto out_disable_iopf; + goto out_free_handle; =20 - if (old->fault) { - iommufd_auto_response_faults(hwpt, old_handle); - if (!hwpt->fault) - iommufd_fault_iopf_disable(idev); - } + iommufd_auto_response_faults(hwpt, old_handle); kfree(old_handle); =20 return 0; =20 -out_disable_iopf: - if (hwpt->fault && !old->fault) - iommufd_fault_iopf_disable(idev); out_free_handle: kfree(handle); return rc; diff --git a/drivers/iommu/iommufd/eventq.c b/drivers/iommu/iommufd/eventq.c index f39cf0797347..e373b9eec7f5 100644 --- a/drivers/iommu/iommufd/eventq.c +++ b/drivers/iommu/iommufd/eventq.c @@ -9,8 +9,6 @@ #include #include #include -#include -#include #include #include =20 @@ -18,50 +16,6 @@ #include "iommufd_private.h" =20 /* IOMMUFD_OBJ_FAULT Functions */ - -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; -} - -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); -} - void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt, struct iommufd_attach_handle *handle) { @@ -70,7 +24,7 @@ void iommufd_auto_response_faults(struct iommufd_hw_paget= able *hwpt, struct list_head free_list; unsigned long index; =20 - if (!fault) + if (!fault || !handle) return; INIT_LIST_HEAD(&free_list); =20 diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommuf= d/iommufd_private.h index 80e8c76d25f2..9ccc83341f32 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -425,9 +425,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 * @@ -506,9 +503,6 @@ iommufd_get_fault(struct iommufd_ucmd *ucmd, u32 id) int iommufd_fault_alloc(struct iommufd_ucmd *ucmd); void iommufd_fault_destroy(struct iommufd_object *obj); int iommufd_fault_iopf_handler(struct iopf_group *group); - -int iommufd_fault_iopf_enable(struct iommufd_device *idev); -void iommufd_fault_iopf_disable(struct iommufd_device *idev); void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt, struct iommufd_attach_handle *handle); =20 --=20 2.43.0 From nobody Sun Dec 14 12:17:06 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (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 874DE270EA0 for ; Fri, 18 Apr 2025 08:01:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963291; cv=none; b=q/zmFvpgNWAXaKnqxuQ2k9CeQITAJL4BZLdlUlAyzm/S3Z2YSTEJPnlbnAEaFtkh5uk4/wySf7pqIdg9aQ/69dT5EzlRXjOhPxsuDs3YN73Er7+96oyNG6v/vIewILxf8mw00URjOqk9bOlda7BzzXkyj4h/nBG9qYIVEWYT9Lc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744963291; c=relaxed/simple; bh=xHvdqCW9VAdclXNKbC1MlwSO7w2MFGw/1Ft2J9d8fQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iHb5s1NP+a9/h1/i2af1vHyVLwUm1MGAcV7Q4cf0rAPg39wX6Pc3Hyixb6IPM1NPMI5BrvRQtH+d9xHtr3fv0RanP3IRkNipOLvba6ZTydSTfk2ftD/+ODsQtAe1ybB8HeTBepxgP/zxef4ONuGNjJb8xUG4DScPGilh49tB2jY= 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=kAy/tkpf; arc=none smtp.client-ip=192.198.163.15 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="kAy/tkpf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1744963289; x=1776499289; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xHvdqCW9VAdclXNKbC1MlwSO7w2MFGw/1Ft2J9d8fQM=; b=kAy/tkpfVXfR60FyJ89snIKeu9YYQPG418vlWSrlo0Yf+NABZl6N9EmB LIA1rosHucjtyOaz3YcpgERoy/iuEfZfgYEhsM/qq1e3iZ8Zxg0hSBLA6 mNUx23APqkH9JIVTyUhI8+0Sz662GsA5FzDo1ZSFIrlFtQJC0NmGCgqGS B0orsHvRkF5nwTDXtTolV5iW9xfDx6d1mt3/t6Xx7BtI7Bjhk9nTYQ3ks aa2EOLuCoqmS1PwNKCgwPq45lxhOWZCq0ypean42JKFqnRaPlrp97jJt7 f+3sH+yGvRl00MkIH2z4irftBGDvygyCEE+nOkVUQzKfYgWDShISPLo23 A==; X-CSE-ConnectionGUID: DGzxR41dTgaxIAbQPM2RTw== X-CSE-MsgGUID: FN6iKs06TNS1w1Q+FPllsw== X-IronPort-AV: E=McAfee;i="6700,10204,11406"; a="46708554" X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="46708554" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2025 01:01:29 -0700 X-CSE-ConnectionGUID: W5K9zok5TFOqHy2BBJ4TUw== X-CSE-MsgGUID: bnsmEDeQSu+2qGeTkk4tyw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.15,221,1739865600"; d="scan'208";a="131358694" Received: from allen-box.sh.intel.com ([10.239.159.52]) by fmviesa008.fm.intel.com with ESMTP; 18 Apr 2025 01:01:26 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Dave Jiang , Vinod Koul , Fenghua Yu , Zhangfei Gao , Zhou Wang , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu , Jason Gunthorpe Subject: [PATCH v5 8/8] iommu: Remove iommu_dev_enable/disable_feature() Date: Fri, 18 Apr 2025 16:01:30 +0800 Message-ID: <20250418080130.1844424-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250418080130.1844424-1-baolu.lu@linux.intel.com> References: <20250418080130.1844424-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 Reviewed-by: Kevin Tian Tested-by: Zhangfei Gao --- 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 17aab6d04a13..a9d539fce982 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2984,36 +2984,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, @@ -3027,8 +2997,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 73f9885d20f1..e91d20e5785e 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -3654,38 +3654,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 @@ -3718,8 +3686,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 9af558390d42..93bc6574d148 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3963,29 +3963,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); @@ -4428,8 +4405,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 264383b507bc..df283bddf6cd 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2910,38 +2910,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 bfdd2e71e124..5c05c0851f9f 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -316,16 +316,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) @@ -657,9 +647,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 @@ -1128,9 +1115,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 @@ -1415,18 +1399,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