Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753343AbeAQNcW (ORCPT + 1 other); Wed, 17 Jan 2018 08:32:22 -0500 Received: from regular1.263xmail.com ([211.150.99.130]:38124 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753136AbeAQNcU (ORCPT ); Wed, 17 Jan 2018 08:32:20 -0500 X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: robin.murphy@arm.com X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <3994d27ca5eadffc0916d0a04bc0b7e4> X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 Message-ID: <5A5F5050.5040308@rock-chips.com> Date: Wed, 17 Jan 2018 21:32:00 +0800 From: JeffyChen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20130126 Thunderbird/19.0 MIME-Version: 1.0 To: Robin Murphy , linux-kernel@vger.kernel.org CC: jcliang@chromium.org, xxm@rock-chips.com, tfiga@chromium.org, Heiko Stuebner , linux-rockchip@lists.infradead.org, iommu@lists.linux-foundation.org, Joerg Roedel , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 13/13] iommu/rockchip: Support sharing IOMMU between masters References: <20180116132540.18939-1-jeffy.chen@rock-chips.com> <20180116132540.18939-14-jeffy.chen@rock-chips.com> <1bd5378d-8285-e0d9-8105-f9dd9f8cfdcb@arm.com> In-Reply-To: <1bd5378d-8285-e0d9-8105-f9dd9f8cfdcb@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hi Robin, On 01/17/2018 09:00 PM, Robin Murphy wrote: > On 16/01/18 13:25, Jeffy Chen wrote: >> There would be some masters sharing the same IOMMU device. Put them in >> the same iommu group and share the same iommu domain. >> >> Signed-off-by: Jeffy Chen >> --- >> >> Changes in v2: None >> >> drivers/iommu/rockchip-iommu.c | 39 >> +++++++++++++++++++++++++++++++-------- >> 1 file changed, 31 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/iommu/rockchip-iommu.c >> b/drivers/iommu/rockchip-iommu.c >> index c8de1456a016..6c316dd0dd2d 100644 >> --- a/drivers/iommu/rockchip-iommu.c >> +++ b/drivers/iommu/rockchip-iommu.c >> @@ -100,11 +100,13 @@ struct rk_iommu { >> struct iommu_device iommu; >> struct list_head node; /* entry in rk_iommu_domain.iommus */ >> struct iommu_domain *domain; /* domain to which iommu is >> attached */ >> + struct iommu_group *group; >> struct mutex pm_mutex; /* serializes power transitions */ >> }; >> struct rk_iommudata { >> struct device_link *link; /* runtime PM link from IOMMU to >> master */ >> + struct iommu_domain *domain; /* domain to which device is >> attached */ > > I don't see why this is needed - for example, mtk_iommu does the same > thing without needing to track the active domain in more than one place. > > Fundamentally, for this kind of IOMMU without the notion of multiple > translation contexts, the logic should look like: > > iommudrv_attach_device(dev, domain) { > iommu = dev_get_iommu(dev); > if (iommu->curr_domain != domain) { > update_hw_state(iommu, domain); > iommu->curr_domain = domain; > } > } > > which I think is essentially what you have anyway. When a group contains > multiple devices, you update the IOMMU state for the first device, then > calls for subsequent devices in the group do nothing since they see the > IOMMU state is already up-to-date with the new domain. > right, will remove it. > Robin.