Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3972296pxb; Mon, 4 Oct 2021 14:05:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw76n8/k01EsaLVi9Gi6ZrVgEkyfHwQy6k7ccSeTQqFqJgRGWHn93QaunQd4lmBOApet7PN X-Received: by 2002:a05:6402:3587:: with SMTP id y7mr1619571edc.182.1633381549842; Mon, 04 Oct 2021 14:05:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633381549; cv=none; d=google.com; s=arc-20160816; b=rxA5hPb0g8na8fj7ppjSgQMr8eOr6wAVKB4iD3LmwXo1j2VZC/QtHc7dXUSFhROBKz 5XssxQKuCU33oOcmzFGbmxM2UZ6ntXVpnXOsqEgE3hsPoXwYL3XnHcpT/cMCGY+M1g2H Eydwll4rnJzpnKr/a1pn87n3Eqyk7BK2l+XBz/PdwVJdDw/NeswtQvjVRdQoOVPWjnWB lMgzdS4aNnJ0BPm/F9OCiVOfK/ZCymWBUDtjYB+w0NbE5q1A46hu1wssJ/qHGupCZTjg Q2qq8P6Zaj0X6zYYnKc1lh48Mzo/3hjtZdnorBIEPoaOf8gkaG+DvSTysZFtkUa4VkGC rjtw== 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=yoTuusFICTLIsEjbJpNAkOqYRSdJ6S5Sx/hRE66zYtaRwBA1tkLeZ7n0NLJJSD+cWo kjllgXYxavolb3k4H4wGqnW6RoURitAGPDkRkI03GpBExPz02U5j5VzFzkQCJzWn62r9 AkCI5oRZjXZwHEL4hggfrX0glRra7Bznay0s5gA4hxbTHIWDzUN03g/iE69MMpsFk3AQ 4YeBo6uzW+HBgVQySAphZQ0syE5Dp4/+aTxhrM20+W5L6diCMF74aCMkCwmYdUEBO47L 10RMI37hdkovzIRdk+7H5lJ9jJu1T1TIeO1cBPaBDaXPa/qRB/1rWKMD+XWl+moRRE9k 96pA== 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 1si16950195ejb.87.2021.10.04.14.05.21; Mon, 04 Oct 2021 14:05:49 -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 S235008AbhJDOrP (ORCPT + 99 others); Mon, 4 Oct 2021 10:47:15 -0400 Received: from mga01.intel.com ([192.55.52.88]:16798 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234937AbhJDOrK (ORCPT ); Mon, 4 Oct 2021 10:47:10 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10126"; a="248714008" X-IronPort-AV: E=Sophos;i="5.85,346,1624345200"; d="scan'208";a="248714008" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 07:37:19 -0700 X-IronPort-AV: E=Sophos;i="5.85,346,1624345200"; d="scan'208";a="622303693" Received: from shearne-mobl.ger.corp.intel.com (HELO tursulin-mobl2.home) ([10.213.208.122]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 07:37:18 -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/8] drm/i915: Keep track of registered clients indexed by task struct Date: Mon, 4 Oct 2021 15:36:47 +0100 Message-Id: <20211004143650.699120-6-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211004143650.699120-1-tvrtko.ursulin@linux.intel.com> References: <20211004143650.699120-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