From patchwork Tue May 22 12:30:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10418601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF35B60224 for ; Tue, 22 May 2018 12:30:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DD8928A6F for ; Tue, 22 May 2018 12:30:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 926EC28B7A; Tue, 22 May 2018 12:30:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 39CC128B61 for ; Tue, 22 May 2018 12:30:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 74F806E2A7; Tue, 22 May 2018 12:30:58 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id CFCF26E143 for ; Tue, 22 May 2018 12:30:34 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id n10-v6so32957042wmc.1 for ; Tue, 22 May 2018 05:30:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4pIySF3SghSqNldR83upx9XnZE6vTM8B28qNThUO6zY=; b=Fn19xaCM9l8YG+nWgAitLPIZ6e0Vxxj/0G3ZDJDtWX4JxGunpbRqs0vr11fHxhgSTc kAToKn3KJDeU9ztCR/kuewdNky2nfXB1YDNq0j3I7b3Lha7uidacMbSknUjYT1fLYiod bFqKFDEYKuTJ46z2ulUqdKJGSob1szSiQBUb+Kv6VhhRybVIzkAGZQcBgsH1rZAJ/vOX 1HxTL7Dc04GGh3X22YbxNTiLaa01PwXQ/apMNljGfMwLZmk11Lrbh6cfoFg/+U3VGIFg CYK+CECIAHjwti4KYBKC9DqQ6zMf8Ss252TCE0+Up32pMqUH58FF+Kpw8sXH9HeB4I0u M9dA== X-Gm-Message-State: ALKqPwcL5w51QkgOVtsUy0rh2JkmWUsp/KL19iies1U4CmFaIu7r5cuO tPY01xQkF0ANOd9QjhsUUnOuWmPC X-Google-Smtp-Source: AB8JxZpiv/Jq6zrnFDW5qoGcnBqgwxW6awrpmaKcvgY1TWOVYf1UtQcHI3bBgMmdKeqBET7HDaCN+A== X-Received: by 2002:a1c:84cb:: with SMTP id g194-v6mr1178971wmd.8.1526992233305; Tue, 22 May 2018 05:30:33 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id z63-v6sm22822227wrb.34.2018.05.22.05.30.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 05:30:32 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Tue, 22 May 2018 13:30:17 +0100 Message-Id: <20180522123020.31624-8-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180522123020.31624-1-tvrtko.ursulin@linux.intel.com> References: <20180522123020.31624-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [RFC 07/10] drm/i915: Update client name on context create X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin Some clients have the DRM fd passed to them over a socket by the X server. Grab the real client and pid when they create their first context and update the exposed data for more useful enumeration. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/i915_drv.h | 8 ++++++++ drivers/gpu/drm/i915/i915_gem.c | 4 ++-- drivers/gpu/drm/i915/i915_gem_context.c | 16 +++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index b25799ca5c5b..d14798bff230 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -3213,6 +3213,14 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, void i915_gem_object_unpin_from_display_plane(struct i915_vma *vma); int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align); + +int +i915_gem_add_client(struct drm_i915_private *i915, + struct drm_i915_file_private *file_priv, + struct task_struct *task, + unsigned int serial); +void i915_gem_remove_client(struct drm_i915_file_private *file_priv); + int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file); void i915_gem_release(struct drm_device *dev, struct drm_file *file); diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 7be92761fc30..cbd5aa818cd4 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -5673,7 +5673,7 @@ show_client_pid(struct device *kdev, struct device_attribute *attr, char *buf) return snprintf(buf, PAGE_SIZE, "%u", file_priv->client.pid); } -static int +int i915_gem_add_client(struct drm_i915_private *i915, struct drm_i915_file_private *file_priv, struct task_struct *task, @@ -5731,7 +5731,7 @@ i915_gem_add_client(struct drm_i915_private *i915, return ret; } -static void i915_gem_remove_client(struct drm_i915_file_private *file_priv) +void i915_gem_remove_client(struct drm_i915_file_private *file_priv) { sysfs_remove_file(file_priv->client.root, (struct attribute *)&file_priv->client.attr.pid); diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c index 37cace775b31..2fcae26f63bb 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -656,9 +656,10 @@ static bool client_is_banned(struct drm_i915_file_private *file_priv) int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, struct drm_file *file) { + struct drm_i915_file_private *file_priv = file->driver_priv; + pid_t pid = pid_nr(get_task_pid(current, PIDTYPE_PID)); struct drm_i915_private *dev_priv = to_i915(dev); struct drm_i915_gem_context_create *args = data; - struct drm_i915_file_private *file_priv = file->driver_priv; struct i915_gem_context *ctx; int ret; @@ -670,8 +671,7 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, if (client_is_banned(file_priv)) { DRM_DEBUG("client %s[%d] banned from creating ctx\n", - current->comm, - pid_nr(get_task_pid(current, PIDTYPE_PID))); + current->comm, pid); return -EIO; } @@ -680,6 +680,16 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, if (ret) return ret; + if (file_priv->client.pid != pid) { + i915_gem_remove_client(file_priv); + ret = i915_gem_add_client(dev_priv, file_priv, current, + file_priv->client.id); + if (ret) { + mutex_unlock(&dev->struct_mutex); + return ret; + } + } + ctx = i915_gem_create_context(dev_priv, file_priv); mutex_unlock(&dev->struct_mutex); if (IS_ERR(ctx))