dri-devel.lists.freedesktop.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 11/20] gpu: host1x: Do not leak BO's phys address to userspace
Date: Thu, 15 Jun 2017 02:18:34 +0300	[thread overview]
Message-ID: <34ee97bf32788b5c6b7adbf961b42d65d757ddb4.1497480757.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>

Perform gathers coping before patching them, so that original gathers are
left untouched. That's not as bad as leaking kernel addresses, but still
doesn't feel right.

Signed-off-by: Dmitry Osipenko <digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Reviewed-by: Mikko Perttunen <mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 drivers/gpu/host1x/job.c | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c
index 14f3f957ffab..4208329ca2af 100644
--- a/drivers/gpu/host1x/job.c
+++ b/drivers/gpu/host1x/job.c
@@ -137,8 +137,9 @@ static void host1x_syncpt_patch_offset(struct host1x_syncpt *sp,
  * avoid a wrap condition in the HW).
  */
 static int do_waitchks(struct host1x_job *job, struct host1x *host,
-		       struct host1x_bo *patch)
+		       struct host1x_job_gather *g)
 {
+	struct host1x_bo *patch = g->bo;
 	int i;
 
 	/* compare syncpt vs wait threshold */
@@ -165,7 +166,8 @@ static int do_waitchks(struct host1x_job *job, struct host1x *host,
 				wait->syncpt_id, sp->name, wait->thresh,
 				host1x_syncpt_read_min(sp));
 
-			host1x_syncpt_patch_offset(sp, patch, wait->offset);
+			host1x_syncpt_patch_offset(sp, patch,
+						   g->offset + wait->offset);
 		}
 
 		wait->bo = NULL;
@@ -269,11 +271,12 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
 	return err;
 }
 
-static int do_relocs(struct host1x_job *job, struct host1x_bo *cmdbuf)
+static int do_relocs(struct host1x_job *job, struct host1x_job_gather *g)
 {
 	int i = 0;
 	u32 last_page = ~0;
 	void *cmdbuf_page_addr = NULL;
+	struct host1x_bo *cmdbuf = g->bo;
 
 	/* pin & patch the relocs for one gather */
 	for (i = 0; i < job->num_relocs; i++) {
@@ -286,6 +289,13 @@ static int do_relocs(struct host1x_job *job, struct host1x_bo *cmdbuf)
 		if (cmdbuf != reloc->cmdbuf.bo)
 			continue;
 
+		if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL)) {
+			target = (u32 *)job->gather_copy_mapped +
+					reloc->cmdbuf.offset / sizeof(u32) +
+						g->offset / sizeof(u32);
+			goto patch_reloc;
+		}
+
 		if (last_page != reloc->cmdbuf.offset >> PAGE_SHIFT) {
 			if (cmdbuf_page_addr)
 				host1x_bo_kunmap(cmdbuf, last_page,
@@ -302,6 +312,7 @@ static int do_relocs(struct host1x_job *job, struct host1x_bo *cmdbuf)
 		}
 
 		target = cmdbuf_page_addr + (reloc->cmdbuf.offset & ~PAGE_MASK);
+patch_reloc:
 		*target = reloc_addr;
 	}
 
@@ -573,6 +584,12 @@ int host1x_job_pin(struct host1x_job *job, struct device *dev)
 	if (err)
 		goto out;
 
+	if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL)) {
+		err = copy_gathers(job, dev);
+		if (err)
+			goto out;
+	}
+
 	/* patch gathers */
 	for (i = 0; i < job->num_gathers; i++) {
 		struct host1x_job_gather *g = &job->gathers[i];
@@ -581,7 +598,9 @@ int host1x_job_pin(struct host1x_job *job, struct device *dev)
 		if (g->handled)
 			continue;
 
-		g->base = job->gather_addr_phys[i];
+		/* copy_gathers() sets gathers base if firewall is enabled */
+		if (!IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL))
+			g->base = job->gather_addr_phys[i];
 
 		for (j = i + 1; j < job->num_gathers; j++) {
 			if (job->gathers[j].bo == g->bo) {
@@ -590,19 +609,15 @@ int host1x_job_pin(struct host1x_job *job, struct device *dev)
 			}
 		}
 
-		err = do_relocs(job, g->bo);
+		err = do_relocs(job, g);
 		if (err)
-			goto out;
+			break;
 
-		err = do_waitchks(job, host, g->bo);
+		err = do_waitchks(job, host, g);
 		if (err)
-			goto out;
+			break;
 	}
 
-	if (!IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL))
-		goto out;
-
-	err = copy_gathers(job, dev);
 out:
 	if (err)
 		host1x_job_unpin(job);
-- 
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   ` [PATCH v3 04/20] drm/tegra: Correct copying of waitchecks and disable them " Dmitry Osipenko
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   ` Dmitry Osipenko [this message]
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=34ee97bf32788b5c6b7adbf961b42d65d757ddb4.1497480757.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).