Skip to contentSkip to conversation

drm: Add decoding for DRM/KMS and i915 ioctls

PATCH In review Patrik Jakobsson 8 participants 30 messages Aug 24, 2015 – Jul 20, 2016 4 messages not in the archive Kbuild

lore
Share & tools
lore
#0 lore raw

v4 cover drm: Add decoding for DRM/KMS and i915 ioctls

This set of patches adds a dispatcher for handling DRM ioctls. The kernel headers for DRM might not be available on all distributions so we depend on libdrm for those. If libdrm is not available we fall back on the kernel headers. Since DRM drivers share the same range of private ioctl numbers I've added a function for detecting the driver based on it's name.

Changes in v2:
* Rebased to master
* Added Changelog to commits
* Keep strace_SOURCES list sorted
* Removed unneeded includes
* Reduced number of driver name checks by adding tcb private data
* Use tprints() for regular strings
* Reworked entering() / exiting() handling for all ioctls
* Use printstr() to print strings in properly quoted form

Changes in v3:
* Moved all umove() into state checks for single state ioctls
* Removed extra curly bracket
* Moved param argument into entering() state in i915_setparam()
* Don't return before private data is freed in drm_ioctl()

Changes in v4:
* Rebased to master
* Rewrote commit messages to GNU changelog standard
* Added private data support to struct tcb
* Reworked drm driver identification
* Reworked drm header detection
* Use recently added return types for decode functions
* Various small fixes

Patrik Jakobsson (5):
drm: Add config for detecting libdrm
drm: Add private data field to trace control block
drm: Add dispatcher and driver identification for DRM
drm: Add decoding of i915 ioctls
drm: Add decoding of DRM and KMS ioctls

 Makefile.am                |   2 +
 configure.ac               |   5 +
 defs.h                     |  11 +
 drm.c                      | 663 +++++++++++++++++++++++++++++++++++++++++++++
 drm_i915.c                 | 342 +++++++++++++++++++++++
 ioctl.c                    |   4 +
 strace.c                   |  14 +
 syscall.c                  |   1 +
 xlat/drm_i915_getparams.in |  28 ++
 xlat/drm_i915_ioctls.in    |  51 ++++
 xlat/drm_i915_setparams.in |   4 +
 11 files changed, 1125 insertions(+)
 create mode 100644 drm.c
 create mode 100644 drm_i915.c
 create mode 100644 xlat/drm_i915_getparams.in
 create mode 100644 xlat/drm_i915_ioctls.in
 create mode 100644 xlat/drm_i915_setparams.in
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH v4 1/5 drm: Add config for detecting libdrm

Use pkg-config to try to find libdrm headers. If that fails look for the kernel headers. If no headers are found, drm support will not be compiled.

* configure.ac: Use pkg-config to find libdrm

---
 configure.ac | 5 +++++
 1 file changed, 5 insertions(+)
configure.ac +5 -0
index 0819f83..ef43278 100644
@@ -870,6 +870,11 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
+PKG_CHECK_MODULES([LIBDRM], [libdrm],
+		  [CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"
+		   AC_CHECK_HEADERS([drm.h i915_drm.h])],
+		  [AC_CHECK_HEADERS([drm/drm.h drm/i915_drm.h])])
+
 if test "$arch" = mips && test "$no_create" != yes; then
 	mkdir -p linux/mips
 	if $srcdir/linux/mips/genstub.sh linux/mips; then
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [PATCH v4 1/5] drm: Add config for detecting libdrm

configure.ac fi · line 876

Quoted 4 lines · Patrik Jakobsson
configure.ac +4 -0
+PKG_CHECK_MODULES([LIBDRM], [libdrm],
+		  [CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"
+		   AC_CHECK_HEADERS([drm.h i915_drm.h])],
+		  [AC_CHECK_HEADERS([drm/drm.h drm/i915_drm.h])])

i would make the drm/xxx headers unconditional -- add them to the big block that does:
AC_CHECK_HEADERS(m4_normalize([

	...

]))

otherwise seems fine
-mike

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw

PATCH v4 2/5 drm: Add private data field to trace control block

In reply to Patrik Jakobsson

We need to be able to store private data in the tcb across it's lifetime. To ensure proper destruction of the data a free_priv_data callback must be provided if an allocation is stored in priv_data. The callback is executed automatically when the life of the tcb ends.

* defs.h: Add extern declaration of free_tcb_priv_data. (struct tcb): Add priv_data and free_priv_data.
* strace.c (free_tcb_priv_data): New function
(drop_tcb): Execute free_tcb_priv_data callback
* syscall.c (trace_syscall_exiting): Execute free_tcb_priv_data callback

---
 defs.h    |  6 ++++++
 strace.c  | 14 ++++++++++++++
 syscall.c |  1 +
 3 files changed, 21 insertions(+)
defs.h +6 -0
index 9059026..bc3bd83 100644
@@ -266,6 +266,10 @@ struct tcb {
 	int u_error;		/* Error code */
 	long scno;		/* System call number */
 	long u_arg[MAX_ARGS];	/* System call arguments */
+
+	void *priv_data;	/* Private data for syscall decoding functions */
+	void (*free_priv_data)(void *); /* Callback for freeing priv_data */
+
 #if defined(LINUX_MIPSN32) || defined(X32)
 	long long ext_arg[MAX_ARGS];
 	long long u_lrval;	/* long long return value */
@@ -470,6 +474,8 @@ extern void get_regs(pid_t pid);
 extern int get_scno(struct tcb *tcp);
 extern const char *syscall_name(long scno);
 
+extern void free_tcb_priv_data(struct tcb *tcp);
+
 extern int umoven(struct tcb *, long, unsigned int, void *);
 #define umove(pid, addr, objp)	\
 	umoven((pid), (addr), sizeof(*(objp)), (void *) (objp))
strace.c +14 -0
index 9b93e79..7a71152 100644
@@ -711,12 +711,26 @@ alloctcb(int pid)
 	error_msg_and_die("bug in alloctcb");
 }
 
+void
+free_tcb_priv_data(struct tcb *tcp)
+{
+	if (tcp->priv_data) {
+		if (tcp->free_priv_data) {
+			tcp->free_priv_data(tcp->priv_data);
+			tcp->free_priv_data = NULL;
+		}
+		tcp->priv_data = NULL;
+	}
+}
+
 static void
 droptcb(struct tcb *tcp)
 {
 	if (tcp->pid == 0)
 		return;
 
+	free_tcb_priv_data(tcp);
+
 #ifdef USE_LIBUNWIND
 	if (stack_trace_enabled) {
 		unwind_tcb_fin(tcp);
syscall.c +1 -0
index 396a7dd..39b973b 100644
@@ -1099,6 +1099,7 @@ trace_syscall_exiting(struct tcb *tcp)
 #endif
 
  ret:
+	free_tcb_priv_data(tcp);
 	tcp->flags &= ~TCB_INSYSCALL;
 	tcp->sys_func_rval = 0;
 	return 0;
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

A message that is not in the archive (sent off-list or not yet received): 1440420170-13337-3-git-send-email-patrik.jakobsson-VuQAYsv1563Yd54FQh9/[email protected]

#5 lore raw

Re: [PATCH v4 2/5] drm: Add private data field to trace control block

Quoted 23 lines · Patrik Jakobsson

We need to be able to store private data in the tcb across it's lifetime. To ensure proper destruction of the data a free_priv_data callback must be provided if an allocation is stored in priv_data. The callback is executed automatically when the life of the tcb ends.

* defs.h: Add extern declaration of free_tcb_priv_data. (struct tcb): Add priv_data and free_priv_data.
* strace.c (free_tcb_priv_data): New function
(drop_tcb): Execute free_tcb_priv_data callback
* syscall.c (trace_syscall_exiting): Execute free_tcb_priv_data callback

---
 defs.h    |  6 ++++++
 strace.c  | 14 ++++++++++++++
 syscall.c |  1 +
 3 files changed, 21 insertions(+)
defs.h +0 -0
index 9059026..bc3bd83 100644

defs.h struct tcb { · line 271

Quoted 6 lines
defs.h +3 -0
@@ -266,6 +266,10 @@ struct tcb {
 	int u_error;		/* Error code */
 	long scno;		/* System call number */
 	long u_arg[MAX_ARGS];	/* System call arguments */
+
+	void *priv_data;	/* Private data for syscall decoding functions */
+	void (*free_priv_data)(void *); /* Callback for freeing priv_data */

should we name these _priv_data and _free_priv_data and provides accessor functions ? i worry that code paths might stomp on each other by accident and we don't end up noticing.

static void set_tcb_priv_data(struct tcb *tcp, void *data, void (*free_data)(void *))

{
	assert(tcp->_priv_data == NULL && tcp->_free_priv_data == NULL);
	...
}

-mike

------------------------------------------------------------------------------

_______________________________________________
Strace-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

#6 lore raw

Re: [PATCH v4 2/5] drm: Add private data field to trace control block

Quoted 35 lines · Mike Frysinger
Quoted 23 lines · Patrik Jakobsson

We need to be able to store private data in the tcb across it's lifetime. To ensure proper destruction of the data a free_priv_data callback must be provided if an allocation is stored in priv_data. The callback is executed automatically when the life of the tcb ends.

* defs.h: Add extern declaration of free_tcb_priv_data. (struct tcb): Add priv_data and free_priv_data.
* strace.c (free_tcb_priv_data): New function
(drop_tcb): Execute free_tcb_priv_data callback
* syscall.c (trace_syscall_exiting): Execute free_tcb_priv_data callback

---
 defs.h    |  6 ++++++
 strace.c  | 14 ++++++++++++++
 syscall.c |  1 +
 3 files changed, 21 insertions(+)
defs.h +0 -0
index 9059026..bc3bd83 100644

defs.h struct tcb { · line 271

Quoted 6 lines
defs.h +3 -0
@@ -266,6 +266,10 @@ struct tcb {
      int u_error;            /* Error code */
      long scno;              /* System call number */
      long u_arg[MAX_ARGS];   /* System call arguments */
+
+     void *priv_data;        /* Private data for syscall decoding functions */
+     void (*free_priv_data)(void *); /* Callback for freeing priv_data */

should we name these _priv_data and _free_priv_data and provides accessor functions ? i worry that code paths might stomp on each other by accident and we don't end up noticing.

Quoted 6 lines

static void set_tcb_priv_data(struct tcb *tcp, void *data, void (*free_data)(void *))

{
        assert(tcp->_priv_data == NULL && tcp->_free_priv_data == NULL);
        ...
}

-mike

Yes, that's a good idea. My use case is pretty simple but usage can easliy grow.

I'll resend this patch and take it out of the drm/i915 series.

-Patrik
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

Re: [PATCH v4 2/5] drm: Add private data field to trace control block

Quoted 43 lines · Patrik Jakobsson
Quoted 35 lines · Mike Frysinger
Quoted 23 lines · Patrik Jakobsson

We need to be able to store private data in the tcb across it's lifetime. To ensure proper destruction of the data a free_priv_data callback must be provided if an allocation is stored in priv_data. The callback is executed automatically when the life of the tcb ends.

* defs.h: Add extern declaration of free_tcb_priv_data. (struct tcb): Add priv_data and free_priv_data.
* strace.c (free_tcb_priv_data): New function
(drop_tcb): Execute free_tcb_priv_data callback
* syscall.c (trace_syscall_exiting): Execute free_tcb_priv_data callback

---
 defs.h    |  6 ++++++
 strace.c  | 14 ++++++++++++++
 syscall.c |  1 +
 3 files changed, 21 insertions(+)
defs.h +0 -0
index 9059026..bc3bd83 100644

defs.h struct tcb { · line 271

Quoted 6 lines
defs.h +3 -0
@@ -266,6 +266,10 @@ struct tcb {
      int u_error;            /* Error code */
      long scno;              /* System call number */
      long u_arg[MAX_ARGS];   /* System call arguments */
+
+     void *priv_data;        /* Private data for syscall decoding functions */
+     void (*free_priv_data)(void *); /* Callback for freeing priv_data */

should we name these _priv_data and _free_priv_data and provides accessor functions ? i worry that code paths might stomp on each other by accident and we don't end up noticing.

Quoted 6 lines

static void set_tcb_priv_data(struct tcb *tcp, void *data, void (*free_data)(void *))

{
        assert(tcp->_priv_data == NULL && tcp->_free_priv_data == NULL);
        ...
}

-mike

Quoted 5 lines

Yes, that's a good idea. My use case is pretty simple but usage can easliy grow.

I'll resend this patch and take it out of the drm/i915 series.

-Patrik

Here's my take on it (I assume it needs some discussion):

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data)

{
	/* A free callback is required before setting private data and private
	 * data must be set back to NULL before being set again.
	 */
	if (tcp->_free_priv_data == NULL ||
	    (tcp->_priv_data && priv_data != NULL))
		return -1;

	tcp->_priv_data = priv_data;
	return 0;
}

void *
get_tcb_priv_data(struct tcb *tcp)

{
	return tcp->_priv_data;
}

int
set_tcb_free_priv_data(struct tcb *tcp, void (*free_priv_data)(void *)) {
/* _free_priv_data must be set back to NULL before being set again. */

	if (tcp->_free_priv_data && free_priv_data != NULL)
		return -1;

	tcp->_free_priv_data = free_priv_data;
	return 0;
}

void
free_tcb_priv_data(struct tcb *tcp)

{
	if (tcp->_priv_data) {
		if (tcp->_free_priv_data) {
			tcp->_free_priv_data(tcp->_priv_data);
			tcp->_free_priv_data = NULL;
		}
		tcp->_priv_data = NULL;
	}
}

Cheers
Patrik
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

A message that is not in the archive (sent off-list or not yet received): 20150831123707.GA22376-mbq0NjRWzOqzCX88HRwER2kA0OJWJZs2VpNB7YpNyf8@public.gmane.org

#9 lore raw

Re: [Intel-gfx] [PATCH v4 2/5] drm: Add private data field to trace control block

On Mon, Aug 31, 2015 at 02:37:07PM +0200, Patrik Jakobsson wrote:
[...]

Quoted 8 lines

Here's my take on it (I assume it needs some discussion):

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data)

{
	/* A free callback is required before setting private data and private
	 * data must be set back to NULL before being set again.
	 */

I think a single function initializing both _priv_data and _free_priv_data would suffice:

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data,

		  void (*free_priv_data)(void *))
{
	if (tcp->_priv_data)
		return -1;

	tcp->_free_priv_data = free_priv_data;
	tcp->_priv_data = priv_data;

	return 0;
}
Signature · 1 line
ldv

------------------------------------------------------------------------------

_______________________________________________
Strace-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

#10 lore raw

Re: [PATCH v4 2/5] drm: Add private data field to trace control block

Quoted 16 lines · Dmitry V. Levin

On Mon, Aug 31, 2015 at 02:37:07PM +0200, Patrik Jakobsson wrote:
[...]

Quoted 8 lines

Here's my take on it (I assume it needs some discussion):

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data)

{
      /* A free callback is required before setting private data and private
       * data must be set back to NULL before being set again.
       */

I think a single function initializing both _priv_data and _free_priv_data would suffice:

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data,

Quoted 10 lines
                  void (*free_priv_data)(void *))
{
        if (tcp->_priv_data)
                return -1;

        tcp->_free_priv_data = free_priv_data;
        tcp->_priv_data = priv_data;

        return 0;
}

Sure, and since they always come in a pairs it might be even better. If it turns out we need it split up it is easily done later.

Thanks
Patrik
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

A message that is not in the archive (sent off-list or not yet received): CAMeQTsZWUPtGUkfVdvhu4bzjQOQ-WvqQ=xOQJzNOw+kOZLGExw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#12 lore raw

Re: [Intel-gfx] [PATCH v4 2/5] drm: Add private data field to trace control block

Quoted 22 lines · Patrik Jakobsson
Quoted 21 lines · Dmitry V. Levin

On Mon, Aug 31, 2015 at 02:37:07PM +0200, Patrik Jakobsson wrote:
[...]

Quoted 8 lines

Here's my take on it (I assume it needs some discussion):

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data)

{
      /* A free callback is required before setting private data and private
       * data must be set back to NULL before being set again.
       */

I think a single function initializing both _priv_data and _free_priv_data would suffice:

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data,

                  void (*free_priv_data)(void *))
{
        if (tcp->_priv_data)
                return -1;
Quoted 8 lines
Quoted 5 lines
        tcp->_free_priv_data = free_priv_data;
        tcp->_priv_data = priv_data;

        return 0;
}

Sure, and since they always come in a pairs it might be even better. If it turns out we need it split up it is easily done later.

The discussion seems to be stalled.
Patrik, would you like to prepare a patch?

Signature · 1 line
ldv

------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK. Use one codebase in this all-in-one HTML5 development environment. Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741551&iu=/4140

_______________________________________________
Strace-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

#13 lore raw

Re: [PATCH v4 2/5] drm: Add private data field to trace control block

Quoted 26 lines · Dmitry V. Levin
Quoted 25 lines · Patrik Jakobsson
Quoted 24 lines · Dmitry V. Levin

On Mon, Aug 31, 2015 at 02:37:07PM +0200, Patrik Jakobsson wrote:
[...]

Quoted 8 lines

Here's my take on it (I assume it needs some discussion):

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data)

{
      /* A free callback is required before setting private data and private
       * data must be set back to NULL before being set again.
       */

I think a single function initializing both _priv_data and _free_priv_data would suffice:

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data,

                  void (*free_priv_data)(void *))
{
        if (tcp->_priv_data)
                return -1;

        tcp->_free_priv_data = free_priv_data;
        tcp->_priv_data = priv_data;
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
        return 0;
}

Sure, and since they always come in a pairs it might be even better. If it turns out we need it split up it is easily done later.

The discussion seems to be stalled.
Patrik, would you like to prepare a patch?

Hi Dmitry

I'll send you new patches this weekend. Thanks for reminding me.

-Patrik

Quoted 4 lines

--
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#14 lore raw

Re: [Intel-gfx] [PATCH v4 2/5] drm: Add private data field to trace control block

In reply to a message not in the archive
Quoted 22 lines · Patrik Jakobsson
Quoted 21 lines · Dmitry V. Levin

On Mon, Aug 31, 2015 at 02:37:07PM +0200, Patrik Jakobsson wrote:
[...]

Quoted 8 lines

Here's my take on it (I assume it needs some discussion):

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data)

{
      /* A free callback is required before setting private data and private
       * data must be set back to NULL before being set again.
       */

I think a single function initializing both _priv_data and _free_priv_data would suffice:

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data,

                  void (*free_priv_data)(void *))
{
        if (tcp->_priv_data)
                return -1;
Quoted 8 lines
Quoted 5 lines
        tcp->_free_priv_data = free_priv_data;
        tcp->_priv_data = priv_data;

        return 0;
}

Sure, and since they always come in a pairs it might be even better. If it turns out we need it split up it is easily done later.

JFYI, I've finalized and merged this set_tcb_priv_data interface.

Signature · 1 line
ldv

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports.http://sdm.link/zohodev2dev

_______________________________________________
Strace-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

#15 lore raw

Re: [PATCH v4 2/5] drm: Add private data field to trace control block

Quoted 11 lines · Dmitry V. Levin
Quoted 9 lines · Patrik Jakobsson
Quoted 8 lines · Dmitry V. Levin

On Mon, Aug 31, 2015 at 02:37:07PM +0200, Patrik Jakobsson wrote:
[...]

Quoted 6 lines

Here's my take on it (I assume it needs some discussion):

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data)

{
      /* A free callback is required before setting private data and

private

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

* data must be set back to NULL before being set again. */

I think a single function initializing both _priv_data and

_free_priv_data

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

would suffice:

int
set_tcb_priv_data(struct tcb *tcp, void *priv_data,

                  void (*free_priv_data)(void *))
{
        if (tcp->_priv_data)
                return -1;
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
        tcp->_free_priv_data = free_priv_data;
        tcp->_priv_data = priv_data;

        return 0;
}

Sure, and since they always come in a pairs it might be even better. If

it turns

Quoted 3 lines
Quoted 1 line

out we need it split up it is easily done later.

JFYI, I've finalized and merged this set_tcb_priv_data interface.

Thanks Dmitry

-Patrik

Quoted 4 lines

--
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#16 lore raw

PATCH v4 3/5 drm: Add dispatcher and driver identification for DRM

In reply to Patrik Jakobsson

* Makefile.am: Add compilation of drm.c.
* defs.h: Add extern declaration of drm_ioctl when drm headers are found.
* drm.c: New file.
* ioctl.c (ioctl_decode): Dispatch drm ioctls when drm headers are found.

---
 Makefile.am |   1 +
 defs.h      |   3 ++
 drm.c       | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ioctl.c     |   4 +++
 4 files changed, 115 insertions(+)
 create mode 100644 drm.c
Makefile.am +1 -0
index f70f6d2..c7c6080 100644
@@ -42,6 +42,7 @@ strace_SOURCES =	\
 	count.c		\
 	desc.c		\
 	dirent.c	\
+	drm.c		\
 	epoll.c		\
 	evdev.c		\
 	eventfd.c	\
defs.h +3 -0
index bc3bd83..dd3c720 100644
@@ -612,6 +612,9 @@ extern const char *sprint_open_modes(int);
 extern void print_seccomp_filter(struct tcb *tcp, unsigned long);
 
 extern int block_ioctl(struct tcb *, const unsigned int, long);
+#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H)
+extern int drm_ioctl(struct tcb *, const unsigned int, long);
+#endif
 extern int evdev_ioctl(struct tcb *, const unsigned int, long);
 extern int loop_ioctl(struct tcb *, const unsigned int, long);
 extern int mtd_ioctl(struct tcb *, const unsigned int, long);
drm.c new file +107 -0

107 lines not on this page · raw message

ioctl.c +4 -0
index 284828a..dfd35d8 100644
@@ -248,6 +248,10 @@ ioctl_decode(struct tcb *tcp)
 	case 0x22:
 		return scsi_ioctl(tcp, code, arg);
 #endif
+#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H)
+	case 'd':
+		return drm_ioctl(tcp, code, arg);
+#endif
 	case 'L':
 		return loop_ioctl(tcp, code, arg);
 	case 'M':
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#17 lore raw

Re: [PATCH v4 3/5] drm: Add dispatcher and driver identification for DRM

Quoted 4 lines · Patrik Jakobsson

* Makefile.am: Add compilation of drm.c.
* defs.h: Add extern declaration of drm_ioctl when drm headers are found.
* drm.c: New file.
* ioctl.c (ioctl_decode): Dispatch drm ioctls when drm headers are found.

* defs.h (drm_decode_number, drm_ioctl): New prototypes.
* drm.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* ioctl.c (ioctl_decode_command_number, ioctl_decode) [HAVE_DRM_H || HAVE_DRM_DRM_H]: Dispatch drm ioctls.

defs.h extern const char *sprint_open_modes(int); · line 617

Quoted 9 lines
defs.h +3 -0
@@ -612,6 +612,9 @@ extern const char *sprint_open_modes(int);
 extern void print_seccomp_filter(struct tcb *tcp, unsigned long);
 
 extern int block_ioctl(struct tcb *, const unsigned int, long);
+#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H)
+extern int drm_ioctl(struct tcb *, const unsigned int, long);
+#endif

I think function these prototypes could be added unconditionally. Note that v3 version of this patch also declared drm_decode_number().

Quoted 2 lines
drm.c new file +0 -0

[...]

drm.c line 41

Quoted 11 lines
drm.c new file +11 -0
+#include "defs.h"
+
+#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H)
+
+#ifdef HAVE_DRM_H
+#include <drm.h>
+#else
+#include <drm/drm.h>
+#endif
+
+#include <sys/param.h>

Let's include <sys/param.h> before drm stuff.

drm.c line 49

Quoted 7 lines
drm.c new file +7 -0
+#define DRM_MAX_NAME_LEN 128
+
+inline int drm_is_priv(const unsigned int num)
+{
+	return (_IOC_NR(num) >= DRM_COMMAND_BASE &&
+		_IOC_NR(num) < DRM_COMMAND_END);
+}

This function has to be static, and like other static functions, it has to be added along with its first user, otherwise the project won't build with --enable-gcc-Werror.

drm.c line 61

Quoted 11 lines
drm.c new file +11 -0
+static char *drm_get_driver_name(struct tcb *tcp)
+{
+	char path[PATH_MAX];
+	char link[PATH_MAX];
+	int ret;
+
+	if (getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1) < 0)
+		return NULL;
+
+	snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver",
+		 basename(path));

if (snprintf(link, sizeof(link), ...) >= sizeof(link))

	return NULL;

drm.c line 74

Quoted 4 lines
drm.c new file +4 -0
+static void drm_free_priv(void *data)
+{
+	free(data);
+}

Do we really need a wrapper for free(3)?

ioctl.c ioctl_decode(struct tcb *tcp) · line 257

Quoted 13 lines
ioctl.c +4 -0
@@ -248,6 +248,10 @@ ioctl_decode(struct tcb *tcp)
 	case 0x22:
 		return scsi_ioctl(tcp, code, arg);
 #endif
+#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H)
+	case 'd':
+		return drm_ioctl(tcp, code, arg);
+#endif
 	case 'L':
 		return loop_ioctl(tcp, code, arg);
 	case 'M':

v3 version also patched ioctl_decode_command_number() to call drm_decode_number().

Signature · 1 line
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#18 lore raw

Re: [PATCH v4 3/5] drm: Add dispatcher and driver identification for DRM

Quoted 11 lines · Dmitry V. Levin
Quoted 4 lines · Patrik Jakobsson

* Makefile.am: Add compilation of drm.c.
* defs.h: Add extern declaration of drm_ioctl when drm headers are found.
* drm.c: New file.
* ioctl.c (ioctl_decode): Dispatch drm ioctls when drm headers are found.

* defs.h (drm_decode_number, drm_ioctl): New prototypes.
* drm.c: New file.
* Makefile.am (strace_SOURCES): Add it.
* ioctl.c (ioctl_decode_command_number, ioctl_decode) [HAVE_DRM_H || HAVE_DRM_DRM_H]: Dispatch drm ioctls.

Ugh, thought I had this correct already. Will fix.

Quoted 5 lines
Quoted 5 lines
defs.h +0 -0
@@ -612,6 +612,9 @@ extern const char *sprint_open_modes(int);
 extern void print_seccomp_filter(struct tcb *tcp, unsigned long);
 
Quoted 7 lines

defs.h extern const char *sprint_open_modes(int); · line 617

Quoted 4 lines
defs.h +3 -0
 extern int block_ioctl(struct tcb *, const unsigned int, long);
+#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H)
+extern int drm_ioctl(struct tcb *, const unsigned int, long);
+#endif

I think function these prototypes could be added unconditionally. Note that v3 version of this patch also declared drm_decode_number().

Ok. Will move the number decoding pieces back into this patch. Not sure why I did this in the first place.

Quoted 16 lines
Quoted 2 lines
drm.c new file +0 -0

[...]

drm.c line 41

Quoted 11 lines
drm.c new file +11 -0
+#include "defs.h"
+
+#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H)
+
+#ifdef HAVE_DRM_H
+#include <drm.h>
+#else
+#include <drm/drm.h>
+#endif
+
+#include <sys/param.h>

Let's include <sys/param.h> before drm stuff.

Ok

Quoted 11 lines

drm.c line 49

Quoted 7 lines
drm.c new file +7 -0
+#define DRM_MAX_NAME_LEN 128
+
+inline int drm_is_priv(const unsigned int num)
+{
+	return (_IOC_NR(num) >= DRM_COMMAND_BASE &&
+		_IOC_NR(num) < DRM_COMMAND_END);
+}

This function has to be static, and like other static functions, it has to be added along with its first user, otherwise the project won't build with --enable-gcc-Werror.

Will move it to the correct patch and make it static.

Quoted 13 lines

drm.c line 61

Quoted 11 lines
drm.c new file +11 -0
+static char *drm_get_driver_name(struct tcb *tcp)
+{
+	char path[PATH_MAX];
+	char link[PATH_MAX];
+	int ret;
+
+	if (getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1) < 0)
+		return NULL;
+
+	snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver",
+		 basename(path));

if (snprintf(link, sizeof(link), ...) >= sizeof(link))

Quoted 2 lines
	return NULL;

According to manpage snprintf never returns more than the specified size - 1. So the only error we can check for is:

if (snprintf(link, sizeof(link), ...) <

    sizeof("/sys/class/drm/%s/device/driver"))
Quoted 6 lines

drm.c line 74

Quoted 4 lines
drm.c new file +4 -0
+static void drm_free_priv(void *data)
+{
+	free(data);
+}

Do we really need a wrapper for free(3)?

No. The only reason I see is for clarity on how to use the tcb priv interface. But that is ofc debatable.

Quoted 8 lines
Quoted 8 lines
ioctl.c +2 -0
@@ -248,6 +248,10 @@ ioctl_decode(struct tcb *tcp)
 	case 0x22:
 		return scsi_ioctl(tcp, code, arg);
 #endif
+#if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H)
+	case 'd':
Quoted 8 lines

ioctl.c ioctl_decode(struct tcb *tcp) · line 257

Quoted 5 lines
ioctl.c +2 -0
+		return drm_ioctl(tcp, code, arg);
+#endif
 	case 'L':
 		return loop_ioctl(tcp, code, arg);
 	case 'M':

v3 version also patched ioctl_decode_command_number() to call drm_decode_number().

Will move it back into this patch.

Quoted 4 lines
Signature · 2 lines
-- 
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#19 lore raw

Re: [PATCH v4 3/5] drm: Add dispatcher and driver identification for DRM

Quoted 2 lines · Patrik Jakobsson
Quoted 1 line · Dmitry V. Levin

On Mon, Aug 24, 2015 at 02:42:48PM +0200, Patrik Jakobsson wrote:

[...]

Quoted 16 lines
Quoted 13 lines

drm.c line 61

Quoted 11 lines
drm.c new file +11 -0
+static char *drm_get_driver_name(struct tcb *tcp)
+{
+	char path[PATH_MAX];
+	char link[PATH_MAX];
+	int ret;
+
+	if (getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1) < 0)
+		return NULL;
+
+	snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver",
+		 basename(path));

if (snprintf(link, sizeof(link), ...) >= sizeof(link))

Quoted 2 lines
	return NULL;
Quoted 1 line

According to manpage snprintf never returns more than the specified size - 1.

Really?

"The functions snprintf() and vsnprintf() do not write more than size bytes (including the terminating null byte ('\0')). If the output was truncated due to this limit, then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available. Thus, a return value of size or more means that the output was truncated."

Signature · 1 line
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#20 lore raw

PATCH v4 4/5 drm: Add decoding of i915 ioctls

In reply to Patrik Jakobsson

First batch of i915 drm ioctls

* Makefile.am: Add compilation of drm_i915.c.
* defs.h: Add extern i915 declarations
* drm.c (drm_ioctl): Dispatch i915 ioctls.
* drm_i915.c: New file.
* xlat/drm_i915_getparams.in: New file.
* xlat/drm_i915_setparams.in: New file.
* xlat/drm_i915_ioctls.in: New file.

---
 Makefile.am                |   1 +
 defs.h                     |   2 +
 drm.c                      |  15 +-
 drm_i915.c                 | 342 +++++++++++++++++++++++++++++++++++++++++++++
 xlat/drm_i915_getparams.in |  28 ++++
 xlat/drm_i915_ioctls.in    |  51 +++++++
 xlat/drm_i915_setparams.in |   4 +
 7 files changed, 442 insertions(+), 1 deletion(-)
 create mode 100644 drm_i915.c
 create mode 100644 xlat/drm_i915_getparams.in
 create mode 100644 xlat/drm_i915_ioctls.in
 create mode 100644 xlat/drm_i915_setparams.in
Makefile.am +1 -0
index c7c6080..0af46f6 100644
@@ -43,6 +43,7 @@ strace_SOURCES =	\
 	desc.c		\
 	dirent.c	\
 	drm.c		\
+	drm_i915.c	\
 	epoll.c		\
 	evdev.c		\
 	eventfd.c	\
defs.h +2 -0
index dd3c720..1d54295 100644
@@ -614,6 +614,8 @@ extern void print_seccomp_filter(struct tcb *tcp, unsigned long);
 extern int block_ioctl(struct tcb *, const unsigned int, long);
 #if defined(HAVE_DRM_H) || defined(HAVE_DRM_DRM_H)
 extern int drm_ioctl(struct tcb *, const unsigned int, long);
+extern int drm_i915_ioctl(struct tcb *tcp, const unsigned int, long);
+extern int drm_i915_decode_number(struct tcb *, unsigned int);
 #endif
 extern int evdev_ioctl(struct tcb *, const unsigned int, long);
 extern int loop_ioctl(struct tcb *, const unsigned int, long);
drm.c +14 -1
index 0829803..e220309 100644
@@ -96,12 +96,25 @@ int drm_is_driver(struct tcb *tcp, const char *name)
 
 int drm_decode_number(struct tcb *tcp, unsigned int code)
 {
+	if (drm_is_priv(tcp->u_arg[1])) {
+		if (verbose(tcp) && drm_is_driver(tcp, "i915"))
+			return drm_i915_decode_number(tcp, code);
+	}
+
 	return 0;
 }
 
 int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
-	return 0;
+	int ret = 0;
+
+	/* Check for device specific ioctls */
+	if (drm_is_priv(tcp->u_arg[1])) {
+		if (verbose(tcp) && drm_is_driver(tcp, "i915"))
+			ret = drm_i915_ioctl(tcp, code, arg);
+	}
+
+	return ret;
 }
 
 #endif /* HAVE_DRM_H || HAVE_DRM_DRM_H */
drm_i915.c new file +342 -0

342 lines not on this page · raw message

xlat/drm_i915_getparams.in new file +28 -0
new file mode 100644
index 0000000..15275cb
@@ -0,0 +1,28 @@
+I915_PARAM_IRQ_ACTIVE
+I915_PARAM_ALLOW_BATCHBUFFER
+I915_PARAM_LAST_DISPATCH
+I915_PARAM_CHIPSET_ID
+I915_PARAM_HAS_GEM
+I915_PARAM_NUM_FENCES_AVAIL
+I915_PARAM_HAS_OVERLAY
+I915_PARAM_HAS_PAGEFLIPPING
+I915_PARAM_HAS_EXECBUF2
+I915_PARAM_HAS_BSD
+I915_PARAM_HAS_BLT
+I915_PARAM_HAS_RELAXED_FENCING
+I915_PARAM_HAS_COHERENT_RINGS
+I915_PARAM_HAS_EXEC_CONSTANTS
+I915_PARAM_HAS_RELAXED_DELTA
+I915_PARAM_HAS_GEN7_SOL_RESET
+I915_PARAM_HAS_LLC
+I915_PARAM_HAS_ALIASING_PPGTT
+I915_PARAM_HAS_WAIT_TIMEOUT
+I915_PARAM_HAS_SEMAPHORES
+I915_PARAM_HAS_PRIME_VMAP_FLUSH
+I915_PARAM_HAS_VEBOX
+I915_PARAM_HAS_SECURE_BATCHES
+I915_PARAM_HAS_PINNED_BATCHES
+I915_PARAM_HAS_EXEC_NO_RELOC
+I915_PARAM_HAS_EXEC_HANDLE_LUT
+I915_PARAM_HAS_WT
+I915_PARAM_CMD_PARSER_VERSION
xlat/drm_i915_ioctls.in new file +51 -0

51 lines not on this page · raw message

xlat/drm_i915_setparams.in new file +4 -0
new file mode 100644
index 0000000..d93d2ea
@@ -0,0 +1,4 @@
+I915_SETPARAM_USE_MI_BATCHBUFFER_START
+I915_SETPARAM_TEX_LRU_LOG_GRANULARITY
+I915_SETPARAM_ALLOW_BATCHBUFFER
+I915_SETPARAM_NUM_USED_FENCES
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#21 lore raw

Re: [PATCH v4 4/5] drm: Add decoding of i915 ioctls

Quoted 4 lines · Patrik Jakobsson
drm_i915.c new file +4 -0
+static int i915_getparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_getparam param;
+	int value;

drm_i915.c line 60

Quoted 10 lines
drm_i915.c new file +10 -0
+
+	if (umove(tcp, arg, &param))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprints(", {param=");
+		printxval(drm_i915_getparams, param.param, "I915_PARAM_???");
+	} else if (exiting(tcp)) {
+		if (umove(tcp, (long)param.value, &value))
+			return RVAL_DECODED;

Since part of param has already been printed, RVAL_DECODED shouldn't be returned here. For the same reason, RVAL_DECODED shouldn't be returned earlier in this function.

drm_i915.c line 65

Quoted 4 lines
drm_i915.c new file +4 -0
+		tprints(", value=");
+		switch (param.param) {
+		case I915_PARAM_CHIPSET_ID:
+			tprintf("0x%04x", value);

Since the value has been fetched by address stored in param.value, it has to be printed in brackets like in printnum_int.

drm_i915.c line 68

Quoted 3 lines
drm_i915.c new file +3 -0
+			break;
+		default:
+			tprintf("%d", value);

Likewise.

drm_i915.c line 73

Quoted 5 lines
drm_i915.c new file +5 -0
+		}
+		tprints("}");
+	}
+
+	return RVAL_DECODED | 1;

This shouldn't be returned on entering(tcp).

Quoted 1 line

+}

So the whole function should look smth like this:

static int i915_getparam(struct tcb *tcp, const unsigned int code, long arg)

{
	struct drm_i915_getparam param;

	if (entering(tcp)) {
		if (umove_or_printaddr(tcp, arg, &param))
			return RVAL_DECODED | 1;
		tprints(", {param=");
		printxval(drm_i915_getparams, param.param, "I915_PARAM_???");
		tprints(", value=");
		return 0;
	} else {
		int value;

		if (umove(tcp, arg, &param)) {
			tprints("???");
		} else if (!umove_or_printaddr(tcp, (long) param.value, &value)) {
			switch (param.param) {
			case I915_PARAM_CHIPSET_ID:
				tprintf("[%#04x]", value);
				break;
			default:
				tprintf("[%d]", value);
			}
		}
		tprints("}");
		return 1;
	}
}

Please apply this approach to all DRM_IOWR parsers.

drm_i915.c line 82

Quoted 8 lines
drm_i915.c new file +8 -0
+
+static int i915_setparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_setparam param;
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &param))
+			return RVAL_DECODED;

In this and other functions I slightly prefer

	if (umove_or_printaddr(tcp, arg, &param))
		return RVAL_DECODED | 1;

over your variant because umove_or_printaddr() handles NULL address and !verbose(tcp) case better.

Signature · 1 line
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#22 lore raw

Re: [PATCH v4 4/5] drm: Add decoding of i915 ioctls

On Tue, Sep 08, 2015 at 04:18:11AM +0300, Dmitry V. Levin wrote:
[...]

Quoted 10 lines

So the whole function should look smth like this:

static int i915_getparam(struct tcb *tcp, const unsigned int code, long arg)

{
	struct drm_i915_getparam param;

	if (entering(tcp)) {
		if (umove_or_printaddr(tcp, arg, &param))
			return RVAL_DECODED | 1;
		tprints(", {param=");

or rather

		tprints(", ");
		if (umove_or_printaddr(tcp, arg, &param))
			return RVAL_DECODED | 1;
		tprints("{param=");
Quoted 5 lines

In this and other functions I slightly prefer

	if (umove_or_printaddr(tcp, arg, &param))
		return RVAL_DECODED | 1;

over your variant because umove_or_printaddr() handles NULL address and !verbose(tcp) case better.

And the whole function will look as simple as this:

static int i915_setparam(struct tcb *tcp, const unsigned int code, long arg) {
struct drm_i915_setparam param;

	tprints(", ");
	if (!umove_or_printaddr(tcp, arg, &param)) {
		tprints("{param=");
		printxval(drm_i915_setparams, param.param, "I915_PARAM_???");
		tprintf(", value=%d}", param.value);
	}

	return RVAL_DECODED | 1;
}

Note the absence of entering(tcp) check because this DRM_IOW parser always returns a value with RVAL_DECODED flag set.

Signature · 1 line
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#23 lore raw

Re: [PATCH v4 4/5] drm: Add decoding of i915 ioctls

Quoted 13 lines · Dmitry V. Levin

On Tue, Sep 08, 2015 at 04:18:11AM +0300, Dmitry V. Levin wrote:
[...]

Quoted 10 lines

So the whole function should look smth like this:

static int i915_getparam(struct tcb *tcp, const unsigned int code, long arg)

{
	struct drm_i915_getparam param;

	if (entering(tcp)) {
		if (umove_or_printaddr(tcp, arg, &param))
			return RVAL_DECODED | 1;
		tprints(", {param=");
Quoted 5 lines

or rather

		tprints(", ");
		if (umove_or_printaddr(tcp, arg, &param))
			return RVAL_DECODED | 1;
		tprints("{param=");

or rather

static int
i915_getparam(struct tcb *tcp, const unsigned int code, const long arg)

{
	struct drm_i915_getparam param;
	int value;

	if (entering(tcp)) {
		tprints(", ");
		if (umove_or_printaddr(tcp, arg, &param))
			return RVAL_DECODED | 1;
		tprints("{param=");
		printxval(drm_i915_getparams, param.param, "I915_PARAM_???");
		return 0;
	}

	if (!umove(tcp, arg, &param)) {
		tprints(", value=");
		if (!umove_or_printaddr(tcp, (long) param.value, &value)) {
			switch (param.param) {
			case I915_PARAM_CHIPSET_ID:
				tprintf("[%#04x]", value);
				break;
			default:
				tprintf("[%d]", value);
			}
		}
	}
	tprints("}");
	return 1;
}

Note that those structure members that are set by the kernel on exiting syscall shouldn't normally be printed in case of syserror(tcp).

In case of i915_getparam, no extra check is needed because param.value is an address supplied by userspace and umove_or_printaddr already performs all necessary checks, but in other IOWR parsers you might want to use

	if (!syserror(tcp) && !umove(tcp, arg, &param)) {

instead.

Signature · 1 line
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#24 lore raw

Re: [PATCH v4 4/5] drm: Add decoding of i915 ioctls

In reply to Dmitry V. Levin
Quoted 11 lines · Dmitry V. Levin
Quoted 10 lines · Patrik Jakobsson
drm_i915.c new file +10 -0
+static int i915_getparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_getparam param;
+	int value;
+
+	if (umove(tcp, arg, &param))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprints(", {param=");
Quoted 9 lines

drm_i915.c line 60

Quoted 4 lines
drm_i915.c new file +4 -0
+		printxval(drm_i915_getparams, param.param, "I915_PARAM_???");
+	} else if (exiting(tcp)) {
+		if (umove(tcp, (long)param.value, &value))
+			return RVAL_DECODED;

Since part of param has already been printed, RVAL_DECODED shouldn't be returned here. For the same reason, RVAL_DECODED shouldn't be returned earlier in this function.

The usage of RVAL_DECODED is quite confusing. RVAL_DECODED to me should be "We decoded this don't do any fallback". How did you intent it to be used?

Quoted 7 lines

drm_i915.c line 65

Quoted 4 lines
drm_i915.c new file +4 -0
+		tprints(", value=");
+		switch (param.param) {
+		case I915_PARAM_CHIPSET_ID:
+			tprintf("0x%04x", value);

Since the value has been fetched by address stored in param.value, it has to be printed in brackets like in printnum_int.

Ok

Quoted 6 lines

drm_i915.c line 68

Quoted 3 lines
drm_i915.c new file +3 -0
+			break;
+		default:
+			tprintf("%d", value);

Likewise.

Quoted 7 lines

drm_i915.c line 73

Quoted 5 lines
drm_i915.c new file +5 -0
+		}
+		tprints("}");
+	}
+
+	return RVAL_DECODED | 1;

This shouldn't be returned on entering(tcp).

If all decoding would be done when entering is finished, wouldn't it make sense to allow RVAL_DECODED here? Still don't understand how this is intended to work.

Quoted 46 lines
Quoted 1 line

+}

So the whole function should look smth like this:

static int i915_getparam(struct tcb *tcp, const unsigned int code, long arg)

{
	struct drm_i915_getparam param;

	if (entering(tcp)) {
		if (umove_or_printaddr(tcp, arg, &param))
			return RVAL_DECODED | 1;
		tprints(", {param=");
		printxval(drm_i915_getparams, param.param, "I915_PARAM_???");
		tprints(", value=");
		return 0;
	} else {
		int value;

		if (umove(tcp, arg, &param)) {
			tprints("???");
		} else if (!umove_or_printaddr(tcp, (long) param.value, &value)) {
			switch (param.param) {
			case I915_PARAM_CHIPSET_ID:
				tprintf("[%#04x]", value);
				break;
			default:
				tprintf("[%d]", value);
			}
		}
		tprints("}");
		return 1;
	}
}

Please apply this approach to all DRM_IOWR parsers.

drm_i915.c line 82

Quoted 8 lines
drm_i915.c new file +8 -0
+
+static int i915_setparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_setparam param;
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &param))
+			return RVAL_DECODED;

In this and other functions I slightly prefer

Quoted 4 lines
	if (umove_or_printaddr(tcp, arg, &param))
		return RVAL_DECODED | 1;

over your variant because umove_or_printaddr() handles NULL address and !verbose(tcp) case better.

Agreed

Quoted 4 lines
Signature · 2 lines
-- 
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#25 lore raw

Re: [PATCH v4 4/5] drm: Add decoding of i915 ioctls

Quoted 21 lines · Patrik Jakobsson
Quoted 11 lines · Dmitry V. Levin
Quoted 10 lines · Patrik Jakobsson
drm_i915.c new file +10 -0
+static int i915_getparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_getparam param;
+	int value;
+
+	if (umove(tcp, arg, &param))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprints(", {param=");
Quoted 8 lines

drm_i915.c line 60

Quoted 4 lines
drm_i915.c new file +4 -0
+		printxval(drm_i915_getparams, param.param, "I915_PARAM_???");
+	} else if (exiting(tcp)) {
+		if (umove(tcp, (long)param.value, &value))
+			return RVAL_DECODED;

Since part of param has already been printed, RVAL_DECODED shouldn't be returned here. For the same reason, RVAL_DECODED shouldn't be returned earlier in this function.

Quoted 2 lines

The usage of RVAL_DECODED is quite confusing. RVAL_DECODED to me should be "We decoded this don't do any fallback". How did you intent it to be used?

RVAL_DECODED itself is trivial: by setting this flag parser tells its caller that decoding is finished on entering and it shouldn't be called on exiting of this syscall. Setting this flag on exiting has no effect.

With regards to ioctl parsers, there might be some confusion because they also have this unusual return code +1 semantics. In this example, the problem with "return RVAL_DECODED" statements is that if they happen on exiting, it means that something has already been printed on entering already and by returning RVAL_DECODED parser tells its caller to perform the default action that also prints something.

That is, ioctl parser should return
- on entering:
+ any value (it's ignored) without RVAL_DECODED flag set:

    continue processing on exiting;

+ RVAL_DECODED:
skip processing on exiting and tell the caller to perform default processing on entering;
+ RVAL_DECODED | (1 + RVAL_*):
skip processing on exiting and tell the caller to skip default processing;
- on exiting:
+ 0 (with or without RVAL_DECODED set, it's ignored anyway):

    tell the caller to perform default processing on exiting;

+ 1 + RVAL_* (RVAL_DECODED is ignored):
tell the caller to skip default processing.

Quoted 14 lines
Quoted 6 lines

drm_i915.c line 68

Quoted 3 lines
drm_i915.c new file +3 -0
+			break;
+		default:
+			tprintf("%d", value);

Likewise.

Quoted 7 lines

drm_i915.c line 73

Quoted 5 lines
drm_i915.c new file +5 -0
+		}
+		tprints("}");
+	}
+
+	return RVAL_DECODED | 1;

This shouldn't be returned on entering(tcp).

Quoted 2 lines

If all decoding would be done when entering is finished, wouldn't it make sense to allow RVAL_DECODED here? Still don't understand how this is intended to work.

Usally only IOW parsers return codes with RVAL_DECODED set on entering. IOWR also print something on exiting so they shouldn't normally return RVAL_DECODED on entering.

Signature · 1 line
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#26 lore raw

PATCH v4 5/5 drm: Add decoding of DRM and KMS ioctls

In reply to Patrik Jakobsson

First batch of drm / kms ioctls.

* drm.c (drm_version, drm_get_unique, drm_get_magic, drm_wait_vblank, drm_mode_get_resources, drm_mode_print_modeinfo, drm_mode_get_crtc, drm_mode_set_crtc, drm_mode_cursor, drm_mode_cursor2, drm_mode_get_gamma, drm_mode_set_gamma, drm_mode_get_encoder, drm_mode_get_connector, drm_mode_get_property, drm_mode_set_property, drm_mode_get_prop_blob, drm_mode_add_fb drm_mode_get_fb, drm_mode_rm_fb, drm_mode_page_flip, drm_mode_dirty_fb, drm_mode_create_dumb, drm_mode_map_dumb, drm_mode_destroy_dumb, drm_gem_close): New function (drm_ioctl): Dispatch drm ioctls

---
 drm.c | 543 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 543 insertions(+)
drm.c +543 -0
index e220309..06f2265 100644
@@ -104,6 +104,471 @@ int drm_decode_number(struct tcb *tcp, unsigned int code)
 	return 0;
 }
 
+static int drm_version(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_version ver;
+
+	if (exiting(tcp)) {
+		if (umove(tcp, arg, &ver))
+			return RVAL_DECODED;
+
+		tprintf(", {version_major=%d, version_minor=%d, version_patchlevel=%d, "
+			"name_len=%lu, name=", ver.version_major,
+			ver.version_minor, ver.version_patchlevel,
+			ver.name_len);
+		printstr(tcp, (long)ver.name, ver.name_len);
+		tprintf(", date_len=%lu, date=", ver.date_len);
+		printstr(tcp, (long)ver.date, ver.date_len);
+		tprintf(", desc_len=%lu, desc=", ver.desc_len);
+		printstr(tcp, (long)ver.desc, ver.desc_len);
+		tprints("}");
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_get_unique(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_unique unique;
+
+	if (exiting(tcp)) {
+		if (umove(tcp, arg, &unique))
+			return RVAL_DECODED;
+
+		tprintf(", {unique_len=%lu, unique=", unique.unique_len);
+		printstr(tcp, (long)unique.unique, unique.unique_len);
+		tprints("}");
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_get_magic(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_auth auth;
+
+	if (exiting(tcp)) {
+		if (umove(tcp, arg, &auth))
+			return RVAL_DECODED;
+
+		tprintf(", {magic=%u}", auth.magic);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_wait_vblank(struct tcb *tcp, const unsigned int code, long arg)
+{
+	union drm_wait_vblank vblank;
+
+	if (umove(tcp, arg, &vblank))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprintf(", {request={type=%u, sequence=%u, signal=%lu}",
+			vblank.request.type, vblank.request.sequence,
+			vblank.request.signal);
+	} else if (exiting(tcp)) {
+		tprintf(", reply={type=%u, sequence=%u, tval_sec=%ld, tval_usec=%ld}}",
+			vblank.reply.type, vblank.reply.sequence,
+			vblank.reply.tval_sec, vblank.reply.tval_usec);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_get_resources(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_card_res res;
+
+	if (exiting(tcp)) {
+		if (umove(tcp, arg, &res))
+			return RVAL_DECODED;
+
+		tprintf(", {fb_id_ptr=%p, crtc_id_ptr=%p, connector_id_ptr=%p, "
+			"encoder_id_ptr=%p, count_fbs=%u, count_crtcs=%u, "
+			"count_connectors=%u, count_encoders=%u, min_width=%u, "
+			"max_width=%u, min_height=%u, max_height=%u}",
+			(void *)res.fb_id_ptr, (void *)res.crtc_id_ptr,
+			(void *)res.connector_id_ptr, (void *)res.encoder_id_ptr,
+			res.count_fbs, res.count_crtcs, res.count_connectors,
+			res.count_encoders, res.min_width, res.max_width,
+			res.min_height, res.max_height);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static void drm_mode_print_modeinfo(struct drm_mode_modeinfo *info)
+{
+	tprintf("clock=%u, hdisplay=%hu, hsync_start=%hu, hsync_end=%hu, "
+		"htotal=%hu, hskew=%hu, vdisplay=%hu, vsync_start=%hu, "
+		"vsync_end=%hu, vtotal=%hu, vscan=%hu, vrefresh=%u, "
+		"flags=0x%x, type=%u, name=%s", info->clock, info->hdisplay,
+		info->hsync_start, info->hsync_end, info->htotal, info->hskew,
+		info->vdisplay, info->vsync_start, info->vsync_end,
+		info->vtotal, info->vscan, info->vrefresh, info->flags,
+		info->type, info->name);
+}
+
+static int drm_mode_get_crtc(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_crtc crtc;
+
+	if (umove(tcp, arg, &crtc))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprintf(", {crtc_id=%u", crtc.crtc_id);
+	} else if (exiting(tcp)) {
+		tprintf(", set_connectors_ptr=%p, count_connectors=%u, "
+			"fb_id=%u, x=%u, y=%u, gamma_size=%u, mode_valid=%u, "
+			"mode={", (void *)crtc.set_connectors_ptr,
+			crtc.count_connectors, crtc.fb_id, crtc.x, crtc.y,
+			crtc.gamma_size, crtc.mode_valid);
+
+		drm_mode_print_modeinfo(&crtc.mode);
+		tprintf("}}");
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_set_crtc(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_crtc crtc;
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &crtc))
+			return RVAL_DECODED;
+
+		tprintf(", {set_connectors_ptr=%p, count_connectors=%u, "
+			"crtc_id=%u, fb_id=%u, x=%u, y=%u, gamma_size=%u, "
+			"mode_valid=%u, mode={", (void *)crtc.set_connectors_ptr,
+			crtc.count_connectors, crtc.crtc_id, crtc.fb_id, crtc.x,
+			crtc.y, crtc.gamma_size, crtc.mode_valid);
+
+		drm_mode_print_modeinfo(&crtc.mode);
+		tprintf("}}");
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_cursor(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_cursor cursor;
+
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &cursor))
+			return RVAL_DECODED;
+
+		tprintf(", {flags=0x%x, crtc_id=%u, x=%d, y=%d, width=%u, "
+			"height=%u, handle=%u}", cursor.flags, cursor.crtc_id,
+			cursor.x, cursor.y, cursor.width, cursor.height,
+			cursor.handle);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_cursor2(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_cursor2 cursor;
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &cursor))
+			return RVAL_DECODED;
+
+		tprintf(", {flags=0x%x, crtc_id=%u, x=%d, y=%d, width=%u, "
+			"height=%u, handle=%u, hot_x=%d, hot_y=%d}",
+			cursor.flags, cursor.crtc_id, cursor.x, cursor.y,
+			cursor.width, cursor.height, cursor.handle,
+			cursor.hot_x, cursor.hot_y);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_get_gamma(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_crtc_lut lut;
+
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &lut))
+			return RVAL_DECODED;
+
+		/* We don't print the entire table, just the pointers */
+		tprintf(", {crtc_id=%u, gamma_size=%u, red=%p, green=%p, "
+			"blue=%p}", lut.crtc_id, lut.gamma_size,
+			(void *)lut.red, (void *)lut.green, (void *)lut.blue);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_set_gamma(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_crtc_lut lut;
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &lut))
+			return RVAL_DECODED;
+
+		/* We don't print the entire table, just the rgb pointers */
+		tprintf(", {crtc_id=%u, gamma_size=%u, red=%p, green=%p, "
+			"blue=%p}", lut.crtc_id, lut.gamma_size,
+			(void *)lut.red, (void *)lut.green, (void *)lut.blue);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_get_encoder(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_get_encoder enc;
+
+	if (umove(tcp, arg, &enc))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprintf(", {encoder_id=%u", enc.encoder_id);
+	} else if (exiting(tcp)) {
+		/* TODO: Print name of encoder type */
+		tprintf(", encoder_type=%u, crtc_id=%u, possible_crtcs=0x%x, "
+			"possible_clones=0x%x}", enc.encoder_type,
+			enc.crtc_id, enc.possible_crtcs, enc.possible_clones);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_get_connector(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_get_connector con;
+
+	if (umove(tcp, arg, &con))
+		return RVAL_DECODED;
+
+	/* We could be very verbose here but keep is simple for now */
+	if (entering(tcp)) {
+		tprintf(", {connector_id=%u", con.connector_id);
+	} else if (exiting(tcp)) {
+		tprintf(", encoders_ptr=%p, modes_ptr=%p, props_ptr=%p, "
+			"prop_values_ptr=%p, count_modes=%u, count_props=%u, "
+			"count_encoders=%u, encoder_id=%u, connector_type=%u, "
+			"connector_type_id=%u, connection=%u, mm_width=%u, "
+			"mm_height=%u, subpixel=%u}", (void *)con.encoders_ptr,
+			(void *)con.modes_ptr, (void *)con.props_ptr,
+			(void *)con.prop_values_ptr, con.count_modes,
+			con.count_props, con.count_encoders, con.encoder_id,
+			con.connector_type, con.connector_type_id,
+			con.connection, con.mm_width, con.mm_height,
+			con.subpixel);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_get_property(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_get_property prop;
+
+	if (umove(tcp, arg, &prop))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprintf(", {prop_id=%u", prop.prop_id);
+	} else if (exiting(tcp)) {
+		tprintf(", values_ptr=%p, enum_blob_ptr=%p, flags=0x%x, "
+			"name=%s, count_values=%u, count_enum_blobs=%u}",
+			(void *)prop.values_ptr, (void *)prop.enum_blob_ptr,
+			prop.flags, prop.name, prop.count_values,
+			prop.count_enum_blobs);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_set_property(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_connector_set_property prop;
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &prop))
+			return RVAL_DECODED;
+
+		tprintf(", {value=%Lu, prop_id=%u, connector_id=%u}",
+			prop.value, prop.prop_id, prop.connector_id);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_get_prop_blob(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_get_blob blob;
+
+	if (umove(tcp, arg, &blob))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprintf(", {blob_id=%u", blob.blob_id);
+	} else if (exiting(tcp)) {
+		tprintf(", length=%u, data=%p}", blob.length,
+			(void *)blob.data);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_add_fb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_fb_cmd cmd;
+
+	if (umove(tcp, arg, &cmd))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprintf(", {width=%u, height=%u, pitch=%u, bpp=%u, depth=%u, "
+			"handle=%u", cmd.width, cmd.height, cmd.pitch,
+			cmd.bpp, cmd.depth, cmd.handle);
+	} else if (exiting(tcp)) {
+		tprintf(", fb_id=%u}", cmd.fb_id);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_get_fb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_fb_cmd cmd;
+
+	if (umove(tcp, arg, &cmd))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprintf(", {fb_id=%u", cmd.fb_id);
+	} else {
+		tprintf(", width=%u, height=%u, pitch=%u, bpp=%u, depth=%u, "
+		"handle=%u}", cmd.width, cmd.height, cmd.pitch,
+		cmd.bpp, cmd.depth, cmd.handle);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_rm_fb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	unsigned int handle;
+
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &handle))
+			return RVAL_DECODED;
+
+		tprintf(", %u", handle);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_page_flip(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_crtc_page_flip flip;
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &flip))
+			return RVAL_DECODED;
+
+		tprintf(", {crtc_id=%u, fb_id=%u, flags=0x%x, user_data=0x%Lx}",
+			flip.crtc_id, flip.fb_id, flip.flags, flip.user_data);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_dirty_fb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_fb_dirty_cmd cmd;
+
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &cmd))
+			return RVAL_DECODED;
+
+		tprintf(", {fb_id=%u, flags=0x%x, color=0x%x, num_clips=%u, "
+			"clips_ptr=%p}", cmd.fb_id, cmd.flags, cmd.color,
+			cmd.num_clips, (void *)cmd.clips_ptr);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_create_dumb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_create_dumb dumb;
+
+	if (umove(tcp, arg, &dumb))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprintf(", {width=%u, height=%u, bpp=%u, flags=0x%x",
+			dumb.width, dumb.height, dumb.bpp, dumb.flags);
+	} else if (exiting(tcp)) {
+		tprintf(", handle=%u, pitch=%u, size=%Lu}", dumb.handle,
+			dumb.pitch, dumb.size);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_map_dumb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_map_dumb dumb;
+
+	if (umove(tcp, arg, &dumb))
+		return RVAL_DECODED;
+
+	if (entering(tcp)) {
+		tprintf(", {handle=%u", dumb.handle);
+	} else if (exiting(tcp)) {
+		tprintf(", offset=%Lu}", dumb.offset);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_mode_destroy_dumb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_destroy_dumb dumb;
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &dumb))
+			return RVAL_DECODED;
+
+		tprintf(", {handle=%u}", dumb.handle);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
+static int drm_gem_close(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_gem_close close;
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &close))
+			return RVAL_DECODED;
+
+		tprintf(", {handle=%u}", close.handle);
+	}
+
+	return RVAL_DECODED | 1;
+}
+
 int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
 	int ret = 0;
@@ -112,6 +577,84 @@ int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 	if (drm_is_priv(tcp->u_arg[1])) {
 		if (verbose(tcp) && drm_is_driver(tcp, "i915"))
 			ret = drm_i915_ioctl(tcp, code, arg);
+	} else {
+		switch (code) {
+		case DRM_IOCTL_VERSION:
+			ret = drm_version(tcp, code, arg);
+			break;
+		case DRM_IOCTL_GET_UNIQUE:
+			ret = drm_get_unique(tcp, code, arg);
+			break;
+		case DRM_IOCTL_GET_MAGIC:
+			ret = drm_get_magic(tcp, code, arg);
+			break;
+		case DRM_IOCTL_WAIT_VBLANK:
+			ret = drm_wait_vblank(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_GETRESOURCES:
+			ret = drm_mode_get_resources(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_GETCRTC:
+			ret = drm_mode_get_crtc(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_SETCRTC:
+			ret = drm_mode_set_crtc(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_CURSOR:
+			ret = drm_mode_cursor(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_CURSOR2:
+			ret = drm_mode_cursor2(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_GETGAMMA:
+			ret = drm_mode_get_gamma(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_SETGAMMA:
+			ret = drm_mode_set_gamma(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_GETENCODER:
+			ret = drm_mode_get_encoder(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_GETCONNECTOR:
+			ret = drm_mode_get_connector(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_GETPROPERTY:
+			ret = drm_mode_get_property(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_SETPROPERTY:
+			ret = drm_mode_set_property(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_GETPROPBLOB:
+			ret = drm_mode_get_prop_blob(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_GETFB:
+			ret = drm_mode_get_fb(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_ADDFB:
+			ret = drm_mode_add_fb(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_RMFB:
+			ret = drm_mode_rm_fb(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_PAGE_FLIP:
+			ret = drm_mode_page_flip(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_DIRTYFB:
+			ret = drm_mode_dirty_fb(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_CREATE_DUMB:
+			ret = drm_mode_create_dumb(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_MAP_DUMB:
+			ret = drm_mode_map_dumb(tcp, code, arg);
+			break;
+		case DRM_IOCTL_MODE_DESTROY_DUMB:
+			ret = drm_mode_destroy_dumb(tcp, code, arg);
+			break;
+		case DRM_IOCTL_GEM_CLOSE:
+			ret = drm_gem_close(tcp, code, arg);
+			break;
+		}
 	}
 
 	return ret;
Signature · 6 lines
2.1.4

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#27 lore raw

Re: [PATCH v4 5/5] drm: Add decoding of DRM and KMS ioctls

Quoted 1 line · Patrik Jakobsson

First batch of drm / kms ioctls.

Several comments in addition to issues similar to 4/5 patch.

Quoted 4 lines
drm.c +4 -0
+static int drm_mode_rm_fb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	unsigned int handle;
+

drm.c int drm_decode_number(struct tcb *tcp, unsigned int code) · line 476

Quoted 10 lines
drm.c +10 -0
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &handle))
+			return RVAL_DECODED;
+
+		tprintf(", %u", handle);
+	}
+
+	return RVAL_DECODED | 1;
+}

Use printnum_int instead:

	tprints(", ");
	printnum_int(tcp, arg, "%u");
	return RVAL_DECODED | 1;
Quoted 7 lines
drm.c +7 -0
+static int drm_mode_create_dumb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_create_dumb dumb;
+
+	if (umove(tcp, arg, &dumb))
+		return RVAL_DECODED;
+

drm.c int drm_decode_number(struct tcb *tcp, unsigned int code) · line 526

Quoted 10 lines
drm.c +10 -0
+	if (entering(tcp)) {
+		tprintf(", {width=%u, height=%u, bpp=%u, flags=0x%x",
+			dumb.width, dumb.height, dumb.bpp, dumb.flags);
+	} else if (exiting(tcp)) {
+		tprintf(", handle=%u, pitch=%u, size=%Lu}", dumb.handle,
+			dumb.pitch, dumb.size);
+	}
+
+	return RVAL_DECODED | 1;
+}

This generates a warning (which turns into an error with --enable-gcc-Werror) on x86_64 when using kernel drm headers:

drm.c: In function 'drm_mode_create_dumb':
drm.c:521:11: error: format '%Lu' expects argument of type 'long long unsigned int', but argument 4 has type 'uint64_t {aka long unsigned int}' [-Werror=format=]

drm.c int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg) · line 584

Quoted 9 lines
drm.c +5 -0
@@ -112,6 +577,84 @@ int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 	if (drm_is_priv(tcp->u_arg[1])) {
 		if (verbose(tcp) && drm_is_driver(tcp, "i915"))
 			ret = drm_i915_ioctl(tcp, code, arg);
+	} else {
+		switch (code) {
+		case DRM_IOCTL_VERSION:
+			ret = drm_version(tcp, code, arg);
+			break;

Looks like the return code can be forwarded without further delays.

Signature · 1 line
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#28 lore raw

Re: [PATCH v4 5/5] drm: Add decoding of DRM and KMS ioctls

Quoted 22 lines · Dmitry V. Levin
Quoted 1 line · Patrik Jakobsson

First batch of drm / kms ioctls.

Several comments in addition to issues similar to 4/5 patch.

Quoted 4 lines
drm.c +4 -0
+static int drm_mode_rm_fb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	unsigned int handle;
+

drm.c int drm_decode_number(struct tcb *tcp, unsigned int code) · line 476

Quoted 10 lines
drm.c +10 -0
+
+	if (entering(tcp)) {
+		if (umove(tcp, arg, &handle))
+			return RVAL_DECODED;
+
+		tprintf(", %u", handle);
+	}
+
+	return RVAL_DECODED | 1;
+}

Use printnum_int instead:

Quoted 3 lines
	tprints(", ");
	printnum_int(tcp, arg, "%u");
	return RVAL_DECODED | 1;

Ok

Quoted 21 lines
Quoted 7 lines
drm.c +7 -0
+static int drm_mode_create_dumb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_create_dumb dumb;
+
+	if (umove(tcp, arg, &dumb))
+		return RVAL_DECODED;
+

drm.c int drm_decode_number(struct tcb *tcp, unsigned int code) · line 526

Quoted 10 lines
drm.c +10 -0
+	if (entering(tcp)) {
+		tprintf(", {width=%u, height=%u, bpp=%u, flags=0x%x",
+			dumb.width, dumb.height, dumb.bpp, dumb.flags);
+	} else if (exiting(tcp)) {
+		tprintf(", handle=%u, pitch=%u, size=%Lu}", dumb.handle,
+			dumb.pitch, dumb.size);
+	}
+
+	return RVAL_DECODED | 1;
+}

This generates a warning (which turns into an error with --enable-gcc-Werror) on x86_64 when using kernel drm headers:

Quoted 2 lines

drm.c: In function 'drm_mode_create_dumb':
drm.c:521:11: error: format '%Lu' expects argument of type 'long long unsigned int', but argument 4 has type 'uint64_t {aka long unsigned int}' [-Werror=format=]

So this brings us back to whether to include drm kernel headers or not. If -Werror is a requirement (which is already broken last time I checked) there will need to be #ifdefs at various places in drm decoding. What would you prefer. Both options are fine by me.

Quoted 11 lines

drm.c int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg) · line 584

Quoted 9 lines
drm.c +5 -0
@@ -112,6 +577,84 @@ int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 	if (drm_is_priv(tcp->u_arg[1])) {
 		if (verbose(tcp) && drm_is_driver(tcp, "i915"))
 			ret = drm_i915_ioctl(tcp, code, arg);
+	} else {
+		switch (code) {
+		case DRM_IOCTL_VERSION:
+			ret = drm_version(tcp, code, arg);
+			break;

Looks like the return code can be forwarded without further delays.

Yes, this is a leftover from before the tcb priv interface. Will remove.

Quoted 4 lines
Signature · 2 lines
-- 
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#29 lore raw

Re: [PATCH v4 5/5] drm: Add decoding of DRM and KMS ioctls

Quoted 23 lines · Patrik Jakobsson
Quoted 22 lines · Dmitry V. Levin
Quoted 7 lines · Patrik Jakobsson
drm.c +7 -0
+static int drm_mode_create_dumb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_create_dumb dumb;
+
+	if (umove(tcp, arg, &dumb))
+		return RVAL_DECODED;
+

drm.c int drm_decode_number(struct tcb *tcp, unsigned int code) · line 526

Quoted 10 lines
drm.c +10 -0
+	if (entering(tcp)) {
+		tprintf(", {width=%u, height=%u, bpp=%u, flags=0x%x",
+			dumb.width, dumb.height, dumb.bpp, dumb.flags);
+	} else if (exiting(tcp)) {
+		tprintf(", handle=%u, pitch=%u, size=%Lu}", dumb.handle,
+			dumb.pitch, dumb.size);
+	}
+
+	return RVAL_DECODED | 1;
+}

This generates a warning (which turns into an error with --enable-gcc-Werror) on x86_64 when using kernel drm headers:

Quoted 5 lines
Quoted 2 lines

drm.c: In function 'drm_mode_create_dumb':
drm.c:521:11: error: format '%Lu' expects argument of type 'long long unsigned int', but argument 4 has type 'uint64_t {aka long unsigned int}' [-Werror=format=]

So this brings us back to whether to include drm kernel headers or not. If -Werror is a requirement (which is already broken last time I checked) there

Is it? Could you cite the error, please?

Quoted 2 lines

will need to be #ifdefs at various places in drm decoding. What would you prefer. Both options are fine by me.

This is the only place where definitions differ to the extent that it's visible. I'd rather cast the argument to unsigned long long.

Signature · 1 line
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

A message that is not in the archive (sent off-list or not yet received): 20150911121005.GB6177-u2l5PoMzF/[email protected]

#31 lore raw

Re: [PATCH v4 5/5] drm: Add decoding of DRM and KMS ioctls

Quoted 24 lines · Dmitry V. Levin
Quoted 23 lines · Patrik Jakobsson
Quoted 22 lines · Dmitry V. Levin
Quoted 7 lines · Patrik Jakobsson
drm.c +7 -0
+static int drm_mode_create_dumb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_create_dumb dumb;
+
+	if (umove(tcp, arg, &dumb))
+		return RVAL_DECODED;
+

drm.c int drm_decode_number(struct tcb *tcp, unsigned int code) · line 526

Quoted 10 lines
drm.c +10 -0
+	if (entering(tcp)) {
+		tprintf(", {width=%u, height=%u, bpp=%u, flags=0x%x",
+			dumb.width, dumb.height, dumb.bpp, dumb.flags);
+	} else if (exiting(tcp)) {
+		tprintf(", handle=%u, pitch=%u, size=%Lu}", dumb.handle,
+			dumb.pitch, dumb.size);
+	}
+
+	return RVAL_DECODED | 1;
+}

This generates a warning (which turns into an error with --enable-gcc-Werror) on x86_64 when using kernel drm headers:

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

drm.c: In function 'drm_mode_create_dumb':
drm.c:521:11: error: format '%Lu' expects argument of type 'long long unsigned int', but argument 4 has type 'uint64_t {aka long unsigned int}' [-Werror=format=]

So this brings us back to whether to include drm kernel headers or not. If -Werror is a requirement (which is already broken last time I checked) there

Is it? Could you cite the error, please?

It's in aio.c:185 which at a closer look is intentional. Would still break the build though. But I'm not arguing that letting warnings slip through (with or without -Werror) is ok, just wondering if it justifies what I'm trying to do here.

Quoted 5 lines
Quoted 2 lines

will need to be #ifdefs at various places in drm decoding. What would you prefer. Both options are fine by me.

This is the only place where definitions differ to the extent that it's visible. I'd rather cast the argument to unsigned long long.

Sounds reasonable, I'll do that.

Quoted 12 lines
Signature · 11 lines
-- 
ldv



------------------------------------------------------------------------------

_______________________________________________
Strace-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/strace-devel

------------------------------------------------------------------------------

#32 lore raw

Re: [PATCH v4 5/5] drm: Add decoding of DRM and KMS ioctls

Quoted 31 lines · Patrik Jakobsson
Quoted 30 lines · Dmitry V. Levin
Quoted 28 lines · Patrik Jakobsson
Quoted 22 lines · Dmitry V. Levin
Quoted 7 lines · Patrik Jakobsson
drm.c +7 -0
+static int drm_mode_create_dumb(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_mode_create_dumb dumb;
+
+	if (umove(tcp, arg, &dumb))
+		return RVAL_DECODED;
+

drm.c int drm_decode_number(struct tcb *tcp, unsigned int code) · line 526

Quoted 10 lines
drm.c +10 -0
+	if (entering(tcp)) {
+		tprintf(", {width=%u, height=%u, bpp=%u, flags=0x%x",
+			dumb.width, dumb.height, dumb.bpp, dumb.flags);
+	} else if (exiting(tcp)) {
+		tprintf(", handle=%u, pitch=%u, size=%Lu}", dumb.handle,
+			dumb.pitch, dumb.size);
+	}
+
+	return RVAL_DECODED | 1;
+}

This generates a warning (which turns into an error with --enable-gcc-Werror) on x86_64 when using kernel drm headers:

Quoted 2 lines

drm.c: In function 'drm_mode_create_dumb':
drm.c:521:11: error: format '%Lu' expects argument of type 'long long unsigned int', but argument 4 has type 'uint64_t {aka long unsigned int}' [-Werror=format=]

So this brings us back to whether to include drm kernel headers or not. If -Werror is a requirement (which is already broken last time I checked) there

Quoted 6 lines
Quoted 1 line

Is it? Could you cite the error, please?

It's in aio.c:185 which at a closer look is intentional. Would still break the build though. But I'm not arguing that letting warnings slip through (with or without -Werror) is ok, just wondering if it justifies what I'm trying to do here.

strace is expected to build without compilation warnings assuming that the compiler and headers are supported. In fact, I routinely build strace with --enable-gcc-Werror. If it doesn't build for you, please report.

Signature · 1 line
ldv

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#33 lore raw
In reply to Patrik Jakobsson
Quoted 6 lines · On Mon, 24 Aug 2015 14:42:45 +0200 Patrik Jakobsson…

This set of patches adds a dispatcher for handling DRM ioctls. The kernel headers for DRM might not be available on all distributions so we depend on libdrm for those. If libdrm is not available we fall back on the kernel headers. Since DRM drivers share the same range of private ioctl numbers I've added a function for detecting the driver based on it's name.

Besides the reflection about the usage/api for priv_data and free_priv_data, this patchset seems to be good. Is there any more remarks for the drm ioctl decoding ?

Quoted 50 lines

Changes in v2:
* Rebased to master
* Added Changelog to commits
* Keep strace_SOURCES list sorted
* Removed unneeded includes
* Reduced number of driver name checks by adding tcb private data
* Use tprints() for regular strings
* Reworked entering() / exiting() handling for all ioctls
* Use printstr() to print strings in properly quoted form

Changes in v3:
* Moved all umove() into state checks for single state ioctls
* Removed extra curly bracket
* Moved param argument into entering() state in i915_setparam()
* Don't return before private data is freed in drm_ioctl()

Changes in v4:
* Rebased to master
* Rewrote commit messages to GNU changelog standard
* Added private data support to struct tcb
* Reworked drm driver identification
* Reworked drm header detection
* Use recently added return types for decode functions
* Various small fixes

Patrik Jakobsson (5):
drm: Add config for detecting libdrm
drm: Add private data field to trace control block
drm: Add dispatcher and driver identification for DRM
drm: Add decoding of i915 ioctls
drm: Add decoding of DRM and KMS ioctls

 Makefile.am                |   2 +
 configure.ac               |   5 +
 defs.h                     |  11 +
 drm.c                      | 663 +++++++++++++++++++++++++++++++++++++++++++++
 drm_i915.c                 | 342 +++++++++++++++++++++++
 ioctl.c                    |   4 +
 strace.c                   |  14 +
 syscall.c                  |   1 +
 xlat/drm_i915_getparams.in |  28 ++
 xlat/drm_i915_ioctls.in    |  51 ++++
 xlat/drm_i915_setparams.in |   4 +
 11 files changed, 1125 insertions(+)
 create mode 100644 drm.c
 create mode 100644 drm_i915.c
 create mode 100644 xlat/drm_i915_getparams.in
 create mode 100644 xlat/drm_i915_ioctls.in
 create mode 100644 xlat/drm_i915_setparams.in
Signature · 5 lines
Gabriel Laskar
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx