Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp5072363rwb; Tue, 17 Jan 2023 08:52:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXvJEmv70o5K2mjaYYt0dfvpAeFoP7lRx/ckaeIZ4CczoBuqr5UNa/dvTnlNyvZPnBuYGDG+ X-Received: by 2002:a05:6402:3883:b0:499:b672:ee39 with SMTP id fd3-20020a056402388300b00499b672ee39mr4101333edb.11.1673974368036; Tue, 17 Jan 2023 08:52:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673974368; cv=none; d=google.com; s=arc-20160816; b=iN6hBFnTqBjtrKY5zLCmM4oGu3ZfyvAOfA6e/es21mXhAbnuJf4WunEWT5j+P0seWQ fBTQQ7g6trarBScQJjt16iNAvuiBjYcEosNHvgApYipgAbfk5bSTTKG3Sx6QhB5r3xc+ 8vG48h5zuaIH02HkdnXxW7UvPmPKL/0VcIvAGdoB2RSojesntlheWGNaxBpTXqRUDhYt elEPxSbz7bZ0l+7SIDVvVomrtgTUE6LFdBpOS/3TGfH+eAJsWjkuW78i1cH3RS6kfxq7 sHe/BvxfABeBpy8O1atvS2+1UHdXoVOeaDAYXp5r3YZ1aL0WMeAyP2/XOI9/YU6lzgwM a5xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TwFvdrDCSgNXXdhtQYj0W6j4Zslsch+dgVaYmeczPBo=; b=LEoCuGeO7cbdC5MxxHRoxP3uoM+WKz46hQjxbRFS7Zs4vJ4Efr0i/i4mi4XRxe9cLK Gabro8a/+B0RftcAdCAcZ9/JLLszGZn/ObnAJ30Org2tOA7/uLXru8ygQwsxDCq10uYN AJlV+ZxDsZpk1vqliKOxZuDTVMoYpFPQZcF4Fhq5gKqFJtcD4N8jCRP32wQE8RmSBJcG LaOf586lpvZgI3CmFW5ZH+Z+BOK7UMbJOgg0Mtid1noKqGMOyD7Jz/XveurHQaVYQgh0 PSaTfT9zjL/mJ72C3BGbLAWXg2SGB+tyQeJ5DDYO8fHXeVzWuzHTIRLWBmH7wbJyIqnM jiKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IubsWkpo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id en14-20020a056402528e00b00499e590d47esi373508edb.36.2023.01.17.08.52.36; Tue, 17 Jan 2023 08:52:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IubsWkpo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231511AbjAQQE5 (ORCPT + 48 others); Tue, 17 Jan 2023 11:04:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231552AbjAQQEx (ORCPT ); Tue, 17 Jan 2023 11:04:53 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A12E3A861; Tue, 17 Jan 2023 08:04:51 -0800 (PST) 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="323427596" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="323427596" 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 Cc: Intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Rob Clark , Brian Welty , Kenny.Ho@amd.com, Tvrtko Ursulin , Daniel Vetter , Johannes Weiner , linux-kernel@vger.kernel.org, =?iso-8859-1?Q?St=E9phane?= Marchesin , Christian =?iso-8859-1?Q?K=F6nig?= , Zefan Li , Dave Airlie , Tejun Heo , cgroups@vger.kernel.org, "T . J . Mercier" Subject: Re: [RFC 04/12] drm/cgroup: Track clients per owning process 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> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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