Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp620750pxa; Tue, 4 Aug 2020 13:46:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBmrj7EkG/hReq69MDEEXTsvFNiYhShfDAG0fadM5L2X2T5qsZmEiZKsKkYuF8utfIlMD+ X-Received: by 2002:a17:906:c10d:: with SMTP id do13mr12582785ejc.109.1596573965808; Tue, 04 Aug 2020 13:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596573965; cv=none; d=google.com; s=arc-20160816; b=n5yCNI8hSt6MBaaZiqNkmCO6NKJQ0Wr1BQYkCx+Yj118Cs4kV+K9caLDG3Qku3zXAd EyV9Qu+My12/JyMrrLzGVTyPHoPA0GaasG00QI3vaSD2rTFJFGOMbguqvWNQEOnYJhDy hL73zx0HmpYJ9Cvrortz50kDKnLxk0U2KI2KyBdrIq72dAfBtFouifOiBZJSUQh/BE1W 7A8/vKBnXP6AEOZnaMNdvL1neGifXO2m7XYllUxDFmdzpN+A/PxQgJ0ORm3/se3/HDT3 JNkoP+yZH/6mkCe0Dkelnlt6R1/enkEskHAfWKetmD5RVx9QWAPTcdv5gfeg1x2MYTK8 bVHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=TlCjdbRMbP/wUOWxhVpHiQRbe/DkH4AfQXHxlQhoVjA=; b=S7BBLlqpBIrg8y3L+IiLe0Fh9BWNnSrEAFga+2G9FI/Kg+a0rJZNNusrPUwgjnq4Zr oYsv6nBnhXZfEjHtmguibw8y6ezGzGC3ZU5x/Gal6tkjJpel9xkVRV1Ho+tjStCse2/2 EZjRQ0XueR5uE4ckpJk9d/4wkmJitt33dZyFQ0mL+zcDnU2bGsXS/o+yQ0d+1lVEl7dq QpSZs6x3eTfrj2AoGiq+hVejMDzIB1LdiAoJmXQuDf60gM/VCDz2szX3V0vvG1NrweVP 6EZwwY+ucHIvMJLBNyGoD8JNd/9niIS9v+aQQBDGx80aYw7fVrh7/2yYd5JaIp/lya8/ rydA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EOi3TYyc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rl3si13261522ejb.643.2020.08.04.13.45.41; Tue, 04 Aug 2020 13:46:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EOi3TYyc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727888AbgHDUnE (ORCPT + 99 others); Tue, 4 Aug 2020 16:43:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbgHDUnD (ORCPT ); Tue, 4 Aug 2020 16:43:03 -0400 Received: from mail-vk1-xa44.google.com (mail-vk1-xa44.google.com [IPv6:2607:f8b0:4864:20::a44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E45C06174A for ; Tue, 4 Aug 2020 13:43:03 -0700 (PDT) Received: by mail-vk1-xa44.google.com with SMTP id m12so1137419vko.5 for ; Tue, 04 Aug 2020 13:43:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=TlCjdbRMbP/wUOWxhVpHiQRbe/DkH4AfQXHxlQhoVjA=; b=EOi3TYycOATstmP6d5D/4kHK77cpmm07nIj5AHuvfKmnLxKlJXrFY2QFvli6qNNCKA wqQ6Gx1OjpknqNrHPOsQ6i5pA4Nsl/0P+o8YnHG9NApjT17RZYWFm2ppHG2Oa91sfuxA V7/UnvO5E3bSeNaQiSfAOAo3JPrbiEZyVWI1xZBomo1Dr5q+3bfJwXgF9dxiWHQGZQ2B pLhcuu+09iTwu7nNQoaBdcI38gAj4GsGHfeAu8E+COwEkQ7qG41AYUnujdSx6sdIvWGB LIzkgD64Cktj4Lrk9qYaJk7E7mh6dWZ2/a0BboxrjqurpZNuVBcAGleuhJxvMUPytp7k 494Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=TlCjdbRMbP/wUOWxhVpHiQRbe/DkH4AfQXHxlQhoVjA=; b=WPVRUYLkDt6330hfUXaSn1RsBCK6wR7ktPVjQnnm6747ykU3j0bis5s1L4JFGPTDbX pqkCfAndE9MmUGfKW341FLdMo5DoDFOpxgnyHoGT7zrWEGXwU4aCl5lIoWsCpW9JZabc cpKYtBCXkRSHlpli3h0FyxQfbwusXgcrFxU8AMlXcyw1LEl0BMWwlRmMFyHWjXnOR+S2 0awKuYItV8dJjmc5quYBFrH3g1iZwC+hss9UR+J5Oj9F0okrTtQkE+ptbU/RplzKXJVC Qd1cG9FkVmOsFgZFVKKAv1R53kEvsRGVgKYIsRjSBnESUaB5pQCLFbEjo/ubz+/t90Uf Cb2Q== X-Gm-Message-State: AOAM531THUPpO5Q+Te7QYCMV2pAyuN4P3EOF9gnfXtiUgUjg6X1D2LEI caOdVRyJiEdTkzptg1X31GiYTw== X-Received: by 2002:a1f:eac1:: with SMTP id i184mr80498vkh.66.1596573782070; Tue, 04 Aug 2020 13:43:02 -0700 (PDT) Received: from google.com (182.71.196.35.bc.googleusercontent.com. [35.196.71.182]) by smtp.gmail.com with ESMTPSA id a3sm2560129vsh.31.2020.08.04.13.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2020 13:43:01 -0700 (PDT) Date: Tue, 4 Aug 2020 20:42:58 +0000 From: Kalesh Singh To: Al Viro Cc: Suren Baghdasaryan , Matthew Wilcox , Jonathan Corbet , Sumit Semwal , Steven Rostedt , Ingo Molnar , linux-doc@vger.kernel.org, LKML , linux-media@vger.kernel.org, DRI mailing list , linaro-mm-sig@lists.linaro.org, linux-fsdevel@vger.kernel.org, Hridya Valsaraju , Ioannis Ilkos , John Stultz , kernel-team Subject: Re: [PATCH 2/2] dmabuf/tracing: Add dma-buf trace events Message-ID: <20200804204258.GA1002979@google.com> References: <20200803144719.3184138-1-kaleshsingh@google.com> <20200803144719.3184138-3-kaleshsingh@google.com> <20200803154125.GA23808@casper.infradead.org> <20200803161230.GB23808@casper.infradead.org> <20200803222831.GI1236603@ZenIV.linux.org.uk> <20200804010913.GA2096725@ZenIV.linux.org.uk> <20200804154451.GA948167@google.com> <20200804182724.GK1236603@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200804182724.GK1236603@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 04, 2020 at 07:27:24PM +0100, Al Viro wrote: > On Tue, Aug 04, 2020 at 03:44:51PM +0000, Kalesh Singh wrote: > > > Hi Al. Thank you for the comments. Ultimately what we need is to identify processes > > that hold a file reference to the dma-buf. Unfortunately we can't use only > > explicit dma_buf_get/dma_buf_put to track them because when an FD is being shared > > between processes the file references are taken implicitly. > > > > For example, on the sender side: > > unix_dgram_sendmsg -> send_scm -> __send_scm -> scm_fp_copy -> fget_raw > > and on the receiver side: > > unix_dgram_recvmsg -> scm_recv -> scm_detach_fds -> __scm_install_fd -> get_file > > > > I understand now that fd_install is not an appropriate abstraction level to track these. > > Is there a more appropriate alternative where we could use to track these implicit file > > references? > > There is no single lock that would stabilize the descriptor tables of all > processes. And there's not going to be one, ever - it would be a contention > point from hell, since that would've been a system-wide lock that would have > to be taken by *ALL* syscalls modifying any descriptor table. Not going to > happen, for obvious reasons. Moreover, you would have to have fork(2) take > the same lock, since it does copy descriptor table. And clone(2) either does > the same, or has the child share the descriptor table of parent. > > What's more, a reference to struct file can bloody well survive without > a single descriptor refering to that file. In the example you've mentioned > above, sender has ever right to close all descriptors it has sent. Files > will stay opened as long as the references are held in the datagram; when > that datagram is received, the references will be inserted into recepient's > descriptor table. At that point you again have descriptors refering to > that file, can do any IO on it, etc. > > So "the set of processes that hold a file reference to the dma-buf" is > * inherently unstable, unless you are willing to freeze every > process in the system except for the one trying to find that set. > * can remain empty for any amount of time (hours, weeks, whatever), > only to get non-empty later, with syscalls affecting the object in question > done afterwards. > > So... what were you going to do with that set if you could calculate it? > If it's really "how do we debug a leak?", it's one thing; in that case > I would suggest keeping track of creation/destruction of objects (not > gaining/dropping references - actual constructors and destructors) to > see what gets stuck around for too long and use fuser(1) to try and locate > the culprits if you see that something *was* living for too long. "Try" > since the only reference might indeed have been stashed into an SCM_RIGHTS > datagram sitting in a queue of some AF_UNIX socket. Note that "fuser > needs elevated priveleges" is not a strong argument - the ability to > do that sort of tracking does imply elevated priveleges anyway, and > having a root process taking requests along the lines of "gimme the > list of PIDs that have such-and-such dma_buf in their descriptor table" > is not much of an attack surface. > > If you want to use it for something else, you'll need to describe that > intended use; there might be sane ways to do that, but it's hard to > come up with one without knowing what's being attempted... Hi Al. Thanks for the guidance and detailed explanation. It appears what we were trying to accomplish here is not feasible. Thanks, Kalesh