Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1050620lqh; Sun, 5 May 2024 13:54:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW8ziI6hGbRtHJxO5faiqupw9evEpvG2Olym5XYREC0yITSOfEGw1XDg2egj4osKZEWfvyJ+Q0h4SQL/H3/BTzHf/3nZtVscAPHm68zag== X-Google-Smtp-Source: AGHT+IFlYTziOBe8a+jaJgIHbEVzreziZSBb7n5EpDqOIJlQTmsCRKGZD70e1mkHjm1WCkKPOFeS X-Received: by 2002:a05:6359:4118:b0:186:119d:8c16 with SMTP id kh24-20020a056359411800b00186119d8c16mr10574599rwc.23.1714942469363; Sun, 05 May 2024 13:54:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714942469; cv=pass; d=google.com; s=arc-20160816; b=ZR9ZvjGW1DN7BazUzqBeBhOrLECDkyZNPFq9Ubt/w7l600e760I3SvtZ4mNMkY1xhw XkyqN11u6xvHutuVOqkugXjuGWkC9G2dtfHBP84VyuMDlH+daqmwGwHXiGiBJeUPKo/2 7eVTag4g1zzTabEqPtkNF6edMist0JeQxhmLmLzmKlHpshegZXHe8scf4kYyb4Liesqp 6vxg6OBqRzPYL/7kHnZccMH9odPgIqS8shxyH2SkqUCTVObbikhP2uV6dRFUICKbplaE 96ZOjd2zlgucNVQzK4tODKxgFaMW87lcanvSKMVXFWeTf5BSoZmdFE669QxbsQV/c3wS 1WpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=JMg+wUi7Jg85TzG1l7LAOtzS/OMsOgVla4IG61dTMc8=; fh=c1ofwW24hi+gsq0NJNYxVl6g8v1UNPy8PvfRrdVZQlE=; b=E39Fir6DEvOcAMxgcIcRciIqwwYvPkACRII8jMc7K+OFMxOkI7a1dUzQ6PlNiVKQwU b+Cprx8XAXE+RYql+kQFnToKgItdliTN4bHPr7TXmvsYlIoNUzRKVYzKSqvfN9CMe892 iHSsJYDHT6An3fz4G+nmUgslJiGUNyP/8YxPvNKyC1hfYK7v0Jt9YY7olQ4zdG9a2m9O jzeJ2tyi4eXZvCfcgyes/iYHHRh/PVj5tiuNQp0IUQ59Gcgf7BKsM/YNmXu92oyQoAwt r3rXfkNTrR13ygsyfixUfNSb6fq9drGQvOVwcJMtuO5pJsx75Eu2husfm1eymbGcFYjM ZFkw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QfxqIRwk; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-169144-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169144-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bq18-20020a056a02045200b0061c31a6bcbasi6252656pgb.65.2024.05.05.13.54.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 13:54:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169144-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QfxqIRwk; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-169144-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169144-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CF816B21057 for ; Sun, 5 May 2024 20:54:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0BF977602F; Sun, 5 May 2024 20:54:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="QfxqIRwk" Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 4B4507174F for ; Sun, 5 May 2024 20:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714942452; cv=none; b=XEdPYQovYOovQF3s7YiYnvS/iQ4o32nM+AV/aSxDtksFwXm8vgFBSj3t62NWapK/Kkd36QbKhppj1UfaReZdWc8gP4m4G2YGDmSymaOeWhUJARSUrxlQ5XN+J8CsunX0a0afcEFpvZ4SvoAHoTEKZYJPUTQGHQcGrIZ2DdQmV3Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714942452; c=relaxed/simple; bh=R+qvYyLMsL0XW6ld3jDTzisj//rKgA9vvCmBe+m5ItU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Nmm0fNJTrLBHpKlp74ar7PpuX5U+iKndWsQ9P61ZZWBfwToRwf72uWOCdXk0sjcLdtF1tgBnUnOD/mmH9fVvGNylsQaTcPwpwF/FazMfos1o0azBow5zuBfxbvz+0yCdRortXtFAbHT8hGSPakRtvr2X/VUlx9Yi0obr6n//zO0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=QfxqIRwk; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-51ab4ee9df8so1623977e87.1 for ; Sun, 05 May 2024 13:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1714942448; x=1715547248; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JMg+wUi7Jg85TzG1l7LAOtzS/OMsOgVla4IG61dTMc8=; b=QfxqIRwkFN/Tk6Jt3ALuLuCDAs2TWQ9uh6fefFuW61ENU3XmrXofSAf4AdpKOzvHpV Yja8kBdje1HVy5FRSUDK9BuUIWxNrOjYGgnhNcjWQtuhQXoSDD+xDqjyA5fw6X+aCAbO tWCzmsg5FF9HDsmkl9x8iFwlgsVN4n3B+HpLM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714942448; x=1715547248; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JMg+wUi7Jg85TzG1l7LAOtzS/OMsOgVla4IG61dTMc8=; b=ateZqU9jT/tDnhznKnTGgmFvyCa9as5RrUheWNXsks5j/MkeDM6IDhaWan8UXvfpwi sMBIWWPi2fY5x52GxvlPPGfYgV4iBWbm8CpgKHdrpe6o/WMYeFhI1fMnjPZjrsjVvxFm RSqEVGo6rYgSAdteFoBryKjqmFm7Y0i5yshZqrdI/05sw7lxA8Xs9MKnM/jNyZ6UpDrE J1vQj4/W9zgf9NKWJVdEZYT6yhFOvFFfvdHOH6FrYtCQXhdCB2gQQrjDJO22aLqrqVGy 9n0NQ4P3wDdlEeSH5sOGkf44XW46+RJDZGvtX7RxGKNgHkib2lAgQI4RW60SNe2cyEA4 wKsQ== X-Forwarded-Encrypted: i=1; AJvYcCXEjWWDlMJgNIDyKdXGWOL3zc22OGH7/ou5+e8TA8Er/JPlnpZJgHaRksOKdbbEuqU28a9Q2OCrgsUF+Z4/DdwGE/SG67sv40H1oeH3 X-Gm-Message-State: AOJu0YyAaDe4FLeP7sPR1ueIqvFi6sCO5oBBye6OEzK9+mbCjzj5kz4l kjbqH1vKx6eLCIafu6EX5SspssQCOgWuFXTPDeYkXpYqG7FQoEHmw0QO4tidZoeTKdR6yRYL3sx ChT3D1w== X-Received: by 2002:ac2:5b01:0:b0:520:107f:8375 with SMTP id v1-20020ac25b01000000b00520107f8375mr3009913lfn.50.1714942448161; Sun, 05 May 2024 13:54:08 -0700 (PDT) Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com. [209.85.128.45]) by smtp.gmail.com with ESMTPSA id gc4-20020a170906c8c400b00a59b2c5003csm1647485ejb.23.2024.05.05.13.54.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 05 May 2024 13:54:06 -0700 (PDT) Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4196c62bb4eso9506245e9.2 for ; Sun, 05 May 2024 13:54:05 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCWOiK5fVn1IzdyTgJ+0IBMVf/NgMad9d0dVuLckjFXl3+0PJjFhhiJNXjQeIFot79xkHnj5Ib56ZJ+MNQ/pql+cpNupJtZJNx4Aua0r X-Received: by 2002:a05:600c:314f:b0:416:88f9:f5ea with SMTP id h15-20020a05600c314f00b0041688f9f5eamr6455233wmo.34.1714942445499; Sun, 05 May 2024 13:54:05 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <202405031110.6F47982593@keescook> <20240503211129.679762-2-torvalds@linux-foundation.org> <20240503212428.GY2118490@ZenIV> <20240504-wohngebiet-restwert-6c3c94fddbdd@brauner> <20240505194603.GH2118490@ZenIV> <20240505203052.GJ2118490@ZenIV> In-Reply-To: <20240505203052.GJ2118490@ZenIV> From: Linus Torvalds Date: Sun, 5 May 2024 13:53:48 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] epoll: try to be a _bit_ better about file lifetimes To: Al Viro Cc: Christian Brauner , keescook@chromium.org, axboe@kernel.dk, 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 Content-Type: text/plain; charset="UTF-8" On Sun, 5 May 2024 at 13:30, Al Viro wrote: > > 0. special-cased ->f_count rule for ->poll() is a wart and it's > better to get rid of it. > > 1. fs/eventpoll.c is a steaming pile of shit and I'd be glad to see > git rm taken to it. Short of that, by all means, let's grab reference > in there around the call of vfs_poll() (see (0)). Agreed on 0/1. > 2. having ->poll() instances grab extra references to file passed > to them is not something that should be encouraged; there's a plenty > of potential problems, and "caller has it pinned, so we are fine with > grabbing extra refs" is nowhere near enough to eliminate those. So it's not clear why you hate it so much, since those extra references are totally normal in all the other VFS paths. I mean, they are perhaps not the *common* case, but we have a lot of random get_file() calls sprinkled around in various places when you end up passing a file descriptor off to some asynchronous operation thing. Yeah, I think most of them tend to be special operations (eg the tty TIOCCONS ioctl to redirect the console), but it's not like vfs_ioctl() is *that* different from vfs_poll. Different operation, not somehow "one is more special than the other". cachefiles and backing-file does it for regular IO, and drop it at IO completion - not that different from what dma-buf does. It's in ->read_iter() rather than ->poll(), but again: different operations, but not "one of them is somehow fundamentally different". > 3. dma-buf uses of get_file() are probably safe (epoll shite aside), > but they do look fishy. That has nothing to do with epoll. Now, what dma-buf basically seems to do is to avoid ref-counting its own fundamental data structure, and replaces that by refcounting the 'struct file' that *points* to it instead. And it is a bit odd, but it actually makes some amount of sense, because then what it passes around is that file pointer (and it allows passing it around from user space *as* that file). And honestly, if you look at why it then needs to add its refcount to it all, it actually makes sense. dma-bufs have this notion of "fences" that are basically completion points for the asynchronous DMA. Doing a "poll()" operation will add a note to the fence to get that wakeup when it's done. And yes, logically it takes a ref to the "struct dma_buf", but because of how the lifetime of the dma_buf is associated with the lifetime of the 'struct file', that then turns into taking a ref on the file. Unusual? Yes. But not illogical. Not obviously broken. Tying the lifetime of the dma_buf to the lifetime of a file that is passed along makes _sense_ for that use. I'm sure dma-bufs could add another level of refcounting on the 'struct dma_buf' itself, and not make it be 1:1 with the file, but it's not clear to me what the advantage would really be, or why it would be wrong to re-use a refcount that is already there. Linus