From patchwork Wed May 29 05:32:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E347DC25B7C for ; Wed, 29 May 2024 05:36:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4F72A11307D; Wed, 29 May 2024 05:36:20 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="VaGQefDP"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id C84B1113028 for ; Wed, 29 May 2024 05:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960972; x=1748496972; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WX+m07wt3DtPAOjU2K7TAng/knQriugPLDZHnttGpjU=; b=VaGQefDPRkneW/E9Kbi0WwIjw2vmsXbpcmSzPcSRbGV66YqmM3cZqVp/ rsTdMRTgrrnJBp2tMbmBKZRUAqK90FkcmszS9LA53ibTl8V+iSPqeaDXb 0Myen88Qex7ersTUSyR3It0D7h9ldQyQTXIO1EVtENUJRarYOeHuO6Y8b o5i6a0heX4iv4k3fx6gAbL6OG94O+w7kmBMbhPntv1hg6vcfndTcQDYDw Uu4OXA4N/acsnWVcAiA0caYRMSDBwIYZGrjcwpQDUUsZCXWyPuKTD+c2C qSsFF94SyLUSe/Q7eWBMcY2goi5eRkSnFfVNigtOvye17Zh+kjkiEIAoH g==; X-CSE-ConnectionGUID: 0X1u3uUIRjOM6B+7khNqXQ== X-CSE-MsgGUID: g4zKeTIuTmic0zHm/rjI2A== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568753" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568753" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:06 -0700 X-CSE-ConnectionGUID: ff5BmhNMSBOq/6aqKuHlTw== X-CSE-MsgGUID: VRTTk5mGQciwJeBPrShRDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257451" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:01 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 01/20] iommu: Add iommu_user_domain_alloc() interface Date: Wed, 29 May 2024 13:32:31 +0800 Message-Id: <20240529053250.91284-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Commit <909f4abd1097> ("iommu: Add new iommu op to create domains owned by userspace") added a dedicated iommu op to allocate a user domain. While IOMMUFD has already made use of this callback, other frameworks like vfio/type1 and vDPA still use the paging domain allocation interface. Add a new interface named iommu_user_domain_alloc(), which indicates the allocation of a domain for device DMA managed by user space driver. All device passthrough frameworks could use this interface for their domain allocation. Although it is expected that all iommu drivers could implement their own domain_alloc_user ops, most drivers haven't implemented it yet. Rollback to the paging domain allocation interface if the iommu driver hasn't implemented this op yet. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 6 ++++++ drivers/iommu/iommu.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 7bc8dff7cf6d..6648b2415474 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -780,6 +780,7 @@ extern bool iommu_present(const struct bus_type *bus); extern bool device_iommu_capable(struct device *dev, enum iommu_cap cap); extern bool iommu_group_has_isolated_msi(struct iommu_group *group); extern struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus); +struct iommu_domain *iommu_user_domain_alloc(struct device *dev, u32 flags); extern void iommu_domain_free(struct iommu_domain *domain); extern int iommu_attach_device(struct iommu_domain *domain, struct device *dev); @@ -1086,6 +1087,11 @@ static inline struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus return NULL; } +static inline struct iommu_domain *iommu_user_domain_alloc(struct device *dev, u32 flags) +{ + return ERR_PTR(-ENODEV); +} + static inline void iommu_domain_free(struct iommu_domain *domain) { } diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 9df7cc75c1bc..f1416892ef8e 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2032,6 +2032,48 @@ struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus) } EXPORT_SYMBOL_GPL(iommu_domain_alloc); +/** + * iommu_user_domain_alloc() - Allocate a user domain + * @dev: device for which the domain is allocated + * @flags: iommufd_hwpt_alloc_flags defined in uapi/linux/iommufd.h + * + * Allocate a user domain which will be managed by a userspace driver. Return + * allocated domain if successful, or a ERR pointer for failure. + */ +struct iommu_domain *iommu_user_domain_alloc(struct device *dev, u32 flags) +{ + struct iommu_domain *domain; + const struct iommu_ops *ops; + + if (!dev_has_iommu(dev)) + return ERR_PTR(-ENODEV); + + ops = dev_iommu_ops(dev); + if (ops->domain_alloc_user) { + domain = ops->domain_alloc_user(dev, flags, NULL, NULL); + if (IS_ERR(domain)) + return domain; + + domain->type = IOMMU_DOMAIN_UNMANAGED; + domain->owner = ops; + domain->pgsize_bitmap = ops->pgsize_bitmap; + domain->ops = ops->default_domain_ops; + + return domain; + } + + /* + * The iommu driver doesn't support domain_alloc_user callback. + * Rollback to a UNMANAGED paging domain which doesn't support + * the allocation flags. + */ + if (flags) + return ERR_PTR(-EOPNOTSUPP); + + return __iommu_domain_alloc(ops, dev, IOMMU_DOMAIN_UNMANAGED); +} +EXPORT_SYMBOL_GPL(iommu_user_domain_alloc); + void iommu_domain_free(struct iommu_domain *domain) { if (domain->type == IOMMU_DOMAIN_SVA) From patchwork Wed May 29 05:32:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677846 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4A733C25B75 for ; Wed, 29 May 2024 05:36:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D6A51112324; Wed, 29 May 2024 05:36:13 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Sw+M80eX"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 13008113034 for ; Wed, 29 May 2024 05:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960972; x=1748496972; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i2g4o4FMSNI6vy56g2mVccrM+MuXNKNyXwoqmECaK9M=; b=Sw+M80eXVuj3vsA5/GVukWgXQq6e3kxxZGr5BekeLXHjiNSD0lYz/aRx of1HmBKp/S2IAPiDGBCf8EQ4FbgildLEXN8Kk42ZLW7hXCAPvMNN7f1aa sYXKOf67jxOLxfhAiQXHkB3+TaSF7i1oYanjgxyLewDDZG5IZQH9J1x4g RviNdTnnxFpDet2uJdP/YyKpitHXE4/6hqrUN6zbn0gfqTgbNkwLyzUig N/cMcK5F9yDtDC5tvW9cMeFcB/MZT5fn2E8L7hZcHiDWp0UgP4GyPlxvp a3tzuAcSQW4R6DOLldZe5e9wzFtLOlGPAq/Drh4/n0O7xarHcZTsBqK9Z Q==; X-CSE-ConnectionGUID: MD2jyBy/TKmTw4dCqJD82g== X-CSE-MsgGUID: 3Id+FhcaSg6VlpnovU2vRQ== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568768" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568768" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:11 -0700 X-CSE-ConnectionGUID: ooEsLAqOTEq37Hrx3ZeYbQ== X-CSE-MsgGUID: FAzliAhcS6u1szAMWmJLKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257473" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:06 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 02/20] iommufd: Use iommu_user_domain_alloc() Date: Wed, 29 May 2024 13:32:32 +0800 Message-Id: <20240529053250.91284-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Replace iommu_domain_alloc() with iommu_user_domain_alloc(). Signed-off-by: Lu Baolu --- drivers/iommu/iommufd/hw_pagetable.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c index 33d142f8057d..ada05fccb36a 100644 --- a/drivers/iommu/iommufd/hw_pagetable.c +++ b/drivers/iommu/iommufd/hw_pagetable.c @@ -127,21 +127,11 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas, hwpt_paging->ioas = ioas; hwpt_paging->nest_parent = flags & IOMMU_HWPT_ALLOC_NEST_PARENT; - if (ops->domain_alloc_user) { - hwpt->domain = ops->domain_alloc_user(idev->dev, flags, NULL, - user_data); - if (IS_ERR(hwpt->domain)) { - rc = PTR_ERR(hwpt->domain); - hwpt->domain = NULL; - goto out_abort; - } - hwpt->domain->owner = ops; - } else { - hwpt->domain = iommu_domain_alloc(idev->dev->bus); - if (!hwpt->domain) { - rc = -ENOMEM; - goto out_abort; - } + hwpt->domain = iommu_user_domain_alloc(idev->dev, flags); + if (IS_ERR(hwpt->domain)) { + rc = PTR_ERR(hwpt->domain); + hwpt->domain = NULL; + goto out_abort; } /* From patchwork Wed May 29 05:32:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B84CC27C44 for ; Wed, 29 May 2024 05:36:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C2B81130BF; Wed, 29 May 2024 05:36:21 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="lobssp4S"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 850F911307D for ; Wed, 29 May 2024 05:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960973; x=1748496973; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ku98pK7UgGN8K4Vqi8YCUxqt/MmWDBRD7GnhYQUhVEg=; b=lobssp4SlPn4FD1ObriFep3zHr2EfzpftuRLSaiCqAYyercF5DmOen01 b42zZie6swzm5d5oGOOrZof991iuwvThIkpdTnPTvm8+/PF0mhloFnjtR bEfbxJW2ftrZ1SBADTAWdRY7yx8NNotey854+PEXb9300+EDAuVsKaUpa dB1jG6gZ9QDmnVOKaG/e6bM7J/IhOPHrw6ttm9zN5rHpcD9gnuZLvA/sf ndfXF9kec00CJM0PcfhV5nmq3WjcABjFyPteYbbYl+0dow5ULY6vblbwG wGh3ETK4LeoG+5xlxLjmlgVaiavbkZ/XQyFA5k2E6moJo4YjKjJi1ZMJa A==; X-CSE-ConnectionGUID: CnHwhSt4TjaqDTbsXX8viA== X-CSE-MsgGUID: T5eSNWaBS8CGlUboTRyNtQ== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568790" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568790" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:16 -0700 X-CSE-ConnectionGUID: WiRHsEl4TRC1JXRxiW5i8g== X-CSE-MsgGUID: 4zBoCP3eR6Ce1YRhsCapLQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257489" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:11 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 03/20] vfio/type1: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:33 +0800 Message-Id: <20240529053250.91284-4-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Replace iommu_domain_alloc() with iommu_user_domain_alloc(). Signed-off-by: Lu Baolu --- drivers/vfio/vfio_iommu_type1.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 3a0218171cfa..1d553f7f7c26 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -2135,7 +2135,7 @@ static int vfio_iommu_domain_alloc(struct device *dev, void *data) { struct iommu_domain **domain = data; - *domain = iommu_domain_alloc(dev->bus); + *domain = iommu_user_domain_alloc(dev, 0); return 1; /* Don't iterate */ } @@ -2192,11 +2192,12 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, * us a representative device for the IOMMU API call. We don't actually * want to iterate beyond the first device (if any). */ - ret = -EIO; iommu_group_for_each_dev(iommu_group, &domain->domain, vfio_iommu_domain_alloc); - if (!domain->domain) + if (IS_ERR(domain->domain)) { + ret = PTR_ERR(domain->domain); goto out_free_domain; + } if (iommu->nesting) { ret = iommu_enable_nesting(domain->domain); From patchwork Wed May 29 05:32:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4E52EC25B75 for ; Wed, 29 May 2024 05:36:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD5BC113124; Wed, 29 May 2024 05:36:37 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Sx2vINgs"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB2B3112324 for ; Wed, 29 May 2024 05:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960973; x=1748496973; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ybhIC+9D0FzFiBqGh0zAWkB79mgKE5w60y1oFabl/b8=; b=Sx2vINgsakEj17UX+hvm9gozdsF9n+3Vor+HTfPXeMG9JMpFxT0HdX8D SUGiAADIgz2aVfCoBViOcK/L/rBnksfDPfbQtuQWHOsUFYZZjSSN00YBU qArX/Wpvc3p4ofZoSpB8pIIibemn2unMw3Edb1l6VV3GznvXTNP/ulj/b sQ+F0UyHAZ0o6T4KDYhZfpNJDurxIJBLs0ONxM8PHNAucGrjzId/nzcYp 03XkJrhNG3zQA5EsHxpDcHzgqqWmi1Q4JuMK9tKjldeu/+BqucXB3HwQS ULoFjwURH1rBsg928XqITx/BBpXF3f5x17ShOt6RYzIVbr9WNv2buWMVg A==; X-CSE-ConnectionGUID: qvkuLEx5TsKXxaw7907V+g== X-CSE-MsgGUID: lV2H01SJQcyhSca3AuyNrw== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568810" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568810" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:20 -0700 X-CSE-ConnectionGUID: Lx3ESut/QGCW7lfZ/TNLuA== X-CSE-MsgGUID: oyY1KD/nRaOxmUib4QeiUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257522" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:15 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 04/20] vhost-vdpa: Use iommu_user_domain_alloc() Date: Wed, 29 May 2024 13:32:34 +0800 Message-Id: <20240529053250.91284-5-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Replace iommu_domain_alloc() with iommu_user_domain_alloc(). Signed-off-by: Lu Baolu --- drivers/vhost/vdpa.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 63a53680a85c..7784218fd9d2 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -1312,26 +1312,21 @@ static int vhost_vdpa_alloc_domain(struct vhost_vdpa *v) struct vdpa_device *vdpa = v->vdpa; const struct vdpa_config_ops *ops = vdpa->config; struct device *dma_dev = vdpa_get_dma_dev(vdpa); - const struct bus_type *bus; int ret; /* Device want to do DMA by itself */ if (ops->set_map || ops->dma_map) return 0; - bus = dma_dev->bus; - if (!bus) - return -EFAULT; - if (!device_iommu_capable(dma_dev, IOMMU_CAP_CACHE_COHERENCY)) { dev_warn_once(&v->dev, "Failed to allocate domain, device is not IOMMU cache coherent capable\n"); return -ENOTSUPP; } - v->domain = iommu_domain_alloc(bus); - if (!v->domain) - return -EIO; + v->domain = iommu_user_domain_alloc(dma_dev, 0); + if (IS_ERR(v->domain)) + return PTR_ERR(v->domain); ret = iommu_attach_device(v->domain, dma_dev); if (ret) From patchwork Wed May 29 05:32:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90D21C25B75 for ; Wed, 29 May 2024 05:36:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 96562113034; Wed, 29 May 2024 05:36:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="G3+6zYeD"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4B56D113034 for ; Wed, 29 May 2024 05:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960974; x=1748496974; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xf05GvXEO+I215J3GQWK9zqCkzSYPhbVb/+Tz/JkYCQ=; b=G3+6zYeD+mjYTJww6E/DHC/b4MF+jX+lJ8CbJKXyk5DakmL2zA2Szohs BBhsye2DWJ+rENNilYHsipZWVhcdfoJt5/twUADc5z1pgDuzW7b87gXdi NDum1WEg82K+/OBSlWy8MjvUkaz2ujU1LNW0OWG+NrkXKsEKeEHb0oc48 gxHCpXlyJui2owOIBjMuLgNYD6wQ4a17vEAfFKanE/2+7Bll+Xbfnb0F8 rkGmAQVCVTs4rRKjbmezEmRzUIKW3Cy3jKcSZGcIiqiJuWviA2jy96OZb 6zepFmDhyHHauoj7Yj9A5XTfW/4mLjCZkp212Uk0/6jm7SVVxHwAt2H5c w==; X-CSE-ConnectionGUID: 1g5a3aJAQxGajdYmj16plg== X-CSE-MsgGUID: Bmtxo+3wR3iWSQyw5rNwiQ== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568829" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568829" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:25 -0700 X-CSE-ConnectionGUID: WkFEj6PrQYqnAeoLtI1GfQ== X-CSE-MsgGUID: eszOZrvySa+kJnN3MKgnnw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257546" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:20 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 05/20] iommu: Add iommu_paging_domain_alloc() interface Date: Wed, 29 May 2024 13:32:35 +0800 Message-Id: <20240529053250.91284-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Commit <17de3f5fdd35> ("iommu: Retire bus ops") removes iommu ops from bus. The iommu subsystem no longer relies on bus for operations. So the bus parameter in iommu_domain_alloc() is no longer relevant. Add a new interface named iommu_paging_domain_alloc(), which explicitly indicates the allocation of a paging domain for DMA managed by a kernel driver. The new interface takes a device pointer as its parameter, that better aligns with the current iommu subsystem. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 6 ++++++ drivers/iommu/iommu.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 6648b2415474..16401de7802d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -781,6 +781,7 @@ extern bool device_iommu_capable(struct device *dev, enum iommu_cap cap); extern bool iommu_group_has_isolated_msi(struct iommu_group *group); extern struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus); struct iommu_domain *iommu_user_domain_alloc(struct device *dev, u32 flags); +struct iommu_domain *iommu_paging_domain_alloc(struct device *dev); extern void iommu_domain_free(struct iommu_domain *domain); extern int iommu_attach_device(struct iommu_domain *domain, struct device *dev); @@ -1092,6 +1093,11 @@ static inline struct iommu_domain *iommu_user_domain_alloc(struct device *dev, u return ERR_PTR(-ENODEV); } +static inline struct iommu_domain *iommu_paging_domain_alloc(struct device *dev) +{ + return ERR_PTR(-ENODEV); +} + static inline void iommu_domain_free(struct iommu_domain *domain) { } diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index f1416892ef8e..7df4a021b040 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2016,6 +2016,10 @@ static int __iommu_domain_alloc_dev(struct device *dev, void *data) return 0; } +/* + * The iommu ops in bus has been retired. Do not use this interface in + * new drivers. + */ struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus) { const struct iommu_ops *ops = NULL; @@ -2074,6 +2078,22 @@ struct iommu_domain *iommu_user_domain_alloc(struct device *dev, u32 flags) } EXPORT_SYMBOL_GPL(iommu_user_domain_alloc); +/** + * iommu_paging_domain_alloc() - Allocate a paging domain + * @dev: device for which the domain is allocated + * + * Allocate a paging domain which will be managed by a kernel driver. Return + * allocated domain if successful, or a ERR pointer for failure. + */ +struct iommu_domain *iommu_paging_domain_alloc(struct device *dev) +{ + if (!dev_has_iommu(dev)) + return ERR_PTR(-ENODEV); + + return __iommu_domain_alloc(dev_iommu_ops(dev), dev, IOMMU_DOMAIN_UNMANAGED); +} +EXPORT_SYMBOL_GPL(iommu_paging_domain_alloc); + void iommu_domain_free(struct iommu_domain *domain) { if (domain->type == IOMMU_DOMAIN_SVA) From patchwork Wed May 29 05:32:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5F54DC25B7C for ; Wed, 29 May 2024 05:36:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 61EDF113127; Wed, 29 May 2024 05:36:38 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="lqiw3jwQ"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id C5AC511307D for ; Wed, 29 May 2024 05:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960975; x=1748496975; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=btq9QncSBgyBYPM+1ZLAyc+X7006n3UNtW5/Bz7GLZE=; b=lqiw3jwQc2SVq6O8cP5eBHlAXTvF8fgsmMPHNDDKg4UhX5OZscVXiLzP 4CUd1VOQJyS2AgHoyeO5UArCs6uFKz06RTg7qRIkNVoPNV4KBXOONry3f VQdxevMmIqG30TozSP74JZXgx2POGkIvoMVJEJscyWiVJQCicm+ukSoiP Nq4IKV275BXvsmr0SwELFk2aUC5NS13ztmgbRmXghhxufG0vrTxCaacCa dpUmKjMZa78OjTARHx0Ln4gpPR6aQogra0tunMlPKGQ+VUvm83NrF8ih+ wxGLHyByNDI/mJtylceqr3Vj0MgntuLlK8ScWkRlnam6GyqfozzX+UlBz g==; X-CSE-ConnectionGUID: cSdOSJPuQDeFdkZUJP/CQw== X-CSE-MsgGUID: +hrlLd9VSqGwnHnG0F7vDw== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568855" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568855" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:30 -0700 X-CSE-ConnectionGUID: PJuAP/85SO2v/dKzt8Un2A== X-CSE-MsgGUID: fVOd5tHsThGjTLV7SoVvmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257574" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:25 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 06/20] drm/msm: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:36 +0800 Message-Id: <20240529053250.91284-7-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The domain allocated in msm_iommu_new() is for the @dev. Replace iommu_domain_alloc() with iommu_paging_domain_alloc() to make it explicit. Update msm_iommu_new() to always return ERR_PTR in failure cases instead of NULL. Signed-off-by: Lu Baolu --- drivers/gpu/drm/msm/msm_iommu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_iommu.c b/drivers/gpu/drm/msm/msm_iommu.c index d5512037c38b..f7e28d4b5f62 100644 --- a/drivers/gpu/drm/msm/msm_iommu.c +++ b/drivers/gpu/drm/msm/msm_iommu.c @@ -407,9 +407,9 @@ struct msm_mmu *msm_iommu_new(struct device *dev, unsigned long quirks) struct msm_iommu *iommu; int ret; - domain = iommu_domain_alloc(dev->bus); - if (!domain) - return NULL; + domain = iommu_paging_domain_alloc(dev); + if (IS_ERR(domain)) + return ERR_CAST(domain); iommu_set_pgtable_quirks(domain, quirks); @@ -441,7 +441,7 @@ struct msm_mmu *msm_iommu_gpu_new(struct device *dev, struct msm_gpu *gpu, unsig struct msm_mmu *mmu; mmu = msm_iommu_new(dev, quirks); - if (IS_ERR_OR_NULL(mmu)) + if (IS_ERR(mmu)) return mmu; iommu = to_msm_iommu(mmu); From patchwork Wed May 29 05:32:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1578C25B75 for ; Wed, 29 May 2024 05:36:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E8B041130FE; Wed, 29 May 2024 05:36:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Wrh37zMd"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 58C3811307D for ; Wed, 29 May 2024 05:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960976; x=1748496976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GbpYXxZBS+r4Y0EiK3BFmXVZKaFfLeJ2IAlI0t0Upno=; b=Wrh37zMdH2gkMq0VgNev7DfrlbEZhc8hFNNDvpKCbAdUsFXU+MAmBcfG TeAAt1jUPvrLhZibyfgBnTE3ZE+PryeHKoc9n9fQ1qwIDahAOD5TDIojv BcX2cOCs64Sp6nqinvRfGjA+ak7uweMiBPRZV810g2DK6FL58Gt0ew53t vfTumsIYdil4IcP5kLFKPoJ87U8zvgpRpHOKBK2UfM1ZXPicQRZjM3jjB 0GPzD/GwchuXEBHwGOpbofk6YU1r9PJ3t+X+yvEYri7UGhX1L2Rh8HEPm Tf7K9M5Wb1EDgPrnWQoo4tKvNMeaOEYVTZtSPv5Uyk9992cUwt1ioKpOJ g==; X-CSE-ConnectionGUID: YvoK27+IQIWxqEphdbxl/A== X-CSE-MsgGUID: HXW3a8GCSfm60n+9l20FNA== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568874" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568874" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:35 -0700 X-CSE-ConnectionGUID: 1de5gOz8RiiJc2GTEm4qYg== X-CSE-MsgGUID: P2dlEMyTRzOFmN4BYECPHg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257612" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:30 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 07/20] drm/nouveau/tegra: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:37 +0800 Message-Id: <20240529053250.91284-8-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In nvkm_device_tegra_probe_iommu(), a paging domain is allocated for @dev and attached to it on success. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu --- drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c index 87caa4a72921..763c4c2925f9 100644 --- a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c +++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c @@ -120,8 +120,8 @@ nvkm_device_tegra_probe_iommu(struct nvkm_device_tegra *tdev) mutex_init(&tdev->iommu.mutex); if (device_iommu_mapped(dev)) { - tdev->iommu.domain = iommu_domain_alloc(&platform_bus_type); - if (!tdev->iommu.domain) + tdev->iommu.domain = iommu_paging_domain_alloc(dev); + if (IS_ERR(tdev->iommu.domain)) goto error; /* From patchwork Wed May 29 05:32:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3A77C27C44 for ; Wed, 29 May 2024 05:36:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 44D51113028; Wed, 29 May 2024 05:36:33 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="VamwWKgr"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9D536113034 for ; Wed, 29 May 2024 05:36:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960978; x=1748496978; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QPVW+nVXZ/Qv6phdysqv5NqIfLXG+N6nb5d8ku5/Eew=; b=VamwWKgrFbJJZ/vC1tQj0486SsBrZLQBgg9XxUhd+fvv+6/bXNg7MdaV KE6kWq2AT23vyrpiVJdTqnLV9QdTq6HArE2E6MD34GQkIdDFrQcmdhLS0 7EDJrvIYMdMcQhdm+WIzvk3M2OAwAq08wdRmlTCyfp1ztEOW7SBgU00Xs 07SJchH2z1RCqdx5Md9KgwU+U66eAwpPSQgXsn2oFeZmK8ijypielcbyV +ccm9tub/gpFkaMW+mQWZB/aNHfdAKZsvWysFdfLsLxPNTvRY/xPecBVW oMN5ld94O/XgDShHrZSH4E30kBoaWC9l62GvSAn2BY4z7aLghMz6HFiMN g==; X-CSE-ConnectionGUID: tb/fdStaTz+O7pywe7bNtg== X-CSE-MsgGUID: 2S8VJhH9Q6OytmoYr/HC4A== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568915" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568915" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:39 -0700 X-CSE-ConnectionGUID: H0Tfydb8Sd2Y4vK78rZTQg== X-CSE-MsgGUID: ejihKNhgR8KfyMoR83nR7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257652" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:34 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 08/20] gpu: host1x: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:38 +0800 Message-Id: <20240529053250.91284-9-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" An iommu domain is allocated in host1x_iommu_attach() and is attached to host->dev. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu --- drivers/gpu/host1x/dev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index 3a0aaa68ac8d..46a2447c1124 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -404,9 +404,9 @@ static struct iommu_domain *host1x_iommu_attach(struct host1x *host) if (err < 0) goto put_group; - host->domain = iommu_domain_alloc(&platform_bus_type); - if (!host->domain) { - err = -ENOMEM; + host->domain = iommu_paging_domain_alloc(host->dev); + if (IS_ERR(host->domain)) { + err = PTR_ERR(host->domain); goto put_cache; } From patchwork Wed May 29 05:32:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677850 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B580DC25B7C for ; Wed, 29 May 2024 05:36:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 24E001130D3; Wed, 29 May 2024 05:36:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Nn4bNbVy"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 86AB01130BF for ; Wed, 29 May 2024 05:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960979; x=1748496979; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hTV3zLZE5NKCbs8//lAHn/CtYF9pijNjI3EBc1agx30=; b=Nn4bNbVyfWKhqgeHV7gWX9hs07K47VC8XiQrMRMQ+omEEKSXxlmQljE2 zqVZYKWEAP89UrYZAwWS752r2jKQWpbVvx4WZbsjadgJGcbc/HOBsf3GT N1PDaYpXMkZjxCJOzekgk2xSzGmEuhMPjTxLC+BJ0C8VubUl6otbB4Cua wVjrvUqW2h0508Xpz7LjLQl4RhplGypMOi2TNrZsKqF0OuPc78wrkJG5X zkz9yi1YN0lUEA0yzSPrpR7gcOjtfERdTk8sexee7zSfoMh0fS0GwALhe gnNb1VBoj1FS3i1MImSs/GQ22BYLyqrtNu27yUQnN8GEk68fpxN1OFP+P w==; X-CSE-ConnectionGUID: rfNklQpdS4qQwE+zuXFYuw== X-CSE-MsgGUID: bM8y3shASyeNfjK5KttxGA== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568940" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568940" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:44 -0700 X-CSE-ConnectionGUID: +cDPAFDtQritcQaJ3GGFSA== X-CSE-MsgGUID: nDbXwaPeTiGGxvK7O/Ioeg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257672" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:39 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 09/20] media: nvidia: tegra: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:39 +0800 Message-Id: <20240529053250.91284-10-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" An iommu domain is allocated in tegra_vde_iommu_init() and is attached to vde->dev. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu --- drivers/media/platform/nvidia/tegra-vde/iommu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/nvidia/tegra-vde/iommu.c b/drivers/media/platform/nvidia/tegra-vde/iommu.c index 5521ed3e465f..5a41b5364238 100644 --- a/drivers/media/platform/nvidia/tegra-vde/iommu.c +++ b/drivers/media/platform/nvidia/tegra-vde/iommu.c @@ -78,9 +78,9 @@ int tegra_vde_iommu_init(struct tegra_vde *vde) arm_iommu_release_mapping(mapping); } #endif - vde->domain = iommu_domain_alloc(&platform_bus_type); - if (!vde->domain) { - err = -ENOMEM; + vde->domain = iommu_paging_domain_alloc(dev); + if (IS_ERR(vde->domain)) { + err = PTR_ERR(vde->domain); goto put_group; } From patchwork Wed May 29 05:32:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03ED3C25B75 for ; Wed, 29 May 2024 05:38:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DF9161129F1; Wed, 29 May 2024 05:38:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="KiL+s0AP"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 322A5113034 for ; Wed, 29 May 2024 05:36:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960980; x=1748496980; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sQhpQrDpkr5d6QzI9UDmfi+nhpzVyW1CcaBVDpyFpuE=; b=KiL+s0APhHa4cQk7rUlYR/EqLgvuj1hDt3yVBexi1tmL78/kydZGGxyt Zpj+5ARBuGzNCKyx3dtTf2FzVrZhY2TvhZmjdVObrROJcKEfH9pn4L80U 8piDyhcwC+wDwWcBcgUmbGsxopq9irKlaWOTmT0D6+hbkD7qkGiJHPIPs q8mEpIBAL+7CH18DzcKYvpvYM5pWjPXeWhFFyKqANFCtLoSM7GqETZ3FA soefGYOe8XG65N992RdniAVp7iz2fE+DmUV/R53C2hIY07ZCBmRSEA1qH IA/nmXj2ENO42w6Lhg13g6PaJZ/0G4nctUGlwNP0HirGRuQpSzmFIe+Wl Q==; X-CSE-ConnectionGUID: Svf94zSkT5qc55GxVHTXsw== X-CSE-MsgGUID: +A82jt+PQ5+Ap6vFWtT9WQ== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568970" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568970" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:49 -0700 X-CSE-ConnectionGUID: ibSOuVsuTWmBLKtjWng6DA== X-CSE-MsgGUID: w/ltsPfbRAaZqzlQJES1fQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257682" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:44 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 10/20] media: venus: firmware: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:40 +0800 Message-Id: <20240529053250.91284-11-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" An iommu domain is allocated in venus_firmware_init() and is attached to core->fw.dev in the same function. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu --- drivers/media/platform/qcom/venus/firmware.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c index fe7da2b30482..66a18830e66d 100644 --- a/drivers/media/platform/qcom/venus/firmware.c +++ b/drivers/media/platform/qcom/venus/firmware.c @@ -316,10 +316,10 @@ int venus_firmware_init(struct venus_core *core) core->fw.dev = &pdev->dev; - iommu_dom = iommu_domain_alloc(&platform_bus_type); - if (!iommu_dom) { + iommu_dom = iommu_paging_domain_alloc(core->fw.dev); + if (IS_ERR(iommu_dom)) { dev_err(core->fw.dev, "Failed to allocate iommu domain\n"); - ret = -ENOMEM; + ret = PTR_ERR(iommu_dom); goto err_unregister; } From patchwork Wed May 29 05:32:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45F69C25B7E for ; Wed, 29 May 2024 05:36:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 36542113116; Wed, 29 May 2024 05:36:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="fEjvpa7V"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 736891130FE for ; Wed, 29 May 2024 05:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960983; x=1748496983; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kv68qkR9q97yuL81djioGxxqJnKTS0o+E5D+XI6WQks=; b=fEjvpa7V1IaOk/PMm4+cS6wlwSmmafhwB9mxRmGszHh+eFavZKBHPyQc ja93Ku9zFwskHeOks7t+WiAxHfiRdYERINwbJCzx4GCsR5n9uhqNd7TgC 1qCPyjUrm9jqQ7VzBtPoQbubQh9o2otLJ+5fsPh6YmFvRAnyRJnD9HFQ6 HCYbgDsQlLgWc7x2xASZqHmTbEB6eEdaHwtGCXhl+fU4j44VdbDpTdrYl dO8OFgh7T1gX/yvlCDHp4xHbtMsQVIUa3QLydxqq36SYFDMfdJ0kng/64 k+YKsjWjZA50UY1Y8a/kI/yflo5lg0EHZCJPZqWO0Wa7CVHvansaqq9Gb Q==; X-CSE-ConnectionGUID: mIQKph62TPejpesWmkXdSg== X-CSE-MsgGUID: 81u/inZ9S5aggsXW5ycXwA== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569000" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569000" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:53 -0700 X-CSE-ConnectionGUID: C5UxFXeCS62GXV5ofkH9mg== X-CSE-MsgGUID: 0gi2TYzwQaSnWJDrgXMwWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257688" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:49 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 11/20] ath10k: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:41 +0800 Message-Id: <20240529053250.91284-12-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" An iommu domain is allocated in ath10k_fw_init() and is attached to ar_snoc->fw.dev in the same function. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu --- drivers/net/wireless/ath/ath10k/snoc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/snoc.c b/drivers/net/wireless/ath/ath10k/snoc.c index 8530550cf5df..0fe47d51013c 100644 --- a/drivers/net/wireless/ath/ath10k/snoc.c +++ b/drivers/net/wireless/ath/ath10k/snoc.c @@ -1635,10 +1635,10 @@ static int ath10k_fw_init(struct ath10k *ar) ar_snoc->fw.dev = &pdev->dev; - iommu_dom = iommu_domain_alloc(&platform_bus_type); - if (!iommu_dom) { + iommu_dom = iommu_paging_domain_alloc(ar_snoc->fw.dev); + if (IS_ERR(iommu_dom)) { ath10k_err(ar, "failed to allocate iommu domain\n"); - ret = -ENOMEM; + ret = PTR_ERR(iommu_dom); goto err_unregister; } From patchwork Wed May 29 05:32:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677854 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2B175C25B7C for ; Wed, 29 May 2024 05:36:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 51A42113126; Wed, 29 May 2024 05:36:30 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="NXlvGmYd"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 77FD21130D3 for ; Wed, 29 May 2024 05:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960983; x=1748496983; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b4g7oPuUpFCf7ehXVGbGAAANzK1lpGoRJJpR32Cbgc4=; b=NXlvGmYdQkJ08XN+Wu0A7SjTu/Ob6qSqMmknHVVY92s15Osl3n642fYU jgWvum5ITAhZiNDvGMFKLmPaI4gqdYy2Dx3auhzmEagLB55/CC9eDwQ+P zdylUOjub5kaT02W/pqjnp0kk1o6u1rexoEU8Y3qvWNv3P1PX4PyyFarV u3c0EDuPcp2qzV/otS8J8lajlPVprFniujHqGfB1hSBV3nGZsq8vu0kps cVLiBDqy6k3RD+pm0dwEXNWLYH+8/YxHRdSAe8cXzGAUU/t+FHiUXK970 p8/oEZ+KZhyQcDF6SQemw/QMLGdIegxup3EEmFnXvXwiNZSBWvd2/RZHK g==; X-CSE-ConnectionGUID: k2WrTQZVQBO+3nRh1VIzAw== X-CSE-MsgGUID: obtW69M/QiGh1M1jPWXCfQ== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569012" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569012" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:35:58 -0700 X-CSE-ConnectionGUID: V3zZjpVoRS2Q2WQoWQMxtQ== X-CSE-MsgGUID: 5T9hg/jYScSPheKhITTpNw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257707" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:53 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 12/20] wifi: ath11k: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:42 +0800 Message-Id: <20240529053250.91284-13-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" An iommu domain is allocated in ath11k_ahb_fw_resources_init() and is attached to ab_ahb->fw.dev in the same function. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu --- drivers/net/wireless/ath/ath11k/ahb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c index ca0f17ddebba..a469647719f9 100644 --- a/drivers/net/wireless/ath/ath11k/ahb.c +++ b/drivers/net/wireless/ath/ath11k/ahb.c @@ -1001,10 +1001,10 @@ static int ath11k_ahb_fw_resources_init(struct ath11k_base *ab) ab_ahb->fw.dev = &pdev->dev; - iommu_dom = iommu_domain_alloc(&platform_bus_type); - if (!iommu_dom) { + iommu_dom = iommu_paging_domain_alloc(ab_ahb->fw.dev); + if (IS_ERR(iommu_dom)) { ath11k_err(ab, "failed to allocate iommu domain\n"); - ret = -ENOMEM; + ret = PTR_ERR(iommu_dom); goto err_unregister; } From patchwork Wed May 29 05:32:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55B83C25B75 for ; Wed, 29 May 2024 05:36:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4E837113140; Wed, 29 May 2024 05:36:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Cc/gmgwj"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 633A8113108 for ; Wed, 29 May 2024 05:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960989; x=1748496989; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kDJcZN33ntEvZZurzXrpsoEVgCNzk8vicnqImPO/kUg=; b=Cc/gmgwjMVfgvIyhmX5Pf0Ek6vCf6Y5AUTC+sae2IfvBenvGTzh/Walg oh6l2O8okOiygO6RI0MrXneJTtriTrLhMO3q5fQaLVwY+uZwtn0kRVe2a OeEzDdAV8KqpCEFIMVpa9yWAOi/qKnmLkcPT+Hu8exrA+J9Je+Vl9uW6N v3th35rSENgek5c5ZMO5maDFcN/auZ6wRFqyNCNoCrFig4C/I4EPC3oVf Z0CGdm+CGAHFpbFzY5cV2mVn4ZVuSpgQNr6dofOrQu5PwPswsciMi+IXb v4KVlGVA/PUhw9c4TQ2QpOay4WA0t9CYNmeyfR0Tir73Los7UKD98VGzI Q==; X-CSE-ConnectionGUID: aR1ThhAuQjqYX5mowu8eDw== X-CSE-MsgGUID: W14YngHISOC/6QA0oKJ49A== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569025" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569025" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:36:03 -0700 X-CSE-ConnectionGUID: ENb7rn90RI6j1x4NRe3Etw== X-CSE-MsgGUID: Ih7YA2CfRI2pwJKPhSeR1g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257728" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:35:58 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 13/20] remoteproc: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:43 +0800 Message-Id: <20240529053250.91284-14-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" An iommu domain is allocated in rproc_enable_iommu() and is attached to rproc->dev.parent in the same function. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu --- drivers/remoteproc/remoteproc_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index f276956f2c5c..eb66f78ec8b7 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -109,10 +109,10 @@ static int rproc_enable_iommu(struct rproc *rproc) return 0; } - domain = iommu_domain_alloc(dev->bus); - if (!domain) { + domain = iommu_paging_domain_alloc(dev); + if (IS_ERR(domain)) { dev_err(dev, "can't alloc iommu domain\n"); - return -ENOMEM; + return PTR_ERR(domain); } iommu_set_fault_handler(domain, rproc_iommu_fault, rproc); From patchwork Wed May 29 05:32:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C79EC25B7C for ; Wed, 29 May 2024 05:36:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 907FD11311A; Wed, 29 May 2024 05:36:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="YgTknBw2"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 87442113109 for ; Wed, 29 May 2024 05:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960990; x=1748496990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qwe6Nm71KNXy5AzCovPyBLpaZan5bLchb/yuvu+UWlE=; b=YgTknBw2rEEAEMuXVSbcMZa9zPzVgjrzkZZC4hx//BmkgMMJvmjyuQYl lQ1sG4Hvj1GXLTp8rybW3GoS4FpKAcvwHDJCKXMm4x1Jbg9sjFKH8nIk9 jiTrQk9CRKowmRhhjFhGeMuFAc68Rj29VOL07dhld2Gk9ktDY0OCpDqHJ sDaxQ4zfCqAYslN+oTBCATHcc+F6VD+zIC0ii+mQittTUkAoJPrXiNZnS N7AgR0WPytx+Oq2x4RILRyvhxxiSBqd6JojlRsCL9qAPmp6OTDwHCVnYL FbG9R73PtzOigOWtO+Ng8NhBPtlTaR25WWD7i4EFGyEXVlMdtd2Vx8pdt w==; X-CSE-ConnectionGUID: nU5HHXFOTCWnQ9orpu23ZQ== X-CSE-MsgGUID: wEKNDVFUT6eBIMjBLQoQHg== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569042" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569042" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:36:08 -0700 X-CSE-ConnectionGUID: 0bpDLxsuTtajCtyXoTqBTA== X-CSE-MsgGUID: Gw6ILwkESJ6yAzh0j9S2wA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257745" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:36:03 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 14/20] soc/fsl/qbman: Use iommu_paging_domain_alloc() Date: Wed, 29 May 2024 13:32:44 +0800 Message-Id: <20240529053250.91284-15-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" An iommu domain is allocated in portal_set_cpu() and is attached to pcfg->dev in the same function. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu --- drivers/soc/fsl/qbman/qman_portal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/soc/fsl/qbman/qman_portal.c b/drivers/soc/fsl/qbman/qman_portal.c index e23b60618c1a..91f17cea3744 100644 --- a/drivers/soc/fsl/qbman/qman_portal.c +++ b/drivers/soc/fsl/qbman/qman_portal.c @@ -48,8 +48,8 @@ static void portal_set_cpu(struct qm_portal_config *pcfg, int cpu) struct device *dev = pcfg->dev; int ret; - pcfg->iommu_domain = iommu_domain_alloc(&platform_bus_type); - if (!pcfg->iommu_domain) { + pcfg->iommu_domain = iommu_paging_domain_alloc(dev); + if (IS_ERR(pcfg->iommu_domain)) { dev_err(dev, "%s(): iommu_domain_alloc() failed", __func__); goto no_iommu; } From patchwork Wed May 29 05:32:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6834DC25B7E for ; Wed, 29 May 2024 05:36:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0DDFE11313C; Wed, 29 May 2024 05:36:39 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Qq81v8Xw"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 97802113116 for ; Wed, 29 May 2024 05:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960990; x=1748496990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kAf7SPBLso5zp49wUYubqs0YKzd/lC+tt+i0+MOxu64=; b=Qq81v8XwXEvl2IvT4ItDR4ufSEKYI0Wck4GaepBxGyOcsdL8oXYAc2nd 2U/hRowbrUxFiT+bHDEIl9VBQ08OD3iNfLOB5RmB6DVVAOcGRmSYzJtc3 QMgr5GiOt+ToVFEeFlGzyjsXU8XgY2ktATE72WadAK0WtGqrmAwm0pIfH EL2eGWvMmtMdA5pIiwPbfWyEKMmxqp8HaqrUU7l29JmcMLd17ll5qqxQ5 z2bt/xQanS1c83M5+JXytejvuD3UuyYwZXZjALuu4Yz0vf9JgiLL5TdJA JlUoSIJmVVdCJV3WtzUH58jCNdmS5V9AWmrY6GorYo39m7LJcRWc1QBsr g==; X-CSE-ConnectionGUID: 5KGnTZ6RTGq69FchtMDpew== X-CSE-MsgGUID: jlbvtVIrQOKQaug+9KGMWQ== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569057" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569057" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:36:12 -0700 X-CSE-ConnectionGUID: cCZToLUCTQGJ9JPHPmk0WA== X-CSE-MsgGUID: 3EA9i3ihQEyIhlN5IVrqow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257754" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:36:07 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 15/20] iommu/vt-d: Add helper to allocate paging domain Date: Wed, 29 May 2024 13:32:45 +0800 Message-Id: <20240529053250.91284-16-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The domain_alloc_user operation is currently implemented by allocating a paging domain using iommu_domain_alloc(). This is because it needs to fully initialize the domain before return. Add a helper to do this to avoid using iommu_domain_alloc(). Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 87 +++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 2e9811bf2a4e..ccde5f5972e4 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3633,6 +3633,79 @@ static struct iommu_domain blocking_domain = { } }; +static int iommu_superpage_capability(struct intel_iommu *iommu, bool first_stage) +{ + if (!intel_iommu_superpage) + return 0; + + if (first_stage) + return cap_fl1gp_support(iommu->cap) ? 2 : 1; + + return fls(cap_super_page_val(iommu->cap)); +} + +static struct dmar_domain *paging_domain_alloc(struct device *dev, bool first_stage) +{ + struct device_domain_info *info = dev_iommu_priv_get(dev); + struct intel_iommu *iommu = info->iommu; + struct dmar_domain *domain; + int addr_width; + + domain = kzalloc(sizeof(*domain), GFP_KERNEL); + if (!domain) + return ERR_PTR(-ENOMEM); + + INIT_LIST_HEAD(&domain->devices); + INIT_LIST_HEAD(&domain->dev_pasids); + INIT_LIST_HEAD(&domain->cache_tags); + spin_lock_init(&domain->lock); + spin_lock_init(&domain->cache_lock); + xa_init(&domain->iommu_array); + + domain->nid = dev_to_node(dev); + domain->has_iotlb_device = info->ats_enabled; + domain->use_first_level = first_stage; + + /* calculate the address width */ + addr_width = agaw_to_width(iommu->agaw); + if (addr_width > cap_mgaw(iommu->cap)) + addr_width = cap_mgaw(iommu->cap); + domain->gaw = addr_width; + domain->agaw = iommu->agaw; + domain->max_addr = __DOMAIN_MAX_ADDR(addr_width); + + /* iommu memory access coherency */ + domain->iommu_coherency = iommu_paging_structure_coherency(iommu); + + /* pagesize bitmap */ + domain->domain.pgsize_bitmap = SZ_4K; + domain->iommu_superpage = iommu_superpage_capability(iommu, first_stage); + domain->domain.pgsize_bitmap |= domain_super_pgsize_bitmap(domain); + + /* + * IOVA aperture: First-level translation restricts the input-address + * to a canonical address (i.e., address bits 63:N have the same value + * as address bit [N-1], where N is 48-bits with 4-level paging and + * 57-bits with 5-level paging). Hence, skip bit [N-1]. + */ + domain->domain.geometry.force_aperture = true; + domain->domain.geometry.aperture_start = 0; + if (first_stage) + domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw - 1); + else + domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw); + + /* always allocate the top pgd */ + domain->pgd = iommu_alloc_page_node(domain->nid, GFP_KERNEL); + if (!domain->pgd) { + kfree(domain); + return ERR_PTR(-ENOMEM); + } + domain_flush_cache(domain, domain->pgd, PAGE_SIZE); + + return domain; +} + static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) { struct dmar_domain *dmar_domain; @@ -3695,15 +3768,11 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, if (user_data || (dirty_tracking && !ssads_supported(iommu))) return ERR_PTR(-EOPNOTSUPP); - /* - * domain_alloc_user op needs to fully initialize a domain before - * return, so uses iommu_domain_alloc() here for simple. - */ - domain = iommu_domain_alloc(dev->bus); - if (!domain) - return ERR_PTR(-ENOMEM); - - dmar_domain = to_dmar_domain(domain); + /* Do not use first stage for user domain translation. */ + dmar_domain = paging_domain_alloc(dev, false); + if (IS_ERR(dmar_domain)) + return ERR_CAST(dmar_domain); + domain = &dmar_domain->domain; if (nested_parent) { dmar_domain->nested_parent = true; From patchwork Wed May 29 05:32:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677865 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7728AC25B75 for ; Wed, 29 May 2024 05:37:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 359FE10E7DF; Wed, 29 May 2024 05:37:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="hMgJEd1q"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 01624113124 for ; Wed, 29 May 2024 05:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960990; x=1748496990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5ePUNFSt1UVyBK/XkIEBW5JIdBwW2K6T9xjoabFYw84=; b=hMgJEd1qtYfG8G2tjNEUh01HoANa7sHi5NU3BQvwrKYbFFa4yfIKmNN1 3kATQnZ0IJZiYK2mS2rDNuw2PX9RJ4gxpW/5TsNXRUXxn4OWdbeRI5gn4 T9pN/f61neDT85lGBPP00MWs71x+fMNZ2gl2p7sPSuJ7cTtjiWh80Eu8v oaAUk0ifdNJkV4okdTKxQzvyO3I8InD2rRTHPmeUXmAWGvTiCDZq/gd76 IOqHjVuh5hnvkIGr07LFOwhBzzYbcQxLF6kZPChQToUtEBjjy/vfJ4Poc YvGVkQ97AJ7Vzjsu28EqpuqgDvZxpyG4alILyRAnLgkVgMOPa4A38XWvB w==; X-CSE-ConnectionGUID: 4z41p8YFTyCD0twKqcpQyA== X-CSE-MsgGUID: +Jbfy2DJT/yvbOW7czpaFQ== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569072" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569072" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:36:18 -0700 X-CSE-ConnectionGUID: bMLT6m7ZQya8CnSU5hJh7Q== X-CSE-MsgGUID: X6Uf2wUXQVWNu0/eZhCs2A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257765" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:36:12 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 16/20] iommu/vt-d: Add domain_alloc_paging support Date: Wed, 29 May 2024 13:32:46 +0800 Message-Id: <20240529053250.91284-17-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Move paging domain allocation code out from intel_iommu_domain_alloc(). The intel_iommu_domain_alloc() is still remaining to allocate an identity domain. However, it will soon disappear as we are about to convert the identity domain to a global static one. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 50 ++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index ccde5f5972e4..eb8e08699b80 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3708,35 +3708,8 @@ static struct dmar_domain *paging_domain_alloc(struct device *dev, bool first_st static struct iommu_domain *intel_iommu_domain_alloc(unsigned type) { - struct dmar_domain *dmar_domain; - struct iommu_domain *domain; - - switch (type) { - case IOMMU_DOMAIN_DMA: - case IOMMU_DOMAIN_UNMANAGED: - dmar_domain = alloc_domain(type); - if (!dmar_domain) { - pr_err("Can't allocate dmar_domain\n"); - return NULL; - } - if (md_domain_init(dmar_domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) { - pr_err("Domain initialization failed\n"); - domain_exit(dmar_domain); - return NULL; - } - - domain = &dmar_domain->domain; - domain->geometry.aperture_start = 0; - domain->geometry.aperture_end = - __DOMAIN_MAX_ADDR(dmar_domain->gaw); - domain->geometry.force_aperture = true; - - return domain; - case IOMMU_DOMAIN_IDENTITY: + if (type == IOMMU_DOMAIN_IDENTITY) return &si_domain->domain; - default: - return NULL; - } return NULL; } @@ -3791,6 +3764,26 @@ intel_iommu_domain_alloc_user(struct device *dev, u32 flags, return domain; } +static struct iommu_domain *intel_iommu_domain_alloc_paging(struct device *dev) +{ + struct dmar_domain *dmar_domain; + struct device_domain_info *info; + struct intel_iommu *iommu; + + /* Do not support the legacy iommu_domain_alloc() interface. */ + if (!dev) + return ERR_PTR(-ENODEV); + + info = dev_iommu_priv_get(dev); + iommu = info->iommu; + dmar_domain = paging_domain_alloc(dev, + sm_supported(iommu) && ecap_flts(iommu->ecap)); + if (IS_ERR(dmar_domain)) + return ERR_CAST(dmar_domain); + + return &dmar_domain->domain; +} + static void intel_iommu_domain_free(struct iommu_domain *domain) { struct dmar_domain *dmar_domain = to_dmar_domain(domain); @@ -4650,6 +4643,7 @@ const struct iommu_ops intel_iommu_ops = { .domain_alloc = intel_iommu_domain_alloc, .domain_alloc_user = intel_iommu_domain_alloc_user, .domain_alloc_sva = intel_svm_domain_alloc, + .domain_alloc_paging = intel_iommu_domain_alloc_paging, .probe_device = intel_iommu_probe_device, .release_device = intel_iommu_release_device, .get_resv_regions = intel_iommu_get_resv_regions, From patchwork Wed May 29 05:32:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DD57C27C50 for ; Wed, 29 May 2024 05:36:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 17D19113128; Wed, 29 May 2024 05:36:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="KD6w92b5"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id F2F6011311A for ; Wed, 29 May 2024 05:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960990; x=1748496990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kMsYOm7U7Zn12dWdb7SeO0fPM3MLpopXhwDJqBymYTM=; b=KD6w92b591ULTsCPBxdeTYPBBGUbUiWfw567/e+elWWAzafFt/mpIrmP LC6pAyRe8A1b2/9iKwSk6jX26MLFzKqJeBs9c/IWQzI6mxd20NY80c0qm jrx8Wu2ccIOV5mXzF7B8gsmkxccs3ksg0QIW9eFuWr+5um27brlnfBYMU hOEVtPNkS/GdIDCOBPmw4im9JSU+ZkowDgr91s9piw7hUvkGBF0l+uudS 89jft2Rq4GT88uKPsBWH1YGgxOvr9+Zr5lC6JvOTz4AxX8R0u2xiBrbMs ZqU8f+5luoYv9i/RgLDO7jxlvTcV3fU3iKrFGBSdXQZdWtQElzZBF8cR4 A==; X-CSE-ConnectionGUID: U612tGhdRmaM/PViv+SArw== X-CSE-MsgGUID: 53uoTe46RoeB3mFY91tCew== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569086" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569086" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:36:23 -0700 X-CSE-ConnectionGUID: ImXU7FqzTUizFrnygOVsyA== X-CSE-MsgGUID: buiM+0knQZG9v/S3HkrdEw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257777" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:36:18 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 17/20] iommu/vt-d: Simplify compatibility check for identity domain Date: Wed, 29 May 2024 13:32:47 +0800 Message-Id: <20240529053250.91284-18-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, the identity domain attachment follows the same path as the paging domain attachment and is subject to the same compatibility checks as a normal paging domain. However, this level of check is unnecessary for the identity domain since it only requires the hardware to support passthrough mode, which is a given for modern hardware. On the early VT-d platforms, where hardware passthrough mode is not yet supported, the identity domain is supported by a makeshift paging domain with the entire system memory 1:1 mapped. For such early hardware, the appropriate domain type should be returned in device_def_domain_type(), and the identity domain should be simplified in compatibility checks. The identity domain workaround in prepare_domain_attach_device() is just temporary and should be removed once the identity domain is converted to have its own dedicated attachment path. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index eb8e08699b80..693a6d7c79ed 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2190,6 +2190,16 @@ static bool device_rmrr_is_relaxable(struct device *dev) */ static int device_def_domain_type(struct device *dev) { + struct device_domain_info *info = dev_iommu_priv_get(dev); + struct intel_iommu *iommu = info->iommu; + + /* + * Hardware does not support the passthrough translation mode. + * Always use a dynamaic mapping domain. + */ + if (!ecap_pass_through(iommu->ecap)) + return IOMMU_DOMAIN_DMA; + if (dev_is_pci(dev)) { struct pci_dev *pdev = to_pci_dev(dev); @@ -3802,6 +3812,14 @@ int prepare_domain_attach_device(struct iommu_domain *domain, struct intel_iommu *iommu = info->iommu; int addr_width; + /* + * This is a temporary solution as the identity domain attachment + * goes through this path as well. It should be removed once the + * identity domain has its own attach path. + */ + if (domain->type == IOMMU_DOMAIN_IDENTITY) + return ecap_pass_through(iommu->ecap) ? 0 : -EOPNOTSUPP; + if (dmar_domain->force_snooping && !ecap_sc_support(iommu->ecap)) return -EINVAL; From patchwork Wed May 29 05:32:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 46DC1C25B7C for ; Wed, 29 May 2024 05:36:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2DC2D113146; Wed, 29 May 2024 05:36:41 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="R+V7ROdX"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 39250113028 for ; Wed, 29 May 2024 05:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960990; x=1748496990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=icmPwJxBqq/SYdv+MT5vO+QjUq8IQyphhpw+Dkkb0Fw=; b=R+V7ROdXZcRSCRJwY4BfQGdEcuLRtardVySb8UDbPTcLOM+g5a9ll2j+ SDNWz2H5Gxd36khj6eCLlwekIaLgPDPy56JYP/Obv/aRNK7aikMzXPm+w +MvrU44+WZM4Zrlil0RKKj3sQEo0vaE2FE3Bg47SDXqn6ilX4AP1BWXIX 9vk4IvMDllR2VKmxbGkzgeyYErPxzm911k6+9FSWs3jgsmZZnthnS9C5s im9rQJTXCWI6oMDB7vrn6joVMnzE1oPUodaGOEVMPfWvAHEyFklmAl2NP UdMwHh1JPk0W7zO7m8PTsuzuKnhDqeol1dlZNK+AJuOFZKvrw/h/kixrm Q==; X-CSE-ConnectionGUID: itMfuCX9SP+1Z/0EXu6C8A== X-CSE-MsgGUID: OROs5oTeR1GNVKf4ywAFGw== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569100" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569100" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:36:29 -0700 X-CSE-ConnectionGUID: esSWeCJpSSi5aauFREJ3HQ== X-CSE-MsgGUID: Fk69VRxaR02KBzRZ+jyvNw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257788" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:36:22 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 18/20] iommu/vt-d: Enhance compatibility check for paging domain attach Date: Wed, 29 May 2024 13:32:48 +0800 Message-Id: <20240529053250.91284-19-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The driver now supports domain_alloc_paging, ensuring that a valid device pointer is provided whenever a paging domain is allocated. Additionally, the dmar_domain attributes are set up at the time of allocation. Consistent with the established semantics in the IOMMU core, if a domain is attached to a device and found to be incompatible with the IOMMU hardware capabilities, the operation will return an -EINVAL error. This implicitly advises the caller to allocate a new domain for the device and attempt the domain attachment again. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 39 ++++++++++++++++++------------------- drivers/iommu/intel/pasid.c | 28 +------------------------- 2 files changed, 20 insertions(+), 47 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 693a6d7c79ed..e9393f5c2c50 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3826,27 +3826,26 @@ int prepare_domain_attach_device(struct iommu_domain *domain, if (domain->dirty_ops && !ssads_supported(iommu)) return -EINVAL; - /* check if this iommu agaw is sufficient for max mapped address */ - addr_width = agaw_to_width(iommu->agaw); - if (addr_width > cap_mgaw(iommu->cap)) - addr_width = cap_mgaw(iommu->cap); - - if (dmar_domain->max_addr > (1LL << addr_width)) + if (dmar_domain->iommu_coherency != + iommu_paging_structure_coherency(iommu)) return -EINVAL; - dmar_domain->gaw = addr_width; - - /* - * Knock out extra levels of page tables if necessary - */ - while (iommu->agaw < dmar_domain->agaw) { - struct dma_pte *pte; - - pte = dmar_domain->pgd; - if (dma_pte_present(pte)) { - dmar_domain->pgd = phys_to_virt(dma_pte_addr(pte)); - iommu_free_page(pte); - } - dmar_domain->agaw--; + + if (domain->type & __IOMMU_DOMAIN_PAGING) { + if (dmar_domain->iommu_superpage != + iommu_superpage_capability(iommu, dmar_domain->use_first_level)) + return -EINVAL; + + if (dmar_domain->use_first_level && + (!sm_supported(iommu) || !ecap_flts(iommu->ecap))) + return -EINVAL; + + /* check if this iommu agaw is sufficient for max mapped address */ + addr_width = agaw_to_width(iommu->agaw); + if (addr_width > cap_mgaw(iommu->cap)) + addr_width = cap_mgaw(iommu->cap); + + if (dmar_domain->gaw > addr_width || dmar_domain->agaw > iommu->agaw) + return -EINVAL; } if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev) && diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index abce19e2ad6f..573e1b8e3cfb 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -345,25 +345,6 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu, return 0; } -/* - * Skip top levels of page tables for iommu which has less agaw - * than default. Unnecessary for PT mode. - */ -static int iommu_skip_agaw(struct dmar_domain *domain, - struct intel_iommu *iommu, - struct dma_pte **pgd) -{ - int agaw; - - for (agaw = domain->agaw; agaw > iommu->agaw; agaw--) { - *pgd = phys_to_virt(dma_pte_addr(*pgd)); - if (!dma_pte_present(*pgd)) - return -EINVAL; - } - - return agaw; -} - /* * Set up the scalable mode pasid entry for second only translation type. */ @@ -374,7 +355,6 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, struct pasid_entry *pte; struct dma_pte *pgd; u64 pgd_val; - int agaw; u16 did; /* @@ -388,12 +368,6 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, } pgd = domain->pgd; - agaw = iommu_skip_agaw(domain, iommu, &pgd); - if (agaw < 0) { - dev_err(dev, "Invalid domain page table\n"); - return -EINVAL; - } - pgd_val = virt_to_phys(pgd); did = domain_id_iommu(domain, iommu); @@ -412,7 +386,7 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, pasid_clear_entry(pte); pasid_set_domain_id(pte, did); pasid_set_slptr(pte, pgd_val); - pasid_set_address_width(pte, agaw); + pasid_set_address_width(pte, domain->agaw); pasid_set_translation_type(pte, PASID_ENTRY_PGTT_SL_ONLY); pasid_set_fault_enable(pte); pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); From patchwork Wed May 29 05:32:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677868 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD18DC25B75 for ; Wed, 29 May 2024 05:38:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9BB581122D8; Wed, 29 May 2024 05:38:11 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Klis21kM"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 73F60113128 for ; Wed, 29 May 2024 05:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716960998; x=1748496998; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5KWn8VzkwrmikfdY6Ercb38rCkbe5TmNZrNn/P2jtlY=; b=Klis21kMJD1gQdyxf0VTTacJhvx7ZkXK4XYj7AGY3NbocKHLMhxN1pNu +Hc/MAPBsl2uNCo7ydLlU41AJw7aFYuFuQ6Rm9bLHeR6vxhR+kFXHscwa XFnP+x+3xVsldYSrWKLvP5fBnDVuPvpPWJSIpjqXk53rDJUK/z6ugRX/p ELY8SYSSp7+CIo5B34IKA1zDKBYdcjf3Ckdxi+Acu5uWMUA29gGf/T8jS Sxnx94EEjR2iQMi86BwZkV/+AncbCrSlZplqFGBASFSnXvZ1jDX7ci/uu KhBzPWgErURqQon262ZQU97SKWnS/WaeHrt3IY2DJP+R6165m/LEGvYxI Q==; X-CSE-ConnectionGUID: g0BSjT4iQRSUSkpmC658MQ== X-CSE-MsgGUID: kWyywqRITXiHtaZrtDCNRg== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569118" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569118" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:36:32 -0700 X-CSE-ConnectionGUID: tfyd8XLnTFavgJ6eGMD+/g== X-CSE-MsgGUID: 8sz1WYkaSFSx14UMZlVbhA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257798" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:36:27 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 19/20] iommu/vt-d: Remove domain_update_iommu_cap() Date: Wed, 29 May 2024 13:32:49 +0800 Message-Id: <20240529053250.91284-20-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The attributes of a paging domain are initialized during the allocation process, and any attempt to attach a domain that is not compatible will result in a failure. Therefore, there is no need to update the domain attributes at the time of domain attachment. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 86 +------------------------------------ 1 file changed, 2 insertions(+), 84 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index e9393f5c2c50..74e005b1c4b4 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -366,36 +366,6 @@ static bool iommu_paging_structure_coherency(struct intel_iommu *iommu) ecap_smpwc(iommu->ecap) : ecap_coherent(iommu->ecap); } -static void domain_update_iommu_coherency(struct dmar_domain *domain) -{ - struct iommu_domain_info *info; - struct dmar_drhd_unit *drhd; - struct intel_iommu *iommu; - bool found = false; - unsigned long i; - - domain->iommu_coherency = true; - xa_for_each(&domain->iommu_array, i, info) { - found = true; - if (!iommu_paging_structure_coherency(info->iommu)) { - domain->iommu_coherency = false; - break; - } - } - if (found) - return; - - /* No hardware attached; use lowest common denominator */ - rcu_read_lock(); - for_each_active_iommu(iommu, drhd) { - if (!iommu_paging_structure_coherency(iommu)) { - domain->iommu_coherency = false; - break; - } - } - rcu_read_unlock(); -} - static int domain_update_iommu_superpage(struct dmar_domain *domain, struct intel_iommu *skip) { @@ -426,29 +396,6 @@ static int domain_update_iommu_superpage(struct dmar_domain *domain, return fls(mask); } -static int domain_update_device_node(struct dmar_domain *domain) -{ - struct device_domain_info *info; - int nid = NUMA_NO_NODE; - unsigned long flags; - - spin_lock_irqsave(&domain->lock, flags); - list_for_each_entry(info, &domain->devices, link) { - /* - * There could possibly be multiple device numa nodes as devices - * within the same domain may sit behind different IOMMUs. There - * isn't perfect answer in such situation, so we select first - * come first served policy. - */ - nid = dev_to_node(info->dev); - if (nid != NUMA_NO_NODE) - break; - } - spin_unlock_irqrestore(&domain->lock, flags); - - return nid; -} - /* Return the super pagesize bitmap if supported. */ static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain) { @@ -466,35 +413,6 @@ static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain) return bitmap; } -/* Some capabilities may be different across iommus */ -void domain_update_iommu_cap(struct dmar_domain *domain) -{ - domain_update_iommu_coherency(domain); - domain->iommu_superpage = domain_update_iommu_superpage(domain, NULL); - - /* - * If RHSA is missing, we should default to the device numa domain - * as fall back. - */ - if (domain->nid == NUMA_NO_NODE) - domain->nid = domain_update_device_node(domain); - - /* - * First-level translation restricts the input-address to a - * canonical address (i.e., address bits 63:N have the same - * value as address bit [N-1], where N is 48-bits with 4-level - * paging and 57-bits with 5-level paging). Hence, skip bit - * [N-1]. - */ - if (domain->use_first_level) - domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw - 1); - else - domain->domain.geometry.aperture_end = __DOMAIN_MAX_ADDR(domain->gaw); - - domain->domain.pgsize_bitmap |= domain_super_pgsize_bitmap(domain); - domain_update_iotlb(domain); -} - struct context_entry *iommu_context_addr(struct intel_iommu *iommu, u8 bus, u8 devfn, int alloc) { @@ -1589,7 +1507,7 @@ int domain_attach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) ret = xa_err(curr) ? : -EBUSY; goto err_clear; } - domain_update_iommu_cap(domain); + domain_update_iotlb(domain); spin_unlock(&iommu->lock); return 0; @@ -1615,7 +1533,7 @@ void domain_detach_iommu(struct dmar_domain *domain, struct intel_iommu *iommu) clear_bit(info->did, iommu->domain_ids); xa_erase(&domain->iommu_array, iommu->seq_id); domain->nid = NUMA_NO_NODE; - domain_update_iommu_cap(domain); + domain_update_iotlb(domain); kfree(info); } spin_unlock(&iommu->lock); From patchwork Wed May 29 05:32:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 13677866 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2470C25B7C for ; Wed, 29 May 2024 05:37:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92E95112A26; Wed, 29 May 2024 05:37:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="gaZT/mxp"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id C52C0113147 for ; Wed, 29 May 2024 05:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716961004; x=1748497004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uZ18e0DpTIgHLOpzfBuHcXvVKSj+fUz+S5osI7EsSTY=; b=gaZT/mxpLDIP2gP2yr2JZam0yRyejPM5ASQJzfEpJ3Ukat7/5DYG/XKY 2MEvXKQNL56+IVwyENHHdIEaPX9A8NrLsRSDYXGxlxGFNVqz3MCwgL8Am eXCycmTq9JAghEfqGYiDTA1dQg4opKQWqovTedHahmFxgFqG3fpquv95L T1gROj+Dsl26KxbIpe6PrwTy8x6vmgZWDaAtlWEP3tZKEJJ58Q0+BD1Sx 8u9YZjLN4dN8vz9YStHPG1942TaJ/JMAHolaiW7xRvSpxN5pwM1O3sHkE GTTmBteZplAY2AFU7HKA0LAMAif3DUUALxYsJuKv4WE7oC9GsAHYMa1Kj Q==; X-CSE-ConnectionGUID: s7p4HG/oRyGHeNh9+fGUaA== X-CSE-MsgGUID: Y2nrLKzgRt6f9fyPqSHedg== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13569136" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13569136" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 22:36:37 -0700 X-CSE-ConnectionGUID: X+RiNsarRtKW3lpRtSJ0IA== X-CSE-MsgGUID: nvefUVcKRTqj8DSSs+S92A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35257811" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa007.fm.intel.com with ESMTP; 28 May 2024 22:36:32 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian Cc: Yi Liu , David Airlie , Daniel Vetter , Kalle Valo , Bjorn Andersson , Mathieu Poirier , Alex Williamson , mst@redhat.com, Jason Wang , Thierry Reding , Jonathan Hunter , Mikko Perttunen , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 20/20] iommu/vt-d: Remove domain_update_iommu_superpage() Date: Wed, 29 May 2024 13:32:50 +0800 Message-Id: <20240529053250.91284-21-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529053250.91284-1-baolu.lu@linux.intel.com> References: <20240529053250.91284-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The requirement for consistent super page support across all the IOMMU hardware in the system has been removed. In the past, if a new IOMMU was hot-added and lacked consistent super page capability, the hot-add process would be aborted. However, with the updated attachment semantics, it is now permissible for the super page capability to vary among different IOMMU hardware units. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 39 +------------------------------------ 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 74e005b1c4b4..660d2b6c531b 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -366,36 +366,6 @@ static bool iommu_paging_structure_coherency(struct intel_iommu *iommu) ecap_smpwc(iommu->ecap) : ecap_coherent(iommu->ecap); } -static int domain_update_iommu_superpage(struct dmar_domain *domain, - struct intel_iommu *skip) -{ - struct dmar_drhd_unit *drhd; - struct intel_iommu *iommu; - int mask = 0x3; - - if (!intel_iommu_superpage) - return 0; - - /* set iommu_superpage to the smallest common denominator */ - rcu_read_lock(); - for_each_active_iommu(iommu, drhd) { - if (iommu != skip) { - if (domain && domain->use_first_level) { - if (!cap_fl1gp_support(iommu->cap)) - mask = 0x1; - } else { - mask &= cap_super_page_val(iommu->cap); - } - - if (!mask) - break; - } - } - rcu_read_unlock(); - - return fls(mask); -} - /* Return the super pagesize bitmap if supported. */ static unsigned long domain_super_pgsize_bitmap(struct dmar_domain *domain) { @@ -2845,8 +2815,8 @@ int dmar_parse_one_satc(struct acpi_dmar_header *hdr, void *arg) static int intel_iommu_add(struct dmar_drhd_unit *dmaru) { - int sp, ret; struct intel_iommu *iommu = dmaru->iommu; + int ret; ret = intel_cap_audit(CAP_AUDIT_HOTPLUG_DMAR, iommu); if (ret) @@ -2858,13 +2828,6 @@ static int intel_iommu_add(struct dmar_drhd_unit *dmaru) return -ENXIO; } - sp = domain_update_iommu_superpage(NULL, iommu) - 1; - if (sp >= 0 && !(cap_super_page_val(iommu->cap) & (1 << sp))) { - pr_warn("%s: Doesn't support large page.\n", - iommu->name); - return -ENXIO; - } - /* * Disable translation if already enabled prior to OS handover. */