From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 0837A15A4A0 for ; Wed, 24 Apr 2024 07:18:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713943130; cv=none; b=M3MJKy4VRpKZRj5tXVVQyIOog2AnrG8wsG4tKSf/QHqJVtdWaoJJbwH55cQhmk+VdCjH+OQd+ZA8wr9Ob2hByI88X9Iz0eSH9uzSX3qHiGtLiE8O5Bc2vWOqiYwPIzm+wBcdvf7jhRx71JIzXwr5iphRa0yG3sYWubTdwRUf2CU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713943130; c=relaxed/simple; bh=VcePmM1MdtsM4T99mmakGlx0KWCXi1lYwWvfq/0RIHs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dX3VaJew1n9NqUnx8rco8HLjooYbuEaxr55SI0O+J8JVxQxpn+aE8QATaXZpxUnc5NUMihSeytjph51/NAm5uKJCXp32OsVVRg3OBLDYbzqmRrqBV7/Ya8HdJzEiLaRTLvguNtch2K6Q8SmgdjDWy77TV3VE1XggitKrRk8jvRk= 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=CMg1/cAf; arc=none smtp.client-ip=192.198.163.8 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="CMg1/cAf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713943129; x=1745479129; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VcePmM1MdtsM4T99mmakGlx0KWCXi1lYwWvfq/0RIHs=; b=CMg1/cAf4ckd8MZkCX7LZcbaxIvrLxt1uJBPwnjGxFyrZbJWN175JUzo t8Zd0yAbD0ZMjib6UTJyQgnzSrfg+VTF+zBVvopxObwoHdlPeZnFQxYBz Mlr6Ld3QtDntKoKVWQWPplNQKkxX0ZkJalxRTHpgjcAjjKK+zQFoRxgEd 2m37WKMIr8saZ00fKqrr3ThWm95ac20BYctIfRGybSjyMYOOP/fyciMAN EgWNPiwyy8WGi6fQdR/pKJiIWmiI5YW21zfMQuzOeIGX6RT8KgLnKJ/GL JO65LMv+pjXMRFmjxdMNWJKNnR4acpdkoBwPen1mBKpyqpiFnX3b+iEVV Q==; X-CSE-ConnectionGUID: LKTGaF6OSKqZX7U3QeiP9A== X-CSE-MsgGUID: 5cIJgneuQd+yA+e9N7lFDA== X-IronPort-AV: E=McAfee;i="6600,9927,11053"; a="27073254" X-IronPort-AV: E=Sophos;i="6.07,225,1708416000"; d="scan'208";a="27073254" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Apr 2024 00:18:49 -0700 X-CSE-ConnectionGUID: WqTgTgVZRYyA6BmYw+wzPg== X-CSE-MsgGUID: x7zwP5ctTjis75Z4qL78vw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,225,1708416000"; d="scan'208";a="24665945" Received: from unknown (HELO allen-box.sh.intel.com) ([10.239.159.127]) by fmviesa010.fm.intel.com with ESMTP; 24 Apr 2024 00:18:46 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jason Gunthorpe , Jingqi Liu , Dimitri Sivanich , Uros Bizjak , Colin Ian King , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 17/18] iommu: Add ops->domain_alloc_sva() Date: Wed, 24 Apr 2024 15:16:43 +0800 Message-Id: <20240424071644.178250-18-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240424071644.178250-1-baolu.lu@linux.intel.com> References: <20240424071644.178250-1-baolu.lu@linux.intel.com> Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Vasant Hegde Reviewed-by: Tina Zhang Link: https://lore.kernel.org/r/20240311090843.133455-15-vasant.hegde@amd.com Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Link: https://lore.kernel.org/r/20240416080656.60968-12-baolu.lu@linux.intel.com --- 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 e6549bdfaed9..f4cdffa985e4 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -517,6 +517,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 Addressing. * @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 IOMMU @@ -557,6 +558,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); 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 /* Allocate a new domain and set it on device pasid. */ domain = iommu_sva_domain_alloc(dev, mm); - if (!domain) { - ret = -ENOMEM; + if (IS_ERR(domain)) { + ret = PTR_ERR(domain); goto out_free_handle; } @@ -283,9 +283,15 @@ struct iommu_domain *iommu_sva_domain_alloc(struct device *dev, const struct iommu_ops *ops = dev_iommu_ops(dev); struct iommu_domain *domain; - domain = ops->domain_alloc(IOMMU_DOMAIN_SVA); - if (!domain) - return NULL; + if (ops->domain_alloc_sva) { + domain = ops->domain_alloc_sva(dev, mm); + if (IS_ERR(domain)) + return domain; + } else { + domain = ops->domain_alloc(IOMMU_DOMAIN_SVA); + if (!domain) + return ERR_PTR(-ENOMEM); + } domain->type = IOMMU_DOMAIN_SVA; mmgrab(mm); -- 2.34.1