From patchwork Tue Nov 12 17:55:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872727 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 6FC6FD42BBA for ; Tue, 12 Nov 2024 17:56:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 695F16B009C; Tue, 12 Nov 2024 12:56:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F8E56B00FA; Tue, 12 Nov 2024 12:56:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44A856B00F9; Tue, 12 Nov 2024 12:56:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2771A6B009C for ; Tue, 12 Nov 2024 12:56:32 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BFE19A013B for ; Tue, 12 Nov 2024 17:56:31 +0000 (UTC) X-FDA: 82778197026.11.A48ACC3 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by imf18.hostedemail.com (Postfix) with ESMTP id 5FC691C0021 for ; Tue, 12 Nov 2024 17:56:11 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=qgeyXOY3; dmarc=none; spf=none (imf18.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434013; a=rsa-sha256; cv=none; b=Fv+J6luScIjNK8nQyqsOOlUggEzD2ShjCZmyqR2owKBAejkIfDL+QZdT3Lcgkh+Xe82Qv/ 8W6v1FUhPutguMRZrmwa4Nq/+DGLDUiwQtBAgDYO80ZHD2dUQyyEf9MEq/RX7CnTIH58Bm RbJusRO+KPPucmgi9mGLN4+kVWrjvQ8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=qgeyXOY3; dmarc=none; spf=none (imf18.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434013; 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=mq4eCWj3WcSxvhXcUvd/jAH4xfodB1FzV8Pinzx/1+k=; b=xEta52s3WFdsJeJb3R3onBf9efk1MsHFKlpXYVXi296pwfpn9zDSSFnwZoPqVajSBbIFh9 4oljYPKR1JO6I5PfuDGK87lb6H+FhwUybn4tT7joYmhvtkTSznFxLAaR7jEOQqpFfkQtq5 Lh5BmNAiKcdQhWhcPOjmI4TWRKvgyts= Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e30d212b6b1so5575395276.0 for ; Tue, 12 Nov 2024 09:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434189; x=1732038989; 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=mq4eCWj3WcSxvhXcUvd/jAH4xfodB1FzV8Pinzx/1+k=; b=qgeyXOY3PGjE+35JBg5sG3slSk8U+tor2e31bykNIx+rYCaEIyKVnp5rd6Eo4ML7OR orLiklGcphQgTy29ygFrjQdI79bqGxy+AqXk0cFU74YAOvhNhRiJP7Twb4GEy8e/zKX6 B9oFQwKWExbNq+qCmFcKxNmhit/MYHU7d+gqoShkSKU03PhAVvBYMxMn0RIBnbShsMtp dtoZzu8q2/4eouxaKcZLBhRZ+IOaqLQk2SzT5vlC/9JTtt+/u8njRDK2tAO/jqk+XTWb mr/PSjNx7gXGVCrQ21aavYriAvUzlvXZQglNsCcOcM3MVsLvbbsII8kBsB+P+HIogWV2 GnTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434189; x=1732038989; 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=mq4eCWj3WcSxvhXcUvd/jAH4xfodB1FzV8Pinzx/1+k=; b=VtfcnelEyeeNTCsFiR1lZz+1x4SkC90Fdso1XAIZZvq0aiXFGDYMiSF5DHUngUmPQ0 7wCIu5mReYzvfPRUfUGdljmN8nZo5NTrTdEgpxA7VPsQWZ5uqdcVnw0UUoPC1OxM2ugo 2pAQyAYCZEJtjveImyqRDAH3x0FmV93035GeGKOLuXGOuXKbmmwbJviE/CJ/ggQDKMyf 3mLghYGItP+B/QeWqaluFUD3c5aflNiH8uqpBOGGx75WCrHxulrYaApw7st+LlSV24WI e0BLxJOLmkqUS6lYa/ETtVnhBZnK4mbSPoLH9JJ12DVY6Gehu0dJ2tqlUpDrhUi9sFsa VD9Q== X-Forwarded-Encrypted: i=1; AJvYcCXzNs4s6Po9CkmVOejtzCOF7bet3YgWwqx/iZVXftqQaUekPwysymgQo9H9mKcvGqPRzGuTOsoQFA==@kvack.org X-Gm-Message-State: AOJu0Ywizt+CWUmQAvay+T9zuir7RW/1KCe8Mm2ACbn+vNJK4Ig9WpHf kc33Z6iAhZiyIpOXX5jCQysMrk9RnSXHDH7IibPysTZxLFql7qmZoadqJuLvsvI= X-Google-Smtp-Source: AGHT+IFBKT6JokrQIp6S+zAuePqtp2Pbd6mVXpN9BpEETDu72cZLQs4+EA2DJXpbqyUYUXFat/YoBg== X-Received: by 2002:a05:6902:2890:b0:e30:bbf9:993 with SMTP id 3f1490d57ef6-e337f861472mr15084106276.20.1731434189089; Tue, 12 Nov 2024 09:56:29 -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-e336ef20671sm2885707276.20.2024.11.12.09.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:28 -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 01/18] fsnotify: opt-in for permission events at file_open_perm() time Date: Tue, 12 Nov 2024 12:55:16 -0500 Message-ID: <8c8e9452d153a1918470cbe52a8eb6505c675911.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: gbjoz7a8qjg965ijked41c78pkkexwnp X-Rspamd-Queue-Id: 5FC691C0021 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731434171-858579 X-HE-Meta: U2FsdGVkX18tycvEnkWQXJEPaXJFYhQ25QvjlovrkaRb4I77DVAUpRuiSy7RfI1rhA9ZIDz5i/gm7W/12lKcLv3SF26tlYEkG+hA1MsucqCn30eCSYkC3gsgWD6deLvMyU6uYqQYN+5TwFw6ScAW/uJebgoXbQtWce+TH+DlKW9gcUKG9pbnTuQsc2pAvF53q8BPaoAtX3w3s+5YprGXL5DU+dlion3Pr+Z9s0dbZpLy5lbFH/vfQEv8x43Nj4CJh6ZyPeddEGghGt8Lrv1cO5x+DSl7/gW9r+tecuI9palt+xXsYw+2OR75rGHXt9cpjfZ240MnGAX/y4Ixm/9Mpgit8vg0HUCdnd1D+RNhfnsqapJvrG9tGHshHolcrR+MVEwRPr1rCRWehtmBrfApXp90aNnu6GztKCPHs9jCM1x5qdHo1vXJl/yWCZkJSc3V+0vXMkxIl/lI7rMA0A+vwZGBCMnifuCghlXHB9dQuI7xeV5F7Zk1TdZUPBWZf/LdX/gBZ3EjUm/KFHYxuKyvuX9MDXiPY0zViUKmR98WMqTfUPDvAHdug0yZPa1dnGZ/6DBZ0fFaHRCnzjYTizy3Z6g77Mej+V1U947LwfxaPsGQKtRjYbGzf8zZWdnGUu2hjPlg5fpIIrj2pAyIYxW/8alMg6dYfrkxMvKBCkEybh35OFvHm/d6m3CQ77aEcUbNXU4ZKEIBKuxFaNaePLWUqiLPVozIaX01I7JiFoB0OKkitinR8Q5SR24OUJpj2rijAw6sFQ34f9JTJAvYb5wKRkI5OQ1ZQst2YkZzi0ptvEJX3KMilcMnazP7gW8sB6Nyo36KfNZhbFxwSqbD6LheALaQJ+FJamhEw1XTlVesvP7pU7ZACcIfHEaC6gcWDvMD9jS98/QcMxN3ra0bjT+rMuekkz+0p/4n3CXw3rROy6RXbR2+vmN+cDrBZ1ZA3utget/W7yIBPlSHIYThhp0 SKf3aZm+ feBIkhOSc8rMNscja5r3taK2sXR3LxoIzYEu5exS/BCIMciXrrt8ekKLt4R5mt1Od4K1smAwJH26W/frI7PJ9RRrkrYtgHKT/XiNQiq+jVKQZMlLziiX7nh/fRx4AkT3qjrZRxw99BEbHllP3fvz8/x6xVEZKre5KvBqmTqLigQcrnOEKiV6TFAjXyXGPVbO2U1DXjDylcZKpS3hu3J5vAAVCoYmjV2vu/J3JY8723TeXMZFcFu4o6BPtxvayFitvNqlEJQUJ9sqxfhFbC5o+fNJeWL5rUAh8+Y66NzMU6j1Cgus4E2Gf2DimLj3KGAH2kjlpCHsesMXk2mxhc0BKFla6GdqM4kDrQJsBCmFmgVi7os5+WqEc0jUpNVhvgZeGZdXSdzdk6k3/wj8tB/ZJruhvh102nya6PhdmpJ/Kk0llZXkYSOL3/pysqGFlBqm9pnFysSVK3QmUlcqaU0OFUMUoIQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Legacy inotify/fanotify listeners can add watches for events on inode, parent or mount and expect to get events (e.g. FS_MODIFY) on files that were already open at the time of setting up the watches. fanotify permission events are typically used by Anti-malware sofware, that is watching the entire mount and it is not common to have more that one Anti-malware engine installed on a system. To reduce the overhead of the fsnotify_file_perm() hooks on every file access, relax the semantics of the legacy FAN_OPEN_PERM event to generate events only if there were *any* permission event listeners on the filesystem at the time that the file was open. The new semantics, implemented with the opt-in FMODE_NOTIFY_PERM flag are also going to apply to the new fanotify pre-content event in order to reduce the cost of the pre-content event vfs hooks. Suggested-by: Linus Torvalds Link: https://lore.kernel.org/linux-fsdevel/CAHk-=wj8L=mtcRTi=NECHMGfZQgXOp_uix1YVh04fEmrKaMnXA@mail.gmail.com/ Signed-off-by: Amir Goldstein --- include/linux/fs.h | 3 ++- include/linux/fsnotify.h | 47 ++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 9c13222362f5..9b58e9887e4b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -173,7 +173,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, #define FMODE_NOREUSE ((__force fmode_t)(1 << 23)) -/* FMODE_* bit 24 */ +/* File may generate fanotify access permission events */ +#define FMODE_NOTIFY_PERM ((__force fmode_t)(1 << 24)) /* File is embedded in backing_file object */ #define FMODE_BACKING ((__force fmode_t)(1 << 25)) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 278620e063ab..f0fd3dcae654 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -108,10 +108,9 @@ static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask) fsnotify_parent(dentry, mask, dentry, FSNOTIFY_EVENT_DENTRY); } -static inline int fsnotify_file(struct file *file, __u32 mask) +/* Should events be generated on this open file regardless of watches? */ +static inline bool fsnotify_file_watchable(struct file *file, __u32 mask) { - const struct path *path; - /* * FMODE_NONOTIFY are fds generated by fanotify itself which should not * generate new events. We also don't want to generate events for @@ -119,14 +118,37 @@ static inline int fsnotify_file(struct file *file, __u32 mask) * handle creation / destruction events and not "real" file events. */ if (file->f_mode & (FMODE_NONOTIFY | FMODE_PATH)) + return false; + + /* Permission events require that watches are set before FS_OPEN_PERM */ + if (mask & ALL_FSNOTIFY_PERM_EVENTS & ~FS_OPEN_PERM && + !(file->f_mode & FMODE_NOTIFY_PERM)) + return false; + + return true; +} + +static inline int fsnotify_file(struct file *file, __u32 mask) +{ + const struct path *path; + + if (!fsnotify_file_watchable(file, mask)) return 0; path = &file->f_path; - /* Permission events require group prio >= FSNOTIFY_PRIO_CONTENT */ - if (mask & ALL_FSNOTIFY_PERM_EVENTS && - !fsnotify_sb_has_priority_watchers(path->dentry->d_sb, - FSNOTIFY_PRIO_CONTENT)) - return 0; + /* + * Permission events require group prio >= FSNOTIFY_PRIO_CONTENT. + * Unless permission event watchers exist at FS_OPEN_PERM time, + * operations on file will not be generating any permission events. + */ + if (mask & ALL_FSNOTIFY_PERM_EVENTS) { + if (!fsnotify_sb_has_priority_watchers(path->dentry->d_sb, + FSNOTIFY_PRIO_CONTENT)) + return 0; + + if (mask & FS_OPEN_PERM) + file->f_mode |= FMODE_NOTIFY_PERM; + } return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH); } @@ -166,15 +188,12 @@ static inline int fsnotify_file_perm(struct file *file, int perm_mask) */ static inline int fsnotify_open_perm(struct file *file) { - int ret; + int ret = fsnotify_file(file, FS_OPEN_PERM); - if (file->f_flags & __FMODE_EXEC) { + if (!ret && file->f_flags & __FMODE_EXEC) ret = fsnotify_file(file, FS_OPEN_EXEC_PERM); - if (ret) - return ret; - } - return fsnotify_file(file, FS_OPEN_PERM); + return ret; } #else From patchwork Tue Nov 12 17:55:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872728 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 A11A5D42BBE for ; Tue, 12 Nov 2024 17:56:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C50B6B00FA; Tue, 12 Nov 2024 12:56:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 274886B00FB; Tue, 12 Nov 2024 12:56:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 116CD6B00FC; Tue, 12 Nov 2024 12:56:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DFCEF6B00FA for ; Tue, 12 Nov 2024 12:56:33 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 65E9A160408 for ; Tue, 12 Nov 2024 17:56:33 +0000 (UTC) X-FDA: 82778196102.27.9723DD9 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf11.hostedemail.com (Postfix) with ESMTP id AAB9540012 for ; Tue, 12 Nov 2024 17:55:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=U6aiWphn; spf=none (imf11.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.173) 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=1731434048; 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=DjBGMOunPJ0cAEWOCfFP2w1O3j7Clx8hp97a9eP3Qf4=; b=TcSp8j+e0tbwQkDeeot6p6XKPmzKBPh4eXA2zbyKGLy4+5BjbXaP5zByji+6OCm+SQT3Y2 1+T7iMtV5Cy5aCZ6w6rImDuDRBGTZjPqu004xFnXtNzM7v5T/Zhfr1yHIrQjzAc/6/FD1x NbxwOM43dxljcGEpLLV6eM9YwJdCV+A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434048; a=rsa-sha256; cv=none; b=rsVvAT6MOF7Hs1SdHhfMgkXpwVUdpT2dxaWwLWmQB+gvc9v/LCVuj4TNSlnkywORCdO4Wn MgsK3QZRz9/q58kWNrZnKT/0z99r+9riDCJ6F9vQnjF2BxaMfpxQeNKqnTz1QKQEcxSPP/ bttQpIPLTz7w9cnO4q+b8PeEnBdaHSI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=U6aiWphn; spf=none (imf11.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.173) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-6e35bf59cf6so40527b3.0 for ; Tue, 12 Nov 2024 09:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434191; x=1732038991; 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=DjBGMOunPJ0cAEWOCfFP2w1O3j7Clx8hp97a9eP3Qf4=; b=U6aiWphnzRGhL5SUMomqopGWDRHUdz9wwB9uQacSPkYr41KAI/Kd4lhUYezpZFLpdw VDCzAR4OFiBA8DQmECoX8Kw3nWWSg14v4suXShSt5B4qrQstPSvQKsYVEQirG+jkWoqs /nQLmcM7//hNKSQq0PxNwNnbcrbgMd0AqQ7UqZB3rI8a7LQRKjSsbhHTmzqaHnyBPblA nY0CdcwLwtr7Hd00ZhQstihaYPJxPT/gSwUXLiS0QxF0RXb8zqOvr0l0jiDu29DOj2S7 SN2EAjTtc4OUFlqrMQfKXu9xntCwz1920rnLKQ/AbeQOkR8mn8d1TiQbN+2YqmxFpV8q rD2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434191; x=1732038991; 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=DjBGMOunPJ0cAEWOCfFP2w1O3j7Clx8hp97a9eP3Qf4=; b=KXPC19iz28RKTMkVfKqsGq4K7OUopQp1wUuuACU5E+lQuvrPUhMLtDhhyDBKZkn2rC a9RvHpqHODeB+aBJQme6a5WBgFJtZvVerOhZ3Ch+dkXNEdwQbPtCgZMPGJZZ+n4eCKnV 5ALGEmfiyaluaJyKV9u3LQD4M/m8TqTtvL+N7yzlMRpwH6oC/CxCTeaQFidzYWrQ8O/U HU9vfB1eJ8p4mDytheFHRjmQSBcpjz41oFj/DhK61PpXxCpKLCpRaZRcL7E/iflio2s2 95Tlq/1hj9TqCwhSz6RVdgAkO39g8gbgKO37s58QNi5wzn+pka+WVlqv/ZyK5xk883Ga SUcw== X-Forwarded-Encrypted: i=1; AJvYcCVivJNd8S50sadQsNNx/bnzbWgvIJJO4LBQzfU/EwNqOCVsybi248nQtljgRoqedrqWEB7I4u1FVw==@kvack.org X-Gm-Message-State: AOJu0YyrGff1L6EBVG8gmbUYaa3Lr2SFF45bHdbbTe2CJKnZ81jhh55d B7ME+2S//Arjqmck8QxNJ5OP8G0C+L88XganfYHkIWEECDAo2l8taceDWlHCAO4= X-Google-Smtp-Source: AGHT+IE9ja6LbFpT71HNVj209iZC1LoqOzL3KmMfD6EjJ8DsteP+p2eBET7rNbO75x+IVtTpW9hviQ== X-Received: by 2002:a05:690c:6902:b0:6ea:86ae:cbc with SMTP id 00721157ae682-6eade510509mr128158657b3.13.1731434190711; Tue, 12 Nov 2024 09:56:30 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8d520asm26537437b3.8.2024.11.12.09.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:30 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 02/18] fanotify: don't skip extra event info if no info_mode is set Date: Tue, 12 Nov 2024 12:55:17 -0500 Message-ID: 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: AAB9540012 X-Stat-Signature: yohc31yc6wkchz3frbhfy7i4j1nzspxg X-HE-Tag: 1731434139-765442 X-HE-Meta: U2FsdGVkX1+2uHQb3QeMf2IGjNJWMuSoq4tV8iGCrEiU0jtN5kkvk124ka6Gld7MIzwDVFSDCT1YOb20gWb7+gn7bxIRo9RqfwAf7yqwTu5EVkvFZrkGmWWB53i/QDAfjaTBjtwpXuwpiqmqvDrMkXl6k4JF6M3IGMOeAsmPZR0wXaWTG2fx7IRnZNzRXzSHBSjG4/wxYHKpLWRq/3b+mauq4kmkOJ3++8IRKlDROUCdUVCCTm7vv4O3MZi1VV599gjCug5S6BlW4vBwL014DDcjBWOBMhqCYSr/t+J77lPnKXjShtoinJ7M++nY2QWWM2zlEXGAma1H65j/Slb/CdpMS2dwjMbnu3k/TJZzxNDHcd9BY9btpn8RSv/XSlv+EbmjLyVA9HjQo8TZwJigtjHFknkIRvrrNnltYkND6ZnoybUtl+UmT7t2RaVsF3OUIs3T5nl2fNDI5sMAo8kC8aG+L3Ty04IP7x1ejudKJIL0LSiLKPnx8z2lHyU4Z3rUtJHfX4nY6Q+ZOQ6fVxZXS4OhTL38z5D+DbuHLXtWimfMsFvebbpgQENTvfTA/yDIlzKjeOcY79Emwk2iFthdw8q8Oa77XOIEwlg5DhfYj1HrFMPUb+AwQlWARaMMBWI2gPNz0QV8sS8Zn4i6CLKoDRB4EUi3g/izYW+DBsW0YCadB8nr5kjScLZVh+/nZEmTOPyNRqv5lM4kFrTO846+j4V0LtHyd8aXtWJa2xtTAgJohZIEXib/KM0ztbwqmUx/ZOGbpnV+E9LlYLdzt6IhKaU0uSIY7wOZbQfSCNg6RTvP+o95Iqu3lsCBfSvQYcZJK9mTczhZdzWChM/n7nqYIhRZaSPemhPa46Gsk4N9zk6Nw1pogd0h0zJ47EAf9VtKQmkFHpC7mSIhvm5unsjiK5FWtuSz/mF83H5qurniuPQc3qyjuYJMw+nMSAOpklNi3RD/R9nHMqVEzv7T04h V+uONfVY hNuHEANrrxeCxF9VAvSqlbbEPd9ra5KSqGXlUNBNmgabQ/rggdu+Xe2SyiHcbi2GR7U1OlbR+Z2nYosmX583REyNdhneUaFcrgbgK07CIkzJpuVN5fHdj0DL3tblfAA3XWljt2pzEPVPjrSxcliraArE1ONyr2uR2ExL3rM4mDEf51T2/K5QQY1yhZKLA8bQ6ikoq9cXEyBhVTGckPI2NbGZcfDsTqflSxwszH94VJ7p2RwbxJl4odNlOuW6W6Yn/ds0JmOxHDYhwc/sCHj5z1BxRs4WWSlir8F6DwaI/AAW30JqNHwLO6XktpMmWZDCTUO1q28iAgT/Evj54xOlVYN0ES0VPbEfYJ7zJsfFkyPrFvl64A0KjCEbHiJ2aysE9P+CYHqVjvr8fQ+EO/NtJ/IgolTP37OCINDpZXjw0iAGYQUaEMIZYm/4IJA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.013364, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Previously we would only include optional information if you requested it via an FAN_ flag at fanotify_init time (FAN_REPORT_FID for example). However this isn't necessary as the event length is encoded in the metadata, and if the user doesn't want to consume the information they don't have to. With the PRE_ACCESS events we will always generate range information, so drop this check in order to allow this extra information to be exported without needing to have another flag. Signed-off-by: Josef Bacik --- fs/notify/fanotify/fanotify_user.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 2d85c71717d6..8528c1bfee7d 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -159,9 +159,6 @@ static size_t fanotify_event_len(unsigned int info_mode, int fh_len; int dot_len = 0; - if (!info_mode) - return event_len; - if (fanotify_is_error_event(event->mask)) event_len += FANOTIFY_ERROR_INFO_LEN; @@ -756,12 +753,10 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, buf += FAN_EVENT_METADATA_LEN; count -= FAN_EVENT_METADATA_LEN; - if (info_mode) { - ret = copy_info_records_to_user(event, info, info_mode, pidfd, - buf, count); - if (ret < 0) - goto out_close_fd; - } + ret = copy_info_records_to_user(event, info, info_mode, pidfd, + buf, count); + if (ret < 0) + goto out_close_fd; if (f) fd_install(fd, f); From patchwork Tue Nov 12 17:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872729 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 3F025D42BBA for ; Tue, 12 Nov 2024 17:56:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3146B6B00FD; Tue, 12 Nov 2024 12:56:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29C726B00FE; Tue, 12 Nov 2024 12:56:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C8396B00FF; Tue, 12 Nov 2024 12:56:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D9E936B00FD for ; Tue, 12 Nov 2024 12:56:35 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 779BC402E9 for ; Tue, 12 Nov 2024 17:56:35 +0000 (UTC) X-FDA: 82778196186.27.99FBE21 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf19.hostedemail.com (Postfix) with ESMTP id 2475A1A0008 for ; Tue, 12 Nov 2024 17:55:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=Jbm94LC2; dmarc=none; spf=none (imf19.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.175) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434131; a=rsa-sha256; cv=none; b=E84HGKDLN0FJJngk5G9C08OHdaz4jQ5qmzM2aRASaf63K15c4agkstneWKo+Gk8FsMJMp2 r/kBQpOR8QEXrV+HsqDikPxabSY904mlEPnZtJZjow1iCq/HSiDOqw0UvdinZ+aqgRT3ad lDf1FSqmjjKXGbMSPYIhdax6c/+qeSw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=Jbm94LC2; dmarc=none; spf=none (imf19.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.175) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434131; 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=FLBk0eY4CldnJ4xEhkKNTvdMfXwQixnxnwnrlcZUems=; b=bs2M0yFCRXCuL7pjPXsvlQof+TCCgdIsReR/R9X9XVdaFr8xYdYdEfTN7N8ILkX4narDFh aBnMjZ3qYQAaSxn//0wieBrc5W+F+HUE0VUoMGkvdWl3/pnmhn5wKFuQ0Uw8XpobMcIr+w UvHpl9d4D7+P9DBvnP7tFZjLDlEzvuM= Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e29047bec8fso4065276.0 for ; Tue, 12 Nov 2024 09:56:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434193; x=1732038993; 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=FLBk0eY4CldnJ4xEhkKNTvdMfXwQixnxnwnrlcZUems=; b=Jbm94LC22hkEIpBU3d3Z3Tl3g2vXPKl4lw6p0DFeZhPG2YynLOOw6oNUVMf/LMGYR2 ZF70KkAA9FbjOWQdsTGBtvZ1UHzzeORW+cne9LehQyOfyLugPy8jpQvDe+N70dFAri4g P5KS63BsDkC7aOK9+uIEhpwiR1TzQJdgy/Gtr/G8ssxEAl/sappYn5vk05KVWDfREO+Z fLaG3/CLbpsOqe95AsoO94oCJj2krTiXdAhSriLhNeVx4m/DHYBjHFQMSyR4+saFLjFw rUn1NRCvRZwRfvL9pM5tjTUxk1Z1NBg4h4mqGCx2JA52lKx+UQnsKIMcbDUfEjna9yxR 0v8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434193; x=1732038993; 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=FLBk0eY4CldnJ4xEhkKNTvdMfXwQixnxnwnrlcZUems=; b=xDIluu6U4XuGSrN1L67G2FNEEpcpMLm/JLt6NZOoWAWV8fgmi+lNtmC2NGzRqakaTA EoxXldVV654Wg9/AoPphVenoVlHbh6gyJx2pRUjrxLDxTJy16dtiWaKGKBBE6tWXykPH 1K7ttq0nf/kFe3tcPRw1heIpFZJRlepUHfMqR6YvfBKrND5OikgiKpEopfBuwtkDOgdq zUHKnHBEkWMjkpw07ifEboypCINwNJYrK16dCIY4Anslziq1MwT3ESR7hYjcjcKLvxiB /HFouy+kNcFI2ngjhAib3ului6VjVKeZs++dEIijzdFoTj1d8OS6ghKB7rHqAYZ5YaMN 8v9A== X-Forwarded-Encrypted: i=1; AJvYcCVfTWHnI+oYR3r6S+QPhJKFAJieCHwxlXLLm9SLJ55UU/HoXHdntPsZAS9Gwbwn2bLGFuH42Y4XCw==@kvack.org X-Gm-Message-State: AOJu0Ywm9ITeAXU+dzETpvOd6M0u4A/Oa19973rt5niVDtiO3VwXuh81 nilrvGGPIpzirLROngdmrB1GJOa7J5xi0ATlcSdSB64QDBi6nWpxJNpsp8wGoqTeOMdCq/3LBQG g X-Google-Smtp-Source: AGHT+IGq9atUwLu6yRfGGU3gZisyi+y0UAqwpKFwzP1csSwnkEjcF1T1CgCueeohLnBc8+4LN1Gtbg== X-Received: by 2002:a25:8481:0:b0:e29:2988:ecf0 with SMTP id 3f1490d57ef6-e337e102bdfmr14488297276.10.1731434192790; Tue, 12 Nov 2024 09:56:32 -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-e336ee1526dsm2752624276.2.2024.11.12.09.56.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:31 -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 03/18] fanotify: rename a misnamed constant Date: Tue, 12 Nov 2024 12:55:18 -0500 Message-ID: <2142cdfd0bce931024cb715b6e178f3f5c49e797.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-Queue-Id: 2475A1A0008 X-Rspamd-Server: rspam01 X-Stat-Signature: 8gakyuhp56cpbaa6qthpguc45ecsrhkm X-HE-Tag: 1731434141-947363 X-HE-Meta: U2FsdGVkX1/hZlrrzbolWAWo3Ste8T0cJaeBw+PQRxAC0tjY6J/ljjcw/xDvfiqN5xwSclIoiUNXw9r7zjUmrTljGJSEIrXpmSbvEZPgvttvSs74s+5aDRbEEFzJNvJmAyQ1lo/EgKvPB6evNIgbvmgKawlJkkb7y1eR9DmGMVu5kW7RwPQkkKyhVl/LbpW0JOzUoiZPBpQSY/AAPszzPg6Yjo6ldXDaGLeT4mW3osoWPL4jO2ZGwU6ZE6Gm8FaqcKHvGrQTl6d10n8ZlgeyhON0aHi5daoE6bSJVh8+az8IkX7uHMpGcHiZbknfEY9pPPkQ1oDSB6Gg+AhxW9V0bB6qXzNWNsH2QtyiIimK+SHJxe6Mox2Pt9dHEPU4geB9pnuWy84QyBO6MiwG9RiUEJlOCTKKpkQUq5LmK3A8b0+df1bulQ1lxOV9c0HxsfYJ8R5LFbps4F/ePiNqClG3Lr1yGsUKKy4y+cs8I+m5DvJXGu39lA5GZXFMnIFb6Mg33pNQbgfXSPVCcHsQob0gh8j0AJy4wkL8tTYLzSX9YnbdX+K8e1KXoJxCbn/OnWaoePWquBBsSd+YFw6EANyXV4KPjQQEZhtFxoDGMnL7G2OACMI/nYRsWdA5XZjyT8MtOGouilnDlOFJKv8ce6YoDee7vtMCni3H8PdI7/OGwKfHGFJl42q4EsX5vrYsnUK5Fpa66PlzJotgub2WzU/6/eNuJtYpoXrIq0dWeTOoxuT7hEXUQbps96yGkkBXZVZv6JJkhmm0rcqEmeTDUI/GI1RYVHwONdaKxBlVMzhK8/zp61ZjsBhVC4N5fpEfeFLRHr7DLjpEbV+25VG0G30MeqP2i4bUv+K3D6VKaAFyFHgTRl3dsmEFR5PDg1OX03OUA/xBlcG8sga5KLduOYZj+mktniAL+Lg6rXiCc478QCuX9fUq0txuqpIOCYRYYPKTJ8INF5c6rgMVyuTxvs8 PMiOHVEx VXtS41JPV79nQy6cy0n7BVmy8LCta/zWe2t5Kdv9J90WCjzoTAWBOLucG4C+ma+lzC7/yg6S1An6OQm7WPebWwUj9bmPwCunZdYUpa1EtWFNqlKrePuBduzfUC6w1mdhncn31VUZAHKFZQ1h69XxcIHpTlPAwoB191WPLemXLs70YgDhS5kw6PbNqgHww4G0Jv7Cmwkvswj6T6LQ2Ut78e4+DgT5S5vM1sBVJHkV3m40XsgZZ6ikHSUZYf6VIGGqF3oIrPw4vdOnOWJxAf35jm7Y8hsn+cpA6UPQPtWK+ig/+E+PWPvjaekzUFEtX21cfQO5ku0AvaFElKVk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein FANOTIFY_PIDFD_INFO_HDR_LEN is not the length of the header. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 8528c1bfee7d..9cc4a9ac1515 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -118,7 +118,7 @@ struct kmem_cache *fanotify_perm_event_cachep __ro_after_init; #define FANOTIFY_EVENT_ALIGN 4 #define FANOTIFY_FID_INFO_HDR_LEN \ (sizeof(struct fanotify_event_info_fid) + sizeof(struct file_handle)) -#define FANOTIFY_PIDFD_INFO_HDR_LEN \ +#define FANOTIFY_PIDFD_INFO_LEN \ sizeof(struct fanotify_event_info_pidfd) #define FANOTIFY_ERROR_INFO_LEN \ (sizeof(struct fanotify_event_info_error)) @@ -173,14 +173,14 @@ static size_t fanotify_event_len(unsigned int info_mode, dot_len = 1; } - if (info_mode & FAN_REPORT_PIDFD) - event_len += FANOTIFY_PIDFD_INFO_HDR_LEN; - if (fanotify_event_has_object_fh(event)) { fh_len = fanotify_event_object_fh_len(event); event_len += fanotify_fid_info_len(fh_len, dot_len); } + if (info_mode & FAN_REPORT_PIDFD) + event_len += FANOTIFY_PIDFD_INFO_LEN; + return event_len; } @@ -503,7 +503,7 @@ static int copy_pidfd_info_to_user(int pidfd, size_t count) { struct fanotify_event_info_pidfd info = { }; - size_t info_len = FANOTIFY_PIDFD_INFO_HDR_LEN; + size_t info_len = FANOTIFY_PIDFD_INFO_LEN; if (WARN_ON_ONCE(info_len > count)) return -EFAULT; From patchwork Tue Nov 12 17:55:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872730 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 0A0E5D42BBF for ; Tue, 12 Nov 2024 17:56:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3EB66B0095; Tue, 12 Nov 2024 12:56:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A10B6B00FF; Tue, 12 Nov 2024 12:56:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81BE56B0100; Tue, 12 Nov 2024 12:56:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 57FFD6B0095 for ; Tue, 12 Nov 2024 12:56:37 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 07818C04D5 for ; Tue, 12 Nov 2024 17:56:37 +0000 (UTC) X-FDA: 82778195892.13.CE0EF22 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf08.hostedemail.com (Postfix) with ESMTP id 4558F160026 for ; Tue, 12 Nov 2024 17:56:07 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=trLXm8Kg; dmarc=none; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.177) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434108; 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=c28yJdRjKgJn+HaLKJzmXzT/1RpIgNKOoAPY3XeErlk=; b=z1VnGRefrgZAXxv4FgfFGPuL45iC+uWMy2xfuG/FXK1VyiSftfaEqnceXj89cnbIyOrcY4 O3FKI7dpTJLOn/nzM9VTDn4rC5BIu79ku1J6DaNgX2LFKqt2gQTsxjFbheAhgldHX2gBAv MlSkjwMnXer4KHTbRPP2XgG5wkt6ls4= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=trLXm8Kg; dmarc=none; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.177) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434108; a=rsa-sha256; cv=none; b=wSiNjG3jt8FAQ0zr035tHFJez3jqT//9J9HjWPOFyjLL1CqgtsETqWFiM5VKQdYM+3lywp yfDUerfaWQEBTxhmbR/RnjQLOmLuQ51EmK0m7ZXXYReGWOeNUir1dZzTxXBANI9wJy4hGe OSh9r+yr+mtGNlKWJUvIxInBXxJuipw= Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e35e9e993f9so421059276.0 for ; Tue, 12 Nov 2024 09:56:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434194; x=1732038994; 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=c28yJdRjKgJn+HaLKJzmXzT/1RpIgNKOoAPY3XeErlk=; b=trLXm8KgRvrs1tv7tFTWtT9QzT4pkH3xwzeybXioIg6PA80VoTFkm3WwYKiB1H78fb zaxU+F93alCneoXq/2IOYADg1LSvkP/JqRtnRTLWWt7///8dbaqkmh+6d6v9TEY108aH hgr5lnjsrk/3iaHNd6o+x2eb9hwXiQMJ0UGSWJLiYiT3WWHL5UNIduZ7lS9g6ed6xy2W wNj9CsDD+7RDARXaVy6USfTDkjZeiODyTz//8E1RzmElGEVKZ0TjxKWay9qPbqg53g/l ZB22+RhGMj1veH5maxfYVenyd3fNnOYeopw7XHwDWBOn0kAi9yPy3mzzGYwi66RvUXiE AWyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434194; x=1732038994; 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=c28yJdRjKgJn+HaLKJzmXzT/1RpIgNKOoAPY3XeErlk=; b=g5ql3reYhyulViQXpln4j7Mr5CInOIcLX2B8qJMAM/6w3xRHN3VupvPHBWEobCBdII 5tty15YNo2Hif7DLvkuCLAcFL2pt80lKMR2qFsGxXL7Yr1ClVFyP3gWnL1NUV37IcfQ1 x5RrrYR13nZHBx+gzhW6UdjOmDNF/ATlBE7Z6A9L7+RdJhf4Vl8+V8IU6Zxj+4zmmrtx 95eLLZxBFjXGya4a5TNNgWh8z/qzYXgZcslhjxTKrKblisV6eUDO9VzPi98gKLFOz3gT J/PspS+2YhDIjpzdrJvMRMw6XV2xQHd1M4nF7n7/WTANqeG47W3nE20dCm8cNTpeHbJh Y1FQ== X-Forwarded-Encrypted: i=1; AJvYcCWUtMOx+TFsSgWzKcPvMJ28CimGNUA3jQQWNFg4IBaiYqxmP65tOYNrC4a7NaEKA93q7cO+WtkUUA==@kvack.org X-Gm-Message-State: AOJu0Yxz4XFkKNCJvL5OjS+N0sPtWVXngg7rh3+eDi8L3RMEfiL0/6/C Jcelbe4G6zHGKZn7wH5Blaj1ahLq4nRlb6BfiKG2+9Ne95WburhwtdWpSMUgfTw= X-Google-Smtp-Source: AGHT+IGHOswKyJpRxtAUdSHm9RVyiLr7O2lKHvfik/aOxq8+Vnb458JxpogP2HSmvoOplu22cOYVQg== X-Received: by 2002:a05:6902:728:b0:e2b:dce5:9c93 with SMTP id 3f1490d57ef6-e337f844799mr17781398276.7.1731434194365; Tue, 12 Nov 2024 09:56:34 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336ef48465sm2752627276.31.2024.11.12.09.56.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:33 -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 04/18] fanotify: reserve event bit of deprecated FAN_DIR_MODIFY Date: Tue, 12 Nov 2024 12:55:19 -0500 Message-ID: <22d02743468d137aeb73dfbc7bef44efd361785d.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: rspam03 X-Rspamd-Queue-Id: 4558F160026 X-Stat-Signature: for83etb7mnrdgx44ntqu4weto5rxbxu X-HE-Tag: 1731434167-323966 X-HE-Meta: U2FsdGVkX19Oc1Q2HCTpbMWADU+0QJsnP7hmn+NUrnqkRpXfPFcwgRUkd6vnycF7HpMEF2G3wSs6+se6BegKjdYCjXGLxKxa1EQYWyBNWVXOyBJW0n5dSOBODst0fp0E4s1KPW+4A+hjLXx+cLeqrrlJkOFNAfjR1AamgeDYVi2bB8fwV1BLwDTeZgDSqGLlHtpi4dNutptTdohyC4P92UPz7xfDodn8gpiXPvBfYQ47nwMI0OzvmoVcU4O1nOT0GDdUHEVC6soim7fw3ROwtSL1eLCVj8xEBoV5CLPnzurjo5w0Z6Je3H8jq42dg9/5py8dtqYxR7rg3cchxVDY5o6CfpSrcnDafhE23n91NdAbLKzaUZ0Nd7zARNhSog+1E3U/A6Rwdkr6ww+t4ejbftaIxbYen/G3FfXxiNRIQio6pRhha3KqUyGhIv4oXdnsP9iN+ETdDOoA5ij1iTTFVrShWrnb/ld3xQA5B43vnJuZ2nCvJmJVNK++BFjpmRyjvk10JrkdRWTikuDghwV1glDwq207FHpgMhdNZD/2nwFPg0+k4NMD4JTiI0hCO/fsKrAxsIc1CVsrjhJE7z4Sr9I8hz+upChJz+M98RQWOiC2LmEMYhMBvqJZDQZrQ+LGriZA6UJzDsyMiSSGqDESknmNzZeDCWa+jOH9EyuQS7cej8HXMx6cNmObYsDxQho9/t00jcZ1PMq9n8ujzQTjOPsgK63fOuOqjcf6uiPFwljiIhB/UfnI19sAezUJwj45DmJ4c0GPtnpHnIpc8ThEYesGV01lXkjBfEkXPOaJzBKJiFEs6+mvVmC9vQre2Qwb426Q83brT8CmASrUuypKjWiMmEQL3wWdVq1zyT3YEUPo20WezuUpAl08DeZaQu/IXis26AtM6l0Q8UTv+uOPO9eY2rCDJ6voAFoyyIQegH4d4iW8SkmwlBG1Goahr+RUA1n1xlvCyVFS8JhOM9W XvEgUpg7 g2hFQe4h/SptOk5JErY8wxvQiOKu4/Y7DCfVMKXFPgSPMhxdAs2SU7DZ3xXHnb6gsICCpC+SjwJiePq2L5VfnUgqmAfpc0x0bwY8cZrLbwqTYPeXdlJG5rE6jv2XMuZDU952iVgDOAkdv4FPDdzVml8RK2WwiDNGom/BMrlTc0kJFsz6sFvcN5N4DxUyrEh+d3mWhKLmgLjO7dZnme/DU3wva1poVYP6WNutktht6hN0MCVnntiNP2Nf8nZZGyhFOMnwxtneZh38yzvXNASQfc6xhK4jIrOfek8UEVqp+ZQURPYObwlI8jEBGiy9iyxt3Y0mchZ/gJFQ+X1RdmW5r4W/JIPCGc0ncGXsPNCBnCrITl2591SUDGrcf9kAaPgWcMuRS+b/yknTqfd9eoRFuLBMFGANDHB1CGi/HtSimVrPvF9Bm/fNwrqwSxTFDalnOnQn3ED+uyyLdL2HqwewwXYRMguGs0GBi9qq2Yh36uQLPm9/F9m1E+lpRCm5UjwRjrwhS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000082, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Avoid reusing it, because we would like to reserve it for future FAN_PATH_MODIFY pre-content event. Signed-off-by: Amir Goldstein --- include/linux/fsnotify_backend.h | 1 + include/uapi/linux/fanotify.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 3ecf7768e577..53d5d0e02943 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -55,6 +55,7 @@ #define FS_OPEN_PERM 0x00010000 /* open event in an permission hook */ #define FS_ACCESS_PERM 0x00020000 /* access event in a permissions hook */ #define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */ +/* #define FS_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ /* * Set on inode mark that cares about things that happen to its children. diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 34f221d3a1b9..79072b6894f2 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -25,6 +25,7 @@ #define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ #define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ +/* #define FAN_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ From patchwork Tue Nov 12 17:55:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872731 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 C4004D42BBE for ; Tue, 12 Nov 2024 17:56:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4741C6B0100; Tue, 12 Nov 2024 12:56:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FE2F6B0102; Tue, 12 Nov 2024 12:56:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2763E6B0103; Tue, 12 Nov 2024 12:56:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 053926B0100 for ; Tue, 12 Nov 2024 12:56:38 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id ADDB0404B0 for ; Tue, 12 Nov 2024 17:56:38 +0000 (UTC) X-FDA: 82778197656.28.AA8CD75 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by imf09.hostedemail.com (Postfix) with ESMTP id C20C6140003 for ; Tue, 12 Nov 2024 17:56:07 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=3GRyiMZi; spf=none (imf09.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731433963; 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=iLJsKK7R4NzIWRPs6scvSLkW1qqZkqCVN1/0a/AzTQ4=; b=PhAVFvUBwpGDQ/Ltppr9X1DnqiPBhYvc5ohsvDgfhNOp45qZSpdHmujg4aB/oqx250PR2u hPsOP2BxFFxvpHZQWmrMht5+RQLlTJdybIo93VvvFFlO98BfJoyfNCFmjjC6u1GGMJg0Vp Ft719DmC+GGhv1+LpWlX8sAxlCADA0A= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=3GRyiMZi; spf=none (imf09.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731433963; a=rsa-sha256; cv=none; b=0lWdpIlphqRlD3o0AKbWbNncrwLg0lidhoOVKbOZKA1l//YBaMYn1GEUBzD7oA6CO1jtBm l1EnZtZ/WIVqt/C4RCHGcNBViIO5Pz+DO1UlZansPhnDjn2DLOvWPsbn6kdgP3dgezVI4B 4Iw5lfPbz2gDVrdtLnq1//DxR5VAEKU= Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e291f1d659aso5804946276.3 for ; Tue, 12 Nov 2024 09:56:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434196; x=1732038996; 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=iLJsKK7R4NzIWRPs6scvSLkW1qqZkqCVN1/0a/AzTQ4=; b=3GRyiMZi2XZvdHbBE5nmdo7lGHvh5FYl7tc0BZWyYSfg7+Jod5UdejHiLhXn1VXfHF 34lxzFCkO0Q9obCJ23brSQvSX4/QR9VeH0Zu4p/18Kq3MaoasASFuc56+OodbCU7ziZd 93d5skrj4rBTGRaOokksOgJxYZEPnN0QuQreLSuc8H+3H+bLPgyEwtIeFVu7qn+/eaxK AXMZCyFU0iM2iIGgqcXWcE5tPgg7A5EE1m8Y4YJCKarHqNvDJ1bnSh8sZf+x2Zf4H20y mUgt7uzER58WSFcDscmlsl4FydYq9HyvkyiQ0U7n4JWYiTJbrZEdp+Qqj7hdYo35aNDG tIyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434196; x=1732038996; 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=iLJsKK7R4NzIWRPs6scvSLkW1qqZkqCVN1/0a/AzTQ4=; b=dLvGS6dQP3jrS/NssPrIYT5aDrOcmvfdt2IjuXL01mTGcZHlzh1N7eMp5I1d0p95+S BjB8/4w6T5+xR0B0Tndi/bQyL3C2QQwaGLFggD1kSaLRMCoe8CJ9Vl3ZFcVTVjfz3Mxo YiL1eopg3h3SGuSwlM8Wsah8i7eBqFyMn0vuMf3oRuctMdW6SQchMBbnMk/t5eIdfNL8 OOXtdbzO8ejf1Vgr6yjPv9Bt0rHtq6f07LXuekL9s4M3SW7ZiHaYxvxYC67Fr4Bci/Z/ 8BSsxfMVPCxil/FwqR+iQyF5ZNXkGHI0SUqtPbEL9GQDRf/isBta1q0U7pyhML5ZzjH8 0VCg== X-Forwarded-Encrypted: i=1; AJvYcCVnwM6/5rLEbrezfc0pX0xz0lXtP2TFM3zHMoQrShoSVMxOoRe2RQsQyY+7NPaAhcP6/wF5kdOMFQ==@kvack.org X-Gm-Message-State: AOJu0YyYBmI07RTZpdGzOhMEw4PPhhcrHbRYyzzwUTS02uEOCMHBzHHs POOxgMtw2c1VxRN8ng7UcyNLoKlZCrJVePPYbkcxPaGiuJy5G/VoKxtglp/uZkk= X-Google-Smtp-Source: AGHT+IEOgMksI4ZuWIGKlsxQ62qh9QTja1/V58VuHmypKT67lw1RxIlzwCqUPq2uOUJYVFxRqQmgoQ== X-Received: by 2002:a05:6902:124f:b0:e2b:db9c:5366 with SMTP id 3f1490d57ef6-e337f8ced5cmr17506428276.37.1731434195837; Tue, 12 Nov 2024 09:56:35 -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-e336f1edd7csm2889924276.59.2024.11.12.09.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:35 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 05/18] fsnotify: introduce pre-content permission events Date: Tue, 12 Nov 2024 12:55:20 -0500 Message-ID: <141e2cc2dfac8b2f49c1c8d219dd7c20925b2cef.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C20C6140003 X-Stat-Signature: qigj9k8e7goczyyw1mnpjmduxyadwesc X-Rspam-User: X-HE-Tag: 1731434167-234007 X-HE-Meta: U2FsdGVkX1+DuOewpNr2DwAnFupuxj3QcQ0PgtZ7McggzO2CWCUtzoG6BuSyXQ0w3eyy/AHzSckNZtigf8qU2AsFhE1TrW/zrkSOfn6vv7ITEokZ2RctlTpBeQQJ9cueqNNF1Ep4q66xUhhguG9Bwn7WuUmVveEC/6ynUtm979vVx5QjZxpSQPvsyRTm1jitQfMw49S5Dg1BTlv5tet0+3fbkAyuSvDSvKXDjhil3PYVMOWSdMTykNcte6YTAZijoZZqMwznofjJ8Ai9oQRyjMOT3XeI+uFvIiN0xqIb38PU9RrPkX2ducJMQdtF8/8OQKpAgjyBAJa1Y2dhvSvZOjT7SoKOSCAnXAVbreDdoacFa27/H7FDKDDjmpAF2h3AvL3KnNqMwYDrv8DBuD+82BpPfXzNlDcJEpYsBgJ8czPa55X4wVTPXqONhkND48/7bw1Oh1eHUuC/OEhYXWw+TFWuvBfO+CcfC38Cd73t+jVDoag331GC2UZjSYDq11LSOyxbXwJbW4n4MDgWStpx5Tm4KcjJ416TlWsnAszL3RFK8gsmjw0g7HGwnugI8oxJIqjXS2aK3lp6PZifuJg1tac8A/HddM74Rli57Dl6IEE7DHYnHhmPadhX5VGrGTkqjgfy1A8z9IsuO/AAANv3FJjy0fAEIMtJ7PNK5HwsC1TZnadjWjC623IRaZNSNiPlKtJHOoQZM2sxJUc1hdW6yNLPsB7fNSGL/FZ+8XGGHfAeQ2fa51lT2qHJ2G37drGhQJOpRqoxIsfkUXf3FKh98tSQub+zV0GHAKIRd5szT6IlJopRcqF37zKgCIlCmb/qhUmPXKvi/JCPeMr9mJnE6cqkqu0wiB0o6ZcJ1EpXGA37NClBiOtqYpSlSjHRI+lHbInneswNb5mafp95DT/CaEopP0l3Cb82irFuk2zGQU4eMoN4FlrccMktHKrFsijGj1sZU3kxuOIbW6954T+ JGLs2v9o x4jIHlqAIAwMaiNCDvOmbKtun9JXGPezOVzwblyYuvsgStboxZxNF3hd3LE7qcpQ7bVtsMlNw3PJnmVjnZllRsc/HCrzIp55HrYADsI4j724fPCV13aTj2BY6+VDgGAlPD7XVYjwmxT++k9cpF8JcST21huNkNKV0FFKjejPeYxg3OeKlMlKjr5YJ/k2UsvJntSk4AgQmJf82w0GxtQDAIGl2wYuVDp50nIFcRtK+1bH+z0II9BGIVpre1T1d9MfON9NzImFR5XpOBizPpxyh2J23dJj5ZXoxp1zRP79uc9Y1UuBnmke2OxOzLou3PMgniiOORHszsZjCK6Z8aIVu01fJEOHlU9BBYtjZv898mA2cZOX92jbTsfmBC2c3/opXRivACRzTX+xqXPVt58kfZZHQHU7UYOJbytKX97h1d+7+RaSUlNfze+JiE15gpwJJxDk6tIAt0iQaG8I= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein The new FS_PRE_ACCESS permission event is similar to FS_ACCESS_PERM, but it meant for a different use case of filling file content before access to a file range, so it has slightly different semantics. Generate FS_PRE_ACCESS/FS_ACCESS_PERM as two seperate events, so content scanners could inspect the content filled by pre-content event handler. Unlike FS_ACCESS_PERM, FS_PRE_ACCESS is also called before a file is modified by syscalls as write() and fallocate(). FS_ACCESS_PERM is reported also on blockdev and pipes, but the new pre-content events are only reported for regular files and dirs. The pre-content events are meant to be used by hierarchical storage managers that want to fill the content of files on first access. There are some specific requirements from filesystems that could be used with pre-content events, so add a flag for fs to opt-in for pre-content events explicitly before they can be used. Signed-off-by: Amir Goldstein Reviewed-by: Amir Goldstein --- fs/notify/fsnotify.c | 2 +- include/linux/fs.h | 1 + include/linux/fsnotify.h | 37 ++++++++++++++++++++++++++++---- include/linux/fsnotify_backend.h | 12 +++++++++-- security/selinux/hooks.c | 3 ++- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 316eec309299..cab5a1a16e57 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -626,7 +626,7 @@ static __init int fsnotify_init(void) { int ret; - BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 23); + BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 24); ret = init_srcu_struct(&fsnotify_mark_srcu); if (ret) diff --git a/include/linux/fs.h b/include/linux/fs.h index 9b58e9887e4b..ee0637fcb197 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1232,6 +1232,7 @@ extern int send_sigurg(struct file *file); #define SB_I_RETIRED 0x00000800 /* superblock shouldn't be reused */ #define SB_I_NOUMASK 0x00001000 /* VFS does not apply umask */ #define SB_I_NOIDMAP 0x00002000 /* No idmapped mounts on this superblock */ +#define SB_I_ALLOW_HSM 0x00004000 /* Allow HSM events on this superblock */ /* Possible states of 'frozen' field */ enum { diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index f0fd3dcae654..0f44cd60ac9a 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -154,14 +154,29 @@ static inline int fsnotify_file(struct file *file, __u32 mask) } #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +static inline int fsnotify_pre_content(struct file *file) +{ + struct inode *inode = file_inode(file); + + /* + * Pre-content events are only reported for regular files and dirs + * if there are any pre-content event watchers on this sb. + */ + if ((!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) || + !(inode->i_sb->s_iflags & SB_I_ALLOW_HSM) || + !fsnotify_sb_has_priority_watchers(inode->i_sb, + FSNOTIFY_PRIO_PRE_CONTENT)) + return 0; + + return fsnotify_file(file, FS_PRE_ACCESS); +} + /* - * fsnotify_file_area_perm - permission hook before access to file range + * fsnotify_file_area_perm - permission hook before access of file range */ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, const loff_t *ppos, size_t count) { - __u32 fsnotify_mask = FS_ACCESS_PERM; - /* * filesystem may be modified in the context of permission events * (e.g. by HSM filling a file on access), so sb freeze protection @@ -169,10 +184,24 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, */ lockdep_assert_once(file_write_not_started(file)); + /* + * read()/write and other types of access generate pre-content events. + */ + if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS)) { + int ret = fsnotify_pre_content(file); + + if (ret) + return ret; + } + if (!(perm_mask & MAY_READ)) return 0; - return fsnotify_file(file, fsnotify_mask); + /* + * read() also generates the legacy FS_ACCESS_PERM event, so content + * scanners can inspect the content filled by pre-content event. + */ + return fsnotify_file(file, FS_ACCESS_PERM); } /* diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 53d5d0e02943..9bda354b5538 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -57,6 +57,8 @@ #define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */ /* #define FS_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ +#define FS_PRE_ACCESS 0x00100000 /* Pre-content access hook */ + /* * Set on inode mark that cares about things that happen to its children. * Always set for dnotify and inotify. @@ -78,8 +80,14 @@ */ #define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE | FS_RENAME) -#define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM | \ - FS_OPEN_EXEC_PERM) +/* Content events can be used to inspect file content */ +#define FSNOTIFY_CONTENT_PERM_EVENTS (FS_OPEN_PERM | FS_OPEN_EXEC_PERM | \ + FS_ACCESS_PERM) +/* Pre-content events can be used to fill file content */ +#define FSNOTIFY_PRE_CONTENT_EVENTS (FS_PRE_ACCESS) + +#define ALL_FSNOTIFY_PERM_EVENTS (FSNOTIFY_CONTENT_PERM_EVENTS | \ + FSNOTIFY_PRE_CONTENT_EVENTS) /* * This is a list of all events that may get sent to a parent that is watching diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index fc926d3cac6e..c6f38705c715 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -3404,7 +3404,8 @@ static int selinux_path_notify(const struct path *path, u64 mask, perm |= FILE__WATCH_WITH_PERM; /* watches on read-like events need the file:watch_reads permission */ - if (mask & (FS_ACCESS | FS_ACCESS_PERM | FS_CLOSE_NOWRITE)) + if (mask & (FS_ACCESS | FS_ACCESS_PERM | FS_PRE_ACCESS | + FS_CLOSE_NOWRITE)) perm |= FILE__WATCH_READS; return path_has_perm(current_cred(), path, perm); From patchwork Tue Nov 12 17:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872732 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 ED887D42BBA for ; Tue, 12 Nov 2024 17:56:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 250596B0104; Tue, 12 Nov 2024 12:56:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 201086B0103; Tue, 12 Nov 2024 12:56:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 052B36B0104; Tue, 12 Nov 2024 12:56:40 -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 CC7706B0102 for ; Tue, 12 Nov 2024 12:56:40 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 55D24140539 for ; Tue, 12 Nov 2024 17:56:40 +0000 (UTC) X-FDA: 82778195220.17.DD6E3B1 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) by imf22.hostedemail.com (Postfix) with ESMTP id 60526C000E for ; Tue, 12 Nov 2024 17:55:46 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=PRua1+Hv; dmarc=none; spf=none (imf22.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.169) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434022; 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=9qmzKtSqQfrhv9mwfplhMG+Dc91SaSr6kT90grfFzXE=; b=TSUeYVu26XqffsCYicV37UuzM/VE8zoEsBTlqXnU2oGNMY7EngBQuYAvM8omX8dMJ9hfEQ TIa15V+uEKGP+Qsx4SpL4swnWQzhrXDCHj95/G04nZIWH2aD3ETa1cFRWt7S4NZ2TmYvcP BhFLIw8LVzmbUTPHiFtmW7KNqmnufUc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=PRua1+Hv; dmarc=none; spf=none (imf22.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.169) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434022; a=rsa-sha256; cv=none; b=nJVZ4dvVk55EIaRYjxD9QMkfIl3zSSGQFbXymXd4BWs+j2HoBk4dkUSWKM4avvCHsUSISa Qdyh/Oo/2exBKLBBniV6DcgNiHlVQiM4w+TfFpG5Zbe5tqLiYmJWX1dZVSRXZWalUaJ5r9 sUfvtjq2fpRb1pKdR5rbEA0sPZipdj0= Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-6ea7c26e195so61476727b3.0 for ; Tue, 12 Nov 2024 09:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434198; x=1732038998; 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=9qmzKtSqQfrhv9mwfplhMG+Dc91SaSr6kT90grfFzXE=; b=PRua1+Hva79vgl8yXshIRK8Dhxu7SaTZPA60P0RcogoJ8t6FlR7h0c8P+RKrp8fAzk wYTtMLqCPCUFyRM7mIRHEu92mBb7SvXkWCmyH8Hvp0gtnns+bWFBIYh5vOOCtm87DJWB YBmkVWStkFkO62/hzcgnG4frep3y4eyRvqu/ITYbBCaBLaAB5etUsKglkwOTmDt3db9J SJofaDyRErG2lGzEw9amj9kUyDGD+IclQx1Yds2AUFS/S5HmBGaDI9SN0xZlkXP6edu2 hA18hyu1RGkJP/EAawv29EjCI5mBagsPRvgbT6FBCzwOGOWXLu1tkDFOk+2E+Ex4Dkak WLDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434198; x=1732038998; 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=9qmzKtSqQfrhv9mwfplhMG+Dc91SaSr6kT90grfFzXE=; b=slFNxHUqv4oGHUOxeV9MgIh4ff5AGa4Lb2GE1Hn8dCNgOYzq+LXGT66isBw0Ssbv7H HeRLZ+F/ZD9qh1KSTfaIxXILbmWgE+b5QuUSV2lk0T2wAdANuBOThe1AoM6R/TFIsnn4 0Yx7ysRTKJjjdG05JR9kUie49LwAjbDJF3eInPKX1TDHcXXf3DFXIDSAEIL5JF8p3H84 3wsHRLEId57eXaQzFQuRP6hKxFcMsIBQwyo70BN97OQl71eZUtWBJUXrVQ33g7Bc1Td7 rLOf8IcTpjSPdBt52cQ7AfCLwyBa1Aa62ihsPjK5LFWKGAXfJNa45w6vg05VB5q3P8JK r0EQ== X-Forwarded-Encrypted: i=1; AJvYcCUuGVNX8U45MzsdkJ3vgv2jAxNXADi+IqNJQ2StI51+kdITsGozkCP72G75FV6ZlPtVHd0YBO0pIg==@kvack.org X-Gm-Message-State: AOJu0YyZbCDARbSN5Oo/NKFnhZotc2QXYIMQj8f9Csm1r1opnS0BhvEw 0r8O7tmfNRvzx338v8yjnIXtkUFGN5pfKFhr/B8AzGKwnFn2cqRWUUDCH6GYbu8= X-Google-Smtp-Source: AGHT+IHyY6QTMjull+z1rPYeXNfxhgVBLW70xt2rGV+KFU983vos+ZL89drz2YsnyEbkmVx23Jm32A== X-Received: by 2002:a05:690c:6885:b0:6ea:7afd:d901 with SMTP id 00721157ae682-6eaddd98734mr177756967b3.18.1731434197704; Tue, 12 Nov 2024 09:56:37 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb65a9csm26511117b3.92.2024.11.12.09.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:37 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 06/18] fsnotify: pass optional file access range in pre-content event Date: Tue, 12 Nov 2024 12:55:21 -0500 Message-ID: <715ea468f03513b1b1a8e478f7096acc69a227fe.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 60526C000E X-Stat-Signature: tm8umeoh9hpfj9foopzf99hui7i1qimk X-Rspam-User: X-HE-Tag: 1731434146-800985 X-HE-Meta: U2FsdGVkX19GKFex7OT4289U0ocIebM8Uu3aMjwBIIwsO3DMbXwwI6mjCrlKqtrBtvHKe5eX+/S2W01gPpWa54x2pmRTwjFtSj1PE4acIu0Za30grQgm9/avfoMuIuR05YnLBKhO9b5bcmdLj4kTXjwgvDhkds2ur2jhQrDi0vH3F0KhSOUf/tBA1YQIHHHNoLI6fX3rfgFYZWwkik9oQ0XhJU78Ulje9gIPaiR2i6dwnNsgeIZrmu+Q0qOl6xubQgD3Gon76xG0urYou115o4MP07WcU53q03IaCIhXDf93HJWhXMlQ47yiz4aPKmZ8gDbtSJRYWgVzv5H+lzEqpBE2diYS3jU5vG9vhL6zvLKmQAmJe8F4Oxgx//bQWuAlk3wXW0Rw4eLdW9QPF7t+6T35xHBE0Ea0b2YYnyrpTLdnB91xcsG6HA/KmfEn/Eh5ZHuZi3322AGZWHDfzfBM/DI6ieMa82NUBSGSJ2WTT9U3mW0G7wMcBayZLjDFlNk9DXjNOGaqi0OMAQJWFQKMFiJ5mTPyMWdb5+EcVb2J8IMlb8/EQ2l+oWWRodCuK/Tu4iWtQoO7G+Pb7lml+CDVqFXrseY/Yf//eF1jKxtY+uuAu9smwLByZkNpccHZY/vDk7/+fkzNGVtXzQJ1mG41FL8SJuScgMgv5bzn4uI5xYT3k3WG+PXVxBrs2ExxatxBC9ZohycICieGi9/tSsawc+09lfuuW9r0FXg5pP+vbgMZRvzgpeff1quDOY0RdpvcvudIz8H74ltDxBsz7GFyU5/3lZdWWQUVBLw5AC9rLps4uUON7hk6kByj2kI5/OtcME39v0DwNPUUcrt38WUFsSnzYOzCvJtnLCM5TSob/e9/DyiOYgC0Ap6Jp48zfIMQpqmcvfoaa8UwW3GkmFAaRHsYQAxm2LB5y+OdV51VSFjAvpZLx45u8OCIObvw8G8cdpz2EWyaI66+G03kGRS 1X6WJuCq d3n/C5/qwjfMmZlRpq7LO8rK9Rd54AbVaesm6ojoP40TNlqcvReYiS7g3pced5hKNM0P+NuXBlUYjZQW4B1zCPdd1stAMe02Z/4GYcQntLaj3em3pUFECDJyIIg9nSW6ZT3huN/wxnYY/a2bK/pXfU584HgQyek2W6BVmqDmjF9PjD4K1t5KbSDCWutT57mcp1YdElqLW17cNopgoMDJXFCpw+nk+DEKIOVuck/Y+CG9PStDs+Qi08MOiTMPO8SuBoXhs3124gofKoppfGaSAvvx/XyncHXHOs0GszAyg9DG+h33omgmCJvu+Xqb3bHwkD02F+bO652dPv4NZ97dcJndWFw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein We would like to add file range information to pre-content events. Pass a struct file_range with offset and length to event handler along with pre-content permission event. The offset and length are aligned to page size, but we may need to align them to minimum folio size for filesystems with large block size. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 11 +++++++++-- fs/notify/fanotify/fanotify.h | 2 ++ include/linux/fsnotify.h | 28 ++++++++++++++++++++++++---- include/linux/fsnotify_backend.h | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 24c7c5df4998..2e6ba94ec405 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -548,9 +548,13 @@ static struct fanotify_event *fanotify_alloc_path_event(const struct path *path, return &pevent->fae; } -static struct fanotify_event *fanotify_alloc_perm_event(const struct path *path, +static struct fanotify_event *fanotify_alloc_perm_event(const void *data, + int data_type, gfp_t gfp) { + const struct path *path = fsnotify_data_path(data, data_type); + const struct file_range *range = + fsnotify_data_file_range(data, data_type); struct fanotify_perm_event *pevent; pevent = kmem_cache_alloc(fanotify_perm_event_cachep, gfp); @@ -564,6 +568,9 @@ static struct fanotify_event *fanotify_alloc_perm_event(const struct path *path, pevent->hdr.len = 0; pevent->state = FAN_EVENT_INIT; pevent->path = *path; + /* NULL ppos means no range info */ + pevent->ppos = range ? &range->pos : NULL; + pevent->count = range ? range->count : 0; path_get(path); return &pevent->fae; @@ -801,7 +808,7 @@ static struct fanotify_event *fanotify_alloc_event( old_memcg = set_active_memcg(group->memcg); if (fanotify_is_perm_event(mask)) { - event = fanotify_alloc_perm_event(path, gfp); + event = fanotify_alloc_perm_event(data, data_type, gfp); } else if (fanotify_is_error_event(mask)) { event = fanotify_alloc_error_event(group, fsid, data, data_type, &hash); diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index e5ab33cae6a7..93598b7d5952 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -425,6 +425,8 @@ FANOTIFY_PE(struct fanotify_event *event) struct fanotify_perm_event { struct fanotify_event fae; struct path path; + const loff_t *ppos; /* optional file range info */ + size_t count; u32 response; /* userspace answer to the event */ unsigned short state; /* state of the event */ int fd; /* fd we passed to userspace for this event */ diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 0f44cd60ac9a..7110bc2f5aa7 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -154,9 +154,16 @@ static inline int fsnotify_file(struct file *file, __u32 mask) } #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS -static inline int fsnotify_pre_content(struct file *file) +static inline int fsnotify_pre_content(const struct file *file, + const loff_t *ppos, size_t count) { struct inode *inode = file_inode(file); + struct file_range range; + const void *data; + int data_type; + + if (!fsnotify_file_watchable(file, FS_PRE_ACCESS)) + return 0; /* * Pre-content events are only reported for regular files and dirs @@ -168,7 +175,20 @@ static inline int fsnotify_pre_content(struct file *file) FSNOTIFY_PRIO_PRE_CONTENT)) return 0; - return fsnotify_file(file, FS_PRE_ACCESS); + /* Report page aligned range only when pos is known */ + if (ppos) { + range.path = &file->f_path; + range.pos = PAGE_ALIGN_DOWN(*ppos); + range.count = PAGE_ALIGN(*ppos + count) - range.pos; + data = ⦥ + data_type = FSNOTIFY_EVENT_FILE_RANGE; + } else { + data = &file->f_path; + data_type = FSNOTIFY_EVENT_PATH; + } + + return fsnotify_parent(file->f_path.dentry, FS_PRE_ACCESS, + data, data_type); } /* @@ -188,7 +208,7 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, * read()/write and other types of access generate pre-content events. */ if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS)) { - int ret = fsnotify_pre_content(file); + int ret = fsnotify_pre_content(file, ppos, count); if (ret) return ret; @@ -205,7 +225,7 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, } /* - * fsnotify_file_perm - permission hook before file access + * fsnotify_file_perm - permission hook before file access (unknown range) */ static inline int fsnotify_file_perm(struct file *file, int perm_mask) { diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 9bda354b5538..abd292edb48c 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -294,6 +294,7 @@ static inline void fsnotify_group_assert_locked(struct fsnotify_group *group) /* When calling fsnotify tell it if the data is a path or inode */ enum fsnotify_data_type { FSNOTIFY_EVENT_NONE, + FSNOTIFY_EVENT_FILE_RANGE, FSNOTIFY_EVENT_PATH, FSNOTIFY_EVENT_INODE, FSNOTIFY_EVENT_DENTRY, @@ -306,6 +307,17 @@ struct fs_error_report { struct super_block *sb; }; +struct file_range { + const struct path *path; + loff_t pos; + size_t count; +}; + +static inline const struct path *file_range_path(const struct file_range *range) +{ + return range->path; +} + static inline struct inode *fsnotify_data_inode(const void *data, int data_type) { switch (data_type) { @@ -315,6 +327,8 @@ static inline struct inode *fsnotify_data_inode(const void *data, int data_type) return d_inode(data); case FSNOTIFY_EVENT_PATH: return d_inode(((const struct path *)data)->dentry); + case FSNOTIFY_EVENT_FILE_RANGE: + return d_inode(file_range_path(data)->dentry); case FSNOTIFY_EVENT_ERROR: return ((struct fs_error_report *)data)->inode; default: @@ -330,6 +344,8 @@ static inline struct dentry *fsnotify_data_dentry(const void *data, int data_typ return (struct dentry *)data; case FSNOTIFY_EVENT_PATH: return ((const struct path *)data)->dentry; + case FSNOTIFY_EVENT_FILE_RANGE: + return file_range_path(data)->dentry; default: return NULL; } @@ -341,6 +357,8 @@ static inline const struct path *fsnotify_data_path(const void *data, switch (data_type) { case FSNOTIFY_EVENT_PATH: return data; + case FSNOTIFY_EVENT_FILE_RANGE: + return file_range_path(data); default: return NULL; } @@ -356,6 +374,8 @@ static inline struct super_block *fsnotify_data_sb(const void *data, return ((struct dentry *)data)->d_sb; case FSNOTIFY_EVENT_PATH: return ((const struct path *)data)->dentry->d_sb; + case FSNOTIFY_EVENT_FILE_RANGE: + return file_range_path(data)->dentry->d_sb; case FSNOTIFY_EVENT_ERROR: return ((struct fs_error_report *) data)->sb; default: @@ -375,6 +395,18 @@ static inline struct fs_error_report *fsnotify_data_error_report( } } +static inline const struct file_range *fsnotify_data_file_range( + const void *data, + int data_type) +{ + switch (data_type) { + case FSNOTIFY_EVENT_FILE_RANGE: + return (struct file_range *)data; + default: + return NULL; + } +} + /* * Index to merged marks iterator array that correlates to a type of watch. * The type of watched object can be deduced from the iterator type, but not From patchwork Tue Nov 12 17:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872733 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 2E3BFD42BBA for ; Tue, 12 Nov 2024 17:56:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A40116B0102; Tue, 12 Nov 2024 12:56:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F12C6B0103; Tue, 12 Nov 2024 12:56:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81B7E6B0105; Tue, 12 Nov 2024 12:56:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 58EBC6B0102 for ; Tue, 12 Nov 2024 12:56:42 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 104C1A0395 for ; Tue, 12 Nov 2024 17:56:42 +0000 (UTC) X-FDA: 82778196480.27.47D6207 Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) by imf28.hostedemail.com (Postfix) with ESMTP id 7E057C000D for ; Tue, 12 Nov 2024 17:55:57 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ySOdZJoM; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.181) 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=1731434026; 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=f/zk511lAvWJc9DDqLFXDlls0KrGnQ6iorjj31bM1x8=; b=fUKQIc0GnWnjepgqKqn248akohWVTVZ35BFzI4viAvZWnBW1L3FjgaSLXIZNXiwW9se8sq PlQ5iLLvxvXasA42kw0iI4FJE0Lu12fiVT0upfKzqx/Vx+3bdAby26MQFt1BYKXk9wJiZi 6FcU3I3NBk94KH8BIml5zz2mNoCPnDc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ySOdZJoM; spf=none (imf28.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.181) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434026; a=rsa-sha256; cv=none; b=WoAuxsOQreDHVu4yiy596o49TkFtnpap459EH+6j9IsG8F15WxEpZh1N/gTAGg915q063C SZQ5DADzgAfGWk5gSq2f/pZnyuQVCWFpEFH43c7u1/FDuN9VDZc8Y463NfOB5lOITeUgr+ YIu9++fhiDjoBvuTWz0NDJbFtO9NVqE= Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-6e5cec98cceso46848727b3.2 for ; Tue, 12 Nov 2024 09:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434199; x=1732038999; 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=f/zk511lAvWJc9DDqLFXDlls0KrGnQ6iorjj31bM1x8=; b=ySOdZJoMjXWhObSUJ47f2jAl/0XAQr39uEcsb/zkumyFw+xwOKIVCcZ+z7XnQaZ1DN WOG6eBu1v/VQ2hoz2wrnD3hNPLdLJ6lP9u72kZapgrIqu4kYDvvRD75Cqogq5zQT5PSs ImlYYpPNGo+8Mtyj6midqyNi0s3RzpUb8+WbRyFWhDGQUHUynmEcRnKQdmEc+uLLR25t TkJlAGijSXdiAKCnZ+l/AlnuT2Pn8uncbypAs+flmYWseHVNgjJkAWPYBe0j8yiQo1xm EEoFNAD5eaGOqsM27aRTtUYITH5DGNo5Bp5pUEfS6Me/5Q2onxdtuiJEkMde560la5EO cZFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434199; x=1732038999; 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=f/zk511lAvWJc9DDqLFXDlls0KrGnQ6iorjj31bM1x8=; b=iPgJnStRx6nSfwKaHNSCUeJLsafqgA+NPBf4bfWU7eJKHCi5YbiLr7L5e4hik6NRJ9 g6uWp0WL71ezH3gUWSc/DXpfbQ5mo8kDV9AB4wosjw/mh8r1ZgepPjVlFAFCuCwoL0iJ 8KlNyFTJGp8nbMADM0qRLvBXUc0RAAZjEHIVsB4I4RiqS7gJCwv5q+7NP2S09uqqaTq3 g1jViA+onYfffrjoPDrnrqVpDPc1KuAEoqftY4AbanBciZ9uYqDeN2xPNHaUVDR9edPa g616u4BVxLiYOE/opdKdryGEghJHWbELxkPeXh5TLl5Y/PWCZg1G/pwt+S7Q1f9qPlOy ZvVQ== X-Forwarded-Encrypted: i=1; AJvYcCWelD+v6xuAyB9tfifgxQdpRiIRjyl0N+8EHYtO/fCdOVH1B/iCj/KHNydqYu/GGV+nt7Zl1tKP0Q==@kvack.org X-Gm-Message-State: AOJu0YwEh/VL0q5tS88eYrkYO+rocFn3JjUFuvbtJW3RN/jvyG/FDauu 5/KNik2tJhLV8IAo1XN+sYpyXFcyVqYPoBEvm6f56yjA3x+G0o59iwvtrxHZrTo= X-Google-Smtp-Source: AGHT+IF3UHQJ040IIKGHttfPGwPkHcoNpKCF3umoPrbhTPK8Z7j1Ql7aKyWKk9X3oelY5giKEXNyJQ== X-Received: by 2002:a05:690c:314:b0:6e5:bca9:cb8f with SMTP id 00721157ae682-6eaddfa3b62mr164950927b3.38.1731434199260; Tue, 12 Nov 2024 09:56:39 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8d5133sm26365837b3.12.2024.11.12.09.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:38 -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 07/18] fsnotify: generate pre-content permission event on open Date: Tue, 12 Nov 2024 12:55:22 -0500 Message-ID: <60a2309da948dc81e4c66b9e5fe3f1e2faa2010e.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7E057C000D X-Stat-Signature: t7t77zi6655wra5m4wyzh3zu94t5fgns X-Rspam-User: X-HE-Tag: 1731434157-288606 X-HE-Meta: U2FsdGVkX18oFGITe8FfHeVLPDt4W8QWWI+vULxMssvrTv56brc1x31QAYXCikgAZF4Kpji1vFuDwC1Xyv1/jypzmlUsCqkTTMRW0g4pM9d+zGCFZxhMOcvYgiF7D2EOzv2dKpuF/RBU24470nyUpoHkm6z1MYcGYabHz7PMHa1VdqCgg+k/Kbxwn7gqhAqaLLzkaoOJH8ZePPvkwQ92fZ5+XsKgafLbUyxJU6cEyumxd4IT68Nvq0xYcAZ5PH/yR2AG+x2JZrD4u3CRehurV7Vx3SDUanFN4+13v3ZM0KNAC1wXtCBOzqmzU/KlG/3iVaTPnFiKueZ9C60YM6gz/PAWwyalTv/G3YV4+dC+5DMAUhWiSoKI5Ddc0qSqnv9rgUQXGOxZuO6JT6FnYnT8EEFC8uI2qCpDI2WdGEHJYyuZQDeLhb/G/pv3TQIgyCISQFhacmY9fAAiJ40/6lXLKb6InwwgQ/Hf8ZoqMKQ9HuY2aU5zjZ3xRSml6F8iM9Q0IHKiF/YTNwOc76+nHUW4vVn0bT/IiIsFk70Tvxexg2g6HHNIa7e3T4EicGINKlgjopuIz3DMbM8o+Pf48FXhP+fxiAxD+g87/MSYzywh1AHTUyyHvf+dk+THmsaZmMLBv7PKS8fH9owB86pVf8oIvoacNneXpF8+DCf3zgzgxoXW9c49V8dRPArjwS6VHe7i8bN34wiRh+dF6KBMP3h0RReIB9hdcUcdjlaQL1WUr81F7VDLbmoC2qdW07wVbUIa6mpeg3dalrRyoBPQypMZtyaRARHPrG5xykHiCKrYFecYT7HCnIvAKqV1IAxTQ23fehOlNl6ijq8iBDeLOaO4BrWPcurHJz+rthaI6Mzc3w+OhkFcIO76BqukQJAYS1BuT+3aKcdCZSQfDjgEKR2+y5vZigZi9tgg8aemP8BFWOVfoTx5kYVnnvbjssBusCW2QulyWLYl/evIttPmsmT wCY3SPgK ktMWjjh7/VIiLSYojaIvlrIrXaOo7q1i8Vq8SZ+8C/uI5YFS9eHyQpNbli2vq2KC3QrCJyCSw/k/bdCPCPAnC1tVaTNEFJ2Sa+G87wg7u6Ecz0t31SIPI7VDFQi06Pw/p+E40wma541i06x+Kahjo/fxfDD2+WdOoiGlzBQ98iGJTcyvJRc4ygQr/H4+U8XGfCFxuHqEr6Ndq66wbKnVFbMKx5Je2KGEsMrAL3CRVFPQT3817SxqdILyLNWf8hHxw9hzJvZt10C2ziqU+84UttvkBCC6dkpKB9zarZC+s2GAOYlqoOR2Z+jMpbDArX4NvXDfgbgO9wQYyTfTq6VL7gBC2PA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000564, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Generate pre-content event on open in addition to FS_OPEN_PERM, but without sb_writers held and after file was truncated in case file was opened with O_CREAT and/or O_TRUNC. The event will have a range info of [0..0] to provide an opportunity to fill entire file content on open. Signed-off-by: Amir Goldstein --- fs/namei.c | 10 +++++++++- include/linux/fsnotify.h | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 9d30c7aa9aa6..a1a5b10893f6 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3836,7 +3836,15 @@ static int do_open(struct nameidata *nd, } if (do_truncate) mnt_drop_write(nd->path.mnt); - return error; + if (error) + return error; + + /* + * This permission hook is different than fsnotify_open_perm() hook. + * This is a pre-content hook that is called without sb_writers held + * and after the file was truncated. + */ + return fsnotify_file_area_perm(file, MAY_OPEN, &file->f_pos, 0); } /** diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 7110bc2f5aa7..2d1c13df112c 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -193,6 +193,8 @@ static inline int fsnotify_pre_content(const struct file *file, /* * fsnotify_file_area_perm - permission hook before access of file range + * + * Called post open with access range [0..0]. */ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, const loff_t *ppos, size_t count) @@ -207,7 +209,7 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, /* * read()/write and other types of access generate pre-content events. */ - if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS)) { + if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS | MAY_OPEN)) { int ret = fsnotify_pre_content(file, ppos, count); if (ret) From patchwork Tue Nov 12 17:55:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872789 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 C45E0D42BBE for ; Tue, 12 Nov 2024 18:04:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E8086B0099; Tue, 12 Nov 2024 13:04:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 368BB6B009F; Tue, 12 Nov 2024 13:04:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E16C6B00CC; Tue, 12 Nov 2024 13:04:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EF55F6B0099 for ; Tue, 12 Nov 2024 13:04:41 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 93920140538 for ; Tue, 12 Nov 2024 18:04:41 +0000 (UTC) X-FDA: 82778216766.25.212E658 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by imf15.hostedemail.com (Postfix) with ESMTP id AA09EA0040 for ; Tue, 12 Nov 2024 18:03:56 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=R6bMdMQN; dmarc=none; spf=none (imf15.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.173) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434617; a=rsa-sha256; cv=none; b=7hCK2leK+SqJcj9v/YaEaw5UqTNZ3/LDygIkDyHumi2LL8ZWW/rRI04fijmiasX6MSSF/Z MIsNMqWc7zYc9ZgvLhDDG7YdFMEEQR/Kq2TRGzFbDkMhZ/bh8wmmMU/3yluDcAW55ZvUA7 m6S4O/9Z3TmOh/jGGnU1nS0XiIVOCXA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=R6bMdMQN; dmarc=none; spf=none (imf15.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.173) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434617; 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=yR+WXWwndS2FLusUnFYSuykN6wegDmBuVaa7pQ21cd8=; b=rFlzxXvjW1OTooJFtXsSsbfDWvRvC7jdQeI78xMkiyPsxotyjuuRnl4BJVb0kVq/6rUoP6 rP+VPyZPltOPP975AvAi3FjYrjN8YuH4fEGNRaAl4H71L9PAeuS6zWWYziJIauyZYyqHJ/ bZJdxdcBZcjR6nNQK3KWieG5taXHN7o= Received: by mail-yb1-f173.google.com with SMTP id 3f1490d57ef6-e30d1d97d20so5300564276.2 for ; Tue, 12 Nov 2024 10:04:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434678; x=1732039478; 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=yR+WXWwndS2FLusUnFYSuykN6wegDmBuVaa7pQ21cd8=; b=R6bMdMQNRH1uqfnQ+kH6bZJ8/wVhysItGM4LB0Km/BZg60wtZhJV5rTSz5TxQ8fH1H l85+KaxUi15oArqhI9UAJHOd8tnn66QpUSJD7Elq9m3Gp9H2GM135bNDQMCwUl3jGiKh oKTDbuyFq4zN9JE/bnqTvE65Vf18PbQkz4s8XZMAVdlkNcM1ueDgOjtPK3FZFIPtKzPo 1gwJuMmgs7Xqqd+YOl1FMopbdjgf3wIHRytT2TdmtJvMOnKn2Sae6JBo8oMrToA69R6z m/ZJohcLv5vgyRwmh7wB5YYr6EsWKGLR8WSCWMb3rv4KAi/k86kpDUbbTTbqdOUdaQ2h J8Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434678; x=1732039478; 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=yR+WXWwndS2FLusUnFYSuykN6wegDmBuVaa7pQ21cd8=; b=faXmUNSCi15DdkkBokPlxa08rHi2zuCkuVSEx2DDu8o8tGhcfGqnlRifq8FJDp0xzK 1cmmXMoYqZyVFgbxq/JRmXnFsSRQWMYCvdpGcp2ev8PBIWonodO+1zGhUnr3VJY7X4vI LFhEoIYAFQuYxAjWw8lDvn648llaAYHQF3IRwPNK4aDCe4e43irhE1PiJPXAqYsn4/+R aGkCFoePRKQr+k8GXbqTjNRpKQHfC0Dco7H0YZuBZzaNL/g9Tdzm3J+Gfq9ecTL0v5zL kcGj1QRXMo9yYl+IREHhfFd3eVXF4tPcDOl4fAFybt0rSz6MS1HNJt4UGSRl87hgbqQU gZmQ== X-Forwarded-Encrypted: i=1; AJvYcCXcVCMs9ofCl4RgkoR4lG5ISLbGEzrNjxyQYNu+y9Ee0PNA/OYh9aglDsyBVHEebeTJgzxMczbC4g==@kvack.org X-Gm-Message-State: AOJu0YweJMKsAR2oNthO/NX659WmZRvRUNiVVxpafzsuK+e4VztwkNOu 7djJXZSeykxX9PRWpWSnJuscil7/hPmVHY06JBeUllmocWTLFj+mUMJJetTGPQ5NZrHmao2e6R6 u X-Google-Smtp-Source: AGHT+IGcFROfyre2Kv1qsuv7MLwuajuAadQn7xHj4Uh/jaGY8cm7A7E77btl+nKFPaxtN+kqNmxpKw== X-Received: by 2002:a05:690c:6e0a:b0:6e7:e5d6:64cc with SMTP id 00721157ae682-6eadddbd36bmr177209777b3.20.1731434200953; Tue, 12 Nov 2024 09:56:40 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8f1d2csm26433717b3.42.2024.11.12.09.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:40 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 08/18] fsnotify: generate pre-content permission event on truncate Date: Tue, 12 Nov 2024 12:55:23 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: AA09EA0040 X-Rspamd-Server: rspam01 X-Stat-Signature: agy9he9fhc3jzwhy7iszect8gffpk771 X-HE-Tag: 1731434636-902162 X-HE-Meta: U2FsdGVkX1/njTTlTvaQR0tpNxxzEE3LoDGh7rpLnNDRN8DO3cbjBzHuEodADI1kJZ3ndY8CWI8rnUOgcntDS9UUT7zcTOBTNHNC3OqV+oHCsJ2a8paEKTNHFWgGKucdMQlPfDKOaLaT2yovFTz/4o8jOnux/xW996i4sc1oIwFtI3cfJkcbwKlmzIE7BsJ8vR6/s/rICJQHMC85aa/USmJiy6HRVbD9UDhr41RhJNREimckComtP++aEGtiT12ROOjE1/zgVIliuJU8zH80cTGgRudN3seTmQFuVERzVF15khlQNGkH6d73UQJSFaibBEO1hxEi6U2abRYNir5T57cfBVMHx/jgHjIZvVn5OcGbScLiRHVwk4TOEdZWirf/qHEdr+Uq7qdpTg0WmHF+1Vh3YUYGeBO6RTEplIrQvYdqlypR+bnws5TO5fbTP8oFDLnQYqvZe50ro6sJxPLQ3vd6glYTnkMO0zW0A0fKWkD/PaSppvolBdBwCdWRi43dCRFP5FgCQrE25Y9aUZIKQXnl0kGiqi0NiWiz1HyHfPgDoNHHOvsiPq3yzFuYlyUjZG/Hx//xPRo/2X3CV/LO5jcX8HPpDq7by4V79dzI0P3bqe/qlgSwDrnOobCizme6ep7ETo/p4lr+7Ay37X3Huszg+QhPnUw/dOo+LlSfvxaZ2UNaJW+MjfoNjxM4xvhvq1iL2DLVWi89459O6GxKVy4bXXr5TYxa0/I+tmynwijfV4nUZFVa/OLbKyzrSOILblxQLlkVoE+rmyd9RsluDQeIc1yh1q9EAxs1+7i8j84Rf4+Rrb4wv9zrWZyw0oKJsmoZ+t2x0TPPUD+Hbp4sOup5RMKVOLODnzgSAatJuirEbO3FWbU5j9ICcMK2RBlUiGNxgVi0jQWR8flqqFK+otHCuLPKrIwcY7YT1kUlRfsRtmQlfUeqGw4vrAAJjGmsmDqkZwqo+p8SKq+GKfZ XbrTeK2n CmVe1jG6gx+PaJysQpsRqJ5M0Q4xB8JtmWQ4WU80TB93nGwFFk98C1HZl69cMViSs/lOqzW5hGbN4PpI42Zxk42+t6I6qwSIRFqvOEFP9i3/xHlEi1ndIdQ/+/+jMxmu9Qc1On7cIAULnH6T8sWlxCt4JH7tW95X1XycQ5orngNUUVpUtHKIcMJkySwTUktzFV2Mcj3b/xqS/EIXnIyzGuAZduFmrSq8CSct9ptbIVZMR81Z+YaAhz2YOsEtiF+SbNZtuLrYaA57oZ6/qZMInP+LeIuV4c5NpuitefVLbstqVFKPH7ldGR/GMhaQMiCTfcunagUTxW/9Pz1IqUTl0RHLyN7RGelFLHuo1XOnATa1et5klTPp4fBPGQD4omtFiyyezvZaSsaIDNiipHC3JeZ92lVP2lP8p92fkfdprg7HYv9BN6Lkjj6uo9F6KHW50/pBVw3HrwACb9vw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Generate FS_PRE_ACCESS event before truncate, without sb_writers held. Move the security hooks also before sb_start_write() to conform with other security hooks (e.g. in write, fallocate). The event will have a range info of the page surrounding the new size to provide an opportunity to fill the conetnt at the end of file before truncating to non-page aligned size. Signed-off-by: Amir Goldstein --- fs/open.c | 31 +++++++++++++++++++++---------- include/linux/fsnotify.h | 32 ++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/fs/open.c b/fs/open.c index e6911101fe71..e75456cda440 100644 --- a/fs/open.c +++ b/fs/open.c @@ -81,14 +81,18 @@ long vfs_truncate(const struct path *path, loff_t length) if (!S_ISREG(inode->i_mode)) return -EINVAL; - error = mnt_want_write(path->mnt); - if (error) - goto out; - idmap = mnt_idmap(path->mnt); error = inode_permission(idmap, inode, MAY_WRITE); if (error) - goto mnt_drop_write_and_out; + return error; + + error = fsnotify_truncate_perm(path, length); + if (error) + return error; + + error = mnt_want_write(path->mnt); + if (error) + return error; error = -EPERM; if (IS_APPEND(inode)) @@ -114,7 +118,7 @@ long vfs_truncate(const struct path *path, loff_t length) put_write_access(inode); mnt_drop_write_and_out: mnt_drop_write(path->mnt); -out: + return error; } EXPORT_SYMBOL_GPL(vfs_truncate); @@ -175,11 +179,18 @@ long do_ftruncate(struct file *file, loff_t length, int small) /* Check IS_APPEND on real upper inode */ if (IS_APPEND(file_inode(file))) return -EPERM; - sb_start_write(inode->i_sb); + error = security_file_truncate(file); - if (!error) - error = do_truncate(file_mnt_idmap(file), dentry, length, - ATTR_MTIME | ATTR_CTIME, file); + if (error) + return error; + + error = fsnotify_truncate_perm(&file->f_path, length); + if (error) + return error; + + sb_start_write(inode->i_sb); + error = do_truncate(file_mnt_idmap(file), dentry, length, + ATTR_MTIME | ATTR_CTIME, file); sb_end_write(inode->i_sb); return error; diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 2d1c13df112c..f1ef072a3b2f 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -154,17 +154,14 @@ static inline int fsnotify_file(struct file *file, __u32 mask) } #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS -static inline int fsnotify_pre_content(const struct file *file, +static inline int fsnotify_pre_content(const struct path *path, const loff_t *ppos, size_t count) { - struct inode *inode = file_inode(file); + struct inode *inode = d_inode(path->dentry); struct file_range range; const void *data; int data_type; - if (!fsnotify_file_watchable(file, FS_PRE_ACCESS)) - return 0; - /* * Pre-content events are only reported for regular files and dirs * if there are any pre-content event watchers on this sb. @@ -177,18 +174,17 @@ static inline int fsnotify_pre_content(const struct file *file, /* Report page aligned range only when pos is known */ if (ppos) { - range.path = &file->f_path; + range.path = path; range.pos = PAGE_ALIGN_DOWN(*ppos); range.count = PAGE_ALIGN(*ppos + count) - range.pos; data = ⦥ data_type = FSNOTIFY_EVENT_FILE_RANGE; } else { - data = &file->f_path; + data = path; data_type = FSNOTIFY_EVENT_PATH; } - return fsnotify_parent(file->f_path.dentry, FS_PRE_ACCESS, - data, data_type); + return fsnotify_parent(path->dentry, FS_PRE_ACCESS, data, data_type); } /* @@ -206,11 +202,14 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, */ lockdep_assert_once(file_write_not_started(file)); + if (!fsnotify_file_watchable(file, FS_PRE_ACCESS | FS_ACCESS_PERM)) + return 0; + /* * read()/write and other types of access generate pre-content events. */ if (perm_mask & (MAY_READ | MAY_WRITE | MAY_ACCESS | MAY_OPEN)) { - int ret = fsnotify_pre_content(file, ppos, count); + int ret = fsnotify_pre_content(&file->f_path, ppos, count); if (ret) return ret; @@ -226,6 +225,14 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, return fsnotify_file(file, FS_ACCESS_PERM); } +/* + * fsnotify_truncate_perm - permission hook before file truncate + */ +static inline int fsnotify_truncate_perm(const struct path *path, loff_t length) +{ + return fsnotify_pre_content(path, &length, 0); +} + /* * fsnotify_file_perm - permission hook before file access (unknown range) */ @@ -254,6 +261,11 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, return 0; } +static inline int fsnotify_truncate_perm(const struct path *path, loff_t length) +{ + return 0; +} + static inline int fsnotify_file_perm(struct file *file, int perm_mask) { return 0; From patchwork Tue Nov 12 17:55:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872734 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 925C7D42BBA for ; Tue, 12 Nov 2024 17:56:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE9296B00A2; Tue, 12 Nov 2024 12:56:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D9B896B00A3; Tue, 12 Nov 2024 12:56:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BECF56B00A7; Tue, 12 Nov 2024 12:56:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9861E6B00A2 for ; Tue, 12 Nov 2024 12:56:45 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1C739120486 for ; Tue, 12 Nov 2024 17:56:45 +0000 (UTC) X-FDA: 82778196438.08.FB6C1CE Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) by imf08.hostedemail.com (Postfix) with ESMTP id 5DA5F160023 for ; Tue, 12 Nov 2024 17:56:15 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b="F/5EYwAr"; dmarc=none; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.181) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434074; a=rsa-sha256; cv=none; b=L29rC39Sd7T7Kxi/HKvReNUPQGo9BjhfaItOrQlVNfJp+u9fy7gYDH56PtjQ1Rd85AAdZF piOMa5Hd2WjpOzOdGoJ2PHuq14yk2HJLfninxZFbrLBCXZaMz5KZEc06W+/3JzXc85zNJ9 WHfFg2/xRDY9vh0v7mD438YOlOxuHEE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b="F/5EYwAr"; dmarc=none; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.181) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434074; 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=F1sPenjaPSV3IbCyPSQxlkDnDJhzpgD7KqSaJNnzDjc=; b=VALonfcIWx7BB6f1l0ETy8Y9LKyD1Av40kq0xKtuD72oQ+KK3V5gSB9Fh/ZwDII0MWQX4e Tbqlw0GQLlY2FcBUUY06sKXihmHLxUfnsBdqikExwN2qqt0Xu8VCieZkATPZ/vqu5/dvfx Z22/W7PPUAUCHn184eeZsIpg97cEtYw= Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-6e9ba45d67fso55430587b3.1 for ; Tue, 12 Nov 2024 09:56:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434202; x=1732039002; 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=F1sPenjaPSV3IbCyPSQxlkDnDJhzpgD7KqSaJNnzDjc=; b=F/5EYwAroUizapWlfNVuf48ncarfclSlnyeHSvTTtGyLnoaMXHLu06ADUnTeaNp/gu dXKw+BtV7NXOygK7Nv5LvaJDpkZqXBP7EfYn2LY06IzvXcfGcNBzmPaf9jBwgaZMbfdq 8VMLmzYa5+gu0CwhJlY1nKBBPq7qdxTlBH7fHQFLMb/yqHJ6HupZ4S0Jy7DolAwPJSly wzLvCx54TrNiM9C1zqj7zRPmb/uCzS9aZGhsmQr86y6To2yVePW3/eAY5IV9tE2NMVEJ 9h+B3gZAwjUUOeZbC6cCjEtY8sTxpE3cj+M59QkfFFOG2fenhKRp9AggPAh+PytQ+6tS 4IOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434202; x=1732039002; 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=F1sPenjaPSV3IbCyPSQxlkDnDJhzpgD7KqSaJNnzDjc=; b=KowEQ87mAhFnFNypxoLY7c8L5PgHLGMNpf14aC4sxk98y5/12YCKonZVau0dxJMvJ8 bbeBlJznUs4KubYYTgcAqpn5MOstlG/mrPIKfUYMQwQhlk98X4XfCbEVCn3P12MtWIk2 ss5aClcMgQGOdTIv2eT+8xgfJ9LphJsc1e1bUyTvheiOOiHnpj+evbpf6rl9ugLkC4p+ vbG0j+bTfGgmVwLjeiFWp72tkb3Msoh6TOL+aC3cRKi8fUhxPS58i0rNfei8e6v4CF+R a3lEWSiXxYcoeP6dFuxIv03cF/ouviom/zkE4SB1X6SGssdq+YLbuj60Tu+DmX1+1shk P9eQ== X-Forwarded-Encrypted: i=1; AJvYcCUoPabbBLHinl4uLnD3+e9I8UVkyHgqQcv3cAqm9G+1j+0WXm5UZI0b8DVj6X2NJIAL2jpNcKsl4A==@kvack.org X-Gm-Message-State: AOJu0YyFrGLUUrGbRyLxbTYBiWDwsDth99/09UVQ0OPI2uaxYLM+Ua4G 43GtQqz4kitFVJsnol37lXI1I1SlB8xUsgsSQ3GUJ/P4SpnkP9kjpIbyOHCOoqs= X-Google-Smtp-Source: AGHT+IGfl+HQnQ1oPuK9Fv3A9ej7wwMHJ/S0LDz/YIf0NJPMnTA+szi6pHRPPnhRlITEFHjDE4KLTA== X-Received: by 2002:a05:690c:7007:b0:6e5:cb46:4641 with SMTP id 00721157ae682-6eca4660862mr42510667b3.13.1731434202410; Tue, 12 Nov 2024 09:56:42 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb0939asm26349277b3.61.2024.11.12.09.56.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:41 -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 09/18] fanotify: introduce FAN_PRE_ACCESS permission event Date: Tue, 12 Nov 2024 12:55:24 -0500 Message-ID: <8de8e335e07502f31011a18ec91583467dff51eb.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 5DA5F160023 X-Stat-Signature: n3e9beno13po4kr55x6mo1zg6u9a8tos X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731434175-271629 X-HE-Meta: U2FsdGVkX18HAJ5vXtN+Xebcalzelk5309R9lNIi7Pwohfgj+PsI5KizZa8mdbyqUItEesszEcuXCFUUkAbH7yVbJmLCl7/KsZG4CYjV05Lj87t02jKs8UdUqMFn7hQCZXFpbEVltR7DXYLmjjQLFIT7qCMnXOboZfsQ716RaPZgMS29BbzMYXnBGf3z1vj+8rEKd7K3FcqsCvsCodpHKzRPfpQ4yv7KKIjeTjCDKQJQbDcFva/BORo7TtD6F9WwuOn33aJx3ovssIn1MthTTlVTQPrrT5051DCoS3YeQ0F2Ie6epmPXCzt6/VxKkIFmug8KDJ1NsmQrOmM4x7DcEpw05OsSMmpMDDr/1U3/SqF/6YYKZF5OonUr8aPBHXZum2tr8ZmDNnFop04G8gYoChearN6g+Z4QENcsIBYhsYHaFRsKmzOedGNIkTubZmZAKFG+u3AIuizRJLSv8i1Zl+ephm6GfXqMUELiPQiQzV1tfV+IkMG+vxqb413bfAPgvRqpYwWKu4JLx8BugO5h/cYe9t7rdUJDLh4ZOckCZGBuVkfY2IO7bFdn8RJn4AddCgmpaLW4yNfp7VhXbtk51aVP9sfIb08jOXsd8ewwDXm6b4TX9m/ImRJCTuvjWS9+5+EVGeGWnonFQL3bzzNE91OJitbSG0/h+DXcwSsvM1GsSgYSmBHRSA4CLTiQWHOGnVrqplAtcpS7uKlwaZA/5fn5ih31pMYkA16s0zVSFjJeaeQkSkoc68F/L2liZB+iLtX+aZ/Q4z2j0u1kiNFBJ+AVucw2muxRfYnZk1K3Gt4R2G58RtenDaZcDMyMw/R/euY3SxvRcrLuItzLsaMCkdz77v1YJmYfe8CNOZ75G4qaZ4ESrs4op/JzuUAz+ouKWfj28JO0T91v/krY3YF9CnanrKwKGeDSoFhkuPB69M0iYrSvBuIuiZS1hvJPqqlk6HZVRa2sjK37I2NpiiC DwbOVDae GUCKb6rXXsNTkNc+fpvXFy7VG3gtm5aEkEQ1XawbbcBA7hHLMf97GNaa+2gn8NhWkaKeD09PlMB6dqaOp5T3gRi6yeawb8348EaXcCC9HBzJH8XQWB9unYu5KZ9PxIlDys2mPhA9i1ONTiRZ9IcoLuP3+J2LdgQu/rvYs5qRuzHFygaF5uzZY1G1+CEoeSBzvzh65LQ6l7/vVyNvpTg985LU/cGSYVELVxfAm4A1FwF5A51XyN4GxZ/+FxqnNYS2b9WTixAgj3jkTpPFKl4PoVRVfzEd2+3Thay6pHkkSrziYT6ccjYuF7UYPsguGTlZGj+yD3vcShz6v1hu+tRS+ERrI1RtuY7fSUY1ph4a8Jx6UEd2M/38rUkRzIgVlp0xRhNit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000169, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein Similar to FAN_ACCESS_PERM permission event, but it is only allowed with class FAN_CLASS_PRE_CONTENT and only allowed on regular files and dirs. Unlike FAN_ACCESS_PERM, it is safe to write to the file being accessed in the context of the event handler. This pre-content event is meant to be used by hierarchical storage managers that want to fill the content of files on first read access. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 3 ++- fs/notify/fanotify/fanotify_user.c | 22 +++++++++++++++++++--- include/linux/fanotify.h | 14 ++++++++++---- include/uapi/linux/fanotify.h | 2 ++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 2e6ba94ec405..da6c3c1c7edf 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -916,8 +916,9 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask, BUILD_BUG_ON(FAN_OPEN_EXEC_PERM != FS_OPEN_EXEC_PERM); BUILD_BUG_ON(FAN_FS_ERROR != FS_ERROR); BUILD_BUG_ON(FAN_RENAME != FS_RENAME); + BUILD_BUG_ON(FAN_PRE_ACCESS != FS_PRE_ACCESS); - BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 21); + BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 22); mask = fanotify_group_event_mask(group, iter_info, &match_mask, mask, data, data_type, dir); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 9cc4a9ac1515..2ec0cc9c85cf 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1633,11 +1633,23 @@ static int fanotify_events_supported(struct fsnotify_group *group, unsigned int flags) { unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; + bool is_dir = d_is_dir(path->dentry); /* Strict validation of events in non-dir inode mask with v5.17+ APIs */ bool strict_dir_events = FAN_GROUP_FLAG(group, FAN_REPORT_TARGET_FID) || (mask & FAN_RENAME) || (flags & FAN_MARK_IGNORE); + /* + * Filesystems need to opt-into pre-content evnets (a.k.a HSM) + * and they are only supported on regular files and directories. + */ + if (mask & FANOTIFY_PRE_CONTENT_EVENTS) { + if (!(path->mnt->mnt_sb->s_iflags & SB_I_ALLOW_HSM)) + return -EINVAL; + if (!is_dir && !d_is_reg(path->dentry)) + return -EINVAL; + } + /* * Some filesystems such as 'proc' acquire unusual locks when opening * files. For them fanotify permission events have high chances of @@ -1670,7 +1682,7 @@ static int fanotify_events_supported(struct fsnotify_group *group, * but because we always allowed it, error only when using new APIs. */ if (strict_dir_events && mark_type == FAN_MARK_INODE && - !d_is_dir(path->dentry) && (mask & FANOTIFY_DIRONLY_EVENT_BITS)) + !is_dir && (mask & FANOTIFY_DIRONLY_EVENT_BITS)) return -ENOTDIR; return 0; @@ -1771,10 +1783,14 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, return -EPERM; /* - * Permission events require minimum priority FAN_CLASS_CONTENT. + * Permission events are not allowed for FAN_CLASS_NOTIF. + * Pre-content permission events are not allowed for FAN_CLASS_CONTENT. */ if (mask & FANOTIFY_PERM_EVENTS && - group->priority < FSNOTIFY_PRIO_CONTENT) + group->priority == FSNOTIFY_PRIO_NORMAL) + return -EINVAL; + else if (mask & FANOTIFY_PRE_CONTENT_EVENTS && + group->priority == FSNOTIFY_PRIO_CONTENT) return -EINVAL; if (mask & FAN_FS_ERROR && diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 89ff45bd6f01..c747af064d2c 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -89,6 +89,16 @@ #define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE | \ FAN_RENAME) +/* Content events can be used to inspect file content */ +#define FANOTIFY_CONTENT_PERM_EVENTS (FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \ + FAN_ACCESS_PERM) +/* Pre-content events can be used to fill file content */ +#define FANOTIFY_PRE_CONTENT_EVENTS (FAN_PRE_ACCESS) + +/* Events that require a permission response from user */ +#define FANOTIFY_PERM_EVENTS (FANOTIFY_CONTENT_PERM_EVENTS | \ + FANOTIFY_PRE_CONTENT_EVENTS) + /* Events that can be reported with event->fd */ #define FANOTIFY_FD_EVENTS (FANOTIFY_PATH_EVENTS | FANOTIFY_PERM_EVENTS) @@ -104,10 +114,6 @@ FANOTIFY_INODE_EVENTS | \ FANOTIFY_ERROR_EVENTS) -/* Events that require a permission response from user */ -#define FANOTIFY_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM | \ - FAN_OPEN_EXEC_PERM) - /* Extra flags that may be reported with event or control handling of events */ #define FANOTIFY_EVENT_FLAGS (FAN_EVENT_ON_CHILD | FAN_ONDIR) diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 79072b6894f2..7596168c80eb 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -27,6 +27,8 @@ #define FAN_OPEN_EXEC_PERM 0x00040000 /* File open/exec in perm check */ /* #define FAN_DIR_MODIFY 0x00080000 */ /* Deprecated (reserved) */ +#define FAN_PRE_ACCESS 0x00100000 /* Pre-content access hook */ + #define FAN_EVENT_ON_CHILD 0x08000000 /* Interested in child events */ #define FAN_RENAME 0x10000000 /* File was renamed */ From patchwork Tue Nov 12 17:55:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872735 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 E8508D42BBE for ; Tue, 12 Nov 2024 17:56:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2ED5E6B00A3; Tue, 12 Nov 2024 12:56:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29F056B0103; Tue, 12 Nov 2024 12:56:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CA686B0105; Tue, 12 Nov 2024 12:56:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CFAB06B00A3 for ; Tue, 12 Nov 2024 12:56:46 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8EA711C4F0C for ; Tue, 12 Nov 2024 17:56:46 +0000 (UTC) X-FDA: 82778196522.19.E3E7F27 Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) by imf22.hostedemail.com (Postfix) with ESMTP id 971A3C000E for ; Tue, 12 Nov 2024 17:55:52 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ZFS3Al5c; dmarc=none; spf=none (imf22.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.179) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434142; a=rsa-sha256; cv=none; b=upioBcFdlC5Ur8khQBn/TZsmR0IeQT1kBHGSfVCO606nLzw5Mt3xvI9A3B1ZOHAw99saZw S0BZdnm/yZsqiQrx2caJ2AP/fl0owTbHsX2JTkjquhh1Ue7kamume25IUrVBjA+1Cz40UU wewN64ckL6Mm3EZQNqht3HfCreoFCE0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ZFS3Al5c; dmarc=none; spf=none (imf22.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.179) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434142; 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=zmpMu+cyUA93dTz87+bG4l2t/L8RTFnzlJy59zXnVRk=; b=Azr6BaPzJyjhblp4qKON0Zf+KdhjNzlneSKd6gPji0B/yURikvqk9opdxeG18SkoF7fIKn mLB3eTgW5FN/zuxE+Eoa6BOXqJRwk6ZWFNGC0mcbBNgdjYO84E+HqgwVN5dnj4niGVK78Z X10hSYjGg7x4IBTre2VuXmRdhzLIIdw= Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-e30d0d84d23so5269949276.3 for ; Tue, 12 Nov 2024 09:56:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434204; x=1732039004; 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=zmpMu+cyUA93dTz87+bG4l2t/L8RTFnzlJy59zXnVRk=; b=ZFS3Al5cDUDA8TWoEZIScmrmqy07n+mEVX14SEdOnc28wB5zLisssjkl2sbpKmDlPU E+sYR9UdBUuGVxjhKsQZDXgUGct8YFTLloVjztTHi4Jmr2vpalTs9B4VEIcJRWtqH1l8 zt6vyFRNjD0vXE+UTEzh1H3BRQlZiIv0MCY9EUFPBhOvu8MnncnjIlTDsGz6krftdw1u PrL/C4qfCqtKyTT7zAL6LXxm6Vn2XIyamd7h/JKjw0LX2D/12obKCclt5u6ZyYwH6JXC zTDRQ3wO6hnCvabMOx+WzNQye72CuKPBDCgSvTnRZoad57d2meKq2CPEXY/IQr75JcYI ZiFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434204; x=1732039004; 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=zmpMu+cyUA93dTz87+bG4l2t/L8RTFnzlJy59zXnVRk=; b=RkPTepQDBI09Iq1UWys8IdYdwAvNBwB+Zc+dCOxW/0KSlGbT+tsrm1LpCJYCgzyDxg AD82uQXVKBTHRiXz7XRUENJ/w8b3DHtFjIkE8wGR7N2Kbg1nnHAhepjwcJ85/OKNYoR+ tMqWk2+ZH2a2cX0CDIzqUsGfNeE0ceiyugM7fFuIhDY62tFGwv0dP3eaDxYnnpJXyMK4 ULlLliin1kQufG/9JvGtUTg0Bs5w7zczM2fR3SW3xdhRArULfbnkKrWyQj+6enODhugF kPjja+qQytNpkZ3BkrIg+g13J3zV0atDwNp8RWhYcU+IRlqIE8XULjL7VIDB7hlFv1U2 IAAg== X-Forwarded-Encrypted: i=1; AJvYcCX3mEmZNd0VD1Nb/NYYnFhNrpOyK6Wwa9K2w8NjrLinA5TCmtKajUWX163YF+KpDwYOW48VU5DDCw==@kvack.org X-Gm-Message-State: AOJu0Yw4W0x1ch/BoqKzLiaKGJIcms3MPqdHwH7D0Md1V/93HU1875wP xhxa7KzBen6S7Wt5ZKJ8y95I2dw/vdYWe1VABWUaHFzfLPGTZVap8xXkkyYy5+U= X-Google-Smtp-Source: AGHT+IFoYbCAjCHUFKm3DZPieLWA6AhlwnAEoVWWiOeBhhtsUN5DL1tJA6JbxgolnU89lhaXg5Pm5g== X-Received: by 2002:a05:690c:6f8d:b0:6d3:f283:8550 with SMTP id 00721157ae682-6eaddf977a8mr188770267b3.28.1731434203995; Tue, 12 Nov 2024 09:56:43 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8d5216sm26312647b3.26.2024.11.12.09.56.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:43 -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 10/18] fanotify: report file range info with pre-content events Date: Tue, 12 Nov 2024 12:55:25 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 971A3C000E X-Rspamd-Server: rspam01 X-Stat-Signature: xcj6ank84icx6ye6snqhwqef7ng4zrzo X-HE-Tag: 1731434152-902760 X-HE-Meta: U2FsdGVkX18CkSfDtr1KD1klSjsAub336c1cEhNOn3TkWpmBDpj7dxil2lrnjIEK5raXDXzSR5KCYgspJxjCNoWwolOVNbs6Q0xfx0m01xZAqs/9e7lUxh7Uz/nTMPXJq/CZZU8iwVsFTCIo6DCpFCYF/anYLJ32DSn8qqYSm4W7gsESLmVHVe9CKZVzax4QH0CBuKwm3F2IfTmx18QRYTEzEuiVfA/G157nM6f+gX2F4nBOaXnNOX8W+a7hcZGmn4GcLw/2WzkprHg13prhg2XaFsPfKlPL6Wxz5A4KwtkSwzfgLJU62sIpBmN4qwShjHYoICuvuMoI8OBgL7Y7AOLZLkPXs07qhSUYnuQxMMuyy3f6m8BlepndDMg/WJl4WmYtdelE57NfwfeIyl8rJ+WF6hZ0bEocATA5E2c3vsDvHUpeIwYyyBpcdpBwxn1IM8iqgqolkxZJsdvgDVAr/eMJ4qYGi2YkDmELsxuVgQhG+5CnwMbTiXZzGJ9YQzLs99K59OjcM9YH18nuMBV+9Pq6zMXhQ+bVN77idDSHf0RvyhB3tKiCJPUNmsnUoRDjjvOPySrNUh/Q+hLRcJBrJkDBDOghSDIsIPbI7bTSWjUPsH3fpfPYqGKla1xFeVOa6UmwJCqZkkOWF0Fo/fvT0OpfocWnTFFUGnFEfd5L0BxpkkBaHo5+IlXvU1hXi70HxFp24WLYhTJ9lODZMWyJdkM0HqU2Npzr/Iq2vOL6uSCHkDkSiDXcYcD0nmJcnHsxJjRPuYhwnv3vVZ5pprttzi9vUyBiOlcZUJXOQz1qQ5ib31MAn9eawDE+QQfnivulerNshwNNrniQcBccCTl8bb87CWBrJygc0OpS8a6bGFtRIWf7aL3rYVHW0f5BCSpT2dWfzcn4ZS3yLBcOK5nzWJGxh5HPbum1fFTar1NADSjUd1gtR3Vk74TBBtWM4bz4j+YpHDuIiN2cXOpc7B+ QJYUg6HY hCsNBX+BjZsVLflJlDBwVOKnRYdWoBCiFgJ4sW4jGsHPOIitVsIO9ggNfbEceZ2n5gbAT10z3GS2dHalE2xDmYSft7quEAlFPZ2hSSwEHe1jhvIJIzQBPbnyIFA3MIltmp+NLoubHhdLOQHK43od0jd72ZMi/7H4MoauA7MEs51JaPMiyG+BKoefhlDLN/kb9m90MqFz+y6TlT8EEQVFeqA/2whPOrk14QBrDaFp6KFE3rGL9k1lLUuWI4mLhwViTAox5nTH2P3VXDnYGqCiaaKmwGU2qFkj8a0lGHTCCydbEo1vhkcP83rUmm9J4N8U5DqmHkVX5BVWTcOZ7MGnsh8ZgQzTbBkDOloA2TjgpxbuEBEDfAv+E+6vtQDVu3C2FMFwL8VzM+9sGMWMrbd+CntDRirMn1XA7a3BMP5HqVhB7/+UYs9rHXMUhrHP6oKCFlqGl4zWiWXxe300= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein With group class FAN_CLASS_PRE_CONTENT, report offset and length info along with FAN_PRE_ACCESS pre-content events. This information is meant to be used by hierarchical storage managers that want to fill partial content of files on first access to range. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.h | 8 +++++++ fs/notify/fanotify/fanotify_user.c | 38 ++++++++++++++++++++++++++++++ include/uapi/linux/fanotify.h | 8 +++++++ 3 files changed, 54 insertions(+) diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 93598b7d5952..7f06355afa1f 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -448,6 +448,14 @@ static inline bool fanotify_is_perm_event(u32 mask) mask & FANOTIFY_PERM_EVENTS; } +static inline bool fanotify_event_has_access_range(struct fanotify_event *event) +{ + if (!(event->mask & FANOTIFY_PRE_CONTENT_EVENTS)) + return false; + + return FANOTIFY_PERM(event)->ppos; +} + static inline struct fanotify_event *FANOTIFY_E(struct fsnotify_event *fse) { return container_of(fse, struct fanotify_event, fse); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 2ec0cc9c85cf..5ab9ad69915a 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -122,6 +122,8 @@ struct kmem_cache *fanotify_perm_event_cachep __ro_after_init; sizeof(struct fanotify_event_info_pidfd) #define FANOTIFY_ERROR_INFO_LEN \ (sizeof(struct fanotify_event_info_error)) +#define FANOTIFY_RANGE_INFO_LEN \ + (sizeof(struct fanotify_event_info_range)) static int fanotify_fid_info_len(int fh_len, int name_len) { @@ -181,6 +183,9 @@ static size_t fanotify_event_len(unsigned int info_mode, if (info_mode & FAN_REPORT_PIDFD) event_len += FANOTIFY_PIDFD_INFO_LEN; + if (fanotify_event_has_access_range(event)) + event_len += FANOTIFY_RANGE_INFO_LEN; + return event_len; } @@ -518,6 +523,30 @@ static int copy_pidfd_info_to_user(int pidfd, return info_len; } +static size_t copy_range_info_to_user(struct fanotify_event *event, + char __user *buf, int count) +{ + struct fanotify_perm_event *pevent = FANOTIFY_PERM(event); + struct fanotify_event_info_range info = { }; + size_t info_len = FANOTIFY_RANGE_INFO_LEN; + + if (WARN_ON_ONCE(info_len > count)) + return -EFAULT; + + if (WARN_ON_ONCE(!pevent->ppos)) + return -EINVAL; + + info.hdr.info_type = FAN_EVENT_INFO_TYPE_RANGE; + info.hdr.len = info_len; + info.offset = *(pevent->ppos); + info.count = pevent->count; + + if (copy_to_user(buf, &info, info_len)) + return -EFAULT; + + return info_len; +} + static int copy_info_records_to_user(struct fanotify_event *event, struct fanotify_info *info, unsigned int info_mode, int pidfd, @@ -639,6 +668,15 @@ static int copy_info_records_to_user(struct fanotify_event *event, total_bytes += ret; } + if (fanotify_event_has_access_range(event)) { + ret = copy_range_info_to_user(event, buf, count); + if (ret < 0) + return ret; + buf += ret; + count -= ret; + total_bytes += ret; + } + return total_bytes; } diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 7596168c80eb..0636a9c85dd0 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -146,6 +146,7 @@ struct fanotify_event_metadata { #define FAN_EVENT_INFO_TYPE_DFID 3 #define FAN_EVENT_INFO_TYPE_PIDFD 4 #define FAN_EVENT_INFO_TYPE_ERROR 5 +#define FAN_EVENT_INFO_TYPE_RANGE 6 /* Special info types for FAN_RENAME */ #define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10 @@ -192,6 +193,13 @@ struct fanotify_event_info_error { __u32 error_count; }; +struct fanotify_event_info_range { + struct fanotify_event_info_header hdr; + __u32 pad; + __u64 offset; + __u64 count; +}; + /* * User space may need to record additional information about its decision. * The extra information type records what kind of information is included. From patchwork Tue Nov 12 17:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872736 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 37C11D42BBE for ; Tue, 12 Nov 2024 17:57:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CADB6B0103; Tue, 12 Nov 2024 12:56:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED11D6B0105; Tue, 12 Nov 2024 12:56:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAF436B0106; Tue, 12 Nov 2024 12:56:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A49C36B0103 for ; Tue, 12 Nov 2024 12:56:48 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6003214039A for ; Tue, 12 Nov 2024 17:56:48 +0000 (UTC) X-FDA: 82778197278.24.CB48015 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) by imf24.hostedemail.com (Postfix) with ESMTP id 13D4E180002 for ; Tue, 12 Nov 2024 17:56:40 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=M4P7Zam4; dmarc=none; spf=none (imf24.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.171) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434144; a=rsa-sha256; cv=none; b=w9l4v5MqbnlRhth/M2hhjaQ2lCxX7MfQ5PSiP3FTGKEbIlWrtwYS94reS7gQ6t5Kv73/O8 KVq/wh3b70facMPajwg2T2MF84Ud4Kv/eKv3eq2xHfUL/1mjT3Tf/eSYx8Vfrd0btHjMnq GmK6TCDFdtouFWDwVSOdy8DghrrcBjY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=M4P7Zam4; dmarc=none; spf=none (imf24.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.171) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434144; 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=wpMEZ8etGpHeGwDSCw0SFADsZn6aen0TJzBYBdUeEVI=; b=zyA6SER8of7vW1G7L1htFvmdw093NbI1cWlvfrfV9V+9CHesONo0GkvGxiB15CoL//UV6I G6w/qu3CNMbvukeNXm1Ok5qZS6Cqmxg2LwlopeVaWM0dJ8nVY+VzrbrbwW/zdW7fHVh1xX 4XvL7XxLhB3+yJvG0xK1K7+IZ61u+NQ= Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e2e444e355fso5304541276.1 for ; Tue, 12 Nov 2024 09:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434205; x=1732039005; 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=wpMEZ8etGpHeGwDSCw0SFADsZn6aen0TJzBYBdUeEVI=; b=M4P7Zam47PQu6DuhoV2EchwEv4dudBwSAXv6coiz1S5msHBnfxPxTTxVbhRxKz6PTO p4+xZ1NFM5ix+FbojDr/U2ysXyBY2HNf2p+go1YPwOuRxIbe4CgRQphWUWy9TftZKdE6 4a0KQzAKfNTMLFDPzdXQzjPzhLcF59iEl56DL/IvfsHy5oPn6rQDNz29N+YSsQx2Vfwk ZRJPANhMP3r7dnK96ZuBNLa98g5x/tD062U5myXffZzk5FK7D7j4mtyKQZrDxOBlcdkD jRKdzx0caaHd+z49Og3QbgsFPcF6cQJbXKnmultn2cJsFagefYtGYwJ1Hnl0sUXN4wLg tFBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434205; x=1732039005; 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=wpMEZ8etGpHeGwDSCw0SFADsZn6aen0TJzBYBdUeEVI=; b=WvXmxuBaI6Od19sBMJewXEKwi1xJ5jWgGwJU0MatXUsOEsfbGy43gvL8eEQ3nyKimT POU9Ay49LyWOJm/WGePJ7iDawER2LU2/6dUrICrKxLlrejA1rEiv/a99a/rb75iwRbiM HsRt+DXzoUAW/sXFIFgB/QGCqwZIxABi8Ekl0UVeNfnV26azs0Vb/n4ip6Oz6m8zBP++ yReE+KmJREm8aU/ZpNbL5LWYAjUOYAByhnvT/M78BLWN6EGTwMGTRXpgM7NFqqrHF0/i pzY9UiyXvRQ1YybRARVjSHgRR/ydaaxSy1j8gnjt8McoHKIAAufXglLoG4g4M4mvXZir +yRw== X-Forwarded-Encrypted: i=1; AJvYcCUiGJ/GMGxHKi1Im/9CPUUGDAViEeUUivzGGVaCsxjZccTjQJto1gqXFX0UOwgeRnUxn4kbVSP7qQ==@kvack.org X-Gm-Message-State: AOJu0Yz6vodjTALt22A2kMpwtbSjh5qny/i0tpL5EjejMDLLaDkzxA42 Q+E5IENHfWEoF27tUWJGy2hqOvjzCCD+Fke79Cv1VWC48lqrIxiIK+mNrMCkOck= X-Google-Smtp-Source: AGHT+IFx6UWdvrNKDaX/OENaRjq87dwE63td/svMIV9HfNIfAMFBzFtM680J2ZNXHuwnb0+bit+2+g== X-Received: by 2002:a25:6b06:0:b0:e29:27db:a1ac with SMTP id 3f1490d57ef6-e337e17cdb1mr14809403276.17.1731434205572; Tue, 12 Nov 2024 09:56:45 -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-e336ee15578sm2749556276.1.2024.11.12.09.56.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:44 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 11/18] fanotify: allow to set errno in FAN_DENY permission response Date: Tue, 12 Nov 2024 12:55:26 -0500 Message-ID: <6f1748cdfa0b2849361223563ac3c8ee417b230c.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-Queue-Id: 13D4E180002 X-Rspamd-Server: rspam11 X-Stat-Signature: 33gihqgqhpirychn75rirqpjzrgpctwn X-HE-Tag: 1731434200-473540 X-HE-Meta: U2FsdGVkX18MOd9NKsXfcx147ttCPTzVx0GjUeEl5BieV1J3HTl1REo9fR3jCx0DwKorqWTtPKFCwVe77TF/2JTna1su4u2w77HJlMsLV9GCWbZXN2jcMGqpVG5EI3CmwOB8nJRg4H9YROlwewKywfzUtXgvSw8NFwDuNT0lPbs6EGY18+R3x7FE847BhCn2bF+gkua+7dFV4+LC3Rb6KtiOdoaLQJZCZVGty4oJ8hsqc1HDRvv0En7j9nVOjAll6odgm/0Ba7RzArk0pGnLbwDgM4Ytc5/Q82AI7wZrUWa+LJsduEnzkKtdQ2z0AgXcqeq6Mkc574THcSiCNomsnDxMwHTZXvSNePXQ6F+sZ0R1CJMbEsXs+HNgjIPvOBehuHPtLyHnuNWJQ2frFn61mTiP5iGqn5gWucHH8cv7+3zlny6tp//r75wThQe7o1YOfd9p9uwZf6rzYuTCRTaOcw2O+HzQzy+sYzMw5LMFKruDJE4B9B0vjfdDHNFB2ERYL30Ft4s9+q4YKwrsVEugykMLjYzH+tKKq16m8mB4CoKqa+3/8uPM4Lp+tNfhw2vdm0zognQ9OiWAxSHRS5RkMHdDMn/K0481rw5F1wMMBA9vezqkqC0JS75xEaYg+YVb41FBcFD2cghBCIZJ70O3vQ1e6/E36z4+vYhiN8Bdeba8EXsR+b0KIik4VPmF99EofsworVyAqLCs8n6dx/DwB8QAlPfB2N/5WK4Q+ahaGlpm6QMw3Y986U8O7wixTRUqUXzoVaDZJfwtTITrnGOLC+f7Ul3fmYoXjEcdX7WspuGFxc2BYgt0cLdz4lVZFmpaZ+m3v1tefQJk/tkxEcfrv2T6/C4XGa7dd7BimKnWeaQUYyl/iMlXtAMUDKzQ49zkqQ28DgGn9qkVQgLVUJ18AHqrXK/gOcPE157DNt24wIYAgynZ425/ccP714ofQKTR+uY7eIMfUzOlG/JVSnN +96h1Ts6 W4VZhSfya+2v8OuVNw39ApAISfwQHNh/ZEeCzPgTNn7q8iEoUwz5m6LYBgh9JJ9YbEC4BJj7c/JnrDAKvvbpT1EdLPCW2AOnT+2zKqIzX6J74Z48WTZjCo63JB8gxHX9Ubi2F8d3jbHF86+10kzmKbVrtZ3FK7TevbCWx+8kn8n8yPrCC2XLfpf29UnsoK1TUC7i86EJP0LCznkyn/3fB/dYntDVnb5bzTd9mpTbDIAsiIkciSaJqODgjMPlsqb5zMCX0k5sAyxiDe4+ZXExFQE8MI8/zC4BcUi1Jlhyi9wT/YDKskS4SBScf3pAFfdu9/xlCpbB69T1USibfwIOrYDJJuoqqX0dvae355DBuZPqMe1Hv3lLgBBJrU5gm2s30otUpwkL6GxDqigHF8NNhz0GzSRZy+Ew30RMBcOMVeMr4U7UyGZI+owPh47QkpkWMh//54QiHymtcvBIj6Fm2uXQcCmGvDHwUhs32BKBiDkfVd5zILr31y3Xmuw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Amir Goldstein With FAN_DENY response, user trying to perform the filesystem operation gets an error with errno set to EPERM. It is useful for hierarchical storage management (HSM) service to be able to deny access for reasons more diverse than EPERM, for example EAGAIN, if HSM could retry the operation later. Allow fanotify groups with priority FAN_CLASSS_PRE_CONTENT to responsd to permission events with the response value FAN_DENY_ERRNO(errno), instead of FAN_DENY to return a custom error. Limit custom error values to errors expected on read(2)/write(2) and open(2) of regular files. This list could be extended in the future. Userspace can test for legitimate values of FAN_DENY_ERRNO(errno) by writing a response to an fanotify group fd with a value of FAN_NOFD in the fd field of the response. The change in fanotify_response is backward compatible, because errno is written in the high 8 bits of the 32bit response field and old kernels reject respose value with high bits set. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 19 +++++++++++---- fs/notify/fanotify/fanotify.h | 5 ++++ fs/notify/fanotify/fanotify_user.c | 37 ++++++++++++++++++++++++++---- include/linux/fanotify.h | 5 +++- include/uapi/linux/fanotify.h | 7 ++++++ 5 files changed, 62 insertions(+), 11 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index da6c3c1c7edf..e3d04d77caba 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -223,7 +223,8 @@ static int fanotify_get_response(struct fsnotify_group *group, struct fanotify_perm_event *event, struct fsnotify_iter_info *iter_info) { - int ret; + int ret, errno; + u32 decision; pr_debug("%s: group=%p event=%p\n", __func__, group, event); @@ -256,20 +257,28 @@ static int fanotify_get_response(struct fsnotify_group *group, goto out; } + decision = event->response & + (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS); /* userspace responded, convert to something usable */ - switch (event->response & FANOTIFY_RESPONSE_ACCESS) { + switch (decision & FANOTIFY_RESPONSE_ACCESS) { case FAN_ALLOW: ret = 0; break; case FAN_DENY: + /* Check custom errno from pre-content events */ + errno = fanotify_get_response_errno(event->response); + if (errno) { + ret = -errno; + break; + } + fallthrough; default: ret = -EPERM; } /* Check if the response should be audited */ - if (event->response & FAN_AUDIT) - audit_fanotify(event->response & ~FAN_AUDIT, - &event->audit_rule); + if (decision & FAN_AUDIT) + audit_fanotify(decision & ~FAN_AUDIT, &event->audit_rule); pr_debug("%s: group=%p event=%p about to return ret=%d\n", __func__, group, event, ret); diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 7f06355afa1f..9e93aba210c9 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -528,3 +528,8 @@ static inline unsigned int fanotify_mark_user_flags(struct fsnotify_mark *mark) return mflags; } + +static inline u32 fanotify_get_response_errno(int res) +{ + return res >> FAN_ERRNO_SHIFT; +} diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 5ab9ad69915a..b83fefc8aa2d 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -329,11 +329,14 @@ static int process_access_response(struct fsnotify_group *group, struct fanotify_perm_event *event; int fd = response_struct->fd; u32 response = response_struct->response; + u32 decision = response & + (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS); + int errno = fanotify_get_response_errno(response); int ret = info_len; struct fanotify_response_info_audit_rule friar; - pr_debug("%s: group=%p fd=%d response=%u buf=%p size=%zu\n", __func__, - group, fd, response, info, info_len); + pr_debug("%s: group=%p fd=%d response=%x errno=%d buf=%p size=%zu\n", + __func__, group, fd, response, errno, info, info_len); /* * make sure the response is valid, if invalid we do nothing and either * userspace can send a valid response or we will clean it up after the @@ -342,18 +345,42 @@ static int process_access_response(struct fsnotify_group *group, if (response & ~FANOTIFY_RESPONSE_VALID_MASK) return -EINVAL; - switch (response & FANOTIFY_RESPONSE_ACCESS) { + switch (decision & FANOTIFY_RESPONSE_ACCESS) { case FAN_ALLOW: + if (errno) + return -EINVAL; + break; case FAN_DENY: + /* Custom errno is supported only for pre-content groups */ + if (errno && group->priority != FSNOTIFY_PRIO_PRE_CONTENT) + return -EINVAL; + + /* + * Limit errno to values expected on open(2)/read(2)/write(2) + * of regular files. + */ + switch (errno) { + case 0: + case EIO: + case EPERM: + case EBUSY: + case ETXTBSY: + case EAGAIN: + case ENOSPC: + case EDQUOT: + break; + default: + return -EINVAL; + } break; default: return -EINVAL; } - if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) + if ((decision & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT)) return -EINVAL; - if (response & FAN_INFO) { + if (decision & FAN_INFO) { ret = process_access_response_info(info, info_len, &friar); if (ret < 0) return ret; diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index c747af064d2c..d9bb48976b53 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -132,7 +132,10 @@ /* These masks check for invalid bits in permission responses. */ #define FANOTIFY_RESPONSE_ACCESS (FAN_ALLOW | FAN_DENY) #define FANOTIFY_RESPONSE_FLAGS (FAN_AUDIT | FAN_INFO) -#define FANOTIFY_RESPONSE_VALID_MASK (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS) +#define FANOTIFY_RESPONSE_ERRNO (FAN_ERRNO_MASK << FAN_ERRNO_SHIFT) +#define FANOTIFY_RESPONSE_VALID_MASK \ + (FANOTIFY_RESPONSE_ACCESS | FANOTIFY_RESPONSE_FLAGS | \ + FANOTIFY_RESPONSE_ERRNO) /* Do not use these old uapi constants internally */ #undef FAN_ALL_CLASS_BITS diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 0636a9c85dd0..bd8167979707 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -235,6 +235,13 @@ struct fanotify_response_info_audit_rule { /* Legit userspace responses to a _PERM event */ #define FAN_ALLOW 0x01 #define FAN_DENY 0x02 +/* errno other than EPERM can specified in upper byte of deny response */ +#define FAN_ERRNO_BITS 8 +#define FAN_ERRNO_SHIFT (32 - FAN_ERRNO_BITS) +#define FAN_ERRNO_MASK ((1 << FAN_ERRNO_BITS) - 1) +#define FAN_DENY_ERRNO(err) \ + (FAN_DENY | ((((__u32)(err)) & FAN_ERRNO_MASK) << FAN_ERRNO_SHIFT)) + #define FAN_AUDIT 0x10 /* Bitmask to create audit record for result */ #define FAN_INFO 0x20 /* Bitmask to indicate additional information */ From patchwork 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+M5IdLGPW6uTZjFB61AjfRoRumdGh1jMLv2ZKiujTddblxK8DNAqQea2uvENOTfJKXaF9BYXCkAQz3ZGLjDxwPIuVSj5sbQsGNv86r5sdBwGfpcZKDay1SUyETt9L0qgerDHGzLK7fTsPQSH8v4oBrCCBAWqGPdbtvUYgKVXexFQDZ6QR28Dzzo0JZoXOsJp3TpgQem6DeOR5MYx4nOwqaZKMrc3rXCXaFM3p2SiZ74PgOaMEaG1xVCQ4RYMQHGRyaLjs8z1D/iY4Bta0fqSnNJuHPPynIj/v5rQcbZsoOkO+o8vKhZ0HP/FvWwrEAqfzyf6sPx8T53GuYwudp9/kqLgfCG31bqnzVra+R5ZIBmP/p9g34YzUqq5P+d8jBNYxelU4V3LTNx0VZldrRY48dO7Ms7+CudjvYL5+biz1715KOl38txQoiAsryzlJvPdBCZDDa9rGNopqcstOqnN/sYkF5HVsl6oFvDarBWnkDtc/1+eEiwyGjgYF0QFZEnK14jeJcEwWpHbT+gRP+3kxjeSeIU241GH9ZwG8d2SG8/8SAFyriQfeMMF8spAp3ZriLnZYt1c5WlnU580dyIVUVau4H2uqZccS2U3RE/6ohDzbbK+N697DTnUBcREp8F5W+GAr44mos0RPS8W2RmU2VpVYW2CbrOcV8z3HG77kMUoHJlFva/LMEtSXhlhtiliHQJJe/TPe9h7qDYI2g1eqiXEpU3bPpsF/ZENs2swCBRLLweAzz3GFDJpjd3L8rDrWM4D8lJJcJtFCT+1xmj9LKjzu9eoLIE1KxxRdiruPKBeY/3x8pKULdxhmBbSrMf1+BcHohXLT93PnZlkphDbmx4b4Xg9fp11oDyQ9aZc4y7uQZWt+ovadcicIa7rIAGlu6dIJopCibirLZFtnxkwQwkZB6cmZyvAsIVbk4+A+xK7 WoqbXWvf A7/xhRU4XeOzK3ZvQZYtIOL0nu6/VVtp5DLw9mHvYxuD4HziqUYw0Cl9xwRO7nkjjeF3f8WsYZ8vaI148B04FfXxD1xFnyJ9TY/pd5qKfxmOkhSQD+Jn71niBcMj0gNDBuTjchEdIsSPnxg/+ZcRwgI8CZjTvlfs0bnEdtKe+zfMTq7nt4Db3qXxQ0wVtQWoqMGFbxiPyT5gLAe4WnefogmJvWyri+0nNeoY2jsMdg8hJWr/s27M8GWM+6/tmGG13M1YqQpNYuV9ZqmU8bCD7y8NDP3Xpw/Rh4geYivVrPiIMA4BlLGldD2DX29C7pnfTVlG2Yzp6CxKMCDRIylSxw9P4B3ljk8hG1fWkbNE7IK3587UBAGeaQSOR3Q== 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 __ */ From patchwork Tue Nov 12 17:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872738 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 0D1CFD42BBA for ; Tue, 12 Nov 2024 17:57:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D2226B00A5; Tue, 12 Nov 2024 12:56:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 059EC6B0108; 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 D728E6B00A5; 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 B1DDC6B0106 for ; Tue, 12 Nov 2024 12:56:51 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6EB6DA04DC for ; Tue, 12 Nov 2024 17:56:51 +0000 (UTC) X-FDA: 82778198244.14.7D3D8BA Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) by imf23.hostedemail.com (Postfix) with ESMTP id 16217140007 for ; Tue, 12 Nov 2024 17:56:21 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=w5tg5gWQ; dmarc=none; spf=none (imf23.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.182) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434147; a=rsa-sha256; cv=none; b=FzmvYoWLTGJqa8EnnfCXn1IoSkYn3NSlvBhCqnl3MVHei33axxJVy3efRTiL8AJdlBbKp/ SAWMdRPTfRzDwqCwoSdsxcXz1SnV6D2nMOmzO/v1UW/8U/LmTa3iL63v2+NZhwxvAlKLK7 DJuDJH+8Zai+RCNHdDgQbz2P/BcywbY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=w5tg5gWQ; dmarc=none; spf=none (imf23.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.182) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434147; 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=DKrH1r2LzuvlRLkIW99g50GCI+7PqnnQMlTA3Xoxniw=; b=09WSHuqPlcjiia8od8NOj7VIFwzpfOlhw14xRrCgZaV5Z755RLsqr1Sp3DLIBPUvvoNFtT 5bpoa57gq+CFW8eWeE6cxVYuTvZYIZPjaY6UrB/yorKOwKYIYBzaH1HMEgmD9dDT6syBCz 27UBRzJpFtViZjNClwqIeGssj+V6+QA= Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-6ea5b97e31cso50199907b3.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=1731434209; x=1732039009; 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=DKrH1r2LzuvlRLkIW99g50GCI+7PqnnQMlTA3Xoxniw=; b=w5tg5gWQ/gpWnYve2uoKKADAocLukQkic5cQI9u1oYCRYTDmRsR7TyhSIPThfyYlHD T3oXYDJaLV5m0yE6WNgMTj3q5QXqNbH+WA4z5SqSTYRWtbH6UL1GKNo/5PM5K0kWHZin FarvWAWdOddM7YRqaBbUcV9L1mb3L4QWcMbjaUyBW2XUH/z/Yp71EhXuQ+eKEZlwDmU+ cKtkf94gO7bQaiVD3twSrHZSrwwxrrK9M7AxxNEDTUkfWLRcsSmmpkAEis0KZzm5r8Td IP85RyB6Z0UerlVeIn7vnohbK/JfuUaiJCLtBGfkgwDrkQD1rlWuqTEe2n1QmWDrkEJQ UHCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434209; x=1732039009; 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=DKrH1r2LzuvlRLkIW99g50GCI+7PqnnQMlTA3Xoxniw=; b=nthXSRpc0/ZK6NenmhNmnwgZW2LdIs4z596IvuGBBgdMGyrHt19En1pCmWpOHmTMfY orrywV0dnWFZVK6jH7LbfzFL14lDpDsRWhv79EOqtiB9CxbsIk0n0xavgkmE3FifXDuO OYMQowBVD/o9ZbpGAGm732m2CJgolHhhTOVMdVeZtikgohnriErowWSHq3ZhSJ8ULjeu SlvM1g8HKoH8iWJqpIDrBf20Z++hRsHDikU+MTSup7Vn/piWT6JHAIYBtfoCR2XsgeWZ 1We0cGsFKSxiJ3uJSiMRuovoHBOTinFAWPgoSgQx8iW5Ll1uqZKRChYJIcwQE/e2Q9Hx UDuA== X-Forwarded-Encrypted: i=1; AJvYcCW2ktSQ//gX0xyiYg3isVpFA2+3Ulh2ThMr1Z4mI+tKwfB+hgCvsbSUVrnHQvNzn1vHGTELDyofrA==@kvack.org X-Gm-Message-State: AOJu0YxiHzN8x9lbH3La21IgoNJaBOYRvsJrGu/FcZkyqTactw0h5I2H i+wfBCzTYZgWzwYc/UDy8L857hWDYS/wJeSth31nYXD59mKpW/IJb1WLRx5ragc= X-Google-Smtp-Source: AGHT+IFJc2RNjc1G/OBWSTi5fyS4IghkV6OUbtpYdZWmaUR5D0i4/YYlt6JaXitbsIbc6IfGCQnj9g== X-Received: by 2002:a05:690c:3510:b0:6e3:c92c:1d57 with SMTP id 00721157ae682-6eadc0a271emr140258467b3.2.1731434208685; Tue, 12 Nov 2024 09:56:48 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb65a75sm26238187b3.97.2024.11.12.09.56.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:48 -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 13/18] fanotify: disable readahead if we have pre-content watches Date: Tue, 12 Nov 2024 12:55:28 -0500 Message-ID: <23edd657a315f2e5ed648f8dba6d34898b4af85b.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-Queue-Id: 16217140007 X-Rspamd-Server: rspam01 X-Stat-Signature: wkptyqae6iaihre6wkb63hqpx9s1a8uw X-HE-Tag: 1731434181-414041 X-HE-Meta: U2FsdGVkX1//IwkV/NvUQs0WkrKiPgyt8/DdPpMKn7qanW8wn/m+g4QPECK3qgx8ceObRA0TJFSEQIn2LPe5O9hx5biQNW6+tJHiER+wyJ20UjwqP+UlGrGiCk+Ogd5bKPxvo0/1dIGu8Da7E7fKwX+pAkISg/BSuAXcnvvr6vHNtXu5v14oaJGimrJvMhRVJ9i1A/6SJDlfAN7E2jAThxH8KLaVu8TY2e6WmewjY/B9Z8uEbIqiqWPlNq8m6DaZMFqaT44JtTwYmOZdXkGllBTVdZV3ZgfTDdWw0dKwTxGgggpFc5q5rLaPBo808ClKbX5PcVqouhsPfdS1nNQftFoWPZ0LINwZbVIPJ1pi8JxAtvt8V8iSZXkCdU9zYxygZ7wbn0VdruJXdBdhzCqWvI8qLIzXv+N6w0hGpwrznxGZb96VPd5kLQHMobdCZ+dkumzB7uijIGwB7BLeCz0HBwBfLy93x7eHH/K0vra+hJzkIAOdo44FE5G39K7gW0uExvtUib1WdkVUJdNToe8O1Emi8KCXBaav1S6XMTfyJmu4PuBqXSZ6tv34WPMAD3+Iu0syDNEFcgEQsVSpt7OEduS8KgUSaa4I0VeeaOq0ZGBJEQwCFj6hEwmODT0/9cvSNS7K9IEuViOynVtM0uHc6faFRS32peK6ITxNVfOIUgT48Ps7/XmLA26vW7dPGQDCLG2p3CfBDA/GxSgicPSCN9CkJlJ/hDynqgzEh9g3LGlcc2OlbA8a26GuoBI6NCnQQXMPN0x2OVyoFz1ArtRjotgVXNcq+pFiagZSt+gOJezhACNWcpiuhJTBCGvExw5d92M5etFiHNVLvNPOmJG4wuMA6GSdSGN7x22kTn8H+x6a6lg4+ceWazww7Gae/JJbny+snAlwFDrVXPee6cTfH0SA2vUKNRm5hWFPHWvifqcS8DegRUNa5PvN3GQxJ2NFrHc/t584nnSxcjyI7qe Dtyk0Nv2 PCHCaOAbODKqmBRWDQjogLACf4WmXTIRrjc3DsJmNMfiXu25lKzphcsg1ouOc++moLPFqfJ5kbW1OGopy63NoOo0ZHlv8zXm08xwqyJpIKhT9jv32xBiGzIuYYaYx/t3RITpbUNdzhxn1Dxio3FjEQEXE13UxpZf3wvMYEduUPcoc3zMO6D+9Xe+Iga6HzZi0GMmNWFRi8LNAICPD76WKpQxmxRctOxaldVUWRjHSesuifg3SQOKfNbKvGZujG73hP9CDufjumYagAphehJWo0MGwEIZBELq30IohAOZZ7OuMooGLXhNFNJwSwzrX/6N8TBozPGwPn7q5+3B3Zis8icjZdigHlMDaTKp60JsfQtrQTBnsQwK934lSchyplNsrceZmCXrJOF0lrce62ZcASKB3zrClZknf0brnIRztrZo9MhqAd1D8CywwOcZOu+hFzSTzQFxv1CwrpKXsvZfMBMAAi1XeIVUwyCO3Pr2pAmNu6rzoJnPxuV5TQ5wI99r98beq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000091, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With page faults we can trigger readahead on the file, and then subsequent faults can find these pages and insert them into the file without emitting an fanotify event. To avoid this case, disable readahead if we have pre-content watches on the file. This way we are guaranteed to get an event for every range we attempt to access on a pre-content watched file. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- mm/filemap.c | 12 ++++++++++++ mm/readahead.c | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index 196779e8e396..68ea596f6905 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3151,6 +3151,14 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) unsigned long vm_flags = vmf->vma->vm_flags; unsigned int mmap_miss; + /* + * If we have pre-content watches we need to disable readahead to make + * sure that we don't populate our mapping with 0 filled pages that we + * never emitted an event for. + */ + if (fsnotify_file_has_pre_content_watches(file)) + return fpin; + #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* Use the readahead code, even if readahead is disabled */ if ((vm_flags & VM_HUGEPAGE) && HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER) { @@ -3219,6 +3227,10 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf, struct file *fpin = NULL; unsigned int mmap_miss; + /* See comment in do_sync_mmap_readahead. */ + if (fsnotify_file_has_pre_content_watches(file)) + return fpin; + /* If we don't want any read-ahead, don't bother */ if (vmf->vma->vm_flags & VM_RAND_READ || !ra->ra_pages) return fpin; diff --git a/mm/readahead.c b/mm/readahead.c index 9a807727d809..277c2061fc82 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -128,6 +128,7 @@ #include #include #include +#include #include "internal.h" @@ -544,6 +545,14 @@ void page_cache_sync_ra(struct readahead_control *ractl, unsigned long max_pages, contig_count; pgoff_t prev_index, miss; + /* + * If we have pre-content watches we need to disable readahead to make + * sure that we don't find 0 filled pages in cache that we never emitted + * events for. + */ + if (ractl->file && fsnotify_file_has_pre_content_watches(ractl->file)) + return; + /* * Even if readahead is disabled, issue this request as readahead * as we'll need it to satisfy the requested range. The forced @@ -622,6 +631,10 @@ void page_cache_async_ra(struct readahead_control *ractl, if (!ra->ra_pages) return; + /* See the comment in page_cache_sync_ra. */ + if (ractl->file && fsnotify_file_has_pre_content_watches(ractl->file)) + return; + /* * Same bit is used for PG_readahead and PG_reclaim. */ From patchwork Tue Nov 12 17:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872739 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 C1952D42BBA for ; Tue, 12 Nov 2024 17:57:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C14696B0105; Tue, 12 Nov 2024 12:56:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BC4546B0106; Tue, 12 Nov 2024 12:56:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3E446B0108; Tue, 12 Nov 2024 12:56:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 846476B0105 for ; Tue, 12 Nov 2024 12:56:53 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 41487404D1 for ; Tue, 12 Nov 2024 17:56:53 +0000 (UTC) X-FDA: 82778197404.23.7451DAB Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf03.hostedemail.com (Postfix) with ESMTP id 2B4C32000A for ; Tue, 12 Nov 2024 17:56:31 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=V66aZR4Y; dmarc=none; spf=none (imf03.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434082; a=rsa-sha256; cv=none; b=yqaA5W6BIEuLVcOvLanAtrndatM9kHbaN0cD4JqtsKn+RSlf9nQ1Bg9fBS4MLF6n5slT7C LZjgS4Ly4bxe82nv/km/FbXjGIaSq9I6HiSRRLTQnhzKiM6DxMuYLlIGO1/lZ5qb+VpDtO xPn8H2umZYIEo9EQlVFpfLnXI9q+4pI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=V66aZR4Y; dmarc=none; spf=none (imf03.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.169) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434082; 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=QtBO4W7ojcvMiQeJDBijogkryb22CThmLCgaVfO4L7E=; b=mnPTGdiaXaFLyq98ic7L/FnmCeR2aB59JeZV3cE8Zj75hInhOc3dWCQS+u4jIERRAJDYug L2cA9VapXEsL789TRVkf0PH0e78E8RvtlDxtFJ45sUuVN8nPbjEQlrT8SooO8FaWNQNAhL VBvcCJf3YAZMH4PKRQJ6fT3RdfQjzHw= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-e28fa2807eeso5710441276.1 for ; Tue, 12 Nov 2024 09:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434210; x=1732039010; 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=QtBO4W7ojcvMiQeJDBijogkryb22CThmLCgaVfO4L7E=; b=V66aZR4YK4g5EY7IgGTnFAi7yQ+LOvMTif9C4lE1rSwsZ2bMBBu0hAbl5pObv6BI6h RT3az57sdDCs0Y9xfRRf137lVqMeLxDhjV8hSU3aVuQ9F7HQgNli4F5fWW9Z5UUfgOSL HT8ZoRxUyk8SZLzmpCr+kb7MDLuvbmVbxmo5QkXb4ZSQGE8hHNQYafpB6raS8tY0rbIp Tz+dTAvO980Cba7eOyInKl1j+WPNNzE5BWxeBNONQcWuYuNqmWrYhDXMiCy8FLgfTprv 7/9mP3bJDk5Q54QYAQXc5N2Oy0VLSJjCqubFjkONjK1nno7THptuCnhE9V/jQUXcjV1n yeSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434210; x=1732039010; 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=QtBO4W7ojcvMiQeJDBijogkryb22CThmLCgaVfO4L7E=; b=bTQCTXUq38zh4HOdXW7puot8LBDE+eaGCJqlcDMUOTUkc6yQhoOdZjnFZCeu1kZtmS 5T6Z0AuHlfSiAYS/SWABejCXYm+VLEiUWMnr4rjkyWfPC+Mbvq7dvNalVuXI7ODtHsJc ytsAAuDfzGTkBiCAUBK5Qorq1xSFq6U7e9le6Hk/qVa9VlsAXjzhkCU9X+ddDfju5bzp sUzOE+n6NQOItoDosCOdH9Gd2SR0+aQ0Ux84wIFPPVIGYb3/+ZCmdZa+l9i4lDcFxBg8 WzdOB0ng8/IWGEQvsTLccsajNGsTOdkHO19T7MwNtnmRWbIpwX9LTluYZhr7tzYyMV/r mbzw== X-Forwarded-Encrypted: i=1; AJvYcCXgRmWHE0xGVImA/x3XogOnayXIuYVu5FH9UPxBMsYqYxvUKBqyqKRHZ3bgmODIp15+Gh/3B+mk3Q==@kvack.org X-Gm-Message-State: AOJu0Yy07mwRykNz2oQyRM6KVuntvMrErtFymBvSzmPkpNuP6bEI16/R K9Jv/eMEesqX+PngE1t7+BnhqCB7PQqJa+BcNzGM3yWNuE3s6xE2Rz/jXnY6JfE= X-Google-Smtp-Source: AGHT+IEKuDZzW/fvP8psHkg5hrvM/70eBZxELM8jsrhGXCGLQnsHGSpuUuvJ02++phM7o+afQ4JSUQ== X-Received: by 2002:a05:6902:20c4:b0:e33:25e2:4b1e with SMTP id 3f1490d57ef6-e337f86d626mr14917803276.19.1731434210511; Tue, 12 Nov 2024 09:56:50 -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-e336f1ba835sm2880031276.47.2024.11.12.09.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:49 -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 14/18] mm: don't allow huge faults for files with pre content watches Date: Tue, 12 Nov 2024 12:55:29 -0500 Message-ID: <532dfc336dc1b09e5604dee4f08b70577089b76a.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 2B4C32000A X-Stat-Signature: kchm4ig6fzx9hdtjn69ai99h11ni1h4c X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731434191-525497 X-HE-Meta: U2FsdGVkX18FFOaB1mY1bUdeVExPPhCfhbyB3tfrm+1lvOQ5IYpCf3uK/IFcK/QmTZpHCtvj/wivBSYILXKZLWnBP3lu8CgvdbuMee2bGhvUhHUynffHzqXlCiHoGPRRPDWg8MYmsVdqtu//r7lvrvyNIDv8WZMmoszA2gO/TG8TUATDaEKIKava0kXjjkuSOkljairZFtI2Jz7Jlp30PwarzseymzkUcZu7Wh/U54vJHrvETd0pePkIRtHTcfiZtStQWRK4eelOZYpl/FRP0VEm6QTyo7q7UUzB8hkTCy2D4UXI6YbyRxX57jDNE76oI/KaRDghItGgidbV0KywqJ/oeOUuM6oedTePV7T2qfV0wtkYZ+TOvPcQ4vrPEWQz0Q9A1LMgyySnH2LdPqmK7S8jnOr2an0od2yK0/rsBpuOlHB0KXxQp75OnwFCHRXv6lmwE59hpmeyuKbJPzQcR2odQAE/vJ69mULNUBJArWaDKEXgKKlbOi64F4ODpJUmGzbtGBjA33JGFpXgWTTGWvwBh9fhtk0DewbbUriQHNnP6eGIObPnce7HRbs/Dqibc0gie1A9C1uJeX77ChTcTNAx7ay3IdUWBKSAFW2MtAG+GeKOqokWACyPGSU74F9/P+Ok5Ttu7rLCxnXa+tVTwzFkGAZyI0fFyRNFFS6OjucVI3J2y3N2Cb3mDluvLwmT8tS/MoRsfHVSxgNHjk5L7gPL7xDQC1Rmo0qpq1+X47eYhvwqJgDUpdKbqoEUfkWD1/2BHvIb/cKYdmcYlVV5uSVmU7G7bgAgvqQvMzILAsTIGfpPmRQeWsy9LO/uAO0qPeiK2fYi9nE17TJS6FWq1byXOxtTlgkiYCzpSFz6gfAh5sy12DPkJfCo0A6+s7Ih6BgktmHSu9sKBaOJNT+XkGp3C9Hznuq2mh90Ignefb3MRMpAPCRCKhvIcziUYbzwU9hcf7fCw/57qfSLkxp 8qo6mtSu mtgzLXSgeqjS0WBF+/9BPv33KtPW1LWKxWE90kUNzTyiu6MkVF2H8XjP/boilwIX0wF0zb0X9ch58CpM8HgXlHu2obXi2xFxh2S5PU1SH9QYjJAgVuLU8dcYUY0o0iWvhucWbeWGwRPuiuH257krawre2JqJu3mxe+2EwBlUKd21HNTZAQzFe/PgWiOU8T0eBmiVQKfZYvx7cbG/zuGOK4EENuH/7LlsidvnLg420WB9Y+sldeFg8+OC0QmFNOwJ8wttmWhfKSztSeNhGMQzHzDHkDn6TJG+A01LKOwPvQPstYToKqLSwG4+RJRxMHm40/L19hQLlOsVHijCp9MrUAdoGaUqd2sF7aK8MD/h+D8wQfT8P1Ng6mb0sgUxR9TsJDSl4heGrzTSddhKfnflx8+IhrZ5FaEpV7q0H6dtmnCLUpFjdoXg9h3frJZyhLm63mLWZAH3hrJ5EWaJtTwk/qy2+HG9Sohw2056tdHpCEprgyJLStvL0aOdoJTIkJXhIyA1Hly/zeV/Z/Ng= X-Bogosity: Ham, tests=bogofilter, spamicity=0.001911, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: There's nothing stopping us from supporting this, we could simply pass the order into the helper and emit the proper length. However currently there's no tests to validate this works properly, so disable it until there's a desire to support this along with the appropriate tests. Reviewed-by: Christian Brauner Signed-off-by: Josef Bacik --- mm/memory.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index bdf77a3ec47b..dc16a0b171e3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -78,6 +78,7 @@ #include #include #include +#include #include @@ -5637,8 +5638,17 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; if (vma_is_anonymous(vma)) return do_huge_pmd_anonymous_page(vmf); + /* + * Currently we just emit PAGE_SIZE for our fault events, so don't allow + * a huge fault if we have a pre content watch on this file. This would + * be trivial to support, but there would need to be tests to ensure + * this works properly and those don't exist currently. + */ + if (file && fsnotify_file_has_pre_content_watches(file)) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PMD_ORDER); return VM_FAULT_FALLBACK; @@ -5648,6 +5658,7 @@ static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; const bool unshare = vmf->flags & FAULT_FLAG_UNSHARE; vm_fault_t ret; @@ -5662,6 +5673,9 @@ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) } if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { + /* See comment in create_huge_pmd. */ + if (file && fsnotify_file_has_pre_content_watches(file)) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PMD_ORDER); if (!(ret & VM_FAULT_FALLBACK)) @@ -5681,9 +5695,13 @@ static vm_fault_t create_huge_pud(struct vm_fault *vmf) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vma)) return VM_FAULT_FALLBACK; + /* See comment in create_huge_pmd. */ + if (file && fsnotify_file_has_pre_content_watches(file)) + return VM_FAULT_FALLBACK; if (vma->vm_ops->huge_fault) return vma->vm_ops->huge_fault(vmf, PUD_ORDER); #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ @@ -5695,12 +5713,16 @@ static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) struct vm_area_struct *vma = vmf->vma; + struct file *file = vma->vm_file; vm_fault_t ret; /* No support for anonymous transparent PUD pages yet */ if (vma_is_anonymous(vma)) goto split; if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) { + /* See comment in create_huge_pmd. */ + if (file && fsnotify_file_has_pre_content_watches(file)) + goto split; if (vma->vm_ops->huge_fault) { ret = vma->vm_ops->huge_fault(vmf, PUD_ORDER); if (!(ret & VM_FAULT_FALLBACK)) From patchwork Tue Nov 12 17:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872740 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 84A85D42BBE for ; Tue, 12 Nov 2024 17:57:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 780FA6B0108; Tue, 12 Nov 2024 12:56:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E3596B0109; Tue, 12 Nov 2024 12:56:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50D2E6B010A; Tue, 12 Nov 2024 12:56:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 325DE6B0108 for ; Tue, 12 Nov 2024 12:56:55 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DA71F160464 for ; Tue, 12 Nov 2024 17:56:54 +0000 (UTC) X-FDA: 82778195850.20.A985FF1 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf13.hostedemail.com (Postfix) with ESMTP id C4E7620007 for ; Tue, 12 Nov 2024 17:56:09 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=JnUeUD3D; spf=none (imf13.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.173) 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=1731434020; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3KCTaRjNmkxmxaKf/dEMrgpxbgs8A3iRugI4cag6Bm4=; b=uxhSuaJocgL72UVrggFE5s8XUkT4L5kR3eXh3bvh7i3eH27b6smIzZgoMFntF/4Hi6MSZ7 4HXCFH4ZE3M5zuSKbfbyan3yjEOCgKe6rRxgbguHbvz1Cob2ju9Gjih0gn8hGd2BF8AX7V vtaMHmGsccJi5qEHh5WyfGDPvyxxJ54= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=JnUeUD3D; spf=none (imf13.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.128.173) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434020; a=rsa-sha256; cv=none; b=YKHxorB7TDRMxK7ZXTznoLTvmX/lWY1CesNyrHi1MmAjAdWZDAVz70O7XHfRFDOtHetnYZ qJTAzoFPbKC77EANKxWZbGxDG+vQTAHou9WSG8apHokvvZHBS/sla9z1VrHGEW9aWFuYzD 5Ge756XPU3AWNcNXV5ixoa8JBIXT20A= Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-6e5b7cd1ef5so51433637b3.1 for ; Tue, 12 Nov 2024 09:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434212; x=1732039012; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3KCTaRjNmkxmxaKf/dEMrgpxbgs8A3iRugI4cag6Bm4=; b=JnUeUD3DHhVybNwrcMFLg7vB/Yq0cHqoSG93uWD4urXjlv9At+PvmjAawU5KP+Op7s pnXJP2wx5omMk1rQwdjGwyZRthFjtr4uLBRRdBDRjJ8lE8bHVvNIVbONJvUIHpIZcBeg WvwcJ3TAv/wGyx0wOz7/l/btrEcNCw6xCAN6k0YEq3wHz+yHmClxvbnAlnQZsJc7LOPJ t05HCjFF5vYzEdO2HMfO3tveRYJEuGV52aKmLwo/WcPR3C4ZEBzmVXK/nCGQgPe+ubfv HUtYva4u9oa4bx9AHOsvtOU367yeK/FmgB+rzcEpRS1lT9QsH8RMnV0NG6rjUn7g/XJO frAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434212; x=1732039012; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3KCTaRjNmkxmxaKf/dEMrgpxbgs8A3iRugI4cag6Bm4=; b=JZNAHf+0bq00GsMaSAU/05qdl5zd6bL5jiXA8c5aELqSOimi4Q1J53337yst6Qa4c2 mRHRV5iZ9MQmifta427DhSQPSpU8GWGrfqxiBWFf2p3YyEPX4WS2flYbEXh40rl3sjs9 SMqQa5w98To4VvbD7FfOwq4EB/9u6cSO/a+bCPIwYMBgAyNjKkuDMjSxnBKhpXD8K1s+ 8UlbdOVhiViSNn6fWk299tyNPFeipaCVMeLosHrkSE3urdYS0ul3rGEloWaXe9je+C4G VUvUq2HpNM157x3svIrTBjSj/Z0bXzN+BclxXu6ho6OY3DIqOsCxpiNXajaE+IlV+f36 prrA== X-Forwarded-Encrypted: i=1; AJvYcCWVqmvtZahk0xHN6ucEl65gjcfbd+IYr0CogxQMZnhlbwFpXpJEylx/EC4/Pg/9iYH9YVsfQnI6kQ==@kvack.org X-Gm-Message-State: AOJu0YzMBFrB9VBGlhbYzMe0ZToOYJm2tV+7OHXtNdYKwEPSMJtnlmUq M0AILDQbPZymDAjXJQ0YIAhy80fCKgFuYwxZH0XNu2mJRvYylYrXCimsImprfHA= X-Google-Smtp-Source: AGHT+IFoXHSrvSv1nHXDianvdqh8AvWvvCdruw2IfTMCI7MfgJuOUf9jQwkCjXgIqLVtzlih0erFEw== X-Received: by 2002:a05:690c:700e:b0:6ea:8dad:c3cf with SMTP id 00721157ae682-6eadddbc58emr168920227b3.20.1731434212150; Tue, 12 Nov 2024 09:56:52 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eaceb0cdc8sm26499817b3.65.2024.11.12.09.56.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:51 -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 15/18] fsnotify: generate pre-content permission event on page fault Date: Tue, 12 Nov 2024 12:55:30 -0500 Message-ID: <8d223ba40c3ad28dcf9369bf16c3182baa925e59.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C4E7620007 X-Stat-Signature: tem4bt4u4g4qaarixdr653k78q7witab X-Rspam-User: X-HE-Tag: 1731434169-268269 X-HE-Meta: U2FsdGVkX1++TXRMXNYujocaTjIRYuV9uaHNkYxYG4ZpXC1C9W5+ArFeISYy16MbKvYK6PGzhmTCMQ1rW4hHr2TaeaLkovPX35rpF34nO4uSFR9UPVPBo2G9OBrrnR+SSaKd4eGaMO/wp0vU8/NtoypGLtP9qfK5XVB+KjYabACjIy0HyPjqILi/nvLY136edJoIzidUkoW/8Gc0qY1Y6ODBaTzVfW9LcuwPF7wnGoC9Tjeyhuqp1MHm6V7HAoRZ5VIB97VP9xegjCIKxuaV8/zLEaupoMZKjbXHk5bYLRAda1CL9t+tbtTht4JAeHQXnhCwbJBkYrAF86ulwOIOzdBGVYfsn6XCczD3CY637L0BH9WTeKScIarUopZFmXAYfplwTEcOFIys0k29oUqo8FLCScec6jYrKRCQkQiOf78KjMfNyAk/RnMOLUBpMevE1AWOJUbyD6Pc+dFg4mtmpdn2UyeRAh7CL1YFmlmma8Hw1aDTrQn9YqkUu4K3VJ5MnEDeF3AzuiCsf9EHXt145YbJP5OpHFQ4jBEygNIbPd+9U7ZHFACF3gS30XyTC3xQHv1RXtdGF9BTYlVkX1qzi3b6d1prZSeKdCpOyDhrgdyzVHitJoKDLb/GcxX0QUw6dboGJAJwOqU2yErecS20A3WrNVRAKkOVGPU6fGvQWW9zzoUNh56PQVXyNJ70AnHIHwXvIfYa9clsjUZK2ExCd9GtnWwgvHKNpe5S26Lq3lk0h/7o8gu9SESL4mrjl4RRzhslzyafw654LdNikCpJTqany8/woyWSOc5HnOr4tWqHu/P5Nc3LD6r9OeyGMiVCwXs44yjtAWJuS6LqBlvQ+tD7wXcvfQuXuoL9R65rVseur857D21mInFAkWvsZdvxbpO/0p2EUphSS3f7BC35LL3y4GsM9egzPmBsqXmtwJy5r+xVyGNNPvLoENBveC9g1eJNgmeR7nUoYILEnGK 9dEoRZP3 RJyDrmgxkKNMhEQsUPqZl+D6Cx44/JHDNtqHN2kGBZhPtAdf/wNzwlU3lXlcTQH/Q2xE5MTSbLFwxbiC05wg0nXA8+qKA7115/+dwwX7ICtvR8aEGqJWwSVaYQUW880U7uRBQJajKtvd7wuSBEod2LUGVQDd+bhbDITBO/xRCwnh2rjboxqdHXjEMNOxEDpehyXNi+YMHpYxisIW+xaYzlEOQoITIz84pSVmcNvnepesWOdKW28/XWergMqssDyhP2NwG4h0q7C5BXQCAxrHBXKcMDSvJxcI8g70Y9kAEPUMPZYpbZm4dt7EdTxgxQJNvGUhnbqoppoJsjhq+CAj7c+algfmVycVBbG1u6GbkTeCpSQX8T/l4Oaj+IAdn5ODxZFRDMIgaCRyoQ5o1Lsyh572siA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: FS_PRE_ACCESS or FS_PRE_MODIFY will be generated on page fault depending on the faulting method. This pre-content event is meant to be used by hierarchical storage managers that want to fill in the file content on first read access. Export a simple helper that file systems that have their own ->fault() will use, and have a more complicated helper to be do fancy things with in filemap_fault. Signed-off-by: Josef Bacik --- include/linux/mm.h | 1 + mm/filemap.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 01c5e7a4489f..90155ef8599a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3406,6 +3406,7 @@ extern vm_fault_t filemap_fault(struct vm_fault *vmf); extern vm_fault_t filemap_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff); extern vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf); +extern vm_fault_t filemap_fsnotify_fault(struct vm_fault *vmf); extern unsigned long stack_guard_gap; /* Generic expand stack which grows the stack according to GROWS{UP,DOWN} */ diff --git a/mm/filemap.c b/mm/filemap.c index 68ea596f6905..0bf7d645dec5 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -3289,6 +3290,52 @@ static vm_fault_t filemap_fault_recheck_pte_none(struct vm_fault *vmf) return ret; } +/** + * filemap_fsnotify_fault - maybe emit a pre-content event. + * @vmf: struct vm_fault containing details of the fault. + * @folio: the folio we're faulting in. + * + * If we have a pre-content watch on this file we will emit an event for this + * range. If we return anything the fault caller should return immediately, we + * will return VM_FAULT_RETRY if we had to emit an event, which will trigger the + * fault again and then the fault handler will run the second time through. + * + * This is meant to be called with the folio that we will be filling in to make + * sure the event is emitted for the correct range. + * + * Return: a bitwise-OR of %VM_FAULT_ codes, 0 if nothing happened. + */ +vm_fault_t filemap_fsnotify_fault(struct vm_fault *vmf) +{ + struct file *fpin = NULL; + int mask = (vmf->flags & FAULT_FLAG_WRITE) ? MAY_WRITE : MAY_ACCESS; + loff_t pos = vmf->pgoff >> PAGE_SHIFT; + size_t count = PAGE_SIZE; + vm_fault_t ret; + + /* + * We already did this and now we're retrying with everything locked, + * don't emit the event and continue. + */ + if (vmf->flags & FAULT_FLAG_TRIED) + return 0; + + /* No watches, we're done. */ + if (!fsnotify_file_has_pre_content_watches(vmf->vma->vm_file)) + return 0; + + fpin = maybe_unlock_mmap_for_io(vmf, fpin); + if (!fpin) + return VM_FAULT_SIGBUS; + + ret = fsnotify_file_area_perm(fpin, mask, &pos, count); + fput(fpin); + if (ret) + return VM_FAULT_SIGBUS; + return VM_FAULT_RETRY; +} +EXPORT_SYMBOL_GPL(filemap_fsnotify_fault); + /** * filemap_fault - read in file data for page fault handling * @vmf: struct vm_fault containing details of the fault @@ -3392,6 +3439,37 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) * or because readahead was otherwise unable to retrieve it. */ if (unlikely(!folio_test_uptodate(folio))) { + /* + * If this is a precontent file we have can now emit an event to + * try and populate the folio. + */ + if (!(vmf->flags & FAULT_FLAG_TRIED) && + fsnotify_file_has_pre_content_watches(file)) { + loff_t pos = folio_pos(folio); + size_t count = folio_size(folio); + + /* We're NOWAIT, we have to retry. */ + if (vmf->flags & FAULT_FLAG_RETRY_NOWAIT) { + folio_unlock(folio); + goto out_retry; + } + + if (mapping_locked) + filemap_invalidate_unlock_shared(mapping); + mapping_locked = false; + + folio_unlock(folio); + fpin = maybe_unlock_mmap_for_io(vmf, fpin); + if (!fpin) + goto out_retry; + + error = fsnotify_file_area_perm(fpin, MAY_ACCESS, &pos, + count); + if (error) + ret = VM_FAULT_SIGBUS; + goto out_retry; + } + /* * If the invalidate lock is not held, the folio was in cache * and uptodate and now it is not. Strange but possible since we From patchwork Tue Nov 12 17:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872741 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 0B309D42BBA for ; Tue, 12 Nov 2024 17:57:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38ADF6B0109; Tue, 12 Nov 2024 12:56:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 339F16B010A; Tue, 12 Nov 2024 12:56:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B3DE6B010B; Tue, 12 Nov 2024 12:56:57 -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 EBB436B0109 for ; Tue, 12 Nov 2024 12:56:56 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B1F4A120446 for ; Tue, 12 Nov 2024 17:56:56 +0000 (UTC) X-FDA: 82778197488.21.20516D4 Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) by imf11.hostedemail.com (Postfix) with ESMTP id D97BF40013 for ; Tue, 12 Nov 2024 17:56:02 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=aD3MzZ89; spf=none (imf11.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=1731434160; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3nbIBZPU5mMiQBH7fH9PUjd6pvpSRIo6Q0oL6vGrX38=; b=51MXdaa6jQfrcU1Z+4+erSz+iNYvTmFt8Zoo+Bz/J8SrG/kt6Kv2dwjGbndk+8Ghx5g7sQ Med081RG8URL8JvB+U+RmIPCfdAtFNNL3S4Ow3WsDwYS3W82jt2Ae8u708YQxUva5MUHuj U2dFwnPnz/1xrqDM/MsMm6YAITGO3nQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434160; a=rsa-sha256; cv=none; b=6BdLjjuLe6L9ZbLP+JvBlx4MCOqBnQhSMo8BlkmhiSk9yAnyjvORlhC74S1IHWOxzbpo/O pbMLBPIg+0+vyEDkVJja3jTo8CsYO5i00oW+LSS2IyuIQHHYwVdmz7XfE4C8o4t/zo+XvN 83INiDxavlGfRrmLjvHtQRqHfwKqQws= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=aD3MzZ89; spf=none (imf11.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-e30d1d97d20so5291609276.2 for ; Tue, 12 Nov 2024 09:56:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434214; x=1732039014; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3nbIBZPU5mMiQBH7fH9PUjd6pvpSRIo6Q0oL6vGrX38=; b=aD3MzZ89+vqXOpyRZzYnMaeANjJ9FUB0na9XlljdVMfIqMb2aO5hDgBZqXOjz7aMT2 r96Qljrjny1Ev2tXy3u7E1x9yGajhi7P6EwsxcfS9rFjPj4tMSlhlgNMcSa89k2RLmEB pLvrz+/AkhWsVHASRd+JRDXopjfq4UOh87+DkxQLci/AIzdXyuWWhvxm/Q+Z9uHGVIFp gr+wucLVsjoFuwfofp1cUSTjRH6vw5chrLMNi3kWF59+dwZt0AtKxI6hL4Gz+IG+DC7t tvtqEzhcMsAdXKBuQ00ld7zPezt2y9GXFPKiubih9PAsixpKRucZI0W9xdv8l2B4ZjgQ rgdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434214; x=1732039014; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3nbIBZPU5mMiQBH7fH9PUjd6pvpSRIo6Q0oL6vGrX38=; b=VdG+YfCS7+pHqJ6ifsNIJISQBngB15rZ0XMyELSMQ3zZksJw5FsdbmeZHByR5Ey5Gd swvLMTclcAQ09oOPkqkKUlZC8auaQ5lP2IkTsNIfLoaWlpzhCFmZrM8NwxTMs4mdPD/Y aQjhDBZjVLNL93nvPL691q8vshu3WYou/lQKbdr+kl81Syzduf2CWqCr3JlWo9Jsei73 usBk4/SOfQGFugtkBOwRRx7QEx0Nk/LW6m8P0qF1rea3I09ix6ihlJoDXbFv/MnxSJIt yUicOrp4sxKI9JzcgU/c8u5ahibXvedX4QfeghrxIHC5qB6cMbKj++ggk6+oxmyTJ744 Bpcg== X-Forwarded-Encrypted: i=1; AJvYcCXdzBDtqGu2gNlAetdJQnqSWiQ9HAFiKZ/HChU6FAgB761jkByBgeD33JTp3IeqkGToidkovAQRxg==@kvack.org X-Gm-Message-State: AOJu0YyxtoWC4yLD6dR624UMaHT8h1kPqhqE+h3ta5k9vSFKGWeG342s yLn5J8LAHDEaNPWoGqzs/dQMgWH07zR1htTZ1ZGVaLd9LGLtHZxSWQZ0RXM9Esw= X-Google-Smtp-Source: AGHT+IFiuIuaM6zhnPYYC70N0ed/AHQHsVCWIUgMJBIkKyN4ZxuOm530ZzxRBomBAB77BqDgpRvfSQ== X-Received: by 2002:a05:6902:150b:b0:e1d:c3ea:da14 with SMTP id 3f1490d57ef6-e337f8f0c7fmr17671301276.32.1731434213851; Tue, 12 Nov 2024 09:56:53 -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-e336ee15907sm2754453276.4.2024.11.12.09.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:53 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 16/18] xfs: add pre-content fsnotify hook for write faults Date: Tue, 12 Nov 2024 12:55:31 -0500 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: kymdi6ipfbndajpjhg1ws61qzqy7sstd X-Rspam-User: X-Rspamd-Queue-Id: D97BF40013 X-Rspamd-Server: rspam02 X-HE-Tag: 1731434162-461128 X-HE-Meta: U2FsdGVkX18xYCnlmZg0EQOHxPzTfJvP1WlLifpi4RqjA5ap+3iJHyIaWwI15lj0iHDQISt5xeCeQUqokv1FEwiQj+oblwR3LxBOu/RSU5sPIHn1Wr3hgoaNuULPSvOm9sN57hAVdZDkQdF9T3TPSZgeqi2xK8KeC/1mVkIbXCIk0I60a8sP0ovkamdah/fcTD8xo08xYi8Hi8oBlJIKe3Hp1u3D3fh4hxmRv8/Hqk43J9PXf9dHTmuERq9I2Vv4BISkJnzv75MaV5DBpHnv727OvIJD8eqnRBRV04/PeSX6niGpZ2XTOj5Nxubaf9prZM6/Smsg+MrQkRKiYZQ0Dc4ok75gUGFk3nyP0QP7m4DsphRdj2LBM8I+myhZTGUh+XFgdMQrduaE3Vr1+h+aY4K+7YH/thX2p2HNmNFrYKUXNJFZa2gYa6h8K4mK4kpNYWg9sDm8komyPc+mff4YY+bmrg9166GxdWWyY8Gi1OEKt2HQJ6QxL36NrzLfEAfDoQwROulPZ+DHu6j19miaHBrDimm7MrH5TjBtM4MjYYg0RtQaWjRZUPdKbdgoeqZC0z+HHAeOIPY0/gn/9eMo2BOs4nZEbGWXXlDUKWGHcIG/J2hl1HkkGa4SYa22sfUr3q8aqzMioi6J+XoPLTS0+DcWf+mXU6MYhkoXi51+36dB66lrsqqsaNCY02mjbrhMapu8NvRwJatjT7XaqCbeItEoNcgwBxuXgNTpf4VRhZBGmG2V3T3R0un4nYjUx7FIQv9sFraq39bkZWNvAknV5naHg4ZEZqi7hb8Fifor7gvoT4UUM2lwNxQQ19+YzIqTEzV5Q2w13iz18lDy/ojK5gmfTOoVd8BXWbSE3hhi9wfUtKRcMsn4hSUoRuitDqiA/k7pMNDnlj3F2i/VdrXmlUxTYCMR41Z4w77FTyKMGceKmqrZTUi5YWT+Ydy5lOnQmn/Jg3f1rdxNwp1BUhr GLOaDCjq 6AdPacgCafNKzMk6CYM2YQOJKE2G3dMKCrZBq5elVFrJFWqZxD1iUUliMd2+9mjUWhTf9sRI4ffMEndSqpXHoWyEZcfIr6Bj0yKnOyXyu/dpWAZRHnbg8WT1iFtq591Uvc/ff1jq6S33CE+UJJTzVmuE/QtlXpys9gD3cue35HgWAEOOpW1B4QSEtd1nm88Q9qRmUNDG0w93jctnuKgdCJlWobb8M3gAPOH7Q8NCU7vJayIQBdaOiS8tq+VT5bhmZg6h30iD8H+Erpc7rDaZREfvfJJvNU71DoNZ1yVeAtcyQzl4eVOs+EEHEuMWheli2gf5TG5CtnrHcy1kOWbrarHuTtRJQssgEmvemY6/+6AJvSaBM4xFLEbzAUg== 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: xfs has it's own handling for write faults, so we need to add the pre-content fsnotify hook for this case. Reads go through filemap_fault so they're handled properly there. Signed-off-by: Josef Bacik --- fs/xfs/xfs_file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index ca47cae5a40a..4fe89770ecb5 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1458,6 +1458,10 @@ xfs_write_fault( unsigned int lock_mode = XFS_MMAPLOCK_SHARED; vm_fault_t ret; + ret = filemap_fsnotify_fault(vmf); + if (unlikely(ret)) + return ret; + sb_start_pagefault(inode->i_sb); file_update_time(vmf->vma->vm_file); From patchwork Tue Nov 12 17:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872742 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 786DFD42BBE for ; Tue, 12 Nov 2024 17:57:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8DC26B008C; Tue, 12 Nov 2024 12:56:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A3EE26B009A; Tue, 12 Nov 2024 12:56:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 891A46B00A8; Tue, 12 Nov 2024 12:56:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 691586B008C for ; Tue, 12 Nov 2024 12:56:58 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1AB44A04C8 for ; Tue, 12 Nov 2024 17:56:58 +0000 (UTC) X-FDA: 82778197614.26.B552D75 Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) by imf08.hostedemail.com (Postfix) with ESMTP id 50E14160023 for ; Tue, 12 Nov 2024 17:56:28 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=zZSSzkk0; dmarc=none; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.178) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434087; a=rsa-sha256; cv=none; b=S8CP98wSSvGUUlkdcP1RfAStDgB3mqJwz7axlDmzl0LPep8lUxa9L496IMXGPtfgdo+ZSs SrbWhNMu557JL292QFmZAeQ8fPfCvkE0FScfLdLsD1yafzOKzDXYe1NYzku/CpYLximv9Y dUvNly7houk2ylnMns02htG5NDwtWyI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=zZSSzkk0; dmarc=none; spf=none (imf08.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.178) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434087; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SVlCssk7TvFYg+mPz0+epJww2XrJywW98H8fNg6oZ9s=; b=YwypNS/K18MG/TpUiYWFoVqFs+SWJJ3JH1rz09dIOivUGP9kcEZQv3f0g+5n8VNnK8p0yN pPWC7dpt1EnI80Sr0mKQVQNFsn55V8CCBeX+Ii/sivyrk6/rnUawQ4I1TCVnHgYghOyvE1 z3pZgJhA1TQZ0OfIivSItyq7euaeyk0= Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e28fe3b02ffso5573194276.3 for ; Tue, 12 Nov 2024 09:56:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434215; x=1732039015; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=SVlCssk7TvFYg+mPz0+epJww2XrJywW98H8fNg6oZ9s=; b=zZSSzkk0Grcm/IFRvEAkFDtiId72dPtMFvy1WqGRL3mKFx+wqYM7IjYt/qBgXZHXqv H+6KKXH6OHycS4edRI09xItWd69pIH4/RiYaS5rX0enckro04tUX67s4/qJ0BVS0BRMN ck6WwomC6v1Q9h0HZn+ewlPH8s46kJOyvd26epeuaCiIOk7j+JwnW34BoR7J0mSwi0BL FyNqQT/Q3h0xxPOdERgdJoUbHalWAqRnH8Ne2jms0vY8o7OLFyCDxl515EKRY1m3YiJO Z9DWmAwC1VsC1pNNjVut7b9mmc9Z1/lwZ7J9tF3bWi3No7otqYVrtlHOMnKXj2/uSL3q yNnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434215; x=1732039015; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SVlCssk7TvFYg+mPz0+epJww2XrJywW98H8fNg6oZ9s=; b=Z0FnBceVETtGsRTTgk1BZapvRP4Zi5rlgtBdUjhnCWEaCM7c3SuF4w7FmwKN/i7KfU +el/K1dufDiw4aABShwWEHhiQ+wOQxDJvyEiAfuciIojiJz25CP/RxT1i9+88622mX+e sTFn0OeHZY3H7zTDpzV8T99jnq/Hzl9Di2/qb9hZoGYjXtorxec6OY2CwzjnZM/m6HE5 /Al0UdIfbChY1v27OHSkups6e9eXY46RoES1gkdSWwQF7Xp+hQaxd539Uv2Z5f2frjMs mMyWobeMt2p56FSRrgEgHy0vxGVu+Y3LxxHlBey1rJoz9EKJgwRTbnOMC7lfMm1NtqhU Wq/g== X-Forwarded-Encrypted: i=1; AJvYcCWs2KzwVIxnt+rqAIVpSYkdYKZdCdixkhdgRQnT2hqUBQ6TeowMZyxd2bJmYs+nRp2mFuQ8XcUilg==@kvack.org X-Gm-Message-State: AOJu0YwKL841qVweo8PtViWlxFElHKoeyXuLjTwbBtuq+59eN/2MfMSC nfGp+WnISVl0qgAfaZ/pTbJ5qYmVYwd3gD2X90gdtHdG7Skse6Nzk+jkob30Agk= X-Google-Smtp-Source: AGHT+IHRWQQqMmmNmJOTp/8rWDSoFWHv3EcV7+6jsx99WLy4Go67YPaRFk01hHzbJnpPfWcpjoX+9Q== X-Received: by 2002:a05:690c:7448:b0:6dd:e837:3596 with SMTP id 00721157ae682-6eaddd9703amr170632707b3.14.1731434215357; Tue, 12 Nov 2024 09:56:55 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eace8f0c5dsm26584767b3.41.2024.11.12.09.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:54 -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 17/18] btrfs: disable defrag on pre-content watched files Date: Tue, 12 Nov 2024 12:55:32 -0500 Message-ID: <6d9ff819edb6df5583844c26169dc6ddd471316d.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 50E14160023 X-Stat-Signature: 3qpeoj1ondrn8omj3aaigqh9nrwzse4u X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731434188-78179 X-HE-Meta: U2FsdGVkX19hCA7C6y3XPfQP8eTDDyAgODsW4pGSd3FXMfGiRhza8Ct9TltDUZ0q2aCH67x8/ywVS3Q678/E0lKa3sWpgI5ZgUNTYEI7eGi6JpzrVR2HlaAPD67tpBSFjIdN+lfOwLzW+h4+2H6dyJpRRXRBA8qf8ElQ1ynKRAeownI6bQOuxkkJKD+hVrz6sAoyi4ZDG4T8P78ha8b/Gp9t9XYi9Vvy3inuGMFTms9/Z27evCUs8+caM+3mvZcW4KucT8+mNXY1DZrCtwMhEus8vesZgLyORtTwvDt4REFPiUIVds4UPpd/Lx8J1c8TBc0ozeibnEwcbyPeuFekz3KH2KxBbYB2xCXAnC0iZkgtgeQm2iKtvwzwyg0DYejVHfJRJFjlP4EGAXnqdyBWqCVMp/6/qPiCXtGAWysbRnrwEoFU9zO8fQ5G8wSJ3hIw8jqUAreVW2Nbrpn1hUmPvEK3JLhb5HQGcEhD88JwlAW1iItFu2DAXbMHGS7rVtQtyf/zCilfT6BQtnpWtHO9LtDFwPawY4Vmpao8XNMdMM5Mtw7Rxk2cKMRoj79WReN5ZziauvR0OXQfSh2qYU01QmpVhAhwvIBPRSR2bmeTvJcHTZDsfOgoPWvC0O+C6ZtJsXa117VhB2a241dvwXZi6AHE2+Tk02HuEvlKcoLilqw7YdUc9kIHmyvfuRA7F6upzRjvKlQ9yF3FN3SpNnmPEfpzFP+1An55skmxbLvDvPanJXoopJJdD5FvQj9YguUud5Uhth20SvnlIFb/5LFAmdXZ7sLHacYX7TJwpvbDzCdDMEsFwr0a/u3Wk7oqSj3ODqxufGaAlfWfI/OBw9J61n93rc8sXXoZzVLgYw/38dZcYOky4nJ8RzygFEZ/BdOgfrypYXAMlMxtAFaAZqsF7lECK2s/q8Wg9iv2W92QAebFJyQouQV5th5XRc554DyhMhBhkMsIUrfufgnqAcC W6mlLjaA 8Vpn49YXA1xHDdQ6SPKCPZRPMYPtVQW1C87x7Dtu9xAlCj2+mccZDqkkiYh2Xk+DDtsRtZyg6Oh76iJRBtuoNwm6ZIkV+cTj6G9GG1LlFwzjPOmE41/f1BNhVy1Is0F94vUcGWCgm/VgYTxUzDtJZqES+tfsDTgA2aH6AwAEVBWeBvgQvHaDT0PmNtreVIGi8KxG53Jq7Y9xVtfyjqYK+y3MgCexUH7I6cvMDJMGkdoFbxHs1VOOKP/VssD24oABqZFrn4iTjZHi2K0PA0UJiVdznJDEgrCJkV1hT6gjbJELT4DezPAHDgkvAEtmFk2w1fz12x2WzLW1YnMtL2c/pGJaPpIv4COuJVd71KDDY6oXg5HkPwduau1SHoMCNBtqjN65rmgwOo2Kg+dDldn7qhDuZoRjLnnDnttnIDNrXinPs9yAWqUnti9DwfCZyc8aCIeWfn6Olr68gtA3B/Jic32OhqA2MUgKoiTGTZJZ5ZElXwBc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We queue up inodes to be defrag'ed asynchronously, which means we do not have their original file for readahead. This means that the code to skip readahead on pre-content watched files will not run, and we could potentially read in empty pages. Handle this corner case by disabling defrag on files that are currently being watched for pre-content events. Signed-off-by: Josef Bacik --- fs/btrfs/ioctl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index c9302d193187..1e5913f276be 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2635,6 +2635,15 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) goto out; } + /* + * Don't allow defrag on pre-content watched files, as it could + * populate the page cache with 0's via readahead. + */ + if (fsnotify_file_has_pre_content_watches(file)) { + ret = -EINVAL; + goto out; + } + if (argp) { if (copy_from_user(&range, argp, sizeof(range))) { ret = -EFAULT; From patchwork Tue Nov 12 17:55:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13872743 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 C4DB6D42BBA for ; Tue, 12 Nov 2024 17:57:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D9056B00AA; Tue, 12 Nov 2024 12:57:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 35FA16B00BA; Tue, 12 Nov 2024 12:57:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18C436B00BC; Tue, 12 Nov 2024 12:57:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E556C6B00AA for ; Tue, 12 Nov 2024 12:56:59 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A24A1C04BD for ; Tue, 12 Nov 2024 17:56:59 +0000 (UTC) X-FDA: 82778197698.23.E5241D9 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by imf04.hostedemail.com (Postfix) with ESMTP id B5AED40018 for ; Tue, 12 Nov 2024 17:56:04 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=IFZw2pYE; spf=none (imf04.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731434130; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Gek1GO8SPggpZ3MPgZMTTjA2lPqNZurY73wIWpdWbQQ=; b=HfmpbiiSEkC1tyYanaAHhHVax504FVd3BBTB3Fwa4cO4F9r0MjFh+aM9j0NbCTsh6vE8bZ 4d0xtSJ0/sUwIb+u76fLf6bV6nDFChH8TAMa13N2ebYhvntO84nqxB+sEg+ro53dnr66YN mHsLMdL5zK0CAcVEHF+psEoBSED8HT4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731434130; a=rsa-sha256; cv=none; b=q1ifoDt6Q6UJIXoesmwaMZG7gxWtQ9ZiGGiDraQRp6E7OHQhtxQQ/RMOwrxGXRVr507bi7 J/qTS9tTLQr1j8iFeQPzQoH6gX7XNLBXx5EHdNeFU5OhIivPChuRfJO0a1opr23JDPHt6f ceokiYFr6AWahOlZzbN8IjcKEyHhSEs= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=IFZw2pYE; spf=none (imf04.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.219.170) smtp.mailfrom=josef@toxicpanda.com; dmarc=none Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e30d0d84d23so5270184276.3 for ; Tue, 12 Nov 2024 09:56:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1731434217; x=1732039017; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Gek1GO8SPggpZ3MPgZMTTjA2lPqNZurY73wIWpdWbQQ=; b=IFZw2pYE8ofeg+9hf0AofSXWjrfgxW9NwWRQOxjWQJMa59rmRKdKCwie6L1zFhKPW1 RANqTxfsZjQUqocHdaQAotGJ3iaPxhy1b8wFe6Ly72zH7c5hu1r6BNhh4kLSRWNtazrZ mPNPslMSCXN19GATEkYHcZ/kqWbQymvSws/hYk36nT0IggkXvYcRJejdyTfjCzPCab9y +THnWcqJetTuCklj7zqprcPTiPCT0G7uh+5XtknVptf34+MkV4BC8z3TdoOfX7Thr6hx oKRzunSThS3aeZET1R7BE24Rb7AYYdbvBgniZ0Zh4r9bAXt6PEJlcJTIWgC8wmxB+t6C rzmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731434217; x=1732039017; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gek1GO8SPggpZ3MPgZMTTjA2lPqNZurY73wIWpdWbQQ=; b=dIPlORn+Wr83wN5IEU4edFhTQ8WxxO4UhP8voZSpOhQedRM/3KeWejPoXCq5Arw8+J XbeFZKZA7pAonC3rB2vFcglwbwM9MY4qXSzRGB9MBoZ7eLK2py3Lnwhe0UPG3oZ/Uf1d 9OqaqlSHFCcH4whY+NjLkYxBavQ78DENiGAEA5eJ7eBtqM2RrLXmcPrlX/eEecfTbPnc dkgqaqq/QaGUKzRefJk2eZFyQYW1QJ3bcB+wdV8J5sn2zopJpB3HJ0WqYfNeoowWYgBW SyVM4zKAQTyMEb5xQAMyyLce//Uq44tnSWGWamKllfq/NNaLXLYrBaKU5rYR05YH8uH4 dAOQ== X-Forwarded-Encrypted: i=1; AJvYcCUACsqSk53SPclK/TgEFnTjxA9wWBUEE8mjNdaOhXrVEeYgYw4o8MtR3qvIpMX06y6bklyIS3QwXw==@kvack.org X-Gm-Message-State: AOJu0YwpGjyFb7rcttyjc9VVnmvzE/Z/P9MvwUJgczhIMY3OP3XqHxPd XyYB4FleNEbzR3WTxglFjzkZoNThq1+9hzxU7e0adHRNrxtj68XVdIutZ5ssjRM= X-Google-Smtp-Source: AGHT+IEseNU1fU18+Eb5Xypvfn1vm8TMH1JcpZ3Hifh4Ob7CJlLkVA7fH8jLCYaFBtppEHVnywJ7Bw== X-Received: by 2002:a05:6902:1ac1:b0:e30:e59b:4a40 with SMTP id 3f1490d57ef6-e337f8822d4mr14895613276.28.1731434217050; Tue, 12 Nov 2024 09:56:57 -0800 (PST) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e336f1ba498sm2747524276.46.2024.11.12.09.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 09:56:56 -0800 (PST) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, torvalds@linux-foundation.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org, linux-ext4@vger.kernel.org Subject: [PATCH v7 18/18] fs: enable pre-content events on supported file systems Date: Tue, 12 Nov 2024 12:55:33 -0500 Message-ID: <476c173aa514c889cfb3d9a1dcf3bb333a223ef7.1731433903.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: nkrmkhoik7ypwnmoqmpya917pkmtwcpg X-Rspamd-Queue-Id: B5AED40018 X-Rspam-User: X-HE-Tag: 1731434164-78358 X-HE-Meta: U2FsdGVkX1/lSHjskondALp5Wm+KmF0eNzp93+GtkBOg4YeH/sqBOWO1c8Y4mYC+CVEHMqA1X/H1NNbstHVDdwGdx2I5p33eFZTaPLL/JPjvmWV5LRUBciL2pmsbBPIG8lO9v0kJxt3qhDkR1kAsKM7CFtOBwljOIsG5Ab+xcMax6DH5MfBzJWy0u4MJIPVWWdGzJjyhnPTWZl9HWIDTcl07IVwWPXBFsm+NCYKo0cmEJFDI7DZJBV+4rBLw9LAcZxNCIZv4pm4jE4BCKBUJypaF4Q5RnvnQUP1j86tgCXlB7S/iFz4qQcU2IjGeByEdE86sZZEc9xTCPRE8dYNK9CIlJpgN/YJvE8jyVZdkO8anZxQZIdbJmMcgdd7xFS/n/uQitMTMaqCpSJC5K9+cOyDTWH+vyH0nDK6wsu1HSP+PSYUPFbP8vRb5sPuZ35cUmiu+9fsCYlSM+uSUD8HxTCY1jyqrtCMZCiZtNtMubZlYRnJy54L94OviStelvl+ByvPIKP78Qvcl+5/lYdxW6Fpcfwha0uT/vVgXhtS6e+kMKgGmL2WJCgwf7sAxJD4/lFieopghXvO4rB2HnNhVtZTrAm/SjjQzxiLsBD67IpG40Cjw2ycOzjzhNwjXcA2HjW6Vp/EiyozLpWIMlMwKuGUiBbVUWQKKn2aGICc8fNdBkpst3QsqALRgtalyklmjOzNuXMRWJyUeOesq+fKxtPwFBE+nCa8ySlvQSEUwllvqgz9iBBlNdC0KJ08lFouLxTR96BQBfpvV7p+3H8Q2kWX31t0k23k7F93at8w2468RgVJkMUn0/WhJCJg+LRQUST7P94VI+97Faz/toT3oofTa4aM0lHrBmK2uzN/qs8JDdMlCsrl1LtXuzqETtmJmshsOmAQCkasLXbOI9mhADGTEdu5a+WtCkCsJhQyTymCLhKr1GnEeAx9l19MkTko7c08tGJWatmRr4XUTS5V oJ2Q8EAv 905qmWJNFo8qJKRP+j7dHaYb/7ZWmf74JSpK7+LfnuF54/W3t+jA7yJT8cxAFZDRJ/BHcUhTzeCbbljKf9CF254AFvk9SVoSZMfrf1MKUpnENUM02RTuaIsv5B1LXMnwHzyXJ8WIJra1GjL79QlbWRnupKT1W8ItEozxpHNd4fYKptim9sti5cFT93pdNk/R5XD/yjX/WxIvn4Ve9/GXO3gedVbKv0c4wOFAxqatf/LTJEHCBeupTuyUyZu5A7ghI/gk8wrM6gdi9qudB9rlkjaAHxj8rSNWQx1G9ykm8CmK0KFv+gs5OV7bv2f2+F80C5nAn336Rn/IlEgqRAMespSurFfnqn7+CI0R+CcZXbpNOF4GaBXS0xLJeLQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Now that all the code has been added for pre-content events, and the various file systems that need the page fault hooks for fsnotify have been updated, add SB_I_ALLOW_HSM to the supported file systems. Signed-off-by: Josef Bacik --- fs/btrfs/super.c | 2 +- fs/ext4/super.c | 3 +++ fs/xfs/xfs_super.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 97a85d180b61..fe6ecc3f1cab 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -961,7 +961,7 @@ static int btrfs_fill_super(struct super_block *sb, #endif sb->s_xattr = btrfs_xattr_handlers; sb->s_time_gran = 1; - sb->s_iflags |= SB_I_CGROUPWB; + sb->s_iflags |= SB_I_CGROUPWB | SB_I_ALLOW_HSM; err = super_setup_bdi(sb); if (err) { diff --git a/fs/ext4/super.c b/fs/ext4/super.c index b3512d78b55c..13b9d67a4eec 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5306,6 +5306,9 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) /* i_version is always enabled now */ sb->s_flags |= SB_I_VERSION; + /* HSM events are allowed by default. */ + sb->s_iflags |= SB_I_ALLOW_HSM; + err = ext4_check_feature_compatibility(sb, es, silent); if (err) goto failed_mount; diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index fda75db739b1..2d1e9db8548d 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1713,7 +1713,7 @@ xfs_fs_fill_super( sb->s_time_max = XFS_LEGACY_TIME_MAX; } trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max); - sb->s_iflags |= SB_I_CGROUPWB; + sb->s_iflags |= SB_I_CGROUPWB | SB_I_ALLOW_HSM; set_posix_acl_flag(sb);