From patchwork Tue Nov 12 17:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872737 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30228D42BBA for ; Tue, 12 Nov 2024 17:57:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7A0D6B0107; Tue, 12 Nov 2024 12:56:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D255F6B0105; Tue, 12 Nov 2024 12:56:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4F906B0107; Tue, 12 Nov 2024 12:56:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8A2476B00A5 for ; Tue, 12 Nov 2024 12:56:51 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5612C14030E for ; Tue, 12 Nov 2024 17:56:51 +0000 (UTC) X-FDA: 82778196858.27.BBF656F Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) by imf01.hostedemail.com (Postfix) with ESMTP id D97224000B for ; Tue, 12 Nov 2024 17:56:16 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=3KoBCl2n; spf=none (imf01.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.174) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434066; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RxllZcuqFsIN/uRNUgqvpvAOYGEhEd5YYx/k8ZgfJq8=; b=eI597hhMCVseZBbxo3p9Fk6HMFYDTOstRkaj5+0lyWzaTUnRfWjdY5LPQqlfOLHV/FnXe7 tr3Qp3ZZR1TJ0LN24DEwswoVG0WdgBgaCaYIG03K62K45105oTgsV6kKsFSVw6pDWksbR/ WfZNMkg63IR7LEDW9kXb9GBujcwsILo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434066; a=rsa-sha256; cv=none; b=8KhHAftBSp6q/QzTMH21yLSCQEhVnP42aZB/rHccEojLbH7XDeG30kDsr9fgDSTp6k3Bhf 10r0/AkXpPeI53o8oKMmYatenwcg74r830eCOoH7KyFvpbsWLhZFatO+50A2GPM2onIjM8 el0nguLvQr96SBwflEvT2XIvhhNXV/o= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=3KoBCl2n; spf=none (imf01.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.174) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-e30d517c82fso5827642276.1 for ; Tue, 12 Nov 2024 09:56:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434208; x=1732039008; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=RxllZcuqFsIN/uRNUgqvpvAOYGEhEd5YYx/k8ZgfJq8=; b=3KoBCl2nO5qamvy3B+9QbnNYTtJ042viNQk56ZdUURKrNR5yiAER+ipba4dJyOC48f /0wHAVMbTZvHl1xGHm8TD+MptX179faoDfj/OFEm3rlc/dK7KBN0qn4A0Co2APsrofZ+ qE/orDF7ODoRT7IwewBggmcDXk5jDVbmRvTgxUg9732LfrZ8tDFlsd75q2Cm4kodIw9R o+R/wPtogauQ+hZiDQ1GxNfsFrhwReU/fmoMDHOFfaYlUSmeONR55/FgWl+T1SJA/EdT UZoA7PitgjK6qs4ySXfwnQl7iUbyfOqD6GRhXA9CfBgg0CHBTqbAYBXZPfixS2kvAcYV Sr6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434208; x=1732039008; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RxllZcuqFsIN/uRNUgqvpvAOYGEhEd5YYx/k8ZgfJq8=; b=wj4wK6vBeyZS23u0qgWSYlCMFxUp2Ac5JNTGODtke80sBm5iMZEmWPThhnpbGj8K0c 19WhhkLReqoLwwbUIYXYCLRA1a6MOzOkbSEoxptPNiSTHP8yXPPk52/GxYcFV+2BJM1p FHkSk3KVgCwdDZdiHaAuqYhQz08H5KRci1E0I9Ee2uZrANMnnh43Vj+BbweHwfuh/Tue XCVLrbVp8MpIWzxJ5Il/hdtEbIo/REEUVOxguiRJr7ipohFtxvEa4mrTqqRW9mFfthtM RYBNgr6b66OZREmpPpBGyaxrutbRx0x8dDII847CmCftjjpGFjKoL6YvP+dvmIMpwAgq IR8Q== X-Forwarded-Encrypted: i=1; AJvYcCWf3gcwMVceRYxb5BtZsv37P72mZgr5sdwwiCevd2gSi/kcHEweCXtbHrkWGCs+ZA+pPuIqTLAzXQ==@kvack.org X-Gm-Message-State: AOJu0Yz0wOe5RQ9qkaRzAJcN38GL7bYCPdPVN8StCBM/mYwDFAYeA2R+ kpzkVY9QWPZsON0t7l1CrRzhTPRY08yx14E4v/IGXxSoR4MV9JeErW6nsyHEuGU= X-Google-Smtp-Source: AGHT+IHPp+fFKmqCSpROu5xxKnzv3LT3agPlNIkaHlSKePfsW7xMW1BrUYUNoa9bR5mHCiwMC/SWmQ== X-Received: by 2002:a05:6902:b1d:b0:e29:48ad:b845 with SMTP id 3f1490d57ef6-e35dc547994mr3050460276.22.1731434207100; Tue, 12 Nov 2024 09:56:47 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336ef2652csm2885436276.22.2024.11.12.09.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:46 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 12/18] fanotify: add a helper to check for pre content events Date: Tue, 12 Nov 2024 12:55:27 -0500 Message-ID: <44afe46517b379b6b998a35ba99dd2e1f55a2c7d.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D97224000B X-Stat-Signature: zshada7apr3xkmfryhpp9t1ms3r16yy1 X-HE-Tag: 1731434176-632199 X-HE-Meta: U2FsdGVkX1+XnFvWIlscK4O9aYy0IIZ55S8rz5v+M5IdLGPW6uTZjFB61AjfRoRumdGh1jMLv2ZKiujTddblxK8DNAqQea2uvENOTfJKXaF9BYXCkAQz3ZGLjDxwPIuVSj5sbQsGNv86r5sdBwGfpcZKDay1SUyETt9L0qgerDHGzLK7fTsPQSH8v4oBrCCBAWqGPdbtvUYgKVXexFQDZ6QR28Dzzo0JZoXOsJp3TpgQem6DeOR5MYx4nOwqaZKMrc3rXCXaFM3p2SiZ74PgOaME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587UBAGeaQSOR3Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to emit events during page fault, and calling into fanotify could be expensive, so add a helper to allow us to skip calling into fanotify from page fault. This will also be used to disable readahead for content watched files which will be handled in a subsequent patch. Signed-off-by: Josef Bacik --- fs/notify/fsnotify.c | 12 ++++++++++++ include/linux/fsnotify_backend.h | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index cab5a1a16e57..17047c44cf91 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -203,6 +203,18 @@ static inline bool fsnotify_object_watched(struct inode *inode, __u32 mnt_mask, return mask & marks_mask & ALL_FSNOTIFY_EVENTS; } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +bool fsnotify_file_object_watched(struct file *file, __u32 mask) +{ + struct inode *inode = file_inode(file); + __u32 mnt_mask = real_mount(file->f_path.mnt)->mnt_fsnotify_mask; + + return fsnotify_object_watched(inode, mnt_mask, mask); +} +EXPORT_SYMBOL_GPL(fsnotify_file_object_watched); +#endif + + /* * Notify this dentry's parent about a child's events with child name info * if parent is watching or if inode/sb/mount are interested in events with diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index abd292edb48c..a92d59b66f93 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -896,6 +896,27 @@ static inline void fsnotify_init_event(struct fsnotify_event *event) INIT_LIST_HEAD(&event->list); } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +bool fsnotify_file_object_watched(struct file *file, __u32 mask); + +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + if (!(file->f_mode & FMODE_NOTIFY_PERM)) + return false; + + if (!(file_inode(file)->i_sb->s_iflags & SB_I_ALLOW_HSM)) + return false; + + return fsnotify_file_object_watched(file, FSNOTIFY_PRE_CONTENT_EVENTS); +} + +#else +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return false; +} +#endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */ + #else static inline int fsnotify(__u32 mask, const void *data, int data_type, @@ -934,6 +955,11 @@ static inline u32 fsnotify_get_cookie(void) static inline void fsnotify_unmount_inodes(struct super_block *sb) {} +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return false; +} + #endif /* CONFIG_FSNOTIFY */ #endif /* __KERNEL __ */