From nobody Sun Dec 14 19:19:41 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