Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp495228pxb; Thu, 30 Sep 2021 10:21:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGjW+OYpm0rbZTxaw2S1uEp0FhiAhJHYtButEzq1qG1u6Zs6Ay+FW/MRKh/Zql0hrUpWXC X-Received: by 2002:a17:907:3e03:: with SMTP id hp3mr419873ejc.183.1633022488973; Thu, 30 Sep 2021 10:21:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633022488; cv=none; d=google.com; s=arc-20160816; b=qA1itdzvcyvWiDdKUSSnoys40r3ZMUJgTu/SME4AQCcse79hiY4Fe/ZwiElWoUPfYB ABPRkgugP+98HMjZbWXBsvjB2EsfMqhBhi8fREBkV/hecwR65nXxgVs7m6Pww4cIS9IA c6By+UlBgQ6nXgw9UlOKDAGgrX2B72zu7lXGf1Du5X8hQ7JcSHYYqZSQZaOnh+fms3Xz 65NzT/5bov4aNiS2T1aiJpNY0l65yBTtRPf8x2jk0UwTX6IbSOJhZPOxEc1rsmGjGVUm kgVCgOcE2MmhrUCrgZ91Wd/+SKqDTCJ+iV5OKSGPmprnDIpYFrvhMvOZCXWxzAaUCbPq 5LFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3vLzDElDMuFeiCPbV3cr1sSIKg5MxCnhKeaWF5p6Hhk=; b=CeZwTfh6kOUusR/uCiFe0f9lAHHwY3QsBTaoJbuomTAF1cSdAwkGSpnzbe3Uygb/zk znvG10L4VcFjIDxS6/o/iQWM+5DpxlkUxN2zitombC78cHEzRRBT5FzJZGJC0//SXcjn J8QJnr23s5vVgPThSypF/6zXe4PwDP7/K/o8lM4sryroBViYCZi4yzZeD6zxJUscB16E 7tPvavTxaOItYA1FXc54PqqwDpik2VXz4A0RnbP66beMbNYB8G263T6vyy2YHSrG+JT6 J5wUcO2sfckRspg0CAIQvQjjm3aACw6EIAzf/Q4TN2S4yIxoFDOXeu+PKGADmcTYn42m 1Olg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qf42si811501ejc.737.2021.09.30.10.21.03; Thu, 30 Sep 2021 10:21:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352552AbhI3RU0 (ORCPT + 99 others); Thu, 30 Sep 2021 13:20:26 -0400 Received: from mga05.intel.com ([192.55.52.43]:4350 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352498AbhI3RUO (ORCPT ); Thu, 30 Sep 2021 13:20:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10123"; a="310787680" X-IronPort-AV: E=Sophos;i="5.85,336,1624345200"; d="scan'208";a="310787680" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2021 10:16:28 -0700 X-IronPort-AV: E=Sophos;i="5.85,336,1624345200"; d="scan'208";a="520489746" Received: from dboland-mobl.ger.corp.intel.com (HELO tursulin-mobl2.home) ([10.213.223.141]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2021 10:16:26 -0700 From: Tvrtko Ursulin To: Intel-gfx@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Tvrtko Ursulin Subject: [RFC 5/6] drm/i915: Keep track of registered clients indexed by task struct Date: Thu, 30 Sep 2021 18:15:51 +0100 Message-Id: <20210930171552.501553-6-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210930171552.501553-1-tvrtko.ursulin@linux.intel.com> References: <20210930171552.501553-1-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tvrtko Ursulin A simple hash table of registered clients indexed by the task struct pointer is kept to be used in a following patch. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 ++ drivers/gpu/drm/i915/i915_drm_client.c | 31 ++++++++++++++++++++- drivers/gpu/drm/i915/i915_drm_client.h | 13 +++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index d1992ba59ed8..8d4d687ab1d0 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -1932,6 +1932,8 @@ int i915_gem_context_create_ioctl(struct drm_device *dev, void *data, return -EIO; } + i915_drm_client_update_owner(ext_data.fpriv->client, current); + ext_data.pc = proto_context_create(i915, args->flags); if (IS_ERR(ext_data.pc)) return PTR_ERR(ext_data.pc); diff --git a/drivers/gpu/drm/i915/i915_drm_client.c b/drivers/gpu/drm/i915/i915_drm_client.c index 91a8559bebf7..82b9636482ef 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.c +++ b/drivers/gpu/drm/i915/i915_drm_client.c @@ -18,6 +18,9 @@ void i915_drm_clients_init(struct i915_drm_clients *clients, clients->next_id = 0; xa_init_flags(&clients->xarray, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); + + rwlock_init(&clients->lock); + hash_init(clients->tasks); } struct i915_drm_client *i915_drm_client_add(struct i915_drm_clients *clients) @@ -42,6 +45,8 @@ struct i915_drm_client *i915_drm_client_add(struct i915_drm_clients *clients) INIT_LIST_HEAD(&client->ctx_list); client->clients = clients; + i915_drm_client_update_owner(client, current); + return client; err: @@ -54,9 +59,14 @@ void __i915_drm_client_free(struct kref *kref) { struct i915_drm_client *client = container_of(kref, typeof(*client), kref); - struct xarray *xa = &client->clients->xarray; + struct i915_drm_clients *clients = client->clients; + struct xarray *xa = &clients->xarray; unsigned long flags; + write_lock(&clients->lock); + hash_del(&client->node); + write_unlock(&clients->lock); + xa_lock_irqsave(xa, flags); __xa_erase(xa, client->id); xa_unlock_irqrestore(xa, flags); @@ -68,3 +78,22 @@ void i915_drm_clients_fini(struct i915_drm_clients *clients) GEM_BUG_ON(!xa_empty(&clients->xarray)); xa_destroy(&clients->xarray); } + +void i915_drm_client_update_owner(struct i915_drm_client *client, + struct task_struct *owner) +{ + struct i915_drm_clients *clients; + + if (READ_ONCE(client->owner) == owner) + return; + + clients = client->clients; + write_lock(&clients->lock); + if (READ_ONCE(client->owner) != owner) { + if (client->owner) + hash_del(&client->node); + client->owner = owner; + hash_add(clients->tasks, &client->node, (uintptr_t)owner); + } + write_unlock(&clients->lock); +} diff --git a/drivers/gpu/drm/i915/i915_drm_client.h b/drivers/gpu/drm/i915/i915_drm_client.h index 0207dfad4568..42fd79f0558a 100644 --- a/drivers/gpu/drm/i915/i915_drm_client.h +++ b/drivers/gpu/drm/i915/i915_drm_client.h @@ -6,8 +6,11 @@ #ifndef __I915_DRM_CLIENT_H__ #define __I915_DRM_CLIENT_H__ +#include #include #include +#include +#include #include #include @@ -18,6 +21,9 @@ struct i915_drm_clients { struct xarray xarray; u32 next_id; + + rwlock_t lock; + DECLARE_HASHTABLE(tasks, 6); }; struct i915_drm_client { @@ -28,6 +34,9 @@ struct i915_drm_client { spinlock_t ctx_lock; /* For add/remove from ctx_list. */ struct list_head ctx_list; /* List of contexts belonging to client. */ + struct task_struct *owner; /* No reference kept, never dereferenced. */ + struct hlist_node node; + struct i915_drm_clients *clients; }; @@ -52,4 +61,8 @@ struct i915_drm_client *i915_drm_client_add(struct i915_drm_clients *clients); void i915_drm_clients_fini(struct i915_drm_clients *clients); +void i915_drm_client_update_owner(struct i915_drm_client *client, + struct task_struct *owner); + + #endif /* !__I915_DRM_CLIENT_H__ */ -- 2.30.2