Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6412465pxb; Tue, 15 Feb 2022 01:44:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZrygaDRidgpJx0E+7MxNNhbZotb2yMrmgDxVnNwPyoxtp+vdgSOuebnSPiR34INQ1HzOG X-Received: by 2002:a05:6402:440c:: with SMTP id y12mr2962839eda.75.1644918250105; Tue, 15 Feb 2022 01:44:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644918250; cv=none; d=google.com; s=arc-20160816; b=03h0AJoOibhHm+u/iW+CInpBdbhu6s7u3iC0l2rHg2iave+vFQ+A8kTJ6c2MLkATlL rN72uc54bDU12aG50NMPmEobcsTFAsQcGks3G7UicYleslE83thnyw8xT/35Ll4sGYrO h+N+rvtk54gwI28s/WGFDUjPmZZLy/ohWffW2/9c0eKs08ysY8u9Vy56fcNWu0QwoxeC DE6L1Ott2Myfsz77Bq9z+Jhx7UQLX0wrcN7Ntf2GdSpo9hN7vwEzujRRG37LeWyYrQ64 PtvspVLFH4RBkm1mjfjeVSJHVPUHkMeVyqUNqkbamaBnHSMKAt2HPjZo1V7qMebwxKzy lRtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=A6Vt6yUnPEpX+Sv2rGVstxQvcH1UBHN+lyF7dCbw5Wg=; b=hu+sd3Z9ATULvVr59I5t9vlaTfu6e547Es4FbfAcIHvDLG+IjzdwsguMVqAlQ4WBDl sCjuc4Odapptzya/R7lNLaZyVgOgxNBYz8TH2q2vHQuf3ZcwLXfHEKfhG6AA3dkSO9Vk svNczbtiDdtOix8U7ORM66quFpQbV/75aDneWQJvUyaBzXPWosD5GaCeT/uq/ZmEyP0Y Gn/Wwd37AvX4a5m/2qiKiy5DCnEyJcHugEZMq8zCcwHjmBPbUa6zg0znP3eJ7JKb1TIT 0h40kTiPJnDIxfMVGuxl9zi7y/87eJ9XfpwUL/5XguB7wIkrLdgO0p5ZQyDIbOURpH+4 huPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Nz1swxY2; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ed5si20931713edb.203.2022.02.15.01.43.46; Tue, 15 Feb 2022 01:44:10 -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=@google.com header.s=20210112 header.b=Nz1swxY2; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234766AbiBOHT5 (ORCPT + 99 others); Tue, 15 Feb 2022 02:19:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234532AbiBOHT4 (ORCPT ); Tue, 15 Feb 2022 02:19:56 -0500 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54F7FEBDF9 for ; Mon, 14 Feb 2022 23:19:47 -0800 (PST) Received: by mail-yb1-xb2a.google.com with SMTP id 124so25205302ybn.11 for ; Mon, 14 Feb 2022 23:19:47 -0800 (PST) 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; bh=A6Vt6yUnPEpX+Sv2rGVstxQvcH1UBHN+lyF7dCbw5Wg=; b=Nz1swxY2TPAOOH/d1/tUe5H0WXsil0iMonbnPxAEWPHYDqHdExDnTYI87V6DuusLdZ alks65Ggqq1yRT/z2+zdbOhihQ6XHcD1ogET1iqj1sDd2buLYiVO/euXlajJ5iZEDOFC g2F7g3fGTwHi4KACmtxBLr7rEtbS7teDNcyCU4I+YH+Yu56OyhFllkiZYFrE7EbwhOzi crWCACfzkQ1HuJZ/Zf8iQ582qUh9/mcdfsP0PEAXdnARf13gFalHNAzTFOp50QjI54s3 zxlCQmi2c3kFY3oqRuexTDezSuj2yGpkhuu4s+uoXOtfwBbyNXCJU7K627hhwo6SEA+6 1Y1w== 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; bh=A6Vt6yUnPEpX+Sv2rGVstxQvcH1UBHN+lyF7dCbw5Wg=; b=KGknxoDZKvovtEeZlR3Ipb3SMnMIrrqhi9SeciuwVro9OPoq3qliSDv/HoBTMCrgN3 1nHc3yo4277yGWB1sJ97gqWNkOBQApJ+ajA2TUIYpAaGHr/xIBizC1GKa4oC776TIKQa uZ1vmN931i9paJtM5fXqXpcHBw1ueh+tn8bD9RGgqPmf8Jb9MMa88BiB9e33zeVg3+T/ DycMAIOTb5EIod7eNMxyxtZLu9AjoWU7QRyl+/smRCd4taHN71+D4Mo/l/8N2isHhgxo mY8mtd3O+OMMsrNRtld7un5qTyamPSaIqXYItYpQV5Ysls0TgzfDoGuPj3P4EyNvSKW9 EoKg== X-Gm-Message-State: AOAM530rOc/xUq/Utgg3tI6MD/9fax5IlSSyCEaaw/GuAv4ExqTKYTZK eiZfPPs2pXxagQYSPCQsy5CaKKvlxxkFnpZZY4d33g== X-Received: by 2002:a25:aac6:: with SMTP id t64mr2615071ybi.602.1644909586308; Mon, 14 Feb 2022 23:19:46 -0800 (PST) MIME-Version: 1.0 References: <20220211161831.3493782-1-tjmercier@google.com> <20220211161831.3493782-7-tjmercier@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 14 Feb 2022 23:19:35 -0800 Message-ID: Subject: Re: [RFC v2 6/6] android: binder: Add a buffer flag to relinquish ownership of fds To: Greg Kroah-Hartman Cc: "T.J. Mercier" , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Hridya Valsaraju , 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 , Kalesh Singh , Kenny.Ho@amd.com, DRI mailing list , "open list:DOCUMENTATION" , LKML , linux-media , "moderated list:DMA BUFFER SHARING FRAMEWORK" , cgroups mailinglist Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Mon, Feb 14, 2022 at 11:01 PM Greg Kroah-Hartman wrote: > > On Mon, Feb 14, 2022 at 02:25:47PM -0800, T.J. Mercier wrote: > > On Fri, Feb 11, 2022 at 11:19 PM Greg Kroah-Hartman > > > > --- a/include/uapi/linux/android/binder.h > > > > +++ b/include/uapi/linux/android/binder.h > > > > @@ -137,6 +137,7 @@ struct binder_buffer_object { > > > > > > > > enum { > > > > BINDER_BUFFER_FLAG_HAS_PARENT = 0x01, > > > > + BINDER_BUFFER_FLAG_SENDER_NO_NEED = 0x02, > > > > }; > > > > > > > > /* struct binder_fd_array_object - object describing an array of fds in a buffer > > > > -- > > > > 2.35.1.265.g69c8d7142f-goog > > > > > > > > > > How does userspace know that binder supports this new flag? > > > > Sorry, I don't completely follow even after Todd's comment. Doesn't > > the presence of BINDER_BUFFER_FLAG_SENDER_NO_NEED in the header do > > this? > > There is no "header" when running a new kernel on an old userspace, > right? How about the other way around, old kernel, new userspace? 1. new kernel + old userspace = kernel supports the feature but userspace does not use it. The old userspace won't even mount the new cgroup controller, accounting is not performed, charge is not transferred. 2. old kernel + new userspace = the new cgroup controller is not supported by the kernel, accounting is not performed, charge is not transferred. 3. old kernel + old userspace = same as #2 4. new kernel + new userspace = cgroup is mounted, feature is supported and used. Does that work or do we need a separate indication of whether binder driver supports the charge transfer feature? > > > So wouldn't userspace need to be compiled against the wrong > > kernel headers for there to be a problem? In that case the allocation > > would still succeed, but there would be no charge transfer and > > unfortunately no error code. > > No error code is not good. People upgrade their kernels all the time, > and do not do a "rebuild the world" when doing so. > > > > And where is the userspace test for this new feature? > > > > I tested this on a Pixel after modifying the gralloc implementation to > > mark allocated buffers as not used by the sender. This required > > setting the BINDER_BUFFER_FLAG_SENDER_NO_NEED in libhwbinder. That > > code can be found here: > > https://android-review.googlesource.com/c/platform/system/libhwbinder/+/1910752/1/Parcel.cpp > > https://android-review.googlesource.com/c/platform/system/libhidl/+/1910611/ > > > > Then by inspecting gpu.memory.current files in sysfs I was able to see > > the memory attributed to processes other than the graphics allocator > > service. Before this change, several megabytes of memory were > > attributed to the graphics allocator service but those buffers are > > actually used by other processes like surfaceflinger, the camera, etc. > > After the change, the gpu.memory.current amount for the graphics > > allocator service was 0 and the charges showed up in the > > gpu.memory.current files for those other processes like this: > > > > PID: 764 Process Name: zygote64 > > system 8192 > > system-uncached 23191552 > > > > PID: 529 Process Name: /system/bin/surfaceflinger > > system-uncached 109535232 > > system 92196864 > > > > PID: 530 Process Name: > > /vendor/bin/hw/android.hardware.graphics.allocator@4.0-service > > system-uncached 0 > > system 0 > > sensor_direct_heap 0 > > > > PID: 806 Process Name: > > /apex/com.google.pixel.camera.hal/bin/hw/android.hardware.camera.provider@2.7-service-google > > system 1196032 > > > > PID: 4608 Process Name: com.google.android.GoogleCamera > > system 2408448 > > system-uncached 38887424 > > sensor_direct_heap 0 > > > > PID: 32102 Process Name: com.google.android.googlequicksearchbox:search > > system-uncached 91279360 > > system 20480 > > > > PID: 2758 Process Name: com.google.android.youtube > > system-uncached 1662976 > > system 8192 > > > > PID: 2517 Process Name: com.google.android.apps.nexuslauncher > > system-uncached 115662848 > > system 122880 > > > > PID: 2066 Process Name: com.android.systemui > > system 86016 > > system-uncached 37957632 > > > > > Isn't there a binder test framework somewhere? > > > > Android has the Vendor Test Suite where automated tests could be added > > for this. Is that what you're thinking of? > > tools/testing/selftests/ is a good start. VTS is the worst-case as no > one can really run that on their own, but it is better than nothing. > Having no test at all for this is not ok. > > thanks, > > greg k-h