From patchwork Fri Oct 9 15:03:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 11826207 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38AD6139F for ; Fri, 9 Oct 2020 15:04:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D9DFC22260 for ; Fri, 9 Oct 2020 15:04:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n2nnRwI0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9DFC22260 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E0D816B009F; Fri, 9 Oct 2020 11:04:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DE3EA6B00A0; Fri, 9 Oct 2020 11:04:22 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFBA594000B; Fri, 9 Oct 2020 11:04:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0039.hostedemail.com [216.40.44.39]) by kanga.kvack.org (Postfix) with ESMTP id A2D266B009F for ; Fri, 9 Oct 2020 11:04:22 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2086A33CD for ; Fri, 9 Oct 2020 15:04:22 +0000 (UTC) X-FDA: 77352707964.25.wire85_27110e6271e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 1F6A91804EE0B for ; Fri, 9 Oct 2020 15:03:53 +0000 (UTC) X-Spam-Summary: 1,0,0,15e62b581d1a49c8,d41d8cd98f00b204,ckoenig.leichtzumerken@gmail.com,,RULES_HIT:1:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1381:1437:1515:1516:1518:1593:1594:1605:1676:1730:1747:1777:1792:1801:2198:2199:2393:2559:2562:2636:2731:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:4605:5007:6119:6261:6653:6737:7875:7903:8603:9413:9592:10004:11026:11233:11657:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12895:12986:13141:13230:13894:14096:14097:14394:14659:14687:21080:21433:21444:21451:21627:21666:21740:21987:21990:30003:30054:30064,0,RBL:209.85.218.66:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yr5xsr3hxqfmaw4wdpcrzhu1npuyp74qdatnj7sk7wtidmozrn8azt13uszzz.nmuxxawgcq813d5e1mzzqcan6fq3b78t5qieag8wde1k791oexgcmxhsg1tgib3.h-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0: 0,LFtime X-HE-Tag: wire85_27110e6271e1 X-Filterd-Recvd-Size: 14190 Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 15:03:52 +0000 (UTC) Received: by mail-ej1-f66.google.com with SMTP id h24so13511928ejg.9 for ; Fri, 09 Oct 2020 08:03:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=6ugvF4IgTz7tWf0PCaB/4auf5Wv0lFq59SvvHpBULxI=; b=n2nnRwI0ufKMCqDombougDt4u0W9ym9MfBOn0RMvHZwK3NSdnCsaI373cmjMSn9J0x yEHKFVrXCmFtnPfIR5jnnICB5dPZNhX87Q1Q/2o9brR9I38rsKGfEqllIKvpiNnpepcZ 3gaEB5jxd/CA3T7+mcOHnp7taJTjTcyBFtuzLZ/JwT1C1+ZGvvDQyvNyRYxlHplNFdOk nFOaOUOKenTgPgauhotJ2XzKWNO1iqGB53YQJRPBjva4Cd2oMkdEqwyLt+R3R2ZuPVth LHKlwPX4o0PTdP3wyJTd5w80ilZD4lH58/RfRuF6N/5jl0hGRvQ1iWZAJVMaCqV/cO2C RoAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6ugvF4IgTz7tWf0PCaB/4auf5Wv0lFq59SvvHpBULxI=; b=fuJy4Xb9Dnq9kUVN/Fedy5PcPGb2i1+sMyvG5e+xeRm42wsEMAsb2LhINJ9It5e8ei DUoLb4Z1//d+1J4oe+QvZxh9GDMos3JghWqpeCat9Ny0x2r1r202Yko96MJrg//yf0Xp oJn7jrckmPGgydBHJdqo0D1n2paPt06lyyD/KRWKnXAGLuK+lpklrHzFsoNyq1T3cjaC lpciX2ypjq1dUVUovthFn2Bmj4ERrs+uDWwmv2lZgskovcpi90k8cz1Reo6uvoqqsz9a xWCx+W2Gy9flA6546ujWhc6do+FWSRccpP/RTaTcnEuzwyR2vyb1cpt4EWdcGu6+XJ0l aKNg== X-Gm-Message-State: AOAM532jDBqOBhltQXx6VfAiX6fH9pYzSsfSUW4QeVOaP9Uz79edsKmw IKZ14OmRD5H4d0EtuNwkGbd+0Q/NUnY= X-Google-Smtp-Source: ABdhPJwqTN2lTowZ4dUG7uMxTX3cR2kAKfoqxbzhNBcJ7B0y+0q8e7eIiVVCBW5m7D99Ax7NgprkrQ== X-Received: by 2002:a17:906:b353:: with SMTP id cd19mr14474953ejb.140.1602255830622; Fri, 09 Oct 2020 08:03:50 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:65f3:51d4:50d0:15b0]) by smtp.gmail.com with ESMTPSA id v14sm789364edy.68.2020.10.09.08.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 08:03:50 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, chris@chris-wilson.co.uk, airlied@redhat.com, akpm@linux-foundation.org, daniel@ffwll.ch, sumit.semwal@linaro.org, willy@infradead.org, jhubbard@nvidia.com, jgg@ziepe.ca Subject: [PATCH 6/6] drm/prime: document that use the page array is deprecated v2 Date: Fri, 9 Oct 2020 17:03:42 +0200 Message-Id: <20201009150342.1979-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201009150342.1979-1-christian.koenig@amd.com> References: <20201009150342.1979-1-christian.koenig@amd.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We have reoccurring requests on this so better document that this approach doesn't work and dma_buf_mmap() needs to be used instead. v2: split it into two functions Signed-off-by: Christian König Acked-by: Daniel Vetter --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 9 ++- drivers/gpu/drm/drm_prime.c | 67 +++++++++++++++------ drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 3 +- drivers/gpu/drm/msm/msm_gem.c | 2 +- drivers/gpu/drm/nouveau/nouveau_bo.c | 5 +- drivers/gpu/drm/radeon/radeon_ttm.c | 9 ++- drivers/gpu/drm/vgem/vgem_drv.c | 3 +- drivers/gpu/drm/vkms/vkms_gem.c | 2 +- drivers/gpu/drm/xen/xen_drm_front_gem.c | 4 +- include/drm/drm_prime.h | 7 ++- 10 files changed, 69 insertions(+), 42 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index ac463e706b19..6a65490de391 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1011,8 +1011,8 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_bo_device *bdev, goto release_sg; /* convert SG to linear array of pages and dma addresses */ - drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, gtt->ttm.dma_address, - ttm->num_pages); + drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address, + ttm->num_pages); return 0; @@ -1345,9 +1345,8 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev, ttm->sg = sgt; } - drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, - gtt->ttm.dma_address, - ttm->num_pages); + drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address, + ttm->num_pages); ttm_tt_set_populated(ttm); return 0; } diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 4910c446db83..8b750c074494 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -954,27 +954,25 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, EXPORT_SYMBOL(drm_gem_prime_import); /** - * drm_prime_sg_to_page_addr_arrays - convert an sg table into a page array + * drm_prime_sg_to_page_array - convert an sg table into a page array * @sgt: scatter-gather table to convert - * @pages: optional array of page pointers to store the page array in - * @addrs: optional array to store the dma bus address of each page - * @max_entries: size of both the passed-in arrays + * @pages: array of page pointers to store the pages in + * @max_entries: size of the passed-in array * - * Exports an sg table into an array of pages and addresses. This is currently - * required by the TTM driver in order to do correct fault handling. + * Exports an sg table into an array of pages. * - * Drivers can use this in their &drm_driver.gem_prime_import_sg_table - * implementation. + * This function is deprecated and strongly discouraged to be used. + * The page array is only useful for page faults and those can corrupt fields + * in the struct page if they are not handled by the exporting driver. */ -int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, - dma_addr_t *addrs, int max_entries) +int __deprecated drm_prime_sg_to_page_array(struct sg_table *sgt, + struct page **pages, + int max_entries) { unsigned count; struct scatterlist *sg; struct page *page; u32 page_len, page_index; - dma_addr_t addr; - u32 dma_len, dma_index; /* * Scatterlist elements contains both pages and DMA addresses, but @@ -984,14 +982,11 @@ int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, * described by the sg_dma_address(sg). */ page_index = 0; - dma_index = 0; for_each_sg(sgt->sgl, sg, sgt->nents, count) { page_len = sg->length; page = sg_page(sg); - dma_len = sg_dma_len(sg); - addr = sg_dma_address(sg); - while (pages && page_len > 0) { + while (page_len > 0) { if (WARN_ON(page_index >= max_entries)) return -1; pages[page_index] = page; @@ -999,7 +994,43 @@ int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, page_len -= PAGE_SIZE; page_index++; } - while (addrs && dma_len > 0) { + } + return 0; +} +EXPORT_SYMBOL(drm_prime_sg_to_page_array); + +/** + * drm_prime_sg_to_dma_addr_array - convert an sg table into a dma addr array + * @sgt: scatter-gather table to convert + * @addrs: array to store the dma bus address of each page + * @max_entries: size of both the passed-in arrays + * + * Exports an sg table into an array of addresses. + * + * Drivers should use this in their &drm_driver.gem_prime_import_sg_table + * implementation. + */ +int drm_prime_sg_to_dma_addr_array(struct sg_table *sgt, dma_addr_t *addrs, + int max_entries) +{ + struct scatterlist *sg; + u32 dma_len, dma_index; + dma_addr_t addr; + unsigned count; + + /* + * Scatterlist elements contains both pages and DMA addresses, but + * one shoud not assume 1:1 relation between them. The sg->length is + * the size of the physical memory chunk described by the sg->page, + * while sg_dma_len(sg) is the size of the DMA (IO virtual) chunk + * described by the sg_dma_address(sg). + */ + dma_index = 0; + for_each_sg(sgt->sgl, sg, sgt->nents, count) { + dma_len = sg_dma_len(sg); + addr = sg_dma_address(sg); + + while (dma_len > 0) { if (WARN_ON(dma_index >= max_entries)) return -1; addrs[dma_index] = addr; @@ -1010,7 +1041,7 @@ int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, } return 0; } -EXPORT_SYMBOL(drm_prime_sg_to_page_addr_arrays); +EXPORT_SYMBOL(drm_prime_sg_to_dma_addr_array); /** * drm_prime_gem_destroy - helper to clean up a PRIME-imported GEM object diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c index 135fbff6fecf..8c04b8e8054c 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c @@ -133,8 +133,7 @@ struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev, goto fail; } - ret = drm_prime_sg_to_page_addr_arrays(sgt, etnaviv_obj->pages, - NULL, npages); + ret = drm_prime_sg_to_page_array(sgt, etnaviv_obj->pages, npages); if (ret) goto fail; diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index a71f42870d5e..616b87641740 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -1174,7 +1174,7 @@ struct drm_gem_object *msm_gem_import(struct drm_device *dev, goto fail; } - ret = drm_prime_sg_to_page_addr_arrays(sgt, msm_obj->pages, NULL, npages); + ret = drm_prime_sg_to_page_array(sgt, msm_obj->pages, npages); if (ret) { mutex_unlock(&msm_obj->lock); goto fail; diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index e378bb491688..835edd74ef59 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -1299,9 +1299,8 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev, return 0; if (slave && ttm->sg) { - drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, - ttm_dma->dma_address, - ttm->num_pages); + drm_prime_sg_to_dma_addr_array(ttm->sg, ttm_dma->dma_address, + ttm->num_pages); ttm_tt_set_populated(ttm); return 0; } diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index 4b92cdbcd29b..7997e4564576 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c @@ -474,8 +474,8 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_bo_device *bdev, struct ttm_tt * if (r) goto release_sg; - drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, gtt->ttm.dma_address, - ttm->num_pages); + drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address, + ttm->num_pages); return 0; @@ -642,9 +642,8 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev, } if (slave && ttm->sg) { - drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, - gtt->ttm.dma_address, - ttm->num_pages); + drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address, + ttm->num_pages); ttm_tt_set_populated(ttm); return 0; } diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c index ea0eecae5153..e505e5a291b3 100644 --- a/drivers/gpu/drm/vgem/vgem_drv.c +++ b/drivers/gpu/drm/vgem/vgem_drv.c @@ -356,8 +356,7 @@ static struct drm_gem_object *vgem_prime_import_sg_table(struct drm_device *dev, } obj->pages_pin_count++; /* perma-pinned */ - drm_prime_sg_to_page_addr_arrays(obj->table, obj->pages, NULL, - npages); + drm_prime_sg_to_page_array(obj->table, obj->pages, npages); return &obj->base; } diff --git a/drivers/gpu/drm/vkms/vkms_gem.c b/drivers/gpu/drm/vkms/vkms_gem.c index 19a0e260a4df..a2ff21f47101 100644 --- a/drivers/gpu/drm/vkms/vkms_gem.c +++ b/drivers/gpu/drm/vkms/vkms_gem.c @@ -256,6 +256,6 @@ vkms_prime_import_sg_table(struct drm_device *dev, return ERR_PTR(-ENOMEM); } - drm_prime_sg_to_page_addr_arrays(sg, obj->pages, NULL, npages); + drm_prime_sg_to_page_array(sg, obj->pages, npages); return &obj->gem; } diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c b/drivers/gpu/drm/xen/xen_drm_front_gem.c index f3830a0d1808..f4150ddfc5e2 100644 --- a/drivers/gpu/drm/xen/xen_drm_front_gem.c +++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c @@ -220,8 +220,8 @@ xen_drm_front_gem_import_sg_table(struct drm_device *dev, xen_obj->sgt_imported = sgt; - ret = drm_prime_sg_to_page_addr_arrays(sgt, xen_obj->pages, - NULL, xen_obj->num_pages); + ret = drm_prime_sg_to_page_array(sgt, xen_obj->pages, + xen_obj->num_pages); if (ret < 0) return ERR_PTR(ret); diff --git a/include/drm/drm_prime.h b/include/drm/drm_prime.h index 093f760cc131..4bda9ab3a3bb 100644 --- a/include/drm/drm_prime.h +++ b/include/drm/drm_prime.h @@ -103,8 +103,9 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg); -int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages, - dma_addr_t *addrs, int max_pages); - +int drm_prime_sg_to_page_array(struct sg_table *sgt, struct page **pages, + int max_pages); +int drm_prime_sg_to_dma_addr_array(struct sg_table *sgt, dma_addr_t *addrs, + int max_pages); #endif /* __DRM_PRIME_H__ */