From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal =?iso-8859-1?Q?Koutn=FD?= Subject: Re: [RFC v3 5/8] dmabuf: Add gpu cgroup charge transfer function Date: Mon, 21 Mar 2022 18:45:30 +0100 Message-ID: <20220321174530.GB9640@blackbody.suse.cz> References: <20220309165222.2843651-1-tjmercier@google.com> <20220309165222.2843651-6-tjmercier@google.com> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1647884732; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=peglqrh0TeDc2F8OaZcmUkLDagjJhol7WzzofXyyxO4=; b=PnmDb1Bn2lmsEUIPSG3oXSY46IqI6iAnrhkUOd3imYGHhzUBGrywA4Q9uGXh7c/svUPKw5 ngHuZu78cVggAJKMr47ybLtd326kLSE1NoNSHr9Gfg480gkY2G8m9HV1lQGRPPiKOrSgdz U10jIZn2E3ClJ36uP4+4GnMAPYs5WBQ= Content-Disposition: inline In-Reply-To: <20220309165222.2843651-6-tjmercier-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org> List-ID: Content-Type: text/plain; charset="windows-1252" To: "T.J. Mercier" Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Hridya Valsaraju , Suren Baghdasaryan , Sumit Semwal , Christian =?iso-8859-1?Q?K=F6nig?= , Benjamin Gaignard , Liam Mark , Laur Hello. On Wed, Mar 09, 2022 at 04:52:15PM +0000, "T.J. Mercier" wrote: > +int dma_buf_charge_transfer(struct dma_buf *dmabuf, struct gpucg *gpucg) > +{ > +#ifdef CONFIG_CGROUP_GPU > + struct gpucg *current_gpucg; > + int ret =3D 0; > + > + /* > + * Verify that the cgroup of the process requesting the transfer is the > + * same as the one the buffer is currently charged to. > + */ > + current_gpucg =3D gpucg_get(current); > + mutex_lock(&dmabuf->lock); > + if (current_gpucg !=3D dmabuf->gpucg) { > + ret =3D -EPERM; > + goto err; > + } Add a shortcut for gpucg =3D=3D current_gpucg? > + > + ret =3D gpucg_try_charge(gpucg, dmabuf->gpucg_dev, dmabuf->size); > + if (ret) > + goto err; > + > + dmabuf->gpucg =3D gpucg; > + > + /* uncharge the buffer from the cgroup it's currently charged to. */ > + gpucg_uncharge(current_gpucg, dmabuf->gpucg_dev, dmabuf->size); I think gpucg_* API would need to cater for such transfers too since possibly transitional breach of a limit during the transfer may unnecessarily fail the operation. My 0.02=E2=82=AC, Michal