Linux Documentation
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Alexander Graf <graf@amazon.com>,
	linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Arnd Bergmann <arnd@arndb.de>
Cc: The AWS Nitro Enclaves Team <aws-nitro-enclaves-devel@amazon.com>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Robin Murphy <robin.murphy@arm.com>,
	linux-doc@vger.kernel.org, iommu@lists.linux.dev,
	Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	nh-open-source@amazon.com, linux-mm@kvack.org,
	Jonathan Corbet <corbet@lwn.net>
Subject: Re: [PATCH 05/40] dma-contiguous: add dma_get_numa_cma_area() accessor
Date: Mon, 16 Nov 2026 13:48:51 +0100	[thread overview]
Message-ID: <2be89ecd-2809-4182-b2c4-df062fcf68b6@samsung.com> (raw)
In-Reply-To: <a1294df95fbe0a2ef5cc3585824d396854c7242c.1794393490.git.graf@amazon.com>

On 11.11.2026 23:41, Alexander Graf wrote:
> With Nitro Sandboxes, we want to allocate per-NUMA memory from the DMA
> contiguous allocator, but have no per-NUMA struct device to pass in.
> dma_alloc_contiguous() takes the node from dev_to_node(dev), and the
> per-node areas sit in dma_contiguous_numa_area[], which is static.
>
> So instead, introduce dma_get_numa_cma_area(), which returns the generic
> per-NUMA DMA CMA area that cma_alloc() would use. This way, the
> nitro_enclaves driver can build its own generic CMA pool per-node
> allocation logic on top of those pools.
>
> Signed-off-by: Alexander Graf <graf@amazon.com>

Take a look at the following patch and the patchset it belongs to:

https://lore.kernel.org/all/20261106184433.761422-5-kuba@kernel.org/


> ---
>  include/linux/dma-map-ops.h |  7 +++++++
>  kernel/dma/contiguous.c     | 36 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+)
>
> diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
> index afaf2c12189b8..5f7138ea6899a 100644
> --- a/include/linux/dma-map-ops.h
> +++ b/include/linux/dma-map-ops.h
> @@ -93,6 +93,7 @@ static inline void set_dma_ops(struct device *dev,
>  #ifdef CONFIG_DMA_CMA
>  struct cma *dev_get_cma_area(struct device *dev);
>  struct cma *dma_contiguous_get_area_by_idx(unsigned int idx);
> +struct cma *dma_get_numa_cma_area(int nid);
>  
>  void dma_contiguous_reserve(phys_addr_t addr_limit);
>  int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
> @@ -115,6 +116,12 @@ static inline struct cma *dma_contiguous_get_area_by_idx(unsigned int idx)
>  {
>  	return NULL;
>  }
> +
> +static inline struct cma *dma_get_numa_cma_area(int nid)
> +{
> +	return NULL;
> +}
> +
>  static inline void dma_contiguous_reserve(phys_addr_t limit)
>  {
>  }
> diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
> index 90937dc7c627d..363b84284d087 100644
> --- a/kernel/dma/contiguous.c
> +++ b/kernel/dma/contiguous.c
> @@ -443,6 +443,42 @@ struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp)
>  	return cma_alloc_aligned(dma_contiguous_default_area, size, gfp);
>  }
>  
> +/**
> + * dma_get_numa_cma_area() - get the CMA area a NUMA node can allocate from
> + * @nid: NUMA node id
> + *
> + * dma_alloc_contiguous() picks a per-node CMA area from dev_to_node(dev),
> + * which a caller cannot override on a per-request basis. This accessor
> + * returns the area a specific node can allocate from, so a caller can
> + * cma_alloc() from the node it wants.
> + *
> + * A per-node area comes from numa_cma= or cma_pernuma=, or from
> + * CONFIG_CMA_SIZE_PERNUMA, which reserves the default area's size on every
> + * online node on top of the default area itself, all three of which are
> + * CONFIG_DMA_NUMA_CMA. Where there is one online node this returns the default
> + * area, so a host that reserved only cma= reaches its reservation through this
> + * accessor as well, and that holds however CONFIG_DMA_NUMA_CMA is set.
> + *
> + * Return: the area @nid can allocate from, or NULL if @nid has none or is not
> + * a valid node (including NUMA_NO_NODE).
> + */
> +struct cma *dma_get_numa_cma_area(int nid)
> +{
> +	if ((unsigned int)nid >= MAX_NUMNODES)
> +		return NULL;
> +
> +#ifdef CONFIG_DMA_NUMA_CMA
> +	if (dma_contiguous_numa_area[nid])
> +		return dma_contiguous_numa_area[nid];
> +#endif
> +
> +	if (nr_online_nodes == 1 && node_online(nid))
> +		return dma_contiguous_default_area;
> +
> +	return NULL;
> +}
> +EXPORT_SYMBOL_GPL(dma_get_numa_cma_area);
> +
>  /**
>   * dma_free_contiguous() - release allocated pages
>   * @dev:   Pointer to device for which the pages were allocated.

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


  reply	other threads:[~2026-11-16 12:48 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 22:41 [PATCH 00/40] nitro_enclaves: Add support for Nitro Sandboxes Alexander Graf
2026-11-11 22:41 ` [PATCH 01/40] nitro_enclaves: Allow the CPU pool to span NUMA nodes Alexander Graf
2026-11-11 22:41 ` [PATCH 02/40] nitro_enclaves: Add NE_ADD_ANY_VCPU Alexander Graf
2026-11-11 22:41 ` [PATCH 03/40] nitro_enclaves: Expose CPU pool state under sysfs Alexander Graf
2026-11-11 22:41 ` [PATCH 04/40] nitro_enclaves: Document multi-NUMA CPU pools Alexander Graf
2026-11-11 22:41 ` [PATCH 05/40] dma-contiguous: add dma_get_numa_cma_area() accessor Alexander Graf
2026-11-16 12:48   ` Marek Szyprowski [this message]
2026-11-16 14:25     ` Graf (AWS), Alexander
2026-11-11 22:41 ` [PATCH 06/40] nitro_enclaves: Add NE_ALLOC_MEMORY ioctl Alexander Graf
2026-11-11 22:41 ` [PATCH 07/40] nitro_enclaves: Add NE_MEMORY_SHARED Alexander Graf
2026-11-11 22:41 ` [PATCH 08/40] nitro_enclaves: Add NE_ADD_MEMORY_REGION Alexander Graf
2026-11-11 22:41 ` [PATCH 09/40] nitro_enclaves: Document the memory pool Alexander Graf
2026-11-11 22:41 ` [PATCH 10/40] nitro_enclaves: Add NE_CREATE_VM2 with a launch flag word Alexander Graf
2026-11-11 22:41 ` [PATCH 11/40] nitro_enclaves: Add NE_ENCLAVE_PCIE_MODE launch flag Alexander Graf
2026-11-11 22:41 ` [PATCH 12/40] nitro_enclaves: Name the device's error codes in the UAPI header Alexander Graf
2026-11-11 22:41 ` [PATCH 13/40] nitro_enclaves: Log a reached device limit at info level Alexander Graf
2026-11-11 22:56 ` [PATCH 14/40] nitro_enclaves: Add NE_SET_INFO_PAGE Alexander Graf
2026-11-11 22:59 ` [PATCH 15/40] nitro_enclaves: Document the info page in the memory pool Alexander Graf
2026-11-11 22:59 ` [PATCH 16/40] nitro_enclaves: Turn the command reply into a per-command union Alexander Graf
2026-11-11 22:59 ` [PATCH 17/40] nitro_enclaves: Add the slot pool donation commands Alexander Graf
2026-11-11 22:59 ` [PATCH 18/40] nitro_enclaves: Donate memory for the slot pool Alexander Graf
2026-11-11 22:59 ` [PATCH 19/40] nitro_enclaves: Add the slot pool growth commands Alexander Graf
2026-11-11 22:59 ` [PATCH 20/40] nitro_enclaves: Add a helper to grow the slot pool Alexander Graf
2026-11-11 22:59 ` [PATCH 21/40] nitro_enclaves: Document " Alexander Graf
2026-11-11 22:59 ` [PATCH 22/40] nitro_enclaves: Expose slot pool state under sysfs Alexander Graf
2026-11-11 22:59 ` [PATCH 23/40] nitro_enclaves: Add the device add command Alexander Graf
2026-11-11 22:59 ` [PATCH 24/40] nitro_enclaves: Add NE_ADD_DEVICE Alexander Graf
2026-11-11 22:59 ` [PATCH 25/40] nitro_enclaves: Read the interrupt multiplexer geometry at probe Alexander Graf
2026-11-11 22:59 ` [PATCH 26/40] nitro_enclaves: Donate a bitmap page per multiplexed vector Alexander Graf
2026-11-11 22:59 ` [PATCH 27/40] nitro_enclaves: Dispatch multiplexed interrupts to per-queue bindings Alexander Graf
2026-11-11 22:59 ` [PATCH 28/40] nitro_enclaves: Add NE_SET_NOTIFY_EVENTFD Alexander Graf
2026-11-11 22:59 ` [PATCH 29/40] nitro_enclaves: Report the device's info notification Alexander Graf
2026-11-11 22:59 ` [PATCH 30/40] nitro_enclaves: Count multiplexed interrupts under debugfs Alexander Graf
2026-11-11 22:59 ` [PATCH 31/40] nitro_enclaves: Map the doorbell window at probe Alexander Graf
2026-11-11 22:59 ` [PATCH 32/40] nitro_enclaves: Add NE_SET_VRING_CALL Alexander Graf
2026-11-11 22:59 ` [PATCH 33/40] nitro_enclaves: Assert the layout of the ioctl argument structs Alexander Graf
2026-11-11 22:59 ` [PATCH 34/40] nitro_enclaves: Pass on the Nitro Sandbox launch flags Alexander Graf
2026-11-11 22:59 ` [PATCH 35/40] nitro_enclaves: Add NE_ENCLAVE_DIRECT_MODE Alexander Graf
2026-11-11 22:59 ` [PATCH 36/40] nitro_enclaves: Add NE_ENCLAVE_PCIE_HOTPLUG_MODE Alexander Graf
2026-11-11 22:59 ` [PATCH 37/40] nitro_enclaves: Add NE_ENCLAVE_CPU_OVERCOMMIT_MODE Alexander Graf
2026-11-11 22:59 ` [PATCH 38/40] nitro_enclaves: Add NE_GET_CAPS Alexander Graf
2026-11-11 22:59 ` [PATCH 39/40] nitro_enclaves: Add NE_UPDATE_DEVICE_CONFIG Alexander Graf
2026-11-11 22:59 ` [PATCH 40/40] nitro_enclaves: Document the driver side of Nitro Sandboxes Alexander Graf
2026-11-12  1:49 ` [PATCH 00/40] nitro_enclaves: Add support for " Randy Dunlap
2026-11-12  3:25   ` Graf (AWS), Alexander

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=2be89ecd-2809-4182-b2c4-df062fcf68b6@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=aws-nitro-enclaves-devel@amazon.com \
    --cc=corbet@lwn.net \
    --cc=david@kernel.org \
    --cc=graf@amazon.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=iommu@lists.linux.dev \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nh-open-source@amazon.com \
    --cc=rdunlap@infradead.org \
    --cc=robin.murphy@arm.com \
    --cc=rppt@kernel.org \
    --cc=skhan@linuxfoundation.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