Linux IOMMU Development
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Dan Carpenter <dan.carpenter@oracle.com>, Joerg Roedel <joro@8bytes.org>
Cc: iommu@lists.linux-foundation.org, Joerg Roedel <jroedel@suse.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iommu/amd: Pass gfp flags to iommu_map_page() in amd_iommu_map()
Date: Fri, 18 Oct 2019 10:50:34 +0100	[thread overview]
Message-ID: <31ba66a3-2435-2fb1-3fc6-782a2f583bf2@arm.com> (raw)
In-Reply-To: <20191018092750.GK21344@kadam>

On 2019-10-18 10:27 am, Dan Carpenter wrote:
> Did you get a chance to look at iommu_dma_alloc_remap() as well?
> 
> drivers/iommu/dma-iommu.c
>     584  static void *iommu_dma_alloc_remap(struct device *dev, size_t size,
>     585                  dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
>                                                  ^^^^^^^^^
>     586  {
>     587          struct iommu_domain *domain = iommu_get_dma_domain(dev);
>     588          struct iommu_dma_cookie *cookie = domain->iova_cookie;
>     589          struct iova_domain *iovad = &cookie->iovad;
>     590          bool coherent = dev_is_dma_coherent(dev);
>     591          int ioprot = dma_info_to_prot(DMA_BIDIRECTIONAL, coherent, attrs);
>     592          pgprot_t prot = dma_pgprot(dev, PAGE_KERNEL, attrs);
>     593          unsigned int count, min_size, alloc_sizes = domain->pgsize_bitmap;
>     594          struct page **pages;
>     595          struct sg_table sgt;
>     596          dma_addr_t iova;
>     597          void *vaddr;
>     598
>     599          *dma_handle = DMA_MAPPING_ERROR;
>     600
>     601          if (unlikely(iommu_dma_deferred_attach(dev, domain)))
>     602                  return NULL;
>     603
>     604          min_size = alloc_sizes & -alloc_sizes;
>     605          if (min_size < PAGE_SIZE) {
>     606                  min_size = PAGE_SIZE;
>     607                  alloc_sizes |= PAGE_SIZE;
>     608          } else {
>     609                  size = ALIGN(size, min_size);
>     610          }
>     611          if (attrs & DMA_ATTR_ALLOC_SINGLE_PAGES)
>     612                  alloc_sizes = min_size;
>     613
>     614          count = PAGE_ALIGN(size) >> PAGE_SHIFT;
>     615          pages = __iommu_dma_alloc_pages(dev, count, alloc_sizes >> PAGE_SHIFT,
>     616                                          gfp);
>     617          if (!pages)
>     618                  return NULL;
>     619
>     620          size = iova_align(iovad, size);
>     621          iova = iommu_dma_alloc_iova(domain, size, dev->coherent_dma_mask, dev);
>     622          if (!iova)
>     623                  goto out_free_pages;
>     624
>     625          if (sg_alloc_table_from_pages(&sgt, pages, count, 0, size, GFP_KERNEL))
>                                                                             ^^^^^^^^^^
> gfp here instead of GFP_KERNEL?

This is, from what I remember, intentional - it's a temporary allocation 
which doesn't need to have the same restrictions as the actual buffer 
being allocated (e.g. GFP_DMA32 etc.). We don't need to worry about 
GFP_ATOMIC since the whole thing is only ever called in sleeping contexts.

Robin.

> 
>     626                  goto out_free_iova;
>     627
>     628          if (!(ioprot & IOMMU_CACHE)) {
> 
> regards,
> dan carpenter
> 
> _______________________________________________
> iommu mailing list
> iommu@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/iommu
> 
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

      reply	other threads:[~2019-10-18  9:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18  9:07 [PATCH] iommu/amd: Pass gfp flags to iommu_map_page() in amd_iommu_map() Joerg Roedel
2019-10-18  9:20 ` Jerry Snitselaar
2019-10-18  9:27 ` Dan Carpenter
2019-10-18  9:50   ` Robin Murphy [this message]

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=31ba66a3-2435-2fb1-3fc6-782a2f583bf2@arm.com \
    --to=robin.murphy@arm.com \
    --cc=dan.carpenter@oracle.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=jroedel@suse.de \
    --cc=linux-kernel@vger.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