From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3CC65C6379F for ; Tue, 17 Jan 2023 16:04:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 630AF10E57D; Tue, 17 Jan 2023 16:04:54 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 21A3910E57D; Tue, 17 Jan 2023 16:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673971492; x=1705507492; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=83QUm+B1soJY7/5R+o87e442WuYAgBdKXUVW9VPPJwY=; b=IubsWkpoktWBNxNWo8Q20thw0LC165CNAyzo7Oolz9r+RtyZIgAjm3Rp A/KNXhaa+IEwcTMt5Ph+RxLkBkgsEQZY9LVP3tYJxmTFH/aLk88lXdWnt aFtxpoz1uPdcB4ouCvVb7boRTeDp7yz3qtCWa3OfyL3MqBKtYNQlJ3nGJ hmC67UgXtRZghYLUei/7ZifIEYnggj8toKfMSOwe4PP5alA9kxuXsqbBq 8qnV9g5hcBbyOUZcFx2FQQ352MwtCF5o1BYUroOLBp46aa6EV7XzLXvI8 /SebZ+j30dkD1d3Jsvwwu9gZjHcHjt04nFfviYG1V2k9Nmx8AeVxDu4gp Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10592"; a="323427600" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="323427600" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2023 08:03:20 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10592"; a="904695680" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="904695680" Received: from joe-255.igk.intel.com (HELO localhost) ([10.91.220.57]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2023 08:03:13 -0800 Date: Tue, 17 Jan 2023 17:03:11 +0100 From: Stanislaw Gruszka To: Tvrtko Ursulin Message-ID: <20230117160311.GA15842@linux.intel.com> References: <20230112165609.1083270-1-tvrtko.ursulin@linux.intel.com> <20230112165609.1083270-5-tvrtko.ursulin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230112165609.1083270-5-tvrtko.ursulin@linux.intel.com> Subject: Re: [Intel-gfx] [RFC 04/12] drm/cgroup: Track clients per owning process X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , cgroups@vger.kernel.org, Dave Airlie , Kenny.Ho@amd.com, Intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, "T . J . Mercier" , Johannes Weiner , Zefan Li , Daniel Vetter , Tejun Heo , =?iso-8859-1?Q?St=E9phane?= Marchesin , Christian =?iso-8859-1?Q?K=F6nig?= Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Hi On Thu, Jan 12, 2023 at 04:56:01PM +0000, Tvrtko Ursulin wrote: > From: Tvrtko Ursulin > > To enable propagation of settings from the cgroup drm controller to drm we > need to start tracking which processes own which drm clients. > > Implement that by tracking the struct pid pointer of the owning process in > a new XArray, pointing to a structure containing a list of associated > struct drm_file pointers. > > Clients are added and removed under the filelist mutex and RCU list > operations are used below it to allow for lockless lookup. > > Signed-off-by: Tvrtko Ursulin > +int drm_clients_open(struct drm_file *file_priv) > +{ > + struct drm_device *dev = file_priv->minor->dev; > + struct drm_pid_clients *clients; > + bool new_client = false; > + unsigned long pid; > + > + lockdep_assert_held(&dev->filelist_mutex); > + > + pid = (unsigned long)rcu_access_pointer(file_priv->pid); > + clients = xa_load(&drm_pid_clients, pid); > + if (!clients) { > + clients = __alloc_clients(); > + if (!clients) > + return -ENOMEM; > + new_client = true; > + } > + atomic_inc(&clients->num); > + list_add_tail_rcu(&file_priv->clink, &clients->file_list); > + if (new_client) { > + void *xret; > + > + xret = xa_store(&drm_pid_clients, pid, clients, GFP_KERNEL); > + if (xa_err(xret)) { > + list_del_init(&file_priv->clink); > + kfree(clients); > + return PTR_ERR(clients); This looks incorrect, rather xa_err(xret) should be returned. Regards Stanislaw