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 02DD0C282D1 for ; Sun, 9 Mar 2025 12:09:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5708E280003; Sun, 9 Mar 2025 08:09:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51FE7280001; Sun, 9 Mar 2025 08:09:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C1C1280003; Sun, 9 Mar 2025 08:09:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 176F9280001 for ; Sun, 9 Mar 2025 08:09:32 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A133EAC0B7 for ; Sun, 9 Mar 2025 12:09:32 +0000 (UTC) X-FDA: 83201892984.23.9191D74 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by imf18.hostedemail.com (Postfix) with ESMTP id AA84D1C0006 for ; Sun, 9 Mar 2025 12:09:30 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QxzKM2NB; spf=pass (imf18.hostedemail.com: domain of amir73il@gmail.com designates 209.85.218.51 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=1741522170; 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=fNxlWzrhZAfEP/KkGdHRDcm/Kf2Os7XzcAXdYkXJHik=; b=spXsKE4t4z5alM8D+DjEJ4kKBj6XCP1YQMx8q3KOBreKl2z4EIVijR/Jyxyvi2xNqMxij9 4FidDv7zsM68UA7kPhMgNxyi2FVvPC7z3wN5X0EWTDowbZpRDnYOd0ZMGM6F8Ef+LkAGRR 6IwnATcVCFsxmUX4pN2ZQgqk/+m5oTo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QxzKM2NB; spf=pass (imf18.hostedemail.com: domain of amir73il@gmail.com designates 209.85.218.51 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=1741522170; a=rsa-sha256; cv=none; b=nCCNZsv1EfelT9Sp3ykFxFHdJ0zPO9PjPPvAluZ3XFAqWRxqV1FEQwT1ZeiIoFgKs7sMan es9ED92qobhRrFE+6Rr9Uc0gn1zlpdx7I2Nx1b/eVKPea7wJyWO4vHEE2aZT8QWY3eEesz Ubw6sz+6XFn9rRyhpbm+Bg9VmmZRAl8= Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-ac286d4ed05so87942866b.3 for ; Sun, 09 Mar 2025 05:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741522169; x=1742126969; 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=fNxlWzrhZAfEP/KkGdHRDcm/Kf2Os7XzcAXdYkXJHik=; b=QxzKM2NBZmETfMX+ZDbNhjwYpdjewEy5V8Xmruq/jfewlvfhXBaEsXc65DfgFMEuje rXUPcOnfrgPpcwATKVpO0MST82J+QyApJlVXo+ETjNgkvBpeNfjPIiuDi/pSmHnFteFu E+Rjf+et36GR62tG6rqKJ3GUw83Vm/EyNBucQwHztq3N+VXQm25jg4Kvs3UKYAR0duBT atYPTcx6huCUNKkIgcy824GAoL6j5/KfcBJOZBA1cV06kZLqYYsajfGz11F5BtHWCA3g 6XkfsefbTqOjyi1ZNVG9HmohY34lK7JZ2HcLNx5SXguygBYYehFs3CkGud8On5/s2tFw Euvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741522169; x=1742126969; 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=fNxlWzrhZAfEP/KkGdHRDcm/Kf2Os7XzcAXdYkXJHik=; b=ChozLhZPCEBAhxZlXMkL7OSx8/omovkL+hN76mPSTRrtPT7PsKhP723JRa46Zor89/ tqxgfgxDq+EeVXq1dQL3z+g1YFk3xltxJJFakXmnst5AbLHg4ra4oznKRLhDpzLzbjnL ioM7o3//87x4tHP1O9mTZ7iqnsqdlGq0f3mxybtl4QmMbe3IyITotztfsKMj7V/iafIR LcV65irzAwb4D+ufqWIUWqlqqqBXaidDu8zHwHtcja+LKV5HW+wedYBNJgYdUHF7D8ER 1CytAEf/51AvNOvXZ6VhIv58TssSXIxahLtasN3HQ+G69CBbkqisZu9N4hvnWCAQqBSe ZqfQ== X-Forwarded-Encrypted: i=1; AJvYcCVcw/ZjV8FsMuG2b4ylvSDv/nyHP13zD9tTnVIl/akxZQPZx/Twf1/4P2DKB6Km3R2N0wp3qZuPEw==@kvack.org X-Gm-Message-State: AOJu0YwrAtjMpnSba3oSGLYJOeULDRmPLA3Q7qGzE+vG2XYDK6PIY1Kj IXlXS4M6qCb5rieJ0HKAeeyMe6Y3ybvEJCOW4uHDVYcI+DYKh4yRs2iPDHxe/xfJV1lcykI1Fdz XI22j6Nz6fdbWmeduAHaE28eGsP4= X-Gm-Gg: ASbGnctbLwJcpum1pD4r94mbqV2QRYcMaqvD2WhrWRMUd3YunTvVWf+6q1And3vFxiw /JV1oK4GVf7y4/zkzl9Wh9QWmmX1/HS7rxZCjSJGZUr74Jts/PK7YrkU9wdMz9A3wfL4a4+mQc/ Aodl0EOOKDLIEgVlZNbk90F9S7Xw== X-Google-Smtp-Source: AGHT+IGgrFqJJNVC5UL1diLMhW9a2kAoskP4FsjK8wLzW90lJ1WC8VhXDjuGoC56OFwUe9K9Bp/gIxMdquEqcns7K9M= X-Received: by 2002:a17:907:c15:b0:abf:b2d1:bb4c with SMTP id a640c23a62f3a-ac252ed8d23mr1177626466b.52.1741522168700; Sun, 09 Mar 2025 05:09:28 -0700 (PDT) MIME-Version: 1.0 References: <67a487f7.050a0220.19061f.05fc.GAE@google.com> <67c4881e.050a0220.1dee4d.0054.GAE@google.com> <7ehxrhbvehlrjwvrduoxsao5k3x4aw275patsb3krkwuq573yv@o2hskrfawbnc> <20250304161509.GA4047943@perftesting> <20250304203657.GA4063187@perftesting> <20250307154614.GA59451@perftesting> In-Reply-To: From: Amir Goldstein Date: Sun, 9 Mar 2025 13:09:16 +0100 X-Gm-Features: AQ5f1JqWUBTbrJKW9qBHk2sgfGwSWVhKZct8CRch-tjqmxf_0yFsxo8aOQ5NZZs Message-ID: Subject: Re: [syzbot] [xfs?] WARNING in fsnotify_file_area_perm To: Josef Bacik Cc: Jan Kara , syzbot , akpm@linux-foundation.org, axboe@kernel.dk, brauner@kernel.org, cem@kernel.org, chandan.babu@oracle.com, djwong@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AA84D1C0006 X-Stat-Signature: g56p1w4di6kmbsp37d6t9pw1cwh8bmfk X-Rspam-User: X-HE-Tag: 1741522170-933825 X-HE-Meta: U2FsdGVkX1/mZMiZ/gGDaIeCSIaASCdC2oXoqsKhiHkx79NUIj4tgjp7UhsDDViMn0cb1FzFOR1t2Smtj1AoDNDXhbwXoC9mURi7jdZ72fIcW7WqyYQj7uFPcavuUaWB5R7ZPgKSRfxHUT6v0zzfqaUcumGJzPCQMKWZRi2GdqNVMdO21W9YnJEh8QGDgNdnfkSBqS0PDiAQQjtqCLFsYnXMnj0tp4/ayE79aL9G3DCz3LnKxplaIoq3xYuw6HPagjmaauXADBzsjErZbFsTUqZns9S0tTDmrByt5f5CmGbCwILpRt0lwVe3MtGoKgwxjknAf+lEeOH7la+Wmp/E2vRwYcN89517BX/sbr8brJmt89ZyZHf2fjtifsiGr4RrCiwBlbAzUq6NoxzJlD7py86ujBrL4RVUT3xWTc++ONNM9erZ1WBPTVrPO00vvbxZsfvL5HNOHQweZzUTmArOOQfhUOQlszNZuQzm8mEzCKg1wpTe0HB5sPQM6ckPhgPhAwPE3POx66iCvuzR/mLyZcZPBj/xjRqR5IvQybVmC+X9TRrY6VyCltFQ0eu5I8h/KAAfAw+d0WgYXwrpNbfo0zGeW/9fkxujIeE+VNeMjNEcsa+MQZcV+RfegdYDR8zIvLAMvsfS6r6Jchdf4Qd9kXhZxuhiQHUQ7mg7ZV76CcOs6rML+LW0YTIrtaGM5LL0oQ32/dFbc8iVkcS/wYeBYbIITvcMdWwkt3rRcyUdJYzKurghaJiitljnAvxQRmwN+PVQNG6fcJaMtMIs+g+xLLyEcWAAlbkxN+vvDGf6lPhhriOK9FRtYzj2KjYiElzsKxhgyGt83+DMMn733H3EXsZPvrSROcLo5v9AUNyQVUBYRwmcMrbcpDntq6KbJrkpuOw+/jYNOlN+dDW03pbdbWy2pV4xAMeI3/Ep56UiM3kifze9bE2s7fcmtYSJtPiN5+fY3Pw8Q9d8lDbt6mZ OxRDGyds iyqf87kW3IYDQV+kcsV8g8WG9sciFskEPhRpGlzmcm8YDZevlCFiaXvzLTQUMd6UO3ObaEb2GCu4kj9o2XAILoEog0QB0LdLp5dbCQlb5FWoquTOR/1NhnJ9TqWplWdrY6tCQXJGtBoQXRT/d4awRB3dUIqGf5csozGLj6NJg5TUQSczzUkjPA2NjGRX8/r/Blrf3qX1Uigy0TsBSs4KHidsf+obGvD8Lews+hIbqz+XmkRv4IzMAu+u1AZ7W33VdfxLX0k4rFopUF+kJrou31h+ztXYiCLz+uYllfWU5AccSIHFbK/2LyFYBEjuinctNQ+ew535lxLwqqsrvJV1VJ6syD3CLmGpuODViNkzX52jVQN8SPTFny/SrEc+e5qRPIMhEBQbYqP+8AwTfWWDZGanvqBOoYoUrB4XFoimV3donv75c58/Ou70lNiHVKtFy5YsGqhxgHbQvubr8OuOoCttnj/O3Z7LS3txltsVBZ6iNcddZh847vynVAdKZLekmYYXr2Q66d9qzgYgDKYMcdVWTKIkdF52ZS5Kf1Eu8Qp60oIdpcrunsy1hHg5nCtQm7FJyeJrrg4n9hgy4nh7v4k0ZkQ== 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 Fri, Mar 7, 2025 at 6:45=E2=80=AFPM Amir Goldstein = wrote: > > On Fri, Mar 7, 2025 at 5:07=E2=80=AFPM Amir Goldstein wrote: > > > > On Fri, Mar 7, 2025 at 4:46=E2=80=AFPM Josef Bacik wrote: > > > > > > On Tue, Mar 04, 2025 at 10:13:39PM +0100, Amir Goldstein wrote: > > > > On Tue, Mar 4, 2025 at 9:37=E2=80=AFPM Josef Bacik wrote: > > > > > > > > > > On Tue, Mar 04, 2025 at 09:27:20PM +0100, Amir Goldstein wrote: > > > > > > On Tue, Mar 4, 2025 at 5:15=E2=80=AFPM Josef Bacik wrote: > > > > > > > > > > > > > > On Tue, Mar 04, 2025 at 04:09:16PM +0100, Amir Goldstein wrot= e: > > > > > > > > On Tue, Mar 4, 2025 at 12:06=E2=80=AFPM Jan Kara wrote: > > > > > > > > > > > > > > > > > > Josef, Amir, > > > > > > > > > > > > > > > > > > this is indeed an interesting case: > > > > > > > > > > > > > > > > > > On Sun 02-03-25 08:32:30, syzbot wrote: > > > > > > > > > > syzbot has found a reproducer for the following issue o= n: > > > > > > > > > ... > > > > > > > > > > ------------[ cut here ]------------ > > > > > > > > > > WARNING: CPU: 1 PID: 6440 at ./include/linux/fsnotify.h= :145 fsnotify_file_area_perm+0x20c/0x25c include/linux/fsnotify.h:145 > > > > > > > > > > Modules linked in: > > > > > > > > > > CPU: 1 UID: 0 PID: 6440 Comm: syz-executor370 Not taint= ed 6.14.0-rc4-syzkaller-ge056da87c780 #0 > > > > > > > > > > Hardware name: Google Google Compute Engine/Google Comp= ute Engine, BIOS Google 12/27/2024 > > > > > > > > > > pstate: 80400005 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS B= TYPE=3D--) > > > > > > > > > > pc : fsnotify_file_area_perm+0x20c/0x25c include/linux/= fsnotify.h:145 > > > > > > > > > > lr : fsnotify_file_area_perm+0x20c/0x25c include/linux/= fsnotify.h:145 > > > > > > > > > > sp : ffff8000a42569d0 > > > > > > > > > > x29: ffff8000a42569d0 x28: ffff0000dcec1b48 x27: ffff00= 00d68a1708 > > > > > > > > > > x26: ffff0000d68a16c0 x25: dfff800000000000 x24: 000000= 0000008000 > > > > > > > > > > x23: 0000000000000001 x22: ffff8000a4256b00 x21: 000000= 0000001000 > > > > > > > > > > x20: 0000000000000010 x19: ffff0000d68a16c0 x18: ffff80= 00a42566e0 > > > > > > > > > > x17: 000000000000e388 x16: ffff800080466c24 x15: 000000= 0000000001 > > > > > > > > > > x14: 1fffe0001b31513c x13: 0000000000000000 x12: 000000= 0000000000 > > > > > > > > > > x11: 0000000000000001 x10: 0000000000ff0100 x9 : 000000= 0000000000 > > > > > > > > > > x8 : ffff0000c6d98000 x7 : 0000000000000000 x6 : 000000= 0000000000 > > > > > > > > > > x5 : 0000000000000020 x4 : 0000000000000000 x3 : 000000= 0000001000 > > > > > > > > > > x2 : ffff8000a4256b00 x1 : 0000000000000001 x0 : 000000= 0000000000 > > > > > > > > > > Call trace: > > > > > > > > > > fsnotify_file_area_perm+0x20c/0x25c include/linux/fsno= tify.h:145 (P) > > > > > > > > > > filemap_fault+0x12b0/0x1518 mm/filemap.c:3509 > > > > > > > > > > xfs_filemap_fault+0xc4/0x194 fs/xfs/xfs_file.c:1543 > > > > > > > > > > __do_fault+0xf8/0x498 mm/memory.c:4988 > > > > > > > > > > do_read_fault mm/memory.c:5403 [inline] > > > > > > > > > > do_fault mm/memory.c:5537 [inline] > > > > > > > > > > do_pte_missing mm/memory.c:4058 [inline] > > > > > > > > > > handle_pte_fault+0x3504/0x57b0 mm/memory.c:5900 > > > > > > > > > > __handle_mm_fault mm/memory.c:6043 [inline] > > > > > > > > > > handle_mm_fault+0xfa8/0x188c mm/memory.c:6212 > > > > > > > > > > do_page_fault+0x570/0x10a8 arch/arm64/mm/fault.c:690 > > > > > > > > > > do_translation_fault+0xc4/0x114 arch/arm64/mm/fault.c:= 783 > > > > > > > > > > do_mem_abort+0x74/0x200 arch/arm64/mm/fault.c:919 > > > > > > > > > > el1_abort+0x3c/0x5c arch/arm64/kernel/entry-common.c:4= 32 > > > > > > > > > > el1h_64_sync_handler+0x60/0xcc arch/arm64/kernel/entry= -common.c:510 > > > > > > > > > > el1h_64_sync+0x6c/0x70 arch/arm64/kernel/entry.S:595 > > > > > > > > > > __uaccess_mask_ptr arch/arm64/include/asm/uaccess.h:16= 9 [inline] (P) > > > > > > > > > > fault_in_readable+0x168/0x310 mm/gup.c:2234 (P) > > > > > > > > > > fault_in_iov_iter_readable+0x1dc/0x22c lib/iov_iter.c:= 94 > > > > > > > > > > iomap_write_iter fs/iomap/buffered-io.c:950 [inline] > > > > > > > > > > iomap_file_buffered_write+0x490/0xd54 fs/iomap/buffere= d-io.c:1039 > > > > > > > > > > xfs_file_buffered_write+0x2dc/0xac8 fs/xfs/xfs_file.c:= 792 > > > > > > > > > > xfs_file_write_iter+0x2c4/0x6ac fs/xfs/xfs_file.c:881 > > > > > > > > > > new_sync_write fs/read_write.c:586 [inline] > > > > > > > > > > vfs_write+0x704/0xa9c fs/read_write.c:679 > > > > > > > > > > > > > > > > > > The backtrace actually explains it all. We had a buffered= write whose > > > > > > > > > buffer was mmapped file on a filesystem with an HSM mark.= Now the prefaulting > > > > > > > > > of the buffer happens already (quite deep) under the file= system freeze > > > > > > > > > protection (obtained in vfs_write()) which breaks assumpt= ions of HSM code > > > > > > > > > and introduces potential deadlock of HSM handler in users= pace with filesystem > > > > > > > > > freezing. So we need to think how to deal with this case.= .. > > > > > > > > > > > > > > > > Ouch. It's like the splice mess all over again. > > > > > > > > Except we do not really care to make this use case work wit= h HSM > > > > > > > > in the sense that we do not care to have to fill in the mma= ped file content > > > > > > > > in this corner case - we just need to let HSM fail the acce= ss if content is > > > > > > > > not available. > > > > > > > > > > > > > > > > If you remember, in one of my very early version of pre-con= tent events, > > > > > > > > the pre-content event (or maybe it was FAN_ACCESS_PERM itse= lf) > > > > > > > > carried a flag (I think it was called FAN_PRE_VFS) to commu= nicate to > > > > > > > > HSM service if it was safe to write to fs in the context of= event handling. > > > > > > > > > > > > > > > > At the moment, I cannot think of any elegant way out of thi= s use case > > > > > > > > except annotating the event from fault_in_readable() as "un= safe-for-write". > > > > > > > > This will relax the debugging code assertion and notify the= HSM service > > > > > > > > (via an event flag) that it can ALLOW/DENY, but it cannot f= ill the file. > > > > > > > > Maybe we can reuse the FAN_ACCESS_PERM event to communicate > > > > > > > > this case to HSM service. > > > > > > > > > > > > > > > > WDYT? > > > > > > > > > > > > > > I think that mmap was a mistake. > > > > > > > > > > > > What do you mean? > > > > > > Isn't the fault hook required for your large executables use ca= se? > > > > > > > > > > I mean the mmap syscall was a mistake ;). > > > > > > > > > > > > > ah :) > > > > > > > > > > > > > > > > > > > > > > > > Is there a way to tell if we're currently in a path that is u= nder fsfreeze > > > > > > > protection? > > > > > > > > > > > > Not at the moment. > > > > > > At the moment, file_write_not_started() is not a reliable check > > > > > > (has false positives) without CONFIG_LOCKDEP. > > > > > > > > > > > > > > One very ugly solution is to require CONFIG_LOCKDEP for > > > > pre-content events. > > > > > > > > > > > Just denying this case would be a simpler short term solution= while > > > > > > > we come up with a long term solution. I think your solution i= s fine, but I'd be > > > > > > > just as happy with a simpler "this isn't allowed" solution. T= hanks, > > > > > > > > > > > > Yeh, I don't mind that, but it's a bit of an overkill consideri= ng that > > > > > > file with no content may in fact be rare. > > > > > > > > > > Agreed, I'm fine with your solution. > > > > > > > > Well, my "solution" was quite hand-wavy - it did not really say how= to > > > > propagate the fact that faults initiated from fault_in_readable(). > > > > Do you guys have any ideas for a simple solution? > > > > > > Sorry I've been elbow deep in helping getting our machine replacement= s working > > > faster. > > > > > > I've been thnking about this, it's not like we can carry context from= the reason > > > we are faulting in, at least not simply, so I think the best thing to= do is > > > either > > > > > > 1) Emit a precontent event at mmap() time for the whole file, since r= eally all I > > > care about is faulting at exec time, and then we can just skip the pr= econtent > > > event if we're not exec. > > > > Sorry, not that familiar with exec code. Do you mean to issue pre-conte= nt > > for page fault only if memory is mapped executable or is there another = way > > of knowing that we are in exec context? > > > > If the former, then syzbot will catch up with us and write a buffer whi= ch is > > mapped readable and exec. > > Oh, I was being silly. You meant to call the hook from page fault only for FMODE_EXEC. This makes sense to me. I will try to write it up. > > > > > > 2) Revert the page fault stuff, put back your thing to fault the whol= e file, and > > > wait until we think of a better way to deal with this. > > > > > > Obviously I'd prefer not #2, but I'd really, really rather not chuck = all of HSM > > > because my page fault thing is silly. I'll carry what I need interna= lly while > > > we figure out what to do upstream. #1 doesn't seem bad, but I haven'= t thought > > > about it that hard. Thanks, > > > > > > > So I started to test this patch, but I may be doing something very > > terribly wrong > > with this. Q: What is this something that is terribly wrong? > > > > > > diff --git a/include/linux/fs.h b/include/linux/fs.h > > index 2788df98080f8..a8822b44d4967 100644 > > --- a/include/linux/fs.h > > +++ b/include/linux/fs.h > > @@ -3033,13 +3033,27 @@ static inline void file_start_write(struct file= *file) > > if (!S_ISREG(file_inode(file)->i_mode)) > > return; > > sb_start_write(file_inode(file)->i_sb); > > + /* > > + * Prevent fault-in user pages that may call HSM hooks with > > + * sb_writers held. > > + */ > > + if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) > > + pagefault_disable(); > > } > > > > static inline bool file_start_write_trylock(struct file *file) > > { > > if (!S_ISREG(file_inode(file)->i_mode)) > > return true; > > - return sb_start_write_trylock(file_inode(file)->i_sb); > > + if (!sb_start_write_trylock(file_inode(file)->i_sb)) > > + return false; > > + /* > > + * Prevent fault-in user pages that may call HSM hooks with > > + * sb_writers held. > > + */ > > + if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) > > + pagefault_disable(); > > + return true; > > } > > > > /** > > @@ -3053,6 +3067,8 @@ static inline void file_end_write(struct file *fi= le) > > if (!S_ISREG(file_inode(file)->i_mode)) > > return; > > sb_end_write(file_inode(file)->i_sb); > > + if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) > > + pagefault_enable(); > > } > > One thing that is wrong is that this is checking if the written file > is marked for > pre-content events, not the input buffer mmaped file. > > What we would have needed here is a check of > unlikely(fsnotify_sb_has_priority_watchers(sb, > FSNOTIFY_PRIO_PRE_CONTENT= ))) > > But Linus will not like that... > > Do we even care about optimizing the pre-content hooks of sporadic files > that are not marked for pre-content events when there are pre-content > watches on the filesystem? > > I think all of our use cases mark the sb for pre-content events anyway > and do not care about a bit of overhead for non-marked files. > If that is the case we can do away with the extra optimization > and then the changes above will really solve the issue. > > I've squashed the followup change to the fsnotify-fixes branch. This was actually a partial revert of commit 318652e07fa5b ("fsnotify: check if file is actually being watched for pre-content events on open"), so posted it as a separate patch. I am not sure if we need this if we go the route of event on mmap(), but posted the patches so we have them if we decide that they are useful. Thanks, Amir.