dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Gmeiner <christian.gmeiner@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: linux+etnaviv@armlinux.org.uk, etnaviv@lists.freedesktop.org,
	cphealy@gmail.com
Subject: [PATCH V2 08/23] drm/etnaviv: copy pmrs from userspace
Date: Sat, 22 Jul 2017 11:53:08 +0200	[thread overview]
Message-ID: <20170722095323.9964-9-christian.gmeiner@gmail.com> (raw)
In-Reply-To: <20170722095323.9964-1-christian.gmeiner@gmail.com>

Changes from v1 -> v2:
- renamed submit_perfmon_request() to submit_perfmon_validate()
- extended flags validation
- added comment about offset 0
- moved assigment of cmdbuf->nr_pmrs below the copy_from_user of the pmrs.

Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com>
---
 drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 69 +++++++++++++++++++++++++++-
 1 file changed, 67 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
index 9c57b14dfcbf..91e35114d25c 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
@@ -21,6 +21,7 @@
 #include "etnaviv_drv.h"
 #include "etnaviv_gpu.h"
 #include "etnaviv_gem.h"
+#include "etnaviv_perfmon.h"
 
 /*
  * Cmdstream submission:
@@ -283,6 +284,54 @@ static int submit_reloc(struct etnaviv_gem_submit *submit, void *stream,
 	return 0;
 }
 
+static int submit_perfmon_validate(struct etnaviv_gem_submit *submit,
+		struct etnaviv_cmdbuf *cmdbuf,
+		const struct drm_etnaviv_gem_submit_pmr *pmrs,
+		u32 nr_pms)
+{
+	u32 i;
+
+	for (i = 0; i < nr_pms; i++) {
+		const struct drm_etnaviv_gem_submit_pmr *r = pmrs + i;
+		struct etnaviv_gem_submit_bo *bo;
+		int ret;
+
+		ret = submit_bo(submit, r->read_idx, &bo);
+		if (ret)
+			return ret;
+
+		/* at offset 0 a sequence number gets stored used for userspace sync */
+		if (r->read_offset == 0) {
+			DRM_ERROR("perfmon request: offset is 0");
+			return -EINVAL;
+		}
+
+		if (r->read_offset >= bo->obj->base.size - sizeof(u32)) {
+			DRM_ERROR("perfmon request: offset %u outside object", i);
+			return -EINVAL;
+		}
+
+		if (!(r->flags & (ETNA_PM_PROCESS_PRE | ETNA_PM_PROCESS_POST))) {
+			DRM_ERROR("perfmon request: flags are not valid");
+			return -EINVAL;
+		}
+
+		if (etnaviv_pm_req_validate(r)) {
+			DRM_ERROR("perfmon request: domain or signal not valid");
+			return -EINVAL;
+		}
+
+		cmdbuf->pmrs[i].flags = r->flags;
+		cmdbuf->pmrs[i].domain = r->domain;
+		cmdbuf->pmrs[i].signal = r->signal;
+		cmdbuf->pmrs[i].sequence = r->sequence;
+		cmdbuf->pmrs[i].offset = r->read_offset;
+		cmdbuf->pmrs[i].bo_vma = etnaviv_gem_vmap(&bo->obj->base);
+	}
+
+	return 0;
+}
+
 static void submit_cleanup(struct etnaviv_gem_submit *submit)
 {
 	unsigned i;
@@ -306,6 +355,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 	struct etnaviv_drm_private *priv = dev->dev_private;
 	struct drm_etnaviv_gem_submit *args = data;
 	struct drm_etnaviv_gem_submit_reloc *relocs;
+	struct drm_etnaviv_gem_submit_pmr *pmrs;
 	struct drm_etnaviv_gem_submit_bo *bos;
 	struct etnaviv_gem_submit *submit;
 	struct etnaviv_cmdbuf *cmdbuf;
@@ -347,11 +397,12 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 	 */
 	bos = kvmalloc_array(args->nr_bos, sizeof(*bos), GFP_KERNEL);
 	relocs = kvmalloc_array(args->nr_relocs, sizeof(*relocs), GFP_KERNEL);
+	pmrs = kvmalloc_array(args->nr_pmrs, sizeof(*pmrs), GFP_KERNEL);
 	stream = kvmalloc_array(1, args->stream_size, GFP_KERNEL);
 	cmdbuf = etnaviv_cmdbuf_new(gpu->cmdbuf_suballoc,
 				    ALIGN(args->stream_size, 8) + 8,
-				    args->nr_bos, 0);
-	if (!bos || !relocs || !stream || !cmdbuf) {
+				    args->nr_bos, args->nr_pmrs);
+	if (!bos || !relocs || !pmrs || !stream || !cmdbuf) {
 		ret = -ENOMEM;
 		goto err_submit_cmds;
 	}
@@ -373,6 +424,14 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 		goto err_submit_cmds;
 	}
 
+	ret = copy_from_user(pmrs, u64_to_user_ptr(args->pmrs),
+			     args->nr_pmrs * sizeof(*pmrs));
+	if (ret) {
+		ret = -EFAULT;
+		goto err_submit_cmds;
+	}
+	cmdbuf->nr_pmrs = args->nr_pmrs;
+
 	ret = copy_from_user(stream, u64_to_user_ptr(args->stream),
 			     args->stream_size);
 	if (ret) {
@@ -441,6 +500,10 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 	if (ret)
 		goto out;
 
+	ret = submit_perfmon_validate(submit, cmdbuf, pmrs, args->nr_pmrs);
+	if (ret)
+		goto out;
+
 	memcpy(cmdbuf->vaddr, stream, args->stream_size);
 	cmdbuf->user_size = ALIGN(args->stream_size, 8);
 
@@ -494,6 +557,8 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 		kvfree(bos);
 	if (relocs)
 		kvfree(relocs);
+	if (pmrs)
+		kvfree(pmrs);
 
 	return ret;
 }
-- 
2.13.3

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

  parent reply	other threads:[~2017-07-22  9:53 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-22  9:53 [PATCH V2 00/23] drm/etnaviv: support performance counters Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 01/23] drm/etnaviv: use bitmap to keep track of events Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 02/23] drm/etnaviv: make it possible to allocate multiple events Christian Gmeiner
2017-08-08 10:00   ` Lucas Stach
2017-08-22  8:27     ` Christian Gmeiner
2017-08-22  8:39       ` Lucas Stach
2017-08-22  8:55         ` Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 03/23] drm/etnaviv: add infrastructure to query perf counter Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 04/23] drm/etnaviv: add uapi for perfmon feature Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 05/23] drm/etnaviv: add internal representation of perfmon_request Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 06/23] drm/etnaviv: extend etnaviv_gpu_cmdbuf_new(..) with nr_pmrs Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 07/23] drm/etnaviv: add performance monitor request validation Christian Gmeiner
2017-07-22  9:53 ` Christian Gmeiner [this message]
2017-08-08 10:13   ` [PATCH V2 08/23] drm/etnaviv: copy pmrs from userspace Lucas Stach
2017-08-22  8:34     ` Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 09/23] drm/etnaviv: add performance monitor request processing Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 10/23] drm/etnaviv: add 'sync point' support Christian Gmeiner
2017-08-08 10:34   ` Lucas Stach
2017-08-22  9:58     ` Christian Gmeiner
2017-08-22 10:17       ` Lucas Stach
2017-07-22  9:53 ` [PATCH V2 11/23] drm/etnaviv: clear alloced event Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 12/23] drm/etnaviv: use 'sync points' for performance monitor requests Christian Gmeiner
2017-08-08 10:49   ` Lucas Stach
2017-08-22  8:39     ` Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 13/23] drm/etnaviv: add HI perf domain Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 14/23] drm/etnaviv: add PE " Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 15/23] drm/etnaviv: add SH " Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 16/23] drm/etnaviv: add PA " Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 17/23] drm/etnaviv: add SE " Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 18/23] drm/etnaviv: add RA " Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 19/23] drm/etnaviv: add TX " Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 20/23] drm/etnaviv: add MC " Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 21/23] drm/etnaviv: need to disable clock gating when doing profiling Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 22/23] drm/etnaviv: enable debug registers on demand Christian Gmeiner
2017-07-22  9:53 ` [PATCH V2 23/23] drm/etnaviv: submit supports performance monitor requests Christian Gmeiner

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=20170722095323.9964-9-christian.gmeiner@gmail.com \
    --to=christian.gmeiner@gmail.com \
    --cc=cphealy@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=etnaviv@lists.freedesktop.org \
    --cc=linux+etnaviv@armlinux.org.uk \
    /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