Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0315C678D4 for ; Fri, 3 Mar 2023 12:50:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229930AbjCCMur (ORCPT ); Fri, 3 Mar 2023 07:50:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbjCCMup (ORCPT ); Fri, 3 Mar 2023 07:50:45 -0500 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2089.outbound.protection.outlook.com [40.107.100.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D852823655 for ; Fri, 3 Mar 2023 04:50:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QmY+ah/5Fjihe5ElpyhsbEELQ82/7zwVfNn8oC8aC/CpwKbwDW5wjY5miKWUdpSQSmNzSCQGDqoDM8a7UzwI2uwVs6YizFTmRpgXqVw51mE9nFQ6Cn8NuLQq2e0znNrS9/Lt1MXvMzKDu0jew40T1RhOOZT8IUuYFeB5ZFXV1e0XHxdzc8sxdhXmESVqhh+GCrwV6UvUJ3elsEAOE2GWGhQmnPS3ixbOzekIoXn4gU1E9/V93KyYlMbbrLkdUGL/4QdAdvqWZRt1yCZwu5X3BdfH2k0lUbMRWzxF2o1Ux5ONVQPr781m4MxoAjx7OAVBCHn5W9iPuv1fSTZzu7LqWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=B2481GQ/du3bmRlSkrFsJmMFN50fOJFxZW0MHt1sVXU=; b=PeDjIB0M4A4RVJrWOS5Pspnoipmma5fvcxQilY5ykuUiHkK7kEY85CjaZqEZSGHSeuxgkUSEO1yj31YrxqV7pltjqv4FbVRst5nuwmU/tzYmwmDRLvL6ZsiG5g0vyt4afpwkHFwrdbxzd3pKaRh6XbZeCQ3zGj20A71PSYpKe9U0z8B0XjvUYbVx4bmqPz3K/xduLQW4Dl8G6mquyvu5+LkrzhW8PJ2xjK7D0cK09XQgN4Myg/qMJdSut4ySjqcAAqXVs1tAh+FtMnLv4a3BRd4cwHE+IPz5C5/n8n+CXjIV8OlgHm7s8fOm1J5KsHkfasYTHO9pcqGggSNlDTAx2w== 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=B2481GQ/du3bmRlSkrFsJmMFN50fOJFxZW0MHt1sVXU=; b=YxsOOPdPm6Y9sScZITVS21UU9IT3YhCCZuhjyUEshpUOechwvzkatfmSnXNARLzMgJy8ud2iRzU0i0s1ptEBGuyNqZybc7haoRwRNopflaRIvAgfz8HcF3mNGWaPYOP2M3xeotPq05AYID2YP+er9PHCsIoH0m5EplOLRpcfAQI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) by DM6PR12MB4353.namprd12.prod.outlook.com (2603:10b6:5:2a6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.19; Fri, 3 Mar 2023 12:50:35 +0000 Received: from BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::d23f:bb1:df95:3918]) by BN8PR12MB3587.namprd12.prod.outlook.com ([fe80::d23f:bb1:df95:3918%4]) with mapi id 15.20.6156.022; Fri, 3 Mar 2023 12:50:35 +0000 Message-ID: <5eb593b8-3cd3-af93-d1ce-59fea6b879b9@amd.com> Date: Fri, 3 Mar 2023 13:50:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH] drm/amdgpu: Implement mmap of imported dma-bufs Content-Language: en-US To: Marek Maslanka , dri-devel@lists.freedesktop.org, Daniel Vetter Cc: Dominik Behr , Alex Deucher , "Pan, Xinhui" , David Airlie , Lijo Lazar , Guchun Chen , Felix Kuehling , Marek Maslanka , Evan Quan , Hawking Zhang , Mario Limonciello , YiPeng Chai , =?UTF-8?Q?Michel_D=c3=a4nzer?= , Kai-Heng Feng , Luben Tuikov , Arunpravin Paneer Selvam , Tong Liu01 , Rajneesh Bhardwaj , Zack Rusin , amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20230303110951.3777850-1-mmaslanka@chromium.org> From: =?UTF-8?Q?Christian_K=c3=b6nig?= In-Reply-To: <20230303110951.3777850-1-mmaslanka@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR3P281CA0067.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:4b::14) To BN8PR12MB3587.namprd12.prod.outlook.com (2603:10b6:408:43::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8PR12MB3587:EE_|DM6PR12MB4353:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d200b2a-c4b3-4de0-b5cd-08db1be5e14d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s72eyISqmY0e6JIzafAP+otT6V2Ikw9Qgqq/1hP8nIWFR6GGQZ1KcinckHEwbSGenMqsjRtli3D7yr6fvQdX+M2ifhnyc+iGP6qcov9b/QZF4JAnmtk67r4nURf4I0YsChRtjUYgjcYbIht2drf3OkPDyfQvJq5VvRWdA4IeX+vq6ILjdzCELuMBYgeI6wQhq/04dkcRyhDPm8UZ0C4Ic6ZQBj7h8Q1eyaBZP0euXuk7QcFfAFecO87DHt/RNFflZHcdP2W7iN3tcvnax2nDgf/wBTgIIU88ADCSWX2+bRxhUtGsVpRpkkoJux8JUV3ujNs1OOba+dgW5GC/xHz5weASuHkaRykXzcytjytO3vywJtQ3Ita5BiaJ7FVcOiiAn9BYLiJxPvrnF9k4Kb7nA9QigNSmZheUbgN1u3PVo1tb7KEKmjsQDTnibMeaG3Bz6aKh+ytygRGwAlWtK4FSJYugswkdMjdk7UB5bMO043g5cF9kFnkdbrqcgXvTNU0pq4YPoAWHmBkp9dNXVw72vouajlCaWI74QUl3Q8Se/JrY/WbnlBc0SdeYohaZHWtJap/6MWqctQBG6pP7o+q/c8XWJ9lczrpFn2Z1PI1FD2unRXzA7FZbc78eGLOtrlygs4c0bR4H/5mczhxauu+nSxNRxMXMsqBrl1edziDGmfxfCdc8Z+/7gEjWY342VPbRCLjV6J0l1hXvUg//KHBZQo4oskoZB9sn8l1ydU5vyn8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR12MB3587.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(136003)(39860400002)(376002)(366004)(396003)(346002)(451199018)(83380400001)(31686004)(38100700002)(6666004)(31696002)(36756003)(5660300002)(8936002)(478600001)(7416002)(66556008)(86362001)(186003)(6506007)(2616005)(6512007)(6486002)(8676002)(66476007)(2906002)(66946007)(316002)(41300700001)(54906003)(110136005)(4326008)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-M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E5CQ3dKS2FscUlqWXErQjNYNUlBT1pNeWo4TUdrVG03TzFhcTNs?= =?utf-8?B?Y3VlUEYrK0NOWWpBbXZnWXRORERpWlFGa2pjZGRnZTEwUHZockJTcmduY1dw?= =?utf-8?B?NmJVbjVtckpubVRHaHNnNjJEUTNoWWhnU3d3VUoyajhnUnlFWHBWOGVlaFlR?= =?utf-8?B?MVpHQnNjeXN5VVJ5T1RaSkJWL25rZ0ViUjNhLzFLMWZtdlI1bGVLMjFSQ3Q5?= =?utf-8?B?QkZ5Y2g4NEhRRFBkYWF6N3lNSThPS0I0eGdiNXBVaFU2eXZxWGpKMjlEc0hh?= =?utf-8?B?U2UzbndvQ0JROHFSa21PS0M2OG5qbjExb3BDV2NxdmcxbTk3dVlxa2dxeTVV?= =?utf-8?B?UFpnSnNkM2p6cHBhMTlvZHgxaDdsK0tUNGdiWkpUZUU3ajE4NEM2eW1OK280?= =?utf-8?Q?L2AEAFxg+2OqdmZ9NrFj3mXeaYUat/2SPot16sKiCNob?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d200b2a-c4b3-4de0-b5cd-08db1be5e14d X-MS-Exchange-CrossTenant-AuthSource: BN8PR12MB3587.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2023 12:50:34.7609 (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: smY8mp08iZj1zoUlsXQj2tRWIM7sn4PeRWMCfbV34pQsYFWc75jn49JNJU2smSWO X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4353 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Well big NAK to this! We have discussed this extensively on the mailing list and absolutely don't want to allow that. Only for some ARM drivers we failed to block that soon enough and will keep the functionality around to not break userspace. Regards, Christian. Am 03.03.23 um 12:09 schrieb Marek Maslanka: > Use dmabuf mmap from exporting driver to do the mapping. > > Signed-off-by: Marek Maslanka > Signed-off-by: Dominik Behr > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 46 +++++++++++++++++++++ > drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h | 2 + > drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- > drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 9 ++++ > drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 + > 5 files changed, 59 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c > index 0c001bb8fc2b..8f22d29ba077 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c > @@ -37,6 +37,7 @@ > #include "amdgpu_dma_buf.h" > #include "amdgpu_xgmi.h" > #include > +#include > #include > #include > #include > @@ -275,6 +276,51 @@ const struct dma_buf_ops amdgpu_dmabuf_ops = { > .vunmap = drm_gem_dmabuf_vunmap, > }; > > +int amdgpu_try_dma_buf_mmap(struct file *filp, struct vm_area_struct *vma) > +{ > + struct drm_file *priv = filp->private_data; > + struct drm_device *dev = priv->minor->dev; > + struct amdgpu_device *adev = drm_to_adev(dev); > + struct ttm_device *bdev = &adev->mman.bdev; > + struct ttm_buffer_object *tbo = NULL; > + struct amdgpu_bo *bo = NULL; > + struct drm_gem_object *obj = NULL; > + struct drm_vma_offset_node *node; > + int ret; > + > + if (drm_dev_is_unplugged(dev)) > + return -ENODEV; > + > + drm_vma_offset_lock_lookup(bdev->vma_manager); > + node = drm_vma_offset_exact_lookup_locked(bdev->vma_manager, > + vma->vm_pgoff, > + vma_pages(vma)); > + > + if (likely(node)) { > + tbo = container_of(node, struct ttm_buffer_object, > + base.vma_node); > + tbo = ttm_bo_get_unless_zero(tbo); > + } > + drm_vma_offset_unlock_lookup(bdev->vma_manager); > + > + if (!tbo) > + return -EINVAL; > + > + bo = ttm_to_amdgpu_bo(tbo); > + obj = &tbo->base; > + > + if (!obj->import_attach) { > + ret = -EINVAL; > + goto done; > + } > + > + ret = dma_buf_mmap(obj->import_attach->dmabuf, vma, 0); > + > +done: > + ttm_bo_put(tbo); > + return ret; > +} > + > /** > * amdgpu_gem_prime_export - &drm_driver.gem_prime_export implementation > * @gobj: GEM BO > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h > index 3e93b9b407a9..ecf1dc32eec4 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.h > @@ -25,6 +25,8 @@ > > #include > > +int amdgpu_try_dma_buf_mmap(struct file *filp, struct vm_area_struct *vma); > + > struct dma_buf *amdgpu_gem_prime_export(struct drm_gem_object *gobj, > int flags); > struct drm_gem_object *amdgpu_gem_prime_import(struct drm_device *dev, > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > index 86fbb4138285..91e94342d48e 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > @@ -2737,7 +2737,7 @@ static const struct file_operations amdgpu_driver_kms_fops = { > .flush = amdgpu_flush, > .release = drm_release, > .unlocked_ioctl = amdgpu_drm_ioctl, > - .mmap = drm_gem_mmap, > + .mmap = amdgpu_mmap, > .poll = drm_poll, > .read = drm_read, > #ifdef CONFIG_COMPAT > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > index c5ef7f7bdc15..41944439cd6c 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > @@ -61,6 +61,7 @@ > #include "amdgpu_hmm.h" > #include "amdgpu_atomfirmware.h" > #include "amdgpu_res_cursor.h" > +#include "amdgpu_dma_buf.h" > #include "bif/bif_4_1_d.h" > > MODULE_IMPORT_NS(DMA_BUF); > @@ -1994,6 +1995,14 @@ static int amdgpu_ttm_prepare_job(struct amdgpu_device *adev, > DMA_RESV_USAGE_BOOKKEEP); > } > > +int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma) > +{ > + if (amdgpu_try_dma_buf_mmap(filp, vma) == 0) > + return 0; > + > + return drm_gem_mmap(filp, vma); > +} > + > int amdgpu_copy_buffer(struct amdgpu_ring *ring, uint64_t src_offset, > uint64_t dst_offset, uint32_t byte_count, > struct dma_resv *resv, > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h > index e2cd5894afc9..e4cd1bda7a2b 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h > @@ -152,6 +152,7 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo, > struct dma_resv *resv, > struct dma_fence **fence); > > +int amdgpu_mmap(struct file *filp, struct vm_area_struct *vma); > int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo); > void amdgpu_ttm_recover_gart(struct ttm_buffer_object *tbo); > uint64_t amdgpu_ttm_domain_start(struct amdgpu_device *adev, uint32_t type);