Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1443664lqh; Mon, 6 May 2024 07:57:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWiD1iSBJM/oqLEJmw2TEQVJrgCW59xvvRmO/5iiR/q0VjbbjvGb6MIW5JsXvz+CoDLwE0Op4eyrge0y+zfh4cw7BvtxK6jqC1u5z0Aag== X-Google-Smtp-Source: AGHT+IHmJ/MQbZm7CPu+dl+iWFcmiNt4qLc5rbqyfUBQZ7vCCZD6NJp74b6T38JC1CHYDNjgZTlD X-Received: by 2002:a17:902:ecc8:b0:1e2:a61e:47fa with SMTP id a8-20020a170902ecc800b001e2a61e47famr16485705plh.15.1715007452256; Mon, 06 May 2024 07:57:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715007452; cv=pass; d=google.com; s=arc-20160816; b=AnEgCYexK3NVI8GAc8I8uhd6h3mCAq/VMQi/RAuoc4sREXAGM3PT5lDM27LopNcxeF lTBD0EARHzFNlDvNJguq9tTuFYx+7ZxvV8nSuFqgl26Fd0OW+qJW/gN/yr7z8IqwYxsy vK7uvXtNhr9gtFFsrl8yvPrn4gburydRquBuhDc+7whbvA76LoxU0PzvLd9NefqP7zou rpb7VgJDdm16W12PcP15/HNLHFDe89A8nkRlbj4BoUAJyq9eGLmVVOkdz2IMEHAy73he dW1AbB85qRUEijhahwlAKeG946Cytzm4mcOSN8Ua2COyT21q4GBFs9bAONeaeahSW7ow CAQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=NmNWteJIHVG/FsNg6lLCmILTCJBN+MkrWHLSaZrPJk4=; fh=6mTavAdLE4QArsmDkOwSewjdteXhFLyM0Cq2o3ENG1Y=; b=BesiwA+DvTNSFULDRu5ekG8DWDdFCyYJjQXUqN90GULDQ15s3rh0qq6Okhp6fY3DGN QEhyEuYTchifHitQfJgni8RxJ9gad3U9t3c0qOj2RMh5BE5hNjVHMffDGy/mwmt7DZex omblkgcuNsaq2qVgniHHr/PlqpywMzAZvKGi4OzQhtOxGAla/F8jmIEWHlg745epGFi7 wAxofL96GT/nNf/HYmew42VRHf832DYSBSjI5WtK6lid+oqKbLIqg98yBYnQK2K3dXrb qL8oWpOD0ilzFoaWUDyDMGw+ptkxJIDqlUPJlgHE6AWXg9fa2NhA/iajb7BGm7l2fSxa ZKIA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=FvBv2a8y; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-169821-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169821-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z12-20020a170902d54c00b001e2832e333dsi8686456plf.511.2024.05.06.07.57.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 07:57:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169821-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=FvBv2a8y; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-169821-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169821-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1C5A72858B9 for ; Mon, 6 May 2024 12:37:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F69553E16; Mon, 6 May 2024 12:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="FvBv2a8y" Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18D5218C19 for ; Mon, 6 May 2024 12:37:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714999036; cv=none; b=YtRdl9/74Q4Q3A1o8oW5GUljArXPGFCAXBEO8Ma/+bnV0vGa+AJQRKr5QS6ncrajYb8T2eiet96cffFcULznE9X3t+szoDZ9mQQTNulzaNvzr/qcqjk/Eklk/VD7LHHYgZEFR2+3h8GhDA76u49w2w+kOPcQWH4w1R5pKIls4Kk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714999036; c=relaxed/simple; bh=W0ii3TeUy067aqvyqv+adtlSG49/aqc2GUx5qBI/NZk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oM2oGAm/QRZyy3lY3dKp/F3Yve0eZMtmXewDaGGDchwrvpBIlByOCWFKib7SXFDR2SXoRGKCjZZgGOFTmzvVBBIcxduQAUbBy/IZ5b5eIlv2dfadXr/c4hvjL8+aRe01+4t8IdGh1qGIuKOHzFGltq/GpLoEVQJyvtfOGdfKyNk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch; spf=none smtp.mailfrom=ffwll.ch; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b=FvBv2a8y; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ffwll.ch Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-41bd8bdd065so2594565e9.3 for ; Mon, 06 May 2024 05:37:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1714999033; x=1715603833; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=NmNWteJIHVG/FsNg6lLCmILTCJBN+MkrWHLSaZrPJk4=; b=FvBv2a8y7KaPOzeWXOlRwnY4lH1/WLZlQfEApXgvbpTUi6F1uRXzYtzHLxd34xbg1u lzQ4L8SrSgf8fTvp0TUjJwrwNvxd5DfSFpaHbPJ0Vust7ey2Py3OgetloVHthlUVf9qR z3R54uLMsCTneHkdevvCARM3z2xfNRrIIF8DQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714999033; x=1715603833; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NmNWteJIHVG/FsNg6lLCmILTCJBN+MkrWHLSaZrPJk4=; b=QxmIr3tOW8IeHwIbhXZIQgRQK3SF4aWYLp1LFjqSZfMSKl75afydQGcCAG/qY8orLL 8TydOMU3qXT8y8DtZ1pfCzI6EvjXpldsMsg+ffykYNPpXaVxKA6dfJgiC+zkEt0PsPaq VO7HxNuXb3Gudh1FpkD+mm3a4Ew7D0hzaGLXMNL//jkIRPjlb3Fomo0gnHMF2pVZwezn 5WHQ9S8H2r5KZcVk3yvOoRpZtaiDPZNxNg94tGsAVPU/AbCAQYJC82CnClZfRGAwYX18 RUleaJwm+PgZrboSvbhgBH8+VT/DbVJESneYlppFNmQyr1lkbxlT3aY0G/Jsn+JHlRy6 vdcw== X-Forwarded-Encrypted: i=1; AJvYcCVHmqenAlaxYDbp9+Na+S9hPKgb/okAGJR1/6i0xQDPnOJ+KnzUjebiHz3wPxpaPyFyBgSRaWg94xl+xfBNyBlPRG6rPekHw1hfn4pt X-Gm-Message-State: AOJu0YzaZ5Nz18IShRnvKfvMcDoQ70DGbOpAOsj4FPPnNI8puU/+ScLE NxhDeKGMCp0lkhYg87ZSIzZ3uQ25NweRVnV/HjUqIN0srG2xYfR7QHhjrT4jgsg= X-Received: by 2002:a05:600c:1d25:b0:418:ef65:4b11 with SMTP id l37-20020a05600c1d2500b00418ef654b11mr7944219wms.2.1714999033407; Mon, 06 May 2024 05:37:13 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id je16-20020a05600c1f9000b0041c7ac6b0ffsm19767802wmb.37.2024.05.06.05.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 05:37:13 -0700 (PDT) Date: Mon, 6 May 2024 14:37:10 +0200 From: Daniel Vetter To: Linus Torvalds Cc: Kees Cook , Al Viro , axboe@kernel.dk, brauner@kernel.org, christian.koenig@amd.com, dri-devel@lists.freedesktop.org, io-uring@vger.kernel.org, jack@suse.cz, laura@labbott.name, linaro-mm-sig@lists.linaro.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, minhquangbui99@gmail.com, sumit.semwal@linaro.org, syzbot+045b454ab35fd82a35fb@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: Re: [PATCH] epoll: try to be a _bit_ better about file lifetimes Message-ID: Mail-Followup-To: Linus Torvalds , Kees Cook , Al Viro , axboe@kernel.dk, brauner@kernel.org, christian.koenig@amd.com, dri-devel@lists.freedesktop.org, io-uring@vger.kernel.org, jack@suse.cz, laura@labbott.name, linaro-mm-sig@lists.linaro.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, minhquangbui99@gmail.com, sumit.semwal@linaro.org, syzbot+045b454ab35fd82a35fb@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com References: <202405031110.6F47982593@keescook> <20240503211129.679762-2-torvalds@linux-foundation.org> <20240503212428.GY2118490@ZenIV> <20240503214531.GB2118490@ZenIV> <202405031529.2CD1BFED37@keescook> <20240503230318.GF2118490@ZenIV> <202405031616.793DF7EEE@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux phenom 6.6.15-amd64 On Fri, May 03, 2024 at 04:41:19PM -0700, Linus Torvalds wrote: > On Fri, 3 May 2024 at 16:23, Kees Cook wrote: > > > > static bool __must_check get_dma_buf_unless_doomed(struct dma_buf *dmabuf) > > { > > return atomic_long_inc_not_zero(&dmabuf->file->f_count) != 0L; > > } > > > > If we end up adding epi_fget(), we'll have 2 cases of using > > "atomic_long_inc_not_zero" for f_count. Do we need some kind of blessed > > helper to live in file.h or something, with appropriate comments? > > I wonder if we could try to abstract this out a bit more. > > These games with non-ref-counted file structures *feel* a bit like the > games we play with non-ref-counted (aka "stashed") 'struct dentry' > that got fairly recently cleaned up with path_from_stashed() when both > nsfs and pidfs started doing the same thing. > > I'm not loving the TTM use of this thing, but at least the locking and > logic feels a lot more straightforward (ie the > atomic_long_inc_not_zero() here is clealy under the 'prime->mutex' > lock The one the vmgfx isn't really needed (I think at least), because all other drivers that use gem or ttm use the dma_buf export cache in drm/drm_prime.c, which is protected by a bog standard mutex. vmwgfx is unfortunately special in a lot of ways due to somewhat parallel dev history. So there might be an uapi reason why the weak reference is required. I suspect because vmwgfx is reinventing a lot of its own wheels it can't play the same tricks as gem_prime.c, which hooks into a few core drm cleanup/release functions. tldr; drm really has no architectural need for a get_file_unless_doomed, and I certainly don't want to spread it it further than the vmwgfx historical special case that was added in 2013. -Sima > IOW, the tty use looks correct to me, and it has fairly simple locking > and is just catching the the race between 'fput()' decrementing the > refcount and and 'file->f_op->release()' doing the actual release. > > You are right that it's similar to the epoll thing in that sense, it > just looks a _lot_ more straightforward to me (and, unlike epoll, > doesn't look actively buggy right now). > > Could we abstract out this kind of "stashed file pointer" so that we'd > have a *common* form for this? Not just the inc_not_zero part, but the > locking rule too? > > Linus -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch