From patchwork Wed Oct 3 12:04:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10624719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F312713BB for ; Wed, 3 Oct 2018 12:04:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E504628947 for ; Wed, 3 Oct 2018 12:04:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D733228944; Wed, 3 Oct 2018 12:04:38 +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 8236E28944 for ; Wed, 3 Oct 2018 12:04:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 979C86E468; Wed, 3 Oct 2018 12:04:35 +0000 (UTC) X-Original-To: Intel-gfx@lists.freedesktop.org Delivered-To: Intel-gfx@lists.freedesktop.org Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id EA1B16E457 for ; Wed, 3 Oct 2018 12:04:24 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id s12-v6so5464448wmc.0 for ; Wed, 03 Oct 2018 05:04:24 -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=/e8KTR24LuMB9nfey6n258TWSNk4vKPeHoEVCRa7O7c=; b=FBeiHnV0QYXunFp7uyCzNrn7PjbsFv4pmC56ocU4tvXb1jlHbi8N50EnCGm6+1Le+H Agl1JvUAEXCkPe6R/BjFuPzb5fPna/DIcLTA6WV9Nl28cANVwKOK1cQpYinmto4Z8/32 Ml8AdvcLM0gdxuA3x4Ep0or6BLOLApCvJqHzGGOHaUd4oqG0nZAKxhI+Z9dwQjsKJnfC wjF2g9344B4Y+oE4qTO0YeAzw20pa6YGCwHLEA7IyRPV2eNU+8nblpsZNyqSbTqIMer8 xQkqFnU+WMaydXb9owQRAo5erF3r+THz40WVxuS+E6+nIgCBNSUg/MVUnYOf2GsC1jGJ pauw== X-Gm-Message-State: ABuFfoiRS/q6DUqnsHh1+3DuJQShZHaCSo3LNYbHxFvnOO0kyBqNRYfZ NGzNGcs7sJsyqVQBVY44ATpMDaXV6WQ= X-Google-Smtp-Source: ACcGV62WuBoJ4Kk1NNYLI27oMSSywLcrEx6cZUc8eYV0BmXaldE2pq5c6NXCSYxfZeEdtCv0aGTV1w== X-Received: by 2002:a1c:c784:: with SMTP id x126-v6mr1338164wmf.90.1538568263310; Wed, 03 Oct 2018 05:04:23 -0700 (PDT) Received: from localhost.localdomain ([95.144.165.37]) by smtp.gmail.com with ESMTPSA id f69-v6sm866657wmf.34.2018.10.03.05.04.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 05:04:22 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Date: Wed, 3 Oct 2018 13:04:04 +0100 Message-Id: <20181003120406.6784-12-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003120406.6784-1-tvrtko.ursulin@linux.intel.com> References: <20181003120406.6784-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [RFC 11/13] 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 f7022533eab1..075a600e066f 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -3273,6 +3273,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 44a875863401..fe684d04be22 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -5908,7 +5908,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, @@ -5968,7 +5968,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 d0fa5dfb8389..738dd7e583e8 100644 --- a/drivers/gpu/drm/i915/i915_gem_context.c +++ b/drivers/gpu/drm/i915/i915_gem_context.c @@ -779,9 +779,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; @@ -793,8 +794,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; } @@ -803,6 +803,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))