linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Will Deacon <will@kernel.org>
Cc: freedreno@lists.freedesktop.org, kvm@vger.kernel.org,
	Michael Ellerman <mpe@ellerman.id.au>,
	linuxppc-dev@lists.ozlabs.org, dri-devel@lists.freedesktop.org,
	Li Yang <leoyang.li@nxp.com>,
	iommu@lists.linux-foundation.org, netdev@vger.kernel.org,
	linux-arm-msm@vger.kernel.org,
	virtualization@lists.linux-foundation.org,
	David Woodhouse <dwmw2@infradead.org>,
	Christoph Hellwig <hch@lst.de>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 16/18] iommu: remove DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE
Date: Wed, 31 Mar 2021 17:05:08 +0100	[thread overview]
Message-ID: <81dd27fe-28ee-c800-fe5d-aaa64cb93513@arm.com> (raw)
In-Reply-To: <20210331153256.GA7815@willie-the-truck>

On 2021-03-31 16:32, Will Deacon wrote:
> On Wed, Mar 31, 2021 at 02:09:37PM +0100, Robin Murphy wrote:
>> On 2021-03-31 12:49, Will Deacon wrote:
>>> On Tue, Mar 30, 2021 at 05:28:19PM +0100, Robin Murphy wrote:
>>>> On 2021-03-30 14:58, Will Deacon wrote:
>>>>> On Tue, Mar 30, 2021 at 02:19:38PM +0100, Robin Murphy wrote:
>>>>>> On 2021-03-30 14:11, Will Deacon wrote:
>>>>>>> On Tue, Mar 16, 2021 at 04:38:22PM +0100, Christoph Hellwig wrote:
>>>>>>>> From: Robin Murphy <robin.murphy@arm.com>
>>>>>>>>
>>>>>>>> Instead make the global iommu_dma_strict paramete in iommu.c canonical by
>>>>>>>> exporting helpers to get and set it and use those directly in the drivers.
>>>>>>>>
>>>>>>>> This make sure that the iommu.strict parameter also works for the AMD and
>>>>>>>> Intel IOMMU drivers on x86.  As those default to lazy flushing a new
>>>>>>>> IOMMU_CMD_LINE_STRICT is used to turn the value into a tristate to
>>>>>>>> represent the default if not overriden by an explicit parameter.
>>>>>>>>
>>>>>>>> Signed-off-by: Robin Murphy <robin.murphy@arm.com>.
>>>>>>>> [ported on top of the other iommu_attr changes and added a few small
>>>>>>>>      missing bits]
>>>>>>>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>>>>>>>> ---
>>>>>>>>      drivers/iommu/amd/iommu.c                   | 23 +-------
>>>>>>>>      drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 50 +---------------
>>>>>>>>      drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h |  1 -
>>>>>>>>      drivers/iommu/arm/arm-smmu/arm-smmu.c       | 27 +--------
>>>>>>>>      drivers/iommu/dma-iommu.c                   |  9 +--
>>>>>>>>      drivers/iommu/intel/iommu.c                 | 64 ++++-----------------
>>>>>>>>      drivers/iommu/iommu.c                       | 27 ++++++---
>>>>>>>>      include/linux/iommu.h                       |  4 +-
>>>>>>>>      8 files changed, 40 insertions(+), 165 deletions(-)
>>>>>>>
>>>>>>> I really like this cleanup, but I can't help wonder if it's going in the
>>>>>>> wrong direction. With SoCs often having multiple IOMMU instances and a
>>>>>>> distinction between "trusted" and "untrusted" devices, then having the
>>>>>>> flush-queue enabled on a per-IOMMU or per-domain basis doesn't sound
>>>>>>> unreasonable to me, but this change makes it a global property.
>>>>>>
>>>>>> The intent here was just to streamline the existing behaviour of stuffing a
>>>>>> global property into a domain attribute then pulling it out again in the
>>>>>> illusion that it was in any way per-domain. We're still checking
>>>>>> dev_is_untrusted() before making an actual decision, and it's not like we
>>>>>> can't add more factors at that point if we want to.
>>>>>
>>>>> Like I say, the cleanup is great. I'm just wondering whether there's a
>>>>> better way to express the complicated logic to decide whether or not to use
>>>>> the flush queue than what we end up with:
>>>>>
>>>>> 	if (!cookie->fq_domain && (!dev || !dev_is_untrusted(dev)) &&
>>>>> 	    domain->ops->flush_iotlb_all && !iommu_get_dma_strict())
>>>>>
>>>>> which is mixing up globals, device properties and domain properties. The
>>>>> result is that the driver code ends up just using the global to determine
>>>>> whether or not to pass IO_PGTABLE_QUIRK_NON_STRICT to the page-table code,
>>>>> which is a departure from the current way of doing things.
>>>>
>>>> But previously, SMMU only ever saw the global policy piped through the
>>>> domain attribute by iommu_group_alloc_default_domain(), so there's no
>>>> functional change there.
>>>
>>> For DMA domains sure, but I don't think that's the case for unmanaged
>>> domains such as those used by VFIO.
>>
>> Eh? This is only relevant to DMA domains anyway. Flush queues are part of
>> the IOVA allocator that VFIO doesn't even use. It's always been the case
>> that unmanaged domains only use strict invalidation.
> 
> Maybe I'm going mad. With this patch, the SMMU driver unconditionally sets
> IO_PGTABLE_QUIRK_NON_STRICT for page-tables if iommu_get_dma_strict() is
> true, no? In which case, that will get set for page-tables corresponding
> to unmanaged domains as well as DMA domains when it is enabled. That didn't
> happen before because you couldn't set the attribute for unmanaged domains.
> 
> What am I missing?

Oh cock... sorry, all this time I've been saying what I *expect* it to 
do, while overlooking the fact that the IO_PGTABLE_QUIRK_NON_STRICT 
hunks were the bits I forgot to write and Christoph had to fix up. 
Indeed, those should be checking the domain type too to preserve the 
existing behaviour. Apologies for the confusion.

Robin.

>>>> Obviously some of the above checks could be factored out into some kind of
>>>> iommu_use_flush_queue() helper that IOMMU drivers can also call if they need
>>>> to keep in sync. Or maybe we just allow iommu-dma to set
>>>> IO_PGTABLE_QUIRK_NON_STRICT directly via iommu_set_pgtable_quirks() if we're
>>>> treating that as a generic thing now.
>>>
>>> I think a helper that takes a domain would be a good starting point.
>>
>> You mean device, right? The one condition we currently have is at the device
>> level, and there's really nothing inherent to the domain itself that matters
>> (since the type is implicitly IOMMU_DOMAIN_DMA to even care about this).
> 
> Device would probably work too; you'd pass the first device to attach to the
> domain when querying this from the SMMU driver, I suppose.
> 
> Will
> 

  reply	other threads:[~2021-03-31 16:06 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 15:38 cleanup unused or almost unused IOMMU APIs and the FSL PAMU driver v2 Christoph Hellwig
2021-03-16 15:38 ` [PATCH 01/18] iommu: remove the unused domain_window_disable method Christoph Hellwig
2021-03-30 12:04   ` Will Deacon
2021-03-16 15:38 ` [PATCH 02/18] iommu/fsl_pamu: remove fsl_pamu_get_domain_attr Christoph Hellwig
2021-03-30 12:10   ` Will Deacon
2021-03-16 15:38 ` [PATCH 03/18] iommu/fsl_pamu: remove support for setting DOMAIN_ATTR_GEOMETRY Christoph Hellwig
2021-03-30 12:15   ` Will Deacon
2021-03-16 15:38 ` [PATCH 04/18] iommu/fsl_pamu: merge iommu_alloc_dma_domain into fsl_pamu_domain_alloc Christoph Hellwig
2021-03-30 12:17   ` Will Deacon
2021-03-16 15:38 ` [PATCH 05/18] iommu/fsl_pamu: remove support for multiple windows Christoph Hellwig
2021-03-30 12:22   ` Will Deacon
2021-04-01  9:29     ` Christoph Hellwig
2021-03-16 15:38 ` [PATCH 06/18] iommu/fsl_pamu: remove ->domain_window_enable Christoph Hellwig
2021-03-30 12:40   ` Will Deacon
2021-04-01  9:32     ` Christoph Hellwig
2021-03-16 15:38 ` [PATCH 07/18] iommu/fsl_pamu: replace DOMAIN_ATTR_FSL_PAMU_STASH with a direct call Christoph Hellwig
2021-03-30 12:44   ` Will Deacon
2021-03-16 15:38 ` [PATCH 08/18] iommu/fsl_pamu: merge pamu_set_liodn and map_liodn Christoph Hellwig
2021-03-30 12:46   ` Will Deacon
2021-04-01  9:34     ` Christoph Hellwig
2021-03-16 15:38 ` [PATCH 09/18] iommu/fsl_pamu: merge handle_attach_device into fsl_pamu_attach_device Christoph Hellwig
2021-03-30 12:48   ` Will Deacon
2021-03-16 15:38 ` [PATCH 10/18] iommu/fsl_pamu: enable the liodn when attaching a device Christoph Hellwig
2021-03-30 12:53   ` Will Deacon
2021-03-16 15:38 ` [PATCH 11/18] iommu/fsl_pamu: remove the snoop_id field Christoph Hellwig
2021-03-30 12:58   ` Will Deacon
2021-04-01  9:36     ` Christoph Hellwig
2021-03-16 15:38 ` [PATCH 12/18] iommu: remove DOMAIN_ATTR_PAGING Christoph Hellwig
2021-03-30 12:58   ` Will Deacon
2021-03-16 15:38 ` [PATCH 13/18] iommu: remove DOMAIN_ATTR_GEOMETRY Christoph Hellwig
2021-03-30 13:00   ` Will Deacon
2021-03-16 15:38 ` [PATCH 14/18] iommu: remove DOMAIN_ATTR_NESTING Christoph Hellwig
2021-03-30 13:04   ` Will Deacon
2021-03-16 15:38 ` [PATCH 15/18] iommu: remove iommu_set_cmd_line_dma_api and iommu_cmd_line_dma_api Christoph Hellwig
2021-03-30 13:05   ` Will Deacon
2021-03-16 15:38 ` [PATCH 16/18] iommu: remove DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE Christoph Hellwig
2021-03-30 13:11   ` Will Deacon
2021-03-30 13:19     ` Robin Murphy
2021-03-30 13:58       ` Will Deacon
2021-03-30 16:28         ` Robin Murphy
2021-03-31 11:49           ` Will Deacon
2021-03-31 13:09             ` Robin Murphy
2021-03-31 15:32               ` Will Deacon
2021-03-31 16:05                 ` Robin Murphy [this message]
2021-04-01  9:59                   ` Christoph Hellwig
2021-04-01 13:26                     ` Will Deacon
2021-03-31 16:07   ` Robin Murphy
2021-03-16 15:38 ` [PATCH 17/18] iommu: remove DOMAIN_ATTR_IO_PGTABLE_CFG Christoph Hellwig
2021-03-30 13:14   ` Will Deacon
2021-03-16 15:38 ` [PATCH 18/18] iommu: remove iommu_domain_{get,set}_attr Christoph Hellwig
2021-03-30 13:16   ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81dd27fe-28ee-c800-fe5d-aaa64cb93513@arm.com \
    --to=robin.murphy@arm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=dwmw2@infradead.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=kvm@vger.kernel.org \
    --cc=leoyang.li@nxp.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).