From patchwork Fri Oct 9 15:03:37 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: 11826173 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 81B3014D5 for ; Fri, 9 Oct 2020 15:03:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3F1DD222BA for ; Fri, 9 Oct 2020 15:03:49 +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="aa4N1QGk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F1DD222BA 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 3D6506B009A; Fri, 9 Oct 2020 11:03:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 386F66B009B; Fri, 9 Oct 2020 11:03:48 -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 24DF66B009C; Fri, 9 Oct 2020 11:03:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id E95636B009A for ; Fri, 9 Oct 2020 11:03:47 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E733233CD for ; Fri, 9 Oct 2020 15:03:46 +0000 (UTC) X-FDA: 77352706452.08.trick86_1913f99271e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id BD83F1819E766 for ; Fri, 9 Oct 2020 15:03:46 +0000 (UTC) X-Spam-Summary: 1,0,0,bb2b02f198c30e14,d41d8cd98f00b204,ckoenig.leichtzumerken@gmail.com,,RULES_HIT:41:69:152:355:379:541:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1381:1437:1515:1516:1518:1535:1542:1593:1594:1676:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2899:3138:3139:3140:3141:3142:3353:3865:3868:3870:4321:4385:4605:5007:6261:6653:6737:7903:8660:9413:9592:10004:10400:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12895:12986:13148:13230:13894:14093:14096:14097:14181:14394:14659:14687:14721:14877:21080:21444:21451:21627:21666:21740:21939:21990:30045:30054:30064:30069:30070,0,RBL:209.85.208.68:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.84.100;04y8zheo869od9t5ig6iaa3pz5ghyoceexai9z3n1wr11o9bej65ks87ms5y1tu.txkm4wwdt8hdudcgf8ptbrp8iobko5cukkimn1yxc16ogh77whrg55o3cqarx39.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,LFtim X-HE-Tag: trick86_1913f99271e1 X-Filterd-Recvd-Size: 5173 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 15:03:46 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id i5so9683015edr.5 for ; Fri, 09 Oct 2020 08:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=HfGOHdnl8P4UkAJXJm+asFhJ2S9PMVltmlEIidPYuz0=; b=aa4N1QGk9MW7oVueE84pS3IhklP/XdU7RdM9t04ujPc6+KsxPbCNzpAmnfSeiYSmsC KZHr/LYqlvTGsoZDC8fMF7aq5OM7PcEj+UFzb/n5MBMqNsV4HiFNcfPx+U870RxwOmLw GRoRXjF2T5oyi2JVye4+SIOr5LZDF+F7fqGvrZu/jXjQRTccEH+EzI3DH/xZJp/mz+yO OwWK8xhq3V2y4QsDyDIf+dMsxIEbHlQTRm4WK0p8lbBa0q8jYQfoCm/ZoqeSuAefFrVZ 0MuUPGHPEXS1TyeXAZHNNS1KCQ/ZLCrRDgD86GSjDsitEqB1cZOrUExVxuVKJacSGZqs I2BA== 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:mime-version :content-transfer-encoding; bh=HfGOHdnl8P4UkAJXJm+asFhJ2S9PMVltmlEIidPYuz0=; b=gM4ZsN70Lj2HifcJdVBHYl+iQxkxOmb/J/OAUj69A2S/NnwFXeAPHsUzL8lzMY94on o5aUDzGSNZl1TKGg7B0ayFxoSBJ0a0EdlhQirdKAkyXjOnpXCVhnYA/tfTZyojgy2RkI /CoIApDkdoelVbFxaiWt0pAbWdCqsLmkvaAETHbD0usqvONLIpm/oppEjukoXe21JPpJ 2HwDbStCK8t8V7+ruOgLbsOoYAvBuzQ3T+am2zXm0N6lDg0gD+EJgJAaaPgmjhVgvLpQ 0VQJMAXZiSDaKLUOMZUgXGHm5/W762lOoEVJGZ4jFhimwiOvac1NEMsO22aHsDKhAaeS 5iMw== X-Gm-Message-State: AOAM533VpuzTsR1F3eVm0SmEIB/8N0XA5iEcyWkS6Yogf1bYcorXv9SV HTy8CJXDeqlJ0cP8rLLTbOnKIM0J6E0= X-Google-Smtp-Source: ABdhPJyibPjE78lcVPlBYyG6PW0fP1GpDj3X5Tpm1VzsO7r6v4QYdB2IMOhxokvqNlnbjQNZuzUauQ== X-Received: by 2002:aa7:cc18:: with SMTP id q24mr8619083edt.108.1602255824666; Fri, 09 Oct 2020 08:03:44 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 08:03:43 -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 1/6] mm: mmap: fix fput in error path Date: Fri, 9 Oct 2020 17:03:37 +0200 Message-Id: <20201009150342.1979-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.17.1 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: Patch "495c10cc1c0c CHROMIUM: dma-buf: restore args..." adds a workaround for a bug in mmap_region. As the comment states ->mmap() callback can change vma->vm_file and so we might call fput() on the wrong file. Revert the workaround and proper fix this in mmap_region. Signed-off-by: Christian König Reviewed-by: Jason Gunthorpe --- drivers/dma-buf/dma-buf.c | 22 +++++----------------- mm/mmap.c | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index a6ba4d598f0e..edd57402a48a 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1143,9 +1143,6 @@ EXPORT_SYMBOL_GPL(dma_buf_end_cpu_access); int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, unsigned long pgoff) { - struct file *oldfile; - int ret; - if (WARN_ON(!dmabuf || !vma)) return -EINVAL; @@ -1163,22 +1160,13 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, return -EINVAL; /* readjust the vma */ - get_file(dmabuf->file); - oldfile = vma->vm_file; - vma->vm_file = dmabuf->file; - vma->vm_pgoff = pgoff; + if (vma->vm_file) + fput(vma->vm_file); - ret = dmabuf->ops->mmap(dmabuf, vma); - if (ret) { - /* restore old parameters on failure */ - vma->vm_file = oldfile; - fput(dmabuf->file); - } else { - if (oldfile) - fput(oldfile); - } - return ret; + vma->vm_file = get_file(dmabuf->file); + vma->vm_pgoff = pgoff; + return dmabuf->ops->mmap(dmabuf, vma); } EXPORT_SYMBOL_GPL(dma_buf_mmap); diff --git a/mm/mmap.c b/mm/mmap.c index 40248d84ad5f..3a2670d73355 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1852,8 +1852,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return addr; unmap_and_free_vma: + fput(vma->vm_file); vma->vm_file = NULL; - fput(file); /* Undo any partial mapping done by a device driver. */ unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); From patchwork Fri Oct 9 15:03:38 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: 11826179 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 537F0139F for ; Fri, 9 Oct 2020 15:03:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C82FE22276 for ; Fri, 9 Oct 2020 15:03:51 +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="gzSB37MJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C82FE22276 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 2C5FF6B009B; Fri, 9 Oct 2020 11:03:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 22AAC6B009C; Fri, 9 Oct 2020 11:03:49 -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 0A15B6B009D; Fri, 9 Oct 2020 11:03:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id CE3556B009B for ; Fri, 9 Oct 2020 11:03:48 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1986A362E for ; Fri, 9 Oct 2020 15:03:48 +0000 (UTC) X-FDA: 77352706536.02.pies09_480375c271e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id DB890101276AD for ; Fri, 9 Oct 2020 15:03:47 +0000 (UTC) X-Spam-Summary: 1,0,0,8faf4c4f908fa0c5,d41d8cd98f00b204,ckoenig.leichtzumerken@gmail.com,,RULES_HIT:2:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1381:1437:1515:1516:1518:1535:1593:1594:1605:1676:1730:1747:1777:1792:1801:2393:2559:2562:3138:3139:3140:3141:3142:3308:3865:3866:3867:3870:3871:4049:4120:4250:4321:4605:5007:6119:6261:6653:6737:7903:9413:9592:11026:11473:11657:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12895:12986:13894:14096:14097:14394:14659:14687:21080:21444:21451:21611:21627:21666:21990:30054:30064:30070,0,RBL:209.85.208.68:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.84.100;04yf7pc8c7crkphj1xj6feaxtrxjxycyda5i5d4mb4qp1h8akkdw8f73td5myop.jiknbq73ux56c58eqswyphorbn6uprobkw4depkzzybccm3ms6q73ugcnffp5em.w-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:1:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: pies09_480375c271e1 X-Filterd-Recvd-Size: 10000 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 15:03:47 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id l16so9688649eds.3 for ; Fri, 09 Oct 2020 08:03:47 -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=/KNFJOYdxSb2qiFFqZrfr76RXgP2ovb/rJFsndCmJ48=; b=gzSB37MJyFLgX68v0gj9Y0CBMFsZHW7vUgsUFgGyj4XT6aRMkgUFklHtBg/E7UM54d ucN5lwxsVw9F5e4KpeZGanQ2ykncrycSPnb8yYKJvlbcD+Gqu2VbY/jE1gG5agagP/Q2 +eMbApqM1L53LppSgymEEHPdAktgpvwHVDWe/qbWso8eN2FPN3lT2kbtOgvRJhiSHXcs VJQ5xE1oaQnSdTopgwegvvKQpQfMSGbWyLoSULRNIzvld78Rpqz7TyYbDPprsaiWNeR8 KMN1J8J7pRo2T9qdZXGOlwH56jXZo8tI9Qum/nRl5FOj5zepGkGts/AozS7x1GTmC/Hx YWsA== 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=/KNFJOYdxSb2qiFFqZrfr76RXgP2ovb/rJFsndCmJ48=; b=Z8tKW1PPEpEaQ0iIxmESywLFSttOSBAYYAFJOhF65nYmouPsFQILLQi+AbLSo03Q/B FJ8lTe/9yk+WNkf0jhbD6kQtvJ/RlpsiHHHYYddlwklF9Q/g2Wphr26YzdhHYFVWEeVG BdzpBjphNjNkikyXu+xnv9SHsqqPSIB8Ou7jiZPPNfqrH4wZpjl9Ehj7oHlhVUrTd52e CYdhFvT2WPW100Jr8pea5dYFZpraLFPvd4TIquq4RE1huap1JojuVFC5ZTQMu5FMDJ0q uP3CDJ1LErYbyPCx5Epux1i9eMAmwpdGfoGzlfpyeu56fT+QHwFZIVB0+NOHSYp+WvRK xPvg== X-Gm-Message-State: AOAM533N+MBgwLxH3zD+hiAAP5etyRu7TtzkWikCjz8lkZ5N6nFtkej4 nLcdQ0/1IlIRycmPmBEKulaBFQGm0Xg= X-Google-Smtp-Source: ABdhPJx6GcrD45dmKFlgGg1W3r7lj4kbvaCGRrSTGkzGy0phV2F1+TZcBxAnCoY4swhtx8cletX0RQ== X-Received: by 2002:a05:6402:3191:: with SMTP id di17mr5377edb.376.1602255825861; Fri, 09 Oct 2020 08:03:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 08:03:45 -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 2/6] mm: introduce vma_set_file function v3 Date: Fri, 9 Oct 2020 17:03:38 +0200 Message-Id: <20201009150342.1979-2-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: Add the new vma_set_file() function to allow changing vma->vm_file with the necessary refcount dance. v2: add more users of this. v3: add missing EXPORT_SYMBOL, rebase on mmap cleanup, add comments why we drop the reference on two occasions. Signed-off-by: Christian König Reviewed-by: Daniel Vetter (v2) --- drivers/dma-buf/dma-buf.c | 5 +---- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 4 +--- drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 3 +-- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 5 +++-- drivers/gpu/drm/msm/msm_gem.c | 4 +--- drivers/gpu/drm/omapdrm/omap_gem.c | 3 +-- drivers/gpu/drm/vgem/vgem_drv.c | 3 +-- drivers/staging/android/ashmem.c | 6 +++--- include/linux/mm.h | 2 ++ mm/mmap.c | 15 +++++++++++++++ 10 files changed, 29 insertions(+), 21 deletions(-) diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index edd57402a48a..8e6a114c6034 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c @@ -1160,10 +1160,7 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma, return -EINVAL; /* readjust the vma */ - if (vma->vm_file) - fput(vma->vm_file); - - vma->vm_file = get_file(dmabuf->file); + vma_set_file(vma, dmabuf->file); vma->vm_pgoff = pgoff; return dmabuf->ops->mmap(dmabuf, vma); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index 312e9d58d5a7..10ce267c0947 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -145,10 +145,8 @@ static int etnaviv_gem_mmap_obj(struct etnaviv_gem_object *etnaviv_obj, * address_space (so unmap_mapping_range does what we want, * in particular in the case of mmap'd dmabufs) */ - fput(vma->vm_file); - get_file(etnaviv_obj->base.filp); vma->vm_pgoff = 0; - vma->vm_file = etnaviv_obj->base.filp; + vma_set_file(vma, etnaviv_obj->base.filp); vma->vm_page_prot = vm_page_prot; } diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c index fec0e1e3dc3e..8ce4c9e28b87 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c @@ -119,8 +119,7 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * if (ret) return ret; - fput(vma->vm_file); - vma->vm_file = get_file(obj->base.filp); + vma_set_file(vma, obj->base.filp); return 0; } diff --git a/drivers/gpu/drm/i915/gem/i915_gem_mman.c b/drivers/gpu/drm/i915/gem/i915_gem_mman.c index 3d69e51f3e4d..ec28a6cde49b 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_mman.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_mman.c @@ -893,8 +893,9 @@ int i915_gem_mmap(struct file *filp, struct vm_area_struct *vma) * requires avoiding extraneous references to their filp, hence why * we prefer to use an anonymous file for their mmaps. */ - fput(vma->vm_file); - vma->vm_file = anon; + vma_set_file(vma, anon); + /* Drop the initial creation reference, the vma is now holding one. */ + fput(anon); switch (mmo->mmap_type) { case I915_MMAP_TYPE_WC: diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index de915ff6f4b4..a71f42870d5e 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -223,10 +223,8 @@ int msm_gem_mmap_obj(struct drm_gem_object *obj, * address_space (so unmap_mapping_range does what we want, * in particular in the case of mmap'd dmabufs) */ - fput(vma->vm_file); - get_file(obj->filp); vma->vm_pgoff = 0; - vma->vm_file = obj->filp; + vma_set_file(vma, obj->filp); vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); } diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c index 979d53a93c2b..0d4542ff1d7d 100644 --- a/drivers/gpu/drm/omapdrm/omap_gem.c +++ b/drivers/gpu/drm/omapdrm/omap_gem.c @@ -564,9 +564,8 @@ int omap_gem_mmap_obj(struct drm_gem_object *obj, * address_space (so unmap_mapping_range does what we want, * in particular in the case of mmap'd dmabufs) */ - fput(vma->vm_file); vma->vm_pgoff = 0; - vma->vm_file = get_file(obj->filp); + vma_set_file(vma, obj->filp); vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); } diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c index fa54a6d1403d..ea0eecae5153 100644 --- a/drivers/gpu/drm/vgem/vgem_drv.c +++ b/drivers/gpu/drm/vgem/vgem_drv.c @@ -397,8 +397,7 @@ static int vgem_prime_mmap(struct drm_gem_object *obj, if (ret) return ret; - fput(vma->vm_file); - vma->vm_file = get_file(obj->filp); + vma_set_file(vma, obj->filp); vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index 10b4be1f3e78..4789d36ddfd3 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -450,9 +450,9 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma) vma_set_anonymous(vma); } - if (vma->vm_file) - fput(vma->vm_file); - vma->vm_file = asma->file; + vma_set_file(vma, asma->file); + /* XXX: merge this with the get_file() above if possible */ + fput(asma->file); out: mutex_unlock(&ashmem_mutex); diff --git a/include/linux/mm.h b/include/linux/mm.h index ca6e6a81576b..f7a005153d02 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2693,6 +2693,8 @@ static inline void vma_set_page_prot(struct vm_area_struct *vma) } #endif +void vma_set_file(struct vm_area_struct *vma, struct file *file); + #ifdef CONFIG_NUMA_BALANCING unsigned long change_prot_numa(struct vm_area_struct *vma, unsigned long start, unsigned long end); diff --git a/mm/mmap.c b/mm/mmap.c index 3a2670d73355..19cd37c3ebac 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -136,6 +136,21 @@ void vma_set_page_prot(struct vm_area_struct *vma) WRITE_ONCE(vma->vm_page_prot, vm_page_prot); } +/* + * Change backing file, only valid to use during initial VMA setup. + */ +void vma_set_file(struct vm_area_struct *vma, struct file *file) +{ + if (file) + get_file(file); + + swap(vma->vm_file, file); + + if (file) + fput(file); +} +EXPORT_SYMBOL(vma_set_file); + /* * Requires inode->i_mapping->i_mmap_rwsem */ From patchwork Fri Oct 9 15:03:39 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: 11826181 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 ACB26139F for ; Fri, 9 Oct 2020 15:03:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6516D22260 for ; Fri, 9 Oct 2020 15:03:54 +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="AGNyrdR7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6516D22260 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 2525A6B009C; Fri, 9 Oct 2020 11:03:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1D9736B009D; Fri, 9 Oct 2020 11:03:50 -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 EA8CF6B009E; Fri, 9 Oct 2020 11:03:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id BB27E6B009C for ; Fri, 9 Oct 2020 11:03:49 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2928B362E for ; Fri, 9 Oct 2020 15:03:49 +0000 (UTC) X-FDA: 77352706578.13.tramp08_5d0dd79271e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 00C3018140B67 for ; Fri, 9 Oct 2020 15:03:48 +0000 (UTC) X-Spam-Summary: 1,0,0,c74d6df2b40b220d,d41d8cd98f00b204,ckoenig.leichtzumerken@gmail.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1381:1515:1516:1518:1534:1541:1593:1594:1676:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3351:3871:3876:5007:6261:6653:6737:9413:10004:10400:11026:11657:11658:11914:12043:12048:12114:12296:12297:12438:12517:12519:12555:12895:13069:13311:13357:13894:14096:14097:14181:14394:14659:14687:14721:21080:21444:21451:21627:21666:21987:21990:30054:30064,0,RBL:209.85.218.65:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yf1r4hyrs75qefo8ukua35puk61oceqphwuqi9uxuosktkwskhfn1i7pcnwez.wjw78ywqym5huzk7m79niczphijx8pbs7njkcazb49sw153pnaj8kgcc7a71nt3.w-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:24,LUA_SUMMARY:none X-HE-Tag: tramp08_5d0dd79271e1 X-Filterd-Recvd-Size: 4502 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 15:03:48 +0000 (UTC) Received: by mail-ej1-f65.google.com with SMTP id qp15so13547989ejb.3 for ; Fri, 09 Oct 2020 08:03:48 -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=MkTgctKmN/+akcDLdg3dMFFDd8/FeV1m0XEzLiveir0=; b=AGNyrdR7ovbvwJNKv5ShYQCGvaCPWMmDRaTW8qFyGws/zj5z3jnoqEBR9M1d8zZE9Q jAk6GE/rpLdeexJkeXjFnem3hWHuZIeIlIu2oYCnFR9FljYxFEIImO4DFZPcYp3a/IJU ksXRHC/0Glzu1uQnao8735fyHT/dBdhu4m5EMqDOtHJ5GcjNcBxeNi09cFjne+MbmsCR up0c37ZFeDZEzWeWAUHS3G0wM2twAG54Nn5vszFVqfa/YipqiiaAOO9t9Xgck5CQP6gc TmIX6Pbg9w3ySpPvLK8s77mld/oQKFhR9HY9wQFxzrvQdE6DYWu3dHcS2m9u47vqcESC ncMw== 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=MkTgctKmN/+akcDLdg3dMFFDd8/FeV1m0XEzLiveir0=; b=HwynNuezGV1TAH2GR68jgHZHLnXjf3a2g3XT9ULWLqC+3eOAfsdoJjMGiqoUQUoOgP gI2ddeQF56MSGSgNJgBUaviJDxEvUg0ZpV0VSOdHu0EpYt8XWKuBN8OxmUbbaq7h2NV2 HJ/1byOwhzI+OiI8kWUGRY677YWgLbdd+EDU0U46NdO91GdxLrO0+JGiFxtmEDV7no1B A2rgGa3ounqMMzOP+8Fn/H6+AIYN5AlBXYdDgRx+OOBM83WtfvzFgdHJ2Rc+O63nBfLC MiXT/C4i3ZhiXVS+lUujcqiAs3IDNmFBl4Q7XPXPQtOG7MYAGia6NEUM0TDmNi2u8bsx v7og== X-Gm-Message-State: AOAM530deTr3V+SYt/VFTemKv1QCQkyvDcJ1GnqNkqTGh2pk3OWYlN8o 9dhTTIgJv+J/+8T5ZluUBZQA36+qSGQ= X-Google-Smtp-Source: ABdhPJxX/Ju3hIyvLL3zSpMfzkxoIFpTpsg2eOHcQ1zbkD40IYw/NBRbhJgYcsG8QXE4hPf8JNVcAA== X-Received: by 2002:a17:906:11d3:: with SMTP id o19mr12363058eja.287.1602255827107; Fri, 09 Oct 2020 08:03:47 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 08:03:46 -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 3/6] drm/radeon: stop using pages with drm_prime_sg_to_page_addr_arrays Date: Fri, 9 Oct 2020 17:03:39 +0200 Message-Id: <20201009150342.1979-3-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: This is deprecated. Signed-off-by: Christian König --- drivers/gpu/drm/radeon/radeon_ttm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index 63e38b05a5bc..4b92cdbcd29b 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, ttm->pages, - gtt->ttm.dma_address, ttm->num_pages); + drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, gtt->ttm.dma_address, + ttm->num_pages); return 0; @@ -642,8 +642,9 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev, } if (slave && ttm->sg) { - drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages, - gtt->ttm.dma_address, ttm->num_pages); + drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, + gtt->ttm.dma_address, + ttm->num_pages); ttm_tt_set_populated(ttm); return 0; } From patchwork Fri Oct 9 15:03:40 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: 11826185 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 5B186139F for ; Fri, 9 Oct 2020 15:03:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 174E722260 for ; Fri, 9 Oct 2020 15:03:57 +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="n2lSWZNp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 174E722260 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 315016B009D; Fri, 9 Oct 2020 11:03:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2A8B06B009E; Fri, 9 Oct 2020 11:03:51 -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 13BFC94000B; Fri, 9 Oct 2020 11:03:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id D54D56B009D for ; Fri, 9 Oct 2020 11:03:50 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 607A9180AD811 for ; Fri, 9 Oct 2020 15:03:50 +0000 (UTC) X-FDA: 77352706620.06.vase96_3b156a5271e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 4260E101DB63F for ; Fri, 9 Oct 2020 15:03:50 +0000 (UTC) X-Spam-Summary: 1,0,0,a0d5def3d0a8cb0a,d41d8cd98f00b204,ckoenig.leichtzumerken@gmail.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1381:1437:1515:1516:1518:1534:1541:1593:1594:1676:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3350:3866:3867:3868:3871:4250:4321:5007:6261:6653:6737:9413:10004:10400:11026:11657:11658:11914:12043:12048:12114:12297:12438:12517:12519:12555:12895:12986:13069:13311:13357:13894:14096:14097:14181:14394:14659:14687:14721:21080:21433:21444:21451:21627:21666:21987:21990:30054:30064,0,RBL:209.85.218.66:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yr4jjecmegu9fb6g1q896jqfmzkoczyw5yk6qfp5csehfduwirg57zp8kb8us.1ja4wps5icgn45cmpinth8usgdsi3a47f7m8455goq4qpso16bnrnyyeckx38qe.k-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:25,LUA_SUMMARY:none X-HE-Tag: vase96_3b156a5271e1 X-Filterd-Recvd-Size: 4485 Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 15:03:49 +0000 (UTC) Received: by mail-ej1-f66.google.com with SMTP id h24so13511713ejg.9 for ; Fri, 09 Oct 2020 08:03:49 -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=aQ0/dy64GNY6E3PqMvkOeCw7tku1OiiEuNnrmc12zf0=; b=n2lSWZNpzrKXWTKd1W6mZN+iU+a03pL3chC65/ow10mL+TcHLgzGZy6LaSdOqRudg2 6ZnCwN00jr16PIJT7A98Fh3R0/ILkQEqWtvrPP/EU7af/GK7xJj7ImO32dzizw+rTHBN UmGIHDUFMyX/UowHrHokTHnotADyzWToutWCXju6AkMzkRsX4dAzjjaZ38Jn1LDDk/rU kQk4B1CL3KlMA1w76fNMBa6Dag//EKTiATOsGcXZhdPTVPjgo08ilGkEuMmtxaTFsFcj LmSJsFK/XxxeDqkKIxFcIh2W6lZz/j27/KRVNINvUTONV0HOh9W4FwjbGGLfQiPc9voJ ZhbQ== 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=aQ0/dy64GNY6E3PqMvkOeCw7tku1OiiEuNnrmc12zf0=; b=cUB9DeDTrEudUeR+Khr+BXIrPCJpN3eHpoG/NrDNf54TzlvaFDRaZZFm7c3V5Lm/NS 8NgYSGpJssjNZZCQQq8l0/R32txMJjV9Y5fIV4/IsK0YAmDuQRfDAK1bAr2E9A5KJ91/ nAZozUhzkIYa6x0fANagmU1SesCd4vVh4tQeTwdAHBBi6GvHigqzhPgtERkoklGZ35WR tT9MGlPZFhJUzM3IOudORAlbKnPYEF62LyZhpIfA2hV9t0EF72uejGp0cw3NVYNVYhtx XjOvJMF4OAp9sm2TUYZUnNcBc7eaAqjFWW5TNcdWwC8QEhmkPnnfYZxptXJoK1wjxbLX Oldg== X-Gm-Message-State: AOAM531WqGI6P6PJs+qrttdyg4nZa2GQshN3lohT1mtTpIOCDR0XihbN A6wWW6gMx7d7/k5N9Elam9JpbaS+uAA= X-Google-Smtp-Source: ABdhPJwwEFyy7ezS1KLDN5XkqzgWY/1qVctpNR81azSANIwKr5bqZ2LqAFPivOFH8zfDpSVfOFDs8Q== X-Received: by 2002:a17:906:2681:: with SMTP id t1mr15258406ejc.474.1602255828284; Fri, 09 Oct 2020 08:03:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 08:03:47 -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 4/6] drm/amdgpu: stop using pages with drm_prime_sg_to_page_addr_arrays Date: Fri, 9 Oct 2020 17:03:40 +0200 Message-Id: <20201009150342.1979-4-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: This is deprecated. Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 399961035ae6..ac463e706b19 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, ttm->pages, - gtt->ttm.dma_address, ttm->num_pages); + drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, gtt->ttm.dma_address, + ttm->num_pages); return 0; @@ -1345,7 +1345,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev, ttm->sg = sgt; } - drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages, + drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, gtt->ttm.dma_address, ttm->num_pages); ttm_tt_set_populated(ttm); From patchwork Fri Oct 9 15:03:41 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: 11826193 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 B5076139F for ; Fri, 9 Oct 2020 15:04:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7BF8E22276 for ; Fri, 9 Oct 2020 15:04:00 +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="XrFUM15i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BF8E22276 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 33BC16B009E; Fri, 9 Oct 2020 11:03:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2C65B94000B; Fri, 9 Oct 2020 11:03:53 -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 169E96B00A0; Fri, 9 Oct 2020 11:03:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id DC8C76B009E for ; Fri, 9 Oct 2020 11:03:52 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7612D1EF1 for ; Fri, 9 Oct 2020 15:03:52 +0000 (UTC) X-FDA: 77352706704.20.balls84_4c0a2d9271e1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 4B45E180C07A3 for ; Fri, 9 Oct 2020 15:03:51 +0000 (UTC) X-Spam-Summary: 1,0,0,864380889208025c,d41d8cd98f00b204,ckoenig.leichtzumerken@gmail.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1381:1437:1515:1516:1518:1534:1540:1568:1593:1594:1676:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3865:3871:4321:5007:6261:6653:6737:9413:10004:10400:11026:11657:11658:11914:12043:12048:12114:12297:12438:12517:12519:12555:12895:12986:13069:13311:13357:13894:14096:14097:14181:14394:14659:14687:14721:21080:21444:21451:21611:21627:21666:21740:21990:30054:30064,0,RBL:209.85.218.68:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04y8xwo3ainu9py38d3j5yxa4gpsgop7wu1ip5wrcu5mq3y7ibtm43z7nwsnaie.1ysbz6sywuqtpwrdmnwhuhhsb9jhbicuap4cwpzgqpr5acb8kehpu73eopw6s5k.s-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:24,LUA_SUMMARY:none X-HE-Tag: balls84_4c0a2d9271e1 X-Filterd-Recvd-Size: 4223 Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 15:03:50 +0000 (UTC) Received: by mail-ej1-f68.google.com with SMTP id p15so13526274ejm.7 for ; Fri, 09 Oct 2020 08:03:50 -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=FmM++3symsvpVR4siwjDU9+9KxruIk1gOAMHnKd0AiE=; b=XrFUM15iMxnW5r+cZykWaD+5lUM1thhhsQebgkflHil7pUpsJux+fxxaFn2fgRiHuV brSdA99+/2bMKqfPsJXJn/FuisTltXZglFLs2uC19dzC+26EGNznnkVDdEZckz8ZF+rt q1Hwvaxg+1a2kKO/MDHWsn09yXrDZALU9AamwjPCGg93X0G0EgyT/fdezAD9ZWNqqkaO BvILBcWk38vWvJGK/2UGNTh0gaNq7ZQJ0np3vWb7pRbdpBWS/pAZjyAxjzAgDYd4AfUr my9kTq68lUQL8GpKWHuIeUW5QVBbid6EmrB4IAeqZY3sXqRGtOgob8ueY2ImHtIhcOF9 f5vA== 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=FmM++3symsvpVR4siwjDU9+9KxruIk1gOAMHnKd0AiE=; b=d4LZ4ltrKdrfKI7oACGq3QSWgcoZY/IAaOgAy/zmS29+9aQRpytPqRcJvZYFmFNNwU jQEtFhwoIDunsr40uQrZKRIAuNn7kDfaBeQwTBu/q4UJwyhtdW3L8LB95FwE5y6h0UWA 5Zr8AyTyElVSGsi/Dxu8Pm3UD1bNxPRHjECw5Fr/dH6WFpP2MTVvrorelrFBNpLSnaxu gWrloCGLUiyVzYb+lodAJl0vthHmHxSxQ203vciEK7px/RB6d4q2hCHgCHqzyzdma1k7 /7/PTFiViZE1a/q/SYqEL4I6h/D7MzyH9PElmFjfKwtsXklK5lmR6ynlU0EwtrG8oVo5 zd3Q== X-Gm-Message-State: AOAM533fW/PdJJnjntzvOUihnOY3QuazKqGGS4KbVo8/J7VZrR3G/wYZ F5b7281ALKT3MVjHhkqoZjrPvGUWXdE= X-Google-Smtp-Source: ABdhPJyN5ELfE5Ze/1hZ+8RjxM7E1Du5RNH1vhDQ1NOfDbdJcYgRfdItr1lNkT4hlsX9OlPerKunKw== X-Received: by 2002:a17:906:7f8d:: with SMTP id f13mr14847374ejr.540.1602255829532; Fri, 09 Oct 2020 08:03:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 08:03:49 -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 5/6] drm/nouveau: stop using pages with drm_prime_sg_to_page_addr_arrays Date: Fri, 9 Oct 2020 17:03:41 +0200 Message-Id: <20201009150342.1979-5-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: This is deprecated, also drop the comment about faults. Signed-off-by: Christian König --- drivers/gpu/drm/nouveau/nouveau_bo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index 0c0ca44a6802..e378bb491688 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -1299,9 +1299,9 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev, return 0; if (slave && ttm->sg) { - /* make userspace faulting work */ - drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages, - ttm_dma->dma_address, ttm->num_pages); + drm_prime_sg_to_page_addr_arrays(ttm->sg, NULL, + ttm_dma->dma_address, + ttm->num_pages); ttm_tt_set_populated(ttm); return 0; } 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__ */