From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BA4EC02194 for ; Mon, 3 Feb 2025 22:05:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73AFD6B007B; Mon, 3 Feb 2025 17:05:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EADF6B0083; Mon, 3 Feb 2025 17:05:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B1F76B0085; Mon, 3 Feb 2025 17:05:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3E3C76B007B for ; Mon, 3 Feb 2025 17:05:09 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CA4591C7497 for ; Mon, 3 Feb 2025 22:05:08 +0000 (UTC) X-FDA: 83080014696.06.7E35349 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by imf30.hostedemail.com (Postfix) with ESMTP id CACD680019 for ; Mon, 3 Feb 2025 22:05:06 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Bs9DN/Vr"; spf=pass (imf30.hostedemail.com: domain of amir73il@gmail.com designates 209.85.208.45 as permitted sender) smtp.mailfrom=amir73il@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738620306; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LfWPhz+INVJNiVKqXovLTadhCIqvZ16J6qdYwJ+KXTc=; b=jnbncV1WBn7K1XUdgtdnJ2xHR51X1UuBVm3gRQeC6ytj2TmS78U+rnZVRYsTNE3fxhYR7b OSCCQxJz99nWOTy7IFGSxsMEEB6nmdjlvziMfKEAJH4jFWs1uMIzfag36zNASrvctgQtYd 5knnRB8SoS3/b95xfP/pFS+jM3fIHhA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Bs9DN/Vr"; spf=pass (imf30.hostedemail.com: domain of amir73il@gmail.com designates 209.85.208.45 as permitted sender) smtp.mailfrom=amir73il@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738620306; a=rsa-sha256; cv=none; b=GfNnZxjb9FehtECwm/aD18dPjZonB2VW0ewM0uKxXNyenCZKSP3w8Mt4R4emh//jZOgv+z qnxjrG44cwLeuh8Q1wqiZTpGdlpSW6IsDeGc1IX0QvlrHTYFgfpqRQ2E85PxvT8m1nH4Go P999MPDw8itP4PvO7H4Lq4kF1rNY/Qs= Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5d9837f201aso11123343a12.0 for ; Mon, 03 Feb 2025 14:05:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738620305; x=1739225105; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LfWPhz+INVJNiVKqXovLTadhCIqvZ16J6qdYwJ+KXTc=; b=Bs9DN/VriRXNNv1d5LMOO5zFjk6WskV6IEbq05zEFNqshZHlsxrIYKJ0rAanxdLZcC gjRXM9+BZs1IeQVJCqNUi7AilkSltrTi5mkKgJoUETeQ5qFyb/3GzIOrgktMUWTAARp4 Tczga4e+Drq9NmBPm2E6tJDA0fwhw1v45qPrK4E16Ef21wjXuW2ruj0rjysLh9yOsMoo XDUoATUiETf7r63a2U8qzLJNb4rkwlRrsfivNm3o6oyCgKldnjfa72CsceFQrUZA+hTZ tDPU/OEc8mF8Yj/YVgTELrLpFvBlW+fZm6/+dcfcZkJKs9UcYNpPOA6xTXiQY9b9BpWI 71Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738620305; x=1739225105; h=content-transfer-encoding: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=LfWPhz+INVJNiVKqXovLTadhCIqvZ16J6qdYwJ+KXTc=; b=Tx5PGwAJITq/4CJX5mc0nh6viI6p00kW2zSAGI5S8UPLVLVgYTxlknCsyPCidSKQZK tBPKmcpyx+pVRrQi0pQggAUK+9IIhi30HGl/tOuF0RPjuPRtsd+ItVcH9lZoOncjpTj+ c8v7K2t4ErzHLqmrseVe17ze/GRyMSLuquiLTNqOOLFwaH3FQAsvFDykJt7JWcXzw3Nz Sj5wnT4plKNmpqzRBoXLtvd0RoxspYnMaMhkrySviuewF7yfL3+Xqtd9YEx9kJG+LJd8 n4eckSr4FbALFncRKnoBqkw5QiTnmqn94a8Vgrn0AwD6xrOHCVK38zxpSA9nKqo2AYBA zGJA== X-Forwarded-Encrypted: i=1; AJvYcCVCe8Vr+OCeNw9EqwE09redI1Po8Fp7f/AKCIv3k04QWTnLWSej2cz7+7LBZgjeA1iQnHaYr+6oqw==@kvack.org X-Gm-Message-State: AOJu0YwTqO4fSuFBO6jGMu5QlIcANvvOiwADrLykvJmCJwtg763OVSwu +OkPRFd7zSo8MeLoAS9xuWyFIdvoZ3M7ik5OkVmYN5u8ZURvTcsFnb/CUe5YBA06tlFBsbE/re1 B7+5SDIYgqIXCOBC9Ej8OV1Ug25E= X-Gm-Gg: ASbGnctjd9J1eI/Cwys12MR21UjDErQMom6E2eHvKPHd8Ihhxt7v4DvOZa86qIDAk4I +R1x6ilrzeeM3ap1whdzhd2V7ojzVz+sIrc8SdQ3El79IyX+fNhqSRwJXKC2x9fvI5DVd/Vlv X-Google-Smtp-Source: AGHT+IEBK110MqEEHGqul3TiQcmes0hYTWLnCbKjzyx7fAeU1bAn7xW39fRuNMB1W3Z9Juvhf087o643m1E06cI4MgU= X-Received: by 2002:a05:6402:13d2:b0:5db:7353:2b5c with SMTP id 4fb4d7f45d1cf-5dcc14db066mr910803a12.11.1738620304633; Mon, 03 Feb 2025 14:05:04 -0800 (PST) MIME-Version: 1.0 References: <9035b82cff08a3801cef3d06bbf2778b2e5a4dba.1731684329.git.josef@toxicpanda.com> <20250131121703.1e4d00a7.alex.williamson@redhat.com> <20250201-legehennen-klopfen-2ab140dc0422@brauner> <20250202-abbauen-meerrettich-912513202ce4@brauner> <20250203144135.1caef6c3.alex.williamson@redhat.com> In-Reply-To: <20250203144135.1caef6c3.alex.williamson@redhat.com> From: Amir Goldstein Date: Mon, 3 Feb 2025 23:04:53 +0100 X-Gm-Features: AWEUYZluDUNL1TbMXt-rEN5-evy5A4JQDjuv20638mpd-F-mrLwQ5eRV4vDdsoY Message-ID: Subject: Re: [REGRESSION] Re: [PATCH v8 15/19] mm: don't allow huge faults for files with pre content watches To: Alex Williamson Cc: Jan Kara , Christian Brauner , Linus Torvalds , Peter Xu , Josef Bacik , kernel-team@fb.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org, "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CACD680019 X-Stat-Signature: euwrx9k8kypid9zjxx9xtfz3j6pytupi X-Rspam-User: X-HE-Tag: 1738620306-600336 X-HE-Me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ncXzAPueZjfHJy2pb832uHtBuQEvFjHtD3LlJIApDojb9lxqJJt3tO0q59uSLxWCZsS9AijPuyU2kNDsBNjZmEjRViwxJquFdSuxwp2mHfcSBT9DJykhhTPRFQvCTcWj5m6OKM3hwyjFfIWD5ikLE6v7QufL2RotJ8yYmKVcdUjGkjXt4wMd4Dd7vmvii3ul5TculyD8WbwOnx+guAaRLbIyYcI7kDyQEwWc0mw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Feb 3, 2025 at 10:41=E2=80=AFPM Alex Williamson wrote: > > On Mon, 3 Feb 2025 21:39:27 +0100 > Amir Goldstein wrote: > > > On Mon, Feb 3, 2025 at 1:41=E2=80=AFPM Jan Kara wrote: > > > > > > On Sun 02-02-25 11:04:02, Christian Brauner wrote: > > > > On Sun, Feb 02, 2025 at 08:46:21AM +0100, Amir Goldstein wrote: > > > > > On Sun, Feb 2, 2025 at 1:58=E2=80=AFAM Linus Torvalds > > > > > wrote: > > > > > > > > > > > > On Sat, 1 Feb 2025 at 06:38, Christian Brauner wrote: > > > > > > > > > > > > > > Ok, but those "device fds" aren't really device fds in the se= nse that > > > > > > > they are character fds. They are regular files afaict from: > > > > > > > > > > > > > > vfio_device_open_file(struct vfio_device *device) > > > > > > > > > > > > > > (Well, it's actually worse as anon_inode_getfile() files don'= t have any > > > > > > > mode at all but that's beside the point.)? > > > > > > > > > > > > > > In any case, I think you're right that such files would (acci= dently?) > > > > > > > qualify for content watches afaict. So at least that should p= robably get > > > > > > > FMODE_NONOTIFY. > > > > > > > > > > > > Hmm. Can we just make all anon_inodes do that? I don't think yo= u can > > > > > > sanely have pre-content watches on anon-inodes, since you can't= really > > > > > > have access to them to _set_ the content watch from outside any= way.. > > > > > > > > > > > > In fact, maybe do it in alloc_file_pseudo()? > > > > > > > > > > > > > > > > The problem is that we cannot set FMODE_NONOTIFY - > > > > > we tried that once but it regressed some workloads watching > > > > > write on pipe fd or something. > > > > > > > > Ok, that might be true. But I would assume that most users of > > > > alloc_file_pseudo() or the anonymous inode infrastructure will not = care > > > > about fanotify events. I would not go for a separate helper. It'd b= e > > > > nice to keep the number of file allocation functions low. > > > > > > > > I'd rather have the subsystems that want it explicitly opt-in to > > > > fanotify watches, i.e., remove FMODE_NONOTIFY. Because right now we= have > > > > broken fanotify support for e.g., nsfs already. So make the subsyst= ems > > > > think about whether they actually want to support it. > > > > > > Agreed, that would be a saner default. > > > > > > > I would disqualify all anonymous inodes and see what actually does > > > > break. I naively suspect that almost no one uses anonymous inodes + > > > > fanotify. I'd be very surprised. > > > > > > > > I'm currently traveling (see you later btw) but from a very cursory > > > > reading I would naively suspect the following: > > > > > > > > // Suspects for FMODE_NONOTIFY > > > > drivers/dma-buf/dma-buf.c: file =3D alloc_file_pseudo(inode, d= ma_buf_mnt, "dmabuf", > > > > drivers/misc/cxl/api.c: file =3D alloc_file_pseudo(inode, cxl_vfs_m= ount, name, > > > > drivers/scsi/cxlflash/ocxl_hw.c: file =3D alloc_file_pseudo(= inode, ocxlflash_vfs_mount, name, > > > > fs/anon_inodes.c: file =3D alloc_file_pseudo(inode, anon_inod= e_mnt, name, > > > > fs/hugetlbfs/inode.c: file =3D alloc_file_pseudo(inode, m= nt, name, O_RDWR, > > > > kernel/bpf/token.c: file =3D alloc_file_pseudo(inode, path.mnt,= BPF_TOKEN_INODE_NAME, O_RDWR, &bpf_token_fops); > > > > mm/secretmem.c: file =3D alloc_file_pseudo(inode, secretmem_mnt, "s= ecretmem", > > > > block/bdev.c: bdev_file =3D alloc_file_pseudo_noaccount(BD_INODE(= bdev), > > > > drivers/tty/pty.c: static int ptmx_open(struct inode *inode, struct= file *filp) > > > > > > > > // Suspects for ~FMODE_NONOTIFY > > > > fs/aio.c: file =3D alloc_file_pseudo(inode, aio_mnt, "[aio]", > > > > > > This is just a helper file for managing aio context so I don't think = any > > > notification makes sense there (events are not well defined). So I'd = say > > > FMODE_NONOTIFY here as well. > > > > > > > fs/pipe.c: f =3D alloc_file_pseudo(inode, pipe_mnt, "", > > > > mm/shmem.c: res =3D alloc_file_pseudo(inode, mnt, name,= O_RDWR, > > > > > > This is actually used for stuff like IPC SEM where notification doesn= 't > > > make sense. It's also used when mmapping /dev/zero but that struct fi= le > > > isn't easily accessible to userspace so overall I'd say this should b= e > > > FMODE_NONOTIFY as well. > > > > I think there is another code path that the audit missed for getting th= ese > > pseudo files not via alloc_file_pseudo(): > > ipc/shm.c: file =3D alloc_file_clone(base, f_flags, > > > > which does not copy f_mode as far as I can tell. > > > > > > > > > // Unsure: > > > > fs/nfs/nfs4file.c: filep =3D alloc_file_pseudo(r_ino, ss_mnt, = read_name, O_RDONLY, > > > > > > AFAICS this struct file is for copy offload and doesn't leave the ker= nel. > > > Hence FMODE_NONOTIFY should be fine. > > > > > > > net/socket.c: file =3D alloc_file_pseudo(SOCK_INODE(sock), sock_m= nt, dname, > > > > > > In this case I think we need to be careful. It's a similar case as pi= pes so > > > probably we should use ~FMODE_NONOTIFY here from pure caution. > > > > > > > I tried this approach with patch: > > "fsnotify: disable notification by default for all pseudo files" > > > > But I also added another patch: > > "fsnotify: disable pre-content and permission events by default" > > > > So that code paths that we missed such as alloc_file_clone() > > will not have pre-content events enabled. > > > > Alex, > > > > Can you please try this branch: > > > > https://github.com/amir73il/linux/commits/fsnotify-fixes/ > > > > and verify that it fixes your issue. > > > > The branch contains one prep patch: > > "fsnotify: use accessor to set FMODE_NONOTIFY_*" > > and two independent Fixes patches. > > > > Assuming that it fixes your issue, can you please test each of the > > Fixes patches individually, because every one of them should be fixing > > the issue independently and every one of them could break something, > > so we may end up reverting it later on. > > Test #1: > > fsnotify: disable pre-content and permission events by default > fsnotify: disable notification by default for all pseudo files > fsnotify: use accessor to set FMODE_NONOTIFY_* > > Result: Pass, vfio-pci huge_fault observed > > Test #2: > > fsnotify: disable notification by default for all pseudo files > fsnotify: use accessor to set FMODE_NONOTIFY_* > > Result: Pass, vfio-pci huge_fault observed > > Test #3: > > fsnotify: disable pre-content and permission events by default > fsnotify: use accessor to set FMODE_NONOTIFY_* > > Result: Pass, vfio-pci huge_fault observed > > Test #4 (control): > > fsnotify: use accessor to set FMODE_NONOTIFY_* > > Result: Fail, no vfio-pci huge_fault observed > > For any combination of the Fixes patches: > > Tested-by: Alex Williamson > That was fast. I will post the patches. Thanks! Amir.