From nobody Sun Feb 8 18:15:25 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CECE91553AC for ; Mon, 25 Mar 2024 02:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711333114; cv=none; b=PKjt/uTurEsPMvkT2S2LYe3dBU/egVZ9CJJr0V0E2u3GWUw78eKISMErUxJ92XcxP4dXrq2xUyLiheOTJpdt0NCPAyukL9SlSXjmlwvpHPptpKDSSTmIbECvKuNfN4AmAVUuL1Z0M81IRxBWw5Vsm+cvkxfHgX9N/FZNcZk5Fbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711333114; c=relaxed/simple; bh=Z4N9WjZXB3Uq7GgVWrBbRtPl6f+yBep/k+sWPTppZwU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sfkxy37DYzcPHfjvqlJ/SdSEhoAKOVO9LpQBZZvtIbNk3U7wnZmGekrFYhetC9HBMs6CgHvc+nN2EvO9OozfZvOvPPoAPpkVkbnFrDEMB9NzEOsjEFF6+leCCwVFGim5Y14aaWTvsTFoaKMphayemuZhrdozfLxbFVAOAIxaQrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=LnbyqRiZ; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="LnbyqRiZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711333113; x=1742869113; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z4N9WjZXB3Uq7GgVWrBbRtPl6f+yBep/k+sWPTppZwU=; b=LnbyqRiZLnPwJUiyEONEepEEkFe8mKSIH8/XfUEWeyNDrVegENWfxp7C psC1IiD9jGkuKZWHf7M4ruqV+A41Y2QbNhnU77VkNqEUzgevWKLiAqQrU seEV7z1spDcaAKv6kXMzfLhgcID66JVDZ+1pur65eHtc7JNDHhha0uyy5 Jx9+xGD7l6wnaMKmYEo4LzTuOkmUhrjKIiWHLUzhMrSVCjctcbzpsBX1Q UOIYBibGjIuzPr9Li9LWpX3PArN0ss3MAZ60UyGU2AgPFNxnO9f6bLhtX vb+vcXiK2VU2H5H8uBdDy0V0iZMd4mEXCeZ4zjvIVKVrP32edhlqogTxA w==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="9271461" X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="9271461" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2024 19:18:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,152,1708416000"; d="scan'208";a="15354011" Received: from allen-box.sh.intel.com ([10.239.159.127]) by orviesa010.jf.intel.com with ESMTP; 24 Mar 2024 19:18:29 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Kevin Tian , Jason Gunthorpe Cc: Tina Zhang , Yi Liu , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Jason Gunthorpe , Vasant Hegde , Lu Baolu Subject: [PATCH 11/12] iommu: Add ops->domain_alloc_sva() Date: Mon, 25 Mar 2024 10:17:04 +0800 Message-Id: <20240325021705.249769-12-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325021705.249769-1-baolu.lu@linux.intel.com> References: <20240325021705.249769-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jason Gunthorpe Make a new op that receives the device and the mm_struct that the SVA domain should be created for. Unlike domain_alloc_paging() the dev argument is never NULL here. This allows drivers to fully initialize the SVA domain and allocate the mmu_notifier during allocation. It allows the notifier lifetime to follow the lifetime of the iommu_domain. Since we have only one call site, upgrade the new op to return ERR_PTR instead of NULL. Signed-off-by: Jason Gunthorpe [Removed smmu3 related changes - Vasant] Signed-off-by: Vasant Hegde Reviewed-by: Tina Zhang Link: https://lore.kernel.org/r/20240311090843.133455-15-vasant.hegde@amd.c= om Signed-off-by: Lu Baolu --- include/linux/iommu.h | 3 +++ drivers/iommu/iommu-sva.c | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 2e925b5eba53..8aabe83af8f2 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -518,6 +518,7 @@ static inline int __iommu_copy_struct_from_user_array( * Upon failure, ERR_PTR must be returned. * @domain_alloc_paging: Allocate an iommu_domain that can be used for * UNMANAGED, DMA, and DMA_FQ domain types. + * @domain_alloc_sva: Allocate an iommu_domain for Shared Virtual Addressi= ng. * @probe_device: Add device to iommu driver handling * @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IO= MMU @@ -558,6 +559,8 @@ struct iommu_ops { struct device *dev, u32 flags, struct iommu_domain *parent, const struct iommu_user_data *user_data); struct iommu_domain *(*domain_alloc_paging)(struct device *dev); + struct iommu_domain *(*domain_alloc_sva)(struct device *dev, + struct mm_struct *mm); =20 struct iommu_device *(*probe_device)(struct device *dev); void (*release_device)(struct device *dev); diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c index 640acc804e8c..18a35e798b72 100644 --- a/drivers/iommu/iommu-sva.c +++ b/drivers/iommu/iommu-sva.c @@ -108,8 +108,8 @@ struct iommu_sva *iommu_sva_bind_device(struct device *= dev, struct mm_struct *mm =20 /* Allocate a new domain and set it on device pasid. */ domain =3D iommu_sva_domain_alloc(dev, mm); - if (!domain) { - ret =3D -ENOMEM; + if (IS_ERR(domain)) { + ret =3D PTR_ERR(domain); goto out_free_handle; } =20 @@ -283,9 +283,15 @@ struct iommu_domain *iommu_sva_domain_alloc(struct dev= ice *dev, const struct iommu_ops *ops =3D dev_iommu_ops(dev); struct iommu_domain *domain; =20 - domain =3D ops->domain_alloc(IOMMU_DOMAIN_SVA); - if (!domain) - return NULL; + if (ops->domain_alloc_sva) { + domain =3D ops->domain_alloc_sva(dev, mm); + if (IS_ERR(domain)) + return domain; + } else { + domain =3D ops->domain_alloc(IOMMU_DOMAIN_SVA); + if (!domain) + return ERR_PTR(-ENOMEM); + } =20 domain->type =3D IOMMU_DOMAIN_SVA; mmgrab(mm); --=20 2.34.1