All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe via iommu <iommu@lists.linux-foundation.org>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Nelson Escobar <neescoba@cisco.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	virtualization@lists.linux-foundation.org,
	Will Deacon <will@kernel.org>, Christoph Hellwig <hch@lst.de>,
	linux-s390@vger.kernel.org, kvm@vger.kernel.org,
	linux-rdma@vger.kernel.org,
	Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
	"Tian, Kevin" <kevin.tian@intel.com>,
	linux-arm-msm@vger.kernel.org,
	Alex Williamson <alex.williamson@redhat.com>,
	linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
	Cornelia Huck <cohuck@redhat.com>,
	iommu@lists.linux-foundation.org,
	Christian Benvenuti <benve@cisco.com>,
	David Woodhouse <dwmw2@infradead.org>
Subject: Re: [PATCH 1/5] iommu: Replace uses of IOMMU_CAP_CACHE_COHERENCY with dev_is_dma_coherent()
Date: Wed, 6 Apr 2022 12:18:23 -0300	[thread overview]
Message-ID: <20220406151823.GG2120790@nvidia.com> (raw)
In-Reply-To: <20220406142432.GF2120790@nvidia.com>

On Wed, Apr 06, 2022 at 11:24:32AM -0300, Jason Gunthorpe wrote:
> On Wed, Apr 06, 2022 at 02:56:56PM +0100, Robin Murphy wrote:
> > On 2022-04-05 17:16, Jason Gunthorpe wrote:
> > > vdpa and usnic are trying to test if IOMMU_CACHE is supported. The correct
> > > way to do this is via dev_is_dma_coherent()
> > 
> > Not necessarily...
> > 
> > Disregarding the complete disaster of PCIe No Snoop on Arm-Based systems,
> > there's the more interesting effectively-opposite scenario where an SMMU
> > bridges non-coherent devices to a coherent interconnect. It's not something
> > we take advantage of yet in Linux, and it can only be properly described in
> > ACPI, but there do exist situations where IOMMU_CACHE is capable of making
> > the device's traffic snoop, but dev_is_dma_coherent() - and
> > device_get_dma_attr() for external users - would still say non-coherent
> > because they can't assume that the SMMU is enabled and programmed in just
> > the right way.
> 
> Oh, I didn't know about device_get_dma_attr()..
> 
> Considering your future issue, maybe this:
> 
> /*
>  * true if the given domain supports IOMMU_CACHE and when dev is attached to
>  * that domain it will have coherent DMA and require no cache
>  * maintenance when IOMMU_CACHE is used.
>  */
> bool iommu_domain_supports_coherent_dma(struct iommu_domain *domain, struct device *dev)
> {
> 	return device_get_dma_attr(dev) == DEV_DMA_COHERENT;
> }
> 
> ? In future it could become a domain op and the SMMU driver could
> figure out the situation you described?

I also spent some time looking at something like this:

struct iommu_domain *iommu_domain_alloc_coherent(struct device *device)
{
	if (device_get_dma_attr(device) == DEV_DMA_COHERENT)
		return NULL;
	return __iommu_domain_alloc(device->bus, IOMMU_DOMAIN_UNMANAGED);
}
EXPORT_SYMBOL_GPL(iommu_domain_alloc_coherent);

Which could evolve into to passing the flag down to the iommu driver
and then it could ensure SMMU is "programmed in just the right way"
or fail?

Could also go like this:

#define IOMMU_DOMAIN_FLAG_COHERENT 1
struct iommu_domain *iommu_device_alloc_domain(struct device *device,
                                               unsigned int flags)

A new alloc option is not so easy to fit VFIO into right now though.

Advices?

Thanks,
Jason
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@nvidia.com>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Christian Benvenuti <benve@cisco.com>,
	Cornelia Huck <cohuck@redhat.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
	iommu@lists.linux-foundation.org,
	Jason Wang <jasowang@redhat.com>, Joerg Roedel <joro@8bytes.org>,
	kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-s390@vger.kernel.org,
	Matthew Rosato <mjrosato@linux.ibm.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Nelson Escobar <neescoba@cisco.com>,
	netdev@vger.kernel.org, Rob Clark <robdclark@gmail.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	virtualization@lists.linux-foundation.org,
	Will Deacon <will@kernel.org>, Christoph Hellwig <hch@lst.de>,
	"Tian, Kevin" <kevin.tian@intel.com>
Subject: Re: [PATCH 1/5] iommu: Replace uses of IOMMU_CAP_CACHE_COHERENCY with dev_is_dma_coherent()
Date: Wed, 6 Apr 2022 12:18:23 -0300	[thread overview]
Message-ID: <20220406151823.GG2120790@nvidia.com> (raw)
In-Reply-To: <20220406142432.GF2120790@nvidia.com>

On Wed, Apr 06, 2022 at 11:24:32AM -0300, Jason Gunthorpe wrote:
> On Wed, Apr 06, 2022 at 02:56:56PM +0100, Robin Murphy wrote:
> > On 2022-04-05 17:16, Jason Gunthorpe wrote:
> > > vdpa and usnic are trying to test if IOMMU_CACHE is supported. The correct
> > > way to do this is via dev_is_dma_coherent()
> > 
> > Not necessarily...
> > 
> > Disregarding the complete disaster of PCIe No Snoop on Arm-Based systems,
> > there's the more interesting effectively-opposite scenario where an SMMU
> > bridges non-coherent devices to a coherent interconnect. It's not something
> > we take advantage of yet in Linux, and it can only be properly described in
> > ACPI, but there do exist situations where IOMMU_CACHE is capable of making
> > the device's traffic snoop, but dev_is_dma_coherent() - and
> > device_get_dma_attr() for external users - would still say non-coherent
> > because they can't assume that the SMMU is enabled and programmed in just
> > the right way.
> 
> Oh, I didn't know about device_get_dma_attr()..
> 
> Considering your future issue, maybe this:
> 
> /*
>  * true if the given domain supports IOMMU_CACHE and when dev is attached to
>  * that domain it will have coherent DMA and require no cache
>  * maintenance when IOMMU_CACHE is used.
>  */
> bool iommu_domain_supports_coherent_dma(struct iommu_domain *domain, struct device *dev)
> {
> 	return device_get_dma_attr(dev) == DEV_DMA_COHERENT;
> }
> 
> ? In future it could become a domain op and the SMMU driver could
> figure out the situation you described?

I also spent some time looking at something like this:

struct iommu_domain *iommu_domain_alloc_coherent(struct device *device)
{
	if (device_get_dma_attr(device) == DEV_DMA_COHERENT)
		return NULL;
	return __iommu_domain_alloc(device->bus, IOMMU_DOMAIN_UNMANAGED);
}
EXPORT_SYMBOL_GPL(iommu_domain_alloc_coherent);

Which could evolve into to passing the flag down to the iommu driver
and then it could ensure SMMU is "programmed in just the right way"
or fail?

Could also go like this:

#define IOMMU_DOMAIN_FLAG_COHERENT 1
struct iommu_domain *iommu_device_alloc_domain(struct device *device,
                                               unsigned int flags)

A new alloc option is not so easy to fit VFIO into right now though.

Advices?

Thanks,
Jason

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@nvidia.com>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Christian Benvenuti <benve@cisco.com>,
	Cornelia Huck <cohuck@redhat.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
	iommu@lists.linux-foundation.org,
	Jason Wang <jasowang@redhat.com>, Joerg Roedel <joro@8bytes.org>,
	kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-s390@vger.kernel.org,
	Matthew Rosato <mjrosato@linux.ibm.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Nelson Escobar <neescoba@cisco.com>,
	netdev@vger.kernel.org, Rob Clark <robdclark@gmail.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	virtualization@lists.linux-foundation.org,
	Will Deacon <will@kernel.org>, Christoph Hellwig <hch@lst.de>,
	"Tian, Kevin" <kevin.tian@intel.com>
Subject: Re: [PATCH 1/5] iommu: Replace uses of IOMMU_CAP_CACHE_COHERENCY with dev_is_dma_coherent()
Date: Wed, 6 Apr 2022 12:18:23 -0300	[thread overview]
Message-ID: <20220406151823.GG2120790@nvidia.com> (raw)
In-Reply-To: <20220406142432.GF2120790@nvidia.com>

On Wed, Apr 06, 2022 at 11:24:32AM -0300, Jason Gunthorpe wrote:
> On Wed, Apr 06, 2022 at 02:56:56PM +0100, Robin Murphy wrote:
> > On 2022-04-05 17:16, Jason Gunthorpe wrote:
> > > vdpa and usnic are trying to test if IOMMU_CACHE is supported. The correct
> > > way to do this is via dev_is_dma_coherent()
> > 
> > Not necessarily...
> > 
> > Disregarding the complete disaster of PCIe No Snoop on Arm-Based systems,
> > there's the more interesting effectively-opposite scenario where an SMMU
> > bridges non-coherent devices to a coherent interconnect. It's not something
> > we take advantage of yet in Linux, and it can only be properly described in
> > ACPI, but there do exist situations where IOMMU_CACHE is capable of making
> > the device's traffic snoop, but dev_is_dma_coherent() - and
> > device_get_dma_attr() for external users - would still say non-coherent
> > because they can't assume that the SMMU is enabled and programmed in just
> > the right way.
> 
> Oh, I didn't know about device_get_dma_attr()..
> 
> Considering your future issue, maybe this:
> 
> /*
>  * true if the given domain supports IOMMU_CACHE and when dev is attached to
>  * that domain it will have coherent DMA and require no cache
>  * maintenance when IOMMU_CACHE is used.
>  */
> bool iommu_domain_supports_coherent_dma(struct iommu_domain *domain, struct device *dev)
> {
> 	return device_get_dma_attr(dev) == DEV_DMA_COHERENT;
> }
> 
> ? In future it could become a domain op and the SMMU driver could
> figure out the situation you described?

I also spent some time looking at something like this:

struct iommu_domain *iommu_domain_alloc_coherent(struct device *device)
{
	if (device_get_dma_attr(device) == DEV_DMA_COHERENT)
		return NULL;
	return __iommu_domain_alloc(device->bus, IOMMU_DOMAIN_UNMANAGED);
}
EXPORT_SYMBOL_GPL(iommu_domain_alloc_coherent);

Which could evolve into to passing the flag down to the iommu driver
and then it could ensure SMMU is "programmed in just the right way"
or fail?

Could also go like this:

#define IOMMU_DOMAIN_FLAG_COHERENT 1
struct iommu_domain *iommu_device_alloc_domain(struct device *device,
                                               unsigned int flags)

A new alloc option is not so easy to fit VFIO into right now though.

Advices?

Thanks,
Jason

  reply	other threads:[~2022-04-06 15:18 UTC|newest]

Thread overview: 135+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-05 16:15 [PATCH 0/5] Make the iommu driver no-snoop block feature consistent Jason Gunthorpe via iommu
2022-04-05 16:15 ` Jason Gunthorpe
2022-04-05 16:15 ` Jason Gunthorpe
2022-04-05 16:16 ` [PATCH 1/5] iommu: Replace uses of IOMMU_CAP_CACHE_COHERENCY with dev_is_dma_coherent() Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-06  5:30   ` Christoph Hellwig
2022-04-06  5:30     ` Christoph Hellwig
2022-04-06  5:30     ` Christoph Hellwig
2022-04-06  5:30     ` Christoph Hellwig
2022-04-06 12:07     ` Jason Gunthorpe via iommu
2022-04-06 12:07       ` Jason Gunthorpe
2022-04-06 12:07       ` Jason Gunthorpe
2022-04-06 13:51       ` Christoph Hellwig
2022-04-06 13:51         ` Christoph Hellwig
2022-04-06 13:51         ` Christoph Hellwig
2022-04-06 13:51         ` Christoph Hellwig
2022-04-06 14:14         ` Jason Gunthorpe via iommu
2022-04-06 14:14           ` Jason Gunthorpe
2022-04-06 14:14           ` Jason Gunthorpe
2022-04-06 15:47           ` Christoph Hellwig
2022-04-06 15:47             ` Christoph Hellwig
2022-04-06 15:47             ` Christoph Hellwig
2022-04-06 15:47             ` Christoph Hellwig
2022-04-06 15:48             ` Jason Gunthorpe via iommu
2022-04-06 15:48               ` Jason Gunthorpe
2022-04-06 15:48               ` Jason Gunthorpe
2022-04-06 15:48           ` Robin Murphy
2022-04-06 15:48             ` Robin Murphy
2022-04-06 15:48             ` Robin Murphy
2022-04-06 15:48             ` Robin Murphy
2022-04-06 13:56   ` Robin Murphy
2022-04-06 13:56     ` Robin Murphy
2022-04-06 13:56     ` Robin Murphy
2022-04-06 13:56     ` Robin Murphy
2022-04-06 14:24     ` Jason Gunthorpe via iommu
2022-04-06 14:24       ` Jason Gunthorpe
2022-04-06 14:24       ` Jason Gunthorpe
2022-04-06 15:18       ` Jason Gunthorpe via iommu [this message]
2022-04-06 15:18         ` Jason Gunthorpe
2022-04-06 15:18         ` Jason Gunthorpe
2022-04-06 15:50         ` Christoph Hellwig
2022-04-06 15:50           ` Christoph Hellwig
2022-04-06 15:50           ` Christoph Hellwig
2022-04-06 15:50           ` Christoph Hellwig
2022-04-06 16:06           ` Jason Gunthorpe via iommu
2022-04-06 16:06             ` Jason Gunthorpe
2022-04-06 16:06             ` Jason Gunthorpe
2022-04-06 16:10             ` Christoph Hellwig
2022-04-06 16:10               ` Christoph Hellwig
2022-04-06 16:10               ` Christoph Hellwig
2022-04-06 16:10               ` Christoph Hellwig
2022-04-06 17:17               ` Jason Gunthorpe via iommu
2022-04-06 17:17                 ` Jason Gunthorpe
2022-04-06 17:17                 ` Jason Gunthorpe
2022-04-07  7:18                 ` Tian, Kevin
2022-04-07  7:18                   ` Tian, Kevin
2022-04-07  7:18                   ` Tian, Kevin
2022-04-07  7:18                   ` Tian, Kevin
2022-04-07 13:59                   ` Jason Gunthorpe via iommu
2022-04-07 13:59                     ` Jason Gunthorpe
2022-04-07 13:59                     ` Jason Gunthorpe
2022-04-07 15:17                     ` Robin Murphy
2022-04-07 15:17                       ` Robin Murphy
2022-04-07 15:17                       ` Robin Murphy
2022-04-07 15:17                       ` Robin Murphy
2022-04-07 15:23                       ` Jason Gunthorpe
2022-04-07 15:23                         ` Jason Gunthorpe
2022-04-07 15:23                         ` Jason Gunthorpe via iommu
2022-04-07 22:37                         ` Alex Williamson
2022-04-07 22:37                           ` Alex Williamson
2022-04-07 22:37                           ` Alex Williamson
2022-04-07 22:37                           ` Alex Williamson
2022-04-07 15:31                       ` Christoph Hellwig
2022-04-07 15:31                         ` Christoph Hellwig
2022-04-07 15:31                         ` Christoph Hellwig
2022-04-07 15:31                         ` Christoph Hellwig
2022-04-07  8:53                 ` Niklas Schnelle
2022-04-07  8:53                   ` Niklas Schnelle
2022-04-07  8:53                   ` Niklas Schnelle
2022-04-05 16:16 ` [PATCH 2/5] vfio: Require that devices support DMA cache coherence Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 19:10   ` Alex Williamson
2022-04-05 19:10     ` Alex Williamson
2022-04-05 19:10     ` Alex Williamson
2022-04-05 19:10     ` Alex Williamson
2022-04-05 19:29     ` Jason Gunthorpe via iommu
2022-04-05 19:29       ` Jason Gunthorpe
2022-04-05 19:29       ` Jason Gunthorpe
2022-04-06  7:02       ` Tian, Kevin
2022-04-06  7:02         ` Tian, Kevin
2022-04-06  7:02         ` Tian, Kevin
2022-04-06  7:02         ` Tian, Kevin
2022-04-07 14:53         ` Jason Gunthorpe
2022-04-07 14:53           ` Jason Gunthorpe
2022-04-07 14:53           ` Jason Gunthorpe via iommu
2022-04-05 16:16 ` [PATCH 3/5] iommu: Introduce the domain op enforce_cache_coherency() Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 19:50   ` Alex Williamson
2022-04-05 19:50     ` Alex Williamson
2022-04-05 19:50     ` Alex Williamson
2022-04-05 19:50     ` Alex Williamson
2022-04-05 22:57     ` Jason Gunthorpe via iommu
2022-04-05 22:57       ` Jason Gunthorpe
2022-04-05 22:57       ` Jason Gunthorpe
2022-04-05 23:31       ` Tian, Kevin
2022-04-05 23:31         ` Tian, Kevin
2022-04-05 23:31         ` Tian, Kevin
2022-04-05 23:31         ` Tian, Kevin
2022-04-06  0:08       ` Tian, Kevin
2022-04-06  0:08         ` Tian, Kevin
2022-04-06  0:08         ` Tian, Kevin
2022-04-06  0:08         ` Tian, Kevin
2022-04-06  7:09   ` Tian, Kevin
2022-04-06  7:09     ` Tian, Kevin
2022-04-06  7:09     ` Tian, Kevin
2022-04-06  7:09     ` Tian, Kevin
2022-04-06 12:27     ` Jason Gunthorpe via iommu
2022-04-06 12:27       ` Jason Gunthorpe
2022-04-06 12:27       ` Jason Gunthorpe
2022-04-05 16:16 ` [PATCH 4/5] vfio: Move the Intel no-snoop control off of IOMMU_CACHE Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16 ` [PATCH 5/5] iommu: Delete IOMMU_CAP_CACHE_COHERENCY Jason Gunthorpe via iommu
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-05 16:16   ` Jason Gunthorpe
2022-04-06  6:52 ` [PATCH 0/5] Make the iommu driver no-snoop block feature consistent Tian, Kevin
2022-04-06  6:52   ` Tian, Kevin
2022-04-06  6:52   ` Tian, Kevin
2022-04-06  6:52   ` Tian, Kevin
2022-04-07 14:56   ` Jason Gunthorpe
2022-04-07 14:56     ` Jason Gunthorpe
2022-04-07 14:56     ` Jason Gunthorpe via iommu

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=20220406151823.GG2120790@nvidia.com \
    --to=iommu@lists.linux-foundation.org \
    --cc=alex.williamson@redhat.com \
    --cc=benve@cisco.com \
    --cc=cohuck@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=gerald.schaefer@linux.ibm.com \
    --cc=hch@lst.de \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=neescoba@cisco.com \
    --cc=netdev@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.