iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: isaacm@codeaurora.org, robin.murphy@arm.com,
	iommu@lists.linux-foundation.org, will@kernel.org
Subject: Re: [PATCH RFC 7/9] iommu: Introduce map_sg() as an IOMMU op for IOMMU drivers
Date: Thu, 28 Jan 2021 10:58:14 +0800	[thread overview]
Message-ID: <092dc0f4-5c9a-a811-00ae-2eb15d5c1675@linux.intel.com> (raw)
In-Reply-To: <161177766681.1311.8296027937092927846.stgit@manet.1015granger.net>

Hi,

On 1/28/21 4:01 AM, Chuck Lever wrote:
> From: Isaac J. Manjarres <isaacm@codeaurora.org>
> 
> Add support for IOMMU drivers to have their own map_sg() callbacks.
> This completes the path for having iommu_map_sg() invoke an IOMMU
> driver's map_sg() callback, which can then invoke the io-pgtable
> map_sg() callback with the entire scatter-gather list, so that it
> can be processed entirely in the io-pgtable layer.
> 
> For IOMMU drivers that do not provide a callback, the default
> implementation of iterating through the scatter-gather list, while
> calling iommu_map() will be used.
> 
> Signed-off-by: Isaac J. Manjarres <isaacm@codeaurora.org>
> Tested-by: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>
> [ cel: adjusted new iotlb_sync_map call site ]
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
>   drivers/iommu/iommu.c |   12 ++++++++++++
>   include/linux/iommu.h |    5 +++++
>   2 files changed, 17 insertions(+)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index ed879a4d7fac..bd7adbd0339b 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -2551,6 +2551,18 @@ static size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova,
>   	unsigned int i = 0;
>   	int ret;
>   
> +	if (ops->map_sg) {
> +		ret = ops->map_sg(domain, iova, sg, nents, prot, gfp, &mapped);
> +
> +		if (ops->iotlb_sync_map)
> +			ops->iotlb_sync_map(domain, iova, mapped);
> +
> +		if (ret)
> +			goto out_err;
> +
> +		return mapped;
> +	}
> +
>   	while (i <= nents) {
>   		phys_addr_t s_phys = sg_phys(sg);
>   
> diff --git a/include/linux/iommu.h b/include/linux/iommu.h
> index cd5f35022a25..667edc7b034a 100644
> --- a/include/linux/iommu.h
> +++ b/include/linux/iommu.h
> @@ -192,6 +192,8 @@ struct iommu_iotlb_gather {
>    * @attach_dev: attach device to an iommu domain
>    * @detach_dev: detach device from an iommu domain
>    * @map: map a physically contiguous memory region to an iommu domain
> + * @map_sg: map a scatter-gather list of physically contiguous chunks to
> + *          an iommu domain.
>    * @unmap: unmap a physically contiguous memory region from an iommu domain
>    * @flush_iotlb_all: Synchronously flush all hardware TLBs for this domain
>    * @iotlb_sync_map: Sync mappings created recently using @map to the hardware
> @@ -243,6 +245,9 @@ struct iommu_ops {
>   	void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
>   	int (*map)(struct iommu_domain *domain, unsigned long iova,
>   		   phys_addr_t paddr, size_t size, int prot, gfp_t gfp);
> +	int (*map_sg)(struct iommu_domain *domain, unsigned long iova,
> +		      struct scatterlist *sg, unsigned int nents, int prot,
> +		      gfp_t gfp, size_t *mapped);

I might be oversensitive. But what if the vendor iommu driver uses iova
beyond the pre-allocated range? It's safer if we could pass an iova
length parameter as well, so that the iommu driver could do some sanity
check.

Best regards,
baolu

>   	size_t (*unmap)(struct iommu_domain *domain, unsigned long iova,
>   		     size_t size, struct iommu_iotlb_gather *iotlb_gather);
>   	void (*flush_iotlb_all)(struct iommu_domain *domain);
> 
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2021-01-28  3:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27 20:00 [PATCH RFC 0/9] Possible set of VT-d optimizations Chuck Lever
2021-01-27 20:00 ` [PATCH RFC 1/9] iommu: Move iotlb_sync_map out from __iommu_map Chuck Lever
2021-01-28  2:40   ` Lu Baolu
2021-01-27 20:00 ` [PATCH RFC 2/9] iommu: Add iova and size as parameters in iotlb_sync_map Chuck Lever
2021-01-28  2:44   ` Lu Baolu
2021-01-28 12:51   ` Joerg Roedel
2021-01-28 13:19     ` Will Deacon
2021-01-28 13:26       ` Joerg Roedel
2021-01-27 20:00 ` [PATCH RFC 3/9] iommu/vt-d: Add iotlb_sync_map callback Chuck Lever
2021-01-27 20:00 ` [PATCH RFC 4/9] iommu/io-pgtable: Introduce map_sg() as a page table op Chuck Lever
2021-01-27 20:00 ` [PATCH RFC 5/9] iommu/io-pgtable-arm: Hook up map_sg() Chuck Lever
2021-01-28 13:53   ` Will Deacon
2021-01-27 20:01 ` [PATCH RFC 6/9] iommu/io-pgtable-arm-v7s: " Chuck Lever
2021-01-27 20:01 ` [PATCH RFC 7/9] iommu: Introduce map_sg() as an IOMMU op for IOMMU drivers Chuck Lever
2021-01-28  2:58   ` Lu Baolu [this message]
2021-01-27 20:01 ` [PATCH RFC 8/9] iommu/arm-smmu: Hook up map_sg() Chuck Lever
2021-01-27 20:01 ` [PATCH RFC 9/9] iommu/vt-d: Introduce map_sg() for Intel IOMMUs Chuck Lever
2021-01-28  2:28 ` [PATCH RFC 0/9] Possible set of VT-d optimizations Lu Baolu
2021-01-28 13:59 ` Robin Murphy
2021-01-28 14:52   ` Chuck Lever
2021-01-29 11:54     ` Lu Baolu
2021-02-01 18:08     ` Chuck Lever

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=092dc0f4-5c9a-a811-00ae-2eb15d5c1675@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=chuck.lever@oracle.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=isaacm@codeaurora.org \
    --cc=robin.murphy@arm.com \
    --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).