From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Dmitry V. Levin" Subject: Re: [PATCH 2/4] drm: Add dispatcher and driver identification for DRM Date: Sat, 13 Jun 2015 02:41:01 +0300 Message-ID: <20150612234101.GA17226@altlinux.org> References: <1433849204-4125-1-git-send-email-patrik.jakobsson@linux.intel.com> <1433849204-4125-3-git-send-email-patrik.jakobsson@linux.intel.com> <20150609221420.GA3210@altlinux.org> <20150610115233.GA18221@rpjakobs-ThinkCentre-E73> <20150610232659.GA19231@altlinux.org> <20150611141149.GB2939@rpjakobs-ThinkCentre-E73> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0645618706==" Return-path: Received: from pegasus3.altlinux.org (pegasus3.altlinux.org [194.107.17.103]) by gabe.freedesktop.org (Postfix) with ESMTP id 567726EB3F for ; Fri, 12 Jun 2015 16:41:05 -0700 (PDT) In-Reply-To: <20150611141149.GB2939@rpjakobs-ThinkCentre-E73> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To: strace-devel@lists.sourceforge.net Cc: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org --===============0645618706== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="FL5UXtIhxfXey3p5" Content-Disposition: inline --FL5UXtIhxfXey3p5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 11, 2015 at 04:11:49PM +0200, Patrik Jakobsson wrote: > On Thu, Jun 11, 2015 at 02:26:59AM +0300, Dmitry V. Levin wrote: > > On Wed, Jun 10, 2015 at 01:52:33PM +0200, Patrik Jakobsson wrote: > > > On Wed, Jun 10, 2015 at 01:14:20AM +0300, Dmitry V. Levin wrote: > > > > On Tue, Jun 09, 2015 at 01:26:42PM +0200, Patrik Jakobsson wrote: > > [...] > > > > > +#define DRM_MAX_NAME_LEN 128 > > > > > + > > > > > +inline int drm_is_priv(const unsigned int num) > > > > > +{ > > > > > + return (_IOC_NR(num) >=3D 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 =3D getfdpath(tcp, tcp->u_arg[0], path, PATH_MAX - 1); > > > > > + if (!ret) > > > > > + return ret; > > > > > + > > > > > + snprintf(link, PATH_MAX, "/sys/class/drm/%s/device/driver", > > > > > + basename(path)); > > > > > + > > > > > + ret =3D readlink(link, path, PATH_MAX - 1); > > > > > + if (ret < 0) > > > > > + return ret; > > > > > + > > > > > + path[ret] =3D '\0'; > > > > > + strncpy(name, basename(path), bufsize); > > > > > + > > > > > + return 0; > > > > > +} > > > > > + > > > > > +int drm_is_driver(struct tcb *tcp, const char *name) > > > > > +{ > > > > > + char drv[DRM_MAX_NAME_LEN]; > > > > > + int ret; > > > > > + > > > > > + ret =3D drm_get_driver_name(tcp, drv, DRM_MAX_NAME_LEN); > > > > > + if (ret) > > > > > + return 0; > > > > > + > > > > > + return strcmp(name, drv) =3D=3D 0; > > > > > +} > > > >=20 > > > > This interface will result to several getfdpath() calls per > > > > ioctl_decode(). If the only purpose of drm_is_driver() is to help = finding > > > > the most appropriate function, let's create a table of pairs > > > > {driver name, function} and pass this table to a function that will= do a > > > > single getfdpath() call, calculate the driver name, and choose the = right > > > > function from the table. > > >=20 > > > Yes I was thinking the same thing but it's a bit tricky. What I need = is: > > > fd -> path -> driver name. And fd -> path could change between ioctls= =2E It is not > > > a likely scenario but it's possible. I could get rid of the extra cal= l in > > > drm_decode_number() if I put it back in drm_ioctl as in my RFC. I cou= ld also > > > optimize path -> driver name with a table but I don't know how expens= ive those > > > calls actually are. Not sure what would be the best solution here. > >=20 > > drm_get_driver_name() is quite expensive as it does two readlink syscal= ls, > > so it should be called at most once per ioctl_decode(). > >=20 > > Another method to achieve this is to change drm_get_driver_name() to re= turn > > basename(path) instead of return code, so that drm_ioctl() would call it > > once and pass the result to strcmp calls: > >=20 > > int > > drm_ioctl(struct tcb *tcp, const unsigned int code, long arg) > > { > > if (verbose(tcp) && drm_is_priv(code)) { > > const char *driver =3D drm_get_driver_name(tcp); > > if (!driver) > > return 0; > > if (!strcmp(driver, "i915")) > > return drm_i915_ioctl(tcp, code, arg); > > } > > return 0; > > } >=20 > I misunderstood you. As you say, we shouldn't do a drm_get_driver_name() = more > than once (no matter how many drm drivers we are looking for) so your sug= gestion > above would fix that. I was thinking about how to get rid of the extra ca= ll in > drm_decode_number() (if we could somehow squash them together). But that = would > make things rather ugly. If ok with you we could just have the same appro= ach in > drm_decode_number() as above and live with the fact that we get two calls= to > drm_get_driver_name() per DRM device specific ioctl. One for drm_decode_n= umber() > and one for drm_ioctl(). This way we would end up with three drm_get_driver_name() calls per ioctl: twice on entering syscall and once on exiting. Maybe we could cache result of the first of these three calls somewhere? --=20 ldv --FL5UXtIhxfXey3p5 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlV7bg0ACgkQfKvmrJ41Nh6PEQCgvqhq9t6B7qmThNeXlcFga/lv z/kAnjspaq8kWgBmaRCfWQrQsXTUBdDY =8JEu -----END PGP SIGNATURE----- --FL5UXtIhxfXey3p5-- --===============0645618706== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KSW50ZWwtZ2Z4 IG1haWxpbmcgbGlzdApJbnRlbC1nZnhAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHA6Ly9saXN0 cy5mcmVlZGVza3RvcC5vcmcvbWFpbG1hbi9saXN0aW5mby9pbnRlbC1nZngK --===============0645618706==--