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=40.93.195.27 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796131504; b=Xeqt55RO8HBjbLuKERPVge0qeQIjWnyFfGJGTxJejbJkfFSd0QL1x6oUIQHSHQ+yf44W 2596sLq/fW8poXrwl/WG7DZOq5eGeOSom6zYNGY0gDUTCEf+GzdBtm9mb7xIIXrnBZUd8 g0zIGHhO4Jypz2c5+70WhOlp3iJoRkuncp6dOFTqiAIXwFC1+CyQ6hZKnvqXydkTiGOor jFi4ojav1gWBYkNhovSl7L1acQDqKayGnq2eGKFy8JnSGoRz7WkY/soWv4fLP0R3zTDw8 FX0Rqh7SAl8OeLFrJw8Yo7E4PwKjimpOSsGZFIel5edBWDRAX2t2ohHKz9zBfJEW0Ng== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796131504; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: 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-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=mWErZouFChc9XZzq2VMzsRuW4u8To0f7X1YqeOCC4F4=; b=XAJLh5FGJVR8JjVmxspBFilBX6g12Ro5ibKgyhlGHuGkWXgWoQc3iIY0M/w1ZjGZNHGd 3OfKXAo8jeIExIoS6+/FT4M8Pl8guCmf+P71MeVBCn33c596NrLRyEyOUmPyBMvTr4jlj LsavLwIaw/hVEhpiPv11H4nymfotMSPJbBFE9MlVXlBPv4/SHtMstvji3WE4QY2DtE0OD GLl1BnBzm+0lpnqypFmOfNdry6cXk5gKovTOr9APC3OCU0XS01ixSIVbIGLXZhBuxZ9v+ dmTw+RcwDj4D2vGIRzwPmL9aQ9fTr87GyT645/BVJ+tR8hAbkzmq1XR3HBPb1iVs5YQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=DW7GkfEU; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.195.27 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012027.outbound.protection.outlook.com [40.93.195.27]) (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 C289D606A320; Tue, 1 Dec 2026 13:25:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C289D606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=DW7GkfEU ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GnaWiRxc7gk7n67yUtWnnEGT01mn6enDG+tOK0RBbvBzFQmM+J2FGLQOBJGKwWbX2ozJL/3kyxYf58Vpc/PDsX81X1sxcH9cUXt1KgRciLc4ue8OgFbKlRY4J7wzv3lbUKAH7ntIdVN+VAWh1wd6ToQBFuKSLNVBeXRLYIX2hC00NfFY0Hb9sfnXri3HbFvXi0/VZ2SLOPdRxRutFSO05lgjLOp01CnVM9Lvg5i51cyLWSCk1Cd/T7nStebrkFhOeomQ/iWC5y/VzuOvPs5EFV5NimFRzp2hKIZF3CvI8GNsCT8UiS3189WgMumRdtUOEEbCoatmKwlNbPmR6j+RFg== 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=mWErZouFChc9XZzq2VMzsRuW4u8To0f7X1YqeOCC4F4=; b=WBuhElki/XoEea3IqF9Dr0wroYhS87vG0gslaOcaq+5KY69FnQdW05OC9kTu+zzgdhIpK5tS6xI66iCA4m+N8grrQB3nSXi/xfQQJEouoBfc07/z6WsAIgTpUSXjucP2T00ayiF5ojv5he3OQA9JxXmpHLSFMEljEwXVoIk3qmM/uh9cWKn0p9LpHuN7adDuKFJypii7oGLSX+PAJyszCw4qTg7G6MrS+BAS7cd2QIR1vyW/RNF2imSL4NmR55+DAf5vsxCs/DuQtug9mHepyV/YX/LV5i5IXoQ5rL7Zy2Q92uGDx4oduhq7HN95CwcL12BEhjvBxtSYuUGiUko16A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mWErZouFChc9XZzq2VMzsRuW4u8To0f7X1YqeOCC4F4=; b=DW7GkfEUEL3LZdtGJCcZmxh8to2jRrN9k+8P8Dl8iVWs4eELeWa9boGFWcn51TO138DidJEAgGtvHWsBoz+ri227io8Sbj+ppQx+YaxINabfElWm3Bph6if1WRHfQNrsRBgEydAxZtoUF+9pn1kJsLNjpQii4xJFwqQiQ0Tgwts= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) by DS8PR12MB712524.namprd12.prod.outlook.com (2603:10b6:8:449::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 13:25:00 +0000 Received: from PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::ce69:cfae:774d:a65c]) by PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::ce69:cfae:774d:a65c%3]) with mapi id 15.21.0662.007; Tue, 1 Dec 2026 13:24:59 +0000 Message-ID: <53a32383-4cf6-42ac-bbd5-476e69a3be5f@amd.com> Date: Tue, 1 Dec 2026 14:24:49 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 03/24] dma-buf: Add the SGT DMA mapping type To: Alistair Popple Cc: Dave Airlie , Jason Gunthorpe , Sumit Semwal , =?UTF-8?Q?Thomas_Hellstr=C3=B6m?= , Simona Vetter , Matthew Brost , Vivek Kasireddy , Dongwon Kim , Kevin Tian , Xu Yilun , Karl Mehltretter , Baolu Lu , Felix Kuehling , Alex Deucher , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Mina Almasry , netdev@vger.kernel.org, Alexey Kardashevskiy , zhipingz@meta.com, treding@nvidia.com, jhubbard@nvidia.com, chaitanyak@nvidia.com, Leon Romanovsky References: <63eb7b6e-e0a8-4443-a434-0301ed59beae@amd.com> <79d62f9a-cea8-4149-a673-7ef86942410d@amd.com> <20261127125753.GS246011@ziepe.ca> <20f5fb10-b71a-40f9-bbb2-f99b4002bf08@amd.com> Content-Language: en-US From: =?UTF-8?Q?Christian_K=C3=B6nig?= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: FR4P281CA0365.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f8::8) To PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR12MB5685:EE_|DS8PR12MB712524:EE_ X-MS-Office365-Filtering-Correlation-Id: 48e3d95c-2025-402c-05a7-08df4fae7fa7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024|23010399003|5023799004|11063799006|4143699003|261009223027099003|3023799007|56012099006|10067099003|261102130727099003|261102123227099003|261021121427099003|261026140227099003|261026121527099003|261028144727099003|261022105027099003|261022075727099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: TualzdGImzjcAAZA4bnhLthJhKA/MVrFHdus+VT62uNXH74DHAGy3rlfOVhaueMz5mbw61vEI4iRkecudmzha/nd7uWOpZuQvQ4RCm6oKUWSXqgPsuSX4eqNf6vlXw6Az9GcMV4c1J7O3MCWFX0Kt9OhnIEnL7iKOWYn8DB7QKQjDaGNouhRaDBTGxMN+6kLPXlF77rHsHMOy+czAgUD5Wfh4XkVkX3fhSzxey9KbroF3VeC05AGg8HRZ4cEfTvv43x3PMKMoGT47UvAhYjgBEr7BwS79FbzI7CkJlZ/YGjwzGhcqmNX2X5wvk/mRW2KcdPtJp28LiVruLfRnbkH8FpDbitjNa5VGTdyXSUAQJJF7EVWdi2OdRPR09BHNWBgrKdrHpe31CkAE4udBkBmNy8+ZuSldkrWu4EcWq1QU6njuVw/ZHYFjM4vLsh45JovKWYeqNZmdUGdwE8u8RqP03QbQkmuG4P+1znbwUEpOJD7s1megyT2BbRf/Ij1dqifqIUMEnNE1SHNM7h96Hk0/P9Bf1L2L6ew5yfF2BzfmSw4Eq9FG0KSMaytWJCuq/Hzb/KNoz9hZbb2nyOuiZH8+qByWQoydYltbVHSPMe5AIwLnxbozQyEd1FHcJnqyGHS X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR12MB5685.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(1800799024)(23010399003)(5023799004)(11063799006)(4143699003)(261009223027099003)(3023799007)(56012099006)(10067099003)(261102130727099003)(261102123227099003)(261021121427099003)(261026140227099003)(261026121527099003)(261028144727099003)(261022105027099003)(261022075727099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Yi9acUl3QndCMDd2MDNWaEZIeXZPV0JoL3p1ditON2dONHV0OWg1Q21HVlRS?= =?utf-8?B?bGRmdE50aFVhOGtUdlZMMGlpS2MyM0o5eFhOanlBaU16WXNPNms3VENISjRS?= =?utf-8?B?TVdPdllrdlkwaVFGTDV0UmxyNlRZQ3UwOEpPd1B1T0JiSjlCRElZVU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OGhYK0Y2SWgrdVdsNUNUU2cyOGFsRko5Y0N5ajAveTNxVWxrZDNKYVVtSnEz?= =?utf-8?B?VmdhT056UnRwL1B4Y3R4Vzl1QzhrWHd2MmZEc3ZKSlBNMnc2UndQazFyRWJG?= =?utf-8?B?ZFlWODdmVnNZb3NSTUpLMmZlM2RwNFpPV3BpT01qUmxFN3p3RkZBZG0yQURB?= =?utf-8?B?WGM4T3RmSjlyU1JGWnhZUU1yanVRRFN1YjVlQndxd0wyRnZieER1K2dOL3RW?= =?utf-8?B?U1ZDRnlBWDRndjVCNVowSHdIT3d1R3ROZ2RKblNtMEpkQW5BZXQwU0dJL2tE?= =?utf-8?B?QkREbjhzdlFhRWlNOFl5allhRC9xQzhhT0JtZTZOVUV2ZmxWVTM5bUF3SXVo?= =?utf-8?Q?wKbmeJwWW0AX/R+CMt?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48e3d95c-2025-402c-05a7-08df4fae7fa7 X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB5685.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 13:24:59.7912 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lfHwbqTpX6h6k26uiAD1iRmIRY4cUSMUdpDSMVVGnMJJ0x8jr37X74C1Vzsvc8BS X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS8PR12MB712524 On 12/1/26 10:33, Alistair Popple wrote: > On 2026-12-01 at 19:11 +1100, Christian König wrote... >> On 12/1/26 08:13, Alistair Popple wrote: >>> On 2026-12-01 at 15:05 +1100, Dave Airlie wrote... >>>>> The problem is I can't figure out how to build that low level API. >> >> Seconded. >> >> I can give you quite a bunch of requirements based on what the high level DMA-buf API and uAPI has on functionality and based on what I have seen on use cases in the wild. > > I think a bunch of requirements would be helpful, because they've kind of been > scattered across threads at this point and I concluded it was kind of impossible > to build given the constraints. > > In particular the one thing that PCIe P2P, IOMMUFD, KVM, etc. all need is the > physical address. That is the vendor agnostic thing below but providing that has > been consistently NACKed and I can't see how you can make any low level API work > without having the physical address. Yeah good point, let's start with that one. There are multiple problems with using physical addresses. First of all a physical address is only what the CPU can see, but there are a lot of use cases where you need to access resources the CPU can't reach. For example hidden device memory or even system memory where the CPU intentionally has no address for because of digital rights management reasons etc... Taking a look at all the use cases I have seen I would say that DMA-buf actually contains more non CPU accessible resources than CPU accessible ones. Then especially for PCI a physical address is only halve the information you need. The importer can also need additional info to stitch together the TLP, like SH, snooping bit, atomic access ops etc.... Then there is the reason that we have seen a tremendous amount of cases where importers abused the physical address and/or struct page pointer which was unfortunately accessible through the SGT. To be honest I can't count the number of CVE entries given to such bugs. There are some use cases for KVM for example which need physical addresses, but to be honest they look like corner cases. Ideally even the exporter shouldn't work with physically addresses I think. For example even when you have a PCI P2P API which fills in your mapping it should work with PCI BAR, offset and length and and not a physical address into the BAR. > I know in the past you've suggested passing all the importer context through to > the exporter, but that is also a complete non-starter. It lets arbitrary drivers > implement the mapping wrong and likely get all the life-times, which belong to > the importer, wrong. So until we can solve that I'm not really seeing much of > way forward here. WOW, wait a second. With the exception of the old interface which pins things down the lifetime of the mapping belongs to the exporter and not the importer! That's one of the reasons why the exporter needs the IOMMU context of the importer for example, otherwise you can't forcefully remove IOMMU mappings without relying on the importer doing that for you. >> But I can't say either what the low level API needs to look like and one of the major reasons I want DMA-buf separated from that low level API is that it seems like this needs a different field of expertise and responsibilities. > > I get it, and I do appreciate the expertise provided here. However if DMA-buf > is supposed to be some separate mechanism just for passing pointer types between > exporter/importer with some lifetime and location negotiation rules it shouldn't > also be seeking to impose constraints on what information those types actually > contain. That is none of it's business and is up to what the low level API > needs. I have to admit that's a pretty good argument, but I would say the restriction is on the exporter, importer and which role is using what and not the low level API itself. > If the low level API needs importer context and physical addresses to do > anything useful then so be it. As long as the low level API is only called by the exporter I have no problem with it taking physical addresses when it is sufficient for the use case. I just think that we have use cases where the exporter needs to give additional information to the physical address to the IOMMU driver for example. I need to attend some customer stuff now and will try to answer the rest of the mail later today. Regards, Christian. >>>>> >>>>> The current low level DMA API can't correctly handle PCIe P2P, or IOMMUFD, or >>>>> the KVM/confidential compute use-cases (I'm less familiar with those). It can >>>>> only handle creating a DMA mapping for system memory for a specific importing >>>>> device. >>>>> >>>>> So I assume you are talking about some new API. Following Dave's lead lets call >>>>> that shared_buf_map(). That would need to take some importing device context >>>>> so that it could dispatch to the correct mapping code and a list of physical >>>>> locations the exporter needs mapped. >>>>> >>>>> At a high level something like: >>>>> >>>>> struct dma_addr_list *shared_buf_map(import_context, location_list); >>>>> >>>>> Where the import_context is some importer specific struct opaque to the exporter >>>>> and the location list is a list of either PCIe MMIO or system RAM physical >>>>> addresses. >>>>> >>>>> Every exporter ->map_dma_buf() should call shared_buf_map() instead of >>>>> open-coding their own mapping code, as I think we all agree we don't want that >>>>> open-coded. >>>>> >>>>> Placement selection can be dealt with as a separate topic, so setting that >>>>> aside means passing in the same location list regardless of importing device. >>>>> shared_buf_map() then has to dispatch to the correct mapping generation code - >>>>> either DMA API, PCIe peer-to-peer API, IOMMUFD API, KVM API or maybe some other >>>>> importing device/driver specific API. >> >> That sounds totally sane to me, yes. > > Ok. The problem is how this shared_buf_map() gets the importer context. > > It would be easy enough to make work if an impoter could call eg. > shared_buf_map(import_type, attachment) or something like that, but I got the > impression from the middle-layer discussion that that would be undesirable and > get NACKed because only exporter should call that. So not sure how to actually > make that work, unless my impression there is wrong. > >>>>> >>>>> I could see how that could be made to work, but it seems more complex than >>>>> a dma_buf exporter op that returns a list of physical locations and a helper >>>>> library that importers call to do the mapping into whatever importer specific >>>>> context is needed. Instead you would have to add importer specific callbacks >>>>> that the shared_buf_map code could call along with plumbing the importer context >>>>> through. >> >> I've thought about that as well for a while but came to the conclusion that we most likely want some more differentiation here. >> >> On the one hand we have the vendor agnostic things like PCI P2P, IOMMU, IOVAs, bus addresses, CPU physical addresses etc... which a vendor agnostic API should be dealing with. > > Right - I'd like to tackle the vendor agnostic things, as they provide the most > value. Vendor specific things have already been hacked up to work in all sorts > of horrible ways, which is why I want to fix this so I can at least remove some > of the horrid hacks from our code. > >> On the other hand we have vendor specific things like XGMI, GDS/GWS/OA, I2C, I2S, doorbells, which only specific drivers understand. >> >> The problem is now that those things at least partially overlap, for example a doorbell which is ringed by a PCI P2P write. > > I'd argue that a doorbell rung by a PCI P2P write isn't any different than any > other PCI P2P access. The data in these buffers doesn't change the type from a > buffer sharing perspective, the type of data in these buffers is always up to > some other layer (eg. userspace), so I don't see the overlap. > >>>> >>>> This is where I got to thinking it might end up, not that we have an >>>> export function that actually exports anything, but merely advertises >>>> this provider has an object with this fd and it can export it in these >>>> ways. >>>> >>>> Then on import we'd have to go into the exporter and setup the object >>>> that gets shared between that specific importer/exporter combination >>>> and not always have a singular export, but one per import, that I >>>> suppose could be refcounted per export if lots of importers wanted the >>>> same thing. >> >> Yes that is a requirement of ROCm as well and we have hacked around such things massively with the KFD and all the rat tail of consequences seen by it. > > I should introduce you to RM :-) > > Thanks. > > - Alistair > >>> That sounds reasonably complex. Do you have a vague plan, ideally in the form >>> of data-structures/API definitions, that would help explain what it would look >>> like? >>> >>> For now I have sent a simplified RFC series - >>> https://lore.kernel.org/dri-devel/20261201-dmabuf_shared_buf_v1_xe_rc5-v1-0-b672717c7fc9@nvidia.com/T/#t - that drops the placement >>> bits and implements the rough plan I outlined in >>> https://lore.kernel.org/dri-devel/awZ_Os1pXelOGaFP@nvdebian.thelocal/ . I'm not >>> sure it addresses everything, but I'd be interested in getting feedback on what >>> it gets right and what specifically needs fixing/changing, and how, to satisfy >>> the design constraints. >>> >>> Thanks. >>> >>> - Alistair >>> >>>> Now maybe we can't call this dma-buf, but I think dma-buf is a subset of this. >> >> I would say that DMA-buf is the high level API which allows importers and exporters to exchange the data structures of the low level API. >> >> Christian. >> >>>> >>>> Dave. >>