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 v2 13/22] gpu: host1x: Do not leak BO's phys address to userspace
Date: Wed, 14 Jun 2017 02:15:52 +0300	[thread overview]
Message-ID: <6409d5e32a30d9e30e402f4638c0d41a233602e2.1497394243.git.digetx@gmail.com> (raw)
In-Reply-To: <cover.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
In-Reply-To: <cover.1497394243.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-13 23:15 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-13 23:15 [PATCH v2 00/22] Tegra DRM fixes Dmitry Osipenko
     [not found] ` <cover.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-13 23:15   ` [PATCH v2 01/22] drm/tegra: Fix lockup on a use of staging API Dmitry Osipenko
     [not found]     ` <d2616b82a1728d0953e84489cde40364999719f0.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14  7:09       ` Erik Faye-Lund
2017-06-13 23:15   ` [PATCH v2 02/22] drm/tegra: Correct idr_alloc() minimum id Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 03/22] drm/tegra: Check for malformed offsets and sizes in the 'submit' IOCTL Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 04/22] drm/tegra: Correct copying of waitchecks and disable them " Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 05/22] drm/tegra: Check syncpoint ID " Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 06/22] drm/tegra: dc: Avoid reset asserts on Tegra20 Dmitry Osipenko
     [not found]     ` <1c7b0c7bf713401073d648f9f228fa152c094a5a.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14  7:13       ` Erik Faye-Lund
2017-06-13 23:15   ` [PATCH v2 07/22] drm/tegra: dc: Apply clipping to the plane Dmitry Osipenko
     [not found]     ` <7adbe0c6e67115fa4fd201026533b7cb97fc44d2.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14  7:20       ` Erik Faye-Lund
2017-06-13 23:15   ` [PATCH v2 08/22] drm/tegra: dc: Disable plane if it is invisible Dmitry Osipenko
2017-06-14  7:21     ` Erik Faye-Lund
2017-06-13 23:15   ` [PATCH v2 09/22] drm/tegra: Don't use IOMMU on Tegra20 Dmitry Osipenko
     [not found]     ` <d707bd34e268f9d8fb29bf510a9f17e5f943a635.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14  7:39       ` Erik Faye-Lund
     [not found]         ` <CABPQNSbMQMrahcvWnczywLDYVU0=Ns=FB6Yseisk-5L_8Y=rpQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-06-14 10:22           ` Dmitry Osipenko
     [not found]             ` <16be88ba-808d-4d3e-533b-7dce4a2765e7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14 22:24               ` Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 10/22] Revert "iommu/tegra: gart: Do not register with bus" Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 11/22] gpu: host1x: Initialize firewall class to the jobs one Dmitry Osipenko
     [not found]     ` <8c0a2417584ce51b716f2c286027bcb18fceda56.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14  7:41       ` Erik Faye-Lund
2017-06-13 23:15   ` [PATCH v2 12/22] gpu: host1x: Correct host1x_job_pin() error handling Dmitry Osipenko
2017-06-13 23:15   ` Dmitry Osipenko [this message]
2017-06-13 23:15   ` [PATCH v2 14/22] gpu: host1x: Forbid relocation address shifting in the firewall Dmitry Osipenko
     [not found]     ` <5e6f06d3e57db40c1c4947282ef7336369c3360f.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14  6:50       ` Mikko Perttunen
     [not found]         ` <6db57dae-0de7-45a5-2ed5-1ebd84577742-/1wQRMveznE@public.gmane.org>
2017-06-14  9:06           ` Dmitry Osipenko
     [not found]             ` <3d723511-45f2-3c80-58fe-c9050624ac94-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14 11:47               ` Mikko Perttunen
     [not found]                 ` <bc4d8ea3-0fd7-85ad-be08-bc869d0e89a6-/1wQRMveznE@public.gmane.org>
2017-06-14 14:49                   ` Dmitry Osipenko
     [not found]                     ` <a18ec3c6-0fa1-4daa-3db4-c81124424cec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14 14:59                       ` Mikko Perttunen
2017-06-13 23:15   ` [PATCH v2 15/22] gpu: host1x: Forbid RESTART opcode " Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 16/22] gpu: host1x: Forbid unrelated SETCLASS " Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 17/22] gpu: host1x: Correct swapped arguments in the is_addr_reg() definition Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 18/22] gpu: host1x: Check waits in the firewall Dmitry Osipenko
     [not found]     ` <bd57829e74c6554c46ab761d013e6d9d3c39b693.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14  7:47       ` Erik Faye-Lund
2017-06-13 23:15   ` [PATCH v2 19/22] gpu: host1x: Remove unused 'struct host1x_cmdbuf' Dmitry Osipenko
2017-06-13 23:15   ` [PATCH v2 20/22] gpu: host1x: Remove unused host1x_cdma_stop() definition Dmitry Osipenko
2017-06-13 23:16   ` [PATCH v2 21/22] gpu: host1x: Refactor channel allocation code Dmitry Osipenko
2017-06-13 23:16   ` [PATCH v2 22/22] gpu: host1x: At first try a non-blocking allocation for the gather copy Dmitry Osipenko
     [not found]     ` <036615566011ab4d52190439a12d943df9e704ef.1497394243.git.digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-14  7:56       ` Erik Faye-Lund
     [not found]         ` <CABPQNSZ8f8QqW4fJYCGfgf3q0pTyQ7NbS_=64x39kvrNDSyhdw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-06-14  8:32           ` Dmitry Osipenko
2017-06-14  8:44             ` Erik Faye-Lund

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=6409d5e32a30d9e30e402f4638c0d41a233602e2.1497394243.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).