virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Nelson Escobar <neescoba@cisco.com>,
	Matthew Rosato <mjrosato@linux.ibm.com>,
	"Michael S. Tsirkin" <mst@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, Joerg Roedel <joro@8bytes.org>,
	iommu@lists.linux-foundation.org,
	Gerald Schaefer <gerald.schaefer@linux.ibm.com>,
	David Woodhouse <dwmw2@infradead.org>,
	linux-arm-msm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
	Cornelia Huck <cohuck@redhat.com>,
	Rob Clark <robdclark@gmail.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Christian Benvenuti <benve@cisco.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Lu Baolu <baolu.lu@linux.intel.com>
Subject: Re: [PATCH 2/5] vfio: Require that devices support DMA cache coherence
Date: Tue, 5 Apr 2022 13:10:44 -0600	[thread overview]
Message-ID: <20220405131044.23910b77.alex.williamson@redhat.com> (raw)
In-Reply-To: <2-v1-ef02c60ddb76+12ca2-intel_no_snoop_jgg@nvidia.com>

On Tue,  5 Apr 2022 13:16:01 -0300
Jason Gunthorpe <jgg@nvidia.com> wrote:

> dev_is_dma_coherent() is the control to determine if IOMMU_CACHE can be
> supported.
> 
> IOMMU_CACHE means that normal DMAs do not require any additional coherency
> mechanism and is the basic uAPI that VFIO exposes to userspace. For
> instance VFIO applications like DPDK will not work if additional coherency
> operations are required.
> 
> Therefore check dev_is_dma_coherent() before allowing a device to join a
> domain. This will block device/platform/iommu combinations from using VFIO
> that do not support cache coherent DMA.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/vfio.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index a4555014bd1e72..2a3aa3e742d943 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -32,6 +32,7 @@
>  #include <linux/vfio.h>
>  #include <linux/wait.h>
>  #include <linux/sched/signal.h>
> +#include <linux/dma-map-ops.h>
>  #include "vfio.h"
>  
>  #define DRIVER_VERSION	"0.3"
> @@ -1348,6 +1349,11 @@ static int vfio_group_get_device_fd(struct vfio_group *group, char *buf)
>  	if (IS_ERR(device))
>  		return PTR_ERR(device);
>  
> +	if (group->type == VFIO_IOMMU && !dev_is_dma_coherent(device->dev)) {
> +		ret = -ENODEV;
> +		goto err_device_put;
> +	}
> +

Failing at the point where the user is trying to gain access to the
device seems a little late in the process and opaque, wouldn't we
rather have vfio bus drivers fail to probe such devices?  I'd expect
this to occur in the vfio_register_group_dev() path.  Thanks,

Alex

>  	if (!try_module_get(device->dev->driver->owner)) {
>  		ret = -ENODEV;
>  		goto err_device_put;

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

       reply	other threads:[~2022-04-05 19:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <0-v1-ef02c60ddb76+12ca2-intel_no_snoop_jgg@nvidia.com>
     [not found] ` <2-v1-ef02c60ddb76+12ca2-intel_no_snoop_jgg@nvidia.com>
2022-04-05 19:10   ` Alex Williamson [this message]
     [not found]     ` <20220405192916.GT2120790@nvidia.com>
2022-04-06  7:02       ` [PATCH 2/5] vfio: Require that devices support DMA cache coherence Tian, Kevin
     [not found] ` <3-v1-ef02c60ddb76+12ca2-intel_no_snoop_jgg@nvidia.com>
2022-04-05 19:50   ` [PATCH 3/5] iommu: Introduce the domain op enforce_cache_coherency() Alex Williamson
     [not found]     ` <20220405225739.GW2120790@nvidia.com>
2022-04-05 23:31       ` Tian, Kevin
2022-04-06  0:08       ` Tian, Kevin
2022-04-06  7:09   ` Tian, Kevin
     [not found] ` <1-v1-ef02c60ddb76+12ca2-intel_no_snoop_jgg@nvidia.com>
2022-04-06  5:30   ` [PATCH 1/5] iommu: Replace uses of IOMMU_CAP_CACHE_COHERENCY with dev_is_dma_coherent() Christoph Hellwig
     [not found]     ` <20220406120730.GA2120790@nvidia.com>
2022-04-06 13:51       ` Christoph Hellwig
     [not found]         ` <20220406141446.GE2120790@nvidia.com>
2022-04-06 15:47           ` Christoph Hellwig
2022-04-06 15:48           ` Robin Murphy
2022-04-06 13:56   ` Robin Murphy
     [not found]     ` <20220406142432.GF2120790@nvidia.com>
     [not found]       ` <20220406151823.GG2120790@nvidia.com>
2022-04-06 15:50         ` Christoph Hellwig
     [not found]           ` <20220406160623.GI2120790@nvidia.com>
2022-04-06 16:10             ` Christoph Hellwig
     [not found]               ` <20220406171729.GJ2120790@nvidia.com>
2022-04-07  7:18                 ` Tian, Kevin
     [not found]                   ` <20220407135946.GM2120790@nvidia.com>
2022-04-07 15:17                     ` Robin Murphy
2022-04-07 15:31                       ` Christoph Hellwig
     [not found]                       ` <20220407152331.GN2120790@nvidia.com>
2022-04-07 22:37                         ` Alex Williamson
2022-04-06  6:52 ` [PATCH 0/5] Make the iommu driver no-snoop block feature consistent Tian, Kevin

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=20220405131044.23910b77.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=benve@cisco.com \
    --cc=cohuck@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=gerald.schaefer@linux.ibm.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --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=mjrosato@linux.ibm.com \
    --cc=mst@redhat.com \
    --cc=neescoba@cisco.com \
    --cc=netdev@vger.kernel.org \
    --cc=robdclark@gmail.com \
    --cc=robin.murphy@arm.com \
    --cc=suravee.suthikulpanit@amd.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 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).