From: Jakub Kicinski <kuba@kernel.org>
To: robin.murphy@arm.com, m.szyprowski@samsung.com
Cc: tglx@kernel.org, dave.hansen@linux.intel.com, x86@kernel.org,
joro@8bytes.org, will@kernel.org, leon@kernel.org,
mbloch@nvidia.com, iommu@lists.linux.dev, netdev@vger.kernel.org,
Jakub Kicinski <kuba@kernel.org>
Subject: [RFC 03/11] iommu/dma: pass the NUMA node to iommu_dma_alloc()
Date: Mon, 26 Oct 2026 19:25:20 -0700 [thread overview]
Message-ID: <20261027022528.633359-4-kuba@kernel.org> (raw)
In-Reply-To: <20261027022528.633359-1-kuba@kernel.org>
iommu_dma_alloc() allocates the pages on the node of the device.
Pass the node in explicitly, so that a node-aware coherent allocation
API can be layered on top.
Memory from the atomic pools is not node-aware.
iommu_dma_alloc_noncontiguous() keeps using the device's node.
Callers pass dev_to_node() for now, no functional change.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
include/linux/iommu-dma.h | 2 +-
drivers/iommu/dma-iommu.c | 28 ++++++++++++++++------------
kernel/dma/mapping.c | 3 ++-
3 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/include/linux/iommu-dma.h b/include/linux/iommu-dma.h
index 060f6e23ab3c..067872f14629 100644
--- a/include/linux/iommu-dma.h
+++ b/include/linux/iommu-dma.h
@@ -31,7 +31,7 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
enum dma_data_direction dir, unsigned long attrs);
void *iommu_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
- gfp_t gfp, unsigned long attrs);
+ gfp_t gfp, unsigned long attrs, int node);
int iommu_dma_mmap(struct device *dev, struct vm_area_struct *vma,
void *cpu_addr, dma_addr_t dma_addr, size_t size,
unsigned long attrs);
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index bb82ba3be440..1dc2e235380a 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -882,10 +882,10 @@ static void __iommu_dma_free_pages(struct page **pages, int count)
}
static struct page **__iommu_dma_alloc_pages(struct device *dev,
- unsigned int count, unsigned long order_mask, gfp_t gfp)
+ unsigned int count, unsigned long order_mask, gfp_t gfp, int nid)
{
struct page **pages;
- unsigned int i = 0, nid = dev_to_node(dev);
+ unsigned int i = 0;
order_mask &= GENMASK(MAX_PAGE_ORDER, 0);
if (!order_mask)
@@ -938,7 +938,8 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev,
* but an IOMMU which supports smaller pages might not map the whole thing.
*/
static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev,
- size_t size, struct sg_table *sgt, gfp_t gfp, unsigned long attrs)
+ size_t size, struct sg_table *sgt, gfp_t gfp, unsigned long attrs,
+ int node)
{
struct iommu_domain *domain = iommu_get_dma_domain(dev);
struct iommu_dma_cookie *cookie = domain->iova_cookie;
@@ -966,7 +967,7 @@ static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev,
count = PAGE_ALIGN(size) >> PAGE_SHIFT;
pages = __iommu_dma_alloc_pages(dev, count, alloc_sizes >> PAGE_SHIFT,
- gfp);
+ gfp, node);
if (!pages)
return NULL;
@@ -1012,14 +1013,15 @@ static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev,
}
static void *iommu_dma_alloc_remap(struct device *dev, size_t size,
- dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
+ dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs, int node)
{
struct page **pages;
struct sg_table sgt;
void *vaddr;
pgprot_t prot = dma_pgprot(dev, PAGE_KERNEL, attrs);
- pages = __iommu_dma_alloc_noncontiguous(dev, size, &sgt, gfp, attrs);
+ pages = __iommu_dma_alloc_noncontiguous(dev, size, &sgt, gfp, attrs,
+ node);
if (!pages)
return NULL;
*dma_handle = sgt.sgl->dma_address;
@@ -1060,7 +1062,8 @@ struct sg_table *iommu_dma_alloc_noncontiguous(struct device *dev, size_t size,
if (!sh)
return NULL;
- sh->pages = __iommu_dma_alloc_noncontiguous(dev, size, &sh->sgt, gfp, attrs);
+ sh->pages = __iommu_dma_alloc_noncontiguous(dev, size, &sh->sgt, gfp,
+ attrs, dev_to_node(dev));
if (!sh->pages) {
kfree(sh);
return NULL;
@@ -1619,11 +1622,10 @@ void iommu_dma_free(struct device *dev, size_t size, void *cpu_addr,
}
static void *iommu_dma_alloc_pages(struct device *dev, size_t size,
- struct page **pagep, gfp_t gfp, unsigned long attrs)
+ struct page **pagep, gfp_t gfp, unsigned long attrs, int node)
{
bool coherent = dev_is_dma_coherent(dev);
size_t alloc_size = PAGE_ALIGN(size);
- int node = dev_to_node(dev);
struct page *page = NULL;
void *cpu_addr;
@@ -1656,7 +1658,7 @@ static void *iommu_dma_alloc_pages(struct device *dev, size_t size,
}
void *iommu_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
- gfp_t gfp, unsigned long attrs)
+ gfp_t gfp, unsigned long attrs, int node)
{
bool coherent = dev_is_dma_coherent(dev);
int ioprot = dma_info_to_prot(DMA_BIDIRECTIONAL, coherent, attrs);
@@ -1672,7 +1674,8 @@ void *iommu_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
if (gfpflags_allow_blocking(gfp) &&
!(attrs & DMA_ATTR_FORCE_CONTIGUOUS)) {
- return iommu_dma_alloc_remap(dev, size, handle, gfp, attrs);
+ return iommu_dma_alloc_remap(dev, size, handle, gfp, attrs,
+ node);
}
if (IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
@@ -1682,7 +1685,8 @@ void *iommu_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
if (!page)
return NULL;
} else {
- cpu_addr = iommu_dma_alloc_pages(dev, size, &page, gfp, attrs);
+ cpu_addr = iommu_dma_alloc_pages(dev, size, &page, gfp, attrs,
+ node);
if (!cpu_addr)
return NULL;
}
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 1c3a70025195..4ace4b68c9c2 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -668,7 +668,8 @@ void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
cpu_addr = dma_direct_alloc(dev, size, dma_handle, flag, attrs,
dev_to_node(dev));
} else if (use_dma_iommu(dev)) {
- cpu_addr = iommu_dma_alloc(dev, size, dma_handle, flag, attrs);
+ cpu_addr = iommu_dma_alloc(dev, size, dma_handle, flag, attrs,
+ dev_to_node(dev));
} else if (ops->alloc) {
cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs);
} else {
--
2.56.0
next prev parent reply other threads:[~2026-10-27 2:26 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 2:25 [RFC 00/11] dma-mapping: add dma_alloc_attrs_node() and dma_alloc_coherent_node() Jakub Kicinski
2026-10-27 2:25 ` [RFC 01/11] dma-contiguous: pass the NUMA node to dma_alloc_contiguous() Jakub Kicinski
2026-10-27 2:25 ` [RFC 02/11] dma-direct: pass the NUMA node to dma_direct_alloc() Jakub Kicinski
2026-10-27 2:25 ` Jakub Kicinski [this message]
2026-10-27 2:25 ` [RFC 04/11] dma-mapping: add dma_alloc_attrs_node() and dma_alloc_coherent_node() Jakub Kicinski
2026-10-27 9:03 ` Björn Töpel
2026-10-27 15:53 ` Jakub Kicinski
2026-10-27 15:24 ` Marek Szyprowski
2026-10-27 17:52 ` Jakub Kicinski
2026-10-28 9:00 ` Marek Szyprowski
2026-10-27 2:25 ` [RFC 05/11] eth: libwx: restore the device's NUMA node after ring allocation Jakub Kicinski
2026-10-27 2:25 ` [RFC 06/11] eth: libwx: use dma_alloc_coherent_node() Jakub Kicinski
2026-10-27 2:25 ` [RFC 07/11] eth: ixgbe: " Jakub Kicinski
2026-10-27 9:06 ` Björn Töpel
2026-10-27 15:51 ` Jakub Kicinski
2026-10-27 16:06 ` Björn Töpel
2026-10-27 18:20 ` Jakub Kicinski
2026-10-29 8:47 ` Björn Töpel
2026-10-29 9:17 ` Marek Szyprowski
2026-10-27 2:25 ` [RFC 08/11] eth: xgbe: " Jakub Kicinski
2026-10-27 2:25 ` [RFC 09/11] eth: fungible: " Jakub Kicinski
2026-10-27 2:25 ` [RFC 10/11] eth: mlx5: " Jakub Kicinski
2026-10-27 2:25 ` [RFC 11/11] eth: mlx4: " Jakub Kicinski
2026-10-27 9:03 ` [RFC 00/11] dma-mapping: add dma_alloc_attrs_node() and dma_alloc_coherent_node() Björn Töpel
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=20261027022528.633359-4-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=leon@kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=tglx@kernel.org \
--cc=will@kernel.org \
--cc=x86@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.