From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC5293370EC for ; Tue, 18 Aug 2026 06:26:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787034365; cv=none; b=Ux/bHMTKrQ/ecBrxyVI2Rvj0KI38lMdOm1y4vRQN3yx2kWqmZU6mdo28uYmIU1uM//luT7uwWYcetbLUnitG5XSYlqZj6hz5sxEa7duyy4YNLArKi23Txi8hfuJb3Xebj67PH6bsN8FxvhCO5K4TY9TR73jspCsYD3GAzntqGFY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787034365; c=relaxed/simple; bh=2mrRYBUZB6QXqcc/lWECjrJo8ItcqmQvUwDzXzT2cek=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=p0WaHKkVvJWHH3inQUinupSYCR78P1/8ZGhlpStr+pJr05flZynUBPtT9Do4iB/GS77OxdaeZ9GTNfZgNmhMP6djR6q1iCqBis3/bEGTwYwctYxmfSX+OFiUFo7jlW6HceDoCEow5B9GNTHE3Pj/rhzkVqyyJiyXwZs/ep9pToA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=f2sYxbLV; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=MrXxIv99; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="f2sYxbLV"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="MrXxIv99" Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67I28W1n2884804 for ; Tue, 18 Aug 2026 06:26:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= QpMSnfPhODIl1ejhgbQgYJBMEXQkyaJTdofbzdBjnW8=; b=f2sYxbLVVxHHE8ah BLL2hEOs11e8uGfhMGoJwcmplrDhvwX33dAV0qiWRM2gDpjxJVPos/JU02gMW9FC LXwzVEPGU7rJi5TIK5da9CVzvzkcJVuj6EHpmZzzxojPfowe4uWJw1vE56Kh38vH PpjZDe3+yq0qUA2tUIqzPDgLNB+qvDT0CvDtc8kuiXB875zbfvrZ0HBTaer95ILn iFiq1bXLOsrZHIspu9HOdT/hDYdagYLCnHuJc6s7BLHeQiteNQ8b7Dv4wzHpIzVF NbRytfgkQu+PFQ5J28BanMviMap2OBU3khIdZ3UoRxyndp/8zj7rcQHuopvzHk/C giU5Xw== Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4g4ebps04p-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 18 Aug 2026 06:26:02 +0000 (GMT) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-38ecc48b3c2so7044382a91.1 for ; Mon, 17 Aug 2026 23:26:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1787034361; x=1787639161; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QpMSnfPhODIl1ejhgbQgYJBMEXQkyaJTdofbzdBjnW8=; b=MrXxIv99Vlkx4Zm0qnD4HQnXfajJ9ridaND6kJXxtlurhWLxVwNcrgg7nFkiKTg9Sh 7GGz/S0OytBorj2XKjNsrelGzWDX1sWH8qa6hbC02zD/V7T29rujeESQDK7qA8pa6v2Y APh/IsPMyoapKxDh0w6zM13XWvpd95GklunEHEZghhhHe945lZ3xoxtt7rwoYypaESKo XdH4fizfi+jexRR1avc0NYYOdY3r5UKJiAAc+lnoE4XYzHm1MHyVTpwJc7qwZimNu3bP kTUk+e3IqQbRmPVNC1xVdLBuBGI27Wo+WPzrI8IvsZMsfViTcNhefjbCt0WRN0VGVC06 6a4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787034361; x=1787639161; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QpMSnfPhODIl1ejhgbQgYJBMEXQkyaJTdofbzdBjnW8=; b=ezB6trdHK6fItReehy2YArvBENzNTB9PwowgsUx/vC0YO021epSKmHD/EufqNaJgoy 73v6hmREWfPdHim4Epu3JgEuwu5ovVU87+GIae07+KGqzLjU3HeCy9TUdP+G/W7Qkv59 fRKXCwRPRCH/B3u2256lNxEbrPnagXWrzjPRCzHTLlKbRg1FOQtz1XXArqbhGDa9fjwO lmT4zyS3TOT9uPu7bFqFzdB/AJWPvUptWhkrDr0QrfbV0f12rAhKqj+MvgFC00ZvxkEi 0rxzDp3sg2TBausa+Ip8+cBPKvrHxwuLhzzV0PQaj7c/PUJs2m61upSCUy6whIn4rsXe HHKA== X-Forwarded-Encrypted: i=1; AHgh+Ro7ZhiWO5qcAJIe6PnpexZOQ+jGO14zQXovvwBGP0SxIaXfmQudilz9ZcG3UVXRvPuN4NwuGdAW0UO3a78=@vger.kernel.org X-Gm-Message-State: AOJu0YwF12xwZzTGVJ+5XrHDDYJ/66yKtCa74n0gUeBAfKngxXv80AN4 8A7ecZyZJ4mmKXCrt30/FsptVPccYw60UsPnPiXGDV5Qz0FTk5ucknT1nnitvR/AQhUAlEv9Vea de8nZaFYWP3MJPtoYAE2/WKxU7tiMfYafbTV7u8h2Zn4EkY/Rim9zUAWVBnIHgtRSNFg= X-Gm-Gg: AR+sD10mU6c0//WKbHGCDj1otJqfYj7lJ+MiVEFctBWPXXjXb8DR71JYVsQUom6E+Nu wolbaGSNrYn4ywY4Ewl0u7GGFm9LUU0DfOukCjpjXv8gMO+jCKl1vSA3xxNRP3SV3LiIIi9yScy 7dT2jIi4BhGueU0Ubgg1yhzogE5XYL+1Epd6UP+gH19en2r1uuBXCO6CVhpQKJ6FcnLXuFfNvBN nHRq39yQCye47fhmgUF4HtVub8/0ftzCrD5gIWO6pp8ky2GC86jlq6LVE+asK/8yU9qTz//YGYX n6408pK/QsrmRMgpnOh6rVtBr7tJ2WhCA7vdZIy1Jzbvrc7tgJC/DFbfwUcpIZQBgiHoLAcFO7r Rv4CyNPfY/PMP38ueo6dw8HgRI7ankA== X-Received: by 2002:a17:90b:48c1:b0:38e:2517:5d1f with SMTP id 98e67ed59e1d1-3933b792c20mr35951566a91.9.1787034361271; Mon, 17 Aug 2026 23:26:01 -0700 (PDT) X-Received: by 2002:a17:90b:48c1:b0:38e:2517:5d1f with SMTP id 98e67ed59e1d1-3933b792c20mr35951459a91.9.1787034360780; Mon, 17 Aug 2026 23:26:00 -0700 (PDT) Received: from [10.219.56.166] ([202.46.23.19]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-39531ff679fsm7486482a91.14.2026.08.17.23.25.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Aug 2026 23:26:00 -0700 (PDT) Message-ID: Date: Tue, 18 Aug 2026 11:55:50 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 11/15] accel/qda: Add PRIME DMA-BUF import support To: Dmitry Baryshkov Cc: Oded Gabbay , Jonathan Corbet , Shuah Khan , Randy Dunlap , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , "Joerg Roedel (AMD)" , Will Deacon , Robin Murphy , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Bharath Kumar , Chenna Kesava Raju , srinivas.kandagatla@oss.qualcomm.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-arm-msm@vger.kernel.org, llvm@lists.linux.dev, iommu@lists.linux.dev, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org References: <20260817-qda-v2-v2-0-69a02e9090d4@oss.qualcomm.com> <20260817-qda-v2-v2-11-69a02e9090d4@oss.qualcomm.com> Content-Language: en-US From: Ekansh Gupta In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: RSj2cqjUlhRgogSJhohq_A8Ms9QdKGyB X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwODE4MDA0NiBTYWx0ZWRfXxy5rDIY4y7Y9 f3RdAeLAYGGi/CDN3BE07U5fiuafZaDKkHxSQqInNSCymi06f5AU4b4NaOVXwVsS/rVjw2sBmOw J8iQgVvaeRNVE82p+mUuRyyROTsAOitCNj0MbiqCPEK9LEo88nHm/Ww0fMgpiMN33ZS2x236Oxl StUD1TuYjJEWy6iikwcDkKp0XhDOvzLbJWaD5yYDWZOwubRw59PaIMmw/HL1Y8DFy4efXAHsJJn b7Riy7uuUcEUMLTsVJRWcXKzbELeYlDzP+KnRk5Ul6jIsX3o6o+E3ZYsaDeMn5L4A3YSFSQyl7N Xj+uwTM+ZZa1fFaHwho8mKZLjte4uzqgU6fL4VlGINrxGckKcJDLDFnuod3/b2aBson6B/8NB6V fG5LP1cbT5NLyM4R1Ms1nxA64APjFRQJQQyLIHnZrsU8YyHp518YeSigM1ccb8JOVPCMuSvJJz+ /oTDKJojV6miAS7M63w== X-Proofpoint-Spam-Info: AW1haW4tMjYwODE4MDA0NiBTYWx0ZWRfX+nxOtjWQD3tr 9hGSB9diP3DBKN8Hq1WctDaymD0xtTU/j+/XaL6GedoiA8xRAdX2TD127b0f6IRfOtTc0PND+2H RIUJ4AItoi5Vck5se7UuSvV47rLxv+A= X-Authority-Analysis: v=2.4 cv=FsU1OWrq c=1 sm=1 tr=0 ts=6a83fafa cx=c_pps a=vVfyC5vLCtgYJKYeQD43oA==:117 a=j4ogTh8yFefVWWEFDRgCtg==:17 a=IkcTkHD0fZMA:10 a=Sv0fKeRqtYgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=EUspDBNiAAAA:8 a=BHqhARD1X7WWxJJUoOYA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=rl5im9kqc5Lf4LNbBjHf:22 X-Proofpoint-ORIG-GUID: RSj2cqjUlhRgogSJhohq_A8Ms9QdKGyB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-17_04,2026-08-12_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 phishscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 adultscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608180046 On 18-08-2026 09:25, Dmitry Baryshkov wrote: > On Mon, Aug 17, 2026 at 10:17:46AM +0530, Ekansh Gupta wrote: >> Allow user-space to import DMA-BUF file descriptors from other >> subsystems (GPU, camera, video) into the QDA driver via the standard >> DRM PRIME interface. >> >> qda_prime.c >> Implements qda_gem_prime_import(), which is set as the driver's >> .gem_prime_import callback. On import it: >> 1. Short-circuits self-import: if the dma_buf was exported by this >> device and is not itself an import, the existing GEM object is >> returned with an incremented reference count. >> 2. Attaches to the dma_buf and maps it with DMA_BIDIRECTIONAL via >> dma_buf_map_attachment_unlocked(), obtaining an sg_table whose >> DMA addresses are IOMMU virtual addresses in the CB device's >> address space. >> 3. Calls qda_memory_manager_alloc() to record the mapping and encode >> the SID in the upper bits of the DMA address, matching the >> convention used for natively allocated buffers. >> >> qda_prime_fd_to_handle() wraps drm_gem_prime_fd_to_handle() under >> qdev->import_lock, storing the calling file_priv in > > Why do you need a separate lock? Will add details in commit message, The lock serialises the `fd_to_handle → gem_prime_import` call so that `current_import_file_priv` is valid for the duration of the import. Without it, two concurrent imports could race and each see the other's `file_priv`. > >> qdev->current_import_file_priv so that qda_gem_prime_import() can >> retrieve it (the .gem_prime_import callback does not receive >> file_priv directly, but the context bank to attach to is per-process). >> >> qda_gem.c >> qda_gem_free_object() is extended to handle the imported-buffer >> teardown path: unmap the sg_table, detach from the dma_buf, and >> release the dma_buf reference. >> qda_gem_mmap_obj() rejects mmap requests on imported objects, which >> must be mapped through the exporter instead. >> >> qda_memory_manager.c >> The DSP is given a single base address per buffer, so only buffers >> that are mapped as one contiguous range can be described to it. > > Is there no IOMMU in front of the DSP? Can we remap the buffer to a > linear are inside the DSP map? The DSP firmware's buffer descriptor format carries a single {base_address, size} pair per buffer and it does not support scatter-gather or multi-entry page tables on its side. This is a firmware interface constraint that we cannot change from the kernel. So imported buffers must present as one contiguous IOVA range, and non-contiguous ones are rejected. Will add this information in commit message and during the check.> >> qda_memory_manager_map_imported() therefore walks the imported >> buffer's scatterlist and rejects any buffer whose entries are not >> contiguous; contiguous imports (for example from the CMA DMA-buf >> heap) are accepted. Whether an exporter or IOMMU coalesces a buffer >> into a single range is not guaranteed, so this is verified rather >> than assumed. >> qda_memory_manager_free() skips the DMA free path for imported >> buffers since the memory is owned by the exporter. >> >> Assisted-by: Claude:claude-sonnet-5 >> Signed-off-by: Ekansh Gupta >> --- >> Changes in v2: >> - Do not assume the exporter or IOMMU maps an imported buffer as a >> single contiguous range; walk the scatterlist and cleanly reject >> non-contiguous imports instead (Christian König) >> - Document that only contiguous imports (e.g. CMA DMA-buf heap) are >> supported >> - Return -EBUSY rather than -ENODEV when no context bank is available >> --- >> drivers/accel/qda/Makefile | 1 + >> } >> >> +static int qda_memory_manager_map_imported(struct qda_gem_obj *gem_obj, >> + struct qda_iommu_device *iommu_dev) >> +{ >> + dma_addr_t dma_addr, expected_addr = 0; >> + struct scatterlist *sg, *s; >> + int i; >> + >> + sg = gem_obj->sgt->sgl; >> + >> + /* >> + * Verify that the imported DMA-BUF is contiguous. While some platforms > > Which "some platforms"? I'll rewrite the comment to be precise.> >> + * or IOMMUs might map buffers as a single range, we must not silently >> + * assume this is always the case. We loop through the scatterlist >> + * entries and reject any that are non-contiguous. >> + */ >