Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2343910pxp; Mon, 21 Mar 2022 17:31:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSyxcmld6FOI2z4IggWpg7ypbuG44Hz8UxywiopPNR8psRExZ86JjVprfrUCTtv82dyorw X-Received: by 2002:a17:902:e845:b0:153:aa16:d74f with SMTP id t5-20020a170902e84500b00153aa16d74fmr15686434plg.18.1647909117917; Mon, 21 Mar 2022 17:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647909117; cv=none; d=google.com; s=arc-20160816; b=uq38rRJUcyXEjede0GPTzecep9B+qM3XG/GmasJ7FKfHf9zgYDy0u41loSeQwNL6rG 3nTRCrkCehx+X6Z6gRozb4unmKmATy66c8cqS0euWVv5R5pctgMQKFdf00YaZmqm6gCa BuqBf5getjbiMFUKFDy4oA/5mRVPZ/IEhzrZfpyPfs1rQc7Ty0iARUCRR3XisPSbbnup 1j54nE9RmcHfSPWu3843s+Z3CwVxI+E9PO7ZFsZAG57/jW1J+tdxSqEAJXvIUJFHUSww 0iu8JmOfyf9p0LFJSNhfwN49771ExLdzUn9Z4NbxjD3OC9AwTZystt7ZfIBHnqmb7ATJ JmrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=qiaO27WzdyEkhPCgtVcKJYNpZr9WKp2+zwnsf/1VvSc=; b=SDQ1H7W1TdcWTBuxU9FXdwem+sq/tqn3AFTcm6QRP63dwdIzRpNdnWy3uBbNd7JsrM mExjJ9OcPiOCkECnFRq0wIjr/4S1Lio1kF0KG0kDwq6nzx2LUC8DVKIYiwSHsBYyZTuf lRRwLvSv3uZX6uz9ImTn/1BwQz945l1buI0CK0ajSS152WFXkLtUv2UioKZpbyOyTC6W U+x6KWFzGiMOEWBKDYOpvV+ZuTvoiqsvRIkrgvqIsqld/+BtWGKsPufNZ8NEqI7xNf+Z J95VNWNsapeIWlJawXiaRLQXE4lBcRYo7ZepmbfbY8bCMKzDW4oDJPviLM77v3G+WGBL t2IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Ri8yuR7/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r29-20020a63205d000000b003816043f0ebsi14831952pgm.736.2022.03.21.17.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 17:31:57 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Ri8yuR7/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BB4F344A10; Mon, 21 Mar 2022 17:01:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233532AbiCUX6Y (ORCPT + 99 others); Mon, 21 Mar 2022 19:58:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233593AbiCUX5w (ORCPT ); Mon, 21 Mar 2022 19:57:52 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D07A1284E79 for ; Mon, 21 Mar 2022 16:55:02 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id j15so18893360eje.9 for ; Mon, 21 Mar 2022 16:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=qiaO27WzdyEkhPCgtVcKJYNpZr9WKp2+zwnsf/1VvSc=; b=Ri8yuR7/Vfc3fPL9gQLx7nlC2w5WarFCPritcrnsHpSsxuLwI5G3Voo8JeXcgyszLb +2uoYc1aMEeZckMfuvJ2tS1RQ4sV4x2bEw3/t6bZI8mymUrBIyCvE8fdVOZNpVekttmd gL3/aF9rUmS8p0UDTQfskhyx+I2egHowIc+sQ/N03tFWDWkkas9yz9J6z6/pRbfJotOJ Hya7yMo0Sw59opqFkSYTZhc7F9NiPgJ8uwx1p8C0nJ00wLf8jKvLHqjCFphRAZgfpYi+ VVSQCs5iHmIrTMa+g/VlfDJHcUV27McnejGmfZoaaKiH2IvdAJP5kg+Lda21FYCK3UME MrGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=qiaO27WzdyEkhPCgtVcKJYNpZr9WKp2+zwnsf/1VvSc=; b=MILDXu1sR+DCW6Y7+dUyx/9El5gdp684njVqA1y+TyZaxnxwBDUlwjlDpOrh2GZUoF vhTeF9XnhOzMK913TSodhnhMAeskoacCCCH0Axm+Vz7pwR9017eBKIIpUkyjCboL6B6a NlWAeuZLJERpiW+ingLTt6RW4MUpMwZTe833KJsR+swoe5YWYIkw5ZO9x/lllClHQezi nlFkn4OY8JjG32zAy05G+wbTHB+z94XWAptv+MwMcRnv+SO60Z1MMBnrsg1WJ2q5JuE5 dB7Ot0ye4djWX8hiykYBaix7WIbD+MJMr2NI1mUfJWFrlakCGVWwvy4H3hk4MuzPNwmp 7JDw== X-Gm-Message-State: AOAM531vIaAP/06E7krYQIAfOGn1UMFQxMS51DCxr9PMKF7cjxoNw4dO Q0g6czUe+maKgGS0iuI10GU3I3FCMzma3NrLqAerdA== X-Received: by 2002:a17:907:3eaa:b0:6df:b058:96a with SMTP id hs42-20020a1709073eaa00b006dfb058096amr18101556ejc.368.1647906877844; Mon, 21 Mar 2022 16:54:37 -0700 (PDT) MIME-Version: 1.0 References: <20220309165222.2843651-1-tjmercier@google.com> <20220309165222.2843651-6-tjmercier@google.com> <20220321174530.GB9640@blackbody.suse.cz> In-Reply-To: <20220321174530.GB9640@blackbody.suse.cz> From: "T.J. Mercier" Date: Mon, 21 Mar 2022 16:54:26 -0700 Message-ID: Subject: Re: [RFC v3 5/8] dmabuf: Add gpu cgroup charge transfer function To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Hridya Valsaraju , Suren Baghdasaryan , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan , Kalesh Singh , Kenny.Ho@amd.com, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 On Mon, Mar 21, 2022 at 10:45 AM Michal Koutn=C3=BD wrot= e: > > 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 *gpuc= g) > > +{ > > +#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? Good idea, thank you! > > > + > > + 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. Since the charge is duplicated in two cgroups for a short period before it is uncharged from the source cgroup I guess the situation you're thinking about is a global (or common ancestor) limit? I can see how that would be a problem for transfers done this way and an alternative would be to swap the order of the charge operations: first uncharge, then try_charge. To be certain the uncharge is reversible if the try_charge fails, I think I'd need either a mutex used at all gpucg_*charge call sites or access to the gpucg_mutex, which implies adding transfer support to gpu.c as part of the gpucg_* API itself and calling it here. Am I following correctly here? This series doesn't actually add limit support just accounting, but I'd like to get it right here. > > My 0.02=E2=82=AC, > Michal Thanks!