From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=210.118.77.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793700680; b=IdkC00w0TdCqfoxiJpl2flF0HvH5wENFOWBfLcvCn+uyO9rdE8SCyR6+Ej0JJcNKOI79 3JrusrwE8PhlRS6tKkMiZnpd0vvBjeDwXHWPOFLaV4/bLoUOUdOmpOplxAboU0HkJQviO BNILlLJj/4UZ+8sdKLaZK8xp6uTICEaHZIbCzCji8zwRHNvcQprFjt5Hy7xUtCQgzpFEp vS7VJx+N+8t5NXVGtug/oV0oQuMK9sjj1ewgitbP0Is9ZjifjXEAm5P73HF6o7A/oW3vv hVL7J/nn3sUbcyVIu/zONU8c5kFxetfRThYhB+ZK0HcPm+543GC/oATez5fQXDQLaRA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793700680; h=DMARC-Filter:Received:DKIM-Filter:DKIM-Signature:Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc: Content-Language:From:In-Reply-To:Content-Transfer-Encoding: X-CMS-MailID:X-Msg-Generator:Content-Type:X-RootMTR:X-EPHeader: X-CMS-RootMailID:References; bh=oEeAOkIMhm2brVx+57mg0HvmlruExTUNaN3KGm7ZRmQ=; b=BH1oujcBicPZR5NqqWTqvYGJ8cMfMyRPJMOc8SJQ7hGjgZNigCtMdhRuXjam8uz5L3Nd Msu6nwXxn06+6ruuQFSZ+hhjYNEABtpuuOqj+fCpcrbB9s83dXrhWAc5lkopzhno5d76K 09frG50FqqFg0HhnyrGCRU6hHINGbk/nzKPJIX9sfAQoFeL6nSWWYHRwZDEvEPTLKnrrn 2SINHygOSGj8xOpppv/dHwQhKAcLyHelABcMb/dpDXUz8+N0Izxto1NmoF9vgoj6GEveS TdmfLCK0ryRqG3XseY/h88BdJ0SF7oXHJEcwG9f7Lu6Cl4xz7fz7HEukvC6s0TX2amA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=W+HKkBv6; arc=none smtp.remote-ip=210.118.77.11 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65443606A32F for ; Tue, 3 Nov 2026 10:11:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 65443606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=samsung.com header.i=@samsung.com header.a=rsa-sha256 header.s=mail20170921 header.b=W+HKkBv6 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20261103101116euoutp014f10021cbfe2ae229578bf507dc5785f~kgUMbu0c92803328033euoutp017 for ; Tue, 3 Nov 2026 10:11:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20261103101116euoutp014f10021cbfe2ae229578bf507dc5785f~kgUMbu0c92803328033euoutp017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1793700676; bh=oEeAOkIMhm2brVx+57mg0HvmlruExTUNaN3KGm7ZRmQ=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=W+HKkBv6baZB/MFF4sW9EQIXMaH/WWcE0xLv30OQ1O3EWG5zu0LlDPyhpUo1rXQWO wP3pGtKk8BL5a/qRQQdn56Eash1rX+aexjjU29CJDaiMoDlrErCvRkS0FO/wcf9yAm I8vBGYoJwHVdGf4B7c7QwwC3yrse8D6SWUm4ERx8= Received: from eusmtip1.samsung.com (unknown [203.254.199.221]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20261103101116eucas1p1eadfbb1f322f96673fff2419c4cc5dac~kgUMEKwti2453024530eucas1p1v; Tue, 3 Nov 2026 10:11:16 +0000 (GMT) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20261103101114eusmtip1ab1d1332cf288f23ef33eca39d491c32~kgUKcvhCg3212232122eusmtip1W; Tue, 3 Nov 2026 10:11:14 +0000 (GMT) Message-ID: <373ea0e8-d0c4-4071-9546-8c4df5d09393@samsung.com> Date: Tue, 3 Nov 2026 11:11:13 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Betterbird (Windows) Subject: Re: [PATCH v2 2/7] dma-mapping: Let a device declare that it reaches private memory To: Nicolin Chen , Jason Gunthorpe , joro@8bytes.org, Will Deacon , Robin Murphy , Catalin Marinas , rafael@kernel.org, Danilo Krummrich , Johan Hovold Cc: Mark Rutland , Greg Kroah-Hartman , Pranjal Shrivastava , Mostafa Saleh , linux-kernel@vger.kernel.org, iommu@lists.linux.dev, driver-core@lists.linux.dev, Sonang Patel , Ankit Agrawal , shameerali.kolothum.thodi@huawei.com Content-Language: en-US From: Marek Szyprowski In-Reply-To: <0697a7ab3e4c4b7703428644444fd13f8dbfccd9.1793676742.git.nicolinc@nvidia.com> Content-Transfer-Encoding: 7bit X-CMS-MailID: 20261103101116eucas1p1eadfbb1f322f96673fff2419c4cc5dac X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20261103035021eucas1p17d005335232f75ad6f3b711b7c4b88d5 X-EPHeader: CA X-CMS-RootMailID: 20261103035021eucas1p17d005335232f75ad6f3b711b7c4b88d5 References: <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 > Signed-off-by: Nicolin Chen Acked-by: Marek Szyprowski > --- > 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