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 02/11] dma-direct: pass the NUMA node to dma_direct_alloc()
Date: Mon, 26 Oct 2026 19:25:19 -0700 [thread overview]
Message-ID: <20261027022528.633359-3-kuba@kernel.org> (raw)
In-Reply-To: <20261027022528.633359-1-kuba@kernel.org>
dma_direct_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, the global coherent pool, restricted
swiotlb pools and arch_dma_alloc() is not node-aware, the node is only
used for the page allocator and the per-numa CMA areas.
Callers pass dev_to_node() for now, no functional change.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
include/linux/dma-direct.h | 2 +-
arch/x86/kernel/amd_gart_64.c | 3 ++-
kernel/dma/direct.c | 18 ++++++++++--------
kernel/dma/mapping.c | 3 ++-
4 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h
index daa31a1adf7b..7e864b75be6b 100644
--- a/include/linux/dma-direct.h
+++ b/include/linux/dma-direct.h
@@ -158,7 +158,7 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
u64 dma_direct_get_required_mask(struct device *dev);
void *dma_direct_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
- gfp_t gfp, unsigned long attrs);
+ gfp_t gfp, unsigned long attrs, int node);
void dma_direct_free(struct device *dev, size_t size, void *cpu_addr,
dma_addr_t dma_addr, unsigned long attrs);
struct page *dma_direct_alloc_pages(struct device *dev, size_t size,
diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
index b5f1f031d45b..05f3d7da6df8 100644
--- a/arch/x86/kernel/amd_gart_64.c
+++ b/arch/x86/kernel/amd_gart_64.c
@@ -468,7 +468,8 @@ gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr,
{
void *vaddr;
- vaddr = dma_direct_alloc(dev, size, dma_addr, flag, attrs);
+ vaddr = dma_direct_alloc(dev, size, dma_addr, flag, attrs,
+ dev_to_node(dev));
if (!vaddr ||
!force_iommu || dev->coherent_dma_mask <= DMA_BIT_MASK(24))
return vaddr;
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 9787a45f46f1..81953adf872c 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -115,9 +115,8 @@ static struct page *dma_direct_alloc_swiotlb(struct device *dev, size_t size,
}
static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
- gfp_t gfp, bool allow_highmem)
+ gfp_t gfp, bool allow_highmem, int node)
{
- int node = dev_to_node(dev);
struct page *page;
u64 phys_limit;
@@ -180,11 +179,12 @@ static struct page *dma_direct_alloc_from_pool(struct device *dev, size_t size,
}
static void *dma_direct_alloc_no_mapping(struct device *dev, size_t size,
- dma_addr_t *dma_handle, gfp_t gfp)
+ dma_addr_t *dma_handle, gfp_t gfp, int node)
{
struct page *page;
- page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO, true);
+ page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO, true,
+ node);
if (!page)
return NULL;
@@ -200,7 +200,7 @@ static void *dma_direct_alloc_no_mapping(struct device *dev, size_t size,
}
void *dma_direct_alloc(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)
{
bool remap = false, set_uncached = false;
bool mark_mem_decrypt = false;
@@ -228,7 +228,8 @@ void *dma_direct_alloc(struct device *dev, size_t size,
if (((attrs & (DMA_ATTR_NO_KERNEL_MAPPING | __DMA_ATTR_ALLOC_CC_SHARED)) ==
DMA_ATTR_NO_KERNEL_MAPPING) && !is_swiotlb_for_alloc(dev))
- return dma_direct_alloc_no_mapping(dev, size, dma_handle, gfp);
+ return dma_direct_alloc_no_mapping(dev, size, dma_handle, gfp,
+ node);
if (!dev_is_dma_coherent(dev)) {
if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_ALLOC) &&
@@ -286,7 +287,8 @@ void *dma_direct_alloc(struct device *dev, size_t size,
}
/* we always manually zero the memory once we are done */
- page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO, allow_highmem);
+ page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO, allow_highmem,
+ node);
if (!page)
return NULL;
@@ -452,7 +454,7 @@ struct page *dma_direct_alloc_pages(struct device *dev, size_t size,
goto setup_page;
}
- page = __dma_direct_alloc_pages(dev, size, gfp, false);
+ page = __dma_direct_alloc_pages(dev, size, gfp, false, dev_to_node(dev));
if (!page)
return NULL;
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index bf2651a70b7c..1c3a70025195 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -665,7 +665,8 @@ void *dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle,
flag &= ~(__GFP_DMA | __GFP_DMA32 | __GFP_HIGHMEM);
if (dma_alloc_direct(dev, ops) || arch_dma_alloc_direct(dev)) {
- cpu_addr = dma_direct_alloc(dev, size, dma_handle, flag, attrs);
+ 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);
} else if (ops->alloc) {
--
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 ` Jakub Kicinski [this message]
2026-10-27 2:25 ` [RFC 03/11] iommu/dma: pass the NUMA node to iommu_dma_alloc() Jakub Kicinski
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-3-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.