From patchwork Wed Sep 4 20:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13791364 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 CADFBCD4F24 for ; Wed, 4 Sep 2024 20:29:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4C4C6B0139; Wed, 4 Sep 2024 16:29:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D44D6B0140; Wed, 4 Sep 2024 16:29:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6ED346B013E; Wed, 4 Sep 2024 16:29:34 -0400 (EDT) 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 4778D6B0139 for ; Wed, 4 Sep 2024 16:29:34 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 01DDA1A052E for ; Wed, 4 Sep 2024 20:29:33 +0000 (UTC) X-FDA: 82528196268.22.0AC8A00 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 2C6334001F for ; Wed, 4 Sep 2024 20:29:31 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ZCfHm3Fi; dmarc=none; spf=none (imf11.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.176) smtp.mailfrom=josef@toxicpanda.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725481701; a=rsa-sha256; cv=none; b=yQxwcAs2N+0wGu34HOKrkoITJlRz+GGJlBp0kVwTG+ohMrC5mVdn+lKv1H52QNuAxrlAjR v47b/iD9ofJ6G+WImGJiGgf/a1WhA+tkxqMRE2GOt1w5uJopsuxnAD7sXnZj1orSlEanA6 0TGDxY3W741Ypxjfc5BxoxfpZqZ/vAM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=toxicpanda-com.20230601.gappssmtp.com header.s=20230601 header.b=ZCfHm3Fi; dmarc=none; spf=none (imf11.hostedemail.com: domain of josef@toxicpanda.com has no SPF policy when checking 209.85.160.176) smtp.mailfrom=josef@toxicpanda.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725481701; 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=hLbVQD1uWq7E7syR9oa0FyZv5hSgj9K2/YM9COMKj/I=; b=n+VoJERxlDhJK/utvfKRi4jCE56TGjgoTAxqSuEEMJRNjIgZKH4JivDbW6sZ7iree1arni 2nN/58zGZbjMkhL7Gd5eh3Ht7F11MVATVUKeiFIAFjDq5Sp1gBVBHzNBm0ORMffUbAkJwV w5DcqGjrvghd0lMpB7KaJW6VfH5iO9Y= Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-4568acc1ca8so320961cf.0 for ; Wed, 04 Sep 2024 13:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1725481771; x=1726086571; 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=hLbVQD1uWq7E7syR9oa0FyZv5hSgj9K2/YM9COMKj/I=; b=ZCfHm3Fii6vyPlR6XFmHN3fGawUQyfthTi7d/lLkKz9th+mbc0WMmtIVTsTZQbt1pL aSj/IZ43x3PKKBhD+3c1U6bQqumFDaGh2JpdrqvInG/2yv4mX1yXD7J8T9idpu+mFM9j HXvp+AhXb7gfix5d8uQ7ANE01MK8bc02Zg1ZewpwMZrOCK+ipOtHTkhbv6RUbbu1IPgs a9Z7Hmtx2m2Rf+cMZrp/Pd1th/eEm7ZgnkCfmaeyBR6q0+aKQVJDRTz3MsYyfGY26UVM GAAdAr/ekgaDIsY4gvmbn1bv5fnxRcEjc5HjNvtqqG6pVfOseNWRriP0/PD/jTXwivME L+0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725481771; x=1726086571; 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=hLbVQD1uWq7E7syR9oa0FyZv5hSgj9K2/YM9COMKj/I=; b=XXRND6ac+NIKZlpOx3n1mDvaM8/7xuB66ATPtfLQ/mYW8up9ErAKb45mXpw307MHiM LZyGoFYUUQFXJV8t78a7V3t9mmTgk1kPKD9pNnW7SHe3VETvrCVIGXmBBZriMeKvXRyr ud+dEyiFUh7WDE2R+cQHLpB/qQZpv1jXM3s1ND9KUP9Ozx62yHp7Z4+jA9TqBzU8/c4S +WiDv2928x/hXY7D+/AVzHN/n6wuw9NJhFtG9dvxWoM/njTnOgJ261iwzKPUx/oYb5qw BCUbe0aekztQpZODhIUNFa7bDBL/LlJ2TQYj/hZiLJ5LGFwi2m64lwWY/WHSpp8pej63 zoFg== X-Forwarded-Encrypted: i=1; AJvYcCVmhsizhKdmfW3SBfq8KqqlQ+kSndeocgTSELbiyaOM4r1wA6skheDmQmE2xBnLZ7ZMiprwsemp4g==@kvack.org X-Gm-Message-State: AOJu0YxFbsv5xU4cXPP7cAQ15LypdfyrhGA9m6YkBXYzEKffKeoZ2QeG 5+IP/N9M5cMHEvDlVCOcSKjekmfdcpqbXUzZviDPIPd4mPpHHk8Fmk0XPxf+q8M= X-Google-Smtp-Source: AGHT+IGdJ5rFqIo2R8SFFCo2OiCjnf+nE2kM7AO4Z/b+MhtME6M5x1ovZdZNYRb7zGAzpKTv2dvAYA== X-Received: by 2002:a05:622a:6209:b0:44f:ed41:6a02 with SMTP id d75a77b69052e-45705429a88mr138893691cf.57.1725481771257; Wed, 04 Sep 2024 13:29:31 -0700 (PDT) Received: from localhost (syn-076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45801b5f7aasm1500371cf.52.2024.09.04.13.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 13:29:30 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, brauner@kernel.org, linux-xfs@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v5 10/18] fs: add a flag to indicate the fs supports pre-content events Date: Wed, 4 Sep 2024 16:28:00 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 2C6334001F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ypatmz656n35eiyepaxjhhiwg9e7j1ii X-HE-Tag: 1725481771-463549 X-HE-Meta: U2FsdGVkX18FaRZjB176X/areRcV1d1nnXX7QS421KSVO71Jx4VodmYPs5yxFwU/lyuWilXWbYx/9FOyEUtN9vafx3+B2kJZAwgnsHAgN+QSFNKc6DaPI0KgrlGuuejLuPt3jwHTaLu0kA1xfnceeSd2ujRDXJTUH8+i3KuyJSm4lizJwFoaxjifhVoIW9wYraWwZ0+6q9bImArPyLTuNVvKsRfiCP3ijVHCNoERJbCmK7OYJoBoVLnnQOPnWDIb8vfpxgukc3DiPrGnfnYTrEib+byDaMSvluPK6NTENk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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: The pre-content events require some extra thinking, especially around page faults. In order to make sure we don't advertise a feature working that doesn't actually work, add a flag to allow file systems to opt-in to this behavior. Signed-off-by: Josef Bacik Reviewed-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 2 ++ include/linux/fs.h | 1 + include/linux/fsnotify.h | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 53eee8af34a0..936e9f9e0cbc 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1736,6 +1736,8 @@ static int fanotify_events_supported(struct fsnotify_group *group, /* Pre-content events are only supported on regular files and dirs */ if (mask & FANOTIFY_PRE_CONTENT_EVENTS) { + if (!(path->mnt->mnt_sb->s_type->fs_flags & FS_ALLOW_HSM)) + return -EINVAL; if (!is_dir && !d_is_reg(path->dentry)) return -EINVAL; if (is_dir && mask & FAN_PRE_MODIFY) diff --git a/include/linux/fs.h b/include/linux/fs.h index fd34b5755c0b..5708e91d3625 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2494,6 +2494,7 @@ struct file_system_type { #define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */ #define FS_DISALLOW_NOTIFY_PERM 16 /* Disable fanotify permission events */ #define FS_ALLOW_IDMAP 32 /* FS has been updated to handle vfs idmappings. */ +#define FS_ALLOW_HSM 64 /* FS can handle fanotify pre-content events. */ #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ int (*init_fs_context)(struct fs_context *); const struct fs_parameter_spec *parameters; diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 9d001d328619..27992b548f0c 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -179,6 +179,10 @@ static inline int fsnotify_file_area_perm(struct file *file, int perm_mask, if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode)) return 0; + /* The fs doesn't support pre-content events. */ + if (!(inode->i_sb->s_type->fs_flags & FS_ALLOW_HSM)) + return 0; + if (perm_mask & MAY_WRITE) fsnotify_mask = FS_PRE_MODIFY; else if (perm_mask & (MAY_READ | MAY_ACCESS))