iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: Jacob Pan <jacob.jun.pan@linux.intel.com>,
	iommu@lists.linux-foundation.org,
	LKML <linux-kernel@vger.kernel.org>,
	Joerg Roedel <joro@8bytes.org>, Jason Gunthorpe <jgg@nvidia.com>,
	Christoph Hellwig <hch@infradead.org>,
	Jean-Philippe Brucker <jean-philippe@linaro.com>
Cc: "Tian, Kevin" <kevin.tian@intel.com>,
	Tony Luck <tony.luck@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Raj Ashok <ashok.raj@intel.com>,
	"Zanussi, Tom" <tom.zanussi@intel.com>,
	"Kumar, Sanjay K" <sanjay.k.kumar@intel.com>,
	Jacob Pan <jacob.jun.pan@intel.com>,
	Dan Williams <dan.j.williams@intel.com>
Subject: Re: [PATCH v2 5/8] iommu: Add PASID support for DMA mapping API users
Date: Fri, 18 Mar 2022 20:43:54 +0800	[thread overview]
Message-ID: <12390112-c497-1f02-5ddc-ad8ee3645347@linux.intel.com> (raw)
In-Reply-To: <20220315050713.2000518-6-jacob.jun.pan@linux.intel.com>

On 2022/3/15 13:07, Jacob Pan wrote:
> DMA mapping API is the de facto standard for in-kernel DMA. It operates
> on a per device/RID basis which is not PASID-aware.
> 
> Some modern devices such as Intel Data Streaming Accelerator, PASID is
> required for certain work submissions. To allow such devices use DMA
> mapping API, we need the following functionalities:
> 1. Provide device a way to retrieve a PASID for work submission within
> the kernel
> 2. Enable the kernel PASID on the IOMMU for the device
> 3. Attach the kernel PASID to the device's default DMA domain, let it
> be IOVA or physical address in case of pass-through.
> 
> This patch introduces a driver facing API that enables DMA API
> PASID usage. Once enabled, device drivers can continue to use DMA APIs as
> is. There is no difference in dma_handle between without PASID and with
> PASID.
> 
> Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
> ---
>   drivers/iommu/dma-iommu.c | 65 +++++++++++++++++++++++++++++++++++++++
>   include/linux/dma-iommu.h |  7 +++++
>   include/linux/iommu.h     |  9 ++++++
>   3 files changed, 81 insertions(+)
> 
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index b22034975301..d0ff1a34b1b6 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -39,6 +39,8 @@ enum iommu_dma_cookie_type {
>   	IOMMU_DMA_MSI_COOKIE,
>   };
>   
> +static DECLARE_IOASID_SET(iommu_dma_pasid);
> +
>   struct iommu_dma_cookie {
>   	enum iommu_dma_cookie_type	type;
>   	union {
> @@ -370,6 +372,69 @@ void iommu_put_dma_cookie(struct iommu_domain *domain)
>   	domain->iova_cookie = NULL;
>   }
>   
> +/**
> + * iommu_enable_pasid_dma --Enable in-kernel DMA request with PASID
> + * @dev:	Device to be enabled
> + *
> + * DMA request with PASID will be mapped the same way as the legacy DMA.
> + * If the device is in pass-through, PASID will also pass-through. If the
> + * device is in IOVA map, the supervisor PASID will point to the same IOVA
> + * page table.
> + *
> + * @return the kernel PASID to be used for DMA or INVALID_IOASID on failure

The comment on the return value should be rephrased according to the
real code.

> + */
> +int iommu_enable_pasid_dma(struct device *dev, ioasid_t *pasid)
> +{
> +	struct iommu_domain *dom;
> +	ioasid_t id, max;
> +	int ret;
> +
> +	dom = iommu_get_domain_for_dev(dev);
> +	if (!dom || !dom->ops || !dom->ops->attach_dev_pasid)
> +		return -ENODEV;
> +	max = iommu_get_dev_pasid_max(dev);
> +	if (!max)
> +		return -EINVAL;
> +
> +	id = ioasid_alloc(&iommu_dma_pasid, 1, max, dev);
> +	if (id == INVALID_IOASID)
> +		return -ENOMEM;
> +
> +	ret = dom->ops->attach_dev_pasid(dom, dev, id);
> +	if (ret) {
> +		ioasid_put(id);
> +		return ret;
> +	}
> +	*pasid = id;
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(iommu_enable_pasid_dma);
> +
> +/**
> + * iommu_disable_pasid_dma --Disable in-kernel DMA request with PASID
> + * @dev:	Device's PASID DMA to be disabled
> + *
> + * It is the device driver's responsibility to ensure no more incoming DMA
> + * requests with the kernel PASID before calling this function. IOMMU driver
> + * ensures PASID cache, IOTLBs related to the kernel PASID are cleared and
> + * drained.
> + *
> + * @return 0 on success or error code on failure

Ditto.

> + */
> +void iommu_disable_pasid_dma(struct device *dev, ioasid_t pasid)
> +{
> +	struct iommu_domain *dom;
> +
> +	/* TODO: check the given PASID is within the ioasid_set */
> +	dom = iommu_get_domain_for_dev(dev);
> +	if (!dom->ops->detach_dev_pasid)
> +		return;
> +	dom->ops->detach_dev_pasid(dom, dev, pasid);
> +	ioasid_put(pasid);
> +}
> +EXPORT_SYMBOL(iommu_disable_pasid_dma);
> +
>   /**
>    * iommu_dma_get_resv_regions - Reserved region driver helper
>    * @dev: Device from iommu_get_resv_regions()
> diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h
> index 24607dc3c2ac..e6cb9b52a420 100644
> --- a/include/linux/dma-iommu.h
> +++ b/include/linux/dma-iommu.h
> @@ -18,6 +18,13 @@ int iommu_get_dma_cookie(struct iommu_domain *domain);
>   int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
>   void iommu_put_dma_cookie(struct iommu_domain *domain);
>   
> +/*
> + * For devices that can do DMA request with PASID, setup a system PASID.
> + * Address modes (IOVA, PA) are selected by the platform code.
> + */

No need for a comment here. Or move it to the function if need.

> +int iommu_enable_pasid_dma(struct device *dev, ioasid_t *pasid);
> +void iommu_disable_pasid_dma(struct device *dev, ioasid_t pasid);
> +
>   /* Setup call for arch DMA mapping code */
>   void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit);
>   int iommu_dma_init_fq(struct iommu_domain *domain);
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index fde5b933dbe3..fb011722e4f8 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -395,6 +395,15 @@ static inline void iommu_set_dev_pasid_max(struct device *dev,
>   
>   	param->pasid_max = max;
>   }
> +static inline ioasid_t iommu_get_dev_pasid_max(struct device *dev)
> +{
> +	struct dev_iommu *param = dev->iommu;
> +
> +	if (WARN_ON(!param))
> +		return 0;
> +
> +	return param->pasid_max;
> +}
>   
>   int iommu_device_register(struct iommu_device *iommu,
>   			  const struct iommu_ops *ops,

Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  parent reply	other threads:[~2022-03-18 12:44 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15  5:07 [PATCH v2 0/8] Enable PASID for DMA API users Jacob Pan
2022-03-15  5:07 ` [PATCH v2 1/8] iommu: Assign per device max PASID Jacob Pan
2022-03-15  5:07 ` [PATCH v2 2/8] iommu: Add attach/detach_dev_pasid domain ops Jacob Pan
2022-03-15 10:24   ` Tian, Kevin
2022-03-15 11:26   ` Jean-Philippe Brucker
2022-03-15 11:49     ` Tian, Kevin
2022-03-15 16:11       ` Jacob Pan
2022-03-18 12:01       ` Lu Baolu
2022-03-18 13:50         ` Jason Gunthorpe via iommu
2022-03-18 11:52   ` Lu Baolu
2022-03-18 13:48     ` Jason Gunthorpe via iommu
2022-03-15  5:07 ` [PATCH v2 3/8] iommu/vt-d: Implement device_pasid domain attach ops Jacob Pan
2022-03-15 10:33   ` Tian, Kevin
2022-03-15 22:23     ` Jacob Pan
2022-03-15 14:33   ` Jason Gunthorpe via iommu
2022-03-15 22:36     ` Jacob Pan
2022-03-15 23:04       ` Jason Gunthorpe via iommu
2022-03-16 20:50         ` Jacob Pan
2022-03-16 22:15           ` Jason Gunthorpe via iommu
2022-03-16 22:23             ` Luck, Tony
2022-03-17  0:04               ` Jason Gunthorpe via iommu
2022-03-18  5:47                 ` Tian, Kevin
2022-03-18 13:47                   ` Jason Gunthorpe via iommu
2022-03-17  0:49             ` Jacob Pan
2022-03-17 13:23               ` Jason Gunthorpe via iommu
2022-03-17 18:23                 ` Jacob Pan
2022-03-16  7:41     ` Tian, Kevin
2022-03-16 21:01       ` Jacob Pan
2022-03-18  5:33         ` Tian, Kevin
2022-03-28 21:41           ` Jacob Pan
2022-03-16  7:39   ` Tian, Kevin
2022-03-16 20:51     ` Jacob Pan
2022-03-15  5:07 ` [PATCH v2 4/8] iommu/vt-d: Use device_pasid attach op for RID2PASID Jacob Pan
2022-03-16  7:54   ` Tian, Kevin
2022-03-17 20:45     ` Jacob Pan
2022-03-15  5:07 ` [PATCH v2 5/8] iommu: Add PASID support for DMA mapping API users Jacob Pan
2022-03-15 11:16   ` Robin Murphy
2022-03-15 14:22     ` Jason Gunthorpe via iommu
2022-03-15 16:31       ` Jacob Pan
2022-03-15 17:05         ` Jason Gunthorpe via iommu
2022-03-15 21:24           ` Jacob Pan
2022-03-16 10:32             ` Tian, Kevin
2022-03-16  8:41       ` Tian, Kevin
2022-03-16 14:07         ` Jason Gunthorpe via iommu
2022-03-15 14:35   ` Jason Gunthorpe via iommu
2022-03-15 16:38     ` Jacob Pan
2022-03-15 23:05       ` Jason Gunthorpe via iommu
2022-03-18 12:43   ` Lu Baolu [this message]
2022-03-28 21:44     ` Jacob Pan
2022-03-15  5:07 ` [PATCH v2 6/8] dmaengine: idxd: Use DMA API for in-kernel DMA with PASID Jacob Pan
2022-03-18  6:10   ` Tian, Kevin
2022-03-29 17:39     ` Jacob Pan
2022-03-15  5:07 ` [PATCH v2 7/8] iommu/vt-d: Delete supervisor/kernel SVA Jacob Pan
2022-03-18  6:16   ` Tian, Kevin
2022-03-29 17:42     ` Jacob Pan
2022-03-15  5:07 ` [PATCH v2 8/8] iommu: Remove unused driver data in sva_bind_device Jacob Pan
2022-03-15 11:37   ` Jean-Philippe Brucker
2022-03-15  5:07 ` [PATCH v2 9/9] dmaengine: idxd: separate user and kernel pasid enabling Jacob Pan
2022-03-18  6:28   ` Tian, Kevin
2022-03-15  8:16 ` [PATCH v2 0/8] Enable PASID for DMA API users Tian, Kevin
2022-03-15 15:49   ` Jacob Pan

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=12390112-c497-1f02-5ddc-ad8ee3645347@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=ashok.raj@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=hch@infradead.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jacob.jun.pan@intel.com \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=jean-philippe@linaro.com \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sanjay.k.kumar@intel.com \
    --cc=tom.zanussi@intel.com \
    --cc=tony.luck@intel.com \
    /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).