All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <deathsimple@vodafone.de>
To: alexdeucher@gmail.com
Cc: dri-devel@lists.freedesktop.org
Subject: [PATCH 2/5] drm/radeon: add userptr flag to limit it to anonymous memory v2
Date: Tue,  5 Aug 2014 18:05:29 +0200	[thread overview]
Message-ID: <1407254732-8332-2-git-send-email-deathsimple@vodafone.de> (raw)
In-Reply-To: <1407254732-8332-1-git-send-email-deathsimple@vodafone.de>

From: Christian König <christian.koenig@amd.com>

Avoid problems with writeback by limiting userptr to anonymous memory.

v2: add commit and code comments

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/radeon/radeon_gem.c |  3 ++-
 drivers/gpu/drm/radeon/radeon_ttm.c | 10 ++++++++++
 include/uapi/drm/radeon_drm.h       |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index 993ab22..032736b 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -290,7 +290,8 @@ int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data,
 		return -EACCES;
 
 	/* reject unknown flag values */
-	if (args->flags & ~RADEON_GEM_USERPTR_READONLY)
+	if (args->flags & ~(RADEON_GEM_USERPTR_READONLY |
+	    RADEON_GEM_USERPTR_ANONONLY))
 		return -EINVAL;
 
 	/* readonly pages not tested on older hardware */
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 0109090..54eb7bc 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -542,6 +542,16 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_tt *ttm)
 		       ttm->num_pages * PAGE_SIZE))
 		return -EFAULT;
 
+	if (gtt->userflags & RADEON_GEM_USERPTR_ANONONLY) {
+		/* check that we only pin down anonymous memory
+		   to prevent problems with writeback */
+		unsigned long end = gtt->userptr + ttm->num_pages * PAGE_SIZE;
+		struct vm_area_struct *vma;
+		vma = find_vma(gtt->usermm, gtt->userptr);
+		if (!vma || vma->vm_file || vma->vm_end < end)
+			return -EPERM;
+	}
+
 	do {
 		unsigned num_pages = ttm->num_pages - pinned;
 		uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;
diff --git a/include/uapi/drm/radeon_drm.h b/include/uapi/drm/radeon_drm.h
index 3a9f209..9720e1a 100644
--- a/include/uapi/drm/radeon_drm.h
+++ b/include/uapi/drm/radeon_drm.h
@@ -816,6 +816,7 @@ struct drm_radeon_gem_create {
  * perform any operation.
  */
 #define RADEON_GEM_USERPTR_READONLY	(1 << 0)
+#define RADEON_GEM_USERPTR_ANONONLY	(1 << 1)
 
 struct drm_radeon_gem_userptr {
 	uint64_t		addr;
-- 
1.9.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2014-08-05 16:06 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-05 16:05 [PATCH 1/5] drm/radeon: add userptr support v7 Christian König
2014-08-05 16:05 ` Christian König [this message]
2014-08-05 17:39   ` [PATCH 2/5] drm/radeon: add userptr flag to limit it to anonymous memory v2 Jerome Glisse
2014-08-05 17:45     ` Christian König
2014-08-05 22:13       ` Jerome Glisse
2014-08-06  6:55         ` Christian König
2014-08-06 16:08           ` Jerome Glisse
2014-08-06 17:17             ` Christian König
2014-08-06 18:34               ` Jerome Glisse
2014-08-06 18:39                 ` Jerome Glisse
2014-08-06 20:24                 ` Daniel Vetter
2014-08-07  3:45                   ` Jerome Glisse
2014-08-07  6:55                     ` Daniel Vetter
2014-08-07  7:36                       ` Christian König
2014-08-05 16:05 ` [PATCH 3/5] drm/radeon: add userptr flag to directly validate the BO to GTT Christian König
2014-08-05 16:05 ` [PATCH 4/5] drm/radeon: add userptr flag to register MMU notifier v3 Christian König
2014-08-06 15:16   ` Jerome Glisse
2014-08-06 15:23     ` Christian König
2014-08-05 16:05 ` [PATCH 5/5] drm/radeon: allow userptr write access under certain conditions Christian König
2014-08-07  7:36 [PATCH 1/5] drm/radeon: add userptr support v8 Christian König
2014-08-07  7:36 ` [PATCH 2/5] drm/radeon: add userptr flag to limit it to anonymous memory v2 Christian König

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=1407254732-8332-2-git-send-email-deathsimple@vodafone.de \
    --to=deathsimple@vodafone.de \
    --cc=alexdeucher@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    /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.