From patchwork Tue Mar 29 07:48:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794528 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92EC2C433F5 for ; Tue, 29 Mar 2022 07:49:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233572AbiC2Hu7 (ORCPT ); Tue, 29 Mar 2022 03:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231891AbiC2Hu4 (ORCPT ); Tue, 29 Mar 2022 03:50:56 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94C641E3190 for ; Tue, 29 Mar 2022 00:49:13 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id j18so23497098wrd.6 for ; Tue, 29 Mar 2022 00:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RBBWODAqEE7f4cxeskCr956agfYsRrTCYelOP6RPfNg=; b=XDoXF5QPqTqa6WYvAEi10KDUsjnBc48c9kSuHSH2XE4tFD54Xb1diKHgLCUiABuGWs jKL4cYqjlFmskpmLEfXYcHPDl+2qIMXhvwlHGI+KifxtXJlST8HijRH4KkaEv+2mv6/b +n2GvIZmO8/Y+sekwQBrp8uoiiUW8QR/aGZ70IupQt//sRgMEX1eswVBV+Nagsc2/Ss2 HRs+LPkbZBooSZbHJmYfT0pJll60y0FTornoRUbf3wT08VOadW62ogZQEBnbx1ki03PH a4K9tInLPXtRnLDinwZIqrl0YRbkID+rYvzi0hCYZnX+2grvKicIu3QAfpPrdtKkE8z/ kpcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RBBWODAqEE7f4cxeskCr956agfYsRrTCYelOP6RPfNg=; b=UqlKwjYvWsfEr+Xcr8K9CkM0Z/1qbitxf0gSlpC0c3MFbFb6z9KxJaIpvEjjVQNdg5 y0mJHqE0dkMk9pAPoRasn2JQqF5DlKnQVEjnF9ByGY1oIgdCjd4sVWu9iuqVKr0qro1W zcMKvRLeHmqFHITBm/jlIhBeS492Vajqf+rMFLtqrxLBEWYaSGSp8q93Hitc6tRs0/Ne JmQAQISMFI6Fk2h6e4E5M1OW/byWpxh9dFMP0qnzRDEOv05x3ylQOloHFT5qfqw1o70Q kWM/Y/P8gKuooU+g+QdCLTctChWd2QnT3A5TzibFE8pUbyqLcn6EV89g5aNrm7zuC/9i idyg== X-Gm-Message-State: AOAM532dbY/AlyTSvIJotowf4oGG59T4ANoh3AJircVVaYLU8gKn9w/q 8ND4KEHAr+FE8VtOrqGeEbEjWE6IxeM= X-Google-Smtp-Source: ABdhPJyIvmYSZTJa+6Dz2je3JaLuuHXQhmuF0F4kYU1E2UES3FcCltx8QDaEOOlcY1xnTiCvshf5gA== X-Received: by 2002:a5d:4381:0:b0:205:cb7d:f315 with SMTP id i1-20020a5d4381000000b00205cb7df315mr7484579wrq.338.1648540152008; Tue, 29 Mar 2022 00:49:12 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:11 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 01/16] inotify: show inotify mask flags in proc fdinfo Date: Tue, 29 Mar 2022 10:48:49 +0300 Message-Id: <20220329074904.2980320-2-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The inotify mask flags IN_ONESHOT and IN_EXCL_UNLINK are not "internal to kernel" and should be exposed in procfs fdinfo so CRIU can restore them. Fixes: 6933599697c9 ("inotify: hide internal kernel bits from fdinfo") Signed-off-by: Amir Goldstein --- fs/notify/fdinfo.c | 11 ++--------- fs/notify/inotify/inotify.h | 12 ++++++++++++ fs/notify/inotify/inotify_user.c | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index 57f0d5d9f934..3451708fd035 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c @@ -83,16 +83,9 @@ static void inotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) inode_mark = container_of(mark, struct inotify_inode_mark, fsn_mark); inode = igrab(fsnotify_conn_inode(mark->connector)); if (inode) { - /* - * IN_ALL_EVENTS represents all of the mask bits - * that we expose to userspace. There is at - * least one bit (FS_EVENT_ON_CHILD) which is - * used only internally to the kernel. - */ - u32 mask = mark->mask & IN_ALL_EVENTS; - seq_printf(m, "inotify wd:%x ino:%lx sdev:%x mask:%x ignored_mask:%x ", + seq_printf(m, "inotify wd:%x ino:%lx sdev:%x mask:%x ignored_mask:0 ", inode_mark->wd, inode->i_ino, inode->i_sb->s_dev, - mask, mark->ignored_mask); + inotify_mark_user_mask(mark)); show_mark_fhandle(m, inode); seq_putc(m, '\n'); iput(inode); diff --git a/fs/notify/inotify/inotify.h b/fs/notify/inotify/inotify.h index 2007e3711916..8f00151eb731 100644 --- a/fs/notify/inotify/inotify.h +++ b/fs/notify/inotify/inotify.h @@ -22,6 +22,18 @@ static inline struct inotify_event_info *INOTIFY_E(struct fsnotify_event *fse) return container_of(fse, struct inotify_event_info, fse); } +/* + * INOTIFY_USER_FLAGS represents all of the mask bits that we expose to + * userspace. There is at least one bit (FS_EVENT_ON_CHILD) which is + * used only internally to the kernel. + */ +#define INOTIFY_USER_MASK (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK) + +static inline __u32 inotify_mark_user_mask(struct fsnotify_mark *fsn_mark) +{ + return fsn_mark->mask & INOTIFY_USER_MASK; +} + extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark, struct fsnotify_group *group); extern int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index 54583f62dc44..3ef57db0ec9d 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -110,7 +110,7 @@ static inline __u32 inotify_arg_to_mask(struct inode *inode, u32 arg) mask |= FS_EVENT_ON_CHILD; /* mask off the flags used to open the fd */ - mask |= (arg & (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK)); + mask |= (arg & INOTIFY_USER_MASK); return mask; } From patchwork Tue Mar 29 07:48:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794529 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6076FC433FE for ; Tue, 29 Mar 2022 07:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233573AbiC2Hu7 (ORCPT ); Tue, 29 Mar 2022 03:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233567AbiC2Hu6 (ORCPT ); Tue, 29 Mar 2022 03:50:58 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4FC81E375F for ; Tue, 29 Mar 2022 00:49:14 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id m30so23544661wrb.1 for ; Tue, 29 Mar 2022 00:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UMdKjcpN0N/Oj/K7Q1FeabEJEAUcuTSG0v/vS8Agcg0=; b=Czcq2WqeYjCqi8Nc0K7f8+76AeuiUnJEHDQ8PhXML2K25hSDU7WnjWV6YJUvgPpFB0 j8M+dkrb38Tqh6/3mbB+IokkJfhCwelDHC+z6bypX4mln7cHD+76p/fs2og48/b319gD R2Zg7MBN1yKfCqZkx+FY7QkeuJNGTy63J7g2E8r0YoOX5sV3j37js3taMV9KxcqY3g+K bzqh8fReH8SSvMWAdNiSD+VilBkGk4Kndvx2dwr0iRkny5q9qoy9/aOydNs9DFmNHL0O IYlBc7tVzX3taGhIzHAQd5xo16jBgkNi/b0Ta1Ut+58vJTMEhZqLTzK6YTWUQFkkkLXm WhLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UMdKjcpN0N/Oj/K7Q1FeabEJEAUcuTSG0v/vS8Agcg0=; b=BdemD1XCSqFdSuDqKHCstTNI2yIzId1575q/da2grgGPYB4QF8gMILlK+tQJxzoUog drpItI05F2KdpFDGpTJlKiVIf+gaZTJVIZpeWngnyVq17SpyFwrm8nIvJuVIgi7Ej01+ k+78XmE7YLcaANGLFbboycG3FdBXbkrMB+bN/TCKJMmy4YPF1wfKjM8AJ1csGbu9fEQq lprhnbHIIvZP+XY7qrfWpR/GCWOOuT4HAxM4VmkljD10Qju68z21Ks/Tgt/G+UHs3J3J 1/eN19HaVOijSMiiUQ/JSygy0sFJDmrkNtVVlLor3D0EeP18v9T9sNvk7WatxUQmaTrn jheg== X-Gm-Message-State: AOAM531QiUv1Dr08DspC29so7hNLKUvR/G2og1wLnyqtAYWfeAHCxpaN QBKNNAZWuoyBAztDfve1L0HnOJOPH2k= X-Google-Smtp-Source: ABdhPJwvSg0NE33t8B2djCVNS8gmAmCL0u78TrT53Otz+njjHFBShEt7oY763abevs5KJVEs2k6RMA== X-Received: by 2002:a05:6000:508:b0:1e4:a027:d147 with SMTP id a8-20020a056000050800b001e4a027d147mr29391787wrf.315.1648540153412; Tue, 29 Mar 2022 00:49:13 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:12 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 02/16] inotify: move control flags from mask to mark flags Date: Tue, 29 Mar 2022 10:48:50 +0300 Message-Id: <20220329074904.2980320-3-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The inotify control flags in the mark mask (e.g. FS_IN_ONE_SHOT) are not relevant to object interest mask, so move them to the mark flags. This frees up some bits in the object interest mask. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 4 +-- fs/notify/inotify/inotify.h | 11 ++++++-- fs/notify/inotify/inotify_fsnotify.c | 2 +- fs/notify/inotify/inotify_user.c | 38 ++++++++++++++++++---------- include/linux/fsnotify_backend.h | 15 ++++++----- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 70a8516b78bc..6eee19d15e8c 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -253,7 +253,7 @@ static int fsnotify_handle_inode_event(struct fsnotify_group *group, if (WARN_ON_ONCE(!inode && !dir)) return 0; - if ((inode_mark->mask & FS_EXCL_UNLINK) && + if ((inode_mark->flags & FSNOTIFY_MARK_FLAG_EXCL_UNLINK) && path && d_unlinked(path->dentry)) return 0; @@ -581,7 +581,7 @@ static __init int fsnotify_init(void) { int ret; - BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 25); + BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 23); ret = init_srcu_struct(&fsnotify_mark_srcu); if (ret) diff --git a/fs/notify/inotify/inotify.h b/fs/notify/inotify/inotify.h index 8f00151eb731..7d5df7a21539 100644 --- a/fs/notify/inotify/inotify.h +++ b/fs/notify/inotify/inotify.h @@ -27,11 +27,18 @@ static inline struct inotify_event_info *INOTIFY_E(struct fsnotify_event *fse) * userspace. There is at least one bit (FS_EVENT_ON_CHILD) which is * used only internally to the kernel. */ -#define INOTIFY_USER_MASK (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK) +#define INOTIFY_USER_MASK (IN_ALL_EVENTS) static inline __u32 inotify_mark_user_mask(struct fsnotify_mark *fsn_mark) { - return fsn_mark->mask & INOTIFY_USER_MASK; + __u32 mask = fsn_mark->mask & INOTIFY_USER_MASK; + + if (fsn_mark->flags & FSNOTIFY_MARK_FLAG_EXCL_UNLINK) + mask |= IN_EXCL_UNLINK; + if (fsn_mark->flags & FSNOTIFY_MARK_FLAG_IN_ONESHOT) + mask |= IN_ONESHOT; + + return mask; } extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark, diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c index d92d7b0adc9a..49cfe2ae6d23 100644 --- a/fs/notify/inotify/inotify_fsnotify.c +++ b/fs/notify/inotify/inotify_fsnotify.c @@ -122,7 +122,7 @@ int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, u32 mask, fsnotify_destroy_event(group, fsn_event); } - if (inode_mark->mask & IN_ONESHOT) + if (inode_mark->flags & FSNOTIFY_MARK_FLAG_IN_ONESHOT) fsnotify_destroy_mark(inode_mark, group); return 0; diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index 3ef57db0ec9d..d8907d32a05b 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -115,6 +115,21 @@ static inline __u32 inotify_arg_to_mask(struct inode *inode, u32 arg) return mask; } +#define INOTIFY_MARK_FLAGS \ + (FSNOTIFY_MARK_FLAG_EXCL_UNLINK | FSNOTIFY_MARK_FLAG_IN_ONESHOT) + +static inline unsigned int inotify_arg_to_flags(u32 arg) +{ + unsigned int flags = 0; + + if (arg & IN_EXCL_UNLINK) + flags |= FSNOTIFY_MARK_FLAG_EXCL_UNLINK; + if (arg & IN_ONESHOT) + flags |= FSNOTIFY_MARK_FLAG_IN_ONESHOT; + + return flags; +} + static inline u32 inotify_mask_to_arg(__u32 mask) { return mask & (IN_ALL_EVENTS | IN_ISDIR | IN_UNMOUNT | IN_IGNORED | @@ -526,13 +541,10 @@ static int inotify_update_existing_watch(struct fsnotify_group *group, struct fsnotify_mark *fsn_mark; struct inotify_inode_mark *i_mark; __u32 old_mask, new_mask; - __u32 mask; - int add = (arg & IN_MASK_ADD); + int replace = !(arg & IN_MASK_ADD); int create = (arg & IN_MASK_CREATE); int ret; - mask = inotify_arg_to_mask(inode, arg); - fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group); if (!fsn_mark) return -ENOENT; @@ -545,10 +557,12 @@ static int inotify_update_existing_watch(struct fsnotify_group *group, spin_lock(&fsn_mark->lock); old_mask = fsn_mark->mask; - if (add) - fsn_mark->mask |= mask; - else - fsn_mark->mask = mask; + if (replace) { + fsn_mark->mask = 0; + fsn_mark->flags &= ~INOTIFY_MARK_FLAGS; + } + fsn_mark->mask |= inotify_arg_to_mask(inode, arg); + fsn_mark->flags |= inotify_arg_to_flags(arg); new_mask = fsn_mark->mask; spin_unlock(&fsn_mark->lock); @@ -579,19 +593,17 @@ static int inotify_new_watch(struct fsnotify_group *group, u32 arg) { struct inotify_inode_mark *tmp_i_mark; - __u32 mask; int ret; struct idr *idr = &group->inotify_data.idr; spinlock_t *idr_lock = &group->inotify_data.idr_lock; - mask = inotify_arg_to_mask(inode, arg); - tmp_i_mark = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL); if (unlikely(!tmp_i_mark)) return -ENOMEM; fsnotify_init_mark(&tmp_i_mark->fsn_mark, group); - tmp_i_mark->fsn_mark.mask = mask; + tmp_i_mark->fsn_mark.mask = inotify_arg_to_mask(inode, arg); + tmp_i_mark->fsn_mark.flags = inotify_arg_to_flags(arg); tmp_i_mark->wd = -1; ret = inotify_add_to_idr(idr, idr_lock, tmp_i_mark); @@ -845,9 +857,7 @@ static int __init inotify_user_setup(void) BUILD_BUG_ON(IN_UNMOUNT != FS_UNMOUNT); BUILD_BUG_ON(IN_Q_OVERFLOW != FS_Q_OVERFLOW); BUILD_BUG_ON(IN_IGNORED != FS_IN_IGNORED); - BUILD_BUG_ON(IN_EXCL_UNLINK != FS_EXCL_UNLINK); BUILD_BUG_ON(IN_ISDIR != FS_ISDIR); - BUILD_BUG_ON(IN_ONESHOT != FS_IN_ONESHOT); BUILD_BUG_ON(HWEIGHT32(ALL_INOTIFY_BITS) != 22); diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 0805b74cae44..8ecdc1750e67 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -55,7 +55,6 @@ #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_EXCL_UNLINK 0x04000000 /* do not send events if object is unlinked */ /* * Set on inode mark that cares about things that happen to its children. * Always set for dnotify and inotify. @@ -66,7 +65,6 @@ #define FS_RENAME 0x10000000 /* File was renamed */ #define FS_DN_MULTISHOT 0x20000000 /* dnotify multishot */ #define FS_ISDIR 0x40000000 /* event occurred against dir */ -#define FS_IN_ONESHOT 0x80000000 /* only send event once */ #define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) @@ -106,8 +104,7 @@ FS_ERROR) /* Extra flags that may be reported with event or control handling of events */ -#define ALL_FSNOTIFY_FLAGS (FS_EXCL_UNLINK | FS_ISDIR | FS_IN_ONESHOT | \ - FS_DN_MULTISHOT | FS_EVENT_ON_CHILD) +#define ALL_FSNOTIFY_FLAGS (FS_ISDIR | FS_EVENT_ON_CHILD | FS_DN_MULTISHOT) #define ALL_FSNOTIFY_BITS (ALL_FSNOTIFY_EVENTS | ALL_FSNOTIFY_FLAGS) @@ -473,9 +470,13 @@ struct fsnotify_mark { struct fsnotify_mark_connector *connector; /* Events types to ignore [mark->lock, group->mark_mutex] */ __u32 ignored_mask; -#define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY 0x01 -#define FSNOTIFY_MARK_FLAG_ALIVE 0x02 -#define FSNOTIFY_MARK_FLAG_ATTACHED 0x04 + /* Internal fsnotify flags */ +#define FSNOTIFY_MARK_FLAG_ALIVE 0x0001 +#define FSNOTIFY_MARK_FLAG_ATTACHED 0x0002 + /* Backend controlled flags */ +#define FSNOTIFY_MARK_FLAG_EXCL_UNLINK 0x0010 +#define FSNOTIFY_MARK_FLAG_IN_ONESHOT 0x0020 +#define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY 0x0100 unsigned int flags; /* flags [mark->lock] */ }; From patchwork Tue Mar 29 07:48:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794530 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 416D6C433F5 for ; Tue, 29 Mar 2022 07:49:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233578AbiC2HvB (ORCPT ); Tue, 29 Mar 2022 03:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233568AbiC2Hu7 (ORCPT ); Tue, 29 Mar 2022 03:50:59 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20CFA1E3E05 for ; Tue, 29 Mar 2022 00:49:16 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id h4so23491832wrc.13 for ; Tue, 29 Mar 2022 00:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=opDUpK7X74k71HVH4N+7XyNkXF8O3XUdZUxk0kOEwc8=; b=FQG0rr95Pqud/m9Yp/dM7za4jb8DC9FPw7ninm+dDkNxsIUrTAFl5YQLgkxY1yGJF1 20gRt6V2cuGaR000Jlxv7m6FVZBmhZoQ/+Hh7AdawQypf3KZxmBQma7A/eT+ngDQvT4M aUnYO+MeMLLs6jZER+aNxlsfQu3FNH3/pu8WesOsUU4c1HdluJPMBvN80ZOOdMnujqB7 AEbyr9LbBqDb2z0vM83FLyG1pGFFpjxEwscV2YLOC2JGrZnYeyIJTdtAh+dXOZDFeFQI UV9B2Ki3muwVRPNUZZ32PHt+HEQODAecEwUD5KH2MKI9tcRREWUHL8KTryiIYhgKbxBN Tm4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=opDUpK7X74k71HVH4N+7XyNkXF8O3XUdZUxk0kOEwc8=; b=oeSRFQj7oHobnMs+9jvxnXteetI/UaeCMx60z86tUWdrGSM0d4uqrypIMfzATOxHTl kXf8ym1lrF+l1d+6H8EhHKS7BLyaKep2MjYUi7N/Ds7K1zK/JfInjDR9iFqybbrsYjlg htY05wI8fjCBjyp0ZdDZeS/lvSUZmxiFk6GqRTyGiZ2T1jUWiJALK9HfcpNgL6gaD/N/ T0QWsYUV2lae/sRQ92v4PeWdnHCIaDFEyyHCVHPdRE4Ja/+t2e7SoQz9fz5nzpx18iWs miDmVJBviB/DynfFYZwVew1O6/6TCRN6kbm6h9OfB+znJtoRVK5FSxuh0t7wvBCFnd4i mlCQ== X-Gm-Message-State: AOAM531l4vsW3aHpNd114KACr8xGdPMmBpvi67m4BpdcfLoyJA9HIZlu Kx6Xp1oZUrQ5ltV6aePMI5Y= X-Google-Smtp-Source: ABdhPJyij0xpAsZsrhN/l3vaHtSno6UUqgAND/t/L4eH7ZnKrykaYsgEYBYnyW7XsK8sRAwvV3yNog== X-Received: by 2002:adf:f943:0:b0:203:e832:129 with SMTP id q3-20020adff943000000b00203e8320129mr29300015wrr.626.1648540154653; Tue, 29 Mar 2022 00:49:14 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:14 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 03/16] fsnotify: pass flags argument to fsnotify_add_mark() via mark Date: Tue, 29 Mar 2022 10:48:51 +0300 Message-Id: <20220329074904.2980320-4-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Instead of passing the allow_dups argument to fsnotify_add_mark() as an argument, define the mark flag FSNOTIFY_MARK_FLAG_ALLOW_DUPS to express the old allow_dups meaning and pass this information on the mark itself. We use mark->flags to pass inotify control flags and will pass more control flags in the future so let's make this the standard. Although the FSNOTIFY_MARK_FLAG_ALLOW_DUPS flag is not used after the call to fsnotify_add_mark(), it does not hurt to leave this information on the mark for future use. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 2 +- fs/notify/inotify/inotify_user.c | 4 ++-- fs/notify/mark.c | 13 ++++++------- include/linux/fsnotify_backend.h | 19 ++++++++++--------- kernel/audit_fsnotify.c | 3 ++- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 9b32b76a9c30..0f0db1efa379 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1144,7 +1144,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, } fsnotify_init_mark(mark, group); - ret = fsnotify_add_mark_locked(mark, connp, obj_type, 0, fsid); + ret = fsnotify_add_mark_locked(mark, connp, obj_type, fsid); if (ret) { fsnotify_put_mark(mark); goto out_dec_ucounts; diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index d8907d32a05b..6fc0f598a7aa 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -603,7 +603,6 @@ static int inotify_new_watch(struct fsnotify_group *group, fsnotify_init_mark(&tmp_i_mark->fsn_mark, group); tmp_i_mark->fsn_mark.mask = inotify_arg_to_mask(inode, arg); - tmp_i_mark->fsn_mark.flags = inotify_arg_to_flags(arg); tmp_i_mark->wd = -1; ret = inotify_add_to_idr(idr, idr_lock, tmp_i_mark); @@ -618,7 +617,8 @@ static int inotify_new_watch(struct fsnotify_group *group, } /* we are on the idr, now get on the inode */ - ret = fsnotify_add_inode_mark_locked(&tmp_i_mark->fsn_mark, inode, 0); + ret = fsnotify_add_inode_mark_locked(&tmp_i_mark->fsn_mark, inode, + inotify_arg_to_flags(arg)); if (ret) { /* we failed to get on the inode, get off the idr */ inotify_remove_from_idr(group, tmp_i_mark); diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 4853184f7dde..b1443e66ba26 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -574,7 +574,7 @@ static struct fsnotify_mark_connector *fsnotify_grab_connector( static int fsnotify_add_mark_list(struct fsnotify_mark *mark, fsnotify_connp_t *connp, unsigned int obj_type, - int allow_dups, __kernel_fsid_t *fsid) + __kernel_fsid_t *fsid) { struct fsnotify_mark *lmark, *last = NULL; struct fsnotify_mark_connector *conn; @@ -633,7 +633,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, if ((lmark->group == mark->group) && (lmark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) && - !allow_dups) { + !(mark->flags & FSNOTIFY_MARK_FLAG_ALLOW_DUPS)) { err = -EEXIST; goto out_err; } @@ -668,7 +668,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, */ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, fsnotify_connp_t *connp, unsigned int obj_type, - int allow_dups, __kernel_fsid_t *fsid) + __kernel_fsid_t *fsid) { struct fsnotify_group *group = mark->group; int ret = 0; @@ -688,7 +688,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, fsnotify_get_mark(mark); /* for g_list */ spin_unlock(&mark->lock); - ret = fsnotify_add_mark_list(mark, connp, obj_type, allow_dups, fsid); + ret = fsnotify_add_mark_list(mark, connp, obj_type, fsid); if (ret) goto err; @@ -708,14 +708,13 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, } int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp, - unsigned int obj_type, int allow_dups, - __kernel_fsid_t *fsid) + unsigned int obj_type, __kernel_fsid_t *fsid) { int ret; struct fsnotify_group *group = mark->group; mutex_lock(&group->mark_mutex); - ret = fsnotify_add_mark_locked(mark, connp, obj_type, allow_dups, fsid); + ret = fsnotify_add_mark_locked(mark, connp, obj_type, fsid); mutex_unlock(&group->mark_mutex); return ret; } diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 8ecdc1750e67..9e8b5b52b9de 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -476,6 +476,7 @@ struct fsnotify_mark { /* Backend controlled flags */ #define FSNOTIFY_MARK_FLAG_EXCL_UNLINK 0x0010 #define FSNOTIFY_MARK_FLAG_IN_ONESHOT 0x0020 +#define FSNOTIFY_MARK_FLAG_ALLOW_DUPS 0x0040 #define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY 0x0100 unsigned int flags; /* flags [mark->lock] */ }; @@ -633,30 +634,30 @@ extern struct fsnotify_mark *fsnotify_find_mark(fsnotify_connp_t *connp, /* Get cached fsid of filesystem containing object */ extern int fsnotify_get_conn_fsid(const struct fsnotify_mark_connector *conn, __kernel_fsid_t *fsid); + /* attach the mark to the object */ extern int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp, unsigned int obj_type, - int allow_dups, __kernel_fsid_t *fsid); + __kernel_fsid_t *fsid); extern int fsnotify_add_mark_locked(struct fsnotify_mark *mark, fsnotify_connp_t *connp, - unsigned int obj_type, int allow_dups, + unsigned int obj_type, __kernel_fsid_t *fsid); /* attach the mark to the inode */ static inline int fsnotify_add_inode_mark(struct fsnotify_mark *mark, - struct inode *inode, - int allow_dups) + struct inode *inode, int flags) { + mark->flags = flags; return fsnotify_add_mark(mark, &inode->i_fsnotify_marks, - FSNOTIFY_OBJ_TYPE_INODE, allow_dups, NULL); + FSNOTIFY_OBJ_TYPE_INODE, NULL); } static inline int fsnotify_add_inode_mark_locked(struct fsnotify_mark *mark, - struct inode *inode, - int allow_dups) + struct inode *inode, int flags) { + mark->flags = flags; return fsnotify_add_mark_locked(mark, &inode->i_fsnotify_marks, - FSNOTIFY_OBJ_TYPE_INODE, allow_dups, - NULL); + FSNOTIFY_OBJ_TYPE_INODE, NULL); } /* given a group and a mark, flag mark to be freed when all references are dropped */ diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c index 02348b48447c..3c35649bc7f5 100644 --- a/kernel/audit_fsnotify.c +++ b/kernel/audit_fsnotify.c @@ -100,7 +100,8 @@ struct audit_fsnotify_mark *audit_alloc_mark(struct audit_krule *krule, char *pa audit_update_mark(audit_mark, dentry->d_inode); audit_mark->rule = krule; - ret = fsnotify_add_inode_mark(&audit_mark->mark, inode, true); + ret = fsnotify_add_inode_mark(&audit_mark->mark, inode, + FSNOTIFY_MARK_FLAG_ALLOW_DUPS); if (ret < 0) { fsnotify_put_mark(&audit_mark->mark); audit_mark = ERR_PTR(ret); From patchwork Tue Mar 29 07:48:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794531 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1182C433EF for ; Tue, 29 Mar 2022 07:49:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233592AbiC2HvL (ORCPT ); Tue, 29 Mar 2022 03:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233574AbiC2HvA (ORCPT ); Tue, 29 Mar 2022 03:51:00 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 562FF1E3E2B for ; Tue, 29 Mar 2022 00:49:17 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id h4so23491893wrc.13 for ; Tue, 29 Mar 2022 00:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4c3DGo6tjgx4VrE0f1pQ13QNGFWI5EFvnHPKPJcp//8=; b=pcmZg3C0BmCACPs/SePkZ9knBAOzPhj/EPrT18VcFjOsdLAYrtXaOih1sBELsvu7Pd 4RxrzznPUzYalLO9WJ4uzwZO//xfM8FQTMVP4Bh8Ak6+0NGR2XxgH6qhCtc1YA3C8/l3 iIo1YFDGccq+wKqfVSHI0z4DDFerZXba4+Q5yqxjsy9cxAUfpyddM9FMkl/zELmUbOwy 73xnd3vApOfK+RSWAFaCzmaV/sIz4WP/qsCBqMGP5AIYMNRytmGusvSgvt/rW0zQcPL7 PwG7JwkzWPOMMU6KEfOF1DyetQiQywOvUZsiyNIyKe6FEjgkjrLwWCChB0gWXU6v+Lgy YmIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4c3DGo6tjgx4VrE0f1pQ13QNGFWI5EFvnHPKPJcp//8=; b=Y8DG6F7CbKiC5sPXgRRM6jthk5iRbaEEiTUqSCsTULifRJNMK4XCpoMb/a3ZH4abbd jsU1UMC0fxp2EfGPabHQjC7MsgLI10zIVpBrbNXhiunpZVbGKTZCWlFAvhsctgounlE3 M1Su8SvxdA9WOgq4GprDpl4+T9nGnC9ZeqapYGOk3DFD4N/Rq4/gV4BUKvb/nBh8lPwc dJ1ff5WQW4HXhfMHUIIrTbdd6G3cI6fEfEt7katOFnkRguIQ5AS6H7oIrITWoD9S2FMS /PXF6RO0N6ugTfO8QRsl1DJsAnAVx3lAakyzVeYXeT9dROPYIYhkbt4GJ0HP5BmZS457 BQnw== X-Gm-Message-State: AOAM533VfOZTB7xRq0aQo1MNjZzKE0yE0J6lnwdDOLAwCp4eFVu4bLZk XnpTtSLdzEEXl708JhLY/nc= X-Google-Smtp-Source: ABdhPJyTR8G3P/XTL2imaHuNtJI88liNV4JLqhuPW6b7BfR/kl+FRIaQhGS9xegGU7aqKzcMREvE3A== X-Received: by 2002:a5d:5507:0:b0:203:e0a3:7016 with SMTP id b7-20020a5d5507000000b00203e0a37016mr28380748wrv.575.1648540155859; Tue, 29 Mar 2022 00:49:15 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:15 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 04/16] fsnotify: remove unneeded refcounts of s_fsnotify_connectors Date: Tue, 29 Mar 2022 10:48:52 +0300 Message-Id: <20220329074904.2980320-5-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org s_fsnotify_connectors is elevated for every inode mark in addition to the refcount already taken by the inode connector. This is a relic from s_fsnotify_inode_refs pre connector era. Remove those unneeded recounts. Signed-off-by: Amir Goldstein --- fs/notify/mark.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index b1443e66ba26..698ed0a1a47e 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -169,21 +169,6 @@ static void fsnotify_connector_destroy_workfn(struct work_struct *work) } } -static void fsnotify_get_inode_ref(struct inode *inode) -{ - ihold(inode); - atomic_long_inc(&inode->i_sb->s_fsnotify_connectors); -} - -static void fsnotify_put_inode_ref(struct inode *inode) -{ - struct super_block *sb = inode->i_sb; - - iput(inode); - if (atomic_long_dec_and_test(&sb->s_fsnotify_connectors)) - wake_up_var(&sb->s_fsnotify_connectors); -} - static void fsnotify_get_sb_connectors(struct fsnotify_mark_connector *conn) { struct super_block *sb = fsnotify_connector_sb(conn); @@ -245,7 +230,7 @@ static void fsnotify_drop_object(unsigned int type, void *objp) /* Currently only inode references are passed to be dropped */ if (WARN_ON_ONCE(type != FSNOTIFY_OBJ_TYPE_INODE)) return; - fsnotify_put_inode_ref(objp); + iput(objp); } void fsnotify_put_mark(struct fsnotify_mark *mark) @@ -519,7 +504,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, } if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { inode = fsnotify_conn_inode(conn); - fsnotify_get_inode_ref(inode); + ihold(inode); } fsnotify_get_sb_connectors(conn); @@ -530,7 +515,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, if (cmpxchg(connp, NULL, conn)) { /* Someone else created list structure for us */ if (inode) - fsnotify_put_inode_ref(inode); + iput(inode); fsnotify_put_sb_connectors(conn); kmem_cache_free(fsnotify_mark_connector_cachep, conn); } From patchwork Tue Mar 29 07:48:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794533 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6468DC433FE for ; Tue, 29 Mar 2022 07:49:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233582AbiC2HvO (ORCPT ); Tue, 29 Mar 2022 03:51:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233577AbiC2HvB (ORCPT ); Tue, 29 Mar 2022 03:51:01 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2B081E5221 for ; Tue, 29 Mar 2022 00:49:18 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id m30so23544865wrb.1 for ; Tue, 29 Mar 2022 00:49:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/XoWmjl6KVYrZaYzowYJtOxfIHq+80q2tmcN4NfcC50=; b=bXPIXfMW9QM+ElhDNsNwA0ksXwkmCqcQVk0eC5Ozsfu6jB4W7eLH60nU869gjIAh2C rn7cgWYg8PP7TNtXuP5YmRTJWrNGftwKCeZZXrv17uhMLzG47ecgG0xuqwP0wZt19PiJ Ve1YKKOJ7wuGUskAn57w1Rcesm5GyYOpwWOjyqn9FIV8zepR7U+5j4LpjEhJ4/qOnc8D 0K9lryjqgzxNXuCfZKqw8Z6UqqRtpfVi9oVy6/hCXPzXJHvFn2x6BO9j8gAoOFJNF648 L9QEIsAW8ThU6HhUU+vJuWuOhJMNHLkxJkY2c++d4moQ3h65rghW/kGnvDUYcUuaB0Y8 Mdtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/XoWmjl6KVYrZaYzowYJtOxfIHq+80q2tmcN4NfcC50=; b=FRHiX0dYWpBySBL71gfU9vIc8bZwLvaaDMYdcf7Lqa1vrIVcHOnCkA6sdNXS3oOUqi LflNrPpsM5Meewb80B/enHi9o5U2ZUt8Dz7FGHFA52DlwrFIyTmW+JdD4CqEFaJAf/4h Sh+nHurrdEPyZbTAl7fImlbT58eymTRrFrHa607bJuK18GMC2AcH9e/IZkeFO+shZ4R8 7xvyZmgexgBD0EIJATylD2s3wkWw6BrKbzkfz4k+RQWZfLqcy//PUVD8RYLvJp7Dxu6Y k+QonlACW0UJpJ+POBlPSPI7G4Vjq0f1Fo62VgYSEJCTmj18BeNt7RHYHK4iaxyfLcn8 oRMA== X-Gm-Message-State: AOAM530FGERm0LO/lDlCSnZ589vTBmxHpBcu85ijbqiaNWmvRlAwxLpm lE59IfFp+w43Y6g5Gx87qg9bbdM5uJI= X-Google-Smtp-Source: ABdhPJw25aSwc/I1xS/H7f0Jz0nfo97PGe5DBf7JfusGg5lWW/Yd+e5f1uc5ZZmzI2aZLEiuY6Bacg== X-Received: by 2002:a5d:59a2:0:b0:204:19bc:42ff with SMTP id p2-20020a5d59a2000000b0020419bc42ffmr28958713wrr.687.1648540157102; Tue, 29 Mar 2022 00:49:17 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:16 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 05/16] fsnotify: fix wrong lockdep annotations Date: Tue, 29 Mar 2022 10:48:53 +0300 Message-Id: <20220329074904.2980320-6-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Commit 6960b0d909cd ("fsnotify: change locking order") changed some of the mark_mutex locks in direct reclaim path to use: mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); This change is explained: "...It uses nested locking to avoid deadlock in case we do the final iput() on an inode which still holds marks and thus would take the mutex again when calling fsnotify_inode_delete() in destroy_inode()." The problem is that the mutex_lock_nested() is not a nested lock at all. In fact, it has the opposite effect of preventing lockdep from warning about a very possible deadlock. Due to these wrong annotations, a deadlock that was introduced with nfsd filecache in kernel v5.4 went unnoticed in v5.4.y for over two years until it was reported recently by Khazhismel Kumykov, only to find out that the deadlock was already fixed in kernel v5.5. Fix the wrong lockdep annotations. Cc: Khazhismel Kumykov Fixes: 6960b0d909cd ("fsnotify: change locking order") Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/ Signed-off-by: Amir Goldstein --- fs/notify/mark.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 698ed0a1a47e..3faf47def7d8 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -437,7 +437,7 @@ void fsnotify_free_mark(struct fsnotify_mark *mark) void fsnotify_destroy_mark(struct fsnotify_mark *mark, struct fsnotify_group *group) { - mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&group->mark_mutex); fsnotify_detach_mark(mark); mutex_unlock(&group->mark_mutex); fsnotify_free_mark(mark); @@ -754,7 +754,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, * move marks to free to to_free list in one go and then free marks in * to_free list one by one. */ - mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&group->mark_mutex); list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) { if (mark->connector->type == obj_type) list_move(&mark->g_list, &to_free); @@ -763,7 +763,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, clear: while (1) { - mutex_lock_nested(&group->mark_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&group->mark_mutex); if (list_empty(head)) { mutex_unlock(&group->mark_mutex); break; From patchwork Tue Mar 29 07:48:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794535 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E82D8C433F5 for ; Tue, 29 Mar 2022 07:49:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233602AbiC2HvR (ORCPT ); Tue, 29 Mar 2022 03:51:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233568AbiC2HvD (ORCPT ); Tue, 29 Mar 2022 03:51:03 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAB241E531D for ; Tue, 29 Mar 2022 00:49:19 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id w21so18962652wra.2 for ; Tue, 29 Mar 2022 00:49:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k/F1Ew7dXYUqEaMuDBnlNJujrZTt52AYtu1m8MN13CU=; b=M63RkBdVrSG00tsmuRXpmEKn8ook/LNQOey4o04i9vTd2g6DI2z+FJCbFDYqRFG+f5 BITpnyHRJrV02mX4LSm8nxYzCdEDPKfNiM2MPMAmYyakaIuhmAI0zNyVQE1Ui67ZdfoG CsICX2R6Lcvc3bztjiqPFlgV6l5gfcC2WSO8wXADn3ODWBOrzmfdJU12qqR/5HATmYJx 2fz4u00/+c2WjRkLaGM13VwnwmJkAjtvR2eyVE8Hwq83g5yT9alt2JjoAX92Y91jOYPs VUXzOKCgWbi9u/aVBVph8UmqXS4VGvQh9iUm3kKFgV18aFbEgSJYKFwi+6P9X97HKGJf Etfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=k/F1Ew7dXYUqEaMuDBnlNJujrZTt52AYtu1m8MN13CU=; b=2m+o8kw+zzTAVunKtG6SpnUUHtqL17g9RExJI2gMeCfRjBfo2GZ9xZmOZaa+GAbOx8 6FI1VgCOU2JY0q0/6YMS3O885OTAWmTk+dxJ1DfBa5IO1yG6XS7GK38Q4AZ7fHsLzqSS GiCB6y73qXy2dCpX5ADVzFfo6jNr/fNgTe3OYJATz4Z6HMzNq3SHPMeaCCK7G6Ln1oui UjpmILEuX10vDP8DL9nFHwP0VqN+N+ajUOmBPq9/fFHcUkqPaAzrxEsASxeyxCi6CICN yzZ3Tii1/8jWJNiKxGe8X9bTDrfrmGfE0zvwoFhwLd+KS3RrD82UOFnTIvlsJZA9qsee D5Bg== X-Gm-Message-State: AOAM5335/LFd6/Y2jY5gD9jg5OUUxogspBH4YUdDuMm+C3uCUQd6nMAW XzKYaf1JIGkzvOkTaUNE+7Zn5O0yzk8= X-Google-Smtp-Source: ABdhPJz1JmxhSCh5ThPSBth5Rpvb6KHg65pK5o34hvbJkhEO0vaoHFgUoNqf7vLqiU7yzKAzy1txVg== X-Received: by 2002:a5d:64c4:0:b0:203:f468:c518 with SMTP id f4-20020a5d64c4000000b00203f468c518mr29964837wri.676.1648540158414; Tue, 29 Mar 2022 00:49:18 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:17 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 06/16] fsnotify: create helpers for group mark_mutex lock Date: Tue, 29 Mar 2022 10:48:54 +0300 Message-Id: <20220329074904.2980320-7-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Create helpers to take and release the group mark_mutex lock. Define a flag FSNOTIFY_GROUP_NOFS in fsnotify backend operations struct that determines if the mark_mutex lock is fs reclaim safe or not. If not safe, the nofs lock helpers should be used to take the lock and disable direct fs reclaim. In that case we annotate the mutex with different lockdep class to express to lockdep that an allocation of mark of an fs reclaim safe group may take the group lock of another "NOFS" group to evict inodes. For now, converted only the callers in common code and no backend defines the NOFS flag. It is intended to be set by fanotify for evictable marks support. Suggested-by: Jan Kara Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/ Signed-off-by: Amir Goldstein --- fs/notify/fdinfo.c | 5 ++-- fs/notify/group.c | 11 ++++++++ fs/notify/mark.c | 28 ++++++++++--------- include/linux/fsnotify_backend.h | 48 ++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 15 deletions(-) diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index 3451708fd035..754a546d647d 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c @@ -27,14 +27,15 @@ static void show_fdinfo(struct seq_file *m, struct file *f, { struct fsnotify_group *group = f->private_data; struct fsnotify_mark *mark; + unsigned int nofs; - mutex_lock(&group->mark_mutex); + nofs = fsnotify_group_nofs_lock(group); list_for_each_entry(mark, &group->marks_list, g_list) { show(m, mark); if (seq_has_overflowed(m)) break; } - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); } #if defined(CONFIG_EXPORTFS) diff --git a/fs/notify/group.c b/fs/notify/group.c index b7d4d64f87c2..0f585febf3d7 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -114,6 +114,7 @@ EXPORT_SYMBOL_GPL(fsnotify_put_group); static struct fsnotify_group *__fsnotify_alloc_group( const struct fsnotify_ops *ops, gfp_t gfp) { + static struct lock_class_key nofs_marks_lock; struct fsnotify_group *group; group = kzalloc(sizeof(struct fsnotify_group), gfp); @@ -133,6 +134,16 @@ static struct fsnotify_group *__fsnotify_alloc_group( INIT_LIST_HEAD(&group->marks_list); group->ops = ops; + /* + * For most backends, eviction of inode with a mark is not expected, + * because marks hold a refcount on the inode against eviction. + * + * Use a different lockdep class for groups that support evictable + * inode marks, because with evictable marks, mark_mutex is NOT + * fs-reclaim safe - the mutex is taken when evicting inodes. + */ + if (FSNOTIFY_GROUP_FLAG(group, NOFS)) + lockdep_set_class(&group->mark_mutex, &nofs_marks_lock); return group; } diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 3faf47def7d8..94d53f9d2b5f 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -383,9 +383,7 @@ void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info) */ void fsnotify_detach_mark(struct fsnotify_mark *mark) { - struct fsnotify_group *group = mark->group; - - WARN_ON_ONCE(!mutex_is_locked(&group->mark_mutex)); + fsnotify_group_assert_locked(mark->group); WARN_ON_ONCE(!srcu_read_lock_held(&fsnotify_mark_srcu) && refcount_read(&mark->refcnt) < 1 + !!(mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED)); @@ -437,9 +435,11 @@ void fsnotify_free_mark(struct fsnotify_mark *mark) void fsnotify_destroy_mark(struct fsnotify_mark *mark, struct fsnotify_group *group) { - mutex_lock(&group->mark_mutex); + unsigned int nofs; + + nofs = fsnotify_group_nofs_lock(group); fsnotify_detach_mark(mark); - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); fsnotify_free_mark(mark); } EXPORT_SYMBOL_GPL(fsnotify_destroy_mark); @@ -658,7 +658,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct fsnotify_group *group = mark->group; int ret = 0; - BUG_ON(!mutex_is_locked(&group->mark_mutex)); + fsnotify_group_assert_locked(group); /* * LOCKING ORDER!!!! @@ -697,10 +697,11 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp, { int ret; struct fsnotify_group *group = mark->group; + unsigned int nofs; - mutex_lock(&group->mark_mutex); + nofs = fsnotify_group_nofs_lock(group); ret = fsnotify_add_mark_locked(mark, connp, obj_type, fsid); - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); return ret; } EXPORT_SYMBOL_GPL(fsnotify_add_mark); @@ -739,6 +740,7 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, struct fsnotify_mark *lmark, *mark; LIST_HEAD(to_free); struct list_head *head = &to_free; + unsigned int nofs; /* Skip selection step if we want to clear all marks. */ if (obj_type == FSNOTIFY_OBJ_TYPE_ANY) { @@ -754,24 +756,24 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group, * move marks to free to to_free list in one go and then free marks in * to_free list one by one. */ - mutex_lock(&group->mark_mutex); + nofs = fsnotify_group_nofs_lock(group); list_for_each_entry_safe(mark, lmark, &group->marks_list, g_list) { if (mark->connector->type == obj_type) list_move(&mark->g_list, &to_free); } - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); clear: while (1) { - mutex_lock(&group->mark_mutex); + nofs = fsnotify_group_nofs_lock(group); if (list_empty(head)) { - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); break; } mark = list_first_entry(head, struct fsnotify_mark, g_list); fsnotify_get_mark(mark); fsnotify_detach_mark(mark); - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); fsnotify_free_mark(mark); fsnotify_put_mark(mark); } diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 9e8b5b52b9de..083333ad451c 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -20,6 +20,7 @@ #include #include #include +#include /* * IN_* from inotfy.h lines up EXACTLY with FS_*, this is so we can easily @@ -152,6 +153,10 @@ struct mem_cgroup; * userspace messages that marks have been removed. */ struct fsnotify_ops { +#define FSNOTIFY_GROUP_NOFS 0x01 /* group lock is not direct reclaim safe */ +#define FSNOTIFY_GROUP_FLAG(group, flag) \ + ((group)->ops->group_flags & FSNOTIFY_GROUP_ ## flag) + int group_flags; int (*handle_event)(struct fsnotify_group *group, u32 mask, const void *data, int data_type, struct inode *dir, const struct qstr *file_name, u32 cookie, @@ -250,6 +255,49 @@ struct fsnotify_group { }; }; +/* + * Use this from common code to prevent deadlock when reclaiming inodes with + * evictable marks of the same group that is allocating a new mark. + */ +static inline unsigned int fsnotify_group_nofs_lock( + struct fsnotify_group *group) +{ + unsigned int nofs = current->flags & PF_MEMALLOC_NOFS; + + mutex_lock(&group->mark_mutex); + if (FSNOTIFY_GROUP_FLAG(group, NOFS)) + nofs = memalloc_nofs_save(); + return nofs; +} + +static inline void fsnotify_group_assert_locked(struct fsnotify_group *group) +{ + WARN_ON_ONCE(!mutex_is_locked(&group->mark_mutex)); + if (FSNOTIFY_GROUP_FLAG(group, NOFS)) + WARN_ON_ONCE(!(current->flags & PF_MEMALLOC_NOFS)); +} + +static inline void fsnotify_group_nofs_unlock(struct fsnotify_group *group, + unsigned int nofs) +{ + memalloc_nofs_restore(nofs); + mutex_unlock(&group->mark_mutex); +} + +/* + * Use this from common code that does not allocate memory or from backends + * who are known to be fs reclaim safe (i.e. no evictable inode marks). + */ +static inline void fsnotify_group_lock(struct fsnotify_group *group) +{ + mutex_lock(&group->mark_mutex); +} + +static inline void fsnotify_group_unlock(struct fsnotify_group *group) +{ + mutex_unlock(&group->mark_mutex); +} + /* When calling fsnotify tell it if the data is a path or inode */ enum fsnotify_data_type { FSNOTIFY_EVENT_NONE, From patchwork Tue Mar 29 07:48:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794532 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 785D0C433EF for ; Tue, 29 Mar 2022 07:49:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233593AbiC2HvL (ORCPT ); Tue, 29 Mar 2022 03:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233580AbiC2HvD (ORCPT ); Tue, 29 Mar 2022 03:51:03 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 088851E5A52 for ; Tue, 29 Mar 2022 00:49:21 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id r13so23495326wrr.9 for ; Tue, 29 Mar 2022 00:49:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VqqNHpEqCAgeMCR+4JoMRfMN5/eBIgAPSl5kfRYHVCc=; b=BL/xQBAIfzSYsJpUPXp8bV41ULGl7Atg3+RW0w7JlyreFgLY9AKbdv/Jy9/DDUNK4x Yu1PPWtxWSLNFreluXvj/+94tiBZQUCR0EyU72/JoAMa1GVST8V9cO36Kb2yQjIgHvS8 Me3fwdn2u1j2Ne3ONt07UXiPFvnzgBUJ7AufZplP+76tyHyCLEism6F49v1+RS8lzkkb UmtUWwWEWeGD+GcO696sKzZjKIDhnygJcr/YL72+ejpiuouuEZF+3/z0zFHX1wvT2orx nZ6oEzNZkm/C8xR7jdb4Qngg4ZYwk8JOxdVcDSjsE7vC70k3ZnX4uTXn8FXMcQvrgckU lHgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VqqNHpEqCAgeMCR+4JoMRfMN5/eBIgAPSl5kfRYHVCc=; b=FD5FifDSmnrtgl6B94VznUSkM82MOFU8HZk6i/NIfwLEPGkJOm4mzRKedbtZCwF1Kd qlODlDJ15Cwke+2gStsJOGMYOt+wDxo6aQCKfBn9nEwckO386xVgA4iTuJgQbCF9+Uc3 RiRShioBMJTIBIqVtyp+p2ZJNxE1BcknbngskhFiwk7HiXr6AaMqEFGSq41Xmb3Mj6Rp hgRqXut9iBrJiaSnFDjsq/LHNOBTssHyfs3AKgP5gGEmgAfwcMfRgwXHeaIRFujBA0RE OcI1EtxDuPiF/YZM4ttrLbRotlYaFZ5HTN9OQaLjcLgfgNuArMSQzsMnKNUSABzJVmr2 012g== X-Gm-Message-State: AOAM531atoiHRLjWY39z4xOs3fouRIQeCHNxMOY4ut9kXPREop1qgWWR dg82JbxsHfVimwftxz1Fo5nulG0lqjk= X-Google-Smtp-Source: ABdhPJzIeNhMC1s4LY6wtp9H9TNIDx9kRTxsS+UWJQPuVeGcVorPWbBt/7sak993ikNKMiWbY/RUJQ== X-Received: by 2002:adf:90e9:0:b0:204:2ee:7d5 with SMTP id i96-20020adf90e9000000b0020402ee07d5mr29036409wri.536.1648540159556; Tue, 29 Mar 2022 00:49:19 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:19 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 07/16] inotify: use fsnotify group lock helpers Date: Tue, 29 Mar 2022 10:48:55 +0300 Message-Id: <20220329074904.2980320-8-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org inotify inode marks pin the inode so there is no need to use the nofs lock variants. Suggested-by: Jan Kara Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/ Signed-off-by: Amir Goldstein --- fs/notify/inotify/inotify_user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index 6fc0f598a7aa..060621faa762 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -640,13 +640,13 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod { int ret = 0; - mutex_lock(&group->mark_mutex); + fsnotify_group_lock(group); /* try to update and existing watch with the new arg */ ret = inotify_update_existing_watch(group, inode, arg); /* no mark present, try to add a new one */ if (ret == -ENOENT) ret = inotify_new_watch(group, inode, arg); - mutex_unlock(&group->mark_mutex); + fsnotify_group_unlock(group); return ret; } From patchwork Tue Mar 29 07:48:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794534 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C457FC433F5 for ; Tue, 29 Mar 2022 07:49:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233601AbiC2HvP (ORCPT ); Tue, 29 Mar 2022 03:51:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233581AbiC2HvF (ORCPT ); Tue, 29 Mar 2022 03:51:05 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41CBE1E6E9A for ; Tue, 29 Mar 2022 00:49:22 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id m30so23545036wrb.1 for ; Tue, 29 Mar 2022 00:49:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=341wtVBQDtCet8LPmHDdO5FfeOX27BaJxnIAMj6yiZk=; b=Tk2MCtxx7gNl4lN1UR6B8ooyr+L9r8EVDrOhO9fI+/7bf9a4PHpAbOGSQx9bJNGNaj VsZmBw4rv9IroDUbaAOlNCZMqWHnzAF/GCFg+BRwZLVMvSE6eupmwdDALo060Larug5q 1ICw2nQKa3rmo7FDWAGaf60kP+qXfMicA9CAs3SeMGVowlTZGPpi6+5ApgC4cWrfyk4w 4FtQYh+vkwK11KR+oH2PKRtGjX1oXodVprE6PdPyZtDTLvrkPh8kBMBWx9p6qwlpW1Wp PWmmQGSbZ7EsHIiHWAsIgU5PhIPhW1Wh0CIYHEHWm/lN+tAm6cCxrEoL/COWnsTPgJLR c9Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=341wtVBQDtCet8LPmHDdO5FfeOX27BaJxnIAMj6yiZk=; b=Ak3QsHw+evZ/08PFF7A5GTR2VWxMdDgqa/0hgF81qlrITF8ZZ3o64/MxZ9lTKq+VJX +YhjkNuqx64L2/pGnwtqVxIfD2obteeoD8JUIz330Ry9g2J8cSKzwxrgC0bj8lUJVu8A Gyn6NIY25pJEHB82DV+/hQOtwJXQwKWhHM7fHVX+fBM/XSNSGrTnambIltx4lyLWKu0f CJZlrAQI6TCSMsrgM/QVl/4g3tfdmzgQzIuWgWOj/tw7vewKmL+bTei+4zEnWbUT2Cd9 PbJEfKHuFF7+jkSPprEwUoCbOhnSUcR0JcK5HXRf/rYhkqtLC/AdTuHN5aN2uVdLKHP5 Pk5Q== X-Gm-Message-State: AOAM531cQ1d8uECdhsgbqcMzsarxycp6oeSHXbwS83g9Oxh0ul7hTheW EYlffrW9V+fs/FQNwCHYOms= X-Google-Smtp-Source: ABdhPJz39UmsWqFC1yYgWjfulCAQxGzrE0I96Lv1IDpEQ/QIk8S23fIhymRm461JJh440bUysO4LhQ== X-Received: by 2002:a05:6000:178f:b0:204:16f0:8e2c with SMTP id e15-20020a056000178f00b0020416f08e2cmr30356180wrg.127.1648540160693; Tue, 29 Mar 2022 00:49:20 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:20 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 08/16] audit: use fsnotify group lock helpers Date: Tue, 29 Mar 2022 10:48:56 +0300 Message-Id: <20220329074904.2980320-9-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org audit inode marks pin the inode so there is no need to use the nofs lock variants. Suggested-by: Jan Kara Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/ Signed-off-by: Amir Goldstein --- kernel/audit_tree.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c index e7315d487163..eaef9c0f1c10 100644 --- a/kernel/audit_tree.c +++ b/kernel/audit_tree.c @@ -351,7 +351,7 @@ static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark) struct audit_chunk *new; int size; - mutex_lock(&audit_tree_group->mark_mutex); + fsnotify_group_lock(audit_tree_group); /* * mark_mutex stabilizes chunk attached to the mark so we can check * whether it didn't change while we've dropped hash_lock. @@ -368,7 +368,7 @@ static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark) replace_mark_chunk(mark, NULL); spin_unlock(&hash_lock); fsnotify_detach_mark(mark); - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); audit_mark_put_chunk(chunk); fsnotify_free_mark(mark); return; @@ -385,12 +385,12 @@ static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark) */ replace_chunk(new, chunk); spin_unlock(&hash_lock); - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); audit_mark_put_chunk(chunk); return; out_mutex: - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); } /* Call with group->mark_mutex held, releases it */ @@ -400,19 +400,19 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree) struct audit_chunk *chunk = alloc_chunk(1); if (!chunk) { - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); return -ENOMEM; } mark = alloc_mark(); if (!mark) { - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); kfree(chunk); return -ENOMEM; } if (fsnotify_add_inode_mark_locked(mark, inode, 0)) { - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); fsnotify_put_mark(mark); kfree(chunk); return -ENOSPC; @@ -422,7 +422,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree) if (tree->goner) { spin_unlock(&hash_lock); fsnotify_detach_mark(mark); - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); fsnotify_free_mark(mark); fsnotify_put_mark(mark); kfree(chunk); @@ -444,7 +444,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree) */ insert_hash(chunk); spin_unlock(&hash_lock); - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); /* * Drop our initial reference. When mark we point to is getting freed, * we get notification through ->freeing_mark callback and cleanup @@ -462,7 +462,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) struct audit_node *p; int n; - mutex_lock(&audit_tree_group->mark_mutex); + fsnotify_group_lock(audit_tree_group); mark = fsnotify_find_mark(&inode->i_fsnotify_marks, audit_tree_group); if (!mark) return create_chunk(inode, tree); @@ -478,7 +478,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) for (n = 0; n < old->count; n++) { if (old->owners[n].owner == tree) { spin_unlock(&hash_lock); - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); fsnotify_put_mark(mark); return 0; } @@ -487,7 +487,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) chunk = alloc_chunk(old->count + 1); if (!chunk) { - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); fsnotify_put_mark(mark); return -ENOMEM; } @@ -495,7 +495,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) spin_lock(&hash_lock); if (tree->goner) { spin_unlock(&hash_lock); - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); fsnotify_put_mark(mark); kfree(chunk); return 0; @@ -515,7 +515,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) */ replace_chunk(chunk, old); spin_unlock(&hash_lock); - mutex_unlock(&audit_tree_group->mark_mutex); + fsnotify_group_unlock(audit_tree_group); fsnotify_put_mark(mark); /* pair to fsnotify_find_mark */ audit_mark_put_chunk(old); @@ -1044,12 +1044,12 @@ static void audit_tree_freeing_mark(struct fsnotify_mark *mark, { struct audit_chunk *chunk; - mutex_lock(&mark->group->mark_mutex); + fsnotify_group_lock(mark->group); spin_lock(&hash_lock); chunk = mark_chunk(mark); replace_mark_chunk(mark, NULL); spin_unlock(&hash_lock); - mutex_unlock(&mark->group->mark_mutex); + fsnotify_group_unlock(mark->group); if (chunk) { evict_chunk(chunk); audit_mark_put_chunk(chunk); From patchwork Tue Mar 29 07:48:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794536 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B009DC433EF for ; Tue, 29 Mar 2022 07:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233603AbiC2HvT (ORCPT ); Tue, 29 Mar 2022 03:51:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233584AbiC2HvK (ORCPT ); Tue, 29 Mar 2022 03:51:10 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 657E31E7452 for ; Tue, 29 Mar 2022 00:49:23 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id k124-20020a1ca182000000b0038c9cf6e2a6so950202wme.0 for ; Tue, 29 Mar 2022 00:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gNHmQfdW9fAdfJsuOOGbavQtw86ytVUNrHym0e+zLfE=; b=bhzt3sYzCkOBO47uEMXBfD3KWmO5Wypui8tfzpHNVoMgfJptGfM62wEA3MZXSH+ho7 NHNleFGQlFngaqwPS04OnzvXB3NQk4bVhHtpFgbhaGsqyVCg4rBcD8E06CCTHFIsU+fG DJgRunDw/oO1HFo4eCvznT8vKMMTiebu51hF10BHDmm+K9D7nvcNkbj42lEMO+7T8JC1 oUusiRIxYaakDeuXGNYZCLoh6UKZpC+YWUBYIcMh1FSvML7iUkodp2QU0LnJORBedgDE FyIZKC8QEjvxgkBmPHgXAJnHSwWjMGHutWHZAqsBhghi3Xpl8lzWUzzbPBe5M1h9/q7M Kcvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gNHmQfdW9fAdfJsuOOGbavQtw86ytVUNrHym0e+zLfE=; b=C0PGL44NQ3h2LX37y7aRujXWD0TWpsgVa022Xpywws6MpJRmT1mPdRW1gnVoIeRPVB EhxbpTJyqUR7N5MK4q9FS0tgtssKy0Jh5bkzCEXr9RVIRECayV49tkBwpAuoJvbvKNCq ZHDlk7Rsm5I6iM5lIrh3otCxniHbfQuNv+ivqeCaqbhNLkSy1/+xu2pbtcmKMiBkj3Ii 8GTGe4pNN8lSxyYv8a+MKMmenGv9ZpFZQMzFHk1kz1akjFkCVi5TRmQKDLUZ6hRXSVEi ePU0gm2Jq4Z1tsI/vI3oLZeYKnMfytsGLOIpHoums7RoiB1/qBunfYjgJc+LcQGinyw5 8XBg== X-Gm-Message-State: AOAM531jds/teBMGAkqaGmeDT3ISn4Y3tyn/gX20XT9XbqVDTEMGIPDQ FGXq/I6rYpB++dz3O3vqIXJZkWTLHrI= X-Google-Smtp-Source: ABdhPJyOmiobtUguFLLwC7iyDxYrtCKAIQlFRwjhxn+wl3tAD3dzADSrh8s7ni5gebhFtJNzGhSKLw== X-Received: by 2002:a05:600c:4ec8:b0:38c:90fb:d3bf with SMTP id g8-20020a05600c4ec800b0038c90fbd3bfmr5020226wmq.0.1648540161956; Tue, 29 Mar 2022 00:49:21 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:21 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 09/16] nfsd: use fsnotify group lock helpers Date: Tue, 29 Mar 2022 10:48:57 +0300 Message-Id: <20220329074904.2980320-10-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Before commit 9542e6a643fc6 ("nfsd: Containerise filecache laundrette") nfsd would close open files in direct reclaim context and that could cause a deadlock when fsnotify mark allocation went into direct reclaim and nfsd shrinker tried to free existing fsnotify marks. To avoid issues like this in future code, set the FSNOTIFY_GROUP_NOFS flag on nfsd fsnotify group to prevent going into direct reclaim from fsnotify_add_inode_mark(). The lookup of fsnotify mark does not allocate memory so the nofs variants of fsnotify group helpers are not needed. Suggested-by: Jan Kara Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/ Signed-off-by: Amir Goldstein --- fs/nfsd/filecache.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 8bc807c5fea4..0a104e530934 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -118,14 +118,14 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf) struct inode *inode = nf->nf_inode; do { - mutex_lock(&nfsd_file_fsnotify_group->mark_mutex); + fsnotify_group_lock(nfsd_file_fsnotify_group); mark = fsnotify_find_mark(&inode->i_fsnotify_marks, - nfsd_file_fsnotify_group); + nfsd_file_fsnotify_group); if (mark) { nfm = nfsd_file_mark_get(container_of(mark, struct nfsd_file_mark, nfm_mark)); - mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex); + fsnotify_group_unlock(nfsd_file_fsnotify_group); if (nfm) { fsnotify_put_mark(mark); break; @@ -133,8 +133,9 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf) /* Avoid soft lockup race with nfsd_file_mark_put() */ fsnotify_destroy_mark(mark, nfsd_file_fsnotify_group); fsnotify_put_mark(mark); - } else - mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex); + } else { + fsnotify_group_unlock(nfsd_file_fsnotify_group); + } /* allocate a new nfm */ new = kmem_cache_alloc(nfsd_file_mark_slab, GFP_KERNEL); @@ -613,6 +614,7 @@ nfsd_file_fsnotify_handle_event(struct fsnotify_mark *mark, u32 mask, static const struct fsnotify_ops nfsd_file_fsnotify_ops = { + .group_flags = FSNOTIFY_GROUP_NOFS, .handle_inode_event = nfsd_file_fsnotify_handle_event, .free_mark = nfsd_file_mark_free, }; From patchwork Tue Mar 29 07:48:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794537 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53BB4C433F5 for ; Tue, 29 Mar 2022 07:49:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233607AbiC2HvW (ORCPT ); Tue, 29 Mar 2022 03:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233586AbiC2HvK (ORCPT ); Tue, 29 Mar 2022 03:51:10 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 075661E8CC5 for ; Tue, 29 Mar 2022 00:49:25 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id p189so9727185wmp.3 for ; Tue, 29 Mar 2022 00:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dgYXuFaXAE2oHVSuPm5rYzIav77e+tMyW29cgBh+Tss=; b=DtBY7KmdeHjMq9p+du9SYA2ulY2G268Sci+509iBb758MFMAFrIa8e2uM+gaicXwhb WVE0wmgmJ+Iw5zi/HfHGMCxo5kAELKGZ7wd+BmPmZNDOHTOoap4HKoy884M9Am1gwiMU OzLFinB6X7vywyGLi/8zux86xAfSq97CfH3TnrhqCGKJzB0z1eIQpOmJ9t0CsbY9rJw/ hxKcMX2xNjFR1bLQI1ZUBcQ7Oa2VcmoGcyMEysJeY4hhEq8k5KPuIjRy3msnbu0WLcYf iLoLkdBDWdSJQC4MFzqW4VYHdT9r/2jk8TW9HuM0jUJULqhz6CQjAaL5XJ6k0qQ/Izgj X22Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dgYXuFaXAE2oHVSuPm5rYzIav77e+tMyW29cgBh+Tss=; b=oSF5EgI1Fvydf0OxLgoz78oChJA3zCow2Gjw5fdz8QB+y9D4oKWlIpHEONcKFqFavU 2FFpbtJ7jgqv2Fvn6gEUvyRjLpQfwK/QeQ+wEjqctDyeTQ7RrpsggtU91lY41uCjpzVq zFNabCf1gvZPUpA18Z1EAxeEoPZAebynuqxcwYU0BuVzMhXYNw+CyEmgNs0h7xsnlPyk cmuFQ3KI8VaCfweSx6bTfOkdNXM25KNOsPE+G6MYfLRaXoODnusESMB0Opx60bKrC32V eUEk8l8K5aOnxxXvJsBJuxcL0sbmS7JR0Gt5hVb6HQQNIyoEgZrzcjWtS7wwvu9Ctf64 vKyw== X-Gm-Message-State: AOAM533X8fixdkorHQfu0NLuXTfqzSQIG5/Hq65xDNKDy4zmLcqiLQTc TByrjQX+quMWMjgNfdDB2Oo= X-Google-Smtp-Source: ABdhPJx72uWSZvZ796rsfK8DIG5F4KCuTRo3XCTgShZO9yMbR/BV/NSKGi5Xq2eQM4btG4vYtfUDJA== X-Received: by 2002:a7b:c14c:0:b0:381:32fb:a128 with SMTP id z12-20020a7bc14c000000b0038132fba128mr5142335wmi.116.1648540163597; Tue, 29 Mar 2022 00:49:23 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:22 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 10/16] dnotify: use fsnotify group lock helpers Date: Tue, 29 Mar 2022 10:48:58 +0300 Message-Id: <20220329074904.2980320-11-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Before commit 9542e6a643fc6 ("nfsd: Containerise filecache laundrette") nfsd would close open files in direct reclaim context. There is no guarantee that others memory shrinkers don't do the same and no guarantee that future shrinkers won't do that. For example, if overlayfs implements inode cache of fscache would keep open files to cached objects, inode shrinkers could end up closing open files to underlying fs. Direct reclaim from dnotify mark allocation context may try to close open files that have dnotify marks of the same group and hit a deadlock on mark_mutex. Set the FSNOTIFY_GROUP_NOFS flag to prevent going into direct reclaim from allocations under dnotify group lock and use the nofs group lock helpers. Suggested-by: Jan Kara Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/ Signed-off-by: Amir Goldstein --- fs/notify/dnotify/dnotify.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index 829dd4a61b66..b291141104ea 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -139,6 +139,7 @@ static void dnotify_free_mark(struct fsnotify_mark *fsn_mark) } static const struct fsnotify_ops dnotify_fsnotify_ops = { + .group_flags = FSNOTIFY_GROUP_NOFS, .handle_inode_event = dnotify_handle_event, .free_mark = dnotify_free_mark, }; @@ -158,6 +159,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id) struct dnotify_struct **prev; struct inode *inode; bool free = false; + unsigned int nofs; inode = file_inode(filp); if (!S_ISDIR(inode->i_mode)) @@ -168,7 +170,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id) return; dn_mark = container_of(fsn_mark, struct dnotify_mark, fsn_mark); - mutex_lock(&dnotify_group->mark_mutex); + nofs = fsnotify_group_nofs_lock(dnotify_group); spin_lock(&fsn_mark->lock); prev = &dn_mark->dn; @@ -191,7 +193,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id) free = true; } - mutex_unlock(&dnotify_group->mark_mutex); + fsnotify_group_nofs_unlock(dnotify_group, nofs); if (free) fsnotify_free_mark(fsn_mark); @@ -267,6 +269,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) fl_owner_t id = current->files; struct file *f; int destroy = 0, error = 0; + unsigned int nofs; __u32 mask; /* we use these to tell if we need to kfree */ @@ -324,7 +327,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) new_dn_mark->dn = NULL; /* this is needed to prevent the fcntl/close race described below */ - mutex_lock(&dnotify_group->mark_mutex); + nofs = fsnotify_group_nofs_lock(dnotify_group); /* add the new_fsn_mark or find an old one. */ fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, dnotify_group); @@ -334,7 +337,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) } else { error = fsnotify_add_inode_mark_locked(new_fsn_mark, inode, 0); if (error) { - mutex_unlock(&dnotify_group->mark_mutex); + fsnotify_group_nofs_unlock(dnotify_group, nofs); goto out_err; } spin_lock(&new_fsn_mark->lock); @@ -383,7 +386,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) if (destroy) fsnotify_detach_mark(fsn_mark); - mutex_unlock(&dnotify_group->mark_mutex); + fsnotify_group_nofs_unlock(dnotify_group, nofs); if (destroy) fsnotify_free_mark(fsn_mark); fsnotify_put_mark(fsn_mark); From patchwork Tue Mar 29 07:48:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794538 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6F77C433F5 for ; Tue, 29 Mar 2022 07:49:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233608AbiC2HvW (ORCPT ); Tue, 29 Mar 2022 03:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233587AbiC2HvK (ORCPT ); Tue, 29 Mar 2022 03:51:10 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AD8A1E521C for ; Tue, 29 Mar 2022 00:49:26 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id a1so23508477wrh.10 for ; Tue, 29 Mar 2022 00:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ts3mTqn+OR+1m0lFg26zb/XHneWH9pyV4TFEIfdRYus=; b=Tzx/pGbfbrIRF19xD2nqGwr6nuRfACofKq1NbaG1GZ8EdKOS/3In9GvEKKIIFv3P9R dUbMn7tGfzCP6NLt4rqFxbYZuDBcc+rD1zAesL+FCDsX82YHuGXAcvEVx3XrXXiN5YZO sf4zKTw0Jql+JcyjTz3yY5F1zf03gFXY7QboxNjkP7JS+WGiy0h9t5MNEWKsLLdAjE46 bqzyoue9yfXRBW0s20Zpwao4zNAW8M8I/DqsafjIBxRRJoqeEJH2t6R00ysCB/tqqezE p5rBuNvvhwy/9pUqWDrnu+sVrcxiYQwLSh0wrh9eHyzfgWRjEWV3lHuiVmGDNw4kSQLN B8og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ts3mTqn+OR+1m0lFg26zb/XHneWH9pyV4TFEIfdRYus=; b=QBZFcRvhok9Avi47bAFv8rRf+AYXKFxHNtKjFS0ZMC5sKdkXpu7s9/cIprjS/OlcbJ 4E115iAzXXrnjfGrSKuic+1PGk1SNPkYFHWLO0a63n3lO2De2Q40966SSNsi/ssEcdoC /0rkuWhg3S8olDvZHUvLlLArvIUUyz74x6lfuLWIVOxFzpTQKqgSlAYyG+c+N4Cd42JI BbBdCSjOZJdD9zR/wLjCCMJyn/Cgq0nmSL8Lb/TiD0Dk1M0pY5Vrrlnq6GhLnjbnJiLC FRgpWpRFD3XktQka/wOgDVrn+AQHbfCCnKRUUFn9wyhpVf5Bun4rUnLchpCy25vKClUo xKwg== X-Gm-Message-State: AOAM531NFg9oTikOR/l9mV9gvYiziQxcQvuE+fgLApnFTNAdOyLWZ/cE IWqJviUnLaKM4V4S2tnhIP/SWBen0aY= X-Google-Smtp-Source: ABdhPJwvDKKo1/6LImFNdzO5MN2TWcH6k4e9v7S0PGB096hk/NLVzsxdraF4niXjiXlXc4NWvUlZUA== X-Received: by 2002:a5d:4688:0:b0:203:f0cc:da10 with SMTP id u8-20020a5d4688000000b00203f0ccda10mr29213470wrq.87.1648540164804; Tue, 29 Mar 2022 00:49:24 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:24 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 11/16] fsnotify: allow adding an inode mark without pinning inode Date: Tue, 29 Mar 2022 10:48:59 +0300 Message-Id: <20220329074904.2980320-12-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org fsnotify_add_mark() and variants implicitly take a reference on inode when attaching a mark to an inode. Make that behavior opt-out with the mark flag FSNOTIFY_MARK_FLAG_NO_IREF. Instead of taking the inode reference when attaching connector to inode and dropping the inode reference when detaching connector from inode, take the inode reference on attach of the first mark that wants to hold an inode reference and drop the inode reference on detach of the last mark that wants to hold an inode reference. Backends can "upgrade" an existing mark to take an inode reference, but cannot "downgrade" a mark with inode reference to release the refernce. This leaves the choice to the backend whether or not to pin the inode when adding an inode mark. This is intended to be used when adding a mark with ignored mask that is used for optimization in cases where group can afford getting unneeded events and reinstate the mark with ignored mask when inode is accessed again after being evicted. Signed-off-by: Amir Goldstein --- fs/notify/mark.c | 68 +++++++++++++++++++++++++------- include/linux/fsnotify_backend.h | 2 + 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/fs/notify/mark.c b/fs/notify/mark.c index 94d53f9d2b5f..3e4de16c0593 100644 --- a/fs/notify/mark.c +++ b/fs/notify/mark.c @@ -116,20 +116,61 @@ __u32 fsnotify_conn_mask(struct fsnotify_mark_connector *conn) return *fsnotify_conn_mask_p(conn); } -static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) +/* + * Update the proxy refcount on inode maintainted by connector. + * + * When it's time to drop the proxy refcount, clear the HAS_IREF flag + * and return the inode object. fsnotify_drop_object() will be resonsible + * for doing iput() outside of spinlocks when last mark that wanted iref + * is detached. + * + * Note that the proxy refcount is NOT dropped if backend only sets the + * NO_IREF mark flag and does detach the mark! + */ +static struct inode *fsnotify_update_iref(struct fsnotify_mark_connector *conn, + bool want_iref) +{ + bool has_iref = conn->flags & FSNOTIFY_CONN_FLAG_HAS_IREF; + struct inode *inode = NULL; + + if (conn->type != FSNOTIFY_OBJ_TYPE_INODE || + want_iref == has_iref) + return NULL; + + if (want_iref) { + /* Pin inode if any mark wants inode refcount held */ + ihold(fsnotify_conn_inode(conn)); + conn->flags |= FSNOTIFY_CONN_FLAG_HAS_IREF; + } else { + /* Unpin inode after detach of last mark that wanted iref */ + inode = fsnotify_conn_inode(conn); + conn->flags &= ~FSNOTIFY_CONN_FLAG_HAS_IREF; + } + + return inode; +} + +static void *__fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) { u32 new_mask = 0; + bool want_iref = false; struct fsnotify_mark *mark; assert_spin_locked(&conn->lock); /* We can get detached connector here when inode is getting unlinked. */ if (!fsnotify_valid_obj_type(conn->type)) - return; + return NULL; hlist_for_each_entry(mark, &conn->list, obj_list) { - if (mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED) - new_mask |= fsnotify_calc_mask(mark); + if (!(mark->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) + continue; + new_mask |= fsnotify_calc_mask(mark); + if (conn->type == FSNOTIFY_OBJ_TYPE_INODE && + !(mark->flags & FSNOTIFY_MARK_FLAG_NO_IREF)) + want_iref = true; } *fsnotify_conn_mask_p(conn) = new_mask; + + return fsnotify_update_iref(conn, want_iref); } /* @@ -198,6 +239,10 @@ static void *fsnotify_detach_connector_from_object( if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { inode = fsnotify_conn_inode(conn); inode->i_fsnotify_mask = 0; + + /* Unpin inode when detaching from connector */ + if (!(conn->flags & FSNOTIFY_CONN_FLAG_HAS_IREF)) + inode = NULL; } else if (conn->type == FSNOTIFY_OBJ_TYPE_VFSMOUNT) { fsnotify_conn_mount(conn)->mnt_fsnotify_mask = 0; } else if (conn->type == FSNOTIFY_OBJ_TYPE_SB) { @@ -208,6 +253,7 @@ static void *fsnotify_detach_connector_from_object( rcu_assign_pointer(*(conn->obj), NULL); conn->obj = NULL; conn->type = FSNOTIFY_OBJ_TYPE_DETACHED; + conn->flags = 0; return inode; } @@ -259,7 +305,8 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) objp = fsnotify_detach_connector_from_object(conn, &type); free_conn = true; } else { - __fsnotify_recalc_mask(conn); + objp = __fsnotify_recalc_mask(conn); + type = conn->type; } WRITE_ONCE(mark->connector, NULL); spin_unlock(&conn->lock); @@ -484,7 +531,6 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, unsigned int obj_type, __kernel_fsid_t *fsid) { - struct inode *inode = NULL; struct fsnotify_mark_connector *conn; conn = kmem_cache_alloc(fsnotify_mark_connector_cachep, GFP_KERNEL); @@ -492,6 +538,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, return -ENOMEM; spin_lock_init(&conn->lock); INIT_HLIST_HEAD(&conn->list); + conn->flags = 0; conn->type = obj_type; conn->obj = connp; /* Cache fsid of filesystem containing the object */ @@ -502,10 +549,6 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, conn->fsid.val[0] = conn->fsid.val[1] = 0; conn->flags = 0; } - if (conn->type == FSNOTIFY_OBJ_TYPE_INODE) { - inode = fsnotify_conn_inode(conn); - ihold(inode); - } fsnotify_get_sb_connectors(conn); /* @@ -514,8 +557,6 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, */ if (cmpxchg(connp, NULL, conn)) { /* Someone else created list structure for us */ - if (inode) - iput(inode); fsnotify_put_sb_connectors(conn); kmem_cache_free(fsnotify_mark_connector_cachep, conn); } @@ -677,8 +718,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, if (ret) goto err; - if (mark->mask || mark->ignored_mask) - fsnotify_recalc_mask(mark->connector); + fsnotify_recalc_mask(mark->connector); return ret; err: diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 083333ad451c..df58439a86fa 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -472,6 +472,7 @@ struct fsnotify_mark_connector { spinlock_t lock; unsigned short type; /* Type of object [lock] */ #define FSNOTIFY_CONN_FLAG_HAS_FSID 0x01 +#define FSNOTIFY_CONN_FLAG_HAS_IREF 0x02 unsigned short flags; /* flags [lock] */ __kernel_fsid_t fsid; /* fsid of filesystem containing object */ union { @@ -526,6 +527,7 @@ struct fsnotify_mark { #define FSNOTIFY_MARK_FLAG_IN_ONESHOT 0x0020 #define FSNOTIFY_MARK_FLAG_ALLOW_DUPS 0x0040 #define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY 0x0100 +#define FSNOTIFY_MARK_FLAG_NO_IREF 0x0200 unsigned int flags; /* flags [mark->lock] */ }; From patchwork Tue Mar 29 07:49:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794539 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3883C433EF for ; Tue, 29 Mar 2022 07:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233609AbiC2HvZ (ORCPT ); Tue, 29 Mar 2022 03:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233591AbiC2HvL (ORCPT ); Tue, 29 Mar 2022 03:51:11 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98FD51E95DB for ; Tue, 29 Mar 2022 00:49:27 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id b19so23487448wrh.11 for ; Tue, 29 Mar 2022 00:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7Xee4LQq4xG5i5yaYMFWrpevH6Upht1xrdhxPOrxCR0=; b=MLMefGBiaGnER1HtulwdRzbsoJ+EGnjNhuV3EUQTomnRTxQMOdmIqux73Hopa5jdks SLBGAKxz+1TFdhPJu1OIKdFG1h/Wo3I9tAfl/SB6Dhp8JEr8NSEwdOHF+lRfzrwnFUDK tJT/tVRyrAefOVIOqFRhgZFcMTmReUhpejlup5vzGNXmfMM5xFmYLepPBvvgmjVclTtu FcGBuLjGBznOjbGKlQWR80z+XgQlLRPyPmQOgdRI6OdL20+A2wX2HqCf+oG7oFlIi8l+ MuK/bTRh77081Iz/Hd+KMuIwhQB/ezQUCPiZA8xedBxoPURVbBgzn1hFRlElC0yMWdK4 2L1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Xee4LQq4xG5i5yaYMFWrpevH6Upht1xrdhxPOrxCR0=; b=0mdKhvSKdbqDkAgqdzm6YeQ3EpyF/zjJQfVYicQD4fETd5GAL6eOpHesJGGSRlgQp8 AZj26GQ6ovDsbidWEQvT2et2XJuAJeH3ed/blFcDvHCWprvQk6uGknVIA1NKJL/mUMv8 Ly02L9G5ote1eIf4hLQg2/V0jHUCe85ypxEiPRJsmSFJWI4tDMvdYIkhg1v/zHXNy3FB 44v2m24kYX9tStx8otSkJmlXsboq70IKlDwjV8GR9wU3eOD1wtoPQAx7fSgQTeFCNgu1 C7gK1qNiwYJt0/JgeiyA4eMrj9ATeAk7Bs+oRBufeZAn2/o9ZcWLfRhfTlQJqlBa45yD J6og== X-Gm-Message-State: AOAM5311ocVloxHmEiJAVVNUWNakbFEUYMs8aslX0TBnIrHBtSbvBoqK 3ekgGb/e+vIIcwlzV88YexbD+yVuFBA= X-Google-Smtp-Source: ABdhPJwlETquIhqVemuxVeDZi1gS9HUlSY85DYnlwhaYu2/XNZipgElMyaQu+BhGy8iZFjO9nyQ1xQ== X-Received: by 2002:a05:6000:508:b0:1e4:a027:d147 with SMTP id a8-20020a056000050800b001e4a027d147mr29392796wrf.315.1648540166166; Tue, 29 Mar 2022 00:49:26 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:25 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 12/16] fanotify: factor out helper fanotify_mark_update_flags() Date: Tue, 29 Mar 2022 10:49:00 +0300 Message-Id: <20220329074904.2980320-13-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Handle FAN_MARK_IGNORED_SURV_MODIFY flag change in a helper that is called after updating the mark mask. Move recalc of object mask inside fanotify_mark_add_to_mask() which makes the code a bit simpler to follow. Add also helper to translate fsnotify mark flags to user visible fanotify mark flags. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.h | 10 ++++++++ fs/notify/fanotify/fanotify_user.c | 39 +++++++++++++++++------------- fs/notify/fdinfo.c | 6 ++--- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index a3d5b751cac5..87142bc0131a 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -490,3 +490,13 @@ static inline unsigned int fanotify_event_hash_bucket( { return event->hash & FANOTIFY_HTABLE_MASK; } + +static inline unsigned int fanotify_mark_user_flags(struct fsnotify_mark *mark) +{ + unsigned int mflags = 0; + + if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY) + mflags |= FAN_MARK_IGNORED_SURV_MODIFY; + + return mflags; +} diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 0f0db1efa379..6e78ea12239c 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1081,42 +1081,50 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group, flags, umask); } -static void fanotify_mark_add_ignored_mask(struct fsnotify_mark *fsn_mark, - __u32 mask, unsigned int flags, - __u32 *removed) +static int fanotify_mark_update_flags(struct fsnotify_mark *fsn_mark, + unsigned int flags, bool *recalc) { - fsn_mark->ignored_mask |= mask; - /* * Setting FAN_MARK_IGNORED_SURV_MODIFY for the first time may lead to * the removal of the FS_MODIFY bit in calculated mask if it was set * because of an ignored mask that is now going to survive FS_MODIFY. */ if ((flags & FAN_MARK_IGNORED_SURV_MODIFY) && + (flags & FAN_MARK_IGNORED_MASK) && !(fsn_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY)) { fsn_mark->flags |= FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY; if (!(fsn_mark->mask & FS_MODIFY)) - *removed = FS_MODIFY; + *recalc = true; } + + return 0; } -static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark, - __u32 mask, unsigned int flags, - __u32 *removed) +static int fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark, + __u32 mask, unsigned int flags) { - __u32 oldmask, newmask; + __u32 oldmask; + bool recalc = false; + int ret; spin_lock(&fsn_mark->lock); oldmask = fsnotify_calc_mask(fsn_mark); if (!(flags & FAN_MARK_IGNORED_MASK)) { fsn_mark->mask |= mask; } else { - fanotify_mark_add_ignored_mask(fsn_mark, mask, flags, removed); + fsn_mark->ignored_mask |= mask; } - newmask = fsnotify_calc_mask(fsn_mark); + + recalc = fsnotify_calc_mask(fsn_mark) & ~oldmask & + ~fsnotify_conn_mask(fsn_mark->connector); + + ret = fanotify_mark_update_flags(fsn_mark, flags, &recalc); spin_unlock(&fsn_mark->lock); - return newmask & ~oldmask; + if (recalc) + fsnotify_recalc_mask(fsn_mark->connector); + + return ret; } static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, @@ -1174,7 +1182,6 @@ static int fanotify_add_mark(struct fsnotify_group *group, __kernel_fsid_t *fsid) { struct fsnotify_mark *fsn_mark; - __u32 added, removed = 0; int ret = 0; mutex_lock(&group->mark_mutex); @@ -1197,9 +1204,7 @@ static int fanotify_add_mark(struct fsnotify_group *group, goto out; } - added = fanotify_mark_add_to_mask(fsn_mark, mask, flags, &removed); - if (removed || (added & ~fsnotify_conn_mask(fsn_mark->connector))) - fsnotify_recalc_mask(fsn_mark->connector); + ret = fanotify_mark_add_to_mask(fsn_mark, mask, flags); out: mutex_unlock(&group->mark_mutex); diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index 754a546d647d..9f81adada3c8 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c @@ -14,6 +14,7 @@ #include #include "inotify/inotify.h" +#include "fanotify/fanotify.h" #include "fdinfo.h" #include "fsnotify.h" @@ -104,12 +105,9 @@ void inotify_show_fdinfo(struct seq_file *m, struct file *f) static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) { - unsigned int mflags = 0; + unsigned int mflags = fanotify_mark_user_flags(mark); struct inode *inode; - if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY) - mflags |= FAN_MARK_IGNORED_SURV_MODIFY; - if (mark->connector->type == FSNOTIFY_OBJ_TYPE_INODE) { inode = igrab(fsnotify_conn_inode(mark->connector)); if (!inode) From patchwork Tue Mar 29 07:49:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794540 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08F86C4332F for ; Tue, 29 Mar 2022 07:49:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233612AbiC2HvZ (ORCPT ); Tue, 29 Mar 2022 03:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233585AbiC2HvL (ORCPT ); Tue, 29 Mar 2022 03:51:11 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01F511E5221 for ; Tue, 29 Mar 2022 00:49:29 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id p26-20020a05600c1d9a00b0038ccbff1951so598986wms.1 for ; Tue, 29 Mar 2022 00:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ghLob7pz1z6BVvec+MhphEZOFMWIi6TQWa4rgtOFJik=; b=DUVxAPYarFHXJphSyMv3+yUz3X3BwudNNfBpRQn0PJfnzmcomE+hLNjMqrAsiduWWV OpupioN/1lKhjlzOGsOtmSeeziH/c3R0NclOjsBKtw1SYXcMGm+4KoUBcVibmNdD+yLn DehU78HORsqWAteBYeOH14W2bVK/z9nInuelGcU88K3Wp9PWePAaA3VUw0La1a3PBMNi 2o6wEhM4deeQopYCjLTYl1iMfDu2gp8UdWE+UT5Ki32/1YX8DDYpge9oq6T6TCLbqK2Q hquvoPi2G+Zb4AYn8XztYyKJMyiRuORHhVofHvsFgm4JSFZADtlTM5bV9Z1t0EGrzXjN wliQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ghLob7pz1z6BVvec+MhphEZOFMWIi6TQWa4rgtOFJik=; b=7z29K8rjz7tqof5ojOjrRxAFd66CRS9FCcUsuzfGFX2Ha51jOehP4SjAEobbhmO8AU 8rCkKSGYJ7jqjtnGKRUarTlBk3t/qRKZKtFxVp5+jNIfsNrGEkMI0wxcIfKgCM84VCJA Dpr0GWT4lNV8OFgGOi48bvopniWPRTE2QyH6UxObRGbkIEwEdBNOUfArxvIoNx12lv6v xBoPJnTke5E8IxnwF6TXsFYMuFAlWVwf31f24J3geUSdBAlBp3pv+zfzmsIk95W98XbY d6pCc+7/w3qt4OT/q0ml8HPmTy+nhQu4iqMiwv6zNhS4At1DdNezR9bfHdAL7X/QHhuI +xjA== X-Gm-Message-State: AOAM533JShB7N3HadAAL85bTCd2CVzO5/1IeoucpLOOpKmiceVYcoMqn sHqNRIln6jZie14C/J8ximdOG3N+Sb0= X-Google-Smtp-Source: ABdhPJwv1dG4W6DEk+WADCnMrrUDf8/mN2TjKCt3w6JBZG9msnWbbOYXtdbpq2l8sYkl5MvDm7Y+Zg== X-Received: by 2002:a1c:6a15:0:b0:38b:57e8:dd5c with SMTP id f21-20020a1c6a15000000b0038b57e8dd5cmr5191610wmc.160.1648540167523; Tue, 29 Mar 2022 00:49:27 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:27 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 13/16] fanotify: implement "evictable" inode marks Date: Tue, 29 Mar 2022 10:49:01 +0300 Message-Id: <20220329074904.2980320-14-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When an inode mark is created with flag FAN_MARK_EVICTABLE, it will not pin the marked inode to inode cache, so when inode is evicted from cache due to memory pressure, the mark will be lost. When an inode mark with flag FAN_MARK_EVICATBLE is updated without using this flag, the marked inode is pinned to inode cache. When an inode mark is updated with flag FAN_MARK_EVICTABLE but an existing mark already has the inode pinned, the mark update fails with error EEXIST. Evictable inode marks can be used to setup inode marks with ignored mask to suppress events from uninteresting files or directories in a lazy manner, upon receiving the first event, without having to iterate all the uninteresting files or directories before hand. The evictbale inode mark feature allows performing this lazy marks setup without exhausting the system memory with pinned inodes. This change does not enable the feature yet. Link: https://lore.kernel.org/linux-fsdevel/CAOQ4uxiRDpuS=2uA6+ZUM7yG9vVU-u212tkunBmSnP_u=mkv=Q@mail.gmail.com/ Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.h | 2 ++ fs/notify/fanotify/fanotify_user.c | 31 +++++++++++++++++++++++++++++- include/uapi/linux/fanotify.h | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 87142bc0131a..80e0ec95b113 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -497,6 +497,8 @@ static inline unsigned int fanotify_mark_user_flags(struct fsnotify_mark *mark) if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY) mflags |= FAN_MARK_IGNORED_SURV_MODIFY; + if (mark->flags & FSNOTIFY_MARK_FLAG_NO_IREF) + mflags |= FAN_MARK_EVICTABLE; return mflags; } diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 6e78ea12239c..2c65038da4ce 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1084,6 +1084,8 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group, static int fanotify_mark_update_flags(struct fsnotify_mark *fsn_mark, unsigned int flags, bool *recalc) { + bool want_iref = !(flags & FAN_MARK_EVICTABLE); + /* * Setting FAN_MARK_IGNORED_SURV_MODIFY for the first time may lead to * the removal of the FS_MODIFY bit in calculated mask if it was set @@ -1097,6 +1099,20 @@ static int fanotify_mark_update_flags(struct fsnotify_mark *fsn_mark, *recalc = true; } + if (fsn_mark->connector->type != FSNOTIFY_OBJ_TYPE_INODE || + want_iref == !(fsn_mark->flags & FSNOTIFY_MARK_FLAG_NO_IREF)) + return 0; + + /* + * NO_IREF may be removed from a mark, but not added. + * When removed, fsnotify_recalc_mask() will take the inode ref. + */ + if (!want_iref) + return -EEXIST; + + fsn_mark->flags &= ~FSNOTIFY_MARK_FLAG_NO_IREF; + *recalc = true; + return 0; } @@ -1130,6 +1146,7 @@ static int fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark, static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, fsnotify_connp_t *connp, unsigned int obj_type, + unsigned int fan_flags, __kernel_fsid_t *fsid) { struct ucounts *ucounts = group->fanotify_data.ucounts; @@ -1152,6 +1169,9 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, } fsnotify_init_mark(mark, group); + if (fan_flags & FAN_MARK_EVICTABLE) + mark->flags |= FSNOTIFY_MARK_FLAG_NO_IREF; + ret = fsnotify_add_mark_locked(mark, connp, obj_type, fsid); if (ret) { fsnotify_put_mark(mark); @@ -1187,7 +1207,8 @@ static int fanotify_add_mark(struct fsnotify_group *group, mutex_lock(&group->mark_mutex); fsn_mark = fsnotify_find_mark(connp, group); if (!fsn_mark) { - fsn_mark = fanotify_add_new_mark(group, connp, obj_type, fsid); + fsn_mark = fanotify_add_new_mark(group, connp, obj_type, flags, + fsid); if (IS_ERR(fsn_mark)) { mutex_unlock(&group->mark_mutex); return PTR_ERR(fsn_mark); @@ -1602,6 +1623,14 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, mark_type != FAN_MARK_FILESYSTEM) goto fput_and_out; + /* + * Evictable is only relevant for inode marks, because only inode object + * can be evicted on memory pressure. + */ + if (flags & FAN_MARK_EVICTABLE && + mark_type != FAN_MARK_INODE) + goto fput_and_out; + /* * Events that do not carry enough information to report * event->fd require a group that supports reporting fid. Those diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index e8ac38cc2fd6..f1f89132d60e 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -82,6 +82,7 @@ #define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 #define FAN_MARK_FLUSH 0x00000080 /* FAN_MARK_FILESYSTEM is 0x00000100 */ +#define FAN_MARK_EVICTABLE 0x00000200 /* These are NOT bitwise flags. Both bits can be used togther. */ #define FAN_MARK_INODE 0x00000000 From patchwork Tue Mar 29 07:49:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794541 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5DA5C433EF for ; Tue, 29 Mar 2022 07:50:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233628AbiC2Hvv (ORCPT ); Tue, 29 Mar 2022 03:51:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233600AbiC2HvM (ORCPT ); Tue, 29 Mar 2022 03:51:12 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 351FC1EA5D8 for ; Tue, 29 Mar 2022 00:49:30 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id h4so23492601wrc.13 for ; Tue, 29 Mar 2022 00:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Br1h8G2qXI9ekFcoSJRm2Y+2Hg4qqQhDn83mn5wMdkE=; b=SodeooKSCF+qrFCbNYx1+B7rWLAKGibqOh8qbZoY8eITLb96c+SUBf251I85KCnNK4 T/+AvuCGFGUpHhH7OB1ncAXnv93OWLuUZ7PnMeCk63xRouucC0BNRKjjpRCGPX2J/mU/ FUedkNFK/p/kaBfUPSzdYWCojU80BcJtI8S0V9jcTRngKo2zOnl9dAnIP8INMT0Vqpxn mS3qY/9Nj9vOneGi47K5S0rs1IwwszKjHLSNZxSepDOiPHrn9sZP8yLFXtPiZkVkUlwK hdJYzCFQJFUxrl5Qpynr+1fx7aNdq1pnijSds3ymoZWY6NB6tnaCK+j7KtSMLHyUTtLb bU7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Br1h8G2qXI9ekFcoSJRm2Y+2Hg4qqQhDn83mn5wMdkE=; b=Fm1pdAXtPLWdu4tJzdFdBYWHDHbyWj4BmW7xweSZHRjT9xldwMQeM6IkSDbq3DfNzD qIKWAj6oe+HzWgDWG+k2Rq5CDyC7VRNkss5xR53OcVzJNY5Z1UAa6Nz3DLjFDJwFIMXp SQ//yoQv0OhaNgJrsc3LzKwLazI5/lYTxGTi3QguL5HESuvseQ1/MzHf3xYH8XR82fLy Qs0IKpY0SD8YaI51P0sN2jXlEzJ9VsOwQQW2iKqjI4WLfJOY+xWKa/54flzgF/5+A/od c/YU3hTgU/QLgOf+js3JHzufA/KOX1cUZDtSkceSdwq15w+aC24JdMNbrORyfZp0/nc1 RZ9g== X-Gm-Message-State: AOAM532dxstnAJyk5TA6LT5um94eaeGf4xfwZeezJbcEZjBTC42w7TO5 YvHf/bEa+VWgbPxzLz3yZPE= X-Google-Smtp-Source: ABdhPJwaNtS0AmYMFdzufWp+IJ+z54NqzNA4ZrK3/5zRJS6ApmyD1oeXJ/39MU+cr/ceuNmVygBHAg== X-Received: by 2002:a5d:59a2:0:b0:204:19bc:42ff with SMTP id p2-20020a5d59a2000000b0020419bc42ffmr28959625wrr.687.1648540168726; Tue, 29 Mar 2022 00:49:28 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:28 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 14/16] fanotify: add FAN_IOC_SET_MARK_PAGE_ORDER ioctl for testing Date: Tue, 29 Mar 2022 10:49:02 +0300 Message-Id: <20220329074904.2980320-15-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The ioctl can be used to request allocation of marks with large size and attach them to an object, even if another mark already exists for the group on the marked object. These large marks serve no function other than testing direct reclaim in the context of mark allocation. Setting the value to 0 restores normal mark allocation. FAN_MARK_REMOVE refers to the first mark of the group on an object, so the number of FAN_MARK_REMOVE calls need to match the number of large marks on the object in order to remove all marks from the object or use FAN_MARK_FLUSH to remove all marks of that object type. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 5 +++- fs/notify/fanotify/fanotify_user.c | 42 +++++++++++++++++++++++++++--- include/linux/fsnotify_backend.h | 2 ++ include/uapi/linux/fanotify.h | 4 +++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 985e995d2a39..02990a6b1b65 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -1075,7 +1075,10 @@ static void fanotify_freeing_mark(struct fsnotify_mark *mark, static void fanotify_free_mark(struct fsnotify_mark *fsn_mark) { - kmem_cache_free(fanotify_mark_cache, fsn_mark); + if (fsn_mark->flags & FSNOTIFY_MARK_FLAG_KMALLOC) + kfree(fsn_mark); + else + kmem_cache_free(fanotify_mark_cache, fsn_mark); } const struct fsnotify_ops fanotify_fsnotify_ops = { diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 2c65038da4ce..a3539bd8e443 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -928,6 +928,16 @@ static long fanotify_ioctl(struct file *file, unsigned int cmd, unsigned long ar spin_unlock(&group->notification_lock); ret = put_user(send_len, (int __user *) p); break; + case FAN_IOC_SET_MARK_PAGE_ORDER: + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + mutex_lock(&group->mark_mutex); + group->fanotify_data.mark_page_order = (unsigned int)arg; + pr_info("fanotify: set mark size page order to %u", + group->fanotify_data.mark_page_order); + ret = 0; + mutex_unlock(&group->mark_mutex); + break; } return ret; @@ -1150,6 +1160,7 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, __kernel_fsid_t *fsid) { struct ucounts *ucounts = group->fanotify_data.ucounts; + unsigned int order = group->fanotify_data.mark_page_order; struct fsnotify_mark *mark; int ret; @@ -1162,7 +1173,21 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, !inc_ucount(ucounts->ns, ucounts->uid, UCOUNT_FANOTIFY_MARKS)) return ERR_PTR(-ENOSPC); - mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); + /* + * If requested to test direct reclaim in mark allocation context, + * start by trying to allocate requested page order per mark and + * fall back to allocation size that is likely to trigger direct + * reclaim but not too large to trigger compaction. + */ + if (order) { + mark = kmalloc(PAGE_SIZE << order, + GFP_KERNEL_ACCOUNT | __GFP_NOWARN); + if (!mark && order > PAGE_ALLOC_COSTLY_ORDER) + mark = kmalloc(PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER, + GFP_KERNEL_ACCOUNT | __GFP_NOWARN); + } else { + mark = kmem_cache_alloc(fanotify_mark_cache, GFP_KERNEL); + } if (!mark) { ret = -ENOMEM; goto out_dec_ucounts; @@ -1171,6 +1196,15 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, fsnotify_init_mark(mark, group); if (fan_flags & FAN_MARK_EVICTABLE) mark->flags |= FSNOTIFY_MARK_FLAG_NO_IREF; + /* + * Allow adding multiple large marks per object for testing. + * FAN_MARK_REMOVE refers to the first mark of the group, so one + * FAN_MARK_REMOVE is needed for every added large mark (or use + * FAN_MARK_FLUSH to remove all marks). + */ + if (order) + mark->flags |= FSNOTIFY_MARK_FLAG_KMALLOC | + FSNOTIFY_MARK_FLAG_ALLOW_DUPS; ret = fsnotify_add_mark_locked(mark, connp, obj_type, fsid); if (ret) { @@ -1201,11 +1235,13 @@ static int fanotify_add_mark(struct fsnotify_group *group, __u32 mask, unsigned int flags, __kernel_fsid_t *fsid) { - struct fsnotify_mark *fsn_mark; + struct fsnotify_mark *fsn_mark = NULL; int ret = 0; mutex_lock(&group->mark_mutex); - fsn_mark = fsnotify_find_mark(connp, group); + /* Allow adding multiple large marks per object for testing */ + if (!group->fanotify_data.mark_page_order) + fsn_mark = fsnotify_find_mark(connp, group); if (!fsn_mark) { fsn_mark = fanotify_add_new_mark(group, connp, obj_type, flags, fsid); diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index df58439a86fa..8220cf560c28 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -250,6 +250,7 @@ struct fsnotify_group { int f_flags; /* event_f_flags from fanotify_init() */ struct ucounts *ucounts; mempool_t error_events_pool; + unsigned int mark_page_order; /* for testing only */ } fanotify_data; #endif /* CONFIG_FANOTIFY */ }; @@ -528,6 +529,7 @@ struct fsnotify_mark { #define FSNOTIFY_MARK_FLAG_ALLOW_DUPS 0x0040 #define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY 0x0100 #define FSNOTIFY_MARK_FLAG_NO_IREF 0x0200 +#define FSNOTIFY_MARK_FLAG_KMALLOC 0x0400 unsigned int flags; /* flags [mark->lock] */ }; diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index f1f89132d60e..49cdc9008bf2 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -3,6 +3,7 @@ #define _UAPI_LINUX_FANOTIFY_H #include +#include /* the following events that user-space can register for */ #define FAN_ACCESS 0x00000001 /* File was accessed */ @@ -206,4 +207,7 @@ struct fanotify_response { (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ (long)(meta)->event_len <= (long)(len)) +/* Only for testing. Not useful otherwise */ +#define FAN_IOC_SET_MARK_PAGE_ORDER _IOW(0xfa, 1, long) + #endif /* _UAPI_LINUX_FANOTIFY_H */ From patchwork Tue Mar 29 07:49:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794542 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72009C433FE for ; Tue, 29 Mar 2022 07:50:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233675AbiC2Hvw (ORCPT ); Tue, 29 Mar 2022 03:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232813AbiC2HvO (ORCPT ); Tue, 29 Mar 2022 03:51:14 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 778281EB82D for ; Tue, 29 Mar 2022 00:49:31 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 125-20020a1c0283000000b0038d043aac51so807257wmc.0 for ; Tue, 29 Mar 2022 00:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=d43EZ7u0/J+yBXaYIqN+17PXgNgwdii5Sde1yDCMQz0=; b=qT9aMX3z00ZAGJL8NwcxMb4R/ejNHxDYNDYtdGK+gHBf+DEA0jQJCuYn0X+aG9rOxP FVcCqayWsagIaN/yXKZjsCJEbaB6kUPWd9ihCJC/2PH7WIUmgQXBCzys5HZ3iyhrNW38 9ShZdOk74cq5x6I9ElEcukqX8zpF5Tf8mF1cx2kR0+uo09IlVqbqPo54lpBLKpwyv2a5 jK9Y6yAmDcz5dmL9HFtWVkHqBvNv+jXk7T/WEMxIzApTibeooxw2bgk7ZeAqpibg48gg uk5wWl47Jz4YF7jCDqijhh1yqNtPB7+Qsx20qhFWd7eXgVyuXsyxcffV3szuLqXo3bBG ssaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d43EZ7u0/J+yBXaYIqN+17PXgNgwdii5Sde1yDCMQz0=; b=zuR6zceL8LlvzQT08qaWUFdgmZ8Ue0u53q+eJZ/ltJE9SDYtRhzUkbyGwtJCjxfnJC iiBztmOIimxHkMPJr71hA7o0C03ddkADhkGDsVo3eyw1Y1ZsOX62Z1Tw6VxziIn+9zds DaEzvUTkJ1KgQ8LgBCY4GwZxryeyNy+dpk2AJEss0Ev7wl619yS6Hd8PfX+Oz+d752Gb yY0ZY8TnocoNgZLQ9KyGzjJBSr/aXanvojlU5N5CeXfR37loeCyQWPQPsLap1rVoJzvh P2QoEsLEQ/NPD49yK6kKmGkCATnCY1vled5vKZ3QcqfgsYjCzadCc5Mc7cVbygua5WfQ gxaQ== X-Gm-Message-State: AOAM5310Th/GrS+zlFEFwU9nRzMMe8uOCRrGEjdWpNTq24h1S4Wbg1If 3p5343divDQwmT9zaIPj0/8= X-Google-Smtp-Source: ABdhPJz+3moLq8ywzrHKPHGNFgd6YV2v0QJASvBmdywKaMmlzWeg7uDkg6G2kn07voLk5GZMXnJnZQ== X-Received: by 2002:a05:600c:240b:b0:38c:eb99:8276 with SMTP id 11-20020a05600c240b00b0038ceb998276mr5132601wmp.82.1648540170057; Tue, 29 Mar 2022 00:49:30 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:29 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 15/16] fanotify: use fsnotify group lock helpers Date: Tue, 29 Mar 2022 10:49:03 +0300 Message-Id: <20220329074904.2980320-16-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Direct reclaim from fanotify mark allocation context may try to evict inodes with evictable marks of the same group and hit this deadlock: [<0>] fsnotify_destroy_mark+0x1f/0x3a [<0>] fsnotify_destroy_marks+0x71/0xd9 [<0>] __destroy_inode+0x24/0x7e [<0>] destroy_inode+0x2c/0x67 [<0>] dispose_list+0x49/0x68 [<0>] prune_icache_sb+0x5b/0x79 [<0>] super_cache_scan+0x11c/0x16f [<0>] shrink_slab.constprop.0+0x23e/0x40f [<0>] shrink_node+0x218/0x3e7 [<0>] do_try_to_free_pages+0x12a/0x2d2 [<0>] try_to_free_pages+0x166/0x242 [<0>] __alloc_pages_slowpath.constprop.0+0x30c/0x903 [<0>] __alloc_pages+0xeb/0x1c7 [<0>] cache_grow_begin+0x6f/0x31e [<0>] fallback_alloc+0xe0/0x12d [<0>] ____cache_alloc_node+0x15a/0x17e [<0>] kmem_cache_alloc_trace+0xa1/0x143 [<0>] fanotify_add_mark+0xd5/0x2b2 [<0>] do_fanotify_mark+0x566/0x5eb [<0>] __x64_sys_fanotify_mark+0x21/0x24 [<0>] do_syscall_64+0x6d/0x80 [<0>] entry_SYSCALL_64_after_hwframe+0x44/0xae Set the FSNOTIFY_GROUP_NOFS flag to prevent going into direct reclaim from allocations under fanotify group lock and use the nofs group lock helpers. Suggested-by: Jan Kara Link: https://lore.kernel.org/r/20220321112310.vpr7oxro2xkz5llh@quack3.lan/ Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 1 + fs/notify/fanotify/fanotify_user.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 02990a6b1b65..c7bcada371cb 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -1082,6 +1082,7 @@ static void fanotify_free_mark(struct fsnotify_mark *fsn_mark) } const struct fsnotify_ops fanotify_fsnotify_ops = { + .group_flags = FSNOTIFY_GROUP_NOFS, .handle_event = fanotify_handle_event, .free_group_priv = fanotify_free_group_priv, .free_event = fanotify_free_event, diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index a3539bd8e443..5c857bfe8c3e 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -931,12 +931,12 @@ static long fanotify_ioctl(struct file *file, unsigned int cmd, unsigned long ar case FAN_IOC_SET_MARK_PAGE_ORDER: if (!capable(CAP_SYS_ADMIN)) return -EPERM; - mutex_lock(&group->mark_mutex); + fsnotify_group_lock(group); group->fanotify_data.mark_page_order = (unsigned int)arg; pr_info("fanotify: set mark size page order to %u", group->fanotify_data.mark_page_order); ret = 0; - mutex_unlock(&group->mark_mutex); + fsnotify_group_unlock(group); break; } @@ -1044,11 +1044,12 @@ static int fanotify_remove_mark(struct fsnotify_group *group, struct fsnotify_mark *fsn_mark = NULL; __u32 removed; int destroy_mark; + unsigned int nofs; - mutex_lock(&group->mark_mutex); + nofs = fsnotify_group_nofs_lock(group); fsn_mark = fsnotify_find_mark(connp, group); if (!fsn_mark) { - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); return -ENOENT; } @@ -1058,7 +1059,7 @@ static int fanotify_remove_mark(struct fsnotify_group *group, fsnotify_recalc_mask(fsn_mark->connector); if (destroy_mark) fsnotify_detach_mark(fsn_mark); - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); if (destroy_mark) fsnotify_free_mark(fsn_mark); @@ -1236,9 +1237,10 @@ static int fanotify_add_mark(struct fsnotify_group *group, __kernel_fsid_t *fsid) { struct fsnotify_mark *fsn_mark = NULL; + unsigned int nofs; int ret = 0; - mutex_lock(&group->mark_mutex); + nofs = fsnotify_group_nofs_lock(group); /* Allow adding multiple large marks per object for testing */ if (!group->fanotify_data.mark_page_order) fsn_mark = fsnotify_find_mark(connp, group); @@ -1246,7 +1248,7 @@ static int fanotify_add_mark(struct fsnotify_group *group, fsn_mark = fanotify_add_new_mark(group, connp, obj_type, flags, fsid); if (IS_ERR(fsn_mark)) { - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); return PTR_ERR(fsn_mark); } } @@ -1264,7 +1266,7 @@ static int fanotify_add_mark(struct fsnotify_group *group, ret = fanotify_mark_add_to_mask(fsn_mark, mask, flags); out: - mutex_unlock(&group->mark_mutex); + fsnotify_group_nofs_unlock(group, nofs); fsnotify_put_mark(fsn_mark); return ret; From patchwork Tue Mar 29 07:49:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 12794543 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 727A2C433F5 for ; Tue, 29 Mar 2022 07:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233597AbiC2Hv4 (ORCPT ); Tue, 29 Mar 2022 03:51:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233614AbiC2Hvf (ORCPT ); Tue, 29 Mar 2022 03:51:35 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4F1C1EC639 for ; Tue, 29 Mar 2022 00:49:32 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so919109wmp.5 for ; Tue, 29 Mar 2022 00:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w5A1yiZw+L1K6U44DKTZa4QH85ywxk7I8QqZCQCmDCw=; b=EuyZQUz0OPwl00Rjs026c/rnJJCbgvXXm5tgWTJigLdNdF9RnvhiZn7hUWGBOXIjDn +mdwR1fm6NLRZaVlTlOnGDwwkThqGUCBQH4GUbCUWVvpsoI3siNg4FtoVZFEL864QMYh 5znQwwKX10Egy8GesC7sooPZgl9OwFNp0pUJGC28dogBiFPmW4rGbAE9PjuxjNpQyhZ2 XrAktZutrLjRxDzIBi3q94qvJnXmib5BfCJwZs9+Vqk47qKjPfkvAxeI/qvEmVGY52Ex 1+MicLMHdEBb6EkLS6oISXI1fYLnlPD0X6x4yxMqOWsxqdPCKM8IZw3AVbKgYHILBXVp t0Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w5A1yiZw+L1K6U44DKTZa4QH85ywxk7I8QqZCQCmDCw=; b=pmm6qVqAGfxQ2AkOWVD5leH3H18myYIqIgHyp3Cl9WOyzN6PLGEUx+yEvl5TGB/WWn UhDdq0yr/2Lv4P/6AKWO6JCJDZpwoaZGrvl58gqLBCIIzlfHeASikvL1WgeDpkQ+jY2g 70v4LbR9dorWFBpa9QaksM9qHoUO6BHU9SwxzuEnSaxjCeyIFDB2BjHx01w6Z7w8DLvl HUHu6FlbixII+mu9mZKUgngQNwOMLP1CEqoMDQAqXmE8R/LwzR+ZQu5VEYd+bNJU5O0f GMK5iJ5RhAGyXRI5qJwI7FRIM2Qt34A00mvCIDcLY9stJysBweBlMtnt/ULzh6bW3Lkf NMXw== X-Gm-Message-State: AOAM531ftBEWrMMH9sSxokXQGBZfPDjXwD4QRLwKgpqhVNmTKxqCzuE4 cQsQh+7p5CE1Iate6E/FCiw= X-Google-Smtp-Source: ABdhPJzll6haXDFBh5oTCIeCu8E6GsqQ4NcGyCmG/6eXr27SBJMe6q8C1MQm1yXW7HquesgVpzMerA== X-Received: by 2002:a05:600c:3586:b0:38c:a92f:1744 with SMTP id p6-20020a05600c358600b0038ca92f1744mr5030455wmq.126.1648540171370; Tue, 29 Mar 2022 00:49:31 -0700 (PDT) Received: from localhost.localdomain ([77.137.71.203]) by smtp.gmail.com with ESMTPSA id k40-20020a05600c1ca800b0038c6c8b7fa8sm1534342wms.25.2022.03.29.00.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 00:49:30 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 16/16] fanotify: enable "evictable" inode marks Date: Tue, 29 Mar 2022 10:49:04 +0300 Message-Id: <20220329074904.2980320-17-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329074904.2980320-1-amir73il@gmail.com> References: <20220329074904.2980320-1-amir73il@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Now that the direct reclaim path is handled we can enable evictable inode marks. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 2 +- include/linux/fanotify.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 5c857bfe8c3e..4ea36659addc 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1821,7 +1821,7 @@ static int __init fanotify_user_setup(void) BUILD_BUG_ON(FANOTIFY_INIT_FLAGS & FANOTIFY_INTERNAL_GROUP_FLAGS); BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 12); - BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 9); + BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 10); fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, SLAB_PANIC|SLAB_ACCOUNT); diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 419cadcd7ff5..edc28555814c 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -66,6 +66,7 @@ FAN_MARK_ONLYDIR | \ FAN_MARK_IGNORED_MASK | \ FAN_MARK_IGNORED_SURV_MODIFY | \ + FAN_MARK_EVICTABLE | \ FAN_MARK_FLUSH) /*