From patchwork Thu Aug 8 13:41:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 2841240 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 158549F294 for ; Thu, 8 Aug 2013 14:22:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0D257204E2 for ; Thu, 8 Aug 2013 14:22:24 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 73DBE204D7 for ; Thu, 8 Aug 2013 14:22:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 21D49E684C for ; Thu, 8 Aug 2013 07:22:22 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com [74.125.83.53]) by gabe.freedesktop.org (Postfix) with ESMTP id DE7D1E684C for ; Thu, 8 Aug 2013 06:42:08 -0700 (PDT) Received: by mail-ee0-f53.google.com with SMTP id b15so1532319eek.26 for ; Thu, 08 Aug 2013 06:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=un0TKIUHb/M466LXn5BRbquLM5qzqQSknAXSgWTx/rs=; b=JtoHEySseAKijYkbfbcT3nthrJoC6TdYUQYcAc20yfhv4W48seReFFxdmd/dhhs9FK UdfA88LyLVYEi9EtwwWFdBEhhRbUyVgamwLB0eeKUkdvX5UaqdJe7Uyr63RyPvQcIdHM trKFglvqD80/WUW9VK5ouYDuBuiH9bRYL4H/0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=un0TKIUHb/M466LXn5BRbquLM5qzqQSknAXSgWTx/rs=; b=EdgaPm/2EOrpATJTKhTXl3/ZkSchNSYypHNjivgtydpiI5lMv+40M0ElQzaLdz8l6k Mm8ThQ2tvk0z6MlZ4PjiqidaO46jwWXuXYur5mjqnWC0Rqzv+1yDQP9R5USjpFlkSigr /zI5GVNesNW4GqeP/xSMhu8bafV7XCXfI4WN28FPJ+An19fYkR1qX1+gs7FdL4Dta9gk Qe36N+S6sBCaxZj47xdDdgHDMINgQBQhp3c+lLc/ndeWdcBw+vLdElAFnkKB/TQl1I6U aW0Z/jZN0L2TJw0TASWBX8Nhsjqv07LsQ6JMXUfFV1X3QEjVpNQxqAidNxoAtuJeHRSX qXYg== X-Gm-Message-State: ALoCoQlYJ6MiMwoyXTb5EneVbGafb9xskp3/2EXYtTeIoOs3DKU3PBmjmYcoxSIAytWFSXACEqSW X-Received: by 10.15.41.77 with SMTP id r53mr8268953eev.64.1375969328144; Thu, 08 Aug 2013 06:42:08 -0700 (PDT) Received: from phenom.ffwll.local (178-83-130-250.dynamic.hispeed.ch. [178.83.130.250]) by mx.google.com with ESMTPSA id bn13sm19282226eeb.11.2013.08.08.06.42.05 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 08 Aug 2013 06:42:06 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH 21/25] drm: hollow-out GET_CLIENT ioctl Date: Thu, 8 Aug 2013 15:41:31 +0200 Message-Id: <1375969295-18929-22-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1375969295-18929-1-git-send-email-daniel.vetter@ffwll.ch> References: <1375969295-18929-1-git-send-email-daniel.vetter@ffwll.ch> Cc: Daniel Vetter , Gwenole Beauchesne X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We not only have debugfs files to do pretty much the equivalent of lsof, we also have an ioctl. Not that compared to lsof this dumps a wee bit more information, but we can still get at that from debugfs easily. I've dug around in mesa, libdrm and ddx histories and the only users seem to be drm/tests/dristat.c and drm/tests/getclients.c. The later is a testcase for the ioctl itself since up to commit b018fcdaa5e8b4eabb8cffda687d00004a3c4785 Author: Eric Anholt Date: Thu Nov 22 18:46:54 2007 +1000 drm: Make DRM_IOCTL_GET_CLIENT return EINVAL when it can't find client #idx there was actually no way at all for userspace to enumerate all clients since the kernel just wouldn't tell it when to stop. Which completely broke it's only user, dristat -c. So obviously that ioctl wasn't much use for debugging. Hence I don't see any point in keeping support for a tool which was pretty obviously never really used, and while we have good replacements in the form of equivalent debugfs files. Still, to keep dristat -c from looping forever again stop it early by returning an unconditional -EINVAL. Also add a comment in the code about why. v2: Slightly less hollowed-out implementation. libva uses GET_CLIENTS to figure out whether the fd it has is already authenticated or not. So we need to keep that part of things working. Simplest way is to just return one entry to keep va_drm_is_authenticated in libva/va/drm/va_drm_auth.c working. This is exercised by igt/drm_get_client_auth which contains a copypasta of the libva auth check code. Cc: Gwenole Beauchesne Cc: David Herrmann Cc: Eric Anholt Reviewed-by: David Herrmann Signed-off-by: Daniel Vetter --- drivers/gpu/drm/drm_ioctl.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 0acf080..ac8ca5c 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -217,29 +217,30 @@ int drm_getclient(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_client *client = data; - struct drm_file *pt; - int idx; - int i; - - idx = client->idx; - i = 0; - mutex_lock(&dev->struct_mutex); - list_for_each_entry(pt, &dev->filelist, lhead) { - if (i++ >= idx) { - client->auth = pt->authenticated; - client->pid = pid_vnr(pt->pid); - client->uid = from_kuid_munged(current_user_ns(), pt->uid); - client->magic = pt->magic; - client->iocs = pt->ioctl_count; - mutex_unlock(&dev->struct_mutex); - - return 0; - } + /* + * Hollowed-out getclient ioctl to keep some dead old drm tests/tools + * not breaking completely. Userspace tools stop enumerating one they + * get -EINVAL, hence this is the return value we need to hand back for + * no clients tracked. + * + * Unfortunately some clients (*cough* libva *cough*) use this in a fun + * attempt to figure out whether they're authenticated or not. Since + * that's the only thing they care about, give it to the directly + * instead of walking one giant list. + */ + if (client->idx == 0) { + client->auth = file_priv->authenticated; + client->pid = pid_vnr(file_priv->pid); + client->uid = from_kuid_munged(current_user_ns(), + file_priv->uid); + client->magic = 0; + client->iocs = 0; + + return 0; + } else { + return -EINVAL; } - mutex_unlock(&dev->struct_mutex); - - return -EINVAL; } /**