mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Nicolin Chen <nicolinc@nvidia.com>,
	Jason Gunthorpe <jgg@nvidia.com>,
	joro@8bytes.org, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	rafael@kernel.org, Danilo Krummrich <dakr@kernel.org>,
	Johan Hovold <johan@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Pranjal Shrivastava <praan@google.com>,
	Mostafa Saleh <smostafa@google.com>,
	linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
	driver-core@lists.linux.dev, Sonang Patel <sonangp@nvidia.com>,
	Ankit Agrawal <ankita@nvidia.com>,
	shameerali.kolothum.thodi@huawei.com
Subject: Re: [PATCH v2 2/7] dma-mapping: Let a device declare that it reaches private memory
Date: Tue, 3 Nov 2026 11:11:13 +0100	[thread overview]
Message-ID: <373ea0e8-d0c4-4071-9546-8c4df5d09393@samsung.com> (raw)
In-Reply-To: <0697a7ab3e4c4b7703428644444fd13f8dbfccd9.1793676742.git.nicolinc@nvidia.com>

On 03.11.2026 04:49, Nicolin Chen wrote:
> DMA devices in a confidential guest can access only shared memory, or both
> private and shared memory. Some method outside the DMA API will confirm the
> device is able to access private memory through DMA.
>
> Add DEV_FLAG_DMA_CC_PRIVATE and dma_set_cc_private(dev, bool).
>
> The flag must be stable while any DMA mapping exists.
>
> Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>

Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>


> ---
>  include/linux/device.h      |  4 ++++
>  include/linux/dma-mapping.h |  4 ++++
>  kernel/dma/mapping.c        | 21 +++++++++++++++++++++
>  3 files changed, 29 insertions(+)
>
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 429e39f647cf9..01d7877d0b571 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -604,6 +604,8 @@ struct device_physical_location {
>   *		ancestor device.
>   * @DEV_FLAG_OFFLINE_DISABLED: If set, the device is permanently online.
>   * @DEV_FLAG_OFFLINE: Set after successful invocation of bus type's .offline().
> + * @DEV_FLAG_DMA_CC_PRIVATE: The device is able to access private (encrypted)
> + *		memory, no shared memory bouncing is required from the DMA API.
>   * @DEV_FLAG_COUNT: Number of defined struct_device_flags.
>   */
>  enum struct_device_flags {
> @@ -617,6 +619,7 @@ enum struct_device_flags {
>  	DEV_FLAG_OF_NODE_REUSED = 7,
>  	DEV_FLAG_OFFLINE_DISABLED = 8,
>  	DEV_FLAG_OFFLINE = 9,
> +	DEV_FLAG_DMA_CC_PRIVATE = 10,
>  
>  	DEV_FLAG_COUNT
>  };
> @@ -834,6 +837,7 @@ __create_dev_flag_accessors(dma_coherent, DEV_FLAG_DMA_COHERENT);
>  __create_dev_flag_accessors(of_node_reused, DEV_FLAG_OF_NODE_REUSED);
>  __create_dev_flag_accessors(offline_disabled, DEV_FLAG_OFFLINE_DISABLED);
>  __create_dev_flag_accessors(offline, DEV_FLAG_OFFLINE);
> +__create_dev_flag_accessors(dma_cc_private, DEV_FLAG_DMA_CC_PRIVATE);
>  
>  #undef __create_dev_flag_accessors
>  
> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
> index efde0e5a58dc2..3cc38db4a7490 100644
> --- a/include/linux/dma-mapping.h
> +++ b/include/linux/dma-mapping.h
> @@ -218,6 +218,7 @@ void *dma_vmap_noncontiguous(struct device *dev, size_t size,
>  void dma_vunmap_noncontiguous(struct device *dev, void *vaddr);
>  int dma_mmap_noncontiguous(struct device *dev, struct vm_area_struct *vma,
>  		size_t size, struct sg_table *sgt);
> +void dma_set_cc_private(struct device *dev, bool private);
>  #else /* CONFIG_HAS_DMA */
>  static inline dma_addr_t dma_map_page_attrs(struct device *dev,
>  		struct page *page, size_t offset, size_t size,
> @@ -357,6 +358,9 @@ static inline int dma_mmap_noncontiguous(struct device *dev,
>  {
>  	return -EINVAL;
>  }
> +static inline void dma_set_cc_private(struct device *dev, bool private)
> +{
> +}
>  #endif /* CONFIG_HAS_DMA */
>  
>  #ifdef CONFIG_IOMMU_DMA
> diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
> index 82e701648d604..ded585b39fb92 100644
> --- a/kernel/dma/mapping.c
> +++ b/kernel/dma/mapping.c
> @@ -501,6 +501,27 @@ static void dma_setup_need_sync(struct device *dev)
>  static inline void dma_setup_need_sync(struct device *dev) { }
>  #endif /* !CONFIG_DMA_NEED_SYNC */
>  
> +/**
> + * dma_set_cc_private - Set whether @dev can DMA to private memory
> + * @dev: device whose confidential-computing DMA access is being updated
> + * @private: whether the device can DMA to private memory
> + *
> + * Called when a device is known to be able to DMA to private memory.
> + * For architected CPU integrated devices their kernel drivers will
> + * self-accept using a driver specific validation. Other devices will
> + * have a userspace managed process.
> + *
> + * DMA mapping must not be active when this flag is changed. For CPU
> + * integrated devices the driver should self accept early during probe
> + * after validation. Other devices have this flag set automatically
> + * before probing.
> + */
> +void dma_set_cc_private(struct device *dev, bool private)
> +{
> +	dev_assign_dma_cc_private(dev, private);
> +}
> +EXPORT_SYMBOL_GPL(dma_set_cc_private);
> +
>  /*
>   * The whole dma_get_sgtable() idea is fundamentally unsafe - it seems
>   * that the intention is to allow exporting memory allocated via the

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


  reply	other threads:[~2026-11-03 10:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  3:49 [PATCH v2 0/7] iommu/arm-smmu-v3: Support guest-level Realm VSMMU (Part-1) Nicolin Chen
2026-11-03  3:49 ` [PATCH v2 1/7] firmware: arm_rmm: Add VSMMU commands and fields Nicolin Chen
2026-11-03  3:49 ` [PATCH v2 2/7] dma-mapping: Let a device declare that it reaches private memory Nicolin Chen
2026-11-03 10:11   ` Marek Szyprowski [this message]
2026-11-03  3:49 ` [PATCH v2 3/7] dma-mapping: Keep DMA memory private for capable devices Nicolin Chen
2026-11-03 10:10   ` Marek Szyprowski
2026-11-03  3:49 ` [PATCH v2 4/7] iommu: Let a driver mark an IOMMU as confidential Nicolin Chen
2026-11-03  3:49 ` [PATCH v2 5/7] iommu: Introduce TDISP T=0 state for confidential IOMMUs Nicolin Chen
2026-11-03  3:49 ` [PATCH v2 6/7] iommu: Park TDISP T=0 devices in the blocking domain Nicolin Chen
2026-11-03  3:49 ` [PATCH v2 7/7] iommu/arm-smmu-v3: Probe a guest-level Realm VSMMU via RSI commands Nicolin Chen

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=373ea0e8-d0c4-4071-9546-8c4df5d09393@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=ankita@nvidia.com \
    --cc=catalin.marinas@arm.com \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=johan@kernel.org \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=nicolinc@nvidia.com \
    --cc=praan@google.com \
    --cc=rafael@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=smostafa@google.com \
    --cc=sonangp@nvidia.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

all inboxes | Powered by JetHome®