From patchwork Fri Nov 15 15:30:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876439 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 9FBCFD68BC6 for ; Fri, 15 Nov 2024 15:31:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36C726B0083; Fri, 15 Nov 2024 10:31:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3182E6B0085; Fri, 15 Nov 2024 10:31:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16A7F6B0088; Fri, 15 Nov 2024 10:31:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F02D76B0083 for ; Fri, 15 Nov 2024 10:31:26 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 736DA141887 for ; Fri, 15 Nov 2024 15:31:26 +0000 (UTC) X-FDA: 82788717144.10.C83918C Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by imf19.hostedemail.com (Postfix) with ESMTP id 85A531A0008 for ; Fri, 15 Nov 2024 15:30:27 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=xojlQ6pa; spf=none (imf19.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684595; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kR1XeBSj0UKEAyle1L8EQtWLZrkZWI4sB29nFtL0fR8=; b=gKLFozoJfdYJnweh5rWMbnQUvVhPxjTP4WsLsIkcg0HVAviJlaEsuJBalthlmatkt2wEHK Z82cLDSSjasExgwsPC8SwhHXFBzK8I8+1ov192h53XfFR2YvqU7hHjMXeSHYKo1cFZUlJb n/re6jqO6hAh1cBLrwqv2BYldG3Dg2o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684595; a=rsa-sha256; cv=none; b=KEXC4Nz/nb1sozO16/K0N74kJSYbn7WwIwt+y+5I0XD5K4Wi8y3h67nd77ELNBopfSOCuz EHP+AP+IVMv0HEuuY9hJqiLCz2MW2jznPFK9yXetvRTm8ho8U8INeqaIu/qMLXpIgaIsDs muIPhnebPgm2TqDWWx6MMMTldwWp0Wc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=xojlQ6pa; spf=none (imf19.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e38277e9477so852810276.0 for ; Fri, 15 Nov 2024 07:31:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684683; x=1732289483; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=kR1XeBSj0UKEAyle1L8EQtWLZrkZWI4sB29nFtL0fR8=; b=xojlQ6pamyGMqxfLeovxSM8JXH+B2IUUmN542bEFSEcbFS5Pb+Sx4+MH2Jc/KxOViJ M7Q/taFQZJHYApYXLePsE8Vm3aGCrJUmy5XWuqqHGDRKxOsdsXOkT17pFD+vXeUfDwAn PxAHJZ1nPt+eUq2O+gPjGg2V1AUspV94Eln+b8dzEzX3uHM4Gicx8QVchkF8zpdPzTC5 TQVs4goqL/i4i1XPvcXqSapk7NmAdQFbTBuzJ1UD7/Dsz9ofCs6raytlthFZi5faE06Q DIfjQT+dEIFhgE7bOQh4zIIaMOVKDuDmarQF3FjBBv29rJrm+VrvJ6sdRz6ffiSvmgL0 ZlGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684683; x=1732289483; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kR1XeBSj0UKEAyle1L8EQtWLZrkZWI4sB29nFtL0fR8=; b=J4u+2iewxXNEgfHfeo30aFZmcXuscmUSbdE/Mv0DbBWZRWiqxrX04N3J2En0bMvfJb +6uG9sFWjcs0FVboJ7rf13T+ebaDU+7HEtnRM1X9f5bHCO23JyOxICpkh7bbizXWY9ia Mme0gMvSmg5URUIxtO2MSCDH8YZKAYPB6WiBBmicpFwoaxfTp2aJb3ifLgMAZ48Xg4Ez RJw/pCQIamei89/JdDvh1GGIZFzMvlWN9hhRakK7Ga0H2ahDkayjF9pGp6t3FrcVckEJ oKGy1TK6/48wbiXXae8h/APpcQFmmn3iheMktBLhU6hN9IfYo3TBr2+KvAu+7q8govVJ 5dew== X-Forwarded-Encrypted: i=1; AJvYcCUcAXuFT6dPidapSub7/7y98ij0m0BWEYlCwgnRo602B3444efFYlzb9UaR4nSkScx9dVvx9YlV+A==@kvack.org X-Gm-Message-State: AOJu0YzkzBcZPz6FVYKT82RJz1MdsMAjqy88PTKDcooTOYy60imYPE7X gFkEbhzXPVDqaqoJCXssBW2ps8Wx8tAO7RRcBNHGBjlVzDqWILolidyITiJiu/c= X-Google-Smtp-Source: AGHT+IGBdJCygNHz6DEBCdeiVRgK2IumpYj4jyGOaPbgCKPpYL6CnPz3nA2B5qY78/GCUuIzkqAI7g== X-Received: by 2002:a05:6902:2b86:b0:e30:e1f3:2aab with SMTP id 3f1490d57ef6-e38263a1b87mr2546246276.39.1731684683163; Fri, 15 Nov 2024 07:31:23 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e38152fe65dsm991511276.35.2024.11.15.07.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:22 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 01/19] fs: get rid of __FMODE_NONOTIFY kludge Date: Fri, 15 Nov 2024 10:30:14 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: axey1wtit575kp4rsdt1eeiyd3pttxq4 X-Rspamd-Queue-Id: 85A531A0008 X-Rspam-User: X-HE-Tag: 1731684627-925289 X-HE-Meta: U2FsdGVkX19znfvPWk7pIL+C4YhZ0oOhZ/6f6nb1i+TZVsLi3rgjQchNK35qDfBtG2YSQkYrt8+E3cJNnVIJJte2Jyxc14+fIpKPBM1GklWkmBtQ9IidRHW+qhmgk3WRgPDpu/7GaZG/e1ivDk44rpk0lnrI+PBkRmBjHXxcL5FWZ9gINZyG6WXP7nHQ9kGzIOB3mqcAe3O1sD2/O9csMpNtSFichowVlGsDyorPKwXbNyFcIq1bWJDy24XiydbcpRs36sO125l3Y20gkAHDBtb4lSjfhB+SM+gAeXDTFnBY9DU1fbDHoXfFgJc1gUViQ3HWXUqVFmUp86ISnfoanDbkkbZ3GxWJqz+zIhaA/vB4fSM3YaH12DxgnlL5pr+knDEkEbXePcS/2/41dPAqQo2RJ2B1LyFidfyjyXL2todWQVNtW5kQ94+WaM5bqwY06KUkBQK3EqEyxew11vMOYsOZcuzZ5XUErPLV4ifFf4Tnhc7sgk9FZCHVG1iCxxZOkulvqBgg0cgXkpKJRoE7Qyty63NCo7QHynVw05FIxFtMYGjaeja7KGPXF0dfw/7ovbnosqiwe8DEIfzF8sHfniGw09+qBwL32JVNoKL7WOPw0X2u5elFsvwJuzquTDizj7+75HjjUL2QAdQUZwC2nMX2odBNSDnVMErcTOcNdkun2bxZhVvKqMODvzTN1M0ImqLh9leMQRG8AqSBlyNU/Cn5JG2G6zlSWTNknHvLkXuPQZ7FS65SKc9FYXwKHMj9ewkchU+xaCgtHJH88iwF5NqODkJzFg/Ovos6l2YBIXc9nTI6uLGzAsI/z5uR4Sf2lAg6kKfyD8dl2+5yztbFpqs+gvfzzOjq6H4HPxwI6RvDZriNxp29I1FoUMAkAEl1H/PQLCHbxUYR7WHkYRLOMwKgQLKjY9qlc39YsNPUfgZxJB+1YcHIm+3F2DTWrqYJ0vnLkM0+N26Oou5rwq1 9j63mqQq RQng+cSFQZQJSFp3Itf3mL74fIrSnQr+GJYz7tJvi+k6L1WEmfDCKcpWBO7X0fBgQGR0fWEp+TKp/RnmYndFz3PrQiL8D8Sey/INQIHUdePX7tKE501ojz1F/YZ7nCjYu4pMKqMzj5ACSuQvVqssx1WAFygFCXh4/7hSV+6+5ngKqR0VpxlcagK6L89Xer8+TryCPSR3vBk1/NjTL8/a6lA8BBTug6YjKuAzDUmJk5ZkFSR2XU5qeZIzTfxlNTj/kUtwa+ziV/fIY3xCCf0PRezOZJ8nksYBwr+XEPIsR7UKD0CaHWzd6wyCaEkseWd4kbb92lm/5EUYSagrrqomNVmDAj+Ps0GbgkmR6Ir89/VKa+M2Phve0Ii6TnPNjtysn/3yiWfj0LReiv0f2EoKVX73P9TIgEPYa4RlMkEgNe/SnZhf6WRJuyN+yN21ecOnTmJqWNAtwkXv8illk8aPiRLygUQ== 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: From: Al Viro All it takes to get rid of the __FMODE_NONOTIFY kludge is switching fanotify from anon_inode_getfd() to anon_inode_getfile_fmode() and adding a dentry_open_fmode() helper to be used by fanotify on the other path. That's it - no more weird shit in OPEN_FMODE(), etc. Suggested-by: Al Viro Link: https://lore.kernel.org/linux-fsdevel/20241113043003.GH3387508@ZenIV/ Signed-off-by: Amir Goldstein --- fs/fcntl.c | 4 ++-- fs/notify/fanotify/fanotify_user.c | 25 ++++++++++++++++--------- fs/open.c | 23 +++++++++++++++++++---- include/linux/fs.h | 6 +++--- include/uapi/asm-generic/fcntl.h | 1 - 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/fs/fcntl.c b/fs/fcntl.c index ac77dd912412..88db23aa864a 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c @@ -1155,10 +1155,10 @@ static int __init fcntl_init(void) * Exceptions: O_NONBLOCK is a two bit define on parisc; O_NDELAY * is defined as O_NONBLOCK on some platforms and not on others. */ - BUILD_BUG_ON(21 - 1 /* for O_RDONLY being 0 */ != + BUILD_BUG_ON(20 - 1 /* for O_RDONLY being 0 */ != HWEIGHT32( (VALID_OPEN_FLAGS & ~(O_NONBLOCK | O_NDELAY)) | - __FMODE_EXEC | __FMODE_NONOTIFY)); + __FMODE_EXEC)); fasync_cache = kmem_cache_create("fasync_cache", sizeof(struct fasync_struct), 0, diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 2d85c71717d6..919ff59cb802 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -100,8 +100,7 @@ static void __init fanotify_sysctls_init(void) * * Internal and external open flags are stored together in field f_flags of * struct file. Only external open flags shall be allowed in event_f_flags. - * Internal flags like FMODE_NONOTIFY, FMODE_EXEC, FMODE_NOCMTIME shall be - * excluded. + * Internal flags like FMODE_EXEC shall be excluded. */ #define FANOTIFY_INIT_ALL_EVENT_F_BITS ( \ O_ACCMODE | O_APPEND | O_NONBLOCK | \ @@ -258,12 +257,11 @@ static int create_fd(struct fsnotify_group *group, const struct path *path, return client_fd; /* - * we need a new file handle for the userspace program so it can read even if it was - * originally opened O_WRONLY. + * We provide an fd for the userspace program, so it could access the + * file without generating fanotify events itself. */ - new_file = dentry_open(path, - group->fanotify_data.f_flags | __FMODE_NONOTIFY, - current_cred()); + new_file = dentry_open_nonotify(path, group->fanotify_data.f_flags, + current_cred()); if (IS_ERR(new_file)) { put_unused_fd(client_fd); client_fd = PTR_ERR(new_file); @@ -1409,6 +1407,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) unsigned int fid_mode = flags & FANOTIFY_FID_BITS; unsigned int class = flags & FANOTIFY_CLASS_BITS; unsigned int internal_flags = 0; + struct file *file; pr_debug("%s: flags=%x event_f_flags=%x\n", __func__, flags, event_f_flags); @@ -1477,7 +1476,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) (!(fid_mode & FAN_REPORT_NAME) || !(fid_mode & FAN_REPORT_FID))) return -EINVAL; - f_flags = O_RDWR | __FMODE_NONOTIFY; + f_flags = O_RDWR; if (flags & FAN_CLOEXEC) f_flags |= O_CLOEXEC; if (flags & FAN_NONBLOCK) @@ -1555,10 +1554,18 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) goto out_destroy_group; } - fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags); + fd = get_unused_fd_flags(f_flags); if (fd < 0) goto out_destroy_group; + file = anon_inode_getfile_fmode("[fanotify]", &fanotify_fops, group, + f_flags, FMODE_NONOTIFY); + if (IS_ERR(file)) { + fd = PTR_ERR(file); + put_unused_fd(fd); + goto out_destroy_group; + } + fd_install(fd, file); return fd; out_destroy_group: diff --git a/fs/open.c b/fs/open.c index e6911101fe71..c3490286092e 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1105,6 +1105,23 @@ struct file *dentry_open(const struct path *path, int flags, } EXPORT_SYMBOL(dentry_open); +struct file *dentry_open_nonotify(const struct path *path, int flags, + const struct cred *cred) +{ + struct file *f = alloc_empty_file(flags, cred); + if (!IS_ERR(f)) { + int error; + + f->f_mode |= FMODE_NONOTIFY; + error = vfs_open(path, f); + if (error) { + fput(f); + f = ERR_PTR(error); + } + } + return f; +} + /** * dentry_create - Create and open a file * @path: path to create @@ -1202,7 +1219,7 @@ inline struct open_how build_open_how(int flags, umode_t mode) inline int build_open_flags(const struct open_how *how, struct open_flags *op) { u64 flags = how->flags; - u64 strip = __FMODE_NONOTIFY | O_CLOEXEC; + u64 strip = O_CLOEXEC; int lookup_flags = 0; int acc_mode = ACC_MODE(flags); @@ -1210,9 +1227,7 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op) "struct open_flags doesn't yet handle flags > 32 bits"); /* - * Strip flags that either shouldn't be set by userspace like - * FMODE_NONOTIFY or that aren't relevant in determining struct - * open_flags like O_CLOEXEC. + * Strip flags that aren't relevant in determining struct open_flags. */ flags &= ~strip; diff --git a/include/linux/fs.h b/include/linux/fs.h index 9c13222362f5..23bd058576b1 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2750,6 +2750,8 @@ static inline struct file *file_open_root_mnt(struct vfsmount *mnt, } struct file *dentry_open(const struct path *path, int flags, const struct cred *creds); +struct file *dentry_open_nonotify(const struct path *path, int flags, + const struct cred *cred); struct file *dentry_create(const struct path *path, int flags, umode_t mode, const struct cred *cred); struct path *backing_file_user_path(struct file *f); @@ -3706,11 +3708,9 @@ struct ctl_table; int __init list_bdev_fs_names(char *buf, size_t size); #define __FMODE_EXEC ((__force int) FMODE_EXEC) -#define __FMODE_NONOTIFY ((__force int) FMODE_NONOTIFY) #define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE]) -#define OPEN_FMODE(flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE) | \ - (flag & __FMODE_NONOTIFY))) +#define OPEN_FMODE(flag) ((__force fmode_t)(((flag + 1) & O_ACCMODE))) static inline bool is_sxid(umode_t mode) { diff --git a/include/uapi/asm-generic/fcntl.h b/include/uapi/asm-generic/fcntl.h index 80f37a0d40d7..613475285643 100644 --- a/include/uapi/asm-generic/fcntl.h +++ b/include/uapi/asm-generic/fcntl.h @@ -6,7 +6,6 @@ /* * FMODE_EXEC is 0x20 - * FMODE_NONOTIFY is 0x4000000 * These cannot be used by userspace O_* until internal and external open * flags are split. * -Eric Paris From patchwork Fri Nov 15 15:30:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876440 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 91811D68BC8 for ; Fri, 15 Nov 2024 15:31:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA2156B0088; Fri, 15 Nov 2024 10:31:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D52376B0089; Fri, 15 Nov 2024 10:31:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0B396B008A; Fri, 15 Nov 2024 10:31:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 93EB86B0088 for ; Fri, 15 Nov 2024 10:31:28 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0EF251418D5 for ; Fri, 15 Nov 2024 15:31:28 +0000 (UTC) X-FDA: 82788717228.10.49F9D4F Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) by imf15.hostedemail.com (Postfix) with ESMTP id 9141DA003F for ; Fri, 15 Nov 2024 15:30:39 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=rpCSgWcD; spf=none (imf15.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.174) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684448; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kj8DHbC84OPYXlyGqV3jogaZDMjK7DzZOpBQs/P23MY=; b=zSAT+SYFhnGM6Qr8wuV2+j5hBvnJD9HErh4zCkuU2GZxT37Cd9lpXdgxztuS27MdUfmtDq NfaIeMo9KUj3B2kq1O5rivCsLwxihYg3YHy+8Gn6gURRukIZBW/iAad50khkFx9otdSz+1 2jkpowIUv5ulfb08TRNgbd/uaLIzTMI= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=rpCSgWcD; spf=none (imf15.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.174) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684448; a=rsa-sha256; cv=none; b=mzD2ytQ/hPeAdrDoEtRj2yDACSNFmByoRIp2d5xpnMM4Be1+QTJJXM9pAFM/BYdamqF+eR blghcnSxn1B28DA3uBnGy2tEGW2wZ7r4W350G/DPfE+JieObvbkY2l6aQT4pWJxirc8pS5 HF3x1iZBVVfil/jTWvHfBgnJsjitRsM= Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-e381cbdd03cso1493131276.1 for ; Fri, 15 Nov 2024 07:31:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684685; x=1732289485; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=kj8DHbC84OPYXlyGqV3jogaZDMjK7DzZOpBQs/P23MY=; b=rpCSgWcDZ7XME+Wb0IE6i27max7Kc2NQxCIe7f5MFJh3J5vHOfL+HMN9GRJ0FugSka Q+FPsUP/1jSaM2KRYbR+f9rJAcJnpdHoVMnTqd0MzKna6xE2JW5JgliCbjHcB2kC1f9o jONru9okm37a2DYTXwCphab5PB0NjfY4OK5Eb/wT5MzqUhkojviiwln81O4y9zbCYZbq UKfEtJJfCcE/ForFOY1vf0XxRr40sbaaEkY62xKa7eLbR02Oow4qvl11i4GHEyn+zJYD gQRux+BVO1AQdrHk+g5f7+iDX/k4QT2u8XSr3XQ7DasK6e8VV/PhI3qm2NBD//2JkJrU u1gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684685; x=1732289485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kj8DHbC84OPYXlyGqV3jogaZDMjK7DzZOpBQs/P23MY=; b=q6QUYhv/Htnxx6YW8JQlsX+Qa0ydjV9HQydm+Xo5o9R6GAO6g+3wsJJOtY3aqdSzbj 4xMH1EfOUZuA5c8BT+z9jkOJEplLw+bYzpq9hSG8AGue35ccSFxxs9QKG5Snsxukl1yx gJCaA0uaCzkEhGgAQT24A/Mj3HQZq3Fd0LZisClD/qTTY/HQmbyMDKQDuV6ZNpodX9b9 r+9zR7lQkToKFODI3ScrHIPqUf7SG9k+L0izTT/s3N1/4ELH1T4AjtoZpnptMdauFLkx 31t4Ru9sQe7rhFJZvCjjPmm8tGE3RljmRovoI3/RBvqJbPFtgSBpUyGHerF18HWMLILp bibQ== X-Forwarded-Encrypted: i=1; AJvYcCUt37zbmqAAlsty+RG0jOnXf3h39/dLjItnfSOM/ZrkL3JM2uIhwMUgEbPn4fk2dLBjIBBOGnNIRQ==@kvack.org X-Gm-Message-State: AOJu0YzVZlpw0zxb8Oo3kI68soxIZQeMpRQH4s+cqfvc9MOosH+xQ5IC m3biPgAgeg++BxjjsOPEau3NzDQQIcYafq6Ve60qi2ZiJtIuT8dr/cxaJWaYVxE= X-Google-Smtp-Source: AGHT+IH8WmaESCVDYemYdBxVVvrkUDwhBuFm4p8CVuem1Xk6vUMMQWpt5yAHUnnmjhKyVYoAl9xVug== X-Received: by 2002:a05:690c:46c4:b0:6ea:ebba:3059 with SMTP id 00721157ae682-6ee558d9384mr37985407b3.0.1731684684910; Fri, 15 Nov 2024 07:31:24 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee44413490sm7666367b3.95.2024.11.15.07.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:24 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 02/19] fsnotify: opt-in for permission events at file open time Date: Fri, 15 Nov 2024 10:30:15 -0500 Message-ID: <5ea5f8e283d1edb55aa79c35187bfe344056af14.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9141DA003F X-Stat-Signature: kr81m48mcaqjgc8rhpi3b1yg4thr9gpf X-Rspam-User: X-HE-Tag: 1731684639-826337 X-HE-Meta: U2FsdGVkX18Dpq5eDNaCaFm1WP7BEomeWZv7HGU1d23txdjckp7vzi6C9o/jIyS1dXDTk6epNlMBBQNzzXeNVmK8l9kym4zaBmAZeVgNlV/x9CP0AJddt3PqE7iIEccef5yGO9Z4qJgOuJjk/PZkPmP9aM8289jnUwe4Bs2VIHG3Lk4a8EYZq+/I/rGZWVDFndueRFfSAo1iYDhlFi6Nm/h+laWSf0oG1wQQiH0JUNIsanTr/GYFUTsAPwYkOVykON/Q4zyI2BCXHg6CKY8VZyfhWsC4/2cMSIwleaqjLRlvAKMJohlj4ZvfyV4mlHLpQxitGVRlRMvw4Q8JjIwA957JqChDdllZhh3WYvwhB6OtpXE62CFnr+TLDfDO9eedMrT8EmHTjmpkgOr94tl8pUQhteNGBi10HVvYaxxDuRderqsGPX/lnD+dts1B+puDXYo329xYzDryjqIG14wJRRi1eR7ZxXAR7BlTXNcQ6xOXwUn6wsXhAl5ULnxjKdB81S29DSerwoWIbLpdudf40TUoiL28tiWDZhuyDTDHTP9fYShMawqvXBbFE6Td9aIUa3GxwwYOG5bBoCZuzVxJty9HRwWyHVAVcMegXopyLFMFtwaIJvnL60e6//d4nLsq+QO8DiDU0CpEw0ZFO67vt+FKRybyEDG6xiMJRUoHCgDtBnM1N9VjitgG72O82cbo9MEk+QoR1c01Ij98XdkS8alK1NdSvtCm5UznKo8/ZeLc7wRv6XJLcQ9re1nLyNj3Y5uU7On6FSYLVIMFmXOS67QYCeLBFsemqAB262QDyahUIA3lzZzlMj8t9eHn5MD6tMMxyFSFNW7heIafu7GYA6D0NuAj7k89Uti1YylXCfoWoYwXFjkuGdPsYY/HrZdFvjcyzwb/QduD7VCStllwrqXXgzs58JO22taijOyqW7CtGf3i9PY5fSd+T9Q4E+yClLqy2UGlLzvDTRgU0Ze UuDTH1JJ i+bqk2rq+AEkVWT/DedZQS02OQe3FlrezzY4abOhl7MB258N43LTAqiQD2FzhtTbU8g3rBfCB3JN8bswMzAjMKJI4zLBFZRnC2PH7sJbLXHd9FCL/uEghcaykZiWFlP339UlkBp+USDlvmP3vKLRdzvHy9iBXz2aye/Pzeh61j1i7iteCQMkExlFYHMmlMnVe/bfs7a56B5EpKym2MaH/fju2TuYgEOH2+hHJme2F9MDbPOYRxalV/ZnO+1/6hxlHhYght1/rY0Uen3dVmeZaemCNflK4PtT/YaUnCxSVAA0lvGGbpxikmptCYas5k5lO5DOQr/AEdRH1Grb2rAgb554PvOweaMqcjUJGXWccKJAqWpmxy61A+bmKnSXs7PXnked4LiV1T8PcdSRK/uHGpH92HMZt9/+Qoi38 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: From: Amir Goldstein Legacy inotify/fanotify listeners can add watches for events on inode, parent or mount and expect to get events (e.g. FS_MODIFY) on files that were already open at the time of setting up the watches. fanotify permission events are typically used by Anti-malware sofware, that is watching the entire mount and it is not common to have more that one Anti-malware engine installed on a system. To reduce the overhead of the fsnotify_file_perm() hooks on every file access, relax the semantics of the legacy FAN_ACCESS_PERM event to generate events only if there were *any* permission event listeners on the filesystem at the time that the file was opened. The new semantic is implemented by extending the FMODE_NONOTIFY bit into two FMODE_NONOTIFY_* bits, that are used to store a mode for which of the events types to report. This is going to apply to the new fanotify pre-content events in order to reduce the cost of the new pre-content event vfs hooks. Suggested-by: Linus Torvalds Link: https://lore.kernel.org/linux-fsdevel/CAHk-=wj8L=mtcRTi=NECHMGfZQgXOp_uix1YVh04fEmrKaMnXA@mail.gmail.com/ Signed-off-by: Amir Goldstein --- fs/open.c | 8 ++++- include/linux/fs.h | 35 ++++++++++++++++--- include/linux/fsnotify.h | 72 +++++++++++++++++++++++++++++++--------- 3 files changed, 93 insertions(+), 22 deletions(-) diff --git a/fs/open.c b/fs/open.c index c3490286092e..1a9483872e1f 100644 --- a/fs/open.c +++ b/fs/open.c @@ -901,7 +901,7 @@ static int do_dentry_open(struct file *f, f->f_sb_err = file_sample_sb_err(f); if (unlikely(f->f_flags & O_PATH)) { - f->f_mode = FMODE_PATH | FMODE_OPENED; + f->f_mode = FMODE_PATH | FMODE_OPENED | FMODE_NONOTIFY; f->f_op = &empty_fops; return 0; } @@ -929,6 +929,12 @@ static int do_dentry_open(struct file *f, if (error) goto cleanup_all; + /* + * Set FMODE_NONOTIFY_* bits according to existing permission watches. + * If FMODE_NONOTIFY was already set for an fanotify fd, this doesn't + * change anything. + */ + file_set_fsnotify_mode(f); error = fsnotify_open_perm(f); if (error) goto cleanup_all; diff --git a/include/linux/fs.h b/include/linux/fs.h index 23bd058576b1..8e5c783013d2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -173,13 +173,14 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, #define FMODE_NOREUSE ((__force fmode_t)(1 << 23)) -/* FMODE_* bit 24 */ - /* File is embedded in backing_file object */ -#define FMODE_BACKING ((__force fmode_t)(1 << 25)) +#define FMODE_BACKING ((__force fmode_t)(1 << 24)) -/* File was opened by fanotify and shouldn't generate fanotify events */ -#define FMODE_NONOTIFY ((__force fmode_t)(1 << 26)) +/* File shouldn't generate fanotify pre-content events */ +#define FMODE_NONOTIFY_HSM ((__force fmode_t)(1 << 25)) + +/* File shouldn't generate fanotify permission events */ +#define FMODE_NONOTIFY_PERM ((__force fmode_t)(1 << 26)) /* File is capable of returning -EAGAIN if I/O will block */ #define FMODE_NOWAIT ((__force fmode_t)(1 << 27)) @@ -190,6 +191,30 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, /* File does not contribute to nr_files count */ #define FMODE_NOACCOUNT ((__force fmode_t)(1 << 29)) +/* + * The two FMODE_NONOTIFY_ bits used together have a special meaning of + * not reporting any events at all including non-permission events. + * These are the possible values of FMODE_FSNOTIFY(f->f_mode) and their meaning: + * + * FMODE_NONOTIFY_HSM - suppress only pre-content events. + * FMODE_NONOTIFY_PERM - suppress permission (incl. pre-content) events. + * FMODE_NONOTIFY - suppress all (incl. non-permission) events. + */ +#define FMODE_FSNOTIFY_MASK \ + (FMODE_NONOTIFY_HSM | FMODE_NONOTIFY_PERM) +#define FMODE_NONOTIFY FMODE_FSNOTIFY_MASK +#define FMODE_FSNOTIFY(mode) \ + ((mode) & FMODE_FSNOTIFY_MASK) + +#define FMODE_FSNOTIFY_NONE(mode) \ + (FMODE_FSNOTIFY(mode) == FMODE_NONOTIFY) +#define FMODE_FSNOTIFY_NORMAL(mode) \ + (FMODE_FSNOTIFY(mode) == FMODE_NONOTIFY_PERM) +#define FMODE_FSNOTIFY_PERM(mode) \ + (!((mode) & FMODE_NONOTIFY_PERM)) +#define FMODE_FSNOTIFY_HSM(mode) \ + (FMODE_FSNOTIFY(mode) == 0) + /* * Attribute flags. These should be or-ed together to figure out what * has been changed! diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 278620e063ab..54ec97366d7c 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -108,38 +108,68 @@ static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask) fsnotify_parent(dentry, mask, dentry, FSNOTIFY_EVENT_DENTRY); } +static inline int fsnotify_path(const struct path *path, __u32 mask) +{ + return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH); +} + static inline int fsnotify_file(struct file *file, __u32 mask) { - const struct path *path; - /* * FMODE_NONOTIFY are fds generated by fanotify itself which should not * generate new events. We also don't want to generate events for * FMODE_PATH fds (involves open & close events) as they are just * handle creation / destruction events and not "real" file events. */ - if (file->f_mode & (FMODE_NONOTIFY | FMODE_PATH)) + if (FMODE_FSNOTIFY_NONE(file->f_mode)) return 0; - path = &file->f_path; - /* Permission events require group prio >= FSNOTIFY_PRIO_CONTENT */ - if (mask & ALL_FSNOTIFY_PERM_EVENTS && - !fsnotify_sb_has_priority_watchers(path->dentry->d_sb, - FSNOTIFY_PRIO_CONTENT)) - return 0; - - return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH); + return fsnotify_path(&file->f_path, mask); } #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +/* + * At open time we check fsnotify_sb_has_priority_watchers() and set the + * FMODE_NONOTIFY_ mode bits accordignly. + * Later, fsnotify permission hooks do not check if there are permission event + * watches, but that there were permission event watches at open time. + */ +static void file_set_fsnotify_mode(struct file *file) +{ + struct super_block *sb = file->f_path.dentry->d_sb; + + /* Is it a file opened by fanotify? */ + if (FMODE_FSNOTIFY_NONE(file->f_mode)) + return; + + /* + * Permission events is a super set of pre-content events, so if there + * are no permission event watchers, there are also no pre-content event + * watchers and this is implied from the single FMODE_NONOTIFY_PERM bit. + */ + if (likely(!fsnotify_sb_has_priority_watchers(sb, + FSNOTIFY_PRIO_CONTENT))) { + file->f_mode |= FMODE_NONOTIFY_PERM; + return; + } + + /* + * FMODE_NONOTIFY_HSM bit means there are permission event watchers, but + * no pre-content event watchers. + */ + if (likely(!fsnotify_sb_has_priority_watchers(sb, + FSNOTIFY_PRIO_PRE_CONTENT))) { + file->f_mode |= FMODE_NONOTIFY_HSM; + return; + } +} + /* * fsnotify_file_area_perm - permission hook before access to file range */ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, const loff_t *ppos, size_t count) { - __u32 fsnotify_mask = FS_ACCESS_PERM; - /* * filesystem may be modified in the context of permission events * (e.g. by HSM filling a file on access), so sb freeze protection @@ -150,7 +180,10 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, if (!(perm_mask & MAY_READ)) return 0; - return fsnotify_file(file, fsnotify_mask); + if (likely(file->f_mode & FMODE_NONOTIFY_PERM)) + return 0; + + return fsnotify_path(&file->f_path, FS_ACCESS_PERM); } /* @@ -168,16 +201,23 @@ static inline int fsnotify_open_perm(struct file *file) { int ret; + if (likely(!FMODE_FSNOTIFY_PERM(file->f_mode))) + return 0; + if (file->f_flags & __FMODE_EXEC) { - ret = fsnotify_file(file, FS_OPEN_EXEC_PERM); + ret = fsnotify_path(&file->f_path, FS_OPEN_EXEC_PERM); if (ret) return ret; } - return fsnotify_file(file, FS_OPEN_PERM); + return fsnotify_path(&file->f_path, FS_OPEN_PERM); } #else +static inline void file_set_fsnotify_mode(struct file *file) +{ +} + static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, const loff_t *ppos, size_t count) { From patchwork Fri Nov 15 15:30:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876441 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 CC5FDD68BC6 for ; Fri, 15 Nov 2024 15:31:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A9B06B0089; Fri, 15 Nov 2024 10:31:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 05A216B008A; Fri, 15 Nov 2024 10:31:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DEFDC6B008C; Fri, 15 Nov 2024 10:31:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BD6CB6B0089 for ; Fri, 15 Nov 2024 10:31:29 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 69C17C182B for ; Fri, 15 Nov 2024 15:31:29 +0000 (UTC) X-FDA: 82788716766.27.572E29D Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.172]) by imf27.hostedemail.com (Postfix) with ESMTP id 114574000E for ; Fri, 15 Nov 2024 15:30:40 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=c1qO7kxP; dmarc=none; spf=none (imf27.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.172) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684598; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6KY5fZdmP1liuAXJOZsCM4eyAqIeREr5VHEr0FLOlUs=; b=Xtk7WPWcrVfWL8p4UEnriXulJHs3P3juV3h7vLUHMs3FUQwLFmOpo1aGwKShBLzV4TP2go HSj/cWpjzwh986t0UwW5f+1rr0auTef6l24q931U2k1TMM9VrC6Nyfq2d37cWWodIH9UdA HBr+Y6e5mdTp7n7SpwPfcnyEgHBMYXc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=c1qO7kxP; dmarc=none; spf=none (imf27.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.172) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684598; a=rsa-sha256; cv=none; b=Kah5tTO+3ooLszHQYTmbyHk+84E1CsgUvfB9N3lFegm6KOsTD1VfL17KWKzKFGcWbXXqW3 tD+vMGURSeIvur/0WTQ7Qh5DrCnFj0B9cQAlVmDeAQK5mLr3auZJLJhmhQ/TGNY5SKgMAG 1ERJozJJVD9UoG13QgwOyPiHCepEkvs= Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-6ee6a2ae6ecso2849727b3.3 for ; Fri, 15 Nov 2024 07:31:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684686; x=1732289486; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=6KY5fZdmP1liuAXJOZsCM4eyAqIeREr5VHEr0FLOlUs=; b=c1qO7kxPQIqmTjG4RZSrdIMwHdDa/XyqHZ307ozkpSnoMhl9co0a72GbOnMNpoyxiU tSfdlE2aK/RVidzpBzmD0v9XPfOrRyqIJqpLPaP3J/xCHBLc26+5ivRt38ak9ZQREPcO cIKBCyd97vIFn1j77QEFfnbLxiHur6yN3XsEHUxDIoDILF3eTmWTIhucnAmNf0HwrGMC sQfDjyYcFRaeV9RNZ8AcQrola74+6UxN8aLwKMCZfJ271eLJdOWPKSC50vSWv50Y2X0h 1lTlevuFXAwfRPfMSdA/R1P4sQ0P8+nUa7RSwB1HCx4RKxEtxOTwcWZsuinnbN5GA99P xHWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684686; x=1732289486; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6KY5fZdmP1liuAXJOZsCM4eyAqIeREr5VHEr0FLOlUs=; b=JCwHXxxT5XpB4n9yxFvrlkadubeunzW8rNtasXcc97CvpGgctNppWfX/bIumR583fY JNwTP3iorrUJk19XcwpMJMytoX8fTK3DURTM/nLNSA8bAvuI7UjiwrU0Bf+SSyUNXPDN 9s0D3N6TyZPuGYUvn8t/aateUmHA9SqJUYCt4UPJYM2ds9mSC5quSQcCCh2++lTTFqh0 5hekRDkf2LO478wbkOmz4+dSmtgf3FEtLd98uraZjenalq3ad945Bk7xIta6QUxFDjRD X+9iP/9P8IpdAe+jWMAOjmetj7YeFGxCfe76mpQjwidR0dVT2BLiGZ5tALXH/OvCCcdf DCgA== X-Forwarded-Encrypted: i=1; AJvYcCVhYNn3IgdlZkkQXtb7x06VifDw04eV1F6zrIVFR+11lNom5TtgcM972rs3m5GaZ6svNBubvPByQQ==@kvack.org X-Gm-Message-State: AOJu0Yxc12J5kVRTPvMOsAkjDYPlkSYzpAGZiB8GhX+Bhln9x5euM2fd wFuCmcJF36l6WvkV3kdydp7ZS0fdhpVJGtyX6+flgu42j7TYFCOjvf/LviTG4v4= X-Google-Smtp-Source: AGHT+IHdSr7sIuKVmbedcInH94EUveWdRZ8jZfw4hoXsU2FWCk1ayn1ufjs9+AX7MxAWuqGyDVgHDQ== X-Received: by 2002:a05:690c:360b:b0:6ea:34b1:62e3 with SMTP id 00721157ae682-6ee55a2f60cmr35106257b3.7.1731684686563; Fri, 15 Nov 2024 07:31:26 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee44070647sm7648387b3.53.2024.11.15.07.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:25 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 03/19] fsnotify: add helper to check if file is actually being watched Date: Fri, 15 Nov 2024 10:30:16 -0500 Message-ID: <2ddcc9f8d1fde48d085318a6b5a889289d8871d8.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 114574000E X-Stat-Signature: tgw9ie9xnq3ix7jqyu4ca4zjs137tfbd X-HE-Tag: 1731684640-999958 X-HE-Meta: U2FsdGVkX18FKMBn/mDHYz3ZagNrvQNmbAcMqOL48C9DPhOdTxiGw2pzkzUZvA/DglCR0Knuj6r8NRBFIQcK1BZIRHklYsZs5yUQRxM4/9TuxnRXHIBR/4Ix/iCmDnMcycnGr41MkJsMc1y7fped7jOe64sqQLf4faOQQAmIY6lhuopHkqfCA8y/tfHWngfZv4Y1ZD8TaSM0bhXjzxDw6y1FI6Qvq77xSsgtbxBYDY20XXGOBHfsBQfRIolrKoNAMQrIotf8Yyn43X8uSfSXsOJLlM2rgrLilD5aLqZ0R+LmXMKbWF98q/+8BZ9m6FsChbtT64/qHh1Ai7Sb4bb2NR3MIBPEykbKZP/OLmICnFrFpi4Vkf7IGO8drCNjoV+7YAHOiPv+UeXctJL0LeTTgO5XK6mVBb61axWCzikPnDN26R0Uc7TQTDIS8CCQtLK2uWY5cCT9iMrduesy1DHIFhdVk1S4SUrGCwMBCe6HlJY3wA3dOrezcwFeplD7FNeAvv5ZZsYmFUBqOoKyVtlWylnx0SIGoq4QFiu9PFv8ZWL8qDAbglx12m4svm/cp9Syt4K8T7vDOzI0tavxMF80991jLBR4yNO6OE+ri57UgjXJVH/PCnWTFULjMuwTvjLb65z2iwflv9yMNP4Sz4F54Kpo26K74cp7q2BZQgjpzJGWogDd1yqF0qLwxLdiMcGhMmOg5cm7oNJsEZNVkHCZqg5w9eKEceyW+GkrMcJ0trnKS3y0NXgfnWS0KIH1dNgYrGEq8vrEmZIAkaRWABjwvlhanB8iADyYAWnrNWJOUaqxBH9g9wDxB7FW5lJQh+pYDUFQkoCeTryegz0xeTRzUyNg3M6ZqUmyxp02x5A+QnYoSfI9rwf/LZ6v/70Nc8Elc6GsW02FGuoQE/yclq/NC3EITEpMUBQ29Hs2UQcmgU0nEaEc/2t8DOQ8hClgDfUcYDLRIOi7Tzm+4dUYC0/ rE5HWbJP 3BXmVrcMSu+1azTOA7Int7zdZaCnsKz+ZXkPvwUwDjXrgwGPZTVjiOJEvYAEyTV+ddmuiDLo0+Zdtf9PIL63rEDWJHVMnnly8JJbJZPUCnt4LPr64fyOFyUj06vTpigqtwmZQ4qCHFhszW18cOUNXNuGSNPW//UWdydLoMqPHcA+8mqrwYc1Swxy6LFgXUONmm60kaAVaEFox4/cvlbLhdK24+69GFALNj88ieOx33QcbM26IRQWTzGeBs50JPn9Rjx+zIsDGxU9gry+UpKN3MCY8UWDETP1YQvrC+NRUO9vqhFSQZkLzoZmg5i6T63YCzpkv6GTQW31zuF34MWTyblA9EQ== 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: From: Amir Goldstein So far, we set FMODE_NONOTIFY_ flags at open time if we know that there are no permission event watchers at all on the filesystem, but lack of FMODE_NONOTIFY_ flags does not mean that the file is actually watched. To make the flags more accurate we add a helper that checks if the file's inode, mount, sb or parent are being watched for a set of events. This is going to be used for setting FMODE_NONOTIFY_HSM only when the specific file is actually watched for pre-content events. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 36 +++++++++++++++++++++++++------- include/linux/fsnotify_backend.h | 7 +++++++ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index f976949d2634..33576a848a9f 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -193,16 +193,38 @@ static bool fsnotify_event_needs_parent(struct inode *inode, __u32 mnt_mask, return mask & marks_mask; } -/* Are there any inode/mount/sb objects that are interested in this event? */ -static inline bool fsnotify_object_watched(struct inode *inode, __u32 mnt_mask, - __u32 mask) +/* Are there any inode/mount/sb objects that watch for these events? */ +static inline __u32 fsnotify_object_watched(struct inode *inode, __u32 mnt_mask, + __u32 events_mask) { __u32 marks_mask = READ_ONCE(inode->i_fsnotify_mask) | mnt_mask | READ_ONCE(inode->i_sb->s_fsnotify_mask); - return mask & marks_mask & ALL_FSNOTIFY_EVENTS; + return events_mask & marks_mask; } +/* Are there any inode/mount/sb/parent objects that watch for these events? */ +__u32 fsnotify_file_object_watched(struct file *file, __u32 events_mask) +{ + struct dentry *dentry = file->f_path.dentry; + struct dentry *parent; + __u32 marks_mask, mnt_mask = + READ_ONCE(real_mount(file->f_path.mnt)->mnt_fsnotify_mask); + + marks_mask = fsnotify_object_watched(d_inode(dentry), mnt_mask, + events_mask); + + if (likely(!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))) + return marks_mask; + + parent = dget_parent(dentry); + marks_mask |= fsnotify_inode_watches_children(d_inode(parent)); + dput(parent); + + return marks_mask & events_mask; +} +EXPORT_SYMBOL_GPL(fsnotify_file_object_watched); + /* * Notify this dentry's parent about a child's events with child name info * if parent is watching or if inode/sb/mount are interested in events with @@ -221,7 +243,7 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, struct dentry *parent; bool parent_watched = dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED; bool parent_needed, parent_interested; - __u32 p_mask; + __u32 p_mask, test_mask = mask & ALL_FSNOTIFY_EVENTS; struct inode *p_inode = NULL; struct name_snapshot name; struct qstr *file_name = NULL; @@ -229,7 +251,7 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, /* Optimize the likely case of nobody watching this path */ if (likely(!parent_watched && - !fsnotify_object_watched(inode, mnt_mask, mask))) + !fsnotify_object_watched(inode, mnt_mask, test_mask))) return 0; parent = NULL; @@ -248,7 +270,7 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data, * Include parent/name in notification either if some notification * groups require parent info or the parent is interested in this event. */ - parent_interested = mask & p_mask & ALL_FSNOTIFY_EVENTS; + parent_interested = p_mask & test_mask; if (parent_needed || parent_interested) { /* When notifying parent, child should be passed as data */ WARN_ON_ONCE(inode != fsnotify_data_inode(data, data_type)); diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 3ecf7768e577..99d81c3c11d7 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -855,8 +855,15 @@ static inline void fsnotify_init_event(struct fsnotify_event *event) INIT_LIST_HEAD(&event->list); } +__u32 fsnotify_file_object_watched(struct file *file, __u32 mask); + #else +static inline __u32 fsnotify_file_object_watched(struct file *file, __u32 mask) +{ + return 0; +} + static inline int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, const struct qstr *name, struct inode *inode, u32 cookie) From patchwork Fri Nov 15 15:30:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876442 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 02E1CD68BC8 for ; Fri, 15 Nov 2024 15:31:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B58F06B008A; Fri, 15 Nov 2024 10:31:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE3BC6B0092; Fri, 15 Nov 2024 10:31:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90FA36B0093; Fri, 15 Nov 2024 10:31:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6B6C86B008A for ; Fri, 15 Nov 2024 10:31:31 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1D1041C63A8 for ; Fri, 15 Nov 2024 15:31:31 +0000 (UTC) X-FDA: 82788715590.20.6BB8AD7 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by imf10.hostedemail.com (Postfix) with ESMTP id 2ACD1C001F for ; Fri, 15 Nov 2024 15:31:08 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=FavfWOpf; dmarc=none; spf=none (imf10.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.182) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684510; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5jVczlJ/TW6EECuU4gj9yYFP++VZ/oJUqPiY9P+PdPU=; b=N6JnYJxLB91kkHJU4+L9ySGslszlMoN/Sjb20CFjftWV6dSR/hzGmRBOce527Et70EvBqB k00PPFpLCmZX/5++tcmMiGnE0WOG6eWugk5zCHAqvbh2ju/esBvtW6JwFKrYv8v10dh5g3 dj9UxNFgotxVucA2C/9ZQ3jRpgP9Mp8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=FavfWOpf; dmarc=none; spf=none (imf10.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.182) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684510; a=rsa-sha256; cv=none; b=5326t7TqGXqKrmgX+sSnoob9SMTa0kGvX+rDQBUOaM5Mc/M2M54RvUNp7W1Zo4gBY1zxpJ HK6CehuOtobINOX6cUKEr+RaGMl+99PTOT3aCLcS5E9aN9gnX9ssQwh3z1ct1ZLcz9eWIL jlimlNiCfWhDSctNVQDBhViq/ejo0Yo= Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-6ea5003deccso21563847b3.0 for ; Fri, 15 Nov 2024 07:31:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684688; x=1732289488; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=5jVczlJ/TW6EECuU4gj9yYFP++VZ/oJUqPiY9P+PdPU=; b=FavfWOpflLX/eaBZyuKnnMw66c0tNxhgSlh/ino2ZSPs3mkk65pamRV//EH5UKvsRG xv33bYWC+LOf8hHl6U7Uo1GGaVTP7efaGKy1C81y6RSSLdNXeJawXvcD/X5as81qdTM5 En9Ew1xzvWbeyK45RTnQPXhi9ZBEkVFElb087hu2nlc59mqSuOfVs5iMyoU7wIkWcVFj obFIYFKvZL53tCutHgAx8hOFoRQp+sFFonLUG09i1LgfzaTAjqw4qazH+dSRaZomvpcR N60aIXGLkoJy4k8I1qoeKuzm3KrPrYnWEKv1bJTjFNGMxOOZ0JyJAUqJ3zxCR0SKVJRG 8hsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684688; x=1732289488; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5jVczlJ/TW6EECuU4gj9yYFP++VZ/oJUqPiY9P+PdPU=; b=lV4DSqONSPVNG8JIpouAR5qtBRj6nRU+6O1i69AtJMgEpTrB3asjwSPzfk3BHRn+HA FF3kGTQ4mAr++2e5CkzYI3gDuA1TzZeM68A/8bpbf5wuks6mz4/dA+aK8BcoXg/HfkUS +DBYp6TmB/ki6ydc7tj50ZUyn6UZUME6m4D5U4ZqFLnGxiDUymS/eCQ7qMkRjeyr9Q3q QObX4UARtV1JJW6gINCsuBf88Vqdy0q1t712tTK3rSvVQlDV7KBd+YIONUgD95f3LvOl 0FuSBkKmbR+EvICKs4OlapfiDNvR02eTemvNJ9VO/G4oCKUvNoDuT7adg+dXmZ/KGwqN ZD9w== X-Forwarded-Encrypted: i=1; AJvYcCXtW3L0eic+jrgcPHNr/CNL6Y1x0FxKXCu8NFiE8vIY5NL8ysMselA7oAdsaydhS1/dBxuaHAsT0g==@kvack.org X-Gm-Message-State: AOJu0YxiQjUe2VWr6X0McHbUcfEPm+PXMrvsaziRLlBRoTN85jlo5ZeF q3lX4JZ6+kSissQMb28UevHKRfVnxiNtulXiILS0BOgsiTr5vNYZq6hlT18lQuE= X-Google-Smtp-Source: AGHT+IEWEdrPnRli1gv+jVnLYsORdUcuZyTi/FsZKRBYcdcM64Io8ydfsi1gmscyy1vF3dAQcsDh6w== X-Received: by 2002:a05:690c:4c02:b0:6ea:2ac4:9df6 with SMTP id 00721157ae682-6ee55bbade0mr37073597b3.3.1731684688405; Fri, 15 Nov 2024 07:31:28 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee4449516asm7602087b3.124.2024.11.15.07.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:27 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 04/19] fanotify: don't skip extra event info if no info_mode is set Date: Fri, 15 Nov 2024 10:30:17 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 2ACD1C001F X-Stat-Signature: g3kdy1to3j8yexxx6s1g8tt5sddgc1pj X-Rspam-User: X-HE-Tag: 1731684668-171819 X-HE-Meta: U2FsdGVkX180wd+0DI0Fya+5ldFQJ7osagJiRkQ621qELru6V0KE84OYodfVVafszm/l380E7ey9g72HIDBh1j8HQr2cKAWxyNirQvnh5ahpUSpZddWgiQ7zvI8pXcjk4szkHoOWtQuIGNGgc37BQZ1fnuGbqS/xIANQiysVR+pXBg3UVh87RZxhwXoCiqv2KHWVeoOrp6ubfr7o0NgpyENJCY3pMg1O6+d+2RaBcbVWWWyuD3KgWrSfnQqu07Y4ZKZdVSbedqTT+Qm8+8FrdWnrCzBE+DYpjLKzZalKNNy9cMEofvHVRVi35mUv4swF6Ck/1bXYnfWFJPPGJln2hpN/7pUovGgz35aDK3hlqEVQOeNbU3hRoJSIgrSteHXqglpD6EGZoQtGh+gpV3tSqESaKZb/53jT+vXoR55GHFfAI1u5rlA/glIRSwnCdfAWTf+ko/xUskTn9c9wkON/MRLCHrUhZKu3qbSO0f3/OmhzcUVR0Zg/Ucg9mKzehK3moE/GuZzpx2YmeGwydASlDBVy/561OgcZ5b12Dj3xY3PJgL6rMiaSmxIUbYXTDatmJLwQEPzmf3aGJy4aT2F2mzzgeC6E8FW/kAcPFJrcZZezKYNVMTaZP2dxDnjTcHyfC4H9950gX1+hEV1WMOlcEOK7e8nR1swoU5Rx1nxpcy1UTHTQEBYo+H/W4SEgBe0grcSN8XIul8BYNS0LF6hQi3eIiYGYIhBamfUKDWCdKBC+410rDH/yzQmjOe602hOSXaSLoKB4wuwCYYwbHfOH94lxQVu3GXx6Z0ixcaNfYiOR0ofjcq7VA2MBnx3culiO25QA40LtU2EsKiOKJqpL9KSmLYdP+u3djMwiyDVp3RLJeBRUi7I78GhTEkAtJf20sztHty1SUU9zUnCPiSCEByTvq1m0laL+4RHXBPMX2bZAcmFmlw1Db+swsXCsiDPc6CC4jWfYzlHz0X7XBmJ 6952Uszx 8eXYcssDSPobc5xkAMsS32VPE3QQumgvdhnkha8uUN0seZopn3cALbMVFJ0jA0uIhqKA+E1nU9sCJoVZzFgWf17kAHjbyK8LJiQpeZn243stBqOGTkMm4h3gdNWNhdpTxWU5vO4lNQsASJh/vYPRzrmndh7vj/6Cg1QQNol3Unl9z04Nvl1YL4/jZGgun0Z8KdKDTpxuV9NIuZB8lC54Os+PUsoe7kTiCniU/AkMDhlfVW3uMkZ/zGUTNCm6rC7bNhsNh/fs03eSBIAo29fTiEoDRFTEy5zePPS9kBc8PJCC7jx4QKjNk3P3hZIptIv/NikGsphAe8T7EG814KhxM9agKx7+D7AkeoeEMnDcv5uz7lDMYrZSOUP7UNBe992NJVOq7XG+RPcnf5dwRjcNF2qkMDvVgZTr8rLKKb+XyHHSXELWs9vw9ktaq8nJZxcelg6IDW8zzYziXcgB8Vl8eQ8OT8+XLgQCOEV0xA+RJr0IFZ6JCksZVD6eu8PRfo+aipIRXqQ7Q9bYwhcFUXyu7pVZeiXTkVt3Jw3UJs8ViGmznopY= 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: From: Amir Goldstein Previously we would only include optional information if you requested it via an FAN_ flag at fanotify_init time (FAN_REPORT_FID for example). However this isn't necessary as the event length is encoded in the metadata, and if the user doesn't want to consume the information they don't have to. With the PRE_ACCESS events we will always generate range information, so drop this check in order to allow this extra information to be exported without needing to have another flag. Signed-off-by: Josef Bacik --- fs/notify/fanotify/fanotify_user.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 919ff59cb802..8fca5ec442e4 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -158,9 +158,6 @@ static size_t fanotify_event_len(unsigned int info_mode, int fh_len; int dot_len = 0; - if (!info_mode) - return event_len; - if (fanotify_is_error_event(event->mask)) event_len += FANOTIFY_ERROR_INFO_LEN; @@ -754,12 +751,10 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, buf += FAN_EVENT_METADATA_LEN; count -= FAN_EVENT_METADATA_LEN; - if (info_mode) { - ret = copy_info_records_to_user(event, info, info_mode, pidfd, - buf, count); - if (ret < 0) - goto out_close_fd; - } + ret = copy_info_records_to_user(event, info, info_mode, pidfd, + buf, count); + if (ret < 0) + goto out_close_fd; if (f) fd_install(fd, f); From patchwork Fri Nov 15 15:30:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876448 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 371DED68BC6 for ; Fri, 15 Nov 2024 15:31:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 454156B009D; Fri, 15 Nov 2024 10:31:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DC256B009E; Fri, 15 Nov 2024 10:31:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20A406B009F; Fri, 15 Nov 2024 10:31:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id F3BAB6B009D for ; Fri, 15 Nov 2024 10:31:43 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9214CC182C for ; Fri, 15 Nov 2024 15:31:43 +0000 (UTC) X-FDA: 82788717228.19.93240B0 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by imf22.hostedemail.com (Postfix) with ESMTP id EAC6CC0010 for ; Fri, 15 Nov 2024 15:30:44 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=DtJQjLN0; dmarc=none; spf=none (imf22.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.54) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684522; a=rsa-sha256; cv=none; b=sSNzWvagjry1fmOAhvrkk2Kc4P2EL+x4Y3YB1pnRhpEjtlfOPHENYgvS4f6tGkJdopteg+ fSFFrDWnUxiscsjrM7iOSHchH5phGlMELgp5Gb98cMrcq+d6yESKLHTYX86ou2d2DPtqsO tw3I/xV8EiSEgk9hz2swsK3c8EaXqVQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=DtJQjLN0; dmarc=none; spf=none (imf22.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.54) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684522; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QSuoTi14zhdgmEJ2e8nj/BNpHIFoytvzNxhl/LStwJg=; b=CZrNg4DlH6EnLqIWlgXdO0O4qePMhA2fm37F6V0WkDo+4q+yUtxMN6ALW1RAS3wZYgL1hZ R+QKNdx/Fz9rmV0nYuVFjwaY4xrznnBFT8rz+c5zbxJ3JhvmcKnHEuzi+VquOTOO5qOD1q l8+mCu9EHVU1UYeyXU+wU3+CdAwhMRk= Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6d4035f2d18so2372756d6.1 for ; Fri, 15 Nov 2024 07:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684701; x=1732289501; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QSuoTi14zhdgmEJ2e8nj/BNpHIFoytvzNxhl/LStwJg=; b=DtJQjLN076V0hI9IqMmeWY2TQUm5JZJLdXRLTFwj7/bxzF7ZfgvUmVLc865EHk/4f1 uR0trpst0iXCpY93IO1Xd/1OC5MVyLJJ5w+q6wP54+UERAt4WtsK7/NVcxyyqf2hebdt mvOJpFqOmw/q43UZUrAr7MKwyCODMcYb1sydGMf2U5eHe6mGxVZYNEqLwSt3oSJxx+0i S4Ok8MfA6moLuM7NOElleE44a3f+jihUGnCiYUpWeTJcW+TdHUlDXonPqtOOpLiBK6Ps jAtEaAoD02XcCsY5u/6+gEHlvguHx2A12FzBk83MfYSrJaLF2DF7WLOqxaD+e4DFNvUI GyBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684701; x=1732289501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QSuoTi14zhdgmEJ2e8nj/BNpHIFoytvzNxhl/LStwJg=; b=SdTnVWZooHHN98ANnceesVn8xCMTUnthrI2QciGBhVq9V+24ErF9zGv2Hx1wb9Bk1m SVjkP3wz3huSdcL69WHd21IfCmqu9RxqNF7JIvBNbbE0DilDdkpOjgEMNG4h55BpWiTG 9dYpE0n29aWuvJsZzmrvuivUYw3VHHRMJNtSW9177g6ecniFQNulfsMHgorgbjLHg5Fq 7Um3moCE7ah0HCXRYOK/kVjLQPlS1UL9Mo7eFs+uNv+0qCy8uLW/86NNWCp+jIbTmEsF yVY/jo25ppjpvvhSUP3Ol6dHxZdwsFnNVVheDIpCQi7WB3O8og9/vsEcWIgW8kG7OpGQ kv8Q== X-Forwarded-Encrypted: i=1; AJvYcCVs6+y46nT7APjJcFthS506kkU3hoc//kA+c4oaO/3k8QE5wX/hvj9x4qoP3HHRT/sJX/sUwBP/gw==@kvack.org X-Gm-Message-State: AOJu0YysFuTbbwlu3Fm9qnYw9AbSt0hAoIT2oMwbkarW8EwR0Tlv7oEc gnXJE7mm98lbymCe+ZDZkEero6g+rkxMLQl26OaL7RMAwg34/1DfI52mKT6vQ0WZXo5+004O5bU D X-Google-Smtp-Source: AGHT+IHJEyVOG62NvWa9d1qggTtMCjzt+EKNCXFckK971VFGqKmUTAI/9H3Oo1mgh59gFKizdUDdeA== X-Received: by 2002:a05:6902:1242:b0:e35:e173:3341 with SMTP id 3f1490d57ef6-e3825bdd813mr3265588276.0.1731684690002; Fri, 15 Nov 2024 07:31:30 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e38152c61d4sm989132276.5.2024.11.15.07.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:29 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 05/19] fanotify: rename a misnamed constant Date: Fri, 15 Nov 2024 10:30:18 -0500 Message-ID: <8776ab90fe538225aeb561c560296bafd16b97c4.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: 6xgkkhampw8uzcsobto87jjtnz38msdq X-Rspamd-Queue-Id: EAC6CC0010 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731684644-307240 X-HE-Meta: U2FsdGVkX1/ow4aPYzqoyG72nOpwwHZJdrFLadCmG0huQTjz5pcfLZsRwCZX8YCoHzjt6Po83UAY6wF/CcVxM2IPd+EzhBU/V+7duaCxK+Ocp8PZwQbwVjztVGuN2tH9MOFIXgpXTkJahFzhbKzSLVDGbqGvrpIjU6dtFxXi7jMG/su84shQE/elijxFw3x4NN6Xca3pG0aZQ04IzbAvTt82f4RFKR+1HbcrkHlKI0+U2VwCiiJKSQq+UDQWwDQpAT0opunAjDLR+9reFMg8uEZKDc/HYQk2Vx4zuMhzoKEW05PSlEo+UNyVQ0ILk/64uS5annkOiOKovPAu54y/ThzdnTX95y6KnTQ9t7hReaKkasJL25b5TKyHPtCnG32NRIrVOzemrT/Jwopfl9oE0pDWLX0q9eWBJPqBnaB18xBgiZwDqgTXeyqqhonTLef36J1EhgnytrH2reg8yNAiP0v7q3WIXxm2uYWBhs2i4vEtEintYE8inhjKK/NxluLnSS1qUNBeBvxWT7hKRSW1sWh2LreqNp4HeUrttO1eWYSkZtQCwt+BLfScVx2nV4P1phNaCruOBvfM2I5KRfe3DROf+Qy1rEqUMGupf7FUusIYUwHe0FZnJHsVuUGzaAMJnqp6qCQforLQH/AQZBn9+F77g/0x8c36GJ9ih8oJVnerp8Tl6nbTIzXE/LKi0WveTD/sKQQutzrfjeSqfkiUlADgLIcRco0nA7ghNMy+e9s27sfTaeaNY1mXmI0VpGWe3HezeOQG9I9qhm1kO+PbdsoxbRbtStkLgC+d0mteF5MW1mYzT8nC0csq5xTrYIjGGLPxfoc9YTW89q6rDCbpcA1O3hUTZf6XUldpejaoyjmFLZR1rh3qCWu/rBDkF2C3O7cH+iMD3rdbcgCge300/AiQ559haW+ys5traj/4nooIJXJCznGqqHTIxYxOfdmdgo62gwV/RNZtHZ6h6mS NH85vTL5 UWCug6q12z+3cnU4ZKw5Dm4on1r4dqZM+K5Qzi1OlAJYn/Ya9i4WxKtGxo4F37rHt5jiK9DrlE98fe2N2ncpuzGu5rDbjzGtpu27zmGfzkL9vtDILnfJJFh6Pmu6kHy+032Qg0xBeY3U3rVDmNN0L4XD0htk2FybwXLNEZeRIZYHk64+ff8y34tPfvC27xasFGaKuFbBQP66hh0swCP9tZz5zcFsL4ZClzYEtfmitH33cCayeTg6rUNo7Wu+E+iAVfsgFerjKwAJamCrVTi0uX85g/rYOj4xDZIjCwlEE/czCyh+9/L+yq1vv8ir+sPaWGKBTGF1GYxgMVPY= 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: From: Amir Goldstein FANOTIFY_PIDFD_INFO_HDR_LEN is not the length of the header. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 8fca5ec442e4..456cc3e92c88 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -117,7 +117,7 @@ struct kmem_cache *fanotify_perm_event_cachep __ro_after_init; #define FANOTIFY_EVENT_ALIGN 4 #define FANOTIFY_FID_INFO_HDR_LEN \ (sizeof(struct fanotify_event_info_fid) + sizeof(struct file_handle)) -#define FANOTIFY_PIDFD_INFO_HDR_LEN \ +#define FANOTIFY_PIDFD_INFO_LEN \ sizeof(struct fanotify_event_info_pidfd) #define FANOTIFY_ERROR_INFO_LEN \ (sizeof(struct fanotify_event_info_error)) @@ -172,14 +172,14 @@ static size_t fanotify_event_len(unsigned int info_mode, dot_len = 1; } - if (info_mode & FAN_REPORT_PIDFD) - event_len += FANOTIFY_PIDFD_INFO_HDR_LEN; - if (fanotify_event_has_object_fh(event)) { fh_len = fanotify_event_object_fh_len(event); event_len += fanotify_fid_info_len(fh_len, dot_len); } + if (info_mode & FAN_REPORT_PIDFD) + event_len += FANOTIFY_PIDFD_INFO_LEN; + return event_len; } @@ -501,7 +501,7 @@ static int copy_pidfd_info_to_user(int pidfd, size_t count) { struct fanotify_event_info_pidfd info = { }; - size_t info_len = FANOTIFY_PIDFD_INFO_HDR_LEN; + size_t info_len = FANOTIFY_PIDFD_INFO_LEN; if (WARN_ON_ONCE(info_len > count)) return -EFAULT; From patchwork Fri Nov 15 15:30:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876443 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 EAF7DD68BC6 for ; Fri, 15 Nov 2024 15:31:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CD9E6B0093; Fri, 15 Nov 2024 10:31:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 22F6F6B0095; Fri, 15 Nov 2024 10:31:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 082346B0096; Fri, 15 Nov 2024 10:31:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D505F6B0093 for ; Fri, 15 Nov 2024 10:31:34 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8B04C818E2 for ; Fri, 15 Nov 2024 15:31:34 +0000 (UTC) X-FDA: 82788717522.30.7F4787F Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf04.hostedemail.com (Postfix) with ESMTP id 0DB8C40029 for ; Fri, 15 Nov 2024 15:30:34 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=kIrp+Xzf; dmarc=none; spf=none (imf04.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684604; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZU0dZL52CuS55HBpnlFc9Ffg6kvih/VgFXFf1fJzIbE=; b=cYUu0Ij6p8lofCu6KRZ6rqK5hQ0S+xILoY62T2dY84OLx53zJnjmofpEux58gactLTQsI7 gM2q7cKI7wtlBavZ/NHtwP4IXAXp37OBTY2ZhZG3DLRGTm93qLMSyZG6Tzp3scKcRSiF1x Y7bTuHYGNLH25Ty7MIFt1uYYf2rxLb8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=kIrp+Xzf; dmarc=none; spf=none (imf04.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684604; a=rsa-sha256; cv=none; b=PO5ALezyPcsEUEjrO+g44PLlttNbnooKF/7eDEbSpsqTNEWDYRubczxHfZTDkjjngBAOA+ c6m+8IM9x1dnoem4ycAmVI9xCvBKOHStfWapgjKSqsc3EFOeVy7DVaSLA85U8sIaW+QmLe bI+CbdapUyRuHwjFDOppYWys/aVFe94= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e38193093a7so1569183276.0 for ; Fri, 15 Nov 2024 07:31:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684692; x=1732289492; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ZU0dZL52CuS55HBpnlFc9Ffg6kvih/VgFXFf1fJzIbE=; b=kIrp+XzfgHfdGHA4WoQYoLiuyEPY1UC1XMbYkFTFeHQRKaLLAwcF5mEK1fqZZ7AprL GPHVKSMWjNq7ehvpYrO/ktwwEfBHUq9EIca8yysEMJaaKb6lSXSzEroc8u7gR3R53sUc c8zpDbdjGstcdZ5CSsWusmsjiXQ95ScfT0vbaMbXXUFlO6OrCoNBlt0f6ifB77D6Jj0E aUFqzwidkqR1aIlcJkU2jOi9cRNqSv/YU5xhoKbFjgsZdaxn41J2IVgb0qJd38j06vNh f+P/4s3W3mhfFhs7B4LuxpFErV8ByazInvgsBmge2ncoiAeAhHDHmZ1x4dl8GvDRxV99 0cqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684692; x=1732289492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZU0dZL52CuS55HBpnlFc9Ffg6kvih/VgFXFf1fJzIbE=; b=l3YmWx8aYbAox1K1KbHcplU078EDag6kV8l4PTnZJabfTteAUORy3hRbo0OCpckz33 hboTF726vZMx4Gt6F4nDtO7HUuyKE3iQChNxKs2DrEllBANiUpdWwMF2Px1g1so0DOZX CXAiLIWPgK8qtm2/JvmjKJ73QSU3HmBaAZeIcBgyzwGWJch4sZJk6Bko4B9W2aUsLVjb 7S9Wlaxt9Gw7dK7V2Nc+pYGskkTEPCPKhgE7KrmUjgi0/XgJwXpP5ojzKlqTElEGbeU8 iRytxJ9lPIrq9CV+oaT1by1fCgkia/9FsYx3dq2EXJoL5mbk91t5AnQo+NbIjE+wvmtP qK4g== X-Forwarded-Encrypted: i=1; AJvYcCUtA/VMszilqmYgT+wC8XwCMIjjpUjjUn3pnFIc9Hk00bKFQylU8v5x7wfnneU/TCaI4w6kZeUC2Q==@kvack.org X-Gm-Message-State: AOJu0Ywa54wJHjobamJHHGTmZ2b1aK+PN9/EAUV0FgNXc4akCaocc2dD 2otEiZiHk4n41AbxqM4VZkWY6pk2JLw0KqTj0X7Ezs+6IR6jdTEs/71p4RNogpY= X-Google-Smtp-Source: AGHT+IGL1oUEZJ3rWhtkHzcHN//l4Kwa6WIU+uMQ5VnS4NxAxx6XDhapJjpe9N68qs8G4gEKoRwuyw== X-Received: by 2002:a05:6902:1825:b0:e28:fa51:634a with SMTP id 3f1490d57ef6-e382615f44fmr2204741276.31.1731684691641; Fri, 15 Nov 2024 07:31:31 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e38152caccdsm1011626276.14.2024.11.15.07.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:30 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 06/19] fanotify: reserve event bit of deprecated FAN_DIR_MODIFY Date: Fri, 15 Nov 2024 10:30:19 -0500 Message-ID: <632d9f80428e2e7a6b6a8ccc2925d87c92bbb518.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0DB8C40029 X-Stat-Signature: 8eufq4h6cjxag1nu6n8ennpzgtwgxeon X-HE-Tag: 1731684634-441655 X-HE-Meta: U2FsdGVkX18ZTu4khX8X+CngbUHIEX8NMy6tqOo1tXzv8KGZcZizP2z4/sjt9CEmjhWfIrtnLypEJq3dlV8dxAP7QbD2NPuMvop73ie2/ANDnnV+m1wEW5iGVidYju1RtlWcyvegRIqZDB5HC/zHvXhqsAvXdTkzDSjCytqffAnSr6/kZLSaUdTxeGYOqynbvz+Ud2TltLCUDmY+3E3PVQ72d7yuxbdvbqSOwbgtv73YCdEYIWUI7NfQOnFNXC2pqA+lqw1Ph6MHTUZtPc/G0+KlvbOEKfIt2FqaiAZW1sTuwYGjRlZW/jMUoQR+dvfBzPSy0LMFE/cNUQGaANm/U+EXEdHc29AWtv732nOl8FT8uHlqgu788IYQDOHj7IPFwy6nPey6QNI7eCrix5/zFO5iu74hClHibQtDsut274JNaczBvvW7F4xNQKVWnwKL9eUpIp78Va6h+tmvFXule5+w00Jp2MeFhc27bwTB0wq9M9ukwy/37o0+GvxkM8bHFwY0kT9zLqOKYTmIKHI8z8hNK2kEQ5cVo9QlxHMuCFKBJ3FT6wUWQweCkcwwLd+muRUVGE6vfj0ZeJVIqFeNwltffiqC02Cn8Y3GySBZ8AUmkNl9T4y/B+H6Dx7yi15Qv0xu7EHG47Muv+lTAv1hwNG0Fyk4+AODzpEKjg0bJ3m53dYPANOxaaX6Mn0KOELkTFSuE1Ml9GcmznI4rTi0O3mooO/5wup3Bak6KIWP2cy4a7QmM4fWCBVqc37gkmgOFJvQY3phcKnO3k8D9y4kks5fAP1esQIKPuBD2e622MNZt6Nd+uu9H4yINF++hl4gs6j+bDrQ1HtCB4fjYYHe8sPz3KQjLZ0v7eMs5MM0UmLeC9QEanWvl8olVO1G85outOUTn6qTVbiQS9MqkGOCpHoYlcKW/ZiwxYtjGVKnVJgY9evZQ/faZlgdYalB48RUVgmmWOvNiApTbtjM6F+ Nl3imt5m Bhlwjud3gdcUYY6KgkKbBprk8TSelG4BwBRq35Rgek8f4cZRVNDsfB8PEiXvKi7w7O5I/+CakCkm1gRIt6E5DNzT8io3SxIPlPyr1G1PHJbzfFDGyPYkDbgCZ3TBfUdNf6Avka2Uf8aSRDaoGrGzyuYFXoi2GuF0xwwY1OUrKHc6wmj025AKjasiS2kUJ7yc4jsxUcbeYix2GknOubMwCGCw7c+pi+IVbrJ9z+miLkwm6LnYuO7thLguj8VFztd3KPwvdUfXMMcoODHhPEW7jWIHkvYcpdyh2dvkKW/KtOX3WmmWPnX+UnE3wTaq5V5iRRt1ZOhHLVSd+QLcr6zMKAXxIuQkoYxM3N0Eaaguwf6IwweMe9ZgFswaySOTXexFHSv5SSH5k+2V4wOmlb9MlL4CEcUwyAALNkTEhvU4lFNMgW5qruyge3NabvDDhJ0orXhMQIUhxy+OerRLXQCeFwk36ea2lAN5TAlgw5EMb2FQLas3kb4YZkZZfFg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Avoid reusing it, because we would like to reserve it for future FAN_PATH_MODIFY pre-content event. Signed-off-by: Amir Goldstein --- include/linux/fsnotify_backend.h | 1 + include/uapi/linux/fanotify.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 99d81c3c11d7..2dc30cf637aa 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -55,6 +55,7 @@ #define FS_OPEN_PERM 0x00010000 /* open event in an permission hook */ #define FS_ACCESS_PERM 0x00020000 /* access event in a permissions hook */ #define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */ +/* #define FS_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ /* * Set on inode mark that cares about things that happen to its children. diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 34f221d3a1b9..79072b6894f2 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -25,6 +25,7 @@ #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ +/* #define FAN_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ From patchwork Fri Nov 15 15:30:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876444 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 B1FCDD68BC6 for ; Fri, 15 Nov 2024 15:31:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A5736B0095; Fri, 15 Nov 2024 10:31:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 256896B0096; Fri, 15 Nov 2024 10:31:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 080E86B0098; Fri, 15 Nov 2024 10:31:37 -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 DE7B46B0095 for ; Fri, 15 Nov 2024 10:31:36 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 648C31C63D4 for ; Fri, 15 Nov 2024 15:31:36 +0000 (UTC) X-FDA: 82788718152.11.ACD82CD Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf18.hostedemail.com (Postfix) with ESMTP id 4829F1C0005 for ; Fri, 15 Nov 2024 15:31:14 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=TT7AbsI9; spf=none (imf18.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684456; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MRzK4Q1A3yuX/T2NQizEcUBNaZlB/P7dkcHbBOaMevU=; b=I3cmM4YgmMO0cvsvF6mwzVS4IvQSIZdqCWRJxUuRN9Kau57/PVzhzkFmQLcVSUWW5yumru 511xgNCEI1hid4aFxB2C9F8ByJ3hQoXg6zZq6+IsqIoZwhnyMTIxHxEnI8j7mvZjAFyVeq oVcQYcT0VkVfoAEMkyZCuIJ7a+o74YA= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=TT7AbsI9; spf=none (imf18.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684456; a=rsa-sha256; cv=none; b=p0TL0mohIaCfC4sYn9FnuJqoTO8eVLL0WKRfReGxJ2NNGpuICWBnk4VIh3YKKpHKMp6nsg oUgrEEJ1A8YK/tDvDaPE33EVStyTBxK6gE2FgeEopZE+NE8X2g4zci5urNZqJZ3SIz9XpG ihaINqOq5tzxfqf81rDkYsAZLfzVb7s= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e380d1389a1so746911276.2 for ; Fri, 15 Nov 2024 07:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684693; x=1732289493; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=MRzK4Q1A3yuX/T2NQizEcUBNaZlB/P7dkcHbBOaMevU=; b=TT7AbsI9sykEGnCh0T8ZrdjFtigBEN+rvNlD39a4qCVfPuYa/n0pI1pbmbY2abfg4e GEIxeUN/Y0/LKF92LURNB7kwnyO6JOmfsAIN39Fyv/JVFGedUZxAQMbVww/A8QGNe2Pf aDOaIimBlKF5XfHY0mEZlQnedqelYL7GsqOF+6WBUGfr/PnQ6y36UBPCU0Q9KF9G3peI 1Pb6OmU35Ebhzmyx3KA9uzboKpbnfZvfyg9MYHBiNuB2Em7JbPwdkWjGBaFhtcqN6689 IH8mm3IjvBD+faZ941xpklbV87yEImstvarA8FiMX8fGuBlR3QlCCLpfaFHgD3vyVNZM hr4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684693; x=1732289493; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MRzK4Q1A3yuX/T2NQizEcUBNaZlB/P7dkcHbBOaMevU=; b=qf++0+Y1Oufq3MDu9XZvQ7eSdXvoDTlV2TSFvcvfA3jlzbJeQcAIPlZ++W+1wo3yJu H/NAt0XBQwyqo/4gfK1eUaRWQFl5s3p5iI70fi6T8sMNL7+4d2yy0GpjFUsi6Uo4j5tV +Ge4D8vciCFdqnGljAWYpfb3/Fvo5HhNgkhlL8sLuu5me1dU8CbSl2N+LU+z/6pr3yS8 mzkOdo1ew/hugdfPPrPvPf6TdJnW0BuovsLMEoSQi2PlgtkJwyxC1Ym7FmqXDR+bKWuS coWU+6RsvJRNyQLKZYKMrNFeuFdNfZ440t761JNsnW1HS9dIv1YF0KRKOiMMMahqQBy9 5wng== X-Forwarded-Encrypted: i=1; AJvYcCV97yqgdsNidJNkI1cIOa/lWoBazDIrp1jiF+SE0WnDYGxNVZ98/L3kwkGs2nlmDy873PGI68H4bw==@kvack.org X-Gm-Message-State: AOJu0YxQ979pPHakJJv8Zu/pZKTpTSznebn+9xmAqcC8URimRsES8EZ4 1u18bIR/A0tFDvNDrmqrUk7fcHpo50cqWia/19/lo/XonHDJhlE3FsAOvD5rY8c= X-Google-Smtp-Source: AGHT+IGyWRJgeIXfM96kmRgZ4BcfzpHMEUIT23gvUh5NA4jhWm1kPkotZW2CvGFTnhHweMUdUT4Lug== X-Received: by 2002:a05:6902:f84:b0:e2b:b45a:149 with SMTP id 3f1490d57ef6-e382639f2b5mr2742461276.39.1731684693281; Fri, 15 Nov 2024 07:31:33 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e38152d0248sm963707276.23.2024.11.15.07.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:32 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 07/19] fsnotify: introduce pre-content permission events Date: Fri, 15 Nov 2024 10:30:20 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4829F1C0005 X-Stat-Signature: 4ncsubcq938byop6b6otybm5ah45am9k X-Rspam-User: X-HE-Tag: 1731684674-375563 X-HE-Meta: U2FsdGVkX18DBmF2cjjkqCj+xD12wReoRPmzC+NdAtBqZWrj9E4J7z0RjIInh5nojaxRcFHtd64Y9MPxJoWF1jzULM9++uN+Cx9gx5mu4PdtFSaZbsI9YXQtxEz4CC0yX9odnGoMfrZoB6nDcjCJVGat8D2NC/lwzocekeKpR9IT/GzWdNvrEfIMVpk/iVlNfntTHk1yF+wLaEtfEkuiXdBXLVXxQpsXVnfAevNARiQpTlWztGHBtFo6ztqzMgBGd7h6tniYijWyeMc9gNJ8WhARQYxfjLAgH0Zw5EGNl13OKUQt3YUl5uxyZckrFgHpglv+jVkJxUYePm3BpCEpLSH5doSLvYdXwpfyhpy5b9lu1VV1tGesywyXRX60HqMTMKTiC9d2kaUmay1AieAFKgXNMKkyUe8eA0Xl7RaMfm7xduQO3bWoYuYdAvnU1ea5LOYWkG1Z7JmnNwJ/lyikUiBV2nCBItnrtl82zDTgniSK/IMGeGe4lno+lLgRCFLGZPkzqNKzqDVqFEDvKzcMfIUorkZtj+hsy/K1buYlRcQ8lhroSQSrcXGJSP6uyCuUCFIWG78hZDbjD6VG6FbgeYEk6reJVYqDxiup7YtscQJMcKb06dJ8rVvTlqMPAOzunec9GgbIsgXej7lc49G71O4fH+FPHk8B3UlgscZtHVCRyOxNpd3dGzJMSFC5i5eiRZK9q9yZiUlOYKtia08Enk0ehRrMfiOHDnQPWIpGYzjs2RH8Fz73QFll5JwvS7ZRk9aZ1Mvr0E39MwdB6daJI6smvKiRV7Ss71zZOq//PB9b10ZOOtyY/+BQRQbbxuNwXPL6JjgiKs02soJLKmlCYrc06pDggIKJuY8NIRfx39kXObaAwMruXxxnc5zeQMs3E1dwK6ct3RR1BiEZ/TwqGW7YEayZeff2flAwGxBH2Q96i+HpFLRKMU6Uj4ZrO16oivwMZd5rYYirZJs+NVY BfECqv04 gSjUt9tLvvnvegAPsWJzg1/KozdhN4Hsh/GyzCPkRLGPnmKu9/6dk1W7aQ5AkqQJDLMZhwbzItS5moKl4tTKXpVhVYBYd0qRRuIaYQp6w8mxvgXKghAb8MAEFw0UVir3WzMRkBVLDts5BzBrekYbAeceYv5gckmiRcPk2/OJrE/iRKhjWswHaIHzuE5Is71G5hAHvsVgwWNh3Wv/N3SW/J1mAz3oGVGXYsifisNcmjYaESWq5i03EykT65tJ7BNVaqqcUuCgY19UjrHBhpLal8v2bgEBMH+2ud8W9z3bGqIg/pvYReitcPSgOJH7mqiajXjMnFLAAX3GGhh5DAPPMIdJFFg== 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: From: Amir Goldstein The new FS_PRE_ACCESS permission event is similar to FS_ACCESS_PERM, but it meant for a different use case of filling file content before access to a file range, so it has slightly different semantics. Generate FS_PRE_ACCESS/FS_ACCESS_PERM as two seperate events, so content scanners could inspect the content filled by pre-content event handler. Unlike FS_ACCESS_PERM, FS_PRE_ACCESS is also called before a file is modified by syscalls as write() and fallocate(). FS_ACCESS_PERM is reported also on blockdev and pipes, but the new pre-content events are only reported for regular files and dirs. The pre-content events are meant to be used by hierarchical storage managers that want to fill the content of files on first access. There are some specific requirements from filesystems that could be used with pre-content events, so add a flag for fs to opt-in for pre-content events explicitly before they can be used. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 2 +- include/linux/fs.h | 1 + include/linux/fsnotify.h | 39 ++++++++++++++++++++++++++++---- include/linux/fsnotify_backend.h | 12 ++++++++-- security/selinux/hooks.c | 3 ++- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 33576a848a9f..d128cb7dee62 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -649,7 +649,7 @@ static __init int fsnotify_init(void) { int ret; - BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 23); + BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 24); ret = init_srcu_struct(&fsnotify_mark_srcu); if (ret) diff --git a/include/linux/fs.h b/include/linux/fs.h index 8e5c783013d2..d231f4bc12aa 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1256,6 +1256,7 @@ extern int send_sigurg(struct file *file); #define SB_I_RETIRED 0x00000800 /* superblock shouldn't be reused */ #define SB_I_NOUMASK 0x00001000 /* VFS does not apply umask */ #define SB_I_NOIDMAP 0x00002000 /* No idmapped mounts on this superblock */ +#define SB_I_ALLOW_HSM 0x00004000 /* Allow HSM events on this superblock */ /* Possible states of 'frozen' field */ enum { diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 54ec97366d7c..994d7a322369 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -134,9 +134,10 @@ static inline int fsnotify_file(struct file *file, __u32 mask) * Later, fsnotify permission hooks do not check if there are permission event * watches, but that there were permission event watches at open time. */ -static void file_set_fsnotify_mode(struct file *file) +static inline void file_set_fsnotify_mode(struct file *file) { struct super_block *sb = file->f_path.dentry->d_sb; + struct inode *inode; /* Is it a file opened by fanotify? */ if (FMODE_FSNOTIFY_NONE(file->f_mode)) @@ -162,6 +163,19 @@ static void file_set_fsnotify_mode(struct file *file) file->f_mode |= FMODE_NONOTIFY_HSM; return; } + + /* + * There are pre-content watchers in the filesystem, but are there + * pre-content watchers on this specific file? + * Pre-content events are only reported for regular files and dirs. + */ + inode = file_inode(file); + if ((!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) || + likely(!fsnotify_file_object_watched(file, + FSNOTIFY_PRE_CONTENT_EVENTS))) { + file->f_mode |= FMODE_NONOTIFY_HSM; + return; + } } /* @@ -177,12 +191,29 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, */ lockdep_assert_once(file_write_not_started(file)); + if (!(perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS))) + return 0; + + if (likely(!FMODE_FSNOTIFY_PERM(file->f_mode))) + return 0; + + /* + * read()/write() and other types of access generate pre-content events. + */ + if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) { + int ret = fsnotify_path(&file->f_path, FS_PRE_ACCESS); + + if (ret) + return ret; + } + if (!(perm_mask & MAY_READ)) return 0; - if (likely(file->f_mode & FMODE_NONOTIFY_PERM)) - return 0; - + /* + * read() also generates the legacy FS_ACCESS_PERM event, so content + * scanners can inspect the content filled by pre-content event. + */ return fsnotify_path(&file->f_path, FS_ACCESS_PERM); } diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 2dc30cf637aa..33880de72ef3 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -57,6 +57,8 @@ #define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */ /* #define FS_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ +#define FS_PRE_ACCESS 0x00100000 /* Pre-content access hook */ + /* * Set on inode mark that cares about things that happen to its children. * Always set for dnotify and inotify. @@ -78,8 +80,14 @@ */ #define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE | FS_RENAME) -#define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM | \ - FS_OPEN_EXEC_PERM) +/* Content events can be used to inspect file content */ +#define FSNOTIFY_CONTENT_PERM_EVENTS (FS_OPEN_PERM | FS_OPEN_EXEC_PERM | \ + FS_ACCESS_PERM) +/* Pre-content events can be used to fill file content */ +#define FSNOTIFY_PRE_CONTENT_EVENTS (FS_PRE_ACCESS) + +#define ALL_FSNOTIFY_PERM_EVENTS (FSNOTIFY_CONTENT_PERM_EVENTS | \ + FSNOTIFY_PRE_CONTENT_EVENTS) /* * This is a list of all events that may get sent to a parent that is watching diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index fc926d3cac6e..c6f38705c715 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3404,7 +3404,8 @@ static int selinux_path_notify(const struct path *path, u64 mask, perm |= FILE__WATCH_WITH_PERM; /* watches on read-like events need the file:watch_reads permission */ - if (mask & (FS_ACCESS | FS_ACCESS_PERM | FS_CLOSE_NOWRITE)) + if (mask & (FS_ACCESS | FS_ACCESS_PERM | FS_PRE_ACCESS | + FS_CLOSE_NOWRITE)) perm |= FILE__WATCH_READS; return path_has_perm(current_cred(), path, perm); From patchwork Fri Nov 15 15:30:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876445 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 BF0BBD68BC8 for ; Fri, 15 Nov 2024 15:31:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42DB86B0096; Fri, 15 Nov 2024 10:31:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DBA86B0099; Fri, 15 Nov 2024 10:31:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E1B36B009A; Fri, 15 Nov 2024 10:31:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EBDDB6B0096 for ; Fri, 15 Nov 2024 10:31:37 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A3FEE1219AD for ; Fri, 15 Nov 2024 15:31:37 +0000 (UTC) X-FDA: 82788716724.03.1116C5C Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) by imf20.hostedemail.com (Postfix) with ESMTP id 134431C002E for ; Fri, 15 Nov 2024 15:30:38 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ErlCvOsc; spf=none (imf20.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.180) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684638; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HmDi22ux7vu/mgZp6ZHEvpaDEJU9ywEimHDaeGkRuI8=; b=4AP8WL65OgBJBojhdrVoBtI/fKj48Nyky/IFYAufLiYHERbLOsCO/0x2/xn9TZbNtUH4z6 huOCVnT2zlKPbyFZ1Bc+qc+141y1C+Bs95Swa+IupsTAqd/8eNxono3/d0CaIbVmUsVZEu CTxTB/P3CvGWJH+dQxsyNra8IfA3Szg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684638; a=rsa-sha256; cv=none; b=KlCaaSWyLf2cKReQ58Ij9gefsAWREX5CGd0brUJMBu+vlUnqgQRpQgR6ZgGLGmRryaee5K uSXt7Ikgw3EOW0bQCEzMw1bKqQdqODXNNY7iGWcaZekPf/W+2X72hvXb+vZK7De6vony2o itboUmNuG1+yt4gfRnhscDozSYHMCNI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ErlCvOsc; spf=none (imf20.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.180) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-6eb0c2dda3cso20774697b3.1 for ; Fri, 15 Nov 2024 07:31:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684695; x=1732289495; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=HmDi22ux7vu/mgZp6ZHEvpaDEJU9ywEimHDaeGkRuI8=; b=ErlCvOscPSm4ulGYNwcMoaCv3Hh83HO1qYWCzc44zo80u+mzyr09lHvFwG2i3zO01D XBOkyhNwLgqhZNice/FxESLKgnobBk5mPK5eG8SZYfpKSyiBc3pJoVRrNzJf8PiSzT/6 0NMRgbzoMwwud88mEkmks+lBtgiwHpe9lMrFcIdO5g3p/fQsi/TewEpi/6K/K9LwwmE/ X2ZVyXtuVrEDhfGyu+rYkGVkjUZc9LEM8waEBZe20zVKj5QV/y5ZxFVlSnEC/yy+GHZa TEpDQlb87CWf5YDGpS53FgGP/soXEGqm4m9YwAd0rzDILaQspRnOEusvB0ZWo7zPJDMH 8S1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684695; x=1732289495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HmDi22ux7vu/mgZp6ZHEvpaDEJU9ywEimHDaeGkRuI8=; b=Y21qkl20Kkexcq5bdljkRQAPSW6XWN+Ym6MPUQduDSXiB3m/DI8N2KXyDXp4hCW5Dj jlmR8IVR7yyFqUKBAE8FNB66nUdd2sKqjE8PPA9AJJp0XP4b0EYhN45EF3d+oaOGr4H3 sMn8Vc0TlOxTaFkOnwIyCB+iwB3BPI7hm/OX4aV06OBSDUbB4IbWFHvIxg10ZH0jtkmg C4bHeVHnHC4BW6QcWDokEmxoGzqCSqAuerXgThFtcGKYi/2i3qwGhtfcP9DLgDKZez31 pDrW0PXCC3KLSf1Iop65ivB4eCaB2I5Uvj1LKhSVfsaxTLEgj8kUf1/cdM7NJNfLdSmD hxfw== X-Forwarded-Encrypted: i=1; AJvYcCV1U/WoMwGNKmIVUbUOTlPar/lnK2pkoae5/Jak80wl5+T9+pBTOo11aLkrVbuXO9hjDzsUmyJsYQ==@kvack.org X-Gm-Message-State: AOJu0YyPcfROf9VW4kafnGR87aunVcvHS7pC+T74zNcZJxW+0mMK6opy lMu3JC2uGqJVUJpEXf4pZc09h95RK3QdIGcMDJbPhQAHXmtcpnkwuwarqqcf/Ks= X-Google-Smtp-Source: AGHT+IHRArDyJHlTef+3JwzlBCm2e+TOdRS4anVHdo81AyQIdw4zsmIETl6tl9pEKTE/6sFxZRHk4g== X-Received: by 2002:a05:690c:490e:b0:652:5838:54ef with SMTP id 00721157ae682-6ee55cff0c8mr38839537b3.37.1731684694891; Fri, 15 Nov 2024 07:31:34 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee4444b907sm7704477b3.121.2024.11.15.07.31.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:34 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 08/19] fsnotify: pass optional file access range in pre-content event Date: Fri, 15 Nov 2024 10:30:21 -0500 Message-ID: <88eddee301231d814aede27fb4d5b41ae37c9702.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: bfk78hdio4psr3i1uifkpjbbc1fstdxi X-Rspam-User: X-Rspamd-Queue-Id: 134431C002E X-Rspamd-Server: rspam02 X-HE-Tag: 1731684638-411341 X-HE-Meta: U2FsdGVkX1+Tq7PT0vEjXUAz+9//tokore4IxWg5DyJb1N9Vw1VcwU5J1iXCNJfJpKGlx6/ENN+DAxkC6pBuugINcoBq0QSb6s6zp1CZvx5Bgo5AZsqQUKWKljP2J1KrrQs3zIHVI/xjdN5pjpMDWKVRh34qQWJIxZqavGrnEapDrh04ExjJ9P/c8sSiIiZCbcKdKfX3G5Cg0oKM5bY0wQfZ4cIAQzjcahE7wBuBcJegsh0CZx2sg9YPWy/Z1uBW8lcGEJPyv7vua/GWncA76H7+vGg73SVQADzZwdZxSjciPw+6MtuEPQqF8vtYsoJGvTXt+wen5CPO0km/uPTQR+MRm4hwKS5Jcqa5+UCsGaGuc7hOQGB27BPFlowRlVrI66ViTj1alOuAhldKjpvO6Jh2ml3gjMiim3q4gs0d1KNQJQK8PLD2XzOkCkWECW01I/u9UGFKg+bK3tKr8q+sY9H1yMCydceLnxG2plFB74kBcWHjT1CMbOecZDtsS7WNn8sfLN9htJPHSWBTO7+rSpn3Q3dvwea4D+iFFKPJaS+HyHag+ACVNaVUMfr/A7vw8XXTWuW7UpoqI5yvqiNYyo/pZ7uj2PSvt6YOd+VDJt7kYsrwVCcb5srgZbJ9QkIEh+Ti4zCpi1EWQWiduHiJREKbEsRRAzM1MSJo0x7HPmBOVqufcLFWMxgWJHtKXhgvtxf+uv3fKrL/NYTyJfn0ZBjOZShax+J3mftH8/N6LfY0W2mtNb1ry7DagA6/BXp2l+OPPME7RQzLDNpPS2TPuVi/nFTm9CU+DxiSN0a6XY/+H5WcHYpS/DRHpTyypeSQX9eEZJukpwbGNpDHYzPND7OSZXnsYbOuXk9sBzkyF/4911s7DnncDPG8RDDDskXdN44q034lXXtlzpDYMYZQFx+AXA6zqMSHpP310b0d2YZfVpuo/28Mmyixi3/565MEt0296/+Rw+eLmZtJy6t iVDlAKfY Okj728zxdgafdf8QLHlgCxwEKzsfmCJ8lp3XGBwYt+oq5oODMd3VjsbtNWEOihb82tcMNz9YhY1ifwh04CT1vGyTy/7X2HshS7jG9v6hd5Dg520+vYOoU5qslR3FE+5vCc6ZMAPryORgUswvWQiyxHrpuRX6zukJ2XLNZVRjQ7cjn7z+Kgz3sHNgGPB4ttfGy6JtdhTl4C1+cpGTeiFJhYcVwtE8L959a6Fzvg65JFHfCcqQLV3pfa05l3NxGjYRTDJq4gy4J/dkm/OIVASX7PpFnyFCCaS3MMYIkJmDi7LJnezNzPPuNqZCi45lfBFlqChETtbEHKnANPQsN024SkjHzMg== 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: From: Amir Goldstein We would like to add file range information to pre-content events. Pass a struct file_range with offset and length to event handler along with pre-content permission event. The offset and length are aligned to page size, but we may need to align them to minimum folio size for filesystems with large block size. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 11 +++++++-- fs/notify/fanotify/fanotify.h | 2 ++ fs/notify/fsnotify.c | 18 ++++++++++++++ include/linux/fsnotify.h | 4 ++-- include/linux/fsnotify_backend.h | 40 ++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 24c7c5df4998..2e6ba94ec405 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -548,9 +548,13 @@ static struct fanotify_event *fanotify_alloc_path_event(const struct path *path, return &pevent->fae; } -static struct fanotify_event *fanotify_alloc_perm_event(const struct path *path, +static struct fanotify_event *fanotify_alloc_perm_event(const void *data, + int data_type, gfp_t gfp) { + const struct path *path = fsnotify_data_path(data, data_type); + const struct file_range *range = + fsnotify_data_file_range(data, data_type); struct fanotify_perm_event *pevent; pevent = kmem_cache_alloc(fanotify_perm_event_cachep, gfp); @@ -564,6 +568,9 @@ static struct fanotify_event *fanotify_alloc_perm_event(const struct path *path, pevent->hdr.len = 0; pevent->state = FAN_EVENT_INIT; pevent->path = *path; + /* NULL ppos means no range info */ + pevent->ppos = range ? &range->pos : NULL; + pevent->count = range ? range->count : 0; path_get(path); return &pevent->fae; @@ -801,7 +808,7 @@ static struct fanotify_event *fanotify_alloc_event( old_memcg = set_active_memcg(group->memcg); if (fanotify_is_perm_event(mask)) { - event = fanotify_alloc_perm_event(path, gfp); + event = fanotify_alloc_perm_event(data, data_type, gfp); } else if (fanotify_is_error_event(mask)) { event = fanotify_alloc_error_event(group, fsid, data, data_type, &hash); diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index e5ab33cae6a7..93598b7d5952 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -425,6 +425,8 @@ FANOTIFY_PE(struct fanotify_event *event) struct fanotify_perm_event { struct fanotify_event fae; struct path path; + const loff_t *ppos; /* optional file range info */ + size_t count; u32 response; /* userspace answer to the event */ unsigned short state; /* state of the event */ int fd; /* fd we passed to userspace for this event */ diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index d128cb7dee62..538aacf990ca 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -225,6 +225,24 @@ __u32 fsnotify_file_object_watched(struct file *file, __u32 events_mask) } EXPORT_SYMBOL_GPL(fsnotify_file_object_watched); +/* Report pre-content event with optional range info */ +int fsnotify_pre_content(const struct path *path, const loff_t *ppos, + size_t count) +{ + struct file_range range; + + /* Report page aligned range only when pos is known */ + if (!ppos) + return fsnotify_path(path, FS_PRE_ACCESS); + + range.path = path; + range.pos = PAGE_ALIGN_DOWN(*ppos); + range.count = PAGE_ALIGN(*ppos + count) - range.pos; + + return fsnotify_parent(path->dentry, FS_PRE_ACCESS, &range, + FSNOTIFY_EVENT_FILE_RANGE); +} + /* * Notify this dentry's parent about a child's events with child name info * if parent is watching or if inode/sb/mount are interested in events with diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 994d7a322369..ce189b4778a5 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -201,7 +201,7 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, * read()/write() and other types of access generate pre-content events. */ if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) { - int ret = fsnotify_path(&file->f_path, FS_PRE_ACCESS); + int ret = fsnotify_pre_content(&file->f_path, ppos, count); if (ret) return ret; @@ -218,7 +218,7 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, } /* - * fsnotify_file_perm - permission hook before file access + * fsnotify_file_perm - permission hook before file access (unknown range) */ static inline int fsnotify_file_perm(struct file *file, int perm_mask) { diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 33880de72ef3..89f351193d8f 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -294,6 +294,7 @@ static inline void fsnotify_group_assert_locked(struct fsnotify_group *group) /* When calling fsnotify tell it if the data is a path or inode */ enum fsnotify_data_type { FSNOTIFY_EVENT_NONE, + FSNOTIFY_EVENT_FILE_RANGE, FSNOTIFY_EVENT_PATH, FSNOTIFY_EVENT_INODE, FSNOTIFY_EVENT_DENTRY, @@ -306,6 +307,17 @@ struct fs_error_report { struct super_block *sb; }; +struct file_range { + const struct path *path; + loff_t pos; + size_t count; +}; + +static inline const struct path *file_range_path(const struct file_range *range) +{ + return range->path; +} + static inline struct inode *fsnotify_data_inode(const void *data, int data_type) { switch (data_type) { @@ -315,6 +327,8 @@ static inline struct inode *fsnotify_data_inode(const void *data, int data_type) return d_inode(data); case FSNOTIFY_EVENT_PATH: return d_inode(((const struct path *)data)->dentry); + case FSNOTIFY_EVENT_FILE_RANGE: + return d_inode(file_range_path(data)->dentry); case FSNOTIFY_EVENT_ERROR: return ((struct fs_error_report *)data)->inode; default: @@ -330,6 +344,8 @@ static inline struct dentry *fsnotify_data_dentry(const void *data, int data_typ return (struct dentry *)data; case FSNOTIFY_EVENT_PATH: return ((const struct path *)data)->dentry; + case FSNOTIFY_EVENT_FILE_RANGE: + return file_range_path(data)->dentry; default: return NULL; } @@ -341,6 +357,8 @@ static inline const struct path *fsnotify_data_path(const void *data, switch (data_type) { case FSNOTIFY_EVENT_PATH: return data; + case FSNOTIFY_EVENT_FILE_RANGE: + return file_range_path(data); default: return NULL; } @@ -356,6 +374,8 @@ static inline struct super_block *fsnotify_data_sb(const void *data, return ((struct dentry *)data)->d_sb; case FSNOTIFY_EVENT_PATH: return ((const struct path *)data)->dentry->d_sb; + case FSNOTIFY_EVENT_FILE_RANGE: + return file_range_path(data)->dentry->d_sb; case FSNOTIFY_EVENT_ERROR: return ((struct fs_error_report *) data)->sb; default: @@ -375,6 +395,18 @@ static inline struct fs_error_report *fsnotify_data_error_report( } } +static inline const struct file_range *fsnotify_data_file_range( + const void *data, + int data_type) +{ + switch (data_type) { + case FSNOTIFY_EVENT_FILE_RANGE: + return (struct file_range *)data; + default: + return NULL; + } +} + /* * Index to merged marks iterator array that correlates to a type of watch. * The type of watched object can be deduced from the iterator type, but not @@ -865,6 +897,8 @@ static inline void fsnotify_init_event(struct fsnotify_event *event) } __u32 fsnotify_file_object_watched(struct file *file, __u32 mask); +int fsnotify_pre_content(const struct path *path, const loff_t *ppos, + size_t count); #else @@ -873,6 +907,12 @@ static inline __u32 fsnotify_file_object_watched(struct file *file, __u32 mask) return 0; } +static inline int fsnotify_pre_content(const struct path *path, + const loff_t *ppos, size_t count) +{ + return 0; +} + static inline int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, const struct qstr *name, struct inode *inode, u32 cookie) From patchwork Fri Nov 15 15:30:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876446 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 0F161D68BC8 for ; Fri, 15 Nov 2024 15:31:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8720D6B0099; Fri, 15 Nov 2024 10:31:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FB226B009A; Fri, 15 Nov 2024 10:31:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6750E6B009B; Fri, 15 Nov 2024 10:31:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 46BC66B0099 for ; Fri, 15 Nov 2024 10:31:39 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0C9371418E7 for ; Fri, 15 Nov 2024 15:31:39 +0000 (UTC) X-FDA: 82788716556.09.6967C74 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by imf08.hostedemail.com (Postfix) with ESMTP id E27E416001D for ; Fri, 15 Nov 2024 15:31:06 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=CtSXebim; dmarc=none; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.182) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684565; a=rsa-sha256; cv=none; b=bQduX9X7dTD9H+bmDNlj3rtaBhEvT8PHSvir8B4lddClsfTwYdsVDxe0Dw2kEDZR0RMPrn Sq6sQ1mnfYxgGTOztQeub7X747wpko/KflMrIaW+XQI0J/SjuxoA1xB9kacB1xUQEdy/Mo jrmVTrDp4UD5LYjB+n0UhPWgR2ktdpY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=CtSXebim; dmarc=none; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.182) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684565; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fc94RDUI6NSDstxP0CCSGWYRtQ6KzVO9XtXkr+KxT+s=; b=Qr0WfjH98g0gdAt0qh3f9fglg9o//R1sLm1js6lv7HAtI7rERo83GcCmmvju1zr0CHl43Q aXJfg1Dwu3PnLTY/e5waZAuPRyMfI4RbLhOyqI4/+17bscyUE/Rh8gLc8vXjbGzPGDSEQz rXH4jDHF+c3Rur4SQWiOFakdLEQ8i2M= Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-6e377e4aea3so16029237b3.3 for ; Fri, 15 Nov 2024 07:31:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684696; x=1732289496; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=fc94RDUI6NSDstxP0CCSGWYRtQ6KzVO9XtXkr+KxT+s=; b=CtSXebimwf4rz2FISjlAgQKaxf7BhkDFtfHgoq2DPbaBX3CpadboGbYpqpM2vvcOYp gWpRMhhkjuVwbWf7LahIqM/RgAFSjgg06LRg2pmpaUnI89RDBN4Qt0EAKzTInwPrpszc CkttiFxbNrkM/SJ7nBzhZhQy85nu9DgR9a17fCJrqXRV2nS2yCAnSYOnEPMJm3bW2dlB RtdIFIKjBqeRcDpkbw+GtrSubhh0Touf+gITEfnjTrNMiPu70N1TZWCbdav81PBMRgAD ZkSfRWEr3RNRFs9WQCKKOZC+eolPjo3fCTwh0ljW4aoan9gXMLSdhokx0xrCMDJcutIM q91A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684696; x=1732289496; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fc94RDUI6NSDstxP0CCSGWYRtQ6KzVO9XtXkr+KxT+s=; b=B3UMF65CUkaMZtZLLgR6/w6+Mm5rf4YzgS5urkl2HWugDLqjHkR2NX8qk5N+TVhlcy JGZcXrPNpIsE9qjv7x+62CHlhR5FuavkXwSf3MzoVIufziLHwTw5GppL0NEtmmoJix4y rfaGjsRkHWclI9/o3T2pXPwwpnyDvaoQOePwjomKgGsmn2e664dSQz+13iz7KgQPyp8+ DC/oaXYEDD3fc36XD+ZoAI/QkRp9tL2LcdWnUSXWiH6q6wxFZ98l6008s2D4990fCQs0 UjwgI+H80mDxA/Rw0xtQQgO/RhyW568abhJZzi4DOEBouSv9yofGKsd753BqE18Dd+dV 9Qrw== X-Forwarded-Encrypted: i=1; AJvYcCXfQ+lgowT/kD2xiQsjPP1939R0NonjfaPZ5pawcHW2cN7tO9W9TpjC/eVoxOH7TCxS7D5LNf8+uw==@kvack.org X-Gm-Message-State: AOJu0YyRV4sWWJATg8DLJ6mENq6ccKPBVyGG8qW94Q+V6hRV15gfk7Hr 8EnsNgJfVxvrnROHcBKE4ticAhtnEpTPECBwswDSH1tfuC54dbf9DwiZinAjjYQ= X-Google-Smtp-Source: AGHT+IF/6XDeCM5HdGyZ+bKpb7CwsA0grIiF+sgXOFU/Ezrvf0/YQwsV5K3Q/P9oh37dfkgoQYNabg== X-Received: by 2002:a05:690c:610f:b0:6e3:31e8:7155 with SMTP id 00721157ae682-6ee55ef7f91mr39398227b3.40.1731684696301; Fri, 15 Nov 2024 07:31:36 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee6dfe1a17sm202557b3.64.2024.11.15.07.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:35 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 09/19] fsnotify: generate pre-content permission event on truncate Date: Fri, 15 Nov 2024 10:30:22 -0500 Message-ID: <23af8201db6ac2efdea94f09ab067d81ba5de7a7.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: E27E416001D X-Stat-Signature: oc79sozctktn546owyuqpxcpbtcd81tt X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731684666-196685 X-HE-Meta: U2FsdGVkX1/DZdFYpX0iAIDi++lOKpVV+Bwurq7VdnA+qiVARQ6/7ly9bXkvRM3xagIgW5auOiI+tJtiUGbM0y0jwZUPTQcCtov0ggwp5nO4s1eiLH9x2QhY2wkEiCO5wmli2RwugD+FhNgcd3OjsKGu2GVmT27FDZItLs+ISoLlW2ZtJG1Km8Fgr9U/Ujce4fOzSyYODiGd0Fb/eikJFBtlh3u7umvNtt0VgygHzV0goC9/D9orHfubhp0ZOkuZAhz6fToeegt9lIlaxYwN13mJJCBpnvw9l0T5/aR8cw91XBcJMZhhlew1pJImUdWM1v2LW2YCjVH7BoGg5gvFm8Yur7dtQt3QElsv4kiMXJVfbBMotAuSr9BSuMAyoKVasfauyFay0+EMyf7y1DG+CqX6de0zG33EGqJ7JEiMyyQuN7olLundr35Q2HpjZbK6IlnIogR0uLLC3qPJpqSduCNqvAmsTrVTXQb6aunGWKag9YkG44soVBNzS/HsBwNFKkd5hpC8AjPm4IF4ZvZ4usOXNv8cISEW/qpxIk9Ru2KohmjGNQUvCtZO2NAx4ejYAova6zZ8GgTpTM8GcKUklzllPBX22DcJb42t2tQmKd6sH7K82bxhnpX2pGI2XFgn4vlc5hUt9r0yXGgkARLbW9prAVxXhUeNuT4oKKcM6Ouz+ub26AuB2e1B8UYeUaaYY6oTZkc2wWE9Mr5p9nU3y+mYlhmjpmIs7FHrqUxNDUfIWc+3RGk2s0GYu7rwvulz5eMnPInVgKlhR4TV/ZUWjtE4CFf23MWd6acpNkVwGoMxkB8hrHqkKfFg+k5td4FAZmxF1hycQd0VZ1FaWJivKJUlu/f6/orR8kUxE2ibZ+4dv16fs0Sm0Hw2HvofgBH1NLhW0qloPk7e0S9qzvVR8TXJeCI0jnXrpIbaxg9BRwk4ZF/y2m0RLsg1Zs3LK43XAseNAGyzqX8ZzXvKAWl Ni49w0p4 HHRHh/Cjh9Tq8ftNOafnmr/V4+09W3kK+442NVQP7imGy5IuD1bCAbZVTTahCmeXH6+wTc+/QIofm37+Tl7n3jbBSnUebxJArStARBl4kvSe1Ce+NMAAUUnyuZ7aN59JdBe6nrNCbIjmdJHE72BjpUTDXlXU/deVOblhyjJVdokw7YF3F2QrIi97JfWNxLjRRV/4x3SpKWdTOgXA2k4Z1DsasovO4zk0541ULCZeMm5s8xvTnRFiXI3efWEafACUP9WDGQaIQfg9Vmw96YNLovociNurlNPaZhbwvJulSscKz86DHO+s8I8MsareaDoD/d7xE71TExDc8hgT8eiCzUEAuHQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Generate FS_PRE_ACCESS event before truncate, without sb_writers held. Move the security hooks also before sb_start_write() to conform with other security hooks (e.g. in write, fallocate). The event will have a range info of the page surrounding the new size to provide an opportunity to fill the conetnt at the end of file before truncating to non-page aligned size. Signed-off-by: Amir Goldstein --- fs/open.c | 31 +++++++++++++++++++++---------- include/linux/fsnotify.h | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/fs/open.c b/fs/open.c index 1a9483872e1f..d11d373dca80 100644 --- a/fs/open.c +++ b/fs/open.c @@ -81,14 +81,18 @@ long vfs_truncate(const struct path *path, loff_t length) if (!S_ISREG(inode->i_mode)) return -EINVAL; - error = mnt_want_write(path->mnt); - if (error) - goto out; - idmap = mnt_idmap(path->mnt); error = inode_permission(idmap, inode, MAY_WRITE); if (error) - goto mnt_drop_write_and_out; + return error; + + error = fsnotify_truncate_perm(path, length); + if (error) + return error; + + error = mnt_want_write(path->mnt); + if (error) + return error; error = -EPERM; if (IS_APPEND(inode)) @@ -114,7 +118,7 @@ long vfs_truncate(const struct path *path, loff_t length) put_write_access(inode); mnt_drop_write_and_out: mnt_drop_write(path->mnt); -out: + return error; } EXPORT_SYMBOL_GPL(vfs_truncate); @@ -175,11 +179,18 @@ long do_ftruncate(struct file *file, loff_t length, int small) /* Check IS_APPEND on real upper inode */ if (IS_APPEND(file_inode(file))) return -EPERM; - sb_start_write(inode->i_sb); + error = security_file_truncate(file); - if (!error) - error = do_truncate(file_mnt_idmap(file), dentry, length, - ATTR_MTIME | ATTR_CTIME, file); + if (error) + return error; + + error = fsnotify_truncate_perm(&file->f_path, length); + if (error) + return error; + + sb_start_write(inode->i_sb); + error = do_truncate(file_mnt_idmap(file), dentry, length, + ATTR_MTIME | ATTR_CTIME, file); sb_end_write(inode->i_sb); return error; diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index ce189b4778a5..08893429a818 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -217,6 +217,21 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, return fsnotify_path(&file->f_path, FS_ACCESS_PERM); } +/* + * fsnotify_truncate_perm - permission hook before file truncate + */ +static inline int fsnotify_truncate_perm(const struct path *path, loff_t length) +{ + struct inode *inode = d_inode(path->dentry); + + if (!(inode->i_sb->s_iflags & SB_I_ALLOW_HSM) || + !fsnotify_sb_has_priority_watchers(inode->i_sb, + FSNOTIFY_PRIO_PRE_CONTENT)) + return 0; + + return fsnotify_pre_content(path, &length, 0); +} + /* * fsnotify_file_perm - permission hook before file access (unknown range) */ @@ -255,6 +270,11 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, return 0; } +static inline int fsnotify_truncate_perm(const struct path *path, loff_t length) +{ + return 0; +} + static inline int fsnotify_file_perm(struct file *file, int perm_mask) { return 0; From patchwork Fri Nov 15 15:30:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876451 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 02EDFD68BC6 for ; Fri, 15 Nov 2024 15:32:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB87E6B00A2; Fri, 15 Nov 2024 10:31:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C670F6B00A3; Fri, 15 Nov 2024 10:31:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B09DB6B00A4; Fri, 15 Nov 2024 10:31:52 -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 901B76B00A2 for ; Fri, 15 Nov 2024 10:31:52 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4641216193A for ; Fri, 15 Nov 2024 15:31:52 +0000 (UTC) X-FDA: 82788719160.02.50DC622 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) by imf18.hostedemail.com (Postfix) with ESMTP id 118AC1C002A for ; Fri, 15 Nov 2024 15:31:29 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=bgToyVgF; spf=none (imf18.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.210.54) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684472; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ma7Y5+BFpcWgfxwOepr2mPEvJR7BrAPr6ViHq4rzmZc=; b=I+c3lpJoz4nuIfdMti76wTrJqq2FNh86xIkv1mlocoEc+pX+5Kkvvd4hWWHQ4oox8WcL7G tLxE7FsWwMh/ikm49mrsP513ZvgjbxDaxDAnn19zHoB4Lk+cgn9ViEIECkawuFDTpcviD5 kIAkCuwMDkV5i+YW5wrlMk7rffCG8Jg= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=bgToyVgF; spf=none (imf18.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.210.54) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684472; a=rsa-sha256; cv=none; b=Tqk5xjnRysGJWlOZPSUE4t4V0CS94PmVTucghNvCdRu200SEcs7GnfjtQy4LgIhhkszGPp /eUVdQlXlvvDKB+1ZuQpVpxJE3KMgTg5MqzqZpcT6MsfkQ0/M7/cNAXsZ9obkSTEDNogux 0wBjo8Qa2J8RkQp5jhzG5UqTB5zwL4o= Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-7180dc76075so917621a34.3 for ; Fri, 15 Nov 2024 07:31:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684709; x=1732289509; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Ma7Y5+BFpcWgfxwOepr2mPEvJR7BrAPr6ViHq4rzmZc=; b=bgToyVgFOT2AdDc5OrCTnKLtrc2zAOTkJaSpT2hdDn8Gtljzsl2/1FTvEjQqB7uGnp n7eOSTkZYG/W3+xCFuEnqDURBdeERwUGV4TcXvmzOviDjWsFmD745Ueuc6vOtbginPlE gG3ITpt3XNADkSfFNBxnLE45lbRtZ3q7Gr3XVz6MFc+gaXbgs7Ko+Lb4O44RIDC5RV9X 8DZGEdwA6NUli1ON3TsiCCusjtXNrUMcAXfkbjfEVLcbd6FVbtXNN1/0Oa0Z2Xykeo0T RucrHkX7o5A6JpHuZ+eaugereNjn9AUDoP0iTY49n8Ccxph9FsDbSzgzNwM56y9p0IQ6 QG0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684709; x=1732289509; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ma7Y5+BFpcWgfxwOepr2mPEvJR7BrAPr6ViHq4rzmZc=; b=gvO53A34LZBvpxGeJ+hW6e4/37gYwujOYBSdP03FQ/dmRBZVaVJTFVP252ADYLgWQf LRDJ/53x36i7UQpjMfGXPr5lUPvznNtLgRm84lr9F28qachvxQOhqWMWbAS053G07Y62 ewIzusvyk4BXtqRGS8bZY7gI0QfnBnFL2fmUPKoRjwgBNsdQgriMPhVAn1cg912zDInP A2PvL3NonWX+Yfz/WII5t87YtzYTZq47NmFB22pDtzl58H70xm4P4DJ8ueMJIkv7VOE7 JkkHkdqXikb/PgHsYHxmnqddKfWxuVh9fjISP0Z+k/tF9hWj00SGRJYRfM630t2nSer0 xvag== X-Forwarded-Encrypted: i=1; AJvYcCUivXEIkMM25fvkDnq2D7ZNxQNr0KxFb12F78SoWTT22A+ynsQAk4JQ5qmA2fo+gDB829/ABbucjQ==@kvack.org X-Gm-Message-State: AOJu0YwP1pQukYYTAtd9AslEgQlZChbOAik14mbZj3Q9E4Uzt4MIMk4g 25RuL8g0G4uUKRH4pB46corM1OJzHWZedXzfzUJdcei7nUUYPbtkulp9YWu3A1S6rPGp+BsqwJ1 O X-Google-Smtp-Source: AGHT+IH4KF4O/0TeALgb4lQDmEiPTFLtEsIEnnQGgceAZNppg9oa7TyTq0ub2EblRWNTki1B2uNPXQ== X-Received: by 2002:a05:6902:18ce:b0:e30:e1f3:2a9c with SMTP id 3f1490d57ef6-e3825bdd1fbmr2969338276.0.1731684697839; Fri, 15 Nov 2024 07:31:37 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e38152ab555sm1006714276.12.2024.11.15.07.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:37 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 10/19] fanotify: introduce FAN_PRE_ACCESS permission event Date: Fri, 15 Nov 2024 10:30:23 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 118AC1C002A X-Stat-Signature: 5r75htu7qariw443suixh4c55ipunke5 X-Rspam-User: X-HE-Tag: 1731684689-88850 X-HE-Meta: U2FsdGVkX1/XMhgaUAbwEi4XtBgkpkV8aBy/iO32lR+u806p5AShQ/Js7a3vDZQcJ5RECSRGJk5xHwEPZhfKwYP9jq4qI79fFAEfv11kwk6g+z9We1dG2NuiBbGQATRWyb1yA2t0aBB5Mo12+Om/HR7H2ghgdeS19EpEXt0w9c2rS3FIUJ+Ab3I1OjTC1u5h6mxOFkuF0lzweKxDygTxn3EdupRhdWE1o0JrPdC4EhIo8T2YPLNE1xTLgvbFkcWVAd97AcOUJI28AGe31mBDT0GOIAc4/k9UzY5Lq8ue1AJ2CgFxsnywWsJCFNP3YJFJcyFMHS+ZSOmJjWky5Rx1qapoY2owdZOoBN9oWKg65fce3BGxEMDA90VZj4nfC1MFQz+hZTncoBacCXOfPkoEkOLoJ7ysHd14pgAiwOOPVZsYJAWONraBM6YHqlYEBhyLEKDUv4Q1qrvqkFTDR7WcEIv7FeY1cbWuO8QgKd3RrCEcTEBL7tYmr8efDzj+ICkDGWQ27fVqe1bhvqhKQAjUZ5V1fYishD3aNz+IAwAZDK1cpsUq4x/ARVhLLm9tsU9uzuvd5JMUWLGfQf8tzwJYcOdeIdXydxTq7tB4jdg3Fssw1IoXEJIk0UJr7HQQojQoVRRQYJzXNeZPUiMtzRAzk9hPF0f0lQ/Itutbpgj/wD10zBWA+d/4jP2CQ/oOeir3NXI3eM8ynHYPw/jHH2e3qCCoqj4zhGo6X7L9yRGsJi/JsPaL+fAavAFbCcIu2vp6z0ZFjnwv8H7/UX4pKhw9PTUYQ5X1V4PAHkicImL8p1GyuihSsgFueSnU2BB3qZGljQlJzpQIxS52cEAcsl8XTXKnFW7w0U9FPu96SnYEC8uKL0j5iM5frPI/SNYirgNZKTQrfiigrkNDGEbQquYJT4PE48GcqCMKYVWVhJu78HRF2LWKvyYgQFfF0atxfdVuSm0cnaXTvWynDJ9zxno YDb2FwLl BoZT4UStlpgRNweYCsVz20cZf2SDrgxeAcv8k5u7MdXUWF6XSG3Pptjts73+ITyIN3US/7HofW3dFH+ObfIGfSsxaS6b5VB8GEgqy0IA4rLNmEKLSv2P5JY2PRhOmj8nDgjUR270Xg/N1txpFPWUIG30NfJWXQCRiTTaHBr6KN6q39MYQIh9gbA0cTAjhf6eNxE6MrIPyOT7fzMYy2CMaDKZi22Cn57dXE0nOZSreTAbySZnq0i4JBAafxtKUe8PqV+5qHLShvgM6qwruEbbzsCE/UgAhFjpJ6skCK5uyBaHtEaIMv8TPvbCFrayz4UPsQ1pXW4yxgYesGQ0akwOCzEBJYRM29rNYmlYw6/utaaYttsVYTHblMNWJYBl7Fy7XfVFXwfWDVgmafdxbzRQfBeQPgMRhhGAEk8B0rMDEBBU7W36r58+u6nc0Wb8gU2LcLvbSC2r2Pv9dsjZ8vaXbLdqNgcMvuKZyM6AdxXQIQ4U5OTX5l6YeSEAdag== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000011, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Similar to FAN_ACCESS_PERM permission event, but it is only allowed with class FAN_CLASS_PRE_CONTENT and only allowed on regular files and dirs. Unlike FAN_ACCESS_PERM, it is safe to write to the file being accessed in the context of the event handler. This pre-content event is meant to be used by hierarchical storage managers that want to fill the content of files on first read access. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 3 ++- fs/notify/fanotify/fanotify_user.c | 22 +++++++++++++++++++--- include/linux/fanotify.h | 14 ++++++++++---- include/uapi/linux/fanotify.h | 2 ++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 2e6ba94ec405..da6c3c1c7edf 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -916,8 +916,9 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask, BUILD_BUG_ON(FAN_OPEN_EXEC_PERM != FS_OPEN_EXEC_PERM); BUILD_BUG_ON(FAN_FS_ERROR != FS_ERROR); BUILD_BUG_ON(FAN_RENAME != FS_RENAME); + BUILD_BUG_ON(FAN_PRE_ACCESS != FS_PRE_ACCESS); - BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 21); + BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 22); mask = fanotify_group_event_mask(group, iter_info, &match_mask, mask, data, data_type, dir); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 456cc3e92c88..5ea447e9e5a8 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1640,11 +1640,23 @@ static int fanotify_events_supported(struct fsnotify_group *group, unsigned int flags) { unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; + bool is_dir = d_is_dir(path->dentry); /* Strict validation of events in non-dir inode mask with v5.17+ APIs */ bool strict_dir_events = FAN_GROUP_FLAG(group, FAN_REPORT_TARGET_FID) || (mask & FAN_RENAME) || (flags & FAN_MARK_IGNORE); + /* + * Filesystems need to opt-into pre-content evnets (a.k.a HSM) + * and they are only supported on regular files and directories. + */ + if (mask & FANOTIFY_PRE_CONTENT_EVENTS) { + if (!(path->mnt->mnt_sb->s_iflags & SB_I_ALLOW_HSM)) + return -EINVAL; + if (!is_dir && !d_is_reg(path->dentry)) + return -EINVAL; + } + /* * Some filesystems such as 'proc' acquire unusual locks when opening * files. For them fanotify permission events have high chances of @@ -1677,7 +1689,7 @@ static int fanotify_events_supported(struct fsnotify_group *group, * but because we always allowed it, error only when using new APIs. */ if (strict_dir_events && mark_type == FAN_MARK_INODE && - !d_is_dir(path->dentry) && (mask & FANOTIFY_DIRONLY_EVENT_BITS)) + !is_dir && (mask & FANOTIFY_DIRONLY_EVENT_BITS)) return -ENOTDIR; return 0; @@ -1778,10 +1790,14 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, return -EPERM; /* - * Permission events require minimum priority FAN_CLASS_CONTENT. + * Permission events are not allowed for FAN_CLASS_NOTIF. + * Pre-content permission events are not allowed for FAN_CLASS_CONTENT. */ if (mask & FANOTIFY_PERM_EVENTS && - group->priority < FSNOTIFY_PRIO_CONTENT) + group->priority == FSNOTIFY_PRIO_NORMAL) + return -EINVAL; + else if (mask & FANOTIFY_PRE_CONTENT_EVENTS && + group->priority == FSNOTIFY_PRIO_CONTENT) return -EINVAL; if (mask & FAN_FS_ERROR && diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 89ff45bd6f01..c747af064d2c 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -89,6 +89,16 @@ #define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE | \ FAN_RENAME) +/* Content events can be used to inspect file content */ +#define FANOTIFY_CONTENT_PERM_EVENTS (FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \ + FAN_ACCESS_PERM) +/* Pre-content events can be used to fill file content */ +#define FANOTIFY_PRE_CONTENT_EVENTS (FAN_PRE_ACCESS) + +/* Events that require a permission response from user */ +#define FANOTIFY_PERM_EVENTS (FANOTIFY_CONTENT_PERM_EVENTS | \ + FANOTIFY_PRE_CONTENT_EVENTS) + /* Events that can be reported with event->fd */ #define FANOTIFY_FD_EVENTS (FANOTIFY_PATH_EVENTS | FANOTIFY_PERM_EVENTS) @@ -104,10 +114,6 @@ FANOTIFY_INODE_EVENTS | \ FANOTIFY_ERROR_EVENTS) -/* Events that require a permission response from user */ -#define FANOTIFY_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM | \ - FAN_OPEN_EXEC_PERM) - /* Extra flags that may be reported with event or control handling of events */ #define FANOTIFY_EVENT_FLAGS (FAN_EVENT_ON_CHILD | FAN_ONDIR) diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 79072b6894f2..7596168c80eb 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -27,6 +27,8 @@ #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ /* #define FAN_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ +#define FAN_PRE_ACCESS 0x00100000 /* Pre-content access hook */ + #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ #define FAN_RENAME 0x10000000 /* File was renamed */ From patchwork Fri Nov 15 15:30:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876447 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 63B02D68BC8 for ; Fri, 15 Nov 2024 15:31:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 601926B009B; Fri, 15 Nov 2024 10:31:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B11E6B009C; Fri, 15 Nov 2024 10:31:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4049C6B009D; Fri, 15 Nov 2024 10:31:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1CF216B009B for ; Fri, 15 Nov 2024 10:31:43 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C7A921418F0 for ; Fri, 15 Nov 2024 15:31:42 +0000 (UTC) X-FDA: 82788717816.10.4238A4F Received: from mail-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) by imf16.hostedemail.com (Postfix) with ESMTP id B03D5180024 for ; Fri, 15 Nov 2024 15:30:55 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=B8OiZm4g; dmarc=none; spf=none (imf16.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.180) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684636; a=rsa-sha256; cv=none; b=wvgU7nbGEd+o61BHLUtD/gNzs0tGxXZZHrF/d2xRIOyxX8gKdL+pz42WNtht+zLnoV4yys lvh8HNheJABkPZDCDoxDeZ7M2u+g7PfC3zwHbCKJZPhwsa49WlBHqvREfrrify6yHtkSKe gKbhGOthEUEfRaFfG2od+9Jzo8EcwmQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=B8OiZm4g; dmarc=none; spf=none (imf16.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.180) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684636; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=28nbpQbjD2HwWvaUP2yIn55iQ73mbNzvgMCNeqvC6/0=; b=uVrZmUNA9ujnnmN53MkWXPitHza9ivcKJzauHCzRP/V5vneNx+4o9QO63DyCgw/uOdYG2P HGJTF4KkHl7ThQsrv1dr2+fSF8+8PrUJnFPIojKkQM37wJgvq2SyeYGD8cWzDWjbAa3Dkm Mr1jmihfVXpyQq0epkD8zVSBNoIpPMY= Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-6ea07d119b7so16596197b3.0 for ; Fri, 15 Nov 2024 07:31:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684700; x=1732289500; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=28nbpQbjD2HwWvaUP2yIn55iQ73mbNzvgMCNeqvC6/0=; b=B8OiZm4gNFiXzs8IUwsntLL3p+2OLBSgdwuGHhDYfiEHCuTJdA+2iS0DjUGmKYgJ11 ogdnft2c0V83Dg9hBXbwcu+hambhu8VOARBMR7yD0DSwJnGG/mfkSoovdpa0bqT/dgI+ tHcpuOmhyIeEqiBlq4rz78WtVNZ1hVB4+7/Clfv1H4LoKf3GyH+8zVRbSMZu0YgBkje5 ckeTOEqycWGK4/ZVo/kexyXiMK74LK4HdiBs7+mgqUqJeeAx/uVL/lt7+rximuznDFYG 7fe6qCiOpWzy/KuBrymehqpCjI15Gcwgkr8a3VS2I1k9WQqsXUm+K3cRH1i3NRWoCjff 6zkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684700; x=1732289500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=28nbpQbjD2HwWvaUP2yIn55iQ73mbNzvgMCNeqvC6/0=; b=CsyYj/mo4r6yHbZxhpfI56JnOpkVIsmKORmLXDrP0+1yLLOVq6MNmyH3GsUDfTmj0P M+6u0Qx3J4QOqtIikhAIe0pUhoeBtKrkR3EzI51Aq3RHcvmvKr3l4sVOzENSrqLrLoIa aZtBUM1kflk7A13SU6aEPZJwYhst+tsIG4kpSXs3dZJ0cLtXFC9j+yS08iaVYaBh2Dfk zPeI7CRuSGMA0zmtQEe1GaBdvxiatkFMGVDdxBC3MefP2orkNSdYFhZ8zMnXiRXrrtdo F1+tn8GyGEvDFGzV+LOF2kQb3ev2GegcOhBGoeGi2G+0hEpq8j6EmWOGhhBjru8XIKlA mFyQ== X-Forwarded-Encrypted: i=1; AJvYcCWizdsWFsrASVj+ID0iFQuJoJneQ+O3KdrCxKBEenMhfyymQ4OTZ78W32MCprGokYKaOt9et5+/3A==@kvack.org X-Gm-Message-State: AOJu0YzOVXsR2op5wseJae/zsl0qU/8xyddXaeaL3usPPCQkvwSo00di 8EVduA9kU2f0f9UL/JnwHGjymtAzvxwhdcZ2z0jHF73Mga3CrlO0wQT4o0iaBSo= X-Google-Smtp-Source: AGHT+IEjW291jTkKzHI4Ae+C3bnCRuhWYH/1lq2dSUG1bbeWzCUoX3SJFcI3pBBBVFezHIznGLjunA== X-Received: by 2002:a05:690c:67c9:b0:6ee:4bee:d912 with SMTP id 00721157ae682-6ee55c304afmr35158487b3.21.1731684699892; Fri, 15 Nov 2024 07:31:39 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee44413323sm7692477b3.77.2024.11.15.07.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:39 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 11/19] fanotify: report file range info with pre-content events Date: Fri, 15 Nov 2024 10:30:24 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: B03D5180024 X-Rspamd-Server: rspam11 X-Stat-Signature: yoiayi13zopeer1inym8x6o8zhu1ydec X-HE-Tag: 1731684655-897145 X-HE-Meta: U2FsdGVkX1/ydsVgDMVrxL+NmB/8JZhxFLq9dU+k0dQl8Bl2TRgc6Oey6dSbmWe6kT8HgF8iyolIdLNMZvusaX0d3JD32RH/A61UQraQkD+X/VsLJwXLVwK6osnEV8r18/J0mMxj4P4v3fgM4AMgAmVTGJtW/vWsAEO9fY1H69A8cwVmgmFG88oY1EaBblNZA0KfTlEBSDkaPhTxmOAlGojUHwX5UVQowWif9Odt8UBgq+cv0L7RUyVfbketmKo6hUC4O/n+aMzJuq8feCzX4Ip6kOugFU4YLsMGZv27tm1V+NdzAq9+205aOThg1hrxZEPC9N0X0i1I/d7HBq5uFE63LRGgEB4vswIAPOLGjFdhuUjalh7SuneUgn6M0eDpgIxWZsaVaZMEug5gV7nQ49b8Mia8kf/Gj2l/320tKlweMB99eD+9FcnzbrpTYo3hnjipXeFbr6FJCRVmhClk2kjQezdAXHxWdTD2ctVLs85QSfTUoc8ENTQZzPJh6fEmD1yss1qVc0zdszVqECE4/btTcHU08L5JKE7E3FUjlU6FsPH3BmOBN6IaXVcMkcLHuIXDlJncJBbmu2UCE51Sc3SWSiZxhz6oyMRasLUHw04h9gWRjj8fw9gmwz5WX4BEx2FJ3HtcqvmhAY+2lkWlwBdX6y+K+RMh9Yu+o9czPwVMDInr1t0kF66LXkjrDSTLIfVN0IOpp7h34osZVjje1gJcgAiI7kExGiSVZ7lmjLU3ipWMcBCiTwhGeZdHRG5tipBKGe9r+puX/ZLyE9wW9x/bwXh4DAYL6/3xNY49TA7rYTNBbpyr/ZrmU88Dc0XPREVAb65/cD2T6BOsfEioLNCxBudDudscBiNEOwhu+kUnLAqacaOayf2Y6+puB7bo/hR5aNATxW2TcuvHwlL5cl4AX0HdcJCUHxffVoYm3A4Mvyyvl3c6TJQPszmdzzMb6iqt2xv7UcB3f4vXKxi Ey44UQiT XGuz2n/AGGGJevqxAg4TsBpHRr0/0h2b+d1jx9owaHIr+Ingp7UoRnlAM2Zrcit2XJii1Lig1tViApO4VOIYw6JILbXTENutUdGTT1l1pUz6ZCbt07wHE/KL1vbiCIxlZMXqjSGWhCU/xUnMd9Tck4FdK3BiA39zwRlyPfzAPssY/zLfYUQ5AJ0U/s3lQHbcyTYRA6/AkHwJ56b6CTVCPr7thIM8b+27+rC/zW3Y5Iqju6uvO5mKxHjxqd0mgnSfpaXX6mdU25iRe/CW7kgXhZRVSqUJHMh/W97RtkE5EtrDITHufguNgmAfcVCLeFWD7oL9JK5aN0eNUjlNF8tSg2dvEyJVrlPgevTCq2VFuoHRDJ2wXzu8PS+cunsdRxfYASpVgRJ3SxfqG5J2W6jkt9BpBE7EfSlSEbCJWShZYMdTvMc4GLwtQ7hXknj12z3U1x9NeTZhJcn8QquU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000025, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein With group class FAN_CLASS_PRE_CONTENT, report offset and length info along with FAN_PRE_ACCESS pre-content events. This information is meant to be used by hierarchical storage managers that want to fill partial content of files on first access to range. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.h | 8 +++++++ fs/notify/fanotify/fanotify_user.c | 38 ++++++++++++++++++++++++++++++ include/uapi/linux/fanotify.h | 8 +++++++ 3 files changed, 54 insertions(+) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 93598b7d5952..7f06355afa1f 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -448,6 +448,14 @@ static inline bool fanotify_is_perm_event(u32 mask) mask & FANOTIFY_PERM_EVENTS; } +static inline bool fanotify_event_has_access_range(struct fanotify_event *event) +{ + if (!(event->mask & FANOTIFY_PRE_CONTENT_EVENTS)) + return false; + + return FANOTIFY_PERM(event)->ppos; +} + static inline struct fanotify_event *FANOTIFY_E(struct fsnotify_event *fse) { return container_of(fse, struct fanotify_event, fse); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 5ea447e9e5a8..c7938d9e8101 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -121,6 +121,8 @@ struct kmem_cache *fanotify_perm_event_cachep __ro_after_init; sizeof(struct fanotify_event_info_pidfd) #define FANOTIFY_ERROR_INFO_LEN \ (sizeof(struct fanotify_event_info_error)) +#define FANOTIFY_RANGE_INFO_LEN \ + (sizeof(struct fanotify_event_info_range)) static int fanotify_fid_info_len(int fh_len, int name_len) { @@ -180,6 +182,9 @@ static size_t fanotify_event_len(unsigned int info_mode, if (info_mode & FAN_REPORT_PIDFD) event_len += FANOTIFY_PIDFD_INFO_LEN; + if (fanotify_event_has_access_range(event)) + event_len += FANOTIFY_RANGE_INFO_LEN; + return event_len; } @@ -516,6 +521,30 @@ static int copy_pidfd_info_to_user(int pidfd, return info_len; } +static size_t copy_range_info_to_user(struct fanotify_event *event, + char __user *buf, int count) +{ + struct fanotify_perm_event *pevent = FANOTIFY_PERM(event); + struct fanotify_event_info_range info = { }; + size_t info_len = FANOTIFY_RANGE_INFO_LEN; + + if (WARN_ON_ONCE(info_len > count)) + return -EFAULT; + + if (WARN_ON_ONCE(!pevent->ppos)) + return -EINVAL; + + info.hdr.info_type = FAN_EVENT_INFO_TYPE_RANGE; + info.hdr.len = info_len; + info.offset = *(pevent->ppos); + info.count = pevent->count; + + if (copy_to_user(buf, &info, info_len)) + return -EFAULT; + + return info_len; +} + static int copy_info_records_to_user(struct fanotify_event *event, struct fanotify_info *info, unsigned int info_mode, int pidfd, @@ -637,6 +666,15 @@ static int copy_info_records_to_user(struct fanotify_event *event, total_bytes += ret; } + if (fanotify_event_has_access_range(event)) { + ret = copy_range_info_to_user(event, buf, count); + if (ret < 0) + return ret; + buf += ret; + count -= ret; + total_bytes += ret; + } + return total_bytes; } diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 7596168c80eb..0636a9c85dd0 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -146,6 +146,7 @@ struct fanotify_event_metadata { #define FAN_EVENT_INFO_TYPE_DFID 3 #define FAN_EVENT_INFO_TYPE_PIDFD 4 #define FAN_EVENT_INFO_TYPE_ERROR 5 +#define FAN_EVENT_INFO_TYPE_RANGE 6 /* Special info types for FAN_RENAME */ #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10 @@ -192,6 +193,13 @@ struct fanotify_event_info_error { __u32 error_count; }; +struct fanotify_event_info_range { + struct fanotify_event_info_header hdr; + __u32 pad; + __u64 offset; + __u64 count; +}; + /* * User space may need to record additional information about its decision. * The extra information type records what kind of information is included. From patchwork Fri Nov 15 15:30:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876449 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 7A7A5D68BC6 for ; Fri, 15 Nov 2024 15:31:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FD8B6B009E; Fri, 15 Nov 2024 10:31:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AEF06B009F; Fri, 15 Nov 2024 10:31:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 562F46B00A0; Fri, 15 Nov 2024 10:31:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3BB4E6B009E for ; Fri, 15 Nov 2024 10:31:45 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E8A50817FF for ; Fri, 15 Nov 2024 15:31:44 +0000 (UTC) X-FDA: 82788717900.10.3B40DD8 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by imf04.hostedemail.com (Postfix) with ESMTP id 601E64000A for ; Fri, 15 Nov 2024 15:30:45 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=WRJ1ae7w; spf=none (imf04.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684613; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oYVz+XyZ9SoqwtPGIrYcB7tf/DoyF2fJkEf/z8ZauDI=; b=n7TDwe9URxbTd9wr0tKz1zU59ptEOwljn+je0BVAnOK7LOM05FPzA6ItxXOQGfS9O+2Wvn JtprBAZOEYCxX4d1qSRa8fm1ja5jfYTVQXHRou2EHhTh5Hh8OjczEp29d/bRl1Re96LGus ugh1UPVYX/nnHyO/tXwMxVZdPb4h4x4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684613; a=rsa-sha256; cv=none; b=UXM2w5UuCGOOzavKts5MYeYXiMn121YyPpF7co+9ZhR1Fs58PjSzrN2T7s8L5T42QyrknQ cw9uhvB/I+xF6Tf8IS3yLpA/yVhAyKt/l/9jtJyFfoqjmVRSN3LRExqa88v1tka4bBuCS2 hZrHdBLk3Cd4i1GRn2kXaW7aB5cFnuw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=WRJ1ae7w; spf=none (imf04.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e380d1389a1so747038276.2 for ; Fri, 15 Nov 2024 07:31:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684702; x=1732289502; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=oYVz+XyZ9SoqwtPGIrYcB7tf/DoyF2fJkEf/z8ZauDI=; b=WRJ1ae7wjRyZgPZb9p8FveKjJSCOHMVSezi8vp8JLlA4L2Y5aC+77o4HkN0CIOpzZ8 mFcG8jWmr2Sr3INPMKPY91HnUURK6Iwfl0tPUf1WhVVsDqvytnLJy9Yp/sySZEAbAhUe Fqj1MmC/BEsE4loz5Qt8lgOtUV/2hZ1VJtzfygbvRz3McRhGsYFFTK9fNr/b1rKiZ+Kn 8ctuXNaxETOUlMTwKbatyKuI+o39YAxyANlln8oUXkXBlZ69eSac7E+6PnUJqc4mJTaj FMynNSaMcKVWyxx65Wgq7z8pN6TgYKWSht8n2A4200wzZGQBvaHy61ZT/CIUA3zyt7LI 3KkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684702; x=1732289502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oYVz+XyZ9SoqwtPGIrYcB7tf/DoyF2fJkEf/z8ZauDI=; b=SRXCTyp73xIiAwQA6jdbe6Nyn1nd4fuFvawXB6Pwg5CdnsPQP47tu6nGF1A9PfyLqX EI9nyb1/VeS92NAgXYzXMozF43a6eG3b7ShnGKz53DYR3UvQtebiq9MvwDYNF/nZDN9M CfeavfPlGPkaZoD8CnzmG1/4j7cEOEswZpbt7k9sHcOWpkh4dpB2D/LkRYsFbfHjVDee ckMg0qiYUM4Oz5NwoVa9V5D3BinTUTsoOZWKrQ8kSnOJyzr/I7X6Q6/AIRHNPsWxuVfm HjZLHT/s+eVjgKTfrYpGmS2G0IYfw5zVW5e+cXKR0BRIWkI6y3KL97sQX92naVrnJzUC MoyA== X-Forwarded-Encrypted: i=1; AJvYcCUQquANjyZC7Sn8YGRd4rx65m5Tje/mBFZIN1JvCZOKfIg0mzqmD3FD3PfXsM5PccYFd1fr2Z2EmA==@kvack.org X-Gm-Message-State: AOJu0YwV54qC6ykrHSnDLnWEOhBEuuJIgBBXWiS1SVc2aaybNImepPeB /MSPXitSA7o6kGpEfBcmQSW4HqSpzu8tcNHXsxP03CHP2kGOEULMFJiF7U25GcI= X-Google-Smtp-Source: AGHT+IFoxy1YCQFnRgPtGkTRCMBhBl4Fu3YB1s0FmhMUuPf3HGnEc2HjxOuL+DFHWmE6fl1W/EqzGQ== X-Received: by 2002:a05:690c:603:b0:6ee:3c22:cc67 with SMTP id 00721157ae682-6ee558ca435mr38407687b3.0.1731684701510; Fri, 15 Nov 2024 07:31:41 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee440737bcsm7797587b3.61.2024.11.15.07.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:40 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 12/19] fanotify: allow to set errno in FAN_DENY permission response Date: Fri, 15 Nov 2024 10:30:25 -0500 Message-ID: <1e5fb6af84b69ca96b5c849fa5f10bdf4d1dc414.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: x5p5tynw7exg7bcoact6pfib31k67w6w X-Rspamd-Queue-Id: 601E64000A X-Rspam-User: X-HE-Tag: 1731684645-729360 X-HE-Meta: U2FsdGVkX1+si5vOBSXyqiBazenNOxhigQKRuYFyqiC132+NQGhzu4ySXZiBkm879vQugXvEA2ADNOrF5atdJy7hE5/OyPwxd0zjHgDlAeo8snvfIGe2WntV3mVDFJMthuVpLKxGGA6pS+yVvFwOtzI54zJdn+WDZ1rpmVASJOpwWtgh8FkCK3wd5qd4aJPHLvnK0DhLM4sZxodyctQkfK2KrEraeixpx0UfXYitfPZJZk1FEdWMSqrRXXG17pEvtBE0rFzwLXUI7TZfF78XIgcqIym/Y42XhGc/ab1StT2odtHpDqWye1EgIxsf2Y6PGgNu1R56XrAR8u7Fez+sBK2A/nhGZEkqSKAi0AYnrpea+0hS56l8qvWAMNnQzhnLQed3N87ihWueTuW+zHAN1UI6W3lpY2N1EJdUPxeK8BcPKv44GyaGM34UwMomfZG+AGOOv9iIuNlyHWj/JceAbEjc3XLmbihS1dA3v4uqob7YsUlmQ29FHFYTGrPZKeyxGb2oVTR4eazLxzJn0C4rIusKMaelfYqwp412JI2BB4Orb+URHbs02kmfSTu+e94HRsegJlm4diTUz5aBO7XkjUotuDUrBEu4f+4tAjV1b1a8b/GEm9XpcGFg1h/RKV7D7uCSDnukEEMZGdhCIrLW/L7tqEOMFKB2YWAq/fYtPCnpoKTAgHcjI19+OKb1pCZ5A2ekG1RzexVWfIMkkdMOgAidjzgm1CnL18lRbasI/LxJH4njiLNpCZo47Mu5Rj0OuCSkp1DEBrCCAPvf3O8y9nF5+XXZwZK69eyiLwKjIfUMmY+IpJJOXcLcyhAaK6y/9MdNv2AVvL6H7O77V+IuTBEtYsqXNQKgTKsAWFc/kMRvewgdiGX1piNyvkgB0FCOwfiNpDzIqvacNAY69Iiovgvu3ro4VxrnNQi9/SjdJrxmXUNu9Hb+BegbntHGTLdOdQH2GNxPQQmsiE1fq3s FIvGZ2Qx ReQwUCrvlMMknld21dBwemUW6IJ24lPcKb5TxOGVEYbId/NqWR12JqqgpJ+nFx4pwwhMbIr4Ssxy0TeV0yUGXBe6+hOdkrRhj1gAqc+xzX/SM4nNvWpUSRTbtLefcY34lQ78LkupdNPVnch319Xvq87cUNrEZ34yBnfL01KM5JD4qMUiGp77757R0vrc/EiNYXU8BPhHY+YW2hAsPD6NHrnJyDa8L1vsLhTjMluLkkyPlEMS1OUtXBssgWmxlmZ4IKeUXt6KnMKHk/XZmqDp970M0GYM6J4XR6bFswebLEOSYV65fN833B1VnfcuT91e58LRd6DSMYxq/2TgYyxfPtBtsE/nuEwsQHi+jb8xqy9+wXG4KoGbD9lR0a2v9u/bo/rjVO8cR+Dv0NIBVJrI/0GL8Mg5oslG8i9V76ir6xT8Gd3m01fM4rU8LYrB9/XCL24gjhL0iMAZGJsPW5ff89w6rXUQwlwRxwI5nbevpEd8CN5oZn0VScWK/zQ== 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: From: Amir Goldstein With FAN_DENY response, user trying to perform the filesystem operation gets an error with errno set to EPERM. It is useful for hierarchical storage management (HSM) service to be able to deny access for reasons more diverse than EPERM, for example EAGAIN, if HSM could retry the operation later. Allow fanotify groups with priority FAN_CLASSS_PRE_CONTENT to responsd to permission events with the response value FAN_DENY_ERRNO(errno), instead of FAN_DENY to return a custom error. Limit custom error values to errors expected on read(2)/write(2) and open(2) of regular files. This list could be extended in the future. Userspace can test for legitimate values of FAN_DENY_ERRNO(errno) by writing a response to an fanotify group fd with a value of FAN_NOFD in the fd field of the response. The change in fanotify_response is backward compatible, because errno is written in the high 8 bits of the 32bit response field and old kernels reject respose value with high bits set. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 19 +++++++++++---- fs/notify/fanotify/fanotify.h | 5 ++++ fs/notify/fanotify/fanotify_user.c | 37 ++++++++++++++++++++++++++---- include/linux/fanotify.h | 5 +++- include/uapi/linux/fanotify.h | 7 ++++++ 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index da6c3c1c7edf..e3d04d77caba 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -223,7 +223,8 @@ static int fanotify_get_response(struct fsnotify_group *group, struct fanotify_perm_event *event, struct fsnotify_iter_info *iter_info) { - int ret; + int ret, errno; + u32 decision; pr_debug("%s: group=%p event=%p\n", __func__, group, event); @@ -256,20 +257,28 @@ static int fanotify_get_response(struct fsnotify_group *group, goto out; } + decision = event->response & + (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS); /* userspace responded, convert to something usable */ - switch (event->response & FANOTIFY_RESPONSE_ACCESS) { + switch (decision & FANOTIFY_RESPONSE_ACCESS) { case FAN_ALLOW: ret = 0; break; case FAN_DENY: + /* Check custom errno from pre-content events */ + errno = fanotify_get_response_errno(event->response); + if (errno) { + ret = -errno; + break; + } + fallthrough; default: ret = -EPERM; } /* Check if the response should be audited */ - if (event->response & FAN_AUDIT) - audit_fanotify(event->response & ~FAN_AUDIT, - &event->audit_rule); + if (decision & FAN_AUDIT) + audit_fanotify(decision & ~FAN_AUDIT, &event->audit_rule); pr_debug("%s: group=%p event=%p about to return ret=%d\n", __func__, group, event, ret); diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 7f06355afa1f..9e93aba210c9 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -528,3 +528,8 @@ static inline unsigned int fanotify_mark_user_flags(struct fsnotify_mark *mark) return mflags; } + +static inline u32 fanotify_get_response_errno(int res) +{ + return res >> FAN_ERRNO_SHIFT; +} diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index c7938d9e8101..28aac467c7e2 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -327,11 +327,14 @@ static int process_access_response(struct fsnotify_group *group, struct fanotify_perm_event *event; int fd = response_struct->fd; u32 response = response_struct->response; + u32 decision = response & + (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS); + int errno = fanotify_get_response_errno(response); int ret = info_len; struct fanotify_response_info_audit_rule friar; - pr_debug("%s: group=%p fd=%d response=%u buf=%p size=%zu\n", __func__, - group, fd, response, info, info_len); + pr_debug("%s: group=%p fd=%d response=%x errno=%d buf=%p size=%zu\n", + __func__, group, fd, response, errno, info, info_len); /* * make sure the response is valid, if invalid we do nothing and either * userspace can send a valid response or we will clean it up after the @@ -340,18 +343,42 @@ static int process_access_response(struct fsnotify_group *group, if (response & ~FANOTIFY_RESPONSE_VALID_MASK) return -EINVAL; - switch (response & FANOTIFY_RESPONSE_ACCESS) { + switch (decision & FANOTIFY_RESPONSE_ACCESS) { case FAN_ALLOW: + if (errno) + return -EINVAL; + break; case FAN_DENY: + /* Custom errno is supported only for pre-content groups */ + if (errno && group->priority != FSNOTIFY_PRIO_PRE_CONTENT) + return -EINVAL; + + /* + * Limit errno to values expected on open(2)/read(2)/write(2) + * of regular files. + */ + switch (errno) { + case 0: + case EIO: + case EPERM: + case EBUSY: + case ETXTBSY: + case EAGAIN: + case ENOSPC: + case EDQUOT: + break; + default: + return -EINVAL; + } break; default: return -EINVAL; } - if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) + if ((decision & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) return -EINVAL; - if (response & FAN_INFO) { + if (decision & FAN_INFO) { ret = process_access_response_info(info, info_len, &friar); if (ret < 0) return ret; diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index c747af064d2c..d9bb48976b53 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -132,7 +132,10 @@ /* These masks check for invalid bits in permission responses. */ #define FANOTIFY_RESPONSE_ACCESS (FAN_ALLOW | FAN_DENY) #define FANOTIFY_RESPONSE_FLAGS (FAN_AUDIT | FAN_INFO) -#define FANOTIFY_RESPONSE_VALID_MASK (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS) +#define FANOTIFY_RESPONSE_ERRNO (FAN_ERRNO_MASK << FAN_ERRNO_SHIFT) +#define FANOTIFY_RESPONSE_VALID_MASK \ + (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS | \ + FANOTIFY_RESPONSE_ERRNO) /* Do not use these old uapi constants internally */ #undef FAN_ALL_CLASS_BITS diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 0636a9c85dd0..bd8167979707 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -235,6 +235,13 @@ struct fanotify_response_info_audit_rule { /* Legit userspace responses to a _PERM event */ #define FAN_ALLOW 0x01 #define FAN_DENY 0x02 +/* errno other than EPERM can specified in upper byte of deny response */ +#define FAN_ERRNO_BITS 8 +#define FAN_ERRNO_SHIFT (32 - FAN_ERRNO_BITS) +#define FAN_ERRNO_MASK ((1 << FAN_ERRNO_BITS) - 1) +#define FAN_DENY_ERRNO(err) \ + (FAN_DENY | ((((__u32)(err)) & FAN_ERRNO_MASK) << FAN_ERRNO_SHIFT)) + #define FAN_AUDIT 0x10 /* Bitmask to create audit record for result */ #define FAN_INFO 0x20 /* Bitmask to indicate additional information */ From patchwork Fri Nov 15 15:30:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876450 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 B25D7D68BC8 for ; Fri, 15 Nov 2024 15:32:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FA5F6B00A0; Fri, 15 Nov 2024 10:31:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 984396B00A1; Fri, 15 Nov 2024 10:31:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 823476B00A2; Fri, 15 Nov 2024 10:31:46 -0500 (EST) 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 5FDC06B00A0 for ; Fri, 15 Nov 2024 10:31:46 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C8B03818A4 for ; Fri, 15 Nov 2024 15:31:45 +0000 (UTC) X-FDA: 82788718278.15.4CF383E Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) by imf02.hostedemail.com (Postfix) with ESMTP id EE4AF80021 for ; Fri, 15 Nov 2024 15:30:17 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=fzGm8ckm; dmarc=none; spf=none (imf02.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.177) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684639; a=rsa-sha256; cv=none; b=lr34OW8pSQ6dFi1eyiHozI8XWfXEEmycdzPvVwtyKmobjUDVb1i7yzhg79w7zIafmwCclZ ci1uGk4fQQAN44PGPVlSJjPfPp5a0cKbUuBoevPn1mc7x/y9YFYJXm9a36AOsvQXrA6Gws sCmF9rWSsradHKBlEAa/ArC0ZaL0Fi4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=fzGm8ckm; dmarc=none; spf=none (imf02.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.177) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684639; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rLlpuiMn0030yB3+s74DQOOZuZXxBi++zrJRvWIMp3o=; b=VkLvjI74uSRfeWXG95QjCoaX3XPKqWbvtvNTgj6hTplYVGOjdfc4WxbgiWPnFSVe5Fwl9W UXoz59wBZfwXw+cCGpwONM5ZHliCFVDIoq9s2BWPjA26XRttGGe2680rD4j4lAGUTzwPXa HkR3MEyeuihxud4PItaVR8P1RIutAvg= Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-6e9f8dec3daso15669767b3.0 for ; Fri, 15 Nov 2024 07:31:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684703; x=1732289503; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=rLlpuiMn0030yB3+s74DQOOZuZXxBi++zrJRvWIMp3o=; b=fzGm8ckmrKIGP1b6xitsOWrDPjXrGxOwwnljrFtKBUVWP2c6nio9zD03nVe8xe/7ji /JEeqnOwkx45KMorQrIZSbrUtDkYfSJjHm9drA+/OSaJEyXEYwkjRHYkulAjKrRM249d zrblxw5y3G2nRWa9WqKClUbP5eoEsAwhAZNxgegN5aX4QuHALsLKG8dkelClw3/0gtGl x93dlZGZTarKNEVN7iVz/+zvAeTM34OZDCNkpSIcG4KBRbtnxGE96AkhKnOMtcjDjWWg yLm338uVIDDhwi9uC7rvP/1xt5aqADAYgZsTtkrXXpz7bmcCnIIgg+lYwh3Et5UW2zzY wLFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684703; x=1732289503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rLlpuiMn0030yB3+s74DQOOZuZXxBi++zrJRvWIMp3o=; b=ZFy/EgFPPPVWm/ig346nZtvqX7yyyxF6HVxrkbnZUYHIdf85tt+bm2am4YXu6kJh1x T1171SI1IDd0vvjJu1aidaTAFgpXYpp3Nlpv4DSOOS3AW4JmhNkoK5bMfxkePWMmI20Q qvXE7z7gzNrGN/SK0PsXNmnqLX5yj6keQbcXq9Sz6xRT/rFKWRC3ZjY5GDK2ztU8huxk 6X3e3QgwRsfIf7qtIHgUMdmGo5ElPkoXKMnknLpEBZgDgmHjKt2Wr1CIPsY4A7rjpzwQ wxiDXJLxRbRtfSDhTLapvVGFRKSfmqRYDO6T4jYHTbcQQ2JSYV9OviQViotBbdh+cKkx W0ZA== X-Forwarded-Encrypted: i=1; AJvYcCXxNKGBhvqShaFgC7l5LCwYQFI/GiGPMRNTacOhw5yj+PrdSUMnT9qo0Yw7uqZRZ3knV6CNrp/9fw==@kvack.org X-Gm-Message-State: AOJu0YzNpCXjKfSns/3hUttsDAskLUm+uGgEQoSIzE29sRSimZ0n5Lqu PTegxG6XM5bbDm1hSmMijwPO6Dm447hpA4gR9ucw2u6GTFGrJvGiI43NcvNjxOw= X-Google-Smtp-Source: AGHT+IHLmXNsFgoxeQH2zoAuWGXM6iZ0/bFoZDUBvajKhRUeKgJ2+BFXj02LrLEKz+I9Qy3GGhxCnw== X-Received: by 2002:a05:690c:6806:b0:6dc:7877:1ea3 with SMTP id 00721157ae682-6ee55a6c9ebmr38646357b3.17.1731684703143; Fri, 15 Nov 2024 07:31:43 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee4400c7dasm7862627b3.24.2024.11.15.07.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:42 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 13/19] fanotify: add a helper to check for pre content events Date: Fri, 15 Nov 2024 10:30:26 -0500 Message-ID: <657f50e37d6d8f908c13f652129bcdd34ed7f4a9.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: EE4AF80021 X-Rspamd-Server: rspam01 X-Stat-Signature: do14kwpa7g5kkj7qnfb3upig5js6ztq5 X-HE-Tag: 1731684617-474806 X-HE-Meta: U2FsdGVkX18kKWA2mB8/GkW1U51aRCDAYDPQhFTCoZs6+p0n8YvcgfBmIHIVA0xZ18IMs3DTvVlmW8ztcpVAVrzDAxtSrk/1Ip/9yUL/NYE4ud+wKBAyHH8v1fmgDl3NU6ZVI4AkTQtbr/MM8ySZJqWjzViwpAF8Y/Mcnluo8+T/yrzw6YJkrTsW2lFtLTqWX6yZbrHCprlEl59oqp7d1K/9BRjqV4e1sNUs1SzX84Rakd/JXUaAu5dZQOUnKND2QIeeKmUZ94Cg9nrz+TdOkU+K04yGqVsjCCGP34Gujk6KRv4xFwLDGLwK9Q8MjQIa7zeEpBpTwvMIde2kHtTBUZiKs8rOGBOCHURfpcCq6OmO7lWABhMkN2wCrproMO1od/yjFAOPrNoRTzIN6f8v1GMik9fzx3Q4FtweCjtzIWZxeh5qoPlr2jfAOEuma9ipliBqyUphvk4DhWhGOwO/xe5kCA3DPUCHcB6f8aEpA1w3COtNstvVTeJICMxs2DodtXQ3TVRWQyZnl64MftSUF2Rq26ZFV5OoO0sc4KNVhnttR5v2H6sU2EZSnyzLS+MsSDoucHIlc2LwCgaRAONLaagFZ/r0+DUB3T12x1GhE6KzTn3+XGZSElgFVqDMyg9glP4z65dHNMxa/SPDRYnVU6Rn8ZCxf/mRHhA1S9hN5/SiNrKbP8PeC4DeE+eeUvPRDa0NvuatFtieZRCR8GKXLOlLtb/WkjFmC+AhndajCFE6GGc5lEBH4xJNEvzgemYfsn4ui5KGg+MzC79wChn7OK4GItSWZAKr5bMHcFOsCFsFi28Z7FWve1H23a0E7p1YDIOuTXMC8QeRKp6DcFPlGZ0AWLObIvmrLM1fyumMmk9G4pyduGHLo38GiaSMy3fMobaevr4sXTW+gLaEDfAnH1xg5+U5L/b/a/Me/+H4qOcmlOldBJYOOO3KozP/wTtCaMCuGHHodILDz7UjVbN 7pBI/po5 nRU4ljiIkV5xcwLtwDdcO06LWH92LqUdfwi8NrM/7nC6ZtIsN1prJyEwmkV0MeKTZrUy7KYe4L2/vWqOZkU6puO6KGdM1TNBf0BFPJPFQ/AxCwsKm5i7e3ZKBsiDYPsRSdvj4mQX+YLwjDZqpZLUmpoITWl8Ld2YntPTxpMnI/1InTiKmo/IrpY3Zh1FXcOLuWKvFimnagqlI7muDV9YzHoijSi6Px+J90j36XUg207374Nz011ohQy0jgVUKQ3puEWLlRKEFe+nC0uxmP4Hm8LP78Cj8RlYfGkgnOUnJxj+uWtbi7yA2dWc2xmF+/P93dbjjhvh1IX1dFOEqKQ+kcBETIZcwS+2d8N6jtZzXaMGZtMwY/Wj3eJLFT321vI/wC4jdp/e1YMRoGIs= 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: From: Amir Goldstein We want to emit events during page fault, and calling into fanotify could be expensive, so add a helper to allow us to skip calling into fanotify from page fault. This will also be used to disable readahead for content watched files which will be handled in a subsequent patch. Signed-off-by: Josef Bacik Signed-off-by: Amir Goldstein --- include/linux/fsnotify.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 08893429a818..d5a0d8648000 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -178,6 +178,11 @@ static inline void file_set_fsnotify_mode(struct file *file) } } +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return file && unlikely(FMODE_FSNOTIFY_HSM(file->f_mode)); +} + /* * fsnotify_file_area_perm - permission hook before access to file range */ @@ -264,6 +269,11 @@ static inline void file_set_fsnotify_mode(struct file *file) { } +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return false; +} + static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, const loff_t *ppos, size_t count) { From patchwork Fri Nov 15 15:30:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876456 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 C53ADD68BC8 for ; Fri, 15 Nov 2024 15:32:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E8696B00AB; Fri, 15 Nov 2024 10:32:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 897E06B00AC; Fri, 15 Nov 2024 10:32:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 711136B00AD; Fri, 15 Nov 2024 10:32:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 52D356B00AB for ; Fri, 15 Nov 2024 10:32:05 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 03DF214184F for ; Fri, 15 Nov 2024 15:32:05 +0000 (UTC) X-FDA: 82788719244.18.9E2E95C Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf20.hostedemail.com (Postfix) with ESMTP id 6083E1C000C for ; Fri, 15 Nov 2024 15:31:06 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=e+gf3xkG; dmarc=none; spf=none (imf20.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.215.176) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684659; a=rsa-sha256; cv=none; b=z0u68BW+fAQa274IB81JVYGBD9n0HrvwdtRWRrX/iKNrFk1GaqoKG74IHSCQVHJpV2Wffw irmPjqlpxnc/lV/WEQip1W7YOcBecIGuXxIx3x7lHTVcMNTGjyNcgeigSfTgz3vTe6qEc2 1IwJTQ12vKDzdMyArfgvfAgHGEZxl6E= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=e+gf3xkG; dmarc=none; spf=none (imf20.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.215.176) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684659; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GWXqETStm7Md/ZZi4QCCd1GSXP4JC1lp6P3n7C6qnQo=; b=g1vFOWPX/vO4pl34bIbIHnJy2dEDTyF8v6NJlacDaRxmm5CQFPr3Y3Hp+dxYhPcUqbuvPw rnq8DazyS4kTdxJvmtrYgfDgHvStrVUw0N+SrXSybJeEuNFEYVNYNcmsbGT2jp/c0pOEvY gqLhXCpFxWJN1KXd0lRMMB1zI0XCBsU= Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7ee11ff7210so1371165a12.1 for ; Fri, 15 Nov 2024 07:32:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684722; x=1732289522; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=GWXqETStm7Md/ZZi4QCCd1GSXP4JC1lp6P3n7C6qnQo=; b=e+gf3xkGy8f8TgOZf++wrKb+/6WdTOzR4gOTWCZoDnA0Qxwj5x7X3qIpxQnEI5iOAJ DHGA3unGG40C2fIeqp6llMESw1XLphRZ/11IGvMt/I3RFjjD4wCGd0U2H7ueGTI+A04p MgrDTZCpiSWpupwVgiKDfkMlN0+GNRmKrfn60Kfs+ucKFy2xFhwb1wADEioNK1CPQwwm NFj+Q5ifvo+tj4AXsRd4c3+DZ1UtnY539rX3DUb4rLnCYE06zEE/3+Y4mLBDYFMf6VC/ LI7RS7vqL5f86CM8NhFPZNqap2j7ahxHXv4zTeqAX3265QYiO0jMoiBnAByoJUDliook 8FlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684722; x=1732289522; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GWXqETStm7Md/ZZi4QCCd1GSXP4JC1lp6P3n7C6qnQo=; b=sjKrob9eUTVuOFPT7aVjK5CmG6h0WTTZyHPZwqfLwu2sfILNxGiqh2uKalkY+8FhPL xtCOOYco88EjRNJAZ6m4qu9hZUM6ZYDYfeyQzwAMYM9OsmR2/IbXiq4zwOZsAqc1cbkK giyPiBRZRQhZN/yPApM+IFBN7EHr+AHUyQmTnX4WkkX5eMAmk4Xul2uwuGypGvEb4hRW kifI20we3GqZkMIMCswcZNpkNXX6OsAqFCy1xPdpVqoA0dhRki4/YHY6He0diT/IYKQi R8ogMNMZAE0E0MXULYwRfujI6sBYUsaj9zn74LMjk6wEkahyoLZ+ym2DFq9mXfGDl8xj FciA== X-Forwarded-Encrypted: i=1; AJvYcCU29W6eu4e7ZdrqMvj2EtmWXpbD5humPDELR/bf0LFRho9YbKAUJHgoEPMvhfiEIe43J8QPPuJSrw==@kvack.org X-Gm-Message-State: AOJu0Yzm+Dqp3L5nS/Qs0iorhzvT+qEFLmkldwOTgN6gjAjNtDZJxPPZ oDJPGK/LZK/L/wZ8e/8tn/3Rxxi+9hde4eUhNLxhX1YWP4oloU4ckkmWmZN1Un40tyl8o+ykC3J 0 X-Google-Smtp-Source: AGHT+IEHUujjEReLNYNPy+KE0ogVxqRd47YtuHwtc3zNs/tYtNRt3+/0IcuvnNweNADhk1HvQaDdYw== X-Received: by 2002:a05:6902:20c7:b0:e29:1627:d4d3 with SMTP id 3f1490d57ef6-e38263c0d7amr3021251276.41.1731684704575; Fri, 15 Nov 2024 07:31:44 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e381545ae18sm987344276.46.2024.11.15.07.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:44 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 14/19] fanotify: disable readahead if we have pre-content watches Date: Fri, 15 Nov 2024 10:30:27 -0500 Message-ID: <70a54e859f555e54bc7a47b32fe5aca92b085615.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 6083E1C000C X-Rspamd-Server: rspam01 X-Stat-Signature: kq3qdcwbbsrirwzqsttssapsnqybx76s X-HE-Tag: 1731684666-439581 X-HE-Meta: U2FsdGVkX19ATRhIb538HvVXg7tJQO4wd2DWZHgoWLeGTn53I6Hl+5PawW5vYXYBD79ayGjZNeepMROd6jK+EgW30nt3uohJzoHXSwcISiQfWEQ/qdHXPP+FBmpHUJTPuESsGB+pBqQQ3GiSLyk66E09pKpaWFlSNKHSPgUaKwS/0pl3hX+waiVHuGXuI/LrByex7Q6Mz81vOgvsQJKq67FDwEoVbdnsI3Qvga7Guh4jLZePYDFmujgYhBKV2esFSXuZaMogp11pIeavAHkZI6yOVyUg4huPKitBIJ7HR9DpSe0Uwih07tJ5sd3pnQJM1FwkTgywkRwCqQPDdRy+gBw7QOBghULwJFc1vDEL/StKbAiwvq/wL66nuo3r7R/PeCoyBl1aLPhhbu2pt/NTaIs4jSKNenkYl5n/WlHIfteDjQoGHdyEzFN7FCoegCijejj/NFR1S4TbtFGWN7UQIBm6s4ivFvmsaczJIOi0IYETHEZB0pYyquzesWMpdCQ5uEpuUjhdvTMVJrc9mWQMnXYAijmsFXx0B3PQNOGdIyD1DUNAV9NCdb5GIkgqNmwLw3rEYW3xA7lCRQ2Q2UFaVOrSMTH594SZG27ZE/gLb7bLHIc5vxhkrDkSfxJJdMmGwA9YbKlhj+ELtbitsuBK8oTe8NmZsCuCwChVl/Y/MrZ1KqYMwLXGyQ/B4tfcoLJjg/AMN/t/7F7IrBGOMDiAVZTOcqF4OnPSey1U7WhFZKxoYKo1dACATJMhXLTf/v92UXKDhYKWgXxi7m2y7gZncLPHpUEBkhituhiTda0f5k9oIF3nEUIGNi79TQxulzj8rNHFdeCqvmURB+7ikI/6PwXIUN+tmghmE08sFO7qCkqy9rE7GWEcpqeX3qGVPRPhxjjrkDi6MMhr6/en4oUjN0P2QRMh0O+4GCRJrRyuyx5b0SM/ggUiwtlh5AV5EipK6okhXkzxzYaSgCwLALP URrxzQIU j0ClQsys4P6OVNkt9pQq6PaC11OlDIpHnu5oYSHsT+LCOrD3Jo5JizUESAloif6IhSMZVDd+U8AO5wRDBc8ckil4uJQvuKfYpHeWl1jRVSMm+8SkCsH3qnp6tqivDgy+B1yyV97ini6tPBEHqWK7/63s+bFZo1JVoKXgIjoCo1xBL9YM0zfaH7963Z4Qiu33a6rPoc6hqePv12HrZv0veir4jo8gO0LC3WgFIPN0pvRl1Sy0l7/OAxZ8xFORzQ+fi6uFMHNR9XH3X3PRiSc9tpVkGclDZjk2CVox5Col2Pwe1ZkulH2/8E1T8S9EyzuuuorPnJAJhhlOOJ/4vBVkPfstydsPQdBizooVVZ493VGY9j24RDsiIeu+3YVwGy9cFYZrRthna97dEf9o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000186, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With page faults we can trigger readahead on the file, and then subsequent faults can find these pages and insert them into the file without emitting an fanotify event. To avoid this case, disable readahead if we have pre-content watches on the file. This way we are guaranteed to get an event for every range we attempt to access on a pre-content watched file. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- mm/filemap.c | 12 ++++++++++++ mm/readahead.c | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index 196779e8e396..68ea596f6905 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3151,6 +3151,14 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) unsigned long vm_flags = vmf->vma->vm_flags; unsigned int mmap_miss; + /* + * If we have pre-content watches we need to disable readahead to make + * sure that we don't populate our mapping with 0 filled pages that we + * never emitted an event for. + */ + if (fsnotify_file_has_pre_content_watches(file)) + return fpin; + #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* Use the readahead code, even if readahead is disabled */ if ((vm_flags & VM_HUGEPAGE) && HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER) { @@ -3219,6 +3227,10 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf, struct file *fpin = NULL; unsigned int mmap_miss; + /* See comment in do_sync_mmap_readahead. */ + if (fsnotify_file_has_pre_content_watches(file)) + return fpin; + /* If we don't want any read-ahead, don't bother */ if (vmf->vma->vm_flags & VM_RAND_READ || !ra->ra_pages) return fpin; diff --git a/mm/readahead.c b/mm/readahead.c index 9a807727d809..b42792c20605 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -128,6 +128,7 @@ #include #include #include +#include #include "internal.h" @@ -544,6 +545,14 @@ void page_cache_sync_ra(struct readahead_control *ractl, unsigned long max_pages, contig_count; pgoff_t prev_index, miss; + /* + * If we have pre-content watches we need to disable readahead to make + * sure that we don't find 0 filled pages in cache that we never emitted + * events for. + */ + if (fsnotify_file_has_pre_content_watches(ractl->file)) + return; + /* * Even if readahead is disabled, issue this request as readahead * as we'll need it to satisfy the requested range. The forced @@ -622,6 +631,10 @@ void page_cache_async_ra(struct readahead_control *ractl, if (!ra->ra_pages) return; + /* See the comment in page_cache_sync_ra. */ + if (fsnotify_file_has_pre_content_watches(ractl->file)) + return; + /* * Same bit is used for PG_readahead and PG_reclaim. */ From patchwork Fri Nov 15 15:30:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876452 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 209A9D68BC8 for ; Fri, 15 Nov 2024 15:32:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47C0B6B00A4; Fri, 15 Nov 2024 10:31:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42B9E6B00A5; Fri, 15 Nov 2024 10:31:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27DA36B00A6; Fri, 15 Nov 2024 10:31:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 05BF06B00A4 for ; Fri, 15 Nov 2024 10:31:55 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B61A31C71CE for ; Fri, 15 Nov 2024 15:31:55 +0000 (UTC) X-FDA: 82788718068.25.39EFFDD Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) by imf28.hostedemail.com (Postfix) with ESMTP id 869BDC0012 for ; Fri, 15 Nov 2024 15:31:07 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=lujG8jlj; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.161.51) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684537; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UmMh2R9TaZZeTO+3Pa04+NECyzvSza2nfFK0oCoLtcs=; b=metnpF0Lp00S+7lRnKKdoumP6WHc4j0B66DA6By05YF7EhZ/aDY09f5f06BMG7LFYGB/zw 9S45V0FeNVMZ4Ry3LL8IibgD/HaQ+DGrcYw5zuMHS1gdk6ni9CXA6r+UUUeNJaD6Kxdv2j fIOdTz16Sm5TTmSC4lCBEgtEYEO1qOw= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=lujG8jlj; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.161.51) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684537; a=rsa-sha256; cv=none; b=cbt1Y8ZjsNP3GAXyfr/FD1DKWBe4KhvROEKL90+Mh81I/ZaAkVi042F1JF5fpONqmlGZjR Lsj4QpVl+8AS6E1BXb7GoX01Y7iTd4p9f3Ly/6lZKMb6MWumDEr4D5+MCP1Va4BJQc010F PojPJZ8Y8iOgJmLCtfRxiQgQMzoRxDQ= Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5ebc0dbc65dso871576eaf.1 for ; Fri, 15 Nov 2024 07:31:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684713; x=1732289513; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UmMh2R9TaZZeTO+3Pa04+NECyzvSza2nfFK0oCoLtcs=; b=lujG8jljBGz+M5Hk77P4oe/nxrZwhmloMdatI2EUwfzFT8AunjA4aiiPdYHCsqq2fM GmP07p1dbk0cD7wxkp1GL1PH9i02yNo9PtAz8Bq0/a+FKnQMdLjEtrcgsOPU8a8QdwFH b8PXjDB9lh9RU2L9yRg+83XudDL1/OlIHOBNx5PL8f+sHBlmXuIXEhAFW9W6hOqskfzM k1sxdWeD8HmB2U7PeXEmUznvaY1t9Qblih82Xh04yPbfMmQhS3VFAu9mwzbt27c6yliq C0/xvepI8nmCQyzfzOBLI+ILhblBCfPVu/h+m3gTi/nbnztbmrPD9nnWB9FW+3asGPGB gcEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684713; x=1732289513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UmMh2R9TaZZeTO+3Pa04+NECyzvSza2nfFK0oCoLtcs=; b=TjokCUPvLZm/IJc8oGr8hs0LTDo9XFbgFrDfQhpAx96hRrgeajBNAbXEFN878Ofpry /HZVbUFAx8u2fZpAawWNHE/zA1aAvBXdRkdBwv9yijuhZgGKP1BkEgCBkNSAVv/KzEdq wWt3bsNmJtCl3km5WxYb5fYxysKDRZrQkDtXveLG3DP58uNTmy34X2JcdFxjUA5OVM1L SyyWZmwIzWhd+ZIhLoYY5RNXVaNt6saAS5I2bC0nO5kTaM5GiRnm5/glYNJpySbU2A3U RKog/Bu3VceeCPVGFe52w6xjA1b9ZsfDjxTruPc7WgFWZ2jHQw+9PE4mxjH8FfkQWB4f Mdjg== X-Forwarded-Encrypted: i=1; AJvYcCV6jOXn8SjeuWSMOBxnRww3gTh5k6VGPuiih9G4OGvc6NNSUzvFuDDCil6+F/ffFyqKOp9Dct1l+Q==@kvack.org X-Gm-Message-State: AOJu0YzIbKOPWxYvhPR2uEzc4fyHcUBh2nlDVqzi/V/XnGzIU/4iHtm7 +arogWw2o5u8h18b4WATtCYVeJj92FYf4gzbJz7ZU+R35KCmRxTJzkCG964UM0ctuQOZl4I/bXb U X-Google-Smtp-Source: AGHT+IHtKZ3WiG2a6Yh90R7O7Da3Go40IEKMQxser6w6wpGF8sO84iqOBIyuVxo5A9VSaCx3/txhnw== X-Received: by 2002:a05:6830:d8c:b0:718:9df:997f with SMTP id 46e09a7af769-71a779b2c25mr3850260a34.14.1731684712917; Fri, 15 Nov 2024 07:31:52 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee4400c6e6sm7807317b3.9.2024.11.15.07.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:52 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 15/19] mm: don't allow huge faults for files with pre content watches Date: Fri, 15 Nov 2024 10:30:28 -0500 Message-ID: <9035b82cff08a3801cef3d06bbf2778b2e5a4dba.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 869BDC0012 X-Stat-Signature: ypyzxg3ncjynh55h3fstp4xjjp1pfwah X-Rspam-User: X-HE-Tag: 1731684667-551340 X-HE-Meta: U2FsdGVkX1+25pxvURho950qhl6AWTvf/fapbzthJZrUSNUiEoePSc4VWRdavK9Nc+yRn5bKuvF09e7t1B6zV6nKe+uzEb6tMkogjwGaFPvsmEVJyheii4OVWXDO9E7tY/83CwxnpyWImKDVdGaTxXr/ws+QyivDZovXq1J1OGnoN38hO26FrsryXbUxywl+9WrLgptdV9s5eZ4eynLGf8kjDSllh0eFc9qlWY1xgSm+GUMF/ZwNm4vMyas8e8quJu1XBgwTzVAc9XQv3AX1cRV/IRg2SK2QTPDqNW77TuK6cMy2Lfbmp2ITTCQ96ysUpIymlt4tjRpbWGtlWnpTrXRdIwEfNy3hXF8E0g+27jKtP3SbKCHbR/vcWJm35EVW1VA4l5A2+8AJRkQ/HRcl+nK2tPuofxrO7xBtUOyNTUqh4634U7do7bVK5x6a4ln9vE1hG3LerNdBJeHRDWQOQDBjWDwIJdk2oAurwzraklWjLHgbz+W9KgPn/YD/zqegMJEQ4dbtJV5+aRq0baNBvwbgay199vWoGuKkr95Bkh3GJViBNFwnGIX2cPfi4WDLb8yYRNkt7OslKWZV/0puStIHZ4jG/S7GQx0XSTECTXZUfGOvpyGdKoZ60nzD3NgnZC2hNe6UCJdNeWMj0zHbzWdfmHQyefcnBuDwEcUp+61y/X5v7jnHuhPZQje+0Y2jX+HeiHchle6+prKZTm/sWmqo0BxM2FFKvcH3HAK6H3XghOJCND/9FU08y6zRmCxUDj2VS0cTgrwm9SdMiSjJE1jQs9zXdX2BPp0S64eiLoKxrLK3KhyYDtV9KSPyfxOcj5KT06YbyZWeljobRo+ARC0T02JyjLbz1kqb5FWM6oQEGicQdmKtzrUyaMGDmDaZ4/oZhsNv2yGzhDphvexaflU//2AxW1V2V1MLuyRMorHVDAT4V9fnt/F3cs1jjvmlE19Wj1RfnAk8VUFauwV RL1TOIN6 nljtj7zDrF4cbJJ+nwYVsPgncWAawZbkRA4h5oO3A95m5d4lAAVMO1U1y16MpmvdAKHSMfqeSFiXxmkwUR+KUrrez+Lwh3/lN4RKkkEI1ClEDrH5j0BJVgYbrM18KbFiBCPrwnOy8EGX3nWuoJS3HU/dZ6TYt1HTWCq9Lb2aVPDwGBDuApUSem79zqLdX5EPLryEVQzooDzewoPECNLqU2Ds83pEMZRv77TqIw6fBdUl1tmJfi0aHoIpbfwU3TEDphQORSohQN6ntk8xKyti1jH6jIfybQ+kRn5e6X9jgNESBlm5MUzpuky2N1J3st9EthTz6t1pwnHDKehNMe5IgJHjNVBs4wuYf2PEabB82dtghax9wCVdEZbIzeXu0/l8a4FktcysSC09KmaY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.008877, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: There's nothing stopping us from supporting this, we could simply pass the order into the helper and emit the proper length. However currently there's no tests to validate this works properly, so disable it until there's a desire to support this along with the appropriate tests. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- mm/memory.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index bdf77a3ec47b..843ad75a4148 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -78,6 +78,7 @@ #include #include #include +#include #include @@ -5637,8 +5638,17 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; if (vma_is_anonymous(vma)) return do_huge_pmd_anonymous_page(vmf); + /* + * Currently we just emit PAGE_SIZE for our fault events, so don't allow + * a huge fault if we have a pre content watch on this file. This would + * be trivial to support, but there would need to be tests to ensure + * this works properly and those don't exist currently. + */ + if (fsnotify_file_has_pre_content_watches(file)) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PMD_ORDER); return VM_FAULT_FALLBACK; @@ -5648,6 +5658,7 @@ static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; const bool unshare = vmf->flags & FAULT_FLAG_UNSHARE; vm_fault_t ret; @@ -5662,6 +5673,9 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) } if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { + /* See comment in create_huge_pmd. */ + if (fsnotify_file_has_pre_content_watches(file)) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PMD_ORDER); if (!(ret & VM_FAULT_FALLBACK)) @@ -5681,9 +5695,13 @@ static vm_fault_t create_huge_pud(struct vm_fault *vmf) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vma)) return VM_FAULT_FALLBACK; + /* See comment in create_huge_pmd. */ + if (fsnotify_file_has_pre_content_watches(file)) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PUD_ORDER); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ @@ -5695,12 +5713,16 @@ static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; vm_fault_t ret; /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vma)) goto split; if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { + /* See comment in create_huge_pmd. */ + if (fsnotify_file_has_pre_content_watches(file)) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PUD_ORDER); if (!(ret & VM_FAULT_FALLBACK)) From patchwork Fri Nov 15 15:30:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876453 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 3E95DD68BC6 for ; Fri, 15 Nov 2024 15:32:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 565D16B00A6; Fri, 15 Nov 2024 10:31:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 517976B00A7; Fri, 15 Nov 2024 10:31:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38FDF6B00A8; Fri, 15 Nov 2024 10:31:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 19F3A6B00A6 for ; Fri, 15 Nov 2024 10:31:58 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CE38E1219CB for ; Fri, 15 Nov 2024 15:31:57 +0000 (UTC) X-FDA: 82788718824.05.653B53B Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) by imf20.hostedemail.com (Postfix) with ESMTP id 916E81C0005 for ; Fri, 15 Nov 2024 15:30:58 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=07cwN6yr; spf=none (imf20.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.172) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684626; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3KCTaRjNmkxmxaKf/dEMrgpxbgs8A3iRugI4cag6Bm4=; b=8VWx7ooN5oF3dacNc/UYjTWZAAr34Wq1i7kAOx+0osaubu9IZPtZfG9Oqn/9wfe145bwBq tP6Sqy5mAVv/VREqTQQJIioi+TZyoDrlutN0nUPe63d73Byet33UQqEGK8DObsNejlIIsG B2BrHx0D4sojgwQegEmiApDcXqRhgP0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684626; a=rsa-sha256; cv=none; b=MiDPPJLiWHt+kbMe4cKDiGVx+TX7doj+wEBUWD/+U7gNAOsYzzSqtwiRXSbbwe3Dn/7oaZ XCE7wEj6xGmgr4eVo4qHQMmI/wtVHLnJeLV2X8NEA5zQL/Gsg2eu98HTkbnCvc0G/DL62h 8ZZg9mD0nMoZTO2PtXwT8PbpKsf2TEY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=07cwN6yr; spf=none (imf20.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.172) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-e38158560d4so2003115276.2 for ; Fri, 15 Nov 2024 07:31:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684714; x=1732289514; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3KCTaRjNmkxmxaKf/dEMrgpxbgs8A3iRugI4cag6Bm4=; b=07cwN6yrdjKh4zfeoa1z3hHkXsqvvFR2TZRo1xhY1CTN/ZkX3a7zlvONTd3d+5T81L giILYyUwY1swVolFShDGMAHGdGalA5ei99TTtrGDvtDu1v0ZiMgVB3ONqhjA8Nv9rXtj eGYD1M0c8lAW0nWuMaQ5IE/QsEBjAs6AB13Nd3nIngOv0mgrXiK1ezKIe/E5n96r6CN5 i9qU6SwYGT2lrfGVXKXqjyht2PQIOGZU2L4EbexGK3WInD64sIUVXwZuYAeb0b714d0B YvDb6c26Ei6P6QjtQ/gMhtX4e+l6jp9je5+f/ieUd5eFswbXk8MDws/qFjCu5s1CKZy2 oAFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684714; x=1732289514; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3KCTaRjNmkxmxaKf/dEMrgpxbgs8A3iRugI4cag6Bm4=; b=rgSOR1zrzMpH99GclZzlZmaZJwm7bnqwtHdJ7i9QnX6ycy6zpAEEneZ6HUcpgROvtl XEibijhWiku0nC6RKX2XbxxXHtTZ537dP8h/2nt6NNiSd612MdkGDFqgRctvrrsidze5 WDUREik76jCZ+g3wABeTAJ3Sre+sIbxG/tLmCRNvVaTS5oOng1j+JgMJrPqxJsyoubH1 nN5ChLSowmohcbz9sXRRV4Q7txwLTkvIDmfbl6gv4MPQ3w/DVt4wSamUdl/dG20FW+Ok mhuMKNBUav5xukrzer8nM6T4BnpfUCYpoQgHRuEr7mC1KYNt9OQfMc79womcEs4sz5L0 XyRA== X-Forwarded-Encrypted: i=1; AJvYcCVhxMjimepF67pzJLj1i0audZ+sNZxa1OoC06vMkZmEm5KnO33sOO2FaquC9ieEjjCqZc9+l78QnA==@kvack.org X-Gm-Message-State: AOJu0YxvptSMeFKGrU4lVTrbEOVmBtMCs/6U/M4VEjDuGMAaAwCAMhFS FzsZUELAvT1ePFrjP3Aqq5cwGdsEAHvhfkabgUSxkPxJtvHVFMHULncgD0hmeag= X-Google-Smtp-Source: AGHT+IFmVYcZJStgSp9a9E1dsOyyT4rBH0daYbq6mRod+diiaSsdzS2Ed6cQkqbS64804RotiUDKFQ== X-Received: by 2002:a05:690c:9:b0:6e2:a129:1623 with SMTP id 00721157ae682-6ee55c69ee9mr29748387b3.38.1731684714337; Fri, 15 Nov 2024 07:31:54 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee4444ccdfsm7704207b3.120.2024.11.15.07.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:53 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 16/19] fsnotify: generate pre-content permission event on page fault Date: Fri, 15 Nov 2024 10:30:29 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: a8dfqs1rmd7rj67drerh9cm5c7beeekb X-Rspamd-Queue-Id: 916E81C0005 X-Rspam-User: X-HE-Tag: 1731684658-241048 X-HE-Meta: U2FsdGVkX1//QXQmMYHKYo/olUOpUOT9gRc/sgWP5MUqgXYwrhRnVLvhK8MjOn+BP4RzJY3SyKhcDexBlK/ohfw3STIj6b2ZPfkvMk6Hc3yQEednDBfwVwbdalD4tMNQIK6+WtLzHzZF/9UsTDw6UW/nXtKv1+WcOhVkt5fku95uGKYLehu3OzQ419AF6tUiZR3yZ+ybqKhjUH7CldhAvZWMBiK9vnGDeFY9JirR7D4NRfEHmXC6I9PLMFsrMBuUWnVk9FqdV2H30XAamt/qlW6B9a5Z0UYdr+Ax/yFubn6q7EbDlt4fuwX1lZHWIiyVEangcmd+APlb6njA2/SHyA9znI5VsXOjMPDXVPHbNH7lUamd+6udQyYOvaoQbiJ+IsZ/kiVzYJ7haBrQ6lz4RK24sF/q2dNaFzWUI+9tsWUAcWEq9qaA5038h9t4kQKVI09dfoNpCf4OQlwYdVBqhxl/knqtFyY1XPWOwRC6gstIPleirWYgBISdRJGpHFLOUVUSoZbskILfqdaWbiFFxguoLd17oGWws7CHuSg+ohPsVWepMoA0fQ8Crw5CyydBIjIpbPeczsU/+IHn3g8kt0Iu3obij7Lym2St466FpCvQ5YHgkj2nkIzLWUBc+VKBMluyoN4BK3+FaFYjwgtXJDY9BCsyNxXVbMmJelu17CTlbNc/bgtkyTVMTkSAcnGjdscl+IUnW6f7V7rYx5JDTjw0yXCCcNtlhDvn7f0GUg0iDwgq/r1MXl+aJIbgvBl3wx/tgoPlKKrjMmmGxp3YaDCZf2DpAMPBqFYKBQEpeKV75w6jEm+eUKMIPqaVRd1b7Gh5jvhx108rJ0Mt4WkcwVD/1lgzmNNvUMJaDurUy0IqaP71WT4nT3n238Zn07GnxgQYUqgzhmLtLc8/wbAg9Fk6S6m3eLQLJAsybhFglnLBq3o5CvEIdJDFJa+ykAB7ZHoRh1fVeI5hEW4iZaw CMMOOEh6 +pUkKzASaG3MNRElWGNHdjv7O791cNqKQOdGTmODk33KnXLe0kBUUwmlUk3tWL0NwFGQEtgQ4N7kU1kzq23lqxAYlj3KXHRsmKyu1njQ5Y1x1BhT1T70lc3qVQAMMFVD0EBP/7ElqhFGWus4slYtqf6p1Jx6E+79PqBJPLGtTUE7UHq3BT3AR5KUOEnSnydpq04TeCehtJONYrLPh1y1cICg/cxJHRc66fFAMvaQbOtV2DPHzXfe0HBgWFQpnRJ5GNXf7LVVy/cjBDbIN2E9yK9ZxCiCupsMlZCJ6czQ7cuEf5KNhXr5BIEjOtbzSpkX1+ooKBNeoZAgcbubs1EyUaxiTKrnkkGp5c0WkJukICONCH0mJZNKgYjDc0neIhYGW5wPaKNyrv+GQJG5RZJtnfNIXjszb1HHH8VpEbQ6/g3dhFVez1kLgNGWMGejwAk5t0+ywupEW8nPNxeSM2OjrRqvyLbUYCW0cr0GdP946hREKxjEtBTs6zig5Rh18Fa8XvuX402+22+Ozn1oPqcjx/LsZzw== 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: FS_PRE_ACCESS or FS_PRE_MODIFY will be generated on page fault depending on the faulting method. This pre-content event is meant to be used by hierarchical storage managers that want to fill in the file content on first read access. Export a simple helper that file systems that have their own ->fault() will use, and have a more complicated helper to be do fancy things with in filemap_fault. Signed-off-by: Josef Bacik --- include/linux/mm.h | 1 + mm/filemap.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 01c5e7a4489f..90155ef8599a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3406,6 +3406,7 @@ extern vm_fault_t filemap_fault(struct vm_fault *vmf); extern vm_fault_t filemap_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff); extern vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf); +extern vm_fault_t filemap_fsnotify_fault(struct vm_fault *vmf); extern unsigned long stack_guard_gap; /* Generic expand stack which grows the stack according to GROWS{UP,DOWN} */ diff --git a/mm/filemap.c b/mm/filemap.c index 68ea596f6905..0bf7d645dec5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -3289,6 +3290,52 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf) return ret; } +/** + * filemap_fsnotify_fault - maybe emit a pre-content event. + * @vmf: struct vm_fault containing details of the fault. + * @folio: the folio we're faulting in. + * + * If we have a pre-content watch on this file we will emit an event for this + * range. If we return anything the fault caller should return immediately, we + * will return VM_FAULT_RETRY if we had to emit an event, which will trigger the + * fault again and then the fault handler will run the second time through. + * + * This is meant to be called with the folio that we will be filling in to make + * sure the event is emitted for the correct range. + * + * Return: a bitwise-OR of %VM_FAULT_ codes, 0 if nothing happened. + */ +vm_fault_t filemap_fsnotify_fault(struct vm_fault *vmf) +{ + struct file *fpin = NULL; + int mask = (vmf->flags & FAULT_FLAG_WRITE) ? MAY_WRITE : MAY_ACCESS; + loff_t pos = vmf->pgoff >> PAGE_SHIFT; + size_t count = PAGE_SIZE; + vm_fault_t ret; + + /* + * We already did this and now we're retrying with everything locked, + * don't emit the event and continue. + */ + if (vmf->flags & FAULT_FLAG_TRIED) + return 0; + + /* No watches, we're done. */ + if (!fsnotify_file_has_pre_content_watches(vmf->vma->vm_file)) + return 0; + + fpin = maybe_unlock_mmap_for_io(vmf, fpin); + if (!fpin) + return VM_FAULT_SIGBUS; + + ret = fsnotify_file_area_perm(fpin, mask, &pos, count); + fput(fpin); + if (ret) + return VM_FAULT_SIGBUS; + return VM_FAULT_RETRY; +} +EXPORT_SYMBOL_GPL(filemap_fsnotify_fault); + /** * filemap_fault - read in file data for page fault handling * @vmf: struct vm_fault containing details of the fault @@ -3392,6 +3439,37 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) * or because readahead was otherwise unable to retrieve it. */ if (unlikely(!folio_test_uptodate(folio))) { + /* + * If this is a precontent file we have can now emit an event to + * try and populate the folio. + */ + if (!(vmf->flags & FAULT_FLAG_TRIED) && + fsnotify_file_has_pre_content_watches(file)) { + loff_t pos = folio_pos(folio); + size_t count = folio_size(folio); + + /* We're NOWAIT, we have to retry. */ + if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) { + folio_unlock(folio); + goto out_retry; + } + + if (mapping_locked) + filemap_invalidate_unlock_shared(mapping); + mapping_locked = false; + + folio_unlock(folio); + fpin = maybe_unlock_mmap_for_io(vmf, fpin); + if (!fpin) + goto out_retry; + + error = fsnotify_file_area_perm(fpin, MAY_ACCESS, &pos, + count); + if (error) + ret = VM_FAULT_SIGBUS; + goto out_retry; + } + /* * If the invalidate lock is not held, the folio was in cache * and uptodate and now it is not. Strange but possible since we From patchwork Fri Nov 15 15:30:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876454 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 2629ED68BC8 for ; Fri, 15 Nov 2024 15:32:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F8396B00A7; Fri, 15 Nov 2024 10:31:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AAC36B00A8; Fri, 15 Nov 2024 10:31:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D53846B00A9; Fri, 15 Nov 2024 10:31:58 -0500 (EST) 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 B4F956B00A7 for ; Fri, 15 Nov 2024 10:31:58 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5224081931 for ; Fri, 15 Nov 2024 15:31:58 +0000 (UTC) X-FDA: 82788719034.04.C500F01 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) by imf11.hostedemail.com (Postfix) with ESMTP id 2306940007 for ; Fri, 15 Nov 2024 15:30:59 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=E5DQhheU; dmarc=none; spf=none (imf11.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.179) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684652; a=rsa-sha256; cv=none; b=qW/yJSgdR4TFLCsp2MoChZiD77bJtiGdmKKL1hEg30ASguzKD83YlfkKbJijUSvf3J/2Vi xNyHC+AXDhgQDU/L6u8cFn2jntJQEZjI98Cz9lJKIHlesqnSgZF19tluRBtDlFs6edAfuV K0NX6J8VX0wpU+V6xncyJ5A0oV6nKCQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=E5DQhheU; dmarc=none; spf=none (imf11.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.179) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684652; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3nbIBZPU5mMiQBH7fH9PUjd6pvpSRIo6Q0oL6vGrX38=; b=3ev7hbtw16YHxDFryoSiBBzt6D62LGs3V5QDHmyMT8L6ufgR/QoV9wYzyAhHqgw7lyZKo+ paEe1YJm4OweiJfAFlkViep+r+sz2ObVfTJ8HejI5eC25UPVVZa9PAZNmJoeqLlQtPtcVH /jo/QdAl9o0HWacUF26mWkSOYEQIiwc= Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-6eb0e90b729so23139647b3.1 for ; Fri, 15 Nov 2024 07:31:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684716; x=1732289516; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3nbIBZPU5mMiQBH7fH9PUjd6pvpSRIo6Q0oL6vGrX38=; b=E5DQhheUpQithTlg46jJInks8euxfHE00A0cHs3M4eqM+raO/aubUaQzZT9P24PFVW 0QqBLvSCy75G6m2on0bb0DIzzOn/W0QD5rM8qm8hx8dHy0meIqGkwz9aD1rcsihCPfQl +vWAqFId805NiPOvQ/0e48+XnkbVtZIjf3bYtjMgVQowobWWwDluzT8ZlbzlswDqjvWZ aU5054KdYJDcts+44mE0A37PN2GBlnFX+5/b1nv+JnrqoQrbp5eoiDj+1jikXhKSX+2V ZjLhuqc+Y9IRdu9ywscXQ7IYJPVPd8Bc72WXikhZXr9/GfEedS8x1jJBi5tHDdi87jPx bLhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684716; x=1732289516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3nbIBZPU5mMiQBH7fH9PUjd6pvpSRIo6Q0oL6vGrX38=; b=nCOHx5UnBE5FdjsqYpAlaXGBTZQOc19U8vY+0H4b+a2iPpX4H0NKcDXUKxZyQ0qfq9 nY5YVbgM3nkfRleoTjDiSliwVXuUUckLv5C4PGTI/0M0OjBWSUMB2i5I+A4E4Y1Sm/P+ MCzHJ7nclw/C37FovAPwZLTYNv+WYZeics7+0vjFeNkFYF4BmvmdwC8QvVQ3l6+ELw9v yYxhnE07t3viIp6OX0Vj7lyfHVhHzY3N5/zgYR2/hqwAbGoLBzTrWkapGTLXNf0QUr2L vRq2FgfrxygwuYnaNVsou8ur0u3wuRs4ynMVnNtsGz6Ro2ngyzALpRYsgbxawxIUFStg Myyg== X-Forwarded-Encrypted: i=1; AJvYcCXEkWjNwZTXkdY9o8p3rlZqdj20p8STqeAu4ylyF93qAc57JKe67KFiqCJ9BDMOnR/SJEazaZgDjg==@kvack.org X-Gm-Message-State: AOJu0YxW41Uk0Dk2X1/ziCBovvWfGtVOliOhOyhPPEuryqT9VR11SMlx JLWffIgAIfNWMPvbHOgALnLzfFPOsBV8xyEYDNGMFpbCIFV3PYFLC6IBAt6leJM= X-Google-Smtp-Source: AGHT+IF2kfSK7avJhhme8jmNEknNmwYth/OIHi/JSJVRuMCWaSMr+rN1yucoeC0+W4HJkwXlrHqqNQ== X-Received: by 2002:a05:690c:688a:b0:6ea:7c46:8c23 with SMTP id 00721157ae682-6ee55ef8021mr42068567b3.35.1731684715691; Fri, 15 Nov 2024 07:31:55 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee440709dbsm7729117b3.54.2024.11.15.07.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:55 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 17/19] xfs: add pre-content fsnotify hook for write faults Date: Fri, 15 Nov 2024 10:30:30 -0500 Message-ID: <9eccdf59a65b72f0a1a5e2f2b9bff8eda2d4f2d9.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 2306940007 X-Rspamd-Server: rspam01 X-Stat-Signature: jpx8dpad4qz8dwf7r18akgtcgsreb71k X-HE-Tag: 1731684659-578615 X-HE-Meta: U2FsdGVkX18YLxEI6xlndVYliP0yfHp55daCOLGE+sPQIdbyzkWtzC0BPspDf+6MWVSL3f5KcPb2L9RNRDMSp9sQ+en4TQsAYATUi8xAIn6cqKYI2oSz05s/I1ZP8Qa+hTfm9gb6ibGJzaD7qIo8apQgLqzY8rfpNUqbpWlkEPQrob270+TI7HXj6TPJ+qudjAZyNFAJ22H7R3CazjzTtS7v3dKmq7cLAIb7qmnrv7ElxQLAl6xDilDBhM2+VbrjzpP91fDshgpu8nvVLGqsv1sLPb9i3Ydl80yO3GcfOJ5CbYuFifj3V+c19yd8p9suj90a1kWSrDzGe4kyOV6Ippq/VjXJ2p19xhVQW5ebkZYTzUzdfR9T4O5W0ThJZEV+1cKph99xQazWrliZQkwpkECUeSLIZ3FcWgZ9GytwFEIJWt0rTa3fZqzMOxGLx8tsfFcj+iC30j6IqinfLdNLAyH8ZesC6aPMpE+4u0C+N3oeVZrS2tumWge2nHoiA6Gz0jbtyXTYgy47FIUk+aym6jsB3v6FtARu4RAQJ/YCXGceTJj73LdX6k41GgtY7sntdFH7AQrf8tsxYZcgeJ5hLE5FY+lZDfQ3BCZR9NXZ9n4YB3/gpC4VrH9yY+grJJuCenakZqG1YNpARuBQy7qlPT0IxEe2JctM1hJkuaErHyKiqTL7BWkEv9jo9skEJ/Ud3AekF1TdFM1aHra0iU6GTbuKXYJb9H0v5DCObUZCOtKigy+bJuB56zEo6JzVv1ytUU/GcDAesv+5bGxRO9eHzDu9TrnmY5uMotDfNV5t+OXLI5Rl5tKTsWy7la3+gDJ+PpoE/bSG284tEcOUQlHNbavdYKIjAgtumPL8lp2l1jJECV0YtyW7+YZt84lBhCqlFW308XRn7OlmzktPBJ4R8wsORlg5lfxzOs/c05eZ5jdBn/LkihW+LkrQlXdwzyUhipCjIEWtBukOF7UzFT1 aEhPLrxv NG/aBpgT60aHL5YSW9mnRKFfCGRZUyJkO267UkLDQpGxAbwF0+Z5raiM7iJlMiUmFFN4s0zOUwAkWJyKY324lFOMQwVmBEaodnmi/mJ2POpG7+1YdqcAe+teSJZNDdk5hZ2XkO8JOUK/0BX46GGBoc+6VNKSagtj1BG3Lpy0RGDc9MjAaF6N70C4cJuZVlRIA1B/bWancAtJF3eds77tVWqJW0lPsYqQ6ghKtr+zVhXT57b+x4Uh3C9WU2P5lPttgjpUht0pO7mjFZVDge9rb9xnTQ2nhhFgCI/mxauoA1HdMXDIkpQNVCqeBm8VWuw6vpjIbH/IQnfWeQCd56L95BtDU2wqo207lVBDbGWT0YL8GFQBXGT/1/8TMuj1oCZUakE9H2/6CMA385DDmmISOaKK9P9jICSWS40mLhJOJk/QleS9nUkIiOriy1WZN8RE6dsHSwm2F5/61UYPnjb1R3xun4TqouGNe2oh+3wcMooG/vtg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.001025, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: xfs has it's own handling for write faults, so we need to add the pre-content fsnotify hook for this case. Reads go through filemap_fault so they're handled properly there. Signed-off-by: Josef Bacik --- fs/xfs/xfs_file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index ca47cae5a40a..4fe89770ecb5 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1458,6 +1458,10 @@ xfs_write_fault( unsigned int lock_mode = XFS_MMAPLOCK_SHARED; vm_fault_t ret; + ret = filemap_fsnotify_fault(vmf); + if (unlikely(ret)) + return ret; + sb_start_pagefault(inode->i_sb); file_update_time(vmf->vma->vm_file); From patchwork Fri Nov 15 15:30:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876455 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 07F26D68BCB for ; Fri, 15 Nov 2024 15:32:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 910836B00A8; Fri, 15 Nov 2024 10:32:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BF9F6B00A9; Fri, 15 Nov 2024 10:32:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EB2A6B00AA; Fri, 15 Nov 2024 10:32:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 488806B00A8 for ; Fri, 15 Nov 2024 10:32:00 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0E86A1418B8 for ; Fri, 15 Nov 2024 15:32:00 +0000 (UTC) X-FDA: 82788719160.11.AD5B703 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) by imf19.hostedemail.com (Postfix) with ESMTP id 36E741A0018 for ; Fri, 15 Nov 2024 15:31:00 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=3f027r1Y; dmarc=none; spf=none (imf19.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.177) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684539; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SVlCssk7TvFYg+mPz0+epJww2XrJywW98H8fNg6oZ9s=; b=xTgA/57RplowbOtCo5pmOtt3Vq3VG8TsSeo5zrhL+lMHkHTHOHeYRM01sIOWqJhR4FUhIV AnmpX46zvLK6imQZ1X2RagYc69m3IaiU2OdBh6JAdUIdTAEnzB5V8gEtKe/8Q4eHIPlPhD 634TMm3k0lEkWtA2L157kqpu/4wbd3c= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=3f027r1Y; dmarc=none; spf=none (imf19.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.177) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684539; a=rsa-sha256; cv=none; b=zquljKG9nKaMvCtc+zvDXbDnmUhI7QMucnC3DLULWuchnAtZhRrRicjAIdWd1KcfPgNjz8 TLgTMpfnRlMp46lDsay4QJlHLAArWpuoQ9U0DGUewqwML54piskXrNbdLx/yqHfqRfwJZd XnJDrNY3rGPOn3y1Flpgi7D+oeZYcwk= Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-6ee55cfa88cso8333567b3.3 for ; Fri, 15 Nov 2024 07:31:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684717; x=1732289517; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=SVlCssk7TvFYg+mPz0+epJww2XrJywW98H8fNg6oZ9s=; b=3f027r1YLvkwNN9Za4nwGdWHTA7lQ6c9xpqnEPNOMbhbGdqD283t16ODeVs3aIOUZ8 7+EYqFUxpoJXFMOuOMQB9vpiCw0bHznCESBLqHC0ZUCc2kOIKjbbBfjMCxymEHGIEZvL yyJlCLZzDMLk0vzAOG1J6CAECF2AhKmsNlHNXOpNPzWoPOQuJs7RG0IZOKotluRUwMTl hjmrtVxsNDDH7eaaLmUB8IxYjfw9xyisNefOjpkFMVpiA57BPGtJW0au5pwUEbfb2OBF K9Y9wiH1CUUDTAuRTkoicF9athLftg0MYVpO5oTsOOX+82OhoUlHG/mLNR+b9VYAxGb6 A35Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684717; x=1732289517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SVlCssk7TvFYg+mPz0+epJww2XrJywW98H8fNg6oZ9s=; b=TvHVf4TrlrY2JVpXRc/yHhQp3EQDp5Yg3eOVq9hXfMt5NMVy215z+wgNxZH7/Fzcr6 jONy931DoBPXpPxkunWKvCJ0ITkCQujVkwVNlaDnhOlatITAD2L5MLZLiN2lEKIUB8Iv XC//487Q7VPL/mApVrMzaODHK5BhY7FEdJXlr34imc7GxRGVVQctgPAc/uih1yEwu7a3 zY2AH+o95fRRcn7je7/EjouPs1roozRdKGr88jumwgqoBvYo5iLuWnHj0nj/hfFRQUMY H8rUYMr4txo0lcVFaQG/YmnScM1DrTCJmC4DiKZFPDwEor+N1nNxcoHOqKsOC/vkZaW0 RLsQ== X-Forwarded-Encrypted: i=1; AJvYcCWPDp63esdugcxwhvU6+29y8AVk4wuVYBOxORZyIanrypnSsbifQa0blyYO5b10//DnLJUu744g/w==@kvack.org X-Gm-Message-State: AOJu0YwANWJYN1K/85hMy/qajFjGT8jTT72AySGMd1O8hVXBQmevS0Xq E89ImoKIHE0JaLXkcGOqLz07tf9VOaLz+D9admEDlkJM1yZyB9x/DfumIHntQyc= X-Google-Smtp-Source: AGHT+IHB7s7jP8NWV/O0FcTu86HRGJSs7P0wkOPC0j5cMuO18DrwRH2o+5qB1EsHLQ8UmBf4vwq9wQ== X-Received: by 2002:a05:690c:62c5:b0:6ea:8a23:7673 with SMTP id 00721157ae682-6ee55bbae6amr38804727b3.8.1731684717148; Fri, 15 Nov 2024 07:31:57 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6ee44075016sm7768367b3.63.2024.11.15.07.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:56 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 18/19] btrfs: disable defrag on pre-content watched files Date: Fri, 15 Nov 2024 10:30:31 -0500 Message-ID: <4cc5bcea13db7904174353d08e85157356282a59.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 36E741A0018 X-Stat-Signature: sbjgt7pcitn93bj73zo9881wycn83ok4 X-Rspam-User: X-HE-Tag: 1731684660-576702 X-HE-Meta: U2FsdGVkX1/hmFX64LmTWTobZoW82pM2cm65reCKn61Ca5b372GZ0XkckErF7B9ZXukqN6I3bC11pjDXyZvY7ymhJIjOqZwrRkEdRhvHFqi987JGXHVEsjaohGsB5bjRNZ0ZaCfIguUJGqszuising4Bihnb1bQrD4d5IdPeb1dF9cLu+VxQ9KaMJfVbgBQ6rS1Ka0lGVofD6SDie4dlAirhD00Fts/xhr3ogt9wvUypv+uE4R8O6gtIxQnQs+n4dDkeInM+1AXHZj/F+EaYPWGV95882bl192v99nLlk5/p2tUMW3irBjbJ6hTk3DAiOO86uCqxGugO0j+n+TlUq9BWPDcXXjI5BVnZ3a4chfD69hrDmvNnfZWVXgJ5MDtUANapGi7mfiiWfJyn9w3QwUrV6j4YrFlYiFXBluv1kP9yJySS2b9O0rqa3RS8fOppV/nD1Uywc3QYhS8y4oSI6IFw9YXtboi3BUfWB3mBfcARp3MkcRHbznpQ1DGFCHSUqynSjACzPd8jVLI8RAsYkfH4YuB4vakoVf50B/AjGzDZYCWWy55P0gQZYQVFeh/FHYIsfXygNtVgAa1rC/10D89Aq0ZYpdJ9F3COvbLzruAngWGDq5X+K47BoKU7ZYSINO+fCmaf7UTPAPkkspJ3IJOiWTn4UMN6Uxqr3wtVAImLExBPPHpY4saeNTpU9L+rBbNIbrCJBFE0LvcRWYbd1XSHcB3moPsPuFnqWirn9V1WN68CL8j/6h+mZXduDZx+DZh2UuPvOT5kfoZ7H2JMzR/dl3ErKVwxUcnXgJGqftQC+iH96OwadqJD6nN7rpXGImwdndAzZYBLlaOlJ3G52J73Q0dQXeaUQMGcusEQZqWFUEdDAopMig5RZALCBjm6aLIcZzHZKMJfwbrjak2aNGp7nRAhawo8EbZPRXfM3FAHSh9RMXOORXW1aWDp7jKc1uJvxSevuiwQ5ieP34V nbyEON9e JewxqwEGfHpMmZpYzXMSfiuBb0V+asWOVY7nATZxZJxQEBSzWHByoZ4+etRDej0deAtOj3gtWMW7Qf/0Ffz02DyRTwMdBH0MLDZ8HGy2p/9IgRPzsJozog3qQFOQwYgOSc7hS99Tm9XbDqoeMxlnxeobs8A7q4oG+tyZIaLFVXXZV08Ao005iZKpu0MZfULcSz72snr4hlUka72ON1zzHU1RJwgnHiL/ZM2ozspKxXiJGJJgi1INLNBw57OCkkkaWnZrMBRWhdRYMUW6OUxgZ7yiRbO/rs0l8DIXVvqKltzfW7+w9CjPf+E1Su5GxaOPV3WneHzArvi86LIINg30ADPFWGlvI+wnRiS8oWUA4UbH6iOkOLPbT4hAnImm7gUyAFJvbNaLOJqVIB7s/CGLwB0YJggPaMsxbY3b7Qy6GTcUJc5PwTlJ9mDRWoIOpg5WYEtj97jLZYQjCwjoazg6aMbzxyan+/cyDjwOgx+flZGrx+5o= 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: We queue up inodes to be defrag'ed asynchronously, which means we do not have their original file for readahead. This means that the code to skip readahead on pre-content watched files will not run, and we could potentially read in empty pages. Handle this corner case by disabling defrag on files that are currently being watched for pre-content events. Signed-off-by: Josef Bacik --- fs/btrfs/ioctl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index c9302d193187..1e5913f276be 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2635,6 +2635,15 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) goto out; } + /* + * Don't allow defrag on pre-content watched files, as it could + * populate the page cache with 0's via readahead. + */ + if (fsnotify_file_has_pre_content_watches(file)) { + ret = -EINVAL; + goto out; + } + if (argp) { if (copy_from_user(&range, argp, sizeof(range))) { ret = -EFAULT; From patchwork Fri Nov 15 15:30:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13876457 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 59171D68BC6 for ; Fri, 15 Nov 2024 15:32:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84D5E6B00AE; Fri, 15 Nov 2024 10:32:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FC586B00AF; Fri, 15 Nov 2024 10:32:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64E546B00B0; Fri, 15 Nov 2024 10:32:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4102F6B00AE for ; Fri, 15 Nov 2024 10:32:13 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E937C81986 for ; Fri, 15 Nov 2024 15:32:12 +0000 (UTC) X-FDA: 82788719706.11.6C899E2 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf16.hostedemail.com (Postfix) with ESMTP id C6D3F180017 for ; Fri, 15 Nov 2024 15:31:25 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=KKnF1Kvo; spf=none (imf16.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731684585; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Gek1GO8SPggpZ3MPgZMTTjA2lPqNZurY73wIWpdWbQQ=; b=OiDpn1+bxxqKQo7vcAZeoJWr8axq45NcMhTxkH7SHXu1u5+OWzew1//BEolovpF65cNSel QMIoRvM3CQNdyOeeLnJ3f4X9znxkZmlLAC4d5wq2yXckLmYrumd0iFVBpTUndZJ/of4/Cz KH5tQRCDRw6EzWr5BDzJPCoDv7CiXEw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731684585; a=rsa-sha256; cv=none; b=GXz2gKhWOkeZQC57dgXdR51+B9sVXhdSyf2d4TmfFJHAb+cnxP2gCUqP9jUH8D1dVZ4mQS foDvbFWJ7qbDasK+UJMVZiGu3JQ4z74ZmmYLgCry1QJae+KsF+o4NJwrwGS9qPuq8Xniih XxyuImeV9cSaZxhkauSHFbs6q0Utvrw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=KKnF1Kvo; spf=none (imf16.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e35e0543b07so1847925276.2 for ; Fri, 15 Nov 2024 07:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731684730; x=1732289530; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Gek1GO8SPggpZ3MPgZMTTjA2lPqNZurY73wIWpdWbQQ=; b=KKnF1KvoU74btQ38zrpGmPBuLSR/cFlLbeR94pPYd+cNN4pUjzDZqWpm9imBvXxDrW 6dD7a3aWHDE7Lle81eM/TbViyay/omiXvBD/awylfZNNqoCkrRA8EBGK9jU4XNuG0Lgo I5QOLaMyWeN2TyerVQdLXZ2pPt0stH91f1ZtIK0ABUru+DfSyX2E82GAFjY+EHnGrKpi TZRJQeFNUGVkXWyPFxl4ttbLKWXax3yfRYs4Er4I2S+mjS7gLf+OhFt/Gw8yeduJ/7M/ WXFCnGNEieKfeFkuQ187QzRNuRtH8skj04jv33GgS7lRGgn7vMTV4X3pGimfg8QIXas9 WcYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731684730; x=1732289530; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gek1GO8SPggpZ3MPgZMTTjA2lPqNZurY73wIWpdWbQQ=; b=wEphhtVu7xBw2EWj3FNwg+xs5B8l5S1hprY3d20KOT/SOtdlEkANknbq9LZxv8el3H EL6XEK43XtpmDNdLBE+emm6gi+0lbsMUBu7ix3KLt4zWadd4/wr//qDPRejjzF+KQno+ 6t86S1S7Y+MXsVac4HqjZV2aE/DIDl4/d4rTvBx8DAT7Q0qNnYK8vkHRWZ4WpwxlVlRS 7cQJGUBhndXlk/JPJK2dhjmXWB464TIECmXNwfNA5FbVuZgpwy/V+KvJxhqQCVioS+e2 ban+biUUopiACeMqFuWeD4KkxVelEFTjSpaSfxJZ4Wyp98N85BF7En0P6GP0L/L54BjB Dr7Q== X-Forwarded-Encrypted: i=1; AJvYcCVmueq7GUUtV0BW9/QtJwcb8XdsX9bvF/Iig6hKg4ve7E2EWnAAAeDOTmG6SEJ0HbkDaqiVl5V/Yw==@kvack.org X-Gm-Message-State: AOJu0YyIUWU+QANS0EW0z3zijIfpvZPAiN6DF048SzB7nUj64nXRuc9S sTsAfGOhlRpwyDEGI5f+TpDEDDWZtcfNXfRzldr2irAu9YVhLogu+nDy8hwcW77BOo+NVRJGc4P k X-Google-Smtp-Source: AGHT+IEUcKBXNGC+FquadsfHiR9BI4UoMJrmZkBZaObeXyKm9EGd5wreVNWR6wH/jakvp0EFNSF0lA== X-Received: by 2002:a05:6902:1209:b0:e30:c977:a360 with SMTP id 3f1490d57ef6-e38261291fdmr3157574276.5.1731684719039; Fri, 15 Nov 2024 07:31:59 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e384121a605sm296041276.52.2024.11.15.07.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 07:31:58 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.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 Subject: [PATCH v8 19/19] fs: enable pre-content events on supported file systems Date: Fri, 15 Nov 2024 10:30:32 -0500 Message-ID: <46960dcb2725fa0317895ed66a8409ba1c306a82.1731684329.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: C6D3F180017 X-Stat-Signature: 631hckoaeqdpfdu335i8wpkx8kf6p9an X-HE-Tag: 1731684685-976645 X-HE-Meta: U2FsdGVkX182YEA9BroDD2Pm3MCZbC8LQX9nDbmZlaICc0ks92X1iuhl96AaSnswQ5Mpm7wH8km3BmMLgwXe+o9Jlnvuyn6/OGCP677AP4aQTyyB68dtPTFGMWXRr/k77Y3/ksXxRGDbZoP7hqnTrtleDFl/SOa4dEE5kUiXkM+5vL7BoF5s9TqVEnMcYERGz+OWHnKjxYD9StBNZAKjeiaHD0sTsN5T1DohtzKJprDrktw/J8F9VuZnUWjgu3dDPbGvLKmYJYJux9k/PGVSG33Bs1C/MHNk6qTiRL7BJBji6v+VEDt5JRNPLEqq103UxCYC/9LoDNNsHNjzb658n5ei8BEG8Lf9oel2inmEhqxi2VeRsMFKt6Mdccyob5Z7jdh/1RYWy16jmHGCX4pHNiCrA4Ykv11TY1bvBqVv0VKWOn9SmIx7H82K2FjzpzB/dujlMdqPh9680Q/DyNgMvhmVQ3jZ6d74q+jvfTmkbUQz3Z5k4Zh5RSbkYrYS0rvGeUeXBRHxlzNQ4b4Yx7xcrTRO0WOqE5FfnOxk2XXzyEYs1lemE6NymHrQcyaYwTPKKtRMPqQK2doiMaJxd8q0N/f48glzd26xX367o0t+aHZtT7Jix0t4LpR3iNV/m0NgwjPwZ6GFS4mj7KuGGb7tjlrU1V6bJFRFJdKSyJ4MH5UFNTgBf4WUPwlfR4S3UXsew66MyTrxwVOxVcB4F3ROfWHnffoDPcq4KHQ7w7/P7jo3RpkEbhO25hvkPZeGfS3tWJp6FzNVSKHJvPNDPNn+GDNApx4mKqIDITEFC/4zf9PVfpjgQiLUJSA1sTTmRLwgziAwyX3j6hcHUYbJ7XlccRoxgIB2YS44BIE4GCv8++Es7MAMo10suBbg68OUOQsDz+ct8D7tOwlilvPMbPX/vbREIbjx/V3uBvPWYIKmTL7eN2ktPFGjaMdTwxoDBs8tQrtqeGcVSVXnBAE3YRn 7k3QpytH rY+Wr6tapT7WA5xpjV6d6E4g6Fb8LqbNcjNrUBcHVG0F4+3Uqb/4w8foi2xLtb7g1k5Br+z5cGO8Pa4m/9F4U1CPPSc4FuvT1P5bDHTnpk6Ex69brSSNecK69m9zre0jgwJHwiBde1EjAH/Zdf9yera+uuL5ojdOuHd3n44+ML36/Y8Mmvnk3th3DoXUIsF7z4dkNOX7PoV9LhbUxGj2YXZIWsBDxdVTGWzTTaAPMl2cmUoE3iVMBNkcYwuE+USAjunxXKG4CU5wDctS3w9xym+WAvhj6ZR+rCUBey+emlJmjucDKCTlTB8I/CX8ySoqIhfYt7vH+KVzan+aaM7ji2S++mcq4um1oAKUNKHrX7QLoSVAQWI3CfE+hYNtE6Ea40dfk3x/S8TuhIBTdUd6Aw88aFVHssokmrTpqyn5uU8TZ4h79dDbjAfmR4d8MiX/2G3vUaimghNL3NFHDPHOwKAep/W0uEwW5EzRXt1dFf1BREgA= 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: Now that all the code has been added for pre-content events, and the various file systems that need the page fault hooks for fsnotify have been updated, add SB_I_ALLOW_HSM to the supported file systems. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 2 +- fs/ext4/super.c | 3 +++ fs/xfs/xfs_super.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 97a85d180b61..fe6ecc3f1cab 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -961,7 +961,7 @@ static int btrfs_fill_super(struct super_block *sb, #endif sb->s_xattr = btrfs_xattr_handlers; sb->s_time_gran = 1; - sb->s_iflags |= SB_I_CGROUPWB; + sb->s_iflags |= SB_I_CGROUPWB | SB_I_ALLOW_HSM; err = super_setup_bdi(sb); if (err) { diff --git a/fs/ext4/super.c b/fs/ext4/super.c index b3512d78b55c..13b9d67a4eec 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5306,6 +5306,9 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) /* i_version is always enabled now */ sb->s_flags |= SB_I_VERSION; + /* HSM events are allowed by default. */ + sb->s_iflags |= SB_I_ALLOW_HSM; + err = ext4_check_feature_compatibility(sb, es, silent); if (err) goto failed_mount; diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index fda75db739b1..2d1e9db8548d 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1713,7 +1713,7 @@ xfs_fs_fill_super( sb->s_time_max = XFS_LEGACY_TIME_MAX; } trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max); - sb->s_iflags |= SB_I_CGROUPWB; + sb->s_iflags |= SB_I_CGROUPWB | SB_I_ALLOW_HSM; set_posix_acl_flag(sb);