All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Zhao <yuzhao@google.com>
To: Christian Koenig <christian.koenig@amd.com>,
	Huang Rui <ray.huang@amd.com>, Junwei Zhang <Jerry.Zhang@amd.com>,
	David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Yu Zhao <yuzhao@google.com>
Subject: [PATCH] drm/ttm: properly unmap dma page upon failure
Date: Mon, 25 Mar 2019 14:22:50 -0600	[thread overview]
Message-ID: <20190325202250.212801-1-yuzhao@google.com> (raw)

dma_unmap_page() must be called with exactly the same dma address
and size returned by dma_map_page(). Otherwise, the function may
fail.

This is at least the case for debug_dma_unmap_page() and AMD iommu
unmap_page callback.

Signed-off-by: Yu Zhao <yuzhao@google.com>
---
 drivers/gpu/drm/ttm/ttm_page_alloc.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index f841accc2c00..c1636595f63c 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -1118,10 +1118,19 @@ int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
 						  0, num_pages * PAGE_SIZE,
 						  DMA_BIDIRECTIONAL);
 		if (dma_mapping_error(dev, tt->dma_address[i])) {
+			num_pages = 1;
 			while (i--) {
+				if (i && tt->ttm.pages[i] -
+					 tt->ttm.pages[i - 1] == 1) {
+					tt->dma_address[i] = 0;
+					num_pages++;
+					continue;
+				}
 				dma_unmap_page(dev, tt->dma_address[i],
-					       PAGE_SIZE, DMA_BIDIRECTIONAL);
+					       num_pages * PAGE_SIZE,
+					       DMA_BIDIRECTIONAL);
 				tt->dma_address[i] = 0;
+				num_pages = 1;
 			}
 			ttm_pool_unpopulate(&tt->ttm);
 			return -EFAULT;
-- 
2.21.0.392.gf8f6787159e-goog


             reply	other threads:[~2019-03-25 20:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-25 20:22 Yu Zhao [this message]
2019-07-06 17:33 ` [PATCH] drm/ttm: properly unmap dma page upon failure Yu Zhao
2019-08-21 19:09 ` Yu Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190325202250.212801-1-yuzhao@google.com \
    --to=yuzhao@google.com \
    --cc=Jerry.Zhang@amd.com \
    --cc=airlied@linux.ie \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ray.huang@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.