Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp453082lqb; Tue, 28 May 2024 23:56:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhKHDq7m3EeT06D4JkzugImln1/WNDv1L7Fllrq9dyrlVoDURTqhL38AA3mnoO1MOcSIc6eQVpykxV9tMnL1FQQpgQqqypEWSt25YkqA== X-Google-Smtp-Source: AGHT+IEpXhvt2qTQdx81Es0YLYLDteEFvVSiQtCghCJPLGlUwoDwjdh+eJABE77oO9/oqMjtW3BQ X-Received: by 2002:a05:6a00:428e:b0:6ed:4f2e:ef22 with SMTP id d2e1a72fcca58-6f8f43dcea3mr17224261b3a.31.1716965768328; Tue, 28 May 2024 23:56:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716965768; cv=pass; d=google.com; s=arc-20160816; b=GIpXNnL9ngSWhQGrj8TbRP5TBc3nEzqr8lj5HXSxpyUflBZuTx/9DlAQEchzDM9SwG Hft/mbhJhwLmTGzzTkws4GaBzjJ9N+zQ622lO3nU8oNRnLGX117+PDVUAtE/C3rP2ALs 8qRbucgja7wS5aS0Zew+yWrkycTeuIm5hcGiPh/lsv8S/2fqDiK2M5bwjTOpNqT7VDis JriG9c5r9hJarZiHijA6rCJT5u8hN3LWWDHzW5xaV2UF6zvdbbXvVXl7Xt/DOS8YZhLt oC4XpcpI5p068HiD+d+kY2gdrgW+n8AO5amVxfpTYLT7Mbj8reuDng7At9voo5ZikqBr uEgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Z1qUGYoigE6Z5Z5D2CJzvTCSIn0IOOSaLOAw2q2y/hY=; fh=u7VIfotmvhCnFPKh0R845OAh004BwcT1TGiZ1dQEGzo=; b=TB1k37q6U9lJIN+R6w6MPd5LNlLHjexLQl7aYk1PGixbXmnoEur426pZ2/xw4j+na7 2LpCfJfAoRgvPbNWt2XmAuMJ68bxH5o4cnZf+BQOo0vMBZlLUCb+2alyFx3HeBN6awhk LpFjSOYGHslkom/6QN8/wy1ndzpZNsfDB7WXLNTVwHeqVmIN8EOopF0yG1IaPdCTEgVD jqRsOFmxlHeVKcs+acsWdQEnZnyMTdQCx53JJ2xO4Ymfhsk0DTxz1BAeoI579vJDTWGz HJKH14LYl07ux02WaizRjroitio6HxhnMIR7AowxsfIvftbEoz6P6N0p0VB8CjiAX0vl RA/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Bgh5+Uq3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-193454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193454-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-68229d0f4d2si9789099a12.697.2024.05.28.23.56.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 23:56:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Bgh5+Uq3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-193454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193454-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D9C7528A476 for ; Wed, 29 May 2024 05:37:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDC251667D1; Wed, 29 May 2024 05:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Bgh5+Uq3" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 8EA0815F417 for ; Wed, 29 May 2024 05:36:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716960976; cv=none; b=G41QqmFWxKjxTthPTq3nlV9G9Vzcox/DnMSjm0bJ977w0Meya37Wgf1M+HuQtfnqcZmMlOuYkyfz9neuwpPTJFW2ZZ537eQjHrTmT1yY81FXrRh3OI2SbjuQEn3wcZ6pWHIIODl7uq9KMqqbVTCqpTJB0SsuQm2DrJ4bysSaFmg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716960976; c=relaxed/simple; bh=xf05GvXEO+I215J3GQWK9zqCkzSYPhbVb/+Tz/JkYCQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ndpwMs/8BTbk/sxW98MFtHi/ERq4vUPJcIIFX8xI7IwWz7bVj+0VdoxO4C3aMEcrptQMe/8azMFeqreVKFQco3jgrCkRZZPJkgL3yroCSy0ibVYuW7fpoLTRVjaaOwhbjpdsbo+KSFbKWnib/aLOoDyqcuF4AVBbE9GGNu+m7p8= 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=Bgh5+Uq3; arc=none smtp.client-ip=192.198.163.14 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 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=xf05GvXEO+I215J3GQWK9zqCkzSYPhbVb/+Tz/JkYCQ=; b=Bgh5+Uq3rfQzo4IujodLM5ApJH6QiUAFgY81W0u2T+C5eQIRSOKgeojc ni4exGqvQDfPFKPX5YAZP7MYcdTqgavCsAcRhkCBwwLexYXaNWcz94lGP BhYpxVJyn+hpdgjhw59L/ybaRVTzq1tF1hS0UOthCi4TCCRmzWKC2BHM8 Y+x8M86GZy6EnDx3MiU7z1iqYcvy6fyI2Gfmr2gDT3KU3ovu0hQzHf5XM lT2Y7DZ5IYtcER1TM52yhv08dNUhyUmJF3lgOlBCF3D5qbLHGjKFL1enO 82PPxini4UQde6xLIDycvWpOyYMyz8jXRUhvIiHagN9NTiNUPUp5FT54B g==; X-CSE-ConnectionGUID: 5J9g22DLRBuUYT/oFcYjnQ== X-CSE-MsgGUID: 4WeBitFrSVCR3d4SU0s8Yg== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13568825" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13568825" 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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) -- 2.34.1