linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Thierry Reding
	<thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Mikko Perttunen <cyndis-/1wQRMveznE@public.gmane.org>,
	Erik Faye-Lund
	<kusmabite-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	DRI Development
	<dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Subject: [PATCH v3 04/20] drm/tegra: Correct copying of waitchecks and disable them in the 'submit' IOCTL
Date: Thu, 15 Jun 2017 02:18:27 +0300	[thread overview]
Message-ID: <e17fe66ca24fc18b2f1207211f14564d0dc2cad3.1497480755.git.digetx@gmail.com> (raw)
In-Reply-To: <cover.1497480751.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
In-Reply-To: <cover.1497480751.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

The waitchecks along with multiple syncpoints per submit are not ready for
use yet, let's forbid them for now.

Signed-off-by: Dmitry Osipenko <digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Reviewed-by: Mikko Perttunen <mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 drivers/gpu/drm/tegra/drm.c | 60 ++++++++++++++++++++++++++++++++++++++++++---
 drivers/gpu/host1x/job.h    |  7 ------
 include/linux/host1x.h      |  7 ++++++
 3 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
index c9246405fc7b..b90ed2cd32ce 100644
--- a/drivers/gpu/drm/tegra/drm.c
+++ b/drivers/gpu/drm/tegra/drm.c
@@ -349,6 +349,36 @@ static int host1x_reloc_copy_from_user(struct host1x_reloc *dest,
 	return 0;
 }
 
+static int host1x_waitchk_copy_from_user(struct host1x_waitchk *dest,
+					 struct drm_tegra_waitchk __user *src,
+					 struct drm_file *file)
+{
+	u32 cmdbuf;
+	int err;
+
+	err = get_user(cmdbuf, &src->handle);
+	if (err < 0)
+		return err;
+
+	err = get_user(dest->offset, &src->offset);
+	if (err < 0)
+		return err;
+
+	err = get_user(dest->syncpt_id, &src->syncpt);
+	if (err < 0)
+		return err;
+
+	err = get_user(dest->thresh, &src->thresh);
+	if (err < 0)
+		return err;
+
+	dest->bo = host1x_bo_lookup(file, cmdbuf);
+	if (!dest->bo)
+		return -ENOENT;
+
+	return 0;
+}
+
 int tegra_drm_submit(struct tegra_drm_context *context,
 		     struct drm_tegra_submit *args, struct drm_device *drm,
 		     struct drm_file *file)
@@ -370,6 +400,10 @@ int tegra_drm_submit(struct tegra_drm_context *context,
 	if (args->num_syncpts != 1)
 		return -EINVAL;
 
+	/* We don't yet support waitchks */
+	if (args->num_waitchks != 0)
+		return -EINVAL;
+
 	job = host1x_job_alloc(context->channel, args->num_cmdbufs,
 			       args->num_relocs, args->num_waitchks);
 	if (!job)
@@ -458,10 +492,28 @@ int tegra_drm_submit(struct tegra_drm_context *context,
 		}
 	}
 
-	if (copy_from_user(job->waitchk, waitchks,
-			   sizeof(*waitchks) * num_waitchks)) {
-		err = -EFAULT;
-		goto fail;
+	/* copy and resolve waitchks from submit */
+	while (num_waitchks--) {
+		struct host1x_waitchk *wait = &job->waitchk[num_waitchks];
+		struct tegra_bo *obj;
+
+		err = host1x_waitchk_copy_from_user(wait,
+						    &waitchks[num_waitchks],
+						    file);
+		if (err < 0)
+			goto fail;
+
+		obj = host1x_to_tegra_bo(wait->bo);
+
+		/*
+		 * The unaligned offset will cause an unaligned write during
+		 * of the waitchks patching, corrupting the commands stream.
+		 */
+		if (wait->offset & 3 ||
+		    wait->offset >= obj->gem.size) {
+			err = -EINVAL;
+			goto fail;
+		}
 	}
 
 	if (copy_from_user(&syncpt, (void __user *)(uintptr_t)args->syncpts,
diff --git a/drivers/gpu/host1x/job.h b/drivers/gpu/host1x/job.h
index 878239c476d2..0debd93a1849 100644
--- a/drivers/gpu/host1x/job.h
+++ b/drivers/gpu/host1x/job.h
@@ -34,13 +34,6 @@ struct host1x_cmdbuf {
 	u32 pad;
 };
 
-struct host1x_waitchk {
-	struct host1x_bo *bo;
-	u32 offset;
-	u32 syncpt_id;
-	u32 thresh;
-};
-
 struct host1x_job_unpin_data {
 	struct host1x_bo *bo;
 	struct sg_table *sgt;
diff --git a/include/linux/host1x.h b/include/linux/host1x.h
index 3d04aa1dc83e..aa323e43ae4e 100644
--- a/include/linux/host1x.h
+++ b/include/linux/host1x.h
@@ -177,6 +177,13 @@ struct host1x_reloc {
 	unsigned long shift;
 };
 
+struct host1x_waitchk {
+	struct host1x_bo *bo;
+	u32 offset;
+	u32 syncpt_id;
+	u32 thresh;
+};
+
 struct host1x_job {
 	/* When refcount goes to zero, job can be freed */
 	struct kref ref;
-- 
2.13.0

  parent reply	other threads:[~2017-06-14 23:18 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-14 23:18 [PATCH v3 00/20] Tegra DRM fixes Dmitry Osipenko
     [not found] ` <cover.1497480751.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14 23:18   ` [PATCH v3 01/20] drm/tegra: Fix lockup on a use of staging API Dmitry Osipenko
     [not found]     ` <7b70a506a9d2355ea6ff19a8c4f4d726b67719b3.1497480754.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-15 12:11       ` Thierry Reding
2017-06-14 23:18   ` [PATCH v3 02/20] drm/tegra: Correct idr_alloc() minimum id Dmitry Osipenko
     [not found]     ` <9c19a44219acd988e678cf9abe21363911184625.1497480754.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-15 12:13       ` Thierry Reding
2017-06-14 23:18   ` [PATCH v3 03/20] drm/tegra: Check for malformed offsets and sizes in the 'submit' IOCTL Dmitry Osipenko
2017-06-14 23:18   ` Dmitry Osipenko [this message]
2017-06-14 23:18   ` [PATCH v3 05/20] drm/tegra: Check syncpoint ID " Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 06/20] drm/tegra: dc: Avoid reset asserts on Tegra20 Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 07/20] drm/tegra: dc: Apply clipping to the plane Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 08/20] drm/tegra: dc: Disable plane if it is invisible Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 09/20] gpu: host1x: Initialize firewall class to the jobs one Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 10/20] gpu: host1x: Correct host1x_job_pin() error handling Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 11/20] gpu: host1x: Do not leak BO's phys address to userspace Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 12/20] gpu: host1x: Forbid relocation address shifting in the firewall Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 13/20] gpu: host1x: Forbid RESTART opcode " Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 14/20] gpu: host1x: Forbid unrelated SETCLASS " Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 15/20] gpu: host1x: Correct swapped arguments in the is_addr_reg() definition Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 16/20] gpu: host1x: Check waits in the firewall Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 17/20] gpu: host1x: Remove unused 'struct host1x_cmdbuf' Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 18/20] gpu: host1x: Remove unused host1x_cdma_stop() definition Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 19/20] gpu: host1x: Refactor channel allocation code Dmitry Osipenko
2017-06-14 23:18   ` [PATCH v3 20/20] gpu: host1x: At first try a non-blocking allocation for the gather copy Dmitry Osipenko
2017-06-15 13:33   ` [PATCH v3 00/20] Tegra DRM fixes Thierry Reding

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=e17fe66ca24fc18b2f1207211f14564d0dc2cad3.1497480755.git.digetx@gmail.com \
    --to=digetx-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=cyndis-/1wQRMveznE@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=kusmabite-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).