Skip to contentSkip to conversation

drm: Add decoding for DRM/KMS and i915 ioctls

PATCH Superseded Patrik Jakobsson 7 participants 22 messages Jul 1, 2015 – Aug 2, 2015 4 messages not in the archive Kbuild

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 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()

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               |   4 +
 defs.h                     |  11 +-
 drm.c                      | 668 +++++++++++++++++++++++++++++++++++++++++++++
 drm_i915.c                 | 332 ++++++++++++++++++++++
 io.c                       |   2 +-
 ioctl.c                    |   6 +-
 xlat/drm_i915_getparams.in |  28 ++
 xlat/drm_i915_ioctls.in    |  51 ++++
 xlat/drm_i915_setparams.in |   4 +
 10 files changed, 1105 insertions(+), 3 deletions(-)
 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

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

#2 lore raw

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

Use pkg-config to try to find libdrm. If that fails use the standard include directory for kernel drm headers in /usr/include/drm.

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

---
 configure.ac | 4 ++++
 1 file changed, 4 insertions(+)
configure.ac +4 -0
index bb8bf46..aa63af7 100644
@@ -844,6 +844,10 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
+PKG_CHECK_MODULES([libdrm], [libdrm],
+	[CPPFLAGS="$CPPFLAGS $libdrm_CFLAGS"],
+	[CPPFLAGS="$CPPFLAGS -I/usr/include/drm"])
+
 if test "$arch" = mips && test "$no_create" != yes; then
 	mkdir -p linux/mips
 	if $srcdir/linux/mips/genstub.sh linux/mips; then
Signature · 9 lines
2.1.4


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/

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

#4 lore raw

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

Quoted 15 lines · Patrik Jakobsson

Use pkg-config to try to find libdrm. If that fails use the standard include directory for kernel drm headers in /usr/include/drm.

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

---
 configure.ac | 4 ++++
 1 file changed, 4 insertions(+)
configure.ac +0 -0
index bb8bf46..aa63af7 100644

configure.ac fi · line 849

Quoted 6 lines
configure.ac +3 -0
@@ -844,6 +844,10 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
+PKG_CHECK_MODULES([libdrm], [libdrm],
+	[CPPFLAGS="$CPPFLAGS $libdrm_CFLAGS"],
+	[CPPFLAGS="$CPPFLAGS -I/usr/include/drm"])

yikes, no, this is a really really bad idea. it should read:
PKG_CHECK_MODULES([LIBDRM], [libdrm],

	[CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"], [:])

-mike

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

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

#5 lore raw

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

Quoted 19 lines · Mike Frysinger
Quoted 18 lines · Patrik Jakobsson

Use pkg-config to try to find libdrm. If that fails use the standard include directory for kernel drm headers in /usr/include/drm.

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

---
 configure.ac | 4 ++++
 1 file changed, 4 insertions(+)
configure.ac +0 -0
index bb8bf46..aa63af7 100644
@@ -844,6 +844,10 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
Quoted 7 lines

configure.ac fi · line 849

Quoted 3 lines
configure.ac +3 -0
+PKG_CHECK_MODULES([libdrm], [libdrm],
+	[CPPFLAGS="$CPPFLAGS $libdrm_CFLAGS"],
+	[CPPFLAGS="$CPPFLAGS -I/usr/include/drm"])

yikes, no, this is a really really bad idea. it should read:
PKG_CHECK_MODULES([LIBDRM], [libdrm],

	[CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"], [:])

Why [:] ? Wouldn't [] suffice?

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): 20150723104417.GA21575-u2l5PoMzF/[email protected]

#7 lore raw

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

Quoted 28 lines · Dmitry V. Levin
Quoted 19 lines · Mike Frysinger
Quoted 18 lines · Patrik Jakobsson

Use pkg-config to try to find libdrm. If that fails use the standard include directory for kernel drm headers in /usr/include/drm.

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

---
 configure.ac | 4 ++++
 1 file changed, 4 insertions(+)
configure.ac +0 -0
index bb8bf46..aa63af7 100644
@@ -844,6 +844,10 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
Quoted 7 lines

configure.ac fi · line 849

Quoted 3 lines
configure.ac +3 -0
+PKG_CHECK_MODULES([libdrm], [libdrm],
+	[CPPFLAGS="$CPPFLAGS $libdrm_CFLAGS"],
+	[CPPFLAGS="$CPPFLAGS -I/usr/include/drm"])

yikes, no, this is a really really bad idea. it should read:
PKG_CHECK_MODULES([LIBDRM], [libdrm],

	[CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"], [:])
Quoted 1 line

Why [:] ? Wouldn't [] suffice?

probably ... force of habit after being bitten by m4 macros that did not expect to expand empty code and thus lead to shell errors (include macros by autotools projects). i.e. if the m4 looked something like:

	if ...check if pkg is available...; then
		$3
	else
		$4
	fi

then the generated configure script would have syntax errors. -mike

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

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

#8 lore raw

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

In reply to Mike Frysinger
Quoted 19 lines · Mike Frysinger
Quoted 18 lines · Patrik Jakobsson

Use pkg-config to try to find libdrm. If that fails use the standard include directory for kernel drm headers in /usr/include/drm.

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

---
 configure.ac | 4 ++++
 1 file changed, 4 insertions(+)
configure.ac +0 -0
index bb8bf46..aa63af7 100644
@@ -844,6 +844,10 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
Quoted 8 lines

configure.ac fi · line 849

Quoted 3 lines
configure.ac +3 -0
+PKG_CHECK_MODULES([libdrm], [libdrm],
+	[CPPFLAGS="$CPPFLAGS $libdrm_CFLAGS"],
+	[CPPFLAGS="$CPPFLAGS -I/usr/include/drm"])

yikes, no, this is a really really bad idea. it should read:
PKG_CHECK_MODULES([LIBDRM], [libdrm],

	[CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"], [:])

-mike

Hi Mike

Please include me in CC.

I take it you don't want me to fallback on kernel headers and skip compiling with drm support if libdrm is not available?

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

#9 lore raw

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

Quoted 28 lines · Patrik Jakobsson
Quoted 19 lines · Mike Frysinger
Quoted 18 lines · Patrik Jakobsson

Use pkg-config to try to find libdrm. If that fails use the standard include directory for kernel drm headers in /usr/include/drm.

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

---
 configure.ac | 4 ++++
 1 file changed, 4 insertions(+)
configure.ac +0 -0
index bb8bf46..aa63af7 100644
@@ -844,6 +844,10 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
Quoted 7 lines

configure.ac fi · line 849

Quoted 3 lines
configure.ac +3 -0
+PKG_CHECK_MODULES([libdrm], [libdrm],
+	[CPPFLAGS="$CPPFLAGS $libdrm_CFLAGS"],
+	[CPPFLAGS="$CPPFLAGS -I/usr/include/drm"])

yikes, no, this is a really really bad idea. it should read:
PKG_CHECK_MODULES([LIBDRM], [libdrm],

	[CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"], [:])
Quoted 2 lines

I take it you don't want me to fallback on kernel headers and skip compiling with drm support if libdrm is not available?

you cannot hardcode any path at all. if the kernel headers provide all of the defines/structs that you need, then just include them directly via #include <drm/xxx.h>.
-mike

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

#10 lore raw

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

Quoted 29 lines · Mike Frysinger
Quoted 28 lines · Patrik Jakobsson
Quoted 26 lines · Mike Frysinger
Quoted 15 lines · Patrik Jakobsson

Use pkg-config to try to find libdrm. If that fails use the standard include directory for kernel drm headers in /usr/include/drm.

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

---
 configure.ac | 4 ++++
 1 file changed, 4 insertions(+)
configure.ac +0 -0
index bb8bf46..aa63af7 100644

configure.ac fi · line 849

Quoted 6 lines
configure.ac +3 -0
@@ -844,6 +844,10 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
+PKG_CHECK_MODULES([libdrm], [libdrm],
+	[CPPFLAGS="$CPPFLAGS $libdrm_CFLAGS"],
+	[CPPFLAGS="$CPPFLAGS -I/usr/include/drm"])

yikes, no, this is a really really bad idea. it should read:
PKG_CHECK_MODULES([LIBDRM], [libdrm],

	[CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"], [:])
Quoted 7 lines
Quoted 2 lines

I take it you don't want me to fallback on kernel headers and skip compiling with drm support if libdrm is not available?

you cannot hardcode any path at all. if the kernel headers provide all of the defines/structs that you need, then just include them directly via #include <drm/xxx.h>.
-mike

The prefered "drm way" is to always use the libdrm headers and never the kernel headers. I know this is breaking the rules but it's what we got to work with. Some distros give you the kernel version and others the libdrm version. The kernel version is wrong and libdrm patches this up since we're not allowed to break the userspace interface. I think the safest way would be to only compile drm support for strace if libdrm is present and ignore the kernel headers.

What do you think?

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

#11 lore raw

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

Quoted 38 lines · Patrik Jakobsson
Quoted 29 lines · Mike Frysinger
Quoted 28 lines · Patrik Jakobsson
Quoted 26 lines · Mike Frysinger
Quoted 15 lines · Patrik Jakobsson

Use pkg-config to try to find libdrm. If that fails use the standard include directory for kernel drm headers in /usr/include/drm.

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

---
 configure.ac | 4 ++++
 1 file changed, 4 insertions(+)
configure.ac +0 -0
index bb8bf46..aa63af7 100644

configure.ac fi · line 849

Quoted 6 lines
configure.ac +3 -0
@@ -844,6 +844,10 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
+PKG_CHECK_MODULES([libdrm], [libdrm],
+	[CPPFLAGS="$CPPFLAGS $libdrm_CFLAGS"],
+	[CPPFLAGS="$CPPFLAGS -I/usr/include/drm"])

yikes, no, this is a really really bad idea. it should read:
PKG_CHECK_MODULES([LIBDRM], [libdrm],

	[CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"], [:])
Quoted 7 lines
Quoted 2 lines

I take it you don't want me to fallback on kernel headers and skip compiling with drm support if libdrm is not available?

you cannot hardcode any path at all. if the kernel headers provide all of the defines/structs that you need, then just include them directly via #include <drm/xxx.h>.
-mike

Quoted 6 lines

The prefered "drm way" is to always use the libdrm headers and never the kernel headers. I know this is breaking the rules but it's what we got to work with. Some distros give you the kernel version and others the libdrm version. The kernel version is wrong and libdrm patches this up since we're not allowed to break the userspace interface. I think the safest way would be to only compile drm support for strace if libdrm is present and ignore the kernel headers.

Unlike most of userspace, strace attempts to show the picture as it's seen from the kernel perspective. Sometimes it forces us to use kernel headers instead of headers provided by libc and other libraries.

If kernel itself uses uapi/drm, it should be safe for strace to use it as well. I suppose the check could be written this way:

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 defined HAVE_DRM_H || defined HAVE_DRM_DRM_H

# ifdef HAVE_DRM_H
#  include <drm.h>
# else
#  include <drm/drm.h>
# endif

[rest of drm.c]

#endif /* HAVE_DRM_H || HAVE_DRM_DRM_H */

Signature · 1 line
ldv

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

#12 lore raw

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

Quoted 67 lines · Dmitry V. Levin
Quoted 38 lines · Patrik Jakobsson
Quoted 29 lines · Mike Frysinger
Quoted 28 lines · Patrik Jakobsson
Quoted 26 lines · Mike Frysinger
Quoted 15 lines · Patrik Jakobsson

Use pkg-config to try to find libdrm. If that fails use the standard include directory for kernel drm headers in /usr/include/drm.

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

---
 configure.ac | 4 ++++
 1 file changed, 4 insertions(+)
configure.ac +0 -0
index bb8bf46..aa63af7 100644

configure.ac fi · line 849

Quoted 6 lines
configure.ac +3 -0
@@ -844,6 +844,10 @@ fi
 AM_CONDITIONAL([USE_LIBUNWIND], [test "x$use_libunwind" = xyes])
 AC_MSG_RESULT([$use_libunwind])
 
+PKG_CHECK_MODULES([libdrm], [libdrm],
+     [CPPFLAGS="$CPPFLAGS $libdrm_CFLAGS"],
+     [CPPFLAGS="$CPPFLAGS -I/usr/include/drm"])

yikes, no, this is a really really bad idea. it should read:
PKG_CHECK_MODULES([LIBDRM], [libdrm],

        [CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"], [:])
Quoted 7 lines
Quoted 2 lines

I take it you don't want me to fallback on kernel headers and skip compiling with drm support if libdrm is not available?

you cannot hardcode any path at all. if the kernel headers provide all of the defines/structs that you need, then just include them directly via #include <drm/xxx.h>.
-mike

Quoted 6 lines

The prefered "drm way" is to always use the libdrm headers and never the kernel headers. I know this is breaking the rules but it's what we got to work with. Some distros give you the kernel version and others the libdrm version. The kernel version is wrong and libdrm patches this up since we're not allowed to break the userspace interface. I think the safest way would be to only compile drm support for strace if libdrm is present and ignore the kernel headers.

Unlike most of userspace, strace attempts to show the picture as it's seen from the kernel perspective. Sometimes it forces us to use kernel headers instead of headers provided by libc and other libraries.

If kernel itself uses uapi/drm, it should be safe for strace to use it as well. I suppose the check could be written this way:

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 defined HAVE_DRM_H || defined HAVE_DRM_DRM_H

# ifdef HAVE_DRM_H
#  include <drm.h>
# else
#  include <drm/drm.h>
# endif
Quoted 3 lines

[rest of drm.c]

#endif /* HAVE_DRM_H || HAVE_DRM_DRM_H */

That would be even better. We'll get some warnings when including the kernel version of drm.h but I guess we can live with that.

Will soon send out a new version of the patches.

Thanks
Patrik

Quoted 10 lines

--
ldv

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

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

#13 lore raw

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

In reply to a message not in the archive

This field can be used by the decode functions of a syscall. The main usecase for now is to allow storing the driver name for drm devices across the lifetime of a trace control block. This allows us to do the driver identification once and reuse the information in all the decode stages of the ioctl.

* defs.h: Add private data field in struct tcb

---
 defs.h | 7 +++++++
 1 file changed, 7 insertions(+)
defs.h +7 -0
index c02f810..5b0670e 100644
@@ -266,6 +266,13 @@ struct tcb {
 	int u_error;		/* Error code */
 	long scno;		/* System call number */
 	long u_arg[MAX_ARGS];	/* System call arguments */
+
+	/*
+	 * Private data for the decoding functions of the syscall. TCB core does
+	 * _not_ handle allocation / deallocation of this data.
+	 */
+	void *priv_data;
+
 #if defined(LINUX_MIPSN32) || defined(X32)
 	long long ext_arg[MAX_ARGS];
 	long long u_lrval;	/* long long return value */
Signature · 9 lines
2.1.4


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
#14 lore raw

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

In reply to a message not in the archive

* Makefile.am: Add compilation of drm.c
* defs.h: Declarations of drm functions
* drm.c: Utility functions for drm driver detection
* io.c: Dispatch drm ioctls
* ioctl.c: Distpatch generic and driver specific ioctls

---
 Makefile.am |   1 +
 defs.h      |   4 ++-
 drm.c       | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 io.c        |   2 +-
 ioctl.c     |   6 +++-
 5 files changed, 118 insertions(+), 3 deletions(-)
 create mode 100644 drm.c
Makefile.am +1 -0
index e2a0f74..99382bd 100644
@@ -41,6 +41,7 @@ strace_SOURCES =	\
 	count.c		\
 	desc.c		\
 	dirent.c	\
+	drm.c		\
 	evdev.c		\
 	execve.c	\
 	exit.c		\
defs.h +3 -1
index 5b0670e..63e4585 100644
@@ -573,8 +573,10 @@ extern const struct_ioctlent *ioctl_lookup(const unsigned int);
 extern const struct_ioctlent *ioctl_next_match(const struct_ioctlent *);
 extern void ioctl_print_code(const unsigned int);
 extern int ioctl_decode(struct tcb *, const unsigned int, long);
-extern int ioctl_decode_command_number(const unsigned int);
+extern int ioctl_decode_command_number(struct tcb *, const unsigned int);
 extern int block_ioctl(struct tcb *, const unsigned int, long);
+extern int drm_decode_number(struct tcb *tcp, unsigned int arg);
+extern int drm_ioctl(struct tcb *, const unsigned int, long);
 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 +108 -0

108 lines not on this page · raw message

io.c +1 -1
index 30ed578..6810a45 100644
@@ -391,7 +391,7 @@ SYS_FUNC(ioctl)
 	if (entering(tcp)) {
 		printfd(tcp, tcp->u_arg[0]);
 		tprints(", ");
-		if (!ioctl_decode_command_number(tcp->u_arg[1])) {
+		if (!ioctl_decode_command_number(tcp, tcp->u_arg[1])) {
 			iop = ioctl_lookup(tcp->u_arg[1]);
 			if (iop) {
 				tprints(iop->symbol);
ioctl.c +5 -1
index c67d048..0b3dd3f 100644
@@ -182,7 +182,7 @@ hiddev_decode_number(unsigned int arg)
 }
 
 int
-ioctl_decode_command_number(unsigned int arg)
+ioctl_decode_command_number(struct tcb *tcp, unsigned int arg)
 {
 	switch (_IOC_TYPE(arg)) {
 		case 'E':
@@ -204,6 +204,8 @@ ioctl_decode_command_number(unsigned int arg)
 				return 1;
 			}
 			return 0;
+		case 'd':
+			return drm_decode_number(tcp, arg);
 		case 'j':
 			if (_IOC_DIR(arg) == _IOC_READ && _IOC_NR(arg) == 0x13) {
 				tprintf("JSIOCGNAME(%u)", _IOC_SIZE(arg));
@@ -243,6 +245,8 @@ ioctl_decode(struct tcb *tcp, unsigned int code, long arg)
 	case 0x22:
 		return scsi_ioctl(tcp, code, arg);
 #endif
+	case 'd':
+		return drm_ioctl(tcp, code, arg);
 	case 'L':
 		return loop_ioctl(tcp, code, arg);
 	case 'M':
Signature · 9 lines
2.1.4


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
#15 lore raw

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

On Wed, Jul 01, 2015 at 02:52:45PM +0200, Patrik Jakobsson wrote:
[...]

defs.h struct tcb { · line 275

Quoted 13 lines
defs.h +7 -0
@@ -266,6 +266,13 @@ struct tcb {
 	int u_error;		/* Error code */
 	long scno;		/* System call number */
 	long u_arg[MAX_ARGS];	/* System call arguments */
+
+	/*
+	 * Private data for the decoding functions of the syscall. TCB core does
+	 * _not_ handle allocation / deallocation of this data.
+	 */
+	void *priv_data;
+

This will result to memory leaks if droptcb() is called before the syscall parser that allocated memory had a chance to deallocate it. As this data is no longer relevant after leaving trace_syscall_exiting(), I suggest to perform deallocation directly from trace_syscall_exiting.

This API could be made more flexible by adding another pointer - the function to be called to deallocate memory, e.g.

struct tcb {
	...
	void *priv_data;
	void (*free_priv_data)(void *);
	...
};
...
void
free_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;
	}
}
...
droptcb(struct tcb *tcp)
{
	...
	free_priv_data(tcp);
	...
}
...
trace_syscall_exiting(struct tcb *tcp)
{
	...
 ret:
	free_priv_data(tcp);
	...
}

[...]

Quoted 5 lines · Patrik Jakobsson
defs.h +0 -0
 * Makefile.am: Add compilation of drm.c
 * defs.h: Declarations of drm functions
 * drm.c: Utility functions for drm driver detection

* io.c: Dispatch drm ioctls
* ioctl.c: Distpatch generic and driver specific ioctls

This is not quite a GNU style changelog entry. Please have a look at
http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html
and examples in strace.git history.

[...]

defs.h

Quoted 4 lines
defs.h +4 -0
+#include "defs.h"
+
+#include <drm.h>
+#include <linux/limits.h>

Please include <sys/param.h> instead of <linux/limits.h>.

Quoted 24 lines
defs.h +24 -0
+#define DRM_MAX_NAME_LEN 128
+
+struct drm_ioctl_priv {
+	char name[DRM_MAX_NAME_LEN];
+};
+
+inline int drm_is_priv(const unsigned int num)
+{
+	return (_IOC_NR(num) >= DRM_COMMAND_BASE &&
+		_IOC_NR(num) < DRM_COMMAND_END);
+}
+
+static int drm_get_driver_name(struct tcb *tcp, char *name, size_t bufsize)
+{
+	char path[PATH_MAX];
+	char link[PATH_MAX];
+	int ret;
+
+	ret = getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1);
+	if (ret < 0)
+		return ret;
+
+	snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver",
+		 basename(path));

defs.h

Quoted 10 lines
defs.h +10 -0
+
+	ret = readlink(link, path, PATH_MAX - 1);
+	if (ret < 0)
+		return ret;
+
+	path[ret] = '\0';
+	strncpy(name, basename(path), bufsize);
+
+	return 0;
+}

I think this is getting too complicated. This function could just return strdup(basename(path)) or NULL in case of any error:

static char *
drm_get_driver_name(struct tcb *tcp, const char *name)

{
	char path[PATH_MAX];
	char link[PATH_MAX];
	int ret;

	if (getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1) < 0)
		return NULL;

	if (snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver",
		     basename(path)) >= PATH_MAX)
		return NULL;

	ret = readlink(link, path, PATH_MAX - 1);
	if (ret < 0)
		return NULL;

	path[ret] = '\0';
	return strdup(basename(path));
}

defs.h

Quoted 12 lines
defs.h +12 -0
+
+int drm_is_driver(struct tcb *tcp, const char *name)
+{
+	struct drm_ioctl_priv *priv;
+	int ret;
+
+	/*
+	 * If no private data is allocated we are detecting the driver name for
+	 * the first time and must resolve it.
+	 */
+	if (tcp->priv_data == NULL) {
+		tcp->priv_data = xcalloc(1, sizeof(struct drm_ioctl_priv));

xcalloc shouldn't be used if a potential memory allocation error is not fatal. In a parser that performs verbose syscall decoding no memory allocation error is fatal.

defs.h

Quoted 10 lines
defs.h +10 -0
+		priv = tcp->priv_data;
+
+		ret = drm_get_driver_name(tcp, priv->name, DRM_MAX_NAME_LEN);
+		if (ret)
+			return 0;
+	}
+
+	priv = tcp->priv_data;
+
+	return strncmp(name, priv->name, DRM_MAX_NAME_LEN) == 0;

Then with priv_data+free_priv_data interface this would looks smth like

	...
	if (!tcp->priv_data) {
		tcp->priv_data = drm_get_driver_name(tcp, name);
		if (tcp->priv_data) {
			tcp->free_priv_data = free;
		} else {
			tcp->priv_data = (void *) "";
			tcp->free_priv_data = NULL;
		}
	}
	return !strcmp(name, (char *) tcp->priv_data);

defs.h

Quoted 3 lines
defs.h +3 -0
+}
+
+int drm_decode_number(struct tcb *tcp, unsigned int arg)

This is an ioctl request code, let's consistently call it "code" to distinguish from its argument.

[...]

ioctl.c hiddev_decode_number(unsigned int arg) · line 185

Quoted 8 lines
ioctl.c +1 -1
@@ -182,7 +182,7 @@ hiddev_decode_number(unsigned int arg)
 }
 
 int
-ioctl_decode_command_number(unsigned int arg)
+ioctl_decode_command_number(struct tcb *tcp, unsigned int arg)

I've already changed ioctl_decode_command_number's signature:
struct tcb * is already there and "arg" is now called "code".

Signature · 1 line
ldv

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

#16 lore raw

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

Quoted 57 lines · Dmitry V. Levin

On Wed, Jul 01, 2015 at 02:52:45PM +0200, Patrik Jakobsson wrote:
[...]

defs.h struct tcb { · line 275

Quoted 13 lines
defs.h +7 -0
@@ -266,6 +266,13 @@ struct tcb {
 	int u_error;		/* Error code */
 	long scno;		/* System call number */
 	long u_arg[MAX_ARGS];	/* System call arguments */
+
+	/*
+	 * Private data for the decoding functions of the syscall. TCB core does
+	 * _not_ handle allocation / deallocation of this data.
+	 */
+	void *priv_data;
+

This will result to memory leaks if droptcb() is called before the syscall parser that allocated memory had a chance to deallocate it. As this data is no longer relevant after leaving trace_syscall_exiting(), I suggest to perform deallocation directly from trace_syscall_exiting.

This API could be made more flexible by adding another pointer - the function to be called to deallocate memory, e.g.

struct tcb {
	...
	void *priv_data;
	void (*free_priv_data)(void *);
	...
};
...
void
free_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;
	}
}
...
droptcb(struct tcb *tcp)
{
	...
	free_priv_data(tcp);
	...
}
...
trace_syscall_exiting(struct tcb *tcp)
{
	...
 ret:
	free_priv_data(tcp);
	...
}
Quoted 2 lines

[...]
On Wed, Jul 01, 2015 at 02:52:46PM +0200, Patrik Jakobsson wrote:

Yes, that's more robust. I was afraid it would be too intrusive.

Quoted 11 lines
Quoted 5 lines
defs.h +0 -0
 * Makefile.am: Add compilation of drm.c
 * defs.h: Declarations of drm functions
 * drm.c: Utility functions for drm driver detection

* io.c: Dispatch drm ioctls
* ioctl.c: Distpatch generic and driver specific ioctls

This is not quite a GNU style changelog entry. Please have a look at
http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html
and examples in strace.git history.

[...]

I'll get that sorted out.

Quoted 6 lines

defs.h

Quoted 4 lines
defs.h +4 -0
+#include "defs.h"
+
+#include <drm.h>
+#include <linux/limits.h>

Please include <sys/param.h> instead of <linux/limits.h>.

Yup

Quoted 52 lines
Quoted 24 lines
defs.h +24 -0
+#define DRM_MAX_NAME_LEN 128
+
+struct drm_ioctl_priv {
+	char name[DRM_MAX_NAME_LEN];
+};
+
+inline int drm_is_priv(const unsigned int num)
+{
+	return (_IOC_NR(num) >= DRM_COMMAND_BASE &&
+		_IOC_NR(num) < DRM_COMMAND_END);
+}
+
+static int drm_get_driver_name(struct tcb *tcp, char *name, size_t bufsize)
+{
+	char path[PATH_MAX];
+	char link[PATH_MAX];
+	int ret;
+
+	ret = getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1);
+	if (ret < 0)
+		return ret;
+
+	snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver",
+		 basename(path));

defs.h

Quoted 10 lines
defs.h +10 -0
+
+	ret = readlink(link, path, PATH_MAX - 1);
+	if (ret < 0)
+		return ret;
+
+	path[ret] = '\0';
+	strncpy(name, basename(path), bufsize);
+
+	return 0;
+}

I think this is getting too complicated. This function could just return strdup(basename(path)) or NULL in case of any error:

static char *
drm_get_driver_name(struct tcb *tcp, const char *name)

{
	char path[PATH_MAX];
	char link[PATH_MAX];
	int ret;

	if (getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1) < 0)
		return NULL;

	if (snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver",
		     basename(path)) >= PATH_MAX)
		return NULL;
Quoted 8 lines
	ret = readlink(link, path, PATH_MAX - 1);
	if (ret < 0)
		return NULL;

	path[ret] = '\0';
	return strdup(basename(path));
}

That's nicer

Quoted 8 lines
Quoted 8 lines
defs.h +8 -0
+
+int drm_is_driver(struct tcb *tcp, const char *name)
+{
+	struct drm_ioctl_priv *priv;
+	int ret;
+
+	/*
+	 * If no private data is allocated we are detecting the driver name for
Quoted 8 lines

defs.h

Quoted 4 lines
defs.h +4 -0
+	 * the first time and must resolve it.
+	 */
+	if (tcp->priv_data == NULL) {
+		tcp->priv_data = xcalloc(1, sizeof(struct drm_ioctl_priv));

xcalloc shouldn't be used if a potential memory allocation error is not fatal. In a parser that performs verbose syscall decoding no memory allocation error is fatal.

Ok

Quoted 37 lines

defs.h

Quoted 10 lines
defs.h +10 -0
+		priv = tcp->priv_data;
+
+		ret = drm_get_driver_name(tcp, priv->name, DRM_MAX_NAME_LEN);
+		if (ret)
+			return 0;
+	}
+
+	priv = tcp->priv_data;
+
+	return strncmp(name, priv->name, DRM_MAX_NAME_LEN) == 0;

Then with priv_data+free_priv_data interface this would looks smth like

	...
	if (!tcp->priv_data) {
		tcp->priv_data = drm_get_driver_name(tcp, name);
		if (tcp->priv_data) {
			tcp->free_priv_data = free;
		} else {
			tcp->priv_data = (void *) "";
			tcp->free_priv_data = NULL;
		}
	}
	return !strcmp(name, (char *) tcp->priv_data);

defs.h

Quoted 3 lines
defs.h +3 -0
+}
+
+int drm_decode_number(struct tcb *tcp, unsigned int arg)

This is an ioctl request code, let's consistently call it "code" to distinguish from its argument.

[...]

Quoted 5 lines
ioctl.c +0 -0
@@ -182,7 +182,7 @@ hiddev_decode_number(unsigned int arg)
 }
 
Quoted 10 lines

ioctl.c hiddev_decode_number(unsigned int arg) · line 185

Quoted 3 lines
ioctl.c +1 -1
 int
-ioctl_decode_command_number(unsigned int arg)
+ioctl_decode_command_number(struct tcb *tcp, unsigned int arg)

I've already changed ioctl_decode_command_number's signature:
struct tcb * is already there and "arg" is now called "code".

Signature · 1 line
ldv

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

#17 lore raw

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

In reply to Patrik Jakobsson

There are more ioctls to add but the ones in this patch are most commonly used.

* Makefile.am: Add compilation of drm_i915.c
* drm.c: Dispatch i915 ioctls
* drm_i915.c: Decode DRM_IOCTL_I915_GETPARAM
* drm_i915.c: Decode DRM_IOCTL_I915_SETPARAM
* drm_i915.c: Decode DRM_IOCTL_I915_GEM_EXECBUFFER2
* drm_i915.c: Decode DRM_IOCTL_I915_GEM_BUSY
* drm_i915.c: Decode DRM_IOCTL_I915_GEM_CREATE
* drm_i915.c: Decode DRM_IOCTL_I915_GEM_PREAD
* drm_i915.c: Decode DRM_IOCTL_I915_GEM_PWRITE
* drm_i915.c: Decode DRM_IOCTL_I915_GEM_MMAP
* drm_i915.c: Decode DRM_IOCTL_I915_GEM_MMAP_GTT
* drm_i915.c: Decode DRM_IOCTL_I915_SET_DOMAIN
* drm_i915.c: Decode DRM_IOCTL_I915_MADVISE
* drm_i915.c: Decode DRM_IOCTL_I915_GET_TILING
* drm_i915.c: Decode DRM_IOCTL_I915_SET_TILING
* drm_i915.c: Decode DRM_IOCTL_I915_USERPTR
* xlat/drm_i915_getparams.in: List GETPARAM parameters
* xlat/drm_i915_setparams.in: List SETPARAM parameters
* xlat/drm_i915_ioctls.in: List i915 ioctls

---
 Makefile.am                |   1 +
 drm.c                      |  18 ++-
 drm_i915.c                 | 332 +++++++++++++++++++++++++++++++++++++++++++++
 xlat/drm_i915_getparams.in |  28 ++++
 xlat/drm_i915_ioctls.in    |  51 +++++++
 xlat/drm_i915_setparams.in |   4 +
 6 files changed, 433 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 99382bd..aa27e0c 100644
@@ -42,6 +42,7 @@ strace_SOURCES =	\
 	desc.c		\
 	dirent.c	\
 	drm.c		\
+	drm_i915.c	\
 	evdev.c		\
 	execve.c	\
 	exit.c		\
drm.c +17 -1
index 61df09f..846ea4d 100644
@@ -35,6 +35,9 @@
 
 #define DRM_MAX_NAME_LEN 128
 
+extern int drm_i915_decode_number(struct tcb *tcp, unsigned int arg);
+extern int drm_i915_ioctl(struct tcb *tcp, const unsigned int code, long arg);
+
 struct drm_ioctl_priv {
 	char name[DRM_MAX_NAME_LEN];
 };
@@ -93,16 +96,29 @@ int drm_is_driver(struct tcb *tcp, const char *name)
 
 int drm_decode_number(struct tcb *tcp, unsigned int arg)
 {
+	if (drm_is_priv(tcp->u_arg[1])) {
+		if (verbose(tcp) && drm_is_driver(tcp, "i915"))
+			return drm_i915_decode_number(tcp, arg);
+	}
+
 	return 0;
 }
 
 int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
+	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);
+	}
+
 	/* Free any allocated private data */
 	if (exiting(tcp) && tcp->priv_data != NULL) {
 		free(tcp->priv_data);
 		tcp->priv_data = NULL;
 	}
 
-	return 0;
+	return ret;
 }
drm_i915.c new file +332 -0

332 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
#18 lore raw

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

On Wed, Jul 01, 2015 at 02:52:47PM +0200, Patrik Jakobsson wrote:
[...]

drm.c line 38

Quoted 7 lines
drm.c +1 -0
@@ -35,6 +35,9 @@
 
 #define DRM_MAX_NAME_LEN 128
 
+extern int drm_i915_decode_number(struct tcb *tcp, unsigned int arg);

Please rename "arg" to "code", and ...

drm.c line 39

Quoted 1 line
drm.c +1 -0
+extern int drm_i915_ioctl(struct tcb *tcp, const unsigned int code, long arg);

... move both declarations to defs.h to make them visible also in the file where these functions are defined.

[...]

Quoted 5 lines
drm.c +5 -0
+static int i915_setparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_setparam param;
+
+	if (entering(tcp)) {

drm.c

Quoted 10 lines
drm.c +10 -0
+		if (umove(tcp, arg, &param))
+			return 0;
+
+		tprints(", {param=");
+		printxval(drm_i915_setparams, param.param, "I915_PARAM_???");
+		tprintf(", value=%d}", param.value);
+	}
+
+	return 1;
+}

In this and most of other parsers of _IOC_WRITE ioctls added by this and the next patches, any error in parser that leads to "return 0" will result to disabled "arg" decoding, including the fallback decoding performed by sys_ioctl.

Maybe it's time to deal with this issue in a more generic way.

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): 20150703003609.GB29080-u2l5PoMzF/[email protected]

#20 lore raw

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

Quoted 39 lines · Dmitry V. Levin

On Wed, Jul 01, 2015 at 02:52:47PM +0200, Patrik Jakobsson wrote:
[...]

drm.c line 38

Quoted 7 lines
drm.c +1 -0
@@ -35,6 +35,9 @@
 
 #define DRM_MAX_NAME_LEN 128
 
+extern int drm_i915_decode_number(struct tcb *tcp, unsigned int arg);

Please rename "arg" to "code", and ...

drm.c line 39

Quoted 1 line
drm.c +1 -0
+extern int drm_i915_ioctl(struct tcb *tcp, const unsigned int code, long arg);

... move both declarations to defs.h to make them visible also in the file where these functions are defined.

[...]

Quoted 5 lines
drm.c +5 -0
+static int i915_setparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_setparam param;
+
+	if (entering(tcp)) {

drm.c

Quoted 10 lines
drm.c +10 -0
+		if (umove(tcp, arg, &param))
+			return 0;
+
+		tprints(", {param=");
+		printxval(drm_i915_setparams, param.param, "I915_PARAM_???");
+		tprintf(", value=%d}", param.value);
+	}
+
+	return 1;
+}

In this and most of other parsers of _IOC_WRITE ioctls added by this and the next patches, any error in parser that leads to "return 0" will result to disabled "arg" decoding, including the fallback decoding performed by sys_ioctl.

Quoted 2 lines

Maybe it's time to deal with this issue in a more generic way.

Yes, I'm thinking SYS_FUNC(ioctl) could be improved. But on the other hand how likely is it that we fail in umove and what chance do we have to recover from that anyway? All I can think of is OOM.

Quoted 3 lines
Signature · 2 lines
-- 
ldv

------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/

#21 lore raw

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

Quoted 40 lines · On Mon, 6 Jul 2015 12:35:52 +0200 Patrik Jakobsson…
Quoted 39 lines · Dmitry V. Levin

On Wed, Jul 01, 2015 at 02:52:47PM +0200, Patrik Jakobsson wrote:
[...]

drm.c line 38

Quoted 7 lines
drm.c +1 -0
@@ -35,6 +35,9 @@
 
 #define DRM_MAX_NAME_LEN 128
 
+extern int drm_i915_decode_number(struct tcb *tcp, unsigned int arg);

Please rename "arg" to "code", and ...

drm.c line 39

Quoted 1 line
drm.c +1 -0
+extern int drm_i915_ioctl(struct tcb *tcp, const unsigned int code, long arg);

... move both declarations to defs.h to make them visible also in the file where these functions are defined.

[...]

Quoted 5 lines
drm.c +5 -0
+static int i915_setparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_setparam param;
+
+	if (entering(tcp)) {

drm.c

Quoted 10 lines
drm.c +10 -0
+		if (umove(tcp, arg, &param))
+			return 0;
+
+		tprints(", {param=");
+		printxval(drm_i915_setparams, param.param, "I915_PARAM_???");
+		tprintf(", value=%d}", param.value);
+	}
+
+	return 1;
+}

In this and most of other parsers of _IOC_WRITE ioctls added by this and the next patches, any error in parser that leads to "return 0" will result to disabled "arg" decoding, including the fallback decoding performed by sys_ioctl.

Quoted 6 lines
Quoted 2 lines

Maybe it's time to deal with this issue in a more generic way.

Yes, I'm thinking SYS_FUNC(ioctl) could be improved. But on the other hand how likely is it that we fail in umove and what chance do we have to recover from that anyway? All I can think of is OOM.

umove() can fail in multiple ways. For example, if the memory is not valid in the tracee, umove() will fail.

Anyway, SYS_FUNC(ioctl) is a bit complicated, and the handling of the fallbacks on failure should be more generic.

Signature · 5 lines
Gabriel Laskar
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#22 lore raw

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

Quoted 44 lines · Gabriel Laskar
Quoted 43 lines · Patrik Jakobsson
Quoted 41 lines · Dmitry V. Levin

On Wed, Jul 01, 2015 at 02:52:47PM +0200, Patrik Jakobsson wrote:
[...]

drm.c line 38

Quoted 7 lines
drm.c +1 -0
@@ -35,6 +35,9 @@
 
 #define DRM_MAX_NAME_LEN 128
 
+extern int drm_i915_decode_number(struct tcb *tcp, unsigned int arg);

Please rename "arg" to "code", and ...

drm.c line 39

Quoted 1 line
drm.c +1 -0
+extern int drm_i915_ioctl(struct tcb *tcp, const unsigned int code, long arg);

... move both declarations to defs.h to make them visible also in the file where these functions are defined.

[...]

Quoted 5 lines
drm.c +5 -0
+static int i915_setparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_setparam param;
+
+	if (entering(tcp)) {

drm.c

Quoted 10 lines
drm.c +10 -0
+		if (umove(tcp, arg, &param))
+			return 0;
+
+		tprints(", {param=");
+		printxval(drm_i915_setparams, param.param, "I915_PARAM_???");
+		tprintf(", value=%d}", param.value);
+	}
+
+	return 1;
+}

In this and most of other parsers of _IOC_WRITE ioctls added by this and the next patches, any error in parser that leads to "return 0" will result to disabled "arg" decoding, including the fallback decoding performed by sys_ioctl.

Maybe it's time to deal with this issue in a more generic way.

Quoted 6 lines
Quoted 3 lines

Yes, I'm thinking SYS_FUNC(ioctl) could be improved. But on the other hand how likely is it that we fail in umove and what chance do we have to recover from that anyway? All I can think of is OOM.

umove() can fail in multiple ways. For example, if the memory is not valid in the tracee, umove() will fail.

Yes, this is the most likely cause for umove() to fail, and the most easily reproducible one, e.g. ioctl(-1, DRM_IOCTL_VERSION, 42);

Quoted 2 lines

Anyway, SYS_FUNC(ioctl) is a bit complicated, and the handling of the fallbacks on failure should be more generic.

What would be useful is a way for "on entering" parsers to return "done with decoding" information to their callers.

This could be implemented by or'ing return value in the current semantics with a flag with "done with decoding" meaning, e.g. RVAL_DONE.

If an ioctl parser returned RVAL_DONE, this would tell SYS_FUNC(ioctl) that the decoding is finished but fallback decoding is needed, while RVAL_DONE+1 would mean that the decoding is finished and no fallback decoding is needed.

Signature · 1 line
ldv

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

#23 lore raw

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

Quoted 49 lines · Dmitry V. Levin
Quoted 48 lines · Gabriel Laskar
Quoted 46 lines · Patrik Jakobsson
Quoted 39 lines · Dmitry V. Levin

On Wed, Jul 01, 2015 at 02:52:47PM +0200, Patrik Jakobsson wrote:
[...]

drm.c line 38

Quoted 7 lines
drm.c +1 -0
@@ -35,6 +35,9 @@
 
 #define DRM_MAX_NAME_LEN 128
 
+extern int drm_i915_decode_number(struct tcb *tcp, unsigned int arg);

Please rename "arg" to "code", and ...

drm.c line 39

Quoted 1 line
drm.c +1 -0
+extern int drm_i915_ioctl(struct tcb *tcp, const unsigned int code, long arg);

... move both declarations to defs.h to make them visible also in the file where these functions are defined.

[...]

Quoted 5 lines
drm.c +5 -0
+static int i915_setparam(struct tcb *tcp, const unsigned int code, long arg)
+{
+	struct drm_i915_setparam param;
+
+	if (entering(tcp)) {

drm.c

Quoted 10 lines
drm.c +10 -0
+		if (umove(tcp, arg, &param))
+			return 0;
+
+		tprints(", {param=");
+		printxval(drm_i915_setparams, param.param, "I915_PARAM_???");
+		tprintf(", value=%d}", param.value);
+	}
+
+	return 1;
+}

In this and most of other parsers of _IOC_WRITE ioctls added by this and the next patches, any error in parser that leads to "return 0" will result to disabled "arg" decoding, including the fallback decoding performed by sys_ioctl.

Quoted 2 lines

Maybe it's time to deal with this issue in a more generic way.

Yes, I'm thinking SYS_FUNC(ioctl) could be improved. But on the other hand how likely is it that we fail in umove and what chance do we have to recover from that anyway? All I can think of is OOM.

Quoted 6 lines
Quoted 2 lines

umove() can fail in multiple ways. For example, if the memory is not valid in the tracee, umove() will fail.

Yes, this is the most likely cause for umove() to fail, and the most easily reproducible one, e.g. ioctl(-1, DRM_IOCTL_VERSION, 42);

Yes, then we definitely need to handle those fails better

Quoted 7 lines
Quoted 3 lines

Anyway, SYS_FUNC(ioctl) is a bit complicated, and the handling of the fallbacks on failure should be more generic.

What would be useful is a way for "on entering" parsers to return "done with decoding" information to their callers.

Quoted 7 lines

This could be implemented by or'ing return value in the current semantics with a flag with "done with decoding" meaning, e.g. RVAL_DONE.

If an ioctl parser returned RVAL_DONE, this would tell SYS_FUNC(ioctl) that the decoding is finished but fallback decoding is needed, while RVAL_DONE+1 would mean that the decoding is finished and no fallback decoding is needed.

I like that idea but isn't the current return semantics already good enough for that? The problem right now is that we ignore the return value from ioctl_decode() "on entering". What we could do is:
1. Call ioctl_decode_number()
2. Call ioctl_decode() if above didn't fail
3. If any of 1 and/or 2 failed we do fallback

Quoted 4 lines
Signature · 2 lines
-- 
ldv

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

#24 lore raw

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

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

On Mon, Jul 06, 2015 at 04:40:24PM +0200, Gabriel Laskar wrote:

[...]

Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

Anyway, SYS_FUNC(ioctl) is a bit complicated, and the handling of the fallbacks on failure should be more generic.

What would be useful is a way for "on entering" parsers to return "done with decoding" information to their callers.

This could be implemented by or'ing return value in the current semantics with a flag with "done with decoding" meaning, e.g. RVAL_DONE.

Quoted 8 lines
Quoted 4 lines

If an ioctl parser returned RVAL_DONE, this would tell SYS_FUNC(ioctl) that the decoding is finished but fallback decoding is needed, while RVAL_DONE+1 would mean that the decoding is finished and no fallback decoding is needed.

I like that idea but isn't the current return semantics already good enough for that? The problem right now is that we ignore the return value from ioctl_decode() "on entering".

After commit v4.10-104-g204c2bc we no longer ignore the return value from ioctl_decode() "on entering".

Signature · 1 line
ldv

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

#25 lore raw

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

In reply to Patrik Jakobsson

This patch adds many of the DRM and KMS ioctls. The rest can be added as needed.

* drm.c: Decode DRM_IOCTL_VERSION
* drm.c: Decode DRM_IOCTL_GET_UNIQUE
* drm.c: Decode DRM_IOCTL_GET_MAGIC
* drm.c: Decode DRM_IOCTL_WAIT_VBLANK
* drm.c: Decode DRM_IOCTL_MODE_GETRESOURCES
* drm.c: Decode DRM_IOCTL_MODE_GETCRTC
* drm.c: Decode DRM_IOCTL_MODE_SETCRTC
* drm.c: Decode DRM_IOCTL_MODE_CURSOR
* drm.c: Decode DRM_IOCTL_MODE_CURSOR2
* drm.c: Decode DRM_IOCTL_MODE_GETGAMMA
* drm.c: Decode DRM_IOCTL_MODE_SETGAMMA
* drm.c: Decode DRM_IOCTL_MODE_GETENCODER
* drm.c: Decode DRM_IOCTL_MODE_GETCONNECTOR
* drm.c: Decode DRM_IOCTL_MODE_GETPROPERTY
* drm.c: Decode DRM_IOCTL_MODE_SETPROPERTY
* drm.c: Decode DRM_IOCTL_MODE_GETPROPBLOB
* drm.c: Decode DRM_IOCTL_MODE_GETFB
* drm.c: Decode DRM_IOCTL_MODE_ADDFB
* drm.c: Decode DRM_IOCTL_MODE_RMFB
* drm.c: Decode DRM_IOCTL_MODE_PAGE_FLIP
* drm.c: Decode DRM_IOCTL_DIRTYFB
* drm.c: Decode DRM_IOCTL_CREATE_DUMB
* drm.c: Decode DRM_IOCTL_MAP_DUMB
* drm.c: Decode DRM_IOCTL_DESTROY_DUMB
* drm.c: Decode DRM_IOCTL_GEM_CLOSE

---
 drm.c | 544 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 544 insertions(+)
drm.c +544 -0
index 846ea4d..c1d54f4 100644
@@ -104,6 +104,472 @@ int drm_decode_number(struct tcb *tcp, unsigned int arg)
 	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 0;
+
+		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 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 0;
+
+		tprintf(", {unique_len=%lu, unique=", unique.unique_len);
+		printstr(tcp, (long)unique.unique, unique.unique_len);
+		tprints("}");
+	}
+
+	return 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 0;
+
+		tprintf(", {magic=%u}", auth.magic);
+	}
+
+	return 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 0;
+
+	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 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 0;
+
+		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 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 0;
+
+	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 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 0;
+
+		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 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 0;
+
+		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 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 0;
+
+		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 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 0;
+
+		/* 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 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 0;
+
+		/* 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 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 0;
+
+	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 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 0;
+
+	/* 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 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 0;
+
+	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 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 0;
+
+		tprintf(", {value=%Lu, prop_id=%u, connector_id=%u}",
+			prop.value, prop.prop_id, prop.connector_id);
+	}
+
+	return 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 0;
+
+	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 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 0;
+
+	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 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 0;
+
+	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 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 0;
+
+		tprintf(", %u", handle);
+	}
+
+	return 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 0;
+
+		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 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 0;
+
+		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 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 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 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 0;
+
+	if (entering(tcp)) {
+		tprintf(", {handle=%u", dumb.handle);
+	} else if (exiting(tcp)) {
+		tprintf(", offset=%Lu}", dumb.offset);
+	}
+
+	return 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 0;
+
+		tprintf(", {handle=%u}", dumb.handle);
+	}
+
+	return 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 0;
+
+		tprintf(", {handle=%u}", close.handle);
+	}
+
+	return 1;
+}
+
 int drm_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
 	int ret = 0;
@@ -112,6 +578,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;
+		}
 	}
 
 	/* Free any allocated private data */
Signature · 6 lines
2.1.4

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