From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.85.50 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796110483; b=c5Q6fyMZsBwdBWYhKwfNi79EO7wsXocNyvd9PywL83z4IxcFxqRNPerTcRlk+xgg2QKe NYG1hE3mOwwF0WtCJ7lkR4n/4EazcW8nJKhk8yG3IUMU+apUNoYl8xEPCiNJQ6i4HmCBf wf1DSt4skmKoW6xJH6Y/cuOoEWmTp6J2RYM9xJt9DW3Q+esW7UML/iejiGXjBDaY7kbe3 LukWQ0uA1deBubVPwKBp44mKyqkCW8UwdVOxOYWJQ4LPhWSt5BXJ4RnZtWsHoNC044oyL LjKBNnuPNUL6F0BYJw67fAAv2wPcwbjEGN5xRI12UpoCNV2w3xIQQ1iZ11bEGxx5ejg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796110483; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:Received:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: Content-Type:X-NV-OnPremToCloud:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=53Sag9OAYWP2UdlPIji4RAFd24YX+qraKoY+eum17Pc=; b=QB/vOGKxrrH4csx8KKn0C+3k5tPV9dMuA8Oc632pi0FqCeyOwhIs8vMYvSUnZlHfFitL 4n+YFl8JRD4KS2YAXUL760Q+YYq4a0FOP5t3ak3pmNdZFiNKRean3TtoC085ZghMl09EK 2ukUyNoFi+5nVwdZCZqDt6W2RcZXZOtaq8RZVFArZ1trt6WOkgW6FRxN8MrzDGfRVxmVC nRnD2QI0Zb42GbLlWELZeaKpok0ozovMO12kikyIbdMyWjBqGUFdbN+yJUzSVTqOTr+zi yNAMKYIqmATReNJeRAiBU9kmnfJKGir4KC9fp5SmwAxAhXC2ELoaWV8fP/YO1EtC5Dw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b="COxd0M5/"; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.85.50 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010050.outbound.protection.outlook.com [52.101.85.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10281606A329 for ; Tue, 1 Dec 2026 07:34:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 10281606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=COxd0M5/ ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cThw+yFHAM9OooScWP/+hFGDRDjBHdwF5HnPxoOnG1OoyO/3aIwsyHsT2Gmtx4deX90VLS6DqRcTKutNZziZivPmKSUJyKictgRZizQ9YxxvqJqvHHnl1VLpV4HSHeFdzSpVSAn/vm2Ky5w3bgBtmRyk/4ZB7hxBHgE56h0HM0c2hVFvThmJ44YMkhVozPQQamiucSkTjlh82u1PyHRFZWDQgpHghP+wsXSNSsCxKtkDf7dry3Vpi3p7rk7fds0GIyLbxfysfkFFh6aD0aZqwqN4ScrWasfXK/vdUgtITgrv4OanxujYZhbSdqBUotTFwuV8GblBo1pfsvuOWNUTgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=53Sag9OAYWP2UdlPIji4RAFd24YX+qraKoY+eum17Pc=; b=s5Y7mOR6fjxzJlAwwogwcBqYP167fFrvjAZJ+G6Ai6eu9vUlJq4Kr869EAAFHv6xZ+OvUgVVrx5Of0ay9uiRACX9QZvobViByRAXCsMyI3Unh2jcDKSNIKH7p3AygkBo8M7z0Y7xODDQnkodzrytwnQDKplFi7iIahQMZMZHqPTX7AneD7xhzeQdbcmLOjdsNMXaSVNrBSjO1sfcqHFkuBmiPj8VZByKyAYAOloS/Q6+3vdMFBFC0+lELomOem0gN+Z2dTJeMVflBbXuDHItl1lFR3t7FVHQeJIVRYP9QB6yU4dyHxLrVa9DlDe29u2L3Z4/a1SwGmito4b7q0fhKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=lists.linux.dev smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=53Sag9OAYWP2UdlPIji4RAFd24YX+qraKoY+eum17Pc=; b=COxd0M5/kiT/jgUrJ4XmiZ+M3SgJNaP3sEC4Mizb+WJcAd6Tse5w46bRv/8u6IWo17VXsExT657isQ/qaTRYD5VNp7QWyjzJ9G8kI3JN9ftuS8o650QfIah8mDs5Fs8lUjKqaAqgFBOV59cT7yYKCh0ghHdnilO8w2xAdZVPNAesC+hyb1zoQOZlQivOB16suhBziW3ZF7OxJxjw6kcq3YXfuxE0w2nZaC2doaX0n7ZDQy3UGa/jXipdyrzjjYp7B8YcfKWH/QPc0OsO8Ws4hvN5NKKc5QvYArADr0VsK7CS/u8DCdkOyDuSMVmNNjHShEK5N9Tdt5zCypsqYPtHMQ== Received: from PH2PEPF00003849.namprd17.prod.outlook.com (2603:10b6:518:1::66) by PH7PR12MB6444.namprd12.prod.outlook.com (2603:10b6:510:1f8::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Tue, 1 Dec 2026 07:34:35 +0000 Received: from MWH0EPF000A6731.namprd04.prod.outlook.com (2a01:111:f403:c91d::1) by PH2PEPF00003849.outlook.office365.com (2603:1036:903:48::3) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 07:34:35 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by MWH0EPF000A6731.mail.protection.outlook.com (10.167.249.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 07:34:35 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 23:34:13 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 23:34:13 -0800 Received: from Asurada-Nvidia.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Mon, 30 Nov 2026 23:34:12 -0800 From: Nicolin Chen To: Jason Gunthorpe , , Will Deacon , Robin Murphy , Catalin Marinas , Greg Kroah-Hartman , , Danilo Krummrich , Johan Hovold , Marek Szyprowski , CC: Mark Rutland , Pranjal Shrivastava , Mostafa Saleh , , , , Sonang Patel , "Ankit Agrawal" , Subject: [PATCH v4 2/6] dma-mapping: Let a device declare that it reaches private memory Date: Mon, 30 Nov 2026 23:33:54 -0800 Message-ID: <53daeafc85d0476b3add7cbaf897db1e935b658a.1796069375.git.nicolinc@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000A6731:EE_|PH7PR12MB6444:EE_ X-MS-Office365-Filtering-Correlation-Id: cd7c19ce-3276-4901-d713-08df4f7d8c4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700016|23010399003|82310400026|376014|7416014|921020|10067099003|56012099006|261026121527099003|261026140227099003|261021135927099003|261021121427099003|261022105027099003|261022075727099003|261021123027099003|261028144727099003|261102123227099003|261102130727099003|261009221727099003|261009221227099003|261009220027099003|261009223027099003|261009223327099003|22082099003|18002099003|5023799004|11063799006|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: jYa/XjMaX07fjdxroZrGnzzAgiI03LTAmP13Y8anU1WnDr77WdOLKXmuUAs+0qW1t3pRQH1fU3fOGlWDIcySJaaf9XkcNWIsyD6DrqNGHMVg66G5/RAJHLnddp80Fbn02uRwrREVbGAOeCildrrghkfmioYH5okUiZcgoFJrgdmlcl1Z1ZxjUGa7h42umyUQBhTkecCFrCu6JM9tAYZ56TIFXKzKWpVTnGPVNrQ63at7vi2zL7gbuouyMXFXE1gjx8Cq+lVLsTvtYVC9irn0byPd72c7A0l2RCan/SdmGDevpbFBNbCAfdloHUcgKz9zn4fN3rF5V4xWpdZrOBB7cVZNrwXkQBH5PcS3C2/5uUem4/iXFsCZzHYtHuJ5n/zsx89IrcGI/u7UoHLBeKYVdlUvHH3si/vgKgg4+Kt47FqBXHqlaKKHQyEih1bBi9V1aWXzfCFboKkiTNadKKEnhkV/SSmvHJ4kDOeaD5Im4CWd5vtjYFd+GD31eWVWRbU+48n/5Qf7W0CGw/uWtCepbOzWTCPt/YrBdczByUfoUysSBcHwxNbRRqm/J3BdSXhowORBlY7DH6j7+J3HwCrhEoAwiCBDSXueKdD8PoZcCMQ+l9Rf1NtORinfVqSpH2XU95apQEqEhh3YNr9HgOEeLMlTYIO2fgcnyevs7vpvUxJhWYjBE5LBRnIrio+Zsjqj+K9Cgmmxx3xii73RZ++GqwbLGhjurUeMrF4U008ZhAb9sDbcWkyQnIGanjmxx9X5 X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700016)(23010399003)(82310400026)(376014)(7416014)(921020)(10067099003)(56012099006)(261026121527099003)(261026140227099003)(261021135927099003)(261021121427099003)(261022105027099003)(261022075727099003)(261021123027099003)(261028144727099003)(261102123227099003)(261102130727099003)(261009221727099003)(261009221227099003)(261009220027099003)(261009223027099003)(261009223327099003)(22082099003)(18002099003)(5023799004)(11063799006)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6L1sqKmOCpbzucsOzkLTZ5A2hZbYAtKNVsSn5v6hMAghleQs7WWQ8EVTWKqWqv6vWSxlYgRd3EXJW3bAoD/MQBwucal8X0epMsGaa135T3dbBokGcaNnrXRBWM0ot/LuYY6U1CFN3pGc/15QOfVbM4ggEvlFWtXhH56jAWt3wFQQj0fYa2kgUHHANXsGeiRHnG9NiJRPpQtG2J5jFK5+Jdfu79gibcDWWugCxAxXQTI/5ep4ZErh4yE4MHXt5LPjB8dtfSxQtE+es+Ny1Ti8/PsKU8r5xCvRicdZ80fQ5jeawSv8GztpLfIjgj30qx83FYfxN4zZrIv1b/sJmMQvwVdtDl6rh2BZbTHY5A5+MCxSNcFlCYOS6DRG2QI8iiuLP109HpBpA2D6PdkysLgIA+i78T84oDp652ObJUy01mdtyj6BqUT61mG7xHMIgc5w X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 07:34:35.2391 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cd7c19ce-3276-4901-d713-08df4f7d8c4e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000A6731.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6444 Inside a confidential VM the HW controls how the DMA translation works. It boils down to a single bit, either the vIOMMU is ignored and only a bit of shared/decrypted address space is reachable or the vIOMMU is used and all address space is reachable. The state of this HW control varies per device and is an input to the DMA API just like all the other DMA parameters, and defines the rules for how the DMA API builds dma_addr_t. Only one bit is needed, so add a DEV_FLAG_DMA_CC_PRIVATE. The bit only has meaning inside a confidential VM and is to only be consumed by the DMA API. It reflects the current HW configuration: - True, if the HW allows the device to DMA to the full address space - False, to keep the current confidential VM behavior of the DMA API unchanged Like other DMA API parameters it must not change once the DMA API is used. Basically it should not change while a driver is bound. However, some SOC embedded devices like the SMMU, are hardwired to be able to access all memory. In this case the driver itself will have some way to confirm if the device has full DMA access and can call dma_set_cc_private() very early, before using the DMA API, to set it up. This flow is similar to dma_set_mask_and_coherent(). A following change teaches the DMA API to use this bit inside confidential VMs. A future series will let TDISP-capable PCIe devices control this bit as well using the TSM subsystem. Suggested-by: Jason Gunthorpe Acked-by: Marek Szyprowski Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- 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 -- 2.43.0