Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp13234197rwl; Wed, 4 Jan 2023 05:32:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXu86h1cbQFiRB9m5mvC6ef7Io/B9Ypf18A78kyj1VKUduFKuIqrSGd0MgowxkP1oF1603T1 X-Received: by 2002:a17:906:5788:b0:78d:f455:c396 with SMTP id k8-20020a170906578800b0078df455c396mr39308317ejq.60.1672839155666; Wed, 04 Jan 2023 05:32:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672839155; cv=none; d=google.com; s=arc-20160816; b=HTcFtm7BQXAii2wqtxpUxsko6eJnRdmBCZiM4wu1b+2C4avBV1rmEM+t+0yGGYh5fG y9gZ6wkQSBMrf7+Z2jnRx8vVdxc+yNR1JYwTixE3qMavN4sfGH8wfKHGC1PZez6fSRGY e4vXLaYgguIfiGDKL4ONAG0ZRybD6+LJ/XyKDTzN1Czm1P7k9b5klMTU2s5v45UZ6Xx9 wJVqPf+aCtM6lqkq3GwSof8r97eciuIRR+Q7LJM/2oEWCRohMZIoBJCvKU/YdzIHSbFn iK5eZsB+Ok5FE7MqenGqbmTnK7eEeSmeiiGNpxEeML+vd/FNS61X0c5uMsql0mW5JmgT ymUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5VH2S4nI3FNargaYEhSNXwqpoV08iAbdsxF7HU55tvQ=; b=YvWVOs8Mtfk4wn1bwnGQj+GYFUSGmj5VNn4Z6zx2SjBaba23eLxcPiCgmtOmcUGloQ RW/VhOjdrCfsdsSAbFJt0E1aYVJl6UJ7R/FdlgscPmtxtVkUYRfB7K37ZCeQcnCcLQbG NgyQzZ/eDZuz+mJC6fa/gE1mwicaq8xaFs9dA/ybJ3axNSqFxIe6umZtHtxBmb+gd4JK 3njwRaqmbswAPjwgNKWhXWpu6VhxXfUaY5DjlcTwGjRYdzzH0/wTxHuIcQL9Ha4162Ni weniIq1AA+7tIpAL9K2/V/VtiOK6ivSLOmK2E8eCoyIC+hw9KLtEn34mCHVA1xM0THP8 bc1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lWpQjES+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t6-20020a170906608600b0084c3ce2f3dbsi21090777ejj.633.2023.01.04.05.32.22; Wed, 04 Jan 2023 05:32:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lWpQjES+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239305AbjADNH2 (ORCPT + 57 others); Wed, 4 Jan 2023 08:07:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239294AbjADNGu (ORCPT ); Wed, 4 Jan 2023 08:06:50 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 097F7E45 for ; Wed, 4 Jan 2023 05:06:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672837588; x=1704373588; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1DSM4fHz5l5HcYyLuKZ27aWJHPiNFSeHrlfd99N8Mho=; b=lWpQjES+ZHcguUi0H5ibzy0IZwpUPiM6OBjo6PAjrR63okVYveqfZpR0 J8mNPR9HCid+Kko/ihZS33gw+YpdHZ9fV+zBdnHC1ce5DxUd2XIyCORza MjxgGDopdPxmAGe25JijzpniQBbleqd3xYnMryUYIHkltm0nK3c8V5/qF ssO1xojZa6Uoty7Vqn9jronKGjA4KJs2AVgtJWPre8FtX0gJVhlv4mpdL QMdaC06BKF0anrF6KyA+nCP0uKrio5zRAYd0bMIzyzKnxIoKanoV0wzD8 Qq7BcAY9Y+/XInH+xQ+FoUrvrhsX1N3NEJFC1yiyO5Xp7LPBd59lCdrU5 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10579"; a="320639955" X-IronPort-AV: E=Sophos;i="5.96,299,1665471600"; d="scan'208";a="320639955" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2023 05:06:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10579"; a="797529106" X-IronPort-AV: E=Sophos;i="5.96,299,1665471600"; d="scan'208";a="797529106" Received: from allen-box.sh.intel.com ([10.239.159.48]) by fmsmga001.fm.intel.com with ESMTP; 04 Jan 2023 05:06:21 -0800 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Kevin Tian , Will Deacon , Robin Murphy , Jean-Philippe Brucker Cc: Suravee Suthikulpanit , Hector Martin , Sven Peter , Rob Clark , Marek Szyprowski , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson , Yong Wu , Matthias Brugger , Heiko Stuebner , Matthew Rosato , Orson Zhai , Baolin Wang , Chunyan Zhang , Chen-Yu Tsai , Thierry Reding , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v4 10/19] iommu: Add set_platform_dma_ops iommu ops Date: Wed, 4 Jan 2023 20:57:16 +0800 Message-Id: <20230104125725.271850-11-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230104125725.271850-1-baolu.lu@linux.intel.com> References: <20230104125725.271850-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When VFIO finishes assigning a device to user space and calls iommu_group_release_dma_owner() to return the device to kernel, the IOMMU core will attach the default domain to the device. Unfortunately, some IOMMU drivers don't support default domain, hence in the end, the core calls .detach_dev instead. This adds set_platform_dma_ops iommu ops to make it clear that what it does is returning control back to the platform DMA ops. Suggested-by: Jason Gunthorpe Reviewed-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- include/linux/iommu.h | 4 ++++ drivers/iommu/iommu.c | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 46e1347bfa22..7b3e3775b069 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -228,6 +228,9 @@ struct iommu_iotlb_gather { * @release_device: Remove device from iommu driver handling * @probe_finalize: Do final setup work after the device is added to an IOMMU * group and attached to the groups domain + * @set_platform_dma_ops: Returning control back to the platform DMA ops. This op + * is to support old IOMMU drivers, new drivers should use + * default domains, and the common IOMMU DMA ops. * @device_group: find iommu group for a particular device * @get_resv_regions: Request list of reserved regions for a device * @of_xlate: add OF master IDs to iommu grouping @@ -256,6 +259,7 @@ struct iommu_ops { struct iommu_device *(*probe_device)(struct device *dev); void (*release_device)(struct device *dev); void (*probe_finalize)(struct device *dev); + void (*set_platform_dma_ops)(struct device *dev); struct iommu_group *(*device_group)(struct device *dev); /* Request/Free a list of reserved regions for a device */ diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index de91dd88705b..4e35a9f94873 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2163,6 +2163,17 @@ static int iommu_group_do_detach_device(struct device *dev, void *data) return 0; } +static int iommu_group_do_set_platform_dma(struct device *dev, void *data) +{ + const struct iommu_ops *ops = dev_iommu_ops(dev); + + if (!ops->set_platform_dma_ops) + return -EINVAL; + + ops->set_platform_dma_ops(dev); + return 0; +} + static int __iommu_group_set_domain(struct iommu_group *group, struct iommu_domain *new_domain) { @@ -2177,10 +2188,14 @@ static int __iommu_group_set_domain(struct iommu_group *group, * platform specific behavior. */ if (!new_domain) { - if (WARN_ON(!group->domain->ops->detach_dev)) - return -EINVAL; - __iommu_group_for_each_dev(group, group->domain, - iommu_group_do_detach_device); + ret = __iommu_group_for_each_dev(group, NULL, + iommu_group_do_set_platform_dma); + if (ret) { + if (WARN_ON(!group->domain->ops->detach_dev)) + return -EINVAL; + __iommu_group_for_each_dev(group, group->domain, + iommu_group_do_detach_device); + } group->domain = NULL; return 0; } -- 2.34.1